@strapi/core 0.0.0-experimental.3f7b2587c5e3d548262671895cf11d8bf8c → 0.0.0-experimental.651a6b8ded3c452fedf2a8598f08c51c214e6cf7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +7 -3
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +6 -2
- package/dist/Strapi.mjs.map +1 -1
- package/dist/core-api/controller/collection-type.d.ts +1 -1
- package/dist/core-api/controller/collection-type.d.ts.map +1 -1
- package/dist/core-api/controller/collection-type.js +9 -20
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/collection-type.mjs +8 -20
- package/dist/core-api/controller/collection-type.mjs.map +1 -1
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +2 -2
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +2 -2
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/single-type.d.ts +1 -1
- package/dist/core-api/controller/single-type.d.ts.map +1 -1
- package/dist/core-api/controller/single-type.js +6 -11
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/single-type.mjs +5 -11
- package/dist/core-api/controller/single-type.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +2 -11
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +4 -18
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +4 -18
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/service/collection-type.d.ts +28 -5
- package/dist/core-api/service/collection-type.d.ts.map +1 -1
- package/dist/core-api/service/collection-type.js +47 -49
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs +47 -50
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/core-service.d.ts +4 -0
- package/dist/core-api/service/core-service.d.ts.map +1 -0
- package/dist/core-api/service/core-service.js +12 -0
- package/dist/core-api/service/core-service.js.map +1 -0
- package/dist/core-api/service/core-service.mjs +12 -0
- package/dist/core-api/service/core-service.mjs.map +1 -0
- package/dist/core-api/service/index.js +2 -2
- package/dist/core-api/service/index.js.map +1 -1
- package/dist/core-api/service/index.mjs +4 -4
- package/dist/core-api/service/index.mjs.map +1 -1
- package/dist/core-api/service/pagination.d.ts +1 -5
- package/dist/core-api/service/pagination.d.ts.map +1 -1
- package/dist/core-api/service/pagination.js +0 -11
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/core-api/service/pagination.mjs +0 -11
- package/dist/core-api/service/pagination.mjs.map +1 -1
- package/dist/core-api/service/single-type.d.ts +14 -8
- package/dist/core-api/service/single-type.d.ts.map +1 -1
- package/dist/core-api/service/single-type.js +36 -50
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs +35 -50
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +2 -12
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +2 -12
- package/dist/factories.mjs.map +1 -1
- package/dist/registries/content-types.d.ts.map +1 -1
- package/dist/registries/content-types.js +1 -2
- package/dist/registries/content-types.js.map +1 -1
- package/dist/registries/content-types.mjs +1 -2
- package/dist/registries/content-types.mjs.map +1 -1
- package/dist/services/document-service/common.d.ts +4 -0
- package/dist/services/document-service/common.d.ts.map +1 -0
- package/dist/services/document-service/common.js +7 -0
- package/dist/services/document-service/common.js.map +1 -0
- package/dist/services/document-service/common.mjs +7 -0
- package/dist/services/document-service/common.mjs.map +1 -0
- package/dist/services/document-service/document-engine.d.ts.map +1 -1
- package/dist/services/document-service/document-engine.js +117 -76
- package/dist/services/document-service/document-engine.js.map +1 -1
- package/dist/services/document-service/document-engine.mjs +112 -71
- package/dist/services/document-service/document-engine.mjs.map +1 -1
- package/dist/services/document-service/draft-and-publish.d.ts +24 -0
- package/dist/services/document-service/draft-and-publish.d.ts.map +1 -0
- package/dist/services/document-service/draft-and-publish.js +41 -0
- package/dist/services/document-service/draft-and-publish.js.map +1 -0
- package/dist/services/document-service/draft-and-publish.mjs +41 -0
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -0
- package/dist/services/document-service/{document-service.d.ts → index.d.ts} +2 -4
- package/dist/services/document-service/index.d.ts.map +1 -0
- package/dist/services/document-service/index.js +22 -0
- package/dist/services/document-service/index.js.map +1 -0
- package/dist/services/document-service/index.mjs +22 -0
- package/dist/services/document-service/index.mjs.map +1 -0
- package/dist/services/document-service/internationalization.d.ts +8 -0
- package/dist/services/document-service/internationalization.d.ts.map +1 -0
- package/dist/services/document-service/internationalization.js +54 -0
- package/dist/services/document-service/internationalization.js.map +1 -0
- package/dist/services/document-service/internationalization.mjs +54 -0
- package/dist/services/document-service/internationalization.mjs.map +1 -0
- package/dist/services/document-service/middlewares.d.ts +8 -0
- package/dist/services/document-service/middlewares.d.ts.map +1 -0
- package/dist/services/document-service/middlewares.js +46 -0
- package/dist/services/document-service/middlewares.js.map +1 -0
- package/dist/services/document-service/middlewares.mjs +46 -0
- package/dist/services/document-service/middlewares.mjs.map +1 -0
- package/dist/services/document-service/repositories/content-type.d.ts +3 -0
- package/dist/services/document-service/repositories/content-type.d.ts.map +1 -0
- package/dist/services/document-service/repositories/content-type.js +139 -0
- package/dist/services/document-service/repositories/content-type.js.map +1 -0
- package/dist/services/document-service/repositories/content-type.mjs +139 -0
- package/dist/services/document-service/repositories/content-type.mjs.map +1 -0
- package/dist/services/document-service/transform/data.d.ts +5 -0
- package/dist/services/document-service/transform/data.d.ts.map +1 -0
- package/dist/services/document-service/transform/data.js +13 -0
- package/dist/services/document-service/transform/data.js.map +1 -0
- package/dist/services/document-service/transform/data.mjs +13 -0
- package/dist/services/document-service/transform/data.mjs.map +1 -0
- package/dist/services/document-service/transform/fields.d.ts +5 -0
- package/dist/services/document-service/transform/fields.d.ts.map +1 -0
- package/dist/services/document-service/transform/fields.js +24 -0
- package/dist/services/document-service/transform/fields.js.map +1 -0
- package/dist/services/document-service/transform/fields.mjs +24 -0
- package/dist/services/document-service/transform/fields.mjs.map +1 -0
- package/dist/services/document-service/transform/id-map.d.ts +23 -0
- package/dist/services/document-service/transform/id-map.d.ts.map +1 -0
- package/dist/services/document-service/transform/id-map.js +72 -0
- package/dist/services/document-service/transform/id-map.js.map +1 -0
- package/dist/services/document-service/transform/id-map.mjs +72 -0
- package/dist/services/document-service/transform/id-map.mjs.map +1 -0
- package/dist/services/document-service/transform/id-transform.d.ts +19 -0
- package/dist/services/document-service/transform/id-transform.d.ts.map +1 -0
- package/dist/services/document-service/transform/id-transform.js +27 -0
- package/dist/services/document-service/transform/id-transform.js.map +1 -0
- package/dist/services/document-service/transform/id-transform.mjs +27 -0
- package/dist/services/document-service/transform/id-transform.mjs.map +1 -0
- package/dist/services/document-service/transform/populate.d.ts +3 -0
- package/dist/services/document-service/transform/populate.d.ts.map +1 -0
- package/dist/services/document-service/transform/populate.js +21 -0
- package/dist/services/document-service/transform/populate.js.map +1 -0
- package/dist/services/document-service/transform/populate.mjs +21 -0
- package/dist/services/document-service/transform/populate.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +13 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.js +79 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs +79 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +10 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.js +117 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +117 -0
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/data.d.ts +4 -0
- package/dist/services/document-service/transform/relations/utils/data.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/data.js +12 -0
- package/dist/services/document-service/transform/relations/utils/data.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/data.mjs +12 -0
- package/dist/services/document-service/transform/relations/utils/data.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/i18n.d.ts +10 -0
- package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/i18n.js +31 -0
- package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/i18n.mjs +31 -0
- package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts +12 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -0
- package/dist/services/document-service/transform/types.d.ts +13 -0
- package/dist/services/document-service/transform/types.d.ts.map +1 -0
- package/dist/services/document-service/utils/populate.d.ts +3 -0
- package/dist/services/document-service/utils/populate.d.ts.map +1 -0
- package/dist/services/document-service/utils/populate.js +41 -0
- package/dist/services/document-service/utils/populate.js.map +1 -0
- package/dist/services/document-service/utils/populate.mjs +41 -0
- package/dist/services/document-service/utils/populate.mjs.map +1 -0
- package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +22 -2
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +22 -2
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +7 -8
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +7 -8
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.d.ts.map +1 -1
- package/dist/services/server/compose-endpoint.js +3 -0
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs +3 -0
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/webhook-store.js +2 -2
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +2 -2
- package/dist/services/webhook-store.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +174 -3
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +80 -41
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +79 -41
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +14 -14
- package/dist/core-api/service/get-fetch-params.d.ts +0 -7
- package/dist/core-api/service/get-fetch-params.d.ts.map +0 -1
- package/dist/core-api/service/get-fetch-params.js +0 -14
- package/dist/core-api/service/get-fetch-params.js.map +0 -1
- package/dist/core-api/service/get-fetch-params.mjs +0 -14
- package/dist/core-api/service/get-fetch-params.mjs.map +0 -1
- package/dist/services/document-service/document-service.d.ts.map +0 -1
- package/dist/services/document-service/document-service.js +0 -132
- package/dist/services/document-service/document-service.js.map +0 -1
- package/dist/services/document-service/document-service.mjs +0 -132
- package/dist/services/document-service/document-service.mjs.map +0 -1
- package/dist/services/document-service/middlewares/defaults/draft-and-publish.d.ts +0 -26
- package/dist/services/document-service/middlewares/defaults/draft-and-publish.d.ts.map +0 -1
- package/dist/services/document-service/middlewares/defaults/draft-and-publish.js +0 -58
- package/dist/services/document-service/middlewares/defaults/draft-and-publish.js.map +0 -1
- package/dist/services/document-service/middlewares/defaults/draft-and-publish.mjs +0 -58
- package/dist/services/document-service/middlewares/defaults/draft-and-publish.mjs.map +0 -1
- package/dist/services/document-service/middlewares/defaults/index.d.ts +0 -3
- package/dist/services/document-service/middlewares/defaults/index.d.ts.map +0 -1
- package/dist/services/document-service/middlewares/defaults/index.js +0 -82
- package/dist/services/document-service/middlewares/defaults/index.js.map +0 -1
- package/dist/services/document-service/middlewares/defaults/index.mjs +0 -82
- package/dist/services/document-service/middlewares/defaults/index.mjs.map +0 -1
- package/dist/services/document-service/middlewares/defaults/locales.d.ts +0 -18
- package/dist/services/document-service/middlewares/defaults/locales.d.ts.map +0 -1
- package/dist/services/document-service/middlewares/defaults/locales.js +0 -50
- package/dist/services/document-service/middlewares/defaults/locales.js.map +0 -1
- package/dist/services/document-service/middlewares/defaults/locales.mjs +0 -50
- package/dist/services/document-service/middlewares/defaults/locales.mjs.map +0 -1
- package/dist/services/document-service/middlewares/index.d.ts +0 -11
- package/dist/services/document-service/middlewares/index.d.ts.map +0 -1
- package/dist/services/document-service/middlewares/index.js +0 -59
- package/dist/services/document-service/middlewares/index.js.map +0 -1
- package/dist/services/document-service/middlewares/index.mjs +0 -59
- package/dist/services/document-service/middlewares/index.mjs.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { contentTypes } from "@strapi/utils";
|
|
2
|
+
const getDeepPopulate = (uid) => {
|
|
3
|
+
const model = strapi.getModel(uid);
|
|
4
|
+
const attributes = Object.entries(model.attributes);
|
|
5
|
+
return attributes.reduce((acc, [attributeName, attribute]) => {
|
|
6
|
+
switch (attribute.type) {
|
|
7
|
+
case "relation": {
|
|
8
|
+
const isVisible = contentTypes.isVisibleAttribute(model, attributeName);
|
|
9
|
+
if (isVisible) {
|
|
10
|
+
acc[attributeName] = { fields: ["document_id", "locale"] };
|
|
11
|
+
}
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
case "media": {
|
|
15
|
+
acc[attributeName] = { fields: ["id"] };
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case "component": {
|
|
19
|
+
const populate = getDeepPopulate(attribute.component);
|
|
20
|
+
acc[attributeName] = { populate };
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case "dynamiczone": {
|
|
24
|
+
const populatedComponents = (attribute.components || []).reduce(
|
|
25
|
+
(acc2, componentUID) => {
|
|
26
|
+
acc2[componentUID] = { populate: getDeepPopulate(componentUID) };
|
|
27
|
+
return acc2;
|
|
28
|
+
},
|
|
29
|
+
{}
|
|
30
|
+
);
|
|
31
|
+
acc[attributeName] = { on: populatedComponents };
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
getDeepPopulate
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=populate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populate.mjs","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Should this just be a plain list?\n // Ignore createdBy, updatedBy, ...\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n if (isVisible) {\n acc[attributeName] = { fields: ['document_id', 'locale'] };\n }\n break;\n }\n\n case 'media': {\n acc[attributeName] = { fields: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component);\n acc[attributeName] = { populate };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: Common.UID.Component) => {\n acc[componentUID] = { populate: getDeepPopulate(componentUID) };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n};\n"],"names":["acc"],"mappings":";AAIa,MAAA,kBAAkB,CAAC,QAA2B;AACnD,QAAA,QAAQ,OAAO,SAAS,GAAG;AACjC,QAAM,aAAa,OAAO,QAAQ,MAAM,UAAU;AAElD,SAAO,WAAW,OAAO,CAAC,KAAU,CAAC,eAAe,SAAS,MAAM;AACjE,YAAQ,UAAU,MAAM;AAAA,MACtB,KAAK,YAAY;AAGf,cAAM,YAAY,aAAa,mBAAmB,OAAO,aAAa;AACtE,YAAI,WAAW;AACb,cAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,eAAe,QAAQ;QACzD;AACA;AAAA,MACF;AAAA,MAEA,KAAK,SAAS;AACZ,YAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;AACtC;AAAA,MACF;AAAA,MAEA,KAAK,aAAa;AACV,cAAA,WAAW,gBAAgB,UAAU,SAAS;AAChD,YAAA,aAAa,IAAI,EAAE;AACvB;AAAA,MACF;AAAA,MAEA,KAAK,eAAe;AAElB,cAAM,uBAAuB,UAAU,cAAc,CAAI,GAAA;AAAA,UACvD,CAACA,MAAU,iBAAuC;AAChDA,iBAAI,YAAY,IAAI,EAAE,UAAU,gBAAgB,YAAY;AACrDA,mBAAAA;AAAAA,UACT;AAAA,UACA,CAAC;AAAA,QAAA;AAGH,YAAI,aAAa,IAAI,EAAE,IAAI,oBAAoB;AAC/C;AAAA,MACF;AAAA,IAGF;AAEO,WAAA;AAAA,EACT,GAAG,CAAE,CAAA;AACP;"}
|
|
@@ -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;gCAyKb,GAAG,WAAW,GAAG;AAAxC,wBAA6D"}
|
|
@@ -15,9 +15,17 @@ const textNodeValidator = strapiUtils.yup.object().shape({
|
|
|
15
15
|
strikethrough: strapiUtils.yup.boolean(),
|
|
16
16
|
code: strapiUtils.yup.boolean()
|
|
17
17
|
});
|
|
18
|
+
const checkValidLink = (link) => {
|
|
19
|
+
try {
|
|
20
|
+
new URL(link.startsWith("/") ? `https://strapi.io${link}` : link);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
18
26
|
const linkNodeValidator = strapiUtils.yup.object().shape({
|
|
19
27
|
type: strapiUtils.yup.string().equals(["link"]).required(),
|
|
20
|
-
url: strapiUtils.yup.string().url()
|
|
28
|
+
url: strapiUtils.yup.string().test("invalid-url", "Please specify a valid link.", (value) => checkValidLink(value ?? "")),
|
|
21
29
|
children: strapiUtils.yup.array().of(textNodeValidator).required()
|
|
22
30
|
});
|
|
23
31
|
const inlineNodeValidator = strapiUtils.yup.lazy((value) => {
|
|
@@ -54,10 +62,22 @@ const listItemNode = strapiUtils.yup.object().shape({
|
|
|
54
62
|
type: strapiUtils.yup.string().equals(["list-item"]).required(),
|
|
55
63
|
children: strapiUtils.yup.array().of(inlineNodeValidator).required()
|
|
56
64
|
});
|
|
65
|
+
const listChildrenValidator = strapiUtils.yup.lazy((value) => {
|
|
66
|
+
switch (value.type) {
|
|
67
|
+
case "list":
|
|
68
|
+
return listNodeValidator;
|
|
69
|
+
case "list-item":
|
|
70
|
+
return listItemNode;
|
|
71
|
+
default:
|
|
72
|
+
return strapiUtils.yup.mixed().test("invalid-type", "Inline node must be list-item or list", () => {
|
|
73
|
+
return false;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
57
77
|
const listNodeValidator = strapiUtils.yup.object().shape({
|
|
58
78
|
type: strapiUtils.yup.string().equals(["list"]).required(),
|
|
59
79
|
format: strapiUtils.yup.string().equals(["ordered", "unordered"]).required(),
|
|
60
|
-
children: strapiUtils.yup.array().of(
|
|
80
|
+
children: strapiUtils.yup.array().of(listChildrenValidator).min(1, "List node children must have at least one ListItem or ListNode").required()
|
|
61
81
|
});
|
|
62
82
|
const imageNodeValidator = strapiUtils.yup.object().shape({
|
|
63
83
|
type: strapiUtils.yup.string().equals(["image"]).required(),
|
|
@@ -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 linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup.string().url()
|
|
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 blocksValidator = yup.array().of(blockNodeValidator);\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport default (metas: any, options: any) => blocksValidator;\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;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,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,kBAAkBA,YAAAA,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAGzD,MAAA,oBAAe,CAAC,OAAY,YAAiB;;"}
|
|
@@ -14,9 +14,17 @@ const textNodeValidator = yup.object().shape({
|
|
|
14
14
|
strikethrough: yup.boolean(),
|
|
15
15
|
code: yup.boolean()
|
|
16
16
|
});
|
|
17
|
+
const checkValidLink = (link) => {
|
|
18
|
+
try {
|
|
19
|
+
new URL(link.startsWith("/") ? `https://strapi.io${link}` : link);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
17
25
|
const linkNodeValidator = yup.object().shape({
|
|
18
26
|
type: yup.string().equals(["link"]).required(),
|
|
19
|
-
url: yup.string().url()
|
|
27
|
+
url: yup.string().test("invalid-url", "Please specify a valid link.", (value) => checkValidLink(value ?? "")),
|
|
20
28
|
children: yup.array().of(textNodeValidator).required()
|
|
21
29
|
});
|
|
22
30
|
const inlineNodeValidator = yup.lazy((value) => {
|
|
@@ -53,10 +61,22 @@ const listItemNode = yup.object().shape({
|
|
|
53
61
|
type: yup.string().equals(["list-item"]).required(),
|
|
54
62
|
children: yup.array().of(inlineNodeValidator).required()
|
|
55
63
|
});
|
|
64
|
+
const listChildrenValidator = yup.lazy((value) => {
|
|
65
|
+
switch (value.type) {
|
|
66
|
+
case "list":
|
|
67
|
+
return listNodeValidator;
|
|
68
|
+
case "list-item":
|
|
69
|
+
return listItemNode;
|
|
70
|
+
default:
|
|
71
|
+
return yup.mixed().test("invalid-type", "Inline node must be list-item or list", () => {
|
|
72
|
+
return false;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
56
76
|
const listNodeValidator = yup.object().shape({
|
|
57
77
|
type: yup.string().equals(["list"]).required(),
|
|
58
78
|
format: yup.string().equals(["ordered", "unordered"]).required(),
|
|
59
|
-
children: yup.array().of(
|
|
79
|
+
children: yup.array().of(listChildrenValidator).min(1, "List node children must have at least one ListItem or ListNode").required()
|
|
60
80
|
});
|
|
61
81
|
const imageNodeValidator = yup.object().shape({
|
|
62
82
|
type: yup.string().equals(["image"]).required(),
|
|
@@ -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 linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup.string().url()
|
|
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 blocksValidator = yup.array().of(blockNodeValidator);\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport default (metas: any, options: any) => blocksValidator;\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,O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T,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,kBAAkB,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAGzD,MAAA,oBAAe,CAAC,OAAY,YAAiB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/validators.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAKvD,UAAU,cAAc,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG;IACvD,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC;IAC1B,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IACnD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACxC;AAED,UAAU,gBAAgB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/validators.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAKvD,UAAU,cAAc,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG;IACvD,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC;IAC1B,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IACnD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACxC;AAED,UAAU,gBAAgB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;;;;;;;;AA0PD,wBAmBE"}
|
|
@@ -39,18 +39,17 @@ const addUniqueValidator = (validator, { attr, model, updatedAttribute, entity }
|
|
|
39
39
|
}
|
|
40
40
|
return validator.test("unique", "This attribute must be unique", async (value) => {
|
|
41
41
|
const isPublish = options.isDraft === false;
|
|
42
|
-
|
|
43
|
-
if (___default.default.isNil(valueToCheck)) {
|
|
42
|
+
if (___default.default.isNil(value)) {
|
|
44
43
|
return true;
|
|
45
44
|
}
|
|
46
|
-
if (!isPublish &&
|
|
45
|
+
if (!isPublish && value === entity?.[updatedAttribute.name]) {
|
|
47
46
|
return true;
|
|
48
47
|
}
|
|
49
|
-
const record = await strapi.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
[updatedAttribute.name]:
|
|
48
|
+
const record = await strapi.db.query(model.uid).findOne({
|
|
49
|
+
where: {
|
|
50
|
+
locale: options.locale,
|
|
51
|
+
publishedAt: options.isDraft ? null : { $notNull: true },
|
|
52
|
+
[updatedAttribute.name]: value,
|
|
54
53
|
...entity?.id ? { id: { $ne: entity.id } } : {}
|
|
55
54
|
}
|
|
56
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport strapiUtils from '@strapi/utils';\nimport type { Attribute, Schema } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nconst { yup } = strapiUtils;\n\ninterface ValidatorMetas<TAttribute extends Attribute.Any> {\n attr: TAttribute;\n model: Schema.ContentType;\n updatedAttribute: { name: string; value: unknown };\n entity: Record<string, unknown> | null;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr, model, updatedAttribute, entity }: ValidatorMetas<Attribute.Any & Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n // When publishing, the value will not have changed so we take the value from the entity\n const valueToCheck = isPublish ? entity?.[updatedAttribute.name] : value;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(valueToCheck)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && valueToCheck === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n /**\n * At this point we know that we are creating a new entry, publishing an entry or that the unique field value has changed\n * We check if there is an entry of this content type in the same locale, publication state and with the same unique field value\n */\n\n const record = await strapi.documents(model.uid).findFirst({\n locale: options.locale,\n status: options.isDraft ? 'draft' : 'published',\n filters: {\n [updatedAttribute.name]: valueToCheck,\n ...(entity?.id ? { id: { $ne: entity.id } } : {}),\n },\n });\n\n return !record;\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (metas: ValidatorMetas<Attribute.Email>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Attribute.Integer | Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Attribute.Decimal | Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<Attribute.Date | Attribute.DateTime | Attribute.Time | Attribute.Timestamp>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":["strapiUtils","_"],"mappings":";;;;;;;AAKA,MAAM,EAAE,IAAQ,IAAAA;AAmBhB,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAaC,WAAE,QAAA,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAaA,mBAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGIA,mBAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAAI;AAKvD,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGIA,mBAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAAI;AAKvD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;AAAA,EACtB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;;"}
|
|
1
|
+
{"version":3,"file":"validators.js","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport strapiUtils from '@strapi/utils';\nimport type { Attribute, Schema } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nconst { yup } = strapiUtils;\n\ninterface ValidatorMetas<TAttribute extends Attribute.Any> {\n attr: TAttribute;\n model: Schema.ContentType;\n updatedAttribute: { name: string; value: unknown };\n entity: Record<string, unknown> | null;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr, model, updatedAttribute, entity }: ValidatorMetas<Attribute.Any & Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(value)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && value === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n /**\n * At this point we know that we are creating a new entry, publishing an entry or that the unique field value has changed\n * We check if there is an entry of this content type in the same locale, publication state and with the same unique field value\n */\n const record = await strapi.db.query(model.uid).findOne({\n where: {\n locale: options.locale,\n publishedAt: options.isDraft ? null : { $notNull: true },\n [updatedAttribute.name]: value,\n ...(entity?.id ? { id: { $ne: entity.id } } : {}),\n },\n });\n\n return !record;\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (metas: ValidatorMetas<Attribute.Email>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Attribute.Integer | Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Attribute.Decimal | Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<Attribute.Date | Attribute.DateTime | Attribute.Time | Attribute.Timestamp>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":["strapiUtils","_"],"mappings":";;;;;;;AAKA,MAAM,EAAE,IAAQ,IAAAA;AAmBhB,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAaC,WAAE,QAAA,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAaA,mBAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,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AAClD;AAEA,MAAe,aAAA;AAAA,EACb,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS,MAAM,IAAI,QAAQ;AAAA,EAC3B,KAAK;AAAA,EACL,MAAM,MAAM,IAAI,MAAM;AAAA,EACtB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;;"}
|
|
@@ -35,18 +35,17 @@ const addUniqueValidator = (validator, { attr, model, updatedAttribute, entity }
|
|
|
35
35
|
}
|
|
36
36
|
return validator.test("unique", "This attribute must be unique", async (value) => {
|
|
37
37
|
const isPublish = options.isDraft === false;
|
|
38
|
-
|
|
39
|
-
if (_.isNil(valueToCheck)) {
|
|
38
|
+
if (_.isNil(value)) {
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
42
|
-
if (!isPublish &&
|
|
41
|
+
if (!isPublish && value === entity?.[updatedAttribute.name]) {
|
|
43
42
|
return true;
|
|
44
43
|
}
|
|
45
|
-
const record = await strapi.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[updatedAttribute.name]:
|
|
44
|
+
const record = await strapi.db.query(model.uid).findOne({
|
|
45
|
+
where: {
|
|
46
|
+
locale: options.locale,
|
|
47
|
+
publishedAt: options.isDraft ? null : { $notNull: true },
|
|
48
|
+
[updatedAttribute.name]: value,
|
|
50
49
|
...entity?.id ? { id: { $ne: entity.id } } : {}
|
|
51
50
|
}
|
|
52
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.mjs","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport strapiUtils from '@strapi/utils';\nimport type { Attribute, Schema } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nconst { yup } = strapiUtils;\n\ninterface ValidatorMetas<TAttribute extends Attribute.Any> {\n attr: TAttribute;\n model: Schema.ContentType;\n updatedAttribute: { name: string; value: unknown };\n entity: Record<string, unknown> | null;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr, model, updatedAttribute, entity }: ValidatorMetas<Attribute.Any & Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n // When publishing, the value will not have changed so we take the value from the entity\n const valueToCheck = isPublish ? entity?.[updatedAttribute.name] : value;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(valueToCheck)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && valueToCheck === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n /**\n * At this point we know that we are creating a new entry, publishing an entry or that the unique field value has changed\n * We check if there is an entry of this content type in the same locale, publication state and with the same unique field value\n */\n\n const record = await strapi.documents(model.uid).findFirst({\n locale: options.locale,\n status: options.isDraft ? 'draft' : 'published',\n filters: {\n [updatedAttribute.name]: valueToCheck,\n ...(entity?.id ? { id: { $ne: entity.id } } : {}),\n },\n });\n\n return !record;\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (metas: ValidatorMetas<Attribute.Email>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Attribute.Integer | Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Attribute.Decimal | Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<Attribute.Date | Attribute.DateTime | Attribute.Time | Attribute.Timestamp>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":[],"mappings":";;;AAKA,MAAM,EAAE,IAAQ,IAAA;AAmBhB,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAa,EAAE,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAa,EAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,EAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,EAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAAI;AAKvD,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAAI;AAKvD,MAAM,0BAA0B,CAC9B,WACA;AAAA,EACE;AACF,MASG;A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P,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;"}
|
|
1
|
+
{"version":3,"file":"validators.mjs","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport strapiUtils from '@strapi/utils';\nimport type { Attribute, Schema } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nconst { yup } = strapiUtils;\n\ninterface ValidatorMetas<TAttribute extends Attribute.Any> {\n attr: TAttribute;\n model: Schema.ContentType;\n updatedAttribute: { name: string; value: unknown };\n entity: Record<string, unknown> | null;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr, model, updatedAttribute, entity }: ValidatorMetas<Attribute.Any & Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(value)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && value === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n /**\n * At this point we know that we are creating a new entry, publishing an entry or that the unique field value has changed\n * We check if there is an entry of this content type in the same locale, publication state and with the same unique field value\n */\n const record = await strapi.db.query(model.uid).findOne({\n where: {\n locale: options.locale,\n publishedAt: options.isDraft ? null : { $notNull: true },\n [updatedAttribute.name]: value,\n ...(entity?.id ? { id: { $ne: entity.id } } : {}),\n },\n });\n\n return !record;\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (metas: ValidatorMetas<Attribute.Email>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Attribute.Integer | Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Attribute.Decimal | Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<Attribute.Date | Attribute.DateTime | Attribute.Time | Attribute.Timestamp>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":[],"mappings":";;;AAKA,MAAM,EAAE,IAAQ,IAAA;AAmBhB,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAa,EAAE,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAa,EAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,EAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,EAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGI,EAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAA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SAAS,MAAM,IAAI,QAAQ;AAAA,EAC3B,KAAK;AAAA,EACL,MAAM,MAAM,IAAI,MAAM;AAAA,EACtB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.d.ts","sourceRoot":"","sources":["../../../src/services/server/compose-endpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,MAAM,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"compose-endpoint.d.ts","sourceRoot":"","sources":["../../../src/services/server/compose-endpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,MAAM,MAAM,aAAa,CAAC;iCAoET,MAAM,aAIb,OAAO,KAAK;YAAwB,MAAM;;AAJ3D,wBAiCE"}
|
|
@@ -30,6 +30,9 @@ const createAuthorizeMiddleware = (strapi) => async (ctx, next) => {
|
|
|
30
30
|
return ctx.unauthorized();
|
|
31
31
|
}
|
|
32
32
|
if (error instanceof strapiUtils.errors.ForbiddenError) {
|
|
33
|
+
if (error instanceof strapiUtils.errors.PolicyError) {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
33
36
|
return ctx.forbidden();
|
|
34
37
|
}
|
|
35
38
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.js","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Strapi, Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { resolvePolicies } from './policy';\n\nconst getMethod = (route: Common.Route) => {\n return trim(toLower(route.method)) as Lowercase<Common.Route['method']>;\n};\n\nconst getPath = (route: Common.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Common.Route): Common.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Common.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Common.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n const policies = resolvePolicies(route);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n ...policies,\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (name: string, { pluginName, apiName }: Common.RouteInfo, strapi: Strapi) => {\n let ctrl: Common.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as Common.UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Common.Route, strapi: Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":["trim","toLower","prop","errors","isNil","resolveRouteMiddlewares","resolvePolicies","compose","castArray"],"mappings":";;;;;;;;AASA,MAAM,YAAY,CAAC,UAAwB;AACzC,SAAOA,EAAK,KAAAC,EAAA,QAAQ,MAAM,MAAM,CAAC;AACnC;AAEA,MAAM,UAAU,CAAC,UAAwBD,EAAA,KAAK,MAAM,IAAI;AAExD,MAAM,4BACJ,CAAC,cACD,CAAC,KAAK,SAAS;AACb,QAAM,QAAQ;AAAA,IACZ,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU,CAAC;AAAA,EAAA;AAG/B,MAAI,MAAM,QAAQ;AAClB,SAAO,KAAK;AACd;AAEF,MAAM,gBAAgBE,EAAAA,KAAK,aAAa;AAExC,MAAM,4BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,QAAM,EAAE,MAAM,UAAU,IAAI;AAEtB,QAAA,cAAc,OAAO,IAAI,MAAM;AAEjC,MAAA;AACF,UAAM,YAAY,OAAO,MAAM,cAAc,KAAK,CAAC;AAEnD,WAAO,MAAM,KAAK;AAAA,WACX,OAAO;AACV,QAAA,iBAAiBC,mBAAO,mBAAmB;AAC7C,aAAO,IAAI;IACb;AAEI,QAAA,iBAAiBA,mBAAO,gBAAgB;
|
|
1
|
+
{"version":3,"file":"compose-endpoint.js","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Strapi, Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { resolvePolicies } from './policy';\n\nconst getMethod = (route: Common.Route) => {\n return trim(toLower(route.method)) as Lowercase<Common.Route['method']>;\n};\n\nconst getPath = (route: Common.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Common.Route): Common.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n // allow PolicyError as an exception to throw a publicly visible message in the API\n if (error instanceof errors.PolicyError) {\n throw error;\n }\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Common.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Common.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n const policies = resolvePolicies(route);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n ...policies,\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (name: string, { pluginName, apiName }: Common.RouteInfo, strapi: Strapi) => {\n let ctrl: Common.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as Common.UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Common.Route, strapi: Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":["trim","toLower","prop","errors","isNil","resolveRouteMiddlewares","resolvePolicies","compose","castArray"],"mappings":";;;;;;;;AASA,MAAM,YAAY,CAAC,UAAwB;AACzC,SAAOA,EAAK,KAAAC,EAAA,QAAQ,MAAM,MAAM,CAAC;AACnC;AAEA,MAAM,UAAU,CAAC,UAAwBD,EAAA,KAAK,MAAM,IAAI;AAExD,MAAM,4BACJ,CAAC,cACD,CAAC,KAAK,SAAS;AACb,QAAM,QAAQ;AAAA,IACZ,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU,CAAC;AAAA,EAAA;AAG/B,MAAI,MAAM,QAAQ;AAClB,SAAO,KAAK;AACd;AAEF,MAAM,gBAAgBE,EAAAA,KAAK,aAAa;AAExC,MAAM,4BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,QAAM,EAAE,MAAM,UAAU,IAAI;AAEtB,QAAA,cAAc,OAAO,IAAI,MAAM;AAEjC,MAAA;AACF,UAAM,YAAY,OAAO,MAAM,cAAc,KAAK,CAAC;AAEnD,WAAO,MAAM,KAAK;AAAA,WACX,OAAO;AACV,QAAA,iBAAiBC,mBAAO,mBAAmB;AAC7C,aAAO,IAAI;IACb;AAEI,QAAA,iBAAiBA,mBAAO,gBAAgB;AAEtC,UAAA,iBAAiBA,mBAAO,aAAa;AACjC,cAAA;AAAA,MACR;AACA,aAAO,IAAI;IACb;AAEM,UAAA;AAAA,EACR;AACF;AAEF,MAAM,+BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,SAAO,OAAO,IAAI,MAAM,EAAE,aAAa,KAAK,IAAI;AAClD;AAEF,MAAM,uBAAiD,OAAO,KAAK,SAAS;AACpE,QAAA,SAAS,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;AAEO,SAAA;AACT;AAEA,MAAM,sBAAsB,CAAC,SAAiB;AAC5C,QAAM,iBAAiB,KAAK,MAAM,GAAG,KAAK,YAAY,GAAG,CAAC;AAC1D,QAAM,aAAa,KAAK,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;AAEhD,SAAA,EAAE,gBAAgB;AAC3B;AAEA,MAAM,YAAY,CAAC,OAAqB,WAAmB;AACnD,QAAA,EAAE,SAAS,KAAS,IAAA;AAC1B,QAAM,EAAE,YAAY,SAAS,KAAK,IAAI,QAAQ,CAAA;AAE9C,MAAI,MAAM,QAAQ,OAAO,KAAK,OAAO,YAAY,YAAY;AACpD,WAAA;AAAA,EACT;AAEA,QAAM,EAAE,gBAAgB,eAAe,oBAAoBR,EAAA,KAAK,OAAO,CAAC;AAElE,QAAA,aAAa,cAAc,gBAAgB,EAAE,YAAY,SAAS,QAAQ,MAAM;AAEtF,MAAI,OAAO,WAAW,UAAU,MAAM,YAAY;AAChD,UAAM,IAAI,MAAM,sBAAsB,OAAO,GAAG;AAAA,EAClD;AAEA,MAAI,OAAO,IAAI,UAAU,KAAK,WAAW,UAAU,GAAG;AACnD,eAAW,UAAU,EAAU,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,IAAI;AAAA,EAAA,OAC5D;AACJ,eAAW,UAAU,EAAU,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI;AAAA,EACjE;AAEA,SAAO,WAAW,UAAU,EAAE,KAAK,UAAU;AAC/C;;"}
|
|
@@ -27,6 +27,9 @@ const createAuthorizeMiddleware = (strapi) => async (ctx, next) => {
|
|
|
27
27
|
return ctx.unauthorized();
|
|
28
28
|
}
|
|
29
29
|
if (error instanceof errors.ForbiddenError) {
|
|
30
|
+
if (error instanceof errors.PolicyError) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
30
33
|
return ctx.forbidden();
|
|
31
34
|
}
|
|
32
35
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.mjs","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Strapi, Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { resolvePolicies } from './policy';\n\nconst getMethod = (route: Common.Route) => {\n return trim(toLower(route.method)) as Lowercase<Common.Route['method']>;\n};\n\nconst getPath = (route: Common.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Common.Route): Common.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Common.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Common.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n const policies = resolvePolicies(route);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n ...policies,\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (name: string, { pluginName, apiName }: Common.RouteInfo, strapi: Strapi) => {\n let ctrl: Common.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as Common.UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Common.Route, strapi: Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":[],"mappings":";;;;;AASA,MAAM,YAAY,CAAC,UAAwB;AACzC,SAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;AACnC;AAEA,MAAM,UAAU,CAAC,UAAwB,KAAK,MAAM,IAAI;AAExD,MAAM,4BACJ,CAAC,cACD,CAAC,KAAK,SAAS;AACb,QAAM,QAAQ;AAAA,IACZ,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU,CAAC;AAAA,EAAA;AAG/B,MAAI,MAAM,QAAQ;AAClB,SAAO,KAAK;AACd;AAEF,MAAM,gBAAgB,KAAK,aAAa;AAExC,MAAM,4BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,QAAM,EAAE,MAAM,UAAU,IAAI;AAEtB,QAAA,cAAc,OAAO,IAAI,MAAM;AAEjC,MAAA;AACF,UAAM,YAAY,OAAO,MAAM,cAAc,KAAK,CAAC;AAEnD,WAAO,MAAM,KAAK;AAAA,WACX,OAAO;AACV,QAAA,iBAAiB,OAAO,mBAAmB;AAC7C,aAAO,IAAI;IACb;AAEI,QAAA,iBAAiB,OAAO,gBAAgB;
|
|
1
|
+
{"version":3,"file":"compose-endpoint.mjs","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Strapi, Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { resolvePolicies } from './policy';\n\nconst getMethod = (route: Common.Route) => {\n return trim(toLower(route.method)) as Lowercase<Common.Route['method']>;\n};\n\nconst getPath = (route: Common.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Common.Route): Common.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n // allow PolicyError as an exception to throw a publicly visible message in the API\n if (error instanceof errors.PolicyError) {\n throw error;\n }\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Strapi): Common.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Common.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Common.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n const policies = resolvePolicies(route);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n ...policies,\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (name: string, { pluginName, apiName }: Common.RouteInfo, strapi: Strapi) => {\n let ctrl: Common.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as Common.UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Common.Route, strapi: Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":[],"mappings":";;;;;AASA,MAAM,YAAY,CAAC,UAAwB;AACzC,SAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;AACnC;AAEA,MAAM,UAAU,CAAC,UAAwB,KAAK,MAAM,IAAI;AAExD,MAAM,4BACJ,CAAC,cACD,CAAC,KAAK,SAAS;AACb,QAAM,QAAQ;AAAA,IACZ,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU,CAAC;AAAA,EAAA;AAG/B,MAAI,MAAM,QAAQ;AAClB,SAAO,KAAK;AACd;AAEF,MAAM,gBAAgB,KAAK,aAAa;AAExC,MAAM,4BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,QAAM,EAAE,MAAM,UAAU,IAAI;AAEtB,QAAA,cAAc,OAAO,IAAI,MAAM;AAEjC,MAAA;AACF,UAAM,YAAY,OAAO,MAAM,cAAc,KAAK,CAAC;AAEnD,WAAO,MAAM,KAAK;AAAA,WACX,OAAO;AACV,QAAA,iBAAiB,OAAO,mBAAmB;AAC7C,aAAO,IAAI;IACb;AAEI,QAAA,iBAAiB,OAAO,gBAAgB;AAEtC,UAAA,iBAAiB,OAAO,aAAa;AACjC,cAAA;AAAA,MACR;AACA,aAAO,IAAI;IACb;AAEM,UAAA;AAAA,EACR;AACF;AAEF,MAAM,+BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,SAAO,OAAO,IAAI,MAAM,EAAE,aAAa,KAAK,IAAI;AAClD;AAEF,MAAM,uBAAiD,OAAO,KAAK,SAAS;AACpE,QAAA,SAAS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C,SAAiB;AAC5C,QAAM,iBAAiB,KAAK,MAAM,GAAG,KAAK,YAAY,GAAG,CAAC;AAC1D,QAAM,aAAa,KAAK,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;AAEhD,SAAA,EAAE,gBAAgB;AAC3B;AAEA,MAAM,YAAY,CAAC,OAAqB,WAAmB;AACnD,QAAA,EAAE,SAAS,KAAS,IAAA;AAC1B,QAAM,EAAE,YAAY,SAAS,KAAK,IAAI,QAAQ,CAAA;AAE9C,MAAI,MAAM,QAAQ,OAAO,KAAK,OAAO,YAAY,YAAY;AACpD,WAAA;AAAA,EACT;AAEA,QAAM,EAAE,gBAAgB,eAAe,oBAAoB,KAAK,OAAO,CAAC;AAElE,QAAA,aAAa,cAAc,gBAAgB,EAAE,YAAY,SAAS,QAAQ,MAAM;AAEtF,MAAI,OAAO,WAAW,UAAU,MAAM,YAAY;AAChD,UAAM,IAAI,MAAM,sBAAsB,OAAO,GAAG;AAAA,EAClD;AAEA,MAAI,OAAO,IAAI,UAAU,KAAK,WAAW,UAAU,GAAG;AACnD,eAAW,UAAU,EAAU,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,IAAI;AAAA,EAAA,OAC5D;AACJ,eAAW,UAAU,EAAU,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI;AAAA,EACjE;AAEA,SAAO,WAAW,UAAU,EAAE,KAAK,UAAU;AAC/C;"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const strapiUtils = require("@strapi/utils");
|
|
4
4
|
const { ValidationError } = strapiUtils.errors;
|
|
5
5
|
const webhookModel = {
|
|
6
|
-
uid: "webhook",
|
|
6
|
+
uid: "strapi::webhook",
|
|
7
7
|
singularName: "strapi_webhooks",
|
|
8
8
|
tableName: "strapi_webhooks",
|
|
9
9
|
attributes: {
|
|
@@ -56,7 +56,7 @@ const webhookEventValidator = async (allowedEvents, events) => {
|
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
const createWebhookStore = ({ db }) => {
|
|
59
|
-
const webhookQueries = db.query("webhook");
|
|
59
|
+
const webhookQueries = db.query("strapi::webhook");
|
|
60
60
|
return {
|
|
61
61
|
allowedEvents: /* @__PURE__ */ new Map([]),
|
|
62
62
|
addAllowedEvent(key, value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-store.js","sources":["../../src/services/webhook-store.ts"],"sourcesContent":["/**\n * Webhook store is the implementation of webhook storage over the core_store\n */\n\nimport { errors } from '@strapi/utils';\nimport type { Model, Database } from '@strapi/database';\n\nconst { ValidationError } = errors;\n\nconst webhookModel: Model = {\n uid: 'webhook',\n singularName: 'strapi_webhooks',\n tableName: 'strapi_webhooks',\n attributes: {\n id: {\n type: 'increments',\n },\n name: {\n type: 'string',\n },\n url: {\n type: 'text',\n },\n headers: {\n type: 'json',\n },\n events: {\n type: 'json',\n },\n enabled: {\n type: 'boolean',\n },\n },\n};\n\ninterface DBInput {\n name: string;\n url: string;\n headers: Record<string, string>;\n events: string[];\n enabled: boolean;\n}\n\ninterface DBOutput {\n id: string;\n name: string;\n url: string;\n headers: Record<string, string>;\n events: string[];\n enabled: boolean;\n}\n\nexport interface Webhook {\n id: string;\n name: string;\n url: string;\n headers: Record<string, string>;\n events: string[];\n isEnabled: boolean;\n}\n\nconst toDBObject = (data: Webhook): DBInput => {\n return {\n name: data.name,\n url: data.url,\n headers: data.headers,\n events: data.events,\n enabled: data.isEnabled,\n };\n};\n\nconst fromDBObject = (row: DBOutput): Webhook => {\n return {\n id: row.id,\n name: row.name,\n url: row.url,\n headers: row.headers,\n events: row.events,\n isEnabled: row.enabled,\n };\n};\n\nconst webhookEventValidator = async (allowedEvents: Map<string, string>, events: string[]) => {\n const allowedValues = Array.from(allowedEvents.values());\n\n events.forEach((event) => {\n if (allowedValues.includes(event)) {\n return;\n }\n\n throw new ValidationError(`Webhook event ${event} is not supported`);\n });\n};\n\nexport interface WebhookStore {\n allowedEvents: Map<string, string>;\n addAllowedEvent(key: string, value: string): void;\n removeAllowedEvent(key: string): void;\n listAllowedEvents(): string[];\n getAllowedEvent(key: string): string | undefined;\n findWebhooks(): Promise<Webhook[]>;\n findWebhook(id: string): Promise<Webhook | null>;\n createWebhook(data: Webhook): Promise<Webhook>;\n updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;\n deleteWebhook(id: string): Promise<Webhook | null>;\n}\n\nconst createWebhookStore = ({ db }: { db: Database }): WebhookStore => {\n const webhookQueries = db.query('webhook');\n\n return {\n allowedEvents: new Map([]),\n addAllowedEvent(key, value) {\n this.allowedEvents.set(key, value);\n },\n removeAllowedEvent(key) {\n this.allowedEvents.delete(key);\n },\n listAllowedEvents() {\n return Array.from(this.allowedEvents.keys());\n },\n getAllowedEvent(key) {\n return this.allowedEvents.get(key);\n },\n async findWebhooks() {\n const results = await webhookQueries.findMany();\n\n return results.map(fromDBObject);\n },\n async findWebhook(id) {\n const result = await webhookQueries.findOne({ where: { id } });\n return result ? fromDBObject(result) : null;\n },\n async createWebhook(data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n return webhookQueries\n .create({\n data: toDBObject({ ...data, isEnabled: true }),\n })\n .then(fromDBObject);\n },\n async updateWebhook(id, data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n const webhook = await webhookQueries.update({\n where: { id },\n data: toDBObject(data),\n });\n\n return webhook ? fromDBObject(webhook) : null;\n },\n async deleteWebhook(id) {\n const webhook = await webhookQueries.delete({ where: { id } });\n return webhook ? fromDBObject(webhook) : null;\n },\n };\n};\n\nexport { webhookModel, createWebhookStore };\n"],"names":["errors"],"mappings":";;;AAOA,MAAM,EAAE,gBAAoB,IAAAA;AAE5B,MAAM,eAAsB;AAAA,EAC1B,KAAK;AAAA,EACL,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,IACV,IAAI;AAAA,MACF,MAAM;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,IACR;AAAA,IACA,KAAK;AAAA,MACH,MAAM;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;AA4BA,MAAM,aAAa,CAAC,SAA2B;AACtC,SAAA;AAAA,IACL,MAAM,KAAK;AAAA,IACX,KAAK,KAAK;AAAA,IACV,SAAS,KAAK;AAAA,IACd,QAAQ,KAAK;AAAA,IACb,SAAS,KAAK;AAAA,EAAA;AAElB;AAEA,MAAM,eAAe,CAAC,QAA2B;AACxC,SAAA;AAAA,IACL,IAAI,IAAI;AAAA,IACR,MAAM,IAAI;AAAA,IACV,KAAK,IAAI;AAAA,IACT,SAAS,IAAI;AAAA,IACb,QAAQ,IAAI;AAAA,IACZ,WAAW,IAAI;AAAA,EAAA;AAEnB;AAEA,MAAM,wBAAwB,OAAO,eAAoC,WAAqB;AAC5F,QAAM,gBAAgB,MAAM,KAAK,cAAc,OAAQ,CAAA;AAEhD,SAAA,QAAQ,CAAC,UAAU;AACpB,QAAA,cAAc,SAAS,KAAK,GAAG;AACjC;AAAA,IACF;AAEA,UAAM,IAAI,gBAAgB,iBAAiB,KAAK,mBAAmB;AAAA,EAAA,CACpE;AACH;AAeA,MAAM,qBAAqB,CAAC,EAAE,SAAyC;AAC/D,QAAA,iBAAiB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"webhook-store.js","sources":["../../src/services/webhook-store.ts"],"sourcesContent":["/**\n * Webhook store is the implementation of webhook storage over the core_store\n */\n\nimport { errors } from '@strapi/utils';\nimport type { Model, Database } from '@strapi/database';\n\nconst { ValidationError } = errors;\n\nconst webhookModel: Model = {\n uid: 'strapi::webhook',\n singularName: 'strapi_webhooks',\n tableName: 'strapi_webhooks',\n attributes: {\n id: {\n type: 'increments',\n },\n name: {\n type: 'string',\n },\n url: {\n type: 'text',\n },\n headers: {\n type: 'json',\n },\n events: {\n type: 'json',\n },\n enabled: {\n type: 'boolean',\n },\n },\n};\n\ninterface DBInput {\n name: string;\n url: string;\n headers: Record<string, string>;\n events: string[];\n enabled: boolean;\n}\n\ninterface DBOutput {\n id: string;\n name: string;\n url: string;\n headers: Record<string, string>;\n events: string[];\n enabled: boolean;\n}\n\nexport interface Webhook {\n id: string;\n name: string;\n url: string;\n headers: Record<string, string>;\n events: string[];\n isEnabled: boolean;\n}\n\nconst toDBObject = (data: Webhook): DBInput => {\n return {\n name: data.name,\n url: data.url,\n headers: data.headers,\n events: data.events,\n enabled: data.isEnabled,\n };\n};\n\nconst fromDBObject = (row: DBOutput): Webhook => {\n return {\n id: row.id,\n name: row.name,\n url: row.url,\n headers: row.headers,\n events: row.events,\n isEnabled: row.enabled,\n };\n};\n\nconst webhookEventValidator = async (allowedEvents: Map<string, string>, events: string[]) => {\n const allowedValues = Array.from(allowedEvents.values());\n\n events.forEach((event) => {\n if (allowedValues.includes(event)) {\n return;\n }\n\n throw new ValidationError(`Webhook event ${event} is not supported`);\n });\n};\n\nexport interface WebhookStore {\n allowedEvents: Map<string, string>;\n addAllowedEvent(key: string, value: string): void;\n removeAllowedEvent(key: string): void;\n listAllowedEvents(): string[];\n getAllowedEvent(key: string): string | undefined;\n findWebhooks(): Promise<Webhook[]>;\n findWebhook(id: string): Promise<Webhook | null>;\n createWebhook(data: Webhook): Promise<Webhook>;\n updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;\n deleteWebhook(id: string): Promise<Webhook | null>;\n}\n\nconst createWebhookStore = ({ db }: { db: Database }): WebhookStore => {\n const webhookQueries = db.query('strapi::webhook');\n\n return {\n allowedEvents: new Map([]),\n addAllowedEvent(key, value) {\n this.allowedEvents.set(key, value);\n },\n removeAllowedEvent(key) {\n this.allowedEvents.delete(key);\n },\n listAllowedEvents() {\n return Array.from(this.allowedEvents.keys());\n },\n getAllowedEvent(key) {\n return this.allowedEvents.get(key);\n },\n async findWebhooks() {\n const results = await webhookQueries.findMany();\n\n return results.map(fromDBObject);\n },\n async findWebhook(id) {\n const result = await webhookQueries.findOne({ where: { id } });\n return result ? fromDBObject(result) : null;\n },\n async createWebhook(data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n return webhookQueries\n .create({\n data: toDBObject({ ...data, isEnabled: true }),\n })\n .then(fromDBObject);\n },\n async updateWebhook(id, data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n const webhook = await webhookQueries.update({\n where: { id },\n data: toDBObject(data),\n });\n\n return webhook ? fromDBObject(webhook) : null;\n },\n async deleteWebhook(id) {\n const webhook = await webhookQueries.delete({ where: { id } });\n return webhook ? fromDBObject(webhook) : null;\n },\n };\n};\n\nexport { webhookModel, createWebhookStore };\n"],"names":["errors"],"mappings":";;;AAOA,MAAM,EAAE,gBAAoB,IAAAA;AAE5B,MAAM,eAAsB;AAAA,EAC1B,KAAK;AAAA,EACL,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,IACV,IAAI;AAAA,MACF,MAAM;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,IACR;AAAA,IACA,KAAK;AAAA,MACH,MAAM;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;AA4BA,MAAM,aAAa,CAAC,SAA2B;AACtC,SAAA;AAAA,IACL,MAAM,KAAK;AAAA,IACX,KAAK,KAAK;AAAA,IACV,SAAS,KAAK;AAAA,IACd,QAAQ,KAAK;AAAA,IACb,SAAS,KAAK;AAAA,EAAA;AAElB;AAEA,MAAM,eAAe,CAAC,QAA2B;AACxC,SAAA;AAAA,IACL,IAAI,IAAI;AAAA,IACR,MAAM,IAAI;AAAA,IACV,KAAK,IAAI;AAAA,IACT,SAAS,IAAI;AAAA,IACb,QAAQ,I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sB,KAAK,eAAe,KAAK,MAAM;AAErD,YAAA,UAAU,MAAM,eAAe,OAAO;AAAA,QAC1C,OAAO,EAAE,GAAG;AAAA,QACZ,MAAM,WAAW,IAAI;AAAA,MAAA,CACtB;AAEM,aAAA,UAAU,aAAa,OAAO,IAAI;AAAA,IAC3C;AAAA,IACA,MAAM,cAAc,IAAI;AAChB,YAAA,UAAU,MAAM,eAAe,OAAO,EAAE,OAAO,EAAE,GAAG,EAAA,CAAG;AACtD,aAAA,UAAU,aAAa,OAAO,IAAI;AAAA,IAC3C;AAAA,EAAA;AAEJ;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { errors } from "@strapi/utils";
|
|
2
2
|
const { ValidationError } = errors;
|
|
3
3
|
const webhookModel = {
|
|
4
|
-
uid: "webhook",
|
|
4
|
+
uid: "strapi::webhook",
|
|
5
5
|
singularName: "strapi_webhooks",
|
|
6
6
|
tableName: "strapi_webhooks",
|
|
7
7
|
attributes: {
|
|
@@ -54,7 +54,7 @@ const webhookEventValidator = async (allowedEvents, events) => {
|
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
56
|
const createWebhookStore = ({ db }) => {
|
|
57
|
-
const webhookQueries = db.query("webhook");
|
|
57
|
+
const webhookQueries = db.query("strapi::webhook");
|
|
58
58
|
return {
|
|
59
59
|
allowedEvents: /* @__PURE__ */ new Map([]),
|
|
60
60
|
addAllowedEvent(key, value) {
|