mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #29530 from overleaf/revert-29472-mfb-from-joi-to-zod-real-time
Revert "Mfb from joi to zod real time" GitOrigin-RevId: 3bb8b01c692083c1b15d8a53066c01f0ec7af8f6
This commit is contained in:
Generated
+2
-3
@@ -52882,7 +52882,6 @@
|
|||||||
"@overleaf/o-error": "*",
|
"@overleaf/o-error": "*",
|
||||||
"@overleaf/redis-wrapper": "*",
|
"@overleaf/redis-wrapper": "*",
|
||||||
"@overleaf/settings": "*",
|
"@overleaf/settings": "*",
|
||||||
"@overleaf/validation-tools": "*",
|
|
||||||
"async": "^3.2.5",
|
"async": "^3.2.5",
|
||||||
"base64id": "0.1.0",
|
"base64id": "0.1.0",
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
@@ -52891,12 +52890,12 @@
|
|||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-session": "^1.17.1",
|
"express-session": "^1.17.1",
|
||||||
|
"joi": "^17.12.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"proxy-addr": "^2.0.7",
|
"proxy-addr": "^2.0.7",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"socket.io": "github:overleaf/socket.io#0.9.19-overleaf-12",
|
"socket.io": "github:overleaf/socket.io#0.9.19-overleaf-12",
|
||||||
"socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5",
|
"socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5"
|
||||||
"zod-validation-error": "^4.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ libraries/metrics/**
|
|||||||
libraries/o-error/**
|
libraries/o-error/**
|
||||||
libraries/redis-wrapper/**
|
libraries/redis-wrapper/**
|
||||||
libraries/settings/**
|
libraries/settings/**
|
||||||
libraries/validation-tools/**
|
|
||||||
package-lock.json
|
package-lock.json
|
||||||
package.json
|
package.json
|
||||||
patches/**
|
patches/**
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ COPY libraries/metrics/package.json /overleaf/libraries/metrics/package.json
|
|||||||
COPY libraries/o-error/package.json /overleaf/libraries/o-error/package.json
|
COPY libraries/o-error/package.json /overleaf/libraries/o-error/package.json
|
||||||
COPY libraries/redis-wrapper/package.json /overleaf/libraries/redis-wrapper/package.json
|
COPY libraries/redis-wrapper/package.json /overleaf/libraries/redis-wrapper/package.json
|
||||||
COPY libraries/settings/package.json /overleaf/libraries/settings/package.json
|
COPY libraries/settings/package.json /overleaf/libraries/settings/package.json
|
||||||
COPY libraries/validation-tools/package.json /overleaf/libraries/validation-tools/package.json
|
|
||||||
COPY services/real-time/package.json /overleaf/services/real-time/package.json
|
COPY services/real-time/package.json /overleaf/services/real-time/package.json
|
||||||
COPY patches/ /overleaf/patches/
|
COPY patches/ /overleaf/patches/
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ COPY libraries/metrics/ /overleaf/libraries/metrics/
|
|||||||
COPY libraries/o-error/ /overleaf/libraries/o-error/
|
COPY libraries/o-error/ /overleaf/libraries/o-error/
|
||||||
COPY libraries/redis-wrapper/ /overleaf/libraries/redis-wrapper/
|
COPY libraries/redis-wrapper/ /overleaf/libraries/redis-wrapper/
|
||||||
COPY libraries/settings/ /overleaf/libraries/settings/
|
COPY libraries/settings/ /overleaf/libraries/settings/
|
||||||
COPY libraries/validation-tools/ /overleaf/libraries/validation-tools/
|
|
||||||
COPY services/real-time/ /overleaf/services/real-time/
|
COPY services/real-time/ /overleaf/services/real-time/
|
||||||
|
|
||||||
FROM app
|
FROM app
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ IMAGE_CACHE ?= $(IMAGE_REPO):cache-$(shell cat \
|
|||||||
$(MONOREPO)/libraries/o-error/package.json \
|
$(MONOREPO)/libraries/o-error/package.json \
|
||||||
$(MONOREPO)/libraries/redis-wrapper/package.json \
|
$(MONOREPO)/libraries/redis-wrapper/package.json \
|
||||||
$(MONOREPO)/libraries/settings/package.json \
|
$(MONOREPO)/libraries/settings/package.json \
|
||||||
$(MONOREPO)/libraries/validation-tools/package.json \
|
|
||||||
$(MONOREPO)/services/real-time/package.json \
|
$(MONOREPO)/services/real-time/package.json \
|
||||||
$(MONOREPO)/patches/* \
|
$(MONOREPO)/patches/* \
|
||||||
| sha256sum | cut -d '-' -f1)
|
| sha256sum | cut -d '-' -f1)
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ const WebsocketAddressManager = require('./WebsocketAddressManager')
|
|||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const base64id = require('base64id')
|
const base64id = require('base64id')
|
||||||
const { UnexpectedArgumentsError } = require('./Errors')
|
const { UnexpectedArgumentsError } = require('./Errors')
|
||||||
const { z, zz } = require('@overleaf/validation-tools')
|
const Joi = require('joi')
|
||||||
const { isZodErrorLike } = require('zod-validation-error')
|
|
||||||
|
|
||||||
const HOSTNAME = require('node:os').hostname()
|
const HOSTNAME = require('node:os').hostname()
|
||||||
const SERVER_PING_INTERVAL = 15000
|
const SERVER_PING_INTERVAL = 15000
|
||||||
const SERVER_PING_LATENCY_THRESHOLD = 5000
|
const SERVER_PING_LATENCY_THRESHOLD = 5000
|
||||||
|
|
||||||
|
const JOI_OBJECT_ID = Joi.string()
|
||||||
|
.required()
|
||||||
|
.regex(/^[0-9a-f]{24}$/)
|
||||||
|
.message('invalid id')
|
||||||
|
|
||||||
let Router
|
let Router
|
||||||
module.exports = Router = {
|
module.exports = Router = {
|
||||||
_handleError(callback, error, client, method, attrs) {
|
_handleError(callback, error, client, method, attrs) {
|
||||||
@@ -25,11 +29,11 @@ module.exports = Router = {
|
|||||||
attrs.client_id = client.id
|
attrs.client_id = client.id
|
||||||
attrs.err = error
|
attrs.err = error
|
||||||
attrs.method = method
|
attrs.method = method
|
||||||
if (isZodErrorLike(error)) {
|
if (Joi.isError(error)) {
|
||||||
logger.info(attrs, 'validation error')
|
logger.info(attrs, 'validation error')
|
||||||
let message = 'invalid'
|
let message = 'invalid'
|
||||||
try {
|
try {
|
||||||
message = error.issues[0].message
|
message = error.details[0].message
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// ignore unexpected errors
|
// ignore unexpected errors
|
||||||
logger.warn({ error, e }, 'unexpected validation error')
|
logger.warn({ error, e }, 'unexpected validation error')
|
||||||
@@ -189,7 +193,7 @@ module.exports = Router = {
|
|||||||
|
|
||||||
if (!isDebugging) {
|
if (!isDebugging) {
|
||||||
try {
|
try {
|
||||||
zz.objectId().parse(projectId)
|
Joi.assert(projectId, JOI_OBJECT_ID)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
metrics.inc('socket-io.connection', 1, {
|
metrics.inc('socket-io.connection', 1, {
|
||||||
status: client.transport,
|
status: client.transport,
|
||||||
@@ -405,11 +409,6 @@ module.exports = Router = {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const joinDocSchema = z.object({
|
|
||||||
doc_id: zz.objectId(),
|
|
||||||
fromVersion: z.number().int().optional(),
|
|
||||||
options: z.object(),
|
|
||||||
})
|
|
||||||
// Variadic. The possible arguments:
|
// Variadic. The possible arguments:
|
||||||
// doc_id, callback
|
// doc_id, callback
|
||||||
// doc_id, fromVersion, callback
|
// doc_id, fromVersion, callback
|
||||||
@@ -443,7 +442,14 @@ module.exports = Router = {
|
|||||||
return Router._handleInvalidArguments(client, 'joinDoc', arguments)
|
return Router._handleInvalidArguments(client, 'joinDoc', arguments)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
joinDocSchema.parse({ doc_id: docId, fromVersion, options })
|
Joi.assert(
|
||||||
|
{ doc_id: docId, fromVersion, options },
|
||||||
|
Joi.object({
|
||||||
|
doc_id: JOI_OBJECT_ID,
|
||||||
|
fromVersion: Joi.number().integer(),
|
||||||
|
options: Joi.object().required(),
|
||||||
|
})
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Router._handleError(callback, error, client, 'joinDoc', {
|
return Router._handleError(callback, error, client, 'joinDoc', {
|
||||||
disconnect: 1,
|
disconnect: 1,
|
||||||
@@ -472,7 +478,7 @@ module.exports = Router = {
|
|||||||
return Router._handleInvalidArguments(client, 'leaveDoc', arguments)
|
return Router._handleInvalidArguments(client, 'leaveDoc', arguments)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
zz.objectId().parse(docId)
|
Joi.assert(docId, JOI_OBJECT_ID)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Router._handleError(callback, error, client, 'joinDoc', {
|
return Router._handleError(callback, error, client, 'joinDoc', {
|
||||||
disconnect: 1,
|
disconnect: 1,
|
||||||
@@ -548,10 +554,6 @@ module.exports = Router = {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const applyOtUpdateSchema = z.object({
|
|
||||||
doc_id: zz.objectId(),
|
|
||||||
update: z.object(),
|
|
||||||
})
|
|
||||||
client.on('applyOtUpdate', function (docId, update, callback) {
|
client.on('applyOtUpdate', function (docId, update, callback) {
|
||||||
if (typeof callback !== 'function') {
|
if (typeof callback !== 'function') {
|
||||||
return Router._handleInvalidArguments(
|
return Router._handleInvalidArguments(
|
||||||
@@ -561,7 +563,13 @@ module.exports = Router = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
applyOtUpdateSchema.parse({ doc_id: docId, update })
|
Joi.assert(
|
||||||
|
{ doc_id: docId, update },
|
||||||
|
Joi.object({
|
||||||
|
doc_id: JOI_OBJECT_ID,
|
||||||
|
update: Joi.object().required(),
|
||||||
|
})
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Router._handleError(callback, error, client, 'applyOtUpdate', {
|
return Router._handleError(callback, error, client, 'applyOtUpdate', {
|
||||||
disconnect: 1,
|
disconnect: 1,
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
"@overleaf/o-error": "*",
|
"@overleaf/o-error": "*",
|
||||||
"@overleaf/redis-wrapper": "*",
|
"@overleaf/redis-wrapper": "*",
|
||||||
"@overleaf/settings": "*",
|
"@overleaf/settings": "*",
|
||||||
"@overleaf/validation-tools": "*",
|
|
||||||
"async": "^3.2.5",
|
"async": "^3.2.5",
|
||||||
"base64id": "0.1.0",
|
"base64id": "0.1.0",
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
@@ -31,12 +30,12 @@
|
|||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-session": "^1.17.1",
|
"express-session": "^1.17.1",
|
||||||
|
"joi": "^17.12.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"proxy-addr": "^2.0.7",
|
"proxy-addr": "^2.0.7",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"socket.io": "github:overleaf/socket.io#0.9.19-overleaf-12",
|
"socket.io": "github:overleaf/socket.io#0.9.19-overleaf-12",
|
||||||
"socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5",
|
"socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5"
|
||||||
"zod-validation-error": "^4.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ describe('joinDoc', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should return an invalid id error', function () {
|
it('should return an invalid id error', function () {
|
||||||
this.error.message.should.equal('invalid Mongo ObjectId')
|
this.error.message.should.equal('invalid id')
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should not have joined the doc room', function (done) {
|
return it('should not have joined the doc room', function (done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user