@strapi/content-releases 0.0.0-next.334c95408abdd9ecc0ece0e8c0fd5eb0024ad027 → 0.0.0-next.36632203b17974c18103c138ffbef53a82e448c3

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 (140) hide show
  1. package/LICENSE +17 -1
  2. package/dist/_chunks/App-BKB1esYS.js +1395 -0
  3. package/dist/_chunks/App-BKB1esYS.js.map +1 -0
  4. package/dist/_chunks/App-Cne--1Z8.mjs +1374 -0
  5. package/dist/_chunks/App-Cne--1Z8.mjs.map +1 -0
  6. package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js +52 -0
  7. package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +1 -0
  8. package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs +52 -0
  9. package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +1 -0
  10. package/dist/_chunks/ReleasesSettingsPage-C1WwGWIH.mjs +178 -0
  11. package/dist/_chunks/ReleasesSettingsPage-C1WwGWIH.mjs.map +1 -0
  12. package/dist/_chunks/ReleasesSettingsPage-kuXIwpWp.js +178 -0
  13. package/dist/_chunks/ReleasesSettingsPage-kuXIwpWp.js.map +1 -0
  14. package/dist/_chunks/{en-gYDqKYFd.js → en-CmYoEnA7.js} +37 -7
  15. package/dist/_chunks/en-CmYoEnA7.js.map +1 -0
  16. package/dist/_chunks/{en-MyLPoISH.mjs → en-D0yVZFqf.mjs} +37 -7
  17. package/dist/_chunks/en-D0yVZFqf.mjs.map +1 -0
  18. package/dist/_chunks/index-5Odi61vw.js +1381 -0
  19. package/dist/_chunks/index-5Odi61vw.js.map +1 -0
  20. package/dist/_chunks/index-Cy7qwpaU.mjs +1362 -0
  21. package/dist/_chunks/index-Cy7qwpaU.mjs.map +1 -0
  22. package/dist/_chunks/schemas-BE1LxE9J.js +62 -0
  23. package/dist/_chunks/schemas-BE1LxE9J.js.map +1 -0
  24. package/dist/_chunks/schemas-DdA2ic2U.mjs +44 -0
  25. package/dist/_chunks/schemas-DdA2ic2U.mjs.map +1 -0
  26. package/dist/admin/index.js +1 -15
  27. package/dist/admin/index.js.map +1 -1
  28. package/dist/admin/index.mjs +2 -16
  29. package/dist/admin/index.mjs.map +1 -1
  30. package/dist/admin/src/components/RelativeTime.d.ts +28 -0
  31. package/dist/admin/src/components/ReleaseAction.d.ts +3 -0
  32. package/dist/admin/src/components/ReleaseActionMenu.d.ts +26 -0
  33. package/dist/admin/src/components/ReleaseActionModal.d.ts +24 -0
  34. package/dist/admin/src/components/ReleaseActionOptions.d.ts +9 -0
  35. package/dist/admin/src/components/ReleaseListCell.d.ts +28 -0
  36. package/dist/admin/src/components/ReleaseModal.d.ts +17 -0
  37. package/dist/admin/src/components/ReleasesPanel.d.ts +3 -0
  38. package/dist/admin/src/constants.d.ts +76 -0
  39. package/dist/admin/src/index.d.ts +3 -0
  40. package/dist/admin/src/modules/hooks.d.ts +7 -0
  41. package/dist/admin/src/pages/App.d.ts +1 -0
  42. package/dist/admin/src/pages/PurchaseContentReleases.d.ts +2 -0
  43. package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +2 -0
  44. package/dist/admin/src/pages/ReleasesPage.d.ts +8 -0
  45. package/dist/admin/src/pages/ReleasesSettingsPage.d.ts +1 -0
  46. package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +181 -0
  47. package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +39 -0
  48. package/dist/admin/src/pluginId.d.ts +1 -0
  49. package/dist/admin/src/services/release.d.ts +112 -0
  50. package/dist/admin/src/store/hooks.d.ts +7 -0
  51. package/dist/admin/src/utils/api.d.ts +6 -0
  52. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  53. package/dist/admin/src/utils/time.d.ts +10 -0
  54. package/dist/admin/src/validation/schemas.d.ts +6 -0
  55. package/dist/server/index.js +1409 -458
  56. package/dist/server/index.js.map +1 -1
  57. package/dist/server/index.mjs +1409 -458
  58. package/dist/server/index.mjs.map +1 -1
  59. package/dist/server/src/bootstrap.d.ts +5 -0
  60. package/dist/server/src/bootstrap.d.ts.map +1 -0
  61. package/dist/server/src/constants.d.ts +21 -0
  62. package/dist/server/src/constants.d.ts.map +1 -0
  63. package/dist/server/src/content-types/index.d.ts +97 -0
  64. package/dist/server/src/content-types/index.d.ts.map +1 -0
  65. package/dist/server/src/content-types/release/index.d.ts +48 -0
  66. package/dist/server/src/content-types/release/index.d.ts.map +1 -0
  67. package/dist/server/src/content-types/release/schema.d.ts +47 -0
  68. package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
  69. package/dist/server/src/content-types/release-action/index.d.ts +48 -0
  70. package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
  71. package/dist/server/src/content-types/release-action/schema.d.ts +47 -0
  72. package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
  73. package/dist/server/src/controllers/index.d.ts +25 -0
  74. package/dist/server/src/controllers/index.d.ts.map +1 -0
  75. package/dist/server/src/controllers/release-action.d.ts +10 -0
  76. package/dist/server/src/controllers/release-action.d.ts.map +1 -0
  77. package/dist/server/src/controllers/release.d.ts +18 -0
  78. package/dist/server/src/controllers/release.d.ts.map +1 -0
  79. package/dist/server/src/controllers/settings.d.ts +11 -0
  80. package/dist/server/src/controllers/settings.d.ts.map +1 -0
  81. package/dist/server/src/controllers/validation/release-action.d.ts +14 -0
  82. package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
  83. package/dist/server/src/controllers/validation/release.d.ts +4 -0
  84. package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
  85. package/dist/server/src/controllers/validation/settings.d.ts +3 -0
  86. package/dist/server/src/controllers/validation/settings.d.ts.map +1 -0
  87. package/dist/server/src/destroy.d.ts +5 -0
  88. package/dist/server/src/destroy.d.ts.map +1 -0
  89. package/dist/server/src/index.d.ts +2115 -0
  90. package/dist/server/src/index.d.ts.map +1 -0
  91. package/dist/server/src/middlewares/documents.d.ts +6 -0
  92. package/dist/server/src/middlewares/documents.d.ts.map +1 -0
  93. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts +9 -0
  94. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -0
  95. package/dist/server/src/migrations/index.d.ts +13 -0
  96. package/dist/server/src/migrations/index.d.ts.map +1 -0
  97. package/dist/server/src/register.d.ts +5 -0
  98. package/dist/server/src/register.d.ts.map +1 -0
  99. package/dist/server/src/routes/index.d.ts +51 -0
  100. package/dist/server/src/routes/index.d.ts.map +1 -0
  101. package/dist/server/src/routes/release-action.d.ts +18 -0
  102. package/dist/server/src/routes/release-action.d.ts.map +1 -0
  103. package/dist/server/src/routes/release.d.ts +18 -0
  104. package/dist/server/src/routes/release.d.ts.map +1 -0
  105. package/dist/server/src/routes/settings.d.ts +18 -0
  106. package/dist/server/src/routes/settings.d.ts.map +1 -0
  107. package/dist/server/src/services/index.d.ts +1828 -0
  108. package/dist/server/src/services/index.d.ts.map +1 -0
  109. package/dist/server/src/services/release-action.d.ts +38 -0
  110. package/dist/server/src/services/release-action.d.ts.map +1 -0
  111. package/dist/server/src/services/release.d.ts +31 -0
  112. package/dist/server/src/services/release.d.ts.map +1 -0
  113. package/dist/server/src/services/scheduling.d.ts +18 -0
  114. package/dist/server/src/services/scheduling.d.ts.map +1 -0
  115. package/dist/server/src/services/settings.d.ts +13 -0
  116. package/dist/server/src/services/settings.d.ts.map +1 -0
  117. package/dist/server/src/services/validation.d.ts +18 -0
  118. package/dist/server/src/services/validation.d.ts.map +1 -0
  119. package/dist/server/src/utils/index.d.ts +35 -0
  120. package/dist/server/src/utils/index.d.ts.map +1 -0
  121. package/dist/shared/contracts/release-actions.d.ts +130 -0
  122. package/dist/shared/contracts/release-actions.d.ts.map +1 -0
  123. package/dist/shared/contracts/releases.d.ts +184 -0
  124. package/dist/shared/contracts/releases.d.ts.map +1 -0
  125. package/dist/shared/contracts/settings.d.ts +39 -0
  126. package/dist/shared/contracts/settings.d.ts.map +1 -0
  127. package/dist/shared/types.d.ts +24 -0
  128. package/dist/shared/types.d.ts.map +1 -0
  129. package/package.json +35 -35
  130. package/dist/_chunks/App-AYV8n9jv.js +0 -989
  131. package/dist/_chunks/App-AYV8n9jv.js.map +0 -1
  132. package/dist/_chunks/App-KBaxZVmD.mjs +0 -967
  133. package/dist/_chunks/App-KBaxZVmD.mjs.map +0 -1
  134. package/dist/_chunks/en-MyLPoISH.mjs.map +0 -1
  135. package/dist/_chunks/en-gYDqKYFd.js.map +0 -1
  136. package/dist/_chunks/index-FYDbIuRi.js +0 -905
  137. package/dist/_chunks/index-FYDbIuRi.js.map +0 -1
  138. package/dist/_chunks/index-NFIckO1N.mjs +0 -884
  139. package/dist/_chunks/index-NFIckO1N.mjs.map +0 -1
  140. package/strapi-server.js +0 -3
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  const utils = require("@strapi/utils");
3
+ const isEqual = require("lodash/isEqual");
4
+ const lodash = require("lodash");
3
5
  const _ = require("lodash/fp");
4
- const EE = require("@strapi/strapi/dist/utils/ee");
6
+ const nodeSchedule = require("node-schedule");
5
7
  const yup = require("yup");
