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