From f5d592a291447baf39d4405b4cd74c3ed3679d51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Jan 2023 03:00:50 +0000 Subject: [PATCH 1/7] Bump mongoose from 6.8.2 to 6.8.3 Bumps [mongoose](https://github.com/Automattic/mongoose) from 6.8.2 to 6.8.3. - [Release notes](https://github.com/Automattic/mongoose/releases) - [Changelog](https://github.com/Automattic/mongoose/blob/master/CHANGELOG.md) - [Commits](https://github.com/Automattic/mongoose/compare/6.8.2...6.8.3) --- updated-dependencies: - dependency-name: mongoose dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 30 +++++++++++++++--------------- package.json | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 796e57bee..b44a6fd57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "marked-extended-tables": "^1.0.5", "markedLegacy": "npm:marked@^0.3.19", "moment": "^2.29.4", - "mongoose": "^6.8.2", + "mongoose": "^6.8.3", "nanoid": "3.3.4", "nconf": "^0.12.0", "npm": "^8.10.0", @@ -9863,9 +9863,9 @@ } }, "node_modules/kareem": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.0.tgz", - "integrity": "sha512-rVBUGGwvqg130iwYu8k7lutHuDBFj1yGRdnlE44wEhxAmFBad1zcL66PdWC1raw3tIObY6XWhtv3VL04xQb/cg==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", + "integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==", "engines": { "node": ">=12.0.0" } @@ -10395,12 +10395,12 @@ } }, "node_modules/mongoose": { - "version": "6.8.2", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.8.2.tgz", - "integrity": "sha512-cIato5N2w/QuJkkh0w4nyf7ty7DqmmP/W8/6PFSM0DrzbxIMlr6VN15LBIceTSJIxbznNl2Mlbh9Rm4sokMw+A==", + "version": "6.8.3", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.8.3.tgz", + "integrity": "sha512-qrVWefJK+wFNBH0ALV+oiyJ+FN42O/BqvHFmlFJJ2LKuNmQEOE0JV8FCxnZqtanwbHs4i+k/SkjhtC+C01haaw==", "dependencies": { "bson": "^4.7.0", - "kareem": "2.5.0", + "kareem": "2.5.1", "mongodb": "4.12.1", "mpath": "0.9.0", "mquery": "4.0.3", @@ -24120,9 +24120,9 @@ "integrity": "sha512-40aUybvhH9t2h71ncA1/1SbtTNCVZHgsTsTgqPUxGWDmUDrXyDf2wMNQKEbdBjbf4AI+fQhbECNTV6lWxQKUzg==" }, "kareem": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.0.tgz", - "integrity": "sha512-rVBUGGwvqg130iwYu8k7lutHuDBFj1yGRdnlE44wEhxAmFBad1zcL66PdWC1raw3tIObY6XWhtv3VL04xQb/cg==" + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", + "integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==" }, "kind-of": { "version": "4.0.0", @@ -24533,12 +24533,12 @@ } }, "mongoose": { - "version": "6.8.2", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.8.2.tgz", - "integrity": "sha512-cIato5N2w/QuJkkh0w4nyf7ty7DqmmP/W8/6PFSM0DrzbxIMlr6VN15LBIceTSJIxbznNl2Mlbh9Rm4sokMw+A==", + "version": "6.8.3", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.8.3.tgz", + "integrity": "sha512-qrVWefJK+wFNBH0ALV+oiyJ+FN42O/BqvHFmlFJJ2LKuNmQEOE0JV8FCxnZqtanwbHs4i+k/SkjhtC+C01haaw==", "requires": { "bson": "^4.7.0", - "kareem": "2.5.0", + "kareem": "2.5.1", "mongodb": "4.12.1", "mpath": "0.9.0", "mquery": "4.0.3", diff --git a/package.json b/package.json index 51f9f8ed8..978bde7e7 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "marked-extended-tables": "^1.0.5", "markedLegacy": "npm:marked@^0.3.19", "moment": "^2.29.4", - "mongoose": "^6.8.2", + "mongoose": "^6.8.3", "nanoid": "3.3.4", "nconf": "^0.12.0", "npm": "^8.10.0", From a9c28e84d0029d4c9cbc588affc5d4df103e7c8d Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 9 Jan 2023 10:30:07 -0500 Subject: [PATCH 2/7] Enable brew version mismatch checking on server Was commented out previously to allow users time to update client code so the proper error displays --- server/homebrew.api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 550da0ddd..47a6e7f42 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -192,8 +192,8 @@ If you believe you should have access to this brew, ask the file owner to invite const brewFromClient = api.excludePropsFromUpdate(req.body); if(req.brew.version && brewFromClient.version && req.brew.version > brewFromClient.version) { console.log(`Version mismatch on brew ${req.body.editId}`); - // res.setHeader('Content-Type', 'application/json'); - // return res.status(409).send(JSON.stringify({ message: `The brew has been changed on a different device. Please save your changes elsewhere, refresh, and try again.` })); + res.setHeader('Content-Type', 'application/json'); + return res.status(409).send(JSON.stringify({ message: `The brew has been changed on a different device. Please save your changes elsewhere, refresh, and try again.` })); } let brew = _.assign(req.brew, brewFromClient); From 8cbab4d4ce07ce866fb66437e9d2a8e5a726844d Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 9 Jan 2023 14:12:57 -0500 Subject: [PATCH 3/7] Fix saving issue when tags do not exist Rare case where tags don't exist at all; gets confused in the step of converting tag strings to arrays --- server/homebrew.api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 47a6e7f42..18269a639 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -77,8 +77,8 @@ If you believe you should have access to this brew, ask the file owner to invite } // Clean up brew: fill in missing fields with defaults / fix old invalid values - stub.tags = stub.tags || undefined; // Clear empty strings - stub.renderer = stub.renderer || undefined; // Clear empty strings + stub.tags = stub?.tags || undefined; // Clear empty strings + stub.renderer = stub?.renderer || undefined; // Clear empty strings stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields req.brew = stub; From 15e5a31767b177cf2e48e16723a7dc268f8508da Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 9 Jan 2023 14:53:35 -0500 Subject: [PATCH 4/7] If no stub exists, start stub as {}, not undefined Recent changes to handle bad brew properties (tags as strings, no renderer, etc.) didn't account for the case where an old Google brew is first being stubbed; since no stub exists, there is no object to perform the corrections on, and we crash. --- server/homebrew.api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 18269a639..b4339011f 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -47,7 +47,7 @@ const api = { console.warn(err); } }); - stub = stub?.toObject(); + stub = stub?.toObject() || {}; // If there is a google id, try to find the google brew if(!stubOnly && (googleId || stub?.googleId)) { @@ -77,8 +77,8 @@ If you believe you should have access to this brew, ask the file owner to invite } // Clean up brew: fill in missing fields with defaults / fix old invalid values - stub.tags = stub?.tags || undefined; // Clear empty strings - stub.renderer = stub?.renderer || undefined; // Clear empty strings + stub.tags = stub.tags || undefined; // Clear empty strings + stub.renderer = stub.renderer || undefined; // Clear empty strings stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields req.brew = stub; From 6ed52f37ccfb26df2d4dc72c4c9bdb0002e46aa5 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 9 Jan 2023 17:30:49 -0500 Subject: [PATCH 5/7] Only fix stub if we actually found one. --- server/homebrew.api.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index b4339011f..56bbb15f4 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -47,7 +47,7 @@ const api = { console.warn(err); } }); - stub = stub?.toObject() || {}; + stub = stub?.toObject(); // If there is a google id, try to find the google brew if(!stubOnly && (googleId || stub?.googleId)) { @@ -77,9 +77,11 @@ If you believe you should have access to this brew, ask the file owner to invite } // Clean up brew: fill in missing fields with defaults / fix old invalid values - stub.tags = stub.tags || undefined; // Clear empty strings - stub.renderer = stub.renderer || undefined; // Clear empty strings - stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields + if(stub) { + stub.tags = stub.tags || undefined; // Clear empty strings + stub.renderer = stub.renderer || undefined; // Clear empty strings + stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields + } req.brew = stub; next(); From 901615d99e60f116aded03209f7b34bb39a7d882 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 10 Jan 2023 21:08:21 -0500 Subject: [PATCH 6/7] Remove extra console log for getGoogleBrew App.js already logs the thrown error, so we were getting double logs (and Google errors are long....). This should make the logs a bit easier to sift through. --- server/homebrew.api.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 56bbb15f4..86352c687 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -54,11 +54,10 @@ const api = { let googleError; const googleBrew = await GoogleActions.getGoogleBrew(googleId || stub?.googleId, id, accessType) .catch((err)=>{ - console.warn(err); googleError = err; }); - // If we can't find the google brew and there is a google id for the brew, throw an error. - if(!googleBrew) throw googleError; + // Throw any error caught while attempting to retrieve Google brew. + if(googleError) throw googleError; // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; } From da676c6ec1dde1f5c6d4a960c4899f89e96b9cf8 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Thu, 12 Jan 2023 13:33:55 -0500 Subject: [PATCH 7/7] Ensure getBrew returns an object if undefined --- server/homebrew.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 86352c687..07b1c33f2 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -82,7 +82,7 @@ If you believe you should have access to this brew, ask the file owner to invite stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields } - req.brew = stub; + req.brew = stub ?? {}; next(); }; },