@strapi/content-manager 0.0.0-experimental.ebcac74d516f1eac8973e3621367a9515e76ca82 → 0.0.0-experimental.edd76a7dfed80cd2a11bc9cb105d222f9f5150b7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/history/components/VersionContent.js +24 -3
- package/dist/admin/history/components/VersionContent.js.map +1 -1
- package/dist/admin/history/components/VersionContent.mjs +25 -4
- package/dist/admin/history/components/VersionContent.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentActions.js +7 -3
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs +7 -3
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/index.js +2 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +1 -0
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.js +18 -6
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +19 -7
- package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js +59 -63
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +61 -65
- package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +12 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +12 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +54 -14
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +55 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js +12 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs +13 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +13 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +14 -3
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +18 -5
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +20 -7
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +153 -105
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +156 -108
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.js +4 -2
- package/dist/admin/pages/EditView/components/FormInputs/UID.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs +4 -2
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.js +86 -118
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.mjs +86 -118
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.js +27 -3
- package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.mjs +27 -3
- package/dist/admin/pages/EditView/components/FormLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +103 -0
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +103 -1
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +74 -65
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs +75 -66
- package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.js +1 -0
- package/dist/admin/pages/ListView/components/Filters.js.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.mjs +1 -0
- package/dist/admin/pages/ListView/components/Filters.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/TableActions.js +13 -3
- package/dist/admin/pages/ListView/components/TableActions.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableActions.mjs +13 -3
- package/dist/admin/pages/ListView/components/TableActions.mjs.map +1 -1
- package/dist/admin/services/api.js +2 -1
- package/dist/admin/services/api.js.map +1 -1
- package/dist/admin/services/api.mjs +2 -1
- package/dist/admin/services/api.mjs.map +1 -1
- package/dist/admin/services/documents.js +4 -4
- package/dist/admin/services/documents.js.map +1 -1
- package/dist/admin/services/documents.mjs +4 -4
- package/dist/admin/services/documents.mjs.map +1 -1
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocumentActions.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/UID.d.ts +1 -0
- package/dist/admin/src/pages/EditView/utils/data.d.ts +19 -1
- package/dist/admin/src/preview/services/preview.d.ts +1 -1
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +23 -17
- package/dist/admin/src/services/homepage.d.ts +1 -1
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +1 -0
- package/dist/admin/translations/fr.json.js +6 -1
- package/dist/admin/translations/fr.json.js.map +1 -1
- package/dist/admin/translations/fr.json.mjs +6 -1
- package/dist/admin/translations/fr.json.mjs.map +1 -1
- package/dist/admin/utils/validation.js +17 -6
- package/dist/admin/utils/validation.js.map +1 -1
- package/dist/admin/utils/validation.mjs +17 -6
- package/dist/admin/utils/validation.mjs.map +1 -1
- package/dist/server/controllers/content-types.js +11 -1
- package/dist/server/controllers/content-types.js.map +1 -1
- package/dist/server/controllers/content-types.mjs +11 -1
- package/dist/server/controllers/content-types.mjs.map +1 -1
- package/dist/server/controllers/relations.js +2 -2
- package/dist/server/controllers/relations.js.map +1 -1
- package/dist/server/controllers/relations.mjs +2 -2
- package/dist/server/controllers/relations.mjs.map +1 -1
- package/dist/server/controllers/validation/index.js +14 -2
- package/dist/server/controllers/validation/index.js.map +1 -1
- package/dist/server/controllers/validation/index.mjs +14 -2
- package/dist/server/controllers/validation/index.mjs.map +1 -1
- package/dist/server/homepage/services/homepage.js +58 -49
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +58 -49
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/services/data-mapper.js +4 -1
- package/dist/server/services/data-mapper.js.map +1 -1
- package/dist/server/services/data-mapper.mjs +4 -1
- package/dist/server/services/data-mapper.mjs.map +1 -1
- package/dist/server/services/document-manager.js +8 -1
- package/dist/server/services/document-manager.js.map +1 -1
- package/dist/server/services/document-manager.mjs +8 -1
- package/dist/server/services/document-manager.mjs.map +1 -1
- package/dist/server/services/document-metadata.js +3 -1
- package/dist/server/services/document-metadata.js.map +1 -1
- package/dist/server/services/document-metadata.mjs +3 -1
- package/dist/server/services/document-metadata.mjs.map +1 -1
- package/dist/server/services/utils/configuration/attributes.js +1 -1
- package/dist/server/services/utils/configuration/attributes.js.map +1 -1
- package/dist/server/services/utils/configuration/attributes.mjs +1 -1
- package/dist/server/services/utils/configuration/attributes.mjs.map +1 -1
- package/dist/server/services/utils/configuration/layouts.js +1 -1
- package/dist/server/services/utils/configuration/layouts.js.map +1 -1
- package/dist/server/services/utils/configuration/layouts.mjs +1 -1
- package/dist/server/services/utils/configuration/layouts.mjs.map +1 -1
- package/dist/server/services/utils/configuration/metadatas.js +8 -0
- package/dist/server/services/utils/configuration/metadatas.js.map +1 -1
- package/dist/server/services/utils/configuration/metadatas.mjs +8 -0
- package/dist/server/services/utils/configuration/metadatas.mjs.map +1 -1
- package/dist/server/services/utils/populate.js +11 -0
- package/dist/server/services/utils/populate.js.map +1 -1
- package/dist/server/services/utils/populate.mjs +11 -0
- package/dist/server/services/utils/populate.mjs.map +1 -1
- package/dist/server/src/controllers/content-types.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/index.d.ts +6 -1
- package/dist/server/src/controllers/validation/index.d.ts.map +1 -1
- package/dist/server/src/homepage/index.d.ts +2 -0
- package/dist/server/src/homepage/index.d.ts.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts +3 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/dist/server/src/homepage/services/index.d.ts +2 -0
- package/dist/server/src/homepage/services/index.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +2 -0
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/services/data-mapper.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +2 -0
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/metadatas.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +0 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -25,7 +25,9 @@ const generateUIDInputSchema = strapiUtils.yup.object({
|
|
|
25
25
|
const checkUIDAvailabilityInputSchema = strapiUtils.yup.object({
|
|
26
26
|
contentTypeUID: strapiUtils.yup.string().required(),
|
|
27
27
|
field: strapiUtils.yup.string().required(),
|
|
28
|
-
value: strapiUtils.yup.string().
|
|
28
|
+
value: strapiUtils.yup.string().required().test('isValueMatchingRegex', `\${path} must match the custom regex or the default one "/^[A-Za-z0-9-_.~]*$/"`, function(value, context) {
|
|
29
|
+
return value === '' || (context.options.context?.regex ? new RegExp(context.options?.context.regex).test(value) : /^[A-Za-z0-9-_.~]*$/.test(value));
|
|
30
|
+
})
|
|
29
31
|
});
|
|
30
32
|
const validateUIDField = (contentTypeUID, field)=>{
|
|
31
33
|
const model = strapi.contentTypes[contentTypeUID];
|
|
@@ -46,7 +48,17 @@ const validateUIDField = (contentTypeUID, field)=>{
|
|
|
46
48
|
const validateKind = strapiUtils.validateYupSchema(kindSchema);
|
|
47
49
|
const validateBulkActionInput = strapiUtils.validateYupSchema(bulkActionInputSchema);
|
|
48
50
|
const validateGenerateUIDInput = strapiUtils.validateYupSchema(generateUIDInputSchema);
|
|
49
|
-
const validateCheckUIDAvailabilityInput =
|
|
51
|
+
const validateCheckUIDAvailabilityInput = (body)=>{
|
|
52
|
+
const options = {};
|
|
53
|
+
const contentType = body.contentTypeUID in strapi.contentTypes ? strapi.contentTypes[body.contentTypeUID] : null;
|
|
54
|
+
if (contentType?.attributes[body.field] && `regex` in contentType.attributes[body.field] && contentType.attributes[body.field].regex) {
|
|
55
|
+
options.context = {
|
|
56
|
+
regex: (contentType?.attributes[body.field]).regex
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const validator = strapiUtils.validateYupSchema(checkUIDAvailabilityInputSchema, options);
|
|
60
|
+
return validator(body);
|
|
61
|
+
};
|
|
50
62
|
|
|
51
63
|
exports.validateBulkActionInput = validateBulkActionInput;
|
|
52
64
|
exports.validateCheckUIDAvailabilityInput = validateCheckUIDAvailabilityInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../server/src/controllers/validation/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup, validateYupSchema, errors } from '@strapi/utils';\nimport createModelConfigurationSchema from './model-configuration';\n\nconst { PaginationError, ValidationError } = errors;\nconst TYPES = ['singleType', 'collectionType'];\n\n/**\n * Validates type kind\n */\nconst kindSchema = yup.string().oneOf(TYPES).nullable();\n\nconst bulkActionInputSchema = yup\n .object({\n documentIds: yup.array().of(yup.strapiID()).min(1).required(),\n })\n .required();\n\nconst generateUIDInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n data: yup.object().required(),\n});\n\nconst checkUIDAvailabilityInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n value: yup\n .string()\n .
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../server/src/controllers/validation/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { Schema, UID } from '@strapi/types';\nimport { yup, validateYupSchema, errors } from '@strapi/utils';\nimport { ValidateOptions } from 'yup/lib/types';\nimport { TestContext } from 'yup';\nimport createModelConfigurationSchema from './model-configuration';\n\nconst { PaginationError, ValidationError } = errors;\nconst TYPES = ['singleType', 'collectionType'];\n\n/**\n * Validates type kind\n */\nconst kindSchema = yup.string().oneOf(TYPES).nullable();\n\nconst bulkActionInputSchema = yup\n .object({\n documentIds: yup.array().of(yup.strapiID()).min(1).required(),\n })\n .required();\n\nconst generateUIDInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n data: yup.object().required(),\n});\n\nconst checkUIDAvailabilityInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n value: yup\n .string()\n .required()\n .test(\n 'isValueMatchingRegex',\n `\\${path} must match the custom regex or the default one \"/^[A-Za-z0-9-_.~]*$/\"`,\n function (value, context: TestContext<{ regex?: string }>) {\n return (\n value === '' ||\n (context.options.context?.regex\n ? new RegExp(context.options?.context.regex).test(value as string)\n : /^[A-Za-z0-9-_.~]*$/.test(value as string))\n );\n }\n ),\n});\n\nconst validateUIDField = (contentTypeUID: any, field: any) => {\n const model = strapi.contentTypes[contentTypeUID];\n\n if (!model) {\n throw new ValidationError('ContentType not found');\n }\n\n if (\n !_.has(model, ['attributes', field]) ||\n _.get(model, ['attributes', field, 'type']) !== 'uid'\n ) {\n throw new ValidationError(`${field} must be a valid \\`uid\\` attribute`);\n }\n};\n\nconst validatePagination = ({ page, pageSize }: any) => {\n const pageNumber = parseInt(page, 10);\n const pageSizeNumber = parseInt(pageSize, 10);\n\n if (Number.isNaN(pageNumber) || pageNumber < 1) {\n throw new PaginationError('invalid pageNumber param');\n }\n if (Number.isNaN(pageSizeNumber) || pageSizeNumber < 1) {\n throw new PaginationError('invalid pageSize param');\n }\n};\n\nconst validateKind = validateYupSchema(kindSchema);\nconst validateBulkActionInput = validateYupSchema(bulkActionInputSchema);\nconst validateGenerateUIDInput = validateYupSchema(generateUIDInputSchema);\nconst validateCheckUIDAvailabilityInput = (body: {\n contentTypeUID: UID.ContentType;\n field: string;\n value: string;\n}) => {\n const options: ValidateOptions<{ regex?: string }> = {};\n\n const contentType =\n body.contentTypeUID in strapi.contentTypes ? strapi.contentTypes[body.contentTypeUID] : null;\n\n if (\n contentType?.attributes[body.field] &&\n `regex` in contentType.attributes[body.field] &&\n (contentType.attributes[body.field] as Schema.Attribute.UID).regex\n ) {\n options.context = {\n regex: (contentType?.attributes[body.field] as Schema.Attribute.UID).regex,\n };\n }\n\n const validator = validateYupSchema(checkUIDAvailabilityInputSchema, options);\n\n return validator(body);\n};\n\nexport {\n createModelConfigurationSchema,\n validateUIDField,\n validatePagination,\n validateKind,\n validateBulkActionInput,\n validateGenerateUIDInput,\n validateCheckUIDAvailabilityInput,\n};\n"],"names":["PaginationError","ValidationError","errors","TYPES","kindSchema","yup","string","oneOf","nullable","bulkActionInputSchema","object","documentIds","array","of","strapiID","min","required","generateUIDInputSchema","contentTypeUID","field","data","checkUIDAvailabilityInputSchema","value","test","context","options","regex","RegExp","validateUIDField","model","strapi","contentTypes","_","has","get","validateKind","validateYupSchema","validateBulkActionInput","validateGenerateUIDInput","validateCheckUIDAvailabilityInput","body","contentType","attributes","validator"],"mappings":";;;;;;;;AAOA,MAAM,EAAEA,eAAe,EAAEC,eAAe,EAAE,GAAGC,kBAAAA;AAC7C,MAAMC,KAAQ,GAAA;AAA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K,EAClE;AACAD,QAAAA,OAAAA,CAAQD,OAAO,GAAG;YAChBE,KAAO,EAACe,CAAAA,WAAAA,EAAaC,UAAU,CAACF,KAAKrB,KAAK,CAAC,EAA0BO;AACvE,SAAA;AACF;IAEA,MAAMiB,SAAAA,GAAYP,8BAAkBf,+BAAiCI,EAAAA,OAAAA,CAAAA;AAErE,IAAA,OAAOkB,SAAUH,CAAAA,IAAAA,CAAAA;AACnB;;;;;;;;"}
|
|
@@ -23,7 +23,9 @@ const generateUIDInputSchema = yup.object({
|
|
|
23
23
|
const checkUIDAvailabilityInputSchema = yup.object({
|
|
24
24
|
contentTypeUID: yup.string().required(),
|
|
25
25
|
field: yup.string().required(),
|
|
26
|
-
value: yup.string().
|
|
26
|
+
value: yup.string().required().test('isValueMatchingRegex', `\${path} must match the custom regex or the default one "/^[A-Za-z0-9-_.~]*$/"`, function(value, context) {
|
|
27
|
+
return value === '' || (context.options.context?.regex ? new RegExp(context.options?.context.regex).test(value) : /^[A-Za-z0-9-_.~]*$/.test(value));
|
|
28
|
+
})
|
|
27
29
|
});
|
|
28
30
|
const validateUIDField = (contentTypeUID, field)=>{
|
|
29
31
|
const model = strapi.contentTypes[contentTypeUID];
|
|
@@ -44,7 +46,17 @@ const validateUIDField = (contentTypeUID, field)=>{
|
|
|
44
46
|
const validateKind = validateYupSchema(kindSchema);
|
|
45
47
|
const validateBulkActionInput = validateYupSchema(bulkActionInputSchema);
|
|
46
48
|
const validateGenerateUIDInput = validateYupSchema(generateUIDInputSchema);
|
|
47
|
-
const validateCheckUIDAvailabilityInput =
|
|
49
|
+
const validateCheckUIDAvailabilityInput = (body)=>{
|
|
50
|
+
const options = {};
|
|
51
|
+
const contentType = body.contentTypeUID in strapi.contentTypes ? strapi.contentTypes[body.contentTypeUID] : null;
|
|
52
|
+
if (contentType?.attributes[body.field] && `regex` in contentType.attributes[body.field] && contentType.attributes[body.field].regex) {
|
|
53
|
+
options.context = {
|
|
54
|
+
regex: (contentType?.attributes[body.field]).regex
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const validator = validateYupSchema(checkUIDAvailabilityInputSchema, options);
|
|
58
|
+
return validator(body);
|
|
59
|
+
};
|
|
48
60
|
|
|
49
61
|
export { validateBulkActionInput, validateCheckUIDAvailabilityInput, validateGenerateUIDInput, validateKind, validateUIDField };
|
|
50
62
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../server/src/controllers/validation/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup, validateYupSchema, errors } from '@strapi/utils';\nimport createModelConfigurationSchema from './model-configuration';\n\nconst { PaginationError, ValidationError } = errors;\nconst TYPES = ['singleType', 'collectionType'];\n\n/**\n * Validates type kind\n */\nconst kindSchema = yup.string().oneOf(TYPES).nullable();\n\nconst bulkActionInputSchema = yup\n .object({\n documentIds: yup.array().of(yup.strapiID()).min(1).required(),\n })\n .required();\n\nconst generateUIDInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n data: yup.object().required(),\n});\n\nconst checkUIDAvailabilityInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n value: yup\n .string()\n .
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../server/src/controllers/validation/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { Schema, UID } from '@strapi/types';\nimport { yup, validateYupSchema, errors } from '@strapi/utils';\nimport { ValidateOptions } from 'yup/lib/types';\nimport { TestContext } from 'yup';\nimport createModelConfigurationSchema from './model-configuration';\n\nconst { PaginationError, ValidationError } = errors;\nconst TYPES = ['singleType', 'collectionType'];\n\n/**\n * Validates type kind\n */\nconst kindSchema = yup.string().oneOf(TYPES).nullable();\n\nconst bulkActionInputSchema = yup\n .object({\n documentIds: yup.array().of(yup.strapiID()).min(1).required(),\n })\n .required();\n\nconst generateUIDInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n data: yup.object().required(),\n});\n\nconst checkUIDAvailabilityInputSchema = yup.object({\n contentTypeUID: yup.string().required(),\n field: yup.string().required(),\n value: yup\n .string()\n .required()\n .test(\n 'isValueMatchingRegex',\n `\\${path} must match the custom regex or the default one \"/^[A-Za-z0-9-_.~]*$/\"`,\n function (value, context: TestContext<{ regex?: string }>) {\n return (\n value === '' ||\n (context.options.context?.regex\n ? new RegExp(context.options?.context.regex).test(value as string)\n : /^[A-Za-z0-9-_.~]*$/.test(value as string))\n );\n }\n ),\n});\n\nconst validateUIDField = (contentTypeUID: any, field: any) => {\n const model = strapi.contentTypes[contentTypeUID];\n\n if (!model) {\n throw new ValidationError('ContentType not found');\n }\n\n if (\n !_.has(model, ['attributes', field]) ||\n _.get(model, ['attributes', field, 'type']) !== 'uid'\n ) {\n throw new ValidationError(`${field} must be a valid \\`uid\\` attribute`);\n }\n};\n\nconst validatePagination = ({ page, pageSize }: any) => {\n const pageNumber = parseInt(page, 10);\n const pageSizeNumber = parseInt(pageSize, 10);\n\n if (Number.isNaN(pageNumber) || pageNumber < 1) {\n throw new PaginationError('invalid pageNumber param');\n }\n if (Number.isNaN(pageSizeNumber) || pageSizeNumber < 1) {\n throw new PaginationError('invalid pageSize param');\n }\n};\n\nconst validateKind = validateYupSchema(kindSchema);\nconst validateBulkActionInput = validateYupSchema(bulkActionInputSchema);\nconst validateGenerateUIDInput = validateYupSchema(generateUIDInputSchema);\nconst validateCheckUIDAvailabilityInput = (body: {\n contentTypeUID: UID.ContentType;\n field: string;\n value: string;\n}) => {\n const options: ValidateOptions<{ regex?: string }> = {};\n\n const contentType =\n body.contentTypeUID in strapi.contentTypes ? strapi.contentTypes[body.contentTypeUID] : null;\n\n if (\n contentType?.attributes[body.field] &&\n `regex` in contentType.attributes[body.field] &&\n (contentType.attributes[body.field] as Schema.Attribute.UID).regex\n ) {\n options.context = {\n regex: (contentType?.attributes[body.field] as Schema.Attribute.UID).regex,\n };\n }\n\n const validator = validateYupSchema(checkUIDAvailabilityInputSchema, options);\n\n return validator(body);\n};\n\nexport {\n createModelConfigurationSchema,\n validateUIDField,\n validatePagination,\n validateKind,\n validateBulkActionInput,\n validateGenerateUIDInput,\n validateCheckUIDAvailabilityInput,\n};\n"],"names":["PaginationError","ValidationError","errors","TYPES","kindSchema","yup","string","oneOf","nullable","bulkActionInputSchema","object","documentIds","array","of","strapiID","min","required","generateUIDInputSchema","contentTypeUID","field","data","checkUIDAvailabilityInputSchema","value","test","context","options","regex","RegExp","validateUIDField","model","strapi","contentTypes","_","has","get","validateKind","validateYupSchema","validateBulkActionInput","validateGenerateUIDInput","validateCheckUIDAvailabilityInput","body","contentType","attributes","validator"],"mappings":";;;;;;AAOA,MAAM,EAAEA,eAAe,EAAEC,eAAe,EAAE,GAAGC,MAAAA;AAC7C,MAAMC,KAAQ,GAAA;AAAC,IAAA,YAAA;AAAc,IAAA;AAAiB,CAAA;AAE9C;;IAGA,MAAMC,aAAaC,GAAIC,CAAAA,MAAM,GAAGC,KAAK,CAACJ,OAAOK,QAAQ,EAAA;AAErD,MAAMC,qBAAAA,GAAwBJ,GAC3BK,CAAAA,MAAM,CAAC;IACNC,WAAaN,EAAAA,GAAAA,CAAIO,KAAK,EAAA,CAAGC,EAAE,CAACR,GAAIS,CAAAA,QAAQ,EAAIC,CAAAA,CAAAA,GAAG,CAAC,CAAA,CAAA,CAAGC,QAAQ;AAC7D,CAAA,CAAA,CACCA,QAAQ,EAAA;AAEX,MAAMC,sBAAAA,GAAyBZ,GAAIK,CAAAA,MAAM,CAAC;IACxCQ,cAAgBb,EAAAA,GAAAA,CAAIC,MAAM,EAAA,CAAGU,QAAQ,EAAA;IACrCG,KAAOd,EAAAA,GAAAA,CAAIC,MAAM,EAAA,CAAGU,QAAQ,EAAA;IAC5BI,IAAMf,EAAAA,GAAAA,CAAIK,MAAM,EAAA,CAAGM,QAAQ;AAC7B,CAAA,CAAA;AAEA,MAAMK,+BAAAA,GAAkChB,GAAIK,CAAAA,MAAM,CAAC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AAA;AAClD,MAAM6B,2BAA2BF,iBAAkBnB,CAAAA,sBAAAA;AACnD,MAAMsB,oCAAoC,CAACC,IAAAA,GAAAA;AAKzC,IAAA,MAAMf,UAA+C,EAAC;AAEtD,IAAA,MAAMgB,WACJD,GAAAA,IAAAA,CAAKtB,cAAc,IAAIY,MAAOC,CAAAA,YAAY,GAAGD,MAAAA,CAAOC,YAAY,CAACS,IAAKtB,CAAAA,cAAc,CAAC,GAAG,IAAA;IAE1F,IACEuB,WAAAA,EAAaC,UAAU,CAACF,IAAKrB,CAAAA,KAAK,CAAC,IACnC,CAAC,KAAK,CAAC,IAAIsB,WAAYC,CAAAA,UAAU,CAACF,IAAAA,CAAKrB,KAAK,CAAC,IAC5CsB,WAAYC,CAAAA,UAAU,CAACF,IAAAA,CAAKrB,KAAK,CAAC,CAA0BO,KAAK,EAClE;AACAD,QAAAA,OAAAA,CAAQD,OAAO,GAAG;YAChBE,KAAO,EAACe,CAAAA,WAAAA,EAAaC,UAAU,CAACF,KAAKrB,KAAK,CAAC,EAA0BO;AACvE,SAAA;AACF;IAEA,MAAMiB,SAAAA,GAAYP,kBAAkBf,+BAAiCI,EAAAA,OAAAA,CAAAA;AAErE,IAAA,OAAOkB,SAAUH,CAAAA,IAAAA,CAAAA;AACnB;;;;"}
|
|
@@ -66,8 +66,12 @@ const createHomepageService = ({ strapi })=>{
|
|
|
66
66
|
};
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
|
-
const formatDocuments = (documents, meta)=>{
|
|
69
|
+
const formatDocuments = (documents, meta, populate)=>{
|
|
70
70
|
return documents.map((document)=>{
|
|
71
|
+
const additionalFields = populate?.reduce((acc, key)=>{
|
|
72
|
+
acc[key] = document[key];
|
|
73
|
+
return acc;
|
|
74
|
+
}, {}) || {};
|
|
71
75
|
return {
|
|
72
76
|
documentId: document.documentId,
|
|
73
77
|
locale: document.locale ?? null,
|
|
@@ -76,79 +80,84 @@ const createHomepageService = ({ strapi })=>{
|
|
|
76
80
|
publishedAt: meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,
|
|
77
81
|
contentTypeUid: meta.uid,
|
|
78
82
|
contentTypeDisplayName: meta.contentType.info.displayName,
|
|
79
|
-
kind: meta.contentType.kind
|
|
83
|
+
kind: meta.contentType.kind,
|
|
84
|
+
...additionalFields
|
|
80
85
|
};
|
|
81
86
|
});
|
|
82
87
|
};
|
|
83
|
-
const addStatusToDocuments = async (documents)=>{
|
|
84
|
-
return Promise.all(documents.map(async (recentDocument)=>{
|
|
85
|
-
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentType(recentDocument.contentTypeUid));
|
|
86
|
-
/**
|
|
87
|
-
* Tries to query the other version of the document if draft and publish is enabled,
|
|
88
|
-
* so that we know when to give the "modified" status.
|
|
89
|
-
*/ const { availableStatus } = await metadataService.getMetadata(recentDocument.contentTypeUid, recentDocument, {
|
|
90
|
-
availableStatus: hasDraftAndPublish,
|
|
91
|
-
availableLocales: false
|
|
92
|
-
});
|
|
93
|
-
const status = metadataService.getStatus(recentDocument, availableStatus);
|
|
94
|
-
return {
|
|
95
|
-
...recentDocument,
|
|
96
|
-
status: hasDraftAndPublish ? status : undefined
|
|
97
|
-
};
|
|
98
|
-
}));
|
|
99
|
-
};
|
|
100
88
|
const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');
|
|
101
89
|
const getPermissionChecker = (uid)=>permissionCheckerService.create({
|
|
102
90
|
userAbility: strapi.requestContext.get()?.state.userAbility,
|
|
103
91
|
model: uid
|
|
104
92
|
});
|
|
105
93
|
return {
|
|
106
|
-
async
|
|
94
|
+
async addStatusToDocuments (documents) {
|
|
95
|
+
return Promise.all(documents.map(async (recentDocument)=>{
|
|
96
|
+
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentType(recentDocument.contentTypeUid));
|
|
97
|
+
/**
|
|
98
|
+
* Tries to query the other version of the document if draft and publish is enabled,
|
|
99
|
+
* so that we know when to give the "modified" status.
|
|
100
|
+
*/ const { availableStatus } = await metadataService.getMetadata(recentDocument.contentTypeUid, recentDocument, {
|
|
101
|
+
availableStatus: hasDraftAndPublish,
|
|
102
|
+
availableLocales: false
|
|
103
|
+
});
|
|
104
|
+
const status = metadataService.getStatus(recentDocument, availableStatus);
|
|
105
|
+
return {
|
|
106
|
+
...recentDocument,
|
|
107
|
+
status: hasDraftAndPublish ? status : undefined
|
|
108
|
+
};
|
|
109
|
+
}));
|
|
110
|
+
},
|
|
111
|
+
async queryLastDocuments (additionalQueryParams, draftAndPublishOnly) {
|
|
107
112
|
const permittedContentTypes = await getPermittedContentTypes();
|
|
108
|
-
const allowedContentTypeUids = permittedContentTypes.filter((uid)=>{
|
|
113
|
+
const allowedContentTypeUids = draftAndPublishOnly ? permittedContentTypes.filter((uid)=>{
|
|
109
114
|
return strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentType(uid));
|
|
110
|
-
});
|
|
115
|
+
}) : permittedContentTypes;
|
|
111
116
|
// Fetch the configuration for each content type in a single query
|
|
112
117
|
const configurations = await getConfiguration(allowedContentTypeUids);
|
|
113
118
|
// Get the necessary metadata for the documents
|
|
114
119
|
const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);
|
|
115
|
-
// Now actually fetch and format the documents
|
|
116
120
|
const recentDocuments = await Promise.all(contentTypesMeta.map(async (meta)=>{
|
|
117
121
|
const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({
|
|
118
122
|
limit: MAX_DOCUMENTS,
|
|
119
|
-
sort: 'publishedAt:desc',
|
|
120
123
|
fields: meta.fields,
|
|
121
|
-
|
|
124
|
+
...additionalQueryParams
|
|
122
125
|
});
|
|
123
126
|
const docs = await strapi.documents(meta.uid).findMany(permissionQuery);
|
|
124
|
-
|
|
127
|
+
const populate = additionalQueryParams?.populate;
|
|
128
|
+
return formatDocuments(docs, meta, populate);
|
|
125
129
|
}));
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
return recentDocuments.flat().sort((a, b)=>{
|
|
131
|
+
switch(additionalQueryParams?.sort){
|
|
132
|
+
case 'publishedAt:desc':
|
|
133
|
+
if (!a.publishedAt || !b.publishedAt) return 0;
|
|
134
|
+
return b.publishedAt.valueOf() - a.publishedAt.valueOf();
|
|
135
|
+
case 'publishedAt:asc':
|
|
136
|
+
if (!a.publishedAt || !b.publishedAt) return 0;
|
|
137
|
+
return a.publishedAt.valueOf() - b.publishedAt.valueOf();
|
|
138
|
+
case 'updatedAt:desc':
|
|
139
|
+
if (!a.updatedAt || !b.updatedAt) return 0;
|
|
140
|
+
return b.updatedAt.valueOf() - a.updatedAt.valueOf();
|
|
141
|
+
case 'updatedAt:asc':
|
|
142
|
+
if (!a.updatedAt || !b.updatedAt) return 0;
|
|
143
|
+
return a.updatedAt.valueOf() - b.updatedAt.valueOf();
|
|
144
|
+
default:
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
129
147
|
}).slice(0, MAX_DOCUMENTS);
|
|
130
|
-
|
|
148
|
+
},
|
|
149
|
+
async getRecentlyPublishedDocuments () {
|
|
150
|
+
const recentlyPublishedDocuments = await this.queryLastDocuments({
|
|
151
|
+
sort: 'publishedAt:desc',
|
|
152
|
+
status: 'published'
|
|
153
|
+
}, true);
|
|
154
|
+
return this.addStatusToDocuments(recentlyPublishedDocuments);
|
|
131
155
|
},
|
|
132
156
|
async getRecentlyUpdatedDocuments () {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);
|
|
138
|
-
// Now actually fetch and format the documents
|
|
139
|
-
const recentDocuments = await Promise.all(contentTypesMeta.map(async (meta)=>{
|
|
140
|
-
const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({
|
|
141
|
-
limit: MAX_DOCUMENTS,
|
|
142
|
-
sort: 'updatedAt:desc',
|
|
143
|
-
fields: meta.fields
|
|
144
|
-
});
|
|
145
|
-
const docs = await strapi.documents(meta.uid).findMany(permissionQuery);
|
|
146
|
-
return formatDocuments(docs, meta);
|
|
147
|
-
}));
|
|
148
|
-
const overallRecentDocuments = recentDocuments.flat().sort((a, b)=>{
|
|
149
|
-
return b.updatedAt.valueOf() - a.updatedAt.valueOf();
|
|
150
|
-
}).slice(0, MAX_DOCUMENTS);
|
|
151
|
-
return addStatusToDocuments(overallRecentDocuments);
|
|
157
|
+
const recentlyUpdatedDocuments = await this.queryLastDocuments({
|
|
158
|
+
sort: 'updatedAt:desc'
|
|
159
|
+
});
|
|
160
|
+
return this.addStatusToDocuments(recentlyUpdatedDocuments);
|
|
152
161
|
}
|
|
153
162
|
};
|
|
154
163
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"homepage.js","sources":["../../../../server/src/homepage/services/homepage.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\nimport type { GetRecentDocuments, RecentDocument } from '../../../../shared/contracts/homepage';\n\nconst createHomepageService = ({ strapi }: { strapi: Core.Strapi }) => {\n const MAX_DOCUMENTS = 4;\n\n const metadataService = strapi.plugin('content-manager').service('document-metadata');\n const permissionService = strapi.admin.services.permission;\n\n type ContentTypeConfiguration = {\n uid: RecentDocument['contentTypeUid'];\n settings: { mainField: string };\n };\n const getConfiguration = async (\n contentTypeUids: RecentDocument['contentTypeUid'][]\n ): Promise<ContentTypeConfiguration[]> => {\n /**\n * Don't use the strapi.store util because we need to make\n * more precise queries than exact key matches, in order to make as few queries as possible.\n */\n const coreStore = strapi.db.query('strapi::core-store');\n const rawConfigurations = await coreStore.findMany({\n where: {\n key: {\n $in: contentTypeUids.map(\n (contentType) => `plugin_content_manager_configuration_content_types::${contentType}`\n ),\n },\n },\n });\n\n return rawConfigurations.map((rawConfiguration) => {\n return JSON.parse(rawConfiguration.value);\n });\n };\n\n const getPermittedContentTypes = async () => {\n const readPermissions: Modules.Permissions.PermissionRule[] = await permissionService.findMany({\n where: {\n role: { users: { id: strapi.requestContext.get()?.state?.user.id } },\n action: 'plugin::content-manager.explorer.read',\n },\n });\n\n return readPermissions\n .map((permission) => permission.subject)\n .filter(Boolean) as RecentDocument['contentTypeUid'][];\n };\n\n type ContentTypeMeta = {\n fields: string[];\n mainField: string;\n contentType: Schema.ContentType;\n hasDraftAndPublish: boolean;\n uid: RecentDocument['contentTypeUid'];\n };\n\n const getContentTypesMeta = (\n allowedContentTypeUids: RecentDocument['contentTypeUid'][],\n configurations: ContentTypeConfiguration[]\n ): ContentTypeMeta[] => {\n return allowedContentTypeUids.map((uid) => {\n const configuration = configurations.find((config) => config.uid === uid);\n const contentType = strapi.contentType(uid);\n const fields = ['documentId', 'updatedAt'];\n\n // Add fields required to get the status if D&P is enabled\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);\n if (hasDraftAndPublish) {\n fields.push('publishedAt');\n }\n\n // Only add the main field if it's defined\n if (configuration?.settings.mainField) {\n fields.push(configuration.settings.mainField);\n }\n\n // Only add locale if it's localized\n const isLocalized = (contentType.pluginOptions?.i18n as any)?.localized;\n if (isLocalized) {\n fields.push('locale');\n }\n\n return {\n fields,\n mainField: configuration!.settings.mainField,\n contentType,\n hasDraftAndPublish,\n uid,\n };\n });\n };\n\n const formatDocuments = (documents: Modules.Documents.AnyDocument[], meta: ContentTypeMeta) => {\n return documents.map((document) => {\n return {\n documentId: document.documentId,\n locale: document.locale ?? null,\n updatedAt: new Date(document.updatedAt),\n title: document[meta.mainField ?? 'documentId'],\n publishedAt:\n meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,\n contentTypeUid: meta.uid,\n contentTypeDisplayName: meta.contentType.info.displayName,\n kind: meta.contentType.kind,\n };\n });\n };\n\n const addStatusToDocuments = async (documents: RecentDocument[]): Promise<RecentDocument[]> => {\n return Promise.all(\n documents.map(async (recentDocument) => {\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(\n strapi.contentType(recentDocument.contentTypeUid)\n );\n /**\n * Tries to query the other version of the document if draft and publish is enabled,\n * so that we know when to give the \"modified\" status.\n */\n const { availableStatus } = await metadataService.getMetadata(\n recentDocument.contentTypeUid,\n recentDocument,\n {\n availableStatus: hasDraftAndPublish,\n availableLocales: false,\n }\n );\n const status: RecentDocument['status'] = metadataService.getStatus(\n recentDocument,\n availableStatus\n );\n\n return {\n ...recentDocument,\n status: hasDraftAndPublish ? status : undefined,\n };\n })\n );\n };\n\n const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');\n const getPermissionChecker = (uid: string) =>\n permissionCheckerService.create({\n userAbility: strapi.requestContext.get()?.state.userAbility,\n model: uid,\n });\n\n return {\n async getRecentlyPublishedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const permittedContentTypes = await getPermittedContentTypes();\n const allowedContentTypeUids = permittedContentTypes.filter((uid) => {\n return contentTypes.hasDraftAndPublish(strapi.contentType(uid));\n });\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n // Now actually fetch and format the documents\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n sort: 'publishedAt:desc',\n fields: meta.fields,\n status: 'published',\n });\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n\n return formatDocuments(docs, meta);\n })\n );\n\n const overallRecentDocuments = recentDocuments\n .flat()\n .sort((a, b) => {\n if (!a.publishedAt || !b.publishedAt) return 0;\n return b.publishedAt.valueOf() - a.publishedAt.valueOf();\n })\n .slice(0, MAX_DOCUMENTS);\n\n return addStatusToDocuments(overallRecentDocuments);\n },\n\n async getRecentlyUpdatedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const allowedContentTypeUids = await getPermittedContentTypes();\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n // Now actually fetch and format the documents\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n sort: 'updatedAt:desc',\n fields: meta.fields,\n });\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n\n return formatDocuments(docs, meta);\n })\n );\n\n const overallRecentDocuments = recentDocuments\n .flat()\n .sort((a, b) => {\n return b.updatedAt.valueOf() - a.updatedAt.valueOf();\n })\n .slice(0, MAX_DOCUMENTS);\n\n return addStatusToDocuments(overallRecentDocuments);\n },\n };\n};\n\nexport { createHomepageService };\n"],"names":["createHomepageService","strapi","MAX_DOCUMENTS","metadataService","plugin","service","permissionService","admin","services","permission","getConfiguration","contentTypeUids","coreStore","db","query","rawConfigurations","findMany","where","key","$in","map","contentType","rawConfiguration","JSON","parse","value","getPermittedContentTypes","readPermissions","role","users","id","requestContext","get","state","user","action","subject","filter","Boolean","getContentTypesMeta","allowedContentTypeUids","configurations","uid","configuration","find","config","fields","hasDraftAndPublish","contentTypes","push","settings","mainField","isLocalized","pluginOptions","i18n","localized","formatDocuments","documents","meta","document","documentId","locale","updatedAt","Date","title","publishedAt","contentTypeUid","contentTypeDisplayName","info","displayName","kind","addStatusToDocuments","Promise","all","recentDocument","availableStatus","getMetadata","availableLocales","status","getStatus","undefined","permissionCheckerService","getPermissionChecker","create","userAbility","model","getRecentlyPublishedDocuments","permittedContentTypes","contentTypesMeta","recentDocuments","permissionQuery","sanitizedQuery","read","limit","sort","docs","overallRecentDocuments","flat","a","b","valueOf","slice","getRecentlyUpdatedDocuments"],"mappings":";;;;AAKA,MAAMA,qBAAwB,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;AAChE,IAAA,MAAMC,aAAgB,GAAA,CAAA;AAEtB,IAAA,MAAMC,kBAAkBF,M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AC0E,eAAAA,CAAAA;AAEvD,gBAAA,OAAOlC,gBAAgBuC,IAAMrC,EAAAA,IAAAA,CAAAA;AAC/B,aAAA,CAAA,CAAA;AAGF,YAAA,MAAMsC,yBAAyBP,eAC5BQ,CAAAA,IAAI,GACJH,IAAI,CAAC,CAACI,CAAGC,EAAAA,CAAAA,GAAAA;gBACR,OAAOA,CAAAA,CAAErC,SAAS,CAACsC,OAAO,KAAKF,CAAEpC,CAAAA,SAAS,CAACsC,OAAO,EAAA;aAEnDC,CAAAA,CAAAA,KAAK,CAAC,CAAGnG,EAAAA,aAAAA,CAAAA;AAEZ,YAAA,OAAOqE,oBAAqByB,CAAAA,sBAAAA,CAAAA;AAC9B;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"homepage.js","sources":["../../../../server/src/homepage/services/homepage.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\nimport type { GetRecentDocuments, RecentDocument } from '../../../../shared/contracts/homepage';\n\nconst createHomepageService = ({ strapi }: { strapi: Core.Strapi }) => {\n const MAX_DOCUMENTS = 4;\n\n const metadataService = strapi.plugin('content-manager').service('document-metadata');\n const permissionService = strapi.admin.services.permission;\n\n type ContentTypeConfiguration = {\n uid: RecentDocument['contentTypeUid'];\n settings: { mainField: string };\n };\n const getConfiguration = async (\n contentTypeUids: RecentDocument['contentTypeUid'][]\n ): Promise<ContentTypeConfiguration[]> => {\n /**\n * Don't use the strapi.store util because we need to make\n * more precise queries than exact key matches, in order to make as few queries as possible.\n */\n const coreStore = strapi.db.query('strapi::core-store');\n const rawConfigurations = await coreStore.findMany({\n where: {\n key: {\n $in: contentTypeUids.map(\n (contentType) => `plugin_content_manager_configuration_content_types::${contentType}`\n ),\n },\n },\n });\n\n return rawConfigurations.map((rawConfiguration) => {\n return JSON.parse(rawConfiguration.value);\n });\n };\n\n const getPermittedContentTypes = async () => {\n const readPermissions: Modules.Permissions.PermissionRule[] = await permissionService.findMany({\n where: {\n role: { users: { id: strapi.requestContext.get()?.state?.user.id } },\n action: 'plugin::content-manager.explorer.read',\n },\n });\n\n return readPermissions\n .map((permission) => permission.subject)\n .filter(Boolean) as RecentDocument['contentTypeUid'][];\n };\n\n type ContentTypeMeta = {\n fields: string[];\n mainField: string;\n contentType: Schema.ContentType;\n hasDraftAndPublish: boolean;\n uid: RecentDocument['contentTypeUid'];\n };\n\n const getContentTypesMeta = (\n allowedContentTypeUids: RecentDocument['contentTypeUid'][],\n configurations: ContentTypeConfiguration[]\n ): ContentTypeMeta[] => {\n return allowedContentTypeUids.map((uid) => {\n const configuration = configurations.find((config) => config.uid === uid);\n const contentType = strapi.contentType(uid);\n const fields = ['documentId', 'updatedAt'];\n\n // Add fields required to get the status if D&P is enabled\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);\n if (hasDraftAndPublish) {\n fields.push('publishedAt');\n }\n\n // Only add the main field if it's defined\n if (configuration?.settings.mainField) {\n fields.push(configuration.settings.mainField);\n }\n\n // Only add locale if it's localized\n const isLocalized = (contentType.pluginOptions?.i18n as any)?.localized;\n if (isLocalized) {\n fields.push('locale');\n }\n\n return {\n fields,\n mainField: configuration!.settings.mainField,\n contentType,\n hasDraftAndPublish,\n uid,\n };\n });\n };\n\n const formatDocuments = (\n documents: Modules.Documents.AnyDocument[],\n meta: ContentTypeMeta,\n populate?: string[]\n ) => {\n return documents.map((document) => {\n const additionalFields =\n populate?.reduce(\n (acc, key) => {\n acc[key] = document[key];\n return acc;\n },\n {} as Record<string, any>\n ) || {};\n return {\n documentId: document.documentId,\n locale: document.locale ?? null,\n updatedAt: new Date(document.updatedAt),\n title: document[meta.mainField ?? 'documentId'],\n publishedAt:\n meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,\n contentTypeUid: meta.uid,\n contentTypeDisplayName: meta.contentType.info.displayName,\n kind: meta.contentType.kind,\n ...additionalFields,\n };\n });\n };\n\n const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');\n const getPermissionChecker = (uid: string) =>\n permissionCheckerService.create({\n userAbility: strapi.requestContext.get()?.state.userAbility,\n model: uid,\n });\n\n return {\n async addStatusToDocuments(documents: RecentDocument[]): Promise<RecentDocument[]> {\n return Promise.all(\n documents.map(async (recentDocument) => {\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(\n strapi.contentType(recentDocument.contentTypeUid)\n );\n /**\n * Tries to query the other version of the document if draft and publish is enabled,\n * so that we know when to give the \"modified\" status.\n */\n const { availableStatus } = await metadataService.getMetadata(\n recentDocument.contentTypeUid,\n recentDocument,\n {\n availableStatus: hasDraftAndPublish,\n availableLocales: false,\n }\n );\n const status: RecentDocument['status'] = metadataService.getStatus(\n recentDocument,\n availableStatus\n );\n\n return {\n ...recentDocument,\n status: hasDraftAndPublish ? status : undefined,\n };\n })\n );\n },\n\n async queryLastDocuments(\n additionalQueryParams?: Record<string, unknown>,\n draftAndPublishOnly?: boolean\n ): Promise<RecentDocument[]> {\n const permittedContentTypes = await getPermittedContentTypes();\n const allowedContentTypeUids = draftAndPublishOnly\n ? permittedContentTypes.filter((uid) => {\n return contentTypes.hasDraftAndPublish(strapi.contentType(uid));\n })\n : permittedContentTypes;\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n fields: meta.fields,\n ...additionalQueryParams,\n });\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n const populate = additionalQueryParams?.populate as string[];\n\n return formatDocuments(docs, meta, populate);\n })\n );\n\n return recentDocuments\n .flat()\n .sort((a, b) => {\n switch (additionalQueryParams?.sort) {\n case 'publishedAt:desc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return b.publishedAt.valueOf() - a.publishedAt.valueOf();\n case 'publishedAt:asc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return a.publishedAt.valueOf() - b.publishedAt.valueOf();\n case 'updatedAt:desc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return b.updatedAt.valueOf() - a.updatedAt.valueOf();\n case 'updatedAt:asc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return a.updatedAt.valueOf() - b.updatedAt.valueOf();\n default:\n return 0;\n }\n })\n .slice(0, MAX_DOCUMENTS);\n },\n\n async getRecentlyPublishedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyPublishedDocuments = await this.queryLastDocuments(\n {\n sort: 'publishedAt:desc',\n status: 'published',\n },\n true\n );\n\n return this.addStatusToDocuments(recentlyPublishedDocuments);\n },\n\n async getRecentlyUpdatedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyUpdatedDocuments = await this.queryLastDocuments({\n sort: 'updatedAt:desc',\n });\n\n return this.addStatusToDocuments(recentlyUpdatedDocuments);\n },\n };\n};\n\nexport { createHomepageService };\n"],"names":["createHomepageService","strapi","MAX_DOCUMENTS","metadataService","plugin","service","permissionService","admin","services","permission","getConfiguration","contentTypeUids","coreStore","db","query","rawConfigurations","findMany","where","key","$in","map","contentType","rawConfiguration","JSON","parse","value","getPermittedContentTypes","readPermissions","role","users","id","requestContext","get","state","user","action","subject","filter","Boolean","getContentTypesMeta","allowedContentTypeUids","configurations","uid","configuration","find","config","fields","hasDraftAndPublish","contentTypes","push","settings","mainField","isLocalized","pluginOptions","i18n","localized","formatDocuments","documents","meta","populate","document","additionalFields","reduce","acc","documentId","locale","updatedAt","Date","title","publishedAt","contentTypeUid","contentTypeDisplayName","info","displayName","kind","permissionCheckerService","getPermissionChecker","create","userAbility","model","addStatusToDocuments","Promise","all","recentDocument","availableStatus","getMetadata","availableLocales","status","getStatus","undefined","queryLastDocuments","additionalQueryParams","draftAndPublishOnly","permittedContentTypes","contentTypesMeta","recentDocuments","permissionQuery","sanitizedQuery","read","limit","docs","flat","sort","a","b","valueOf","slice","getRecentlyPublishedDocuments","recentlyPublishedDocuments","getRecentlyUpdatedDocuments","recentlyUpdatedDocuments"],"mappings":";;;;AAKA,MAAMA,qBAAwB,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;AAChE,IAAA,MAAMC,aAAgB,GAAA,CAAA;AAEtB,IAAA,MAAMC,kBAAkBF,MAAOG,CAAAA,MAAM,CAAC,iBAAA,CAAA,CAAmBC,OAAO,CAAC,mBAAA,CAAA;AACjE,IAAA,MAAMC,oBAAoBL,MAAOM,CAAAA,KAAK,CAACC,QAAQ,CAACC,UAAU;AAM1D,IAAA,MAAMC,mBAAmB,OACvBC,eAAAA,GAAAA;AAEA;;;AAGC,QACD,MAAMC,SAAYX,GAAAA,MAAAA,CAAOY,EAAE,CAACC,KAAK,CAAC,oBAAA,CAAA;AAClC,QAAA,MAAMC,iBAAoB,GAAA,MAAMH,SAAUI,CAAAA,QAAQ,CAAC;YACjDC,KAAO,EAAA;gBACLC,GAAK,EAAA;oBACHC,GAAKR,EAAAA,eAAAA,CAAgBS,GAAG,CACtB,CAACC,cAAgB,CAAC,oDAAoD,EAAEA,WAAAA,CAAY,CAAC;AAEzF;AACF;AACF,SAAA,CAAA;QAEA,OAAON,iBAAAA,CAAkBK,GAAG,CAAC,CAACE,gBAAAA,GAAAA;AAC5B,YAAA,OAAOC,IAAKC,CAAAA,KAAK,CAACF,gBAAAA,CAAiBG,KAAK,CAAA;AAC1C,SAAA,CAAA;AACF,KAAA;AAEA,IAAA,MAAMC,wBAA2B,GAAA,UAAA;AAC/B,QAAA,MAAMC,eAAwD,GAAA,MAAMrB,iBAAkBU,CAAAA,QAAQ,CAAC;YAC7FC,KAAO,EAAA;gBACLW,IAAM,EAAA;oBAAEC,KAAO,EAAA;AAAEC,wBAAAA,EAAAA,EAAI7B,OAAO8B,cAAc,CAACC,GAAG,EAAA,EAAIC,OAAOC,IAAKJ,CAAAA;AAAG;AAA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,CAAAA,WAAW,CAACoC,OAAO,EAAA;oBACxD,KAAK,gBAAA;wBACH,IAAI,CAACF,EAAErC,SAAS,IAAI,CAACsC,CAAEtC,CAAAA,SAAS,EAAE,OAAO,CAAA;wBACzC,OAAOsC,CAAAA,CAAEtC,SAAS,CAACuC,OAAO,KAAKF,CAAErC,CAAAA,SAAS,CAACuC,OAAO,EAAA;oBACpD,KAAK,eAAA;wBACH,IAAI,CAACF,EAAErC,SAAS,IAAI,CAACsC,CAAEtC,CAAAA,SAAS,EAAE,OAAO,CAAA;wBACzC,OAAOqC,CAAAA,CAAErC,SAAS,CAACuC,OAAO,KAAKD,CAAEtC,CAAAA,SAAS,CAACuC,OAAO,EAAA;AACpD,oBAAA;wBACE,OAAO,CAAA;AACX;aAEDC,CAAAA,CAAAA,KAAK,CAAC,CAAGxG,EAAAA,aAAAA,CAAAA;AACd,SAAA;QAEA,MAAMyG,6BAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMC,0BAA6B,GAAA,MAAM,IAAI,CAAClB,kBAAkB,CAC9D;gBACEY,IAAM,EAAA,kBAAA;gBACNf,MAAQ,EAAA;aAEV,EAAA,IAAA,CAAA;YAGF,OAAO,IAAI,CAACP,oBAAoB,CAAC4B,0BAAAA,CAAAA;AACnC,SAAA;QAEA,MAAMC,2BAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMC,wBAA2B,GAAA,MAAM,IAAI,CAACpB,kBAAkB,CAAC;gBAC7DY,IAAM,EAAA;AACR,aAAA,CAAA;YAEA,OAAO,IAAI,CAACtB,oBAAoB,CAAC8B,wBAAAA,CAAAA;AACnC;AACF,KAAA;AACF;;;;"}
|
|
@@ -64,8 +64,12 @@ const createHomepageService = ({ strapi })=>{
|
|
|
64
64
|
};
|
|
65
65
|
});
|
|
66
66
|
};
|
|
67
|
-
const formatDocuments = (documents, meta)=>{
|
|
67
|
+
const formatDocuments = (documents, meta, populate)=>{
|
|
68
68
|
return documents.map((document)=>{
|
|
69
|
+
const additionalFields = populate?.reduce((acc, key)=>{
|
|
70
|
+
acc[key] = document[key];
|
|
71
|
+
return acc;
|
|
72
|
+
}, {}) || {};
|
|
69
73
|
return {
|
|
70
74
|
documentId: document.documentId,
|
|
71
75
|
locale: document.locale ?? null,
|
|
@@ -74,79 +78,84 @@ const createHomepageService = ({ strapi })=>{
|
|
|
74
78
|
publishedAt: meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,
|
|
75
79
|
contentTypeUid: meta.uid,
|
|
76
80
|
contentTypeDisplayName: meta.contentType.info.displayName,
|
|
77
|
-
kind: meta.contentType.kind
|
|
81
|
+
kind: meta.contentType.kind,
|
|
82
|
+
...additionalFields
|
|
78
83
|
};
|
|
79
84
|
});
|
|
80
85
|
};
|
|
81
|
-
const addStatusToDocuments = async (documents)=>{
|
|
82
|
-
return Promise.all(documents.map(async (recentDocument)=>{
|
|
83
|
-
const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.contentType(recentDocument.contentTypeUid));
|
|
84
|
-
/**
|
|
85
|
-
* Tries to query the other version of the document if draft and publish is enabled,
|
|
86
|
-
* so that we know when to give the "modified" status.
|
|
87
|
-
*/ const { availableStatus } = await metadataService.getMetadata(recentDocument.contentTypeUid, recentDocument, {
|
|
88
|
-
availableStatus: hasDraftAndPublish,
|
|
89
|
-
availableLocales: false
|
|
90
|
-
});
|
|
91
|
-
const status = metadataService.getStatus(recentDocument, availableStatus);
|
|
92
|
-
return {
|
|
93
|
-
...recentDocument,
|
|
94
|
-
status: hasDraftAndPublish ? status : undefined
|
|
95
|
-
};
|
|
96
|
-
}));
|
|
97
|
-
};
|
|
98
86
|
const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');
|
|
99
87
|
const getPermissionChecker = (uid)=>permissionCheckerService.create({
|
|
100
88
|
userAbility: strapi.requestContext.get()?.state.userAbility,
|
|
101
89
|
model: uid
|
|
102
90
|
});
|
|
103
91
|
return {
|
|
104
|
-
async
|
|
92
|
+
async addStatusToDocuments (documents) {
|
|
93
|
+
return Promise.all(documents.map(async (recentDocument)=>{
|
|
94
|
+
const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.contentType(recentDocument.contentTypeUid));
|
|
95
|
+
/**
|
|
96
|
+
* Tries to query the other version of the document if draft and publish is enabled,
|
|
97
|
+
* so that we know when to give the "modified" status.
|
|
98
|
+
*/ const { availableStatus } = await metadataService.getMetadata(recentDocument.contentTypeUid, recentDocument, {
|
|
99
|
+
availableStatus: hasDraftAndPublish,
|
|
100
|
+
availableLocales: false
|
|
101
|
+
});
|
|
102
|
+
const status = metadataService.getStatus(recentDocument, availableStatus);
|
|
103
|
+
return {
|
|
104
|
+
...recentDocument,
|
|
105
|
+
status: hasDraftAndPublish ? status : undefined
|
|
106
|
+
};
|
|
107
|
+
}));
|
|
108
|
+
},
|
|
109
|
+
async queryLastDocuments (additionalQueryParams, draftAndPublishOnly) {
|
|
105
110
|
const permittedContentTypes = await getPermittedContentTypes();
|
|
106
|
-
const allowedContentTypeUids = permittedContentTypes.filter((uid)=>{
|
|
111
|
+
const allowedContentTypeUids = draftAndPublishOnly ? permittedContentTypes.filter((uid)=>{
|
|
107
112
|
return contentTypes.hasDraftAndPublish(strapi.contentType(uid));
|
|
108
|
-
});
|
|
113
|
+
}) : permittedContentTypes;
|
|
109
114
|
// Fetch the configuration for each content type in a single query
|
|
110
115
|
const configurations = await getConfiguration(allowedContentTypeUids);
|
|
111
116
|
// Get the necessary metadata for the documents
|
|
112
117
|
const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);
|
|
113
|
-
// Now actually fetch and format the documents
|
|
114
118
|
const recentDocuments = await Promise.all(contentTypesMeta.map(async (meta)=>{
|
|
115
119
|
const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({
|
|
116
120
|
limit: MAX_DOCUMENTS,
|
|
117
|
-
sort: 'publishedAt:desc',
|
|
118
121
|
fields: meta.fields,
|
|
119
|
-
|
|
122
|
+
...additionalQueryParams
|
|
120
123
|
});
|
|
121
124
|
const docs = await strapi.documents(meta.uid).findMany(permissionQuery);
|
|
122
|
-
|
|
125
|
+
const populate = additionalQueryParams?.populate;
|
|
126
|
+
return formatDocuments(docs, meta, populate);
|
|
123
127
|
}));
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
return recentDocuments.flat().sort((a, b)=>{
|
|
129
|
+
switch(additionalQueryParams?.sort){
|
|
130
|
+
case 'publishedAt:desc':
|
|
131
|
+
if (!a.publishedAt || !b.publishedAt) return 0;
|
|
132
|
+
return b.publishedAt.valueOf() - a.publishedAt.valueOf();
|
|
133
|
+
case 'publishedAt:asc':
|
|
134
|
+
if (!a.publishedAt || !b.publishedAt) return 0;
|
|
135
|
+
return a.publishedAt.valueOf() - b.publishedAt.valueOf();
|
|
136
|
+
case 'updatedAt:desc':
|
|
137
|
+
if (!a.updatedAt || !b.updatedAt) return 0;
|
|
138
|
+
return b.updatedAt.valueOf() - a.updatedAt.valueOf();
|
|
139
|
+
case 'updatedAt:asc':
|
|
140
|
+
if (!a.updatedAt || !b.updatedAt) return 0;
|
|
141
|
+
return a.updatedAt.valueOf() - b.updatedAt.valueOf();
|
|
142
|
+
default:
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
127
145
|
}).slice(0, MAX_DOCUMENTS);
|
|
128
|
-
|
|
146
|
+
},
|
|
147
|
+
async getRecentlyPublishedDocuments () {
|
|
148
|
+
const recentlyPublishedDocuments = await this.queryLastDocuments({
|
|
149
|
+
sort: 'publishedAt:desc',
|
|
150
|
+
status: 'published'
|
|
151
|
+
}, true);
|
|
152
|
+
return this.addStatusToDocuments(recentlyPublishedDocuments);
|
|
129
153
|
},
|
|
130
154
|
async getRecentlyUpdatedDocuments () {
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);
|
|
136
|
-
// Now actually fetch and format the documents
|
|
137
|
-
const recentDocuments = await Promise.all(contentTypesMeta.map(async (meta)=>{
|
|
138
|
-
const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({
|
|
139
|
-
limit: MAX_DOCUMENTS,
|
|
140
|
-
sort: 'updatedAt:desc',
|
|
141
|
-
fields: meta.fields
|
|
142
|
-
});
|
|
143
|
-
const docs = await strapi.documents(meta.uid).findMany(permissionQuery);
|
|
144
|
-
return formatDocuments(docs, meta);
|
|
145
|
-
}));
|
|
146
|
-
const overallRecentDocuments = recentDocuments.flat().sort((a, b)=>{
|
|
147
|
-
return b.updatedAt.valueOf() - a.updatedAt.valueOf();
|
|
148
|
-
}).slice(0, MAX_DOCUMENTS);
|
|
149
|
-
return addStatusToDocuments(overallRecentDocuments);
|
|
155
|
+
const recentlyUpdatedDocuments = await this.queryLastDocuments({
|
|
156
|
+
sort: 'updatedAt:desc'
|
|
157
|
+
});
|
|
158
|
+
return this.addStatusToDocuments(recentlyUpdatedDocuments);
|
|
150
159
|
}
|
|
151
160
|
};
|
|
152
161
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/services/homepage.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\nimport type { GetRecentDocuments, RecentDocument } from '../../../../shared/contracts/homepage';\n\nconst createHomepageService = ({ strapi }: { strapi: Core.Strapi }) => {\n const MAX_DOCUMENTS = 4;\n\n const metadataService = strapi.plugin('content-manager').service('document-metadata');\n const permissionService = strapi.admin.services.permission;\n\n type ContentTypeConfiguration = {\n uid: RecentDocument['contentTypeUid'];\n settings: { mainField: string };\n };\n const getConfiguration = async (\n contentTypeUids: RecentDocument['contentTypeUid'][]\n ): Promise<ContentTypeConfiguration[]> => {\n /**\n * Don't use the strapi.store util because we need to make\n * more precise queries than exact key matches, in order to make as few queries as possible.\n */\n const coreStore = strapi.db.query('strapi::core-store');\n const rawConfigurations = await coreStore.findMany({\n where: {\n key: {\n $in: contentTypeUids.map(\n (contentType) => `plugin_content_manager_configuration_content_types::${contentType}`\n ),\n },\n },\n });\n\n return rawConfigurations.map((rawConfiguration) => {\n return JSON.parse(rawConfiguration.value);\n });\n };\n\n const getPermittedContentTypes = async () => {\n const readPermissions: Modules.Permissions.PermissionRule[] = await permissionService.findMany({\n where: {\n role: { users: { id: strapi.requestContext.get()?.state?.user.id } },\n action: 'plugin::content-manager.explorer.read',\n },\n });\n\n return readPermissions\n .map((permission) => permission.subject)\n .filter(Boolean) as RecentDocument['contentTypeUid'][];\n };\n\n type ContentTypeMeta = {\n fields: string[];\n mainField: string;\n contentType: Schema.ContentType;\n hasDraftAndPublish: boolean;\n uid: RecentDocument['contentTypeUid'];\n };\n\n const getContentTypesMeta = (\n allowedContentTypeUids: RecentDocument['contentTypeUid'][],\n configurations: ContentTypeConfiguration[]\n ): ContentTypeMeta[] => {\n return allowedContentTypeUids.map((uid) => {\n const configuration = configurations.find((config) => config.uid === uid);\n const contentType = strapi.contentType(uid);\n const fields = ['documentId', 'updatedAt'];\n\n // Add fields required to get the status if D&P is enabled\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);\n if (hasDraftAndPublish) {\n fields.push('publishedAt');\n }\n\n // Only add the main field if it's defined\n if (configuration?.settings.mainField) {\n fields.push(configuration.settings.mainField);\n }\n\n // Only add locale if it's localized\n const isLocalized = (contentType.pluginOptions?.i18n as any)?.localized;\n if (isLocalized) {\n fields.push('locale');\n }\n\n return {\n fields,\n mainField: configuration!.settings.mainField,\n contentType,\n hasDraftAndPublish,\n uid,\n };\n });\n };\n\n const formatDocuments = (documents: Modules.Documents.AnyDocument[], meta: ContentTypeMeta) => {\n return documents.map((document) => {\n return {\n documentId: document.documentId,\n locale: document.locale ?? null,\n updatedAt: new Date(document.updatedAt),\n title: document[meta.mainField ?? 'documentId'],\n publishedAt:\n meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,\n contentTypeUid: meta.uid,\n contentTypeDisplayName: meta.contentType.info.displayName,\n kind: meta.contentType.kind,\n };\n });\n };\n\n const addStatusToDocuments = async (documents: RecentDocument[]): Promise<RecentDocument[]> => {\n return Promise.all(\n documents.map(async (recentDocument) => {\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(\n strapi.contentType(recentDocument.contentTypeUid)\n );\n /**\n * Tries to query the other version of the document if draft and publish is enabled,\n * so that we know when to give the \"modified\" status.\n */\n const { availableStatus } = await metadataService.getMetadata(\n recentDocument.contentTypeUid,\n recentDocument,\n {\n availableStatus: hasDraftAndPublish,\n availableLocales: false,\n }\n );\n const status: RecentDocument['status'] = metadataService.getStatus(\n recentDocument,\n availableStatus\n );\n\n return {\n ...recentDocument,\n status: hasDraftAndPublish ? status : undefined,\n };\n })\n );\n };\n\n const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');\n const getPermissionChecker = (uid: string) =>\n permissionCheckerService.create({\n userAbility: strapi.requestContext.get()?.state.userAbility,\n model: uid,\n });\n\n return {\n async getRecentlyPublishedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const permittedContentTypes = await getPermittedContentTypes();\n const allowedContentTypeUids = permittedContentTypes.filter((uid) => {\n return contentTypes.hasDraftAndPublish(strapi.contentType(uid));\n });\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n // Now actually fetch and format the documents\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n sort: 'publishedAt:desc',\n fields: meta.fields,\n status: 'published',\n });\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n\n return formatDocuments(docs, meta);\n })\n );\n\n const overallRecentDocuments = recentDocuments\n .flat()\n .sort((a, b) => {\n if (!a.publishedAt || !b.publishedAt) return 0;\n return b.publishedAt.valueOf() - a.publishedAt.valueOf();\n })\n .slice(0, MAX_DOCUMENTS);\n\n return addStatusToDocuments(overallRecentDocuments);\n },\n\n async getRecentlyUpdatedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const allowedContentTypeUids = await getPermittedContentTypes();\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n // Now actually fetch and format the documents\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n sort: 'updatedAt:desc',\n fields: meta.fields,\n });\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n\n return formatDocuments(docs, meta);\n })\n );\n\n const overallRecentDocuments = recentDocuments\n .flat()\n .sort((a, b) => {\n return b.updatedAt.valueOf() - a.updatedAt.valueOf();\n })\n .slice(0, MAX_DOCUMENTS);\n\n return addStatusToDocuments(overallRecentDocuments);\n },\n };\n};\n\nexport { createHomepageService };\n"],"names":["createHomepageService","strapi","MAX_DOCUMENTS","metadataService","plugin","service","permissionService","admin","services","permission","getConfiguration","contentTypeUids","coreStore","db","query","rawConfigurations","findMany","where","key","$in","map","contentType","rawConfiguration","JSON","parse","value","getPermittedContentTypes","readPermissions","role","users","id","requestContext","get","state","user","action","subject","filter","Boolean","getContentTypesMeta","allowedContentTypeUids","configurations","uid","configuration","find","config","fields","hasDraftAndPublish","contentTypes","push","settings","mainField","isLocalized","pluginOptions","i18n","localized","formatDocuments","documents","meta","document","documentId","locale","updatedAt","Date","title","publishedAt","contentTypeUid","contentTypeDisplayName","info","displayName","kind","addStatusToDocuments","Promise","all","recentDocument","availableStatus","getMetadata","availableLocales","status","getStatus","undefined","permissionCheckerService","getPermissionChecker","create","userAbility","model","getRecentlyPublishedDocuments","permittedContentTypes","contentTypesMeta","recentDocuments","permissionQuery","sanitizedQuery","read","limit","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P4F,IAAM,EAAA,gBAAA;AACNhD,oBAAAA,MAAAA,EAAQY,KAAKZ;AACf,iBAAA,CAAA;gBAEA,MAAMiD,IAAAA,GAAO,MAAM9F,MAAOwD,CAAAA,SAAS,CAACC,IAAKhB,CAAAA,GAAG,CAAE1B,CAAAA,QAAQ,CAAC0E,eAAAA,CAAAA;AAEvD,gBAAA,OAAOlC,gBAAgBuC,IAAMrC,EAAAA,IAAAA,CAAAA;AAC/B,aAAA,CAAA,CAAA;AAGF,YAAA,MAAMsC,yBAAyBP,eAC5BQ,CAAAA,IAAI,GACJH,IAAI,CAAC,CAACI,CAAGC,EAAAA,CAAAA,GAAAA;gBACR,OAAOA,CAAAA,CAAErC,SAAS,CAACsC,OAAO,KAAKF,CAAEpC,CAAAA,SAAS,CAACsC,OAAO,EAAA;aAEnDC,CAAAA,CAAAA,KAAK,CAAC,CAAGnG,EAAAA,aAAAA,CAAAA;AAEZ,YAAA,OAAOqE,oBAAqByB,CAAAA,sBAAAA,CAAAA;AAC9B;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/services/homepage.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\nimport type { GetRecentDocuments, RecentDocument } from '../../../../shared/contracts/homepage';\n\nconst createHomepageService = ({ strapi }: { strapi: Core.Strapi }) => {\n const MAX_DOCUMENTS = 4;\n\n const metadataService = strapi.plugin('content-manager').service('document-metadata');\n const permissionService = strapi.admin.services.permission;\n\n type ContentTypeConfiguration = {\n uid: RecentDocument['contentTypeUid'];\n settings: { mainField: string };\n };\n const getConfiguration = async (\n contentTypeUids: RecentDocument['contentTypeUid'][]\n ): Promise<ContentTypeConfiguration[]> => {\n /**\n * Don't use the strapi.store util because we need to make\n * more precise queries than exact key matches, in order to make as few queries as possible.\n */\n const coreStore = strapi.db.query('strapi::core-store');\n const rawConfigurations = await coreStore.findMany({\n where: {\n key: {\n $in: contentTypeUids.map(\n (contentType) => `plugin_content_manager_configuration_content_types::${contentType}`\n ),\n },\n },\n });\n\n return rawConfigurations.map((rawConfiguration) => {\n return JSON.parse(rawConfiguration.value);\n });\n };\n\n const getPermittedContentTypes = async () => {\n const readPermissions: Modules.Permissions.PermissionRule[] = await permissionService.findMany({\n where: {\n role: { users: { id: strapi.requestContext.get()?.state?.user.id } },\n action: 'plugin::content-manager.explorer.read',\n },\n });\n\n return readPermissions\n .map((permission) => permission.subject)\n .filter(Boolean) as RecentDocument['contentTypeUid'][];\n };\n\n type ContentTypeMeta = {\n fields: string[];\n mainField: string;\n contentType: Schema.ContentType;\n hasDraftAndPublish: boolean;\n uid: RecentDocument['contentTypeUid'];\n };\n\n const getContentTypesMeta = (\n allowedContentTypeUids: RecentDocument['contentTypeUid'][],\n configurations: ContentTypeConfiguration[]\n ): ContentTypeMeta[] => {\n return allowedContentTypeUids.map((uid) => {\n const configuration = configurations.find((config) => config.uid === uid);\n const contentType = strapi.contentType(uid);\n const fields = ['documentId', 'updatedAt'];\n\n // Add fields required to get the status if D&P is enabled\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);\n if (hasDraftAndPublish) {\n fields.push('publishedAt');\n }\n\n // Only add the main field if it's defined\n if (configuration?.settings.mainField) {\n fields.push(configuration.settings.mainField);\n }\n\n // Only add locale if it's localized\n const isLocalized = (contentType.pluginOptions?.i18n as any)?.localized;\n if (isLocalized) {\n fields.push('locale');\n }\n\n return {\n fields,\n mainField: configuration!.settings.mainField,\n contentType,\n hasDraftAndPublish,\n uid,\n };\n });\n };\n\n const formatDocuments = (\n documents: Modules.Documents.AnyDocument[],\n meta: ContentTypeMeta,\n populate?: string[]\n ) => {\n return documents.map((document) => {\n const additionalFields =\n populate?.reduce(\n (acc, key) => {\n acc[key] = document[key];\n return acc;\n },\n {} as Record<string, any>\n ) || {};\n return {\n documentId: document.documentId,\n locale: document.locale ?? null,\n updatedAt: new Date(document.updatedAt),\n title: document[meta.mainField ?? 'documentId'],\n publishedAt:\n meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,\n contentTypeUid: meta.uid,\n contentTypeDisplayName: meta.contentType.info.displayName,\n kind: meta.contentType.kind,\n ...additionalFields,\n };\n });\n };\n\n const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');\n const getPermissionChecker = (uid: string) =>\n permissionCheckerService.create({\n userAbility: strapi.requestContext.get()?.state.userAbility,\n model: uid,\n });\n\n return {\n async addStatusToDocuments(documents: RecentDocument[]): Promise<RecentDocument[]> {\n return Promise.all(\n documents.map(async (recentDocument) => {\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(\n strapi.contentType(recentDocument.contentTypeUid)\n );\n /**\n * Tries to query the other version of the document if draft and publish is enabled,\n * so that we know when to give the \"modified\" status.\n */\n const { availableStatus } = await metadataService.getMetadata(\n recentDocument.contentTypeUid,\n recentDocument,\n {\n availableStatus: hasDraftAndPublish,\n availableLocales: false,\n }\n );\n const status: RecentDocument['status'] = metadataService.getStatus(\n recentDocument,\n availableStatus\n );\n\n return {\n ...recentDocument,\n status: hasDraftAndPublish ? status : undefined,\n };\n })\n );\n },\n\n async queryLastDocuments(\n additionalQueryParams?: Record<string, unknown>,\n draftAndPublishOnly?: boolean\n ): Promise<RecentDocument[]> {\n const permittedContentTypes = await getPermittedContentTypes();\n const allowedContentTypeUids = draftAndPublishOnly\n ? permittedContentTypes.filter((uid) => {\n return contentTypes.hasDraftAndPublish(strapi.contentType(uid));\n })\n : permittedContentTypes;\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n fields: meta.fields,\n ...additionalQueryParams,\n });\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n const populate = additionalQueryParams?.populate as string[];\n\n return formatDocuments(docs, meta, populate);\n })\n );\n\n return recentDocuments\n .flat()\n .sort((a, b) => {\n switch (additionalQueryParams?.sort) {\n case 'publishedAt:desc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return b.publishedAt.valueOf() - a.publishedAt.valueOf();\n case 'publishedAt:asc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return a.publishedAt.valueOf() - b.publishedAt.valueOf();\n case 'updatedAt:desc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return b.updatedAt.valueOf() - a.updatedAt.valueOf();\n case 'updatedAt:asc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return a.updatedAt.valueOf() - b.updatedAt.valueOf();\n default:\n return 0;\n }\n })\n .slice(0, MAX_DOCUMENTS);\n },\n\n async getRecentlyPublishedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyPublishedDocuments = await this.queryLastDocuments(\n {\n sort: 'publishedAt:desc',\n status: 'published',\n },\n true\n );\n\n return this.addStatusToDocuments(recentlyPublishedDocuments);\n },\n\n async getRecentlyUpdatedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyUpdatedDocuments = await this.queryLastDocuments({\n sort: 'updatedAt:desc',\n });\n\n return this.addStatusToDocuments(recentlyUpdatedDocuments);\n },\n };\n};\n\nexport { createHomepageService };\n"],"names":["createHomepageService","strapi","MAX_DOCUMENTS","metadataService","plugin","service","permissionService","admin","services","permission","getConfiguration","contentTypeUids","coreStore","db","query","rawConfigurations","findMany","where","key","$in","map","contentType","rawConfiguration","JSON","parse","value","getPermittedContentTypes","readPermissions","role","users","id","requestContext","get","state","user","action","subject","filter","Boolean","getContentTypesMeta","allowedContentTypeUids","configurations","uid","configuration","find","config","fields","hasDraftAndPublish","contentTypes","push","settings","mainField","isLocalized","pluginOptions","i18n","localized","formatDocuments","documents","meta","populate","document","additionalFields","reduce","acc","documentId","locale","updatedAt","Date","title","publishedAt","contentTypeUid","contentTypeDisplayName","info","displayName","kind","permissionCheckerService","getPermissionChecker","create","userAbility","model","addStatusToDocuments","Promise","all","recentDocument","availableStatus","getMetadata","availableLocales","status","getStatus","undefined","queryLastDocuments","additionalQueryParams","draftAndPublishOnly","permittedContentTypes","contentTypesMeta","recentDocuments","permissionQuery","sanitizedQuery","read","limit","docs","flat","sort","a","b","valueOf","slice","getRecentlyPublishedDocuments","recentlyPublishedDocuments","getRecentlyUpdatedDocuments","recentlyUpdatedDocuments"],"mappings":";;AAKA,MAAMA,qBAAwB,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;AAChE,IAAA,MAAMC,aAAgB,GAAA,CAAA;AAEtB,IAAA,MAAMC,kBAAkBF,MAAOG,CAAAA,MAAM,CAAC,iBAAA,CAAA,CAAmBC,OAAO,CAAC,mBAAA,CAAA;AACjE,IAAA,MAAMC,oBAAoBL,MAAOM,CAAAA,KAAK,CAACC,QAAQ,CAACC,UAAU;AAM1D,IAAA,MAAMC,mBAAmB,OACvBC,eAAAA,GAAAA;AAEA;;;AAGC,QACD,MAAMC,SAAYX,GAAAA,MAAAA,CAAOY,EAAE,CAACC,KAAK,CAAC,oBAAA,CAAA;AAClC,QAAA,MAAMC,iBAAoB,GAAA,MAAMH,SAAUI,CAAAA,QAAQ,CAAC;YACjDC,KAAO,EAAA;gBACLC,GAAK,EAAA;oBACHC,GAAKR,EAAAA,eAAAA,CAAgBS,GAAG,CACtB,CAACC,cAAgB,CAAC,oDAAoD,EAAEA,WAAAA,CAAY,CAAC;AAEzF;AACF;AACF,SAAA,CAAA;QAEA,OAAON,iBAAAA,CAAkBK,GAAG,CAAC,CAACE,gBAAAA,GAAAA;AAC5B,YAAA,OAAOC,IAAKC,CAAAA,KAAK,CAACF,gBAAAA,CAAiBG,KAAK,CAAA;AAC1C,SAAA,CAAA;AACF,KAAA;AAEA,IAAA,MAAMC,wBAA2B,GAAA,UAAA;AAC/B,QAAA,MAAMC,eAAwD,GAAA,MAAMrB,i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