Merge pull request #46 from overleaf/jpa-bulk-dependency-upgrades

[misc] bulk dependency upgrades
This commit is contained in:
Jakob Ackermann 2021-07-13 15:43:13 +02:00 committed by GitHub
commit a9ba4ce187
18 changed files with 1224 additions and 2709 deletions

View file

@ -3,9 +3,9 @@
// https://github.com/sharelatex/sharelatex-dev-environment
{
"extends": [
"eslint:recommended",
"standard",
"prettier",
"prettier/standard"
"prettier"
],
"parserOptions": {
"ecmaVersion": 2018
@ -20,6 +20,19 @@
"mocha": true
},
"rules": {
// TODO(das7pad): remove overrides after fixing all the violations manually (https://github.com/overleaf/issues/issues/3882#issuecomment-878999671)
// START of temporary overrides
"array-callback-return": "off",
"no-dupe-else-if": "off",
"no-var": "off",
"no-empty": "off",
"node/handle-callback-err": "off",
"no-loss-of-precision": "off",
"node/no-callback-literal": "off",
"node/no-path-concat": "off",
"prefer-regex-literals": "off",
// END of temporary overrides
// Swap the no-unused-expressions rule with a more chai-friendly one
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": "error",

View file

@ -20,4 +20,4 @@ updates:
# future if we reorganise teams
labels:
- "dependencies"
- "Team-Magma"
- "type:maintenance"

View file

@ -1 +1 @@
12.21.0
12.22.3

View file

@ -2,6 +2,10 @@
# Instead run bin/update_build_scripts from
# https://github.com/sharelatex/sharelatex-dev-environment
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false
}

View file

@ -2,7 +2,7 @@
# Instead run bin/update_build_scripts from
# https://github.com/sharelatex/sharelatex-dev-environment
FROM node:12.21.0 as base
FROM node:12.22.3 as base
WORKDIR /app

View file

@ -7,7 +7,7 @@
*/
const metrics = require('@overleaf/metrics')
metrics.initialize('notifications')
const Settings = require('settings-sharelatex')
const Settings = require('@overleaf/settings')
const logger = require('logger-sharelatex')
logger.initialize('notifications-sharelatex')
const express = require('express')
@ -56,12 +56,12 @@ app.get('*', (req, res) => res.sendStatus(404))
const host =
__guard__(
Settings.internal != null ? Settings.internal.notifications : undefined,
(x) => x.host
x => x.host
) || 'localhost'
const port =
__guard__(
Settings.internal != null ? Settings.internal.notifications : undefined,
(x1) => x1.port
x1 => x1.port
) || 3042
mongodb
@ -71,7 +71,7 @@ mongodb
logger.info(`notifications starting up, listening on ${host}:${port}`)
)
})
.catch((err) => {
.catch(err => {
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
process.exit(1)
})

View file

@ -1,7 +1,6 @@
/* eslint-disable
camelcase,
no-dupe-keys,
standard/no-callback-literal,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
@ -15,20 +14,20 @@ const { db, ObjectId } = require('./mongodb')
const request = require('request')
const async = require('async')
const _ = require('underscore')
const settings = require('settings-sharelatex')
const settings = require('@overleaf/settings')
const { port } = settings.internal.notifications
const logger = require('logger-sharelatex')
module.exports = {
check(callback) {
const user_id = ObjectId()
const cleanupNotifications = (callback) =>
const cleanupNotifications = callback =>
db.notifications.remove({ user_id }, callback)
let notification_key = `smoke-test-notification-${ObjectId()}`
const getOpts = (endPath) => ({
const getOpts = endPath => ({
url: `http://localhost:${port}/user/${user_id}${endPath}`,
timeout: 5000
timeout: 5000,
})
logger.log(
{ user_id, opts: getOpts(), key: notification_key, user_id },
@ -41,7 +40,7 @@ module.exports = {
key: notification_key,
messageOpts: '',
templateKey: 'f4g5',
user_id
user_id,
}
return request.post(opts, cb)
},
@ -59,7 +58,7 @@ module.exports = {
}
const hasNotification = _.some(
body,
(notification) =>
notification =>
notification.key === notification_key &&
notification.user_id === user_id.toString()
)
@ -73,7 +72,7 @@ module.exports = {
return cb('notification not found in response')
}
})
}
},
]
return async.series(jobs, function (err, body) {
if (err != null) {
@ -112,5 +111,5 @@ module.exports = {
})
}
})
}
},
}

View file

@ -23,7 +23,7 @@ module.exports = Notifications = {
}
const query = {
user_id: ObjectId(user_id),
templateKey: { $exists: true }
templateKey: { $exists: true },
}
db.notifications.find(query).toArray(callback)
},
@ -34,7 +34,7 @@ module.exports = Notifications = {
}
const query = {
user_id: ObjectId(user_id),
key: notification.key
key: notification.key,
}
return db.notifications.count(query, function (err, count) {
if (err != null) {
@ -45,52 +45,53 @@ module.exports = Notifications = {
},
addNotification(user_id, notification, callback) {
return this._countExistingNotifications(user_id, notification, function (
err,
count
) {
if (err != null) {
return callback(err)
}
if (count !== 0 && !notification.forceCreate) {
return callback()
}
const doc = {
user_id: ObjectId(user_id),
key: notification.key,
messageOpts: notification.messageOpts,
templateKey: notification.templateKey
}
// TTL index on the optional `expires` field, which should arrive as an iso date-string, corresponding to
// a datetime in the future when the document should be automatically removed.
// in Mongo, TTL indexes only work on date fields, and ignore the document when that field is missing
// see `README.md` for instruction on creating TTL index
if (notification.expires != null) {
try {
doc.expires = new Date(notification.expires)
const _testValue = doc.expires.toISOString()
} catch (error) {
err = error
logger.error(
{ user_id, expires: notification.expires },
'error converting `expires` field to Date'
)
return this._countExistingNotifications(
user_id,
notification,
function (err, count) {
if (err != null) {
return callback(err)
}
if (count !== 0 && !notification.forceCreate) {
return callback()
}
const doc = {
user_id: ObjectId(user_id),
key: notification.key,
messageOpts: notification.messageOpts,
templateKey: notification.templateKey,
}
// TTL index on the optional `expires` field, which should arrive as an iso date-string, corresponding to
// a datetime in the future when the document should be automatically removed.
// in Mongo, TTL indexes only work on date fields, and ignore the document when that field is missing
// see `README.md` for instruction on creating TTL index
if (notification.expires != null) {
try {
doc.expires = new Date(notification.expires)
const _testValue = doc.expires.toISOString()
} catch (error) {
err = error
logger.error(
{ user_id, expires: notification.expires },
'error converting `expires` field to Date'
)
return callback(err)
}
}
db.notifications.updateOne(
{ user_id: doc.user_id, key: notification.key },
{ $set: doc },
{ upsert: true },
callback
)
}
db.notifications.updateOne(
{ user_id: doc.user_id, key: notification.key },
{ $set: doc },
{ upsert: true },
callback
)
})
)
},
removeNotificationId(user_id, notification_id, callback) {
const searchOps = {
user_id: ObjectId(user_id),
_id: ObjectId(notification_id)
_id: ObjectId(notification_id),
}
const updateOperation = { $unset: { templateKey: true, messageOpts: true } }
db.notifications.updateOne(searchOps, updateOperation, callback)
@ -99,7 +100,7 @@ module.exports = Notifications = {
removeNotificationKey(user_id, notification_key, callback) {
const searchOps = {
user_id: ObjectId(user_id),
key: notification_key
key: notification_key,
}
const updateOperation = { $unset: { templateKey: true } }
db.notifications.updateOne(searchOps, updateOperation, callback)
@ -115,8 +116,8 @@ module.exports = Notifications = {
deleteNotificationByKeyOnly(notification_key, callback) {
const searchOps = { key: notification_key }
db.notifications.deleteOne(searchOps, callback)
}
},
}
;['getUserNotifications', 'addNotification'].map((method) =>
;['getUserNotifications', 'addNotification'].map(method =>
metrics.timeAsyncMethod(Notifications, method, 'mongo.Notifications', logger)
)

View file

@ -50,7 +50,7 @@ module.exports = {
logger.log(
{
user_id: req.params.user_id,
notification_id: req.params.notification_id
notification_id: req.params.notification_id,
},
'mark id notification as read'
)
@ -83,5 +83,5 @@ module.exports = {
notification_key,
(err, notifications) => res.sendStatus(200)
)
}
},
}

View file

@ -1,4 +1,4 @@
const Settings = require('settings-sharelatex')
const Settings = require('@overleaf/settings')
const { MongoClient, ObjectId } = require('mongodb')
const clientPromise = MongoClient.connect(
@ -24,5 +24,5 @@ async function setupDb() {
module.exports = {
db,
ObjectId,
waitForDb
waitForDb,
}

View file

@ -3,6 +3,6 @@ notifications
--docker-repos=gcr.io/overleaf-ops
--env-add=
--env-pass-through=
--node-version=12.21.0
--node-version=12.22.3
--public-repo=True
--script-version=3.8.0
--script-version=3.11.0

View file

@ -2,17 +2,17 @@ module.exports = {
internal: {
notifications: {
port: 3042,
host: process.env.LISTEN_ADDRESS || 'localhost'
}
host: process.env.LISTEN_ADDRESS || 'localhost',
},
},
mongo: {
options: {
useUnifiedTopology:
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true'
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
},
url:
process.env.MONGO_CONNECTION_STRING ||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`
}
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
},
}

View file

@ -6,7 +6,7 @@ version: "2.3"
services:
test_unit:
image: node:12.21.0
image: node:12.22.3
volumes:
- .:/app
working_dir: /app
@ -18,7 +18,7 @@ services:
user: node
test_acceptance:
image: node:12.21.0
image: node:12.22.3
volumes:
- .:/app
working_dir: /app

File diff suppressed because it is too large Load diff

View file

@ -10,48 +10,42 @@
"test:unit:_run": "mocha --recursive --reporter spec $@ test/unit/js",
"test:unit": "npm run test:unit:_run -- --grep=$MOCHA_GREP",
"nodemon": "nodemon --config nodemon.json",
"lint": "node_modules/.bin/eslint --max-warnings 0 .",
"format": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --list-different",
"format:fix": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --write"
"lint": "eslint --max-warnings 0 --format unix .",
"format": "prettier --list-different $PWD/'**/*.js'",
"format:fix": "prettier --write $PWD/'**/*.js'",
"lint:fix": "eslint --fix ."
},
"author": "",
"license": "ISC",
"dependencies": {
"@overleaf/metrics": "^3.5.1",
"@overleaf/settings": "^2.1.1",
"async": "^2.6.3",
"body-parser": "^1.19.0",
"coffee-script": "^1.12.7",
"bunyan": "^1.8.15",
"errorhandler": "^1.5.1",
"express": "4.17.1",
"logger-sharelatex": "^2.2.0",
"method-override": "^3.0.0",
"mongodb": "^3.6.0",
"request": "^2.88.2",
"settings-sharelatex": "^1.1.0",
"underscore": "1.13.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"bunyan": "^1.8.12",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-standard": "^14.1.0",
"eslint-config-standard-jsx": "^8.1.0",
"eslint-config-standard-react": "^9.2.0",
"eslint-plugin-chai-expect": "^2.1.0",
"eslint-plugin-chai-friendly": "^0.5.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-node": "^11.0.0",
"chai-as-promised": "^7.1.1",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-chai-expect": "^2.2.0",
"eslint-plugin-chai-friendly": "^0.6.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.1",
"prettier": "^2.0.0",
"prettier-eslint-cli": "^5.0.0",
"mocha": "^8.3.2",
"prettier": "^2.2.1",
"sandboxed-module": "^2.0.3",
"sinon": "^9.0.1"
}

View file

@ -14,8 +14,8 @@ SandboxedModule.configure({
warn() {},
err() {},
error() {},
fatal() {}
}
fatal() {},
},
},
globals: { Buffer, JSON, console, process }
globals: { Buffer, JSON, console, process },
})

