@strapi/core 0.0.0-experimental.74f28e080f05b204d7a0feb2c141027a94e45782 → 0.0.0-experimental.75524da74c8427faada874289db9595b2831263a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +2 -1
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +2 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +2 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +2 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +3 -2
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +13 -3
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +13 -3
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/index.d.ts +4 -22
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +150 -8
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +131 -8
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +244 -0
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -0
- package/dist/core-api/routes/validation/attributes.js +560 -0
- package/dist/core-api/routes/validation/attributes.js.map +1 -0
- package/dist/core-api/routes/validation/attributes.mjs +521 -0
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -0
- package/dist/core-api/routes/validation/common.d.ts +105 -0
- package/dist/core-api/routes/validation/common.d.ts.map +1 -0
- package/dist/core-api/routes/validation/common.js +116 -0
- package/dist/core-api/routes/validation/common.js.map +1 -0
- package/dist/core-api/routes/validation/common.mjs +95 -0
- package/dist/core-api/routes/validation/common.mjs.map +1 -0
- package/dist/core-api/routes/validation/component.d.ts +34 -0
- package/dist/core-api/routes/validation/component.d.ts.map +1 -0
- package/dist/core-api/routes/validation/component.js +45 -0
- package/dist/core-api/routes/validation/component.js.map +1 -0
- package/dist/core-api/routes/validation/component.mjs +43 -0
- package/dist/core-api/routes/validation/component.mjs.map +1 -0
- package/dist/core-api/routes/validation/constants.d.ts +8 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -0
- package/dist/core-api/routes/validation/constants.js +18 -0
- package/dist/core-api/routes/validation/constants.js.map +1 -0
- package/dist/core-api/routes/validation/constants.mjs +16 -0
- package/dist/core-api/routes/validation/constants.mjs.map +1 -0
- package/dist/core-api/routes/validation/content-type.d.ts +128 -0
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -0
- package/dist/core-api/routes/validation/content-type.js +201 -0
- package/dist/core-api/routes/validation/content-type.js.map +1 -0
- package/dist/core-api/routes/validation/content-type.mjs +180 -0
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -0
- package/dist/core-api/routes/validation/index.d.ts +5 -0
- package/dist/core-api/routes/validation/index.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.d.ts +105 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.js +273 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +249 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
- package/dist/core-api/routes/validation/utils.d.ts +47 -0
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
- package/dist/core-api/routes/validation/utils.js +128 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +106 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +3 -0
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +3 -0
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/factories.d.ts +3 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +10 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +10 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts +9 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +39 -17
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +39 -18
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +14 -12
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +14 -12
- package/dist/package.json.mjs.map +1 -1
- package/dist/services/content-api/index.d.ts +1 -1
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +2 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +12 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +86 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +84 -0
- package/dist/services/content-source-maps.mjs.map +1 -0
- package/dist/services/document-service/components.d.ts +6 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +97 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +97 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +11 -4
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +12 -5
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +9 -8
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +9 -8
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -2
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -2
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/register-routes.js +22 -2
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +22 -2
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +10 -0
- package/dist/services/server/routing.d.ts.map +1 -1
- package/dist/services/server/routing.js +7 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs +7 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/package.json +14 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,SAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,gBAAgBD,GAAKJ,EAAAA,SAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,YAAAA,EAAc,EAAC;AACfC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEaC,MAAAA,YAAAA,GAAe,CAC1Bd,SAAAA,EACAe,SACAC,E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C/C,YAAA,OAAOF,qBAAqBc,QAAUZ,EAAAA,SAAAA,CAAAA;AACxC,SAAA;AACA4C,QAAAA,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO7B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE6C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAIhC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcG,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBe,WAAab,EAAAA,SAAAA,CAAAA;AAC3C,SAAA;AACA8C,QAAAA,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO/B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE+C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAItC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcO,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBW,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n set routes(routes: Record<string, Core.Router>) {\n rawModule.routes = routes;\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,SAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,gBAAgBD,GAAKJ,EAAAA,SAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,YAAAA,EAAc,EAAC;AACfC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEaC,MAAAA,YAAAA,GAAe,CAC1Bd,SAAAA,EACAe,SACAC,EAAAA,MAAAA,GAAAA;IAEAf,CAAEgB,CAAAA,QAAQ,CAACF,SAAWT,EAAAA,aAAAA,CAAAA;IAEtB,IAAI;QACFY,cAAeH,CAAAA,SAAAA,CAAAA;AACjB,KAAA,CAAE,OAAOI,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,GAAIC,CAAAA,eAAe,EAAE;AACpC,YAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,iCAAiC,EAAEtB,SAAU,CAAA,IAAI,EAAEmB,CAAAA,CAAEI,MAAM,CAACC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC3F;AACF;AAEA,IAAA,MAAMC,SAA0B,EAAC;IACjC,OAAO;QACL,MAAMC,SAAAA,CAAAA,GAAAA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AG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBe,WAAab,EAAAA,SAAAA,CAAAA;AAC3C,SAAA;AACA8C,QAAAA,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO/B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE+C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAItC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcO,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBW,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
package/dist/factories.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Core, UID, Utils } from '@strapi/types';
|
|
2
|
+
import { CoreContentTypeRouteValidator } from './core-api/routes/validation';
|
|
2
3
|
type WithStrapiCallback<T> = T | (<S extends {
|
|
3
4
|
strapi: Core.Strapi;
|
|
4
5
|
}>(params: S) => T);
|
|
@@ -9,6 +10,7 @@ declare function createCoreService<TUID extends UID.ContentType, TService extend
|
|
|
9
10
|
strapi: Core.Strapi;
|
|
10
11
|
}) => TService & Core.CoreAPI.Service.ContentType<TUID>;
|
|
11
12
|
declare function createCoreRouter<T extends UID.ContentType>(uid: T, cfg?: Core.CoreAPI.Router.RouterConfig<T>): Core.CoreAPI.Router.Router;
|
|
13
|
+
declare const createCoreValidator: <T extends UID.ContentType>(uid: T, strapi: Core.Strapi) => CoreContentTypeRouteValidator;
|
|
12
14
|
declare const isCustomController: <T extends Core.Controller>(controller: T) => boolean;
|
|
13
|
-
export { createCoreController, createCoreService, createCoreRouter, isCustomController };
|
|
15
|
+
export { createCoreController, createCoreService, createCoreRouter, createCoreValidator, isCustomController, };
|
|
14
16
|
//# sourceMappingURL=factories.d.ts.map
|
package/dist/factories.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAQ7E,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAEvF,QAAA,MAAM,oBAAoB,oGAInB,IAAI,QACH,mBACJ,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAC9E,mBAIE;IACD,MAAM,EAAE,KAAK,MAAM,CAAC;CACrB,KAAG,WAAW,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAwB3D,CAAC;AAEF,iBAAS,iBAAiB,CACxB,IAAI,SAAS,GAAG,CAAC,WAAW,EAC5B,QAAQ,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAEtD,GAAG,EAAE,IAAI,EACT,GAAG,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAI9F;IACD,MAAM,EAAE,KAAK,MAAM,CAAC;CACrB,KAAG,QAAQ,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CActD;AAED,iBAAS,gBAAgB,CAAC,CAAC,SAAS,GAAG,CAAC,WAAW,EACjD,GAAG,EAAE,CAAC,EACN,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,GACxC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CA+B5B;AAED,QAAA,MAAM,mBAAmB,mCAClB,CAAC,UACE,KAAK,MAAM,KAClB,6BAEF,CAAC;AAEF,QAAA,MAAM,kBAAkB,0CAA2C,CAAC,KAAG,OAEtE,CAAC;AAEF,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,CAAC"}
|
package/dist/factories.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var fp = require('lodash/fp');
|
|
4
4
|
var index = require('./core-api/controller/index.js');
|
|
5
|
+
require('@strapi/utils');
|
|
6
|
+
require('zod/v4');
|
|
7
|
+
var contentType = require('./core-api/routes/validation/content-type.js');
|
|
5
8
|
var index$1 = require('./core-api/service/index.js');
|
|
6
9
|
var index$2 = require('./core-api/routes/index.js');
|
|
7
10
|
|
|
@@ -60,12 +63,13 @@ function createCoreRouter(uid, cfg) {
|
|
|
60
63
|
if (!routes) {
|
|
61
64
|
const contentType = strapi.contentType(uid);
|
|
62
65
|
const defaultRoutes = index$2.createRoutes({
|
|
63
|
-
contentType
|
|
66
|
+
contentType,
|
|
67
|
+
strapi
|
|
64
68
|
});
|
|
65
69
|
const keys = Object.keys(defaultRoutes);
|
|
66
70
|
keys.forEach((routeName)=>{
|
|
67
71
|
const defaultRoute = defaultRoutes[routeName];
|
|
68
|
-
|
|
72
|
+
defaultRoute.config = config[routeName] ?? {};
|
|
69
73
|
});
|
|
70
74
|
const selectedRoutes = fp.pipe((routes)=>except ? fp.omit(except, routes) : routes, (routes)=>only ? fp.pick(only, routes) : routes)(defaultRoutes);
|
|
71
75
|
routes = Object.values(selectedRoutes);
|
|
@@ -74,6 +78,9 @@ function createCoreRouter(uid, cfg) {
|
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
80
|
}
|
|
81
|
+
const createCoreValidator = (uid, strapi1)=>{
|
|
82
|
+
return new contentType.CoreContentTypeRouteValidator(strapi1, uid);
|
|
83
|
+
};
|
|
77
84
|
const isCustomController = (controller)=>{
|
|
78
85
|
return symbols.CustomController in controller;
|
|
79
86
|
};
|
|
@@ -81,5 +88,6 @@ const isCustomController = (controller)=>{
|
|
|
81
88
|
exports.createCoreController = createCoreController;
|
|
82
89
|
exports.createCoreRouter = createCoreRouter;
|
|
83
90
|
exports.createCoreService = createCoreService;
|
|
91
|
+
exports.createCoreValidator = createCoreValidator;
|
|
84
92
|
exports.isCustomController = isCustomController;
|
|
85
93
|
//# sourceMappingURL=factories.js.map
|
package/dist/factories.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n
|
|
1
|
+
{"version":3,"file":"factories.js","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { CoreContentTypeRouteValidator } from './core-api/routes/validation';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType, strapi });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n defaultRoute.config = (config[routeName] ?? {}) as Core.RouteConfig;\n });\n\n const selectedRoutes = pipe(\n (routes) => (except ? omit(except, routes) : routes),\n (routes) => (only ? pick(only, routes) : routes)\n )(defaultRoutes);\n\n routes = Object.values(selectedRoutes);\n }\n\n return routes;\n },\n };\n}\n\nconst createCoreValidator = <T extends UID.ContentType>(\n uid: T,\n strapi: Core.Strapi\n): CoreContentTypeRouteValidator => {\n return new CoreContentTypeRouteValidator(strapi, uid);\n};\n\nconst isCustomController = <T extends Core.Controller>(controller: T): boolean => {\n return symbols.CustomController in controller;\n};\n\nexport {\n createCoreController,\n createCoreService,\n createCoreRouter,\n createCoreValidator,\n isCustomController,\n};\n"],"names":["symbols","CustomController","Symbol","createCoreController","uid","cfg","strapi","baseController","createController","contentType","userCtrl","methodName","Object","keys","undefined","setPrototypeOf","isCustom","defineProperty","writable","configurable","enumerable","createCoreService","baseService","createService","userService","createCoreRouter","prefix","config","only","except","type","routes","defaultRoutes","createRoutes","forEach","routeName","defaultRoute","selectedRoutes","pipe","omit","pick","values","createCoreValidator","CoreContentTypeRouteValidator","isCustomController","controller"],"mappings":";;;;;;;;;;AAQA,MAAMA,OAAU,GAAA;AACdC,IAAAA,gBAAAA,EAAkBC,MAAO,CAAA,4BAAA;AAC3B,CAAA;AAIMC,M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,iBAAA,CAAA;AAEA,gBAAA,MAAME,cAAiBC,GAAAA,OAAAA,CACrB,CAACP,MAAAA,GAAYF,SAASU,OAAKV,CAAAA,MAAAA,EAAQE,MAAUA,CAAAA,GAAAA,MAAAA,EAC7C,CAACA,MAAYH,GAAAA,IAAAA,GAAOY,OAAKZ,CAAAA,IAAAA,EAAMG,UAAUA,MACzCC,CAAAA,CAAAA,aAAAA,CAAAA;gBAEFD,MAASnB,GAAAA,MAAAA,CAAO6B,MAAM,CAACJ,cAAAA,CAAAA;AACzB;YAEA,OAAON,MAAAA;AACT;AACF,KAAA;AACF;AAEMW,MAAAA,mBAAAA,GAAsB,CAC1BtC,GACAE,EAAAA,OAAAA,GAAAA;IAEA,OAAO,IAAIqC,0CAA8BrC,OAAQF,EAAAA,GAAAA,CAAAA;AACnD;AAEA,MAAMwC,qBAAqB,CAA4BC,UAAAA,GAAAA;IACrD,OAAO7C,OAAAA,CAAQC,gBAAgB,IAAI4C,UAAAA;AACrC;;;;;;;;"}
|
package/dist/factories.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { pipe, omit, pick } from 'lodash/fp';
|
|
2
2
|
import { createController } from './core-api/controller/index.mjs';
|
|
3
|
+
import '@strapi/utils';
|
|
4
|
+
import 'zod/v4';
|
|
5
|
+
import { CoreContentTypeRouteValidator } from './core-api/routes/validation/content-type.mjs';
|
|
3
6
|
import { createService } from './core-api/service/index.mjs';
|
|
4
7
|
import { createRoutes } from './core-api/routes/index.mjs';
|
|
5
8
|
|
|
@@ -58,12 +61,13 @@ function createCoreRouter(uid, cfg) {
|
|
|
58
61
|
if (!routes) {
|
|
59
62
|
const contentType = strapi.contentType(uid);
|
|
60
63
|
const defaultRoutes = createRoutes({
|
|
61
|
-
contentType
|
|
64
|
+
contentType,
|
|
65
|
+
strapi
|
|
62
66
|
});
|
|
63
67
|
const keys = Object.keys(defaultRoutes);
|
|
64
68
|
keys.forEach((routeName)=>{
|
|
65
69
|
const defaultRoute = defaultRoutes[routeName];
|
|
66
|
-
|
|
70
|
+
defaultRoute.config = config[routeName] ?? {};
|
|
67
71
|
});
|
|
68
72
|
const selectedRoutes = pipe((routes)=>except ? omit(except, routes) : routes, (routes)=>only ? pick(only, routes) : routes)(defaultRoutes);
|
|
69
73
|
routes = Object.values(selectedRoutes);
|
|
@@ -72,9 +76,12 @@ function createCoreRouter(uid, cfg) {
|
|
|
72
76
|
}
|
|
73
77
|
};
|
|
74
78
|
}
|
|
79
|
+
const createCoreValidator = (uid, strapi1)=>{
|
|
80
|
+
return new CoreContentTypeRouteValidator(strapi1, uid);
|
|
81
|
+
};
|
|
75
82
|
const isCustomController = (controller)=>{
|
|
76
83
|
return symbols.CustomController in controller;
|
|
77
84
|
};
|
|
78
85
|
|
|
79
|
-
export { createCoreController, createCoreRouter, createCoreService, isCustomController };
|
|
86
|
+
export { createCoreController, createCoreRouter, createCoreService, createCoreValidator, isCustomController };
|
|
80
87
|
//# sourceMappingURL=factories.mjs.map
|
package/dist/factories.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.mjs","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n
|
|
1
|
+
{"version":3,"file":"factories.mjs","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { CoreContentTypeRouteValidator } from './core-api/routes/validation';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : (cfg ?? ({} as any));\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType, strapi });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n defaultRoute.config = (config[routeName] ?? {}) as Core.RouteConfig;\n });\n\n const selectedRoutes = pipe(\n (routes) => (except ? omit(except, routes) : routes),\n (routes) => (only ? pick(only, routes) : routes)\n )(defaultRoutes);\n\n routes = Object.values(selectedRoutes);\n }\n\n return routes;\n },\n };\n}\n\nconst createCoreValidator = <T extends UID.ContentType>(\n uid: T,\n strapi: Core.Strapi\n): CoreContentTypeRouteValidator => {\n return new CoreContentTypeRouteValidator(strapi, uid);\n};\n\nconst isCustomController = <T extends Core.Controller>(controller: T): boolean => {\n return symbols.CustomController in controller;\n};\n\nexport {\n createCoreController,\n createCoreService,\n createCoreRouter,\n createCoreValidator,\n isCustomController,\n};\n"],"names":["symbols","CustomController","Symbol","createCoreController","uid","cfg","strapi","baseController","createController","contentType","userCtrl","methodName","Object","keys","undefined","setPrototypeOf","isCustom","defineProperty","writable","configurable","enumerable","createCoreService","baseService","createService","userService","createCoreRouter","prefix","config","only","except","type","routes","defaultRoutes","createRoutes","forEach","routeName","defaultRoute","selectedRoutes","pipe","omit","pick","values","createCoreValidator","CoreContentTypeRouteValidator","isCustomController","controller"],"mappings":";;;;;;;;AAQA,MAAMA,OAAU,GAAA;AACdC,IAAAA,gBAAAA,EAAkBC,MAAO,CAAA,4BAAA;AAC3B,CAAA;AAIMC,MAAAA,oBAAAA,GAAuB,CAI3BC,GACAC,E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C,GAAAA,IAAAA,CACrB,CAACP,MAAAA,GAAYF,SAASU,IAAKV,CAAAA,MAAAA,EAAQE,MAAUA,CAAAA,GAAAA,MAAAA,EAC7C,CAACA,MAAYH,GAAAA,IAAAA,GAAOY,IAAKZ,CAAAA,IAAAA,EAAMG,UAAUA,MACzCC,CAAAA,CAAAA,aAAAA,CAAAA;gBAEFD,MAASnB,GAAAA,MAAAA,CAAO6B,MAAM,CAACJ,cAAAA,CAAAA;AACzB;YAEA,OAAON,MAAAA;AACT;AACF,KAAA;AACF;AAEMW,MAAAA,mBAAAA,GAAsB,CAC1BtC,GACAE,EAAAA,OAAAA,GAAAA;IAEA,OAAO,IAAIqC,8BAA8BrC,OAAQF,EAAAA,GAAAA,CAAAA;AACnD;AAEA,MAAMwC,qBAAqB,CAA4BC,UAAAA,GAAAA;IACrD,OAAO7C,OAAAA,CAAQC,gBAAgB,IAAI4C,UAAAA;AACrC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Core } from '@strapi/types';
|
|
2
2
|
export type Config = {
|
|
3
3
|
enabled?: boolean;
|
|
4
|
-
origin: string | string[] | ((ctx: any) => string | string[]);
|
|
4
|
+
origin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>);
|
|
5
5
|
expose?: string | string[];
|
|
6
6
|
maxAge?: number;
|
|
7
7
|
credentials?: boolean;
|
|
@@ -9,5 +9,13 @@ export type Config = {
|
|
|
9
9
|
headers?: string | string[];
|
|
10
10
|
keepHeadersOnError?: boolean;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Determines if a request origin is allowed based on the configured origin list
|
|
14
|
+
* @param requestOrigin - The origin from the request header
|
|
15
|
+
* @param configuredOrigin - The origin configuration (string, array, or function)
|
|
16
|
+
* @param ctx - The Koa context (for function-based origin)
|
|
17
|
+
* @returns The allowed origin string or empty string if blocked
|
|
18
|
+
*/
|
|
19
|
+
export declare const matchOrigin: (requestOrigin: string | undefined, configuredOrigin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>), ctx?: any) => Promise<string>;
|
|
12
20
|
export declare const cors: Core.MiddlewareFactory<Config>;
|
|
13
21
|
//# sourceMappingURL=cors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;IAC3F,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAWF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,kBACP,MAAM,GAAG,SAAS,oBAE7B,MAAM,GACN,MAAM,EAAE,GACR,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,QAAQ,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,QAC5D,GAAG,KACR,QAAQ,MAAM,CAgChB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CA0B/C,CAAC"}
|
package/dist/middlewares/cors.js
CHANGED
|
@@ -23,6 +23,42 @@ const defaults = {
|
|
|
23
23
|
],
|
|
24
24
|
keepHeadersOnError: false
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Determines if a request origin is allowed based on the configured origin list
|
|
28
|
+
* @param requestOrigin - The origin from the request header
|
|
29
|
+
* @param configuredOrigin - The origin configuration (string, array, or function)
|
|
30
|
+
* @param ctx - The Koa context (for function-based origin)
|
|
31
|
+
* @returns The allowed origin string or empty string if blocked
|
|
32
|
+
*/ const matchOrigin = async (requestOrigin, configuredOrigin, ctx)=>{
|
|
33
|
+
if (!requestOrigin) {
|
|
34
|
+
return '*';
|
|
35
|
+
}
|
|
36
|
+
let originList;
|
|
37
|
+
if (typeof configuredOrigin === 'function') {
|
|
38
|
+
originList = await configuredOrigin(ctx);
|
|
39
|
+
} else {
|
|
40
|
+
originList = configuredOrigin;
|
|
41
|
+
}
|
|
42
|
+
// Normalize originList into an array
|
|
43
|
+
let normalizedOrigins;
|
|
44
|
+
if (Array.isArray(originList)) {
|
|
45
|
+
normalizedOrigins = originList;
|
|
46
|
+
} else if (originList === undefined || originList === null) {
|
|
47
|
+
// Handle undefined/null - treat as wildcard
|
|
48
|
+
normalizedOrigins = [
|
|
49
|
+
'*'
|
|
50
|
+
];
|
|
51
|
+
} else {
|
|
52
|
+
// Handle comma-separated string of origins
|
|
53
|
+
normalizedOrigins = originList.split(',').map((origin)=>origin.trim());
|
|
54
|
+
}
|
|
55
|
+
// Check if wildcard is in the normalized origins
|
|
56
|
+
if (normalizedOrigins.includes('*')) {
|
|
57
|
+
return requestOrigin;
|
|
58
|
+
}
|
|
59
|
+
// Check if request origin is in the normalized origins
|
|
60
|
+
return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';
|
|
61
|
+
};
|
|
26
62
|
const cors = (config)=>{
|
|
27
63
|
const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {
|
|
28
64
|
...defaults,
|
|
@@ -33,23 +69,8 @@ const cors = (config)=>{
|
|
|
33
69
|
}
|
|
34
70
|
return koaCors({
|
|
35
71
|
async origin (ctx) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
let originList;
|
|
40
|
-
if (typeof origin === 'function') {
|
|
41
|
-
originList = await origin(ctx);
|
|
42
|
-
} else {
|
|
43
|
-
originList = origin;
|
|
44
|
-
}
|
|
45
|
-
if (Array.isArray(originList)) {
|
|
46
|
-
return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
|
|
47
|
-
}
|
|
48
|
-
const parsedOrigin = originList.split(',').map((origin)=>origin.trim());
|
|
49
|
-
if (parsedOrigin.length > 1) {
|
|
50
|
-
return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
|
|
51
|
-
}
|
|
52
|
-
return originList;
|
|
72
|
+
const requestOrigin = ctx.get('Origin');
|
|
73
|
+
return matchOrigin(requestOrigin, origin, ctx);
|
|
53
74
|
},
|
|
54
75
|
exposeHeaders: expose,
|
|
55
76
|
maxAge,
|
|
@@ -61,4 +82,5 @@ const cors = (config)=>{
|
|
|
61
82
|
};
|
|
62
83
|
|
|
63
84
|
exports.cors = cors;
|
|
85
|
+
exports.matchOrigin = matchOrigin;
|
|
64
86
|
//# sourceMappingURL=cors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\
|
|
1
|
+
{"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\n/**\n * Determines if a request origin is allowed based on the configured origin list\n * @param requestOrigin - The origin from the request header\n * @param configuredOrigin - The origin configuration (string, array, or function)\n * @param ctx - The Koa context (for function-based origin)\n * @returns The allowed origin string or empty string if blocked\n */\nexport const matchOrigin = async (\n requestOrigin: string | undefined,\n configuredOrigin:\n | string\n | string[]\n | ((ctx: any) => string | string[] | Promise<string | string[]>),\n ctx?: any\n): Promise<string> => {\n if (!requestOrigin) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof configuredOrigin === 'function') {\n originList = await configuredOrigin(ctx);\n } else {\n originList = configuredOrigin;\n }\n\n // Normalize originList into an array\n let normalizedOrigins: string[];\n if (Array.isArray(originList)) {\n normalizedOrigins = originList;\n } else if (originList === undefined || originList === null) {\n // Handle undefined/null - treat as wildcard\n normalizedOrigins = ['*'];\n } else {\n // Handle comma-separated string of origins\n normalizedOrigins = originList.split(',').map((origin) => origin.trim());\n }\n\n // Check if wildcard is in the normalized origins\n if (normalizedOrigins.includes('*')) {\n return requestOrigin;\n }\n\n // Check if request origin is in the normalized origins\n return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n const requestOrigin = ctx.get('Origin');\n return matchOrigin(requestOrigin, origin, ctx);\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["defaults","origin","maxAge","credentials","methods","headers","keepHeadersOnError","matchOrigin","requestOrigin","configuredOrigin","ctx","originList","normalizedOrigins","Array","isArray","undefined","split","map","trim","includes","cors","config","expose","enabled","strapi","log","warn","koaCors","get","exposeHeaders","allowMethods","allowHeaders"],"mappings":";;;;AAeA,MAAMA,QAAmB,GAAA;IACvBC,MAAQ,EAAA,GAAA;IACRC,MAAQ,EAAA,QAAA;IACRC,WAAa,EAAA,IAAA;IACbC,OAAS,EAAA;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA,MAAA;AAAQ,QAAA;AAAU,KAAA;IACrEC,OAAS,EAAA;AAAC,QAAA,cAAA;AAAgB,QAAA,eAAA;AAAiB,QAAA,QAAA;AAAU,QAAA;AAAS,KAAA;IAC9DC,kBAAoB,EAAA;AACtB,CAAA;AAEA;;;;;;AAMC,IACM,MAAMC,WAAc,GAAA,OACzBC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AA,OAAOC,OAAQ,CAAA;AACb,QAAA,MAAM1B,QAAOS,GAAG,EAAA;YACd,MAAMF,aAAAA,GAAgBE,GAAIkB,CAAAA,GAAG,CAAC,QAAA,CAAA;YAC9B,OAAOrB,WAAAA,CAAYC,eAAeP,MAAQS,EAAAA,GAAAA,CAAAA;AAC5C,SAAA;QACAmB,aAAeP,EAAAA,MAAAA;AACfpB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;QACA2B,YAAc1B,EAAAA,OAAAA;QACd2B,YAAc1B,EAAAA,OAAAA;AACdC,QAAAA;AACF,KAAA,CAAA;AACF;;;;;"}
|
|
@@ -21,6 +21,42 @@ const defaults = {
|
|
|
21
21
|
],
|
|
22
22
|
keepHeadersOnError: false
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Determines if a request origin is allowed based on the configured origin list
|
|
26
|
+
* @param requestOrigin - The origin from the request header
|
|
27
|
+
* @param configuredOrigin - The origin configuration (string, array, or function)
|
|
28
|
+
* @param ctx - The Koa context (for function-based origin)
|
|
29
|
+
* @returns The allowed origin string or empty string if blocked
|
|
30
|
+
*/ const matchOrigin = async (requestOrigin, configuredOrigin, ctx)=>{
|
|
31
|
+
if (!requestOrigin) {
|
|
32
|
+
return '*';
|
|
33
|
+
}
|
|
34
|
+
let originList;
|
|
35
|
+
if (typeof configuredOrigin === 'function') {
|
|
36
|
+
originList = await configuredOrigin(ctx);
|
|
37
|
+
} else {
|
|
38
|
+
originList = configuredOrigin;
|
|
39
|
+
}
|
|
40
|
+
// Normalize originList into an array
|
|
41
|
+
let normalizedOrigins;
|
|
42
|
+
if (Array.isArray(originList)) {
|
|
43
|
+
normalizedOrigins = originList;
|
|
44
|
+
} else if (originList === undefined || originList === null) {
|
|
45
|
+
// Handle undefined/null - treat as wildcard
|
|
46
|
+
normalizedOrigins = [
|
|
47
|
+
'*'
|
|
48
|
+
];
|
|
49
|
+
} else {
|
|
50
|
+
// Handle comma-separated string of origins
|
|
51
|
+
normalizedOrigins = originList.split(',').map((origin)=>origin.trim());
|
|
52
|
+
}
|
|
53
|
+
// Check if wildcard is in the normalized origins
|
|
54
|
+
if (normalizedOrigins.includes('*')) {
|
|
55
|
+
return requestOrigin;
|
|
56
|
+
}
|
|
57
|
+
// Check if request origin is in the normalized origins
|
|
58
|
+
return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';
|
|
59
|
+
};
|
|
24
60
|
const cors = (config)=>{
|
|
25
61
|
const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {
|
|
26
62
|
...defaults,
|
|
@@ -31,23 +67,8 @@ const cors = (config)=>{
|
|
|
31
67
|
}
|
|
32
68
|
return koaCors({
|
|
33
69
|
async origin (ctx) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
let originList;
|
|
38
|
-
if (typeof origin === 'function') {
|
|
39
|
-
originList = await origin(ctx);
|
|
40
|
-
} else {
|
|
41
|
-
originList = origin;
|
|
42
|
-
}
|
|
43
|
-
if (Array.isArray(originList)) {
|
|
44
|
-
return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
|
|
45
|
-
}
|
|
46
|
-
const parsedOrigin = originList.split(',').map((origin)=>origin.trim());
|
|
47
|
-
if (parsedOrigin.length > 1) {
|
|
48
|
-
return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';
|
|
49
|
-
}
|
|
50
|
-
return originList;
|
|
70
|
+
const requestOrigin = ctx.get('Origin');
|
|
71
|
+
return matchOrigin(requestOrigin, origin, ctx);
|
|
51
72
|
},
|
|
52
73
|
exposeHeaders: expose,
|
|
53
74
|
maxAge,
|
|
@@ -58,5 +79,5 @@ const cors = (config)=>{
|
|
|
58
79
|
});
|
|
59
80
|
};
|
|
60
81
|
|
|
61
|
-
export { cors };
|
|
82
|
+
export { cors, matchOrigin };
|
|
62
83
|
//# sourceMappingURL=cors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\
|
|
1
|
+
{"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[] | Promise<string | string[]>);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\n/**\n * Determines if a request origin is allowed based on the configured origin list\n * @param requestOrigin - The origin from the request header\n * @param configuredOrigin - The origin configuration (string, array, or function)\n * @param ctx - The Koa context (for function-based origin)\n * @returns The allowed origin string or empty string if blocked\n */\nexport const matchOrigin = async (\n requestOrigin: string | undefined,\n configuredOrigin:\n | string\n | string[]\n | ((ctx: any) => string | string[] | Promise<string | string[]>),\n ctx?: any\n): Promise<string> => {\n if (!requestOrigin) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof configuredOrigin === 'function') {\n originList = await configuredOrigin(ctx);\n } else {\n originList = configuredOrigin;\n }\n\n // Normalize originList into an array\n let normalizedOrigins: string[];\n if (Array.isArray(originList)) {\n normalizedOrigins = originList;\n } else if (originList === undefined || originList === null) {\n // Handle undefined/null - treat as wildcard\n normalizedOrigins = ['*'];\n } else {\n // Handle comma-separated string of origins\n normalizedOrigins = originList.split(',').map((origin) => origin.trim());\n }\n\n // Check if wildcard is in the normalized origins\n if (normalizedOrigins.includes('*')) {\n return requestOrigin;\n }\n\n // Check if request origin is in the normalized origins\n return normalizedOrigins.includes(requestOrigin) ? requestOrigin : '';\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n const requestOrigin = ctx.get('Origin');\n return matchOrigin(requestOrigin, origin, ctx);\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["defaults","origin","maxAge","credentials","methods","headers","keepHeadersOnError","matchOrigin","requestOrigin","configuredOrigin","ctx","originList","normalizedOrigins","Array","isArray","undefined","split","map","trim","includes","cors","config","expose","enabled","strapi","log","warn","koaCors","get","exposeHeaders","allowMethods","allowHeaders"],"mappings":";;AAeA,MAAMA,QAAmB,GAAA;IACvBC,MAAQ,EAAA,GAAA;IACRC,MAAQ,EAAA,QAAA;IACRC,WAAa,EAAA,IAAA;IACbC,OAAS,EAAA;AAAC,QAAA,KAAA;AAAO,QAAA,MAAA;AAAQ,QAAA,KAAA;AAAO,QAAA,OAAA;AAAS,QAAA,QAAA;AAAU,QAAA,MAAA;AAAQ,QAAA;AAAU,KAAA;IACrEC,OAAS,EAAA;AAAC,QAAA,cAAA;AAAgB,QAAA,eAAA;AAA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OAAO,KAAKR,SAAW,EAAA;AAChCS,QAAAA,MAAAA,CAAOC,GAAG,CAACC,IAAI,CACb,kFACE,wGACA,GAAA,6CAAA,CAAA;AAEN;AAEA,IAAA,OAAOC,OAAQ,CAAA;AACb,QAAA,MAAM1B,QAAOS,GAAG,EAAA;YACd,MAAMF,aAAAA,GAAgBE,GAAIkB,CAAAA,GAAG,CAAC,QAAA,CAAA;YAC9B,OAAOrB,WAAAA,CAAYC,eAAeP,MAAQS,EAAAA,GAAAA,CAAAA;AAC5C,SAAA;QACAmB,aAAeP,EAAAA,MAAAA;AACfpB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;QACA2B,YAAc1B,EAAAA,OAAAA;QACd2B,YAAc1B,EAAAA,OAAAA;AACdC,QAAAA;AACF,KAAA,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-published-at.d.ts","sourceRoot":"","sources":["../../src/migrations/first-published-at.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAUxC,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBA6D7E,CAAC;AAEF,OAAO,EAAE,sBAAsB,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var strapiUtils = require('@strapi/utils');
|
|
4
|
+
var _ = require('lodash');
|
|
5
|
+
|
|
6
|
+
const enableFirstPublishedAt = async ({ oldContentTypes, contentTypes })=>{
|
|
7
|
+
if (!oldContentTypes) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return strapi.db.transaction(async (trx)=>{
|
|
11
|
+
for(const uid in contentTypes){
|
|
12
|
+
if (!oldContentTypes[uid]) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const contentType = contentTypes[uid];
|
|
16
|
+
if (!strapiUtils.contentTypes.hasFirstPublishedAtField(contentType)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (!contentType.attributes?.firstPublishedAt) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const content = await strapi.db.queryBuilder(uid).select('*').transacting(trx).execute();
|
|
23
|
+
// Process content types in pairs: draft and published.
|
|
24
|
+
// If only one exist, which means the value is not published yet and we can ignore it
|
|
25
|
+
const groupedContent = _.groupBy(content, (item)=>`${item.documentId}-${item.locale}`);
|
|
26
|
+
for (const items of Object.values(groupedContent)){
|
|
27
|
+
// If there is only one item, which means nothing is published yet for this locale
|
|
28
|
+
if (items.length <= 1) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// If firstPublishedAt is already present, do not do anything
|
|
32
|
+
if (items[0].firstPublishedAt != null && items[1].firstPublishedAt != null) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const publishedContent = items.filter((item)=>item.publishedAt != null).at(0);
|
|
36
|
+
if (!publishedContent) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
await strapi.db.queryBuilder(uid).update({
|
|
40
|
+
firstPublishedAt: new Date(publishedContent.publishedAt)
|
|
41
|
+
}).where({
|
|
42
|
+
documentId: publishedContent.documentId,
|
|
43
|
+
locale: publishedContent.locale
|
|
44
|
+
}).transacting(trx).execute();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
exports.enable = enableFirstPublishedAt;
|
|
51
|
+
//# sourceMappingURL=first-published-at.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-published-at.js","sources":["../../src/migrations/first-published-at.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils } from '@strapi/utils';\nimport _ from 'lodash';\nimport { Input } from './draft-publish';\n\ninterface ContentTypeData {\n id: number;\n documentId: string;\n publishedAt: Date;\n firstPublishedAt: Date;\n locale: string;\n}\n\nconst enableFirstPublishedAt = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const contentType = contentTypes[uid];\n\n if (!contentTypesUtils.hasFirstPublishedAtField(contentType)) {\n continue;\n }\n\n if (!contentType.attributes?.firstPublishedAt) {\n continue;\n }\n\n const content: ContentTypeData[] = await strapi.db\n .queryBuilder(uid)\n .select('*')\n .transacting(trx)\n .execute();\n\n // Process content types in pairs: draft and published.\n // If only one exist, which means the value is not published yet and we can ignore it\n const groupedContent = _.groupBy(content, (item) => `${item.documentId}-${item.locale}`);\n\n for (const items of Object.values(groupedContent)) {\n // If there is only one item, which means nothing is published yet for this locale\n if (items.length <= 1) {\n continue;\n }\n\n // If firstPublishedAt is already present, do not do anything\n if (items[0].firstPublishedAt != null && items[1].firstPublishedAt != null) {\n continue;\n }\n\n const publishedContent = items.filter((item) => item.publishedAt != null).at(0);\n if (!publishedContent) {\n continue;\n }\n\n await strapi.db\n .queryBuilder(uid)\n .update({\n firstPublishedAt: new Date(publishedContent.publishedAt),\n })\n .where({\n documentId: publishedContent.documentId,\n locale: publishedContent.locale,\n })\n .transacting(trx)\n .execute();\n }\n }\n });\n};\n\nexport { enableFirstPublishedAt as enable };\n"],"names":["enableFirstPublishedAt","oldContentTypes","contentTypes","strapi","db","transaction","trx","uid","contentType","contentTypesUtils","hasFirstPublishedAtField","attributes","firstPublishedAt","content","queryBuilder","select","transacting","execute","groupedContent","_","groupBy","item","documentId","locale","items","Object","values","length","publishedContent","filter","publishedAt","at","update","Date","where"],"mappings":";;;;;AAYA,MAAMA,yBAAyB,OAAO,EAAEC,eAAe,EAAEC,YAAY,EAAS,GAAA;AAC5E,IAAA,IAAI,CAACD,eAAiB,EAAA;AACpB,QAAA;AACF;AAEA,IAAA,OAAOE,MAAOC,CAAAA,EAAE,CAACC,WAAW,CAAC,OAAOC,GAAAA,GAAAA;QAClC,IAAK,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