@strapi/content-releases 0.0.0-experimental.f6c00790e260ea5a9b6b86abac5fea02b05d569c → 0.0.0-experimental.f736daceb203b33d9ed36a1149e21f2814d1935c

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 (55) hide show
  1. package/dist/_chunks/{App-JwN_xBnA.mjs → App-CiZCkScI.mjs} +300 -116
  2. package/dist/_chunks/App-CiZCkScI.mjs.map +1 -0
  3. package/dist/_chunks/{App-BFo3ibui.js → App-SGjO5UPV.js} +340 -157
  4. package/dist/_chunks/App-SGjO5UPV.js.map +1 -0
  5. package/dist/_chunks/{PurchaseContentReleases-Be3acS2L.js → PurchaseContentReleases--qQepXpP.js} +2 -2
  6. package/dist/_chunks/PurchaseContentReleases--qQepXpP.js.map +1 -0
  7. package/dist/_chunks/{PurchaseContentReleases-_MxP6-Dt.mjs → PurchaseContentReleases-D-n-w-st.mjs} +2 -2
  8. package/dist/_chunks/{PurchaseContentReleases-_MxP6-Dt.mjs.map → PurchaseContentReleases-D-n-w-st.mjs.map} +1 -1
  9. package/dist/_chunks/{ReleasesSettingsPage-BanjZwEc.js → ReleasesSettingsPage-Cto_NLUd.js} +3 -3
  10. package/dist/_chunks/{ReleasesSettingsPage-BanjZwEc.js.map → ReleasesSettingsPage-Cto_NLUd.js.map} +1 -1
  11. package/dist/_chunks/{ReleasesSettingsPage-CNMXGcZC.mjs → ReleasesSettingsPage-DQT8N3A-.mjs} +3 -3
  12. package/dist/_chunks/{ReleasesSettingsPage-CNMXGcZC.mjs.map → ReleasesSettingsPage-DQT8N3A-.mjs.map} +1 -1
  13. package/dist/_chunks/{en-CmYoEnA7.js → en-BWPPsSH-.js} +11 -2
  14. package/dist/_chunks/en-BWPPsSH-.js.map +1 -0
  15. package/dist/_chunks/{en-D0yVZFqf.mjs → en-D9Q4YW03.mjs} +11 -2
  16. package/dist/_chunks/en-D9Q4YW03.mjs.map +1 -0
  17. package/dist/_chunks/{index-C_e6DQb0.mjs → index-BjvFfTtA.mjs} +68 -24
  18. package/dist/_chunks/index-BjvFfTtA.mjs.map +1 -0
  19. package/dist/_chunks/{index-Em3KctMx.js → index-CyU534vL.js} +69 -26
  20. package/dist/_chunks/index-CyU534vL.js.map +1 -0
  21. package/dist/_chunks/{schemas-z5zp-_Gd.js → schemas-DBYv9gK8.js} +3 -4
  22. package/dist/_chunks/schemas-DBYv9gK8.js.map +1 -0
  23. package/dist/_chunks/{schemas-63pFihNF.mjs → schemas-DdA2ic2U.mjs} +2 -2
  24. package/dist/_chunks/schemas-DdA2ic2U.mjs.map +1 -0
  25. package/dist/admin/index.js +1 -1
  26. package/dist/admin/index.mjs +1 -1
  27. package/dist/admin/src/components/EntryValidationPopover.d.ts +13 -0
  28. package/dist/admin/src/services/release.d.ts +28 -28
  29. package/dist/server/index.js +108 -14
  30. package/dist/server/index.js.map +1 -1
  31. package/dist/server/index.mjs +107 -12
  32. package/dist/server/index.mjs.map +1 -1
  33. package/dist/server/src/controllers/release.d.ts.map +1 -1
  34. package/dist/server/src/index.d.ts +2 -6
  35. package/dist/server/src/index.d.ts.map +1 -1
  36. package/dist/server/src/middlewares/documents.d.ts.map +1 -1
  37. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -1
  38. package/dist/server/src/services/index.d.ts +2 -6
  39. package/dist/server/src/services/index.d.ts.map +1 -1
  40. package/dist/server/src/services/release-action.d.ts +3 -7
  41. package/dist/server/src/services/release-action.d.ts.map +1 -1
  42. package/dist/server/src/utils/index.d.ts.map +1 -1
  43. package/dist/shared/contracts/release-actions.d.ts +8 -1
  44. package/dist/shared/contracts/release-actions.d.ts.map +1 -1
  45. package/package.json +16 -16
  46. package/dist/_chunks/App-BFo3ibui.js.map +0 -1
  47. package/dist/_chunks/App-JwN_xBnA.mjs.map +0 -1
  48. package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +0 -1
  49. package/dist/_chunks/en-CmYoEnA7.js.map +0 -1
  50. package/dist/_chunks/en-D0yVZFqf.mjs.map +0 -1
  51. package/dist/_chunks/index-C_e6DQb0.mjs.map +0 -1
  52. package/dist/_chunks/index-Em3KctMx.js.map +0 -1
  53. package/dist/_chunks/schemas-63pFihNF.mjs.map +0 -1
  54. package/dist/_chunks/schemas-z5zp-_Gd.js.map +0 -1
  55. package/strapi-server.js +0 -3
