@strapi/core 0.0.0-experimental.ca5f02ef2ec166e219546983049c0543bed92f8d → 0.0.0-experimental.cad2fba5593c9ceddfc264fcecd9313a7f866d1a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +22 -6
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +22 -6
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/config-loader.mjs.map +1 -1
- package/dist/configuration/index.d.ts +0 -3
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +0 -3
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +0 -3
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/configuration/urls.js.map +1 -1
- package/dist/configuration/urls.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/container.js.map +1 -1
- package/dist/container.mjs.map +1 -1
- package/dist/core-api/controller/collection-type.d.ts.map +1 -1
- package/dist/core-api/controller/collection-type.js +1 -1
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/collection-type.mjs +1 -1
- package/dist/core-api/controller/collection-type.mjs.map +1 -1
- package/dist/core-api/controller/index.js +1 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +1 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/single-type.js +1 -1
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/single-type.mjs +1 -1
- package/dist/core-api/controller/single-type.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +9 -5
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +9 -5
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +35 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs +35 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -1
- package/dist/core-api/routes/validation/utils.js +22 -6
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/core-api/routes/validation/utils.mjs +22 -6
- package/dist/core-api/routes/validation/utils.mjs.map +1 -1
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.js +1 -2
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +1 -2
- package/dist/ee/license.mjs.map +1 -1
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs.map +1 -1
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/components.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/loaders/src-index.js.map +1 -1
- package/dist/loaders/src-index.mjs.map +1 -1
- package/dist/middlewares/logger.js.map +1 -1
- package/dist/middlewares/logger.mjs.map +1 -1
- package/dist/middlewares/response-time.js.map +1 -1
- package/dist/middlewares/response-time.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +2 -15
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +2 -15
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +21 -7
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +1470 -58
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +1471 -59
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +13 -12
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +13 -12
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/session-manager.d.ts +3 -0
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/session-manager.js +23 -0
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/session-manager.mjs +21 -0
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/apis.mjs.map +1 -1
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/custom-fields.mjs.map +1 -1
- package/dist/registries/namespace.js.map +1 -1
- package/dist/registries/namespace.mjs.map +1 -1
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/plugins.mjs.map +1 -1
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/services/config.js.map +1 -1
- package/dist/services/config.mjs.map +1 -1
- package/dist/services/content-api/index.d.ts +1 -1
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +2 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/content-api/permissions/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +8 -3
- package/dist/services/content-source-maps.d.ts.map +1 -1
- package/dist/services/content-source-maps.js +71 -82
- package/dist/services/content-source-maps.js.map +1 -1
- package/dist/services/content-source-maps.mjs +71 -82
- package/dist/services/content-source-maps.mjs.map +1 -1
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +31 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +109 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +107 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +12 -5
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +13 -6
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/fields.js.map +1 -1
- package/dist/services/document-service/transform/fields.mjs.map +1 -1
- package/dist/services/document-service/transform/id-map.js.map +1 -1
- package/dist/services/document-service/transform/id-map.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.js +145 -0
- package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs +143 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/metrics/index.js +2 -1
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +2 -1
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -1
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -1
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/index.mjs.map +1 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/middleware.mjs.map +1 -1
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +167 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +529 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +526 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/dist/services/webhook-runner.js +2 -2
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs +2 -2
- package/dist/services/webhook-runner.mjs.map +1 -1
- package/dist/services/worker-queue.js +2 -2
- package/dist/services/worker-queue.js.map +1 -1
- package/dist/services/worker-queue.mjs +2 -2
- package/dist/services/worker-queue.mjs.map +1 -1
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-config-file.mjs.map +1 -1
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/package.json +13 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { sanitize, validate } from '@strapi/utils';
|
|
2
|
+
import { sanitize, validate, sanitizeRoutesMapForSerialization } from '@strapi/utils';
|
|
3
3
|
import instantiatePermissionsUtilities from './permissions/index.mjs';
|
|
4
4
|
|
|
5
5
|
const transformRoutePrefixFor = (pluginName)=>(route)=>{
|
|
@@ -47,7 +47,7 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
47
47
|
path: `${apiPrefix}${route.path}`
|
|
48
48
|
}));
|
|
49
49
|
});
|
|
50
|
-
return routesMap;
|
|
50
|
+
return sanitizeRoutesMapForSerialization(routesMap);
|
|
51
51
|
};
|
|
52
52
|
const sanitizer = sanitize.createAPISanitizers({
|
|
53
53
|
getModel (uid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return routesMap;\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate, sanitizeRoutesMapForSerialization } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return sanitizeRoutesMapForSerialization(routesMap);\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizeRoutesMapForSerialization","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;AAClD,QAAA,MAAME,IAAOF,GAAAA,MAAAA,KAAWG,SAAY,GAAA,CAAA,EAAGH,SAASD,KAAMG,CAAAA,IAAI,CAAE,CAAA,GAAG,CAAC,CAAC,EAAEJ,UAAaC,CAAAA,EAAAA,KAAAA,CAAMG,IAAI,CAAE,CAAA;QAE5F,OAAO;AACL,YAAA,GAAGH,KAAK;AACRG,YAAAA;AACF,SAAA;AACF,KAAA;AAEA,MAAME,mBAAmB,CAACL,KAAAA,GAAsBA,MAAMM,IAAI,CAACC,IAAI,KAAK,aAAA;AAEpE;;IAGA,MAAMC,mBAAmB,CAACC,MAAAA,GAAAA;AACxB,IAAA,MAAMC,YAAe,GAAA,UAAA;AACnB,QAAA,MAAMC,YAA0C,EAAC;AAEjDC,QAAAA,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UAAa,CAAA,GAAA;YACf,OAAO;AACLL,gBAAAA,KAAAA,EAAO3B,MAAOgC,CAAAA,UAAU,CAACnB,GAAG,CAAC,mBAAA;AAC/B,aAAA;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AACLoB,QAAAA,WAAAA,EAAaC,+BAAgClC,CAAAA,MAAAA,CAAAA;AAC7CC,QAAAA,YAAAA;QACAqB,QAAUD,EAAAA,SAAAA;QACVS,QAAUD,EAAAA;AACZ,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/services/content-api/permissions/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\nimport { createActionProvider, createConditionProvider } from './providers';\nimport createPermissionEngine from './engine';\n\nconst typeSymbol = Symbol.for('__type__');\n\ninterface ValidatePermissionHandler {\n (params: { permission: { action: string } }): boolean;\n}\n\n/**\n * Creates a handler that checks if the permission's action exists in the action registry\n */\nconst createValidatePermissionHandler =\n (actionProvider: ReturnType<typeof createActionProvider>): ValidatePermissionHandler =>\n ({ permission }) => {\n const action = actionProvider.get(permission.action);\n\n // If the action isn't registered into the action provider, then ignore the permission and warn the user\n if (!action) {\n strapi.log.debug(\n `Unknown action \"${permission.action}\" supplied when registering a new permission`\n );\n\n return false;\n }\n\n return true;\n };\n\n/**\n * Create instances of providers and permission engine for the core content-API service.\n * Also, expose utilities to get information about available actions and such.\n */\nexport default (strapi: Core.Strapi) => {\n // NOTE: Here we define both an action and condition provider,\n // but at the moment, we're only using the action one.\n const providers = {\n action: createActionProvider(),\n condition: createConditionProvider(),\n };\n\n /**\n * Get a tree representation of the available Content API actions\n * based on the methods of the Content API controllers.\n *\n * @note Only actions bound to a content-API route are returned.\n */\n const getActionsMap = () => {\n const actionMap: Record<\n string,\n {\n controllers: Record<string, string[]>;\n }\n > = {};\n\n /**\n * Check if a controller's action is bound to the\n * content-api by looking at a potential __type__ symbol\n */\n const isContentApi = (action: Core.ControllerHandler & { [s: symbol]: any }) => {\n if (!_.has(action, typeSymbol)) {\n return false;\n }\n\n return action[typeSymbol].includes('content-api');\n };\n\n /**\n * Register actions from a specific API source into the result tree\n */\n const registerAPIsActions = (\n apis: Record<string, Core.Plugin | Core.Module>,\n source: 'api' | 'plugin'\n ) => {\n _.forEach(apis, (api, apiName) => {\n const controllers = _.reduce(\n api.controllers,\n (acc, controller, controllerName) => {\n const contentApiActions = _.pickBy(controller, isContentApi);\n\n if (_.isEmpty(contentApiActions)) {\n return acc;\n }\n\n acc[controllerName] = Object.keys(contentApiActions);\n\n return acc;\n },\n {} as Record<string, string[]>\n );\n\n if (!_.isEmpty(controllers)) {\n actionMap[`${source}::${apiName}`] = { controllers };\n }\n });\n };\n\n registerAPIsActions(strapi.apis, 'api');\n registerAPIsActions(strapi.plugins, 'plugin');\n\n return actionMap;\n };\n\n /**\n * Register all the content-API controllers actions into the action provider.\n * This method make use of the {@link getActionsMap} to generate the list of actions to register.\n */\n const registerActions = async () => {\n const actionsMap = getActionsMap();\n\n // For each API\n for (const [api, value] of Object.entries(actionsMap)) {\n const { controllers } = value;\n\n // Register controllers methods as actions\n for (const [controller, actions] of Object.entries(controllers)) {\n // Register each action individually\n await Promise.all(\n actions.map((action) => {\n const actionUID = `${api}.${controller}.${action}`;\n\n return providers.action.register(actionUID, {\n api,\n controller,\n action,\n uid: actionUID,\n });\n })\n );\n }\n }\n };\n\n // Create an instance of a content-API permission engine\n // and binds a custom validation handler to it\n const engine = createPermissionEngine({ providers });\n\n engine.on(\n 'before-format::validate.permission',\n createValidatePermissionHandler(providers.action)\n );\n\n return {\n engine,\n providers,\n registerActions,\n getActionsMap,\n };\n};\n"],"names":["typeSymbol","Symbol","for","createValidatePermissionHandler","actionProvider","permission","action","get","strapi","log","debug","providers","createActionProvider","condition","createConditionProvider","getActionsMap","actionMap","isContentApi","_","has","includes","registerAPIsActions","apis","source","forEach","api","apiName","controllers","reduce","acc","controller","controllerName","contentApiActions","pickBy","isEmpty","Object","keys","plugins","registerActions","actionsMap","value","entries","actions","Promise","all","map","actionUID","register","uid","engine","createPermissionEngine","on"],"mappings":";;;;;;;AAKA,MAAMA,UAAAA,GAAaC,MAAOC,CAAAA,GAAG,CAAC,UAAA,CAAA;AAM9B;;AAEC,IACD,MAAMC,+BACJ,GAAA,CAACC,iBACD,CAAC,EAAEC,UAAU,EAAE,GAAA;AACb,QAAA,MAAMC,MAASF,GAAAA,cAAAA,CAAeG,GAAG,CAACF,WAAWC,MAAM,CAAA;;AAGnD,QAAA,IAAI,CAACA,MAAQ,EAAA;YACXE,MAAOC,CAAAA,GAAG,CAACC,KAAK,CACd,CAAC,gBAAgB,EAAEL,UAAWC,CAAAA,MAAM,CAAC,4CAA4C,CAAC,CAAA;YAGpF,OAAO,KAAA;AACT;QAEA,OAAO,IAAA;AACT,KAAA;AAEF;;;IAIA,sCAAe,CAAA,CAACE,OAAAA,GAAAA;;;AAGd,IAAA,MAAMG,SAAY,GAAA;QAChBL,MAAQM,EAAAA,MAAAA,EAAAA;QACRC,SAAWC,EAAAA,SAAAA;AACb,KAAA;AAEA;;;;;AAKC,MACD,MAAMC,aAAgB,GAAA,IAAA;AACpB,QAAA,MAAMC,YAKF,EAAC;AAEL;;;QAIA,MAAMC,eAAe,CAACX,MAAAA,GAAAA;AACpB,YAAA,IAAI,CAACY,CAAAA,CAAEC,GAAG,CAACb,QAAQN,UAAa,CAAA,EAAA;gBAC9B,OAAO,KAAA;AACT;AAEA,YAAA,OAAOM,MAAM,CAACN,UAAW,CAAA,CAACoB,QAAQ,CAAC,aAAA,CAAA;AACrC,SAAA;AAEA;;QAGA,MAAMC,mBAAsB,GAAA,CAC1BC,IACAC,EAAAA,MAAAA,GAAAA;AAEAL,YAAAA,CAAAA,CAAEM,OAAO,CAACF,IAAM,EAAA,CAACG,GAAKC,EAAAA,OAAAA,GAAAA;gBACpB,MAAMC,WAAAA,GAAcT,EAAEU,MAAM,CAC1BH,IAAIE,WAAW,EACf,CAACE,GAAAA,EAAKC,UAAYC,EAAAA,cAAAA,GAAAA;AAChB,oBAAA,MAAMC,iBAAoBd,GAAAA,CAAAA,CAAEe,MAAM,CAACH,UAAYb,EAAAA,YAAAA,CAAAA;oBAE/C,IAAIC,CAAAA,CAAEgB,OAAO,CAACF,iBAAoB,CAAA,EAAA;wBAChC,OAAOH,GAAAA;AACT;AAEAA,oBAAAA,GAAG,CAACE,cAAAA,CAAe,GAAGI,MAAAA,CAAOC,IAAI,CAACJ,iBAAAA,CAAAA;oBAElC,OAAOH,GAAAA;AACT,iBAAA,EACA,EAAC,CAAA;AAGH,gBAAA,IAAI,CAACX,CAAAA,CAAEgB,OAAO,CAACP,WAAc,CAAA,EAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/services/content-api/permissions/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\nimport { createActionProvider, createConditionProvider } from './providers';\nimport createPermissionEngine from './engine';\n\nconst typeSymbol = Symbol.for('__type__');\n\ninterface ValidatePermissionHandler {\n (params: { permission: { action: string } }): boolean;\n}\n\n/**\n * Creates a handler that checks if the permission's action exists in the action registry\n */\nconst createValidatePermissionHandler =\n (actionProvider: ReturnType<typeof createActionProvider>): ValidatePermissionHandler =>\n ({ permission }) => {\n const action = actionProvider.get(permission.action);\n\n // If the action isn't registered into the action provider, then ignore the permission and warn the user\n if (!action) {\n strapi.log.debug(\n `Unknown action \"${permission.action}\" supplied when registering a new permission`\n );\n\n return false;\n }\n\n return true;\n };\n\n/**\n * Create instances of providers and permission engine for the core content-API service.\n * Also, expose utilities to get information about available actions and such.\n */\nexport default (strapi: Core.Strapi) => {\n // NOTE: Here we define both an action and condition provider,\n // but at the moment, we're only using the action one.\n const providers = {\n action: createActionProvider(),\n condition: createConditionProvider(),\n };\n\n /**\n * Get a tree representation of the available Content API actions\n * based on the methods of the Content API controllers.\n *\n * @note Only actions bound to a content-API route are returned.\n */\n const getActionsMap = () => {\n const actionMap: Record<\n string,\n {\n controllers: Record<string, string[]>;\n }\n > = {};\n\n /**\n * Check if a controller's action is bound to the\n * content-api by looking at a potential __type__ symbol\n */\n const isContentApi = (action: Core.ControllerHandler & { [s: symbol]: any }) => {\n if (!_.has(action, typeSymbol)) {\n return false;\n }\n\n return action[typeSymbol].includes('content-api');\n };\n\n /**\n * Register actions from a specific API source into the result tree\n */\n const registerAPIsActions = (\n apis: Record<string, Core.Plugin | Core.Module>,\n source: 'api' | 'plugin'\n ) => {\n _.forEach(apis, (api, apiName) => {\n const controllers = _.reduce(\n api.controllers,\n (acc, controller, controllerName) => {\n const contentApiActions = _.pickBy(controller, isContentApi);\n\n if (_.isEmpty(contentApiActions)) {\n return acc;\n }\n\n acc[controllerName] = Object.keys(contentApiActions);\n\n return acc;\n },\n {} as Record<string, string[]>\n );\n\n if (!_.isEmpty(controllers)) {\n actionMap[`${source}::${apiName}`] = { controllers };\n }\n });\n };\n\n registerAPIsActions(strapi.apis, 'api');\n registerAPIsActions(strapi.plugins, 'plugin');\n\n return actionMap;\n };\n\n /**\n * Register all the content-API controllers actions into the action provider.\n * This method make use of the {@link getActionsMap} to generate the list of actions to register.\n */\n const registerActions = async () => {\n const actionsMap = getActionsMap();\n\n // For each API\n for (const [api, value] of Object.entries(actionsMap)) {\n const { controllers } = value;\n\n // Register controllers methods as actions\n for (const [controller, actions] of Object.entries(controllers)) {\n // Register each action individually\n await Promise.all(\n actions.map((action) => {\n const actionUID = `${api}.${controller}.${action}`;\n\n return providers.action.register(actionUID, {\n api,\n controller,\n action,\n uid: actionUID,\n });\n })\n );\n }\n }\n };\n\n // Create an instance of a content-API permission engine\n // and binds a custom validation handler to it\n const engine = createPermissionEngine({ providers });\n\n engine.on(\n 'before-format::validate.permission',\n createValidatePermissionHandler(providers.action)\n );\n\n return {\n engine,\n providers,\n registerActions,\n getActionsMap,\n };\n};\n"],"names":["typeSymbol","Symbol","for","createValidatePermissionHandler","actionProvider","permission","action","get","strapi","log","debug","providers","createActionProvider","condition","createConditionProvider","getActionsMap","actionMap","isContentApi","_","has","includes","registerAPIsActions","apis","source","forEach","api","apiName","controllers","reduce","acc","controller","controllerName","contentApiActions","pickBy","isEmpty","Object","keys","plugins","registerActions","actionsMap","value","entries","actions","Promise","all","map","actionUID","register","uid","engine","createPermissionEngine","on"],"mappings":";;;;;;;AAKA,MAAMA,UAAAA,GAAaC,MAAOC,CAAAA,GAAG,CAAC,UAAA,CAAA;AAM9B;;AAEC,IACD,MAAMC,+BACJ,GAAA,CAACC,iBACD,CAAC,EAAEC,UAAU,EAAE,GAAA;AACb,QAAA,MAAMC,MAASF,GAAAA,cAAAA,CAAeG,GAAG,CAACF,WAAWC,MAAM,CAAA;;AAGnD,QAAA,IAAI,CAACA,MAAQ,EAAA;YACXE,MAAOC,CAAAA,GAAG,CAACC,KAAK,CACd,CAAC,gBAAgB,EAAEL,UAAWC,CAAAA,MAAM,CAAC,4CAA4C,CAAC,CAAA;YAGpF,OAAO,KAAA;AACT;QAEA,OAAO,IAAA;AACT,KAAA;AAEF;;;IAIA,sCAAe,CAAA,CAACE,OAAAA,GAAAA;;;AAGd,IAAA,MAAMG,SAAY,GAAA;QAChBL,MAAQM,EAAAA,MAAAA,EAAAA;QACRC,SAAWC,EAAAA,SAAAA;AACb,KAAA;AAEA;;;;;AAKC,MACD,MAAMC,aAAgB,GAAA,IAAA;AACpB,QAAA,MAAMC,YAKF,EAAC;AAEL;;;QAIA,MAAMC,eAAe,CAACX,MAAAA,GAAAA;AACpB,YAAA,IAAI,CAACY,CAAAA,CAAEC,GAAG,CAACb,QAAQN,UAAa,CAAA,EAAA;gBAC9B,OAAO,KAAA;AACT;AAEA,YAAA,OAAOM,MAAM,CAACN,UAAW,CAAA,CAACoB,QAAQ,CAAC,aAAA,CAAA;AACrC,SAAA;AAEA;;QAGA,MAAMC,mBAAsB,GAAA,CAC1BC,IACAC,EAAAA,MAAAA,GAAAA;AAEAL,YAAAA,CAAAA,CAAEM,OAAO,CAACF,IAAM,EAAA,CAACG,GA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AAA,MAAMgB,QAAQC,GAAG,CACfF,OAAQG,CAAAA,GAAG,CAAC,CAACvC,MAAAA,GAAAA;oBACX,MAAMwC,SAAAA,GAAY,GAAGrB,GAAI,CAAA,CAAC,EAAEK,UAAW,CAAA,CAAC,EAAExB,MAAQ,CAAA,CAAA;AAElD,oBAAA,OAAOK,SAAUL,CAAAA,MAAM,CAACyC,QAAQ,CAACD,SAAW,EAAA;AAC1CrB,wBAAAA,GAAAA;AACAK,wBAAAA,UAAAA;AACAxB,wBAAAA,MAAAA;wBACA0C,GAAKF,EAAAA;AACP,qBAAA,CAAA;AACF,iBAAA,CAAA,CAAA;AAEJ;AACF;AACF,KAAA;;;AAIA,IAAA,MAAMG,WAASC,MAAuB,CAAA;AAAEvC,QAAAA;AAAU,KAAA,CAAA;AAElDsC,IAAAA,QAAAA,CAAOE,EAAE,CACP,oCACAhD,EAAAA,+BAAAA,CAAgCQ,UAAUL,MAAM,CAAA,CAAA;IAGlD,OAAO;AACL2C,gBAAAA,QAAAA;AACAtC,QAAAA,SAAAA;AACA2B,QAAAA,eAAAA;AACAvB,QAAAA;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/services/content-api/permissions/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\nimport { createActionProvider, createConditionProvider } from './providers';\nimport createPermissionEngine from './engine';\n\nconst typeSymbol = Symbol.for('__type__');\n\ninterface ValidatePermissionHandler {\n (params: { permission: { action: string } }): boolean;\n}\n\n/**\n * Creates a handler that checks if the permission's action exists in the action registry\n */\nconst createValidatePermissionHandler =\n (actionProvider: ReturnType<typeof createActionProvider>): ValidatePermissionHandler =>\n ({ permission }) => {\n const action = actionProvider.get(permission.action);\n\n // If the action isn't registered into the action provider, then ignore the permission and warn the user\n if (!action) {\n strapi.log.debug(\n `Unknown action \"${permission.action}\" supplied when registering a new permission`\n );\n\n return false;\n }\n\n return true;\n };\n\n/**\n * Create instances of providers and permission engine for the core content-API service.\n * Also, expose utilities to get information about available actions and such.\n */\nexport default (strapi: Core.Strapi) => {\n // NOTE: Here we define both an action and condition provider,\n // but at the moment, we're only using the action one.\n const providers = {\n action: createActionProvider(),\n condition: createConditionProvider(),\n };\n\n /**\n * Get a tree representation of the available Content API actions\n * based on the methods of the Content API controllers.\n *\n * @note Only actions bound to a content-API route are returned.\n */\n const getActionsMap = () => {\n const actionMap: Record<\n string,\n {\n controllers: Record<string, string[]>;\n }\n > = {};\n\n /**\n * Check if a controller's action is bound to the\n * content-api by looking at a potential __type__ symbol\n */\n const isContentApi = (action: Core.ControllerHandler & { [s: symbol]: any }) => {\n if (!_.has(action, typeSymbol)) {\n return false;\n }\n\n return action[typeSymbol].includes('content-api');\n };\n\n /**\n * Register actions from a specific API source into the result tree\n */\n const registerAPIsActions = (\n apis: Record<string, Core.Plugin | Core.Module>,\n source: 'api' | 'plugin'\n ) => {\n _.forEach(apis, (api, apiName) => {\n const controllers = _.reduce(\n api.controllers,\n (acc, controller, controllerName) => {\n const contentApiActions = _.pickBy(controller, isContentApi);\n\n if (_.isEmpty(contentApiActions)) {\n return acc;\n }\n\n acc[controllerName] = Object.keys(contentApiActions);\n\n return acc;\n },\n {} as Record<string, string[]>\n );\n\n if (!_.isEmpty(controllers)) {\n actionMap[`${source}::${apiName}`] = { controllers };\n }\n });\n };\n\n registerAPIsActions(strapi.apis, 'api');\n registerAPIsActions(strapi.plugins, 'plugin');\n\n return actionMap;\n };\n\n /**\n * Register all the content-API controllers actions into the action provider.\n * This method make use of the {@link getActionsMap} to generate the list of actions to register.\n */\n const registerActions = async () => {\n const actionsMap = getActionsMap();\n\n // For each API\n for (const [api, value] of Object.entries(actionsMap)) {\n const { controllers } = value;\n\n // Register controllers methods as actions\n for (const [controller, actions] of Object.entries(controllers)) {\n // Register each action individually\n await Promise.all(\n actions.map((action) => {\n const actionUID = `${api}.${controller}.${action}`;\n\n return providers.action.register(actionUID, {\n api,\n controller,\n action,\n uid: actionUID,\n });\n })\n );\n }\n }\n };\n\n // Create an instance of a content-API permission engine\n // and binds a custom validation handler to it\n const engine = createPermissionEngine({ providers });\n\n engine.on(\n 'before-format::validate.permission',\n createValidatePermissionHandler(providers.action)\n );\n\n return {\n engine,\n providers,\n registerActions,\n getActionsMap,\n };\n};\n"],"names":["typeSymbol","Symbol","for","createValidatePermissionHandler","actionProvider","permission","action","get","strapi","log","debug","providers","createActionProvider","condition","createConditionProvider","getActionsMap","actionMap","isContentApi","_","has","includes","registerAPIsActions","apis","source","forEach","api","apiName","controllers","reduce","acc","controller","controllerName","contentApiActions","pickBy","isEmpty","Object","keys","plugins","registerActions","actionsMap","value","entries","actions","Promise","all","map","actionUID","register","uid","engine","createPermissionEngine","on"],"mappings":";;;;;AAKA,MAAMA,UAAAA,GAAaC,MAAOC,CAAAA,GAAG,CAAC,UAAA,CAAA;AAM9B;;AAEC,IACD,MAAMC,+BACJ,GAAA,CAACC,iBACD,CAAC,EAAEC,UAAU,EAAE,GAAA;AACb,QAAA,MAAMC,MAASF,GAAAA,cAAAA,CAAeG,GAAG,CAACF,WAAWC,MAAM,CAAA;;AAGnD,QAAA,IAAI,CAACA,MAAQ,EAAA;YACXE,MAAOC,CAAAA,GAAG,CAACC,KAAK,CACd,CAAC,gBAAgB,EAAEL,UAAWC,CAAAA,MAAM,CAAC,4CAA4C,CAAC,CAAA;YAGpF,OAAO,KAAA;AACT;QAEA,OAAO,IAAA;AACT,KAAA;AAEF;;;IAIA,sCAAe,CAAA,CAACE,OAAAA,GAAAA;;;AAGd,IAAA,MAAMG,SAAY,GAAA;QAChBL,MAAQM,EAAAA,oBAAAA,EAAAA;QACRC,SAAWC,EAAAA,uBAAAA;AACb,KAAA;AAEA;;;;;AAKC,MACD,MAAMC,aAAgB,GAAA,IAAA;AACpB,QAAA,MAAMC,YAKF,EAAC;AAEL;;;QAIA,MAAMC,eAAe,CAACX,MAAAA,GAAAA;AACpB,YAAA,IAAI,CAACY,CAAAA,CAAEC,GAAG,CAACb,QAAQN,UAAa,CAAA,EAAA;gBAC9B,OAAO,KAAA;AACT;AAEA,YAAA,OAAOM,MAAM,CAACN,UAAW,CAAA,CAACoB,QAAQ,CAAC,aAAA,CAAA;AACrC,SAAA;AAEA;;QAGA,MAAMC,mBAAsB,GAAA,CAC1BC,IACAC,EAAAA,MAAAA,GAAAA;AAEAL,YAAAA,CAAAA,CAAEM,OAAO,CAACF,IAAM,EAAA,CAACG,GAAKC,EAAAA,OAAAA,GAAAA;gBACpB,MAAMC,WAAAA,GAAcT,EAAEU,MAAM,CAC1BH,IAAIE,WAAW,EACf,CAACE,GAAAA,EAAKC,UAAYC,EAAAA,cAAAA,GAAAA;AAChB,oBAAA,MAAMC,iBAAoBd,GAAAA,CAAAA,CAAEe,MAAM,CAACH,UAAYb,EAAAA,YAAAA,CAAAA;oBAE/C,IAAIC,CAAAA,CAAEgB,OAAO,CAACF,iBAAoB,CAAA,EAAA;wBAChC,OAAOH,GAAAA;AACT;AAEAA,oBAAAA,GAAG,CAACE,cAAAA,CAAe,GAAGI,MAAAA,CAAOC,IAAI,CAACJ,iBAAAA,CAAAA;oBAElC,OAAOH,GAAAA;AACT,iBAAA,EACA,EAAC,CAAA;AAGH,gBAAA,IAAI,CAACX,CAAAA,CAAEgB,OAAO,CAACP,WAAc,CAAA,EAAA;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/services/content-api/permissions/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\nimport { createActionProvider, createConditionProvider } from './providers';\nimport createPermissionEngine from './engine';\n\nconst typeSymbol = Symbol.for('__type__');\n\ninterface ValidatePermissionHandler {\n (params: { permission: { action: string } }): boolean;\n}\n\n/**\n * Creates a handler that checks if the permission's action exists in the action registry\n */\nconst createValidatePermissionHandler =\n (actionProvider: ReturnType<typeof createActionProvider>): ValidatePermissionHandler =>\n ({ permission }) => {\n const action = actionProvider.get(permission.action);\n\n // If the action isn't registered into the action provider, then ignore the permission and warn the user\n if (!action) {\n strapi.log.debug(\n `Unknown action \"${permission.action}\" supplied when registering a new permission`\n );\n\n return false;\n }\n\n return true;\n };\n\n/**\n * Create instances of providers and permission engine for the core content-API service.\n * Also, expose utilities to get information about available actions and such.\n */\nexport default (strapi: Core.Strapi) => {\n // NOTE: Here we define both an action and condition provider,\n // but at the moment, we're only using the action one.\n const providers = {\n action: createActionProvider(),\n condition: createConditionProvider(),\n };\n\n /**\n * Get a tree representation of the available Content API actions\n * based on the methods of the Content API controllers.\n *\n * @note Only actions bound to a content-API route are returned.\n */\n const getActionsMap = () => {\n const actionMap: Record<\n string,\n {\n controllers: Record<string, string[]>;\n }\n > = {};\n\n /**\n * Check if a controller's action is bound to the\n * content-api by looking at a potential __type__ symbol\n */\n const isContentApi = (action: Core.ControllerHandler & { [s: symbol]: any }) => {\n if (!_.has(action, typeSymbol)) {\n return false;\n }\n\n return action[typeSymbol].includes('content-api');\n };\n\n /**\n * Register actions from a specific API source into the result tree\n */\n const registerAPIsActions = (\n apis: Record<string, Core.Plugin | Core.Module>,\n source: 'api' | 'plugin'\n ) => {\n _.forEach(apis, (api, apiName) => {\n const controllers = _.reduce(\n api.controllers,\n (acc, controller, controllerName) => {\n const contentApiActions = _.pickBy(controller, isContentApi);\n\n if (_.isEmpty(contentApiActions)) {\n return acc;\n }\n\n acc[controllerName] = Object.keys(contentApiActions);\n\n return acc;\n },\n {} as Record<string, string[]>\n );\n\n if (!_.isEmpty(controllers)) {\n actionMap[`${source}::${apiName}`] = { controllers };\n }\n });\n };\n\n registerAPIsActions(strapi.apis, 'api');\n registerAPIsActions(strapi.plugins, 'plugin');\n\n return actionMap;\n };\n\n /**\n * Register all the content-API controllers actions into the action provider.\n * This method make use of the {@link getActionsMap} to generate the list of actions to register.\n */\n const registerActions = async () => {\n const actionsMap = getActionsMap();\n\n // For each API\n for (const [api, value] of Object.entries(actionsMap)) {\n const { controllers } = value;\n\n // Register controllers methods as actions\n for (const [controller, actions] of Object.entries(controllers)) {\n // Register each action individually\n await Promise.all(\n actions.map((action) => {\n const actionUID = `${api}.${controller}.${action}`;\n\n return providers.action.register(actionUID, {\n api,\n controller,\n action,\n uid: actionUID,\n });\n })\n );\n }\n }\n };\n\n // Create an instance of a content-API permission engine\n // and binds a custom validation handler to it\n const engine = createPermissionEngine({ providers });\n\n engine.on(\n 'before-format::validate.permission',\n createValidatePermissionHandler(providers.action)\n );\n\n return {\n engine,\n providers,\n registerActions,\n getActionsMap,\n };\n};\n"],"names":["typeSymbol","Symbol","for","createValidatePermissionHandler","actionProvider","permission","action","get","strapi","log","debug","providers","createActionProvider","condition","createConditionProvider","getActionsMap","actionMap","isContentApi","_","has","includes","registerAPIsActions","apis","source","forEach","api","apiName","controllers","reduce","acc","controller","controllerName","contentApiActions","pickBy","isEmpty","Object","keys","plugins","registerActions","actionsMap","value","entries","actions","Promise","all","map","actionUID","register","uid","engine","createPermissionEngine","on"],"mappings":";;;;;AAKA,MAAMA,UAAAA,GAAaC,MAAOC,CAAAA,GAAG,CAAC,UAAA,CAAA;AAM9B;;AAEC,IACD,MAAMC,+BACJ,GAAA,CAACC,iBACD,CAAC,EAAEC,UAAU,EAAE,GAAA;AACb,QAAA,MAAMC,MAASF,GAAAA,cAAAA,CAAeG,GAAG,CAACF,WAAWC,MAAM,CAAA;;AAGnD,QAAA,IAAI,CAACA,MAAQ,EAAA;YACXE,MAAOC,CAAAA,GAAG,CAACC,KAAK,CACd,CAAC,gBAAgB,EAAEL,UAAWC,CAAAA,MAAM,CAAC,4CAA4C,CAAC,CAAA;YAGpF,OAAO,KAAA;AACT;QAEA,OAAO,IAAA;AACT,KAAA;AAEF;;;IAIA,sCAAe,CAAA,CAACE,OAAAA,GAAAA;;;AAGd,IAAA,MAAMG,SAAY,GAAA;QAChBL,MAAQM,EAAAA,oBAAAA,EAAAA;QACRC,SAAWC,EAAAA,uBAAAA;AACb,KAAA;AAEA;;;;;AAKC,MACD,MAAMC,aAAgB,GAA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admin';
|
|
3
|
+
interface EncodingInfo {
|
|
4
|
+
data: any;
|
|
5
|
+
schema: Struct.Schema;
|
|
6
|
+
}
|
|
2
7
|
declare const createContentSourceMapsService: (strapi: Core.Strapi) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
encodeSourceMaps(data
|
|
8
|
+
encodeField(text: string, { kind, model, documentId, type, path, locale }: FieldContentSourceMap): string;
|
|
9
|
+
encodeEntry({ data, schema }: EncodingInfo): Promise<any>;
|
|
10
|
+
encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any>;
|
|
6
11
|
};
|
|
7
12
|
export { createContentSourceMapsService };
|
|
8
13
|
//# sourceMappingURL=content-source-maps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-source-maps.d.ts","sourceRoot":"","sources":["../../src/services/content-source-maps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"content-source-maps.d.ts","sourceRoot":"","sources":["../../src/services/content-source-maps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAO,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAwCxE,UAAU,YAAY;IACpB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;CACvB;AAMD,QAAA,MAAM,8BAA8B,WAAY,KAAK,MAAM;sBAG/C,MAAM,mDACqC,qBAAqB;kCAyBpC,YAAY,GAAG,QAAQ,GAAG,CAAC;uCAiCtB,YAAY,GAAG,QAAQ,GAAG,CAAC;CAmBvE,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var stega = require('@vercel/stega');
|
|
4
|
+
var strapiUtils = require('@strapi/utils');
|
|
4
5
|
|
|
5
6
|
const ENCODABLE_TYPES = [
|
|
6
7
|
'string',
|
|
7
8
|
'text',
|
|
8
9
|
'richtext',
|
|
9
|
-
'
|
|
10
|
-
'enumeration',
|
|
11
|
-
'email',
|
|
10
|
+
'biginteger',
|
|
12
11
|
'date',
|
|
13
|
-
'datetime',
|
|
14
12
|
'time',
|
|
15
|
-
'
|
|
13
|
+
'datetime',
|
|
14
|
+
'timestamp',
|
|
15
|
+
'boolean',
|
|
16
|
+
'enumeration',
|
|
17
|
+
'json',
|
|
18
|
+
'media',
|
|
19
|
+
'email',
|
|
20
|
+
'password'
|
|
16
21
|
];
|
|
22
|
+
// TODO: use a centralized store for these fields that would be shared with the CM and CTB
|
|
17
23
|
const EXCLUDED_FIELDS = [
|
|
18
24
|
'id',
|
|
19
25
|
'documentId',
|
|
@@ -25,92 +31,75 @@ const EXCLUDED_FIELDS = [
|
|
|
25
31
|
'updated_at',
|
|
26
32
|
'publishedAt'
|
|
27
33
|
];
|
|
34
|
+
const isObject = (value)=>{
|
|
35
|
+
return typeof value === 'object' && value !== null;
|
|
36
|
+
};
|
|
28
37
|
const createContentSourceMapsService = (strapi)=>{
|
|
29
38
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
encodeField (text, { kind, model, documentId, type, path, locale }) {
|
|
40
|
+
/**
|
|
41
|
+
* Combine all metadata into into a one string so we only have to deal with one data-atribute
|
|
42
|
+
* on the frontend. Make it human readable because that data-attribute may be set manually by
|
|
43
|
+
* users for fields that don't support sourcemap encoding.
|
|
44
|
+
*/ const strapiSource = new URLSearchParams();
|
|
45
|
+
strapiSource.set('documentId', documentId);
|
|
46
|
+
strapiSource.set('type', type);
|
|
47
|
+
strapiSource.set('path', path);
|
|
48
|
+
if (model) {
|
|
49
|
+
strapiSource.set('model', model);
|
|
38
50
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
isEnabled () {
|
|
42
|
-
return this.config.enabled ?? true;
|
|
43
|
-
},
|
|
44
|
-
async encodeSourceMaps (data, contentType, rootId, rootModel) {
|
|
45
|
-
if (!this.isEnabled()) {
|
|
46
|
-
return;
|
|
51
|
+
if (kind) {
|
|
52
|
+
strapiSource.set('kind', kind);
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
if (locale) {
|
|
55
|
+
strapiSource.set('locale', locale);
|
|
56
|
+
}
|
|
57
|
+
return stega.vercelStegaCombine(text, {
|
|
58
|
+
strapiSource: strapiSource.toString()
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
async encodeEntry ({ data, schema }) {
|
|
62
|
+
if (!isObject(data) || data === undefined) {
|
|
63
|
+
return data;
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
if (
|
|
65
|
+
return strapiUtils.traverseEntity(({ key, value, attribute, schema, path }, { set })=>{
|
|
66
|
+
if (!attribute || EXCLUDED_FIELDS.includes(key)) {
|
|
57
67
|
return;
|
|
58
68
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
console.log('Encoding relation. value:', value);
|
|
91
|
-
return encodeEntry(value.id, relatedModel.uid, value, strapi.getModel(attribute.target));
|
|
92
|
-
}
|
|
93
|
-
if (attribute.type === 'media') {
|
|
94
|
-
if (Array.isArray(value.data)) {
|
|
95
|
-
return value.data.forEach((item)=>{
|
|
96
|
-
return encodeEntry(entryRootId, entryRootModel, item, fileModel);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return encodeEntry(entryRootId, entryRootModel, value.data, fileModel);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
69
|
+
if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {
|
|
70
|
+
set(key, this.encodeField(value, {
|
|
71
|
+
path: path.rawWithIndices,
|
|
72
|
+
type: attribute.type,
|
|
73
|
+
kind: schema.kind,
|
|
74
|
+
model: schema.uid,
|
|
75
|
+
locale: data.locale,
|
|
76
|
+
documentId: data.documentId
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
schema,
|
|
81
|
+
getModel: (uid)=>strapi.getModel(uid)
|
|
82
|
+
}, data);
|
|
83
|
+
},
|
|
84
|
+
async encodeSourceMaps ({ data, schema }) {
|
|
85
|
+
try {
|
|
86
|
+
if (Array.isArray(data)) {
|
|
87
|
+
return await Promise.all(data.map((item)=>this.encodeSourceMaps({
|
|
88
|
+
data: item,
|
|
89
|
+
schema
|
|
90
|
+
})));
|
|
91
|
+
}
|
|
92
|
+
if (!isObject(data)) {
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
return await this.encodeEntry({
|
|
96
|
+
data,
|
|
97
|
+
schema
|
|
102
98
|
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
strapi.log.error('Error encoding source maps:', error);
|
|
101
|
+
return data;
|
|
103
102
|
}
|
|
104
|
-
if (Array.isArray(data)) {
|
|
105
|
-
data.forEach((item)=>this.encodeSourceMaps(item, contentType));
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (typeof data !== 'object' || data === null) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const actualRootId = rootId || data.id;
|
|
112
|
-
const actualRootModel = rootModel || contentType.uid;
|
|
113
|
-
await encodeEntry(actualRootId, actualRootModel, data, contentType);
|
|
114
103
|
}
|
|
115
104
|
};
|
|
116
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-source-maps.js","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct } from '@strapi/types';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n '
|
|
1
|
+
{"version":3,"file":"content-source-maps.js","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n return vercelStegaCombine(text, { strapiSource: strapiSource.toString() });\n },\n\n async encodeEntry({ data, schema }: EncodingInfo): Promise<any> {\n if (!isObject(data) || data === undefined) {\n return data;\n }\n\n return traverseEntity(\n ({ key, value, attribute, schema, path }, { set }) => {\n if (!attribute || EXCLUDED_FIELDS.includes(key)) {\n return;\n }\n\n if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {\n set(\n key,\n this.encodeField(value, {\n path: path.rawWithIndices!,\n type: attribute.type,\n kind: schema.kind,\n model: schema.uid as UID.Schema,\n locale: data.locale,\n documentId: data.documentId,\n }) as any\n );\n }\n },\n {\n schema,\n getModel: (uid) => strapi.getModel(uid as UID.Schema),\n },\n data\n );\n },\n\n async encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any> {\n try {\n if (Array.isArray(data)) {\n return await Promise.all(\n data.map((item) => this.encodeSourceMaps({ data: item, schema }))\n );\n }\n\n if (!isObject(data)) {\n return data;\n }\n\n return await this.encodeEntry({ data, schema });\n } catch (error) {\n strapi.log.error('Error encoding source maps:', error);\n return data;\n }\n },\n };\n};\n\nexport { createContentSourceMapsService };\n"],"names":["ENCODABLE_TYPES","EXCLUDED_FIELDS","isObject","value","createContentSourceMapsService","strapi","encodeField","text","kind","model","documentId","type","path","locale","strapiSource","URLSearchParams","set","vercelStegaCombine","toString","encodeEntry","data","schema","undefined","traverseEntity","key","attribute","includes","rawWithIndices","uid","getModel","encodeSourceMaps","Array","isArray","Promise","all","map","item","error","log"],"mappings":";;;;;AAKA,MAAMA,eAAkB,GAAA;AACtB,IAAA,QAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;AACA,IAAA,MAA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U,KAAAA,CAAMC,OAAO,CAACZ,IAAO,CAAA,EAAA;AACvB,oBAAA,OAAO,MAAMa,OAAAA,CAAQC,GAAG,CACtBd,IAAKe,CAAAA,GAAG,CAAC,CAACC,IAAS,GAAA,IAAI,CAACN,gBAAgB,CAAC;4BAAEV,IAAMgB,EAAAA,IAAAA;AAAMf,4BAAAA;AAAO,yBAAA,CAAA,CAAA,CAAA;AAElE;gBAEA,IAAI,CAACnB,SAASkB,IAAO,CAAA,EAAA;oBACnB,OAAOA,IAAAA;AACT;AAEA,gBAAA,OAAO,MAAM,IAAI,CAACD,WAAW,CAAC;AAAEC,oBAAAA,IAAAA;AAAMC,oBAAAA;AAAO,iBAAA,CAAA;AAC/C,aAAA,CAAE,OAAOgB,KAAO,EAAA;AACdhC,gBAAAA,MAAAA,CAAOiC,GAAG,CAACD,KAAK,CAAC,6BAA+BA,EAAAA,KAAAA,CAAAA;gBAChD,OAAOjB,IAAAA;AACT;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { vercelStegaCombine } from '@vercel/stega';
|
|
2
|
+
import { traverseEntity } from '@strapi/utils';
|
|
2
3
|
|
|
3
4
|
const ENCODABLE_TYPES = [
|
|
4
5
|
'string',
|
|
5
6
|
'text',
|
|
6
7
|
'richtext',
|
|
7
|
-
'
|
|
8
|
-
'enumeration',
|
|
9
|
-
'email',
|
|
8
|
+
'biginteger',
|
|
10
9
|
'date',
|
|
11
|
-
'datetime',
|
|
12
10
|
'time',
|
|
13
|
-
'
|
|
11
|
+
'datetime',
|
|
12
|
+
'timestamp',
|
|
13
|
+
'boolean',
|
|
14
|
+
'enumeration',
|
|
15
|
+
'json',
|
|
16
|
+
'media',
|
|
17
|
+
'email',
|
|
18
|
+
'password'
|
|
14
19
|
];
|
|
20
|
+
// TODO: use a centralized store for these fields that would be shared with the CM and CTB
|
|
15
21
|
const EXCLUDED_FIELDS = [
|
|
16
22
|
'id',
|
|
17
23
|
'documentId',
|
|
@@ -23,92 +29,75 @@ const EXCLUDED_FIELDS = [
|
|
|
23
29
|
'updated_at',
|
|
24
30
|
'publishedAt'
|
|
25
31
|
];
|
|
32
|
+
const isObject = (value)=>{
|
|
33
|
+
return typeof value === 'object' && value !== null;
|
|
34
|
+
};
|
|
26
35
|
const createContentSourceMapsService = (strapi)=>{
|
|
27
36
|
return {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
encodeField (text, { kind, model, documentId, type, path, locale }) {
|
|
38
|
+
/**
|
|
39
|
+
* Combine all metadata into into a one string so we only have to deal with one data-atribute
|
|
40
|
+
* on the frontend. Make it human readable because that data-attribute may be set manually by
|
|
41
|
+
* users for fields that don't support sourcemap encoding.
|
|
42
|
+
*/ const strapiSource = new URLSearchParams();
|
|
43
|
+
strapiSource.set('documentId', documentId);
|
|
44
|
+
strapiSource.set('type', type);
|
|
45
|
+
strapiSource.set('path', path);
|
|
46
|
+
if (model) {
|
|
47
|
+
strapiSource.set('model', model);
|
|
36
48
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
isEnabled () {
|
|
40
|
-
return this.config.enabled ?? true;
|
|
41
|
-
},
|
|
42
|
-
async encodeSourceMaps (data, contentType, rootId, rootModel) {
|
|
43
|
-
if (!this.isEnabled()) {
|
|
44
|
-
return;
|
|
49
|
+
if (kind) {
|
|
50
|
+
strapiSource.set('kind', kind);
|
|
45
51
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
if (locale) {
|
|
53
|
+
strapiSource.set('locale', locale);
|
|
54
|
+
}
|
|
55
|
+
return vercelStegaCombine(text, {
|
|
56
|
+
strapiSource: strapiSource.toString()
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async encodeEntry ({ data, schema }) {
|
|
60
|
+
if (!isObject(data) || data === undefined) {
|
|
61
|
+
return data;
|
|
52
62
|
}
|
|
53
|
-
|
|
54
|
-
if (
|
|
63
|
+
return traverseEntity(({ key, value, attribute, schema, path }, { set })=>{
|
|
64
|
+
if (!attribute || EXCLUDED_FIELDS.includes(key)) {
|
|
55
65
|
return;
|
|
56
66
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
console.log('Encoding relation. value:', value);
|
|
89
|
-
return encodeEntry(value.id, relatedModel.uid, value, strapi.getModel(attribute.target));
|
|
90
|
-
}
|
|
91
|
-
if (attribute.type === 'media') {
|
|
92
|
-
if (Array.isArray(value.data)) {
|
|
93
|
-
return value.data.forEach((item)=>{
|
|
94
|
-
return encodeEntry(entryRootId, entryRootModel, item, fileModel);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return encodeEntry(entryRootId, entryRootModel, value.data, fileModel);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
67
|
+
if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {
|
|
68
|
+
set(key, this.encodeField(value, {
|
|
69
|
+
path: path.rawWithIndices,
|
|
70
|
+
type: attribute.type,
|
|
71
|
+
kind: schema.kind,
|
|
72
|
+
model: schema.uid,
|
|
73
|
+
locale: data.locale,
|
|
74
|
+
documentId: data.documentId
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
schema,
|
|
79
|
+
getModel: (uid)=>strapi.getModel(uid)
|
|
80
|
+
}, data);
|
|
81
|
+
},
|
|
82
|
+
async encodeSourceMaps ({ data, schema }) {
|
|
83
|
+
try {
|
|
84
|
+
if (Array.isArray(data)) {
|
|
85
|
+
return await Promise.all(data.map((item)=>this.encodeSourceMaps({
|
|
86
|
+
data: item,
|
|
87
|
+
schema
|
|
88
|
+
})));
|
|
89
|
+
}
|
|
90
|
+
if (!isObject(data)) {
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
return await this.encodeEntry({
|
|
94
|
+
data,
|
|
95
|
+
schema
|
|
100
96
|
});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
strapi.log.error('Error encoding source maps:', error);
|
|
99
|
+
return data;
|
|
101
100
|
}
|
|
102
|
-
if (Array.isArray(data)) {
|
|
103
|
-
data.forEach((item)=>this.encodeSourceMaps(item, contentType));
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (typeof data !== 'object' || data === null) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const actualRootId = rootId || data.id;
|
|
110
|
-
const actualRootModel = rootModel || contentType.uid;
|
|
111
|
-
await encodeEntry(actualRootId, actualRootModel, data, contentType);
|
|
112
101
|
}
|
|
113
102
|
};
|
|
114
103
|
};
|