View file

@ -27,17 +27,17 @@ describe('Notifications Controller', function () {
requires: {
'./Notifications': this.notifications,
'@overleaf/metrics': {
inc: sinon.stub()
}
}
inc: sinon.stub(),
},
},
})
return (this.stubbedNotification = [
{
key: notification_key,
messageOpts: 'some info',
templateKey: 'template-key'
}
templateKey: 'template-key',
},
])
})
@ -48,17 +48,17 @@ describe('Notifications Controller', function () {
.callsArgWith(1, null, this.stubbedNotification)
const req = {
params: {
user_id
}
user_id,
},
}
return this.controller.getUserNotifications(req, {
json: (result) => {
json: result => {
result.should.equal(this.stubbedNotification)
this.notifications.getUserNotifications
.calledWith(user_id)
.should.equal(true)
return done()
}
},
})
})
})
@ -68,18 +68,18 @@ describe('Notifications Controller', function () {
this.notifications.addNotification = sinon.stub().callsArgWith(2)
const req = {
params: {
user_id
user_id,
},
body: this.stubbedNotification
body: this.stubbedNotification,
}
return this.controller.addNotification(req, {
sendStatus: (code) => {
sendStatus: code => {
this.notifications.addNotification
.calledWith(user_id, this.stubbedNotification)
.should.equal(true)
code.should.equal(200)
return done()
}
},
})
})
})
@ -90,17 +90,17 @@ describe('Notifications Controller', function () {
const req = {
params: {
user_id,
notification_id
}
notification_id,
},
}
return this.controller.removeNotificationId(req, {
sendStatus: (code) => {
sendStatus: code => {
this.notifications.removeNotificationId
.calledWith(user_id, notification_id)
.should.equal(true)
code.should.equal(200)
return done()
}
},
})
})
})
@ -110,18 +110,18 @@ describe('Notifications Controller', function () {
this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
const req = {
params: {
user_id
user_id,
},
body: { key: notification_key }
body: { key: notification_key },
}
return this.controller.removeNotificationKey(req, {
sendStatus: (code) => {
sendStatus: code => {
this.notifications.removeNotificationKey
.calledWith(user_id, notification_key)
.should.equal(true)
code.should.equal(200)
return done()
}
},
})
})
})
@ -133,17 +133,17 @@ describe('Notifications Controller', function () {
.callsArgWith(1)
const req = {
params: {
key: notification_key
}
key: notification_key,
},
}
return this.controller.removeNotificationByKeyOnly(req, {
sendStatus: (code) => {
sendStatus: code => {
this.notifications.removeNotificationByKeyOnly
.calledWith(notification_key)
.should.equal(true)
code.should.equal(200)
return done()
}
},
})
})
})

