@strapi/content-manager 0.0.0-experimental.e9122b401c96877b6707775c4f893660eab93ae3 → 0.0.0-experimental.eba25ec571b091c6bde1104eb6c753debdf15462

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 (174) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs → ComponentConfigurationPage-BaJMOQyq.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs.map → ComponentConfigurationPage-BaJMOQyq.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-_zF8p6CY.js → ComponentConfigurationPage-N-CTtgQa.js} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-_zF8p6CY.js.map → ComponentConfigurationPage-N-CTtgQa.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js → EditConfigurationPage-BHkjAbxH.js} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js.map → EditConfigurationPage-BHkjAbxH.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs → EditConfigurationPage-CKK-5LfX.mjs} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs.map → EditConfigurationPage-CKK-5LfX.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-DeTn7rAF.mjs → EditViewPage-B11aeMcf.mjs} +50 -10
  10. package/dist/_chunks/EditViewPage-B11aeMcf.mjs.map +1 -0
  11. package/dist/_chunks/{EditViewPage-G9uNzwYL.js → EditViewPage-QPUftxUd.js} +49 -9
  12. package/dist/_chunks/EditViewPage-QPUftxUd.js.map +1 -0
  13. package/dist/_chunks/{Field-CnCKhI1R.mjs → Field-Bj_RgtGo.mjs} +109 -46
  14. package/dist/_chunks/Field-Bj_RgtGo.mjs.map +1 -0
  15. package/dist/_chunks/{Field-DDHUWEfV.js → Field-DUK83cfh.js} +108 -45
  16. package/dist/_chunks/Field-DUK83cfh.js.map +1 -0
  17. package/dist/_chunks/{Form-DYETaKUX.js → Form-DHmBRlHd.js} +3 -3
  18. package/dist/_chunks/Form-DHmBRlHd.js.map +1 -0
  19. package/dist/_chunks/{Form-IvVVwqRL.mjs → Form-DLMSoXV7.mjs} +3 -3
  20. package/dist/_chunks/Form-DLMSoXV7.mjs.map +1 -0
  21. package/dist/_chunks/{History-BMunT-do.mjs → History-CfCSNlG9.mjs} +43 -100
  22. package/dist/_chunks/History-CfCSNlG9.mjs.map +1 -0
  23. package/dist/_chunks/{History-CnZDctSO.js → History-Di3zm4HT.js} +41 -98
  24. package/dist/_chunks/History-Di3zm4HT.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs → ListConfigurationPage-0mtv_iqk.mjs} +6 -5
  26. package/dist/_chunks/ListConfigurationPage-0mtv_iqk.mjs.map +1 -0
  27. package/dist/_chunks/{ListConfigurationPage-BynalOp8.js → ListConfigurationPage-Cq361KIt.js} +5 -4
  28. package/dist/_chunks/ListConfigurationPage-Cq361KIt.js.map +1 -0
  29. package/dist/_chunks/{ListViewPage-_5gS-DOF.mjs → ListViewPage-BxLVROX8.mjs} +69 -42
  30. package/dist/_chunks/ListViewPage-BxLVROX8.mjs.map +1 -0
  31. package/dist/_chunks/{ListViewPage-I88Ouzoq.js → ListViewPage-DFDcG8gM.js} +69 -42
  32. package/dist/_chunks/ListViewPage-DFDcG8gM.js.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs → NoContentTypePage-BRfDd67_.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs.map → NoContentTypePage-BRfDd67_.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js → NoContentTypePage-BSyvnDZZ.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js.map → NoContentTypePage-BSyvnDZZ.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs → NoPermissionsPage-CV9V8KWa.mjs} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs.map → NoPermissionsPage-CV9V8KWa.mjs.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js → NoPermissionsPage-DyLphsn_.js} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js.map → NoPermissionsPage-DyLphsn_.js.map} +1 -1
  41. package/dist/_chunks/Preview-C_B1nx3g.mjs +272 -0
  42. package/dist/_chunks/Preview-C_B1nx3g.mjs.map +1 -0
  43. package/dist/_chunks/Preview-D_3aO6Ly.js +291 -0
  44. package/dist/_chunks/Preview-D_3aO6Ly.js.map +1 -0
  45. package/dist/_chunks/{Relations-Chdt5qWc.mjs → Relations-C6pwmDXh.mjs} +72 -36
  46. package/dist/_chunks/Relations-C6pwmDXh.mjs.map +1 -0
  47. package/dist/_chunks/{Relations-BPgFQeGj.js → Relations-Cne2AlrL.js} +71 -35
  48. package/dist/_chunks/Relations-Cne2AlrL.js.map +1 -0
  49. package/dist/_chunks/{en-CPTj6CjC.mjs → en-DhFUjrNW.mjs} +22 -11
  50. package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-DhFUjrNW.mjs.map} +1 -1
  51. package/dist/_chunks/{en-BVzUkPxZ.js → en-Ic0kXjxB.js} +22 -11
  52. package/dist/_chunks/{en-BVzUkPxZ.js.map → en-Ic0kXjxB.js.map} +1 -1
  53. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  54. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  55. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  56. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  57. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  58. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  59. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  60. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  61. package/dist/_chunks/{index-D4UGPFZC.mjs → index-BpxR3En4.mjs} +887 -726
  62. package/dist/_chunks/index-BpxR3En4.mjs.map +1 -0
  63. package/dist/_chunks/{index-BhbLFX4l.js → index-T-aWjbj2.js} +884 -722
  64. package/dist/_chunks/index-T-aWjbj2.js.map +1 -0
  65. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  66. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  67. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  68. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  69. package/dist/_chunks/{layout-CYA7s0qO.js → layout-BEuNwv-F.js} +3 -3
  70. package/dist/_chunks/{layout-CYA7s0qO.js.map → layout-BEuNwv-F.js.map} +1 -1
  71. package/dist/_chunks/{layout-D4HI4_PS.mjs → layout-DhMZ_lDx.mjs} +3 -3
  72. package/dist/_chunks/{layout-D4HI4_PS.mjs.map → layout-DhMZ_lDx.mjs.map} +1 -1
  73. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  74. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  75. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  76. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  77. package/dist/_chunks/{relations-1pXaYpBK.mjs → relations-BdnxoX6f.mjs} +6 -7
  78. package/dist/_chunks/relations-BdnxoX6f.mjs.map +1 -0
  79. package/dist/_chunks/{relations-DDZ9OxNo.js → relations-kLcuobLk.js} +6 -7
  80. package/dist/_chunks/relations-kLcuobLk.js.map +1 -0
  81. package/dist/admin/index.js +2 -1
  82. package/dist/admin/index.js.map +1 -1
  83. package/dist/admin/index.mjs +4 -3
  84. package/dist/admin/src/exports.d.ts +1 -1
  85. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  86. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  87. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
  88. package/dist/admin/src/pages/EditView/components/Header.d.ts +1 -0
  89. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  90. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  91. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  92. package/dist/admin/src/preview/constants.d.ts +1 -0
  93. package/dist/admin/src/preview/index.d.ts +4 -0
  94. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  95. package/dist/admin/src/preview/routes.d.ts +3 -0
  96. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  97. package/dist/admin/src/router.d.ts +1 -1
  98. package/dist/admin/src/services/documents.d.ts +0 -3
  99. package/dist/server/index.js +421 -160
  100. package/dist/server/index.js.map +1 -1
  101. package/dist/server/index.mjs +422 -161
  102. package/dist/server/index.mjs.map +1 -1
  103. package/dist/server/src/bootstrap.d.ts.map +1 -1
  104. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  105. package/dist/server/src/controllers/index.d.ts.map +1 -1
  106. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  107. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  108. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  109. package/dist/server/src/history/services/history.d.ts.map +1 -1
  110. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  111. package/dist/server/src/history/services/utils.d.ts +2 -3
  112. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  113. package/dist/server/src/index.d.ts +4 -4
  114. package/dist/server/src/preview/constants.d.ts +2 -0
  115. package/dist/server/src/preview/constants.d.ts.map +1 -0
  116. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  117. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  118. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  119. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  120. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  121. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  122. package/dist/server/src/preview/index.d.ts +4 -0
  123. package/dist/server/src/preview/index.d.ts.map +1 -0
  124. package/dist/server/src/preview/routes/index.d.ts +8 -0
  125. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  126. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  127. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  128. package/dist/server/src/preview/services/index.d.ts +16 -0
  129. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  130. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  131. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  132. package/dist/server/src/preview/services/preview.d.ts +12 -0
  133. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  134. package/dist/server/src/preview/utils.d.ts +19 -0
  135. package/dist/server/src/preview/utils.d.ts.map +1 -0
  136. package/dist/server/src/register.d.ts.map +1 -1
  137. package/dist/server/src/routes/index.d.ts.map +1 -1
  138. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  139. package/dist/server/src/services/document-metadata.d.ts +8 -8
  140. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  141. package/dist/server/src/services/index.d.ts +4 -4
  142. package/dist/server/src/services/index.d.ts.map +1 -1
  143. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  144. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  145. package/dist/server/src/utils/index.d.ts +2 -0
  146. package/dist/server/src/utils/index.d.ts.map +1 -1
  147. package/dist/shared/contracts/index.d.ts +1 -0
  148. package/dist/shared/contracts/index.d.ts.map +1 -1
  149. package/dist/shared/contracts/preview.d.ts +27 -0
  150. package/dist/shared/contracts/preview.d.ts.map +1 -0
  151. package/dist/shared/index.js +4 -0
  152. package/dist/shared/index.js.map +1 -1
  153. package/dist/shared/index.mjs +4 -0
  154. package/dist/shared/index.mjs.map +1 -1
  155. package/package.json +13 -13
  156. package/dist/_chunks/EditViewPage-DeTn7rAF.mjs.map +0 -1
  157. package/dist/_chunks/EditViewPage-G9uNzwYL.js.map +0 -1
  158. package/dist/_chunks/Field-CnCKhI1R.mjs.map +0 -1
  159. package/dist/_chunks/Field-DDHUWEfV.js.map +0 -1
  160. package/dist/_chunks/Form-DYETaKUX.js.map +0 -1
  161. package/dist/_chunks/Form-IvVVwqRL.mjs.map +0 -1
  162. package/dist/_chunks/History-BMunT-do.mjs.map +0 -1
  163. package/dist/_chunks/History-CnZDctSO.js.map +0 -1
  164. package/dist/_chunks/ListConfigurationPage-BynalOp8.js.map +0 -1
  165. package/dist/_chunks/ListConfigurationPage-CDqkCxgV.mjs.map +0 -1
  166. package/dist/_chunks/ListViewPage-I88Ouzoq.js.map +0 -1
  167. package/dist/_chunks/ListViewPage-_5gS-DOF.mjs.map +0 -1
  168. package/dist/_chunks/Relations-BPgFQeGj.js.map +0 -1
  169. package/dist/_chunks/Relations-Chdt5qWc.mjs.map +0 -1
  170. package/dist/_chunks/index-BhbLFX4l.js.map +0 -1
  171. package/dist/_chunks/index-D4UGPFZC.mjs.map +0 -1
  172. package/dist/_chunks/relations-1pXaYpBK.mjs.map +0 -1
  173. package/dist/_chunks/relations-DDZ9OxNo.js.map +0 -1
  174. package/strapi-server.js +0 -3
