@strapi/core 0.0.0-experimental.a65a85fdea97faae8679d3ffc5f9d79af61abd26 → 0.0.0-experimental.abc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -3
- package/dist/Strapi.d.ts +3 -1
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +59 -15
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +38 -13
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/get-dirs.js +2 -2
- package/dist/configuration/get-dirs.js.map +1 -1
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/core-api/controller/collection-type.d.ts.map +1 -1
- package/dist/core-api/controller/collection-type.js +5 -3
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/collection-type.mjs +2 -0
- package/dist/core-api/controller/collection-type.mjs.map +1 -1
- package/dist/core-api/controller/index.js +2 -2
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/single-type.d.ts.map +1 -1
- package/dist/core-api/controller/single-type.js +3 -2
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/single-type.mjs +1 -0
- package/dist/core-api/controller/single-type.mjs.map +1 -1
- package/dist/core-api/controller/transform.js +8 -8
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/service/collection-type.d.ts +1 -7
- package/dist/core-api/service/collection-type.d.ts.map +1 -1
- package/dist/core-api/service/collection-type.js +3 -2
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs +4 -3
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/pagination.d.ts +4 -11
- package/dist/core-api/service/pagination.d.ts.map +1 -1
- package/dist/core-api/service/pagination.js +18 -44
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/core-api/service/pagination.mjs +16 -42
- package/dist/core-api/service/pagination.mjs.map +1 -1
- package/dist/domain/content-type/index.js +4 -4
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/ee/index.js +3 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/factories.js +4 -4
- package/dist/factories.js.map +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/apis.js +2 -2
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +34 -9
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +4 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +2 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.js +6 -6
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/middlewares/body.js +2 -2
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +9 -7
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +9 -7
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/middlewares/public.js +2 -2
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/query.d.ts.map +1 -1
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/query.mjs.map +1 -1
- package/dist/middlewares/responses.js +2 -2
- package/dist/middlewares/responses.js.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +12 -5
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +11 -4
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/middlewares/session.js +2 -2
- package/dist/middlewares/session.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +19 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +1 -0
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +2 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/draft-publish.d.ts.map +1 -1
- package/dist/migrations/draft-publish.js +14 -31
- package/dist/migrations/draft-publish.js.map +1 -1
- package/dist/migrations/draft-publish.mjs +15 -32
- package/dist/migrations/draft-publish.mjs.map +1 -1
- package/dist/registries/apis.js +2 -2
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/components.js +2 -2
- package/dist/registries/components.js.map +1 -1
- package/dist/registries/content-types.js +3 -3
- package/dist/registries/content-types.js.map +1 -1
- package/dist/registries/controllers.js +3 -3
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/custom-fields.js +4 -4
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/hooks.js +2 -2
- package/dist/registries/hooks.js.map +1 -1
- package/dist/registries/middlewares.js +3 -3
- package/dist/registries/middlewares.js.map +1 -1
- package/dist/registries/modules.js +3 -3
- package/dist/registries/modules.js.map +1 -1
- package/dist/registries/plugins.js +2 -2
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/policies.js +4 -4
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/services.js +3 -3
- package/dist/registries/services.js.map +1 -1
- package/dist/services/auth/index.js +3 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/core-store.js +3 -3
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/cron.js +3 -3
- package/dist/services/cron.js.map +1 -1
- package/dist/services/document-service/attributes/index.js +2 -2
- package/dist/services/document-service/attributes/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +3 -3
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.js +15 -15
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +16 -16
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/entries.d.ts +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +7 -6
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +2 -1
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/events.d.ts +25 -0
- package/dist/services/document-service/events.d.ts.map +1 -0
- package/dist/services/document-service/events.js +47 -0
- package/dist/services/document-service/events.js.map +1 -0
- package/dist/services/document-service/events.mjs +47 -0
- package/dist/services/document-service/events.mjs.map +1 -0
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/internationalization.d.ts.map +1 -1
- package/dist/services/document-service/internationalization.js +21 -12
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs +14 -5
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/params.js +2 -2
- package/dist/services/document-service/params.js.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +74 -46
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +69 -41
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/id-transform.js +2 -2
- package/dist/services/document-service/transform/id-transform.js.map +1 -1
- package/dist/services/document-service/transform/query.js +3 -3
- package/dist/services/document-service/transform/query.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +5 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs +3 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +5 -2
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +3 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.js +2 -2
- package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.js +13 -9
- package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs +7 -3
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js +4 -0
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +4 -0
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
- package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +4 -3
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +3 -3
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts +15 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +103 -51
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +89 -37
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +36 -25
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +134 -23
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +126 -15
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/event-hub.d.ts +1 -0
- package/dist/services/event-hub.d.ts.map +1 -1
- package/dist/services/event-hub.js +9 -4
- package/dist/services/event-hub.js.map +1 -1
- package/dist/services/event-hub.mjs +9 -4
- package/dist/services/event-hub.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js +7 -7
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/index.js +1 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/index.mjs +1 -1
- package/dist/services/server/index.mjs.map +1 -1
- package/dist/services/server/koa.js +3 -3
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +3 -3
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/routing.js +2 -2
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/utils/dynamic-zones.js +5 -5
- package/dist/services/utils/dynamic-zones.js.map +1 -1
- package/dist/services/webhook-runner.d.ts +2 -1
- package/dist/services/webhook-runner.d.ts.map +1 -1
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs.map +1 -1
- package/dist/services/webhook-store.d.ts +2 -8
- package/dist/services/webhook-store.d.ts.map +1 -1
- package/dist/services/webhook-store.js +9 -2
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +9 -2
- package/dist/services/webhook-store.mjs.map +1 -1
- package/dist/utils/cron.js +3 -3
- package/dist/utils/cron.js.map +1 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +4 -3
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +4 -3
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +27 -6
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs +25 -5
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/is-initialized.js +3 -3
- package/dist/utils/is-initialized.js.map +1 -1
- package/dist/utils/startup-logger.js +4 -4
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs +3 -3
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +16 -4
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +15 -3
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +16 -14
@@ -1,10 +1,11 @@
|
|
1
|
-
import { has,
|
2
|
-
import { errors } from "@strapi/utils";
|
1
|
+
import { has, isNil, omit, toNumber } from "lodash/fp";
|
2
|
+
import { errors, pagination } from "@strapi/utils";
|
3
3
|
const getLimitConfigDefaults = () => ({
|
4
4
|
defaultLimit: toNumber(strapi.config.get("api.rest.defaultLimit", 25)),
|
5
5
|
maxLimit: toNumber(strapi.config.get("api.rest.maxLimit")) || null
|
6
6
|
});
|
7
|
-
const
|
7
|
+
const isOffsetPagination = (pagination2) => has("start", pagination2) || has("limit", pagination2);
|
8
|
+
const isPagedPagination = (pagination2) => has("page", pagination2) || has("pageSize", pagination2) || !isOffsetPagination(pagination2);
|
8
9
|
const shouldCount = (params) => {
|
9
10
|
if (has("pagination.withCount", params)) {
|
10
11
|
const withCount = params.pagination?.withCount;
|
@@ -26,52 +27,25 @@ const shouldCount = (params) => {
|
|
26
27
|
}
|
27
28
|
return Boolean(strapi.config.get("api.rest.withCount", true));
|
28
29
|
};
|
29
|
-
const isOffsetPagination = (pagination) => has("start", pagination) || has("limit", pagination);
|
30
|
-
const isPagedPagination = (pagination) => has("page", pagination) || has("pageSize", pagination);
|
31
30
|
const getPaginationInfo = (params) => {
|
32
31
|
const { defaultLimit, maxLimit } = getLimitConfigDefaults();
|
33
|
-
const {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"Invalid pagination parameters. Expected either start/limit or page/pageSize"
|
39
|
-
);
|
40
|
-
}
|
41
|
-
if (!isOffset && !isPaged) {
|
42
|
-
return {
|
43
|
-
page: 1,
|
44
|
-
pageSize: defaultLimit
|
45
|
-
};
|
46
|
-
}
|
47
|
-
if (isPagedPagination(pagination)) {
|
48
|
-
const pageSize = isUndefined(pagination.pageSize) ? defaultLimit : Math.max(1, toNumber(pagination.pageSize));
|
49
|
-
return {
|
50
|
-
page: Math.max(1, toNumber(pagination.page || 1)),
|
51
|
-
pageSize: typeof maxLimit === "number" && shouldApplyMaxLimit(pageSize, maxLimit, { isPagedPagination: true }) ? maxLimit : Math.max(1, pageSize)
|
52
|
-
};
|
53
|
-
}
|
54
|
-
const limit = isUndefined(pagination.limit) ? defaultLimit : toNumber(pagination.limit);
|
55
|
-
return {
|
56
|
-
start: Math.max(0, toNumber(pagination.start || 0)),
|
57
|
-
limit: shouldApplyMaxLimit(limit, maxLimit) ? maxLimit || -1 : Math.max(1, limit)
|
58
|
-
};
|
32
|
+
const { start, limit } = pagination.withDefaultPagination(params.pagination || {}, {
|
33
|
+
defaults: { offset: { limit: defaultLimit }, page: { pageSize: defaultLimit } },
|
34
|
+
maxLimit: maxLimit || -1
|
35
|
+
});
|
36
|
+
return { start, limit };
|
59
37
|
};
|
60
|
-
const transformPaginationResponse = (paginationInfo,
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
total: count
|
66
|
-
};
|
38
|
+
const transformPaginationResponse = (paginationInfo, total, isPaged) => {
|
39
|
+
const transform = isPaged ? pagination.transformPagedPaginationInfo : pagination.transformOffsetPaginationInfo;
|
40
|
+
const paginationResponse = transform(paginationInfo, total);
|
41
|
+
if (isNil(total)) {
|
42
|
+
return omit(["total", "pageCount"], paginationResponse);
|
67
43
|
}
|
68
|
-
return
|
69
|
-
...paginationInfo,
|
70
|
-
total: count
|
71
|
-
};
|
44
|
+
return paginationResponse;
|
72
45
|
};
|
73
46
|
export {
|
74
47
|
getPaginationInfo,
|
48
|
+
isPagedPagination,
|
75
49
|
shouldCount,
|
76
50
|
transformPaginationResponse
|
77
51
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pagination.mjs","sources":["../../../src/core-api/service/pagination.ts"],"sourcesContent":["import { has, toNumber,
|
1
|
+
{"version":3,"file":"pagination.mjs","sources":["../../../src/core-api/service/pagination.ts"],"sourcesContent":["import { omit, has, toNumber, isNil } from 'lodash/fp';\n\nimport { errors, pagination } from '@strapi/utils';\n\ninterface BasePaginationParams {\n withCount?: boolean | 't' | '1' | 'true' | 'f' | '0' | 'false' | 0 | 1;\n}\n\ntype PagedPagination = BasePaginationParams & {\n page?: number;\n pageSize?: number;\n};\n\ntype OffsetPagination = BasePaginationParams & {\n start?: number;\n limit?: number;\n};\n\nexport type PaginationParams = PagedPagination | OffsetPagination;\n\ntype PaginationInfo =\n | {\n page: number;\n pageSize: number;\n }\n | {\n start: number;\n limit: number;\n };\n\n/**\n * Default limit values from config\n */\nconst getLimitConfigDefaults = () => ({\n defaultLimit: toNumber(strapi.config.get('api.rest.defaultLimit', 25)),\n maxLimit: toNumber(strapi.config.get('api.rest.maxLimit')) || null,\n});\n\nconst isOffsetPagination = (pagination?: PaginationParams): pagination is OffsetPagination =>\n has('start', pagination) || has('limit', pagination);\n\nconst isPagedPagination = (pagination?: PaginationParams): pagination is PagedPagination =>\n has('page', pagination) || has('pageSize', pagination) || !isOffsetPagination(pagination);\n\nconst shouldCount = (params: { pagination?: PaginationParams }) => {\n if (has('pagination.withCount', params)) {\n const withCount = params.pagination?.withCount;\n\n if (typeof withCount === 'boolean') {\n return withCount;\n }\n\n if (typeof withCount === 'undefined') {\n return false;\n }\n\n if (['true', 't', '1', 1].includes(withCount)) {\n return true;\n }\n\n if (['false', 'f', '0', 0].includes(withCount)) {\n return false;\n }\n\n throw new errors.ValidationError(\n 'Invalid withCount parameter. Expected \"t\",\"1\",\"true\",\"false\",\"0\",\"f\"'\n );\n }\n\n return Boolean(strapi.config.get('api.rest.withCount', true));\n};\n\nconst getPaginationInfo = (params: { pagination?: PaginationParams }): PaginationInfo => {\n const { defaultLimit, maxLimit } = getLimitConfigDefaults();\n\n const { start, limit } = pagination.withDefaultPagination(params.pagination || {}, {\n defaults: { offset: { limit: defaultLimit }, page: { pageSize: defaultLimit } },\n maxLimit: maxLimit || -1,\n });\n\n return { start, limit };\n};\n\nconst transformPaginationResponse = (\n paginationInfo: PaginationInfo,\n total: number | undefined,\n isPaged: boolean\n) => {\n const transform = isPaged\n ? pagination.transformPagedPaginationInfo\n : pagination.transformOffsetPaginationInfo;\n\n const paginationResponse = transform(paginationInfo, total!);\n\n if (isNil(total)) {\n // Ignore total and pageCount if `total` value is not available.\n return omit(['total', 'pageCount'], paginationResponse) as ReturnType<typeof transform>;\n }\n\n return paginationResponse;\n};\n\nexport { isPagedPagination, shouldCount, getPaginationInfo, transformPaginationResponse };\n"],"names":["pagination"],"mappings":";;AAiCA,MAAM,yBAAyB,OAAO;AAAA,EACpC,cAAc,SAAS,OAAO,OAAO,IAAI,yBAAyB,EAAE,CAAC;AAAA,EACrE,UAAU,SAAS,OAAO,OAAO,IAAI,mBAAmB,CAAC,KAAK;AAChE;AAEA,MAAM,qBAAqB,CAACA,gBAC1B,IAAI,SAASA,WAAU,KAAK,IAAI,SAASA,WAAU;AAErD,MAAM,oBAAoB,CAACA,gBACzB,IAAI,QAAQA,WAAU,KAAK,IAAI,YAAYA,WAAU,KAAK,CAAC,mBAAmBA,WAAU;AAEpF,MAAA,cAAc,CAAC,WAA8C;AAC7D,MAAA,IAAI,wBAAwB,MAAM,GAAG;AACjC,UAAA,YAAY,OAAO,YAAY;AAEjC,QAAA,OAAO,cAAc,WAAW;AAC3B,aAAA;AAAA,IACT;AAEI,QAAA,OAAO,cAAc,aAAa;AAC7B,aAAA;AAAA,IACT;AAEI,QAAA,CAAC,QAAQ,KAAK,KAAK,CAAC,EAAE,SAAS,SAAS,GAAG;AACtC,aAAA;AAAA,IACT;AAEI,QAAA,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE,SAAS,SAAS,GAAG;AACvC,aAAA;AAAA,IACT;AAEA,UAAM,IAAI,OAAO;AAAA,MACf;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO,QAAQ,OAAO,OAAO,IAAI,sBAAsB,IAAI,CAAC;AAC9D;AAEM,MAAA,oBAAoB,CAAC,WAA8D;AACvF,QAAM,EAAE,cAAc,SAAS,IAAI,uBAAuB;AAEpD,QAAA,EAAE,OAAO,UAAU,WAAW,sBAAsB,OAAO,cAAc,IAAI;AAAA,IACjF,UAAU,EAAE,QAAQ,EAAE,OAAO,aAAa,GAAG,MAAM,EAAE,UAAU,eAAe;AAAA,IAC9E,UAAU,YAAY;AAAA,EAAA,CACvB;AAEM,SAAA,EAAE,OAAO;AAClB;AAEA,MAAM,8BAA8B,CAClC,gBACA,OACA,YACG;AACH,QAAM,YAAY,UACd,WAAW,+BACX,WAAW;AAET,QAAA,qBAAqB,UAAU,gBAAgB,KAAM;AAEvD,MAAA,MAAM,KAAK,GAAG;AAEhB,WAAO,KAAK,CAAC,SAAS,WAAW,GAAG,kBAAkB;AAAA,EACxD;AAEO,SAAA;AACT;"}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
4
|
-
const _
|
3
|
+
const fp = require("lodash/fp");
|
4
|
+
const _ = require("lodash");
|
5
5
|
const strapiUtils = require("@strapi/utils");
|
6
6
|
const validator = require("./validator.js");
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
8
|
-
const ___default = /* @__PURE__ */ _interopDefault(_
|
8
|
+
const ___default = /* @__PURE__ */ _interopDefault(_);
|
9
9
|
const {
|
10
10
|
CREATED_AT_ATTRIBUTE,
|
11
11
|
UPDATED_AT_ATTRIBUTE,
|
@@ -23,7 +23,7 @@ ${e.errors}`);
|
|
23
23
|
}
|
24
24
|
throw e;
|
25
25
|
}
|
26
|
-
const { schema, actions, lifecycles } =
|
26
|
+
const { schema, actions, lifecycles } = fp.cloneDeep(definition);
|
27
27
|
Object.assign(schema, {
|
28
28
|
uid,
|
29
29
|
modelType: "contentType",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["contentTypesUtils","validateContentTypeDefinition","yup","cloneDeep","_"],"mappings":";;;;;;;;AAYA,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA,YAAAA,aAAkB;AAEhB,MAAA,oBAAoB,CAAC,KAAa,eAAsC;AACxE,MAAA;AACFC,cAAA,8BAA8B,UAAU;AAAA,WACjC,GAAG;AACN,QAAA,aAAaC,gBAAI,iBAAiB;AAC9B,YAAA,IAAI,MAAM,0CAA0C,GAAG;AAAA,EAAO,EAAE,MAAM,EAAE;AAAA,IAChF;AAEM,UAAA;AAAA,EACR;AAEA,QAAM,EAAE,QAAQ,SAAS,WAAW,IAAIC,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["contentTypesUtils","validateContentTypeDefinition","yup","cloneDeep","_"],"mappings":";;;;;;;;AAYA,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA,YAAAA,aAAkB;AAEhB,MAAA,oBAAoB,CAAC,KAAa,eAAsC;AACxE,MAAA;AACFC,cAAA,8BAA8B,UAAU;AAAA,WACjC,GAAG;AACN,QAAA,aAAaC,gBAAI,iBAAiB;AAC9B,YAAA,IAAI,MAAM,0CAA0C,GAAG;AAAA,EAAO,EAAE,MAAM,EAAE;AAAA,IAChF;AAEM,UAAA;AAAA,EACR;AAEA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AQ;AAAA,IACR,cAAc;AAAA,IACd,UAAU;AAAA,IACV,SAAS;AAAA,IACT,cAAc;AAAA,IACd,SAAS;AAAA,EAAA;AAEb;AAEM,MAAA,cAAc,CAAC,QAA4B,WAAoB;AAC7D,QAAA,YAAY,OAAO,KAAK;AAC9B,QAAM,WAAW,SAAS,GAAG,MAAM,IAAI,SAAS,KAAK;AAErD,SAAO,OAAO,YAAYA,mBAAE,WAAWA,WAAAA,QAAE,UAAU,QAAQ,CAAC;AAC9D;AAEA,MAAM,aAAa,CAAC,UAA8B;AAChD,QAAM,SAASA,WAAAA,QAAE;AAAA,IACfA,WAAA,QAAE,KAAK,OAAO;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EAAA;AAGI,SAAA,OAAO,MAAM,QAAQ;AACrB,SAAA;AACT;;;"}
|
package/dist/ee/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const license = require("./license.js");
|
4
4
|
const cron = require("../utils/cron.js");
|
5
5
|
const ONE_MINUTE = 1e3 * 60;
|
@@ -10,7 +10,7 @@ const ee = {
|
|
10
10
|
const disable = (message) => {
|
11
11
|
const shouldEmitEvent = ee.enabled !== false;
|
12
12
|
ee.logger?.warn(`${message} Switching to CE.`);
|
13
|
-
ee.licenseInfo =
|
13
|
+
ee.licenseInfo = fp.pick("licenseKey", ee.licenseInfo);
|
14
14
|
ee.enabled = false;
|
15
15
|
if (shouldEmitEvent) {
|
16
16
|
strapi.eventHub.emit("ee.disable");
|
@@ -73,7 +73,7 @@ const onlineUpdate = async ({ strapi: strapi2 }) => {
|
|
73
73
|
if (license$1) {
|
74
74
|
try {
|
75
75
|
const newLicenseInfo = license.verifyLicense(license$1);
|
76
|
-
const licenseInfoChanged = !
|
76
|
+
const licenseInfoChanged = !fp.isEqual(newLicenseInfo.features, ee.licenseInfo.features) || newLicenseInfo.seats !== ee.licenseInfo.seats || newLicenseInfo.type !== ee.licenseInfo.type;
|
77
77
|
ee.licenseInfo = newLicenseInfo;
|
78
78
|
const wasEnabled = ee.enabled;
|
79
79
|
validateInfo();
|
package/dist/ee/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/ee/index.ts"],"sourcesContent":["import { pick, isEqual } from 'lodash/fp';\nimport type { Logger } from '@strapi/logger';\nimport type { Core } from '@strapi/types';\n\nimport { readLicense, verifyLicense, fetchLicense, LicenseCheckError } from './license';\nimport { shiftCronExpression } from '../utils/cron';\n\nconst ONE_MINUTE = 1000 * 60;\n\ninterface EE {\n enabled: boolean;\n licenseInfo: {\n licenseKey?: string;\n features?: Array<{ name: string; [key: string]: any } | string>;\n expireAt?: string;\n seats?: number;\n type?: string;\n };\n logger?: Logger;\n}\n\nconst ee: EE = {\n enabled: false,\n licenseInfo: {},\n};\n\nconst disable = (message: string) => {\n // Prevent emitting ee.disable if it was already disabled\n const shouldEmitEvent = ee.enabled !== false;\n\n ee.logger?.warn(`${message} Switching to CE.`);\n // Only keep the license key for potential re-enabling during a later check\n ee.licenseInfo = pick('licenseKey', ee.licenseInfo);\n\n ee.enabled = false;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.disable');\n }\n};\n\nconst enable = () => {\n // Prevent emitting ee.enable if it was already enabled\n const shouldEmitEvent = ee.enabled !== true;\n\n ee.enabled = true;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.enable');\n }\n};\n\nlet initialized = false;\n\n/**\n * Optimistically enable EE if the format of the license is valid, only run once.\n */\nconst init = (licenseDir: string, logger?: Logger) => {\n if (initialized) {\n return;\n }\n\n initialized = true;\n ee.logger = logger;\n\n if (process.env.STRAPI_DISABLE_EE?.toLowerCase() === 'true') {\n return;\n }\n\n try {\n const license = process.env.STRAPI_LICENSE || readLicense(licenseDir);\n\n if (license) {\n ee.licenseInfo = verifyLicense(license);\n enable();\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n};\n\n/**\n * Contact the license registry to update the license to its latest state.\n *\n * Store the result in database to avoid unecessary requests, and will fallback to that in case of a network failure.\n */\nconst onlineUpdate = async ({ strapi }: { strapi: Core.Strapi }) => {\n const { get, commit, rollback } = (await strapi.db?.transaction()) as any;\n const transaction = get();\n\n try {\n const storedInfo = await strapi.db\n ?.queryBuilder('strapi::core-store')\n .where({ key: 'ee_information' })\n .select('value')\n .first()\n .transacting(transaction)\n .forUpdate()\n .execute()\n .then((result: any) => (result ? JSON.parse(result.value) : result));\n\n const shouldContactRegistry = (storedInfo?.lastCheckAt ?? 0) < Date.now() - ONE_MINUTE;\n const result: {\n license?: string | null;\n error?: string;\n lastCheckAt?: number;\n } = { lastCheckAt: Date.now() };\n\n const fallback = (error: Error) => {\n if (error instanceof LicenseCheckError && error.shouldFallback && storedInfo?.license) {\n ee.logger?.warn(\n `${error.message} The last stored one will be used as a potential fallback.`\n );\n return storedInfo.license;\n }\n\n result.error = error.message;\n disable(error.message);\n };\n\n if (!ee?.licenseInfo?.licenseKey) {\n throw new Error('Missing license key.');\n }\n\n const license = shouldContactRegistry\n ? await fetchLicense({ strapi }, ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(\n fallback\n )\n : storedInfo.license;\n\n if (license) {\n try {\n // Verify license and check if its info changed\n const newLicenseInfo = verifyLicense(license);\n const licenseInfoChanged =\n !isEqual(newLicenseInfo.features, ee.licenseInfo.features) ||\n newLicenseInfo.seats !== ee.licenseInfo.seats ||\n newLicenseInfo.type !== ee.licenseInfo.type;\n\n // Store the new license info\n ee.licenseInfo = newLicenseInfo;\n const wasEnabled = ee.enabled;\n validateInfo();\n\n // Notify EE features\n if (licenseInfoChanged && wasEnabled) {\n strapi.eventHub.emit('ee.update');\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n } else if (!shouldContactRegistry) {\n disable(storedInfo.error);\n }\n\n if (shouldContactRegistry) {\n result.license = license ?? null;\n const query = strapi.db.queryBuilder('strapi::core-store').transacting(transaction);\n\n if (!storedInfo) {\n query.insert({ key: 'ee_information', value: JSON.stringify(result) });\n } else {\n query.update({ value: JSON.stringify(result) }).where({ key: 'ee_information' });\n }\n\n await query.execute();\n }\n\n await commit();\n } catch (error) {\n // Example of errors: SQLite does not support FOR UPDATE\n await rollback();\n }\n};\n\nconst validateInfo = () => {\n if (typeof ee.licenseInfo.expireAt === 'undefined') {\n throw new Error('Missing license key.');\n }\n\n const expirationTime = new Date(ee.licenseInfo.expireAt).getTime();\n\n if (expirationTime < new Date().getTime()) {\n return disable('License expired.');\n }\n\n enable();\n};\n\nconst checkLicense = async ({ strapi }: { strapi: Core.Strapi }) => {\n const shouldStayOffline =\n ee.licenseInfo.type === 'gold' &&\n // This env variable support is temporarily used to ease the migration between online vs offline\n process.env.STRAPI_DISABLE_LICENSE_PING?.toLowerCase() === 'true';\n\n if (!shouldStayOffline) {\n await onlineUpdate({ strapi });\n strapi.cron.add({ [shiftCronExpression('0 0 */12 * * *')]: onlineUpdate });\n } else {\n if (!ee.licenseInfo.expireAt) {\n return disable('Your license does not have offline support.');\n }\n\n validateInfo();\n }\n};\n\nconst list = () => {\n return (\n ee.licenseInfo.features?.map((feature) =>\n typeof feature === 'object' ? feature : { name: feature }\n ) || []\n );\n};\n\nconst get = (featureName: string) => list().find((feature) => feature.name === featureName);\n\nexport default Object.freeze({\n init,\n checkLicense,\n\n get isEE() {\n return ee.enabled;\n },\n\n get seats() {\n return ee.licenseInfo.seats;\n },\n\n features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["pick","license","readLicense","verifyLicense","strapi","get","result","LicenseCheckError","fetchLicense","isEqual","shiftCronExpression"],"mappings":";;;;AAOA,MAA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AAO,KAAK,CAAC,YAAY,QAAQ,SAAS,WAAW;AAE1F,MAAe,QAAA,OAAO,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,GAAG;AAAA,EACZ;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,GAAG,YAAY;AAAA,EACxB;AAAA,EAEA,UAAU,OAAO,OAAO;AAAA,IACtB;AAAA,IACA;AAAA,IACA,WAAW,CAAC,gBAAwB,IAAI,WAAW,MAAM;AAAA,EAAA,CAC1D;AACH,CAAC;;"}
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/ee/index.ts"],"sourcesContent":["import { pick, isEqual } from 'lodash/fp';\nimport type { Logger } from '@strapi/logger';\nimport type { Core } from '@strapi/types';\n\nimport { readLicense, verifyLicense, fetchLicense, LicenseCheckError } from './license';\nimport { shiftCronExpression } from '../utils/cron';\n\nconst ONE_MINUTE = 1000 * 60;\n\ninterface EE {\n enabled: boolean;\n licenseInfo: {\n licenseKey?: string;\n features?: Array<{ name: string; [key: string]: any } | string>;\n expireAt?: string;\n seats?: number;\n type?: string;\n };\n logger?: Logger;\n}\n\nconst ee: EE = {\n enabled: false,\n licenseInfo: {},\n};\n\nconst disable = (message: string) => {\n // Prevent emitting ee.disable if it was already disabled\n const shouldEmitEvent = ee.enabled !== false;\n\n ee.logger?.warn(`${message} Switching to CE.`);\n // Only keep the license key for potential re-enabling during a later check\n ee.licenseInfo = pick('licenseKey', ee.licenseInfo);\n\n ee.enabled = false;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.disable');\n }\n};\n\nconst enable = () => {\n // Prevent emitting ee.enable if it was already enabled\n const shouldEmitEvent = ee.enabled !== true;\n\n ee.enabled = true;\n\n if (shouldEmitEvent) {\n // Notify EE features that they should be disabled\n strapi.eventHub.emit('ee.enable');\n }\n};\n\nlet initialized = false;\n\n/**\n * Optimistically enable EE if the format of the license is valid, only run once.\n */\nconst init = (licenseDir: string, logger?: Logger) => {\n if (initialized) {\n return;\n }\n\n initialized = true;\n ee.logger = logger;\n\n if (process.env.STRAPI_DISABLE_EE?.toLowerCase() === 'true') {\n return;\n }\n\n try {\n const license = process.env.STRAPI_LICENSE || readLicense(licenseDir);\n\n if (license) {\n ee.licenseInfo = verifyLicense(license);\n enable();\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n};\n\n/**\n * Contact the license registry to update the license to its latest state.\n *\n * Store the result in database to avoid unecessary requests, and will fallback to that in case of a network failure.\n */\nconst onlineUpdate = async ({ strapi }: { strapi: Core.Strapi }) => {\n const { get, commit, rollback } = (await strapi.db?.transaction()) as any;\n const transaction = get();\n\n try {\n const storedInfo = await strapi.db\n ?.queryBuilder('strapi::core-store')\n .where({ key: 'ee_information' })\n .select('value')\n .first()\n .transacting(transaction)\n .forUpdate()\n .execute()\n .then((result: any) => (result ? JSON.parse(result.value) : result));\n\n const shouldContactRegistry = (storedInfo?.lastCheckAt ?? 0) < Date.now() - ONE_MINUTE;\n const result: {\n license?: string | null;\n error?: string;\n lastCheckAt?: number;\n } = { lastCheckAt: Date.now() };\n\n const fallback = (error: Error) => {\n if (error instanceof LicenseCheckError && error.shouldFallback && storedInfo?.license) {\n ee.logger?.warn(\n `${error.message} The last stored one will be used as a potential fallback.`\n );\n return storedInfo.license;\n }\n\n result.error = error.message;\n disable(error.message);\n };\n\n if (!ee?.licenseInfo?.licenseKey) {\n throw new Error('Missing license key.');\n }\n\n const license = shouldContactRegistry\n ? await fetchLicense({ strapi }, ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(\n fallback\n )\n : storedInfo.license;\n\n if (license) {\n try {\n // Verify license and check if its info changed\n const newLicenseInfo = verifyLicense(license);\n const licenseInfoChanged =\n !isEqual(newLicenseInfo.features, ee.licenseInfo.features) ||\n newLicenseInfo.seats !== ee.licenseInfo.seats ||\n newLicenseInfo.type !== ee.licenseInfo.type;\n\n // Store the new license info\n ee.licenseInfo = newLicenseInfo;\n const wasEnabled = ee.enabled;\n validateInfo();\n\n // Notify EE features\n if (licenseInfoChanged && wasEnabled) {\n strapi.eventHub.emit('ee.update');\n }\n } catch (error) {\n if (error instanceof Error) {\n disable(error.message);\n } else {\n disable('Invalid license.');\n }\n }\n } else if (!shouldContactRegistry) {\n disable(storedInfo.error);\n }\n\n if (shouldContactRegistry) {\n result.license = license ?? null;\n const query = strapi.db.queryBuilder('strapi::core-store').transacting(transaction);\n\n if (!storedInfo) {\n query.insert({ key: 'ee_information', value: JSON.stringify(result) });\n } else {\n query.update({ value: JSON.stringify(result) }).where({ key: 'ee_information' });\n }\n\n await query.execute();\n }\n\n await commit();\n } catch (error) {\n // Example of errors: SQLite does not support FOR UPDATE\n await rollback();\n }\n};\n\nconst validateInfo = () => {\n if (typeof ee.licenseInfo.expireAt === 'undefined') {\n throw new Error('Missing license key.');\n }\n\n const expirationTime = new Date(ee.licenseInfo.expireAt).getTime();\n\n if (expirationTime < new Date().getTime()) {\n return disable('License expired.');\n }\n\n enable();\n};\n\nconst checkLicense = async ({ strapi }: { strapi: Core.Strapi }) => {\n const shouldStayOffline =\n ee.licenseInfo.type === 'gold' &&\n // This env variable support is temporarily used to ease the migration between online vs offline\n process.env.STRAPI_DISABLE_LICENSE_PING?.toLowerCase() === 'true';\n\n if (!shouldStayOffline) {\n await onlineUpdate({ strapi });\n strapi.cron.add({ [shiftCronExpression('0 0 */12 * * *')]: onlineUpdate });\n } else {\n if (!ee.licenseInfo.expireAt) {\n return disable('Your license does not have offline support.');\n }\n\n validateInfo();\n }\n};\n\nconst list = () => {\n return (\n ee.licenseInfo.features?.map((feature) =>\n typeof feature === 'object' ? feature : { name: feature }\n ) || []\n );\n};\n\nconst get = (featureName: string) => list().find((feature) => feature.name === featureName);\n\nexport default Object.freeze({\n init,\n checkLicense,\n\n get isEE() {\n return ee.enabled;\n },\n\n get seats() {\n return ee.licenseInfo.seats;\n },\n\n features: Object.freeze({\n list,\n get,\n isEnabled: (featureName: string) => get(featureName) !== undefined,\n }),\n});\n"],"names":["pick","license","readLicense","verifyLicense","strapi","get","result","LicenseCheckError","fetchLicense","isEqual","shiftCronExpression"],"mappings":";;;;AAOA,MAAM,aAAa,MAAO;AAc1B,MAAM,KAAS;AAAA,EACb,SAAS;AAAA,EACT,aAAa,CAAC;AAChB;AAEA,MAAM,UAAU,CAAC,YAAoB;AAE7B,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,QAAQ,KAAK,GAAG,OAAO,mBAAmB;AAE7C,KAAG,cAAcA,GAAA,KAAK,cAAc,GAAG,WAAW;AAElD,KAAG,UAAU;AAEb,MAAI,iBAAiB;AAEZ,WAAA,SAAS,KAAK,YAAY;AAAA,EACnC;AACF;AAEA,MAAM,SAAS,MAAM;AAEb,QAAA,kBAAkB,GAAG,YAAY;AAEvC,KAAG,UAAU;AAEb,MAAI,iBAAiB;AAEZ,WAAA,SAAS,KAAK,WAAW;AAAA,EAClC;AACF;AAEA,IAAI,cAAc;AAKlB,MAAM,OAAO,CAAC,YAAoB,WAAoB;AACpD,MAAI,aAAa;AACf;AAAA,EACF;AAEc,gBAAA;AACd,KAAG,SAAS;AAEZ,MAAI,QAAQ,IAAI,mBAAmB,YAAA,MAAkB,QAAQ;AAC3D;AAAA,EACF;AAEI,MAAA;AACF,UAAMC,YAAU,QAAQ,IAAI,kBAAkBC,QAAAA,YAAY,UAAU;AAEpE,QAAID,WAAS;AACR,SAAA,cAAcE,sBAAcF,SAAO;AAC/B;IACT;AAAA,WACO,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,cAAQ,MAAM,OAAO;AAAA,IAAA,OAChB;AACL,cAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AACF;AAOA,MAAM,eAAe,OAAO,EAAE,QAAAG,cAAsC;AAC5D,QAAA,EAAE,KAAAC,MAAK,QAAQ,SAAc,IAAA,MAAMD,QAAO,IAAI;AACpD,QAAM,cAAcC;AAEhB,MAAA;AACF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AA,GAAG,YAAY,UAAU;AAAA,IAAI,CAAC,YAC5B,OAAO,YAAY,WAAW,UAAU,EAAE,MAAM,QAAQ;AAAA,OACrD;AAET;AAEA,MAAM,MAAM,CAAC,gBAAwB,OAAO,KAAK,CAAC,YAAY,QAAQ,SAAS,WAAW;AAE1F,MAAe,QAAA,OAAO,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,GAAG;AAAA,EACZ;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,GAAG,YAAY;AAAA,EACxB;AAAA,EAEA,UAAU,OAAO,OAAO;AAAA,IACtB;AAAA,IACA;AAAA,IACA,WAAW,CAAC,gBAAwB,IAAI,WAAW,MAAM;AAAA,EAAA,CAC1D;AACH,CAAC;;"}
|
package/dist/factories.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const index = require("./core-api/controller/index.js");
|
5
5
|
const index$1 = require("./core-api/service/index.js");
|
6
6
|
const index$2 = require("./core-api/routes/index.js");
|
@@ -60,9 +60,9 @@ function createCoreRouter(uid, cfg) {
|
|
60
60
|
const defaultRoute = defaultRoutes[routeName];
|
61
61
|
Object.assign(defaultRoute.config, config[routeName] || {});
|
62
62
|
});
|
63
|
-
const selectedRoutes =
|
64
|
-
(routes2) => except ?
|
65
|
-
(routes2) => only ?
|
63
|
+
const selectedRoutes = fp.pipe(
|
64
|
+
(routes2) => except ? fp.omit(except, routes2) : routes2,
|
65
|
+
(routes2) => only ? fp.pick(only, routes2) : routes2
|
66
66
|
)(defaultRoutes);
|
67
67
|
routes = Object.values(selectedRoutes);
|
68
68
|
}
|
package/dist/factories.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"factories.js","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : cfg ?? ({} as any);\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : cfg ?? ({} as any);\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n Object.assign(defaultRoute.config, config[routeName] || {});\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 isCustomController = <T extends Core.Controller>(controller: T): boolean => {\n return symbols.CustomController in controller;\n};\n\nexport { createCoreController, createCoreService, createCoreRouter, isCustomController };\n"],"names":["strapi","createController","createService","createRoutes","pipe","routes","omit","pick"],"mappings":";;;;;;AAOA,MAAM,UAAU;AAAA,EACd,kBAAkB,OAAO,4BAA4B;AACvD;AAIM,MAAA,uBAAuB,CAI3B,KACA,QAGG;AACH,SAAO,CAAC;AAAA,IACN,QAAAA;AAAAA,EAAA,MAG6D;AACvD,UAAA,iBAAiBC,uBAAiB,EAAE,aAAaD,QAAO,YAAY,GAAG,GAAG;AAE1E,UAAA,WAAW,OAAO,QAAQ,aAAa,IAAI,EAAE,QAAAA,QAAQ,CAAA,IAAI,OAAQ;AAEvE,eAAW,cAAc,OAAO,KAAK,cAAc,GAAyC;AACtF,UAAA,SAAS,UAAU,MAAM,QAAW;AAC7B,iBAAA,UAAU,IAAI,eAAe,UAAU;AAAA,MAClD;AAAA,IACF;AAEO,WAAA,eAAe,UAAU,cAAc;AAExC,UAAA,WAAW,OAAO,QAAQ;AAChC,QAAI,UAAU;AACL,aAAA,eAAe,UAAU,QAAQ,kBAAkB;AAAA,QACxD,UAAU;AAAA,QACV,cAAc;AAAA,QACd,YAAY;AAAA,MAAA,CACb;AAAA,IACH;AAEO,WAAA;AAAA,EAAA;AAEX;AAEA,SAAS,kBAIP,KACA,KACA;AACA,SAAO,CAAC;AAAA,IACN,QAAAA;AAAAA,EAAA,MAGuD;AACjD,UAAA,cAAcE,sBAAc,EAAE,aAAaF,QAAO,YAAY,GAAG,GAAG;AAEpE,UAAA,cAAc,OAAO,QAAQ,aAAa,IAAI,EAAE,QAAAA,QAAQ,CAAA,IAAI,OAAQ;AAE1E,eAAW,cAAc,OAAO,KAAK,WAAW,GAAsC;AAChF,UAAA,YAAY,UAAU,MAAM,QAAW;AAC7B,oBAAA,UAAU,IAAI,YAAY,UAAU;AAAA,MAClD;AAAA,IACF;AAEO,WAAA,eAAe,aAAa,WAAW;AACvC,WAAA;AAAA,EAAA;AAEX;AAEA,SAAS,iBACP,KACA,KAC4B;AACtB,QAAA,EAAE,QAAQ,SAAS,CAAA,GAAI,MAAM,QAAQ,OAAO,cAAA,IAAkB,OAAO;AACvE,MAAA;AAEG,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,SAAS;AACX,UAAI,CAAC,QAAQ;AACL,cAAA,cAAc,OAAO,YAAY,GAAG;AAE1C,cAAM,gBAAgBG,QAAAA,aAAa,EAAE,YAAa,CAAA;AAC5C,cAAA,OAAO,OAAO,KAAK,aAAa;AAEjC,aAAA,QAAQ,CAAC,cAAc;AACpB,gBAAA,eAAe,cAAc,SAAS;AAE5C,iBAAO,OAAO,aAAa,QAAQ,OAAO,SAAS,KAAK,CAAA,CAAE;AAAA,QAAA,CAC3D;AAED,cAAM,iBAAiBC,
|
1
|
+
{"version":3,"file":"factories.js","sources":["../src/factories.ts"],"sourcesContent":["import { pipe, omit, pick } from 'lodash/fp';\nimport type { Core, UID, Utils } from '@strapi/types';\n\nimport { createController } from './core-api/controller';\nimport { createService } from './core-api/service';\nimport { createRoutes } from './core-api/routes';\n\nconst symbols = {\n CustomController: Symbol('StrapiCustomCoreController'),\n} as const;\n\ntype WithStrapiCallback<T> = T | (<S extends { strapi: Core.Strapi }>(params: S) => T);\n\nconst createCoreController = <\n TUID extends UID.ContentType,\n TController extends Core.CoreAPI.Controller.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<\n Utils.PartialWithThis<Core.CoreAPI.Controller.Extendable<TUID> & TController>\n >\n) => {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TController & Core.CoreAPI.Controller.ContentType<TUID> => {\n const baseController = createController({ contentType: strapi.contentType(uid) });\n\n const userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : cfg ?? ({} as any);\n\n for (const methodName of Object.keys(baseController) as Array<keyof typeof baseController>) {\n if (userCtrl[methodName] === undefined) {\n userCtrl[methodName] = baseController[methodName];\n }\n }\n\n Object.setPrototypeOf(userCtrl, baseController);\n\n const isCustom = typeof cfg !== 'undefined';\n if (isCustom) {\n Object.defineProperty(userCtrl, symbols.CustomController, {\n writable: false,\n configurable: false,\n enumerable: false,\n });\n }\n\n return userCtrl;\n };\n};\n\nfunction createCoreService<\n TUID extends UID.ContentType,\n TService extends Core.CoreAPI.Service.Extendable<TUID>,\n>(\n uid: TUID,\n cfg?: WithStrapiCallback<Utils.PartialWithThis<Core.CoreAPI.Service.Extendable<TUID> & TService>>\n) {\n return ({\n strapi,\n }: {\n strapi: Core.Strapi;\n }): TService & Core.CoreAPI.Service.ContentType<TUID> => {\n const baseService = createService({ contentType: strapi.contentType(uid) });\n\n const userService = typeof cfg === 'function' ? cfg({ strapi }) : cfg ?? ({} as any);\n\n for (const methodName of Object.keys(baseService) as Array<keyof typeof baseService>) {\n if (userService[methodName] === undefined) {\n userService[methodName] = baseService[methodName];\n }\n }\n\n Object.setPrototypeOf(userService, baseService);\n return userService;\n };\n}\n\nfunction createCoreRouter<T extends UID.ContentType>(\n uid: T,\n cfg?: Core.CoreAPI.Router.RouterConfig<T>\n): Core.CoreAPI.Router.Router {\n const { prefix, config = {}, only, except, type = 'content-api' } = cfg ?? {};\n let routes: Core.CoreAPI.Router.Route[];\n\n return {\n type,\n prefix,\n get routes() {\n if (!routes) {\n const contentType = strapi.contentType(uid);\n\n const defaultRoutes = createRoutes({ contentType });\n const keys = Object.keys(defaultRoutes) as Array<keyof typeof defaultRoutes>;\n\n keys.forEach((routeName) => {\n const defaultRoute = defaultRoutes[routeName];\n\n Object.assign(defaultRoute.config, config[routeName] || {});\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 isCustomController = <T extends Core.Controller>(controller: T): boolean => {\n return symbols.CustomController in controller;\n};\n\nexport { createCoreController, createCoreService, createCoreRouter, isCustomController };\n"],"names":["strapi","createController","createService","createRoutes","pipe","routes","omit","pick"],"mappings":";;;;;;AAOA,MAAM,UAAU;AAAA,EACd,kBAAkB,OAAO,4BAA4B;AACvD;AAIM,MAAA,uBAAuB,CAI3B,KACA,QAGG;AACH,SAAO,CAAC;AAAA,IACN,QAAAA;AAAAA,EAAA,MAG6D;AACvD,UAAA,iBAAiBC,uBAAiB,EAAE,aAAaD,QAAO,YAAY,GAAG,GAAG;AAE1E,UAAA,WAAW,OAAO,QAAQ,aAAa,IAAI,EAAE,QAAAA,QAAQ,CAAA,IAAI,OAAQ;AAEvE,eAAW,cAAc,OAAO,KAAK,cAAc,GAAyC;AACtF,UAAA,SAAS,UAAU,MAAM,QAAW;AAC7B,iBAAA,UAAU,IAAI,eAAe,UAAU;AAAA,MAClD;AAAA,IACF;AAEO,WAAA,eAAe,UAAU,cAAc;AAExC,UAAA,WAAW,OAAO,QAAQ;AAChC,QAAI,UAAU;AACL,aAAA,eAAe,UAAU,QAAQ,kBAAkB;AAAA,QACxD,UAAU;AAAA,QACV,cAAc;AAA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EAAA;AAEJ;AAEM,MAAA,qBAAqB,CAA4B,eAA2B;AAChF,SAAO,QAAQ,oBAAoB;AACrC;;;;;"}
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
+
import * as qs from 'qs';
|
1
2
|
import type { Core } from '@strapi/types';
|
2
3
|
import Strapi, { type StrapiOptions } from './Strapi';
|
3
4
|
export { default as compileStrapi } from './compile';
|
4
5
|
export * as factories from './factories';
|
5
6
|
export declare const createStrapi: (options?: Partial<StrapiOptions>) => Core.Strapi;
|
7
|
+
declare module 'koa' {
|
8
|
+
type ParsedQuery = ReturnType<typeof qs.parse>;
|
9
|
+
interface BaseRequest {
|
10
|
+
_querycache?: ParsedQuery;
|
11
|
+
get query(): ParsedQuery;
|
12
|
+
set query(obj: any);
|
13
|
+
}
|
14
|
+
interface BaseContext {
|
15
|
+
_querycache?: ParsedQuery;
|
16
|
+
get query(): ParsedQuery;
|
17
|
+
set query(obj: any);
|
18
|
+
}
|
19
|
+
}
|
6
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,MAAM,EAAE,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,aAAa,QAAQ,aAAa,CAAC,KAAQ,WAanE,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,MAAM,EAAE,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,aAAa,QAAQ,aAAa,CAAC,KAAQ,WAanE,CAAC;AAIF,OAAO,QAAQ,KAAK,CAAC;IACnB,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAE/C,UAAiB,WAAW;QAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;QAE1B,IAAI,KAAK,IAAI,WAAW,CAAC;QACzB,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE;KACrB;IAED,UAAiB,WAAW;QAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;QAE1B,IAAI,KAAK,IAAI,WAAW,CAAC;QACzB,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE;KACrB;CACF"}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n"],"names":["resolveWorkingDirectories","destroyOnSignal","createUpdateNotifier"],"mappings":";;;;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import * as qs from 'qs';\nimport type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n\n// Augment Koa query type based on Strapi query middleware\n\ndeclare module 'koa' {\n type ParsedQuery = ReturnType<typeof qs.parse>;\n\n export interface BaseRequest {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n\n export interface BaseContext {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n}\n"],"names":["resolveWorkingDirectories","destroyOnSignal","createUpdateNotifier"],"mappings":";;;;;;;;;;;;;;;;;AASO,MAAM,eAAe,CAAC,UAAkC,OAAoB;AAC3E,QAAA,SAAS,IAAI,OAAO;AAAA,IACxB,GAAG;AAAA,IACH,GAAGA,mBAAAA,0BAA0B,OAAO;AAAA,EAAA,CACrC;AAEDC,UAAA,gBAAgB,MAAM;AACtBC,QAAA,qBAAqB,MAAM;AAG3B,SAAO,SAAS;AAET,SAAA;AACT;;;;"}
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import * as qs from 'qs';\nimport type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n\n// Augment Koa query type based on Strapi query middleware\n\ndeclare module 'koa' {\n type ParsedQuery = ReturnType<typeof qs.parse>;\n\n export interface BaseRequest {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n\n export interface BaseContext {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AASO,MAAM,eAAe,CAAC,UAAkC,OAAoB;AAC3E,QAAA,SAAS,IAAI,OAAO;AAAA,IACxB,GAAG;AAAA,IACH,GAAG,0BAA0B,OAAO;AAAA,EAAA,CACrC;AAED,kBAAgB,MAAM;AACtB,uBAAqB,MAAM;AAG3B,SAAO,SAAS;AAET,SAAA;AACT;"}
|
package/dist/loaders/apis.js
CHANGED
@@ -3,7 +3,7 @@ const path = require("path");
|
|
3
3
|
const fse = require("fs-extra");
|
4
4
|
const _ = require("lodash");
|
5
5
|
const strapiUtils = require("@strapi/utils");
|
6
|
-
const
|
6
|
+
const fp = require("lodash/fp");
|
7
7
|
const index = require("../domain/content-type/index.js");
|
8
8
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
9
9
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
@@ -91,7 +91,7 @@ const loadContentTypes = async (apiName, dir) => {
|
|
91
91
|
}
|
92
92
|
const contentTypeName = normalizeName(fd.name);
|
93
93
|
const loadedContentType = (await loadDir(path.join(dir, fd.name)))?.result;
|
94
|
-
if (
|
94
|
+
if (fp.isEmpty(loadedContentType) || fp.isEmpty(loadedContentType.schema)) {
|
95
95
|
throw new Error(`Could not load content type found at ${dir}`);
|
96
96
|
}
|
97
97
|
const contentType = {
|
package/dist/loaders/apis.js.map
CHANGED
@@ -1 +1 @@
|
|
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":["strings","_","existsSync","fse","join","index","isEmpty","getGlobalId","extname","basename","importDefault"],"mappings":";;;;;;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf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,MAAMD,KAAAA,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,KAAK,MAAM,SAASJ,KAAA,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG;AAAA,EAClE;AAEO,SAAA,EAAE,QAAQ;AACnB;AAGA,MAAM,WAAW,OAAO,SAA+C;AAC/D,QAAA,MAAMI,aAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,EAAE,QAAQE,0BAAc,IAAI,EAAE;AAAA,IACvC,KAAK;AACH,aAAO,EAAE,QAAQ,MAAMP,aAAAA,QAAI,SAAS,IAAI,EAAE;AAAA,IAC5C;AACS,aAAA,EAAE,QAAQ,CAAA;EACrB;AACF;;"}
|
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":["strings","_","existsSync","fse","join","index","isEmpty","getGlobalId","extname","basename","importDefault"],"mappings":";;;;;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AG,OAAO,KAAKK,aAAQ,GAAG,IAAI,MAAM,QAAQ;AAC/C;AAAA,IACF;AAEA,UAAM,MAAMC,KAAS,SAAA,GAAG,MAAMD,KAAAA,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,KAAK,MAAM,SAASJ,KAAA,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG;AAAA,EAClE;AAEO,SAAA,EAAE,QAAQ;AACnB;AAGA,MAAM,WAAW,OAAO,SAA+C;AAC/D,QAAA,MAAMI,aAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,EAAE,QAAQE,0BAAc,IAAI,EAAE;AAAA,IACvC,KAAK;AACH,aAAO,EAAE,QAAQ,MAAMP,aAAAA,QAAI,SAAS,IAAI,EAAE;AAAA,IAC5C;AACS,aAAA,EAAE,QAAQ,CAAA;EACrB;AACF;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.d.ts","sourceRoot":"","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"get-enabled-plugins.d.ts","sourceRoot":"","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAiF1C,eAAO,MAAM,iBAAiB,WAAkB,KAAK,MAAM;;kBAiF1D,CAAC"}
|
@@ -1,9 +1,31 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
+
for (let key of __getOwnPropNames(from))
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
+
}
|
14
|
+
return to;
|
15
|
+
};
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
2
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
25
|
const path = require("path");
|
4
26
|
const fs = require("fs");
|
5
27
|
const _ = require("lodash");
|
6
|
-
const
|
28
|
+
const fp = require("lodash/fp");
|
7
29
|
const strapiUtils = require("@strapi/utils");
|
8
30
|
const getUserPluginsConfig = require("./get-user-plugins-config.js");
|
9
31
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
@@ -17,7 +39,7 @@ const INTERNAL_PLUGINS = [
|
|
17
39
|
"@strapi/content-releases",
|
18
40
|
"@strapi/review-workflows"
|
19
41
|
];
|
20
|
-
const isStrapiPlugin = (info) =>
|
42
|
+
const isStrapiPlugin = (info) => fp.get("strapi.kind", info) === "plugin";
|
21
43
|
const validatePluginName = (pluginName) => {
|
22
44
|
if (!strapiUtils.strings.isKebabCase(pluginName)) {
|
23
45
|
throw new Error(`Plugin name "${pluginName}" is not in kebab (an-example-of-kebab-case)`);
|
@@ -52,7 +74,10 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
52
74
|
const internalPlugins = {};
|
53
75
|
for (const dep of INTERNAL_PLUGINS) {
|
54
76
|
const packagePath = path.join(dep, "package.json");
|
55
|
-
const
|
77
|
+
const packageModulePath = require.resolve(packagePath, {
|
78
|
+
paths: [require.resolve("@strapi/strapi/package.json"), process.cwd()]
|
79
|
+
});
|
80
|
+
const packageInfo = require(packageModulePath);
|
56
81
|
validatePluginName(packageInfo.strapi.name);
|
57
82
|
internalPlugins[packageInfo.strapi.name] = {
|
58
83
|
...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),
|
@@ -97,15 +122,15 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
97
122
|
}
|
98
123
|
}
|
99
124
|
});
|
100
|
-
const declaredPluginsResolves =
|
101
|
-
const installedPluginsNotAlreadyUsed =
|
125
|
+
const declaredPluginsResolves = fp.map(fp.prop("pathToPlugin"), declaredPlugins);
|
126
|
+
const installedPluginsNotAlreadyUsed = fp.pickBy(
|
102
127
|
(p) => !declaredPluginsResolves.includes(p.pathToPlugin),
|
103
128
|
installedPlugins
|
104
129
|
);
|
105
|
-
const enabledPlugins =
|
106
|
-
|
107
|
-
|
108
|
-
|
130
|
+
const enabledPlugins = fp.pipe(
|
131
|
+
fp.defaultsDeep(declaredPlugins),
|
132
|
+
fp.defaultsDeep(installedPluginsNotAlreadyUsed),
|
133
|
+
fp.pickBy((p) => p.enabled)
|
109
134
|
)(internalPlugins);
|
110
135
|
return enabledPlugins;
|
111
136
|
};
|
@@ -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}\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 */\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 const
|
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}\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: packagePath, isModule: client }),\n info: packageInfo.strapi,\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 };\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 }\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":["get","strings","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,GAAAA,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAACC,YAAA,QAAQ,YAAY,UAAU,GAAG;AACpC,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;AAAA,IACvE,SAAS,YAAY;AAAA,EAAA;AAGvB,MAAI,aAAa,SAAS;AACxB,QAAI,eAAe;AAEnB,QAAI,YAAY,UAAU;AAIT,qBAAAC,KAAAA,KAAK,YAAY,SAAS,IAAI;AAAA,IAAA,OACxC;AACD,UAAA;AACF,uBAAeC,KAAQ,QAAA,QAAQ,QAAQ,YAAY,OAAO,CAAC;AAAA,eACpD,GAAG;AACV,uBAAeC,KAAAA,QAAQ,OAAO,KAAK,IAAI,MAAM,YAAY,OAAO;AAE5D,YAAA,CAACC,cAAW,YAAY,KAAK,CAACC,GAAAA,SAAS,YAAY,EAAE,eAAe;AACtE,gBAAM,IAAI,MAAM,GAAG,YAAY,OAAO,uBAAuB;AAAA,QAC/D;AAA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Aa,eAAe;AACxD,uBAAmB,UAAU;AAE7B,oBAAgB,UAAU,IAAI;AAAA,MAC5B,GAAG,sBAAsB,WAAW;AAAA,MACpC,MAAM,CAAC;AAAA,IAAA;AAGT,UAAM,EAAE,aAAA,IAAiB,gBAAgB,UAAU;AAGnD,QAAI,cAAc;AACV,YAAA,cAAcP,KAAAA,KAAK,cAAc,cAAc;AAC/C,YAAA,cAAc,QAAQ,WAAW;AAEnC,UAAA,eAAe,WAAW,GAAG;AAC/B,wBAAgB,UAAU,EAAE,OAAO,YAAY,UAAU,CAAA;AAAA,MAC3D;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0BQ,GAAAA,IAAIC,GAAAA,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiCC,GAAA;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiBC,GAAA;AAAA,IACrBC,GAAAA,aAAa,eAAe;AAAA,IAC5BA,GAAAA,aAAa,8BAA8B;AAAA,IAC3CF,GAAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
|
@@ -48,7 +48,10 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
48
48
|
const internalPlugins = {};
|
49
49
|
for (const dep of INTERNAL_PLUGINS) {
|
50
50
|
const packagePath = join(dep, "package.json");
|
51
|
-
const
|
51
|
+
const packageModulePath = require.resolve(packagePath, {
|
52
|
+
paths: [require.resolve("@strapi/strapi/package.json"), process.cwd()]
|
53
|
+
});
|
54
|
+
const packageInfo = require(packageModulePath);
|
52
55
|
validatePluginName(packageInfo.strapi.name);
|
53
56
|
internalPlugins[packageInfo.strapi.name] = {
|
54
57
|
...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),
|
@@ -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}\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 */\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 const
|
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}\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: packagePath, isModule: client }),\n info: packageInfo.strapi,\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 };\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 }\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":["strapi"],"mappings":";;;;;;AAkCA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqB,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAAC,QAAQ,YAAY,UAAU,GAAG;AACpC,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;AAAA,IACvE,SAAS,YAAY;AAAA,EAAA;AAGvB,MAAI,aAAa,SAAS;AACxB,QAAI,eAAe;AAEnB,QAAI,YAAY,UAAU;AAIT,qBAAA,KAAK,YAAY,SAAS,IAAI;AAAA,IAAA,OACxC;AACD,UAAA;AACF,uBAAe,QAAQ,QAAQ,QAAQ,YAAY,OAAO,CAAC;AAAA,eACpD,GAAG;AACV,uBAAe,QAAQ,OAAO,KAAK,IAAI,MAAM,YAAY,OAAO;AAE5D,YAAA,CAAC,WAAW,YAA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