@strapi/core 0.0.0-experimental.a9a5a36dd73072c19eadeff5f387e8286b2a4d22 → 0.0.0-experimental.abc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -3
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +26 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +4 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +4 -0
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +4 -0
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/middlewares/query.d.ts.map +1 -1
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/query.mjs.map +1 -1
- package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
- package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +4 -3
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +3 -3
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts +2 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +10 -15
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +14 -19
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +32 -23
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +123 -53
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +122 -53
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +2 -2
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs +2 -2
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/package.json +13 -13
package/LICENSE
CHANGED
@@ -2,7 +2,21 @@ Copyright (c) 2015-present Strapi Solutions SAS
|
|
2
2
|
|
3
3
|
Portions of the Strapi software are licensed as follows:
|
4
4
|
|
5
|
-
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined
|
5
|
+
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined below.
|
6
|
+
|
7
|
+
Enterprise License
|
8
|
+
|
9
|
+
If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
|
10
|
+
https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
|
11
|
+
represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
|
12
|
+
agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
|
13
|
+
Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
|
14
|
+
|
15
|
+
BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
|
16
|
+
IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
|
17
|
+
HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
|
18
|
+
THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
|
19
|
+
IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
|
6
20
|
|
7
21
|
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
8
22
|
|
@@ -18,5 +32,6 @@ furnished to do so, subject to the following conditions:
|
|
18
32
|
The above copyright notice and this permission notice shall be included in all
|
19
33
|
copies or substantial portions of the Software.
|
20
34
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
-
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
37
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
+
import * as qs from 'qs';
|
1
2
|
import type { Core } from '@strapi/types';
|
2
3
|
import Strapi, { type StrapiOptions } from './Strapi';
|
3
4
|
export { default as compileStrapi } from './compile';
|
4
5
|
export * as factories from './factories';
|
5
6
|
export declare const createStrapi: (options?: Partial<StrapiOptions>) => Core.Strapi;
|
7
|
+
declare module 'koa' {
|
8
|
+
type ParsedQuery = ReturnType<typeof qs.parse>;
|
9
|
+
interface BaseRequest {
|
10
|
+
_querycache?: ParsedQuery;
|
11
|
+
get query(): ParsedQuery;
|
12
|
+
set query(obj: any);
|
13
|
+
}
|
14
|
+
interface BaseContext {
|
15
|
+
_querycache?: ParsedQuery;
|
16
|
+
get query(): ParsedQuery;
|
17
|
+
set query(obj: any);
|
18
|
+
}
|
19
|
+
}
|
6
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,MAAM,EAAE,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,aAAa,QAAQ,aAAa,CAAC,KAAQ,WAanE,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,MAAM,EAAE,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,aAAa,QAAQ,aAAa,CAAC,KAAQ,WAanE,CAAC;AAIF,OAAO,QAAQ,KAAK,CAAC;IACnB,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAE/C,UAAiB,WAAW;QAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;QAE1B,IAAI,KAAK,IAAI,WAAW,CAAC;QACzB,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE;KACrB;IAED,UAAiB,WAAW;QAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;QAE1B,IAAI,KAAK,IAAI,WAAW,CAAC;QACzB,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE;KACrB;CACF"}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n"],"names":["resolveWorkingDirectories","destroyOnSignal","createUpdateNotifier"],"mappings":";;;;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import * as qs from 'qs';\nimport type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n\n// Augment Koa query type based on Strapi query middleware\n\ndeclare module 'koa' {\n type ParsedQuery = ReturnType<typeof qs.parse>;\n\n export interface BaseRequest {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n\n export interface BaseContext {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n}\n"],"names":["resolveWorkingDirectories","destroyOnSignal","createUpdateNotifier"],"mappings":";;;;;;;;;;;;;;;;;AASO,MAAM,eAAe,CAAC,UAAkC,OAAoB;AAC3E,QAAA,SAAS,IAAI,OAAO;AAAA,IACxB,GAAG;AAAA,IACH,GAAGA,mBAAAA,0BAA0B,OAAO;AAAA,EAAA,CACrC;AAEDC,UAAA,gBAAgB,MAAM;AACtBC,QAAA,qBAAqB,MAAM;AAG3B,SAAO,SAAS;AAET,SAAA;AACT;;;;"}
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import * as qs from 'qs';\nimport type { Core } from '@strapi/types';\n\nimport Strapi, { type StrapiOptions } from './Strapi';\nimport { destroyOnSignal, resolveWorkingDirectories, createUpdateNotifier } from './utils';\n\nexport { default as compileStrapi } from './compile';\nexport * as factories from './factories';\n\nexport const createStrapi = (options: Partial<StrapiOptions> = {}): Core.Strapi => {\n const strapi = new Strapi({\n ...options,\n ...resolveWorkingDirectories(options),\n });\n\n destroyOnSignal(strapi);\n createUpdateNotifier(strapi);\n\n // TODO: deprecate and remove in next major\n global.strapi = strapi;\n\n return strapi;\n};\n\n// Augment Koa query type based on Strapi query middleware\n\ndeclare module 'koa' {\n type ParsedQuery = ReturnType<typeof qs.parse>;\n\n export interface BaseRequest {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n\n export interface BaseContext {\n _querycache?: ParsedQuery;\n\n get query(): ParsedQuery;\n set query(obj: any);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AASO,MAAM,eAAe,CAAC,UAAkC,OAAoB;AAC3E,QAAA,SAAS,IAAI,OAAO;AAAA,IACxB,GAAG;AAAA,IACH,GAAG,0BAA0B,OAAO;AAAA,EAAA,CACrC;AAED,kBAAgB,MAAM;AACtB,uBAAqB,MAAM;AAG3B,SAAO,SAAS;AAET,SAAA;AACT;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.d.ts","sourceRoot":"","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAiF1C,eAAO,MAAM,iBAAiB,WAAkB,KAAK,MAAM;;
|
1
|
+
{"version":3,"file":"get-enabled-plugins.d.ts","sourceRoot":"","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAiF1C,eAAO,MAAM,iBAAiB,WAAkB,KAAK,MAAM;;kBAiF1D,CAAC"}
|
@@ -1,4 +1,26 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
+
for (let key of __getOwnPropNames(from))
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
+
}
|
14
|
+
return to;
|
15
|
+
};
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
2
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
25
|
const path = require("path");
|
4
26
|
const fs = require("fs");
|
@@ -52,7 +74,10 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
52
74
|
const internalPlugins = {};
|
53
75
|
for (const dep of INTERNAL_PLUGINS) {
|
54
76
|
const packagePath = path.join(dep, "package.json");
|
55
|
-
const
|
77
|
+
const packageModulePath = require.resolve(packagePath, {
|
78
|
+
paths: [require.resolve("@strapi/strapi/package.json"), process.cwd()]
|
79
|
+
});
|
80
|
+
const packageInfo = require(packageModulePath);
|
56
81
|
validatePluginName(packageInfo.strapi.name);
|
57
82
|
internalPlugins[packageInfo.strapi.name] = {
|
58
83
|
...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const
|
1
|
+
{"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","strings","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,GAAAA,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAACC,YAAA,QAAQ,YAAY,UAAU,GAAG;AACpC,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;AAAA,IACvE,SAAS,YAAY;AAAA,EAAA;AAGvB,MAAI,aAAa,SAAS;AACxB,QAAI,eAAe;AAEnB,QAAI,YAAY,UAAU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S) {
|
50
50
|
const packagePath = join(dep, "package.json");
|
51
|
-
const
|
51
|
+
const packageModulePath = require.resolve(packagePath, {
|
52
|
+
paths: [require.resolve("@strapi/strapi/package.json"), process.cwd()]
|
53
|
+
});
|
54
|
+
const packageInfo = require(packageModulePath);
|
52
55
|
validatePluginName(packageInfo.strapi.name);
|
53
56
|
internalPlugins[packageInfo.strapi.name] = {
|
54
57
|
...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const
|
1
|
+
{"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n *\n * NOTE: These are excluded from the content manager plugin list, as they are always enabled.\n * See admin.ts server controller on the content-manager plugin for more details.\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n\n // NOTE: internal plugins should be resolved from the strapi package\n const packageModulePath = require.resolve(packagePath, {\n paths: [require.resolve('@strapi/strapi/package.json'), process.cwd()],\n });\n\n const packageInfo = require(packageModulePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["strapi"],"mappings":";;;;;;AAkCA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqB,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAAC,QAAQ,YAAY,UAAU,GAAG;AACpC,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,w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"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC9D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAWF,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC9D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAWF,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CA8C/C,CAAC"}
|
package/dist/middlewares/cors.js
CHANGED
@@ -35,6 +35,10 @@ const cors = (config) => {
|
|
35
35
|
if (Array.isArray(originList)) {
|
36
36
|
return originList.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
37
37
|
}
|
38
|
+
const parsedOrigin = originList.split(",").map((origin2) => origin2.trim());
|
39
|
+
if (parsedOrigin.length > 1) {
|
40
|
+
return parsedOrigin.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
41
|
+
}
|
38
42
|
return originList;
|
39
43
|
},
|
40
44
|
exposeHeaders: expose,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["koaCors"],"mappings":";;;;;AAeA,MAAM,WAAmB;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS,CAAC,OAAO,QAAQ,OAAO,SAAS,UAAU,QAAQ,SAAS;AAAA,EACpE,SAAS,CAAC,gBAAgB,iBAAiB,UAAU,QAAQ;AAAA,EAC7D,oBAAoB;AACtB;AAEa,MAAA,OAAuC,CAAC,WAAW;AACxD,QAAA,EAAE,QAAQ,QAAQ,QAAQ,aAAa,SAAS,SAAS,uBAAuB;AAAA,IACpF,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGD,MAAA,OAAO,YAAY,QAAW;AAChC,WAAO,IAAI;AAAA,MACT;AAAA,IAAA;AAAA,EAIJ;AAEA,SAAOA,yBAAQ;AAAA,IACb,MAAM,OAAO,KAAK;AAChB,UAAI,CAAC,IAAI,IAAI,QAAQ,GAAG;AACf,eAAA;AAAA,MACT;AAEI,UAAA;AAEA,UAAA,OAAO,WAAW,YAAY;AACnB,qBAAA,MAAM,OAAO,GAAG;AAAA,MAAA,OACxB;AACQ,qBAAA;AAAA,MACf;AAEI,UAAA,MAAM,QAAQ,UAAU,GAAG;AACtB,eAAA,WAAW,SAAS,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,MACtE;AAEO,aAAA;AAAA,IACT;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,cAAc;AAAA,IACd;AAAA,EAAA,CACD;AACH;;"}
|
1
|
+
{"version":3,"file":"cors.js","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n const parsedOrigin = originList.split(',').map((origin) => origin.trim());\n if (parsedOrigin.length > 1) {\n return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["koaCors","origin"],"mappings":";;;;;AAeA,MAAM,WAAmB;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS,CAAC,OAAO,QAAQ,OAAO,SAAS,UAAU,QAAQ,SAAS;AAAA,EACpE,SAAS,CAAC,gBAAgB,iBAAiB,UAAU,QAAQ;AAAA,EAC7D,oBAAoB;AACtB;AAEa,MAAA,OAAuC,CAAC,WAAW;AACxD,QAAA,EAAE,QAAQ,QAAQ,QAAQ,aAAa,SAAS,SAAS,uBAAuB;AAAA,IACpF,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGD,MAAA,OAAO,YAAY,QAAW;AAChC,WAAO,IAAI;AAAA,MACT;AAAA,IAAA;AAAA,EAIJ;AAEA,SAAOA,yBAAQ;AAAA,IACb,MAAM,OAAO,KAAK;AAChB,UAAI,CAAC,IAAI,IAAI,QAAQ,GAAG;AACf,eAAA;AAAA,MACT;AAEI,UAAA;AAEA,UAAA,OAAO,WAAW,YAAY;AACnB,qBAAA,MAAM,OAAO,GAAG;AAAA,MAAA,OACxB;AACQ,qBAAA;AAAA,MACf;AAEI,UAAA,MAAM,QAAQ,UAAU,GAAG;AACtB,eAAA,WAAW,SAAS,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,MACtE;AAEM,YAAA,eAAe,WAAW,MAAM,GAAG,EAAE,IAAI,CAACC,YAAWA,QAAO,KAAA,CAAM;AACpE,UAAA,aAAa,SAAS,GAAG;AACpB,eAAA,aAAa,SAAS,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,MACxE;AAEO,aAAA;AAAA,IACT;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,cAAc;AAAA,IACd;AAAA,EAAA,CACD;AACH;;"}
|
@@ -31,6 +31,10 @@ const cors = (config) => {
|
|
31
31
|
if (Array.isArray(originList)) {
|
32
32
|
return originList.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
33
33
|
}
|
34
|
+
const parsedOrigin = originList.split(",").map((origin2) => origin2.trim());
|
35
|
+
if (parsedOrigin.length > 1) {
|
36
|
+
return parsedOrigin.includes(ctx.get("Origin")) ? ctx.get("Origin") : "";
|
37
|
+
}
|
34
38
|
return originList;
|
35
39
|
},
|
36
40
|
exposeHeaders: expose,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":[],"mappings":";AAeA,MAAM,WAAmB;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS,CAAC,OAAO,QAAQ,OAAO,SAAS,UAAU,QAAQ,SAAS;AAAA,EACpE,SAAS,CAAC,gBAAgB,iBAAiB,UAAU,QAAQ;AAAA,EAC7D,oBAAoB;AACtB;AAEa,MAAA,OAAuC,CAAC,WAAW;AACxD,QAAA,EAAE,QAAQ,QAAQ,QAAQ,aAAa,SAAS,SAAS,uBAAuB;AAAA,IACpF,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGD,MAAA,OAAO,YAAY,QAAW;AAChC,WAAO,IAAI;AAAA,MACT;AAAA,IAAA;AAAA,EAIJ;AAEA,SAAO,QAAQ;AAAA,IACb,MAAM,OAAO,KAAK;AAChB,UAAI,CAAC,IAAI,IAAI,QAAQ,GAAG;AACf,eAAA;AAAA,MACT;AAEI,UAAA;AAEA,UAAA,OAAO,WAAW,YAAY;AACnB,qBAAA,MAAM,OAAO,GAAG;AAAA,MAAA,OACxB;AACQ,qBAAA;AAAA,MACf;AAEI,UAAA,MAAM,QAAQ,UAAU,GAAG;AACtB,eAAA,WAAW,SAAS,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,MACtE;AAEO,aAAA;AAAA,IACT;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,cAAc;AAAA,IACd;AAAA,EAAA,CACD;AACH;"}
|
1
|
+
{"version":3,"file":"cors.mjs","sources":["../../src/middlewares/cors.ts"],"sourcesContent":["import koaCors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = {\n enabled?: boolean;\n origin: string | string[] | ((ctx: any) => string | string[]);\n expose?: string | string[];\n maxAge?: number;\n credentials?: boolean;\n methods?: string | string[];\n headers?: string | string[];\n keepHeadersOnError?: boolean;\n};\n\nconst defaults: Config = {\n origin: '*',\n maxAge: 31536000,\n credentials: true,\n methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],\n headers: ['Content-Type', 'Authorization', 'Origin', 'Accept'],\n keepHeadersOnError: false,\n};\n\nexport const cors: Core.MiddlewareFactory<Config> = (config) => {\n const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } = {\n ...defaults,\n ...config,\n };\n\n if (config.enabled !== undefined) {\n strapi.log.warn(\n 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +\n ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +\n ' the exported array in config/middleware.js'\n );\n }\n\n return koaCors({\n async origin(ctx) {\n if (!ctx.get('Origin')) {\n return '*';\n }\n\n let originList: string | string[];\n\n if (typeof origin === 'function') {\n originList = await origin(ctx);\n } else {\n originList = origin;\n }\n\n if (Array.isArray(originList)) {\n return originList.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n const parsedOrigin = originList.split(',').map((origin) => origin.trim());\n if (parsedOrigin.length > 1) {\n return parsedOrigin.includes(ctx.get('Origin')) ? ctx.get('Origin') : '';\n }\n\n return originList;\n },\n exposeHeaders: expose,\n maxAge,\n credentials,\n allowMethods: methods,\n allowHeaders: headers,\n keepHeadersOnError,\n });\n};\n"],"names":["origin"],"mappings":";AAeA,MAAM,WAAmB;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS,CAAC,OAAO,QAAQ,OAAO,SAAS,UAAU,QAAQ,SAAS;AAAA,EACpE,SAAS,CAAC,gBAAgB,iBAAiB,UAAU,QAAQ;AAAA,EAC7D,oBAAoB;AACtB;AAEa,MAAA,OAAuC,CAAC,WAAW;AACxD,QAAA,EAAE,QAAQ,QAAQ,QAAQ,aAAa,SAAS,SAAS,uBAAuB;AAAA,IACpF,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGD,MAAA,OAAO,YAAY,QAAW;AAChC,WAAO,IAAI;AAAA,MACT;AAAA,IAAA;AAAA,EAIJ;AAEA,SAAO,QAAQ;AAAA,IACb,MAAM,OAAO,KAAK;AAChB,UAAI,CAAC,IAAI,IAAI,QAAQ,GAAG;AACf,eAAA;AAAA,MACT;AAEI,UAAA;AAEA,UAAA,OAAO,WAAW,YAAY;AACnB,qBAAA,MAAM,OAAO,GAAG;AAAA,MAAA,OACxB;AACQ,qBAAA;AAAA,MACf;AAEI,UAAA,MAAM,QAAQ,UAAU,GAAG;AACtB,eAAA,WAAW,SAAS,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,MACtE;AAEM,YAAA,eAAe,WAAW,MAAM,GAAG,EAAE,IAAI,CAACA,YAAWA,QAAO,KAAA,CAAM;AACpE,UAAA,aAAa,SAAS,GAAG;AACpB,eAAA,aAAa,SAAS,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,MACxE;AAEO,aAAA;AAAA,IACT;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,cAAc;AAAA,IACd;AAAA,EAAA,CACD;AACH;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/middlewares/query.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/middlewares/query.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AA4C1C,eAAO,MAAM,KAAK,EAAE,IAAI,CAAC,iBAKxB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.js","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs
|
1
|
+
{"version":3,"file":"query.js","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs from 'qs';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\ntype Config = Parameters<typeof qs.parse>[1];\n\nconst defaults: Config = {\n strictNullHandling: true,\n arrayLimit: 100,\n depth: 20,\n};\n\n/**\n * Body parser hook\n */\nconst addQsParser = (app: Koa, settings: Config) => {\n Object.defineProperty(app.request, 'query', {\n configurable: false,\n enumerable: true,\n /*\n * Get parsed query-string.\n */\n get() {\n const qstr = this.querystring;\n\n this._querycache = this._querycache || {};\n const cache = this._querycache;\n\n if (!cache[qstr]) {\n cache[qstr] = qs.parse(qstr, settings);\n }\n\n return cache[qstr];\n },\n\n /*\n * Set query-string as an object.\n */\n set(obj) {\n this.querystring = qs.stringify(obj);\n },\n } satisfies PropertyDescriptor & ThisType<Koa.BaseRequest>);\n\n return app;\n};\n\nexport const query: Core.MiddlewareFactory = (\n config: Partial<Config>,\n { strapi }: { strapi: Core.Strapi }\n) => {\n addQsParser(strapi.server.app, { ...defaults, ...config });\n};\n"],"names":["qs"],"mappings":";;;;;AAMA,MAAM,WAAmB;AAAA,EACvB,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT;AAKA,MAAM,cAAc,CAAC,KAAU,aAAqB;AAC3C,SAAA,eAAe,IAAI,SAAS,SAAS;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA;AAAA;AAAA;AAAA,IAIZ,MAAM;AACJ,YAAM,OAAO,KAAK;AAEb,WAAA,cAAc,KAAK,eAAe,CAAA;AACvC,YAAM,QAAQ,KAAK;AAEf,UAAA,CAAC,MAAM,IAAI,GAAG;AAChB,cAAM,IAAI,IAAIA,YAAAA,QAAG,MAAM,MAAM,QAAQ;AAAA,MACvC;AAEA,aAAO,MAAM,IAAI;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAK;AACF,WAAA,cAAcA,YAAAA,QAAG,UAAU,GAAG;AAAA,IACrC;AAAA,EAAA,CACwD;AAEnD,SAAA;AACT;AAEO,MAAM,QAAgC,CAC3C,QACA,EAAE,aACC;AACS,cAAA,OAAO,OAAO,KAAK,EAAE,GAAG,UAAU,GAAG,QAAQ;AAC3D;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.mjs","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs
|
1
|
+
{"version":3,"file":"query.mjs","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs from 'qs';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\ntype Config = Parameters<typeof qs.parse>[1];\n\nconst defaults: Config = {\n strictNullHandling: true,\n arrayLimit: 100,\n depth: 20,\n};\n\n/**\n * Body parser hook\n */\nconst addQsParser = (app: Koa, settings: Config) => {\n Object.defineProperty(app.request, 'query', {\n configurable: false,\n enumerable: true,\n /*\n * Get parsed query-string.\n */\n get() {\n const qstr = this.querystring;\n\n this._querycache = this._querycache || {};\n const cache = this._querycache;\n\n if (!cache[qstr]) {\n cache[qstr] = qs.parse(qstr, settings);\n }\n\n return cache[qstr];\n },\n\n /*\n * Set query-string as an object.\n */\n set(obj) {\n this.querystring = qs.stringify(obj);\n },\n } satisfies PropertyDescriptor & ThisType<Koa.BaseRequest>);\n\n return app;\n};\n\nexport const query: Core.MiddlewareFactory = (\n config: Partial<Config>,\n { strapi }: { strapi: Core.Strapi }\n) => {\n addQsParser(strapi.server.app, { ...defaults, ...config });\n};\n"],"names":[],"mappings":";AAMA,MAAM,WAAmB;AAAA,EACvB,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT;AAKA,MAAM,cAAc,CAAC,KAAU,aAAqB;AAC3C,SAAA,eAAe,IAAI,SAAS,SAAS;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA;AAAA;AAAA;AAAA,IAIZ,MAAM;AACJ,YAAM,OAAO,KAAK;AAEb,WAAA,cAAc,KAAK,eAAe,CAAA;AACvC,YAAM,QAAQ,KAAK;AAEf,UAAA,CAAC,MAAM,IAAI,GAAG;AAChB,cAAM,IAAI,IAAI,GAAG,MAAM,MAAM,QAAQ;AAAA,MACvC;AAEA,aAAO,MAAM,IAAI;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAK;AACF,WAAA,cAAc,GAAG,UAAU,GAAG;AAAA,IACrC;AAAA,EAAA,CACwD;AAEnD,SAAA;AACT;AAEO,MAAM,QAAgC,CAC3C,QACA,EAAE,aACC;AACS,cAAA,OAAO,OAAO,KAAK,EAAE,GAAG,UAAU,GAAG,QAAQ;AAC3D;"}
|
@@ -1,4 +1,3 @@
|
|
1
1
|
import { yup } from '@strapi/utils';
|
2
|
-
declare const
|
3
|
-
export default _default;
|
2
|
+
export declare const blocksValidator: () => yup.ArraySchema<any, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
|
4
3
|
//# sourceMappingURL=blocks-validator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"blocks-validator.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAwKpC,eAAO,MAAM,eAAe,qGAA8B,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
2
3
|
const strapiUtils = require("@strapi/utils");
|
3
4
|
const textNodeValidator = strapiUtils.yup.object().shape({
|
4
5
|
type: strapiUtils.yup.string().equals(["text"]).required(),
|
@@ -121,7 +122,7 @@ const blockNodeValidator = strapiUtils.yup.lazy((value) => {
|
|
121
122
|
});
|
122
123
|
}
|
123
124
|
});
|
124
|
-
const
|
125
|
-
const blocksValidator
|
126
|
-
|
125
|
+
const blocksValidatorSchema = strapiUtils.yup.array().of(blockNodeValidator);
|
126
|
+
const blocksValidator = () => blocksValidatorSchema;
|
127
|
+
exports.blocksValidator = blocksValidator;
|
127
128
|
//# sourceMappingURL=blocks-validator.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst
|
1
|
+
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["yup"],"mappings":";;;AAEA,MAAM,oBAAoBA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAMA,gBAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,MAAMA,YAAAA,IACH,OAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA,CAAC,SAAkB;AACV,aAAA,OAAO,SAAS,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF;AAAA,EACF,MAAMA,gBAAI,QAAQ;AAAA,EAClB,QAAQA,gBAAI,QAAQ;AAAA,EACpB,WAAWA,gBAAI,QAAQ;AAAA,EACvB,eAAeA,gBAAI,QAAQ;AAAA,EAC3B,MAAMA,gBAAI,QAAQ;AACpB,CAAC;AAED,MAAM,iBAAiB,CAAC,SAAiB;AACnC,MAAA;AAEE,QAAA,IAAI,KAAK,WAAW,GAAG,IAAI,oBAAoB,IAAI,KAAK,IAAI;AAAA,WACzD,OAAO;AACP,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEA,MAAM,oBAAoBA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAMA,gBAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,KAAKA,YAAA,IACF,OAAO,EACP,KAAK,eAAe,gCAAgC,CAAC,UAAU,eAAe,SAAS,EAAE,CAAC;AAAA,EAC7F,UAAUA,YAAI,IAAA,MAAA,EAAQ,GAAG,iBAAiB,EAAE,SAAS;AACvD,CAAC;AAGD,MAAM,sBAA2BA,YAAA,IAAI,KAAK,CAAC,UAA4B;AACrE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAOA,YAAAA,IAAI,MAAM,EAAE,KAAK,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;AAAA,IAC/B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,KAAKA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC3B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,YAAYA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAClC,UAAUA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAChC,mBAAmBA,YAAA,IAAI,MAAM,EAAE,SAAS;AAAA,IACxC,WAAWA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IACjC,WAAWA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,EAAA,CAClC;AAAA,EACD,UAAUA,YAAI,IAAA,MAAA,EAAQ,GAAG,mBAAmB,EAAE,SAAS;AACzD,CAAC;AAGD,MAAM,qBAA0BA,YAAA,IAAI,KAAK,CAAC,UAA4B;AACpE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAOA,YAAAA,IAAI,MAAM,EAAE,KAAK,gBAAgB,iCAAiC,MAAM;AACtE,eAAA;AAAA,MAAA,CACR;AAAA,EACL;AACF,CAAC;AAED,MAAM,wBAAwBA,YAAAA,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAExD,MAAM,kBAAkB,MAAM;;"}
|
@@ -120,9 +120,9 @@ const blockNodeValidator = yup.lazy((value) => {
|
|
120
120
|
});
|
121
121
|
}
|
122
122
|
});
|
123
|
-
const
|
124
|
-
const blocksValidator
|
123
|
+
const blocksValidatorSchema = yup.array().of(blockNodeValidator);
|
124
|
+
const blocksValidator = () => blocksValidatorSchema;
|
125
125
|
export {
|
126
|
-
blocksValidator
|
126
|
+
blocksValidator
|
127
127
|
};
|
128
128
|
//# sourceMappingURL=blocks-validator.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst
|
1
|
+
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":[],"mappings":";AAEA,MAAM,oBAAoB,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAM,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,MAAM,IACH,OAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA,CAAC,SAAkB;AACV,aAAA,OAAO,SAAS,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF;AAAA,EACF,MAAM,IAAI,QAAQ;AAAA,EAClB,QAAQ,IAAI,QAAQ;AAAA,EACpB,WAAW,IAAI,QAAQ;AAAA,EACvB,eAAe,IAAI,QAAQ;AAAA,EAC3B,MAAM,IAAI,QAAQ;AACpB,CAAC;AAED,MAAM,iBAAiB,CAAC,SAAiB;AACnC,MAAA;AAEE,QAAA,IAAI,KAAK,WAAW,GAAG,IAAI,oBAAoB,IAAI,KAAK,IAAI;AAAA,WACzD,OAAO;AACP,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEA,MAAM,oBAAoB,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAM,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,KAAK,IACF,OAAO,EACP,KAAK,eAAe,gCAAgC,CAAC,UAAU,eAAe,SAAS,EAAE,CAAC;AAAA,EAC7F,UAAU,IAAI,MAAA,EAAQ,GAAG,iBAAiB,EAAE,SAAS;AACvD,CAAC;AAGD,MAAM,sBAA2B,IAAI,KAAK,CAAC,UAA4B;AACrE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA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,OAAO,EAAE,SAAS;AAAA,IAC5B,YAAY,IAAI,OAAO,EAAE,SAAS;AAAA,IAClC,UAAU,IAAI,OAAO,EAAE,SAAS;AAAA,IAChC,mBAAmB,IAAI,MAAM,EAAE,SAAS;AAAA,IACxC,WAAW,IAAI,OAAO,EAAE,SAAS;AAAA,IACjC,WAAW,IAAI,OAAO,EAAE,SAAS;AAAA,EAAA,CAClC;AAAA,EACD,UAAU,IAAI,MAAA,EAAQ,GAAG,mBAAmB,EAAE,SAAS;AACzD,CAAC;AAGD,MAAM,qBAA0B,IAAI,KAAK,CAAC,UAA4B;AACpE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAO,IAAI,MAAM,EAAE,KAAK,gBAAgB,iCAAiC,MAAM;AACtE,eAAA;AAAA,MAAA,CACR;AAAA,EACL;AACF,CAAC;AAED,MAAM,wBAAwB,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAExD,MAAM,kBAAkB,MAAM;"}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* Entity validator
|
3
3
|
* Module that will validate input data for entity creation or edition
|
4
4
|
*/
|
5
|
-
import { Modules, Struct } from '@strapi/types';
|
5
|
+
import { Modules, Struct, Schema } from '@strapi/types';
|
6
6
|
export type ComponentContext = {
|
7
7
|
parentContent: {
|
8
8
|
model: Struct.Schema;
|
@@ -11,6 +11,7 @@ export type ComponentContext = {
|
|
11
11
|
};
|
12
12
|
pathToComponent: string[];
|
13
13
|
repeatableData: Modules.EntityValidator.Entity[];
|
14
|
+
fullDynamicZoneContent?: Schema.Attribute.Value<Schema.Attribute.DynamicZone>;
|
14
15
|
};
|
15
16
|
interface ValidatorContext {
|
16
17
|
isDraft?: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAO,MAAM,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAO,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa7D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,aAAa,EAAE;QAEb,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QAErB,EAAE,CAAC,EAAE,MAAM,CAAC;QAGZ,OAAO,CAAC,EAAE,gBAAgB,CAAC;KAC5B,CAAC;IAEF,eAAe,EAAE,MAAM,EAAE,CAAC;IAG1B,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;IACjD,sBAAsB,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;CAC/E,CAAC;AAWF,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AA+gBD,QAAA,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,eAG9C,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -131,8 +131,8 @@ const createRelationValidator = ({
|
|
131
131
|
};
|
132
132
|
const createScalarAttributeValidator = (createOrUpdate) => (metas, options) => {
|
133
133
|
let validator;
|
134
|
-
if (fp.has(metas.attr.type, validators)) {
|
135
|
-
validator = validators[metas.attr.type](metas, options);
|
134
|
+
if (fp.has(metas.attr.type, validators.Validators)) {
|
135
|
+
validator = validators.Validators[metas.attr.type](metas, options);
|
136
136
|
} else {
|
137
137
|
validator = yup.mixed();
|
138
138
|
}
|
@@ -149,14 +149,14 @@ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
|
|
149
149
|
} else if (isScalarAttribute(metas.attr)) {
|
150
150
|
validator = createScalarAttributeValidator(createOrUpdate)(metas, options);
|
151
151
|
} else {
|
152
|
-
if (metas.attr.type === "component") {
|
152
|
+
if (metas.attr.type === "component" && metas.componentContext) {
|
153
153
|
const pathToComponent = [
|
154
154
|
...metas?.componentContext?.pathToComponent ?? [],
|
155
155
|
metas.updatedAttribute.name
|
156
156
|
];
|
157
157
|
const repeatableData = metas.attr.repeatable && pathToComponent.length === 1 ? metas.updatedAttribute.value : metas.componentContext?.repeatableData;
|
158
158
|
const newComponentContext = {
|
159
|
-
...metas
|
159
|
+
...metas.componentContext,
|
160
160
|
pathToComponent,
|
161
161
|
repeatableData
|
162
162
|
};
|
@@ -168,19 +168,14 @@ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
|
|
168
168
|
},
|
169
169
|
options
|
170
170
|
);
|
171
|
-
} else if (metas.attr.type === "dynamiczone") {
|
172
|
-
const pathToComponent = [
|
173
|
-
...metas?.componentContext?.pathToComponent ?? [],
|
174
|
-
metas.updatedAttribute.name
|
175
|
-
];
|
171
|
+
} else if (metas.attr.type === "dynamiczone" && metas.componentContext) {
|
176
172
|
const newComponentContext = {
|
177
|
-
...metas
|
178
|
-
|
173
|
+
...metas.componentContext,
|
174
|
+
fullDynamicZoneContent: metas.updatedAttribute.value,
|
175
|
+
pathToComponent: [...metas.componentContext.pathToComponent, metas.updatedAttribute.name]
|
179
176
|
};
|
180
|
-
|
181
|
-
|
182
|
-
options
|
183
|
-
);
|
177
|
+
Object.assign(metas, { componentContext: newComponentContext });
|
178
|
+
validator = createDzValidator(createOrUpdate)(metas, options);
|
184
179
|
} else if (metas.attr.type === "relation") {
|
185
180
|
validator = createRelationValidator({
|
186
181
|
attr: metas.attr,
|