@strapi/content-manager 5.12.6 → 5.12.7

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.
Files changed (76) hide show
  1. package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +2 -0
  2. package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
  3. package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +2 -0
  4. package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
  5. package/dist/admin/services/homepage.js +9 -5
  6. package/dist/admin/services/homepage.js.map +1 -1
  7. package/dist/admin/services/homepage.mjs +9 -5
  8. package/dist/admin/services/homepage.mjs.map +1 -1
  9. package/dist/server/controllers/index.js +3 -1
  10. package/dist/server/controllers/index.js.map +1 -1
  11. package/dist/server/controllers/index.mjs +3 -1
  12. package/dist/server/controllers/index.mjs.map +1 -1
  13. package/dist/server/homepage/controllers/homepage.js +57 -0
  14. package/dist/server/homepage/controllers/homepage.js.map +1 -0
  15. package/dist/server/homepage/controllers/homepage.mjs +36 -0
  16. package/dist/server/homepage/controllers/homepage.mjs.map +1 -0
  17. package/dist/server/homepage/controllers/index.js +10 -0
  18. package/dist/server/homepage/controllers/index.js.map +1 -0
  19. package/dist/server/homepage/controllers/index.mjs +8 -0
  20. package/dist/server/homepage/controllers/index.mjs.map +1 -0
  21. package/dist/server/homepage/index.js +14 -0
  22. package/dist/server/homepage/index.js.map +1 -0
  23. package/dist/server/homepage/index.mjs +12 -0
  24. package/dist/server/homepage/index.mjs.map +1 -0
  25. package/dist/server/homepage/routes/homepage.js +25 -0
  26. package/dist/server/homepage/routes/homepage.js.map +1 -0
  27. package/dist/server/homepage/routes/homepage.mjs +23 -0
  28. package/dist/server/homepage/routes/homepage.mjs.map +1 -0
  29. package/dist/server/homepage/routes/index.js +13 -0
  30. package/dist/server/homepage/routes/index.js.map +1 -0
  31. package/dist/server/homepage/routes/index.mjs +11 -0
  32. package/dist/server/homepage/routes/index.mjs.map +1 -0
  33. package/dist/server/homepage/services/homepage.js +157 -0
  34. package/dist/server/homepage/services/homepage.js.map +1 -0
  35. package/dist/server/homepage/services/homepage.mjs +155 -0
  36. package/dist/server/homepage/services/homepage.mjs.map +1 -0
  37. package/dist/server/homepage/services/index.js +10 -0
  38. package/dist/server/homepage/services/index.js.map +1 -0
  39. package/dist/server/homepage/services/index.mjs +8 -0
  40. package/dist/server/homepage/services/index.mjs.map +1 -0
  41. package/dist/server/preview/services/preview.js +0 -1
  42. package/dist/server/preview/services/preview.js.map +1 -1
  43. package/dist/server/preview/services/preview.mjs +0 -1
  44. package/dist/server/preview/services/preview.mjs.map +1 -1
  45. package/dist/server/routes/index.js +3 -1
  46. package/dist/server/routes/index.js.map +1 -1
  47. package/dist/server/routes/index.mjs +3 -1
  48. package/dist/server/routes/index.mjs.map +1 -1
  49. package/dist/server/services/index.js +3 -1
  50. package/dist/server/services/index.js.map +1 -1
  51. package/dist/server/services/index.mjs +3 -1
  52. package/dist/server/services/index.mjs.map +1 -1
  53. package/dist/server/src/controllers/index.d.ts.map +1 -1
  54. package/dist/server/src/homepage/controllers/homepage.d.ts +7 -0
  55. package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -0
  56. package/dist/server/src/homepage/controllers/index.d.ts +2 -0
  57. package/dist/server/src/homepage/controllers/index.d.ts.map +1 -0
  58. package/dist/server/src/homepage/index.d.ts +16 -0
  59. package/dist/server/src/homepage/index.d.ts.map +1 -0
  60. package/dist/server/src/homepage/routes/homepage.d.ts +4 -0
  61. package/dist/server/src/homepage/routes/homepage.d.ts.map +1 -0
  62. package/dist/server/src/homepage/routes/index.d.ts +8 -0
  63. package/dist/server/src/homepage/routes/index.d.ts.map +1 -0
  64. package/dist/server/src/{services → homepage/services}/homepage.d.ts +1 -1
  65. package/dist/server/src/homepage/services/homepage.d.ts.map +1 -0
  66. package/dist/server/src/homepage/services/index.d.ts +9 -0
  67. package/dist/server/src/homepage/services/index.d.ts.map +1 -0
  68. package/dist/server/src/index.d.ts +7 -0
  69. package/dist/server/src/index.d.ts.map +1 -1
  70. package/dist/server/src/preview/services/preview.d.ts.map +1 -1
  71. package/dist/server/src/routes/index.d.ts +1 -0
  72. package/dist/server/src/routes/index.d.ts.map +1 -1
  73. package/dist/server/src/services/index.d.ts +6 -0
  74. package/dist/server/src/services/index.d.ts.map +1 -1
  75. package/package.json +5 -5
  76. package/dist/server/src/services/homepage.d.ts.map +0 -1
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var homepage = require('./homepage.js');
4
+
5
+ const controllers = {
6
+ homepage: homepage.createHomepageController
7
+ };
8
+
9
+ exports.controllers = controllers;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../server/src/homepage/controllers/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { createHomepageController } from './homepage';\n\nexport const controllers = {\n homepage: createHomepageController,\n /**\n * Casting is needed because the types aren't aware that Strapi supports\n * passing a controller factory as the value, instead of a controller object directly\n */\n} as unknown as Plugin.LoadedPlugin['controllers'];\n"],"names":["controllers","homepage","createHomepageController"],"mappings":";;;;MAGaA,WAAc,GAAA;IACzBC,QAAUC,EAAAA;AAKZ;;;;"}
@@ -0,0 +1,8 @@
1
+ import { createHomepageController } from './homepage.mjs';
2
+
3
+ const controllers = {
4
+ homepage: createHomepageController
5
+ };
6
+
7
+ export { controllers };
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../server/src/homepage/controllers/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { createHomepageController } from './homepage';\n\nexport const controllers = {\n homepage: createHomepageController,\n /**\n * Casting is needed because the types aren't aware that Strapi supports\n * passing a controller factory as the value, instead of a controller object directly\n */\n} as unknown as Plugin.LoadedPlugin['controllers'];\n"],"names":["controllers","homepage","createHomepageController"],"mappings":";;MAGaA,WAAc,GAAA;IACzBC,QAAUC,EAAAA;AAKZ;;;;"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var index = require('./routes/index.js');
4
+ var index$1 = require('./controllers/index.js');
5
+ var index$2 = require('./services/index.js');
6
+
7
+ var homepage = {
8
+ routes: index.routes,
9
+ controllers: index$1.controllers,
10
+ services: index$2.services
11
+ };
12
+
13
+ module.exports = homepage;
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../server/src/homepage/index.ts"],"sourcesContent":["import { routes } from './routes';\nimport { controllers } from './controllers';\nimport { services } from './services';\n\nexport default {\n routes,\n controllers,\n services,\n};\n"],"names":["routes","controllers","services"],"mappings":";;;;;;AAIA,eAAe;AACbA,YAAAA,YAAAA;AACAC,iBAAAA,mBAAAA;AACAC,cAAAA;AACF,CAAE;;;;"}
@@ -0,0 +1,12 @@
1
+ import { routes } from './routes/index.mjs';
2
+ import { controllers } from './controllers/index.mjs';
3
+ import { services } from './services/index.mjs';
4
+
5
+ var homepage = {
6
+ routes,
7
+ controllers,
8
+ services
9
+ };
10
+
11
+ export { homepage as default };
12
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../server/src/homepage/index.ts"],"sourcesContent":["import { routes } from './routes';\nimport { controllers } from './controllers';\nimport { services } from './services';\n\nexport default {\n routes,\n controllers,\n services,\n};\n"],"names":["routes","controllers","services"],"mappings":";;;;AAIA,eAAe;AACbA,IAAAA,MAAAA;AACAC,IAAAA,WAAAA;AACAC,IAAAA;AACF,CAAE;;;;"}
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const info = {
4
+ pluginName: 'content-manager',
5
+ type: 'admin'
6
+ };
7
+ const homepageRouter = {
8
+ type: 'admin',
9
+ routes: [
10
+ {
11
+ method: 'GET',
12
+ info,
13
+ path: '/homepage/recent-documents',
14
+ handler: 'homepage.getRecentDocuments',
15
+ config: {
16
+ policies: [
17
+ 'admin::isAuthenticatedAdmin'
18
+ ]
19
+ }
20
+ }
21
+ ]
22
+ };
23
+
24
+ exports.homepageRouter = homepageRouter;
25
+ //# sourceMappingURL=homepage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"homepage.js","sources":["../../../../server/src/homepage/routes/homepage.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\n\nconst info = { pluginName: 'content-manager', type: 'admin' };\n\nconst homepageRouter: Plugin.LoadedPlugin['routes'][string] = {\n type: 'admin',\n routes: [\n {\n method: 'GET',\n info,\n path: '/homepage/recent-documents',\n handler: 'homepage.getRecentDocuments',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n ],\n};\n\nexport { homepageRouter };\n"],"names":["info","pluginName","type","homepageRouter","routes","method","path","handler","config","policies"],"mappings":";;AAEA,MAAMA,IAAO,GAAA;IAAEC,UAAY,EAAA,iBAAA;IAAmBC,IAAM,EAAA;AAAQ,CAAA;AAE5D,MAAMC,cAAwD,GAAA;IAC5DD,IAAM,EAAA,OAAA;IACNE,MAAQ,EAAA;AACN,QAAA;YACEC,MAAQ,EAAA,KAAA;AACRL,YAAAA,IAAAA;YACAM,IAAM,EAAA,4BAAA;YACNC,OAAS,EAAA,6BAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF;AACD;AACH;;;;"}
@@ -0,0 +1,23 @@
1
+ const info = {
2
+ pluginName: 'content-manager',
3
+ type: 'admin'
4
+ };
5
+ const homepageRouter = {
6
+ type: 'admin',
7
+ routes: [
8
+ {
9
+ method: 'GET',
10
+ info,
11
+ path: '/homepage/recent-documents',
12
+ handler: 'homepage.getRecentDocuments',
13
+ config: {
14
+ policies: [
15
+ 'admin::isAuthenticatedAdmin'
16
+ ]
17
+ }
18
+ }
19
+ ]
20
+ };
21
+
22
+ export { homepageRouter };
23
+ //# sourceMappingURL=homepage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/routes/homepage.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\n\nconst info = { pluginName: 'content-manager', type: 'admin' };\n\nconst homepageRouter: Plugin.LoadedPlugin['routes'][string] = {\n type: 'admin',\n routes: [\n {\n method: 'GET',\n info,\n path: '/homepage/recent-documents',\n handler: 'homepage.getRecentDocuments',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n ],\n};\n\nexport { homepageRouter };\n"],"names":["info","pluginName","type","homepageRouter","routes","method","path","handler","config","policies"],"mappings":"AAEA,MAAMA,IAAO,GAAA;IAAEC,UAAY,EAAA,iBAAA;IAAmBC,IAAM,EAAA;AAAQ,CAAA;AAE5D,MAAMC,cAAwD,GAAA;IAC5DD,IAAM,EAAA,OAAA;IACNE,MAAQ,EAAA;AACN,QAAA;YACEC,MAAQ,EAAA,KAAA;AACRL,YAAAA,IAAAA;YACAM,IAAM,EAAA,4BAAA;YACNC,OAAS,EAAA,6BAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF;AACD;AACH;;;;"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var homepage = require('./homepage.js');
4
+
5
+ /**
6
+ * The routes will be merged with the other Content Manager routers,
7
+ * so we need to avoid conficts in the router name, and to prefix the path for each route.
8
+ */ const routes = {
9
+ homepage: homepage.homepageRouter
10
+ };
11
+
12
+ exports.routes = routes;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../server/src/homepage/routes/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { homepageRouter } from './homepage';\n\n/**\n * The routes will be merged with the other Content Manager routers,\n * so we need to avoid conficts in the router name, and to prefix the path for each route.\n */\nexport const routes = {\n homepage: homepageRouter,\n} satisfies Plugin.LoadedPlugin['routes'];\n"],"names":["routes","homepage","homepageRouter"],"mappings":";;;;AAGA;;;UAIaA,MAAS,GAAA;IACpBC,QAAUC,EAAAA;AACZ;;;;"}
@@ -0,0 +1,11 @@
1
+ import { homepageRouter } from './homepage.mjs';
2
+
3
+ /**
4
+ * The routes will be merged with the other Content Manager routers,
5
+ * so we need to avoid conficts in the router name, and to prefix the path for each route.
6
+ */ const routes = {
7
+ homepage: homepageRouter
8
+ };
9
+
10
+ export { routes };
11
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../server/src/homepage/routes/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { homepageRouter } from './homepage';\n\n/**\n * The routes will be merged with the other Content Manager routers,\n * so we need to avoid conficts in the router name, and to prefix the path for each route.\n */\nexport const routes = {\n homepage: homepageRouter,\n} satisfies Plugin.LoadedPlugin['routes'];\n"],"names":["routes","homepage","homepageRouter"],"mappings":";;AAGA;;;UAIaA,MAAS,GAAA;IACpBC,QAAUC,EAAAA;AACZ;;;;"}
@@ -0,0 +1,157 @@
1
+ 'use strict';
2
+
3
+ var strapiUtils = require('@strapi/utils');
4
+
5
+ const createHomepageService = ({ strapi })=>{
6
+ const MAX_DOCUMENTS = 4;
7
+ const metadataService = strapi.plugin('content-manager').service('document-metadata');
8
+ const permissionService = strapi.admin.services.permission;
9
+ const getConfiguration = async (contentTypeUids)=>{
10
+ /**
11
+ * Don't use the strapi.store util because we need to make
12
+ * more precise queries than exact key matches, in order to make as few queries as possible.
13
+ */ const coreStore = strapi.db.query('strapi::core-store');
14
+ const rawConfigurations = await coreStore.findMany({
15
+ where: {
16
+ key: {
17
+ $in: contentTypeUids.map((contentType)=>`plugin_content_manager_configuration_content_types::${contentType}`)
18
+ }
19
+ }
20
+ });
21
+ return rawConfigurations.map((rawConfiguration)=>{
22
+ return JSON.parse(rawConfiguration.value);
23
+ });
24
+ };
25
+ const getPermittedContentTypes = async ()=>{
26
+ const readPermissions = await permissionService.findMany({
27
+ where: {
28
+ role: {
29
+ users: {
30
+ id: strapi.requestContext.get()?.state?.user.id
31
+ }
32
+ },
33
+ action: 'plugin::content-manager.explorer.read'
34
+ }
35
+ });
36
+ return readPermissions.map((permission)=>permission.subject).filter(Boolean);
37
+ };
38
+ const getContentTypesMeta = (allowedContentTypeUids, configurations)=>{
39
+ return allowedContentTypeUids.map((uid)=>{
40
+ const configuration = configurations.find((config)=>config.uid === uid);
41
+ const contentType = strapi.contentType(uid);
42
+ const fields = [
43
+ 'documentId',
44
+ 'updatedAt'
45
+ ];
46
+ // Add fields required to get the status if D&P is enabled
47
+ const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(contentType);
48
+ if (hasDraftAndPublish) {
49
+ fields.push('publishedAt');
50
+ }
51
+ // Only add the main field if it's defined
52
+ if (configuration?.settings.mainField) {
53
+ fields.push(configuration.settings.mainField);
54
+ }
55
+ // Only add locale if it's localized
56
+ const isLocalized = contentType.pluginOptions?.i18n?.localized;
57
+ if (isLocalized) {
58
+ fields.push('locale');
59
+ }
60
+ return {
61
+ fields,
62
+ mainField: configuration.settings.mainField,
63
+ contentType,
64
+ hasDraftAndPublish,
65
+ uid
66
+ };
67
+ });
68
+ };
69
+ const formatDocuments = (documents, meta)=>{
70
+ return documents.map((document)=>{
71
+ return {
72
+ documentId: document.documentId,
73
+ locale: document.locale ?? null,
74
+ updatedAt: new Date(document.updatedAt),
75
+ title: document[meta.mainField ?? 'documentId'],
76
+ publishedAt: meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,
77
+ contentTypeUid: meta.uid,
78
+ contentTypeDisplayName: meta.contentType.info.displayName,
79
+ kind: meta.contentType.kind
80
+ };
81
+ });
82
+ };
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
+ const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');
101
+ const getPermissionChecker = (uid)=>permissionCheckerService.create({
102
+ userAbility: strapi.requestContext.get()?.state.userAbility,
103
+ model: uid
104
+ });
105
+ return {
106
+ async getRecentlyPublishedDocuments () {
107
+ const permittedContentTypes = await getPermittedContentTypes();
108
+ const allowedContentTypeUids = permittedContentTypes.filter((uid)=>{
109
+ return strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentType(uid));
110
+ });
111
+ // Fetch the configuration for each content type in a single query
112
+ const configurations = await getConfiguration(allowedContentTypeUids);
113
+ // Get the necessary metadata for the documents
114
+ const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);
115
+ // Now actually fetch and format the documents
116
+ const recentDocuments = await Promise.all(contentTypesMeta.map(async (meta)=>{
117
+ const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({
118
+ limit: MAX_DOCUMENTS,
119
+ sort: 'publishedAt:desc',
120
+ fields: meta.fields,
121
+ status: 'published'
122
+ });
123
+ const docs = await strapi.documents(meta.uid).findMany(permissionQuery);
124
+ return formatDocuments(docs, meta);
125
+ }));
126
+ const overallRecentDocuments = recentDocuments.flat().sort((a, b)=>{
127
+ if (!a.publishedAt || !b.publishedAt) return 0;
128
+ return b.publishedAt.valueOf() - a.publishedAt.valueOf();
129
+ }).slice(0, MAX_DOCUMENTS);
130
+ return addStatusToDocuments(overallRecentDocuments);
131
+ },
132
+ async getRecentlyUpdatedDocuments () {
133
+ const allowedContentTypeUids = await getPermittedContentTypes();
134
+ // Fetch the configuration for each content type in a single query
135
+ const configurations = await getConfiguration(allowedContentTypeUids);
136
+ // Get the necessary metadata for the documents
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);
152
+ }
153
+ };
154
+ };
155
+
156
+ exports.createHomepageService = createHomepageService;
157
+ //# sourceMappingURL=homepage.js.map
@@ -0,0 +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","getRecentlyUpdated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A,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;;;;"}
@@ -0,0 +1,155 @@
1
+ import { contentTypes } from '@strapi/utils';
2
+
3
+ const createHomepageService = ({ strapi })=>{
4
+ const MAX_DOCUMENTS = 4;
5
+ const metadataService = strapi.plugin('content-manager').service('document-metadata');
6
+ const permissionService = strapi.admin.services.permission;
7
+ const getConfiguration = async (contentTypeUids)=>{
8
+ /**
9
+ * Don't use the strapi.store util because we need to make
10
+ * more precise queries than exact key matches, in order to make as few queries as possible.
11
+ */ const coreStore = strapi.db.query('strapi::core-store');
12
+ const rawConfigurations = await coreStore.findMany({
13
+ where: {
14
+ key: {
15
+ $in: contentTypeUids.map((contentType)=>`plugin_content_manager_configuration_content_types::${contentType}`)
16
+ }
17
+ }
18
+ });
19
+ return rawConfigurations.map((rawConfiguration)=>{
20
+ return JSON.parse(rawConfiguration.value);
21
+ });
22
+ };
23
+ const getPermittedContentTypes = async ()=>{
24
+ const readPermissions = await permissionService.findMany({
25
+ where: {
26
+ role: {
27
+ users: {
28
+ id: strapi.requestContext.get()?.state?.user.id
29
+ }
30
+ },
31
+ action: 'plugin::content-manager.explorer.read'
32
+ }
33
+ });
34
+ return readPermissions.map((permission)=>permission.subject).filter(Boolean);
35
+ };
36
+ const getContentTypesMeta = (allowedContentTypeUids, configurations)=>{
37
+ return allowedContentTypeUids.map((uid)=>{
38
+ const configuration = configurations.find((config)=>config.uid === uid);
39
+ const contentType = strapi.contentType(uid);
40
+ const fields = [
41
+ 'documentId',
42
+ 'updatedAt'
43
+ ];
44
+ // Add fields required to get the status if D&P is enabled
45
+ const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);
46
+ if (hasDraftAndPublish) {
47
+ fields.push('publishedAt');
48
+ }
49
+ // Only add the main field if it's defined
50
+ if (configuration?.settings.mainField) {
51
+ fields.push(configuration.settings.mainField);
52
+ }
53
+ // Only add locale if it's localized
54
+ const isLocalized = contentType.pluginOptions?.i18n?.localized;
55
+ if (isLocalized) {
56
+ fields.push('locale');
57
+ }
58
+ return {
59
+ fields,
60
+ mainField: configuration.settings.mainField,
61
+ contentType,
62
+ hasDraftAndPublish,
63
+ uid
64
+ };
65
+ });
66
+ };
67
+ const formatDocuments = (documents, meta)=>{
68
+ return documents.map((document)=>{
69
+ return {
70
+ documentId: document.documentId,
71
+ locale: document.locale ?? null,
72
+ updatedAt: new Date(document.updatedAt),
73
+ title: document[meta.mainField ?? 'documentId'],
74
+ publishedAt: meta.hasDraftAndPublish && document.publishedAt ? new Date(document.publishedAt) : null,
75
+ contentTypeUid: meta.uid,
76
+ contentTypeDisplayName: meta.contentType.info.displayName,
77
+ kind: meta.contentType.kind
78
+ };
79
+ });
80
+ };
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
+ const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');
99
+ const getPermissionChecker = (uid)=>permissionCheckerService.create({
100
+ userAbility: strapi.requestContext.get()?.state.userAbility,
101
+ model: uid
102
+ });
103
+ return {
104
+ async getRecentlyPublishedDocuments () {
105
+ const permittedContentTypes = await getPermittedContentTypes();
106
+ const allowedContentTypeUids = permittedContentTypes.filter((uid)=>{
107
+ return contentTypes.hasDraftAndPublish(strapi.contentType(uid));
108
+ });
109
+ // Fetch the configuration for each content type in a single query
110
+ const configurations = await getConfiguration(allowedContentTypeUids);
111
+ // Get the necessary metadata for the documents
112
+ const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);
113
+ // Now actually fetch and format the documents
114
+ const recentDocuments = await Promise.all(contentTypesMeta.map(async (meta)=>{
115
+ const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({
116
+ limit: MAX_DOCUMENTS,
117
+ sort: 'publishedAt:desc',
118
+ fields: meta.fields,
119
+ status: 'published'
120
+ });
121
+ const docs = await strapi.documents(meta.uid).findMany(permissionQuery);
122
+ return formatDocuments(docs, meta);
123
+ }));
124
+ const overallRecentDocuments = recentDocuments.flat().sort((a, b)=>{
125
+ if (!a.publishedAt || !b.publishedAt) return 0;
126
+ return b.publishedAt.valueOf() - a.publishedAt.valueOf();
127
+ }).slice(0, MAX_DOCUMENTS);
128
+ return addStatusToDocuments(overallRecentDocuments);
129
+ },
130
+ async getRecentlyUpdatedDocuments () {
131
+ const allowedContentTypeUids = await getPermittedContentTypes();
132
+ // Fetch the configuration for each content type in a single query
133
+ const configurations = await getConfiguration(allowedContentTypeUids);
134
+ // Get the necessary metadata for the documents
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);
150
+ }
151
+ };
152
+ };
153
+
154
+ export { createHomepageService };
155
+ //# sourceMappingURL=homepage.mjs.map
@@ -0,0 +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","sort","docs","overallRecentDocuments","flat","a","b","valueOf","slice","getRecentlyUpdatedDocuments"],"mappings":";;AAKA,MAAMA,qBAAwB,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;AAChE,IAAA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S,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;;;;"}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var homepage = require('./homepage.js');
4
+
5
+ const services = {
6
+ homepage: homepage.createHomepageService
7
+ };
8
+
9
+ exports.services = services;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../server/src/homepage/services/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\n\nimport { createHomepageService } from './homepage';\n\nexport const services = {\n homepage: createHomepageService,\n} satisfies Plugin.LoadedPlugin['services'];\n"],"names":["services","homepage","createHomepageService"],"mappings":";;;;MAIaA,QAAW,GAAA;IACtBC,QAAUC,EAAAA;AACZ;;;;"}
@@ -0,0 +1,8 @@
1
+ import { createHomepageService } from './homepage.mjs';
2
+
3
+ const services = {
4
+ homepage: createHomepageService
5
+ };
6
+
7
+ export { services };
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../server/src/homepage/services/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\n\nimport { createHomepageService } from './homepage';\n\nexport const services = {\n homepage: createHomepageService,\n} satisfies Plugin.LoadedPlugin['services'];\n"],"names":["services","homepage","createHomepageService"],"mappings":";;MAIaA,QAAW,GAAA;IACtBC,QAAUC,EAAAA;AACZ;;;;"}
@@ -18,7 +18,6 @@ var utils = require('../utils.js');
18
18
  strapi.log.error(`Failed to get preview URL: ${error}`);
