Skip to content

Commit 9df6842

Browse files
authoredJan 31, 2024
Merge pull request #68 from BloomBooks/parse-server-7
Upgrade to parse-server 7.0.0-alpha.1 for MongoDB 7 support (BL-12843)
2 parents 1a9b8b1 + eaa48c7 commit 9df6842

10 files changed

+3942
-2009
lines changed
 

‎.eslintrc.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
2-
"env": {
3-
"commonjs": true,
4-
"es6": true,
5-
"node": true
6-
},
72
"extends": "eslint:recommended",
8-
"globals": {
9-
"Atomics": "readonly",
10-
"SharedArrayBuffer": "readonly"
3+
"env": {
4+
"node": true,
5+
"es6": true
116
},
127
"parserOptions": {
13-
"ecmaVersion": 2018
8+
"ecmaVersion": 2021,
9+
"sourceType": "module",
10+
"requireConfigFile": false
1411
},
12+
"parser": "@babel/eslint-parser",
1513
"rules": {
14+
},
15+
"globals" : {
16+
"Parse" : true
1617
}
17-
}
18+
}

‎.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"bloomlibrary",
44
"mailgun",
55
"rebrand"
6-
]
6+
],
7+
"editor.formatOnSave": true
78
}

‎bloomFirebaseAuthAdapter.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const Parse = require("parse/node").Parse;
2-
const httpsRequest = require("./httpsRequest");
3-
const jwt = require("jsonwebtoken");
1+
import jwt from "jsonwebtoken";
2+
import { get as httpGet } from "./httpsRequest.js";
43

