@strapi/core 0.0.0-experimental.a65a85fdea97faae8679d3ffc5f9d79af61abd26 → 0.0.0-experimental.a6728ad43ac70ae19dabb624dbfca1f2d9610a86
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 +3 -9
- 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/factories.mjs.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 +39 -11
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +9 -3
- 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.d.ts.map +1 -1
- package/dist/loaders/plugins/index.js +34 -7
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +9 -1
- package/dist/loaders/plugins/index.mjs.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 +27 -6
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +51 -11
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +53 -13
- 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/providers/admin.d.ts.map +1 -1
- package/dist/providers/admin.js.map +1 -1
- package/dist/providers/admin.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.d.ts +1 -1
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +5 -5
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +1 -1
- package/dist/registries/policies.mjs.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/content-api/index.d.ts +10 -12
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +10 -12
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
- package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
- package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
- package/dist/services/core-store.js +3 -3
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/cron.d.ts +3 -3
- package/dist/services/cron.d.ts.map +1 -1
- package/dist/services/cron.js +3 -3
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs.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 +110 -46
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +106 -42
- 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 +7 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +7 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +33 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.js +58 -0
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs +58 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
- 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 +148 -33
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +140 -25
- 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 +2 -2
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +17 -4
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +16 -3
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +18 -16
@@ -48,11 +48,15 @@ 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 }),
|
55
|
-
info: packageInfo.strapi
|
58
|
+
info: packageInfo.strapi,
|
59
|
+
packageInfo
|
56
60
|
};
|
57
61
|
}
|
58
62
|
const installedPlugins = {};
|
@@ -72,7 +76,8 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
72
76
|
info: {
|
73
77
|
...packageInfo.strapi,
|
74
78
|
packageName: packageInfo.name
|
75
|
-
}
|
79
|
+
},
|
80
|
+
packageInfo
|
76
81
|
};
|
77
82
|
}
|
78
83
|
}
|
@@ -90,6 +95,7 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
90
95
|
const packageInfo = require(packagePath);
|
91
96
|
if (isStrapiPlugin(packageInfo)) {
|
92
97
|
declaredPlugins[pluginName].info = packageInfo.strapi || {};
|
98
|
+
declaredPlugins[pluginName].packageInfo = packageInfo;
|
93
99
|
}
|
94
100
|
}
|
95
101
|
});
|
@@ -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 packageInfo?: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n packageInfo,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n packageInfo,\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n declaredPlugins[pluginName].packageInfo = packageInfo;\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["strapi"],"mappings":";;;;;;AAmCA,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;AAE5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AA;AAAA,IAEJ;AAAA,EACF;AAEA,QAAM,kBAA+B,CAAA;AAC/B,QAAA,oBAAoB,MAAM;AAEhC,IAAE,QAAQ,mBAAmB,CAAC,aAAa,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,cAAc,KAAK,cAAc,cAAc;AAC/C,YAAA,cAAc,QAAQ,WAAW;AAEnC,UAAA,eAAe,WAAW,GAAG;AAC/B,wBAAgB,UAAU,EAAE,OAAO,YAAY,UAAU,CAAA;AACzC,wBAAA,UAAU,EAAE,cAAc;AAAA,MAC5C;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0B,IAAI,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiC;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiB;AAAA,IACrB,aAAa,eAAe;AAAA,IAC5B,aAAa,8BAA8B;AAAA,IAC3C,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;"}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const path = require("path");
|
4
4
|
const fse = require("fs-extra");
|
5
|
-
const
|
5
|
+
const fp = require("lodash/fp");
|
6
6
|
const loadConfigFile = require("../../utils/load-config-file.js");
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
8
8
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
@@ -19,7 +19,7 @@ const getUserPluginsConfig = async () => {
|
|
19
19
|
config = loadConfigFile.loadConfigFile(globalUserConfigPath);
|
20
20
|
}
|
21
21
|
if (await fse__default.default.pathExists(currentEnvUserConfigPath)) {
|
22
|
-
config =
|
22
|
+
config = fp.merge(config, loadConfigFile.loadConfigFile(currentEnvUserConfigPath));
|
23
23
|
}
|
24
24
|
return config;
|
25
25
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-user-plugins-config.js","sources":["../../../src/loaders/plugins/get-user-plugins-config.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { merge } from 'lodash/fp';\nimport { loadConfigFile } from '../../utils/load-config-file';\n\n/**\n * Return user defined plugins' config\n * first load config from `config/plugins.js`\n * and then merge config from `config/env/{env}/plugins.js`\n */\nexport const getUserPluginsConfig = async () => {\n const globalUserConfigPath = join(strapi.dirs.dist.config, 'plugins.js');\n const currentEnvUserConfigPath = join(\n strapi.dirs.dist.config,\n 'env',\n process.env.NODE_ENV as string,\n 'plugins.js'\n );\n let config = {};\n\n // assign global user config if exists\n if (await fse.pathExists(globalUserConfigPath)) {\n config = loadConfigFile(globalUserConfigPath);\n }\n\n // and merge user config by environment if exists\n if (await fse.pathExists(currentEnvUserConfigPath)) {\n config = merge(config, loadConfigFile(currentEnvUserConfigPath));\n }\n\n return config;\n};\n"],"names":["join","fse","loadConfigFile","merge"],"mappings":";;;;;;;;AAUO,MAAM,uBAAuB,YAAY;AAC9C,QAAM,uBAAuBA,KAAAA,KAAK,OAAO,KAAK,KAAK,QAAQ,YAAY;AACvE,QAAM,2BAA2BA,KAAA;AAAA,IAC/B,OAAO,KAAK,KAAK;AAAA,IACjB;AAAA,IACA,QAAQ,IAAI;AAAA,IACZ;AAAA,EAAA;AAEF,MAAI,SAAS,CAAA;AAGb,MAAI,MAAMC,aAAA,QAAI,WAAW,oBAAoB,GAAG;AAC9C,aAASC,eAAAA,eAAe,oBAAoB;AAAA,EAC9C;AAGA,MAAI,MAAMD,aAAA,QAAI,WAAW,wBAAwB,GAAG;AAClD,aAASE,
|
1
|
+
{"version":3,"file":"get-user-plugins-config.js","sources":["../../../src/loaders/plugins/get-user-plugins-config.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { merge } from 'lodash/fp';\nimport { loadConfigFile } from '../../utils/load-config-file';\n\n/**\n * Return user defined plugins' config\n * first load config from `config/plugins.js`\n * and then merge config from `config/env/{env}/plugins.js`\n */\nexport const getUserPluginsConfig = async () => {\n const globalUserConfigPath = join(strapi.dirs.dist.config, 'plugins.js');\n const currentEnvUserConfigPath = join(\n strapi.dirs.dist.config,\n 'env',\n process.env.NODE_ENV as string,\n 'plugins.js'\n );\n let config = {};\n\n // assign global user config if exists\n if (await fse.pathExists(globalUserConfigPath)) {\n config = loadConfigFile(globalUserConfigPath);\n }\n\n // and merge user config by environment if exists\n if (await fse.pathExists(currentEnvUserConfigPath)) {\n config = merge(config, loadConfigFile(currentEnvUserConfigPath));\n }\n\n return config;\n};\n"],"names":["join","fse","loadConfigFile","merge"],"mappings":";;;;;;;;AAUO,MAAM,uBAAuB,YAAY;AAC9C,QAAM,uBAAuBA,KAAAA,KAAK,OAAO,KAAK,KAAK,QAAQ,YAAY;AACvE,QAAM,2BAA2BA,KAAA;AAAA,IAC/B,OAAO,KAAK,KAAK;AAAA,IACjB;AAAA,IACA,QAAQ,IAAI;AAAA,IACZ;AAAA,EAAA;AAEF,MAAI,SAAS,CAAA;AAGb,MAAI,MAAMC,aAAA,QAAI,WAAW,oBAAoB,GAAG;AAC9C,aAASC,eAAAA,eAAe,oBAAoB;AAAA,EAC9C;AAGA,MAAI,MAAMD,aAAA,QAAI,WAAW,wBAAwB,GAAG;AAClD,aAASE,GAAAA,MAAM,QAAQD,eAAAA,eAAe,wBAAwB,CAAC;AAAA,EACjE;AAEO,SAAA;AACT;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loaders/plugins/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loaders/plugins/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,eAAe,CAAC;AAiF1D,wBAA8B,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,iBAqD5D"}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
const path = require("path");
|
3
3
|
const fse = require("fs-extra");
|
4
|
-
const
|
4
|
+
const fp = require("lodash/fp");
|
5
|
+
const resolve = require("resolve.exports");
|
5
6
|
const strapiUtils = require("@strapi/utils");
|
6
7
|
const loadConfigFile = require("../../utils/load-config-file.js");
|
7
8
|
const loadFiles = require("../../utils/load-files.js");
|
@@ -9,7 +10,26 @@ const getEnabledPlugins = require("./get-enabled-plugins.js");
|
|
9
10
|
const getUserPluginsConfig = require("./get-user-plugins-config.js");
|
10
11
|
const index = require("../../domain/content-type/index.js");
|
11
12
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
13
|
+
function _interopNamespace(e) {
|
14
|
+
if (e && e.__esModule)
|
15
|
+
return e;
|
16
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
17
|
+
if (e) {
|
18
|
+
for (const k in e) {
|
19
|
+
if (k !== "default") {
|
20
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
22
|
+
enumerable: true,
|
23
|
+
get: () => e[k]
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
n.default = e;
|
29
|
+
return Object.freeze(n);
|
30
|
+
}
|
12
31
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
32
|
+
const resolve__namespace = /* @__PURE__ */ _interopNamespace(resolve);
|
13
33
|
const defaultPlugin = {
|
14
34
|
bootstrap() {
|
15
35
|
},
|
@@ -39,7 +59,7 @@ const applyUserExtension = async (plugins) => {
|
|
39
59
|
for (const pluginName of Object.keys(plugins)) {
|
40
60
|
const plugin = plugins[pluginName];
|
41
61
|
for (const ctName of Object.keys(plugin.contentTypes)) {
|
42
|
-
const extendedSchema =
|
62
|
+
const extendedSchema = fp.get([pluginName, "content-types", ctName, "schema"], extendedSchemas);
|
43
63
|
if (extendedSchema) {
|
44
64
|
plugin.contentTypes[ctName].schema = {
|
45
65
|
...plugin.contentTypes[ctName].schema,
|
@@ -47,7 +67,7 @@ const applyUserExtension = async (plugins) => {
|
|
47
67
|
};
|
48
68
|
}
|
49
69
|
}
|
50
|
-
const strapiServer =
|
70
|
+
const strapiServer = fp.get([pluginName, "strapi-server"], strapiServers);
|
51
71
|
if (strapiServer) {
|
52
72
|
plugins[pluginName] = await strapiServer(plugin);
|
53
73
|
}
|
@@ -57,9 +77,9 @@ const applyUserConfig = async (plugins) => {
|
|
57
77
|
const userPluginsConfig = await getUserPluginsConfig.getUserPluginsConfig();
|
58
78
|
for (const pluginName of Object.keys(plugins)) {
|
59
79
|
const plugin = plugins[pluginName];
|
60
|
-
const userPluginConfig =
|
80
|
+
const userPluginConfig = fp.getOr({}, `${pluginName}.config`, userPluginsConfig);
|
61
81
|
const defaultConfig = typeof plugin.config.default === "function" ? plugin.config.default({ env: strapiUtils.env }) : plugin.config.default;
|
62
|
-
const config =
|
82
|
+
const config = fp.defaultsDeep(defaultConfig, userPluginConfig);
|
63
83
|
try {
|
64
84
|
plugin.config.validator(config);
|
65
85
|
} catch (e) {
|
@@ -78,8 +98,15 @@ async function loadPlugins(strapi2) {
|
|
78
98
|
for (const pluginName of Object.keys(enabledPlugins)) {
|
79
99
|
const enabledPlugin = enabledPlugins[pluginName];
|
80
100
|
let serverEntrypointPath;
|
101
|
+
let resolvedExport = "./strapi-server.js";
|
102
|
+
try {
|
103
|
+
resolvedExport = (resolve__namespace.exports(enabledPlugin.packageInfo, "strapi-server", {
|
104
|
+
require: true
|
105
|
+
}) ?? "./strapi-server.js").toString();
|
106
|
+
} catch (e) {
|
107
|
+
}
|
81
108
|
try {
|
82
|
-
serverEntrypointPath = path.join(enabledPlugin.pathToPlugin,
|
109
|
+
serverEntrypointPath = path.join(enabledPlugin.pathToPlugin, resolvedExport);
|
83
110
|
} catch (e) {
|
84
111
|
throw new Error(
|
85
112
|
`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`
|
@@ -93,7 +120,7 @@ async function loadPlugins(strapi2) {
|
|
93
120
|
...defaultPlugin,
|
94
121
|
...pluginServer,
|
95
122
|
contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),
|
96
|
-
config:
|
123
|
+
config: fp.defaults(defaultPlugin.config, pluginServer.config),
|
97
124
|
routes: pluginServer.routes ?? defaultPlugin.routes
|
98
125
|
};
|
99
126
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n\n try {\n
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["fse","loadFiles","get","getUserPluginsConfig","getOr","env","defaultsDeep","strapi","getEnabledPlugins","resolve","join","loadConfigFile","defaults","getGlobalId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,gBAAgB;AAAA,EACpB,YAAY;AAAA,EAAC;AAAA,EACb,UAAU;AAAA,EAAC;AAAA,EACX,WAAW;AAAA,EAAC;AAAA,EACZ,QAAQ;AAAA,IACN,SAAS,CA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7B,QAAM,mBAAmB,OAAO;AAEhC,aAAW,cAAc,OAAO,KAAK,OAAO,GAAG;AAC7CL,YAAO,IAAI,SAAS,EAAE,IAAI,YAAY,QAAQ,UAAU,CAAC;AAAA,EAC3D;AACF;AAEA,MAAM,qBAAqB,CACzB,YACA,iBACG;AACH,SAAO,OAAO,YAAY,EAAE,QAAQ,CAAC,eAAe;AAC5C,UAAA,EAAE,OAAW,IAAA;AAEnB,WAAO,OAAO,QAAQ;AAAA,MACpB,QAAQ;AAAA,MACR,gBACE,OAAO,kBAAkB,GAAG,UAAU,IAAI,OAAO,KAAK,YAAY,GAAG,YAAY;AAAA,MACnF,UAAUM,MAAAA,YAAY,QAAQ,UAAU;AAAA,IAAA,CACzC;AAAA,EAAA,CACF;AAEM,SAAA;AACT;;"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { join } from "path";
|
2
2
|
import fse from "fs-extra";
|
3
3
|
import { defaults, get, getOr, defaultsDeep } from "lodash/fp";
|
4
|
+
import * as resolve from "resolve.exports";
|
4
5
|
import { env } from "@strapi/utils";
|
5
6
|
import { loadConfigFile } from "../../utils/load-config-file.mjs";
|
6
7
|
import { loadFiles } from "../../utils/load-files.mjs";
|
@@ -75,8 +76,15 @@ async function loadPlugins(strapi2) {
|
|
75
76
|
for (const pluginName of Object.keys(enabledPlugins)) {
|
76
77
|
const enabledPlugin = enabledPlugins[pluginName];
|
77
78
|
let serverEntrypointPath;
|
79
|
+
let resolvedExport = "./strapi-server.js";
|
78
80
|
try {
|
79
|
-
|
81
|
+
resolvedExport = (resolve.exports(enabledPlugin.packageInfo, "strapi-server", {
|
82
|
+
require: true
|
83
|
+
}) ?? "./strapi-server.js").toString();
|
84
|
+
} catch (e) {
|
85
|
+
}
|
86
|
+
try {
|
87
|
+
serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);
|
80
88
|
} catch (e) {
|
81
89
|
throw new Error(
|
82
90
|
`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n\n try {\n
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/loaders/plugins/index.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { defaultsDeep, defaults, getOr, get } from 'lodash/fp';\nimport * as resolve from 'resolve.exports';\n\nimport { env } from '@strapi/utils';\nimport type { Core, Plugin, Struct } from '@strapi/types';\nimport { loadConfigFile } from '../../utils/load-config-file';\nimport { loadFiles } from '../../utils/load-files';\nimport { getEnabledPlugins } from './get-enabled-plugins';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\nimport { getGlobalId } from '../../domain/content-type';\n\ninterface Plugins {\n [key: string]: Plugin.LoadedPlugin;\n}\n\nconst defaultPlugin = {\n bootstrap() {},\n destroy() {},\n register() {},\n config: {\n default: {},\n validator() {},\n },\n routes: [],\n controllers: {},\n services: {},\n policies: {},\n middlewares: {},\n contentTypes: {},\n};\n\nconst applyUserExtension = async (plugins: Plugins) => {\n const extensionsDir = strapi.dirs.dist.extensions;\n if (!(await fse.pathExists(extensionsDir))) {\n return;\n }\n\n const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');\n const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n // first: load json schema\n for (const ctName of Object.keys(plugin.contentTypes)) {\n const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);\n if (extendedSchema) {\n plugin.contentTypes[ctName].schema = {\n ...plugin.contentTypes[ctName].schema,\n ...extendedSchema,\n };\n }\n }\n // second: execute strapi-server extension\n const strapiServer = get([pluginName, 'strapi-server'], strapiServers);\n if (strapiServer) {\n plugins[pluginName] = await strapiServer(plugin);\n }\n }\n};\n\nconst applyUserConfig = async (plugins: Plugins) => {\n const userPluginsConfig = await getUserPluginsConfig();\n\n for (const pluginName of Object.keys(plugins)) {\n const plugin = plugins[pluginName];\n const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);\n const defaultConfig =\n typeof plugin.config.default === 'function'\n ? plugin.config.default({ env })\n : plugin.config.default;\n\n const config = defaultsDeep(defaultConfig, userPluginConfig);\n try {\n plugin.config.validator(config);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error regarding ${pluginName} config: ${e.message}`);\n }\n\n throw e;\n }\n plugin.config = config;\n }\n};\n\nexport default async function loadPlugins(strapi: Core.Strapi) {\n const plugins: Plugins = {};\n\n const enabledPlugins = await getEnabledPlugins(strapi);\n\n strapi.config.set('enabledPlugins', enabledPlugins);\n\n for (const pluginName of Object.keys(enabledPlugins)) {\n const enabledPlugin = enabledPlugins[pluginName];\n\n let serverEntrypointPath;\n let resolvedExport = './strapi-server.js';\n\n try {\n resolvedExport = (\n resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {\n require: true,\n }) ?? './strapi-server.js'\n ).toString();\n } catch (e) {\n // no export map or missing strapi-server export => fallback to default\n }\n\n try {\n serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);\n } catch (e) {\n throw new Error(\n `Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`\n );\n }\n\n // only load plugins with a server entrypoint\n if (!(await fse.pathExists(serverEntrypointPath))) {\n continue;\n }\n\n const pluginServer = loadConfigFile(serverEntrypointPath);\n plugins[pluginName] = {\n ...defaultPlugin,\n ...pluginServer,\n contentTypes: formatContentTypes(pluginName, pluginServer.contentTypes ?? {}),\n config: defaults(defaultPlugin.config, pluginServer.config),\n routes: pluginServer.routes ?? defaultPlugin.routes,\n };\n }\n\n // TODO: validate plugin format\n await applyUserConfig(plugins);\n await applyUserExtension(plugins);\n\n for (const pluginName of Object.keys(plugins)) {\n strapi.get('plugins').add(pluginName, plugins[pluginName]);\n }\n}\n\nconst formatContentTypes = (\n pluginName: string,\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>\n) => {\n Object.values(contentTypes).forEach((definition) => {\n const { schema } = definition;\n\n Object.assign(schema, {\n plugin: pluginName,\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, pluginName),\n });\n });\n\n return contentTypes;\n};\n"],"names":["strapi"],"mappings":";;;;;;;;;;AAiBA,MAAM,gBAAgB;AAAA,EACpB,YAAY;AAAA,EAAC;AAAA,EACb,UAAU;AAAA,EAAC;AAAA,EACX,WAAW;AAAA,EAAC;AAAA,EACZ,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,IACV,YAAY;AAAA,IAAC;AAAA,EACf;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,aAAa,CAAC;AAAA,EACd,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,aAAa,CAAC;AAAA,EACd,cAAc,CAAC;AACjB;AAEA,MAAM,qBAAqB,OAAO,YAAqB;AAC/C,QAAA,gBAAgB,OAAO,KAAK,KAAK;AACvC,MAAI,CAAE,MAAM,IAAI,WAAW,aAAa,GAAI;AAC1C;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM,UAAU,eAAe,iCAAiC;AACxF,QAAM,gBAAgB,MAAM,UAAU,eAAe,qBAAqB;AAE1E,aAAW,cAAc,OAAO,KAAK,OAAO,GAAG;AACvC,UAAA,SAAS,QAAQ,UAAU;AAEjC,eAAW,UAAU,OAA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AQ,cAAc,aAAa,iBAAiB;AAAA,QAC1D,SAAS;AAAA,MAAA,CACV,KAAK,sBACN;aACK,GAAG;AAAA,IAEZ;AAEI,QAAA;AACqB,6BAAA,KAAK,cAAc,cAAc,cAAc;AAAA,aAC/D,GAAG;AACV,YAAM,IAAI;AAAA,QACR,4BAA4B,UAAU,YAAY,UAAU;AAAA,MAAA;AAAA,IAEhE;AAGA,QAAI,CAAE,MAAM,IAAI,WAAW,oBAAoB,GAAI;AACjD;AAAA,IACF;AAEM,UAAA,eAAe,eAAe,oBAAoB;AACxD,YAAQ,UAAU,IAAI;AAAA,MACpB,GAAG;AAAA,MACH,GAAG;AAAA,MACH,cAAc,mBAAmB,YAAY,aAAa,gBAAgB,CAAA,CAAE;AAAA,MAC5E,QAAQ,SAAS,cAAc,QAAQ,aAAa,MAAM;AAAA,MAC1D,QAAQ,aAAa,UAAU,cAAc;AAAA,IAAA;AAAA,EAEjD;AAGA,QAAM,gBAAgB,OAAO;AAC7B,QAAM,mBAAmB,OAAO;AAEhC,aAAW,cAAc,OAAO,KAAK,OAAO,GAAG;AAC7CA,YAAO,IAAI,SAAS,EAAE,IAAI,YAAY,QAAQ,UAAU,CAAC;AAAA,EAC3D;AACF;AAEA,MAAM,qBAAqB,CACzB,YACA,iBACG;AACH,SAAO,OAAO,YAAY,EAAE,QAAQ,CAAC,eAAe;AAC5C,UAAA,EAAE,OAAW,IAAA;AAEnB,WAAO,OAAO,QAAQ;AAAA,MACpB,QAAQ;AAAA,MACR,gBACE,OAAO,kBAAkB,GAAG,UAAU,IAAI,OAAO,KAAK,YAAY,GAAG,YAAY;AAAA,MACnF,UAAU,YAAY,QAAQ,UAAU;AAAA,IAAA,CACzC;AAAA,EAAA,CACF;AAEM,SAAA;AACT;"}
|
package/dist/middlewares/body.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const fse = require("fs-extra");
|
4
|
-
const
|
4
|
+
const fp = require("lodash/fp");
|
5
5
|
const body = require("koa-body");
|
6
6
|
const mime = require("mime-types");
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
@@ -21,7 +21,7 @@ function getFiles(ctx) {
|
|
21
21
|
return ctx?.request?.files?.files;
|
22
22
|
}
|
23
23
|
const bodyMiddleware = (config, { strapi }) => {
|
24
|
-
const bodyConfig =
|
24
|
+
const bodyConfig = fp.defaultsDeep(defaults, config);
|
25
25
|
let gqlEndpoint;
|
26
26
|
if (strapi.plugin("graphql")) {
|
27
27
|
const { config: gqlConfig } = strapi.plugin("graphql");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"body.js","sources":["../../src/middlewares/body.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport { defaultsDeep } from 'lodash/fp';\nimport body, { KoaBodyMiddlewareOptions } from 'koa-body';\nimport mime from 'mime-types';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\nexport type Config = KoaBodyMiddlewareOptions;\n\nconst defaults = {\n multipart: true,\n patchKoa: true,\n};\n\nfunction ensureFileMimeType(file: any): void {\n if (!file.type) {\n file.type = mime.lookup(file.name) || 'application/octet-stream';\n }\n}\n\nfunction getFiles(ctx: Koa.Context) {\n return ctx?.request?.files?.files;\n}\n\nconst bodyMiddleware: Core.MiddlewareFactory<Config> = (config, { strapi }) => {\n const bodyConfig: Config = defaultsDeep(defaults, config);\n\n let gqlEndpoint: string | undefined;\n if (strapi.plugin('graphql')) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n gqlEndpoint = gqlConfig('endpoint');\n }\n\n return async (ctx, next) => {\n // TODO: find a better way later\n if (gqlEndpoint && ctx.url === gqlEndpoint) {\n await next();\n } else {\n try {\n await body(bodyConfig)(ctx, async () => {});\n\n const files = getFiles(ctx);\n\n /**\n * in case the mime-type wasn't sent, Strapi tries to guess it\n * from the file extension, to avoid a corrupt database state\n */\n if (files) {\n if (Array.isArray(files)) {\n files.forEach(ensureFileMimeType);\n } else {\n ensureFileMimeType(files);\n }\n }\n\n await next();\n } catch (error) {\n if (\n error instanceof Error &&\n error.message &&\n error.message.includes('maxFileSize exceeded')\n ) {\n return ctx.payloadTooLarge('FileTooBig');\n }\n\n throw error;\n }\n }\n\n const files = getFiles(ctx);\n\n // clean any file that was uploaded\n if (files) {\n if (Array.isArray(files)) {\n // not awaiting to not slow the request\n Promise.all(files.map((file) => fse.remove(file.filepath)));\n } else if (files && files.filepath) {\n // not awaiting to not slow the request\n fse.remove(files.filepath);\n }\n delete ctx.request.files;\n }\n };\n};\n\nexport { bodyMiddleware as body };\n"],"names":["mime","defaultsDeep","body","files","fse"],"mappings":";;;;;;;;;;AASA,MAAM,WAAW;AAAA,EACf,WAAW;AAAA,EACX,UAAU;AACZ;AAEA,SAAS,mBAAmB,MAAiB;AACvC,MAAA,CAAC,KAAK,MAAM;AACd,SAAK,OAAOA,sBAAK,OAAO,KAAK,IAAI,KAAK;AAAA,EACxC;AACF;AAEA,SAAS,SAAS,KAAkB;AAC3B,SAAA,KAAK,SAAS,OAAO;AAC9B;AAEA,MAAM,iBAAiD,CAAC,QAAQ,EAAE,aAAa;AACvE,QAAA,aAAqBC,
|
1
|
+
{"version":3,"file":"body.js","sources":["../../src/middlewares/body.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport { defaultsDeep } from 'lodash/fp';\nimport body, { KoaBodyMiddlewareOptions } from 'koa-body';\nimport mime from 'mime-types';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\nexport type Config = KoaBodyMiddlewareOptions;\n\nconst defaults = {\n multipart: true,\n patchKoa: true,\n};\n\nfunction ensureFileMimeType(file: any): void {\n if (!file.type) {\n file.type = mime.lookup(file.name) || 'application/octet-stream';\n }\n}\n\nfunction getFiles(ctx: Koa.Context) {\n return ctx?.request?.files?.files;\n}\n\nconst bodyMiddleware: Core.MiddlewareFactory<Config> = (config, { strapi }) => {\n const bodyConfig: Config = defaultsDeep(defaults, config);\n\n let gqlEndpoint: string | undefined;\n if (strapi.plugin('graphql')) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n gqlEndpoint = gqlConfig('endpoint');\n }\n\n return async (ctx, next) => {\n // TODO: find a better way later\n if (gqlEndpoint && ctx.url === gqlEndpoint) {\n await next();\n } else {\n try {\n await body(bodyConfig)(ctx, async () => {});\n\n const files = getFiles(ctx);\n\n /**\n * in case the mime-type wasn't sent, Strapi tries to guess it\n * from the file extension, to avoid a corrupt database state\n */\n if (files) {\n if (Array.isArray(files)) {\n files.forEach(ensureFileMimeType);\n } else {\n ensureFileMimeType(files);\n }\n }\n\n await next();\n } catch (error) {\n if (\n error instanceof Error &&\n error.message &&\n error.message.includes('maxFileSize exceeded')\n ) {\n return ctx.payloadTooLarge('FileTooBig');\n }\n\n throw error;\n }\n }\n\n const files = getFiles(ctx);\n\n // clean any file that was uploaded\n if (files) {\n if (Array.isArray(files)) {\n // not awaiting to not slow the request\n Promise.all(files.map((file) => fse.remove(file.filepath)));\n } else if (files && files.filepath) {\n // not awaiting to not slow the request\n fse.remove(files.filepath);\n }\n delete ctx.request.files;\n }\n };\n};\n\nexport { bodyMiddleware as body };\n"],"names":["mime","defaultsDeep","body","files","fse"],"mappings":";;;;;;;;;;AASA,MAAM,WAAW;AAAA,EACf,WAAW;AAAA,EACX,UAAU;AACZ;AAEA,SAAS,mBAAmB,MAAiB;AACvC,MAAA,CAAC,KAAK,MAAM;AACd,SAAK,OAAOA,sBAAK,OAAO,KAAK,IAAI,KAAK;AAAA,EACxC;AACF;AAEA,SAAS,SAAS,KAAkB;AAC3B,SAAA,KAAK,SAAS,OAAO;AAC9B;AAEA,MAAM,iBAAiD,CAAC,QAAQ,EAAE,aAAa;AACvE,QAAA,aAAqBC,GAAAA,aAAa,UAAU,MAAM;AAEpD,MAAA;AACA,MAAA,OAAO,OAAO,SAAS,GAAG;AAC5B,UAAM,EAAE,QAAQ,UAAA,IAAc,OAAO,OAAO,SAAS;AACrD,kBAAc,U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C;IAC9D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAWF,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC9D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAWF,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CA8C/C,CAAC"}
|
package/dist/middlewares/cors.js
CHANGED
@@ -23,21 +23,23 @@ const cors = (config) => {
|
|
23
23
|
}
|
24
24
|
return koaCors__default.default({
|
25
25
|
async origin(ctx) {
|
26
|
+
if (!ctx.get("Origin")) {
|
27
|
+
return "*";
|
28
|
+
}
|
26
29
|
let originList;
|
27
30
|
if (typeof origin === "function") {
|
28
31
|
originList = await origin(ctx);
|
29
32
|
} else {
|
30
33
|
originList = origin;
|
31
34
|
}
|
32
|
-
|
33
|
-
|
34
|
-
if (whitelist.includes("*")) {
|
35
|
-
return credentials ? requestOrigin : "*";
|
35
|
+
if (Array.isArray(originList)) {
|
36
|
+
return originList.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
36
37
|
}
|
37
|
-
|
38
|
-
|
38
|
+
const parsedOrigin = originList.split(",").map((origin2) => origin2.trim());
|
39
|
+
if (parsedOrigin.length > 1) {
|
40
|
+
return parsedOrigin.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
39
41
|
}
|
40
|
-
return
|
42
|
+
return originList;
|
41
43
|
},
|
42
44
|
exposeHeaders: expose,
|
43
45
|
maxAge,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n
|
1
|
+
{"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n const parsedOrigin = originList.split(',').map((origin) => origin.trim());\n if (parsedOrigin.length > 1) {\n return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["koaCors","origin"],"mappings":";;;;;AAeA,MAAM,WAAmB;AAAA,EACvB,QAAQ;AAAA,EACR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
24
|
+
}
|
22
25
|
let originList;
|
23
26
|
if (typeof origin === "function") {
|
24
27
|
originList = await origin(ctx);
|
25
28
|
} else {
|
26
29
|
originList = origin;
|
27
30
|
}
|
28
|
-
|
29
|
-
|
30
|
-
if (whitelist.includes("*")) {
|
31
|
-
return credentials ? requestOrigin : "*";
|
31
|
+
if (Array.isArray(originList)) {
|
32
|
+
return originList.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
32
33
|
}
|
33
|
-
|
34
|
-
|
34
|
+
const parsedOrigin = originList.split(",").map((origin2) => origin2.trim());
|
35
|
+
if (parsedOrigin.length > 1) {
|
36
|
+
return parsedOrigin.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
35
37
|
}
|
36
|
-
return
|
38
|
+
return originList;
|
37
39
|
},
|
38
40
|
exposeHeaders: expose,
|
39
41
|
maxAge,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n
|
1
|
+
{"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n const parsedOrigin = originList.split(',').map((origin) => origin.trim());\n if (parsedOrigin.length > 1) {\n return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["origin"],"mappings":";AAeA,MAAM,WAAmB;AAAA,EACvB,QAA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p");
|
4
4
|
const koaStatic = require("koa-static");
|
5
5
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
6
6
|
const koaStatic__default = /* @__PURE__ */ _interopDefault(koaStatic);
|
@@ -8,7 +8,7 @@ const defaults = {
|
|
8
8
|
maxAge: 6e4
|
9
9
|
};
|
10
10
|
const publicStatic = (config, { strapi }) => {
|
11
|
-
const { maxAge } =
|
11
|
+
const { maxAge } = fp.defaultsDeep(defaults, config);
|
12
12
|
strapi.server.routes([
|
13
13
|
{
|
14
14
|
method: "GET",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"public.js","sources":["../../src/middlewares/public.ts"],"sourcesContent":["import { defaultsDeep } from 'lodash/fp';\nimport koaStatic from 'koa-static';\nimport type { Core } from '@strapi/types';\n\ntype Config = koaStatic.Options;\n\nconst defaults = {\n maxAge: 60000,\n};\n\nexport const publicStatic: Core.MiddlewareFactory = (\n config: Config,\n { strapi }: { strapi: Core.Strapi }\n) => {\n const { maxAge } = defaultsDeep(defaults, config);\n\n strapi.server.routes([\n {\n method: 'GET',\n path: '/',\n handler(ctx) {\n ctx.redirect(strapi.config.get('admin.url', '/admin'));\n },\n config: { auth: false },\n },\n // All other public GET-routes except /uploads/(.*) which is handled in upload middleware\n {\n method: 'GET',\n path: '/((?!uploads/).+)',\n handler: koaStatic(strapi.dirs.static.public, {\n maxage: maxAge,\n defer: true,\n }),\n config: { auth: false },\n },\n ]);\n};\n"],"names":["defaultsDeep","koaStatic"],"mappings":";;;;;;AAMA,MAAM,WAAW;AAAA,EACf,QAAQ;AACV;AAEO,MAAM,eAAuC,CAClD,QACA,EAAE,aACC;AACH,QAAM,EAAE,OAAW,IAAAA,
|
1
|
+
{"version":3,"file":"public.js","sources":["../../src/middlewares/public.ts"],"sourcesContent":["import { defaultsDeep } from 'lodash/fp';\nimport koaStatic from 'koa-static';\nimport type { Core } from '@strapi/types';\n\ntype Config = koaStatic.Options;\n\nconst defaults = {\n maxAge: 60000,\n};\n\nexport const publicStatic: Core.MiddlewareFactory = (\n config: Config,\n { strapi }: { strapi: Core.Strapi }\n) => {\n const { maxAge } = defaultsDeep(defaults, config);\n\n strapi.server.routes([\n {\n method: 'GET',\n path: '/',\n handler(ctx) {\n ctx.redirect(strapi.config.get('admin.url', '/admin'));\n },\n config: { auth: false },\n },\n // All other public GET-routes except /uploads/(.*) which is handled in upload middleware\n {\n method: 'GET',\n path: '/((?!uploads/).+)',\n handler: koaStatic(strapi.dirs.static.public, {\n maxage: maxAge,\n defer: true,\n }),\n config: { auth: false },\n },\n ]);\n};\n"],"names":["defaultsDeep","koaStatic"],"mappings":";;;;;;AAMA,MAAM,WAAW;AAAA,EACf,QAAQ;AACV;AAEO,MAAM,eAAuC,CAClD,QACA,EAAE,aACC;AACH,QAAM,EAAE,OAAW,IAAAA,GAAA,aAAa,UAAU,MAAM;AAEhD,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,QAAQ,KAAK;AACX,YAAI,SAAS,OAAO,OAAO,IAAI,aAAa,QAAQ,CAAC;AAAA,MACvD;AAAA,MACA,QAAQ,EAAE,MAAM,MAAM;AAAA,IACxB;AAAA;AAAA,IAEA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,SAASC,mBAAAA,QAAU,OAAO,KAAK,OAAO,QAAQ;AAAA,QAC5C,QAAQ;AAAA,QACR,OAAO;AAAA,MAAA,CACR;AAAA,MACD,QAAQ,EAAE,MAAM,MAAM;AAAA,IACxB;AAAA,EAAA,CACD;AACH;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/middlewares/query.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/middlewares/query.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AA4C1C,eAAO,MAAM,KAAK,EAAE,IAAI,CAAC,iBAKxB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.js","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs
|
1
|
+
{"version":3,"file":"query.js","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs from 'qs';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\ntype Config = Parameters<typeof qs.parse>[1];\n\nconst defaults: Config = {\n strictNullHandling: true,\n arrayLimit: 100,\n depth: 20,\n};\n\n/**\n * Body parser hook\n */\nconst addQsParser = (app: Koa, settings: Config) => {\n Object.defineProperty(app.request, 'query', {\n configurable: false,\n enumerable: true,\n /*\n * Get parsed query-string.\n */\n get() {\n const qstr = this.querystring;\n\n this._querycache = this._querycache || {};\n const cache = this._querycache;\n\n if (!cache[qstr]) {\n cache[qstr] = qs.parse(qstr, settings);\n }\n\n return cache[qstr];\n },\n\n /*\n * Set query-string as an object.\n */\n set(obj) {\n this.querystring = qs.stringify(obj);\n },\n } satisfies PropertyDescriptor & ThisType<Koa.BaseRequest>);\n\n return app;\n};\n\nexport const query: Core.MiddlewareFactory = (\n config: Partial<Config>,\n { strapi }: { strapi: Core.Strapi }\n) => {\n addQsParser(strapi.server.app, { ...defaults, ...config } as Config);\n};\n"],"names":["qs"],"mappings":";;;;;AAMA,MAAM,WAAmB;AAAA,EACvB,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT;AAKA,MAAM,cAAc,CAAC,KAAU,aAAqB;AAC3C,SAAA,eAAe,IAAI,SAAS,SAAS;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA;AAAA;AAAA;AAAA,IAIZ,MAAM;AACJ,YAAM,OAAO,KAAK;AAEb,WAAA,cAAc,KAAK,eAAe,CAAA;AACvC,YAAM,QAAQ,KAAK;AAEf,UAAA,CAAC,MAAM,IAAI,GAAG;AAChB,cAAM,IAAI,IAAIA,YAAAA,QAAG,MAAM,MAAM,QAAQ;AAAA,MACvC;AAEA,aAAO,MAAM,IAAI;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAK;AACF,WAAA,cAAcA,YAAAA,QAAG,UAAU,GAAG;AAAA,IACrC;AAAA,EAAA,CACwD;AAEnD,SAAA;AACT;AAEO,MAAM,QAAgC,CAC3C,QACA,EAAE,aACC;AACS,cAAA,OAAO,OAAO,KAAK,EAAE,GAAG,UAAU,GAAG,QAAkB;AACrE;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.mjs","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs
|
1
|
+
{"version":3,"file":"query.mjs","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs from 'qs';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\ntype Config = Parameters<typeof qs.parse>[1];\n\nconst defaults: Config = {\n strictNullHandling: true,\n arrayLimit: 100,\n depth: 20,\n};\n\n/**\n * Body parser hook\n */\nconst addQsParser = (app: Koa, settings: Config) => {\n Object.defineProperty(app.request, 'query', {\n configurable: false,\n enumerable: true,\n /*\n * Get parsed query-string.\n */\n get() {\n const qstr = this.querystring;\n\n this._querycache = this._querycache || {};\n const cache = this._querycache;\n\n if (!cache[qstr]) {\n cache[qstr] = qs.parse(qstr, settings);\n }\n\n return cache[qstr];\n },\n\n /*\n * Set query-string as an object.\n */\n set(obj) {\n this.querystring = qs.stringify(obj);\n },\n } satisfies PropertyDescriptor & ThisType<Koa.BaseRequest>);\n\n return app;\n};\n\nexport const query: Core.MiddlewareFactory = (\n config: Partial<Config>,\n { strapi }: { strapi: Core.Strapi }\n) => {\n addQsParser(strapi.server.app, { ...defaults, ...config } as Config);\n};\n"],"names":[],"mappings":";AAMA,MAAM,WAAmB;AAAA,EACvB,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT;AAKA,MAAM,cAAc,CAAC,KAAU,aAAqB;AAC3C,SAAA,eAAe,IAAI,SAAS,SAAS;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA;AAAA;AAAA;AAAA,IAIZ,MAAM;AACJ,YAAM,OAAO,KAAK;AAEb,WAAA,cAAc,KAAK,eAAe,CAAA;AACvC,YAAM,QAAQ,KAAK;AAEf,UAAA,CAAC,MAAM,IAAI,GAAG;AAChB,cAAM,IAAI,IAAI,GAAG,MAAM,MAAM,QAAQ;AAAA,MACvC;AAEA,aAAO,MAAM,IAAI;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAK;AACF,WAAA,cAAc,GAAG,UAAU,GAAG;AAAA,IACrC;AAAA,EAAA,CACwD;AAEnD,SAAA;AACT;AAEO,MAAM,QAAgC,CAC3C,QACA,EAAE,aACC;AACS,cAAA,OAAO,OAAO,KAAK,EAAE,GAAG,UAAU,GAAG,QAAkB;AACrE;"}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const responses = (config = {}) => {
|
5
5
|
return async (ctx, next) => {
|
6
6
|
await next();
|
7
7
|
const { status } = ctx;
|
8
8
|
const handler = config?.handlers?.[status];
|
9
|
-
if (
|
9
|
+
if (fp.isFunction(handler)) {
|
10
10
|
await handler(ctx, next);
|
11
11
|
}
|
12
12
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"responses.js","sources":["../../src/middlewares/responses.ts"],"sourcesContent":["import { isFunction } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\nexport interface Config {\n handlers?: Record<number, Core.MiddlewareHandler>;\n}\n\nexport const responses: Core.MiddlewareFactory<Config> = (config = {}) => {\n return async (ctx, next) => {\n await next();\n\n const { status } = ctx;\n const handler = config?.handlers?.[status];\n\n if (isFunction(handler)) {\n await handler(ctx, next);\n }\n };\n};\n"],"names":["isFunction"],"mappings":";;;AAOO,MAAM,YAA4C,CAAC,SAAS,OAAO;AACjE,SAAA,OAAO,KAAK,SAAS;AAC1B,UAAM,KAAK;AAEL,UAAA,EAAE,OAAW,IAAA;AACb,UAAA,UAAU,QAAQ,WAAW,MAAM;AAErC,QAAAA,
|
1
|
+
{"version":3,"file":"responses.js","sources":["../../src/middlewares/responses.ts"],"sourcesContent":["import { isFunction } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\nexport interface Config {\n handlers?: Record<number, Core.MiddlewareHandler>;\n}\n\nexport const responses: Core.MiddlewareFactory<Config> = (config = {}) => {\n return async (ctx, next) => {\n await next();\n\n const { status } = ctx;\n const handler = config?.handlers?.[status];\n\n if (isFunction(handler)) {\n await handler(ctx, next);\n }\n };\n};\n"],"names":["isFunction"],"mappings":";;;AAOO,MAAM,YAA4C,CAAC,SAAS,OAAO;AACjE,SAAA,OAAO,KAAK,SAAS;AAC1B,UAAM,KAAK;AAEL,UAAA,EAAE,OAAW,IAAA;AACb,UAAA,UAAU,QAAQ,WAAW,MAAM;AAErC,QAAAA,GAAAA,WAAW,OAAO,GAAG;AACjB,YAAA,QAAQ,KAAK,IAAI;AAAA,IACzB;AAAA,EAAA;AAEJ;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/middlewares/security.ts"],"names":[],"mappings":"AACA,OAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/middlewares/security.ts"],"names":[],"mappings":"AACA,OAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAkC3D,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAmEjD,CAAC"}
|
@@ -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 helmet = require("koa-helmet");
|
5
5
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
6
6
|
const helmet__default = /* @__PURE__ */ _interopDefault(helmet);
|
@@ -27,8 +27,15 @@ const defaults = {
|
|
27
27
|
action: "sameorigin"
|
28
28
|
}
|
29
29
|
};
|
30
|
+
const mergeConfig = (existingConfig, newConfig) => {
|
31
|
+
return fp.mergeWith(
|
32
|
+
(obj, src) => Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : void 0,
|
33
|
+
existingConfig,
|
34
|
+
newConfig
|
35
|
+
);
|
36
|
+
};
|
30
37
|
const security = (config, { strapi }) => (ctx, next) => {
|
31
|
-
let helmetConfig =
|
38
|
+
let helmetConfig = fp.defaultsDeep(defaults, config);
|
32
39
|
const specialPaths = ["/documentation"];
|
33
40
|
const directives = {
|
34
41
|
"script-src": ["'self'", "'unsafe-inline'", "cdn.jsdelivr.net"],
|
@@ -47,7 +54,7 @@ const security = (config, { strapi }) => (ctx, next) => {
|
|
47
54
|
directives["frame-src"].push("sandbox.embed.apollographql.com");
|
48
55
|
}
|
49
56
|
if (ctx.method === "GET" && specialPaths.some((str) => ctx.path.startsWith(str))) {
|
50
|
-
helmetConfig =
|
57
|
+
helmetConfig = mergeConfig(helmetConfig, {
|
51
58
|
crossOriginEmbedderPolicy: false,
|
52
59
|
// TODO: only use this for graphql playground
|
53
60
|
contentSecurityPolicy: {
|
@@ -55,8 +62,8 @@ const security = (config, { strapi }) => (ctx, next) => {
|
|
55
62
|
}
|
56
63
|
});
|
57
64
|
}
|
58
|
-
if (process.env.NODE_ENV
|
59
|
-
helmetConfig =
|
65
|
+
if (["development", "test"].includes(process.env.NODE_ENV ?? "") && ctx.method === "GET" && ctx.path.startsWith(strapi.config.get("admin.path"))) {
|
66
|
+
helmetConfig = mergeConfig(helmetConfig, {
|
60
67
|
contentSecurityPolicy: {
|
61
68
|
directives: {
|
62
69
|
"script-src": ["'self'", "'unsafe-inline'"],
|