@@ -33,10 +33,10 @@ const isNil__default = /* @__PURE__ */ _interopDefault(isNil);
33
33
  const ___default = /* @__PURE__ */ _interopDefault(_);
34
34
  const qs__default = /* @__PURE__ */ _interopDefault(qs);
35
35
  const slugify__default = /* @__PURE__ */ _interopDefault(slugify);
36
- const getService$1 = (name) => {
36
+ const getService$2 = (name) => {
37
37
  return strapi.plugin("content-manager").service(name);
38
38
  };
39
- function getService(strapi2, name) {
39
+ function getService$1(strapi2, name) {
40
40
  return strapi2.service(`plugin::content-manager.${name}`);
41
41
  }
42
42
  const historyRestoreVersionSchema = yup__namespace.object().shape({
@@ -72,7 +72,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
72
72
  if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
73
73
  throw new strapiUtils.errors.ForbiddenError("contentType and documentId are required");
74
74
  }
75
- const permissionChecker2 = getService$1("permission-checker").create({
75
+ const permissionChecker2 = getService$2("permission-checker").create({
76
76
  userAbility: ctx.state.userAbility,
77
77
  model: ctx.query.contentType
78
78
  });
@@ -80,7 +80,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
80
80
  return ctx.forbidden();
81
81
  }
82
82
  const query = await permissionChecker2.sanitizeQuery(ctx.query);
83
- const { results, pagination } = await getService(strapi2, "history").findVersionsPage({
83
+ const { results, pagination } = await getService$1(strapi2, "history").findVersionsPage({
84
84
  query: {
85
85
  ...query,
86
86
  ...getValidPagination({ page: query.page, pageSize: query.pageSize })
@@ -105,14 +105,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
105
105
  async restoreVersion(ctx) {
106
106
  const request = ctx.request;
107
107
  await validateRestoreVersion(request.body, "contentType is required");
108
- const permissionChecker2 = getService$1("permission-checker").create({
108
+ const permissionChecker2 = getService$2("permission-checker").create({
109
109
  userAbility: ctx.state.userAbility,
110
110
  model: request.body.contentType
111
111
  });
112
112
  if (permissionChecker2.cannot.update()) {
113
113
  throw new strapiUtils.errors.ForbiddenError();
114
114
  }
115
- const restoredDocument = await getService(strapi2, "history").restoreVersion(
115
+ const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
116
116
  request.params.versionId
117
117
  );
118
118
  return {
@@ -121,7 +121,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
121
121
  }
122
122
  };
123
123
  };
124
- const controllers$1 = {
124
+ const controllers$2 = {
125
125
  "history-version": createHistoryVersionController
126
126
  /**
127
127
  * Casting is needed because the types aren't aware that Strapi supports
@@ -228,6 +228,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
228
228
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
229
229
  return documentMetadataService.getStatus(document, meta.availableStatus);
230
230
  };
231
+ const getComponentFields = (componentUID) => {
232
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
233
+ (fieldsAcc, [key, attribute]) => {
234
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
235
+ fieldsAcc.push(key);
236
+ }
237
+ return fieldsAcc;
238
+ },
239
+ []
240
+ );
241
+ };
231
242
  const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
232
243
  const model = strapi2.getModel(uid2);
233
244
  const attributes = Object.entries(model.attributes);
@@ -251,13 +262,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
251
262
  }
252
263
  case "component": {
253
264
  const populate = getDeepPopulate2(attribute.component);
254
- acc[attributeName] = { populate };
265
+ acc[attributeName] = {
266
+ populate,
267
+ [fieldSelector]: getComponentFields(attribute.component)
268
+ };
255
269
  break;
256
270
  }
257
271
  case "dynamiczone": {
258
272
  const populatedComponents = (attribute.components || []).reduce(
259
273
  (acc2, componentUID) => {
260
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
274
+ acc2[componentUID] = {
275
+ populate: getDeepPopulate2(componentUID),
276
+ [fieldSelector]: getComponentFields(componentUID)
277
+ };
261
278
  return acc2;
262
279
  },
263
280
  {}
@@ -370,7 +387,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
370
387
  const attributeValue = entry.data[attributeKey];
371
388
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
372
389
  if (attributeSchema.type === "media") {
373
- const permissionChecker2 = getService$1("permission-checker").create({
390
+ const permissionChecker2 = getService$2("permission-checker").create({
374
391
  userAbility: params.state.userAbility,
375
392
  model: "plugin::upload.file"
376
393
  });
@@ -393,7 +410,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
393
410
  if (userToPopulate == null) {
394
411
  return null;
395
412
  }
396
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
413
+ return strapi2.query("admin::user").findOne({
414
+ where: {
415
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
416
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
417
+ }
418
+ });
397
419
  })
398
420
  );
399
421
  return {
@@ -406,7 +428,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
406
428
  [attributeKey]: adminUsers
407
429
  };
408
430
  }
409
- const permissionChecker2 = getService$1("permission-checker").create({
431
+ const permissionChecker2 = getService$2("permission-checker").create({
410
432
  userAbility: params.state.userAbility,
411
433
  model: attributeSchema.target
412
434
  });
@@ -582,7 +604,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
582
604
  onCommit(async () => {
583
605
  for (const entry of localeEntries) {
584
606
  const status = await serviceUtils.getVersionStatus(uid2, entry);
585
- await getService(strapi2, "history").createVersion({
607
+ await getService$1(strapi2, "history").createVersion({
586
608
  contentType: uid2,
587
609
  data: fp.omit(FIELDS_TO_IGNORE, entry),
588
610
  relatedDocumentId: documentId,
@@ -595,15 +617,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
595
617
  });
596
618
  return result;
597
619
  });
598
- state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
620
+ state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
599
621
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
600
622
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
601
623
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
602
624
  where: {
603
625
  created_at: {
604
- $lt: expirationDate.toISOString()
626
+ $lt: expirationDate
605
627
  }
606
628
  }
629
+ }).catch((error) => {
630
+ if (error instanceof Error) {
631
+ strapi2.log.error("Error deleting expired history versions", error.message);
632
+ }
607
633
  });
608
634
  });
609
635
  state.isInitialized = true;
@@ -615,17 +641,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
615
641
  }
616
642
  };
617
643
  };
618
- const services$1 = {
644
+ const services$2 = {
619
645
  history: createHistoryService,
620
646
  lifecycles: createLifecyclesService
621
647
  };
622
- const info = { pluginName: "content-manager", type: "admin" };
648
+ const info$1 = { pluginName: "content-manager", type: "admin" };
623
649
  const historyVersionRouter = {
624
650
  type: "admin",
625
651
  routes: [
626
652
  {
627
653
  method: "GET",
628
- info,
654
+ info: info$1,
629
655
  path: "/history-versions",
630
656
  handler: "history-version.findMany",
631
657
  config: {
@@ -634,7 +660,7 @@ const historyVersionRouter = {
634
660
  },
635
661
  {
636
662
  method: "PUT",
637
- info,
663
+ info: info$1,
638
664
  path: "/history-versions/:versionId/restore",
639
665
  handler: "history-version.restoreVersion",
640
666
  config: {
@@ -643,7 +669,7 @@ const historyVersionRouter = {
643
669
  }
644
670
  ]
645
671
  };
646
- const routes$1 = {
672
+ const routes$2 = {
647
673
  "history-version": historyVersionRouter
648
674
  };
649
675
  const historyVersion = {
@@ -690,21 +716,21 @@ const historyVersion = {
690
716
  }
691
717
  }
692
718
  };
693
- const getFeature = () => {
719
+ const getFeature$1 = () => {
694
720
  if (strapi.ee.features.isEnabled("cms-content-history")) {
695
721
  return {
696
722
  register({ strapi: strapi2 }) {
697
723
  strapi2.get("models").add(historyVersion);
698
724
  },
699
725
  bootstrap({ strapi: strapi2 }) {
700
- getService(strapi2, "lifecycles").bootstrap();
726
+ getService$1(strapi2, "lifecycles").bootstrap();
701
727
  },
702
728
  destroy({ strapi: strapi2 }) {
703
- getService(strapi2, "lifecycles").destroy();
729
+ getService$1(strapi2, "lifecycles").destroy();
704
730
  },
705
- controllers: controllers$1,
706
- services: services$1,
707
- routes: routes$1
731
+ controllers: controllers$2,
732
+ services: services$2,
733
+ routes: routes$2
708
734
  };
709
735
  }
710
736
  return {
@@ -713,9 +739,205 @@ const getFeature = () => {
713
739
  }
714
740
  };
715
741
  };
716
- const history = getFeature();
742
+ const history = getFeature$1();
743
+ const FEATURE_ID = "preview";
744
+ const info = { pluginName: "content-manager", type: "admin" };
745
+ const previewRouter = {
746
+ type: "admin",
747
+ routes: [
748
+ {
749
+ method: "GET",
750
+ info,
751
+ path: "/preview/url/:contentType",
752
+ handler: "preview.getPreviewUrl",
753
+ config: {
754
+ policies: ["admin::isAuthenticatedAdmin"]
755
+ }
756
+ }
757
+ ]
758
+ };
759
+ const routes$1 = {
760
+ preview: previewRouter
761
+ };
762
+ function getService(strapi2, name) {
763
+ return strapi2.service(`plugin::content-manager.${name}`);
764
+ }
765
+ const getPreviewUrlSchema = yup__namespace.object().shape({
766
+ // Will be undefined for single types
767
+ documentId: yup__namespace.string(),
768
+ locale: yup__namespace.string().nullable(),
769
+ status: yup__namespace.string()
770
+ }).required();
771
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
772
+ await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
773
+ const newParams = fp.pick(["documentId", "locale", "status"], params);
774
+ const model = strapi2.getModel(uid2);
775
+ if (!model || model.modelType !== "contentType") {
776
+ throw new strapiUtils.errors.ValidationError("Invalid content type");
777
+ }
778
+ const isSingleType = model?.kind === "singleType";
779
+ if (!isSingleType && !params.documentId) {
780
+ throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
781
+ }
782
+ if (isSingleType) {
783
+ const doc = await strapi2.documents(uid2).findFirst();
784
+ if (!doc) {
785
+ throw new strapiUtils.errors.NotFoundError("Document not found");
786
+ }
787
+ newParams.documentId = doc?.documentId;
788
+ }
789
+ if (!newParams.status) {
790
+ const isDPEnabled = model?.options?.draftAndPublish;
791
+ newParams.status = isDPEnabled ? "draft" : "published";
792
+ }
793
+ return newParams;
794
+ };
795
+ const createPreviewController = () => {
796
+ return {
797
+ /**
798
+ * Transforms an entry into a preview URL, so that it can be previewed
799
+ * in the Content Manager.
800
+ */
801
+ async getPreviewUrl(ctx) {
802
+ const uid2 = ctx.params.contentType;
803
+ const query = ctx.request.query;
804
+ const params = await validatePreviewUrl(strapi, uid2, query);
805
+ const previewService = getService(strapi, "preview");
806
+ const url = await previewService.getPreviewUrl(uid2, params);
807
+ if (!url) {
808
+ ctx.status = 204;
809
+ }
810
+ return {
811
+ data: { url }
812
+ };
813
+ }
814
+ };
815
+ };
816
+ const controllers$1 = {
817
+ preview: createPreviewController
818
+ /**
819
+ * Casting is needed because the types aren't aware that Strapi supports
820
+ * passing a controller factory as the value, instead of a controller object directly
821
+ */
822
+ };
823
+ const createPreviewService = ({ strapi: strapi2 }) => {
824
+ const config = getService(strapi2, "preview-config");
825
+ return {
826
+ async getPreviewUrl(uid2, params) {
827
+ const handler = config.getPreviewHandler();
828
+ try {
829
+ return handler(uid2, params);
830
+ } catch (error) {
831
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
832
+ throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
833
+ }
834
+ return;
835
+ }
836
+ };
837
+ };
838
+ const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
839
+ const middlewares = strapi.config.get("middlewares");
840
+ const configuredMiddlewares = middlewares.map((currentMiddleware) => {
841
+ if (currentMiddleware === middleware.name) {
842
+ return middleware;
843
+ }
844
+ if (currentMiddleware.name === middleware.name) {
845
+ return fp.mergeWith(
846
+ (objValue, srcValue) => {
847
+ if (Array.isArray(objValue)) {
848
+ return objValue.concat(srcValue);
849
+ }
850
+ return void 0;
851
+ },
852
+ currentMiddleware,
853
+ middleware
854
+ );
855
+ }
856
+ return currentMiddleware;
857
+ });
858
+ strapi.config.set("middlewares", configuredMiddlewares);
859
+ };
860
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
861
+ return {
862
+ register() {
863
+ if (!this.isEnabled()) {
864
+ return;
865
+ }
866
+ const config = strapi2.config.get("admin.preview");
867
+ if (config.config?.allowedOrigins) {
868
+ extendMiddlewareConfiguration({
869
+ name: "strapi::security",
870
+ config: {
871
+ contentSecurityPolicy: {
872
+ directives: {
873
+ "frame-src": config.config.allowedOrigins
874
+ }
875
+ }
876
+ }
877
+ });
878
+ }
879
+ },
880
+ isEnabled() {
881
+ const config = strapi2.config.get("admin.preview");
882
+ if (!config) {
883
+ return false;
884
+ }
885
+ return config?.enabled ?? true;
886
+ },
887
+ /**
888
+ * Validate if the configuration is valid
889
+ */
890
+ validate() {
891
+ if (!this.isEnabled()) {
892
+ return;
893
+ }
894
+ const handler = this.getPreviewHandler();
895
+ if (typeof handler !== "function") {
896
+ throw new strapiUtils.errors.ValidationError(
897
+ "Preview configuration is invalid. Handler must be a function"
898
+ );
899
+ }
900
+ },
901
+ /**
902
+ * Utility to get the preview handler from the configuration
903
+ */
904
+ getPreviewHandler() {
905
+ const config = strapi2.config.get("admin.preview");
906
+ const emptyHandler = () => {
907
+ return void 0;
908
+ };
909
+ if (!this.isEnabled()) {
910
+ return emptyHandler;
911
+ }
912
+ return config?.config?.handler || emptyHandler;
913
+ }
914
+ };
915
+ };
916
+ const services$1 = {
917
+ preview: createPreviewService,
918
+ "preview-config": createPreviewConfigService
919
+ };
920
+ const getFeature = () => {
921
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
922
+ return {};
923
+ }
924
+ return {
925
+ register() {
926
+ const config = getService(strapi, "preview-config");
927
+ config.validate();
928
+ config.register();
929
+ },
930
+ bootstrap() {
931
+ },
932
+ routes: routes$1,
933
+ controllers: controllers$1,
934
+ services: services$1
935
+ };
936
+ };
937
+ const preview = getFeature();
717
938
  const register = async ({ strapi: strapi2 }) => {
718
939
  await history.register?.({ strapi: strapi2 });
940
+ await preview.register?.({ strapi: strapi2 });
719
941
  };
720
942
  const ALLOWED_WEBHOOK_EVENTS = {
721
943
  ENTRY_PUBLISH: "entry.publish",
@@ -725,11 +947,12 @@ const bootstrap = async () => {
725
947
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
726
948
  strapi.get("webhookStore").addAllowedEvent(key, value);
727
949
  });
728
- getService$1("field-sizes").setCustomFieldInputSizes();
729
- await getService$1("components").syncConfigurations();
730
- await getService$1("content-types").syncConfigurations();
731
- await getService$1("permission").registerPermissions();
950
+ getService$2("field-sizes").setCustomFieldInputSizes();
951
+ await getService$2("components").syncConfigurations();
952
+ await getService$2("content-types").syncConfigurations();
953
+ await getService$2("permission").registerPermissions();
732
954
  await history.bootstrap?.({ strapi });
955
+ await preview.bootstrap?.({ strapi });
733
956
  };
734
957
  const destroy = async ({ strapi: strapi2 }) => {
735
958
  await history.destroy?.({ strapi: strapi2 });
@@ -1219,7 +1442,8 @@ const admin = {
1219
1442
  };
1220
1443
  const routes = {
1221
1444
  admin,
1222
- ...history.routes ? history.routes : {}
1445
+ ...history.routes ? history.routes : {},
1446
+ ...preview.routes ? preview.routes : {}
1223
1447
  };
1224
1448
  const hasPermissionsSchema = strapiUtils.yup.object({
1225
1449
  actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
@@ -1476,7 +1700,7 @@ const createMetadasSchema = (schema) => {
1476
1700
  if (!value) {
1477
1701
  return strapiUtils.yup.string();
1478
1702
  }
1479
- const targetSchema = getService$1("content-types").findContentType(
1703
+ const targetSchema = getService$2("content-types").findContentType(
1480
1704
  schema.attributes[key].targetModel
1481
1705
  );
1482
1706
  if (!targetSchema) {
@@ -1645,7 +1869,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1645
1869
  }
1646
1870
  };
1647
1871
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1648
- const documentMetadata2 = getService$1("document-metadata");
1872
+ const documentMetadata2 = getService$2("document-metadata");
1649
1873
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1650
1874
  let {
1651
1875
  meta: { availableLocales, availableStatus }
@@ -1671,8 +1895,8 @@ const createDocument = async (ctx, opts) => {
1671
1895
  const { userAbility, user } = ctx.state;
1672
1896
  const { model } = ctx.params;
1673
1897
  const { body } = ctx.request;
1674
- const documentManager2 = getService$1("document-manager");
1675
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1898
+ const documentManager2 = getService$2("document-manager");
1899
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1676
1900
  if (permissionChecker2.cannot.create()) {
1677
1901
  throw new strapiUtils.errors.ForbiddenError();
1678
1902
  }
@@ -1692,13 +1916,13 @@ const updateDocument = async (ctx, opts) => {
1692
1916
  const { userAbility, user } = ctx.state;
1693
1917
  const { id, model } = ctx.params;
1694
1918
  const { body } = ctx.request;
1695
- const documentManager2 = getService$1("document-manager");
1696
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1919
+ const documentManager2 = getService$2("document-manager");
1920
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1697
1921
  if (permissionChecker2.cannot.update()) {
1698
1922
  throw new strapiUtils.errors.ForbiddenError();
1699
1923
  }
1700
1924
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1701
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1925
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1702
1926
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1703
1927
  const [documentVersion, documentExists] = await Promise.all([
1704
1928
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1715,7 +1939,7 @@ const updateDocument = async (ctx, opts) => {
1715
1939
  throw new strapiUtils.errors.ForbiddenError();
1716
1940
  }
1717
1941
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1718
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1942
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1719
1943
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1720
1944
  const sanitizedBody = await sanitizeFn(body);
1721
1945
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1729,14 +1953,14 @@ const collectionTypes = {
1729
1953
  const { userAbility } = ctx.state;
1730
1954
  const { model } = ctx.params;
1731
1955
  const { query } = ctx.request;
1732
- const documentMetadata2 = getService$1("document-metadata");
1733
- const documentManager2 = getService$1("document-manager");
1734
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1956
+ const documentMetadata2 = getService$2("document-metadata");
1957
+ const documentManager2 = getService$2("document-manager");
1958
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1735
1959
  if (permissionChecker2.cannot.read()) {
1736
1960
  return ctx.forbidden();
1737
1961
  }
1738
1962
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1739
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1963
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1740
1964
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1741
1965
  const { results: documents, pagination } = await documentManager2.findPage(
1742
1966
  { ...permissionQuery, populate, locale, status },
@@ -1765,13 +1989,13 @@ const collectionTypes = {
1765
1989
  async findOne(ctx) {
1766
1990
  const { userAbility } = ctx.state;
1767
1991
  const { model, id } = ctx.params;
1768
- const documentManager2 = getService$1("document-manager");
1769
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1992
+ const documentManager2 = getService$2("document-manager");
1993
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1770
1994
  if (permissionChecker2.cannot.read()) {
1771
1995
  return ctx.forbidden();
1772
1996
  }
1773
1997
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1774
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1998
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1775
1999
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1776
2000
  const version = await documentManager2.findOne(id, model, {
1777
2001
  populate,
@@ -1802,7 +2026,7 @@ const collectionTypes = {
1802
2026
  async create(ctx) {
1803
2027
  const { userAbility } = ctx.state;
1804
2028
  const { model } = ctx.params;
1805
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2029
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1806
2030
  const [totalEntries, document] = await Promise.all([
1807
2031
  strapi.db.query(model).count(),
1808
2032
  createDocument(ctx)
@@ -1823,7 +2047,7 @@ const collectionTypes = {
1823
2047
  async update(ctx) {
1824
2048
  const { userAbility } = ctx.state;
1825
2049
  const { model } = ctx.params;
1826
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2050
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1827
2051
  const updatedVersion = await updateDocument(ctx);
1828
2052
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1829
2053
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1832,13 +2056,13 @@ const collectionTypes = {
1832
2056
  const { userAbility, user } = ctx.state;
1833
2057
  const { model, sourceId: id } = ctx.params;
1834
2058
  const { body } = ctx.request;
1835
- const documentManager2 = getService$1("document-manager");
1836
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2059
+ const documentManager2 = getService$2("document-manager");
2060
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1837
2061
  if (permissionChecker2.cannot.create()) {
1838
2062
  return ctx.forbidden();
1839
2063
  }
1840
2064
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1841
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2065
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1842
2066
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1843
2067
  const document = await documentManager2.findOne(id, model, {
1844
2068
  populate,
@@ -1877,13 +2101,13 @@ const collectionTypes = {
1877
2101
  async delete(ctx) {
1878
2102
  const { userAbility } = ctx.state;
1879
2103
  const { id, model } = ctx.params;
1880
- const documentManager2 = getService$1("document-manager");
1881
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2104
+ const documentManager2 = getService$2("document-manager");
2105
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1882
2106
  if (permissionChecker2.cannot.delete()) {
1883
2107
  return ctx.forbidden();
1884
2108
  }
1885
2109
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1886
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2110
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1887
2111
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1888
2112
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1889
2113
  if (documentLocales.length === 0) {
@@ -1905,14 +2129,14 @@ const collectionTypes = {
1905
2129
  const { userAbility } = ctx.state;
1906
2130
  const { id, model } = ctx.params;
1907
2131
  const { body } = ctx.request;
1908
- const documentManager2 = getService$1("document-manager");
1909
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2132
+ const documentManager2 = getService$2("document-manager");
2133
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1910
2134
  if (permissionChecker2.cannot.publish()) {
1911
2135
  return ctx.forbidden();
1912
2136
  }
1913
2137
  const publishedDocument = await strapi.db.transaction(async () => {
1914
2138
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1915
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2139
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1916
2140
  let document;
1917
2141
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1918
2142
  const isCreate = fp.isNil(id);
@@ -1924,11 +2148,17 @@ const collectionTypes = {
1924
2148
  }
1925
2149
  const isUpdate = !isCreate;
1926
2150
  if (isUpdate) {
1927
- document = await documentManager2.findOne(id, model, { populate, locale });
1928
- if (!document) {
2151
+ const documentExists = documentManager2.exists(model, id);
2152
+ if (!documentExists) {
1929
2153
  throw new strapiUtils.errors.NotFoundError("Document not found");
1930
2154
  }
1931
- if (permissionChecker2.can.update(document)) {
2155
+ document = await documentManager2.findOne(id, model, { populate, locale });
2156
+ if (!document) {
2157
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2158
+ throw new strapiUtils.errors.ForbiddenError();
2159
+ }
2160
+ document = await updateDocument(ctx);
2161
+ } else if (permissionChecker2.can.update(document)) {
1932
2162
  await updateDocument(ctx);
1933
2163
  }
1934
2164
  }
@@ -1954,13 +2184,13 @@ const collectionTypes = {
1954
2184
  const { body } = ctx.request;
1955
2185
  const { documentIds } = body;
1956
2186
  await validateBulkActionInput(body);
1957
- const documentManager2 = getService$1("document-manager");
1958
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2187
+ const documentManager2 = getService$2("document-manager");
2188
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1959
2189
  if (permissionChecker2.cannot.publish()) {
1960
2190
  return ctx.forbidden();
1961
2191
  }
1962
2192
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1963
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2193
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1964
2194
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1965
2195
  allowMultipleLocales: true
1966
2196
  });
@@ -1985,8 +2215,8 @@ const collectionTypes = {
1985
2215
  const { body } = ctx.request;
1986
2216
  const { documentIds } = body;
1987
2217
  await validateBulkActionInput(body);
1988
- const documentManager2 = getService$1("document-manager");
1989
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2218
+ const documentManager2 = getService$2("document-manager");
2219
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1990
2220
  if (permissionChecker2.cannot.unpublish()) {
1991
2221
  return ctx.forbidden();
1992
2222
  }
@@ -2015,8 +2245,8 @@ const collectionTypes = {
2015
2245
  const {
2016
2246
  body: { discardDraft, ...body }
2017
2247
  } = ctx.request;
2018
- const documentManager2 = getService$1("document-manager");
2019
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2248
+ const documentManager2 = getService$2("document-manager");
2249
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2020
2250
  if (permissionChecker2.cannot.unpublish()) {
2021
2251
  return ctx.forbidden();
2022
2252
  }
@@ -2024,7 +2254,7 @@ const collectionTypes = {
2024
2254
  return ctx.forbidden();
2025
2255
  }
2026
2256
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
2027
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2257
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2028
2258
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2029
2259
  const document = await documentManager2.findOne(id, model, {
2030
2260
  populate,
@@ -2055,13 +2285,13 @@ const collectionTypes = {
2055
2285
  const { userAbility } = ctx.state;
2056
2286
  const { id, model } = ctx.params;
2057
2287
  const { body } = ctx.request;
2058
- const documentManager2 = getService$1("document-manager");
2059
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2288
+ const documentManager2 = getService$2("document-manager");
2289
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2060
2290
  if (permissionChecker2.cannot.discard()) {
2061
2291
  return ctx.forbidden();
2062
2292
  }
2063
2293
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2064
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2294
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2065
2295
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2066
2296
  const document = await documentManager2.findOne(id, model, {
2067
2297
  populate,
@@ -2086,13 +2316,13 @@ const collectionTypes = {
2086
2316
  const { query, body } = ctx.request;
2087
2317
  const { documentIds } = body;
2088
2318
  await validateBulkActionInput(body);
2089
- const documentManager2 = getService$1("document-manager");
2090
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2319
+ const documentManager2 = getService$2("document-manager");
2320
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2091
2321
  if (permissionChecker2.cannot.delete()) {
2092
2322
  return ctx.forbidden();
2093
2323
  }
2094
2324
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2095
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2325
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2096
2326
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2097
2327
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2098
2328
  populate,
@@ -2113,13 +2343,13 @@ const collectionTypes = {
2113
2343
  async countDraftRelations(ctx) {
2114
2344
  const { userAbility } = ctx.state;
2115
2345
  const { model, id } = ctx.params;
2116
- const documentManager2 = getService$1("document-manager");
2117
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2346
+ const documentManager2 = getService$2("document-manager");
2347
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2118
2348
  if (permissionChecker2.cannot.read()) {
2119
2349
  return ctx.forbidden();
2120
2350
  }
2121
2351
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2122
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2352
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2123
2353
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2124
2354
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2125
2355
  if (!entity) {
@@ -2138,8 +2368,8 @@ const collectionTypes = {
2138
2368
  const ids = ctx.request.query.documentIds;
2139
2369
  const locale = ctx.request.query.locale;
2140
2370
  const { model } = ctx.params;
2141
- const documentManager2 = getService$1("document-manager");
2142
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2371
+ const documentManager2 = getService$2("document-manager");
2372
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2143
2373
  if (permissionChecker2.cannot.read()) {
2144
2374
  return ctx.forbidden();
2145
2375
  }
@@ -2163,13 +2393,13 @@ const collectionTypes = {
2163
2393
  };
2164
2394
  const components$1 = {
2165
2395
  findComponents(ctx) {
2166
- const components2 = getService$1("components").findAllComponents();
2167
- const { toDto } = getService$1("data-mapper");
2396
+ const components2 = getService$2("components").findAllComponents();
2397
+ const { toDto } = getService$2("data-mapper");
2168
2398
  ctx.body = { data: components2.map(toDto) };
2169
2399
  },
2170
2400
  async findComponentConfiguration(ctx) {
2171
2401
  const { uid: uid2 } = ctx.params;
2172
- const componentService = getService$1("components");
2402
+ const componentService = getService$2("components");
2173
2403
  const component = componentService.findComponent(uid2);
2174
2404
  if (!component) {
2175
2405
  return ctx.notFound("component.notFound");
@@ -2186,7 +2416,7 @@ const components$1 = {
2186
2416
  async updateComponentConfiguration(ctx) {
2187
2417
  const { uid: uid2 } = ctx.params;
2188
2418
  const { body } = ctx.request;
2189
- const componentService = getService$1("components");
2419
+ const componentService = getService$2("components");
2190
2420
  const component = componentService.findComponent(uid2);
2191
2421
  if (!component) {
2192
2422
  return ctx.notFound("component.notFound");
@@ -2220,12 +2450,12 @@ const contentTypes = {
2220
2450
  } catch (error) {
2221
2451
  return ctx.send({ error }, 400);
2222
2452
  }
2223
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2224
- const { toDto } = getService$1("data-mapper");
2453
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2454
+ const { toDto } = getService$2("data-mapper");
2225
2455
  ctx.body = { data: contentTypes2.map(toDto) };
2226
2456
  },
2227
2457
  async findContentTypesSettings(ctx) {
2228
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2458
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2229
2459
  const contentTypes2 = await findAllContentTypes();
2230
2460
  const configurations = await Promise.all(
2231
2461
  contentTypes2.map(async (contentType) => {
@@ -2239,7 +2469,7 @@ const contentTypes = {
2239
2469
  },
2240
2470
  async findContentTypeConfiguration(ctx) {
2241
2471
  const { uid: uid2 } = ctx.params;
2242
- const contentTypeService = getService$1("content-types");
2472
+ const contentTypeService = getService$2("content-types");
2243
2473
  const contentType = await contentTypeService.findContentType(uid2);
2244
2474
  if (!contentType) {
2245
2475
  return ctx.notFound("contentType.notFound");
@@ -2261,13 +2491,13 @@ const contentTypes = {
2261
2491
  const { userAbility } = ctx.state;
2262
2492
  const { uid: uid2 } = ctx.params;
2263
2493
  const { body } = ctx.request;
2264
- const contentTypeService = getService$1("content-types");
2265
- const metricsService = getService$1("metrics");
2494
+ const contentTypeService = getService$2("content-types");
2495
+ const metricsService = getService$2("metrics");
2266
2496
  const contentType = await contentTypeService.findContentType(uid2);
2267
2497
  if (!contentType) {
2268
2498
  return ctx.notFound("contentType.notFound");
2269
2499
  }
2270
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2500
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2271
2501
  return ctx.forbidden();
2272
2502
  }
2273
2503
  let input;
@@ -2300,10 +2530,10 @@ const contentTypes = {
2300
2530
  };
2301
2531
  const init = {
2302
2532
  getInitData(ctx) {
2303
- const { toDto } = getService$1("data-mapper");
2304
- const { findAllComponents } = getService$1("components");
2305
- const { getAllFieldSizes } = getService$1("field-sizes");
2306
- const { findAllContentTypes } = getService$1("content-types");
2533
+ const { toDto } = getService$2("data-mapper");
2534
+ const { findAllComponents } = getService$2("components");
2535
+ const { getAllFieldSizes } = getService$2("field-sizes");
2536
+ const { findAllContentTypes } = getService$2("content-types");
2307
2537
  ctx.body = {
2308
2538
  data: {
2309
2539
  fieldSizes: getAllFieldSizes(),
@@ -2339,7 +2569,7 @@ const addFiltersClause = (params, filtersClause) => {
2339
2569
  params.filters.$and.push(filtersClause);
2340
2570
  };
2341
2571
  const sanitizeMainField = (model, mainField, userAbility) => {
2342
- const permissionChecker2 = getService$1("permission-checker").create({
2572
+ const permissionChecker2 = getService$2("permission-checker").create({
2343
2573
  userAbility,
2344
2574
  model: model.uid
2345
2575
  });
@@ -2353,15 +2583,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2353
2583
  }
2354
2584
  return mainField;
2355
2585
  };
2356
- const addStatusToRelations = async (uid2, relations2) => {
2357
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2586
+ const addStatusToRelations = async (targetUid, relations2) => {
2587
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2588
+ return relations2;
2589
+ }
2590
+ const documentMetadata2 = getService$2("document-metadata");
2591
+ if (!relations2.length) {
2358
2592
  return relations2;
2359
2593
  }
2360
- const documentMetadata2 = getService$1("document-metadata");
2361
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2594
+ const firstRelation = relations2[0];
2595
+ const filters = {
2596
+ documentId: { $in: relations2.map((r) => r.documentId) },
2597
+ // NOTE: find the "opposite" status
2598
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2599
+ };
2600
+ const availableStatus = await strapi.query(targetUid).findMany({
2601
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2602
+ filters
2603
+ });
2362
2604
  return relations2.map((relation) => {
2363
- const availableStatuses = documentsAvailableStatus.filter(
2364
- (availableDocument) => availableDocument.documentId === relation.documentId
2605
+ const availableStatuses = availableStatus.filter(
2606
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2365
2607
  );
2366
2608
  return {
2367
2609
  ...relation,
@@ -2382,11 +2624,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2382
2624
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2383
2625
  const isSourceLocalized = isLocalized(sourceModel);
2384
2626
  const isTargetLocalized = isLocalized(targetModel);
2385
- let validatedLocale = locale;
2386
- if (!targetModel || !isTargetLocalized)
2387
- validatedLocale = void 0;
2388
2627
  return {
2389
- locale: validatedLocale,
2628
+ locale,
2390
2629
  isSourceLocalized,
2391
2630
  isTargetLocalized
2392
2631
  };
@@ -2426,7 +2665,7 @@ const relations = {
2426
2665
  ctx.request?.query?.locale
2427
2666
  );
2428
2667
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2429
- const permissionChecker2 = getService$1("permission-checker").create({
2668
+ const permissionChecker2 = getService$2("permission-checker").create({
2430
2669
  userAbility,
2431
2670
  model
2432
2671
  });
@@ -2451,7 +2690,7 @@ const relations = {
2451
2690
  where.id = id;
2452
2691
  }
2453
2692
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2454
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2693
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2455
2694
  const currentEntity = await strapi.db.query(model).findOne({
2456
2695
  where,
2457
2696
  populate
@@ -2466,7 +2705,7 @@ const relations = {
2466
2705
  }
2467
2706
  entryId = currentEntity.id;
2468
2707
  }
2469
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2708
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2470
2709
  const targetSchema = strapi.getModel(targetUid);
2471
2710
  const mainField = fp.flow(
2472
2711
  fp.prop(`metadatas.${targetField}.edit.mainField`),
@@ -2489,7 +2728,7 @@ const relations = {
2489
2728
  attribute,
2490
2729
  fieldsToSelect,
2491
2730
  mainField,
2492
- source: { schema: sourceSchema },
2731
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2493
2732
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2494
2733
  sourceSchema,
2495
2734
  targetSchema,
@@ -2511,7 +2750,8 @@ const relations = {
2511
2750
  fieldsToSelect,
2512
2751
  mainField,
2513
2752
  source: {
2514
- schema: { uid: sourceUid, modelType: sourceModelType }
2753
+ schema: { uid: sourceUid, modelType: sourceModelType },
2754
+ isLocalized: isSourceLocalized
2515
2755
  },
2516
2756
  target: {
2517
2757
  schema: { uid: targetUid },
@@ -2519,7 +2759,7 @@ const relations = {
2519
2759
  }
2520
2760
  } = await this.extractAndValidateRequestInfo(ctx, id);
2521
2761
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2522
- const permissionChecker2 = getService$1("permission-checker").create({
2762
+ const permissionChecker2 = getService$2("permission-checker").create({
2523
2763
  userAbility: ctx.state.userAbility,
2524
2764
  model: targetUid
2525
2765
  });
@@ -2549,12 +2789,16 @@ const relations = {
2549
2789
  } else {
2550
2790
  where.id = id;
2551
2791
  }
2552
- if (status) {
2553
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2792
+ const publishedAt = getPublishedAtClause(status, targetUid);
2793
+ if (!fp.isEmpty(publishedAt)) {
2794
+ where[`${alias}.published_at`] = publishedAt;
2554
2795
  }
2555
- if (filterByLocale) {
2796
+ if (isTargetLocalized && locale) {
2556
2797
  where[`${alias}.locale`] = locale;
2557
2798
  }
2799
+ if (isSourceLocalized && locale) {
2800
+ where.locale = locale;
2801
+ }
2558
2802
  if ((idsToInclude?.length ?? 0) !== 0) {
2559
2803
  where[`${alias}.id`].$notIn = idsToInclude;
2560
2804
  }
@@ -2572,7 +2816,8 @@ const relations = {
2572
2816
  id: { $notIn: fp.uniq(idsToOmit) }
2573
2817
  });
2574
2818
  }
2575
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2819
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2820
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2576
2821
  ctx.body = {
2577
2822
  ...res,
2578
2823
  results: await addStatusToRelations(targetUid, res.results)
@@ -2587,21 +2832,33 @@ const relations = {
2587
2832
  attribute,
2588
2833
  targetField,
2589
2834
  fieldsToSelect,
2590
- source: {
2591
- schema: { uid: sourceUid }
2592
- },
2593
- target: {
2594
- schema: { uid: targetUid }
2595
- }
2835
+ status,
2836
+ source: { schema: sourceSchema },
2837
+ target: { schema: targetSchema }
2596
2838
  } = await this.extractAndValidateRequestInfo(ctx, id);
2597
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2839
+ const { uid: sourceUid } = sourceSchema;
2840
+ const { uid: targetUid } = targetSchema;
2841
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2598
2842
  const dbQuery = strapi.db.query(sourceUid);
2599
2843
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2844
+ const filters = {};
2845
+ if (sourceSchema?.options?.draftAndPublish) {
2846
+ if (targetSchema?.options?.draftAndPublish) {
2847
+ if (status === "published") {
2848
+ filters.publishedAt = { $notNull: true };
2849
+ } else {
2850
+ filters.publishedAt = { $null: true };
2851
+ }
2852
+ }
2853
+ } else if (targetSchema?.options?.draftAndPublish) {
2854
+ filters.publishedAt = { $null: true };
2855
+ }
2600
2856
  const res = await loadRelations({ id: entryId }, targetField, {
2601
- select: ["id", "documentId", "locale", "publishedAt"],
2857
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2602
2858
  ordering: "desc",
2603
2859
  page: ctx.request.query.page,
2604
- pageSize: ctx.request.query.pageSize
2860
+ pageSize: ctx.request.query.pageSize,
2861
+ filters
2605
2862
  });
2606
2863
  const loadedIds = res.results.map((item) => item.id);
2607
2864
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2622,10 +2879,10 @@ const relations = {
2622
2879
  }
2623
2880
  };
2624
2881
  const buildPopulateFromQuery = async (query, model) => {
2625
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2882
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2626
2883
  };
2627
2884
  const findDocument = async (query, uid2, opts = {}) => {
2628
- const documentManager2 = getService$1("document-manager");
2885
+ const documentManager2 = getService$2("document-manager");
2629
2886
  const populate = await buildPopulateFromQuery(query, uid2);
2630
2887
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2631
2888
  };
@@ -2633,8 +2890,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2633
2890
  const { user, userAbility } = ctx.state;
2634
2891
  const { model } = ctx.params;
2635
2892
  const { body, query } = ctx.request;
2636
- const documentManager2 = getService$1("document-manager");
2637
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2893
+ const documentManager2 = getService$2("document-manager");
2894
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2638
2895
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2639
2896
  throw new strapiUtils.errors.ForbiddenError();
2640
2897
  }
@@ -2675,7 +2932,7 @@ const singleTypes = {
2675
2932
  const { userAbility } = ctx.state;
2676
2933
  const { model } = ctx.params;
2677
2934
  const { query = {} } = ctx.request;
2678
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2935
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2679
2936
  if (permissionChecker2.cannot.read()) {
2680
2937
  return ctx.forbidden();
2681
2938
  }
@@ -2694,7 +2951,7 @@ const singleTypes = {
2694
2951
  permissionChecker2,
2695
2952
  model,
2696
2953
  // @ts-expect-error - fix types
2697
- { id: document.documentId, locale, publishedAt: null },
2954
+ { documentId: document.documentId, locale, publishedAt: null },
2698
2955
  { availableLocales: true, availableStatus: false }
2699
2956
  );
2700
2957
  ctx.body = { data: {}, meta };
@@ -2709,7 +2966,7 @@ const singleTypes = {
2709
2966
  async createOrUpdate(ctx) {
2710
2967
  const { userAbility } = ctx.state;
2711
2968
  const { model } = ctx.params;
2712
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2969
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2713
2970
  const document = await createOrUpdateDocument(ctx);
2714
2971
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2715
2972
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2718,8 +2975,8 @@ const singleTypes = {
2718
2975
  const { userAbility } = ctx.state;
2719
2976
  const { model } = ctx.params;
2720
2977
  const { query = {} } = ctx.request;
2721
- const documentManager2 = getService$1("document-manager");
2722
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2978
+ const documentManager2 = getService$2("document-manager");
2979
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2723
2980
  if (permissionChecker2.cannot.delete()) {
2724
2981
  return ctx.forbidden();
2725
2982
  }
@@ -2747,8 +3004,8 @@ const singleTypes = {
2747
3004
  const { userAbility } = ctx.state;
2748
3005
  const { model } = ctx.params;
2749
3006
  const { query = {} } = ctx.request;
2750
- const documentManager2 = getService$1("document-manager");
2751
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3007
+ const documentManager2 = getService$2("document-manager");
3008
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2752
3009
  if (permissionChecker2.cannot.publish()) {
2753
3010
  return ctx.forbidden();
2754
3011
  }
@@ -2776,8 +3033,8 @@ const singleTypes = {
2776
3033
  body: { discardDraft, ...body },
2777
3034
  query = {}
2778
3035
  } = ctx.request;
2779
- const documentManager2 = getService$1("document-manager");
2780
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3036
+ const documentManager2 = getService$2("document-manager");
3037
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2781
3038
  if (permissionChecker2.cannot.unpublish()) {
2782
3039
  return ctx.forbidden();
2783
3040
  }
@@ -2811,8 +3068,8 @@ const singleTypes = {
2811
3068
  const { userAbility } = ctx.state;
2812
3069
  const { model } = ctx.params;
2813
3070
  const { body, query = {} } = ctx.request;
2814
- const documentManager2 = getService$1("document-manager");
2815
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3071
+ const documentManager2 = getService$2("document-manager");
3072
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2816
3073
  if (permissionChecker2.cannot.discard()) {
2817
3074
  return ctx.forbidden();
2818
3075
  }
@@ -2835,8 +3092,8 @@ const singleTypes = {
2835
3092
  const { userAbility } = ctx.state;
2836
3093
  const { model } = ctx.params;
2837
3094
  const { query } = ctx.request;
2838
- const documentManager2 = getService$1("document-manager");
2839
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3095
+ const documentManager2 = getService$2("document-manager");
3096
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2840
3097
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2841
3098
  if (permissionChecker2.cannot.read()) {
2842
3099
  return ctx.forbidden();
@@ -2860,7 +3117,7 @@ const uid$1 = {
2860
3117
  const { query = {} } = ctx.request;
2861
3118
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2862
3119
  await validateUIDField(contentTypeUID, field);
2863
- const uidService = getService$1("uid");
3120
+ const uidService = getService$2("uid");
2864
3121
  ctx.body = {
2865
3122
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2866
3123
  };
@@ -2872,7 +3129,7 @@ const uid$1 = {
2872
3129
  const { query = {} } = ctx.request;
2873
3130
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2874
3131
  await validateUIDField(contentTypeUID, field);
2875
- const uidService = getService$1("uid");
3132
+ const uidService = getService$2("uid");
2876
3133
  const isAvailable = await uidService.checkUIDAvailability({
2877
3134
  contentTypeUID,
2878
3135
  field,
@@ -2893,7 +3150,8 @@ const controllers = {
2893
3150
  relations,
2894
3151
  "single-types": singleTypes,
2895
3152
  uid: uid$1,
2896
- ...history.controllers ? history.controllers : {}
3153
+ ...history.controllers ? history.controllers : {},
3154
+ ...preview.controllers ? preview.controllers : {}
2897
3155
  };
2898
3156
  const keys = {
2899
3157
  CONFIGURATION: "configuration"
@@ -3044,12 +3302,12 @@ async function syncMetadatas(configuration, schema) {
3044
3302
  return ___default.default.assign(metasWithDefaults, updatedMetas);
3045
3303
  }
3046
3304
  const getTargetSchema = (targetModel) => {
3047
- return getService$1("content-types").findContentType(targetModel);
3305
+ return getService$2("content-types").findContentType(targetModel);
3048
3306
  };
3049
3307
  const DEFAULT_LIST_LENGTH = 4;
3050
3308
  const MAX_ROW_SIZE = 12;
3051
3309
  const isAllowedFieldSize = (type, size) => {
3052
- const { getFieldSize } = getService$1("field-sizes");
3310
+ const { getFieldSize } = getService$2("field-sizes");
3053
3311
  const fieldSize = getFieldSize(type);
3054
3312
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3055
3313
  return false;
@@ -3057,7 +3315,7 @@ const isAllowedFieldSize = (type, size) => {
3057
3315
  return size <= MAX_ROW_SIZE;
3058
3316
  };
3059
3317
  const getDefaultFieldSize = (attribute) => {
3060
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3318
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3061
3319
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3062
3320
  };
3063
3321
  async function createDefaultLayouts(schema) {
@@ -3092,7 +3350,7 @@ function syncLayouts(configuration, schema) {
3092
3350
  for (const el of row) {
3093
3351
  if (!hasEditableAttribute(schema, el.name))
3094
3352
  continue;
3095
- const { hasFieldSize } = getService$1("field-sizes");
3353
+ const { hasFieldSize } = getService$2("field-sizes");
3096
3354
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3097
3355
  if (!isAllowedFieldSize(fieldType, el.size)) {
3098
3356
  elementsToReAppend.push(el.name);
@@ -3232,17 +3490,17 @@ const configurationService$1 = createConfigurationService({
3232
3490
  isComponent: true,
3233
3491
  prefix: STORE_KEY_PREFIX,
3234
3492
  getModels() {
3235
- const { toContentManagerModel } = getService$1("data-mapper");
3493
+ const { toContentManagerModel } = getService$2("data-mapper");
3236
3494
  return fp.mapValues(toContentManagerModel, strapi.components);
3237
3495
  }
3238
3496
  });
3239
3497
  const components = ({ strapi: strapi2 }) => ({
3240
3498
  findAllComponents() {
3241
- const { toContentManagerModel } = getService$1("data-mapper");
3499
+ const { toContentManagerModel } = getService$2("data-mapper");
3242
3500
  return Object.values(strapi2.components).map(toContentManagerModel);
3243
3501
  },
3244
3502
  findComponent(uid2) {
3245
- const { toContentManagerModel } = getService$1("data-mapper");
3503
+ const { toContentManagerModel } = getService$2("data-mapper");
3246
3504
  const component = strapi2.components[uid2];
3247
3505
  return fp.isNil(component) ? component : toContentManagerModel(component);
3248
3506
  },
@@ -3293,17 +3551,17 @@ const configurationService = createConfigurationService({
3293
3551
  storeUtils,
3294
3552
  prefix: "content_types",
3295
3553
  getModels() {
3296
- const { toContentManagerModel } = getService$1("data-mapper");
3554
+ const { toContentManagerModel } = getService$2("data-mapper");
3297
3555
  return fp.mapValues(toContentManagerModel, strapi.contentTypes);
3298
3556
  }
3299
3557
  });
3300
3558
  const service = ({ strapi: strapi2 }) => ({
3301
3559
  findAllContentTypes() {
3302
- const { toContentManagerModel } = getService$1("data-mapper");
3560
+ const { toContentManagerModel } = getService$2("data-mapper");
3303
3561
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3304
3562
  },
3305
3563
  findContentType(uid2) {
3306
- const { toContentManagerModel } = getService$1("data-mapper");
3564
+ const { toContentManagerModel } = getService$2("data-mapper");
3307
3565
  const contentType = strapi2.contentTypes[uid2];
3308
3566
  return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
3309
3567
  },
@@ -3332,7 +3590,7 @@ const service = ({ strapi: strapi2 }) => ({
3332
3590
  return this.findConfiguration(contentType);
3333
3591
  },
3334
3592
  findComponentsConfigurations(contentType) {
3335
- return getService$1("components").findComponentsConfigurations(contentType);
3593
+ return getService$2("components").findComponentsConfigurations(contentType);
3336
3594
  },
3337
3595
  syncConfigurations() {
3338
3596
  return configurationService.syncConfigurations();
@@ -3604,7 +3862,7 @@ const permission = ({ strapi: strapi2 }) => ({
3604
3862
  return userAbility.can(action);
3605
3863
  },
3606
3864
  async registerPermissions() {
3607
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3865
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3608
3866
  const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
3609
3867
  const actions = [
3610
3868
  {
@@ -3880,7 +4138,7 @@ const getQueryPopulate = async (uid2, query) => {
3880
4138
  return populateQuery;
3881
4139
  };
3882
4140
  const buildDeepPopulate = (uid2) => {
3883
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4141
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3884
4142
  };
3885
4143
  const populateBuilder = (uid2) => {
3886
4144
  let getInitialPopulate = async () => {
@@ -4065,7 +4323,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4065
4323
  */
4066
4324
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4067
4325
  const versionsByLocale = fp.groupBy("locale", allVersions);
4068
- delete versionsByLocale[version.locale];
4326
+ if (version.locale) {
4327
+ delete versionsByLocale[version.locale];
4328
+ }
4069
4329
  const model = strapi2.getModel(uid2);
4070
4330
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4071
4331
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
@@ -4421,7 +4681,8 @@ const services = {
4421
4681
  permission,
4422
4682
  "populate-builder": populateBuilder$1,
4423
4683
  uid,
4424
- ...history.services ? history.services : {}
4684
+ ...history.services ? history.services : {},
4685
+ ...preview.services ? preview.services : {}
4425
4686
  };
4426
4687
  const index = () => {
4427
4688
  return {