@strapi/content-releases 4.20.5 → 4.21.1

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 (31) hide show
  1. package/dist/_chunks/{App-bpzO2Ljh.mjs → App-XbK-TdJn.mjs} +96 -107
  2. package/dist/_chunks/App-XbK-TdJn.mjs.map +1 -0
  3. package/dist/_chunks/{App-p8aKBitd.js → App-ftICpqDz.js} +95 -106
  4. package/dist/_chunks/App-ftICpqDz.js.map +1 -0
  5. package/dist/_chunks/{PurchaseContentReleases-Clm0iACO.mjs → PurchaseContentReleases-3tRbmbY3.mjs} +2 -2
  6. package/dist/_chunks/PurchaseContentReleases-3tRbmbY3.mjs.map +1 -0
  7. package/dist/_chunks/{PurchaseContentReleases-YhAPgpG9.js → PurchaseContentReleases-bpIYXOfu.js} +2 -2
  8. package/dist/_chunks/PurchaseContentReleases-bpIYXOfu.js.map +1 -0
  9. package/dist/_chunks/{en-gcJJ5htG.js → en-4CUzVH2g.js} +2 -3
  10. package/dist/_chunks/en-4CUzVH2g.js.map +1 -0
  11. package/dist/_chunks/{en-WuuhP6Bn.mjs → en-pOJ6G5fC.mjs} +2 -3
  12. package/dist/_chunks/en-pOJ6G5fC.mjs.map +1 -0
  13. package/dist/_chunks/{index-AECgcaDa.mjs → index-8LrruHqK.mjs} +9 -9
  14. package/dist/_chunks/index-8LrruHqK.mjs.map +1 -0
  15. package/dist/_chunks/{index-fP3qoWZ4.js → index-RYVGXFeL.js} +9 -9
  16. package/dist/_chunks/index-RYVGXFeL.js.map +1 -0
  17. package/dist/admin/index.js +1 -1
  18. package/dist/admin/index.mjs +1 -1
  19. package/dist/server/index.js +213 -151
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/server/index.mjs +213 -151
  22. package/dist/server/index.mjs.map +1 -1
  23. package/package.json +9 -9
  24. package/dist/_chunks/App-bpzO2Ljh.mjs.map +0 -1
  25. package/dist/_chunks/App-p8aKBitd.js.map +0 -1
  26. package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs.map +0 -1
  27. package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js.map +0 -1
  28. package/dist/_chunks/en-WuuhP6Bn.mjs.map +0 -1
  29. package/dist/_chunks/en-gcJJ5htG.js.map +0 -1
  30. package/dist/_chunks/index-AECgcaDa.mjs.map +0 -1
  31. package/dist/_chunks/index-fP3qoWZ4.js.map +0 -1
@@ -383,27 +383,23 @@ const bootstrap = async ({ strapi: strapi2 }) => {
383
383
  }
384
384
  }
385
385
  });
386
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
387
- getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
388
- strapi2.log.error(
389
- "Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
390
- );
391
- throw err;
392
- });
393
- Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
394
- strapi2.webhookStore.addAllowedEvent(key, value);
395
- });
396
- }
386
+ getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
387
+ strapi2.log.error(
388
+ "Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
389
+ );
390
+ throw err;
391
+ });
392
+ Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
393
+ strapi2.webhookStore.addAllowedEvent(key, value);
394
+ });
397
395
  }
398
396
  };
399
397
  const destroy = async ({ strapi: strapi2 }) => {
400
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
401
- const scheduledJobs = getService("scheduling", {
402
- strapi: strapi2
403
- }).getAll();
404
- for (const [, job] of scheduledJobs) {
405
- job.cancel();
406
- }
398
+ const scheduledJobs = getService("scheduling", {
399
+ strapi: strapi2
400
+ }).getAll();
401
+ for (const [, job] of scheduledJobs) {
402
+ job.cancel();
407
403
  }
408
404
  };
409
405
  const schema$1 = {
@@ -528,6 +524,94 @@ const createReleaseService = ({ strapi: strapi2 }) => {
528
524
  release: release2
529
525
  });
530
526
  };
