@strapi/content-releases 5.0.0-beta.0 → 5.0.0-beta.10

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 (71) hide show
  1. package/dist/_chunks/{App-IkyOz9wq.mjs → App-B2R2exNT.mjs} +257 -256
  2. package/dist/_chunks/App-B2R2exNT.mjs.map +1 -0
  3. package/dist/_chunks/{App-FuRaphre.js → App-CEwOQkKT.js} +265 -265
  4. package/dist/_chunks/App-CEwOQkKT.js.map +1 -0
  5. package/dist/_chunks/{PurchaseContentReleases-YhAPgpG9.js → PurchaseContentReleases-Be3acS2L.js} +8 -7
  6. package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +1 -0
  7. package/dist/_chunks/{PurchaseContentReleases-Clm0iACO.mjs → PurchaseContentReleases-_MxP6-Dt.mjs} +9 -8
  8. package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +1 -0
  9. package/dist/_chunks/{en-RdapH-9X.mjs → en-B9Ur3VsE.mjs} +11 -2
  10. package/dist/_chunks/en-B9Ur3VsE.mjs.map +1 -0
  11. package/dist/_chunks/{en-faJDuv3q.js → en-DtFJ5ViE.js} +11 -2
  12. package/dist/_chunks/en-DtFJ5ViE.js.map +1 -0
  13. package/dist/_chunks/{index-Sb3Nal8H.js → index-BrWv-zV4.js} +169 -193
  14. package/dist/_chunks/index-BrWv-zV4.js.map +1 -0
  15. package/dist/_chunks/{index-qP3rNiDS.mjs → index-DbmynICx.mjs} +170 -192
  16. package/dist/_chunks/index-DbmynICx.mjs.map +1 -0
  17. package/dist/admin/index.js +1 -1
  18. package/dist/admin/index.mjs +2 -2
  19. package/dist/admin/src/components/CMReleasesContainer.d.ts +21 -0
  20. package/dist/admin/src/components/ReleaseAction.d.ts +3 -0
  21. package/dist/admin/src/components/ReleaseActionMenu.d.ts +1 -1
  22. package/dist/admin/src/components/ReleaseListCell.d.ts +0 -0
  23. package/dist/admin/src/components/ReleaseModal.d.ts +3 -2
  24. package/dist/admin/src/services/release.d.ts +56 -320
  25. package/dist/admin/src/utils/api.d.ts +6 -0
  26. package/dist/server/index.js +101 -52
  27. package/dist/server/index.js.map +1 -1
  28. package/dist/server/index.mjs +102 -53
  29. package/dist/server/index.mjs.map +1 -1
  30. package/dist/server/src/bootstrap.d.ts +2 -2
  31. package/dist/server/src/bootstrap.d.ts.map +1 -1
  32. package/dist/server/src/controllers/index.d.ts +1 -0
  33. package/dist/server/src/controllers/index.d.ts.map +1 -1
  34. package/dist/server/src/controllers/release-action.d.ts.map +1 -1
  35. package/dist/server/src/controllers/release.d.ts +1 -0
  36. package/dist/server/src/controllers/release.d.ts.map +1 -1
  37. package/dist/server/src/controllers/validation/release-action.d.ts +7 -2
  38. package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -1
  39. package/dist/server/src/destroy.d.ts +2 -2
  40. package/dist/server/src/destroy.d.ts.map +1 -1
  41. package/dist/server/src/index.d.ts +1412 -1411
  42. package/dist/server/src/index.d.ts.map +1 -1
  43. package/dist/server/src/migrations/index.d.ts.map +1 -1
  44. package/dist/server/src/register.d.ts +2 -2
  45. package/dist/server/src/register.d.ts.map +1 -1
  46. package/dist/server/src/routes/release.d.ts.map +1 -1
  47. package/dist/server/src/services/index.d.ts +1407 -1407
  48. package/dist/server/src/services/release.d.ts +9 -9
  49. package/dist/server/src/services/release.d.ts.map +1 -1
  50. package/dist/server/src/services/scheduling.d.ts +6 -6
  51. package/dist/server/src/services/scheduling.d.ts.map +1 -1
  52. package/dist/server/src/services/validation.d.ts +2 -2
  53. package/dist/server/src/services/validation.d.ts.map +1 -1
  54. package/dist/server/src/utils/index.d.ts +10 -10
  55. package/dist/server/src/utils/index.d.ts.map +1 -1
  56. package/dist/shared/contracts/release-actions.d.ts +9 -9
  57. package/dist/shared/contracts/release-actions.d.ts.map +1 -1
  58. package/dist/shared/contracts/releases.d.ts +17 -1
  59. package/dist/shared/contracts/releases.d.ts.map +1 -1
  60. package/dist/shared/types.d.ts +2 -2
  61. package/dist/shared/types.d.ts.map +1 -1
  62. package/package.json +19 -19
  63. package/dist/_chunks/App-FuRaphre.js.map +0 -1
  64. package/dist/_chunks/App-IkyOz9wq.mjs.map +0 -1
  65. package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs.map +0 -1
  66. package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js.map +0 -1
  67. package/dist/_chunks/en-RdapH-9X.mjs.map +0 -1
  68. package/dist/_chunks/en-faJDuv3q.js.map +0 -1
  69. package/dist/_chunks/index-Sb3Nal8H.js.map +0 -1
  70. package/dist/_chunks/index-qP3rNiDS.mjs.map +0 -1
  71. package/dist/admin/src/services/axios.d.ts +0 -29
