@strapi/core 0.0.0-next.0e47ec1b0a372a20f2ceb1a335f43b5cb9d6b3fe → 0.0.0-next.10e62155f737fd6e63fc8a032ef377bdbf764e76
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 +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +22 -5
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +22 -5
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/config-loader.mjs.map +1 -1
- package/dist/configuration/urls.js.map +1 -1
- package/dist/configuration/urls.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/container.js.map +1 -1
- package/dist/container.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/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/domain/content-type/index.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/ee/index.js.map +1 -1
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.js +1 -2
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +1 -2
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.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/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs.map +1 -1
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/components.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/loaders/src-index.js.map +1 -1
- package/dist/loaders/src-index.mjs.map +1 -1
- package/dist/middlewares/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/middlewares/logger.js.map +1 -1
- package/dist/middlewares/logger.mjs.map +1 -1
- package/dist/middlewares/response-time.js.map +1 -1
- package/dist/middlewares/response-time.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +2 -15
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +2 -15
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/migrations/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 +18 -15
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +18 -15
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/session-manager.d.ts +3 -0
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/session-manager.js +23 -0
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/session-manager.mjs +21 -0
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/apis.mjs.map +1 -1
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/custom-fields.mjs.map +1 -1
- package/dist/registries/namespace.js.map +1 -1
- package/dist/registries/namespace.mjs.map +1 -1
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/plugins.mjs.map +1 -1
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/services/config.js.map +1 -1
- package/dist/services/config.mjs.map +1 -1
- package/dist/services/content-api/index.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-api/permissions/index.js.map +1 -1
- package/dist/services/content-api/permissions/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +13 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +108 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +106 -0
- package/dist/services/content-source-maps.mjs.map +1 -0
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +31 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +109 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +107 -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 +12 -5
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +13 -6
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/fields.js.map +1 -1
- package/dist/services/document-service/transform/fields.mjs.map +1 -1
- package/dist/services/document-service/transform/id-map.js.map +1 -1
- package/dist/services/document-service/transform/id-map.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.js +145 -0
- package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs +143 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -0
- 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/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +11 -9
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +11 -9
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -1
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -1
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/index.mjs.map +1 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/middleware.mjs.map +1 -1
- package/dist/services/server/register-routes.js +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/dist/services/session-manager.d.ts +167 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +529 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +526 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs.map +1 -1
- package/dist/services/worker-queue.js.map +1 -1
- package/dist/services/worker-queue.mjs.map +1 -1
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-config-file.mjs.map +1 -1
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/package.json +18 -15
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(): Core.CoreAPI.Router.Route[] {\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,Q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extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Core, Struct } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Core.Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n // @ts-expect-error TODO verify that it's a valid api, not missing bootstrap, register, and destroy\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] = (\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ])\n ).map((result) => result?.result);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = (await loadDir(join(dir, fd.name)))?.result;\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return { result: contentTypes };\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = (await loadFile(join(dir, fd.name))).result;\n }\n\n return { result: root };\n};\n\n// because this is async and its contents are dynamic, we must return it as an array to avoid a property called `then` being interpreted as a Promise\nconst loadFile = async (file: string): Promise<{ result: unknown }> => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return { result: importDefault(file) };\n case '.json':\n return { result: await fse.readJSON(file) };\n default:\n return { result: {} };\n }\n};\n"],"names":["DEFAULT_CONTENT_TYPE","schema","actions","lifecycles","normalizeName","name","strings","isKebabCase","_","kebabCase","isDirectory","fd","isDotFile","startsWith","loadAPIs","strapi","existsSync","dirs","dist","api","apisFDs","fse","readdir","withFileTypes","filter","negate","apis","apiFD","apiName","loadAPI","join","validateContentTypesUnicity","Object","keys","get","add","allApisSchemas","values","flatMap","contentTypes","names","forEach","info","singularName","includes","Error","push","pluralName","dir","index","config","routes","controllers","services","policies","middlewares","Promise","all","loadIndex","loadDir","loadContentTypes","map","result","pathExists","loadFile","fds","isFile","contentTypeName","loadedContentType","isEmpty","contentType","assign","collectionName","globalId","getGlobalId","root","extname","key","basename","file","ext","importDefault","readJSON"],"mappings":";;;;;;;;;AAyBA,MAAMA,oBAAuB,GAAA;AAC3BC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,OAAAA,EAAS,EAAC;AACVC,IAAAA,UAAAA,EAAY;AACd,CAAA;AAEA;AACA,M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B,gBAAAA,MAAAA,EAAQmB,yBAAcF,CAAAA,IAAAA;AAAM,aAAA;QACvC,KAAK,OAAA;YACH,OAAO;gBAAEjB,MAAQ,EAAA,MAAMzC,GAAI6D,CAAAA,QAAQ,CAACH,IAAAA;AAAM,aAAA;AAC5C,QAAA;YACE,OAAO;AAAEjB,gBAAAA,MAAAA,EAAQ;AAAG,aAAA;AACxB;AACF,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"apis.js","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Core, Struct } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Core.Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n // @ts-expect-error TODO verify that it's a valid api, not missing bootstrap, register, and destroy\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] = (\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ])\n ).map((result) => result?.result);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = (await loadDir(join(dir, fd.name)))?.result;\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return { result: contentTypes };\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = (await loadFile(join(dir, fd.name))).result;\n }\n\n return { result: root };\n};\n\n// because this is async and its contents are dynamic, we must return it as an array to avoid a property called `then` being interpreted as a Promise\nconst loadFile = async (file: string): Promise<{ result: unknown }> => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return { result: importDefault(file) };\n case '.json':\n return { result: await fse.readJSON(file) };\n default:\n return { result: {} };\n }\n};\n"],"names":["DEFAULT_CONTENT_TYPE","schema","actions","lifecycles","normalizeName","name","strings","isKebabCase","_","kebabCase","isDirectory","fd","isDotFile","startsWith","loadAPIs","strapi","existsSync","dirs","dist","api","apisFDs","fse","readdir","withFileTypes","filter","negate","apis","apiFD","apiName","loadAPI","join","validateContentTypesUnicity","Object","keys","get","add","allApisSchemas","values","flatMap","contentTypes","names","forEach","info","singularName","includes","Error","push","pluralName","dir","index","config","routes","controllers","services","policies","middlewares","Promise","all","loadIndex","loadDir","loadContentTypes","map","result","pathExists","loadFile","fds","isFile","contentTypeName","loadedContentType","isEmpty","contentType","assign","collectionName","globalId","getGlobalId","root","extname","key","basename","file","ext","importDefault","readJSON"],"mappings":";;;;;;;;;AAyBA,MAAMA,oBAAuB,GAAA;AAC3BC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,OAAAA,EAAS,EAAC;AACVC,IAAAA,UAAAA,EAAY;AACd,CAAA;AAEA;AACA,MAAMC,aAAAA,GAAgB,CAACC,IAAAA,GAAkBC,mBAAQC,CAAAA,WAAW,CAACF,IAAQA,CAAAA,GAAAA,IAAAA,GAAOG,CAAEC,CAAAA,SAAS,CAACJ,IAAAA,CAAAA;AAExF,MAAMK,WAAc,GAAA,CAACC,EAAmBA,GAAAA,EAAAA,CAAGD,WAAW,EAAA;AACtD,MAAME,YAAY,CAACD,EAAAA,GAAmBA,GAAGN,IAAI,CAACQ,UAAU,CAAC,GAAA,CAAA;AAE1C,eAAeC,SAASC,MAAmB,EAAA;IACxD,IAAI,CAACC,eAAWD,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,CAAG,EAAA;AACrC,QAAA;AACF;AAEA,IAAA,MAAMC,OAAU,GAAA,MAAM,CAAC,MAAMC,GAAIC,CAAAA,OAAO,CAACP,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,GAAG,EAAE;QAAEI,aAAe,EAAA;KAAM,CAAA,EACnFC,MAAM,CAACd,WAAAA,CAAAA,CACPc,MAAM,CAAChB,CAAAA,CAAEiB,MAAM,CAACb,SAAAA,CAAAA,CAAAA;AAEnB,IAAA,MAAMc,OAAa,EAAC;;IAGpB,KAAK,MAAMC,SAASP,OAAS,CAAA;QAC3B,MAAMQ,OAAAA,GAAUxB,aAAcuB,CAAAA,KAAAA,CAAMtB,IAAI,CAAA;AACxC,QAAA,MAAMc,GAAM,GAAA,MAAMU,OAAQD,CAAAA,OAA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AAA,GAAG,CAAC,MAAMb,QAASlC,CAAAA,SAAAA,CAAKkB,GAAKrC,EAAAA,EAAAA,CAAGN,IAAI,CAAA,CAAC,EAAGyD,MAAM;AACxE;IAEA,OAAO;QAAEA,MAAQa,EAAAA;AAAK,KAAA;AACxB,CAAA;AAEA;AACA,MAAMX,WAAW,OAAOe,IAAAA,GAAAA;AACtB,IAAA,MAAMC,MAAMJ,YAAQG,CAAAA,IAAAA,CAAAA;IAEpB,OAAQC,GAAAA;QACN,KAAK,KAAA;YACH,OAAO;AAAElB,gBAAAA,MAAAA,EAAQmB,yBAAcF,CAAAA,IAAAA;AAAM,aAAA;QACvC,KAAK,OAAA;YACH,OAAO;gBAAEjB,MAAQ,EAAA,MAAMzC,GAAI6D,CAAAA,QAAQ,CAACH,IAAAA;AAAM,aAAA;AAC5C,QAAA;YACE,OAAO;AAAEjB,gBAAAA,MAAAA,EAAQ;AAAG,aAAA;AACxB;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apis.mjs","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Core, Struct } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Core.Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n // @ts-expect-error TODO verify that it's a valid api, not missing bootstrap, register, and destroy\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] = (\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ])\n ).map((result) => result?.result);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = (await loadDir(join(dir, fd.name)))?.result;\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return { result: contentTypes };\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = (await loadFile(join(dir, fd.name))).result;\n }\n\n return { result: root };\n};\n\n// because this is async and its contents are dynamic, we must return it as an array to avoid a property called `then` being interpreted as a Promise\nconst loadFile = async (file: string): Promise<{ result: unknown }> => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return { result: importDefault(file) };\n case '.json':\n return { result: await fse.readJSON(file) };\n default:\n return { result: {} };\n }\n};\n"],"names":["DEFAULT_CONTENT_TYPE","schema","actions","lifecycles","normalizeName","name","strings","isKebabCase","_","kebabCase","isDirectory","fd","isDotFile","startsWith","loadAPIs","strapi","existsSync","dirs","dist","api","apisFDs","fse","readdir","withFileTypes","filter","negate","apis","apiFD","apiName","loadAPI","join","validateContentTypesUnicity","Object","keys","get","add","allApisSchemas","values","flatMap","contentTypes","names","forEach","info","singularName","includes","Error","push","pluralName","dir","index","config","routes","controllers","services","policies","middlewares","Promise","all","loadIndex","loadDir","loadContentTypes","map","result","pathExists","loadFile","fds","isFile","contentTypeName","loadedContentType","isEmpty","contentType","assign","collectionName","globalId","getGlobalId","root","extname","key","basename","file","ext","importDefault","readJSON"],"mappings":";;;;;;;AAyBA,MAAMA,oBAAuB,GAAA;AAC3BC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,OAAAA,EAAS,EAAC;AACVC,IAAAA,UAAAA,EAAY;AACd,CAAA;AAEA;AACA,MAAMC,aAAAA,GAAgB,CAACC,IAAAA,GAAkBC,OAAQC,CAAAA,WAAW,CAACF,IAAQA,CAAAA,GAAAA,IAAAA,GAAOG,CAAEC,CAAAA,SAAS,CAACJ,IAAAA,CAAAA;AAExF,MAAMK,WAAc,GAAA,CAACC,EAAmBA,GAAAA,EAAAA,CAAGD,WAAW,EAAA;AACtD,MAAME,YAAY,CAACD,EAAAA,GAAmBA,GAAGN,IAAI,CAACQ,UAAU,CAAC,GAAA,CAAA;AAE1C,eAAeC,SAASC,MAAmB,EAAA;IACxD,IAAI,CAACC,WAAWD,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,CAAG,EAAA;AACrC,QAAA;AACF;AAEA,IAAA,MAAMC,OAAU,GAAA,MAAM,CAAC,MAAMC,GAAIC,CAAAA,OAAO,CAACP,MAAAA,CAAOE,IAAI,CAACC,IAA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A,MAAMoD,OAAgC,EAAC;IACvC,KAAK,MAAMhE,MAAMsD,GAAK,CAAA;QACpB,IAAI,CAACtD,GAAGuD,MAAM,EAAA,IAAMU,QAAQjE,EAAGN,CAAAA,IAAI,MAAM,MAAQ,EAAA;AAC/C,YAAA;AACF;AAEA,QAAA,MAAMwE,MAAMC,QAASnE,CAAAA,EAAAA,CAAGN,IAAI,EAAEuE,OAAAA,CAAQjE,GAAGN,IAAI,CAAA,CAAA;AAE7CsE,QAAAA,IAAI,CAACvE,aAAAA,CAAcyE,GAAK,CAAA,CAAA,GAAG,CAAC,MAAMb,QAASlC,CAAAA,IAAAA,CAAKkB,GAAKrC,EAAAA,EAAAA,CAAGN,IAAI,CAAA,CAAC,EAAGyD,MAAM;AACxE;IAEA,OAAO;QAAEA,MAAQa,EAAAA;AAAK,KAAA;AACxB,CAAA;AAEA;AACA,MAAMX,WAAW,OAAOe,IAAAA,GAAAA;AACtB,IAAA,MAAMC,MAAMJ,OAAQG,CAAAA,IAAAA,CAAAA;IAEpB,OAAQC,GAAAA;QACN,KAAK,KAAA;YACH,OAAO;AAAElB,gBAAAA,MAAAA,EAAQmB,aAAcF,CAAAA,IAAAA;AAAM,aAAA;QACvC,KAAK,OAAA;YACH,OAAO;gBAAEjB,MAAQ,EAAA,MAAMzC,GAAI6D,CAAAA,QAAQ,CAACH,IAAAA;AAAM,aAAA;AAC5C,QAAA;YACE,OAAO;AAAEjB,gBAAAA,MAAAA,EAAQ;AAAG,aAAA;AACxB;AACF,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"apis.mjs","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Core, Struct } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Core.Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n // @ts-expect-error TODO verify that it's a valid api, not missing bootstrap, register, and destroy\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] = (\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ])\n ).map((result) => result?.result);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = (await loadDir(join(dir, fd.name)))?.result;\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return { result: contentTypes };\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = (await loadFile(join(dir, fd.name))).result;\n }\n\n return { result: root };\n};\n\n// because this is async and its contents are dynamic, we must return it as an array to avoid a property called `then` being interpreted as a Promise\nconst loadFile = async (file: string): Promise<{ result: unknown }> => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return { result: importDefault(file) };\n case '.json':\n return { result: await fse.readJSON(file) };\n default:\n return { result: {} };\n }\n};\n"],"names":["DEFAULT_CONTENT_TYPE","schema","actions","lifecycles","normalizeName","name","strings","isKebabCase","_","kebabCase","isDirectory","fd","isDotFile","startsWith","loadAPIs","strapi","existsSync","dirs","dist","api","apisFDs","fse","readdir","withFileTypes","filter","negate","apis","apiFD","apiName","loadAPI","join","validateContentTypesUnicity","Object","keys","get","add","allApisSchemas","values","flatMap","contentTypes","names","forEach","info","singularName","includes","Error","push","pluralName","dir","index","config","routes","controllers","services","policies","middlewares","Promise","all","loadIndex","loadDir","loadContentTypes","map","result","pathExists","loadFile","fds","isFile","contentTypeName","loadedContentType","isEmpty","contentType","assign","collectionName","globalId","getGlobalId","root","extname","key","basename","file","ext","importDefault","readJSON"],"mappings":";;;;;;;AAyBA,MAAMA,oBAAuB,GAAA;AAC3BC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,OAAAA,EAAS,EAAC;AACVC,IAAAA,UAAAA,EAAY;AACd,CAAA;AAEA;AACA,MAAMC,aAAAA,GAAgB,CAACC,IAAAA,GAAkBC,OAAQC,CAAAA,WAAW,CAACF,IAAQA,CAAAA,GAAAA,IAAAA,GAAOG,CAAEC,CAAAA,SAAS,CAACJ,IAAAA,CAAAA;AAExF,MAAMK,WAAc,GAAA,CAACC,EAAmBA,GAAAA,EAAAA,CAAGD,WAAW,EAA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AA,EAAQ;AAAG,aAAA;AACxB;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../src/loaders/components.ts"],"sourcesContent":["import { join } from 'path';\nimport _ from 'lodash';\nimport { pathExists } from 'fs-extra';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { loadFiles } from '../utils/load-files';\n\ntype LoadedComponent = {\n collectionName: string;\n __filename__: string;\n __schema__: LoadedComponent;\n uid: string;\n category: string;\n modelName: string;\n globalId: string;\n info: any;\n attributes: any;\n};\n\ntype LoadedComponents = {\n [category: string]: {\n [key: string]: LoadedComponent;\n };\n};\n\ntype ComponentMap = {\n [uid in UID.Component]: Struct.ComponentSchema;\n};\n\nexport default async function loadComponents(strapi: Core.Strapi) {\n if (!(await pathExists(strapi.dirs.dist.components))) {\n return {};\n }\n\n const map = await loadFiles<LoadedComponents>(strapi.dirs.dist.components, '*/*.*(js|json)');\n\n const components = Object.keys(map).reduce((acc, category) => {\n Object.keys(map[category]).forEach((key) => {\n const schema = map[category][key];\n\n if (!schema.collectionName) {\n // NOTE: We're using the filepath from the app directory instead of the dist for information purpose\n const filePath = join(strapi.dirs.app.components, category, schema.__filename__);\n\n return strapi.stopWithError(\n `Component ${key} is missing a \"collectionName\" property.\\nVerify file ${filePath}.`\n );\n }\n\n const uid: UID.Component = `${category}.${key}`;\n\n acc[uid] = Object.assign(schema, {\n __schema__: _.cloneDeep(schema),\n uid,\n category,\n modelType: 'component' as const,\n modelName: key,\n globalId: schema.globalId || _.upperFirst(_.camelCase(`component_${uid}`)),\n });\n });\n\n return acc;\n }, {} as ComponentMap);\n\n strapi.get('components').add(components);\n}\n"],"names":["loadComponents","strapi","pathExists","dirs","dist","components","map","loadFiles","Object","keys","reduce","acc","category","forEach","key","schema","collectionName","filePath","join","app","__filename__","stopWithError","uid","assign","__schema__","_","cloneDeep","modelType","modelName","globalId","upperFirst","camelCase","get","add"],"mappings":";;;;;;;AA4Be,eAAeA,eAAeC,MAAmB,EAAA;IAC9D,IAAI,CAAE,MAAMC,cAAWD,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,CAAI,EAAA;AACpD,QAAA,OAAO,EAAC;AACV;IAEA,MAAMC,GAAAA,GAAM,MAAMC,mBAA4BN,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,EAAE,gBAAA,CAAA;IAE3E,MAAMA,UAAAA,GAAaG,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAAC,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;QAC/CJ,MAAOC,CAAAA,IAAI,CAACH,GAAG,CAACM,SAAS,CAAEC,CAAAA,OAAO,CAAC,CAACC,GAAAA,GAAAA;AAClC,YAAA,MAAMC,MAAST,GAAAA,GAAG,CAACM,QAAAA,CAAS,CAACE,GAAI,CAAA;YAEjC,IAAI,CAACC,MAAOC,CAAAA,cAAc,EAAE;;gBAE1B,MAAMC,QAAAA,GAAWC,SAAKjB,CAAAA,MAAAA,CAAOE,IAAI,CAACgB,GAAG,CAACd,UAAU,EAAEO,QAAUG,EAAAA,MAAAA,CAAOK,YAAY,CAAA;gBAE/E,OAAOnB,MAAAA,CAAOoB,aAAa,CACzB,CAAC,UAAU,EAAEP,GAAAA,CAAI,sDAAsD,EAAEG,QAAS,CAAA,CAAC,CAAC,CAAA;AAExF;AAEA,YAAA,MAAMK,
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../src/loaders/components.ts"],"sourcesContent":["import { join } from 'path';\nimport _ from 'lodash';\nimport { pathExists } from 'fs-extra';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { loadFiles } from '../utils/load-files';\n\ntype LoadedComponent = {\n collectionName: string;\n __filename__: string;\n __schema__: LoadedComponent;\n uid: string;\n category: string;\n modelName: string;\n globalId: string;\n info: any;\n attributes: any;\n};\n\ntype LoadedComponents = {\n [category: string]: {\n [key: string]: LoadedComponent;\n };\n};\n\ntype ComponentMap = {\n [uid in UID.Component]: Struct.ComponentSchema;\n};\n\nexport default async function loadComponents(strapi: Core.Strapi) {\n if (!(await pathExists(strapi.dirs.dist.components))) {\n return {};\n }\n\n const map = await loadFiles<LoadedComponents>(strapi.dirs.dist.components, '*/*.*(js|json)');\n\n const components = Object.keys(map).reduce((acc, category) => {\n Object.keys(map[category]).forEach((key) => {\n const schema = map[category][key];\n\n if (!schema.collectionName) {\n // NOTE: We're using the filepath from the app directory instead of the dist for information purpose\n const filePath = join(strapi.dirs.app.components, category, schema.__filename__);\n\n return strapi.stopWithError(\n `Component ${key} is missing a \"collectionName\" property.\\nVerify file ${filePath}.`\n );\n }\n\n const uid: UID.Component = `${category}.${key}`;\n\n acc[uid] = Object.assign(schema, {\n __schema__: _.cloneDeep(schema),\n uid,\n category,\n modelType: 'component' as const,\n modelName: key,\n globalId: schema.globalId || _.upperFirst(_.camelCase(`component_${uid}`)),\n });\n });\n\n return acc;\n }, {} as ComponentMap);\n\n strapi.get('components').add(components);\n}\n"],"names":["loadComponents","strapi","pathExists","dirs","dist","components","map","loadFiles","Object","keys","reduce","acc","category","forEach","key","schema","collectionName","filePath","join","app","__filename__","stopWithError","uid","assign","__schema__","_","cloneDeep","modelType","modelName","globalId","upperFirst","camelCase","get","add"],"mappings":";;;;;;;AA4Be,eAAeA,eAAeC,MAAmB,EAAA;IAC9D,IAAI,CAAE,MAAMC,cAAWD,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,CAAI,EAAA;AACpD,QAAA,OAAO,EAAC;AACV;IAEA,MAAMC,GAAAA,GAAM,MAAMC,mBAA4BN,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,EAAE,gBAAA,CAAA;IAE3E,MAAMA,UAAAA,GAAaG,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAAC,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;QAC/CJ,MAAOC,CAAAA,IAAI,CAACH,GAAG,CAACM,SAAS,CAAEC,CAAAA,OAAO,CAAC,CAACC,GAAAA,GAAAA;AAClC,YAAA,MAAMC,MAAST,GAAAA,GAAG,CAACM,QAAAA,CAAS,CAACE,GAAI,CAAA;YAEjC,IAAI,CAACC,MAAOC,CAAAA,cAAc,EAAE;;gBAE1B,MAAMC,QAAAA,GAAWC,SAAKjB,CAAAA,MAAAA,CAAOE,IAAI,CAACgB,GAAG,CAACd,UAAU,EAAEO,QAAUG,EAAAA,MAAAA,CAAOK,YAAY,CAAA;gBAE/E,OAAOnB,MAAAA,CAAOoB,aAAa,CACzB,CAAC,UAAU,EAAEP,GAAAA,CAAI,sDAAsD,EAAEG,QAAS,CAAA,CAAC,CAAC,CAAA;AAExF;AAEA,YAAA,MAAMK,GAAqB,GAAA,CAAA,EAAGV,QAAS,CAAA,CAAC,EAAEE,GAAK,CAAA,CAAA;AAE/CH,YAAAA,GAAG,CAACW,GAAI,CAAA,GAAGd,MAAOe,CAAAA,MAAM,CAACR,MAAQ,EAAA;gBAC/BS,UAAYC,EAAAA,CAAAA,CAAEC,SAAS,CAACX,MAAAA,CAAAA;AACxBO,gBAAAA,GAAAA;AACAV,gBAAAA,QAAAA;gBACAe,SAAW,EAAA,WAAA;gBACXC,SAAWd,EAAAA,GAAAA;AACXe,gBAAAA,QAAAA,EAAUd,MAAOc,CAAAA,QAAQ,IAAIJ,CAAAA,CAAEK,UAAU,CAACL,CAAEM,CAAAA,SAAS,CAAC,CAAC,UAAU,EAAET,GAAK,CAAA,CAAA,CAAA;AAC1E,aAAA,CAAA;AACF,SAAA,CAAA;QAEA,OAAOX,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;AAEJV,IAAAA,MAAAA,CAAO+B,GAAG,CAAC,YAAcC,CAAAA,CAAAA,GAAG,CAAC5B,UAAAA,CAAAA;AAC/B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","sources":["../../src/loaders/components.ts"],"sourcesContent":["import { join } from 'path';\nimport _ from 'lodash';\nimport { pathExists } from 'fs-extra';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { loadFiles } from '../utils/load-files';\n\ntype LoadedComponent = {\n collectionName: string;\n __filename__: string;\n __schema__: LoadedComponent;\n uid: string;\n category: string;\n modelName: string;\n globalId: string;\n info: any;\n attributes: any;\n};\n\ntype LoadedComponents = {\n [category: string]: {\n [key: string]: LoadedComponent;\n };\n};\n\ntype ComponentMap = {\n [uid in UID.Component]: Struct.ComponentSchema;\n};\n\nexport default async function loadComponents(strapi: Core.Strapi) {\n if (!(await pathExists(strapi.dirs.dist.components))) {\n return {};\n }\n\n const map = await loadFiles<LoadedComponents>(strapi.dirs.dist.components, '*/*.*(js|json)');\n\n const components = Object.keys(map).reduce((acc, category) => {\n Object.keys(map[category]).forEach((key) => {\n const schema = map[category][key];\n\n if (!schema.collectionName) {\n // NOTE: We're using the filepath from the app directory instead of the dist for information purpose\n const filePath = join(strapi.dirs.app.components, category, schema.__filename__);\n\n return strapi.stopWithError(\n `Component ${key} is missing a \"collectionName\" property.\\nVerify file ${filePath}.`\n );\n }\n\n const uid: UID.Component = `${category}.${key}`;\n\n acc[uid] = Object.assign(schema, {\n __schema__: _.cloneDeep(schema),\n uid,\n category,\n modelType: 'component' as const,\n modelName: key,\n globalId: schema.globalId || _.upperFirst(_.camelCase(`component_${uid}`)),\n });\n });\n\n return acc;\n }, {} as ComponentMap);\n\n strapi.get('components').add(components);\n}\n"],"names":["loadComponents","strapi","pathExists","dirs","dist","components","map","loadFiles","Object","keys","reduce","acc","category","forEach","key","schema","collectionName","filePath","join","app","__filename__","stopWithError","uid","assign","__schema__","_","cloneDeep","modelType","modelName","globalId","upperFirst","camelCase","get","add"],"mappings":";;;;;AA4Be,eAAeA,eAAeC,MAAmB,EAAA;IAC9D,IAAI,CAAE,MAAMC,UAAWD,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,CAAI,EAAA;AACpD,QAAA,OAAO,EAAC;AACV;IAEA,MAAMC,GAAAA,GAAM,MAAMC,SAA4BN,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,EAAE,gBAAA,CAAA;IAE3E,MAAMA,UAAAA,GAAaG,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAAC,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;QAC/CJ,MAAOC,CAAAA,IAAI,CAACH,GAAG,CAACM,SAAS,CAAEC,CAAAA,OAAO,CAAC,CAACC,GAAAA,GAAAA;AAClC,YAAA,MAAMC,MAAST,GAAAA,GAAG,CAACM,QAAAA,CAAS,CAACE,GAAI,CAAA;YAEjC,IAAI,CAACC,MAAOC,CAAAA,cAAc,EAAE;;gBAE1B,MAAMC,QAAAA,GAAWC,IAAKjB,CAAAA,MAAAA,CAAOE,IAAI,CAACgB,GAAG,CAACd,UAAU,EAAEO,QAAUG,EAAAA,MAAAA,CAAOK,YAAY,CAAA;gBAE/E,OAAOnB,MAAAA,CAAOoB,aAAa,CACzB,CAAC,UAAU,EAAEP,GAAAA,CAAI,sDAAsD,EAAEG,QAAS,CAAA,CAAC,CAAC,CAAA;AAExF;AAEA,YAAA,MAAMK,
|
|
1
|
+
{"version":3,"file":"components.mjs","sources":["../../src/loaders/components.ts"],"sourcesContent":["import { join } from 'path';\nimport _ from 'lodash';\nimport { pathExists } from 'fs-extra';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { loadFiles } from '../utils/load-files';\n\ntype LoadedComponent = {\n collectionName: string;\n __filename__: string;\n __schema__: LoadedComponent;\n uid: string;\n category: string;\n modelName: string;\n globalId: string;\n info: any;\n attributes: any;\n};\n\ntype LoadedComponents = {\n [category: string]: {\n [key: string]: LoadedComponent;\n };\n};\n\ntype ComponentMap = {\n [uid in UID.Component]: Struct.ComponentSchema;\n};\n\nexport default async function loadComponents(strapi: Core.Strapi) {\n if (!(await pathExists(strapi.dirs.dist.components))) {\n return {};\n }\n\n const map = await loadFiles<LoadedComponents>(strapi.dirs.dist.components, '*/*.*(js|json)');\n\n const components = Object.keys(map).reduce((acc, category) => {\n Object.keys(map[category]).forEach((key) => {\n const schema = map[category][key];\n\n if (!schema.collectionName) {\n // NOTE: We're using the filepath from the app directory instead of the dist for information purpose\n const filePath = join(strapi.dirs.app.components, category, schema.__filename__);\n\n return strapi.stopWithError(\n `Component ${key} is missing a \"collectionName\" property.\\nVerify file ${filePath}.`\n );\n }\n\n const uid: UID.Component = `${category}.${key}`;\n\n acc[uid] = Object.assign(schema, {\n __schema__: _.cloneDeep(schema),\n uid,\n category,\n modelType: 'component' as const,\n modelName: key,\n globalId: schema.globalId || _.upperFirst(_.camelCase(`component_${uid}`)),\n });\n });\n\n return acc;\n }, {} as ComponentMap);\n\n strapi.get('components').add(components);\n}\n"],"names":["loadComponents","strapi","pathExists","dirs","dist","components","map","loadFiles","Object","keys","reduce","acc","category","forEach","key","schema","collectionName","filePath","join","app","__filename__","stopWithError","uid","assign","__schema__","_","cloneDeep","modelType","modelName","globalId","upperFirst","camelCase","get","add"],"mappings":";;;;;AA4Be,eAAeA,eAAeC,MAAmB,EAAA;IAC9D,IAAI,CAAE,MAAMC,UAAWD,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,CAAI,EAAA;AACpD,QAAA,OAAO,EAAC;AACV;IAEA,MAAMC,GAAAA,GAAM,MAAMC,SAA4BN,CAAAA,MAAAA,CAAOE,IAAI,CAACC,IAAI,CAACC,UAAU,EAAE,gBAAA,CAAA;IAE3E,MAAMA,UAAAA,GAAaG,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAAC,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;QAC/CJ,MAAOC,CAAAA,IAAI,CAACH,GAAG,CAACM,SAAS,CAAEC,CAAAA,OAAO,CAAC,CAACC,GAAAA,GAAAA;AAClC,YAAA,MAAMC,MAAST,GAAAA,GAAG,CAACM,QAAAA,CAAS,CAACE,GAAI,CAAA;YAEjC,IAAI,CAACC,MAAOC,CAAAA,cAAc,EAAE;;gBAE1B,MAAMC,QAAAA,GAAWC,IAAKjB,CAAAA,MAAAA,CAAOE,IAAI,CAACgB,GAAG,CAACd,UAAU,EAAEO,QAAUG,EAAAA,MAAAA,CAAOK,YAAY,CAAA;gBAE/E,OAAOnB,MAAAA,CAAOoB,aAAa,CACzB,CAAC,UAAU,EAAEP,GAAAA,CAAI,sDAAsD,EAAEG,QAAS,CAAA,CAAC,CAAC,CAAA;AAExF;AAEA,YAAA,MAAMK,GAAqB,GAAA,CAAA,EAAGV,QAAS,CAAA,CAAC,EAAEE,GAAK,CAAA,CAAA;AAE/CH,YAAAA,GAAG,CAACW,GAAI,CAAA,GAAGd,MAAOe,CAAAA,MAAM,CAACR,MAAQ,EAAA;gBAC/BS,UAAYC,EAAAA,CAAAA,CAAEC,SAAS,CAACX,MAAAA,CAAAA;AACxBO,gBAAAA,GAAAA;AACAV,gBAAAA,QAAAA;gBACAe,SAAW,EAAA,WAAA;gBACXC,SAAWd,EAAAA,GAAAA;AACXe,gBAAAA,QAAAA,EAAUd,MAAOc,CAAAA,QAAQ,IAAIJ,CAAAA,CAAEK,UAAU,CAACL,CAAEM,CAAAA,SAAS,CAAC,CAAC,UAAU,EAAET,GAAK,CAAA,CAAA,CAAA;AAC1E,aAAA,CAAA;AACF,SAAA,CAAA;QAEA,OAAOX,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;AAEJV,IAAAA,MAAAA,CAAO+B,GAAG,CAAC,YAAcC,CAAAA,CAAAA,GAAG,CAAC5B,UAAAA,CAAAA;AAC/B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n packageInfo?: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packageModulePath, isModule: client }),\n info: packageInfo.strapi,\n packageInfo,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n packageInfo,\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n declaredPlugins[pluginName].packageInfo = packageInfo;\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["INTERNAL_PLUGINS","isStrapiPlugin","info","get","validatePluginName","pluginName","strings","isKebabCase","Error","toDetailedDeclaration","declaration","enabled","detailedDeclaration","resolve","pathToPlugin","isModule","join","dirname","require","e","strapi","dirs","app","root","existsSync","statSync","isDirectory","getEnabledPlugins","client","internalPlugins","dep","packagePath","packageModulePath","paths","process","cwd","packageInfo","name","installedPlugins","dependencies","config","Object","keys","packageName","declaredPlugins","userPluginsConfig","getUserPluginsConfig","_","forEach","declaredPluginsResolves","map","prop","installedPluginsNotAlreadyUsed","pickBy","p","includes","enabledPlugins","pipe","defaultsDeep"],"mappings":";;;;;;;;;AA6BA;;;;;AAKC,IACD,MAAMA,gBAAmB,GAAA;AACvB,IAAA,yBAAA;AACA,IAAA,8BAAA;AACA,IAAA,eAAA;AACA,IAAA,gBAAA;AACA,IAAA,cAAA;AACA,IAAA,0BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,cAAiB,GAAA,CAACC,IAAqBC,GAAAA,MAAAA,CAAI,eAAeD,IAAU,CAAA,KAAA,QAAA;AAE1E,MAAME,qBAAqB,CAACC,UAAAA,GAAAA;AAC1B,IAAA,IAAI,CAACC,mBAAAA,CAAQC,WAAW,CAACF,UAAa,CAAA,EAAA;AACpC,QAAA,MAAM,IAAIG,KAAM,CAAA,CAAC,aAAa,EAAEH,UAAAA,CAAW,4CAA4C,CAAC,CAAA;AAC1F;AACF,CAAA;AAEA,MAAMI,wBAAwB,CAACC,WAAAA,GAAAA;IAC7B,IAAI,OAAOA,gBAAgB,SAAW,EAAA;QACpC,OAAO;YAAEC,OAASD,EAAAA;AAAY,SAAA;AAChC;AAEA,IAAA,MAAME,mBAAmE,GAAA;AACvED,QAAAA,OAAAA,EAASD,YAAYC;AACvB,KAAA;AAEA,IAAA,IAAID,aAAaG,OAAS,EAAA;AACxB,QAAA,IAAIC,YAAe,GAAA,EAAA;QAEnB,IAAIJ,WAAAA,CAAYK,QAAQ,EAAE;AACxB;;AAEC,UACDD,YAAeE,GAAAA,SAAAA,CAAKN,WAAYG,CAAAA,OAAO,EAAE,IAAA,CAAA;SACpC,MAAA;YACL,IAAI;AACFC,gBAAAA,YAAAA,GAAeG,YAAQC,CAAAA,OAAAA,CAAQL,OAAO,CAACH,YAAYG,OAAO,CAAA,CAAA;AAC5D,aAAA,CAAE,OAAOM,CAAG,EAAA;gBACVL,YAAeD,GAAAA,YAAAA,CAAQO,OAAOC,IAAI,CAACC,GAAG,CAACC,IAAI,EAAEb,WAAAA,CAAYG,OAAO,CAAA;AAEhE,gBAAA,IAAI,CAACW,aAAWV,CAAAA,YAAAA,CAAAA,IAAiB,CAACW,WAASX,CAAAA,YAAAA,CAAAA,CAAcY,WAAW,EAAI,EAAA;
|
|
1
|
+
{"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n packageInfo?: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packageModulePath, isModule: client }),\n info: packageInfo.strapi,\n packageInfo,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n packageInfo,\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n declaredPlugins[pluginName].packageInfo = packageInfo;\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["INTERNAL_PLUGINS","isStrapiPlugin","info","get","validatePluginName","pluginName","strings","isKebabCase","Error","toDetailedDeclaration","declaration","enabled","detailedDeclaration","resolve","pathToPlugin","isModule","join","dirname","require","e","strapi","dirs","app","root","existsSync","statSync","isDirectory","getEnabledPlugins","client","internalPlugins","dep","packagePath","packageModulePath","paths","process","cwd","packageInfo","name","installedPlugins","dependencies","config","Object","keys","packageName","declaredPlugins","userPluginsConfig","getUserPluginsConfig","_","forEach","declaredPluginsResolves","map","prop","installedPluginsNotAlreadyUsed","pickBy","p","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AMiB,WAAAA,GAAcf,UAAKF,YAAc,EAAA,cAAA,CAAA;AACvC,YAAA,MAAMsB,cAAclB,OAAQa,CAAAA,WAAAA,CAAAA;AAE5B,YAAA,IAAI9B,eAAemC,WAAc,CAAA,EAAA;gBAC/BQ,eAAe,CAACvC,WAAW,CAACH,IAAI,GAAGkC,WAAYhB,CAAAA,MAAM,IAAI,EAAC;AAC1DwB,gBAAAA,eAAe,CAACvC,UAAAA,CAAW,CAAC+B,WAAW,GAAGA,WAAAA;AAC5C;AACF;AACF,KAAA,CAAA;IAEA,MAAMa,uBAAAA,GAA0BC,MAAIC,CAAAA,OAAAA,CAAK,cAAiBP,CAAAA,EAAAA,eAAAA,CAAAA;IAC1D,MAAMQ,8BAAAA,GAAiCC,SACrC,CAAA,CAACC,CAAM,GAAA,CAACL,wBAAwBM,QAAQ,CAACD,CAAExC,CAAAA,YAAY,CACvDwB,EAAAA,gBAAAA,CAAAA;IAGF,MAAMkB,cAAAA,GAAiBC,OACrBC,CAAAA,eAAAA,CAAad,eACbc,CAAAA,EAAAA,eAAAA,CAAaN,8BACbC,CAAAA,EAAAA,SAAAA,CAAO,CAACC,CAAAA,GAAkBA,CAAE3C,CAAAA,OAAO,CACnCkB,CAAAA,CAAAA,eAAAA,CAAAA;IAEF,OAAO2B,cAAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n packageInfo?: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packageModulePath, isModule: client }),\n info: packageInfo.strapi,\n packageInfo,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n packageInfo,\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n declaredPlugins[pluginName].packageInfo = packageInfo;\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["INTERNAL_PLUGINS","isStrapiPlugin","info","get","validatePluginName","pluginName","strings","isKebabCase","Error","toDetailedDeclaration","declaration","enabled","detailedDeclaration","resolve","pathToPlugin","isModule","join","dirname","require","e","strapi","dirs","app","root","existsSync","statSync","isDirectory","getEnabledPlugins","client","internalPlugins","dep","packagePath","packageModulePath","paths","process","cwd","packageInfo","name","installedPlugins","dependencies","config","Object","keys","packageName","declaredPlugins","userPluginsConfig","getUserPluginsConfig","_","forEach","declaredPluginsResolves","map","prop","installedPluginsNotAlreadyUsed","pickBy","p","includes","enabledPlugins","pipe","defaultsDeep"],"mappings":";;;;;;;AA6BA;;;;;AAKC,IACD,MAAMA,gBAAmB,GAAA;AACvB,IAAA,yBAAA;AACA,IAAA,8BAAA;AACA,IAAA,eAAA;AACA,IAAA,gBAAA;AACA,IAAA,cAAA;AACA,IAAA,0BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,cAAiB,GAAA,CAACC,IAAqBC,GAAAA,GAAAA,CAAI,eAAeD,IAAU,CAAA,KAAA,QAAA;AAE1E,MAAME,qBAAqB,CAACC,UAAAA,GAAAA;AAC1B,IAAA,IAAI,CAACC,OAAAA,CAAQC,WAAW,CAACF,UAAa,CAAA,EAAA;AACpC,QAAA,MAAM,IAAIG,KAAM,CAAA,CAAC,aAAa,EAAEH,UAAAA,CAAW,4CAA4C,CAAC,CAAA;AAC1F;AACF,CAAA;AAEA,MAAMI,wBAAwB,CAACC,WAAAA,GAAAA;IAC7B,IAAI,OAAOA,gBAAgB,SAAW,EAAA;QACpC,OAAO;YAAEC,OAASD,EAAAA;AAAY,SAAA;AAChC;AAEA,IAAA,MAAME,mBAAmE,GAAA;AACvED,QAAAA,OAAAA,EAASD,YAAYC;AACvB,KAAA;AAEA,IAAA,IAAID,aAAaG,OAAS,EAAA;AACxB,QAAA,IAAIC,YAAe,GAAA,EAAA;QAEnB,IAAIJ,WAAAA,CAAYK,QAAQ,EAAE;AACxB;;AAEC,UACDD,YAAeE,GAAAA,IAAAA,CAAKN,WAAYG,CAAAA,OAAO,EAAE,IAAA,CAAA;SACpC,MAAA;YACL,IAAI;AACFC,gBAAAA,YAAAA,GAAeG,OAAQC,CAAAA,OAAAA,CAAQL,OAAO,CAACH,YAAYG,OAAO,CAAA,CAAA;AAC5D,aAAA,CAAE,OAAOM,CAAG,EAAA;gBACVL,YAAeD,GAAAA,OAAAA,CAAQO,OAAOC,IAAI,CAACC,GAAG,CAACC,IAAI,EAAEb,WAAAA,CAAYG,OAAO,CAAA;AAEhE,gBAAA,IAAI,CAACW,UAAWV,CAAAA,YAAAA,CAAAA,IAAiB,CAACW,QAASX,CAAAA,YAAAA,CAAAA,CAAcY,WAAW,EAAI,EAAA;
|
|
1
|
+
{"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n packageInfo?: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packageModulePath, isModule: client }),\n info: packageInfo.strapi,\n packageInfo,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n packageInfo,\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n declaredPlugins[pluginName].packageInfo = packageInfo;\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["INTERNAL_PLUGINS","isStrapiPlugin","info","get","validatePluginName","pluginName","strings","isKebabCase","Error","toDetailedDeclaration","declaration","enabled","detailedDeclaration","resolve","pathToPlugin","isModule","join","dirname","require","e","strapi","dirs","app","root","existsSync","statSync","isDirectory","getEnabledPlugins","client","internalPlugins","dep","packagePath","packageModulePath","paths","process","cwd","packageInfo","name","installedPlugins","dependencies","config","Object","keys","packageName","declaredPlugins","userPluginsConfig","getUserPluginsConfig","_","forEach","declaredPluginsResolves","map","prop","installedPluginsNotAlreadyUsed","pickBy","p","includes","enabledPlugins","pipe","defaultsDeep"],"mappings":";;;;;;;AA6BA;;;;;AAKC,IACD,MAAMA,gBAAmB,GAAA;AACvB,IAAA,yBAAA;AACA,IAAA,8BAAA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B,eAAemC,WAAc,CAAA,EAAA;gBAC/BQ,eAAe,CAACvC,WAAW,CAACH,IAAI,GAAGkC,WAAYhB,CAAAA,MAAM,IAAI,EAAC;AAC1DwB,gBAAAA,eAAe,CAACvC,UAAAA,CAAW,CAAC+B,WAAW,GAAGA,WAAAA;AAC5C;AACF;AACF,KAAA,CAAA;IAEA,MAAMa,uBAAAA,GAA0BC,GAAIC,CAAAA,IAAAA,CAAK,cAAiBP,CAAAA,EAAAA,eAAAA,CAAAA;IAC1D,MAAMQ,8BAAAA,GAAiCC,MACrC,CAAA,CAACC,CAAM,GAAA,CAACL,wBAAwBM,QAAQ,CAACD,CAAExC,CAAAA,YAAY,CACvDwB,EAAAA,gBAAAA,CAAAA;IAGF,MAAMkB,cAAAA,GAAiBC,IACrBC,CAAAA,YAAAA,CAAad,eACbc,CAAAA,EAAAA,YAAAA,CAAaN,8BACbC,CAAAA,EAAAA,MAAAA,CAAO,CAACC,CAAAA,GAAkBA,CAAE3C,CAAAA,OAAO,CACnCkB,CAAAA,CAAAA,eAAAA,CAAAA;IAEF,OAAO2B,cAAAA;AACT;;;;"}
|
|
@@ -117,7 +117,7 @@ async function loadPlugins(strapi1) {
|
|
|
117
117
|
try {
|
|
118
118
|
serverEntrypointPath = path.join(enabledPlugin.pathToPlugin, resolvedExport);
|
|
119
119
|
} catch (e) {
|
|
120
|
-
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove
|
|
120
|
+
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`);
|
|
121
121
|
}
|
|
122
122
|
// only load plugins with a server entrypoint
|
|
123
123
|
if (!await fse.pathExists(serverEntrypointPath)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa,CAAA,GAAA;AACf,KAAA;AACAC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,YAAAA,EAAc;AAChB,CAAA;AAEA,MAAMC,qBAAqB,OAAOC,OAAAA,GAAAA;AAChC,IAAA,MAAMC,gBAAgBC,MAAOC,CAAAA,IAAI,CAACC,IAAI,CAACC,UAAU;AACjD,IAAA,IAAI,CAAE,MAAMC,GAAIC,CAAAA,UAAU,CAACN,aAAiB,CAAA,EAAA;AAC1C,QAAA;AACF;IAEA,MAAMO,eAAAA,GAAkB,MAAMC,mBAAAA,CAAUR,aAAe,EAAA,iCAAA,CAAA;IACvD,MAAMS,aAAAA,GAAgB,MAAMD,mBAAAA,CAAUR,aAAe,EAAA,qBAAA,CAAA;AAErD,IAAA,K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AAAA,OAAO,CAAC,CAACC,UAAAA,GAAAA;QACnC,MAAM,EAAElC,MAAM,EAAE,GAAGkC,UAAAA;QAEnBxC,MAAOyC,CAAAA,MAAM,CAACnC,MAAQ,EAAA;YACpBJ,MAAQH,EAAAA,UAAAA;AACR2C,YAAAA,cAAAA,EACEpC,MAAOoC,CAAAA,cAAc,IAAI,CAAC,EAAE3C,UAAW,CAAA,CAAC,EAAEO,MAAAA,CAAOqC,IAAI,CAACC,YAAY,CAAC,CAAC,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,kBAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa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AAAA,aAAAA,CAAcI,MAAM,EAAEuD,aAAavD,MAAM,CAAA;AAC1DG,YAAAA,MAAAA,EAAQoD,YAAapD,CAAAA,MAAM,IAAIP,aAAAA,CAAcO;AAC/C,SAAA;AACF;;AAGA,IAAA,MAAM2B,eAAgBpB,CAAAA,OAAAA,CAAAA;AACtB,IAAA,MAAMD,kBAAmBC,CAAAA,OAAAA,CAAAA;AAEzB,IAAA,KAAK,MAAMW,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACb,OAAU,CAAA,CAAA;QAC7CE,OAAOe,CAAAA,GAAG,CAAC,SAAWgC,CAAAA,CAAAA,GAAG,CAACtC,UAAYX,EAAAA,OAAO,CAACW,UAAW,CAAA,CAAA;AAC3D;AACF;AAEA,MAAMoC,kBAAAA,GAAqB,CACzBpC,UACAb,EAAAA,YAAAA,GAAAA;AAEAc,IAAAA,MAAAA,CAAOsC,MAAM,CAACpD,YAAcqD,CAAAA,CAAAA,OAAO,CAAC,CAACC,UAAAA,GAAAA;QACnC,MAAM,EAAElC,MAAM,EAAE,GAAGkC,UAAAA;QAEnBxC,MAAOyC,CAAAA,MAAM,CAACnC,MAAQ,EAAA;YACpBJ,MAAQH,EAAAA,UAAAA;AACR2C,YAAAA,cAAAA,EACEpC,MAAOoC,CAAAA,cAAc,IAAI,CAAA,EAAG3C,UAAW,CAAA,CAAC,EAAEO,MAAAA,CAAOqC,IAAI,CAACC,YAAY,CAAA,CAAE,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,kBAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
@@ -96,7 +96,7 @@ async function loadPlugins(strapi1) {
|
|
|
96
96
|
try {
|
|
97
97
|
serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);
|
|
98
98
|
} catch (e) {
|
|
99
|
-
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove
|
|
99
|
+
throw new Error(`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`);
|
|
100
100
|
}
|
|
101
101
|
// only load plugins with a server entrypoint
|
|
102
102
|
if (!await fse.pathExists(serverEntrypointPath)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa,CAAA,GAAA;AACf,KAAA;AACAC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,YAAAA,EAAc;AAChB,CAAA;AAEA,MAAMC,qBAAqB,OAAOC,OAAAA,GAAAA;AACh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K,MAAMW,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACb,OAAU,CAAA,CAAA;QAC7CE,OAAOe,CAAAA,GAAG,CAAC,SAAWgC,CAAAA,CAAAA,GAAG,CAACtC,UAAYX,EAAAA,OAAO,CAACW,UAAW,CAAA,CAAA;AAC3D;AACF;AAEA,MAAMoC,kBAAAA,GAAqB,CACzBpC,UACAb,EAAAA,YAAAA,GAAAA;AAEAc,IAAAA,MAAAA,CAAOsC,MAAM,CAACpD,YAAcqD,CAAAA,CAAAA,OAAO,CAAC,CAACC,UAAAA,GAAAA;QACnC,MAAM,EAAElC,MAAM,EAAE,GAAGkC,UAAAA;QAEnBxC,MAAOyC,CAAAA,MAAM,CAACnC,MAAQ,EAAA;YACpBJ,MAAQH,EAAAA,UAAAA;AACR2C,YAAAA,cAAAA,EACEpC,MAAOoC,CAAAA,cAAc,IAAI,CAAC,EAAE3C,UAAW,CAAA,CAAC,EAAEO,MAAAA,CAAOqC,IAAI,CAACC,YAAY,CAAC,CAAC,CAACC,WAAW,EAAA;AAClFC,YAAAA,QAAAA,EAAUC,YAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove its configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["defaultPlugin","bootstrap","destroy","register","config","default","validator","routes","controllers","services","policies","middlewares","contentTypes","applyUserExtension","plugins","extensionsDir","strapi","dirs","dist","extensions","fse","pathExists","extendedSchemas","loadFiles","strapiServers","pluginName","Object","keys","plugin","ctName","extendedSchema","get","schema","strapiServer","applyUserConfig","userPluginsConfig","getUserPluginsConfig","userPluginConfig","getOr","defaultConfig","env","defaultsDeep","e","Error","message","loadPlugins","enabledPlugins","getEnabledPlugins","set","enabledPlugin","serverEntrypointPath","resolvedExport","resolve","exports","packageInfo","require","toString","join","pathToPlugin","pluginServer","loadConfigFile","formatContentTypes","defaults","add","values","forEach","definition","assign","collectionName","info","singularName","toLowerCase","globalId","getGlobalId"],"mappings":";;;;;;;;;;;AAiBA,MAAMA,aAAgB,GAAA;IACpBC,SAAa,CAAA,GAAA,EAAA;IACbC,OAAW,CAAA,GAAA,EAAA;IACXC,QAAY,CAAA,GAAA,EAAA;IACZC,MAAQ,EAAA;AACNC,QAAAA,OAAAA,EAAS,EAAC;QACVC,SAAa,CAAA,GAAA;AACf,KAAA;AACAC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,YAAAA,EAAc;AAChB,CAAA;AAEA,MAAMC,qBAAqB,OAAOC,OAAAA,GAAAA;AAChC,IAAA,MAAMC,gBAAgBC,MAAOC,CAAAA,IAAI,CAACC,IAAI,CAACC,UAAU;AACjD,IAAA,IAAI,CAAE,MAAMC,GAAIC,CAAAA,UAAU,CAACN,aAAiB,CAAA,EAAA;AAC1C,QAAA;AACF;IAEA,MAAMO,eAAAA,GAAkB,MAAMC,SAAAA,CAAUR,aAAe,EAAA,iCAAA,CAAA;IACvD,MAAMS,aAAAA,GAAgB,MAAMD,SAAAA,CAAUR,aAAe,EAAA,qBAAA,CAAA;AAErD,IAAA,KAAK,MAAMU,UAAAA,IAAcC,MAAOC,CAAAA,IAAI,CAACb,OAAU,CAAA,CAAA;QAC7C,MAAMc,MAAAA,GAASd,OAAO,CAACW,UAAW,CAAA;;AAElC,QAAA,KAAK,MAAMI,MAAUH,IAAAA,MAAAA,CAAOC,IAAI,CAACC,MAAAA,CAAOhB,YAAY,CAAG,CAAA;AACrD,YAAA,MAAMkB,iBAAiBC,GAAI,CAAA;AAACN,gBAAAA,UAAAA;AAAY,gBAAA,eAAA;AAAiBI,gBAAAA,MAAAA;AA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UC,YAAYzC,MAAQP,EAAAA,UAAAA;AAChC,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,OAAOb,YAAAA;AACT,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-index.js","sources":["../../src/loaders/src-index.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport { yup, importDefault } from '@strapi/utils';\n\nimport type { Core } from '@strapi/types';\n\nconst srcSchema = yup\n .object()\n .shape({\n bootstrap: yup.mixed().isFunction(),\n register: yup.mixed().isFunction(),\n destroy: yup.mixed().isFunction(),\n })\n .noUnknown();\n\nconst validateSrcIndex = (srcIndex: unknown) => {\n return srcSchema.validateSync(srcIndex, { strict: true, abortEarly: false });\n};\n\nexport default (strapi: Core.Strapi) => {\n if (!existsSync(strapi.dirs.dist.src)) {\n return;\n }\n\n const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');\n if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {\n return {};\n }\n\n const srcIndex = importDefault(pathToSrcIndex);\n\n try {\n validateSrcIndex(srcIndex);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n strapi.stopWithError({ message: `Invalid file \\`./src/index.js\\`: ${e.message}` });\n }\n\n throw e;\n }\n\n strapi.app = srcIndex;\n};\n"],"names":["srcSchema","yup","object","shape","bootstrap","mixed","isFunction","register","destroy","noUnknown","validateSrcIndex","srcIndex","validateSync","strict","abortEarly","strapi","existsSync","dirs","dist","src","pathToSrcIndex","resolve","statSync","isDirectory","importDefault","e","ValidationError","stopWithError","message","app"],"mappings":";;;;;;AAMA,MAAMA,SAAYC,GAAAA,eAAAA,CACfC,MAAM,EAAA,CACNC,KAAK,CAAC;IACLC,SAAWH,EAAAA,eAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU,EAAA;IACjCC,QAAUN,EAAAA,eAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU,EAAA;IAChCE,OAASP,EAAAA,eAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU;AACjC,CAAA,CAAA,CACCG,SAAS,EAAA;AAEZ,MAAMC,mBAAmB,CAACC,QAAAA,GAAAA;IACxB,OAAOX,SAAAA,CAAUY,YAAY,CAACD,QAAU,EAAA;QAAEE,MAAQ,EAAA,IAAA;QAAMC,UAAY,EAAA;AAAM,KAAA,CAAA;AAC5E,CAAA;AAEA,mBAAe,CAAA,CAACC,MAAAA,GAAAA;IACd,IAAI,CAACC,cAAWD,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,CAAG,EAAA;AACrC,QAAA;AACF;IAEA,MAAMC,cAAAA,GAAiBC,aAAQN,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,EAAE,UAAA,CAAA;AACrD,IAAA,IAAI,CAACH,aAAWI,CAAAA,cAAAA,CAAAA,IAAmBE,WAASF,CAAAA,cAAAA,CAAAA,CAAgBG,WAAW,EAAI,EAAA;AACzE,QAAA,OAAO,EAAC;AACV;AAEA,IAAA,MAAMZ,WAAWa,yBAAcJ,CAAAA,cAAAA,CAAAA;IAE/B,IAAI;QACFV,gBAAiBC,CAAAA,QAAAA,CAAAA;AACnB,KAAA,CAAE,OAAOc,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaxB,eAAIyB,CAAAA,eAAe,EAAE;AACpCX,YAAAA,MAAAA,CAAOY,aAAa,CAAC;AAAEC,gBAAAA,OAAAA,EAAS,CAAC,iCAAiC,EAAEH,CAAEG,
|
|
1
|
+
{"version":3,"file":"src-index.js","sources":["../../src/loaders/src-index.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport { yup, importDefault } from '@strapi/utils';\n\nimport type { Core } from '@strapi/types';\n\nconst srcSchema = yup\n .object()\n .shape({\n bootstrap: yup.mixed().isFunction(),\n register: yup.mixed().isFunction(),\n destroy: yup.mixed().isFunction(),\n })\n .noUnknown();\n\nconst validateSrcIndex = (srcIndex: unknown) => {\n return srcSchema.validateSync(srcIndex, { strict: true, abortEarly: false });\n};\n\nexport default (strapi: Core.Strapi) => {\n if (!existsSync(strapi.dirs.dist.src)) {\n return;\n }\n\n const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');\n if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {\n return {};\n }\n\n const srcIndex = importDefault(pathToSrcIndex);\n\n try {\n validateSrcIndex(srcIndex);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n strapi.stopWithError({ message: `Invalid file \\`./src/index.js\\`: ${e.message}` });\n }\n\n throw e;\n }\n\n strapi.app = srcIndex;\n};\n"],"names":["srcSchema","yup","object","shape","bootstrap","mixed","isFunction","register","destroy","noUnknown","validateSrcIndex","srcIndex","validateSync","strict","abortEarly","strapi","existsSync","dirs","dist","src","pathToSrcIndex","resolve","statSync","isDirectory","importDefault","e","ValidationError","stopWithError","message","app"],"mappings":";;;;;;AAMA,MAAMA,SAAYC,GAAAA,eAAAA,CACfC,MAAM,EAAA,CACNC,KAAK,CAAC;IACLC,SAAWH,EAAAA,eAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU,EAAA;IACjCC,QAAUN,EAAAA,eAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU,EAAA;IAChCE,OAASP,EAAAA,eAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU;AACjC,CAAA,CAAA,CACCG,SAAS,EAAA;AAEZ,MAAMC,mBAAmB,CAACC,QAAAA,GAAAA;IACxB,OAAOX,SAAAA,CAAUY,YAAY,CAACD,QAAU,EAAA;QAAEE,MAAQ,EAAA,IAAA;QAAMC,UAAY,EAAA;AAAM,KAAA,CAAA;AAC5E,CAAA;AAEA,mBAAe,CAAA,CAACC,MAAAA,GAAAA;IACd,IAAI,CAACC,cAAWD,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,CAAG,EAAA;AACrC,QAAA;AACF;IAEA,MAAMC,cAAAA,GAAiBC,aAAQN,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,EAAE,UAAA,CAAA;AACrD,IAAA,IAAI,CAACH,aAAWI,CAAAA,cAAAA,CAAAA,IAAmBE,WAASF,CAAAA,cAAAA,CAAAA,CAAgBG,WAAW,EAAI,EAAA;AACzE,QAAA,OAAO,EAAC;AACV;AAEA,IAAA,MAAMZ,WAAWa,yBAAcJ,CAAAA,cAAAA,CAAAA;IAE/B,IAAI;QACFV,gBAAiBC,CAAAA,QAAAA,CAAAA;AACnB,KAAA,CAAE,OAAOc,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaxB,eAAIyB,CAAAA,eAAe,EAAE;AACpCX,YAAAA,MAAAA,CAAOY,aAAa,CAAC;AAAEC,gBAAAA,OAAAA,EAAS,CAAC,iCAAiC,EAAEH,CAAAA,CAAEG,OAAO,CAAE;AAAC,aAAA,CAAA;AAClF;QAEA,MAAMH,CAAAA;AACR;AAEAV,IAAAA,MAAAA,CAAOc,GAAG,GAAGlB,QAAAA;AACf,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-index.mjs","sources":["../../src/loaders/src-index.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport { yup, importDefault } from '@strapi/utils';\n\nimport type { Core } from '@strapi/types';\n\nconst srcSchema = yup\n .object()\n .shape({\n bootstrap: yup.mixed().isFunction(),\n register: yup.mixed().isFunction(),\n destroy: yup.mixed().isFunction(),\n })\n .noUnknown();\n\nconst validateSrcIndex = (srcIndex: unknown) => {\n return srcSchema.validateSync(srcIndex, { strict: true, abortEarly: false });\n};\n\nexport default (strapi: Core.Strapi) => {\n if (!existsSync(strapi.dirs.dist.src)) {\n return;\n }\n\n const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');\n if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {\n return {};\n }\n\n const srcIndex = importDefault(pathToSrcIndex);\n\n try {\n validateSrcIndex(srcIndex);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n strapi.stopWithError({ message: `Invalid file \\`./src/index.js\\`: ${e.message}` });\n }\n\n throw e;\n }\n\n strapi.app = srcIndex;\n};\n"],"names":["srcSchema","yup","object","shape","bootstrap","mixed","isFunction","register","destroy","noUnknown","validateSrcIndex","srcIndex","validateSync","strict","abortEarly","strapi","existsSync","dirs","dist","src","pathToSrcIndex","resolve","statSync","isDirectory","importDefault","e","ValidationError","stopWithError","message","app"],"mappings":";;;;AAMA,MAAMA,SAAYC,GAAAA,GAAAA,CACfC,MAAM,EAAA,CACNC,KAAK,CAAC;IACLC,SAAWH,EAAAA,GAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU,EAAA;IACjCC,QAAUN,EAAAA,GAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU,EAAA;IAChCE,OAASP,EAAAA,GAAAA,CAAII,KAAK,EAAA,CAAGC,UAAU;AACjC,CAAA,CAAA,CACCG,SAAS,EAAA;AAEZ,MAAMC,mBAAmB,CAACC,QAAAA,GAAAA;IACxB,OAAOX,SAAAA,CAAUY,YAAY,CAACD,QAAU,EAAA;QAAEE,MAAQ,EAAA,IAAA;QAAMC,UAAY,EAAA;AAAM,KAAA,CAAA;AAC5E,CAAA;AAEA,mBAAe,CAAA,CAACC,MAAAA,GAAAA;IACd,IAAI,CAACC,WAAWD,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,CAAG,EAAA;AACrC,QAAA;AACF;IAEA,MAAMC,cAAAA,GAAiBC,QAAQN,MAAOE,CAAAA,IAAI,CAACC,IAAI,CAACC,GAAG,EAAE,UAAA,CAAA;AACrD,IAAA,IAAI,CAACH,UAAWI,CAAAA,cAAAA,CAAAA,IAAmBE,QAASF,CAAAA,cAAAA,CAAAA,CAAgBG,WAAW,EAAI,EAAA;AACzE,QAAA,OAAO,EAAC;AACV;AAEA,IAAA,MAAMZ,WAAWa,aAAcJ,CAAAA,cAAAA,CAAAA;IAE/B,IAAI;QACFV,gBAAiBC,CAAAA,QAAAA,CAAAA;AACnB,KAAA,CAAE,OAAOc,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaxB,GAAIyB,CAAAA,eAAe,EAAE;AACpCX,YAAAA,MAAAA,CAAOY,aAAa,CAAC;AAAEC,gBAAAA,OAAAA,EAAS,CAAC,iCAAiC,EAAEH,CAAEG,
|
|
1
|
+
{"version":3,"file":"src-index.mjs","sources":["../../src/loaders/src-index.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport { yup, importDefault } from '@strapi/utils';\n\nimport type { Core } from '@strapi/types';\n\nconst srcSchema = yup\n .object()\n .shape({\n bootstrap: yup.mixed().isFunction(),\n register: yup.mixed().isFunction(),\n destroy: yup.mixed().isFunction(),\n })\n .noUnknown();\n\nconst validateSrcIndex = (srcIndex: unknown) => {\n return srcSchema.validateSync(srcIndex, { strict: true, abortEarly: false });\n};\n\nexport default (strapi: Core.Strapi) => {\n if (!existsSync(strapi.dirs.dist.src)) {\n return;\n }\n\n const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');\n if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {\n return {};\n }\n\n const srcIndex = importDefault(pathToSrcIndex);\n\n try {\n validateSrcIndex(srcIndex);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n strapi.stopWithError({ message: `Invalid file \\`./src/index.js\\`: ${e.message}` });\n }\n\n throw e;\n }\n\n strapi.app = srcIndex;\n};\n"],"names":["srcSchema","yup","object","shape","bootstrap","mixed","isFunction","register","destroy","noUnknown","validateSrcIndex","srcIndex","validateSync","strict","abortEarly","strapi","existsSync","dirs","dist","src","pathToSrcIndex","resolve","statSync","isDirectory","importDefault","e","ValidationError","stopWithError","message","app"],"mappings":";;;;AAMA,MAAMA,SAAYC,GAAAA,GAAAA,CACfC,MAAM,EAAA,CACNC,KAAK,CAAC;IACLC,SAAWH,EAAAA,GAAAA,CA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'@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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