54
// This adapter, modified from the 'apple' one in parse-server, validates a user when
65
// presented with a valid, current firebase-auth token from the appropriate domain whose email
@@ -22,7 +21,7 @@ let currentKey;
2221
const getPublicKeys = async () => {
2322
let data;
2423
try {
25-
data = await httpsRequest.get(TOKEN_ISSUER);
24+
data = await httpGet(TOKEN_ISSUER);
2625
} catch (e) {
2726
if (currentKey) {
2827
return currentKey;
@@ -49,7 +48,7 @@ const tryPublicKeys = (token, publicKeys) => {
4948
// and encypted with the given private key and returns it decoded.
5049
// It will fail appropriately if the token is expired.
5150
const jwtClaims = jwt.verify(token, publicKey, {
52-
algorithms: "RS256"
51+
algorithms: "RS256",
5352
});
5453
if (jwtClaims) {
5554
return jwtClaims;
@@ -122,7 +121,7 @@ function validateAppId() {
122121
return Promise.resolve();
123122
}
124123

125-
module.exports = {
124+
export default {
126125
validateAppId,
127-
validateAuthData
126+
validateAuthData,
128127
};

‎cloud/emails.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Parse.Cloud.define("testBookSaved", async () => {
4747

4848
// Send an email to notify about a newly created book.
4949
// It is sent to an internal address, set by environment variable EMAIL_BOOK_EVENT_RECIPIENT on the server.
50-
exports.sendEmailAboutNewBookAsync = async (parseBook) => {
50+
export const sendEmailAboutNewBookAsync = async (parseBook) => {
5151
var bookId = parseBook.id;
5252
var query = new Parse.Query("books");
5353
query.equalTo("objectId", bookId);

‎cloud/main.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* eslint-disable no-undef */
2-
require("./emails.js"); // allows email-specific could functions to be defined
3-
require("./utility.js"); // utility functions which don't belong in the main file
1+
import "./emails.js"; // allows email-specific cloud functions to be defined
2+
import "./utility.js"; // utility functions which don't belong in the main file
43

54
// This function will call save on every book. This is useful for
65
// applying the functionality in beforeSaveBook to every book,

‎httpsRequest.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// helper file needed by bloomAuth0Adapater; copied from file required by apple authAdapter
2-
// in parser-server core code.
3-
const https = require("https");
1+
// This helper file is needed by bloomFirebaseAuthAdapter.
2+
// It was copied (and slightly modified) from a file required by apple authAdapter in parser-server core code.
3+
import https from "https";
44

55
function makeCallback(resolve, reject, noJSON) {
6-
return function(res) {
6+
return function (res) {
77
let data = "";
8-
res.on("data", chunk => {
8+
res.on("data", (chunk) => {
99
data += chunk;
1010
});
1111
res.on("end", () => {
@@ -23,21 +23,19 @@ function makeCallback(resolve, reject, noJSON) {
2323
};
2424
}
2525

26-
function get(options, noJSON = false) {
26+
export function get(options, noJSON = false) {
2727
return new Promise((resolve, reject) => {
2828
https
2929
.get(options, makeCallback(resolve, reject, noJSON))
3030
.on("error", reject);
3131
});
3232
}
3333

34-
function request(options, postData) {
34+
export function request(options, postData) {
3535
return new Promise((resolve, reject) => {
3636
const req = https.request(options, makeCallback(resolve, reject));
3737
req.on("error", reject);
3838
req.write(postData);
3939
req.end();
4040
});
4141
}
42-
43-
module.exports = { get, request };

‎index.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const express = require("express");
2-
const ParseServer = require("parse-server").ParseServer;
3-
const ParseDashboard = require("parse-dashboard");
4-
const BloomFirebaseAuthAdapter = require("./bloomFirebaseAuthAdapter");
1+
import express from "express";
2+
import { ParseServer } from "parse-server";
3+
import http from "http";
4+
import ParseDashboard from "parse-dashboard";
5+
import BloomFirebaseAuthAdapter from "./bloomFirebaseAuthAdapter.js";
56

67
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
78

@@ -11,19 +12,20 @@ if (!databaseUri) {
1112

1213
const serverConfig = {
1314
databaseURI: databaseUri || "mongodb://localhost:27017/dev",
14-
cloud: process.env.CLOUD_CODE_MAIN || __dirname + "/cloud/main.js",
15+
cloud: function () {
16+
import("./cloud/main.js");
17+
},
1518
appId: process.env.APP_ID || "myAppId",
1619
masterKey: process.env.MASTER_KEY || "123",
1720
readOnlyMasterKey: process.env.READ_ONLY_MASTER_KEY || "ro",
1821
serverURL: process.env.SERVER_URL || "http://localhost:1337/parse",
1922

2023
appName: process.env.APP_NAME || "BloomLibrary.org",
2124

22-
auth: { bloom: BloomFirebaseAuthAdapter },
25+
auth: { bloom: { module: BloomFirebaseAuthAdapter, enabled: true } },
2326

2427
allowClientClassCreation: false,
2528
};
26-
const api = new ParseServer(serverConfig);
2729

2830
const dashboard = new ParseDashboard({
2931
apps: [
@@ -56,6 +58,12 @@ const dashboard = new ParseDashboard({
5658

5759
const app = express();
5860

61+
// Serve the Parse API on the /parse URL prefix
62+
const mountPath = process.env.PARSE_MOUNT || "/parse";
63+
const server = new ParseServer(serverConfig);
64+
await server.start();
65+
app.use(mountPath, server.app);
66+
5967
// The main thing here is the google-site-verification meta tag.
6068
// This lets us access the site on the Google Search Console.
6169
app.get("/", function (req, res) {
@@ -67,14 +75,10 @@ app.get("/", function (req, res) {
6775
);
6876
});
6977

70-
// Serve the Parse API on the /parse URL prefix
71-
const mountPath = process.env.PARSE_MOUNT || "/parse";
72-
app.use(mountPath, api);
73-
7478
app.use("/dashboard", dashboard);
7579

7680
const port = process.env.PORT || 1337;
77-
const httpServer = require("http").createServer(app);
81+
const httpServer = http.createServer(app);
7882
httpServer.listen(port, function () {
7983
console.log("bloom-parse-server running on port " + port + ".");
8084
});

‎package-lock.json

+3,874-1,946
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+17-14
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@
22
"name": "bloom-parse-server",
33
"version": "1.4.0",
44
"description": "Parse server for bloomlibrary.org",
5-
"main": "index.js",
65
"repository": {
76
"type": "git",
87
"url": "https://github.com/BloomBooks/bloom-parse-server"
98
},
109
"license": "MIT",
11-
"dependencies": {
12-
"express": "4.18.2",
13-
"jsonwebtoken": "^9.0.0",
14-
"mailgun-js": "^0.22.0",
15-
"parse-dashboard": "5.0.0",
16-
"parse-server": "5.4.1",
17-
"patch-package": "^6.5.1"
18-
},
10+
"main": "index.js",
1911
"scripts": {
2012
"start": "node index.js",
2113
"postinstall": "patch-package"
2214
},
15+
"// mailgun-js is deprecated; we should replace it with officially-supported mailgun.js": " ",
16+
"dependencies": {
17+
"express": "4.18.2",
18+
"jsonwebtoken": "9.0.2",
19+
"mailgun-js": "0.22.0",
20+
"parse-dashboard": "5.3.0",
21+
"parse-server": "7.0.0-alpha.1",
22+
"patch-package": "8.0.0"
23+
},
24+
"type": "module",
25+
"devDependencies": {
26+
"@babel/eslint-parser": "7.21.3",
27+
"eslint": "8.38.0",
28+
"prettier": "2.8.7"
29+
},
2330
"// On the server, this is set in Configuration > Application settings > WEBSITE_NODE_DEFAULT_VERSION": " ",
2431
"// (18.12.1 as of Feb 2023)": " ",
2532
"engines": {
26-
"node": ">=16 <19"
27-
},
28-
"devDependencies": {
29-
"eslint": "^6.8.0",
30-
"prettier": "^2.8.3"
33+
"node": ">=16 <17 || >=18 <19"
3134
}
3235
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
diff --git a/node_modules/parse-server/lib/RestQuery.js b/node_modules/parse-server/lib/RestQuery.js
2-
index 8d1ff6b..135e614 100644
2+
index 1155c10..ab368d0 100644
33
--- a/node_modules/parse-server/lib/RestQuery.js
44
+++ b/node_modules/parse-server/lib/RestQuery.js
5-
@@ -200,8 +200,8 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, cl
6-
RestQuery.prototype.execute = function (executeOptions) {
5+
@@ -242,8 +242,8 @@ _UnsafeRestQuery.prototype.execute = function (executeOptions) {
76
return Promise.resolve().then(() => {
87
return this.buildRestWhere();
9-
- }).then(() => {
8+
}).then(() => {
109
- return this.denyProtectedFields();
11-
+// }).then(() => {
10+
- }).then(() => {
1211
+// return this.denyProtectedFields();
13-
}).then(() => {
12+
+// }).then(() => {
1413
return this.handleIncludeAll();
1514
}).then(() => {
15+
return this.handleExcludeKeys();

0 commit comments

Comments
 (0)
Please sign in to comment.