@@ -88,6 +88,13 @@ const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
88
88
  // @ts-expect-error - FIXME: entity here is unnecessary
89
89
  entry
90
90
  );
91
+ const workflowsService = strapi2.plugin("review-workflows").service("workflows");
92
+ const workflow = await workflowsService.getAssignedWorkflow(contentTypeUid, {
93
+ populate: "stageRequiredToPublish"
94
+ });
95
+ if (workflow?.stageRequiredToPublish) {
96
+ return entry.strapi_stage.id === workflow.stageRequiredToPublish.id;
97
+ }
91
98
  return true;
92
99
  } catch {
93
100
  return false;
@@ -101,7 +108,11 @@ const getEntry = async ({
101
108
  status = "draft"
102
109
  }, { strapi: strapi2 }) => {
103
110
  if (documentId) {
104
- return strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
111
+ const entry = await strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
112
+ if (status === "published" && !entry) {
113
+ return strapi2.documents(contentType).findOne({ documentId, locale, populate, status: "draft" });
114
+ }
115
+ return entry;
105
116
  }
106
117
  return strapi2.documents(contentType).findFirst({ locale, populate, status });
107
118
  };
@@ -306,6 +317,10 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
306
317
  const addEntryDocumentToReleaseActions = {
307
318
  name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
308
319
  async up(trx, db) {
320
+ const hasTable = await trx.schema.hasTable("strapi_release_actions");
321
+ if (!hasTable) {
322
+ return;
323
+ }
309
324
  const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
310
325
  if (hasPolymorphicColumn) {
311
326
  const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
@@ -347,6 +362,7 @@ const register = async ({ strapi: strapi2 }) => {
347
362
  const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
348
363
  const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
349
364
  where: {
365
+ releasedAt: null,
350
366
  actions: {
351
367
  contentType,
352
368
  entryDocumentId: entry.documentId,
@@ -355,7 +371,7 @@ const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) =>
355
371
  }
356
372
  });
357
373
  const entryStatus = await isEntryValid(contentType, entry, { strapi });
358
- await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
374
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).updateMany({
359
375
  where: {
360
376
  contentType,
361
377
  entryDocumentId: entry.documentId,
@@ -459,8 +475,8 @@ const bootstrap = async ({ strapi: strapi2 }) => {
459
475
  const { where } = event.params;
460
476
  deleteReleasesActionsAndUpdateReleaseStatus({
461
477
  contentType: model.uid,
462
- locale: where.locale ?? null,
463
- ...where.documentId && { entryDocumentId: where.documentId }
478
+ locale: where?.locale ?? null,
479
+ ...where?.documentId && { entryDocumentId: where.documentId }
464
480
  });
465
481
  }
466
482
  } catch (error) {
@@ -914,6 +930,14 @@ const createReleaseActionService = ({ strapi: strapi2 }) => {
914
930
  validateEntryData(action.contentType, action.entryDocumentId),
915
931
  validateUniqueEntry(releaseId, action)
916
932
  ]);
933
+ const model = strapi2.contentType(action.contentType);
934
+ if (model.kind === "singleType") {
935
+ const document = await strapi2.db.query(model.uid).findOne({ select: ["documentId"] });
936
+ if (!document) {
937
+ throw new errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
938
+ }
939
+ action.entryDocumentId = document.documentId;
940
+ }
917
941
  const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
918
942
  if (!release2) {
919
943
  throw new errors.NotFoundError(`No release found for id ${releaseId}`);
@@ -1007,16 +1031,26 @@ const createReleaseActionService = ({ strapi: strapi2 }) => {
1007
1031
  const groupName = getGroupName(groupBy);
1008
1032
  return _.groupBy(groupName)(formattedData);
1009
1033
  },
1010
- getContentTypeModelsFromActions(actions) {
1034
+ async getContentTypeModelsFromActions(actions) {
1011
1035
  const contentTypeUids = actions.reduce((acc, action) => {
1012
1036
  if (!acc.includes(action.contentType)) {
1013
1037
  acc.push(action.contentType);
1014
1038
  }
1015
1039
  return acc;
1016
1040
  }, []);
1017
- const contentTypeModelsMap = contentTypeUids.reduce(
1018
- (acc, contentTypeUid) => {
1019
- acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
1041
+ const workflowsService = strapi2.plugin("review-workflows").service("workflows");
1042
+ const contentTypeModelsMap = await async.reduce(contentTypeUids)(
1043
+ async (accPromise, contentTypeUid) => {
1044
+ const acc = await accPromise;
1045
+ const contentTypeModel = strapi2.getModel(contentTypeUid);
1046
+ const workflow = await workflowsService.getAssignedWorkflow(contentTypeUid, {
1047
+ populate: "stageRequiredToPublish"
1048
+ });
1049
+ acc[contentTypeUid] = {
1050
+ ...contentTypeModel,
1051
+ hasReviewWorkflow: !!workflow,
1052
+ stageRequiredToPublish: workflow?.stageRequiredToPublish
1053
+ };
1020
1054
  return acc;
1021
1055
  },
1022
1056
  {}
@@ -1044,7 +1078,7 @@ const createReleaseActionService = ({ strapi: strapi2 }) => {
1044
1078
  `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1045
1079
  );
1046
1080
  }
1047
- const actionStatus = update.type === "publish" ? getDraftEntryValidStatus(
1081
+ const actionStatus = update.type === "publish" ? await getDraftEntryValidStatus(
1048
1082
  {
1049
1083
  contentType: action.contentType,
1050
1084
  documentId: action.entryDocumentId,
@@ -1091,6 +1125,54 @@ const createReleaseActionService = ({ strapi: strapi2 }) => {
1091
1125
  }
1092
1126
  getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1093
1127
  return deletedAction;
1128
+ },
1129
+ async validateActionsByContentTypes(contentTypeUids) {
1130
+ const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
1131
+ where: {
1132
+ contentType: {
1133
+ $in: contentTypeUids
1134
+ },
1135
+ // We only want to validate actions that are going to be published
1136
+ type: "publish",
1137
+ release: {
1138
+ releasedAt: {
1139
+ $null: true
1140
+ }
1141
+ }
1142
+ },
1143
+ populate: { release: true }
1144
+ });
1145
+ const releasesUpdated = [];
1146
+ await async.map(actions, async (action) => {
1147
+ const isValid = await getDraftEntryValidStatus(
1148
+ {
1149
+ contentType: action.contentType,
1150
+ documentId: action.entryDocumentId,
1151
+ locale: action.locale
1152
+ },
1153
+ { strapi: strapi2 }
1154
+ );
1155
+ await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
1156
+ where: {
1157
+ id: action.id
1158
+ },
1159
+ data: {
1160
+ isEntryValid: isValid
1161
+ }
1162
+ });
1163
+ if (!releasesUpdated.includes(action.release.id)) {
1164
+ releasesUpdated.push(action.release.id);
1165
+ }
1166
+ return {
1167
+ id: action.id,
1168
+ isEntryValid: isValid
1169
+ };
1170
+ });
1171
+ if (releasesUpdated.length > 0) {
1172
+ await async.map(releasesUpdated, async (releaseId) => {
1173
+ await getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1174
+ });
1175
+ }
1094
1176
  }
1095
1177
  };
1096
1178
  };
@@ -1285,7 +1367,15 @@ const releaseController = {
1285
1367
  const releaseService = getService("release", { strapi });
1286
1368
  const query = await permissionsManager.sanitizeQuery(ctx.query);
1287
1369
  await validatefindByDocumentAttachedParams(query);
1288
- const { contentType, entryDocumentId, hasEntryAttached, locale } = query;
1370
+ const model = strapi.getModel(query.contentType);
1371
+ if (model.kind && model.kind === "singleType") {
1372
+ const document = await strapi.db.query(model.uid).findOne({ select: ["documentId"] });
1373
+ if (!document) {
1374
+ throw new errors.NotFoundError(`No entry found for contentType ${query.contentType}`);
1375
+ }
1376
+ query.entryDocumentId = document.documentId;
1377
+ }
1378
+ const { contentType, hasEntryAttached, entryDocumentId, locale } = query;
1289
1379
  const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
1290
1380
  if (isEntryAttached) {
1291
1381
  const releases = await releaseService.findMany({
@@ -1299,7 +1389,12 @@ const releaseController = {
1299
1389
  },
1300
1390
  populate: {
1301
1391
  actions: {
1302
- fields: ["type"]
1392
+ fields: ["type"],
1393
+ filters: {
1394
+ contentType,
1395
+ entryDocumentId: entryDocumentId ?? null,
1396
+ locale: locale ?? null
1397
+ }
1303
1398
  }
1304
1399
  }
1305
1400
  });
@@ -1596,7 +1691,7 @@ const releaseActionController = {
1596
1691
  entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
1597
1692
  }));
1598
1693
  const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
1599
- const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
1694
+ const contentTypes2 = await releaseActionService.getContentTypeModelsFromActions(results);
1600
1695
  const releaseService = getService("release", { strapi });
1601
1696
  const components = await releaseService.getAllComponents();
1602
1697
  ctx.body = {