@strapi/core 0.0.0-next.281b331dc777a6a76694c122f7d1d9bc8c783747 → 0.0.0-next.29273b8e8a9a5aa635e5680190eda01f861431aa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +4 -4
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +4 -4
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/config-loader.mjs.map +1 -1
- package/dist/configuration/urls.js.map +1 -1
- package/dist/configuration/urls.mjs.map +1 -1
- package/dist/container.js.map +1 -1
- package/dist/container.mjs.map +1 -1
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/core-api/routes/validation/utils.mjs.map +1 -1
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.js +1 -2
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +1 -2
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs.map +1 -1
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/components.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/loaders/src-index.js.map +1 -1
- package/dist/loaders/src-index.mjs.map +1 -1
- package/dist/middlewares/logger.js.map +1 -1
- package/dist/middlewares/logger.mjs.map +1 -1
- package/dist/middlewares/response-time.js.map +1 -1
- package/dist/middlewares/response-time.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +2 -15
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +2 -15
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/first-published-at.js.map +1 -1
- package/dist/migrations/first-published-at.mjs.map +1 -1
- package/dist/package.json.js +14 -14
- package/dist/package.json.mjs +14 -14
- package/dist/providers/index.js +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +1 -1
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/{sessionManager.d.ts → session-manager.d.ts} +1 -1
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/{sessionManager.js → session-manager.js} +6 -4
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/{sessionManager.mjs → session-manager.mjs} +6 -4
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/apis.mjs.map +1 -1
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/custom-fields.mjs.map +1 -1
- package/dist/registries/namespace.js.map +1 -1
- package/dist/registries/namespace.mjs.map +1 -1
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/plugins.mjs.map +1 -1
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/services/config.js.map +1 -1
- package/dist/services/config.mjs.map +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/content-api/permissions/index.mjs.map +1 -1
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/repository.js +1 -1
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +1 -1
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/fields.js.map +1 -1
- package/dist/services/document-service/transform/fields.mjs.map +1 -1
- package/dist/services/document-service/transform/id-map.js.map +1 -1
- package/dist/services/document-service/transform/id-map.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.js +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.mjs +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -1
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -1
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -1
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/index.mjs.map +1 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/middleware.mjs.map +1 -1
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +8 -1
- package/dist/services/session-manager.d.ts.map +1 -1
- package/dist/services/session-manager.js +74 -21
- package/dist/services/session-manager.js.map +1 -1
- package/dist/services/session-manager.mjs +74 -21
- package/dist/services/session-manager.mjs.map +1 -1
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs.map +1 -1
- package/dist/services/worker-queue.js.map +1 -1
- package/dist/services/worker-queue.mjs.map +1 -1
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-config-file.mjs.map +1 -1
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/package.json +14 -14
- package/dist/providers/sessionManager.d.ts.map +0 -1
- package/dist/providers/sessionManager.js.map +0 -1
- package/dist/providers/sessionManager.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/services/server/index.ts"],"sourcesContent":["import Router from '@koa/router';\nimport type { Core, Modules } from '@strapi/types';\n\nimport { createHTTPServer } from './http-server';\nimport { createRouteManager } from './routing';\nimport { createAdminAPI } from './admin-api';\nimport { createContentAPI } from './content-api';\nimport registerAllRoutes from './register-routes';\nimport registerApplicationMiddlewares from './register-middlewares';\nimport createKoaApp from './koa';\nimport requestCtx from '../request-context';\n\nconst healthCheck: Core.MiddlewareHandler = async (ctx) => {\n ctx.set('strapi', 'You are so French!');\n ctx.status = 204;\n};\n\nconst createServer = (strapi: Core.Strapi): Modules.Server.Server => {\n const app = createKoaApp({\n proxy: strapi.config.get('server.proxy.koa'),\n keys: strapi.config.get('server.app.keys'),\n });\n\n app.use((ctx, next) => requestCtx.run(ctx, () => next()));\n\n const router = new Router();\n\n const routeManager = createRouteManager(strapi);\n\n const httpServer = createHTTPServer(strapi, app);\n\n const apis = {\n 'content-api': createContentAPI(strapi),\n admin: createAdminAPI(strapi),\n };\n\n // init health check\n router.all('/_health', healthCheck);\n\n const state = {\n mounted: false,\n };\n\n return {\n app,\n router,\n httpServer,\n\n api(name) {\n return apis[name];\n },\n\n use(...args) {\n app.use(...args);\n return this;\n },\n\n routes(routes: Core.Router | Omit<Core.Route, 'info'>[]) {\n if (!Array.isArray(routes) && routes.type) {\n const api = apis[routes.type];\n if (!api) {\n throw new Error(`API ${routes.type} not found. Possible APIs are ${Object.keys(apis)}`);\n }\n\n apis[routes.type].routes(routes);\n return this;\n }\n\n routeManager.addRoutes(routes, router);\n return this;\n },\n\n mount() {\n state.mounted = true;\n\n Object.values(apis).forEach((api) => api.mount(router));\n app.use(router.routes()).use(router.allowedMethods());\n\n return this;\n },\n\n initRouting() {\n registerAllRoutes(strapi);\n\n return this;\n },\n\n async initMiddlewares() {\n await registerApplicationMiddlewares(strapi);\n\n return this;\n },\n\n listRoutes() {\n return [...router.stack];\n },\n\n listen(...args: any[]) {\n if (!state.mounted) {\n this.mount();\n }\n\n return httpServer.listen(...args);\n },\n\n async destroy() {\n await httpServer.destroy();\n },\n };\n};\n\nexport { createServer };\n"],"names":["healthCheck","ctx","set","status","createServer","strapi","app","createKoaApp","proxy","config","get","keys","use","next","requestCtx","run","router","Router","routeManager","createRouteManager","httpServer","createHTTPServer","apis","createContentAPI","admin","createAdminAPI","all","state","mounted","api","name","args","routes","Array","isArray","type","Error","Object","addRoutes","mount","values","forEach","allowedMethods","initRouting","registerAllRoutes","initMiddlewares","registerApplicationMiddlewares","listRout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A,CAAAA,CAAI,GAAGmB,IAAI,EAAA;AACTzB,YAAAA,GAAAA,CAAIM,GAAG,CAAImB,GAAAA,IAAAA,CAAAA;AACX,YAAA,OAAO,IAAI;AACb,SAAA;AAEAC,QAAAA,MAAAA,CAAAA,CAAOA,MAAgD,EAAA;AACrD,YAAA,IAAI,CAACC,KAAMC,CAAAA,OAAO,CAACF,MAAWA,CAAAA,IAAAA,MAAAA,CAAOG,IAAI,EAAE;AACzC,gBAAA,MAAMN,GAAMP,GAAAA,IAAI,CAACU,MAAAA,CAAOG,IAAI,CAAC;AAC7B,gBAAA,IAAI,CAACN,GAAK,EAAA;AACR,oBAAA,MAAM,IAAIO,KAAAA,CAAM,CAAC,IAAI,EAAEJ,
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/services/server/index.ts"],"sourcesContent":["import Router from '@koa/router';\nimport type { Core, Modules } from '@strapi/types';\n\nimport { createHTTPServer } from './http-server';\nimport { createRouteManager } from './routing';\nimport { createAdminAPI } from './admin-api';\nimport { createContentAPI } from './content-api';\nimport registerAllRoutes from './register-routes';\nimport registerApplicationMiddlewares from './register-middlewares';\nimport createKoaApp from './koa';\nimport requestCtx from '../request-context';\n\nconst healthCheck: Core.MiddlewareHandler = async (ctx) => {\n ctx.set('strapi', 'You are so French!');\n ctx.status = 204;\n};\n\nconst createServer = (strapi: Core.Strapi): Modules.Server.Server => {\n const app = createKoaApp({\n proxy: strapi.config.get('server.proxy.koa'),\n keys: strapi.config.get('server.app.keys'),\n });\n\n app.use((ctx, next) => requestCtx.run(ctx, () => next()));\n\n const router = new Router();\n\n const routeManager = createRouteManager(strapi);\n\n const httpServer = createHTTPServer(strapi, app);\n\n const apis = {\n 'content-api': createContentAPI(strapi),\n admin: createAdminAPI(strapi),\n };\n\n // init health check\n router.all('/_health', healthCheck);\n\n const state = {\n mounted: false,\n };\n\n return {\n app,\n router,\n httpServer,\n\n api(name) {\n return apis[name];\n },\n\n use(...args) {\n app.use(...args);\n return this;\n },\n\n routes(routes: Core.Router | Omit<Core.Route, 'info'>[]) {\n if (!Array.isArray(routes) && routes.type) {\n const api = apis[routes.type];\n if (!api) {\n throw new Error(`API ${routes.type} not found. Possible APIs are ${Object.keys(apis)}`);\n }\n\n apis[routes.type].routes(routes);\n return this;\n }\n\n routeManager.addRoutes(routes, router);\n return this;\n },\n\n mount() {\n state.mounted = true;\n\n Object.values(apis).forEach((api) => api.mount(router));\n app.use(router.routes()).use(router.allowedMethods());\n\n return this;\n },\n\n initRouting() {\n registerAllRoutes(strapi);\n\n return this;\n },\n\n async initMiddlewares() {\n await registerApplicationMiddlewares(strapi);\n\n return this;\n },\n\n listRoutes() {\n return [...router.stack];\n },\n\n listen(...args: any[]) {\n if (!state.mounted) {\n this.mount();\n }\n\n return httpServer.listen(...args);\n },\n\n async destroy() {\n await httpServer.destroy();\n },\n };\n};\n\nexport { createServer };\n"],"names":["healthCheck","ctx","set","status","createServer","strapi","app","createKoaApp","proxy","config","get","keys","use","next","requestCtx","run","router","Router","routeManager","createRouteManager","httpServer","createHTTPServer","apis","createContentAPI","admin","createAdminAPI","all","state","mounted","api","name","args","routes","Array","isArray","type","Error","Object","addRoutes","mount","values","forEach","allowedMethods","initRouting","registerAllRoutes","initMiddlewares","registerApplicationMiddlewares","listRoutes","stack","listen","destroy"],"mappings":";;;;;;;;;;AAYA,MAAMA,cAAsC,OAAOC,GAAAA,GAAAA;IACjDA,GAAIC,CAAAA,GAAG,CAAC,QAAU,EAAA,oBAAA,CAAA;AAClBD,IAAAA,GAAAA,CAAIE,MAAM,GAAG,GAAA;AACf,CAAA;AAEA,MAAMC,eAAe,CAACC,MAAAA,GAAAA;AACpB,IAAA,MAAMC,MAAMC,YAAa,CAAA;AACvBC,QAAAA,KAAAA,EAAOH,MAAOI,CAAAA,MAAM,CAACC,GAAG,CAAC,kBAAA,CAAA;AACzBC,QAAAA,IAAAA,EAAMN,MAAOI,CAAAA,MAAM,CAACC,GAAG,CAAC,iBAAA;AAC1B,KAAA,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lB,GAAAA,IAAAA,CAAAA;AAC9B,SAAA;QAEA,MAAMmB,OAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAM9B,WAAW8B,OAAO,EAAA;AAC1B;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sources":["../../../src/services/server/middleware.ts"],"sourcesContent":["import path from 'path';\nimport { isArray } from 'lodash/fp';\nimport { importDefault } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst instantiateMiddleware = (\n middlewareFactory: Core.MiddlewareFactory,\n name: string,\n config: unknown,\n strapi: Core.Strapi\n) => {\n try {\n return middlewareFactory(config, { strapi });\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Middleware \"${name}\": ${e.message}`);\n }\n }\n};\n\nconst resolveRouteMiddlewares = (route: Core.Route, strapi: Core.Strapi) => {\n const middlewaresConfig = route?.config?.middlewares ?? [];\n\n if (!isArray(middlewaresConfig)) {\n throw new Error('Route middlewares config must be an array');\n }\n\n const middlewares = resolveMiddlewares(middlewaresConfig, strapi);\n\n return middlewares.map(({ handler }) => handler);\n};\n\nconst dummyMiddleware: Core.MiddlewareHandler = (_, next) => next();\n\n/**\n * Initialize every configured middlewares\n */\nconst resolveMiddlewares = (\n config: Array<Core.MiddlewareName | Core.MiddlewareConfig | Core.MiddlewareHandler>,\n strapi: Core.Strapi\n) => {\n const middlewares: {\n name: string | null;\n handler: Core.MiddlewareHandler;\n }[] = [];\n\n for (const item of config) {\n if (typeof item === 'function') {\n middlewares.push({\n name: null,\n handler: item,\n });\n\n continue;\n }\n\n if (typeof item === 'string') {\n const middlewareFactory = strapi.middleware(item);\n\n if (!middlewareFactory) {\n throw new Error(`Middleware ${item} not found.`);\n }\n\n middlewares.push({\n name: item,\n handler: instantiateMiddleware(middlewareFactory, item, {}, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (typeof item === 'object' && item !== null) {\n const { name, resolve, config = {} } = item;\n\n if (name) {\n const middlewareFactory = strapi.middleware(name);\n middlewares.push({\n name,\n handler:\n instantiateMiddleware(middlewareFactory, name, config, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (resolve) {\n const resolvedMiddlewareFactory = resolveCustomMiddleware(resolve, strapi);\n middlewares.push({\n name: resolve,\n handler:\n instantiateMiddleware(resolvedMiddlewareFactory, resolve, config, strapi) ??\n dummyMiddleware,\n });\n\n continue;\n }\n\n throw new Error('Invalid middleware configuration. Missing name or resolve properties.');\n }\n\n throw new Error(\n 'Middleware config must either be a string or an object {name?: string, resolve?: string, config: any}.'\n );\n }\n\n return middlewares;\n};\n\n/**\n * Resolve middleware from package name or path\n */\nconst resolveCustomMiddleware = (resolve: string, strapi: Core.Strapi) => {\n let modulePath;\n\n try {\n modulePath = require.resolve(resolve);\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {\n modulePath = path.resolve(strapi.dirs.dist.root, resolve);\n } else {\n throw error;\n }\n }\n\n try {\n return importDefault(modulePath);\n } catch (err) {\n throw new Error(`Could not load middleware \"${modulePath}\".`);\n }\n};\n\nexport { resolveRouteMiddlewares, resolveMiddlewares };\n"],"names":["instantiateMiddleware","middlewareFactory","name","config","strapi","e","Error","message","resolveRouteMiddlewares","route","middlewaresConfig","middlewares","isArray","resolveMiddlewares","map","handler","dummyMiddleware","_","next","item","push","middleware","resolve","resolvedMiddlewareFactory","resolveCustomMiddleware","modulePath","require","error","code","path","dirs","dist","root","importDefault","err"],"mappings":";;;;;;AAKA,MAAMA,qBAAwB,GAAA,CAC5BC,iBACAC,EAAAA,IAAAA,EACAC,MACAC,EAAAA,MAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,OAAOH,kBAAkBE,MAAQ,EAAA;AAAEC,YAAAA;AAAO,SAAA,CAAA;AAC5C,KAAA,CAAE,OAAOC,CAAG,EAAA;AACV,QAAA,IAAIA,aAAaC,KAAO,EAAA;YACtB,MAAM,IAAIA,KAAM,CAAA,CAAC,YAAY,EAAEJ,
|
|
1
|
+
{"version":3,"file":"middleware.js","sources":["../../../src/services/server/middleware.ts"],"sourcesContent":["import path from 'path';\nimport { isArray } from 'lodash/fp';\nimport { importDefault } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst instantiateMiddleware = (\n middlewareFactory: Core.MiddlewareFactory,\n name: string,\n config: unknown,\n strapi: Core.Strapi\n) => {\n try {\n return middlewareFactory(config, { strapi });\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Middleware \"${name}\": ${e.message}`);\n }\n }\n};\n\nconst resolveRouteMiddlewares = (route: Core.Route, strapi: Core.Strapi) => {\n const middlewaresConfig = route?.config?.middlewares ?? [];\n\n if (!isArray(middlewaresConfig)) {\n throw new Error('Route middlewares config must be an array');\n }\n\n const middlewares = resolveMiddlewares(middlewaresConfig, strapi);\n\n return middlewares.map(({ handler }) => handler);\n};\n\nconst dummyMiddleware: Core.MiddlewareHandler = (_, next) => next();\n\n/**\n * Initialize every configured middlewares\n */\nconst resolveMiddlewares = (\n config: Array<Core.MiddlewareName | Core.MiddlewareConfig | Core.MiddlewareHandler>,\n strapi: Core.Strapi\n) => {\n const middlewares: {\n name: string | null;\n handler: Core.MiddlewareHandler;\n }[] = [];\n\n for (const item of config) {\n if (typeof item === 'function') {\n middlewares.push({\n name: null,\n handler: item,\n });\n\n continue;\n }\n\n if (typeof item === 'string') {\n const middlewareFactory = strapi.middleware(item);\n\n if (!middlewareFactory) {\n throw new Error(`Middleware ${item} not found.`);\n }\n\n middlewares.push({\n name: item,\n handler: instantiateMiddleware(middlewareFactory, item, {}, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (typeof item === 'object' && item !== null) {\n const { name, resolve, config = {} } = item;\n\n if (name) {\n const middlewareFactory = strapi.middleware(name);\n middlewares.push({\n name,\n handler:\n instantiateMiddleware(middlewareFactory, name, config, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (resolve) {\n const resolvedMiddlewareFactory = resolveCustomMiddleware(resolve, strapi);\n middlewares.push({\n name: resolve,\n handler:\n instantiateMiddleware(resolvedMiddlewareFactory, resolve, config, strapi) ??\n dummyMiddleware,\n });\n\n continue;\n }\n\n throw new Error('Invalid middleware configuration. Missing name or resolve properties.');\n }\n\n throw new Error(\n 'Middleware config must either be a string or an object {name?: string, resolve?: string, config: any}.'\n );\n }\n\n return middlewares;\n};\n\n/**\n * Resolve middleware from package name or path\n */\nconst resolveCustomMiddleware = (resolve: string, strapi: Core.Strapi) => {\n let modulePath;\n\n try {\n modulePath = require.resolve(resolve);\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {\n modulePath = path.resolve(strapi.dirs.dist.root, resolve);\n } else {\n throw error;\n }\n }\n\n try {\n return importDefault(modulePath);\n } catch (err) {\n throw new Error(`Could not load middleware \"${modulePath}\".`);\n }\n};\n\nexport { resolveRouteMiddlewares, resolveMiddlewares };\n"],"names":["instantiateMiddleware","middlewareFactory","name","config","strapi","e","Error","message","resolveRouteMiddlewares","route","middlewaresConfig","middlewares","isArray","resolveMiddlewares","map","handler","dummyMiddleware","_","next","item","push","middleware","resolve","resolvedMiddlewareFactory","resolveCustomMiddleware","modulePath","require","error","code","path","dirs","dist","root","importDefault","err"],"mappings":";;;;;;AAKA,MAAMA,qBAAwB,GAAA,CAC5BC,iBACAC,EAAAA,IAAAA,EACAC,MACAC,EAAAA,MAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,OAAOH,kBAAkBE,MAAQ,EAAA;AAAEC,YAAAA;AAAO,SAAA,CAAA;AAC5C,KAAA,CAAE,OAAOC,CAAG,EAAA;AACV,QAAA,IAAIA,aAAaC,KAAO,EAAA;YACtB,MAAM,IAAIA,KAAM,CAAA,CAAC,YAAY,EAAEJ,KAAK,GAAG,EAAEG,CAAEE,CAAAA,OAAO,CAAE,CAAA,CAAA;AACtD;AACF;AACF,CAAA;AAEMC,MAAAA,uBAAAA,GAA0B,CAACC,KAAmBL,E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EAAA;YAClFH,UAAaI,GAAAA,IAAAA,CAAKP,OAAO,CAAClB,MAAAA,CAAO0B,IAAI,CAACC,IAAI,CAACC,IAAI,EAAEV,OAAAA,CAAAA;SAC5C,MAAA;YACL,MAAMK,KAAAA;AACR;AACF;IAEA,IAAI;AACF,QAAA,OAAOM,yBAAcR,CAAAA,UAAAA,CAAAA;AACvB,KAAA,CAAE,OAAOS,GAAK,EAAA;AACZ,QAAA,MAAM,IAAI5B,KAAM,CAAA,CAAC,2BAA2B,EAAEmB,UAAAA,CAAW,EAAE,CAAC,CAAA;AAC9D;AACF,CAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","sources":["../../../src/services/server/middleware.ts"],"sourcesContent":["import path from 'path';\nimport { isArray } from 'lodash/fp';\nimport { importDefault } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst instantiateMiddleware = (\n middlewareFactory: Core.MiddlewareFactory,\n name: string,\n config: unknown,\n strapi: Core.Strapi\n) => {\n try {\n return middlewareFactory(config, { strapi });\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Middleware \"${name}\": ${e.message}`);\n }\n }\n};\n\nconst resolveRouteMiddlewares = (route: Core.Route, strapi: Core.Strapi) => {\n const middlewaresConfig = route?.config?.middlewares ?? [];\n\n if (!isArray(middlewaresConfig)) {\n throw new Error('Route middlewares config must be an array');\n }\n\n const middlewares = resolveMiddlewares(middlewaresConfig, strapi);\n\n return middlewares.map(({ handler }) => handler);\n};\n\nconst dummyMiddleware: Core.MiddlewareHandler = (_, next) => next();\n\n/**\n * Initialize every configured middlewares\n */\nconst resolveMiddlewares = (\n config: Array<Core.MiddlewareName | Core.MiddlewareConfig | Core.MiddlewareHandler>,\n strapi: Core.Strapi\n) => {\n const middlewares: {\n name: string | null;\n handler: Core.MiddlewareHandler;\n }[] = [];\n\n for (const item of config) {\n if (typeof item === 'function') {\n middlewares.push({\n name: null,\n handler: item,\n });\n\n continue;\n }\n\n if (typeof item === 'string') {\n const middlewareFactory = strapi.middleware(item);\n\n if (!middlewareFactory) {\n throw new Error(`Middleware ${item} not found.`);\n }\n\n middlewares.push({\n name: item,\n handler: instantiateMiddleware(middlewareFactory, item, {}, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (typeof item === 'object' && item !== null) {\n const { name, resolve, config = {} } = item;\n\n if (name) {\n const middlewareFactory = strapi.middleware(name);\n middlewares.push({\n name,\n handler:\n instantiateMiddleware(middlewareFactory, name, config, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (resolve) {\n const resolvedMiddlewareFactory = resolveCustomMiddleware(resolve, strapi);\n middlewares.push({\n name: resolve,\n handler:\n instantiateMiddleware(resolvedMiddlewareFactory, resolve, config, strapi) ??\n dummyMiddleware,\n });\n\n continue;\n }\n\n throw new Error('Invalid middleware configuration. Missing name or resolve properties.');\n }\n\n throw new Error(\n 'Middleware config must either be a string or an object {name?: string, resolve?: string, config: any}.'\n );\n }\n\n return middlewares;\n};\n\n/**\n * Resolve middleware from package name or path\n */\nconst resolveCustomMiddleware = (resolve: string, strapi: Core.Strapi) => {\n let modulePath;\n\n try {\n modulePath = require.resolve(resolve);\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {\n modulePath = path.resolve(strapi.dirs.dist.root, resolve);\n } else {\n throw error;\n }\n }\n\n try {\n return importDefault(modulePath);\n } catch (err) {\n throw new Error(`Could not load middleware \"${modulePath}\".`);\n }\n};\n\nexport { resolveRouteMiddlewares, resolveMiddlewares };\n"],"names":["instantiateMiddleware","middlewareFactory","name","config","strapi","e","Error","message","resolveRouteMiddlewares","route","middlewaresConfig","middlewares","isArray","resolveMiddlewares","map","handler","dummyMiddleware","_","next","item","push","middleware","resolve","resolvedMiddlewareFactory","resolveCustomMiddleware","modulePath","require","error","code","path","dirs","dist","root","importDefault","err"],"mappings":";;;;AAKA,MAAMA,qBAAwB,GAAA,CAC5BC,iBACAC,EAAAA,IAAAA,EACAC,MACAC,EAAAA,MAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,OAAOH,kBAAkBE,MAAQ,EAAA;AAAEC,YAAAA;AAAO,SAAA,CAAA;AAC5C,KAAA,CAAE,OAAOC,CAAG,EAAA;AACV,QAAA,IAAIA,aAAaC,KAAO,EAAA;YACtB,MAAM,IAAIA,KAAM,CAAA,CAAC,YAAY,EAAEJ,
|
|
1
|
+
{"version":3,"file":"middleware.mjs","sources":["../../../src/services/server/middleware.ts"],"sourcesContent":["import path from 'path';\nimport { isArray } from 'lodash/fp';\nimport { importDefault } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst instantiateMiddleware = (\n middlewareFactory: Core.MiddlewareFactory,\n name: string,\n config: unknown,\n strapi: Core.Strapi\n) => {\n try {\n return middlewareFactory(config, { strapi });\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Middleware \"${name}\": ${e.message}`);\n }\n }\n};\n\nconst resolveRouteMiddlewares = (route: Core.Route, strapi: Core.Strapi) => {\n const middlewaresConfig = route?.config?.middlewares ?? [];\n\n if (!isArray(middlewaresConfig)) {\n throw new Error('Route middlewares config must be an array');\n }\n\n const middlewares = resolveMiddlewares(middlewaresConfig, strapi);\n\n return middlewares.map(({ handler }) => handler);\n};\n\nconst dummyMiddleware: Core.MiddlewareHandler = (_, next) => next();\n\n/**\n * Initialize every configured middlewares\n */\nconst resolveMiddlewares = (\n config: Array<Core.MiddlewareName | Core.MiddlewareConfig | Core.MiddlewareHandler>,\n strapi: Core.Strapi\n) => {\n const middlewares: {\n name: string | null;\n handler: Core.MiddlewareHandler;\n }[] = [];\n\n for (const item of config) {\n if (typeof item === 'function') {\n middlewares.push({\n name: null,\n handler: item,\n });\n\n continue;\n }\n\n if (typeof item === 'string') {\n const middlewareFactory = strapi.middleware(item);\n\n if (!middlewareFactory) {\n throw new Error(`Middleware ${item} not found.`);\n }\n\n middlewares.push({\n name: item,\n handler: instantiateMiddleware(middlewareFactory, item, {}, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (typeof item === 'object' && item !== null) {\n const { name, resolve, config = {} } = item;\n\n if (name) {\n const middlewareFactory = strapi.middleware(name);\n middlewares.push({\n name,\n handler:\n instantiateMiddleware(middlewareFactory, name, config, strapi) ?? dummyMiddleware,\n });\n\n continue;\n }\n\n if (resolve) {\n const resolvedMiddlewareFactory = resolveCustomMiddleware(resolve, strapi);\n middlewares.push({\n name: resolve,\n handler:\n instantiateMiddleware(resolvedMiddlewareFactory, resolve, config, strapi) ??\n dummyMiddleware,\n });\n\n continue;\n }\n\n throw new Error('Invalid middleware configuration. Missing name or resolve properties.');\n }\n\n throw new Error(\n 'Middleware config must either be a string or an object {name?: string, resolve?: string, config: any}.'\n );\n }\n\n return middlewares;\n};\n\n/**\n * Resolve middleware from package name or path\n */\nconst resolveCustomMiddleware = (resolve: string, strapi: Core.Strapi) => {\n let modulePath;\n\n try {\n modulePath = require.resolve(resolve);\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {\n modulePath = path.resolve(strapi.dirs.dist.root, resolve);\n } else {\n throw error;\n }\n }\n\n try {\n return importDefault(modulePath);\n } catch (err) {\n throw new Error(`Could not load middleware \"${modulePath}\".`);\n }\n};\n\nexport { resolveRouteMiddlewares, resolveMiddlewares };\n"],"names":["instantiateMiddleware","middlewareFactory","name","config","strapi","e","Error","message","resolveRouteMiddlewares","route","middlewaresConfig","middlewares","isArray","resolveMiddlewares","map","handler","dummyMiddleware","_","next","item","push","middleware","resolve","resolvedMiddlewareFactory","resolveCustomMiddleware","modulePath","require","error","code","path","dirs","dist","root","importDefault","err"],"mappings":";;;;AAKA,MAAMA,qBAAwB,GAAA,CAC5BC,iBACAC,EAAAA,IAAAA,EACAC,MACAC,EAAAA,MAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,OAAOH,kBAAkBE,MAAQ,EAAA;AAAEC,YAAAA;AAAO,SAAA,CAAA;AAC5C,KAAA,CAA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AA;IAChD,IAAIqB,UAAAA;IAEJ,IAAI;QACFA,UAAaC,GAAAA,OAAAA,CAAQJ,OAAO,CAACA,OAAAA,CAAAA;AAC/B,KAAA,CAAE,OAAOK,KAAO,EAAA;AACd,QAAA,IAAIA,iBAAiBrB,KAAS,IAAA,MAAA,IAAUqB,SAASA,KAAMC,CAAAA,IAAI,KAAK,kBAAoB,EAAA;YAClFH,UAAaI,GAAAA,IAAAA,CAAKP,OAAO,CAAClB,MAAAA,CAAO0B,IAAI,CAACC,IAAI,CAACC,IAAI,EAAEV,OAAAA,CAAAA;SAC5C,MAAA;YACL,MAAMK,KAAAA;AACR;AACF;IAEA,IAAI;AACF,QAAA,OAAOM,aAAcR,CAAAA,UAAAA,CAAAA;AACvB,KAAA,CAAE,OAAOS,GAAK,EAAA;AACZ,QAAA,MAAM,IAAI5B,KAAM,CAAA,CAAC,2BAA2B,EAAEmB,UAAAA,CAAW,EAAE,CAAC,CAAA;AAC9D;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n // Instantiate function-like routers\n // Mutate admin.routes in-place and make sure router factories are instantiated correctly\n strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);\n\n _.forEach(strapi.admin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n // Instantiate function-like routers\n // Mutate plugin.routes in-place and make sure router factories are instantiated correctly\n plugin.routes = instantiateRouterInputs(plugin.routes, strapi);\n\n _.forEach(plugin.routes, (router) => {\n router.type = router.type ?? 'admin';\n router.prefix = router.prefix ?? `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n // Mutate api.routes in-place and make sure router factories are instantiated correctly\n api.routes = instantiateRouterInputs(api.routes, strapi);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n\nconst instantiateRouterInputs = (\n routers: Record<string, Core.RouterConfig>,\n strapi: Core.Strapi\n): Record<string, Core.Router> => {\n const entries = Object.entries(routers);\n\n return entries.reduce((record, [key, inputOrCallback]) => {\n const isCallback = typeof inputOrCallback === 'function';\n\n return { ...record, [key]: isCallback ? inputOrCallback({ strapi }) : inputOrCallback };\n }, {});\n};\n"],"names":["createRouteScopeGenerator","namespace","route","prefix","endsWith","handler","_","defaultsDeep","config","auth","scope","startsWith","strapi","registerAdminRoutes","registerAPIRoutes","registerPluginRoutes","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":";;;;AAGA,MAAMA,yBAAAA,GAA4B,CAACC,SAAAA,GAAsB,CAACC,KAAAA,GAAAA;QACxD,MAAMC,MAAAA,GAASF,
|
|
1
|
+
{"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n // Instantiate function-like routers\n // Mutate admin.routes in-place and make sure router factories are instantiated correctly\n strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);\n\n _.forEach(strapi.admin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n // Instantiate function-like routers\n // Mutate plugin.routes in-place and make sure router factories are instantiated correctly\n plugin.routes = instantiateRouterInputs(plugin.routes, strapi);\n\n _.forEach(plugin.routes, (router) => {\n router.type = router.type ?? 'admin';\n router.prefix = router.prefix ?? `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n // Mutate api.routes in-place and make sure router factories are instantiated correctly\n api.routes = instantiateRouterInputs(api.routes, strapi);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n\nconst instantiateRouterInputs = (\n routers: Record<string, Core.RouterConfig>,\n strapi: Core.Strapi\n): Record<string, Core.Router> => {\n const entries = Object.entries(routers);\n\n return entries.reduce((record, [key, inputOrCallback]) => {\n const isCallback = typeof inputOrCallback === 'function';\n\n return { ...record, [key]: isCallback ? inputOrCallback({ strapi }) : inputOrCallback };\n }, {});\n};\n"],"names":["createRouteScopeGenerator","namespace","route","prefix","endsWith","handler","_","defaultsDeep","config","auth","scope","startsWith","strapi","registerAdminRoutes","registerAPIRoutes","registerPluginRoutes","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":";;;;AAGA,MAAMA,yBAAAA,GAA4B,CAACC,SAAAA,GAAsB,CAACC,KAAAA,GAAAA;QACxD,MAAMC,MAAAA,GAASF,UAAUG,QAAQ,CAAC,QAAQH,SAAY,GAAA,CAAA,EAAGA,SAAU,CAAA,CAAC,CAAC;AAErE,QAAA,IAAI,OAAOC,KAAAA,CAAMG,OAAO,KAAK,QAAU,EAAA;YACrCC,CAAEC,CAAAA,YAAY,CAACL,KAAO,EAAA;gBACpBM,MAAQ,EAAA;oBACNC,IAAM,EAAA;wBACJC,KAAO,EAAA;4BAAC,CAAGR,EAAAA,KAAAA,CAAMG,OAAO,CAACM,UAAU,CAACR,UAAU,EAAKA,GAAAA,MAAAA,CAAAA,EAASD,KAAMG,CAAAA,OAAO,CAAE;AAAC;AAC9E;AACF;AACF,aAAA,CAAA;AACF;AACF,KAAA;AAEA;;IAGA,wBAAe,CAAA,CAACO,MAAAA,GAAAA;IACdC,mBAAoBD,CAAAA,MAAAA,CAAAA;IACpBE,iBAAkBF,CAAAA,MAAAA,CAAAA;IAClBG,oBAAqBH,CAAAA,MAAAA,CAAAA;AACvB,CAAA;AAEA;;;IAIA,MAAMC,sBAAsB,CAACD,MAAAA,GAAAA;AAC3B,IAAA,MAAMI,kBAAqBhB,GAAAA,yBAAAA,CAA0B,CAAC,OAAO,CAAC,CAAA;;;IAI9DY,MAAOK,CAAAA,KAAK,CAACC,MAAM,GAAGC,wBAAwBP,MAAOK,CAAAA,KAAK,CAACC,MAAM,EAAEN,MAAAA,CAAAA;AAEnEN,IAAAA,CAAAA,CAAEc,OAAO,CAACR,MAAAA,CAAOK,KAAK,CAACC,MAAM,EAAE,CAACG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M,EAAE,CAACG,MAAAA,GAAAA;;;AAGrBA,YAAAA,MAAAA,CAAOC,IAAI,GAAG,aAAA;YACdD,MAAOH,CAAAA,MAAM,EAAEE,OAAAA,CAAQ,CAAClB,KAAAA,GAAAA;gBACtBc,kBAAmBd,CAAAA,KAAAA,CAAAA;AACnBA,gBAAAA,KAAAA,CAAMqB,IAAI,GAAG;AAAES,oBAAAA;AAAQ,iBAAA;AACzB,aAAA,CAAA;AAEA,YAAA,OAAOpB,MAAOa,CAAAA,MAAM,CAACP,MAAM,CAACG,MAAAA,CAAAA;AAC9B,SAAA,CAAA;AACF;AACF,CAAA;AAEA,MAAMF,uBAAAA,GAA0B,CAC9BgB,OACAvB,EAAAA,MAAAA,GAAAA;IAEA,MAAMwB,OAAAA,GAAUV,MAAOU,CAAAA,OAAO,CAACD,OAAAA,CAAAA;AAE/B,IAAA,OAAOC,QAAQC,MAAM,CAAC,CAACC,MAAQ,EAAA,CAACC,KAAKC,eAAgB,CAAA,GAAA;QACnD,MAAMC,UAAAA,GAAa,OAAOD,eAAoB,KAAA,UAAA;QAE9C,OAAO;AAAE,YAAA,GAAGF,MAAM;YAAE,CAACC,GAAAA,GAAME,UAAAA,GAAaD,eAAgB,CAAA;AAAE5B,gBAAAA;aAAY4B,CAAAA,GAAAA;AAAgB,SAAA;AACxF,KAAA,EAAG,EAAC,CAAA;AACN,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-routes.mjs","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n // Instantiate function-like routers\n // Mutate admin.routes in-place and make sure router factories are instantiated correctly\n strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);\n\n _.forEach(strapi.admin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n // Instantiate function-like routers\n // Mutate plugin.routes in-place and make sure router factories are instantiated correctly\n plugin.routes = instantiateRouterInputs(plugin.routes, strapi);\n\n _.forEach(plugin.routes, (router) => {\n router.type = router.type ?? 'admin';\n router.prefix = router.prefix ?? `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n // Mutate api.routes in-place and make sure router factories are instantiated correctly\n api.routes = instantiateRouterInputs(api.routes, strapi);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n\nconst instantiateRouterInputs = (\n routers: Record<string, Core.RouterConfig>,\n strapi: Core.Strapi\n): Record<string, Core.Router> => {\n const entries = Object.entries(routers);\n\n return entries.reduce((record, [key, inputOrCallback]) => {\n const isCallback = typeof inputOrCallback === 'function';\n\n return { ...record, [key]: isCallback ? inputOrCallback({ strapi }) : inputOrCallback };\n }, {});\n};\n"],"names":["createRouteScopeGenerator","namespace","route","prefix","endsWith","handler","_","defaultsDeep","config","auth","scope","startsWith","strapi","registerAdminRoutes","registerAPIRoutes","registerPluginRoutes","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":";;AAGA,MAAMA,yBAAAA,GAA4B,CAACC,SAAAA,GAAsB,CAACC,KAAAA,GAAAA;QACxD,MAAMC,MAAAA,GAASF,
|
|
1
|
+
{"version":3,"file":"register-routes.mjs","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n // Instantiate function-like routers\n // Mutate admin.routes in-place and make sure router factories are instantiated correctly\n strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);\n\n _.forEach(strapi.admin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n // Instantiate function-like routers\n // Mutate plugin.routes in-place and make sure router factories are instantiated correctly\n plugin.routes = instantiateRouterInputs(plugin.routes, strapi);\n\n _.forEach(plugin.routes, (router) => {\n router.type = router.type ?? 'admin';\n router.prefix = router.prefix ?? `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n // Mutate api.routes in-place and make sure router factories are instantiated correctly\n api.routes = instantiateRouterInputs(api.routes, strapi);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n\nconst instantiateRouterInputs = (\n routers: Record<string, Core.RouterConfig>,\n strapi: Core.Strapi\n): Record<string, Core.Router> => {\n const entries = Object.entries(routers);\n\n return entries.reduce((record, [key, inputOrCallback]) => {\n const isCallback = typeof inputOrCallback === 'function';\n\n return { ...record, [key]: isCallback ? inputOrCallback({ strapi }) : inputOrCallback };\n }, {});\n};\n"],"names":["createRouteScopeGenerator","namespace","route","prefix","endsWith","handler","_","defaultsDeep","config","auth","scope","startsWith","strapi","registerAdminRoutes","registerAPIRoutes","registerPluginRoutes","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":";;AAGA,MAAMA,yBAAAA,GAA4B,CAACC,SAAAA,GAAsB,CAACC,KAAAA,GAAAA;QACxD,MAAMC,MAAAA,GAASF,UAAUG,QAAQ,CAAC,QAAQH,SAAY,GAAA,CAAA,EAAGA,SAAU,CAAA,CAAC,CAAC;AAErE,QAAA,IAAI,OAAOC,KAAAA,CAAMG,OAAO,KAAK,QAAU,EAAA;YACrCC,CAAEC,CAAAA,YAAY,CAACL,KAAO,EAAA;gBACpBM,MAAQ,EAAA;oBACNC,IAAM,EAAA;wBACJC,KAAO,EAAA;4BAAC,CAAGR,EAAAA,KAAAA,CAAMG,OAAO,CAACM,UAAU,CAACR,UAAU,EAAKA,GAAAA,MAAAA,CAAAA,EAASD,KAAMG,CAAAA,OAAO,CAAE;AAAC;AAC9E;AACF;AACF,aAAA,CAAA;AACF;AACF,KAAA;AAEA;;IAGA,wBAAe,CAAA,CAACO,MAAAA,GAAAA;IACdC,mBAAoBD,CAAAA,MAAAA,CAAAA;IACpBE,iBAAkBF,CAAAA,MAAAA,CAAAA;IAClBG,oBAAqBH,CAAAA,MAAAA,CAAAA;AACvB,CAAA;AAEA;;;IAIA,MAAMC,sBAAsB,CAACD,MAAAA,GAAAA;AAC3B,IAAA,MAAMI,kBAAqBhB,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,kBAAqBhB,GAAAA,yBAAAA,CAA0B,CAAC,KAAK,EAAEgC,OAAS,CAAA,CAAA,CAAA;;AAGtEE,QAAAA,GAAAA,CAAIhB,MAAM,GAAGC,uBAAwBe,CAAAA,GAAAA,CAAIhB,MAAM,EAAEN,MAAAA,CAAAA;AAEjDN,QAAAA,CAAAA,CAAEc,OAAO,CAACc,GAAIhB,CAAAA,MAAM,EAAE,CAACG,MAAAA,GAAAA;;;AAGrBA,YAAAA,MAAAA,CAAOC,IAAI,GAAG,aAAA;YACdD,MAAOH,CAAAA,MAAM,EAAEE,OAAAA,CAAQ,CAAClB,KAAAA,GAAAA;gBACtBc,kBAAmBd,CAAAA,KAAAA,CAAAA;AACnBA,gBAAAA,KAAAA,CAAMqB,IAAI,GAAG;AAAES,oBAAAA;AAAQ,iBAAA;AACzB,aAAA,CAAA;AAEA,YAAA,OAAOpB,MAAOa,CAAAA,MAAM,CAACP,MAAM,CAACG,MAAAA,CAAAA;AAC9B,SAAA,CAAA;AACF;AACF,CAAA;AAEA,MAAMF,uBAAAA,GAA0B,CAC9BgB,OACAvB,EAAAA,MAAAA,GAAAA;IAEA,MAAMwB,OAAAA,GAAUV,MAAOU,CAAAA,OAAO,CAACD,OAAAA,CAAAA;AAE/B,IAAA,OAAOC,QAAQC,MAAM,CAAC,CAACC,MAAQ,EAAA,CAACC,KAAKC,eAAgB,CAAA,GAAA;QACnD,MAAMC,UAAAA,GAAa,OAAOD,eAAoB,KAAA,UAAA;QAE9C,OAAO;AAAE,YAAA,GAAGF,MAAM;YAAE,CAACC,GAAAA,GAAME,UAAAA,GAAaD,eAAgB,CAAA;AAAE5B,gBAAAA;aAAY4B,CAAAA,GAAAA;AAAgB,SAAA;AACxF,KAAA,EAAG,EAAC,CAAA;AACN,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sources":["../../../src/services/server/routing.ts"],"sourcesContent":["import Router from '@koa/router';\nimport { has } from 'lodash/fp';\nimport { yup } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nimport createEndpointComposer from './compose-endpoint';\n\nconst policyOrMiddlewareSchema = yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (typeof value === 'function') {\n return yup.mixed().isFunction();\n }\n\n return yup.object({\n name: yup.string().required(),\n options: yup.object().notRequired(), // any options\n });\n});\n\nconst routeSchema = yup.object({\n method: yup.string().oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL']).required(),\n path: yup.string().required(),\n handler: yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (Array.isArray(value)) {\n return yup.array().required();\n }\n\n return yup.mixed().isFunction().required();\n }),\n request: yup\n .object({\n params: yup.object().notRequired(),\n query: yup.object().notRequired(),\n body: yup.object().notRequired(),\n })\n .notRequired(),\n response: yup.object().notRequired(),\n config: yup\n .object({\n auth: yup.lazy((value) => {\n if (value === false) {\n return yup.boolean().required();\n }\n\n return yup.object({\n scope: yup.array().of(yup.string()).required(),\n });\n }),\n policies: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n middlewares: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n })\n .notRequired(),\n});\n\nconst validateRouteConfig = (routeConfig: Core.RouteInput) => {\n try {\n return routeSchema.validateSync(routeConfig, {\n strict: true,\n abortEarly: false,\n stripUnknown: true,\n });\n } catch (error) {\n if (error instanceof yup.ValidationError) {\n throw new Error(`Invalid route config ${error.message}`);\n }\n }\n};\n\nconst createRouteManager = (strapi: Core.Strapi, opts: { type?: string } = {}) => {\n const { type } = opts;\n\n const composeEndpoint = createEndpointComposer(strapi);\n\n const createRoute = (route: Core.RouteInput, router: Router) => {\n validateRouteConfig(route);\n\n // NOTE: the router type is used to tag controller actions and for authentication / authorization so we need to pass this info down to the route level\n const routeWithInfo = Object.assign(route, {\n info: {\n ...(route.info ?? {}),\n type: type ?? 'api',\n },\n });\n\n composeEndpoint(routeWithInfo, { router });\n };\n\n const addRoutes = (routes: Core.Router | Core.RouteInput[], router: Router) => {\n if (Array.isArray(routes)) {\n routes.forEach((route) => createRoute(route, router));\n } else if (routes.routes) {\n const subRouter = new Router({ prefix: routes.prefix });\n\n routes.routes.forEach((route) => {\n const hasPrefix = has('prefix', route.config);\n createRoute(route, hasPrefix ? router : subRouter);\n });\n\n return router.use(subRouter.routes(), subRouter.allowedMethods());\n }\n };\n\n return {\n addRoutes,\n };\n};\n\nexport { validateRouteConfig, createRouteManager };\n"],"names":["policyOrMiddlewareSchema","yup","lazy","value","string","required","mixed","isFunction","object","name","options","notRequired","routeSchema","method","oneOf","path","handler","Array","isArray","array","request","params","query","body","response","config","auth","boolean","scope","of","policies","middlewares","validateRouteConfig","routeConfig","validateSync","strict","abortEarly","stripUnknown","error","ValidationError","Error","message","createRouteManager","strapi","opts","type","composeEndpoint","createEndpointComposer","createRoute","route","router","routeWithInfo","Object","assign","info","addRoutes","routes","forEach","subRouter","Router","prefix","hasPrefix","has","use","allowedMethods"],"mappings":";;;;;;;AAOA,MAAMA,wBAA2BC,GAAAA,eAAAA,CAAIC,IAAI,CAAC,CAACC,KAAAA,GAAAA;IACzC,IAAI,OAAOA,UAAU,QAAU,EAAA;QAC7B,OAAOF,eAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC9B;IAEA,IAAI,OAAOF,UAAU,UAAY,EAAA;QAC/B,OAAOF,eAAAA,CAAIK,KAAK,EAAA,CAAGC,UAAU,EAAA;AAC/B;IAEA,OAAON,eAAAA,CAAIO,MAAM,CAAC;QAChBC,IAAMR,EAAAA,eAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;QAC3BK,OAAST,EAAAA,eAAAA,CAAIO,MAAM,EAAA,CAAGG,WAAW;AACnC,KAAA,CAAA;AACF,CAAA,CAAA;AAEA,MAAMC,WAAAA,GAAcX,eAAIO,CAAAA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0B,OAAO,EAAA,CAAGtB,QAAQ,EAAA;AAC/B;YAEA,OAAOJ,eAAAA,CAAIO,MAAM,CAAC;gBAChBoB,KAAO3B,EAAAA,eAAAA,CAAIkB,KAAK,EAAGU,CAAAA,EAAE,CAAC5B,eAAIG,CAAAA,MAAM,IAAIC,QAAQ;AAC9C,aAAA,CAAA;AACF,SAAA,CAAA;QACAyB,QAAU7B,EAAAA,eAAAA,CACPkB,KAAK,EACN;SACCU,EAAE,CAAC7B,0BACHW,WAAW,EAAA;QACdoB,WAAa9B,EAAAA,eAAAA,CACVkB,KAAK,EACN;SACCU,EAAE,CAAC7B,0BACHW,WAAW;AAChB,KAAA,CAAA,CACCA,WAAW;AAChB,CAAA,CAAA;AAEA,MAAMqB,sBAAsB,CAACC,WAAAA,GAAAA;IAC3B,IAAI;QACF,OAAOrB,WAAAA,CAAYsB,YAAY,CAACD,WAAa,EAAA;YAC3CE,MAAQ,EAAA,IAAA;YACRC,UAAY,EAAA,KAAA;YACZC,YAAc,EAAA;AAChB,SAAA,CAAA;AACF,KAAA,CAAE,OAAOC,KAAO,EAAA;QACd,IAAIA,KAAAA,YAAiBrC,eAAIsC,CAAAA,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"routing.js","sources":["../../../src/services/server/routing.ts"],"sourcesContent":["import Router from '@koa/router';\nimport { has } from 'lodash/fp';\nimport { yup } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nimport createEndpointComposer from './compose-endpoint';\n\nconst policyOrMiddlewareSchema = yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (typeof value === 'function') {\n return yup.mixed().isFunction();\n }\n\n return yup.object({\n name: yup.string().required(),\n options: yup.object().notRequired(), // any options\n });\n});\n\nconst routeSchema = yup.object({\n method: yup.string().oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL']).required(),\n path: yup.string().required(),\n handler: yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (Array.isArray(value)) {\n return yup.array().required();\n }\n\n return yup.mixed().isFunction().required();\n }),\n request: yup\n .object({\n params: yup.object().notRequired(),\n query: yup.object().notRequired(),\n body: yup.object().notRequired(),\n })\n .notRequired(),\n response: yup.object().notRequired(),\n config: yup\n .object({\n auth: yup.lazy((value) => {\n if (value === false) {\n return yup.boolean().required();\n }\n\n return yup.object({\n scope: yup.array().of(yup.string()).required(),\n });\n }),\n policies: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n middlewares: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n })\n .notRequired(),\n});\n\nconst validateRouteConfig = (routeConfig: Core.RouteInput) => {\n try {\n return routeSchema.validateSync(routeConfig, {\n strict: true,\n abortEarly: false,\n stripUnknown: true,\n });\n } catch (error) {\n if (error instanceof yup.ValidationError) {\n throw new Error(`Invalid route config ${error.message}`);\n }\n }\n};\n\nconst createRouteManager = (strapi: Core.Strapi, opts: { type?: string } = {}) => {\n const { type } = opts;\n\n const composeEndpoint = createEndpointComposer(strapi);\n\n const createRoute = (route: Core.RouteInput, router: Router) => {\n validateRouteConfig(route);\n\n // NOTE: the router type is used to tag controller actions and for authentication / authorization so we need to pass this info down to the route level\n const routeWithInfo = Object.assign(route, {\n info: {\n ...(route.info ?? {}),\n type: type ?? 'api',\n },\n });\n\n composeEndpoint(routeWithInfo, { router });\n };\n\n const addRoutes = (routes: Core.Router | Core.RouteInput[], router: Router) => {\n if (Array.isArray(routes)) {\n routes.forEach((route) => createRoute(route, router));\n } else if (routes.routes) {\n const subRouter = new Router({ prefix: routes.prefix });\n\n routes.routes.forEach((route) => {\n const hasPrefix = has('prefix', route.config);\n createRoute(route, hasPrefix ? router : subRouter);\n });\n\n return router.use(subRouter.routes(), subRouter.allowedMethods());\n }\n };\n\n return {\n addRoutes,\n };\n};\n\nexport { validateRouteConfig, createRouteManager };\n"],"names":["policyOrMiddlewareSchema","yup","lazy","value","string","required","mixed","isFunction","object","name","options","notRequired","routeSchema","method","oneOf","path","handler","Array","isArray","array","request","params","query","body","response","config","auth","boolean","scope","of","policies","middlewares","validateRouteConfig","routeConfig","validateSync","strict","abortEarly","stripUnknown","error","ValidationError","Error","message","createRouteManager","strapi","opts","type","composeEndpoint","createEndpointComposer","createRoute","route","router","routeWithInfo","Object","assign","info","addRoutes","routes","forEach","subRouter","Router","prefix","hasPrefix","has","use","allowedMethods"],"mappings":";;;;;;;AAOA,MAAMA,wBAA2BC,GAAAA,eAAAA,CAAIC,IAAI,CAAC,CAACC,KAAAA,GAAAA;IACzC,IAAI,OAAOA,UAAU,QAAU,EAAA;QAC7B,OAAOF,eAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC9B;IAEA,IAAI,OAAOF,UAAU,UAAY,EAAA;QAC/B,OAAOF,eAAAA,CAAIK,KAAK,EAAA,CAAGC,UAAU,EAAA;AAC/B;IAEA,OAAON,eAAAA,CAAIO,MAAM,CAAC;QAChBC,IAAMR,EAAAA,eAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;QAC3BK,OAAST,EAAAA,eAAAA,CAAIO,MAAM,EAAA,CAAGG,WAAW;AACnC,KAAA,CAAA;AACF,CAAA,CAAA;AAEA,MAAMC,WAAAA,GAAcX,eAAIO,CAAAA,MAAM,CAAC;AAC7BK,IAAAA,MAAAA,EAAQZ,eAAIG,CAAAA,MAAM,EAAGU,CAAAA,KAAK,CAAC;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA;AAAM,KAAA,CAAA,CAAET,QAAQ,EAAA;IACrFU,IAAMd,EAAAA,eAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;IAC3BW,OAASf,EAAAA,eAAAA,CAAIC,IAAI,CAAC,CAACC,KAAAA,GAAAA;QACjB,IAAI,OAAOA,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,GAAUD,YAAYC,KAAOC,EAAAA,MAAAA,CAAAA,CAAAA;SACxC,MAAA,IAAIM,MAAOA,CAAAA,MAAM,EAAE;YACxB,MAAME,SAAAA,GAAY,IAAIC,MAAO,CAAA;AAAEC,gBAAAA,MAAAA,EAAQJ,OAAOI;AAAO,aAAA,CAAA;AAErDJ,YAAAA,MAAAA,CAAOA,MAAM,CAACC,OAAO,CAAC,CAACR,KAAAA,GAAAA;AACrB,gBAAA,MAAMY,SAAYC,GAAAA,MAAAA,CAAI,QAAUb,EAAAA,KAAAA,CAAMxB,MAAM,CAAA;gBAC5CuB,WAAYC,CAAAA,KAAAA,EAAOY,YAAYX,MAASQ,GAAAA,SAAAA,CAAAA;AAC1C,aAAA,CAAA;AAEA,YAAA,OAAOR,OAAOa,GAAG,CAACL,UAAUF,MAAM,EAAA,EAAIE,UAAUM,cAAc,EAAA,CAAA;AAChE;AACF,KAAA;IAEA,OAAO;AACLT,QAAAA;AACF,KAAA;AACF;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.mjs","sources":["../../../src/services/server/routing.ts"],"sourcesContent":["import Router from '@koa/router';\nimport { has } from 'lodash/fp';\nimport { yup } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nimport createEndpointComposer from './compose-endpoint';\n\nconst policyOrMiddlewareSchema = yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (typeof value === 'function') {\n return yup.mixed().isFunction();\n }\n\n return yup.object({\n name: yup.string().required(),\n options: yup.object().notRequired(), // any options\n });\n});\n\nconst routeSchema = yup.object({\n method: yup.string().oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL']).required(),\n path: yup.string().required(),\n handler: yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (Array.isArray(value)) {\n return yup.array().required();\n }\n\n return yup.mixed().isFunction().required();\n }),\n request: yup\n .object({\n params: yup.object().notRequired(),\n query: yup.object().notRequired(),\n body: yup.object().notRequired(),\n })\n .notRequired(),\n response: yup.object().notRequired(),\n config: yup\n .object({\n auth: yup.lazy((value) => {\n if (value === false) {\n return yup.boolean().required();\n }\n\n return yup.object({\n scope: yup.array().of(yup.string()).required(),\n });\n }),\n policies: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n middlewares: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n })\n .notRequired(),\n});\n\nconst validateRouteConfig = (routeConfig: Core.RouteInput) => {\n try {\n return routeSchema.validateSync(routeConfig, {\n strict: true,\n abortEarly: false,\n stripUnknown: true,\n });\n } catch (error) {\n if (error instanceof yup.ValidationError) {\n throw new Error(`Invalid route config ${error.message}`);\n }\n }\n};\n\nconst createRouteManager = (strapi: Core.Strapi, opts: { type?: string } = {}) => {\n const { type } = opts;\n\n const composeEndpoint = createEndpointComposer(strapi);\n\n const createRoute = (route: Core.RouteInput, router: Router) => {\n validateRouteConfig(route);\n\n // NOTE: the router type is used to tag controller actions and for authentication / authorization so we need to pass this info down to the route level\n const routeWithInfo = Object.assign(route, {\n info: {\n ...(route.info ?? {}),\n type: type ?? 'api',\n },\n });\n\n composeEndpoint(routeWithInfo, { router });\n };\n\n const addRoutes = (routes: Core.Router | Core.RouteInput[], router: Router) => {\n if (Array.isArray(routes)) {\n routes.forEach((route) => createRoute(route, router));\n } else if (routes.routes) {\n const subRouter = new Router({ prefix: routes.prefix });\n\n routes.routes.forEach((route) => {\n const hasPrefix = has('prefix', route.config);\n createRoute(route, hasPrefix ? router : subRouter);\n });\n\n return router.use(subRouter.routes(), subRouter.allowedMethods());\n }\n };\n\n return {\n addRoutes,\n };\n};\n\nexport { validateRouteConfig, createRouteManager };\n"],"names":["policyOrMiddlewareSchema","yup","lazy","value","string","required","mixed","isFunction","object","name","options","notRequired","routeSchema","method","oneOf","path","handler","Array","isArray","array","request","params","query","body","response","config","auth","boolean","scope","of","policies","middlewares","validateRouteConfig","routeConfig","validateSync","strict","abortEarly","stripUnknown","error","ValidationError","Error","message","createRouteManager","strapi","opts","type","composeEndpoint","createEndpointComposer","createRoute","route","router","routeWithInfo","Object","assign","info","addRoutes","routes","forEach","subRouter","Router","prefix","hasPrefix","has","use","allowedMethods"],"mappings":";;;;;AAOA,MAAMA,wBAA2BC,GAAAA,GAAAA,CAAIC,IAAI,CAAC,CAACC,KAAAA,GAAAA;IACzC,IAAI,OAAOA,UAAU,QAAU,EAAA;QAC7B,OAAOF,GAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC9B;IAEA,IAAI,OAAOF,UAAU,UAAY,EAAA;QAC/B,OAAOF,GAAAA,CAAIK,KAAK,EAAA,CAAGC,UAAU,EAAA;AAC/B;IAEA,OAAON,GAAAA,CAAIO,MAAM,CAAC;QAChBC,IAAMR,EAAAA,GAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;QAC3BK,OAAST,EAAAA,GAAAA,CAAIO,MAAM,EAAA,CAAGG,WAAW;AACnC,KAAA,CAAA;AACF,CAAA,CAAA;AAEA,MAAMC,WAAAA,GAAcX,GAAIO,CAAAA,MAAM,CAAC;AAC7BK,IAAAA,MAAAA,EAAQZ,GAAIG,CAAAA,MAAM,EAAGU,CAAAA,KAAK,CAAC;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA;AAAM,KAAA,CAAA,CAAET,QAAQ,EAAA;IACrFU,IAAMd,EAAAA,GAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;IAC3BW,OAASf,EAAAA,GAAAA,CAAIC,IAAI,CAAC,CAACC,KAAAA,GAAAA;QACjB,IAAI,OAAOA,UAAU,QAAU,EAAA;YAC7B,OAAOF,GAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC9B;QAEA,IAAIY,KAAA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IAC3B,IAAI;QACF,OAAOrB,WAAAA,CAAYsB,YAAY,CAACD,WAAa,EAAA;YAC3CE,MAAQ,EAAA,IAAA;YACRC,UAAY,EAAA,KAAA;YACZC,YAAc,EAAA;AAChB,SAAA,CAAA;AACF,KAAA,CAAE,OAAOC,KAAO,EAAA;QACd,IAAIA,KAAAA,YAAiBrC,GAAIsC,CAAAA,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"routing.mjs","sources":["../../../src/services/server/routing.ts"],"sourcesContent":["import Router from '@koa/router';\nimport { has } from 'lodash/fp';\nimport { yup } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nimport createEndpointComposer from './compose-endpoint';\n\nconst policyOrMiddlewareSchema = yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (typeof value === 'function') {\n return yup.mixed().isFunction();\n }\n\n return yup.object({\n name: yup.string().required(),\n options: yup.object().notRequired(), // any options\n });\n});\n\nconst routeSchema = yup.object({\n method: yup.string().oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL']).required(),\n path: yup.string().required(),\n handler: yup.lazy((value) => {\n if (typeof value === 'string') {\n return yup.string().required();\n }\n\n if (Array.isArray(value)) {\n return yup.array().required();\n }\n\n return yup.mixed().isFunction().required();\n }),\n request: yup\n .object({\n params: yup.object().notRequired(),\n query: yup.object().notRequired(),\n body: yup.object().notRequired(),\n })\n .notRequired(),\n response: yup.object().notRequired(),\n config: yup\n .object({\n auth: yup.lazy((value) => {\n if (value === false) {\n return yup.boolean().required();\n }\n\n return yup.object({\n scope: yup.array().of(yup.string()).required(),\n });\n }),\n policies: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n middlewares: yup\n .array()\n // FIXME: fixed in yup v1\n .of(policyOrMiddlewareSchema as any)\n .notRequired(),\n })\n .notRequired(),\n});\n\nconst validateRouteConfig = (routeConfig: Core.RouteInput) => {\n try {\n return routeSchema.validateSync(routeConfig, {\n strict: true,\n abortEarly: false,\n stripUnknown: true,\n });\n } catch (error) {\n if (error instanceof yup.ValidationError) {\n throw new Error(`Invalid route config ${error.message}`);\n }\n }\n};\n\nconst createRouteManager = (strapi: Core.Strapi, opts: { type?: string } = {}) => {\n const { type } = opts;\n\n const composeEndpoint = createEndpointComposer(strapi);\n\n const createRoute = (route: Core.RouteInput, router: Router) => {\n validateRouteConfig(route);\n\n // NOTE: the router type is used to tag controller actions and for authentication / authorization so we need to pass this info down to the route level\n const routeWithInfo = Object.assign(route, {\n info: {\n ...(route.info ?? {}),\n type: type ?? 'api',\n },\n });\n\n composeEndpoint(routeWithInfo, { router });\n };\n\n const addRoutes = (routes: Core.Router | Core.RouteInput[], router: Router) => {\n if (Array.isArray(routes)) {\n routes.forEach((route) => createRoute(route, router));\n } else if (routes.routes) {\n const subRouter = new Router({ prefix: routes.prefix });\n\n routes.routes.forEach((route) => {\n const hasPrefix = has('prefix', route.config);\n createRoute(route, hasPrefix ? router : subRouter);\n });\n\n return router.use(subRouter.routes(), subRouter.allowedMethods());\n }\n };\n\n return {\n addRoutes,\n };\n};\n\nexport { validateRouteConfig, createRouteManager };\n"],"names":["policyOrMiddlewareSchema","yup","lazy","value","string","required","mixed","isFunction","object","name","options","notRequired","routeSchema","method","oneOf","path","handler","Array","isArray","array","request","params","query","body","response","config","auth","boolean","scope","of","policies","middlewares","validateRouteConfig","routeConfig","validateSync","strict","abortEarly","stripUnknown","error","ValidationError","Error","message","createRouteManager","strapi","opts","type","composeEndpoint","createEndpointComposer","createRoute","route","router","routeWithInfo","Object","assign","info","addRoutes","routes","forEach","subRouter","Router","prefix","hasPrefix","has","use","allowedMethods"],"mappings":";;;;;AAOA,MAAMA,wBAA2BC,GAAAA,GAAAA,CAAIC,IAAI,CAAC,CAACC,KAAAA,GAAAA;IACzC,IAAI,OAAOA,UAAU,QAAU,EAAA;QAC7B,OAAOF,GAAAA,CAAIG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC9B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ACL,UAAUF,MAAM,EAAA,EAAIE,UAAUM,cAAc,EAAA,CAAA;AAChE;AACF,KAAA;IAEA,OAAO;AACLT,QAAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Algorithm } from 'jsonwebtoken';
|
|
1
2
|
import type { Database } from '@strapi/database';
|
|
2
3
|
export interface SessionProvider {
|
|
3
4
|
create(session: SessionData): Promise<SessionData>;
|
|
@@ -47,12 +48,14 @@ export interface ValidateRefreshTokenResult {
|
|
|
47
48
|
error?: 'invalid_token' | 'token_expired' | 'session_not_found' | 'session_expired' | 'wrong_token_type';
|
|
48
49
|
}
|
|
49
50
|
export interface SessionManagerConfig {
|
|
50
|
-
jwtSecret
|
|
51
|
+
jwtSecret?: string;
|
|
51
52
|
accessTokenLifespan: number;
|
|
52
53
|
maxRefreshTokenLifespan: number;
|
|
53
54
|
idleRefreshTokenLifespan: number;
|
|
54
55
|
maxSessionLifespan: number;
|
|
55
56
|
idleSessionLifespan: number;
|
|
57
|
+
algorithm?: Algorithm;
|
|
58
|
+
jwtOptions?: Record<string, unknown>;
|
|
56
59
|
}
|
|
57
60
|
declare class OriginSessionManager {
|
|
58
61
|
private sessionManager;
|
|
@@ -111,6 +114,10 @@ declare class SessionManager {
|
|
|
111
114
|
* Get configuration for a specific origin, throw error if not defined
|
|
112
115
|
*/
|
|
113
116
|
private getConfigForOrigin;
|
|
117
|
+
/**
|
|
118
|
+
* Get the appropriate JWT key based on the algorithm
|
|
119
|
+
*/
|
|
120
|
+
private getJwtKey;
|
|
114
121
|
generateSessionId(): string;
|
|
115
122
|
private maybeCleanupExpired;
|
|
116
123
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/services/session-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/services/session-manager.ts"],"names":[],"mappings":"AAEA,O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AAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;KAC7B,GACD;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CACpB;IAmJD;;;OAGG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAmB3E;AAED,QAAA,MAAM,sBAAsB,OAAQ,QAAQ,eAAe,MAAM,KAAG,eAEnE,CAAC;AAEF,QAAA,MAAM,oBAAoB,YAEvB;IACD,EAAE,EAAE,QAAQ,CAAC;CACd,KAAG,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,oBAAoB,CA8B7D,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -113,6 +113,32 @@ class SessionManager {
|
|
|
113
113
|
}
|
|
114
114
|
throw new Error(`SessionManager: Origin '${origin}' is not defined. Please define it using defineOrigin('${origin}', config).`);
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the appropriate JWT key based on the algorithm
|
|
118
|
+
*/ getJwtKey(config, algorithm, operation) {
|
|
119
|
+
const isAsymmetric = algorithm.startsWith('RS') || algorithm.startsWith('ES') || algorithm.startsWith('PS');
|
|
120
|
+
if (isAsymmetric) {
|
|
121
|
+
// For asymmetric algorithms, check if user has provided proper key configuration
|
|
122
|
+
if (operation === 'sign') {
|
|
123
|
+
const privateKey = config.jwtOptions?.privateKey;
|
|
124
|
+
if (privateKey) {
|
|
125
|
+
return privateKey;
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`SessionManager: Private key is required for asymmetric algorithm ${algorithm}. Please configure admin.auth.options.privateKey.`);
|
|
128
|
+
} else {
|
|
129
|
+
const publicKey = config.jwtOptions?.publicKey;
|
|
130
|
+
if (publicKey) {
|
|
131
|
+
return publicKey;
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`SessionManager: Public key is required for asymmetric algorithm ${algorithm}. Please configure admin.auth.options.publicKey.`);
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
if (!config.jwtSecret) {
|
|
137
|
+
throw new Error(`SessionManager: Secret key is required for symmetric algorithm ${algorithm}`);
|
|
138
|
+
}
|
|
139
|
+
return config.jwtSecret;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
116
142
|
generateSessionId() {
|
|
117
143
|
return crypto.randomBytes(16).toString('hex');
|
|
118
144
|
}
|
|
@@ -134,6 +160,8 @@ class SessionManager {
|
|
|
134
160
|
}
|
|
135
161
|
await this.maybeCleanupExpired();
|
|
136
162
|
const config = this.getConfigForOrigin(origin);
|
|
163
|
+
const algorithm = config.algorithm || constants.DEFAULT_ALGORITHM;
|
|
164
|
+
const jwtKey = this.getJwtKey(config, algorithm, 'sign');
|
|
137
165
|
const sessionId = this.generateSessionId();
|
|
138
166
|
const tokenType = options?.type ?? 'refresh';
|
|
139
167
|
const isRefresh = tokenType === 'refresh';
|
|
@@ -165,9 +193,13 @@ class SessionManager {
|
|
|
165
193
|
iat: issuedAtSeconds,
|
|
166
194
|
exp: expiresAtSeconds
|
|
167
195
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
196
|
+
// Filter out conflicting options that are already handled by the payload or used for key selection
|
|
197
|
+
const jwtOptions = config.jwtOptions || {};
|
|
198
|
+
const { expiresIn, privateKey, publicKey, ...jwtSignOptions } = jwtOptions;
|
|
199
|
+
const token = jwt.sign(payload, jwtKey, {
|
|
200
|
+
algorithm,
|
|
201
|
+
noTimestamp: true,
|
|
202
|
+
...jwtSignOptions
|
|
171
203
|
});
|
|
172
204
|
return {
|
|
173
205
|
token,
|
|
@@ -181,10 +213,13 @@ class SessionManager {
|
|
|
181
213
|
}
|
|
182
214
|
try {
|
|
183
215
|
const config = this.getConfigForOrigin(origin);
|
|
184
|
-
const
|
|
216
|
+
const algorithm = config.algorithm || constants.DEFAULT_ALGORITHM;
|
|
217
|
+
const jwtKey = this.getJwtKey(config, algorithm, 'verify');
|
|
218
|
+
const payload = jwt.verify(token, jwtKey, {
|
|
185
219
|
algorithms: [
|
|
186
|
-
|
|
187
|
-
]
|
|
220
|
+
algorithm
|
|
221
|
+
],
|
|
222
|
+
...config.jwtOptions
|
|
188
223
|
});
|
|
189
224
|
// Ensure this is an access token
|
|
190
225
|
if (!payload || payload.type !== 'access') {
|
|
@@ -210,12 +245,15 @@ class SessionManager {
|
|
|
210
245
|
}
|
|
211
246
|
try {
|
|
212
247
|
const config = this.getConfigForOrigin(origin);
|
|
248
|
+
const algorithm = config.algorithm || constants.DEFAULT_ALGORITHM;
|
|
249
|
+
const jwtKey = this.getJwtKey(config, algorithm, 'verify');
|
|
213
250
|
const verifyOptions = {
|
|
214
251
|
algorithms: [
|
|
215
|
-
|
|
216
|
-
]
|
|
252
|
+
algorithm
|
|
253
|
+
],
|
|
254
|
+
...config.jwtOptions
|
|
217
255
|
};
|
|
218
|
-
const payload = jwt.verify(token,
|
|
256
|
+
const payload = jwt.verify(token, jwtKey, verifyOptions);
|
|
219
257
|
if (payload.type !== 'refresh') {
|
|
220
258
|
return {
|
|
221
259
|
isValid: false
|
|
@@ -287,9 +325,15 @@ class SessionManager {
|
|
|
287
325
|
type: 'access'
|
|
288
326
|
};
|
|
289
327
|
const config = this.getConfigForOrigin(origin);
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
328
|
+
const algorithm = config.algorithm || constants.DEFAULT_ALGORITHM;
|
|
329
|
+
const jwtKey = this.getJwtKey(config, algorithm, 'sign');
|
|
330
|
+
// Filter out conflicting options that are already handled by the payload or used for key selection
|
|
331
|
+
const jwtOptions = config.jwtOptions || {};
|
|
332
|
+
const { expiresIn, privateKey, publicKey, ...jwtSignOptions } = jwtOptions;
|
|
333
|
+
const token = jwt.sign(payload, jwtKey, {
|
|
334
|
+
algorithm,
|
|
335
|
+
expiresIn: config.accessTokenLifespan,
|
|
336
|
+
...jwtSignOptions
|
|
293
337
|
});
|
|
294
338
|
return {
|
|
295
339
|
token
|
|
@@ -301,10 +345,13 @@ class SessionManager {
|
|
|
301
345
|
}
|
|
302
346
|
try {
|
|
303
347
|
const config = this.getConfigForOrigin(origin);
|
|
304
|
-
const
|
|
348
|
+
const algorithm = config.algorithm || constants.DEFAULT_ALGORITHM;
|
|
349
|
+
const jwtKey = this.getJwtKey(config, algorithm, 'verify');
|
|
350
|
+
const payload = jwt.verify(refreshToken, jwtKey, {
|
|
305
351
|
algorithms: [
|
|
306
|
-
|
|
307
|
-
]
|
|
352
|
+
algorithm
|
|
353
|
+
],
|
|
354
|
+
...config.jwtOptions
|
|
308
355
|
});
|
|
309
356
|
if (!payload || payload.type !== 'refresh') {
|
|
310
357
|
return {
|
|
@@ -330,9 +377,12 @@ class SessionManager {
|
|
|
330
377
|
iat: childIat,
|
|
331
378
|
exp: childExp
|
|
332
379
|
};
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
380
|
+
// Filter out conflicting options that are already handled by the payload
|
|
381
|
+
const { expiresIn, ...jwtSignOptions } = config.jwtOptions || {};
|
|
382
|
+
const childToken = jwt.sign(childPayload, jwtKey, {
|
|
383
|
+
algorithm,
|
|
384
|
+
noTimestamp: true,
|
|
385
|
+
...jwtSignOptions
|
|
336
386
|
});
|
|
337
387
|
let absoluteExpiresAt;
|
|
338
388
|
if (child.absoluteExpiresAt) {
|
|
@@ -389,9 +439,12 @@ class SessionManager {
|
|
|
389
439
|
iat: childIat,
|
|
390
440
|
exp: childExp
|
|
391
441
|
};
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
442
|
+
// Filter out conflicting options that are already handled by the payload
|
|
443
|
+
const { expiresIn, ...jwtSignOptions } = config.jwtOptions || {};
|
|
444
|
+
const childToken = jwt.sign(payloadOut, jwtKey, {
|
|
445
|
+
algorithm,
|
|
446
|
+
noTimestamp: true,
|
|
447
|
+
...jwtSignOptions
|
|
395
448
|
});
|
|
396
449
|
await this.provider.updateBySessionId(current.sessionId, {
|
|
397
450
|
status: 'rotated',
|