6
8
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
7
9
  function _interopNamespace(e) {
@@ -22,8 +24,8 @@ function _interopNamespace(e) {
22
24
  n.default = e;
23
25
  return Object.freeze(n);
24
26
  }
27
+ const isEqual__default = /* @__PURE__ */ _interopDefault(isEqual);
25
28
  const ___default = /* @__PURE__ */ _interopDefault(_);
26
- const EE__default = /* @__PURE__ */ _interopDefault(EE);
27
29
  const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
28
30
  const RELEASE_MODEL_UID = "plugin::content-releases.release";
29
31
  const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
@@ -69,82 +71,455 @@ const ACTIONS = [
69
71
  displayName: "Add an entry to a release",
70
72
  uid: "create-action",
71
73
  pluginName: "content-releases"
74
+ },
75
+ // Settings
76
+ {
77
+ uid: "settings.read",
78
+ section: "settings",
79
+ displayName: "Read",
80
+ category: "content releases",
81
+ subCategory: "options",
82
+ pluginName: "content-releases"
83
+ },
84
+ {
85
+ uid: "settings.update",
86
+ section: "settings",
87
+ displayName: "Edit",
88
+ category: "content releases",
89
+ subCategory: "options",
90
+ pluginName: "content-releases"
72
91
  }
73
92
  ];
74
- const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
93
+ const ALLOWED_WEBHOOK_EVENTS = {
94
+ RELEASES_PUBLISH: "releases.publish"
95
+ };
96
+ const getService = (name, { strapi: strapi2 }) => {
75
97
  return strapi2.plugin("content-releases").service(name);
76
98
  };
77
- const { features: features$2 } = require("@strapi/strapi/dist/utils/ee");
78
- const register = async ({ strapi: strapi2 }) => {
79
- if (features$2.isEnabled("cms-content-releases") && strapi2.features.future.isEnabled("contentReleases")) {
80
- await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
81
- const releaseActionService = getService("release-action", { strapi: strapi2 });
82
- const eventManager = getService("event-manager", { strapi: strapi2 });
83
- const destroyContentTypeUpdateListener = strapi2.eventHub.on(
84
- "content-type.update",
85
- async ({ contentType }) => {
86
- if (contentType.schema.options.draftAndPublish === false) {
87
- await releaseActionService.deleteManyForContentType(contentType.uid);
99
+ const getDraftEntryValidStatus = async ({ contentType, documentId, locale }, { strapi: strapi2 }) => {
100
+ const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
101
+ const populate = await populateBuilderService(contentType).populateDeep(Infinity).build();
102
+ const entry = await getEntry({ contentType, documentId, locale, populate }, { strapi: strapi2 });
103
+ return isEntryValid(contentType, entry, { strapi: strapi2 });
104
+ };
105
+ const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
106
+ try {
107
+ await strapi2.entityValidator.validateEntityCreation(
108
+ strapi2.getModel(contentTypeUid),
109
+ entry,
110
+ void 0,
111
+ // @ts-expect-error - FIXME: entity here is unnecessary
112
+ entry
113
+ );
114
+ return true;
115
+ } catch {
116
+ return false;
117
+ }
118
+ };
119
+ const getEntry = async ({
120
+ contentType,
121
+ documentId,
122
+ locale,
123
+ populate,
124
+ status = "draft"
125
+ }, { strapi: strapi2 }) => {
126
+ if (documentId) {
127
+ const entry = await strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
128
+ if (status === "published" && !entry) {
129
+ return strapi2.documents(contentType).findOne({ documentId, locale, populate, status: "draft" });
130
+ }
131
+ return entry;
132
+ }
133
+ return strapi2.documents(contentType).findFirst({ locale, populate, status });
134
+ };
135
+ const getEntryStatus = async (contentType, entry) => {
136
+ if (entry.publishedAt) {
137
+ return "published";
138
+ }
139
+ const publishedEntry = await strapi.documents(contentType).findOne({
140
+ documentId: entry.documentId,
141
+ locale: entry.locale,
142
+ status: "published",
143
+ fields: ["updatedAt"]
144
+ });
145
+ if (!publishedEntry) {
146
+ return "draft";
147
+ }
148
+ const entryUpdatedAt = new Date(entry.updatedAt).getTime();
149
+ const publishedEntryUpdatedAt = new Date(publishedEntry.updatedAt).getTime();
150
+ if (entryUpdatedAt > publishedEntryUpdatedAt) {
151
+ return "modified";
152
+ }
153
+ return "published";
154
+ };
155
+ async function deleteActionsOnDisableDraftAndPublish({
156
+ oldContentTypes,
157
+ contentTypes: contentTypes2
158
+ }) {
159
+ if (!oldContentTypes) {
160
+ return;
161
+ }
162
+ for (const uid in contentTypes2) {
163
+ if (!oldContentTypes[uid]) {
164
+ continue;
165
+ }
166
+ const oldContentType = oldContentTypes[uid];
167
+ const contentType = contentTypes2[uid];
168
+ if (utils.contentTypes.hasDraftAndPublish(oldContentType) && !utils.contentTypes.hasDraftAndPublish(contentType)) {
169
+ await strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: uid }).execute();
170
+ }
171
+ }
172
+ }
173
+ async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes: contentTypes2 }) {
174
+ const deletedContentTypes = lodash.difference(lodash.keys(oldContentTypes), lodash.keys(contentTypes2)) ?? [];
175
+ if (deletedContentTypes.length) {
176
+ await utils.async.map(deletedContentTypes, async (deletedContentTypeUID) => {
177
+ return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: deletedContentTypeUID }).execute();
178
+ });
179
+ }
180
+ }
181
+ async function migrateIsValidAndStatusReleases() {
182
+ const releasesWithoutStatus = await strapi.db.query(RELEASE_MODEL_UID).findMany({
183
+ where: {
184
+ status: null,
185
+ releasedAt: null
186
+ },
187
+ populate: {
188
+ actions: {
189
+ populate: {
190
+ entry: true
88
191
  }
89
192
  }
90
- );
91
- eventManager.addDestroyListenerCallback(destroyContentTypeUpdateListener);
92
- const destroyContentTypeDeleteListener = strapi2.eventHub.on(
93
- "content-type.delete",
94
- async ({ contentType }) => {
95
- await releaseActionService.deleteManyForContentType(contentType.uid);
193
+ }
194
+ });
195
+ utils.async.map(releasesWithoutStatus, async (release2) => {
196
+ const actions = release2.actions;
197
+ const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
198
+ for (const action of notValidatedActions) {
199
+ if (action.entry) {
200
+ const isEntryValid2 = getDraftEntryValidStatus(
201
+ {
202
+ contentType: action.contentType,
203
+ documentId: action.entryDocumentId,
204
+ locale: action.locale
205
+ },
206
+ { strapi }
207
+ );
208
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
209
+ where: {
210
+ id: action.id
211
+ },
212
+ data: {
213
+ isEntryValid: isEntryValid2
214
+ }
215
+ });
216
+ }
217
+ }
218
+ return getService("release", { strapi }).updateReleaseStatus(release2.id);
219
+ });
220
+ const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
221
+ where: {
222
+ status: null,
223
+ releasedAt: {
224
+ $notNull: true
225
+ }
226
+ }
227
+ });
228
+ utils.async.map(publishedReleases, async (release2) => {
229
+ return strapi.db.query(RELEASE_MODEL_UID).update({
230
+ where: {
231
+ id: release2.id
232
+ },
233
+ data: {
234
+ status: "done"
96
235
  }
236
+ });
237
+ });
238
+ }
239
+ async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: contentTypes2 }) {
240
+ if (oldContentTypes !== void 0 && contentTypes2 !== void 0) {
241
+ const contentTypesWithDraftAndPublish = Object.keys(oldContentTypes).filter(
242
+ (uid) => oldContentTypes[uid]?.options?.draftAndPublish
97
243
  );
98
- eventManager.addDestroyListenerCallback(destroyContentTypeDeleteListener);
244
+ const releasesAffected = /* @__PURE__ */ new Set();
245
+ utils.async.map(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
246
+ const oldContentType = oldContentTypes[contentTypeUID];
247
+ const contentType = contentTypes2[contentTypeUID];
248
+ if (!isEqual__default.default(oldContentType?.attributes, contentType?.attributes)) {
249
+ const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
250
+ where: {
251
+ contentType: contentTypeUID
252
+ },
253
+ populate: {
254
+ entry: true,
255
+ release: true
256
+ }
257
+ });
258
+ await utils.async.map(actions, async (action) => {
259
+ if (action.entry && action.release && action.type === "publish") {
260
+ const isEntryValid2 = await getDraftEntryValidStatus(
261
+ {
262
+ contentType: contentTypeUID,
263
+ documentId: action.entryDocumentId,
264
+ locale: action.locale
265
+ },
266
+ { strapi }
267
+ );
268
+ releasesAffected.add(action.release.id);
269
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
270
+ where: {
271
+ id: action.id
272
+ },
273
+ data: {
274
+ isEntryValid: isEntryValid2
275
+ }
276
+ });
277
+ }
278
+ });
279
+ }
280
+ }).then(() => {
281
+ utils.async.map(releasesAffected, async (releaseId) => {
282
+ return getService("release", { strapi }).updateReleaseStatus(releaseId);
283
+ });
284
+ });
285
+ }
286
+ }
287
+ async function disableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
288
+ if (!oldContentTypes) {
289
+ return;
290
+ }
291
+ const i18nPlugin = strapi.plugin("i18n");
292
+ if (!i18nPlugin) {
293
+ return;
294
+ }
295
+ for (const uid in contentTypes2) {
296
+ if (!oldContentTypes[uid]) {
297
+ continue;
298
+ }
299
+ const oldContentType = oldContentTypes[uid];
300
+ const contentType = contentTypes2[uid];
301
+ const { isLocalizedContentType } = i18nPlugin.service("content-types");
302
+ if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
303
+ await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
304
+ locale: null
305
+ }).where({ contentType: uid }).execute();
306
+ }
307
+ }
308
+ }
309
+ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
310
+ if (!oldContentTypes) {
311
+ return;
312
+ }
313
+ const i18nPlugin = strapi.plugin("i18n");
314
+ if (!i18nPlugin) {
315
+ return;
316
+ }
317
+ for (const uid in contentTypes2) {
318
+ if (!oldContentTypes[uid]) {
319
+ continue;
320
+ }
321
+ const oldContentType = oldContentTypes[uid];
322
+ const contentType = contentTypes2[uid];
323
+ const { isLocalizedContentType } = i18nPlugin.service("content-types");
324
+ const { getDefaultLocale } = i18nPlugin.service("locales");
325
+ if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
326
+ const defaultLocale = await getDefaultLocale();
327
+ await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
328
+ locale: defaultLocale
329
+ }).where({ contentType: uid }).execute();
330
+ }
331
+ }
332
+ }
333
+ const addEntryDocumentToReleaseActions = {
334
+ name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
335
+ async up(trx, db) {
336
+ const hasTable = await trx.schema.hasTable("strapi_release_actions");
337
+ if (!hasTable) {
338
+ return;
339
+ }
340
+ const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
341
+ if (hasPolymorphicColumn) {
342
+ const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
343
+ "strapi_release_actions",
344
+ "entry_document_id"
345
+ );
346
+ if (!hasEntryDocumentIdColumn) {
347
+ await trx.schema.alterTable("strapi_release_actions", (table) => {
348
+ table.string("entry_document_id");
349
+ });
350
+ }
351
+ const releaseActions = await trx.select("*").from("strapi_release_actions");
352
+ utils.async.map(releaseActions, async (action) => {
353
+ const { target_type, target_id } = action;
354
+ const entry = await db.query(target_type).findOne({ where: { id: target_id } });
355
+ if (entry) {
356
+ await trx("strapi_release_actions").update({ entry_document_id: entry.documentId }).where("id", action.id);
357
+ }
358
+ });
359
+ }
360
+ },
361
+ async down() {
362
+ throw new Error("not implemented");
363
+ }
364
+ };
365
+ const register = async ({ strapi: strapi2 }) => {
366
+ if (strapi2.ee.features.isEnabled("cms-content-releases")) {
367
+ await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
368
+ strapi2.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
369
+ strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
370
+ strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
371
+ }
372
+ if (strapi2.plugin("graphql")) {
373
+ const graphqlExtensionService = strapi2.plugin("graphql").service("extension");
374
+ graphqlExtensionService.shadowCRUD(RELEASE_MODEL_UID).disable();
375
+ graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
376
+ }
377
+ };
378
+ const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
379
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
380
+ where: {
381
+ actions: {
382
+ contentType,
383
+ entryDocumentId: entry.documentId,
384
+ locale: entry.locale
385
+ }
386
+ }
387
+ });
388
+ const entryStatus = await isEntryValid(contentType, entry, { strapi });
389
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
390
+ where: {
391
+ contentType,
392
+ entryDocumentId: entry.documentId,
393
+ locale: entry.locale
394
+ },
395
+ data: {
396
+ isEntryValid: entryStatus
397
+ }
398
+ });
399
+ for (const release2 of releases) {
400
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
401
+ }
402
+ };
403
+ const deleteActionsAndUpdateReleaseStatus = async (params) => {
404
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
405
+ where: {
406
+ actions: params
407
+ }
408
+ });
409
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
410
+ where: params
411
+ });
412
+ for (const release2 of releases) {
413
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
414
+ }
415
+ };
416
+ const deleteActionsOnDelete = async (ctx, next) => {
417
+ if (ctx.action !== "delete") {
418
+ return next();
419
+ }
420
+ if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
421
+ return next();
422
+ }
423
+ const contentType = ctx.contentType.uid;
424
+ const { documentId, locale } = ctx.params;
425
+ const result = await next();
426
+ if (!result) {
427
+ return result;
428
+ }
429
+ try {
430
+ deleteActionsAndUpdateReleaseStatus({
431
+ contentType,
432
+ entryDocumentId: documentId,
433
+ ...locale !== "*" && { locale }
434
+ });
435
+ } catch (error) {
436
+ strapi.log.error("Error while deleting release actions after delete", {
437
+ error
438
+ });
439
+ }
440
+ return result;
441
+ };
442
+ const updateActionsOnUpdate = async (ctx, next) => {
443
+ if (ctx.action !== "update") {
444
+ return next();
445
+ }
446
+ if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
447
+ return next();
448
+ }
449
+ const contentType = ctx.contentType.uid;
450
+ const result = await next();
451
+ if (!result) {
452
+ return result;
453
+ }
454
+ try {
455
+ updateActionsStatusAndUpdateReleaseStatus(contentType, result);
456
+ } catch (error) {
457
+ strapi.log.error("Error while updating release actions after update", {
458
+ error
459
+ });
460
+ }
461
+ return result;
462
+ };
463
+ const deleteReleasesActionsAndUpdateReleaseStatus = async (params) => {
464
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
465
+ where: {
466
+ actions: params
467
+ }
468
+ });
469
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
470
+ where: params
471
+ });
472
+ for (const release2 of releases) {
473
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
99
474
  }
