@strapi/core 5.48.1 → 5.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Strapi.js +9 -5
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +0 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/ai.d.ts +2 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +8 -0
- package/dist/ai.js.map +1 -0
- package/dist/ai.mjs +3 -0
- package/dist/ai.mjs.map +1 -0
- package/dist/configuration/config-loader.js +11 -6
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/index.js +22 -15
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/urls.js +11 -7
- package/dist/configuration/urls.js.map +1 -1
- package/dist/core-api/routes/index.js +3 -2
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/validation/common.js +3 -2
- package/dist/core-api/routes/validation/common.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +3 -2
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +3 -2
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/utils.js +3 -2
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/domain/content-type/index.js +9 -5
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/validator.js +6 -2
- package/dist/domain/content-type/validator.js.map +1 -1
- package/dist/domain/module/index.js +6 -2
- package/dist/domain/module/index.js.map +1 -1
- package/dist/ee/license.js +8 -3
- package/dist/ee/license.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/admin.js +5 -1
- package/dist/loaders/admin.js.map +1 -1
- package/dist/loaders/apis.js +16 -11
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/components.js +6 -2
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/middlewares.js +6 -2
- package/dist/loaders/middlewares.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +5 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +6 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.js +8 -4
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/policies.js +6 -2
- package/dist/loaders/policies.js.map +1 -1
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +12 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcp.mjs +4 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/middlewares/body.js +8 -3
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/compression.js +5 -1
- package/dist/middlewares/compression.js.map +1 -1
- package/dist/middlewares/cors.js +5 -1
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/favicon.js +5 -1
- package/dist/middlewares/favicon.js.map +1 -1
- package/dist/middlewares/ip.js +5 -1
- package/dist/middlewares/ip.js.map +1 -1
- package/dist/middlewares/public.js +5 -1
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/query.js +6 -2
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/security.js +5 -1
- package/dist/middlewares/security.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +5 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/first-published-at.js +5 -1
- package/dist/migrations/first-published-at.js.map +1 -1
- package/dist/package.json.js +15 -15
- package/dist/package.json.mjs +15 -15
- package/dist/registries/sanitizers.js +7 -3
- package/dist/registries/sanitizers.js.map +1 -1
- package/dist/registries/validators.js +7 -3
- package/dist/registries/validators.js.map +1 -1
- package/dist/services/auth/index.js +7 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/content-api/index.js +10 -6
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/permissions/engine.js +5 -1
- package/dist/services/content-api/permissions/engine.js.map +1 -1
- package/dist/services/content-api/permissions/index.js +10 -6
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +5 -1
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +14 -10
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +1 -1
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs +1 -1
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +6 -2
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +7 -3
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts +2 -0
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js +7 -1
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs +7 -2
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/entity-service/index.js +9 -4
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -4
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.js +10 -6
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/errors.js +7 -3
- package/dist/services/errors.js.map +1 -1
- package/dist/services/fs.js +10 -5
- package/dist/services/fs.js.map +1 -1
- package/dist/services/mcp/prompt-registry.d.ts +31 -3
- package/dist/services/mcp/prompt-registry.d.ts.map +1 -1
- package/dist/services/mcp/prompt-registry.js +31 -0
- package/dist/services/mcp/prompt-registry.js.map +1 -1
- package/dist/services/mcp/prompt-registry.mjs +31 -1
- package/dist/services/mcp/prompt-registry.mjs.map +1 -1
- package/dist/services/mcp/resource-registry.d.ts +31 -1
- package/dist/services/mcp/resource-registry.d.ts.map +1 -1
- package/dist/services/mcp/resource-registry.js +31 -0
- package/dist/services/mcp/resource-registry.js.map +1 -1
- package/dist/services/mcp/resource-registry.mjs +31 -1
- package/dist/services/mcp/resource-registry.mjs.map +1 -1
- package/dist/services/mcp/tool-registry.d.ts +36 -9
- package/dist/services/mcp/tool-registry.d.ts.map +1 -1
- package/dist/services/mcp/tool-registry.js +35 -3
- package/dist/services/mcp/tool-registry.js.map +1 -1
- package/dist/services/mcp/tool-registry.mjs +35 -3
- package/dist/services/mcp/tool-registry.mjs.map +1 -1
- package/dist/services/mcp/tools/log.d.ts +15 -85
- package/dist/services/mcp/tools/log.d.ts.map +1 -1
- package/dist/services/metrics/admin-user-hash.js +5 -1
- package/dist/services/metrics/admin-user-hash.js.map +1 -1
- package/dist/services/metrics/is-truthy.js +5 -1
- package/dist/services/metrics/is-truthy.js.map +1 -1
- package/dist/services/metrics/sender.js +17 -9
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/server/api.js +5 -1
- package/dist/services/server/api.js.map +1 -1
- package/dist/services/server/compose-endpoint.js +5 -1
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/http-server.js +5 -1
- package/dist/services/server/http-server.js.map +1 -1
- package/dist/services/server/index.js +5 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/koa.js +12 -5
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +5 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/openapi.js +11 -6
- package/dist/services/server/openapi.js.map +1 -1
- package/dist/services/server/register-routes.js +8 -4
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/routing.js +5 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/session-manager.js +14 -9
- package/dist/services/session-manager.js.map +1 -1
- package/dist/services/webhook-runner.js +7 -2
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/worker-queue.js +5 -1
- package/dist/services/worker-queue.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +13 -8
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/load-config-file.js +7 -2
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-files.js +12 -6
- package/dist/utils/load-files.js.map +1 -1
- package/dist/utils/open-browser.js +5 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/resolve-working-dirs.js +6 -2
- package/dist/utils/resolve-working-dirs.js.map +1 -1
- package/dist/utils/startup-logger.js +27 -21
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +10 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/update-notifier/index.d.ts.map +1 -1
- package/dist/utils/update-notifier/index.js +21 -8
- package/dist/utils/update-notifier/index.js.map +1 -1
- package/dist/utils/update-notifier/index.mjs +6 -1
- package/dist/utils/update-notifier/index.mjs.map +1 -1
- package/package.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/configuration/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport { omit } from 'lodash/fp';\nimport dotenv from 'dotenv';\nimport type { Core } from '@strapi/types';\nimport { strings } from '@strapi/utils';\n\nimport { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } from './urls';\nimport loadConfigDir from './config-loader';\nimport { getDirs } from './get-dirs';\n\nimport type { StrapiOptions } from '../Strapi';\nimport { version as strapiVersion } from '../../package.json';\n\ndotenv.config({ path: process.env.ENV_PATH });\n\nprocess.env.NODE_ENV = process.env.NODE_ENV || 'development';\n\nconst defaultServerConfig = {\n host: process.env.HOST || os.hostname() || 'localhost',\n port: Number(process.env.PORT) || 1337,\n proxy: false,\n cron: { enabled: false },\n admin: { autoOpen: false },\n dirs: { public: './public' },\n transfer: {\n remote: {\n enabled: true,\n },\n },\n logger: {\n updates: {\n enabled: true,\n },\n startup: {\n enabled: true,\n },\n },\n openapi: {\n 'content-api': {\n access: 'disabled',\n route: {\n path: '/openapi.json',\n },\n cache: {\n enabled: true,\n maxAgeMs: 60_000,\n filePath: '.strapi/openapi/content-api.json',\n },\n },\n admin: {\n access: 'disabled',\n route: {\n path: '/openapi.json',\n },\n cache: {\n enabled: true,\n maxAgeMs: 60_000,\n filePath: '.strapi/openapi/admin.json',\n },\n },\n },\n} satisfies Partial<Core.Config.Server>;\n\nconst defaultConfig = {\n server: defaultServerConfig,\n admin: {} satisfies Partial<Core.Config.Admin>,\n api: {\n rest: {\n prefix: '/api',\n },\n } satisfies Partial<Core.Config.Api>,\n};\n\nexport const loadConfiguration = (opts: StrapiOptions) => {\n const { appDir, distDir, autoReload = false, serveAdminPanel = true } = opts;\n\n const pkgJSON = require(path.resolve(appDir, 'package.json'));\n\n const configDir = path.resolve(distDir || process.cwd(), 'config');\n\n const rootConfig = {\n launchedAt: Date.now(),\n autoReload,\n environment: process.env.NODE_ENV,\n uuid: _.get(pkgJSON, 'strapi.uuid'),\n installId: _.get(pkgJSON, 'strapi.installId'),\n packageJsonStrapi: _.omit(_.get(pkgJSON, 'strapi', {}), 'uuid'),\n info: {\n ...pkgJSON,\n strapi: strapiVersion,\n },\n admin: {\n serveAdminPanel,\n },\n };\n\n // See packages/core/core/src/domain/module/index.ts for plugin config loading\n const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later\n\n const envDir = path.resolve(configDir, 'env', process.env.NODE_ENV as string);\n const envConfig = loadConfigDir(envDir);\n\n const config = _.merge(rootConfig, defaultConfig, baseConfig, envConfig);\n\n const { serverUrl, adminUrl } = getConfigUrls(config);\n\n const serverAbsoluteUrl = getAbsoluteServerUrl(config);\n const adminAbsoluteUrl = getAbsoluteAdminUrl(config);\n\n const sameOrigin = new URL(adminAbsoluteUrl).origin === new URL(serverAbsoluteUrl).origin;\n\n const adminPath = sameOrigin\n ? adminUrl.replace(strings.getCommonPath(serverUrl, adminUrl), '')\n : new URL(adminUrl).pathname;\n\n _.set(config, 'server.url', serverUrl);\n _.set(config, 'server.absoluteUrl', serverAbsoluteUrl);\n _.set(config, 'admin.url', adminUrl);\n _.set(config, 'admin.path', adminPath);\n _.set(config, 'admin.absoluteUrl', adminAbsoluteUrl);\n _.set(config, 'dirs', getDirs(opts, config));\n\n return config;\n};\n"],"names":["dotenv","config","path","process","env","ENV_PATH","NODE_ENV","defaultServerConfig","host","HOST","os","hostname","port","Number","PORT","proxy","cron","enabled","admin","autoOpen","dirs","public","transfer","remote","logger","updates","startup","openapi","access","route","cache","maxAgeMs","filePath","defaultConfig","server","api","rest","prefix","loadConfiguration","opts","appDir","distDir","autoReload","serveAdminPanel","pkgJSON","require","resolve","configDir","cwd","rootConfig","launchedAt","Date","now","environment","uuid","_","get","installId","packageJsonStrapi","omit","info","strapi","strapiVersion","baseConfig","loadConfigDir","envDir","envConfig","merge","serverUrl","adminUrl","getConfigUrls","serverAbsoluteUrl","getAbsoluteServerUrl","adminAbsoluteUrl","getAbsoluteAdminUrl","sameOrigin","URL","origin","adminPath","replace","strings","getCommonPath","pathname","set","getDirs"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/configuration/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport { omit } from 'lodash/fp';\nimport dotenv from 'dotenv';\nimport type { Core } from '@strapi/types';\nimport { strings } from '@strapi/utils';\n\nimport { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } from './urls';\nimport loadConfigDir from './config-loader';\nimport { getDirs } from './get-dirs';\n\nimport type { StrapiOptions } from '../Strapi';\nimport { version as strapiVersion } from '../../package.json';\n\ndotenv.config({ path: process.env.ENV_PATH });\n\nprocess.env.NODE_ENV = process.env.NODE_ENV || 'development';\n\nconst defaultServerConfig = {\n host: process.env.HOST || os.hostname() || 'localhost',\n port: Number(process.env.PORT) || 1337,\n proxy: false,\n cron: { enabled: false },\n admin: { autoOpen: false },\n dirs: { public: './public' },\n transfer: {\n remote: {\n enabled: true,\n },\n },\n logger: {\n updates: {\n enabled: true,\n },\n startup: {\n enabled: true,\n },\n },\n openapi: {\n 'content-api': {\n access: 'disabled',\n route: {\n path: '/openapi.json',\n },\n cache: {\n enabled: true,\n maxAgeMs: 60_000,\n filePath: '.strapi/openapi/content-api.json',\n },\n },\n admin: {\n access: 'disabled',\n route: {\n path: '/openapi.json',\n },\n cache: {\n enabled: true,\n maxAgeMs: 60_000,\n filePath: '.strapi/openapi/admin.json',\n },\n },\n },\n} satisfies Partial<Core.Config.Server>;\n\nconst defaultConfig = {\n server: defaultServerConfig,\n admin: {} satisfies Partial<Core.Config.Admin>,\n api: {\n rest: {\n prefix: '/api',\n },\n } satisfies Partial<Core.Config.Api>,\n};\n\nexport const loadConfiguration = (opts: StrapiOptions) => {\n const { appDir, distDir, autoReload = false, serveAdminPanel = true } = opts;\n\n const pkgJSON = require(path.resolve(appDir, 'package.json'));\n\n const configDir = path.resolve(distDir || process.cwd(), 'config');\n\n const rootConfig = {\n launchedAt: Date.now(),\n autoReload,\n environment: process.env.NODE_ENV,\n uuid: _.get(pkgJSON, 'strapi.uuid'),\n installId: _.get(pkgJSON, 'strapi.installId'),\n packageJsonStrapi: _.omit(_.get(pkgJSON, 'strapi', {}), 'uuid'),\n info: {\n ...pkgJSON,\n strapi: strapiVersion,\n },\n admin: {\n serveAdminPanel,\n },\n };\n\n // See packages/core/core/src/domain/module/index.ts for plugin config loading\n const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later\n\n const envDir = path.resolve(configDir, 'env', process.env.NODE_ENV as string);\n const envConfig = loadConfigDir(envDir);\n\n const config = _.merge(rootConfig, defaultConfig, baseConfig, envConfig);\n\n const { serverUrl, adminUrl } = getConfigUrls(config);\n\n const serverAbsoluteUrl = getAbsoluteServerUrl(config);\n const adminAbsoluteUrl = getAbsoluteAdminUrl(config);\n\n const sameOrigin = new URL(adminAbsoluteUrl).origin === new URL(serverAbsoluteUrl).origin;\n\n const adminPath = sameOrigin\n ? adminUrl.replace(strings.getCommonPath(serverUrl, adminUrl), '')\n : new URL(adminUrl).pathname;\n\n _.set(config, 'server.url', serverUrl);\n _.set(config, 'server.absoluteUrl', serverAbsoluteUrl);\n _.set(config, 'admin.url', adminUrl);\n _.set(config, 'admin.path', adminPath);\n _.set(config, 'admin.absoluteUrl', adminAbsoluteUrl);\n _.set(config, 'dirs', getDirs(opts, config));\n\n return config;\n};\n"],"names":["dotenv","config","path","process","env","ENV_PATH","NODE_ENV","defaultServerConfig","host","HOST","os","hostname","port","Number","PORT","proxy","cron","enabled","admin","autoOpen","dirs","public","transfer","remote","logger","updates","startup","openapi","access","route","cache","maxAgeMs","filePath","defaultConfig","server","api","rest","prefix","loadConfiguration","opts","appDir","distDir","autoReload","serveAdminPanel","pkgJSON","require","resolve","configDir","cwd","rootConfig","launchedAt","Date","now","environment","uuid","_","get","installId","packageJsonStrapi","omit","info","strapi","strapiVersion","baseConfig","loadConfigDir","envDir","envConfig","merge","serverUrl","adminUrl","getConfigUrls","serverAbsoluteUrl","getAbsoluteServerUrl","adminAbsoluteUrl","getAbsoluteAdminUrl","sameOrigin","URL","origin","adminPath","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vB,kBAAAA,CAAE4B,GAAG,CAAClF,MAAAA,EAAQ,mBAAA,EAAqBwE,gBAAAA,CAAAA;AACnClB,IAAAA,kBAAAA,CAAE4B,GAAG,CAAClF,MAAAA,EAAQ,MAAA,EAAQmF,gBAAQ7C,IAAAA,EAAMtC,MAAAA,CAAAA,CAAAA;IAEpC,OAAOA,MAAAA;AACT;;;;"}
|
|
@@ -4,18 +4,22 @@ var _ = require('lodash');
|
|
|
4
4
|
var strapiUtils = require('@strapi/utils');
|
|
5
5
|
var node_net = require('node:net');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
10
|
+
|
|
7
11
|
const getConfigUrls = (config, forAdminBuild = false)=>{
|
|
8
12
|
const serverConfig = config.server;
|
|
9
13
|
const adminConfig = config.admin;
|
|
10
14
|
// Defines serverUrl value
|
|
11
|
-
let serverUrl =
|
|
12
|
-
serverUrl =
|
|
15
|
+
let serverUrl = ___default.default.get(serverConfig, 'url', '');
|
|
16
|
+
serverUrl = ___default.default.trim(serverUrl, '/ ');
|
|
13
17
|
if (typeof serverUrl !== 'string') {
|
|
14
18
|
throw new Error('Invalid server url config. Make sure the url is a string.');
|
|
15
19
|
}
|
|
16
20
|
if (serverUrl.startsWith('http')) {
|
|
17
21
|
try {
|
|
18
|
-
serverUrl =
|
|
22
|
+
serverUrl = ___default.default.trim(new URL(serverConfig.url).toString(), '/');
|
|
19
23
|
} catch (e) {
|
|
20
24
|
throw new Error('Invalid server url config. Make sure the url defined in server.js is valid.');
|
|
21
25
|
}
|
|
@@ -23,14 +27,14 @@ const getConfigUrls = (config, forAdminBuild = false)=>{
|
|
|
23
27
|
serverUrl = `/${serverUrl}`;
|
|
24
28
|
}
|
|
25
29
|
// Defines adminUrl value
|
|
26
|
-
let adminUrl =
|
|
27
|
-
adminUrl =
|
|
30
|
+
let adminUrl = ___default.default.get(adminConfig, 'url', '/admin');
|
|
31
|
+
adminUrl = ___default.default.trim(adminUrl, '/ ');
|
|
28
32
|
if (typeof adminUrl !== 'string') {
|
|
29
33
|
throw new Error('Invalid admin url config. Make sure the url is a non-empty string.');
|
|
30
34
|
}
|
|
31
35
|
if (adminUrl.startsWith('http')) {
|
|
32
36
|
try {
|
|
33
|
-
adminUrl =
|
|
37
|
+
adminUrl = ___default.default.trim(new URL(adminUrl).toString(), '/');
|
|
34
38
|
} catch (e) {
|
|
35
39
|
throw new Error('Invalid admin url config. Make sure the url defined in server.js is valid.');
|
|
36
40
|
}
|
|
@@ -41,7 +45,7 @@ const getConfigUrls = (config, forAdminBuild = false)=>{
|
|
|
41
45
|
let adminPath = adminUrl;
|
|
42
46
|
if (serverUrl.startsWith('http') && adminUrl.startsWith('http') && new URL(adminUrl).origin === new URL(serverUrl).origin && !forAdminBuild) {
|
|
43
47
|
adminPath = adminUrl.replace(strapiUtils.strings.getCommonPath(serverUrl, adminUrl), '');
|
|
44
|
-
adminPath = `/${
|
|
48
|
+
adminPath = `/${___default.default.trim(adminPath, '/')}`;
|
|
45
49
|
} else if (adminUrl.startsWith('http')) {
|
|
46
50
|
adminPath = new URL(adminUrl).pathname;
|
|
47
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.js","sources":["../../src/configuration/urls.ts"],"sourcesContent":["import _ from 'lodash';\nimport { strings } from '@strapi/utils';\nimport { isIP } from 'node:net';\n\ninterface ServerConfig {\n url: string;\n host: string;\n port: number | string;\n}\n\nexport const getConfigUrls = (config: Record<string, unknown>, forAdminBuild = false) => {\n const serverConfig = config.server as ServerConfig;\n const adminConfig = config.admin;\n\n // Defines serverUrl value\n let serverUrl = _.get(serverConfig, 'url', '');\n serverUrl = _.trim(serverUrl, '/ ');\n if (typeof serverUrl !== 'string') {\n throw new Error('Invalid server url config. Make sure the url is a string.');\n }\n\n if (serverUrl.startsWith('http')) {\n try {\n serverUrl = _.trim(new URL(serverConfig.url).toString(), '/');\n } catch (e) {\n throw new Error(\n 'Invalid server url config. Make sure the url defined in server.js is valid.'\n );\n }\n } else if (serverUrl !== '') {\n serverUrl = `/${serverUrl}`;\n }\n\n // Defines adminUrl value\n let adminUrl = _.get(adminConfig, 'url', '/admin');\n adminUrl = _.trim(adminUrl, '/ ');\n if (typeof adminUrl !== 'string') {\n throw new Error('Invalid admin url config. Make sure the url is a non-empty string.');\n }\n if (adminUrl.startsWith('http')) {\n try {\n adminUrl = _.trim(new URL(adminUrl).toString(), '/');\n } catch (e) {\n throw new Error('Invalid admin url config. Make sure the url defined in server.js is valid.');\n }\n } else {\n adminUrl = `${serverUrl}/${adminUrl}`;\n }\n\n // Defines adminPath value\n let adminPath = adminUrl;\n if (\n serverUrl.startsWith('http') &&\n adminUrl.startsWith('http') &&\n new URL(adminUrl).origin === new URL(serverUrl).origin &&\n !forAdminBuild\n ) {\n adminPath = adminUrl.replace(strings.getCommonPath(serverUrl, adminUrl), '');\n adminPath = `/${_.trim(adminPath, '/')}`;\n } else if (adminUrl.startsWith('http')) {\n adminPath = new URL(adminUrl).pathname;\n }\n\n return {\n serverUrl,\n adminUrl,\n adminPath,\n };\n};\n\nconst getAbsoluteUrl =\n (adminOrServer: 'admin' | 'server') =>\n (config: Record<string, unknown>, forAdminBuild = false) => {\n const { serverUrl, adminUrl } = getConfigUrls(config, forAdminBuild);\n const url = adminOrServer === 'server' ? serverUrl : adminUrl;\n\n if (url.startsWith('http')) {\n return url;\n }\n\n const serverConfig = config.server as ServerConfig;\n\n const isLocalhost =\n config.environment === 'development' &&\n ['127.0.0.1', '0.0.0.0', '::1', '::'].includes(serverConfig.host);\n\n if (isLocalhost) {\n return `http://localhost:${serverConfig.port}${url}`;\n }\n\n if (isIP(serverConfig.host) === 6) {\n return `http://[${serverConfig.host}]:${serverConfig.port}${url}`;\n }\n\n return `http://${serverConfig.host}:${serverConfig.port}${url}`;\n };\n\nexport const getAbsoluteAdminUrl = getAbsoluteUrl('admin');\nexport const getAbsoluteServerUrl = getAbsoluteUrl('server');\n"],"names":["getConfigUrls","config","forAdminBuild","serverConfig","server","adminConfig","admin","serverUrl","_","get","trim","Error","startsWith","URL","url","toString","e","adminUrl","adminPath","origin","replace","strings","getCommonPath","pathname","getAbsoluteUrl","adminOrServer","isLocalhost","environment","includes","host","port","isIP","getAbsoluteAdminUrl","getAbsoluteServerUrl"],"mappings":"
|
|
1
|
+
{"version":3,"file":"urls.js","sources":["../../src/configuration/urls.ts"],"sourcesContent":["import _ from 'lodash';\nimport { strings } from '@strapi/utils';\nimport { isIP } from 'node:net';\n\ninterface ServerConfig {\n url: string;\n host: string;\n port: number | string;\n}\n\nexport const getConfigUrls = (config: Record<string, unknown>, forAdminBuild = false) => {\n const serverConfig = config.server as ServerConfig;\n const adminConfig = config.admin;\n\n // Defines serverUrl value\n let serverUrl = _.get(serverConfig, 'url', '');\n serverUrl = _.trim(serverUrl, '/ ');\n if (typeof serverUrl !== 'string') {\n throw new Error('Invalid server url config. Make sure the url is a string.');\n }\n\n if (serverUrl.startsWith('http')) {\n try {\n serverUrl = _.trim(new URL(serverConfig.url).toString(), '/');\n } catch (e) {\n throw new Error(\n 'Invalid server url config. Make sure the url defined in server.js is valid.'\n );\n }\n } else if (serverUrl !== '') {\n serverUrl = `/${serverUrl}`;\n }\n\n // Defines adminUrl value\n let adminUrl = _.get(adminConfig, 'url', '/admin');\n adminUrl = _.trim(adminUrl, '/ ');\n if (typeof adminUrl !== 'string') {\n throw new Error('Invalid admin url config. Make sure the url is a non-empty string.');\n }\n if (adminUrl.startsWith('http')) {\n try {\n adminUrl = _.trim(new URL(adminUrl).toString(), '/');\n } catch (e) {\n throw new Error('Invalid admin url config. Make sure the url defined in server.js is valid.');\n }\n } else {\n adminUrl = `${serverUrl}/${adminUrl}`;\n }\n\n // Defines adminPath value\n let adminPath = adminUrl;\n if (\n serverUrl.startsWith('http') &&\n adminUrl.startsWith('http') &&\n new URL(adminUrl).origin === new URL(serverUrl).origin &&\n !forAdminBuild\n ) {\n adminPath = adminUrl.replace(strings.getCommonPath(serverUrl, adminUrl), '');\n adminPath = `/${_.trim(adminPath, '/')}`;\n } else if (adminUrl.startsWith('http')) {\n adminPath = new URL(adminUrl).pathname;\n }\n\n return {\n serverUrl,\n adminUrl,\n adminPath,\n };\n};\n\nconst getAbsoluteUrl =\n (adminOrServer: 'admin' | 'server') =>\n (config: Record<string, unknown>, forAdminBuild = false) => {\n const { serverUrl, adminUrl } = getConfigUrls(config, forAdminBuild);\n const url = adminOrServer === 'server' ? serverUrl : adminUrl;\n\n if (url.startsWith('http')) {\n return url;\n }\n\n const serverConfig = config.server as ServerConfig;\n\n const isLocalhost =\n config.environment === 'development' &&\n ['127.0.0.1', '0.0.0.0', '::1', '::'].includes(serverConfig.host);\n\n if (isLocalhost) {\n return `http://localhost:${serverConfig.port}${url}`;\n }\n\n if (isIP(serverConfig.host) === 6) {\n return `http://[${serverConfig.host}]:${serverConfig.port}${url}`;\n }\n\n return `http://${serverConfig.host}:${serverConfig.port}${url}`;\n };\n\nexport const getAbsoluteAdminUrl = getAbsoluteUrl('admin');\nexport const getAbsoluteServerUrl = getAbsoluteUrl('server');\n"],"names":["getConfigUrls","config","forAdminBuild","serverConfig","server","adminConfig","admin","serverUrl","_","get","trim","Error","startsWith","URL","url","toString","e","adminUrl","adminPath","origin","replace","strings","getCommonPath","pathname","getAbsoluteUrl","adminOrServer","isLocalhost","environment","includes","host","port","isIP","getAbsoluteAdminUrl","getAbsoluteServerUrl"],"mappings":";;;;;;;;;;AAUO,MAAMA,aAAAA,GAAgB,CAACC,MAAAA,EAAiCC,gBAAgB,KAAK,GAAA;IAClF,MAAMC,YAAAA,GAAeF,OAAOG,MAAM;IAClC,MAAMC,WAAAA,GAAcJ,OAAOK,KAAK;;AAGhC,IAAA,IAAIC,SAAAA,GAAYC,kBAAAA,CAAEC,GAAG,CAACN,cAAc,KAAA,EAAO,EAAA,CAAA;IAC3CI,SAAAA,GAAYC,kBAAAA,CAAEE,IAA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,QAAQ,CAACzB,YAAAA,CAAa0B,IAAI,CAAA;AAElE,QAAA,IAAIH,WAAAA,EAAa;AACf,YAAA,OAAO,CAAC,iBAAiB,EAAEvB,YAAAA,CAAa2B,IAAI,GAAGhB,GAAAA,CAAAA,CAAK;AACtD,QAAA;AAEA,QAAA,IAAIiB,aAAAA,CAAK5B,YAAAA,CAAa0B,IAAI,CAAA,KAAM,CAAA,EAAG;YACjC,OAAO,CAAC,QAAQ,EAAE1B,YAAAA,CAAa0B,IAAI,CAAC,EAAE,EAAE1B,YAAAA,CAAa2B,IAAI,CAAA,EAAGhB,GAAAA,CAAAA,CAAK;AACnE,QAAA;QAEA,OAAO,CAAC,OAAO,EAAEX,YAAAA,CAAa0B,IAAI,CAAC,CAAC,EAAE1B,YAAAA,CAAa2B,IAAI,CAAA,EAAGhB,GAAAA,CAAAA,CAAK;AACjE,IAAA,CAAA;AAEK,MAAMkB,mBAAAA,GAAsBR,cAAAA,CAAe,OAAA;AAC3C,MAAMS,oBAAAA,GAAuBT,cAAAA,CAAe,QAAA;;;;;;"}
|
|
@@ -4,7 +4,8 @@ var strapiUtils = require('@strapi/utils');
|
|
|
4
4
|
var z = require('zod/v4');
|
|
5
5
|
var contentType = require('./validation/content-type.js');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
8
9
|
var n = Object.create(null);
|
|
9
10
|
if (e) {
|
|
10
11
|
Object.keys(e).forEach(function (k) {
|
|
@@ -21,7 +22,7 @@ function _interopNamespaceDefault(e) {
|
|
|
21
22
|
return Object.freeze(n);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
var z__namespace = /*#__PURE__*/
|
|
25
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
25
26
|
|
|
26
27
|
const createRoutes = ({ strapi: strapi1, contentType })=>{
|
|
27
28
|
if (strapiUtils.contentTypes.isSingleType(contentType)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/core-api/routes/index.ts"],"sourcesContent":["import type { Core, Schema } from '@strapi/types';\n\nimport { contentTypes, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport * as z from 'zod/v4';\nimport type { QueryParam } from './validation/content-type';\n\nimport { CoreContentTypeRouteValidator } from './validation';\n\nexport const createRoutes = ({\n strapi,\n contentType,\n}: {\n strapi: Core.Strapi;\n contentType: Schema.ContentType;\n}) => {\n if (contentTypeUtils.isSingleType(contentType)) {\n return getSingleTypeRoutes(contentType, strapi);\n }\n\n return getCollectionTypeRoutes(contentType, strapi);\n};\n\nconst getSingleTypeRoutes = (\n schema: Schema.ContentType,\n strapi: Core.Strapi\n): Record<string, Partial<Core.Route>> => {\n const { uid, info } = schema;\n\n const validator = new CoreContentTypeRouteValidator(strapi, uid);\n const conditionalQueryParams = getConditionalQueryParams(schema);\n\n return {\n find: {\n method: 'GET',\n path: `/${info.singularName}`,\n handler: `${uid}.find`,\n request: {\n query: validator.queryParams(['fields', 'populate', 'filters', ...conditionalQueryParams]),\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n update: {\n method: 'PUT',\n path: `/${info.singularName}`,\n handler: `${uid}.update`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n body: { 'application/json': validator.partialBody },\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n delete: {\n method: 'DELETE',\n path: `/${info.singularName}`,\n handler: `${uid}.delete`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n };\n};\n\nconst getCollectionTypeRoutes = (\n schema: Schema.ContentType,\n strapi: Core.Strapi\n): Record<string, Partial<Core.Route>> => {\n const { uid, info } = schema;\n\n const validator = new CoreContentTypeRouteValidator(strapi, uid);\n const conditionalQueryParams = getConditionalQueryParams(schema);\n\n return {\n find: {\n method: 'GET',\n path: `/${info.pluralName}`,\n handler: `${uid}.find`,\n request: {\n query: validator.queryParams([\n 'fields',\n 'filters',\n '_q',\n 'pagination',\n 'sort',\n 'populate',\n ...conditionalQueryParams,\n ]),\n },\n response: z.object({ data: validator.documents }),\n config: {},\n },\n findOne: {\n method: 'GET',\n path: `/${info.pluralName}/:id`,\n handler: `${uid}.findOne`,\n request: {\n params: { id: validator.documentID },\n query: validator.queryParams([\n 'fields',\n 'populate',\n 'filters',\n 'sort',\n ...conditionalQueryParams,\n ]),\n },\n response: z.object({ data: validator.document }),\n },\n create: {\n method: 'POST',\n path: `/${info.pluralName}`,\n handler: `${uid}.create`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n body: { 'application/json': validator.body },\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n update: {\n method: 'PUT',\n path: `/${info.pluralName}/:id`,\n handler: `${uid}.update`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n params: { id: validator.documentID },\n body: { 'application/json': validator.partialBody },\n },\n response: z.object({ data: validator.document }),\n },\n delete: {\n method: 'DELETE',\n path: `/${info.pluralName}/:id`,\n handler: `${uid}.delete`,\n request: {\n query: validator.queryParams(['fields', 'populate', 'filters', ...conditionalQueryParams]),\n params: { id: validator.documentID },\n },\n response: z.object({ data: validator.document }),\n },\n };\n};\n\n/**\n * Query params that are conditionally part of this route's contract (and OpenAPI spec)\n * based on the content type: e.g. locale only for localized types, status only for draft & publish.\n *\n * This is separate from the runtime allowlist used when api.rest.strictParams is on\n * (ALLOWED_QUERY_PARAM_KEYS + registerQueryParam in @strapi/utils). That allowlist is global\n * (locale and status are always allowed); validate/sanitize then pass them through and the\n * document service or i18n layer ignores them when not applicable.\n *\n * So the two can differ: a non-localized route will not declare \"locale\" here (OpenAPI says\n * no locale param), but the runtime allowlist still allows the key and downstream ignores it.\n * That is intentional: this drives the route contract/docs; the allowlist drives enforcement.\n */\nconst getConditionalQueryParams = (schema: Schema.ContentType) => {\n const isLocalized = strapi.plugin('i18n').service('content-types').isLocalizedContentType(schema);\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(schema);\n\n return [\n ...(isLocalized ? ['locale'] : []),\n ...(hasDraftAndPublish\n ? [\n 'status',\n 'publicationFilter',\n // Deprecated: replaced by `publicationFilter`; kept for OpenAPI/clients still using the boolean.\n 'hasPublishedVersion',\n ]\n : []),\n ] as QueryParam[];\n};\n"],"names":["createRoutes","strapi","contentType","contentTypeUtils","isSingleType","getSingleTypeRoutes","getCollectionTypeRoutes","schema","uid","info","validator","CoreContentTypeRouteValidator","conditionalQueryParams","getConditionalQueryParams","find","method","path","singularName","handler","request","query","queryParams","response","z","object","data","document","config","update","body","partialBody","delete","pluralName","documents","findOne","params","id","documentID","create","isLocalized","plugin","service","isLocalizedContentType","hasDraftAndPublish","contentTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAQO,MAAMA,eAAe,CAAC,EAC3BC,QAAAA,OAAM,EACNC,WAAW,EAIZ,GAAA;IACC,IAAIC,wBAAAA,CAAiBC,YAAY,CAACF,WAAAA,CAAAA,EAAc;AAC9C,QAAA,OAAOG,oBAAoBH,WAAAA,EAAaD,OAAAA,CAAAA;AAC1C,IAAA;AAEA,IAAA,OAAOK,wBAAwBJ,WAAAA,EAAaD,OAAAA,CAAAA;AAC9C;AAEA,MAAMI,mBAAAA,GAAsB,CAC1BE,MAAAA,EACAN,OAAAA,GAAAA;AAEA,IAAA,MAAM,EAAEO,GAAG,EAAEC,IAAI,EAAE,GAAGF,MAAAA;IAEtB,MAAMG,SAAAA,GAAY,IAAIC,yCAAAA,CAA8BV,OAAAA,EAAQO,GAAAA,CAAAA;AAC5D,IAAA,MAAMI,yBAAyBC,yBAAAA,CAA0BN,MAAAA,CAAAA;IAEzD,OAAO;QACLO,IAAAA,EAAM;YACJC,MAAAA,EAAQ,KAAA;AACRC,YAAAA,IAAAA,EAAM,CAAC,CAAC,EAAEP,IAAAA,CAAKQ,YAAY,CAAA,CAAE;YAC7BC,OAAAA,E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,QAAA;AACA,YAAA,mBAAA;;AAEA,YAAA;AACD,SAAA,GACD;AACL,KAAA;AACH,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/core-api/routes/index.ts"],"sourcesContent":["import type { Core, Schema } from '@strapi/types';\n\nimport { contentTypes, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport * as z from 'zod/v4';\nimport type { QueryParam } from './validation/content-type';\n\nimport { CoreContentTypeRouteValidator } from './validation';\n\nexport const createRoutes = ({\n strapi,\n contentType,\n}: {\n strapi: Core.Strapi;\n contentType: Schema.ContentType;\n}) => {\n if (contentTypeUtils.isSingleType(contentType)) {\n return getSingleTypeRoutes(contentType, strapi);\n }\n\n return getCollectionTypeRoutes(contentType, strapi);\n};\n\nconst getSingleTypeRoutes = (\n schema: Schema.ContentType,\n strapi: Core.Strapi\n): Record<string, Partial<Core.Route>> => {\n const { uid, info } = schema;\n\n const validator = new CoreContentTypeRouteValidator(strapi, uid);\n const conditionalQueryParams = getConditionalQueryParams(schema);\n\n return {\n find: {\n method: 'GET',\n path: `/${info.singularName}`,\n handler: `${uid}.find`,\n request: {\n query: validator.queryParams(['fields', 'populate', 'filters', ...conditionalQueryParams]),\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n update: {\n method: 'PUT',\n path: `/${info.singularName}`,\n handler: `${uid}.update`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n body: { 'application/json': validator.partialBody },\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n delete: {\n method: 'DELETE',\n path: `/${info.singularName}`,\n handler: `${uid}.delete`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n };\n};\n\nconst getCollectionTypeRoutes = (\n schema: Schema.ContentType,\n strapi: Core.Strapi\n): Record<string, Partial<Core.Route>> => {\n const { uid, info } = schema;\n\n const validator = new CoreContentTypeRouteValidator(strapi, uid);\n const conditionalQueryParams = getConditionalQueryParams(schema);\n\n return {\n find: {\n method: 'GET',\n path: `/${info.pluralName}`,\n handler: `${uid}.find`,\n request: {\n query: validator.queryParams([\n 'fields',\n 'filters',\n '_q',\n 'pagination',\n 'sort',\n 'populate',\n ...conditionalQueryParams,\n ]),\n },\n response: z.object({ data: validator.documents }),\n config: {},\n },\n findOne: {\n method: 'GET',\n path: `/${info.pluralName}/:id`,\n handler: `${uid}.findOne`,\n request: {\n params: { id: validator.documentID },\n query: validator.queryParams([\n 'fields',\n 'populate',\n 'filters',\n 'sort',\n ...conditionalQueryParams,\n ]),\n },\n response: z.object({ data: validator.document }),\n },\n create: {\n method: 'POST',\n path: `/${info.pluralName}`,\n handler: `${uid}.create`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n body: { 'application/json': validator.body },\n },\n response: z.object({ data: validator.document }),\n config: {},\n },\n update: {\n method: 'PUT',\n path: `/${info.pluralName}/:id`,\n handler: `${uid}.update`,\n request: {\n query: validator.queryParams(['fields', 'populate', ...conditionalQueryParams]),\n params: { id: validator.documentID },\n body: { 'application/json': validator.partialBody },\n },\n response: z.object({ data: validator.document }),\n },\n delete: {\n method: 'DELETE',\n path: `/${info.pluralName}/:id`,\n handler: `${uid}.delete`,\n request: {\n query: validator.queryParams(['fields', 'populate', 'filters', ...conditionalQueryParams]),\n params: { id: validator.documentID },\n },\n response: z.object({ data: validator.document }),\n },\n };\n};\n\n/**\n * Query params that are conditionally part of this route's contract (and OpenAPI spec)\n * based on the content type: e.g. locale only for localized types, status only for draft & publish.\n *\n * This is separate from the runtime allowlist used when api.rest.strictParams is on\n * (ALLOWED_QUERY_PARAM_KEYS + registerQueryParam in @strapi/utils). That allowlist is global\n * (locale and status are always allowed); validate/sanitize then pass them through and the\n * document service or i18n layer ignores them when not applicable.\n *\n * So the two can differ: a non-localized route will not declare \"locale\" here (OpenAPI says\n * no locale param), but the runtime allowlist still allows the key and downstream ignores it.\n * That is intentional: this drives the route contract/docs; the allowlist drives enforcement.\n */\nconst getConditionalQueryParams = (schema: Schema.ContentType) => {\n const isLocalized = strapi.plugin('i18n').service('content-types').isLocalizedContentType(schema);\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(schema);\n\n return [\n ...(isLocalized ? ['locale'] : []),\n ...(hasDraftAndPublish\n ? [\n 'status',\n 'publicationFilter',\n // Deprecated: replaced by `publicationFilter`; kept for OpenAPI/clients still using the boolean.\n 'hasPublishedVersion',\n ]\n : []),\n ] as QueryParam[];\n};\n"],"names":["createRoutes","strapi","contentType","contentTypeUtils","isSingleType","getSingleTypeRoutes","getCollectionTypeRoutes","schema","uid","info","validator","CoreContentTypeRouteValidator","conditionalQueryParams","getConditionalQueryParams","find","method","path","singularName","handler","request","query","queryParams","response","z","object","data","document","config","update","body","partialBody","delete","pluralName","documents","findOne","params","id","documentID","create","isLocalized","plugin","service","isLocalizedContentType","hasDraftAndPublish","contentTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQO,MAAMA,eAAe,CAAC,EAC3BC,QAAAA,OAAM,EACNC,WAAW,EAIZ,GAAA;IACC,IAAIC,wBAAAA,CAAiBC,YAAY,CAACF,WAAAA,CAAAA,EAAc;AAC9C,QAAA,OAAOG,oBAAoBH,WAAAA,EAAaD,OAAAA,CAAAA;AAC1C,IAAA;AAEA,IAAA,OAAOK,wBAAwBJ,WAAAA,EAAaD,OAAAA,CAAAA;AAC9C;AAEA,MAAMI,mBAAAA,GAAsB,CAC1BE,MAAAA,EACAN,OAAAA,GAAAA;AAEA,IAAA,MAAM,EAAEO,GAAG,EAAEC,IAAI,EAAE,GAAGF,MAAAA;IAEtB,MAAMG,SAAAA,GAAY,IAAIC,yCAAAA,CAA8BV,OAAAA,EAAQO,GAAAA,CAAAA;AAC5D,IAAA,MAAMI,yBAAyBC,yBAAAA,CAA0BN,MAAAA,CAAAA;IAEzD,OAAO;QACLO,IAAAA,EAAM;YACJC,MAAAA,EAAQ,KAAA;AACRC,YAAAA,IAA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AAAA,GAAc;AAAC,YAAA;AAAS,SAAA,GAAG,EAAE;WAC7BI,kBAAAA,GACA;AACE,YAAA,QAAA;AACA,YAAA,mBAAA;;AAEA,YAAA;AACD,SAAA,GACD;AACL,KAAA;AACH,CAAA;;;;"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
var strapiUtils = require('@strapi/utils');
|
|
4
4
|
var z = require('zod/v4');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
7
8
|
var n = Object.create(null);
|
|
8
9
|
if (e) {
|
|
9
10
|
Object.keys(e).forEach(function (k) {
|
|
@@ -20,7 +21,7 @@ function _interopNamespaceDefault(e) {
|
|
|
20
21
|
return Object.freeze(n);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
var z__namespace = /*#__PURE__*/
|
|
24
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* AbstractCoreRouteValidator provides the foundation for validating and managing core routes within a Strapi context for a specific model.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sources":["../../../../src/core-api/routes/validation/common.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\n\nimport { contentTypes, AbstractRouteValidator } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n/**\n * AbstractCoreRouteValidator provides the foundation for validating and managing core routes within a Strapi context for a specific model.\n *\n * This abstract class extends the base AbstractRouteValidator from utils to add schema-aware validation\n * logic for scalar and populatable fields defined in a model schema.\n *\n * It uses runtime information about Strapi models to derive and expose schema validations.\n *\n * @template {UID.Schema} T Representing the schema identifier to be validated.\n */\nexport abstract class AbstractCoreRouteValidator<\n T extends UID.Schema,\n> extends AbstractRouteValidator {\n /**\n * The `_strapi` variable serves as a reference to the core Strapi instance.\n * It is used for interacting with the loaded model.\n */\n protected readonly _strapi: Core.Strapi;\n\n /**\n * A unique identifier used to represent a model within Strapi.\n *\n * The type of the identifier is generic to allow flexibility and ensure type safety\n * when working with either content-types or components.\n */\n protected readonly _uid: T;\n\n /**\n * Protected constructor for initializing the class with the provided Strapi instance and unique identifier (UID).\n *\n * @param strapi The Strapi instance to be used.\n * @param uid The unique identifier for the instance.\n */\n public constructor(strapi: Core.Strapi, uid: T) {\n super();\n this._strapi = strapi;\n this._uid = uid;\n }\n\n /**\n * Retrieves an enum schema constructed from the keys of the scalar fields.\n *\n * @return A Zod enum containing the keys from the scalar fields.\n */\n public get scalarFieldsEnum() {\n return z.enum(Object.keys(this._scalarFields) as [string]);\n }\n\n /**\n * Retrieves an enum schema constructed from the keys of fields that can be populated (relations, components, files, etc.)\n *\n * @return A ZodEnum object containing the list of populatable field keys.\n */\n public get populatableFieldsEnum() {\n return z.enum(Object.keys(this._populatableFields) as [string]);\n }\n\n /**\n * Retrieves an array representation of the scalar fields.\n *\n * @return An array containing the scalar fields as defined by {@link scalarFieldsEnum}.\n */\n public get scalarFieldsArray() {\n return z.array(this.scalarFieldsEnum);\n }\n\n /**\n * Retrieves an array of populatable fields.\n *\n * @return A Zod array schema representing the available populatable fields as defined by {@link populatableFieldsEnum}.\n */\n public get populatableFieldsArray() {\n return z.array(this.populatableFieldsEnum);\n }\n\n /**\n * Retrieves the schema associated with the current model.\n *\n * The schema represents the structural definition of the model,\n * as retrieved from the Strapi model associated with the given UID.\n *\n * @return The schema of the model retrieved from Strapi.\n */\n protected get _schema() {\n return this._strapi.getModel(this._uid);\n }\n\n /**\n * Retrieves scalar fields from the object's schema attributes.\n *\n * Filters the schema attributes to include only those that are scalar and not private.\n *\n * @return An object composed of scalar fields from the schema attributes.\n */\n protected get _scalarFields() {\n const attributes = Object.entries(this._schema.attributes);\n\n const scalarEntries = attributes\n .filter(([, attribute]) => contentTypes.isScalarAttribute(attribute))\n .filter(([attributeName]) => !contentTypes.isPrivateAttribute(this._schema, attributeName));\n\n return Object.fromEntries(scalarEntries);\n }\n\n /**\n * Retrieves the populatable fields from the schema attributes.\n *\n * Filters the schema attributes to include only those that are populatable and not private.\n *\n * @return An object containing the populatable fields derived from the schema attributes.\n */\n protected get _populatableFields() {\n const attributes = Object.entries(this._schema.attributes);\n\n const populatableEntries = attributes\n .filter(([, attribute]) => !contentTypes.isScalarAttribute(attribute))\n .filter(([attributeName]) => !contentTypes.isPrivateAttribute(this._schema, attributeName));\n\n return Object.fromEntries(populatableEntries);\n }\n\n /**\n * Creates a Zod schema as a record with scalar fields as keys and the specified type as values.\n *\n * @param type - The Zod type to use for the record's values.\n * @return A Zod record schema with scalar fields as keys and the specified type as values.\n */\n public fieldRecord(type: z.ZodTypeAny) {\n return z.record(this.scalarFieldsEnum, type);\n }\n}\n"],"names":["AbstractCoreRouteValidator","AbstractRouteValidator","scalarFieldsEnum","z","enum","Object","keys","_scalarFields","populatableFieldsEnum","_populatableFields","scalarFieldsArray","array","populatableFieldsArray","_schema","_strapi","getModel","_uid","attributes","entries","scalarEntries","filter","attribute","contentTypes","isScalarAttribute","attributeName","isPrivateAttribute","fromEntries","populatableEntries","fieldRecord","type","record","strapi","uid"],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.js","sources":["../../../../src/core-api/routes/validation/common.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\n\nimport { contentTypes, AbstractRouteValidator } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n/**\n * AbstractCoreRouteValidator provides the foundation for validating and managing core routes within a Strapi context for a specific model.\n *\n * This abstract class extends the base AbstractRouteValidator from utils to add schema-aware validation\n * logic for scalar and populatable fields defined in a model schema.\n *\n * It uses runtime information about Strapi models to derive and expose schema validations.\n *\n * @template {UID.Schema} T Representing the schema identifier to be validated.\n */\nexport abstract class AbstractCoreRouteValidator<\n T extends UID.Schema,\n> extends AbstractRouteValidator {\n /**\n * The `_strapi` variable serves as a reference to the core Strapi instance.\n * It is used for interacting with the loaded model.\n */\n protected readonly _strapi: Core.Strapi;\n\n /**\n * A unique identifier used to represent a model within Strapi.\n *\n * The type of the identifier is generic to allow flexibility and ensure type safety\n * when working with either content-types or components.\n */\n protected readonly _uid: T;\n\n /**\n * Protected constructor for initializing the class with the provided Strapi instance and unique identifier (UID).\n *\n * @param strapi The Strapi instance to be used.\n * @param uid The unique identifier for the instance.\n */\n public constructor(strapi: Core.Strapi, uid: T) {\n super();\n this._strapi = strapi;\n this._uid = uid;\n }\n\n /**\n * Retrieves an enum schema constructed from the keys of the scalar fields.\n *\n * @return A Zod enum containing the keys from the scalar fields.\n */\n public get scalarFieldsEnum() {\n return z.enum(Object.keys(this._scalarFields) as [string]);\n }\n\n /**\n * Retrieves an enum schema constructed from the keys of fields that can be populated (relations, components, files, etc.)\n *\n * @return A ZodEnum object containing the list of populatable field keys.\n */\n public get populatableFieldsEnum() {\n return z.enum(Object.keys(this._populatableFields) as [string]);\n }\n\n /**\n * Retrieves an array representation of the scalar fields.\n *\n * @return An array containing the scalar fields as defined by {@link scalarFieldsEnum}.\n */\n public get scalarFieldsArray() {\n return z.array(this.scalarFieldsEnum);\n }\n\n /**\n * Retrieves an array of populatable fields.\n *\n * @return A Zod array schema representing the available populatable fields as defined by {@link populatableFieldsEnum}.\n */\n public get populatableFieldsArray() {\n return z.array(this.populatableFieldsEnum);\n }\n\n /**\n * Retrieves the schema associated with the current model.\n *\n * The schema represents the structural definition of the model,\n * as retrieved from the Strapi model associated with the given UID.\n *\n * @return The schema of the model retrieved from Strapi.\n */\n protected get _schema() {\n return this._strapi.getModel(this._uid);\n }\n\n /**\n * Retrieves scalar fields from the object's schema attributes.\n *\n * Filters the schema attributes to include only those that are scalar and not private.\n *\n * @return An object composed of scalar fields from the schema attributes.\n */\n protected get _scalarFields() {\n const attributes = Object.entries(this._schema.attributes);\n\n const scalarEntries = attributes\n .filter(([, attribute]) => contentTypes.isScalarAttribute(attribute))\n .filter(([attributeName]) => !contentTypes.isPrivateAttribute(this._schema, attributeName));\n\n return Object.fromEntries(scalarEntries);\n }\n\n /**\n * Retrieves the populatable fields from the schema attributes.\n *\n * Filters the schema attributes to include only those that are populatable and not private.\n *\n * @return An object containing the populatable fields derived from the schema attributes.\n */\n protected get _populatableFields() {\n const attributes = Object.entries(this._schema.attributes);\n\n const populatableEntries = attributes\n .filter(([, attribute]) => !contentTypes.isScalarAttribute(attribute))\n .filter(([attributeName]) => !contentTypes.isPrivateAttribute(this._schema, attributeName));\n\n return Object.fromEntries(populatableEntries);\n }\n\n /**\n * Creates a Zod schema as a record with scalar fields as keys and the specified type as values.\n *\n * @param type - The Zod type to use for the record's values.\n * @return A Zod record schema with scalar fields as keys and the specified type as values.\n */\n public fieldRecord(type: z.ZodTypeAny) {\n return z.record(this.scalarFieldsEnum, type);\n }\n}\n"],"names":["AbstractCoreRouteValidator","AbstractRouteValidator","scalarFieldsEnum","z","enum","Object","keys","_scalarFields","populatableFieldsEnum","_populatableFields","scalarFieldsArray","array","populatableFieldsArray","_schema","_strapi","getModel","_uid","attributes","entries","scalarEntries","filter","attribute","contentTypes","isScalarAttribute","attributeName","isPrivateAttribute","fromEntries","populatableEntries","fieldRecord","type","record","strapi","uid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;;;;;;;;IAUO,MAAeA,0BAAAA,SAEZC,kCAAAA,CAAAA;AA2BR;;;;AAIC,MACD,IAAWC,gBAAAA,GAAmB;QAC5B,OAAOC,YAAAA,CAAEC,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAAC,IAAI,CAACC,aAAa,CAAA,CAAA;AAC9C,IAAA;AAEA;;;;AAIC,MACD,IAAWC,qBAAAA,GAAwB;QACjC,OAAOL,YAAAA,CAAEC,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAAC,IAAI,CAACG,kBAAkB,CAAA,CAAA;AACnD,IAAA;AAEA;;;;AAIC,MACD,IAAWC,iBAAAA,GAAoB;AAC7B,QAAA,OAAOP,YAAAA,CAAEQ,KAAK,CAAC,IAAI,CAACT,gBAAgB,CAAA;AACtC,IAAA;AAEA;;;;AAIC,MACD,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YC,IAAkB,EAAE;AACrC,QAAA,OAAO1B,aAAE2B,MAAM,CAAC,IAAI,CAAC5B,gBAAgB,EAAE2B,IAAAA,CAAAA;AACzC,IAAA;AAtGA;;;;;AAKC,MACD,WAAA,CAAmBE,MAAmB,EAAEC,GAAM,CAAE;QAC9C,KAAK,EAAA;QACL,IAAI,CAAClB,OAAO,GAAGiB,MAAAA;QACf,IAAI,CAACf,IAAI,GAAGgB,GAAAA;AACd,IAAA;AA6FF;;;;"}
|
|
@@ -5,7 +5,8 @@ var z = require('zod/v4');
|
|
|
5
5
|
var mappers = require('./mappers.js');
|
|
6
6
|
var common = require('./common.js');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
9
10
|
var n = Object.create(null);
|
|
10
11
|
if (e) {
|
|
11
12
|
Object.keys(e).forEach(function (k) {
|
|
@@ -22,7 +23,7 @@ function _interopNamespaceDefault(e) {
|
|
|
22
23
|
return Object.freeze(n);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
var z__namespace = /*#__PURE__*/
|
|
26
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* A validator for core content-type routes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.js","sources":["../../../../src/core-api/routes/validation/content-type.ts"],"sourcesContent":["import type { Schema, UID } from '@strapi/types';\n\nimport { contentTypes } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport { createAttributesInputSchema, createAttributesSchema } from './mappers';\nimport { AbstractCoreRouteValidator } from './common';\n\n/** REST query param names. `hasPublishedVersion` is deprecated in favor of `publicationFilter`. */\nexport type QueryParam =\n | 'fields'\n | 'populate'\n | 'sort'\n | 'status'\n | 'publicationFilter'\n | 'hasPublishedVersion'\n | 'locale'\n | 'pagination'\n | 'filters'\n | '_q';\n\n/**\n * A validator for core content-type routes.\n *\n * Provides validation schemas and utilities for handling content-type-specific route validation.\n * Extends the base AbstractRouteValidator with schema-aware validation for Strapi content types.\n *\n * @example\n * ```ts\n * const strapi = // ... strapi instance\n * const uid = 'api::article.article'\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n *\n * // Get validation schema for document\n * const documentSchema = validator.document;\n *\n * // Validate query parameters with schema awareness\n * const querySchema = validator.queryParams(['fields', 'populate', 'sort']);\n * ```\n */\nexport class CoreContentTypeRouteValidator extends AbstractCoreRouteValidator<UID.ContentType> {\n /**\n * Generates a validation schema for document IDs\n *\n * @returns A schema that validates UUIDs\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const idSchema = validator.documentID;\n * ```\n */\n get documentID() {\n return z.uuid().describe('The document ID, represented by a UUID');\n }\n\n /**\n * Generates a comprehensive validation schema for a single document.\n *\n * Combines scalar fields and populatable fields into a single schema.\n *\n * @returns A schema for validating complete documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docSchema = validator.document;\n * ```\n */\n get document() {\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove passwords from the attribute list\n .filter(([, attribute]) => !['password'].includes(attribute.type));\n\n // Merge all attributes into a single schema\n const attributesSchema = createAttributesSchema(this._strapi, sanitizedAttributes);\n\n return z\n .object({\n documentId: this.documentID,\n id: z.union([z.string(), z.number()]),\n })\n .extend(attributesSchema.shape);\n }\n\n /**\n * Generates a validation schema for an array of documents\n *\n * @returns A schema for validating arrays of documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docsSchema = validator.documents;\n * ```\n */\n get documents() {\n return z.array(this.document);\n }\n\n /**\n * Schema-aware fields validation that restricts to actual model fields\n */\n protected get schemaAwareQueryFields() {\n return this.scalarFieldsArray\n .readonly()\n .describe(\n `The fields to return, this doesn't include populatable fields like relations, components, files, or dynamic zones`\n );\n }\n\n /**\n * Schema-aware populate validation that restricts to actual populatable fields\n */\n protected get schemaAwareQueryPopulate() {\n const wildcardPopulate = z\n .literal('*')\n .readonly()\n .describe(\n 'Populate all the first level relations, components, files, and dynamic zones for the entry'\n );\n\n const singleFieldPopulate = this.populatableFieldsEnum\n .readonly()\n .describe('Populate a single relation, component, file, or dynamic zone');\n\n const multiPopulate = this.populatableFieldsArray.describe(\n 'Populate a selection of multiple relations, components, files, or dynamic zones'\n );\n\n return z.union([wildcardPopulate, singleFieldPopulate, multiPopulate]);\n }\n\n /**\n * Schema-aware sort validation that restricts to actual model fields\n */\n protected get schemaAwareQuerySort() {\n const orderDirection = z.enum(['asc', 'desc']);\n\n // TODO: Handle nested sorts but very low priority, very little usage\n return z\n .union([\n this.scalarFieldsEnum, // 'name' | 'title'\n this.scalarFieldsArray, // ['name', 'title']\n this.fieldRecord(orderDirection), // { name: 'desc' } | { title: 'asc' }\n z.array(this.fieldRecord(orderDirection)), // [{ name: 'desc'}, { title: 'asc' }]\n ])\n .describe('Sort the result');\n }\n\n /**\n * Schema-aware filters validation that restricts to actual model fields\n */\n protected get schemaAwareFilters() {\n return z.record(this.scalarFieldsEnum, z.any()).describe('Filters to apply to the query');\n }\n\n get locale() {\n return z.string().describe('Select a locale');\n }\n\n get status() {\n return z\n .enum(['draft', 'published'])\n .describe('Fetch documents based on their status. Default to \"published\" if not specified.');\n }\n\n get publicationFilter() {\n return z\n .enum([\n 'never-published',\n 'has-published-version',\n 'modified',\n 'unmodified',\n 'never-published-document',\n 'has-published-version-document',\n 'published-without-draft',\n 'published-with-draft',\n ])\n .describe(\n 'Derived publication cohort: pair-scoped (per documentId+locale), document-scoped variants (-document), or published-slice diagnostics (published-without-draft / published-with-draft)'\n );\n }\n\n /** @deprecated Use `publicationFilter` instead (`never-published`, `has-published-version`, …). */\n get hasPublishedVersion() {\n return z\n .union([z.boolean(), z.enum(['true', 'false'])])\n .describe(\n '[Deprecated: prefer publicationFilter] Filter documents by whether they have a published version. Use with status=draft to find documents that have never been published'\n );\n }\n\n get data() {\n const isWritableAttribute = ([attributeName]: [string, Schema.Attribute.AnyAttribute]) => {\n return contentTypes.isWritableAttribute(this._schema, attributeName);\n };\n\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove non-writable attributes\n .filter(isWritableAttribute);\n\n return createAttributesInputSchema(this._strapi, sanitizedAttributes);\n }\n\n get query() {\n return z.string();\n }\n\n get body() {\n return z.object({ data: this.data });\n }\n\n get partialBody() {\n return z.object({ data: this.data.partial() });\n }\n\n /**\n * Creates validation schemas for query parameters\n *\n * @param params - Array of query parameters to validate ('fields', 'populate', 'sort', ...)\n * @returns Object containing validation schemas for requested parameters\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const querySchemas = validator.queryParams(['fields', 'populate']);\n * ```\n */\n queryParams(params: QueryParam[]): Partial<Record<QueryParam, z.Schema>> {\n const map: Record<QueryParam, () => z.Schema> = {\n fields: () => this.schemaAwareQueryFields.optional(),\n populate: () => this.schemaAwareQueryPopulate.optional(),\n sort: () => this.schemaAwareQuerySort.optional(),\n filters: () => this.schemaAwareFilters.optional(),\n locale: () => this.locale.optional(),\n pagination: () => this.pagination.optional(),\n status: () => this.status.optional(),\n publicationFilter: () => this.publicationFilter.optional(),\n hasPublishedVersion: () => this.hasPublishedVersion.optional(),\n _q: () => this.query.optional(),\n } as const;\n\n return params.reduce(\n (acc, param) => ({ ...acc, [param]: map[param]() }),\n {} as Partial<Record<QueryParam, z.Schema>>\n );\n }\n}\n"],"names":["CoreContentTypeRouteValidator","AbstractCoreRouteValidator","documentID","z","uuid","describe","document","entries","Object","_scalarFields","_populatableFields","sanitizedAttributes","filter","attribute","includes","type","attributesSchema","createAttributesSchema","_strapi","object","documentId","id","union","string","number","extend","shape","documents","array","schemaAwareQueryFields","scalarFieldsArray","readonly","schemaAwareQueryPopulate","wildcardPopulate","literal","singleFieldPopulate","populatableFieldsEnum","multiPopulate","populatableFieldsArray","schemaAwareQuerySort","orderDirection","enum","scalarFieldsEnum","fieldRecord","schemaAwareFilters","record","any","locale","status","publicationFilter","hasPublishedVersion","boolean","data","isWritableAttribute","attributeName","contentTypes","_schema","createAttributesInputSchema","query","body","partialBody","partial","queryParams","params","map","fields","optional","populate","sort","filters","pagination","_q","reduce","acc","param"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;;;;;;;;;;IAmBO,MAAMA,6BAAAA,SAAsCC,iCAAAA,CAAAA;AACjD;;;;;;;;;;AAUC,MACD,IAAIC,UAAAA,GAAa;AACf,QAAA,OAAOC,YAAAA,CAAEC,IAAI,EAAA,CAAGC,QAAQ,CAAC,wCAAA,CAAA;AAC3B,IAAA;AAEA;;;;;;;;;;;;AAYC,MACD,IAAIC,QAAAA,GAAW;QACb,MAAMC,OAAAA,GAAUC,MAAAA,CAAOD,OAAO,CAAC;YAAE,GAAG,IAAI,CAACE,aAAa;YAAE,GAAG,IAAI,CAACC;AAAmB,SAAA,CAAA;QAEnF,MAAMC,mBAAAA,GAAsBJ,OAC1B;AACCK,SAAAA,MAAM,CAAC,CAAC,GAAGC,SAAAA,CAAU,GAAK,CAAC;AAAC,gBAAA;aAAW,CAACC,QAAQ,CAACD,SAAAA,CAAUE,IAAI,CAAA,CAAA;;AAGlE,QAAA,MAAMC,gBAAAA,GAAmBC,8BAAAA,CAAuB,IAAI,CAACC,OAAO,EAAEP,mBAAAA,CAAAA;QAE9D,OAAOR,YAAAA,CACJgB,MAAM,CAAC;YACNC,UAAAA,EAAY,IAAI,CAAClB,UAAU;YAC3BmB,EAAAA,EAAIlB,YAAAA,CAAEmB,KAAK,CAAC;AAACnB,gBAAAA,YAAAA,CAAEoB,MAAM,EAAA;AAAIpB,gBAAAA,YAAAA,CAAEqB,MAAM;AAAG,aAAA;SACtC,CAAA,CACCC,MAAM,CAACT,gBAAAA,CAAiBU,KAAK,CAAA;A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,EAAQ,IAAM,IAAI,CAACA,MAAM,CAACkB,QAAQ,EAAA;AAClCjB,YAAAA,iBAAAA,EAAmB,IAAM,IAAI,CAACA,iBAAiB,CAACiB,QAAQ,EAAA;AACxDhB,YAAAA,mBAAAA,EAAqB,IAAM,IAAI,CAACA,mBAAmB,CAACgB,QAAQ,EAAA;AAC5DK,YAAAA,EAAAA,EAAI,IAAM,IAAI,CAACb,KAAK,CAACQ,QAAQ;AAC/B,SAAA;AAEA,QAAA,OAAOH,OAAOS,MAAM,CAClB,CAACC,GAAAA,EAAKC,SAAW;AAAE,gBAAA,GAAGD,GAAG;AAAE,gBAAA,CAACC,KAAAA,GAAQV,GAAG,CAACU,KAAAA,CAAM;AAAG,aAAA,GACjD,EAAC,CAAA;AAEL,IAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"content-type.js","sources":["../../../../src/core-api/routes/validation/content-type.ts"],"sourcesContent":["import type { Schema, UID } from '@strapi/types';\n\nimport { contentTypes } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport { createAttributesInputSchema, createAttributesSchema } from './mappers';\nimport { AbstractCoreRouteValidator } from './common';\n\n/** REST query param names. `hasPublishedVersion` is deprecated in favor of `publicationFilter`. */\nexport type QueryParam =\n | 'fields'\n | 'populate'\n | 'sort'\n | 'status'\n | 'publicationFilter'\n | 'hasPublishedVersion'\n | 'locale'\n | 'pagination'\n | 'filters'\n | '_q';\n\n/**\n * A validator for core content-type routes.\n *\n * Provides validation schemas and utilities for handling content-type-specific route validation.\n * Extends the base AbstractRouteValidator with schema-aware validation for Strapi content types.\n *\n * @example\n * ```ts\n * const strapi = // ... strapi instance\n * const uid = 'api::article.article'\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n *\n * // Get validation schema for document\n * const documentSchema = validator.document;\n *\n * // Validate query parameters with schema awareness\n * const querySchema = validator.queryParams(['fields', 'populate', 'sort']);\n * ```\n */\nexport class CoreContentTypeRouteValidator extends AbstractCoreRouteValidator<UID.ContentType> {\n /**\n * Generates a validation schema for document IDs\n *\n * @returns A schema that validates UUIDs\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const idSchema = validator.documentID;\n * ```\n */\n get documentID() {\n return z.uuid().describe('The document ID, represented by a UUID');\n }\n\n /**\n * Generates a comprehensive validation schema for a single document.\n *\n * Combines scalar fields and populatable fields into a single schema.\n *\n * @returns A schema for validating complete documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docSchema = validator.document;\n * ```\n */\n get document() {\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove passwords from the attribute list\n .filter(([, attribute]) => !['password'].includes(attribute.type));\n\n // Merge all attributes into a single schema\n const attributesSchema = createAttributesSchema(this._strapi, sanitizedAttributes);\n\n return z\n .object({\n documentId: this.documentID,\n id: z.union([z.string(), z.number()]),\n })\n .extend(attributesSchema.shape);\n }\n\n /**\n * Generates a validation schema for an array of documents\n *\n * @returns A schema for validating arrays of documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docsSchema = validator.documents;\n * ```\n */\n get documents() {\n return z.array(this.document);\n }\n\n /**\n * Schema-aware fields validation that restricts to actual model fields\n */\n protected get schemaAwareQueryFields() {\n return this.scalarFieldsArray\n .readonly()\n .describe(\n `The fields to return, this doesn't include populatable fields like relations, components, files, or dynamic zones`\n );\n }\n\n /**\n * Schema-aware populate validation that restricts to actual populatable fields\n */\n protected get schemaAwareQueryPopulate() {\n const wildcardPopulate = z\n .literal('*')\n .readonly()\n .describe(\n 'Populate all the first level relations, components, files, and dynamic zones for the entry'\n );\n\n const singleFieldPopulate = this.populatableFieldsEnum\n .readonly()\n .describe('Populate a single relation, component, file, or dynamic zone');\n\n const multiPopulate = this.populatableFieldsArray.describe(\n 'Populate a selection of multiple relations, components, files, or dynamic zones'\n );\n\n return z.union([wildcardPopulate, singleFieldPopulate, multiPopulate]);\n }\n\n /**\n * Schema-aware sort validation that restricts to actual model fields\n */\n protected get schemaAwareQuerySort() {\n const orderDirection = z.enum(['asc', 'desc']);\n\n // TODO: Handle nested sorts but very low priority, very little usage\n return z\n .union([\n this.scalarFieldsEnum, // 'name' | 'title'\n this.scalarFieldsArray, // ['name', 'title']\n this.fieldRecord(orderDirection), // { name: 'desc' } | { title: 'asc' }\n z.array(this.fieldRecord(orderDirection)), // [{ name: 'desc'}, { title: 'asc' }]\n ])\n .describe('Sort the result');\n }\n\n /**\n * Schema-aware filters validation that restricts to actual model fields\n */\n protected get schemaAwareFilters() {\n return z.record(this.scalarFieldsEnum, z.any()).describe('Filters to apply to the query');\n }\n\n get locale() {\n return z.string().describe('Select a locale');\n }\n\n get status() {\n return z\n .enum(['draft', 'published'])\n .describe('Fetch documents based on their status. Default to \"published\" if not specified.');\n }\n\n get publicationFilter() {\n return z\n .enum([\n 'never-published',\n 'has-published-version',\n 'modified',\n 'unmodified',\n 'never-published-document',\n 'has-published-version-document',\n 'published-without-draft',\n 'published-with-draft',\n ])\n .describe(\n 'Derived publication cohort: pair-scoped (per documentId+locale), document-scoped variants (-document), or published-slice diagnostics (published-without-draft / published-with-draft)'\n );\n }\n\n /** @deprecated Use `publicationFilter` instead (`never-published`, `has-published-version`, …). */\n get hasPublishedVersion() {\n return z\n .union([z.boolean(), z.enum(['true', 'false'])])\n .describe(\n '[Deprecated: prefer publicationFilter] Filter documents by whether they have a published version. Use with status=draft to find documents that have never been published'\n );\n }\n\n get data() {\n const isWritableAttribute = ([attributeName]: [string, Schema.Attribute.AnyAttribute]) => {\n return contentTypes.isWritableAttribute(this._schema, attributeName);\n };\n\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove non-writable attributes\n .filter(isWritableAttribute);\n\n return createAttributesInputSchema(this._strapi, sanitizedAttributes);\n }\n\n get query() {\n return z.string();\n }\n\n get body() {\n return z.object({ data: this.data });\n }\n\n get partialBody() {\n return z.object({ data: this.data.partial() });\n }\n\n /**\n * Creates validation schemas for query parameters\n *\n * @param params - Array of query parameters to validate ('fields', 'populate', 'sort', ...)\n * @returns Object containing validation schemas for requested parameters\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const querySchemas = validator.queryParams(['fields', 'populate']);\n * ```\n */\n queryParams(params: QueryParam[]): Partial<Record<QueryParam, z.Schema>> {\n const map: Record<QueryParam, () => z.Schema> = {\n fields: () => this.schemaAwareQueryFields.optional(),\n populate: () => this.schemaAwareQueryPopulate.optional(),\n sort: () => this.schemaAwareQuerySort.optional(),\n filters: () => this.schemaAwareFilters.optional(),\n locale: () => this.locale.optional(),\n pagination: () => this.pagination.optional(),\n status: () => this.status.optional(),\n publicationFilter: () => this.publicationFilter.optional(),\n hasPublishedVersion: () => this.hasPublishedVersion.optional(),\n _q: () => this.query.optional(),\n } as const;\n\n return params.reduce(\n (acc, param) => ({ ...acc, [param]: map[param]() }),\n {} as Partial<Record<QueryParam, z.Schema>>\n );\n }\n}\n"],"names":["CoreContentTypeRouteValidator","AbstractCoreRouteValidator","documentID","z","uuid","describe","document","entries","Object","_scalarFields","_populatableFields","sanitizedAttributes","filter","attribute","includes","type","attributesSchema","createAttributesSchema","_strapi","object","documentId","id","union","string","number","extend","shape","documents","array","schemaAwareQueryFields","scalarFieldsArray","readonly","schemaAwareQueryPopulate","wildcardPopulate","literal","singleFieldPopulate","populatableFieldsEnum","multiPopulate","populatableFieldsArray","schemaAwareQuerySort","orderDirection","enum","scalarFieldsEnum","fieldRecord","schemaAwareFilters","record","any","locale","status","publicationFilter","hasPublishedVersion","boolean","data","isWritableAttribute","attributeName","contentTypes","_schema","createAttributesInputSchema","query","body","partialBody","partial","queryParams","params","map","fields","optional","populate","sort","filters","pagination","_q","reduce","acc","param"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;;;;;;;;;;IAmBO,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M,CAClB,CAACC,GAAAA,EAAKC,SAAW;AAAE,gBAAA,GAAGD,GAAG;AAAE,gBAAA,CAACC,KAAAA,GAAQV,GAAG,CAACU,KAAAA,CAAM;AAAG,aAAA,GACjD,EAAC,CAAA;AAEL,IAAA;AACF;;;;"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
var z = require('zod/v4');
|
|
4
4
|
var attributes = require('./attributes.js');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
7
8
|
var n = Object.create(null);
|
|
8
9
|
if (e) {
|
|
9
10
|
Object.keys(e).forEach(function (k) {
|
|
@@ -20,7 +21,7 @@ function _interopNamespaceDefault(e) {
|
|
|
20
21
|
return Object.freeze(n);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
var z__namespace = /*#__PURE__*/
|
|
24
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
24
25
|
|
|
25
26
|
const isCustomFieldAttribute = (attribute)=>{
|
|
26
27
|
return !!attribute && typeof attribute === 'object' && attribute.type === 'customField' && typeof attribute.customField === 'string';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.js","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Core, Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(strapi, attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(strapi, attribute);\n case 'relation':\n return attributes.relationToSchema(strapi, attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","strapi","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","get","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SAAAA,IACF,OAAOA,cAAc,QAAA,IACpBA,SAAAA,CAAkBC,IAAI,KAAK,aAAA,IAC5B,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMC,sBAAAA,GAAyB,CACpCC,MAAAA,EACAC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMR,SAAAA,CAAU,GAAA;QAC9C,OAAOO,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOE,qBAAqBN,MAAAA,EAAQJ,SAAAA,CAAAA;AACtC,YAAA;AACF,SAAA,CAAA;IACF,CAAA,EAAGW,YAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;AAiBC,IACM,MAAMC,2BAAAA,GAA8B,CACzCT,MAAAA,EACAC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK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WAAAA,GAAcE,OAAOY,GAAG,CAAC,iBAAiBA,GAAG,CAACD,OAAOb,WAAW,CAAA;AACtE,oBAAA,IAAI,CAACA,WAAAA,EAAa;wBAChB,MAAM,IAAIe,MAAM,CAAC,cAAc,EAAEF,MAAAA,CAAOb,WAAW,CAAC,WAAW,CAAC,CAAA;AAClE,oBAAA;;AAGA,oBAAA,OAAOY,0BAA0BV,MAAAA,EAAQ;AAAE,wBAAA,GAAGW,MAAM;AAAEd,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AAC/E,gBAAA;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIiB,KAAAA,CAAM,CAAC,4BAA4B,EAAEhB,IAAAA,CAAAA,CAAM,CAAA;AACvD,YAAA;AACF;AACF;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"mappers.js","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Core, Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(strapi, attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(strapi, attribute);\n case 'relation':\n return attributes.relationToSchema(strapi, attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","strapi","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","get","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SAAAA,IACF,OAAOA,cAAc,QAAA,IACpBA,SAAAA,CAAkBC,IAAI,KAAK,aAAA,IAC5B,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMC,sBAAAA,GAAyB,CACpCC,MAAAA,EACAC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMR,SAAAA,CAAU,GAAA;QAC9C,OAAOO,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOE,qBAAqBN,MAAAA,EAAQJ,SAAAA,CAAAA;AACtC,YAAA;AACF,SAAA,CAAA;IACF,CAAA,EAAGW,YAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;AAiBC,IACM,MAAMC,2BAAAA,GAA8B,CACzCT,MAAAA,EACAC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMR,SAAAA,CAAU,GAAA;QAC9C,OAAOO,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOM,0BAA0BV,MAAAA,EAAQJ,SAAAA,CAAAA;AAC3C,YAAA;AACF,SAAA,CAAA;IACF,CAAA,EAAGW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ClE,oBAAA;;AAGA,oBAAA,OAAOY,0BAA0BV,MAAAA,EAAQ;AAAE,wBAAA,GAAGW,MAAM;AAAEd,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AAC/E,gBAAA;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIiB,KAAAA,CAAM,CAAC,4BAA4B,EAAEhB,IAAAA,CAAAA,CAAM,CAAA;AACvD,YAAA;AACF;AACF;;;;;;;"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
var strapiUtils = require('@strapi/utils');
|
|
4
4
|
var z = require('zod/v4');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
7
8
|
var n = Object.create(null);
|
|
8
9
|
if (e) {
|
|
9
10
|
Object.keys(e).forEach(function (k) {
|
|
@@ -20,7 +21,7 @@ function _interopNamespaceDefault(e) {
|
|
|
20
21
|
return Object.freeze(n);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
var z__namespace = /*#__PURE__*/
|
|
24
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
24
25
|
|
|
25
26
|
// Schema generation happens on-demand when schemas don't exist in the registry
|
|
26
27
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Core, Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (\n strapi: Core.Strapi,\n id: Internal.UID.Schema,\n schema: z.ZodType\n) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (\n strapi: Core.Strapi,\n id: Internal.UID.Schema,\n callback: () => z.ZodType\n) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(strapi, id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(strapi, id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","strapi","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Core, Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (\n strapi: Core.Strapi,\n id: Internal.UID.Schema,\n schema: z.ZodType\n) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (\n strapi: Core.Strapi,\n id: Internal.UID.Schema,\n callback: () => z.ZodType\n) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(strapi, id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(strapi, id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","strapi","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAAA,GAAwB,CACnCC,QACAC,EAAAA,EACAC,MAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,MAAM,EAAEC,MAAAA,EAAQC,KAAK,EAAE,GAAGC,aAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,0CAAAA,CAA+BP,EAAAA,CAAAA;QAErD,MAAMQ,WAAAA,GAAcL,KAAAA,CAAMM,GAAG,CAACH,aAAAA,CAAAA;AAE9B,QAAA,IAAIE,WAAAA,EAAa;;AA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ACF;;;;;"}
|
|
@@ -5,6 +5,10 @@ var _ = require('lodash');
|
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
|
6
6
|
var validator = require('./validator.js');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
11
|
+
|
|
8
12
|
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
9
13
|
const createContentType = (uid, definition)=>{
|
|
10
14
|
try {
|
|
@@ -47,8 +51,8 @@ const addTimestamps = (schema)=>{
|
|
|
47
51
|
});
|
|
48
52
|
};
|
|
49
53
|
const addDraftAndPublish = (schema)=>{
|
|
50
|
-
if (!
|
|
51
|
-
|
|
54
|
+
if (!___default.default.has(schema, 'options.draftAndPublish')) {
|
|
55
|
+
___default.default.set(schema, 'options.draftAndPublish', false); // Disabled by default
|
|
52
56
|
}
|
|
53
57
|
schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {
|
|
54
58
|
type: 'datetime',
|
|
@@ -76,7 +80,7 @@ const addFirstPublishedAt = (schema)=>{
|
|
|
76
80
|
}
|
|
77
81
|
};
|
|
78
82
|
const addCreatorFields = (schema)=>{
|
|
79
|
-
const isPrivate = !
|
|
83
|
+
const isPrivate = !___default.default.get(schema, 'options.populateCreatorFields', false);
|
|
80
84
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
|
81
85
|
type: 'relation',
|
|
82
86
|
relation: 'oneToOne',
|
|
@@ -101,10 +105,10 @@ const addCreatorFields = (schema)=>{
|
|
|
101
105
|
const getGlobalId = (schema, prefix)=>{
|
|
102
106
|
const modelName = schema.info.singularName;
|
|
103
107
|
const globalId = prefix ? `${prefix}-${modelName}` : modelName;
|
|
104
|
-
return schema.globalId ||
|
|
108
|
+
return schema.globalId || ___default.default.upperFirst(___default.default.camelCase(globalId));
|
|
105
109
|
};
|
|
106
110
|
const pickSchema = (model)=>{
|
|
107
|
-
const schema =
|
|
111
|
+
const schema = ___default.default.cloneDeep(___default.default.pick(model, [
|
|
108
112
|
'connection',
|
|
109
113
|
'collectionName',
|
|
110
114
|
'info',
|