View file

@ -35,23 +35,23 @@ describe('Notifications Tests', function () {
find: this.findStub,
count: this.countStub,
updateOne: this.updateOneStub,
deleteOne: this.deleteOneStub
}
deleteOne: this.deleteOneStub,
},
}
this.notifications = SandboxedModule.require(modulePath, {
requires: {
'settings-sharelatex': {},
'@overleaf/settings': {},
'./mongodb': { db: this.db, ObjectId },
'@overleaf/metrics': { timeAsyncMethod: sinon.stub() }
}
'@overleaf/metrics': { timeAsyncMethod: sinon.stub() },
},
})
this.stubbedNotification = {
user_id: ObjectId(user_id),
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key'
templateKey: 'template-key',
}
return (this.stubbedNotificationArray = [this.stubbedNotification])
})
@ -65,7 +65,7 @@ describe('Notifications Tests', function () {
notifications.should.equal(this.stubbedNotificationArray)
assert.deepEqual(this.findStub.args[0][0], {
user_id: ObjectId(user_id),
templateKey: { $exists: true }
templateKey: { $exists: true },
})
return done()
}
@ -79,17 +79,17 @@ describe('Notifications Tests', function () {
user_id: ObjectId(user_id),
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key'
templateKey: 'template-key',
}
this.expectedDocument = {
user_id: this.stubbedNotification.user_id,
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key'
templateKey: 'template-key',
}
this.expectedQuery = {
user_id: this.stubbedNotification.user_id,
key: 'notification-key'
key: 'notification-key',
}
this.updateOneStub.yields()
return this.countStub.yields(null, 0)
@ -99,7 +99,7 @@ describe('Notifications Tests', function () {
return this.notifications.addNotification(
user_id,
this.stubbedNotification,
(err) => {
err => {
expect(err).not.to.exist
sinon.assert.calledWith(
this.updateOneStub,
@ -121,7 +121,7 @@ describe('Notifications Tests', function () {
return this.notifications.addNotification(
user_id,
this.stubbedNotification,
(err) => {
err => {
expect(err).not.to.exist
sinon.assert.notCalled(this.updateOneStub)
return done()
@ -134,7 +134,7 @@ describe('Notifications Tests', function () {
return this.notifications.addNotification(
user_id,
this.stubbedNotification,
(err) => {
err => {
expect(err).not.to.exist
sinon.assert.calledWith(
this.updateOneStub,
@ -155,18 +155,18 @@ describe('Notifications Tests', function () {
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
expires: '2922-02-13T09:32:56.289Z'
expires: '2922-02-13T09:32:56.289Z',
}
this.expectedDocument = {
user_id: this.stubbedNotification.user_id,
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
expires: new Date(this.stubbedNotification.expires)
expires: new Date(this.stubbedNotification.expires),
}
return (this.expectedQuery = {
user_id: this.stubbedNotification.user_id,
key: 'notification-key'
key: 'notification-key',
})
})
@ -174,7 +174,7 @@ describe('Notifications Tests', function () {
return this.notifications.addNotification(
user_id,
this.stubbedNotification,
(err) => {
err => {
expect(err).not.to.exist
sinon.assert.calledWith(
this.updateOneStub,
@ -195,14 +195,14 @@ describe('Notifications Tests', function () {
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
expires: 'WAT'
expires: 'WAT',
}
return (this.expectedDocument = {
user_id: this.stubbedNotification.user_id,
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
expires: new Date(this.stubbedNotification.expires)
expires: new Date(this.stubbedNotification.expires),
})
})
@ -210,7 +210,7 @@ describe('Notifications Tests', function () {
return this.notifications.addNotification(
user_id,
this.stubbedNotification,
(err) => {
err => {
;(err instanceof Error).should.equal(true)
sinon.assert.notCalled(this.updateOneStub)
return done()
@ -227,13 +227,13 @@ describe('Notifications Tests', function () {
return this.notifications.removeNotificationId(
user_id,
notification_id,
(err) => {
err => {
const searchOps = {
user_id: ObjectId(user_id),
_id: ObjectId(notification_id)
_id: ObjectId(notification_id),
}
const updateOperation = {
$unset: { templateKey: true, messageOpts: true }
$unset: { templateKey: true, messageOpts: true },
}
assert.deepEqual(this.updateOneStub.args[0][0], searchOps)
assert.deepEqual(this.updateOneStub.args[0][1], updateOperation)
@ -250,13 +250,13 @@ describe('Notifications Tests', function () {
return this.notifications.removeNotificationKey(
user_id,
notification_key,
(err) => {
err => {
const searchOps = {
user_id: ObjectId(user_id),
key: notification_key
key: notification_key,
}
const updateOperation = {
$unset: { templateKey: true }
$unset: { templateKey: true },
}
assert.deepEqual(this.updateOneStub.args[0][0], searchOps)
assert.deepEqual(this.updateOneStub.args[0][1], updateOperation)
@ -272,7 +272,7 @@ describe('Notifications Tests', function () {
return this.notifications.removeNotificationByKeyOnly(
notification_key,
(err) => {
err => {
const searchOps = { key: notification_key }
const updateOperation = { $unset: { templateKey: true } }
assert.deepEqual(this.updateOneStub.args[0][0], searchOps)
@ -289,7 +289,7 @@ describe('Notifications Tests', function () {
return this.notifications.deleteNotificationByKeyOnly(
notification_key,
(err) => {
err => {
const searchOps = { key: notification_key }
assert.deepEqual(this.deleteOneStub.args[0][0], searchOps)
return done()