100
475
  };
101
- const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
102
476
  const bootstrap = async ({ strapi: strapi2 }) => {
103
- if (features$1.isEnabled("cms-content-releases") && strapi2.features.future.isEnabled("contentReleases")) {
477
+ if (strapi2.ee.features.isEnabled("cms-content-releases")) {
478
+ const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
479
+ (uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
480
+ );
104
481
  strapi2.db.lifecycles.subscribe({
105
- afterDelete(event) {
106
- const { model, result } = event;
107
- if (model.kind === "collectionType" && model.options.draftAndPublish) {
108
- const { id } = result;
109
- strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
110
- where: {
111
- target_type: model.uid,
112
- target_id: id
113
- }
114
- });
115
- }
116
- },
482
+ models: contentTypesWithDraftAndPublish,
117
483
  /**
118
- * deleteMany hook doesn't return the deleted entries ids
119
- * so we need to fetch them before deleting the entries to save the ids on our state
120
- */
121
- async beforeDeleteMany(event) {
122
- const { model, params } = event;
123
- if (model.kind === "collectionType" && model.options.draftAndPublish) {
124
- const { where } = params;
125
- const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
126
- event.state.entriesToDelete = entriesToDelete;
127
- }
128
- },
129
- /**
130
- * We delete the release actions related to deleted entries
131
- * We make this only after deleteMany is succesfully executed to avoid errors
484
+ * deleteMany is still used outside documents service, for example when deleting a locale
132
485
  */
133
486
  async afterDeleteMany(event) {
134
- const { model, state } = event;
135
- const entriesToDelete = state.entriesToDelete;
136
- if (entriesToDelete) {
137
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
138
- where: {
139
- target_type: model.uid,
140
- target_id: {
141
- $in: entriesToDelete.map((entry) => entry.id)
142
- }
143
- }
487
+ try {
488
+ const model = strapi2.getModel(event.model.uid);
489
+ if (model.kind === "collectionType" && model.options?.draftAndPublish) {
490
+ const { where } = event.params;
491
+ deleteReleasesActionsAndUpdateReleaseStatus({
492
+ contentType: model.uid,
493
+ locale: where?.locale ?? null,
494
+ ...where?.documentId && { entryDocumentId: where.documentId }
495
+ });
496
+ }
497
+ } catch (error) {
498
+ strapi2.log.error("Error while deleting release actions after entry deleteMany", {
499
+ error
144
500
  });
145
501
  }
146
502
  }
147
503
  });
504
+ strapi2.documents.use(deleteActionsOnDelete);
505
+ strapi2.documents.use(updateActionsOnUpdate);
506
+ getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
507
+ strapi2.log.error(
508
+ "Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
509
+ );
510
+ throw err;
511
+ });
512
+ Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
513
+ strapi2.get("webhookStore").addAllowedEvent(key, value);
514
+ });
515
+ }
516
+ };
517
+ const destroy = async ({ strapi: strapi2 }) => {
518
+ const scheduledJobs = getService("scheduling", {
519
+ strapi: strapi2
520
+ }).getAll();
521
+ for (const [, job] of scheduledJobs) {
522
+ job.cancel();
148
523
  }
149
524
  };
