mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #29471 from overleaf/revert-29369-mfb-from-joi-to-zod-clsi-cache
Revert "migrate from joi to zod CLSI-CACHE service" GitOrigin-RevId: 1846e5a1d990f7ff22982fc32277e24d69e9d1e0
This commit is contained in:
committed by
Copybot
parent
1720314726
commit
a88c307962
@@ -1,17 +0,0 @@
|
|||||||
const { isZodErrorLike, fromError } = require('zod-validation-error')
|
|
||||||
/**
|
|
||||||
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
|
|
||||||
*/
|
|
||||||
|
|
||||||
const handleValidationError = [
|
|
||||||
/** @type {ErrorRequestHandler} */
|
|
||||||
(err, req, res, next) => {
|
|
||||||
if (!isZodErrorLike(err)) {
|
|
||||||
return next(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.status(400).json({ ...fromError(err), statusCode: 400 })
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
module.exports = { handleValidationError }
|
|
||||||
@@ -2,12 +2,10 @@ const { ParamsError } = require('./Errors')
|
|||||||
const { z } = require('zod')
|
const { z } = require('zod')
|
||||||
const { zz } = require('./zodHelpers')
|
const { zz } = require('./zodHelpers')
|
||||||
const { validateReq } = require('./validateReq')
|
const { validateReq } = require('./validateReq')
|
||||||
const { handleValidationError } = require('./handleValidationError')
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
z,
|
z,
|
||||||
zz,
|
zz,
|
||||||
validateReq,
|
validateReq,
|
||||||
handleValidationError,
|
|
||||||
ParamsError,
|
ParamsError,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@overleaf/o-error": "*",
|
"@overleaf/o-error": "*",
|
||||||
"mongodb": "^6.12.0",
|
"mongodb": "^6.12.0",
|
||||||
"zod": "^4.1.8",
|
"zod": "^4.1.8"
|
||||||
"zod-validation-error": "^4.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
|
|||||||
Generated
+2
-3
@@ -541,8 +541,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@overleaf/o-error": "*",
|
"@overleaf/o-error": "*",
|
||||||
"mongodb": "^6.12.0",
|
"mongodb": "^6.12.0",
|
||||||
"zod": "^4.1.8",
|
"zod": "^4.1.8"
|
||||||
"zod-validation-error": "^4.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
@@ -51425,9 +51424,9 @@
|
|||||||
"@overleaf/promise-utils": "*",
|
"@overleaf/promise-utils": "*",
|
||||||
"@overleaf/settings": "*",
|
"@overleaf/settings": "*",
|
||||||
"@overleaf/stream-utils": "*",
|
"@overleaf/stream-utils": "*",
|
||||||
"@overleaf/validation-tools": "*",
|
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
|
"celebrate": "^15.0.3",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"p-limit": "^3.1.0"
|
"p-limit": "^3.1.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import express from 'express'
|
|||||||
import Settings from '@overleaf/settings'
|
import Settings from '@overleaf/settings'
|
||||||
import logger from '@overleaf/logger'
|
import logger from '@overleaf/logger'
|
||||||
import metrics from '@overleaf/metrics'
|
import metrics from '@overleaf/metrics'
|
||||||
|
import Validation from './Validation.js'
|
||||||
import csp, { removeCSPHeaders } from './CSP.mjs'
|
import csp, { removeCSPHeaders } from './CSP.mjs'
|
||||||
import Router from '../router.mjs'
|
import Router from '../router.mjs'
|
||||||
import helmet from 'helmet'
|
import helmet from 'helmet'
|
||||||
@@ -37,7 +38,6 @@ import os from 'node:os'
|
|||||||
import http from 'node:http'
|
import http from 'node:http'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import serveStaticWrapper from './ServeStaticWrapper.mjs'
|
import serveStaticWrapper from './ServeStaticWrapper.mjs'
|
||||||
import { handleValidationError } from '@overleaf/validation-tools'
|
|
||||||
|
|
||||||
const { hasAdminAccess } = AdminAuthorizationHelper
|
const { hasAdminAccess } = AdminAuthorizationHelper
|
||||||
const sessionsRedisClient = UserSessionsRedis.client()
|
const sessionsRedisClient = UserSessionsRedis.client()
|
||||||
@@ -356,17 +356,17 @@ const server = http.createServer(app)
|
|||||||
if (Settings.enabledServices.includes('api')) {
|
if (Settings.enabledServices.includes('api')) {
|
||||||
logger.debug({}, 'providing api router')
|
logger.debug({}, 'providing api router')
|
||||||
app.use(privateApiRouter)
|
app.use(privateApiRouter)
|
||||||
app.use(handleValidationError)
|
app.use(Validation.errorMiddleware)
|
||||||
app.use(ErrorController.handleApiError)
|
app.use(ErrorController.handleApiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.enabledServices.includes('web')) {
|
if (Settings.enabledServices.includes('web')) {
|
||||||
logger.debug({}, 'providing web router')
|
logger.debug({}, 'providing web router')
|
||||||
app.use(publicApiRouter) // public API goes with web router for public access
|
app.use(publicApiRouter) // public API goes with web router for public access
|
||||||
app.use(handleValidationError)
|
app.use(Validation.errorMiddleware)
|
||||||
app.use(ErrorController.handleApiError)
|
app.use(ErrorController.handleApiError)
|
||||||
app.use(webRouter)
|
app.use(webRouter)
|
||||||
app.use(handleValidationError)
|
app.use(Validation.errorMiddleware)
|
||||||
app.use(ErrorController.handleError)
|
app.use(ErrorController.handleError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,22 @@ const {
|
|||||||
zz,
|
zz,
|
||||||
ParamsError,
|
ParamsError,
|
||||||
} = require('@overleaf/validation-tools')
|
} = require('@overleaf/validation-tools')
|
||||||
|
const { isZodErrorLike, fromError } = require('zod-validation-error')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
|
||||||
|
*/
|
||||||
|
|
||||||
|
const errorMiddleware = [
|
||||||
|
/** @type {ErrorRequestHandler} */
|
||||||
|
(err, req, res, next) => {
|
||||||
|
if (!isZodErrorLike(err)) {
|
||||||
|
return next(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(400).json({ ...fromError(err), statusCode: 400 })
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
const validateReqWeb = (req, schema) => {
|
const validateReqWeb = (req, schema) => {
|
||||||
try {
|
try {
|
||||||
@@ -21,6 +37,7 @@ const validateReqWeb = (req, schema) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
errorMiddleware,
|
||||||
validateReq: validateReqWeb,
|
validateReq: validateReqWeb,
|
||||||
z,
|
z,
|
||||||
zz,
|
zz,
|
||||||
|
|||||||
Reference in New Issue
Block a user