527
+ const publishSingleTypeAction = async (uid, actionType, entryId) => {
528
+ const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
529
+ const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
530
+ const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
531
+ const entry = await strapi2.entityService.findOne(uid, entryId, { populate });
532
+ try {
533
+ if (actionType === "publish") {
534
+ await entityManagerService.publish(entry, uid);
535
+ } else {
536
+ await entityManagerService.unpublish(entry, uid);
537
+ }
538
+ } catch (error) {
539
+ if (error instanceof errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft"))
540
+ ;
541
+ else {
542
+ throw error;
543
+ }
544
+ }
545
+ };
546
+ const publishCollectionTypeAction = async (uid, entriesToPublishIds, entriestoUnpublishIds) => {
547
+ const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
548
+ const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
549
+ const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
550
+ const entriesToPublish = await strapi2.entityService.findMany(uid, {
551
+ filters: {
552
+ id: {
553
+ $in: entriesToPublishIds
554
+ }
555
+ },
556
+ populate
557
+ });
558
+ const entriesToUnpublish = await strapi2.entityService.findMany(uid, {
559
+ filters: {
560
+ id: {
561
+ $in: entriestoUnpublishIds
562
+ }
563
+ },
564
+ populate
565
+ });
566
+ if (entriesToPublish.length > 0) {
567
+ await entityManagerService.publishMany(entriesToPublish, uid);
568
+ }
569
+ if (entriesToUnpublish.length > 0) {
570
+ await entityManagerService.unpublishMany(entriesToUnpublish, uid);
571
+ }
572
+ };
573
+ const getFormattedActions = async (releaseId) => {
574
+ const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
575
+ where: {
576
+ release: {
577
+ id: releaseId
578
+ }
579
+ },
580
+ populate: {
581
+ entry: {
582
+ fields: ["id"]
583
+ }
584
+ }
585
+ });
586
+ if (actions.length === 0) {
587
+ throw new errors.ValidationError("No entries to publish");
588
+ }
589
+ const collectionTypeActions = {};
590
+ const singleTypeActions = [];
591
+ for (const action of actions) {
592
+ const contentTypeUid = action.contentType;
593
+ if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
594
+ if (!collectionTypeActions[contentTypeUid]) {
595
+ collectionTypeActions[contentTypeUid] = {
596
+ entriesToPublishIds: [],
597
+ entriesToUnpublishIds: []
598
+ };
599
+ }
600
+ if (action.type === "publish") {
601
+ collectionTypeActions[contentTypeUid].entriesToPublishIds.push(action.entry.id);
602
+ } else {
603
+ collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
604
+ }
605
+ } else {
606
+ singleTypeActions.push({
607
+ uid: contentTypeUid,
608
+ action: action.type,
609
+ id: action.entry.id
610
+ });
611
+ }
612
+ }
613
+ return { collectionTypeActions, singleTypeActions };
614
+ };
531
615
  return {
532
616
  async create(releaseData, { user }) {
533
617
  const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
@@ -547,7 +631,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
547
631
  status: "empty"
548
632
  }
549
633
  });
550
- if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
634
+ if (releaseWithCreatorFields.scheduledAt) {
551
635
  const schedulingService = getService("scheduling", { strapi: strapi2 });
552
636
  await schedulingService.set(release2.id, release2.scheduledAt);
553
637
  }
@@ -672,13 +756,11 @@ const createReleaseService = ({ strapi: strapi2 }) => {
672
756
  // @ts-expect-error see above
673
757
  data: releaseWithCreatorFields
674
758
  });
675
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
676
- const schedulingService = getService("scheduling", { strapi: strapi2 });
677
- if (releaseData.scheduledAt) {
678
- await schedulingService.set(id, releaseData.scheduledAt);
679
- } else if (release2.scheduledAt) {
680
- schedulingService.cancel(id);
681
- }
759
+ const schedulingService = getService("scheduling", { strapi: strapi2 });
760
+ if (releaseData.scheduledAt) {
761
+ await schedulingService.set(id, releaseData.scheduledAt);
762
+ } else if (release2.scheduledAt) {
763
+ schedulingService.cancel(id);
682
764
  }
683
765
  this.updateReleaseStatus(id);
684
766
  strapi2.telemetry.send("didUpdateContentRelease");
@@ -844,7 +926,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
844
926
  });
845
927
  await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
846
928
  });
847
- if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
929
+ if (release2.scheduledAt) {
848
930
  const schedulingService = getService("scheduling", { strapi: strapi2 });
849
931
  await schedulingService.cancel(release2.id);
850
932
  }
@@ -852,145 +934,71 @@ const createReleaseService = ({ strapi: strapi2 }) => {
852
934
  return release2;
853
935
  },