150
525
  const schema$1 = {
@@ -173,6 +548,17 @@ const schema$1 = {
173
548
  releasedAt: {
174
549
  type: "datetime"
175
550
  },
551
+ scheduledAt: {
552
+ type: "datetime"
553
+ },
554
+ timezone: {
555
+ type: "string"
556
+ },
557
+ status: {
558
+ type: "enumeration",
559
+ enum: ["ready", "blocked", "failed", "done", "empty"],
560
+ required: true
561
+ },
176
562
  actions: {
177
563
  type: "relation",
178
564
  relation: "oneToMany",
@@ -208,15 +594,13 @@ const schema = {
208
594
  enum: ["publish", "unpublish"],
209
595
  required: true
210
596
  },
211
- entry: {
212
- type: "relation",
213
- relation: "morphToOne",
214
- configurable: false
215
- },
216
597
  contentType: {
217
598
  type: "string",
218
599
  required: true
219
600
  },
601
+ entryDocumentId: {
602
+ type: "string"
603
+ },
220
604
  locale: {
221
605
  type: "string"
222
606
  },
@@ -225,6 +609,9 @@ const schema = {
225
609
  relation: "manyToOne",
226
610
  target: RELEASE_MODEL_UID,
227
611
  inversedBy: "actions"
612
+ },
613
+ isEntryValid: {
614
+ type: "boolean"
228
615
  }
229
616
  }
230
617
  };
@@ -235,211 +622,297 @@ const contentTypes = {
235
622
  release: release$1,
236
623
  "release-action": releaseAction$1
237
624
  };
238
- const createReleaseActionService = ({ strapi: strapi2 }) => ({
239
- async deleteManyForContentType(contentTypeUid) {
240
- return strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
241
- where: {
242
- target_type: contentTypeUid
243
- }
625
+ const createReleaseService = ({ strapi: strapi2 }) => {
626
+ const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
627
+ strapi2.eventHub.emit(event, {
628
+ isPublished,
629
+ error,
630
+ release: release2
244
631
  });
245
- }
246
- });
247
- const getGroupName = (queryValue) => {
248
- switch (queryValue) {
249
- case "contentType":
250
- return "entry.contentType.displayName";
251
- case "action":
252
- return "type";
253
- case "locale":
254
- return ___default.default.getOr("No locale", "entry.locale.name");
255
- default:
256
- return "entry.contentType.displayName";
257
- }
258
- };
259
- const createReleaseService = ({ strapi: strapi2 }) => ({
260
- async create(releaseData, { user }) {
261
- const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
262
- await getService("release-validation", { strapi: strapi2 }).validatePendingReleasesLimit();
263
- return strapi2.entityService.create(RELEASE_MODEL_UID, {
264
- data: releaseWithCreatorFields
265
- });
266
- },
267
- async findOne(id, query = {}) {
268
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
269
- ...query
270
- });
271
- return release2;
272
- },
273
- findPage(query) {
274
- return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
275
- ...query,
276
- populate: {
277
- actions: {
278
- // @ts-expect-error Ignore missing properties
279
- count: true
632
+ };
633
+ const getFormattedActions = async (releaseId) => {
634
+ const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
635
+ where: {
636
+ release: {
637
+ id: releaseId
280
638
  }
281
639
  }
282
640
  });
283
- },
284
- async findManyForContentTypeEntry(contentTypeUid, entryId, {
285
- hasEntryAttached
286
- } = {
287
- hasEntryAttached: false
288
- }) {
289
- const whereActions = hasEntryAttached ? {
290
- // Find all Releases where the content type entry is present
291
- actions: {
292
- target_type: contentTypeUid,
293
- target_id: entryId
641
+ if (actions.length === 0) {
642
+ throw new utils.errors.ValidationError("No entries to publish");
643
+ }
644
+ const formattedActions = {};
645
+ for (const action of actions) {
646
+ const contentTypeUid = action.contentType;
647
+ if (!formattedActions[contentTypeUid]) {
648
+ formattedActions[contentTypeUid] = {
649
+ publish: [],
650
+ unpublish: []
651
+ };
294
652
  }
295
- } : {
296
- // Find all Releases where the content type entry is not present
297
- $or: [
298
- {
299
- $not: {
300
- actions: {
301
- target_type: contentTypeUid,
302
- target_id: entryId
303
- }
304
- }
305
- },
306
- {
307
- actions: null
308
- }
309
- ]
310
- };
311
- const populateAttachedAction = hasEntryAttached ? {
312
- // Filter the action to get only the content type entry
313
- actions: {
314
- where: {
315
- target_type: contentTypeUid,
316
- target_id: entryId
653
+ formattedActions[contentTypeUid][action.type].push({
654
+ documentId: action.entryDocumentId,
655
+ locale: action.locale
656
+ });
657
+ }
658
+ return formattedActions;
659
+ };
660
+ return {
661
+ async create(releaseData, { user }) {
662
+ const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
663
+ const {
664
+ validatePendingReleasesLimit,
665
+ validateUniqueNameForPendingRelease,
666
+ validateScheduledAtIsLaterThanNow
667
+ } = getService("release-validation", { strapi: strapi2 });
668
+ await Promise.all([
669
+ validatePendingReleasesLimit(),
670
+ validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
671
+ validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
672
+ ]);
673
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).create({
674
+ data: {
675
+ ...releaseWithCreatorFields,
676
+ status: "empty"
317
677
  }
678
+ });
679
+ if (releaseWithCreatorFields.scheduledAt) {
680
+ const schedulingService = getService("scheduling", { strapi: strapi2 });
681
+ await schedulingService.set(release2.id, release2.scheduledAt);
318
682
  }
319
- } : {};
320
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
321
- where: {
322
- ...whereActions,
323
- releasedAt: {
324
- $null: true
683
+ strapi2.telemetry.send("didCreateContentRelease");
684
+ return release2;
685
+ },
686
+ async findOne(id, query = {}) {
687
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
688
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
689
+ ...dbQuery,
690
+ where: { id }
691
+ });
692
+ return release2;
693
+ },
694
+ findPage(query) {
695
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
696
+ return strapi2.db.query(RELEASE_MODEL_UID).findPage({
697
+ ...dbQuery,
698
+ populate: {
699
+ actions: {
700
+ count: true
701
+ }
325
702
  }
326
- },
327
- populate: {
328
- ...populateAttachedAction
703
+ });
704
+ },
705
+ findMany(query) {
706
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
707
+ return strapi2.db.query(RELEASE_MODEL_UID).findMany({
708
+ ...dbQuery
709
+ });
710
+ },
711
+ async update(id, releaseData, { user }) {
712
+ const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(
713
+ releaseData
714
+ );
715
+ const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
716
+ "release-validation",
717
+ { strapi: strapi2 }
718
+ );
719
+ await Promise.all([
720
+ validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
721
+ validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
722
+ ]);
723
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id } });
724
+ if (!release2) {
725
+ throw new utils.errors.NotFoundError(`No release found for id ${id}`);
329
726
  }
330
- });
331
- return releases.map((release2) => {
332
- if (release2.actions?.length) {
333
- const [actionForEntry] = release2.actions;
334
- delete release2.actions;
335
- return {
336
- ...release2,
337
- action: actionForEntry
338
- };
727
+ if (release2.releasedAt) {
728
+ throw new utils.errors.ValidationError("Release already published");
339
729
  }
340
- return release2;
341
- });
342
- },
343
- async update(id, releaseData, { user }) {
344
- const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(releaseData);
345
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
346
- if (!release2) {
347
- throw new utils.errors.NotFoundError(`No release found for id ${id}`);
348
- }
349
- if (release2.releasedAt) {
350
- throw new utils.errors.ValidationError("Release already published");
351
- }
352
- const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
353
- /*
354
- * The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
355
- * is not compatible with the type we are passing here: UpdateRelease.Request['body']
356
- */
357
- // @ts-expect-error see above
358
- data: releaseWithCreatorFields
359
- });
360
- return updatedRelease;
361
- },
362
- async createAction(releaseId, action) {
363
- const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
364
- strapi: strapi2
365
- });
366
- await Promise.all([
367
- validateEntryContentType(action.entry.contentType),
368
- validateUniqueEntry(releaseId, action)
369
- ]);
370
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
371
- if (!release2) {
372
- throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
373
- }
374
- if (release2.releasedAt) {
375
- throw new utils.errors.ValidationError("Release already published");
376
- }
377
- const { entry, type } = action;
378
- return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
379
- data: {
380
- type,
381
- contentType: entry.contentType,
382
- locale: entry.locale,
383
- entry: {
384
- id: entry.id,
385
- __type: entry.contentType,
386
- __pivot: { field: "entry" }
730
+ const updatedRelease = await strapi2.db.query(RELEASE_MODEL_UID).update({
731
+ where: { id },
732
+ data: releaseWithCreatorFields
733
+ });
734
+ const schedulingService = getService("scheduling", { strapi: strapi2 });
735
+ if (releaseData.scheduledAt) {
736
+ await schedulingService.set(id, releaseData.scheduledAt);
737
+ } else if (release2.scheduledAt) {
738
+ schedulingService.cancel(id);
739
+ }
740
+ this.updateReleaseStatus(id);
741
+ strapi2.telemetry.send("didUpdateContentRelease");
742
+ return updatedRelease;
743
+ },
744
+ async getAllComponents() {
745
+ const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
746
+ const components = await contentManagerComponentsService.findAllComponents();
747
+ const componentsMap = components.reduce(
748
+ (acc, component) => {
749
+ acc[component.uid] = component;
750
+ return acc;
387
751
  },
388
- release: releaseId
389
- },
390
- populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
391
- });
392
- },
393
- async findActions(releaseId, query) {
394
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
395
- fields: ["id"]
396
- });
397
- if (!release2) {
398
- throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
399
- }
400
- return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
401
- ...query,
402
- populate: {
403
- entry: true
404
- },
405
- filters: {
406
- release: releaseId
752
+ {}
753
+ );
754
+ return componentsMap;
755
+ },
756
+ async delete(releaseId) {
757
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
758
+ where: { id: releaseId },
759
+ populate: {
760
+ actions: {
761
+ select: ["id"]
762
+ }
763
+ }
764
+ });
765
+ if (!release2) {
766
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
407
767
  }
408
- });
409
- },
410
- async countActions(query) {
411
- return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
412
- },
413
- async groupActions(actions, groupBy) {
414
- const contentTypeUids = actions.reduce((acc, action) => {
415
- if (!acc.includes(action.contentType)) {
416
- acc.push(action.contentType);
768
+ if (release2.releasedAt) {
769
+ throw new utils.errors.ValidationError("Release already published");
417
770
  }
418
- return acc;
419
- }, []);
420
- const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
421
- contentTypeUids
422
- );
423
- const allLocalesDictionary = await this.getLocalesDataForActions();
424
- const formattedData = actions.map((action) => {
425
- const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
426
- return {
427
- ...action,
428
- entry: {
429
- id: action.entry.id,
430
- contentType: {
431
- displayName,
432
- mainFieldValue: action.entry[mainField]
771
+ await strapi2.db.transaction(async () => {
772
+ await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
773
+ where: {
774
+ id: {
775
+ $in: release2.actions.map((action) => action.id)
776
+ }
777
+ }
778
+ });
779
+ await strapi2.db.query(RELEASE_MODEL_UID).delete({
780
+ where: {
781
+ id: releaseId
782
+ }
783
+ });
784
+ });
785
+ if (release2.scheduledAt) {
786
+ const schedulingService = getService("scheduling", { strapi: strapi2 });
787
+ await schedulingService.cancel(release2.id);
788
+ }
789
+ strapi2.telemetry.send("didDeleteContentRelease");
790
+ return release2;
791
+ },
792
+ async publish(releaseId) {
793
+ const {
794
+ release: release2,
795
+ error
796
+ } = await strapi2.db.transaction(async ({ trx }) => {
797
+ const lockedRelease = await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).select(["id", "name", "releasedAt", "status"]).first().transacting(trx).forUpdate().execute();
798
+ if (!lockedRelease) {
799
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
800
+ }
801
+ if (lockedRelease.releasedAt) {
802
+ throw new utils.errors.ValidationError("Release already published");
803
+ }
804
+ if (lockedRelease.status === "failed") {
805
+ throw new utils.errors.ValidationError("Release failed to publish");
806
+ }
807
+ try {
808
+ strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
809
+ const formattedActions = await getFormattedActions(releaseId);
810
+ await strapi2.db.transaction(
811
+ async () => Promise.all(
812
+ Object.keys(formattedActions).map(async (contentTypeUid) => {
813
+ const contentType = contentTypeUid;
814
+ const { publish, unpublish } = formattedActions[contentType];
815
+ return Promise.all([
816
+ ...publish.map((params) => strapi2.documents(contentType).publish(params)),
817
+ ...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
818
+ ]);
819
+ })
820
+ )
821
+ );
822
+ const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
823
+ where: {
824
+ id: releaseId
825
+ },
826
+ data: {
827
+ status: "done",
828
+ releasedAt: /* @__PURE__ */ new Date()
829
+ }
830
+ });
831
+ dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
832
+ isPublished: true,
833
+ release: release22
834
+ });
835
+ strapi2.telemetry.send("didPublishContentRelease");
836
+ return { release: release22, error: null };
837
+ } catch (error2) {
838
+ dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
839
+ isPublished: false,
840
+ error: error2
841
+ });
842
+ await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
843
+ status: "failed"
844
+ }).transacting(trx).execute();
845
+ return {
846
+ release: null,
847
+ error: error2
848
+ };
849
+ }
850
+ });
851
+ if (error instanceof Error) {
852
+ throw error;
853
+ }
854
+ return release2;
855
+ },
856
+ async updateReleaseStatus(releaseId) {
857
+ const releaseActionService = getService("release-action", { strapi: strapi2 });
858
+ const [totalActions, invalidActions] = await Promise.all([
859
+ releaseActionService.countActions({
860
+ filters: {
861
+ release: releaseId
862
+ }
863
+ }),
864
+ releaseActionService.countActions({
865
+ filters: {
866
+ release: releaseId,
867
+ isEntryValid: false
868
+ }
869
+ })
870
+ ]);
871
+ if (totalActions > 0) {
872
+ if (invalidActions > 0) {
873
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
874
+ where: {
875
+ id: releaseId
876
+ },
877
+ data: {
878
+ status: "blocked"
879
+ }
880
+ });
881
+ }
882
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
883
+ where: {
884
+ id: releaseId
433
885
  },
