@strapi/core 5.48.1 → 5.49.0
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.
- package/dist/Strapi.js +9 -5
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +0 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/ai.d.ts +2 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +8 -0
- package/dist/ai.js.map +1 -0
- package/dist/ai.mjs +3 -0
- package/dist/ai.mjs.map +1 -0
- package/dist/configuration/config-loader.js +11 -6
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/index.js +22 -15
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/urls.js +11 -7
- package/dist/configuration/urls.js.map +1 -1
- package/dist/core-api/routes/index.js +3 -2
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/validation/common.js +3 -2
- package/dist/core-api/routes/validation/common.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +3 -2
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +3 -2
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/utils.js +3 -2
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/domain/content-type/index.js +9 -5
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/validator.js +6 -2
- package/dist/domain/content-type/validator.js.map +1 -1
- package/dist/domain/module/index.js +6 -2
- package/dist/domain/module/index.js.map +1 -1
- package/dist/ee/license.js +8 -3
- package/dist/ee/license.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/admin.js +5 -1
- package/dist/loaders/admin.js.map +1 -1
- package/dist/loaders/apis.js +16 -11
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/components.js +6 -2
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/middlewares.js +6 -2
- package/dist/loaders/middlewares.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +5 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +6 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.js +8 -4
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/policies.js +6 -2
- package/dist/loaders/policies.js.map +1 -1
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +12 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcp.mjs +4 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/middlewares/body.js +8 -3
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/compression.js +5 -1
- package/dist/middlewares/compression.js.map +1 -1
- package/dist/middlewares/cors.js +5 -1
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/favicon.js +5 -1
- package/dist/middlewares/favicon.js.map +1 -1
- package/dist/middlewares/ip.js +5 -1
- package/dist/middlewares/ip.js.map +1 -1
- package/dist/middlewares/public.js +5 -1
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/query.js +6 -2
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/security.js +5 -1
- package/dist/middlewares/security.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +5 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/first-published-at.js +5 -1
- package/dist/migrations/first-published-at.js.map +1 -1
- package/dist/package.json.js +15 -15
- package/dist/package.json.mjs +15 -15
- package/dist/registries/sanitizers.js +7 -3
- package/dist/registries/sanitizers.js.map +1 -1
- package/dist/registries/validators.js +7 -3
- package/dist/registries/validators.js.map +1 -1
- package/dist/services/auth/index.js +7 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/content-api/index.js +10 -6
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/permissions/engine.js +5 -1
- package/dist/services/content-api/permissions/engine.js.map +1 -1
- package/dist/services/content-api/permissions/index.js +10 -6
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +5 -1
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +14 -10
- 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/draft-and-publish.js +1 -1
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs +1 -1
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +6 -2
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +7 -3
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts +2 -0
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js +7 -1
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs +7 -2
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/entity-service/index.js +9 -4
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -4
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.js +10 -6
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/errors.js +7 -3
- package/dist/services/errors.js.map +1 -1
- package/dist/services/fs.js +10 -5
- package/dist/services/fs.js.map +1 -1
- package/dist/services/mcp/prompt-registry.d.ts +31 -3
- package/dist/services/mcp/prompt-registry.d.ts.map +1 -1
- package/dist/services/mcp/prompt-registry.js +31 -0
- package/dist/services/mcp/prompt-registry.js.map +1 -1
- package/dist/services/mcp/prompt-registry.mjs +31 -1
- package/dist/services/mcp/prompt-registry.mjs.map +1 -1
- package/dist/services/mcp/resource-registry.d.ts +31 -1
- package/dist/services/mcp/resource-registry.d.ts.map +1 -1
- package/dist/services/mcp/resource-registry.js +31 -0
- package/dist/services/mcp/resource-registry.js.map +1 -1
- package/dist/services/mcp/resource-registry.mjs +31 -1
- package/dist/services/mcp/resource-registry.mjs.map +1 -1
- package/dist/services/mcp/tool-registry.d.ts +36 -9
- package/dist/services/mcp/tool-registry.d.ts.map +1 -1
- package/dist/services/mcp/tool-registry.js +35 -3
- package/dist/services/mcp/tool-registry.js.map +1 -1
- package/dist/services/mcp/tool-registry.mjs +35 -3
- package/dist/services/mcp/tool-registry.mjs.map +1 -1
- package/dist/services/mcp/tools/log.d.ts +15 -85
- package/dist/services/mcp/tools/log.d.ts.map +1 -1
- package/dist/services/metrics/admin-user-hash.js +5 -1
- package/dist/services/metrics/admin-user-hash.js.map +1 -1
- package/dist/services/metrics/is-truthy.js +5 -1
- package/dist/services/metrics/is-truthy.js.map +1 -1
- package/dist/services/metrics/sender.js +17 -9
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/server/api.js +5 -1
- package/dist/services/server/api.js.map +1 -1
- package/dist/services/server/compose-endpoint.js +5 -1
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/http-server.js +5 -1
- package/dist/services/server/http-server.js.map +1 -1
- package/dist/services/server/index.js +5 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/koa.js +12 -5
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +5 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/openapi.js +11 -6
- package/dist/services/server/openapi.js.map +1 -1
- package/dist/services/server/register-routes.js +8 -4
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/routing.js +5 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/session-manager.js +14 -9
- package/dist/services/session-manager.js.map +1 -1
- package/dist/services/webhook-runner.js +7 -2
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/worker-queue.js +5 -1
- package/dist/services/worker-queue.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +13 -8
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/load-config-file.js +7 -2
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-files.js +12 -6
- package/dist/utils/load-files.js.map +1 -1
- package/dist/utils/open-browser.js +5 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/resolve-working-dirs.js +6 -2
- package/dist/utils/resolve-working-dirs.js.map +1 -1
- package/dist/utils/startup-logger.js +27 -21
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +10 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/update-notifier/index.d.ts.map +1 -1
- package/dist/utils/update-notifier/index.js +21 -8
- package/dist/utils/update-notifier/index.js.map +1 -1
- package/dist/utils/update-notifier/index.mjs +6 -1
- package/dist/utils/update-notifier/index.mjs.map +1 -1
- package/package.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":["../../../src/services/server/api.ts"],"sourcesContent":["import Router from '@koa/router';\nimport type { Core } from '@strapi/types';\n\nimport { createRouteManager } from './routing';\n\ninterface Options {\n prefix?: string;\n type?: string;\n}\n\nconst createAPI = (strapi: Core.Strapi, opts: Options = {}) => {\n const { prefix, type } = opts;\n\n const api = new Router({ prefix });\n\n const routeManager = createRouteManager(strapi, { type });\n\n return {\n listRoutes() {\n return [...api.stack];\n },\n\n use(fn: Router.Middleware) {\n api.use(fn);\n return this;\n },\n\n routes(routes: Core.Router | Core.Route[]) {\n routeManager.addRoutes(routes, api);\n return this;\n },\n\n mount(router: Router) {\n router.use(api.routes(), api.allowedMethods());\n return this;\n },\n };\n};\n\nexport { createAPI };\n"],"names":["createAPI","strapi","opts","prefix","type","api","Router","routeManager","createRouteManager","listRoutes","stack","use","fn","routes","addRoutes","mount","router","allowedMethods"],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.js","sources":["../../../src/services/server/api.ts"],"sourcesContent":["import Router from '@koa/router';\nimport type { Core } from '@strapi/types';\n\nimport { createRouteManager } from './routing';\n\ninterface Options {\n prefix?: string;\n type?: string;\n}\n\nconst createAPI = (strapi: Core.Strapi, opts: Options = {}) => {\n const { prefix, type } = opts;\n\n const api = new Router({ prefix });\n\n const routeManager = createRouteManager(strapi, { type });\n\n return {\n listRoutes() {\n return [...api.stack];\n },\n\n use(fn: Router.Middleware) {\n api.use(fn);\n return this;\n },\n\n routes(routes: Core.Router | Core.Route[]) {\n routeManager.addRoutes(routes, api);\n return this;\n },\n\n mount(router: Router) {\n router.use(api.routes(), api.allowedMethods());\n return this;\n },\n };\n};\n\nexport { createAPI };\n"],"names":["createAPI","strapi","opts","prefix","type","api","Router","routeManager","createRouteManager","listRoutes","stack","use","fn","routes","addRoutes","mount","router","allowedMethods"],"mappings":";;;;;;;;;AAUA,MAAMA,SAAAA,GAAY,CAACC,MAAAA,EAAqBC,IAAAA,GAAgB,EAAE,GAAA;AACxD,IAAA,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGF,IAAAA;IAEzB,MAAMG,GAAAA,GAAM,IAAIC,uBAAAA,CAAO;AAAEH,QAAAA;AAAO,KAAA,CAAA;IAEhC,MAAMI,YAAAA,GAAeC,2BAAmBP,MAAAA,EAAQ;AAAEG,QAAAA;AAAK,KAAA,CAAA;IAEvD,OAAO;AACLK,QAAAA,UAAAA,CAAAA,GAAAA;YACE,OAAO;AAAIJ,gBAAAA,GAAAA,GAAAA,CAAIK;AAAM,aAAA;AACvB,QAAA,CAAA;AAEAC,QAAAA,GAAAA,CAAAA,CAAIC,EAAqB,EAAA;AACvBP,YAAAA,GAAAA,CAAIM,GAAG,CAACC,EAAAA,CAAAA;AACR,YAAA,OAAO,IAAI;AACb,QAAA,CAAA;AAEAC,QAAAA,MAAAA,CAAAA,CAAOA,MAAkC,EAAA;YACvCN,YAAAA,CAAaO,SAAS,CAACD,MAAAA,EAAQR,GAAAA,CAAAA;AAC/B,YAAA,OAAO,IAAI;AACb,QAAA,CAAA;AAEAU,QAAAA,KAAAA,CAAAA,CAAMC,MAAc,EAAA;AAClBA,YAAAA,MAAAA,CAAOL,GAAG,CAACN,GAAAA,CAAIQ,MAAM,EAAA,EAAIR,IAAIY,cAAc,EAAA,CAAA;AAC3C,YAAA,OAAO,IAAI;AACb,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -6,6 +6,10 @@ var compose = require('koa-compose');
|
|
|
6
6
|
var middleware = require('./middleware.js');
|
|
7
7
|
var policy = require('./policy.js');
|
|
8
8
|
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var compose__default = /*#__PURE__*/_interopDefault(compose);
|
|
12
|
+
|
|
9
13
|
const getMethod = (route)=>{
|
|
10
14
|
return fp.trim(fp.toLower(route.method));
|
|
11
15
|
};
|
|
@@ -57,7 +61,7 @@ var createEndpointComposer = ((strapi)=>{
|
|
|
57
61
|
const path = getPath(route);
|
|
58
62
|
const middlewares = middleware.resolveRouteMiddlewares(route, strapi);
|
|
59
63
|
const action = getAction(route, strapi);
|
|
60
|
-
const routeHandler =
|
|
64
|
+
const routeHandler = compose__default.default([
|
|
61
65
|
createRouteInfoMiddleware(route),
|
|
62
66
|
authenticate,
|
|
63
67
|
authorize,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.js","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { createPolicicesMiddleware } from './policy';\n\nconst getMethod = (route: Core.Route) => {\n return trim(toLower(route.method)) as Lowercase<Core.Route['method']>;\n};\n\nconst getPath = (route: Core.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Core.Route): Core.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n // allow PolicyError as an exception to throw a publicly visible message in the API\n if (error instanceof errors.PolicyError) {\n throw error;\n }\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Core.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Core.Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Core.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n createPolicicesMiddleware(route, strapi),\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (\n name: string,\n { pluginName, apiName }: Core.RouteInfo,\n strapi: Core.Strapi\n) => {\n let ctrl: Core.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Core.Route, strapi: Core.Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":["getMethod","route","trim","toLower","method","getPath","path","createRouteInfoMiddleware","routeInfo","ctx","next","config","state","getAuthConfig","prop","createAuthorizeMiddleware","strapi","auth","authService","get","verify","error","errors","UnauthorizedError","unauthorized","ForbiddenError","PolicyError","forbidden","createAuthenticateMiddleware","authenticate","returnBodyMiddleware","values","isNil","body","authorize","router","middlewares","resolveRouteMiddlewares","action","getAction","routeHandler","compose","createPolicicesMiddleware","castArray","Error","message","getController","name","pluginName","apiName","ctrl","controller","plugin","extractHandlerParts","controllerName","slice","lastIndexOf","actionName","handler","info","type","Array","isArray","Symbol","for","push","bind"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compose-endpoint.js","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { createPolicicesMiddleware } from './policy';\n\nconst getMethod = (route: Core.Route) => {\n return trim(toLower(route.method)) as Lowercase<Core.Route['method']>;\n};\n\nconst getPath = (route: Core.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Core.Route): Core.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n // allow PolicyError as an exception to throw a publicly visible message in the API\n if (error instanceof errors.PolicyError) {\n throw error;\n }\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Core.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Core.Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Core.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n createPolicicesMiddleware(route, strapi),\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (\n name: string,\n { pluginName, apiName }: Core.RouteInfo,\n strapi: Core.Strapi\n) => {\n let ctrl: Core.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Core.Route, strapi: Core.Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":["getMethod","route","trim","toLower","method","getPath","path","createRouteInfoMiddleware","routeInfo","ctx","next","config","state","getAuthConfig","prop","createAuthorizeMiddleware","strapi","auth","authService","get","verify","error","errors","UnauthorizedError","unauthorized","ForbiddenError","PolicyError","forbidden","createAuthenticateMiddleware","authenticate","returnBodyMiddleware","values","isNil","body","authorize","router","middlewares","resolveRouteMiddlewares","action","getAction","routeHandler","compose","createPolicicesMiddleware","castArray","Error","message","getController","name","pluginName","apiName","ctrl","controller","plugin","extractHandlerParts","controllerName","slice","lastIndexOf","actionName","handler","info","type","Array","isArray","Symbol","for","push","bind"],"mappings":";;;;;;;;;;;;AASA,MAAMA,YAAY,CAACC,KAAAA,GAAAA;IACjB,OAAOC,OAAAA,CAAKC,UAAAA,CAAQF,KAAAA,CAAMG,MAAM,CAAA,CAAA;AAClC,CAAA;AAEA,MAAMC,OAAAA,GAAU,CAACJ,KAAAA,GAAsBC,OAAAA,CAAKD,MAAMK,IAAI,CAAA;AAEtD,MAAMC,yBAAAA,GACJ,CAACC,SAAAA,GACD,CAACC,GAAAA,EAAKC,IAAAA,GAAAA;AACJ,QAAA,MAAMT,KAAAA,GAAQ;AACZ,YAAA,GAAGO,SAAS;YACZG,MAAAA,EAAQH,SAAAA,CAAUG,MAAM,IAAI;AAC9B,SAAA;QAEAF,GAAAA,CAAIG,KAAK,CAACX,KAAK,GAAGA,KAAAA;QAClB,OAAOS,IAAAA,EAAAA;AACT,IAAA,CAAA;AAEF,MAAMG,gBAAgBC,OAAAA,CAAK,aAAA,CAAA;AAE3B,MAAMC,yBAAAA,GACJ,CAACC,MAAAA,GACD,OAAOP,GAAAA,EAAKC,IAAAA,GAAAA;AACV,QAAA,MAAM,EA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AACJ,OAAAA,CAAAA,IAAY,OAAOA,YAAY,UAAA,EAAY;QAC3D,OAAOA,OAAAA;AACT,IAAA;AAEA,IAAA,MAAM,EAAEJ,cAAc,EAAEG,UAAU,EAAE,GAAGJ,oBAAoBnD,OAAAA,CAAKwD,OAAAA,CAAAA,CAAAA;IAEhE,MAAMP,UAAAA,GAAaL,cAAcQ,cAAAA,EAAgB;AAAEN,QAAAA,UAAAA;AAAYC,QAAAA,OAAc,CAAA,EAAGjC,MAAAA,CAAAA;AAEhF,IAAA,IAAI,OAAOmC,UAAU,CAACM,UAAAA,CAAW,KAAK,UAAA,EAAY;AAChD,QAAA,MAAM,IAAIb,KAAAA,CAAM,CAAC,mBAAmB,EAAEc,OAAAA,CAAQ,CAAC,CAAC,CAAA;AAClD,IAAA;AAEA,IAAA,IAAIK,OAAOC,GAAG,CAAC,eAAeb,UAAU,CAACM,WAAW,EAAE;QACnDN,UAAU,CAACM,UAAAA,CAAmB,CAACM,MAAAA,CAAOC,GAAG,CAAC,UAAA,CAAA,CAAY,CAACC,IAAI,CAACL,IAAAA,CAAAA;IAC/D,CAAA,MAAO;QACJT,UAAU,CAACM,WAAW,CAASM,OAAOC,GAAG,CAAC,YAAY,GAAG;AAACJ,YAAAA;AAAK,SAAA;AAClE,IAAA;AAEA,IAAA,OAAOT,UAAU,CAACM,UAAAA,CAAW,CAACS,IAAI,CAACf,UAAAA,CAAAA;AACrC,CAAA;;;;"}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var http = require('http');
|
|
4
4
|
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var http__default = /*#__PURE__*/_interopDefault(http);
|
|
8
|
+
|
|
5
9
|
const createHTTPServer = (strapi, koaApp)=>{
|
|
6
10
|
const connections = new Set();
|
|
7
11
|
// lazy creation of the request listener
|
|
@@ -13,7 +17,7 @@ const createHTTPServer = (strapi, koaApp)=>{
|
|
|
13
17
|
return handler(req, res);
|
|
14
18
|
};
|
|
15
19
|
const options = strapi.config.get('server.http.serverOptions', {});
|
|
16
|
-
const server =
|
|
20
|
+
const server = http__default.default.createServer(options, listener);
|
|
17
21
|
server.on('connection', (connection)=>{
|
|
18
22
|
connections.add(connection);
|
|
19
23
|
connection.on('close', ()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.js","sources":["../../../src/services/server/http-server.ts"],"sourcesContent":["import http from 'http';\nimport type { Socket } from 'net';\nimport Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\nexport interface Server extends http.Server {\n destroy: () => Promise<void>;\n}\n\nconst createHTTPServer = (strapi: Core.Strapi, koaApp: Koa): Server => {\n const connections = new Set<Socket>();\n\n // lazy creation of the request listener\n let handler: http.RequestListener;\n const listener: http.RequestListener = function handleRequest(req, res) {\n if (!handler) {\n handler = koaApp.callback();\n }\n\n return handler(req, res);\n };\n\n const options = strapi.config.get<http.ServerOptions>('server.http.serverOptions', {});\n\n const server: http.Server = http.createServer(options, listener);\n\n server.on('connection', (connection) => {\n connections.add(connection);\n\n connection.on('close', () => {\n connections.delete(connection);\n });\n });\n\n // handle port in use cleanly\n server.on('error', (err) => {\n if ('code' in err && 'port' in err && err.code === 'EADDRINUSE') {\n return strapi.stopWithError(`The port ${err.port} is already used by another application.`);\n }\n\n strapi.log.error(err);\n });\n\n const destroy = async () => {\n for (const connection of connections) {\n connection.destroy();\n\n connections.delete(connection);\n }\n\n if (!server.listening) {\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n server.close((error) => {\n if (error) {\n reject(error);\n } else {\n resolve();\n }\n });\n });\n };\n\n return Object.assign(server, { destroy });\n};\n\nexport { createHTTPServer };\n"],"names":["createHTTPServer","strapi","koaApp","connections","Set","handler","listener","handleRequest","req","res","callback","options","config","get","server","http","createServer","on","connection","add","delete","err","code","stopWithError","port","log","error","destroy","listening","Promise","resolve","reject","close","Object","assign"],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-server.js","sources":["../../../src/services/server/http-server.ts"],"sourcesContent":["import http from 'http';\nimport type { Socket } from 'net';\nimport Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\nexport interface Server extends http.Server {\n destroy: () => Promise<void>;\n}\n\nconst createHTTPServer = (strapi: Core.Strapi, koaApp: Koa): Server => {\n const connections = new Set<Socket>();\n\n // lazy creation of the request listener\n let handler: http.RequestListener;\n const listener: http.RequestListener = function handleRequest(req, res) {\n if (!handler) {\n handler = koaApp.callback();\n }\n\n return handler(req, res);\n };\n\n const options = strapi.config.get<http.ServerOptions>('server.http.serverOptions', {});\n\n const server: http.Server = http.createServer(options, listener);\n\n server.on('connection', (connection) => {\n connections.add(connection);\n\n connection.on('close', () => {\n connections.delete(connection);\n });\n });\n\n // handle port in use cleanly\n server.on('error', (err) => {\n if ('code' in err && 'port' in err && err.code === 'EADDRINUSE') {\n return strapi.stopWithError(`The port ${err.port} is already used by another application.`);\n }\n\n strapi.log.error(err);\n });\n\n const destroy = async () => {\n for (const connection of connections) {\n connection.destroy();\n\n connections.delete(connection);\n }\n\n if (!server.listening) {\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n server.close((error) => {\n if (error) {\n reject(error);\n } else {\n resolve();\n }\n });\n });\n };\n\n return Object.assign(server, { destroy });\n};\n\nexport { createHTTPServer };\n"],"names":["createHTTPServer","strapi","koaApp","connections","Set","handler","listener","handleRequest","req","res","callback","options","config","get","server","http","createServer","on","connection","add","delete","err","code","stopWithError","port","log","error","destroy","listening","Promise","resolve","reject","close","Object","assign"],"mappings":";;;;;;;;AASA,MAAMA,gBAAAA,GAAmB,CAACC,MAAAA,EAAqBC,MAAAA,GAAAA;AAC7C,IAAA,MAAMC,cAAc,IAAIC,GAAAA,EAAAA;;IAGxB,IAAIC,OAAAA;AACJ,IAAA,MAAMC,QAAAA,GAAiC,SAASC,aAAAA,CAAcC,GAAG,EAAEC,GAAG,EAAA;AACpE,QAAA,IAAI,CAACJ,OAAAA,EAAS;A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AAO,IAAIC,OAAAA,CAAc,CAACC,OAAAA,EAASC,MAAAA,GAAAA;YACjCjB,MAAAA,CAAOkB,KAAK,CAAC,CAACN,KAAAA,GAAAA;AACZ,gBAAA,IAAIA,KAAAA,EAAO;oBACTK,MAAAA,CAAOL,KAAAA,CAAAA;gBACT,CAAA,MAAO;AACLI,oBAAAA,OAAAA,EAAAA;AACF,gBAAA;AACF,YAAA,CAAA,CAAA;AACF,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;IAEA,OAAOG,MAAAA,CAAOC,MAAM,CAACpB,MAAAA,EAAQ;AAAEa,QAAAA;AAAQ,KAAA,CAAA;AACzC;;;;"}
|
|
@@ -10,6 +10,10 @@ var registerMiddlewares = require('./register-middlewares.js');
|
|
|
10
10
|
var koa = require('./koa.js');
|
|
11
11
|
var requestContext = require('../request-context.js');
|
|
12
12
|
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var Router__default = /*#__PURE__*/_interopDefault(Router);
|
|
16
|
+
|
|
13
17
|
const healthCheck = async (ctx)=>{
|
|
14
18
|
ctx.set('strapi', 'You are so French!');
|
|
15
19
|
ctx.status = 204;
|
|
@@ -20,7 +24,7 @@ const createServer = (strapi)=>{
|
|
|
20
24
|
keys: strapi.config.get('server.app.keys')
|
|
21
25
|
});
|
|
22
26
|
app.use((ctx, next)=>requestContext.run(ctx, ()=>next()));
|
|
23
|
-
const router = new
|
|
27
|
+
const router = new Router__default.default();
|
|
24
28
|
const routeManager = routing.createRouteManager(strapi);
|
|
25
29
|
const httpServer$1 = httpServer.createHTTPServer(strapi, app);
|
|
26
30
|
const apis = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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":"
|
|
1
|
+
{"version":3,"file":"index.js","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,GAAAA,CAAIC,GAAG,CAAC,QAAA,EAAU,oBAAA,CAAA;AAClBD,IAAAA,GAAAA,CAAIE,MAAM,GAAG,GAAA;AACf,CAAA;AAEA,MAAMC,eAAe,CAACC,MAAAA,GAAAA;AACpB,IAAA,MAAMC,MAAMC,GAAAA,CAAa;AACvBC,QAAAA,KAAAA,EAAOH,MAAAA,CAAOI,MAAM,CAACC,GAAG,CAAC,kBAAA,CAAA;AACzBC,QAAAA,IAAAA,EAAMN,MAAAA,CAAOI,MAAM,CAACC,GAAG,CAAC,iBAAA;AAC1B,KAAA,CAAA;IAEAJ,GAAAA,CAAIM,GAAG,CAAC,CAACX,GAAAA,EAAKY,OAASC,cAAAA,CAAWC,GAAG,CAACd,GAAAA,EAAK,IAAMY,IAAAA,EAAAA,CAAAA,CAAAA;AAEjD,IAAA,MAAMG,SAAS,IAAIC,uBAAAA,EAAAA;AAEnB,IAAA,MAAMC,eAAeC,0BAAAA,CAAmBd,MAAAA,CAAAA;IAExC,MAAM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ates');
|
|
|
7
7
|
var statuses = require('statuses');
|
|
8
8
|
var errors = require('../errors.js');
|
|
9
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var Koa__default = /*#__PURE__*/_interopDefault(Koa);
|
|
13
|
+
var createError__default = /*#__PURE__*/_interopDefault(createError);
|
|
14
|
+
var delegate__default = /*#__PURE__*/_interopDefault(delegate);
|
|
15
|
+
var statuses__default = /*#__PURE__*/_interopDefault(statuses);
|
|
16
|
+
|
|
10
17
|
const addCustomMethods = (app)=>{
|
|
11
|
-
const delegator =
|
|
12
|
-
/* errors */
|
|
13
|
-
const name =
|
|
18
|
+
const delegator = delegate__default.default(app.context, 'response');
|
|
19
|
+
/* errors */ statuses__default.default.codes.filter((code)=>code >= 400 && code < 600).forEach((code)=>{
|
|
20
|
+
const name = statuses__default.default(code);
|
|
14
21
|
const camelCasedName = fp.camelCase(name);
|
|
15
22
|
app.response[camelCasedName] = function responseCode(message = name, details = {}) {
|
|
16
|
-
const httpError =
|
|
23
|
+
const httpError = createError__default.default(code, message, {
|
|
17
24
|
details
|
|
18
25
|
});
|
|
19
26
|
const { status, body } = errors.formatHttpError(httpError);
|
|
@@ -42,7 +49,7 @@ const addCustomMethods = (app)=>{
|
|
|
42
49
|
return app;
|
|
43
50
|
};
|
|
44
51
|
const createKoaApp = ({ proxy, keys })=>{
|
|
45
|
-
const app = new
|
|
52
|
+
const app = new Koa__default.default({
|
|
46
53
|
proxy
|
|
47
54
|
});
|
|
48
55
|
app.keys = keys;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"koa.js","sources":["../../../src/services/server/koa.ts"],"sourcesContent":["import { isNil, camelCase } from 'lodash/fp';\nimport Koa from 'koa';\nimport createError from 'http-errors';\nimport delegate from 'delegates';\nimport statuses from 'statuses';\nimport { formatHttpError } from '../errors';\n\ndeclare module 'koa' {\n interface BaseResponse {\n send: (data: any, status?: number) => void;\n created: (data: any) => void;\n deleted: (data: any) => void;\n _explicitStatus: boolean;\n [key: string]: (message: string, details?: unknown) => void;\n }\n}\n\nconst addCustomMethods = (app: Koa) => {\n const delegator = delegate(app.context, 'response');\n\n /* errors */\n statuses.codes\n .filter((code) => code >= 400 && code < 600)\n .forEach((code) => {\n const name = statuses(code);\n\n const camelCasedName = camelCase(name);\n app.response[camelCasedName] = function responseCode(message = name, details = {}) {\n const httpError = createError(code, message, { details });\n const { status, body } = formatHttpError(httpError);\n this.status = status;\n this.body = body;\n };\n delegator.method(camelCasedName);\n });\n\n /* send, created, deleted */\n app.response.send = function send(data, status = 200) {\n this.status = status;\n this.body = data;\n };\n\n app.response.created = function created(data) {\n this.status = 201;\n this.body = data;\n };\n\n app.response.deleted = function deleted(data) {\n if (isNil(data)) {\n this.status = 204;\n } else {\n this.status = 200;\n this.body = data;\n }\n };\n\n delegator.method('send').method('created').method('deleted');\n\n return app;\n};\n\nconst createKoaApp = ({ proxy, keys }: { proxy: boolean; keys: string[] }) => {\n const app = new Koa({ proxy });\n app.keys = keys;\n\n addCustomMethods(app);\n\n return app;\n};\n\nexport default createKoaApp;\n"],"names":["addCustomMethods","app","delegator","delegate","context","statuses","codes","filter","code","forEach","name","camelCasedName","camelCase","response","responseCode","message","details","httpError","createError","status","body","formatHttpError","method","send","data","created","deleted","isNil","createKoaApp","proxy","keys","Koa"],"mappings":"
|
|
1
|
+
{"version":3,"file":"koa.js","sources":["../../../src/services/server/koa.ts"],"sourcesContent":["import { isNil, camelCase } from 'lodash/fp';\nimport Koa from 'koa';\nimport createError from 'http-errors';\nimport delegate from 'delegates';\nimport statuses from 'statuses';\nimport { formatHttpError } from '../errors';\n\ndeclare module 'koa' {\n interface BaseResponse {\n send: (data: any, status?: number) => void;\n created: (data: any) => void;\n deleted: (data: any) => void;\n _explicitStatus: boolean;\n [key: string]: (message: string, details?: unknown) => void;\n }\n}\n\nconst addCustomMethods = (app: Koa) => {\n const delegator = delegate(app.context, 'response');\n\n /* errors */\n statuses.codes\n .filter((code) => code >= 400 && code < 600)\n .forEach((code) => {\n const name = statuses(code);\n\n const camelCasedName = camelCase(name);\n app.response[camelCasedName] = function responseCode(message = name, details = {}) {\n const httpError = createError(code, message, { details });\n const { status, body } = formatHttpError(httpError);\n this.status = status;\n this.body = body;\n };\n delegator.method(camelCasedName);\n });\n\n /* send, created, deleted */\n app.response.send = function send(data, status = 200) {\n this.status = status;\n this.body = data;\n };\n\n app.response.created = function created(data) {\n this.status = 201;\n this.body = data;\n };\n\n app.response.deleted = function deleted(data) {\n if (isNil(data)) {\n this.status = 204;\n } else {\n this.status = 200;\n this.body = data;\n }\n };\n\n delegator.method('send').method('created').method('deleted');\n\n return app;\n};\n\nconst createKoaApp = ({ proxy, keys }: { proxy: boolean; keys: string[] }) => {\n const app = new Koa({ proxy });\n app.keys = keys;\n\n addCustomMethods(app);\n\n return app;\n};\n\nexport default createKoaApp;\n"],"names":["addCustomMethods","app","delegator","delegate","context","statuses","codes","filter","code","forEach","name","camelCasedName","camelCase","response","responseCode","message","details","httpError","createError","status","body","formatHttpError","method","send","data","created","deleted","isNil","createKoaApp","proxy","keys","Koa"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAMA,mBAAmB,CAACC,GAAAA,GAAAA;AACxB,IAAA,MAAMC,SAAAA,GAAYC,yBAAAA,CAASF,GAAAA,CAAIG,OAAO,EAAE,UAAA,CAAA;AAExC,iBACAC,yBAAAA,CAASC,KAAK,CACXC,MAAM,CAAC,CAACC,IAAAA,GAASA,IAAAA,IAAQ,GAAA,IAAOA,IAAAA,GAAO,GAAA,CAAA,CACvCC,OAAO,CAAC,CAACD,IAAAA,GAAAA;AACR,QAAA,MAAME,OAAOL,yBAAAA,CAASG,IAAAA,CAAAA;AAEtB,QAAA,MAAMG,iBAAiBC,YAAAA,CAAUF,IAAAA,CAAAA;QACjCT,GAAAA,CAAIY,QAAQ,CAACF,cAAAA,CAAe,GAAG,SAASG,YAAAA,CAAaC,OAAAA,GAAUL,IAAI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C,EAAEC,KAAK,EAAEC,IAAI,EAAsC,GAAA;IACvE,MAAM7B,GAAAA,GAAM,IAAI8B,oBAAAA,CAAI;AAAEF,QAAAA;AAAM,KAAA,CAAA;AAC5B5B,IAAAA,GAAAA,CAAI6B,IAAI,GAAGA,IAAAA;IAEX9B,gBAAAA,CAAiBC,GAAAA,CAAAA;IAEjB,OAAOA,GAAAA;AACT;;;;"}
|
|
@@ -4,6 +4,10 @@ var path = require('path');
|
|
|
4
4
|
var fp = require('lodash/fp');
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
+
|
|
7
11
|
const instantiateMiddleware = (middlewareFactory, name, config, strapi)=>{
|
|
8
12
|
try {
|
|
9
13
|
return middlewareFactory(config, {
|
|
@@ -79,7 +83,7 @@ const dummyMiddleware = (_, next)=>next();
|
|
|
79
83
|
modulePath = require.resolve(resolve);
|
|
80
84
|
} catch (error) {
|
|
81
85
|
if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {
|
|
82
|
-
modulePath =
|
|
86
|
+
modulePath = path__default.default.resolve(strapi.dirs.dist.root, resolve);
|
|
83
87
|
} else {
|
|
84
88
|
throw error;
|
|
85
89
|
}
|
|
@@ -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":"
|
|
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,qBAAAA,GA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AAA,CAAA;AAEA,gBAAA;AACF,YAAA;AAEA,YAAA,MAAM,IAAIV,KAAAA,CAAM,uEAAA,CAAA;AAClB,QAAA;AAEA,QAAA,MAAM,IAAIA,KAAAA,CACR,wGAAA,CAAA;AAEJ,IAAA;IAEA,OAAOK,WAAAA;AACT;AAEA;;IAGA,MAAMa,uBAAAA,GAA0B,CAACF,OAAAA,EAAiBlB,MAAAA,GAAAA;IAChD,IAAIqB,UAAAA;IAEJ,IAAI;QACFA,UAAAA,GAAaC,OAAAA,CAAQJ,OAAO,CAACA,OAAAA,CAAAA;AAC/B,IAAA,CAAA,CAAE,OAAOK,KAAAA,EAAO;AACd,QAAA,IAAIA,iBAAiBrB,KAAAA,IAAS,MAAA,IAAUqB,SAASA,KAAAA,CAAMC,IAAI,KAAK,kBAAA,EAAoB;YAClFH,UAAAA,GAAaI,qBAAAA,CAAKP,OAAO,CAAClB,MAAAA,CAAO0B,IAAI,CAACC,IAAI,CAACC,IAAI,EAAEV,OAAAA,CAAAA;QACnD,CAAA,MAAO;YACL,MAAMK,KAAAA;AACR,QAAA;AACF,IAAA;IAEA,IAAI;AACF,QAAA,OAAOM,yBAAAA,CAAcR,UAAAA,CAAAA;AACvB,IAAA,CAAA,CAAE,OAAOS,GAAAA,EAAK;AACZ,QAAA,MAAM,IAAI5B,KAAAA,CAAM,CAAC,2BAA2B,EAAEmB,UAAAA,CAAW,EAAE,CAAC,CAAA;AAC9D,IAAA;AACF,CAAA;;;;;"}
|
|
@@ -4,7 +4,10 @@ var path = require('path');
|
|
|
4
4
|
var fse = require('fs-extra');
|
|
5
5
|
var openapi = require('@strapi/openapi');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
8
11
|
var n = Object.create(null);
|
|
9
12
|
if (e) {
|
|
10
13
|
Object.keys(e).forEach(function (k) {
|
|
@@ -21,7 +24,9 @@ function _interopNamespaceDefault(e) {
|
|
|
21
24
|
return Object.freeze(n);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
var
|
|
27
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
28
|
+
var fse__default = /*#__PURE__*/_interopDefault(fse);
|
|
29
|
+
var openapi__namespace = /*#__PURE__*/_interopNamespace(openapi);
|
|
25
30
|
|
|
26
31
|
const SUPPORTED_ACCESS = {
|
|
27
32
|
'content-api': [
|
|
@@ -86,7 +91,7 @@ const resolveEndpointConfig = (strapi, rawConfig, type)=>{
|
|
|
86
91
|
const cacheEnabled = rawConfig?.cache?.enabled ?? DEFAULTS.cacheEnabled;
|
|
87
92
|
const cacheMaxAgeMs = rawConfig?.cache?.maxAgeMs ?? DEFAULTS.cacheMaxAgeMs;
|
|
88
93
|
const configuredCachePath = rawConfig?.cache?.filePath ?? DEFAULTS.cacheRelativeFilePaths[type];
|
|
89
|
-
const absoluteCachePath =
|
|
94
|
+
const absoluteCachePath = path__default.default.isAbsolute(configuredCachePath) ? configuredCachePath : path__default.default.resolve(strapi.dirs.app.root, configuredCachePath);
|
|
90
95
|
return {
|
|
91
96
|
type,
|
|
92
97
|
access,
|
|
@@ -130,18 +135,18 @@ const readCache = async (cachePath, maxAgeMs)=>{
|
|
|
130
135
|
return null;
|
|
131
136
|
}
|
|
132
137
|
try {
|
|
133
|
-
const stat = await
|
|
138
|
+
const stat = await fse__default.default.stat(cachePath);
|
|
134
139
|
const ageMs = Date.now() - stat.mtimeMs;
|
|
135
140
|
if (ageMs > maxAgeMs) {
|
|
136
141
|
return null;
|
|
137
142
|
}
|
|
138
|
-
return await
|
|
143
|
+
return await fse__default.default.readJson(cachePath);
|
|
139
144
|
} catch {
|
|
140
145
|
return null;
|
|
141
146
|
}
|
|
142
147
|
};
|
|
143
148
|
const writeCache = async (cachePath, document)=>{
|
|
144
|
-
await
|
|
149
|
+
await fse__default.default.outputJson(cachePath, document, {
|
|
145
150
|
spaces: 2
|
|
146
151
|
});
|
|
147
152
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","sources":["../../../src/services/server/openapi.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport * as openapi from '@strapi/openapi';\nimport type { Core } from '@strapi/types';\n\ntype OpenAPIConfig = Core.Config.OpenAPI;\ntype OpenAPIRouteType = keyof OpenAPIConfig;\ntype OpenAPIEndpointConfig = NonNullable<OpenAPIConfig[OpenAPIRouteType]>;\ntype OpenAPIAccess =\n | NonNullable<NonNullable<OpenAPIConfig['content-api']>['access']>\n | NonNullable<NonNullable<OpenAPIConfig['admin']>['access']>;\n\nconst SUPPORTED_ACCESS = {\n 'content-api': ['disabled', 'public'],\n admin: ['disabled', 'authenticated'],\n} as const satisfies Record<OpenAPIRouteType, readonly OpenAPIAccess[]>;\n\ninterface ResolvedEndpointConfig {\n type: OpenAPIRouteType;\n access: OpenAPIAccess;\n routePath: string;\n routerPrefix?: string;\n fullPath: string;\n cacheEnabled: boolean;\n cacheMaxAgeMs: number;\n absoluteCachePath: string;\n}\n\nconst DEFAULTS = {\n routePath: '/openapi.json',\n access: 'disabled' as const,\n cacheEnabled: true,\n cacheMaxAgeMs: 60_000,\n cacheRelativeFilePaths: {\n 'content-api': '.strapi/openapi/content-api.json',\n admin: '.strapi/openapi/admin.json',\n } as Record<OpenAPIRouteType, string>,\n};\n\nconst normalizePath = (value: string) => {\n if (!value) {\n return DEFAULTS.routePath;\n }\n\n return value.startsWith('/') ? value : `/${value}`;\n};\n\nconst joinPaths = (basePath: string, routePath: string) => {\n const normalizedBasePath = normalizePath(basePath || '/');\n const normalizedRoutePath = normalizePath(routePath || DEFAULTS.routePath);\n\n const trimmedBasePath = normalizedBasePath === '/' ? '' : normalizedBasePath.replace(/\\/+$/, '');\n\n return `${trimmedBasePath}${normalizedRoutePath}` || '/';\n};\n\nconst stripBasePrefix = (routePath: string, basePath: string) => {\n const normalizedBasePath = normalizePath(basePath || '/');\n const normalizedRoutePath = normalizePath(routePath || DEFAULTS.routePath);\n\n if (normalizedBasePath === '/') {\n return normalizedRoutePath;\n }\n\n if (normalizedRoutePath === normalizedBasePath) {\n return '/';\n }\n\n if (normalizedRoutePath.startsWith(`${normalizedBasePath}/`)) {\n const strippedPath = normalizedRoutePath.slice(normalizedBasePath.length);\n return normalizePath(strippedPath);\n }\n\n return normalizedRoutePath;\n};\n\nconst resolveEndpointConfig = (\n strapi: Core.Strapi,\n rawConfig: OpenAPIEndpointConfig | undefined,\n type: OpenAPIRouteType\n): ResolvedEndpointConfig => {\n const apiPrefix = strapi.config.get('api.rest.prefix', '/api');\n const adminPath = strapi.config.get('admin.path', '/admin');\n const basePath = type === 'content-api' ? apiPrefix : adminPath;\n\n const configuredPath = rawConfig?.route?.path ?? DEFAULTS.routePath;\n const routePath = stripBasePrefix(configuredPath, basePath);\n const routerPrefix = type === 'admin' ? normalizePath(basePath) : undefined;\n const fullPath =\n type === 'content-api'\n ? joinPaths(normalizePath(apiPrefix), routePath)\n : joinPaths(routerPrefix!, routePath);\n const access = rawConfig?.access ?? DEFAULTS.access;\n const supportedAccess = SUPPORTED_ACCESS[type];\n\n if (!(supportedAccess as readonly OpenAPIAccess[]).includes(access)) {\n throw new Error(\n `Invalid OpenAPI access \"${access}\" for \"${type}\". Expected one of: ${supportedAccess.join(', ')}`\n );\n }\n\n const cacheEnabled = rawConfig?.cache?.enabled ?? DEFAULTS.cacheEnabled;\n const cacheMaxAgeMs = rawConfig?.cache?.maxAgeMs ?? DEFAULTS.cacheMaxAgeMs;\n const configuredCachePath = rawConfig?.cache?.filePath ?? DEFAULTS.cacheRelativeFilePaths[type];\n const absoluteCachePath = path.isAbsolute(configuredCachePath)\n ? configuredCachePath\n : path.resolve(strapi.dirs.app.root, configuredCachePath);\n\n return {\n type,\n access,\n routePath,\n routerPrefix,\n fullPath,\n cacheEnabled,\n cacheMaxAgeMs,\n absoluteCachePath,\n };\n};\n\n/**\n * Build the route `config` (auth + policies) for an endpoint.\n *\n * - `admin`: requires an authenticated admin via the `admin::isAuthenticatedAdmin`\n * policy.\n * Granular per-permission RBAC is intentionally left for a later iteration.\n * - `content-api`: only supports public access for now, which disables auth so\n * anyone can read the spec.\n */\nconst buildRouteConfig = (config: ResolvedEndpointConfig): Record<string, unknown> => {\n if (config.type === 'admin') {\n return { policies: ['admin::isAuthenticatedAdmin'] };\n }\n\n return { auth: false };\n};\n\nconst resolveOpenAPIConfig = (strapi: Core.Strapi) => {\n const rawConfig = strapi.config.get('server.openapi', {}) as OpenAPIConfig;\n\n return [\n resolveEndpointConfig(strapi, rawConfig['content-api'], 'content-api'),\n resolveEndpointConfig(strapi, rawConfig.admin, 'admin'),\n ].filter((config) => config.access !== 'disabled');\n};\n\nconst readCache = async (cachePath: string, maxAgeMs: number) => {\n if (maxAgeMs < 0) {\n return null;\n }\n\n try {\n const stat = await fs.stat(cachePath);\n const ageMs = Date.now() - stat.mtimeMs;\n\n if (ageMs > maxAgeMs) {\n return null;\n }\n\n return await fs.readJson(cachePath);\n } catch {\n return null;\n }\n};\n\nconst writeCache = async (cachePath: string, document: unknown) => {\n await fs.outputJson(cachePath, document, { spaces: 2 });\n};\n\nconst generateDocument = (strapi: Core.Strapi, type: OpenAPIRouteType) => {\n return openapi.generate(strapi, { type }).document;\n};\n\nexport const registerOpenAPIRoute = (strapi: Core.Strapi) => {\n const configs = resolveOpenAPIConfig(strapi);\n\n if (!configs.length) {\n return;\n }\n\n const fullPathSet = new Set<string>();\n\n for (const config of configs) {\n if (fullPathSet.has(config.fullPath)) {\n throw new Error(`Duplicate OpenAPI endpoint path detected: \"${config.fullPath}\"`);\n }\n\n fullPathSet.add(config.fullPath);\n }\n\n const routers = configs.map((config) => {\n const handler: Core.MiddlewareHandler = async (ctx) => {\n try {\n if (config.cacheEnabled) {\n const cachedDocument = await readCache(config.absoluteCachePath, config.cacheMaxAgeMs);\n\n if (cachedDocument) {\n ctx.set('Content-Type', 'application/json');\n ctx.body = cachedDocument;\n return;\n }\n }\n\n const document = generateDocument(strapi, config.type);\n\n if (config.cacheEnabled) {\n await writeCache(config.absoluteCachePath, document);\n }\n\n ctx.set('Content-Type', 'application/json');\n ctx.body = document;\n } catch (error) {\n strapi.log.error(error);\n ctx.internalServerError('Failed to generate OpenAPI document');\n }\n };\n\n return {\n type: config.type,\n ...(config.routerPrefix ? { prefix: config.routerPrefix } : {}),\n routes: [\n {\n method: 'GET' as const,\n path: config.routePath,\n handler,\n info: {\n type: config.type,\n },\n config: buildRouteConfig(config),\n },\n ],\n };\n });\n\n routers.forEach((router) => strapi.server.routes(router));\n};\n"],"names":["SUPPORTED_ACCESS","admin","DEFAULTS","routePath","access","cacheEnabled","cacheMaxAgeMs","cacheRelativeFilePaths","normalizePath","value","startsWith","joinPaths","basePath","normalizedBasePath","normalizedRoutePath","trimmedBasePath","replace","stripBasePrefix","strippedPath","slice","length","resolveEndpointConfig","strapi","rawConfig","type","apiPrefix","config","get","adminPath","configuredPath","route","path","routerPrefix","undefined","fullPath","supportedAccess","includes","Error","join","cache","enabled","maxAgeMs","configuredCachePath","filePath","absoluteCachePath","isAbsolute","resolve","dirs","app","root","buildRouteConfig","policies","auth","resolveOpenAPIConfig","filter","readCache","cachePath","stat","fs","ageMs","Date","now","mtimeMs","readJson","writeCache","document","outputJson","spaces","generateDocument","openapi","generate","registerOpenAPIRoute","configs","fullPathSet","Set","has","add","routers","map","handler","ctx","cachedDocument","set","body","error","log","internalServerError","prefix","routes","method","info","forEach","router","server"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAMA,gBAAAA,GAAmB;IACvB,aAAA,EAAe;AAAC,QAAA,UAAA;AAAY,QAAA;AAAS,KAAA;IACrCC,KAAAA,EAAO;AAAC,QAAA,UAAA;AAAY,QAAA;AAAgB;AACtC,CAAA;AAaA,MAAMC,QAAAA,GAAW;IACfC,SAAAA,EAAW,eAAA;IACXC,MAAAA,EAAQ,UAAA;IACRC,YAA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YAAA,CAAA,CAAE,OAAOmB,KAAAA,EAAO;gBACd9D,MAAAA,CAAO+D,GAAG,CAACD,KAAK,CAACA,KAAAA,CAAAA;AACjBJ,gBAAAA,GAAAA,CAAIM,mBAAmB,CAAC,qCAAA,CAAA;AAC1B,YAAA;AACF,QAAA,CAAA;QAEA,OAAO;AACL9D,YAAAA,IAAAA,EAAME,OAAOF,IAAI;YACjB,GAAIE,MAAAA,CAAOM,YAAY,GAAG;AAAEuD,gBAAAA,MAAAA,EAAQ7D,OAAOM;AAAa,aAAA,GAAI,EAAE;YAC9DwD,MAAAA,EAAQ;AACN,gBAAA;oBACEC,MAAAA,EAAQ,KAAA;AACR1D,oBAAAA,IAAAA,EAAML,OAAOvB,SAAS;AACtB4E,oBAAAA,OAAAA;oBACAW,IAAAA,EAAM;AACJlE,wBAAAA,IAAAA,EAAME,OAAOF;AACf,qBAAA;AACAE,oBAAAA,MAAAA,EAAQwB,gBAAAA,CAAiBxB,MAAAA;AAC3B;AACD;AACH,SAAA;AACF,IAAA,CAAA,CAAA;IAEAmD,OAAAA,CAAQc,OAAO,CAAC,CAACC,MAAAA,GAAWtE,OAAOuE,MAAM,CAACL,MAAM,CAACI,MAAAA,CAAAA,CAAAA;AACnD;;;;"}
|
|
1
|
+
{"version":3,"file":"openapi.js","sources":["../../../src/services/server/openapi.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport * as openapi from '@strapi/openapi';\nimport type { Core } from '@strapi/types';\n\ntype OpenAPIConfig = Core.Config.OpenAPI;\ntype OpenAPIRouteType = keyof OpenAPIConfig;\ntype OpenAPIEndpointConfig = NonNullable<OpenAPIConfig[OpenAPIRouteType]>;\ntype OpenAPIAccess =\n | NonNullable<NonNullable<OpenAPIConfig['content-api']>['access']>\n | NonNullable<NonNullable<OpenAPIConfig['admin']>['access']>;\n\nconst SUPPORTED_ACCESS = {\n 'content-api': ['disabled', 'public'],\n admin: ['disabled', 'authenticated'],\n} as const satisfies Record<OpenAPIRouteType, readonly OpenAPIAccess[]>;\n\ninterface ResolvedEndpointConfig {\n type: OpenAPIRouteType;\n access: OpenAPIAccess;\n routePath: string;\n routerPrefix?: string;\n fullPath: string;\n cacheEnabled: boolean;\n cacheMaxAgeMs: number;\n absoluteCachePath: string;\n}\n\nconst DEFAULTS = {\n routePath: '/openapi.json',\n access: 'disabled' as const,\n cacheEnabled: true,\n cacheMaxAgeMs: 60_000,\n cacheRelativeFilePaths: {\n 'content-api': '.strapi/openapi/content-api.json',\n admin: '.strapi/openapi/admin.json',\n } as Record<OpenAPIRouteType, string>,\n};\n\nconst normalizePath = (value: string) => {\n if (!value) {\n return DEFAULTS.routePath;\n }\n\n return value.startsWith('/') ? value : `/${value}`;\n};\n\nconst joinPaths = (basePath: string, routePath: string) => {\n const normalizedBasePath = normalizePath(basePath || '/');\n const normalizedRoutePath = normalizePath(routePath || DEFAULTS.routePath);\n\n const trimmedBasePath = normalizedBasePath === '/' ? '' : normalizedBasePath.replace(/\\/+$/, '');\n\n return `${trimmedBasePath}${normalizedRoutePath}` || '/';\n};\n\nconst stripBasePrefix = (routePath: string, basePath: string) => {\n const normalizedBasePath = normalizePath(basePath || '/');\n const normalizedRoutePath = normalizePath(routePath || DEFAULTS.routePath);\n\n if (normalizedBasePath === '/') {\n return normalizedRoutePath;\n }\n\n if (normalizedRoutePath === normalizedBasePath) {\n return '/';\n }\n\n if (normalizedRoutePath.startsWith(`${normalizedBasePath}/`)) {\n const strippedPath = normalizedRoutePath.slice(normalizedBasePath.length);\n return normalizePath(strippedPath);\n }\n\n return normalizedRoutePath;\n};\n\nconst resolveEndpointConfig = (\n strapi: Core.Strapi,\n rawConfig: OpenAPIEndpointConfig | undefined,\n type: OpenAPIRouteType\n): ResolvedEndpointConfig => {\n const apiPrefix = strapi.config.get('api.rest.prefix', '/api');\n const adminPath = strapi.config.get('admin.path', '/admin');\n const basePath = type === 'content-api' ? apiPrefix : adminPath;\n\n const configuredPath = rawConfig?.route?.path ?? DEFAULTS.routePath;\n const routePath = stripBasePrefix(configuredPath, basePath);\n const routerPrefix = type === 'admin' ? normalizePath(basePath) : undefined;\n const fullPath =\n type === 'content-api'\n ? joinPaths(normalizePath(apiPrefix), routePath)\n : joinPaths(routerPrefix!, routePath);\n const access = rawConfig?.access ?? DEFAULTS.access;\n const supportedAccess = SUPPORTED_ACCESS[type];\n\n if (!(supportedAccess as readonly OpenAPIAccess[]).includes(access)) {\n throw new Error(\n `Invalid OpenAPI access \"${access}\" for \"${type}\". Expected one of: ${supportedAccess.join(', ')}`\n );\n }\n\n const cacheEnabled = rawConfig?.cache?.enabled ?? DEFAULTS.cacheEnabled;\n const cacheMaxAgeMs = rawConfig?.cache?.maxAgeMs ?? DEFAULTS.cacheMaxAgeMs;\n const configuredCachePath = rawConfig?.cache?.filePath ?? DEFAULTS.cacheRelativeFilePaths[type];\n const absoluteCachePath = path.isAbsolute(configuredCachePath)\n ? configuredCachePath\n : path.resolve(strapi.dirs.app.root, configuredCachePath);\n\n return {\n type,\n access,\n routePath,\n routerPrefix,\n fullPath,\n cacheEnabled,\n cacheMaxAgeMs,\n absoluteCachePath,\n };\n};\n\n/**\n * Build the route `config` (auth + policies) for an endpoint.\n *\n * - `admin`: requires an authenticated admin via the `admin::isAuthenticatedAdmin`\n * policy.\n * Granular per-permission RBAC is intentionally left for a later iteration.\n * - `content-api`: only supports public access for now, which disables auth so\n * anyone can read the spec.\n */\nconst buildRouteConfig = (config: ResolvedEndpointConfig): Record<string, unknown> => {\n if (config.type === 'admin') {\n return { policies: ['admin::isAuthenticatedAdmin'] };\n }\n\n return { auth: false };\n};\n\nconst resolveOpenAPIConfig = (strapi: Core.Strapi) => {\n const rawConfig = strapi.config.get('server.openapi', {}) as OpenAPIConfig;\n\n return [\n resolveEndpointConfig(strapi, rawConfig['content-api'], 'content-api'),\n resolveEndpointConfig(strapi, rawConfig.admin, 'admin'),\n ].filter((config) => config.access !== 'disabled');\n};\n\nconst readCache = async (cachePath: string, maxAgeMs: number) => {\n if (maxAgeMs < 0) {\n return null;\n }\n\n try {\n const stat = await fs.stat(cachePath);\n const ageMs = Date.now() - stat.mtimeMs;\n\n if (ageMs > maxAgeMs) {\n return null;\n }\n\n return await fs.readJson(cachePath);\n } catch {\n return null;\n }\n};\n\nconst writeCache = async (cachePath: string, document: unknown) => {\n await fs.outputJson(cachePath, document, { spaces: 2 });\n};\n\nconst generateDocument = (strapi: Core.Strapi, type: OpenAPIRouteType) => {\n return openapi.generate(strapi, { type }).document;\n};\n\nexport const registerOpenAPIRoute = (strapi: Core.Strapi) => {\n const configs = resolveOpenAPIConfig(strapi);\n\n if (!configs.length) {\n return;\n }\n\n const fullPathSet = new Set<string>();\n\n for (const config of configs) {\n if (fullPathSet.has(config.fullPath)) {\n throw new Error(`Duplicate OpenAPI endpoint path detected: \"${config.fullPath}\"`);\n }\n\n fullPathSet.add(config.fullPath);\n }\n\n const routers = configs.map((config) => {\n const handler: Core.MiddlewareHandler = async (ctx) => {\n try {\n if (config.cacheEnabled) {\n const cachedDocument = await readCache(config.absoluteCachePath, config.cacheMaxAgeMs);\n\n if (cachedDocument) {\n ctx.set('Content-Type', 'application/json');\n ctx.body = cachedDocument;\n return;\n }\n }\n\n const document = generateDocument(strapi, config.type);\n\n if (config.cacheEnabled) {\n await writeCache(config.absoluteCachePath, document);\n }\n\n ctx.set('Content-Type', 'application/json');\n ctx.body = document;\n } catch (error) {\n strapi.log.error(error);\n ctx.internalServerError('Failed to generate OpenAPI document');\n }\n };\n\n return {\n type: config.type,\n ...(config.routerPrefix ? { prefix: config.routerPrefix } : {}),\n routes: [\n {\n method: 'GET' as const,\n path: config.routePath,\n handler,\n info: {\n type: config.type,\n },\n config: buildRouteConfig(config),\n },\n ],\n };\n });\n\n routers.forEach((router) => strapi.server.routes(router));\n};\n"],"names":["SUPPORTED_ACCESS","admin","DEFAULTS","routePath","access","cacheEnabled","cacheMaxAgeMs","cacheRelativeFilePaths","normalizePath","value","startsWith","joinPaths","basePath","normalizedBasePath","normalizedRoutePath","trimmedBasePath","replace","stripBasePrefix","strippedPath","slice","length","resolveEndpointConfig","strapi","rawConfig","type","apiPrefix","config","get","adminPath","configuredPath","route","path","routerPrefix","undefined","fullPath","supportedAccess","includes","Error","join","cache","enabled","maxAgeMs","configuredCachePath","filePath","absoluteCachePath","isAbsolute","resolve","dirs","app","root","buildRouteConfig","policies","auth","resolveOpenAPIConfig","filter","readCache","cachePath","stat","fs","ageMs","Date","now","mtimeMs","readJson","writeCache","document","outputJson","spaces","generateDocument","openapi","generate","registerOpenAPIRoute","configs","fullPathSet","Set","has","add","routers","map","handler","ctx","cachedDocument","set","body","error","log","internalServerError","prefix","routes","method","info","forEach","router","server"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAMA,gBAAAA,GAAmB;IACvB,aAAA,EAAe;AAAC,QAAA,UAAA;AAAY,QAAA;AAAS,KAAA;IACrCC,KAAAA,EAAO;AAAC,QAAA,UAAA;AAAY,QAAA;AAAgB;AACtC,CAAA;AAaA,MAAMC,QAAAA,GAAW;IACfC,SAAAA,EAAW,eAAA;IACXC,MAAAA,EAAQ,UAAA;IACRC,YAAAA,EAAc,IAAA;IACdC,aAAAA,EAAe,KAAA;IACfC,sBAAAA,EAAwB;QACtB,aAAA,EAAe,kCAAA;QACfN,KAAAA,EAAO;AACT;AACF,CAAA;AAEA,MAAMO,gBAAgB,CAACC,KAAAA,GAAAA;AACrB,IAAA,IAAI,CAACA,KAAAA,EAAO;AACV,QAAA,OAAOP,SAASC,SAAS;AAC3B,IAAA;IAEA,OAAOM,KAAAA,CAAMC,UAAU,CAAC,GAAA,CAAA,GAAOD,QAAQ,CAAC,CAAC,EAAEA,KAAAA,CAAAA,CAAO;AACpD,CAAA;AAEA,MAAME,SAAAA,GAAY,CAACC,QAAAA,EAAkBT,SAAAA,GAAAA;IACnC,MAAMU,kBAAAA,GAAqBL,cAAcI,QAAAA,IAAY,GAAA,CAAA;AACrD,IAAA,MAAME,mBAAAA,GAAsBN,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IAAAA,EAAME,OAAOF;AACf,qBAAA;AACAE,oBAAAA,MAAAA,EAAQwB,gBAAAA,CAAiBxB,MAAAA;AAC3B;AACD;AACH,SAAA;AACF,IAAA,CAAA,CAAA;IAEAmD,OAAAA,CAAQc,OAAO,CAAC,CAACC,MAAAA,GAAWtE,OAAOuE,MAAM,CAACL,MAAM,CAACI,MAAAA,CAAAA,CAAAA;AACnD;;;;"}
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var openapi = require('./openapi.js');
|
|
5
5
|
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
9
|
+
|
|
6
10
|
const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
7
11
|
const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;
|
|
8
12
|
if (typeof route.handler === 'string') {
|
|
9
|
-
|
|
13
|
+
___default.default.defaultsDeep(route, {
|
|
10
14
|
config: {
|
|
11
15
|
auth: {
|
|
12
16
|
scope: [
|
|
@@ -33,7 +37,7 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
33
37
|
// Instantiate function-like routers
|
|
34
38
|
// Mutate admin.routes in-place and make sure router factories are instantiated correctly
|
|
35
39
|
strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);
|
|
36
|
-
|
|
40
|
+
___default.default.forEach(strapi.admin.routes, (router)=>{
|
|
37
41
|
router.type = router.type || 'admin';
|
|
38
42
|
router.prefix = router.prefix || `/admin`;
|
|
39
43
|
router.routes.forEach((route)=>{
|
|
@@ -69,7 +73,7 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
69
73
|
// Instantiate function-like routers
|
|
70
74
|
// Mutate plugin.routes in-place and make sure router factories are instantiated correctly
|
|
71
75
|
plugin.routes = instantiateRouterInputs(plugin.routes, strapi);
|
|
72
|
-
|
|
76
|
+
___default.default.forEach(plugin.routes, (router)=>{
|
|
73
77
|
router.type = router.type ?? 'admin';
|
|
74
78
|
router.prefix = router.prefix ?? `/${pluginName}`;
|
|
75
79
|
router.routes.forEach((route)=>{
|
|
@@ -92,7 +96,7 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
92
96
|
const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);
|
|
93
97
|
// Mutate api.routes in-place and make sure router factories are instantiated correctly
|
|
94
98
|
api.routes = instantiateRouterInputs(api.routes, strapi);
|
|
95
|
-
|
|
99
|
+
___default.default.forEach(api.routes, (router)=>{
|
|
96
100
|
// TODO: remove once auth setup
|
|
97
101
|
// pass meta down to compose endpoint
|
|
98
102
|
router.type = 'content-api';
|
|
@@ -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';\nimport { registerOpenAPIRoute } from './openapi';\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 registerOpenAPIRoute(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 strapi.contentAPI.applyExtraParamsToRoutes(plugin.routes);\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 strapi.contentAPI.applyExtraParamsToRoutes(router.routes ?? []);\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 strapi.contentAPI.applyExtraParamsToRoutes(router.routes ?? []);\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","registerOpenAPIRoute","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","contentAPI","applyExtraParamsToRoutes","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\nimport { registerOpenAPIRoute } from './openapi';\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 registerOpenAPIRoute(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 strapi.contentAPI.applyExtraParamsToRoutes(plugin.routes);\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 strapi.contentAPI.applyExtraParamsToRoutes(router.routes ?? []);\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 strapi.contentAPI.applyExtraParamsToRoutes(router.routes ?? []);\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","registerOpenAPIRoute","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","contentAPI","applyExtraParamsToRoutes","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":";;;;;;;;;AAIA,MAAMA,yBAAAA,GAA4B,CAACC,SAAAA,GAAsB,CAACC,KAAAA,GAAAA;QACxD,MAAMC,MAAAA,GAASF,UAAUG,QAAQ,CAAC,QAAQH,SAAAA,GAAY,CAAA,EAAGA,SAAAA,CAAU,CAAC,CAAC;AAErE,QAAA,IAAI,OAAOC,KAAAA,CAAMG,OAAO,KAAK,QAAA,EAAU;YACrCC,kBAAAA,CAAEC,YAAY,CAACL,KAAAA,EAAO;gBACpBM,MAAAA,EAAQ;oBACNC,IAAAA,EAAM;wBACJC,KAAAA,EAAO;4BAAC,CAAA,EAAGR,KAAAA,CAAMG,OAAO,CAACM,UAAU,CAACR,UAAU,EAAA,GAAKA,MAAAA,CAAAA,EAASD,KAAAA,CAAMG,OAAO,CAAA;AAAG;AAC9E;AACF;AACF,aAAA,CAAA;AACF,QAAA;AACF,IAAA,CAAA;AAEA;;IAGA,wBAAe,CAAA,CAACO,MAAAA,GAAAA;IACdC,mBAAAA,CAAoBD,MAAAA,CAAAA;IACpBE,iBAAAA,CAAkBF,MAAAA,CAAAA;IAClBG,oBAAAA,CAAqBH,MAAAA,CAAAA;IACrBI,4BAAAA,CAAqBJ,MAAAA,CAAAA;AACvB,CAAA;AAEA;;;IAIA,MAAMC,sBAAsB,CAACD,MAAAA,GAAAA;AAC3B,IAAA,MAAMK,kBAAAA,GAAqBjB,yBA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GAAa,OAAOD,eAAAA,KAAoB,UAAA;QAE9C,OAAO;AAAE,YAAA,GAAGF,MAAM;YAAE,CAACC,GAAAA,GAAME,UAAAA,GAAaD,eAAAA,CAAgB;AAAE/B,gBAAAA;aAAO,CAAA,GAAK+B;AAAgB,SAAA;AACxF,IAAA,CAAA,EAAG,EAAC,CAAA;AACN,CAAA;;;;"}
|
|
@@ -5,6 +5,10 @@ var fp = require('lodash/fp');
|
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
|
6
6
|
var composeEndpoint = require('./compose-endpoint.js');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var Router__default = /*#__PURE__*/_interopDefault(Router);
|
|
11
|
+
|
|
8
12
|
const policyOrMiddlewareSchema = strapiUtils.yup.lazy((value)=>{
|
|
9
13
|
if (typeof value === 'string') {
|
|
10
14
|
return strapiUtils.yup.string().required();
|
|
@@ -90,7 +94,7 @@ const createRouteManager = (strapi, opts = {})=>{
|
|
|
90
94
|
if (Array.isArray(routes)) {
|
|
91
95
|
routes.forEach((route)=>createRoute(route, router));
|
|
92
96
|
} else if (routes.routes) {
|
|
93
|
-
const subRouter = new
|
|
97
|
+
const subRouter = new Router__default.default({
|
|
94
98
|
prefix: routes.prefix
|
|
95
99
|
});
|
|
96
100
|
routes.routes.forEach((route)=>{
|
|
@@ -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":"
|
|
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","allowedM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