854
936
  async publish(releaseId) {
855
- try {
856
- const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
857
- RELEASE_MODEL_UID,
858
- releaseId,
859
- {
860
- populate: {
861
- actions: {
862
- populate: {
863
- entry: {
864
- fields: ["id"]
865
- }
866
- }
867
- }
868
- }
869
- }
870
- );
871
- if (!releaseWithPopulatedActionEntries) {
937
+ const {
938
+ release: release2,
939
+ error
940
+ } = await strapi2.db.transaction(async ({ trx }) => {
941
+ const lockedRelease = await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).select(["id", "name", "releasedAt", "status"]).first().transacting(trx).forUpdate().execute();
942
+ if (!lockedRelease) {
872
943
  throw new errors.NotFoundError(`No release found for id ${releaseId}`);
873
944
  }
874
- if (releaseWithPopulatedActionEntries.releasedAt) {
945
+ if (lockedRelease.releasedAt) {
875
946
  throw new errors.ValidationError("Release already published");
876
947
  }
877
- if (releaseWithPopulatedActionEntries.actions.length === 0) {
878
- throw new errors.ValidationError("No entries to publish");
879
- }
880
- const collectionTypeActions = {};
881
- const singleTypeActions = [];
882
- for (const action of releaseWithPopulatedActionEntries.actions) {
883
- const contentTypeUid = action.contentType;
884
- if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
885
- if (!collectionTypeActions[contentTypeUid]) {
886
- collectionTypeActions[contentTypeUid] = {
887
- entriestoPublishIds: [],
888
- entriesToUnpublishIds: []
889
- };
890
- }
891
- if (action.type === "publish") {
892
- collectionTypeActions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
893
- } else {
894
- collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
895
- }
896
- } else {
897
- singleTypeActions.push({
898
- uid: contentTypeUid,
899
- action: action.type,
900
- id: action.entry.id
901
- });
902
- }
948
+ if (lockedRelease.status === "failed") {
949
+ throw new errors.ValidationError("Release failed to publish");
903
950
  }
904
- const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
905
- const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
906
- await strapi2.db.transaction(async () => {
907
- for (const { uid, action, id } of singleTypeActions) {
908
- const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
909
- const entry = await strapi2.entityService.findOne(uid, id, { populate });
910
- try {
911
- if (action === "publish") {
912
- await entityManagerService.publish(entry, uid);
913
- } else {
914
- await entityManagerService.unpublish(entry, uid);
915
- }
916
- } catch (error) {
917
- if (error instanceof errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft")) {
918
- } else {
919
- throw error;
920
- }
921
- }
922
- }
923
- for (const contentTypeUid of Object.keys(collectionTypeActions)) {
924
- const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
925
- const { entriestoPublishIds, entriesToUnpublishIds } = collectionTypeActions[contentTypeUid];
926
- const entriesToPublish = await strapi2.entityService.findMany(
927
- contentTypeUid,
928
- {
929
- filters: {
930
- id: {
931
- $in: entriestoPublishIds
932
- }
933
- },
934
- populate
935
- }
936
- );
937
- const entriesToUnpublish = await strapi2.entityService.findMany(
938
- contentTypeUid,
939
- {
940
- filters: {
941
- id: {
942
- $in: entriesToUnpublishIds
943
- }
944
- },
945
- populate
946
- }
947
- );
948
- if (entriesToPublish.length > 0) {
949
- await entityManagerService.publishMany(entriesToPublish, contentTypeUid);
951
+ try {
952
+ strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
953
+ const { collectionTypeActions, singleTypeActions } = await getFormattedActions(
954
+ releaseId
955
+ );
956
+ await strapi2.db.transaction(async () => {
957
+ for (const { uid, action, id } of singleTypeActions) {
958
+ await publishSingleTypeAction(uid, action, id);
950
959
  }
951
- if (entriesToUnpublish.length > 0) {
952
- await entityManagerService.unpublishMany(entriesToUnpublish, contentTypeUid);
960
+ for (const contentTypeUid of Object.keys(collectionTypeActions)) {
961
+ const uid = contentTypeUid;
962
+ await publishCollectionTypeAction(
963
+ uid,
964
+ collectionTypeActions[uid].entriesToPublishIds,
965
+ collectionTypeActions[uid].entriesToUnpublishIds
966
+ );
953
967
  }
954
- }
955
- });
956
- const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
957
- data: {
958
- /*
959
- * The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
960
- */
961
- // @ts-expect-error see above
962
- releasedAt: /* @__PURE__ */ new Date()
963
- },
964
- populate: {
965
- actions: {
966
- // @ts-expect-error is not expecting count but it is working
967
- count: true
968
+ });
969
+ const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
970
+ where: {
971
+ id: releaseId
972
+ },
973
+ data: {
974
+ status: "done",
975
+ releasedAt: /* @__PURE__ */ new Date()
968
976
  }
969
- }
970
- });
971
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
977
+ });
972
978
  dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
973
979
  isPublished: true,
974
- release: release2
980
+ release: release22
975
981
  });
976
- }
977
- strapi2.telemetry.send("didPublishContentRelease");
978
- return release2;
979
- } catch (error) {
980
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
982
+ strapi2.telemetry.send("didPublishContentRelease");
983
+ return { release: release22, error: null };
984
+ } catch (error2) {
981
985
  dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
982
986
  isPublished: false,
983
- error
987
+ error: error2
984
988
  });