434
- locale: action.locale ? allLocalesDictionary[action.locale] : null,
435
- status: action.entry.publishedAt ? "published" : "draft"
886
+ data: {
887
+ status: "ready"
888
+ }
889
+ });
890
+ }
891
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
892
+ where: {
893
+ id: releaseId
894
+ },
895
+ data: {
896
+ status: "empty"
436
897
  }
437
- };
438
- });
439
- const groupName = getGroupName(groupBy);
440
- return ___default.default.groupBy(groupName)(formattedData);
441
- },
442
- async getLocalesDataForActions() {
898
+ });
899
+ }
900
+ };
901
+ };
902
+ const getGroupName = (queryValue) => {
903
+ switch (queryValue) {
904
+ case "contentType":
905
+ return "contentType.displayName";
906
+ case "type":
907
+ return "type";
908
+ case "locale":
909
+ return ___default.default.getOr("No locale", "locale.name");
910
+ default:
911
+ return "contentType.displayName";
912
+ }
913
+ };
914
+ const createReleaseActionService = ({ strapi: strapi2 }) => {
915
+ const getLocalesDataForActions = async () => {
443
916
  if (!strapi2.plugin("i18n")) {
444
917
  return {};
445
918
  }
@@ -448,8 +921,8 @@ const createReleaseService = ({ strapi: strapi2 }) => ({
448
921
  acc[locale.code] = { name: locale.name, code: locale.code };
449
922
  return acc;
450
923
  }, {});
451
- },
452
- async getContentTypesDataForActions(contentTypesUids) {
924
+ };
925
+ const getContentTypesDataForActions = async (contentTypesUids) => {
453
926
  const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
454
927
  const contentTypesData = {};
455
928
  for (const contentTypeUid of contentTypesUids) {
@@ -462,167 +935,249 @@ const createReleaseService = ({ strapi: strapi2 }) => ({
462
935
  };
463
936
  }
464
937
  return contentTypesData;
465
- },
466
- async delete(releaseId) {
467
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
468
- populate: {
469
- actions: {
470
- fields: ["id"]
938
+ };
939
+ return {
940
+ async create(releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
941
+ const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
942
+ strapi: strapi2
943
+ });
944
+ await Promise.all([
945
+ validateEntryData(action.contentType, action.entryDocumentId),
946
+ validateUniqueEntry(releaseId, action)
947
+ ]);
948
+ const model = strapi2.contentType(action.contentType);
949
+ if (model.kind === "singleType") {
950
+ const document = await strapi2.db.query(model.uid).findOne({ select: ["documentId"] });
951
+ if (!document) {
952
+ throw new utils.errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
471
953
  }
954
+ action.entryDocumentId = document.documentId;
472
955
  }
473
- });
474
- if (!release2) {
475
- throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
476
- }
477
- if (release2.releasedAt) {
478
- throw new utils.errors.ValidationError("Release already published");
479
- }
480
- await strapi2.db.transaction(async () => {
481
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
956
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
957
+ if (!release2) {
958
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
959
+ }
960
+ if (release2.releasedAt) {
961
+ throw new utils.errors.ValidationError("Release already published");
962
+ }
963
+ const actionStatus = action.type === "publish" ? await getDraftEntryValidStatus(
964
+ {
965
+ contentType: action.contentType,
966
+ documentId: action.entryDocumentId,
967
+ locale: action.locale
968
+ },
969
+ {
970
+ strapi: strapi2
971
+ }
972
+ ) : true;
973
+ const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
974
+ data: {
975
+ ...action,
976
+ release: release2.id,
977
+ isEntryValid: actionStatus
978
+ },
979
+ populate: { release: { select: ["id"] } }
980
+ });
981
+ if (!disableUpdateReleaseStatus) {
982
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
983
+ }
984
+ return releaseAction2;
985
+ },
986
+ async findPage(releaseId, query) {
987
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
988
+ where: { id: releaseId },
989
+ select: ["id"]
990
+ });
991
+ if (!release2) {
992
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
993
+ }
994
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
995
+ const { results: actions, pagination } = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
996
+ ...dbQuery,
482
997
  where: {
483
- id: {
484
- $in: release2.actions.map((action) => action.id)
485
- }
998
+ release: releaseId
486
999
  }
487
1000
  });
488
- await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
489
- });
490
- return release2;
491
- },
492
- async publish(releaseId) {
493
- const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
494
- RELEASE_MODEL_UID,
495
- releaseId,
496
- {
497
- populate: {
498
- actions: {
499
- populate: {
500
- entry: true
501
- }
502
- }
1001
+ const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
1002
+ const actionsWithEntry = await utils.async.map(actions, async (action) => {
1003
+ const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
1004
+ const entry = await getEntry(
1005
+ {
1006
+ contentType: action.contentType,
1007
+ documentId: action.entryDocumentId,
1008
+ locale: action.locale,
1009
+ populate,
1010
+ status: action.type === "publish" ? "draft" : "published"
1011
+ },
1012
+ { strapi: strapi2 }
1013
+ );
1014
+ return {
1015
+ ...action,
1016
+ entry,
1017
+ status: entry ? await getEntryStatus(action.contentType, entry) : null
1018
+ };
1019
+ });
1020
+ return {
1021
+ results: actionsWithEntry,
1022
+ pagination
1023
+ };
1024
+ },
1025
+ async groupActions(actions, groupBy) {
1026
+ const contentTypeUids = actions.reduce((acc, action) => {
1027
+ if (!acc.includes(action.contentType)) {
1028
+ acc.push(action.contentType);
503
1029
  }
504
- }
505
- );
506
- if (!releaseWithPopulatedActionEntries) {
507
- throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
508
- }
509
- if (releaseWithPopulatedActionEntries.releasedAt) {
510
- throw new utils.errors.ValidationError("Release already published");
511
- }
512
- if (releaseWithPopulatedActionEntries.actions.length === 0) {
513
- throw new utils.errors.ValidationError("No entries to publish");
514
- }
515
- const actions = {};
516
- for (const action of releaseWithPopulatedActionEntries.actions) {
517
- const contentTypeUid = action.contentType;
518
- if (!actions[contentTypeUid]) {
519
- actions[contentTypeUid] = {
520
- publish: [],
521
- unpublish: []
1030
+ return acc;
1031
+ }, []);
1032
+ const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
1033
+ const allLocalesDictionary = await getLocalesDataForActions();
1034
+ const formattedData = actions.map((action) => {
1035
+ const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
1036
+ return {
1037
+ ...action,
1038
+ locale: action.locale ? allLocalesDictionary[action.locale] : null,
1039
+ contentType: {
1040
+ displayName,
1041
+ mainFieldValue: action.entry[mainField],
1042
+ uid: action.contentType
1043
+ }
522
1044
  };
523
- }
524
- if (action.type === "publish") {
525
- actions[contentTypeUid].publish.push(action.entry);
526
- } else {
527
- actions[contentTypeUid].unpublish.push(action.entry);
528
- }
529
- }
530
- const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
531
- await strapi2.db.transaction(async () => {
532
- for (const contentTypeUid of Object.keys(actions)) {
533
- const { publish, unpublish } = actions[contentTypeUid];
534
- if (publish.length > 0) {
535
- await entityManagerService.publishMany(publish, contentTypeUid);
1045
+ });
1046
+ const groupName = getGroupName(groupBy);
1047
+ return ___default.default.groupBy(groupName)(formattedData);
1048
+ },
1049
+ getContentTypeModelsFromActions(actions) {
1050
+ const contentTypeUids = actions.reduce((acc, action) => {
1051
+ if (!acc.includes(action.contentType)) {
1052
+ acc.push(action.contentType);
536
1053
  }
537
- if (unpublish.length > 0) {
538
- await entityManagerService.unpublishMany(unpublish, contentTypeUid);
1054
+ return acc;
1055
+ }, []);
1056
+ const contentTypeModelsMap = contentTypeUids.reduce(
1057
+ (acc, contentTypeUid) => {
1058
+ acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
1059
+ return acc;
1060
+ },
1061
+ {}
1062
+ );
1063
+ return contentTypeModelsMap;
1064
+ },
1065
+ async countActions(query) {
1066
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
1067
+ return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
1068
+ },
1069
+ async update(actionId, releaseId, update) {
1070
+ const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
1071
+ where: {
1072
+ id: actionId,
1073
+ release: {
1074
+ id: releaseId,
1075
+ releasedAt: {
1076
+ $null: true
1077
+ }
1078
+ }
539
1079
  }
1080
+ });
1081
+ if (!action) {
1082
+ throw new utils.errors.NotFoundError(
1083
+ `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1084
+ );
540
1085
  }
541
- });
542
- const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
543
- data: {
544
- /*
545
- * The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
546
- */
547
- // @ts-expect-error see above
548
- releasedAt: /* @__PURE__ */ new Date()
549
- }
550
- });
551
- return release2;
552
- },
553
- async updateAction(actionId, releaseId, update) {
554
- const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
555
- where: {
556
- id: actionId,
557
- release: {
558
- id: releaseId,
559
- releasedAt: {
560
- $null: true
1086
+ const actionStatus = update.type === "publish" ? await getDraftEntryValidStatus(
1087
+ {
1088
+ contentType: action.contentType,
1089
+ documentId: action.entryDocumentId,
1090
+ locale: action.locale
1091
+ },
1092
+ {
1093
+ strapi: strapi2
1094
+ }
1095
+ ) : true;
1096
+ const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
1097
+ where: {
1098
+ id: actionId,
1099
+ release: {
1100
+ id: releaseId,
1101
+ releasedAt: {
1102
+ $null: true
1103
+ }
561
1104
  }
1105
+ },
1106
+ data: {
1107
+ ...update,
1108
+ isEntryValid: actionStatus
562
1109
  }
563
- },
564
- data: update
565
- });
566
- if (!updatedAction) {
567
- throw new utils.errors.NotFoundError(
568
- `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
569
- );
570
- }
571
- return updatedAction;
572
- },
573
- async deleteAction(actionId, releaseId) {
574
- const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
575
- where: {
576
- id: actionId,
577
- release: {
578
- id: releaseId,
579
- releasedAt: {
580
- $null: true
1110
+ });
1111
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1112
+ return updatedAction;
1113
+ },
1114
+ async delete(actionId, releaseId) {
1115
+ const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
1116
+ where: {
1117
+ id: actionId,
1118
+ release: {
1119
+ id: releaseId,
1120
+ releasedAt: {
1121
+ $null: true
1122
+ }
581
1123
  }
582
1124
  }
1125
+ });
1126
+ if (!deletedAction) {
1127
+ throw new utils.errors.NotFoundError(
1128
+ `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1129
+ );
583
1130
  }
584
- });
585
- if (!deletedAction) {
586
- throw new utils.errors.NotFoundError(
587
- `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
588
- );
1131
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1132
+ return deletedAction;
589
1133
  }
590
- return deletedAction;
1134
+ };
1135
+ };
1136
+ class AlreadyOnReleaseError extends utils.errors.ApplicationError {
1137
+ constructor(message) {
1138
+ super(message);
1139
+ this.name = "AlreadyOnReleaseError";
591
1140
  }
592
- });
1141
+ }
593
1142
  const createReleaseValidationService = ({ strapi: strapi2 }) => ({
594
1143
  async validateUniqueEntry(releaseId, releaseActionArgs) {
595
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
596
- populate: { actions: { populate: { entry: { fields: ["id"] } } } }
1144
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
1145
+ where: {
1146
+ id: releaseId
1147
+ },
1148
+ populate: {
1149
+ actions: true
1150
+ }
597
1151
  });
598
1152
  if (!release2) {
599
1153
  throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
600
1154
  }
601
1155
  const isEntryInRelease = release2.actions.some(
602
- (action) => Number(action.entry.id) === Number(releaseActionArgs.entry.id) && action.contentType === releaseActionArgs.entry.contentType
1156
+ (action) => action.entryDocumentId === releaseActionArgs.entryDocumentId && action.contentType === releaseActionArgs.contentType && (releaseActionArgs.locale ? action.locale === releaseActionArgs.locale : true)
603
1157
  );
604
1158
  if (isEntryInRelease) {
605
- throw new utils.errors.ValidationError(
606
- `Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
1159
+ throw new AlreadyOnReleaseError(
1160
+ `Entry with documentId ${releaseActionArgs.entryDocumentId}${releaseActionArgs.locale ? `( ${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
607
1161
  );
608
1162
  }
609
1163
  },
610
- validateEntryContentType(contentTypeUid) {
1164
+ validateEntryData(contentTypeUid, entryDocumentId) {
611
1165
  const contentType = strapi2.contentType(contentTypeUid);
612
1166
  if (!contentType) {
613
1167
  throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
614
1168
  }
615
- if (!contentType.options?.draftAndPublish) {
1169
+ if (!utils.contentTypes.hasDraftAndPublish(contentType)) {
616
1170
  throw new utils.errors.ValidationError(
617
1171
  `Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
618
1172
  );
619
1173
  }
1174
+ if (contentType.kind === "collectionType" && !entryDocumentId) {
1175
+ throw new utils.errors.ValidationError("Document id is required for collection type");
1176
+ }
620
1177
  },
621
1178
  async validatePendingReleasesLimit() {
622
- const maximumPendingReleases = (
623
- // @ts-expect-error - options is not typed into features
624
- EE__default.default.features.get("cms-content-releases")?.options?.maximumReleases || 3
625
- );
1179
+ const featureCfg = strapi2.ee.features.get("cms-content-releases");
1180
+ const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
626
1181
  const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
627
1182
  filters: {
628
1183
  releasedAt: {
@@ -633,23 +1188,98 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
633
1188
  if (pendingReleasesCount >= maximumPendingReleases) {
634
1189
  throw new utils.errors.ValidationError("You have reached the maximum number of pending releases");
635
1190
  }
1191
+ },
1192
+ async validateUniqueNameForPendingRelease(name, id) {
1193
+ const pendingReleases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
1194
+ where: {
1195
+ releasedAt: {
1196
+ $null: true
1197
+ },
1198
+ name,
1199
+ ...id && { id: { $ne: id } }
1200
+ }
1201
+ });
1202
+ const isNameUnique = pendingReleases.length === 0;
1203
+ if (!isNameUnique) {
1204
+ throw new utils.errors.ValidationError(`Release with name ${name} already exists`);
1205
+ }
1206
+ },
1207
+ async validateScheduledAtIsLaterThanNow(scheduledAt) {
1208
+ if (scheduledAt && new Date(scheduledAt) <= /* @__PURE__ */ new Date()) {
1209
+ throw new utils.errors.ValidationError("Scheduled at must be later than now");
1210
+ }
636
1211
  }
637
1212
  });