19
19
  throw new strapiUtils.errors.ApplicationError('Failed to get preview URL');
20
20
  }
21
- return;
22
21
  }
23
22
  };
24
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","sources":["../../../../server/src/preview/services/preview.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { getService } from '../utils';\nimport type { HandlerParams } from './preview-config';\n\n/**\n * Responsible of routing an entry to a preview URL.\n */\nconst createPreviewService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = getService(strapi, 'preview-config');\n\n return {\n async getPreviewUrl(uid: UID.ContentType, params: HandlerParams) {\n const handler = config.getPreviewHandler();\n\n try {\n // Try to get the preview URL from the user-defined handler\n return handler(uid, params);\n } catch (error) {\n // Log the error and throw a generic error\n strapi.log.error(`Failed to get preview URL: ${error}`);\n throw new errors.ApplicationError('Failed to get preview URL');\n }\n\n return;\n },\n };\n};\n\nexport { createPreviewService };\n"],"names":["createPreviewService","strapi","config","getService","getPreviewUrl","uid","params","handler","getPreviewHandler","error","log","errors","ApplicationError"],"mappings":";;;;;AAMA;;AAEC,IACKA,MAAAA,oBAAAA,GAAuB,CAAC,EAAEC,MAAM,EAA2B,GAAA;IAC/D,MAAMC,MAAAA,GAASC,iBAAWF,MAAQ,EAAA,gBAAA,CAAA;IAElC,OAAO;QACL,MAAMG,aAAAA,CAAAA,CAAcC,GAAoB,EAAEC,MAAqB,EAAA;YAC7D,MAAMC,OAAAA,GAAUL,OAAOM,iBAAiB,EAAA;YAExC,IAAI;;AAEF,gBAAA,OAAOD,QAAQF,GAAKC,EAAAA,MAAAA,CAAAA;AACtB,aAAA,CAAE,OAAOG,KAAO,EAAA;;gBAEdR,MAAOS,CAAAA,GAAG,CAACD,KAAK,CAAC,CAAC,2BAA2B,EAAEA,MAAM,CAAC,CAAA;gBACtD,MAAM,IAAIE,kBAAOC,CAAAA,gBAAgB,CAAC,2BAAA,CAAA;AACpC;AAEA,YAAA;AACF;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"preview.js","sources":["../../../../server/src/preview/services/preview.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { getService } from '../utils';\nimport type { HandlerParams } from './preview-config';\n\n/**\n * Responsible of routing an entry to a preview URL.\n */\nconst createPreviewService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = getService(strapi, 'preview-config');\n\n return {\n async getPreviewUrl(uid: UID.ContentType, params: HandlerParams) {\n const handler = config.getPreviewHandler();\n\n try {\n // Try to get the preview URL from the user-defined handler\n return handler(uid, params);\n } catch (error) {\n // Log the error and throw a generic error\n strapi.log.error(`Failed to get preview URL: ${error}`);\n throw new errors.ApplicationError('Failed to get preview URL');\n }\n },\n };\n};\n\nexport { createPreviewService };\n"],"names":["createPreviewService","strapi","config","getService","getPreviewUrl","uid","params","handler","getPreviewHandler","error","log","errors","ApplicationError"],"mappings":";;;;;AAMA;;AAEC,IACKA,MAAAA,oBAAAA,GAAuB,CAAC,EAAEC,MAAM,EAA2B,GAAA;IAC/D,MAAMC,MAAAA,GAASC,iBAAWF,MAAQ,EAAA,gBAAA,CAAA;IAElC,OAAO;QACL,MAAMG,aAAAA,CAAAA,CAAcC,GAAoB,EAAEC,MAAqB,EAAA;YAC7D,MAAMC,OAAAA,GAAUL,OAAOM,iBAAiB,EAAA;YAExC,IAAI;;AAEF,gBAAA,OAAOD,QAAQF,GAAKC,EAAAA,MAAAA,CAAAA;AACtB,aAAA,CAAE,OAAOG,KAAO,EAAA;;gBAEdR,MAAOS,CAAAA,GAAG,CAACD,KAAK,CAAC,CAAC,2BAA2B,EAAEA,MAAM,CAAC,CAAA;gBACtD,MAAM,IAAIE,kBAAOC,CAAAA,gBAAgB,CAAC,2BAAA,CAAA;AACpC;AACF;AACF,KAAA;AACF;;;;"}
@@ -16,7 +16,6 @@ import { getService } from '../utils.mjs';
16
16
  strapi.log.error(`Failed to get preview URL: ${error}`);
17
17
  throw new errors.ApplicationError('Failed to get preview URL');
18
18
  }
19
- return;
20
19
  }
21
20
  };