985
- }
986
- strapi2.db.query(RELEASE_MODEL_UID).update({
987
- where: { id: releaseId },
988
- data: {
989
+ await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
989
990
  status: "failed"
990
- }
991
- });
991
+ }).transacting(trx).execute();
992
+ return {
993
+ release: null,
994
+ error: error2
995
+ };
996
+ }
997
+ });
998
+ if (error) {
992
999
  throw error;
993
1000
  }
1001
+ return release2;
994
1002
  },
995
1003
  async updateAction(actionId, releaseId, update) {
996
1004
  const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
@@ -1077,6 +1085,12 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1077
1085
  }
1078
1086
  };
1079
1087
  };
1088
+ class AlreadyOnReleaseError extends errors.ApplicationError {
1089
+ constructor(message) {
1090
+ super(message);
1091
+ this.name = "AlreadyOnReleaseError";
1092
+ }
1093
+ }
1080
1094
  const createReleaseValidationService = ({ strapi: strapi2 }) => ({
1081
1095
  async validateUniqueEntry(releaseId, releaseActionArgs) {
1082
1096
  const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
@@ -1089,7 +1103,7 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
1089
1103
  (action) => Number(action.entry.id) === Number(releaseActionArgs.entry.id) && action.contentType === releaseActionArgs.entry.contentType
1090
1104
  );
1091
1105
  if (isEntryInRelease) {
1092
- throw new errors.ValidationError(
1106
+ throw new AlreadyOnReleaseError(
1093
1107
  `Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
1094
1108
  );
1095
1109
  }
@@ -1197,7 +1211,7 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
1197
1211
  const services = {
1198
1212
  release: createReleaseService,
1199
1213
  "release-validation": createReleaseValidationService,
1200
- ...strapi.features.future.isEnabled("contentReleasesScheduling") ? { scheduling: createSchedulingService } : {}
1214
+ scheduling: createSchedulingService
1201
1215
  };
1202
1216
  const RELEASE_SCHEMA = yup.object().shape({
1203
1217
  name: yup.string().trim().required(),
@@ -1373,6 +1387,38 @@ const releaseActionController = {
1373
1387
  data: releaseAction2
1374
1388
  };
1375
1389
  },
1390
+ async createMany(ctx) {
1391
+ const releaseId = ctx.params.releaseId;
1392
+ const releaseActionsArgs = ctx.request.body;
1393
+ await Promise.all(
1394
+ releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
1395
+ );
1396
+ const releaseService = getService("release", { strapi });
1397
+ const releaseActions = await strapi.db.transaction(async () => {
1398
+ const releaseActions2 = await Promise.all(
1399
+ releaseActionsArgs.map(async (releaseActionArgs) => {
1400
+ try {
1401
+ const action = await releaseService.createAction(releaseId, releaseActionArgs);
1402
+ return action;
1403
+ } catch (error) {
1404
+ if (error instanceof AlreadyOnReleaseError) {
1405
+ return null;
1406
+ }
1407
+ throw error;
1408
+ }
1409
+ })
1410
+ );
1411
+ return releaseActions2;
1412
+ });
1413
+ const newReleaseActions = releaseActions.filter((action) => action !== null);
1414
+ ctx.body = {
1415
+ data: newReleaseActions,
1416
+ meta: {
1417
+ entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
1418
+ totalEntries: releaseActions.length
1419
+ }
1420
+ };
1421
+ },
1376
1422
  async findMany(ctx) {
1377
1423
  const releaseId = ctx.params.releaseId;
1378
1424
  const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
@@ -1558,6 +1604,22 @@ const releaseAction = {
1558
1604
  ]
1559
1605
  }
1560
1606
  },
1607
+ {
1608
+ method: "POST",
1609
+ path: "/:releaseId/actions/bulk",
1610
+ handler: "release-action.createMany",
1611
+ config: {
1612
+ policies: [
1613
+ "admin::isAuthenticatedAdmin",
1614
+ {
1615
+ name: "admin::hasPermissions",
1616
+ config: {
1617
+ actions: ["plugin::content-releases.create-action"]
1618
+ }
1619
+ }
1620
+ ]
1621
+ }
1622
+ },
1561
1623
  {
1562
1624
  method: "GET",
1563
1625
  path: "/:releaseId/actions",