@strapi/core 5.19.0 → 5.21.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/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 +238 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +214 -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 +112 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +90 -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 +13 -12
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +13 -12
- package/dist/package.json.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 +7 -4
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +7 -4
- package/dist/services/document-service/repository.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/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 +13 -12
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,MAAAA,oBAAAA,GAAuB,CAI3BC,GACAC,EAAAA,GAAAA,GAAAA;AAIA,IAAA,OAAO,CAAC,EACNC,MAAAA,EAAAA,OAAM,EAGP,GAAA;AACC,QAAA,MAAMC,iBAAiBC,sBAAiB,CAAA;YAAEC,WAAaH,EAAAA,OAAAA,CAAOG,WAAW,CAACL,GAAAA;AAAK,SAAA,CAAA;AAE/E,QAAA,MAAMM,QAAW,GAAA,OAAOL,GAAQ,KAAA,UAAA,GAAaA,GAAI,CAAA;YAAEC,MAAAA,EAAAA;AAAO,SAAA,CAAA,GAAMD,OAAQ,EAAC;AAEzE,QAAA,KAAK,MAAMM,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACN,cAAuD,CAAA,CAAA;AAC1F,YAAA,IAAIG,QAAQ,CAACC,UAAW,CAAA,KAAKG,SAAW,EAAA;AACtCJ,gBAAAA,QAAQ,CAACC,UAAAA,CAAW,GAAGJ,cAAc,CAACI,UAAW,CAAA;AACnD;AACF;QAEAC,MAAOG,CAAAA,cAAc,CAACL,QAAUH,EAAAA,cAAAA,CAAAA;QAEhC,MAAMS,QAAAA,GAAW,OAAOX,GAAQ,KAAA,WAAA;AAChC,QAAA,IAAIW,QAAU,EAAA;AACZJ,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AACA,MAAQ,EAAA;gBACX,MAAMtB,WAAAA,GAAcH,MAAOG,CAAAA,WAAW,CAACL,GAAAA,CAAAA;AAEvC,gBAAA,MAAM4B,gBAAgBC,oBAAa,CAAA;AAAExB,oBAAAA,WAAAA;AAAaH,oBAAAA;AAAO,iBAAA,CAAA;gBACzD,MAAMO,IAAAA,GAAOD,MAAOC,CAAAA,IAAI,CAACmB,aAAAA,CAAAA;gBAEzBnB,IAAKqB,CAAAA,OAAO,CAAC,CAACC,SAAAA,GAAAA;oBACZ,MAAMC,YAAAA,GAAeJ,aAAa,CAACG,SAAU,CAAA;AAE7CC,oBAAAA,YAAAA,CAAaT,MAAM,GAAIA,MAAM,CAACQ,SAAAA,CAAU,IAAI,EAAC;AAC/C,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,EAAAA,GAAAA,GAAAA;AAIA,IAAA,OAAO,CAAC,EACNC,MAAAA,EAAAA,OAAM,EAGP,GAAA;AACC,QAAA,MAAMC,iBAAiBC,gBAAiB,CAAA;YAAEC,WAAaH,EAAAA,OAAAA,CAAOG,WAAW,CAACL,GAAAA;AAAK,SAAA,CAAA;AAE/E,QAAA,MAAMM,QAAW,GAAA,OAAOL,GAAQ,KAAA,UAAA,GAAaA,GAAI,CAAA;YAAEC,MAAAA,EAAAA;AAAO,SAAA,CAAA,GAAMD,OAAQ,EAAC;AAEzE,QAAA,KAAK,MAAMM,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACN,cAAuD,CAAA,CAAA;AAC1F,YAAA,IAAIG,QAAQ,CAACC,UAAW,CAAA,KAAKG,SAAW,EAAA;AACtCJ,gBAAAA,QAAQ,CAACC,UAAAA,CAAW,GAAGJ,cAAc,CAACI,UAAW,CAAA;AACnD;AACF;QAEAC,MAAOG,CAAAA,cAAc,CAACL,QAAUH,EAAAA,cAAAA,CAAAA;QAEhC,MAAMS,QAAAA,GAAW,OAAOX,GAAQ,KAAA,WAAA;AAChC,QAAA,IAAIW,QAAU,EAAA;AACZJ,YAAAA,MAAAA,CAAOK,cAAc,CAACP,QAAUV,EAAAA,OAAAA,CAAQC,gBAAgB,EAAE;gBACxDiB,QAAU,EAAA,KAAA;gBACVC,YAAc,EAAA,KAAA;gBACdC,U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oBAAAA,WAAAA;AAAaH,oBAAAA;AAAO,iBAAA,CAAA;gBACzD,MAAMO,IAAAA,GAAOD,MAAOC,CAAAA,IAAI,CAACmB,aAAAA,CAAAA;gBAEzBnB,IAAKqB,CAAAA,OAAO,CAAC,CAACC,SAAAA,GAAAA;oBACZ,MAAMC,YAAAA,GAAeJ,aAAa,CAACG,SAAU,CAAA;AAE7CC,oBAAAA,YAAAA,CAAaT,MAAM,GAAIA,MAAM,CAACQ,SAAAA,CAAU,IAAI,EAAC;AAC/C,iBAAA,CAAA;AAEA,gBAAA,MAAME,cAAiBC,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,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KR,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;;;;;"}
|
@@ -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;AAAiB,QAAA,QAAA;AAAU,QAAA;AAAS,KAAA;IAC9DC,kBAAoB,EAAA;AACtB,CAAA;AA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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,MAAMC,OAAOL,YAAc,CAAA;AAC9B,YAAA,IAAI,CAACD,eAAe,CAACM,GAAAA,CAAI,EAAE;AACzB,gBAAA;AACF;YAEA,MAAMC,WAAAA,GAAcN,YAAY,CAACK,GAAI,CAAA;AAErC,YAAA,IAAI,CAACE,wBAAAA,CAAkBC,wBAAwB,CAACF,WAA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CC,oBAAAA,MAAAA,EAAQK,iBAAiBL;iBAE1BP,CAAAA,CAAAA,WAAW,CAACV,GAAAA,CAAAA,CACZW,OAAO,EAAA;AACZ;AACF;AACF,KAAA,CAAA;AACF;;;;"}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { contentTypes } from '@strapi/utils';
|
2
|
+
import _ from 'lodash';
|
3
|
+
|
4
|
+
const enableFirstPublishedAt = async ({ oldContentTypes, contentTypes: contentTypes$1 })=>{
|
5
|
+
if (!oldContentTypes) {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
return strapi.db.transaction(async (trx)=>{
|
9
|
+
for(const uid in contentTypes$1){
|
10
|
+
if (!oldContentTypes[uid]) {
|
11
|
+
continue;
|
12
|
+
}
|
13
|
+
const contentType = contentTypes$1[uid];
|
14
|
+
if (!contentTypes.hasFirstPublishedAtField(contentType)) {
|
15
|
+
continue;
|
16
|
+
}
|
17
|
+
if (!contentType.attributes?.firstPublishedAt) {
|
18
|
+
continue;
|
19
|
+
}
|
20
|
+
const content = await strapi.db.queryBuilder(uid).select('*').transacting(trx).execute();
|
21
|
+
// Process content types in pairs: draft and published.
|
22
|
+
// If only one exist, which means the value is not published yet and we can ignore it
|
23
|
+
const groupedContent = _.groupBy(content, (item)=>`${item.documentId}-${item.locale}`);
|
24
|
+
for (const items of Object.values(groupedContent)){
|
25
|
+
// If there is only one item, which means nothing is published yet for this locale
|
26
|
+
if (items.length <= 1) {
|
27
|
+
continue;
|
28
|
+
}
|
29
|
+
// If firstPublishedAt is already present, do not do anything
|
30
|
+
if (items[0].firstPublishedAt != null && items[1].firstPublishedAt != null) {
|
31
|
+
continue;
|
32
|
+
}
|
33
|
+
const publishedContent = items.filter((item)=>item.publishedAt != null).at(0);
|
34
|
+
if (!publishedContent) {
|
35
|
+
continue;
|
36
|
+
}
|
37
|
+
await strapi.db.queryBuilder(uid).update({
|
38
|
+
firstPublishedAt: new Date(publishedContent.publishedAt)
|
39
|
+
}).where({
|
40
|
+
documentId: publishedContent.documentId,
|
41
|
+
locale: publishedContent.locale
|
42
|
+
}).transacting(trx).execute();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
});
|
46
|
+
};
|
47
|
+
|
48
|
+
export { enableFirstPublishedAt as enable };
|
49
|
+
//# sourceMappingURL=first-published-at.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"first-published-at.mjs","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,gBAAEC,cAAY,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,MAAMC,OAAOL,cAAc,CAAA;AAC9B,YAAA,IAAI,CAACD,eAAe,CAACM,GAAAA,CAAI,EAAE;AACzB,gBAAA;AACF;YAEA,MAAMC,WAAAA,GAAcN,cAAY,CAACK,GAAI,CAAA;AAErC,YAAA,IAAI,CAACE,YAAAA,CAAkBC,wBAAwB,CAACF,WAAc,CAAA,EAAA;AAC5D,gBAAA;AACF;AAEA,YAAA,IAAI,CAACA,WAAAA,CAAYG,UAAU,EAAEC,gBAAkB,EAAA;AAC7C,gBAAA;AACF;AAEA,YAAA,MAAMC,OAA6B,GAAA,MAAMV,MAAOC,CAAAA,EAAE,CAC/CU,YAAY,CAACP,GACbQ,CAAAA,CAAAA,MAAM,CAAC,GAAA,CAAA,CACPC,WAAW,CAACV,KACZW,OAAO,EAAA;;;AAIV,YAAA,MAAMC,iBAAiBC,CAAEC,CAAAA,OAAO,CAACP,OAAAA,EAAS,CAACQ,IAAS,GAAA,CAAC,EAAEA,IAAAA,CAAKC,UAAU,CAAC,CAAC,EAAED,IAAKE,CAAAA,MAAM,CAAC,CAAC,CAAA;AAEvF,YAAA,KAAK,MAAMC,KAAAA,IAASC,MAAOC,CAAAA,MAAM,CAACR,cAAiB,CAAA,CAAA;;gBAEjD,IAAIM,KAAAA,CAAMG,MAAM,IAAI,CAAG,EAAA;AACrB,oBAAA;AACF;;AAGA,gBAAA,IAAIH,KAAK,CAAC,CAAE,CAAA,CAACZ,gBAAgB,IAAI,IAAQY,IAAAA,KAAK,CAAC,CAAA,CAAE,CAACZ,gBAAgB,IAAI,IAAM,EAAA;AAC1E,oBAAA;AACF;gBAEA,MAAMgB,gBAAAA,GAAmBJ,KAAMK,CAAAA,MAAM,CAAC,CAACR,IAASA,GAAAA,IAAAA,CAAKS,WAAW,IAAI,IAAMC,CAAAA,CAAAA,EAAE,CAAC,CAAA,CAAA;AAC7E,gBAAA,IAAI,CAACH,gBAAkB,EAAA;AACrB,oBAAA;AACF;AAEA,gBAAA,MAAMzB,OAAOC,EAAE,CACZU,YAAY,CAACP,GAAAA,CAAAA,CACbyB,MAAM,CAAC;oBACNpB,gBAAkB,EAAA,IAAIqB,IAAKL,CAAAA,gBAAAA,CAAiBE,WAAW;AACzD,iBAAA,CAAA,CACCI,KAAK,CAAC;AACLZ,oBAAAA,UAAAA,EAAYM,iBAAiBN,UAAU;AACvCC,oBAAAA,MAAAA,EAAQK,iBAAiBL;iBAE1BP,CAAAA,CAAAA,WAAW,CAACV,GAAAA,CAAAA,CACZW,OAAO,EAAA;AACZ;AACF;AACF,KAAA,CAAA;AACF;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,QAAA,MAAM,MAAM,sCAA6C,KAAK,kBAI7D,CAAC;AAEF,QAAA,MAAM,OAAO,sCAA6C,KAAK,kBAG9D,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/migrations/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var draftPublish = require('./draft-publish.js');
|
4
|
+
var firstPublishedAt = require('./first-published-at.js');
|
4
5
|
var i18n = require('./i18n.js');
|
5
6
|
|
6
7
|
const enable = async ({ oldContentTypes, contentTypes })=>{
|
@@ -12,6 +13,10 @@ const enable = async ({ oldContentTypes, contentTypes })=>{
|
|
12
13
|
oldContentTypes,
|
13
14
|
contentTypes
|
14
15
|
});
|
16
|
+
await firstPublishedAt.enable({
|
17
|
+
oldContentTypes,
|
18
|
+
contentTypes
|
19
|
+
});
|
15
20
|
};
|
16
21
|
const disable = async ({ oldContentTypes, contentTypes })=>{
|
17
22
|
await i18n.disable({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/migrations/index.ts"],"sourcesContent":["import * as draftPublishMigrations from './draft-publish';\nimport * as i18nMigrations from './i18n';\nimport type { Input } from './draft-publish';\n\nconst enable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.enable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.enable({ oldContentTypes, contentTypes });\n};\n\nconst disable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.disable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.disable({ oldContentTypes, contentTypes });\n};\n\nexport { enable, disable };\n"],"names":["enable","oldContentTypes","contentTypes","i18nMigrations","draftPublishMigrations","disable"],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/migrations/index.ts"],"sourcesContent":["import * as draftPublishMigrations from './draft-publish';\nimport * as firstPublishedAt from './first-published-at';\nimport * as i18nMigrations from './i18n';\nimport type { Input } from './draft-publish';\n\nconst enable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.enable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.enable({ oldContentTypes, contentTypes });\n await firstPublishedAt.enable({ oldContentTypes, contentTypes });\n};\n\nconst disable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.disable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.disable({ oldContentTypes, contentTypes });\n};\n\nexport { enable, disable };\n"],"names":["enable","oldContentTypes","contentTypes","i18nMigrations","draftPublishMigrations","firstPublishedAt","disable"],"mappings":";;;;;;AAKA,MAAMA,SAAS,OAAO,EAAEC,eAAe,EAAEC,YAAY,EAAS,GAAA;IAC5D,MAAMC,WAAqB,CAAC;AAAEF,QAAAA,eAAAA;AAAiBC,QAAAA;AAAa,KAAA,CAAA;IAC5D,MAAME,mBAA6B,CAAC;AAAEH,QAAAA,eAAAA;AAAiBC,QAAAA;AAAa,KAAA,CAAA;IACpE,MAAMG,uBAAuB,CAAC;AAAEJ,QAAAA,eAAAA;AAAiBC,QAAAA;AAAa,KAAA,CAAA;AAChE;AAEA,MAAMI,UAAU,OAAO,EAAEL,eAAe,EAAEC,YAAY,EAAS,GAAA;IAC7D,MAAMC,YAAsB,CAAC;AAAEF,QAAAA,eAAAA;AAAiBC,QAAAA;AAAa,KAAA,CAAA;IAC7D,MAAME,oBAA8B,CAAC;AAAEH,QAAAA,eAAAA;AAAiBC,QAAAA;AAAa,KAAA,CAAA;AACvE;;;;;"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { enable as enableDraftAndPublish, disable as disableDraftAndPublish } from './draft-publish.mjs';
|
2
|
+
import { enable as enableFirstPublishedAt } from './first-published-at.mjs';
|
2
3
|
import { enable as enableI18n, disable as disableI18n } from './i18n.mjs';
|
3
4
|
|
4
5
|
const enable = async ({ oldContentTypes, contentTypes })=>{
|
@@ -10,6 +11,10 @@ const enable = async ({ oldContentTypes, contentTypes })=>{
|
|
10
11
|
oldContentTypes,
|
11
12
|
contentTypes
|
12
13
|
});
|
14
|
+
await enableFirstPublishedAt({
|
15
|
+
oldContentTypes,
|
16
|
+
contentTypes
|
17
|
+
});
|
13
18
|
};
|
14
19
|
const disable = async ({ oldContentTypes, contentTypes })=>{
|
15
20
|
await disableI18n({
|