638
- const createEventManagerService = () => {
639
- const state = {
640
- destroyListenerCallbacks: []
641
- };
1213
+ const createSchedulingService = ({ strapi: strapi2 }) => {
1214
+ const scheduledJobs = /* @__PURE__ */ new Map();
642
1215
  return {
643
- addDestroyListenerCallback(destroyListenerCallback) {
644
- state.destroyListenerCallbacks.push(destroyListenerCallback);
1216
+ async set(releaseId, scheduleDate) {
1217
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId, releasedAt: null } });
1218
+ if (!release2) {
1219
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
1220
+ }
1221
+ const job = nodeSchedule.scheduleJob(scheduleDate, async () => {
1222
+ try {
1223
+ await getService("release", { strapi: strapi2 }).publish(releaseId);
1224
+ } catch (error) {
1225
+ }
1226
+ this.cancel(releaseId);
1227
+ });
1228
+ if (scheduledJobs.has(releaseId)) {
1229
+ this.cancel(releaseId);
1230
+ }
1231
+ scheduledJobs.set(releaseId, job);
1232
+ return scheduledJobs;
645
1233
  },
646
- destroyAllListeners() {
647
- if (!state.destroyListenerCallbacks.length) {
648
- return;
1234
+ cancel(releaseId) {
1235
+ if (scheduledJobs.has(releaseId)) {
1236
+ scheduledJobs.get(releaseId).cancel();
1237
+ scheduledJobs.delete(releaseId);
649
1238
  }
650
- state.destroyListenerCallbacks.forEach((destroyListenerCallback) => {
651
- destroyListenerCallback();
1239
+ return scheduledJobs;
1240
+ },
1241
+ getAll() {
1242
+ return scheduledJobs;
1243
+ },
1244
+ /**
1245
+ * On bootstrap, we can use this function to make sure to sync the scheduled jobs from the database that are not yet released
1246
+ * This is useful in case the server was restarted and the scheduled jobs were lost
1247
+ * This also could be used to sync different Strapi instances in case of a cluster
1248
+ */
1249
+ async syncFromDatabase() {
1250
+ const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
1251
+ where: {
1252
+ scheduledAt: {
1253
+ $gte: /* @__PURE__ */ new Date()
1254
+ },
1255
+ releasedAt: null
1256
+ }
652
1257
  });
1258
+ for (const release2 of releases) {
1259
+ this.set(release2.id, release2.scheduledAt);
1260
+ }
1261
+ return scheduledJobs;
1262
+ }
1263
+ };
1264
+ };
1265
+ const DEFAULT_SETTINGS = {
1266
+ defaultTimezone: null
1267
+ };
1268
+ const createSettingsService = ({ strapi: strapi2 }) => {
1269
+ const getStore = async () => strapi2.store({ type: "core", name: "content-releases" });
1270
+ return {
1271
+ async update({ settings: settings2 }) {
1272
+ const store = await getStore();
1273
+ store.set({ key: "settings", value: settings2 });
1274
+ return settings2;
1275
+ },
1276
+ async find() {
1277
+ const store = await getStore();
1278
+ const settings2 = await store.get({ key: "settings" });
1279
+ return {
1280
+ ...DEFAULT_SETTINGS,
1281
+ ...settings2 || {}
1282
+ };
653
1283
  }
654
1284
  };
655
1285
  };
@@ -657,64 +1287,148 @@ const services = {
657
1287
  release: createReleaseService,
658
1288
  "release-action": createReleaseActionService,
659
1289
  "release-validation": createReleaseValidationService,
660
- "event-manager": createEventManagerService
1290
+ scheduling: createSchedulingService,
1291
+ settings: createSettingsService
661
1292
  };
662
- const RELEASE_SCHEMA = yup__namespace.object().shape({
663
- name: yup__namespace.string().trim().required()
1293
+ const RELEASE_SCHEMA = utils.yup.object().shape({
1294
+ name: utils.yup.string().trim().required(),
1295
+ scheduledAt: utils.yup.string().nullable(),
1296
+ timezone: utils.yup.string().when("scheduledAt", {
1297
+ is: (value) => value !== null && value !== void 0,
1298
+ then: utils.yup.string().required(),
1299
+ otherwise: utils.yup.string().nullable()
1300
+ })
1301
+ }).required().noUnknown();
1302
+ const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = utils.yup.object().shape({
1303
+ contentType: utils.yup.string().required(),
1304
+ entryDocumentId: utils.yup.string().nullable(),
1305
+ hasEntryAttached: utils.yup.string().nullable(),
1306
+ locale: utils.yup.string().nullable()
664
1307
  }).required().noUnknown();
665
1308
  const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
1309
+ const validatefindByDocumentAttachedParams = utils.validateYupSchema(
1310
+ FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA
1311
+ );
666
1312
  const releaseController = {
667
- async findMany(ctx) {
668
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1313
+ /**
1314
+ * Find releases based on documents attached or not to the release.
1315
+ * If `hasEntryAttached` is true, it will return all releases that have the entry attached.
1316
+ * If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
1317
+ */
1318
+ async findByDocumentAttached(ctx) {
1319
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
669
1320
  ability: ctx.state.userAbility,
670
1321
  model: RELEASE_MODEL_UID
671
1322
  });
672
1323
  await permissionsManager.validateQuery(ctx.query);
673
1324
  const releaseService = getService("release", { strapi });
674
- const isFindManyForContentTypeEntry = Boolean(ctx.query?.contentTypeUid && ctx.query?.entryId);
675
- if (isFindManyForContentTypeEntry) {
676
- const query = await permissionsManager.sanitizeQuery(ctx.query);
677
- const contentTypeUid = query.contentTypeUid;
678
- const entryId = query.entryId;
679
- const hasEntryAttached = typeof query.hasEntryAttached === "string" ? JSON.parse(query.hasEntryAttached) : false;
680
- const data = await releaseService.findManyForContentTypeEntry(contentTypeUid, entryId, {
681
- hasEntryAttached
1325
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
1326
+ await validatefindByDocumentAttachedParams(query);
1327
+ const model = strapi.getModel(query.contentType);
1328
+ if (model.kind && model.kind === "singleType") {
1329
+ const document = await strapi.db.query(model.uid).findOne({ select: ["documentId"] });
1330
+ if (!document) {
1331
+ throw new utils.errors.NotFoundError(`No entry found for contentType ${query.contentType}`);
1332
+ }
1333
+ query.entryDocumentId = document.documentId;
1334
+ }
1335
+ const { contentType, hasEntryAttached, entryDocumentId, locale } = query;
1336
+ const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
1337
+ if (isEntryAttached) {
1338
+ const releases = await releaseService.findMany({
1339
+ where: {
1340
+ releasedAt: null,
1341
+ actions: {
1342
+ contentType,
1343
+ entryDocumentId: entryDocumentId ?? null,
1344
+ locale: locale ?? null
1345
+ }
1346
+ },
1347
+ populate: {
1348
+ actions: {
1349
+ fields: ["type"],
1350
+ filters: {
1351
+ contentType,
1352
+ entryDocumentId: entryDocumentId ?? null,
1353
+ locale: locale ?? null
1354
+ }
1355
+ }
1356
+ }
682
1357
  });
683
- ctx.body = { data };
1358
+ ctx.body = { data: releases };
684
1359
  } else {
685
- const query = await permissionsManager.sanitizeQuery(ctx.query);
686
- const { results, pagination } = await releaseService.findPage(query);
687
- const data = results.map((release2) => {
688
- const { actions, ...releaseData } = release2;
689
- return {
690
- ...releaseData,
1360
+ const relatedReleases = await releaseService.findMany({
1361
+ where: {
1362
+ releasedAt: null,
691
1363
  actions: {
692
- meta: {
693
- count: actions.count
694
- }
1364
+ contentType,
1365
+ entryDocumentId: entryDocumentId ?? null,
1366
+ locale: locale ?? null
695
1367
  }
696
- };
1368
+ }
697
1369
  });
698
- ctx.body = { data, meta: { pagination } };
1370
+ const releases = await releaseService.findMany({
1371
+ where: {
1372
+ $or: [
1373
+ {
1374
+ id: {
1375
+ $notIn: relatedReleases.map((release2) => release2.id)
1376
+ }
1377
+ },
1378
+ {
1379
+ actions: null
1380
+ }
1381
+ ],
1382
+ releasedAt: null
1383
+ }
1384
+ });
1385
+ ctx.body = { data: releases };
699
1386
  }
700
1387
  },
701
- async findOne(ctx) {
702
- const id = ctx.params.id;
703
- const releaseService = getService("release", { strapi });
704
- const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
705
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1388
+ async findPage(ctx) {
1389
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
706
1390
  ability: ctx.state.userAbility,
707
1391
  model: RELEASE_MODEL_UID
708
1392
  });
709
- const sanitizedRelease = await permissionsManager.sanitizeOutput(release2);
710
- const count = await releaseService.countActions({
711
- filters: {
712
- release: id
1393
+ await permissionsManager.validateQuery(ctx.query);
1394
+ const releaseService = getService("release", { strapi });
1395
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
1396
+ const { results, pagination } = await releaseService.findPage(query);
1397
+ const data = results.map((release2) => {
1398
+ const { actions, ...releaseData } = release2;
1399
+ return {
1400
+ ...releaseData,
1401
+ actions: {
1402
+ meta: {
1403
+ count: actions.count
1404
+ }
1405
+ }
1406
+ };
1407
+ });
1408
+ const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
1409
+ where: {
1410
+ releasedAt: null
713
1411
  }
714
1412
  });
1413
+ ctx.body = { data, meta: { pagination, pendingReleasesCount } };
1414
+ },
1415
+ async findOne(ctx) {
1416
+ const id = ctx.params.id;
1417
+ const releaseService = getService("release", { strapi });
1418
+ const releaseActionService = getService("release-action", { strapi });
1419
+ const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
715
1420
  if (!release2) {
716
1421
  throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
717
1422
  }
1423
+ const count = await releaseActionService.countActions({
1424
+ filters: {
1425
+ release: id
1426
+ }
1427
+ });
1428
+ const sanitizedRelease = {
1429
+ ...release2,
1430
+ createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
1431
+ };
718
1432
  const data = {
719
1433
  ...sanitizedRelease,
720
1434
  actions: {
@@ -725,19 +1439,63 @@ const releaseController = {
725
1439
  };
726
1440
  ctx.body = { data };
727
1441
  },
1442
+ async mapEntriesToReleases(ctx) {
1443
+ const { contentTypeUid, documentIds, locale } = ctx.query;
1444
+ if (!contentTypeUid || !documentIds) {
1445
+ throw new utils.errors.ValidationError("Missing required query parameters");
1446
+ }
1447
+ const releaseService = getService("release", { strapi });
1448
+ const releasesWithActions = await releaseService.findMany({
1449
+ where: {
1450
+ releasedAt: null,
1451
+ actions: {
1452
+ contentType: contentTypeUid,
1453
+ entryDocumentId: {
1454
+ $in: documentIds
1455
+ },
1456
+ locale
1457
+ }
1458
+ },
1459
+ populate: {
1460
+ actions: true
1461
+ }
1462
+ });
1463
+ const mappedEntriesInReleases = releasesWithActions.reduce(
1464
+ (acc, release2) => {
1465
+ release2.actions.forEach((action) => {
1466
+ if (action.contentType !== contentTypeUid) {
1467
+ return;
1468
+ }
1469
+ if (locale && action.locale !== locale) {
1470
+ return;
1471
+ }
1472
+ if (!acc[action.entryDocumentId]) {
1473
+ acc[action.entryDocumentId] = [{ id: release2.id, name: release2.name }];
1474
+ } else {
1475
+ acc[action.entryDocumentId].push({ id: release2.id, name: release2.name });
1476
+ }
1477
+ });
1478
+ return acc;
1479
+ },
1480
+ {}
1481
+ );
1482
+ ctx.body = {
1483
+ data: mappedEntriesInReleases
1484
+ };
1485
+ },
728
1486
  async create(ctx) {
729
1487
  const user = ctx.state.user;
730
1488
  const releaseArgs = ctx.request.body;
731
1489
  await validateRelease(releaseArgs);
732
1490
  const releaseService = getService("release", { strapi });
733
1491
  const release2 = await releaseService.create(releaseArgs, { user });
734
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1492
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
735
1493
  ability: ctx.state.userAbility,
736
1494
  model: RELEASE_MODEL_UID
737
1495
  });
738
- ctx.body = {
1496
+ ctx.created({
739
1497
  data: await permissionsManager.sanitizeOutput(release2)
740
- };
1498
+ });
741
1499
  },
742
1500
  async update(ctx) {
743
1501
  const user = ctx.state.user;
@@ -746,7 +1504,7 @@ const releaseController = {
746
1504
  await validateRelease(releaseArgs);
747
1505
  const releaseService = getService("release", { strapi });
748
1506
  const release2 = await releaseService.update(id, releaseArgs, { user });
749
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1507
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
750
1508
  ability: ctx.state.userAbility,
751
1509
  model: RELEASE_MODEL_UID
752
1510
  });
@@ -763,55 +1521,142 @@ const releaseController = {
763
1521
  };
764
1522
  },
765
1523
  async publish(ctx) {
766
- const user = ctx.state.user;
767
1524
  const id = ctx.params.id;
768
1525
  const releaseService = getService("release", { strapi });
769
- const release2 = await releaseService.publish(id, { user });
1526
+ const releaseActionService = getService("release-action", { strapi });
1527
+ const release2 = await releaseService.publish(id);
1528
+ const [countPublishActions, countUnpublishActions] = await Promise.all([
1529
+ releaseActionService.countActions({
1530
+ filters: {
1531
+ release: id,
1532
+ type: "publish"
1533
+ }
1534
+ }),
1535
+ releaseActionService.countActions({
1536
+ filters: {
1537
+ release: id,
1538
+ type: "unpublish"
1539
+ }
1540
+ })
1541
+ ]);
770
1542
  ctx.body = {
771
- data: release2
1543
+ data: release2,
1544
+ meta: {
1545
+ totalEntries: countPublishActions + countUnpublishActions,
1546
+ totalPublishedEntries: countPublishActions,
1547
+ totalUnpublishedEntries: countUnpublishActions
1548
+ }
772
1549
  };
773
1550
  }
774
1551
  };
775
1552
  const RELEASE_ACTION_SCHEMA = utils.yup.object().shape({
776
- entry: utils.yup.object().shape({
777
- id: utils.yup.strapiID().required(),
778
- contentType: utils.yup.string().required()
779
- }).required(),
1553
+ contentType: utils.yup.string().required(),
1554
+ entryDocumentId: utils.yup.strapiID(),
1555
+ locale: utils.yup.string(),
780
1556
  type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
781
1557
  });
782
1558
  const RELEASE_ACTION_UPDATE_SCHEMA = utils.yup.object().shape({
783
1559
  type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
784
1560
  });
1561
+ const FIND_MANY_ACTIONS_PARAMS = utils.yup.object().shape({
1562
+ groupBy: utils.yup.string().oneOf(["action", "contentType", "locale"])
1563
+ });
785
1564
  const validateReleaseAction = utils.validateYupSchema(RELEASE_ACTION_SCHEMA);
786
1565
  const validateReleaseActionUpdateSchema = utils.validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
1566
+ const validateFindManyActionsParams = utils.validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
787
1567
  const releaseActionController = {
788
1568
  async create(ctx) {
789
1569
  const releaseId = ctx.params.releaseId;
790
1570
  const releaseActionArgs = ctx.request.body;
791
1571
  await validateReleaseAction(releaseActionArgs);
792
- const releaseService = getService("release", { strapi });
793
- const releaseAction2 = await releaseService.createAction(releaseId, releaseActionArgs);
794
- ctx.body = {
1572
+ const releaseActionService = getService("release-action", { strapi });
1573
+ const releaseAction2 = await releaseActionService.create(releaseId, releaseActionArgs);
1574
+ ctx.created({
795
1575
  data: releaseAction2
796
- };
1576
+ });
1577
+ },
1578
+ async createMany(ctx) {
1579
+ const releaseId = ctx.params.releaseId;
1580
+ const releaseActionsArgs = ctx.request.body;
1581
+ await Promise.all(
1582
+ releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
1583
+ );
1584
+ const releaseActionService = getService("release-action", { strapi });
1585
+ const releaseService = getService("release", { strapi });
1586
+ const releaseActions = await strapi.db.transaction(async () => {
1587
+ const releaseActions2 = await Promise.all(
1588
+ releaseActionsArgs.map(async (releaseActionArgs) => {
1589
+ try {
1590
+ const action = await releaseActionService.create(releaseId, releaseActionArgs, {
1591
+ disableUpdateReleaseStatus: true
1592
+ });
1593
+ return action;
1594
+ } catch (error) {
1595
+ if (error instanceof AlreadyOnReleaseError) {
1596
+ return null;
1597
+ }
1598
+ throw error;
1599
+ }
1600
+ })
1601
+ );
1602
+ return releaseActions2;
1603
+ });
1604
+ const newReleaseActions = releaseActions.filter((action) => action !== null);
1605
+ if (newReleaseActions.length > 0) {
1606
+ releaseService.updateReleaseStatus(releaseId);
1607
+ }
1608
+ ctx.created({
1609
+ data: newReleaseActions,
1610
+ meta: {
1611
+ entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
1612
+ totalEntries: releaseActions.length
1613
+ }
1614
+ });
797
1615
  },
798
1616
  async findMany(ctx) {
799
1617
  const releaseId = ctx.params.releaseId;
800
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1618
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
801
1619
  ability: ctx.state.userAbility,
802
1620
  model: RELEASE_ACTION_MODEL_UID
803
1621
  });
1622
+ await validateFindManyActionsParams(ctx.query);
1623
+ if (ctx.query.groupBy) {
1624
+ if (!["action", "contentType", "locale"].includes(ctx.query.groupBy)) {
1625
+ ctx.badRequest("Invalid groupBy parameter");
1626
+ }
1627
+ }
1628
+ ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
1629
+ delete ctx.query.groupBy;
804
1630
  const query = await permissionsManager.sanitizeQuery(ctx.query);
805
- const releaseService = getService("release", { strapi });
806
- const { results, pagination } = await releaseService.findActions(releaseId, {
807
- sort: query.groupBy === "action" ? "type" : query.groupBy,
1631
+ const releaseActionService = getService("release-action", { strapi });
1632
+ const { results, pagination } = await releaseActionService.findPage(releaseId, {
808
1633
  ...query
809
1634
  });
810
- const groupedData = await releaseService.groupActions(results, query.groupBy);
1635
+ const contentTypeOutputSanitizers = results.reduce((acc, action) => {
1636
+ if (acc[action.contentType]) {
1637
+ return acc;
1638
+ }
1639
+ const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
1640
+ ability: ctx.state.userAbility,
1641
+ model: action.contentType
1642
+ });
1643
+ acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
1644
+ return acc;
1645
+ }, {});
1646
+ const sanitizedResults = await utils.async.map(results, async (action) => ({
1647
+ ...action,
1648
+ entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
1649
+ }));
1650
+ const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
1651
+ const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
1652
+ const releaseService = getService("release", { strapi });
1653
+ const components = await releaseService.getAllComponents();
811
1654
  ctx.body = {
812
1655
  data: groupedData,
813
1656
  meta: {
814
- pagination
1657
+ pagination,
1658
+ contentTypes: contentTypes2,
1659
+ components
815
1660
  }
816
1661
  };
817
1662
  },
@@ -820,8 +1665,8 @@ const releaseActionController = {
820
1665
  const releaseId = ctx.params.releaseId;
821
1666
  const releaseActionUpdateArgs = ctx.request.body;
822
1667
  await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
823
- const releaseService = getService("release", { strapi });
824
- const updatedAction = await releaseService.updateAction(
1668
+ const releaseActionService = getService("release-action", { strapi });
1669
+ const updatedAction = await releaseActionService.update(
825
1670
  actionId,
826
1671
  releaseId,
827
1672
  releaseActionUpdateArgs
@@ -833,17 +1678,71 @@ const releaseActionController = {
833
1678
  async delete(ctx) {
834
1679
  const actionId = ctx.params.actionId;
835
1680
  const releaseId = ctx.params.releaseId;
836
- const releaseService = getService("release", { strapi });
837
- const deletedReleaseAction = await releaseService.deleteAction(actionId, releaseId);
1681
+ const releaseActionService = getService("release-action", { strapi });
1682
+ const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
838
1683
  ctx.body = {
839
1684
  data: deletedReleaseAction
840
1685
  };
841
1686
  }
842
1687
  };
843
- const controllers = { release: releaseController, "release-action": releaseActionController };
1688
+ const SETTINGS_SCHEMA = yup__namespace.object().shape({
1689
+ defaultTimezone: yup__namespace.string().nullable().default(null)
1690
+ }).required().noUnknown();
1691
+ const validateSettings = utils.validateYupSchema(SETTINGS_SCHEMA);
1692
+ const settingsController = {
1693
+ async find(ctx) {
1694
+ const settingsService = getService("settings", { strapi });
1695
+ const settings2 = await settingsService.find();
1696
+ ctx.body = { data: settings2 };
1697
+ },
1698
+ async update(ctx) {
1699
+ const settingsBody = ctx.request.body;
1700
+ const settings2 = await validateSettings(settingsBody);
1701
+ const settingsService = getService("settings", { strapi });
1702
+ const updatedSettings = await settingsService.update({ settings: settings2 });
1703
+ ctx.body = { data: updatedSettings };
1704
+ }
1705
+ };
1706
+ const controllers = {
1707
+ release: releaseController,
1708
+ "release-action": releaseActionController,
1709
+ settings: settingsController
1710
+ };
844
1711
  const release = {
845
1712
  type: "admin",
846
1713
  routes: [
1714
+ {
1715
+ method: "GET",
1716
+ path: "/mapEntriesToReleases",
1717
+ handler: "release.mapEntriesToReleases",
1718
+ config: {
1719
+ policies: [
1720
+ "admin::isAuthenticatedAdmin",
1721
+ {
1722
+ name: "admin::hasPermissions",
1723
+ config: {
1724
+ actions: ["plugin::content-releases.read"]
1725
+ }
1726
+ }
1727
+ ]
1728
+ }
1729
+ },
1730
+ {
1731
+ method: "GET",
1732
+ path: "/getByDocumentAttached",
1733
+ handler: "release.findByDocumentAttached",
1734
+ config: {
1735
+ policies: [
1736
+ "admin::isAuthenticatedAdmin",
1737
+ {
1738
+ name: "admin::hasPermissions",
1739
+ config: {
1740
+ actions: ["plugin::content-releases.read"]
1741
+ }
1742
+ }
1743
+ ]
1744
+ }
1745
+ },
847
1746
  {
848
1747
  method: "POST",
849
1748
  path: "/",
@@ -863,7 +1762,7 @@ const release = {
863
1762
  {
864
1763
  method: "GET",
865
1764
  path: "/",
866
- handler: "release.findMany",
1765
+ handler: "release.findPage",
867
1766
  config: {
868
1767
  policies: [
869
1768
  "admin::isAuthenticatedAdmin",
@@ -961,6 +1860,22 @@ const releaseAction = {
961
1860
  ]
962
1861
  }
963
1862
  },
1863
+ {
1864
+ method: "POST",
1865
+ path: "/:releaseId/actions/bulk",
1866
+ handler: "release-action.createMany",
1867
+ config: {
1868
+ policies: [
1869
+ "admin::isAuthenticatedAdmin",
1870
+ {
1871
+ name: "admin::hasPermissions",
1872
+ config: {
1873
+ actions: ["plugin::content-releases.create-action"]
1874
+ }
1875
+ }
1876
+ ]
1877
+ }
1878
+ },
964
1879
  {
965
1880
  method: "GET",
966
1881
  path: "/:releaseId/actions",
@@ -1011,28 +1926,64 @@ const releaseAction = {
1011
1926
  }
1012
1927
  ]
1013
1928
  };
1929
+ const settings = {
1930
+ type: "admin",
1931
+ routes: [
1932
+ {
1933
+ method: "GET",
1934
+ path: "/settings",
1935
+ handler: "settings.find",
1936
+ config: {
1937
+ policies: [
1938
+ "admin::isAuthenticatedAdmin",
1939
+ {
1940
+ name: "admin::hasPermissions",
1941
+ config: {
1942
+ actions: ["plugin::content-releases.settings.read"]
1943
+ }
1944
+ }
1945
+ ]
1946
+ }
1947
+ },
1948
+ {
1949
+ method: "PUT",
1950
+ path: "/settings",
1951
+ handler: "settings.update",
1952
+ config: {
1953
+ policies: [
1954
+ "admin::isAuthenticatedAdmin",
1955
+ {
1956
+ name: "admin::hasPermissions",
1957
+ config: {
1958
+ actions: ["plugin::content-releases.settings.update"]
1959
+ }
1960
+ }
1961
+ ]
1962
+ }
1963
+ }
1964
+ ]
1965
+ };
1014
1966
  const routes = {
1967
+ settings,
1015
1968
  release,
1016
1969
  "release-action": releaseAction
1017
1970
  };
1018
- const { features } = require("@strapi/strapi/dist/utils/ee");
1019
1971
  const getPlugin = () => {
1020
- if (features.isEnabled("cms-content-releases") && strapi.features.future.isEnabled("contentReleases")) {
1972
+ if (strapi.ee.features.isEnabled("cms-content-releases")) {
1021
1973
  return {
1022
1974
  register,
1023
1975
  bootstrap,
1976
+ destroy,
1024
1977
  contentTypes,
1025
1978
  services,
1026
1979
  controllers,
1027
- routes,
1028
- destroy() {
1029
- if (features.isEnabled("cms-content-releases") && strapi.features.future.isEnabled("contentReleases")) {
1030
- getService("event-manager").destroyAllListeners();
1031
- }
1032
- }
1980
+ routes
1033
1981
  };
1034
1982
  }
1035
1983
  return {
1984
+ // Always return register, it handles its own feature check
1985
+ register,
1986
+ // Always return contentTypes to avoid losing data when the feature is disabled
1036
1987
  contentTypes
1037
1988
  };
1038
1989
  };