@@ -76,10 +76,10 @@ const ACTIONS = [
76
76
  const ALLOWED_WEBHOOK_EVENTS = {
77
77
  RELEASES_PUBLISH: "releases.publish"
78
78
  };
79
- const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
79
+ const getService = (name, { strapi: strapi2 }) => {
80
80
  return strapi2.plugin("content-releases").service(name);
81
81
  };
82
- const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 } = { strapi: global.strapi }) => {
82
+ const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 }) => {
83
83
  const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
84
84
  const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
85
85
  const entry = await strapi2.db.query(contentTypeUid).findOne({
@@ -88,7 +88,7 @@ const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 } =
88
88
  });
89
89
  return entry;
90
90
  };
91
- const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 } = { strapi: global.strapi }) => {
91
+ const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 }) => {
92
92
  try {
93
93
  await strapi2.entityValidator.validateEntityCreation(
94
94
  strapi2.getModel(contentTypeUid),
@@ -236,13 +236,16 @@ async function disableContentTypeLocalized({ oldContentTypes, contentTypes: cont
236
236
  if (!oldContentTypes) {
237
237
  return;
238
238
  }
239
+ const i18nPlugin = strapi.plugin("i18n");
240
+ if (!i18nPlugin) {
241
+ return;
242
+ }
239
243
  for (const uid in contentTypes2) {
240
244
  if (!oldContentTypes[uid]) {
241
245
  continue;
242
246
  }
243
247
  const oldContentType = oldContentTypes[uid];
244
248
  const contentType = contentTypes2[uid];
245
- const i18nPlugin = strapi.plugin("i18n");
246
249
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
247
250
  if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
248
251
  await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
@@ -255,13 +258,16 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
255
258
  if (!oldContentTypes) {
256
259
  return;
257
260
  }
261
+ const i18nPlugin = strapi.plugin("i18n");
262
+ if (!i18nPlugin) {
263
+ return;
264
+ }
258
265
  for (const uid in contentTypes2) {
259
266
  if (!oldContentTypes[uid]) {
260
267
  continue;
261
268
  }
262
269
  const oldContentType = oldContentTypes[uid];
263
270
  const contentType = contentTypes2[uid];
264
- const i18nPlugin = strapi.plugin("i18n");
265
271
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
266
272
  const { getDefaultLocale } = i18nPlugin.service("locales");
267
273
  if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
@@ -274,7 +280,7 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
274
280
  }
275
281
  const register = async ({ strapi: strapi2 }) => {
276
282
  if (strapi2.ee.features.isEnabled("cms-content-releases")) {
277
- await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
283
+ await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
278
284
  strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
279
285
  strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
280
286
  }
@@ -344,9 +350,7 @@ const bootstrap = async ({ strapi: strapi2 }) => {
344
350
  actions: {
345
351
  target_type: model.uid,
346
352
  target_id: {
347
- $in: entriesToDelete.map(
348
- (entry) => entry.id
349
- )
353
+ $in: entriesToDelete.map((entry) => entry.id)
350
354
  }
351
355
  }
352
356
  }
@@ -373,13 +377,9 @@ const bootstrap = async ({ strapi: strapi2 }) => {
373
377
  try {
374
378
  const { model, result } = event;
375
379
  if (model.kind === "collectionType" && model.options?.draftAndPublish) {
376
- const isEntryValid = await getEntryValidStatus(
377
- model.uid,
378
- result,
379
- {
380
- strapi: strapi2
381
- }
382
- );
380
+ const isEntryValid = await getEntryValidStatus(model.uid, result, {
381
+ strapi: strapi2
382
+ });
383
383
  await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
384
384
  where: {
385
385
  target_type: model.uid,
@@ -413,7 +413,7 @@ const bootstrap = async ({ strapi: strapi2 }) => {
413
413
  throw err;
414
414
  });
415
415
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
416
- strapi2.webhookStore.addAllowedEvent(key, value);
416
+ strapi2.get("webhookStore").addAllowedEvent(key, value);
417
417
  });
418
418
  }
419
419
  };
@@ -662,7 +662,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
662
662
  return release2;
663
663
  },
664
664
  async findOne(id, query = {}) {
665
- const dbQuery = utils.convertQueryParams.transformParamsToQuery(RELEASE_MODEL_UID, query);
665
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
666
666
  const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
667
667
  ...dbQuery,
668
668
  where: { id }
@@ -670,7 +670,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
670
670
  return release2;
671
671
  },
672
672
  findPage(query) {
673
- const dbQuery = utils.convertQueryParams.transformParamsToQuery(RELEASE_MODEL_UID, query ?? {});
673
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
674
674
  return strapi2.db.query(RELEASE_MODEL_UID).findPage({
675
675
  ...dbQuery,
676
676
  populate: {
@@ -680,12 +680,18 @@ const createReleaseService = ({ strapi: strapi2 }) => {
680
680
  }
681
681
  });
682
682
  },
683
- async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
683
+ async findManyWithContentTypeEntryAttached(contentTypeUid, entriesIds) {
684
+ let entries = entriesIds;
685
+ if (!Array.isArray(entriesIds)) {
686
+ entries = [entriesIds];
687
+ }
684
688
  const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
685
689
  where: {
686
690
  actions: {
687
691
  target_type: contentTypeUid,
688
- target_id: entryId
692
+ target_id: {
693
+ $in: entries
694
+ }
689
695
  },
690
696
  releasedAt: {
691
697
  $null: true
@@ -696,18 +702,25 @@ const createReleaseService = ({ strapi: strapi2 }) => {
696
702
  actions: {
697
703
  where: {
698
704
  target_type: contentTypeUid,
699
- target_id: entryId
705
+ target_id: {
706
+ $in: entries
707
+ }
708
+ },
709
+ populate: {
710
+ entry: {
711
+ select: ["id"]
712
+ }
700
713
  }
701
714
  }
702
715
  }
703
716
  });
704
717
  return releases.map((release2) => {
705
718
  if (release2.actions?.length) {
706
- const [actionForEntry] = release2.actions;
719
+ const actionsForEntry = release2.actions;
707
720
  delete release2.actions;
708
721
  return {
709
722
  ...release2,
710
- action: actionForEntry
723
+ actions: actionsForEntry
711
724
  };
712
725
  }
713
726
  return release2;
@@ -831,10 +844,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
831
844
  if (!release2) {
832
845
  throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
833
846
  }
834
- const dbQuery = utils.convertQueryParams.transformParamsToQuery(
835
- RELEASE_ACTION_MODEL_UID,
836
- query ?? {}
837
- );
847
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
838
848
  return strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
839
849
  ...dbQuery,
840
850
  populate: {
@@ -848,10 +858,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
848
858
  });
849
859
  },
850
860
  async countActions(query) {
851
- const dbQuery = utils.convertQueryParams.transformParamsToQuery(
852
- RELEASE_ACTION_MODEL_UID,
853
- query ?? {}
854
- );
861
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
855
862
  return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
856
863
  },
857
864
  async groupActions(actions, groupBy) {
@@ -861,9 +868,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
861
868
  }
862
869
  return acc;
863
870
  }, []);
864
- const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
865
- contentTypeUids
866
- );
871
+ const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(contentTypeUids);
867
872
  const allLocalesDictionary = await this.getLocalesDataForActions();
868
873
  const formattedData = actions.map((action) => {
869
874
  const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
@@ -985,9 +990,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
985
990
  }
986
991
  try {
987
992
  strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
988
- const { collectionTypeActions, singleTypeActions } = await getFormattedActions(
989
- releaseId
990
- );
993
+ const { collectionTypeActions, singleTypeActions } = await getFormattedActions(releaseId);
991
994
  await strapi2.db.transaction(async () => {
992
995
  for (const { uid, action, id } of singleTypeActions) {
993
996
  await publishSingleTypeAction(uid, action, id);
@@ -1158,7 +1161,8 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
1158
1161
  }
1159
1162
  },
1160
1163
  async validatePendingReleasesLimit() {
1161
- const maximumPendingReleases = strapi2.ee.features.get("cms-content-releases")?.options?.maximumReleases || 3;
1164
+ const featureCfg = strapi2.ee.features.get("cms-content-releases");
1165
+ const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
1162
1166
  const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
1163
1167
  filters: {
1164
1168
  releasedAt: {
@@ -1201,7 +1205,7 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
1201
1205
  }
1202
1206
  const job = nodeSchedule.scheduleJob(scheduleDate, async () => {
1203
1207
  try {
1204
- await getService("release").publish(releaseId);
1208
+ await getService("release", { strapi: strapi2 }).publish(releaseId);
1205
1209
  } catch (error) {
1206
1210
  }
1207
1211
  this.cancel(releaseId);
@@ -1271,7 +1275,7 @@ const RELEASE_SCHEMA = yup__namespace.object().shape({
1271
1275
  const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
1272
1276
  const releaseController = {
1273
1277
  async findMany(ctx) {
1274
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1278
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1275
1279
  ability: ctx.state.userAbility,
1276
1280
  model: RELEASE_MODEL_UID
1277
1281
  });
@@ -1321,7 +1325,7 @@ const releaseController = {
1321
1325
  });
1322
1326
  const sanitizedRelease = {
1323
1327
  ...release2,
1324
- createdBy: release2.createdBy ? strapi.admin.services.user.sanitizeUser(release2.createdBy) : null
1328
+ createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
1325
1329
  };
1326
1330
  const data = {
1327
1331
  ...sanitizedRelease,
@@ -1333,19 +1337,48 @@ const releaseController = {
1333
1337
  };
1334
1338
  ctx.body = { data };
1335
1339
  },
1340
+ async mapEntriesToReleases(ctx) {
1341
+ const { contentTypeUid, entriesIds } = ctx.query;
1342
+ if (!contentTypeUid || !entriesIds) {
1343
+ throw new utils.errors.ValidationError("Missing required query parameters");
1344
+ }
1345
+ const releaseService = getService("release", { strapi });
1346
+ const releasesWithActions = await releaseService.findManyWithContentTypeEntryAttached(
1347
+ contentTypeUid,
1348
+ entriesIds
1349
+ );
1350
+ const mappedEntriesInReleases = releasesWithActions.reduce(
1351
+ // TODO: Fix for v5 removed mappedEntriedToRelease
1352
+ (acc, release2) => {
1353
+ release2.actions.forEach((action) => {
1354
+ if (!acc[action.entry.id]) {
1355
+ acc[action.entry.id] = [{ id: release2.id, name: release2.name }];
1356
+ } else {
1357
+ acc[action.entry.id].push({ id: release2.id, name: release2.name });
1358
+ }
1359
+ });
1360
+ return acc;
1361
+ },
1362
+ // TODO: Fix for v5 removed mappedEntriedToRelease
1363
+ {}
1364
+ );
1365
+ ctx.body = {
1366
+ data: mappedEntriesInReleases
1367
+ };
1368
+ },
1336
1369
  async create(ctx) {
1337
1370
  const user = ctx.state.user;
1338
1371
  const releaseArgs = ctx.request.body;
1339
1372
  await validateRelease(releaseArgs);
1340
1373
  const releaseService = getService("release", { strapi });
1341
1374
  const release2 = await releaseService.create(releaseArgs, { user });
1342
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1375
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1343
1376
  ability: ctx.state.userAbility,
1344
1377
  model: RELEASE_MODEL_UID
1345
1378
  });
1346
- ctx.body = {
1379
+ ctx.created({
1347
1380
  data: await permissionsManager.sanitizeOutput(release2)
1348
- };
1381
+ });
1349
1382
  },
1350
1383
  async update(ctx) {
1351
1384
  const user = ctx.state.user;
@@ -1354,7 +1387,7 @@ const releaseController = {
1354
1387
  await validateRelease(releaseArgs);
1355
1388
  const releaseService = getService("release", { strapi });
1356
1389
  const release2 = await releaseService.update(id, releaseArgs, { user });
1357
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1390
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1358
1391
  ability: ctx.state.userAbility,
1359
1392
  model: RELEASE_MODEL_UID
1360
1393
  });
@@ -1418,9 +1451,9 @@ const releaseActionController = {
1418
1451
  await validateReleaseAction(releaseActionArgs);
1419
1452
  const releaseService = getService("release", { strapi });
1420
1453
  const releaseAction2 = await releaseService.createAction(releaseId, releaseActionArgs);
1421
- ctx.body = {
1454
+ ctx.created({
1422
1455
  data: releaseAction2
1423
- };
1456
+ });
1424
1457
  },
1425
1458
  async createMany(ctx) {
1426
1459
  const releaseId = ctx.params.releaseId;
@@ -1446,17 +1479,17 @@ const releaseActionController = {
1446
1479
  return releaseActions2;
1447
1480
  });
1448
1481
  const newReleaseActions = releaseActions.filter((action) => action !== null);
1449
- ctx.body = {
1482
+ ctx.created({
1450
1483
  data: newReleaseActions,
1451
1484
  meta: {
1452
1485
  entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
1453
1486
  totalEntries: releaseActions.length
1454
1487
  }
1455
- };
1488
+ });
1456
1489
  },
1457
1490
  async findMany(ctx) {
1458
1491
  const releaseId = ctx.params.releaseId;
1459
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1492
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1460
1493
  ability: ctx.state.userAbility,
1461
1494
  model: RELEASE_ACTION_MODEL_UID
1462
1495
  });
@@ -1470,7 +1503,7 @@ const releaseActionController = {
1470
1503
  if (acc[action.contentType]) {
1471
1504
  return acc;
1472
1505
  }
1473
- const contentTypePermissionsManager = strapi.admin.services.permission.createPermissionsManager({
1506
+ const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
1474
1507
  ability: ctx.state.userAbility,
1475
1508
  model: action.contentType
1476
1509
  });
@@ -1522,6 +1555,22 @@ const controllers = { release: releaseController, "release-action": releaseActio
1522
1555
  const release = {
1523
1556
  type: "admin",
1524
1557
  routes: [
1558
+ {
1559
+ method: "GET",
1560
+ path: "/mapEntriesToReleases",
1561
+ handler: "release.mapEntriesToReleases",
1562
+ config: {
1563
+ policies: [
1564
+ "admin::isAuthenticatedAdmin",
1565
+ {
1566
+ name: "admin::hasPermissions",
1567
+ config: {
1568
+ actions: ["plugin::content-releases.read"]
1569
+ }
1570
+ }
1571
+ ]
1572
+ }
1573
+ },
1525
1574
  {
1526
1575
  method: "POST",
1527
1576
  path: "/",