22
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"preview.mjs","sources":["../../../../server/src/preview/services/preview.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { getService } from '../utils';\nimport type { HandlerParams } from './preview-config';\n\n/**\n * Responsible of routing an entry to a preview URL.\n */\nconst createPreviewService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = getService(strapi, 'preview-config');\n\n return {\n async getPreviewUrl(uid: UID.ContentType, params: HandlerParams) {\n const handler = config.getPreviewHandler();\n\n try {\n // Try to get the preview URL from the user-defined handler\n return handler(uid, params);\n } catch (error) {\n // Log the error and throw a generic error\n strapi.log.error(`Failed to get preview URL: ${error}`);\n throw new errors.ApplicationError('Failed to get preview URL');\n }\n\n return;\n },\n };\n};\n\nexport { createPreviewService };\n"],"names":["createPreviewService","strapi","config","getService","getPreviewUrl","uid","params","handler","getPreviewHandler","error","log","errors","ApplicationError"],"mappings":";;;AAMA;;AAEC,IACKA,MAAAA,oBAAAA,GAAuB,CAAC,EAAEC,MAAM,EAA2B,GAAA;IAC/D,MAAMC,MAAAA,GAASC,WAAWF,MAAQ,EAAA,gBAAA,CAAA;IAElC,OAAO;QACL,MAAMG,aAAAA,CAAAA,CAAcC,GAAoB,EAAEC,MAAqB,EAAA;YAC7D,MAAMC,OAAAA,GAAUL,OAAOM,iBAAiB,EAAA;YAExC,IAAI;;AAEF,gBAAA,OAAOD,QAAQF,GAAKC,EAAAA,MAAAA,CAAAA;AACtB,aAAA,CAAE,OAAOG,KAAO,EAAA;;gBAEdR,MAAOS,CAAAA,GAAG,CAACD,KAAK,CAAC,CAAC,2BAA2B,EAAEA,MAAM,CAAC,CAAA;gBACtD,MAAM,IAAIE,MAAOC,CAAAA,gBAAgB,CAAC,2BAAA,CAAA;AACpC;AAEA,YAAA;AACF;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"preview.mjs","sources":["../../../../server/src/preview/services/preview.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { getService } from '../utils';\nimport type { HandlerParams } from './preview-config';\n\n/**\n * Responsible of routing an entry to a preview URL.\n */\nconst createPreviewService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = getService(strapi, 'preview-config');\n\n return {\n async getPreviewUrl(uid: UID.ContentType, params: HandlerParams) {\n const handler = config.getPreviewHandler();\n\n try {\n // Try to get the preview URL from the user-defined handler\n return handler(uid, params);\n } catch (error) {\n // Log the error and throw a generic error\n strapi.log.error(`Failed to get preview URL: ${error}`);\n throw new errors.ApplicationError('Failed to get preview URL');\n }\n },\n };\n};\n\nexport { createPreviewService };\n"],"names":["createPreviewService","strapi","config","getService","getPreviewUrl","uid","params","handler","getPreviewHandler","error","log","errors","ApplicationError"],"mappings":";;;AAMA;;AAEC,IACKA,MAAAA,oBAAAA,GAAuB,CAAC,EAAEC,MAAM,EAA2B,GAAA;IAC/D,MAAMC,MAAAA,GAASC,WAAWF,MAAQ,EAAA,gBAAA,CAAA;IAElC,OAAO;QACL,MAAMG,aAAAA,CAAAA,CAAcC,GAAoB,EAAEC,MAAqB,EAAA;YAC7D,MAAMC,OAAAA,GAAUL,OAAOM,iBAAiB,EAAA;YAExC,IAAI;;AAEF,gBAAA,OAAOD,QAAQF,GAAKC,EAAAA,MAAAA,CAAAA;AACtB,aAAA,CAAE,OAAOG,KAAO,EAAA;;gBAEdR,MAAOS,CAAAA,GAAG,CAACD,KAAK,CAAC,CAAC,2BAA2B,EAAEA,MAAM,CAAC,CAAA;gBACtD,MAAM,IAAIE,MAAOC,CAAAA,gBAAgB,CAAC,2BAAA,CAAA;AACpC;AACF;AACF,KAAA;AACF;;;;"}