@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
@@ -1,5 +1,5 @@
1
1
  import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
2
- import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
2
+ import { pick, omit, difference, castArray, mergeWith, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
3
3
  import "@strapi/types";
4
4
  import * as yup from "yup";
5
5
  import { scheduleJob } from "node-schedule";
@@ -7,10 +7,10 @@ import isNil from "lodash/isNil";
7
7
  import _, { intersection as intersection$1, difference as difference$1 } from "lodash";
8
8
  import qs from "qs";
9
9
  import slugify from "@sindresorhus/slugify";
10
- const getService$1 = (name) => {
10
+ const getService$2 = (name) => {
11
11
  return strapi.plugin("content-manager").service(name);
12
12
  };
13
- function getService(strapi2, name) {
13
+ function getService$1(strapi2, name) {
14
14
  return strapi2.service(`plugin::content-manager.${name}`);
15
15
  }
16
16
  const historyRestoreVersionSchema = yup.object().shape({
@@ -46,7 +46,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
46
46
  if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
47
47
  throw new errors.ForbiddenError("contentType and documentId are required");
48
48
  }
49
- const permissionChecker2 = getService$1("permission-checker").create({
49
+ const permissionChecker2 = getService$2("permission-checker").create({
50
50
  userAbility: ctx.state.userAbility,
51
51
  model: ctx.query.contentType
52
52
  });
@@ -54,7 +54,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
54
54
  return ctx.forbidden();
55
55
  }
56
56
  const query = await permissionChecker2.sanitizeQuery(ctx.query);
57
- const { results, pagination: pagination2 } = await getService(strapi2, "history").findVersionsPage({
57
+ const { results, pagination: pagination2 } = await getService$1(strapi2, "history").findVersionsPage({
58
58
  query: {
59
59
  ...query,
60
60
  ...getValidPagination({ page: query.page, pageSize: query.pageSize })
@@ -79,14 +79,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
79
79
  async restoreVersion(ctx) {
80
80
  const request = ctx.request;
81
81
  await validateRestoreVersion(request.body, "contentType is required");
82
- const permissionChecker2 = getService$1("permission-checker").create({
82
+ const permissionChecker2 = getService$2("permission-checker").create({
83
83
  userAbility: ctx.state.userAbility,
84
84
  model: request.body.contentType
85
85
  });
86
86
  if (permissionChecker2.cannot.update()) {
87
87
  throw new errors.ForbiddenError();
88
88
  }
89
- const restoredDocument = await getService(strapi2, "history").restoreVersion(
89
+ const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
90
90
  request.params.versionId
91
91
  );
92
92
  return {
@@ -95,7 +95,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
95
95
  }
96
96
  };
97
97
  };
98
- const controllers$1 = {
98
+ const controllers$2 = {
99
99
  "history-version": createHistoryVersionController
100
100
  /**
101
101
  * Casting is needed because the types aren't aware that Strapi supports
@@ -202,6 +202,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
202
202
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
203
203
  return documentMetadataService.getStatus(document, meta.availableStatus);
204
204
  };
205
+ const getComponentFields = (componentUID) => {
206
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
207
+ (fieldsAcc, [key, attribute]) => {
208
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
209
+ fieldsAcc.push(key);
210
+ }
211
+ return fieldsAcc;
212
+ },
213
+ []
214
+ );
215
+ };
205
216
  const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
206
217
  const model = strapi2.getModel(uid2);
207
218
  const attributes = Object.entries(model.attributes);
@@ -225,13 +236,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
225
236
  }
226
237
  case "component": {
227
238
  const populate = getDeepPopulate2(attribute.component);
228
- acc[attributeName] = { populate };
239
+ acc[attributeName] = {
240
+ populate,
241
+ [fieldSelector]: getComponentFields(attribute.component)
242
+ };
229
243
  break;
230
244
  }
231
245
  case "dynamiczone": {
232
246
  const populatedComponents = (attribute.components || []).reduce(
233
247
  (acc2, componentUID) => {
234
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
248
+ acc2[componentUID] = {
249
+ populate: getDeepPopulate2(componentUID),
250
+ [fieldSelector]: getComponentFields(componentUID)
251
+ };
235
252
  return acc2;
236
253
  },
237
254
  {}
@@ -344,7 +361,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
344
361
  const attributeValue = entry.data[attributeKey];
345
362
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
346
363
  if (attributeSchema.type === "media") {
347
- const permissionChecker2 = getService$1("permission-checker").create({
364
+ const permissionChecker2 = getService$2("permission-checker").create({
348
365
  userAbility: params.state.userAbility,
349
366
  model: "plugin::upload.file"
350
367
  });
@@ -367,7 +384,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
367
384
  if (userToPopulate == null) {
368
385
  return null;
369
386
  }
370
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
387
+ return strapi2.query("admin::user").findOne({
388
+ where: {
389
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
390
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
391
+ }
392
+ });
371
393
  })
372
394
  );
373
395
  return {
@@ -380,7 +402,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
380
402
  [attributeKey]: adminUsers
381
403
  };
382
404
  }
383
- const permissionChecker2 = getService$1("permission-checker").create({
405
+ const permissionChecker2 = getService$2("permission-checker").create({
384
406
  userAbility: params.state.userAbility,
385
407
  model: attributeSchema.target
386
408
  });
@@ -556,7 +578,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
556
578
  onCommit(async () => {
557
579
  for (const entry of localeEntries) {
558
580
  const status = await serviceUtils.getVersionStatus(uid2, entry);
559
- await getService(strapi2, "history").createVersion({
581
+ await getService$1(strapi2, "history").createVersion({
560
582
  contentType: uid2,
561
583
  data: omit(FIELDS_TO_IGNORE, entry),
562
584
  relatedDocumentId: documentId,
@@ -569,15 +591,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
569
591
  });
570
592
  return result;
571
593
  });
572
- state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
594
+ state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
573
595
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
574
596
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
575
597
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
576
598
  where: {
577
599
  created_at: {
578
- $lt: expirationDate.toISOString()
600
+ $lt: expirationDate
579
601
  }
580
602
  }
603
+ }).catch((error) => {
604
+ if (error instanceof Error) {
605
+ strapi2.log.error("Error deleting expired history versions", error.message);
606
+ }
581
607
  });
582
608
  });
583
609
  state.isInitialized = true;
@@ -589,17 +615,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
589
615
  }
590
616
  };
591
617
  };
592
- const services$1 = {
618
+ const services$2 = {
593
619
  history: createHistoryService,
594
620
  lifecycles: createLifecyclesService
595
621
  };
596
- const info = { pluginName: "content-manager", type: "admin" };
622
+ const info$1 = { pluginName: "content-manager", type: "admin" };
597
623
  const historyVersionRouter = {
598
624
  type: "admin",
599
625
  routes: [
600
626
  {
601
627
  method: "GET",
602
- info,
628
+ info: info$1,
603
629
  path: "/history-versions",
604
630
  handler: "history-version.findMany",
605
631
  config: {
@@ -608,7 +634,7 @@ const historyVersionRouter = {
608
634
  },
609
635
  {
610
636
  method: "PUT",
611
- info,
637
+ info: info$1,
612
638
  path: "/history-versions/:versionId/restore",
613
639
  handler: "history-version.restoreVersion",
614
640
  config: {
@@ -617,7 +643,7 @@ const historyVersionRouter = {
617
643
  }
618
644
  ]
619
645
  };
620
- const routes$1 = {
646
+ const routes$2 = {
621
647
  "history-version": historyVersionRouter
622
648
  };
623
649
  const historyVersion = {
@@ -664,21 +690,21 @@ const historyVersion = {
664
690
  }
665
691
  }
666
692
  };
667
- const getFeature = () => {
693
+ const getFeature$1 = () => {
668
694
  if (strapi.ee.features.isEnabled("cms-content-history")) {
669
695
  return {
670
696
  register({ strapi: strapi2 }) {
671
697
  strapi2.get("models").add(historyVersion);
672
698
  },
673
699
  bootstrap({ strapi: strapi2 }) {
674
- getService(strapi2, "lifecycles").bootstrap();
700
+ getService$1(strapi2, "lifecycles").bootstrap();
675
701
  },
676
702
  destroy({ strapi: strapi2 }) {
677
- getService(strapi2, "lifecycles").destroy();
703
+ getService$1(strapi2, "lifecycles").destroy();
678
704
  },
679
- controllers: controllers$1,
680
- services: services$1,
681
- routes: routes$1
705
+ controllers: controllers$2,
706
+ services: services$2,
707
+ routes: routes$2
682
708
  };
683
709
  }
684
710
  return {
@@ -687,9 +713,205 @@ const getFeature = () => {
687
713
  }
688
714
  };
689
715
  };
690
- const history = getFeature();
716
+ const history = getFeature$1();
717
+ const FEATURE_ID = "preview";
718
+ const info = { pluginName: "content-manager", type: "admin" };
719
+ const previewRouter = {
720
+ type: "admin",
721
+ routes: [
722
+ {
723
+ method: "GET",
724
+ info,
725
+ path: "/preview/url/:contentType",
726
+ handler: "preview.getPreviewUrl",
727
+ config: {
728
+ policies: ["admin::isAuthenticatedAdmin"]
729
+ }
730
+ }
731
+ ]
732
+ };
733
+ const routes$1 = {
734
+ preview: previewRouter
735
+ };
736
+ function getService(strapi2, name) {
737
+ return strapi2.service(`plugin::content-manager.${name}`);
738
+ }
739
+ const getPreviewUrlSchema = yup.object().shape({
740
+ // Will be undefined for single types
741
+ documentId: yup.string(),
742
+ locale: yup.string().nullable(),
743
+ status: yup.string()
744
+ }).required();
745
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
746
+ await validateYupSchema(getPreviewUrlSchema)(params);
747
+ const newParams = pick(["documentId", "locale", "status"], params);
748
+ const model = strapi2.getModel(uid2);
749
+ if (!model || model.modelType !== "contentType") {
750
+ throw new errors.ValidationError("Invalid content type");
751
+ }
752
+ const isSingleType = model?.kind === "singleType";
753
+ if (!isSingleType && !params.documentId) {
754
+ throw new errors.ValidationError("documentId is required for Collection Types");
755
+ }
756
+ if (isSingleType) {
757
+ const doc = await strapi2.documents(uid2).findFirst();
758
+ if (!doc) {
759
+ throw new errors.NotFoundError("Document not found");
760
+ }
761
+ newParams.documentId = doc?.documentId;
762
+ }
763
+ if (!newParams.status) {
764
+ const isDPEnabled = model?.options?.draftAndPublish;
765
+ newParams.status = isDPEnabled ? "draft" : "published";
766
+ }
767
+ return newParams;
768
+ };
769
+ const createPreviewController = () => {
770
+ return {
771
+ /**
772
+ * Transforms an entry into a preview URL, so that it can be previewed
773
+ * in the Content Manager.
774
+ */
775
+ async getPreviewUrl(ctx) {
776
+ const uid2 = ctx.params.contentType;
777
+ const query = ctx.request.query;
778
+ const params = await validatePreviewUrl(strapi, uid2, query);
779
+ const previewService = getService(strapi, "preview");
780
+ const url = await previewService.getPreviewUrl(uid2, params);
781
+ if (!url) {
782
+ ctx.status = 204;
783
+ }
784
+ return {
785
+ data: { url }
786
+ };
787
+ }
788
+ };
789
+ };
790
+ const controllers$1 = {
791
+ preview: createPreviewController
792
+ /**
793
+ * Casting is needed because the types aren't aware that Strapi supports
794
+ * passing a controller factory as the value, instead of a controller object directly
795
+ */
796
+ };
797
+ const createPreviewService = ({ strapi: strapi2 }) => {
798
+ const config = getService(strapi2, "preview-config");
799
+ return {
800
+ async getPreviewUrl(uid2, params) {
801
+ const handler = config.getPreviewHandler();
802
+ try {
803
+ return handler(uid2, params);
804
+ } catch (error) {
805
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
806
+ throw new errors.ApplicationError("Failed to get preview URL");
807
+ }
808
+ return;
809
+ }
810
+ };
811
+ };
812
+ const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
813
+ const middlewares = strapi.config.get("middlewares");
814
+ const configuredMiddlewares = middlewares.map((currentMiddleware) => {
815
+ if (currentMiddleware === middleware.name) {
816
+ return middleware;
817
+ }
818
+ if (currentMiddleware.name === middleware.name) {
819
+ return mergeWith(
820
+ (objValue, srcValue) => {
821
+ if (Array.isArray(objValue)) {
822
+ return objValue.concat(srcValue);
823
+ }
824
+ return void 0;
825
+ },
826
+ currentMiddleware,
827
+ middleware
828
+ );
829
+ }
830
+ return currentMiddleware;
831
+ });
832
+ strapi.config.set("middlewares", configuredMiddlewares);
833
+ };
834
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
835
+ return {
836
+ register() {
837
+ if (!this.isEnabled()) {
838
+ return;
839
+ }
840
+ const config = strapi2.config.get("admin.preview");
841
+ if (config.config?.allowedOrigins) {
842
+ extendMiddlewareConfiguration({
843
+ name: "strapi::security",
844
+ config: {
845
+ contentSecurityPolicy: {
846
+ directives: {
847
+ "frame-src": config.config.allowedOrigins
848
+ }
849
+ }
850
+ }
851
+ });
852
+ }
853
+ },
854
+ isEnabled() {
855
+ const config = strapi2.config.get("admin.preview");
856
+ if (!config) {
857
+ return false;
858
+ }
859
+ return config?.enabled ?? true;
860
+ },
861
+ /**
862
+ * Validate if the configuration is valid
863
+ */
864
+ validate() {
865
+ if (!this.isEnabled()) {
866
+ return;
867
+ }
868
+ const handler = this.getPreviewHandler();
869
+ if (typeof handler !== "function") {
870
+ throw new errors.ValidationError(
871
+ "Preview configuration is invalid. Handler must be a function"
872
+ );
873
+ }
874
+ },
875
+ /**
876
+ * Utility to get the preview handler from the configuration
877
+ */
878
+ getPreviewHandler() {
879
+ const config = strapi2.config.get("admin.preview");
880
+ const emptyHandler = () => {
881
+ return void 0;
882
+ };
883
+ if (!this.isEnabled()) {
884
+ return emptyHandler;
885
+ }
886
+ return config?.config?.handler || emptyHandler;
887
+ }
888
+ };
889
+ };
890
+ const services$1 = {
891
+ preview: createPreviewService,
892
+ "preview-config": createPreviewConfigService
893
+ };
894
+ const getFeature = () => {
895
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
896
+ return {};
897
+ }
898
+ return {
899
+ register() {
900
+ const config = getService(strapi, "preview-config");
901
+ config.validate();
902
+ config.register();
903
+ },
904
+ bootstrap() {
905
+ },
906
+ routes: routes$1,
907
+ controllers: controllers$1,
908
+ services: services$1
909
+ };
910
+ };
911
+ const preview = getFeature();
691
912
  const register = async ({ strapi: strapi2 }) => {
692
913
  await history.register?.({ strapi: strapi2 });
914
+ await preview.register?.({ strapi: strapi2 });
693
915
  };
694
916
  const ALLOWED_WEBHOOK_EVENTS = {
695
917
  ENTRY_PUBLISH: "entry.publish",
@@ -699,11 +921,12 @@ const bootstrap = async () => {
699
921
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
700
922
  strapi.get("webhookStore").addAllowedEvent(key, value);
701
923
  });
702
- getService$1("field-sizes").setCustomFieldInputSizes();
703
- await getService$1("components").syncConfigurations();
704
- await getService$1("content-types").syncConfigurations();
705
- await getService$1("permission").registerPermissions();
924
+ getService$2("field-sizes").setCustomFieldInputSizes();
925
+ await getService$2("components").syncConfigurations();
926
+ await getService$2("content-types").syncConfigurations();
927
+ await getService$2("permission").registerPermissions();
706
928
  await history.bootstrap?.({ strapi });
929
+ await preview.bootstrap?.({ strapi });
707
930
  };
708
931
  const destroy = async ({ strapi: strapi2 }) => {
709
932
  await history.destroy?.({ strapi: strapi2 });
@@ -1193,7 +1416,8 @@ const admin = {
1193
1416
  };
1194
1417
  const routes = {
1195
1418
  admin,
1196
- ...history.routes ? history.routes : {}
1419
+ ...history.routes ? history.routes : {},
1420
+ ...preview.routes ? preview.routes : {}
1197
1421
  };
1198
1422
  const hasPermissionsSchema = yup$1.object({
1199
1423
  actions: yup$1.array().of(yup$1.string()),
@@ -1450,7 +1674,7 @@ const createMetadasSchema = (schema) => {
1450
1674
  if (!value) {
1451
1675
  return yup$1.string();
1452
1676
  }
1453
- const targetSchema = getService$1("content-types").findContentType(
1677
+ const targetSchema = getService$2("content-types").findContentType(
1454
1678
  schema.attributes[key].targetModel
1455
1679
  );
1456
1680
  if (!targetSchema) {
@@ -1619,7 +1843,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1619
1843
  }
1620
1844
  };
1621
1845
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1622
- const documentMetadata2 = getService$1("document-metadata");
1846
+ const documentMetadata2 = getService$2("document-metadata");
1623
1847
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1624
1848
  let {
1625
1849
  meta: { availableLocales, availableStatus }
@@ -1645,8 +1869,8 @@ const createDocument = async (ctx, opts) => {
1645
1869
  const { userAbility, user } = ctx.state;
1646
1870
  const { model } = ctx.params;
1647
1871
  const { body } = ctx.request;
1648
- const documentManager2 = getService$1("document-manager");
1649
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1872
+ const documentManager2 = getService$2("document-manager");
1873
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1650
1874
  if (permissionChecker2.cannot.create()) {
1651
1875
  throw new errors.ForbiddenError();
1652
1876
  }
@@ -1666,13 +1890,13 @@ const updateDocument = async (ctx, opts) => {
1666
1890
  const { userAbility, user } = ctx.state;
1667
1891
  const { id, model } = ctx.params;
1668
1892
  const { body } = ctx.request;
1669
- const documentManager2 = getService$1("document-manager");
1670
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1893
+ const documentManager2 = getService$2("document-manager");
1894
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1671
1895
  if (permissionChecker2.cannot.update()) {
1672
1896
  throw new errors.ForbiddenError();
1673
1897
  }
1674
1898
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1675
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1899
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1676
1900
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1677
1901
  const [documentVersion, documentExists] = await Promise.all([
1678
1902
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1689,7 +1913,7 @@ const updateDocument = async (ctx, opts) => {
1689
1913
  throw new errors.ForbiddenError();
1690
1914
  }
1691
1915
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1692
- const setCreator = setCreatorFields({ user, isEdition: true });
1916
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1693
1917
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1694
1918
  const sanitizedBody = await sanitizeFn(body);
1695
1919
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1703,14 +1927,14 @@ const collectionTypes = {
1703
1927
  const { userAbility } = ctx.state;
1704
1928
  const { model } = ctx.params;
1705
1929
  const { query } = ctx.request;
1706
- const documentMetadata2 = getService$1("document-metadata");
1707
- const documentManager2 = getService$1("document-manager");
1708
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1930
+ const documentMetadata2 = getService$2("document-metadata");
1931
+ const documentManager2 = getService$2("document-manager");
1932
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1709
1933
  if (permissionChecker2.cannot.read()) {
1710
1934
  return ctx.forbidden();
1711
1935
  }
1712
1936
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1713
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1937
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1714
1938
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1715
1939
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1716
1940
  { ...permissionQuery, populate, locale, status },
@@ -1739,13 +1963,13 @@ const collectionTypes = {
1739
1963
  async findOne(ctx) {
1740
1964
  const { userAbility } = ctx.state;
1741
1965
  const { model, id } = ctx.params;
1742
- const documentManager2 = getService$1("document-manager");
1743
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1966
+ const documentManager2 = getService$2("document-manager");
1967
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1744
1968
  if (permissionChecker2.cannot.read()) {
1745
1969
  return ctx.forbidden();
1746
1970
  }
1747
1971
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1748
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1972
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1749
1973
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1750
1974
  const version = await documentManager2.findOne(id, model, {
1751
1975
  populate,
@@ -1776,7 +2000,7 @@ const collectionTypes = {
1776
2000
  async create(ctx) {
1777
2001
  const { userAbility } = ctx.state;
1778
2002
  const { model } = ctx.params;
1779
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2003
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1780
2004
  const [totalEntries, document] = await Promise.all([
1781
2005
  strapi.db.query(model).count(),
1782
2006
  createDocument(ctx)
@@ -1797,7 +2021,7 @@ const collectionTypes = {
1797
2021
  async update(ctx) {
1798
2022
  const { userAbility } = ctx.state;
1799
2023
  const { model } = ctx.params;
1800
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2024
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1801
2025
  const updatedVersion = await updateDocument(ctx);
1802
2026
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1803
2027
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1806,13 +2030,13 @@ const collectionTypes = {
1806
2030
  const { userAbility, user } = ctx.state;
1807
2031
  const { model, sourceId: id } = ctx.params;
1808
2032
  const { body } = ctx.request;
1809
- const documentManager2 = getService$1("document-manager");
1810
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2033
+ const documentManager2 = getService$2("document-manager");
2034
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1811
2035
  if (permissionChecker2.cannot.create()) {
1812
2036
  return ctx.forbidden();
1813
2037
  }
1814
2038
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1815
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2039
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1816
2040
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1817
2041
  const document = await documentManager2.findOne(id, model, {
1818
2042
  populate,
@@ -1851,13 +2075,13 @@ const collectionTypes = {
1851
2075
  async delete(ctx) {
1852
2076
  const { userAbility } = ctx.state;
1853
2077
  const { id, model } = ctx.params;
1854
- const documentManager2 = getService$1("document-manager");
1855
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2078
+ const documentManager2 = getService$2("document-manager");
2079
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1856
2080
  if (permissionChecker2.cannot.delete()) {
1857
2081
  return ctx.forbidden();
1858
2082
  }
1859
2083
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1860
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2084
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1861
2085
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1862
2086
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1863
2087
  if (documentLocales.length === 0) {
@@ -1879,14 +2103,14 @@ const collectionTypes = {
1879
2103
  const { userAbility } = ctx.state;
1880
2104
  const { id, model } = ctx.params;
1881
2105
  const { body } = ctx.request;
1882
- const documentManager2 = getService$1("document-manager");
1883
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2106
+ const documentManager2 = getService$2("document-manager");
2107
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1884
2108
  if (permissionChecker2.cannot.publish()) {
1885
2109
  return ctx.forbidden();
1886
2110
  }
1887
2111
  const publishedDocument = await strapi.db.transaction(async () => {
1888
2112
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1889
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2113
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1890
2114
  let document;
1891
2115
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1892
2116
  const isCreate = isNil$1(id);
@@ -1898,11 +2122,17 @@ const collectionTypes = {
1898
2122
  }
1899
2123
  const isUpdate = !isCreate;
1900
2124
  if (isUpdate) {
1901
- document = await documentManager2.findOne(id, model, { populate, locale });
1902
- if (!document) {
2125
+ const documentExists = documentManager2.exists(model, id);
2126
+ if (!documentExists) {
1903
2127
  throw new errors.NotFoundError("Document not found");
1904
2128
  }
1905
- if (permissionChecker2.can.update(document)) {
2129
+ document = await documentManager2.findOne(id, model, { populate, locale });
2130
+ if (!document) {
2131
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2132
+ throw new errors.ForbiddenError();
2133
+ }
2134
+ document = await updateDocument(ctx);
2135
+ } else if (permissionChecker2.can.update(document)) {
1906
2136
  await updateDocument(ctx);
1907
2137
  }
1908
2138
  }
@@ -1928,13 +2158,13 @@ const collectionTypes = {
1928
2158
  const { body } = ctx.request;
1929
2159
  const { documentIds } = body;
1930
2160
  await validateBulkActionInput(body);
1931
- const documentManager2 = getService$1("document-manager");
1932
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2161
+ const documentManager2 = getService$2("document-manager");
2162
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1933
2163
  if (permissionChecker2.cannot.publish()) {
1934
2164
  return ctx.forbidden();
1935
2165
  }
1936
2166
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1937
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2167
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1938
2168
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1939
2169
  allowMultipleLocales: true
1940
2170
  });
@@ -1959,8 +2189,8 @@ const collectionTypes = {
1959
2189
  const { body } = ctx.request;
1960
2190
  const { documentIds } = body;
1961
2191
  await validateBulkActionInput(body);
1962
- const documentManager2 = getService$1("document-manager");
1963
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2192
+ const documentManager2 = getService$2("document-manager");
2193
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1964
2194
  if (permissionChecker2.cannot.unpublish()) {
1965
2195
  return ctx.forbidden();
1966
2196
  }
@@ -1989,8 +2219,8 @@ const collectionTypes = {
1989
2219
  const {
1990
2220
  body: { discardDraft, ...body }
1991
2221
  } = ctx.request;
1992
- const documentManager2 = getService$1("document-manager");
1993
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2222
+ const documentManager2 = getService$2("document-manager");
2223
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1994
2224
  if (permissionChecker2.cannot.unpublish()) {
1995
2225
  return ctx.forbidden();
1996
2226
  }
@@ -1998,7 +2228,7 @@ const collectionTypes = {
1998
2228
  return ctx.forbidden();
1999
2229
  }
2000
2230
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
2001
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2231
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2002
2232
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2003
2233
  const document = await documentManager2.findOne(id, model, {
2004
2234
  populate,
@@ -2029,13 +2259,13 @@ const collectionTypes = {
2029
2259
  const { userAbility } = ctx.state;
2030
2260
  const { id, model } = ctx.params;
2031
2261
  const { body } = ctx.request;
2032
- const documentManager2 = getService$1("document-manager");
2033
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2262
+ const documentManager2 = getService$2("document-manager");
2263
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2034
2264
  if (permissionChecker2.cannot.discard()) {
2035
2265
  return ctx.forbidden();
2036
2266
  }
2037
2267
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2038
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2268
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2039
2269
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2040
2270
  const document = await documentManager2.findOne(id, model, {
2041
2271
  populate,
@@ -2060,13 +2290,13 @@ const collectionTypes = {
2060
2290
  const { query, body } = ctx.request;
2061
2291
  const { documentIds } = body;
2062
2292
  await validateBulkActionInput(body);
2063
- const documentManager2 = getService$1("document-manager");
2064
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2293
+ const documentManager2 = getService$2("document-manager");
2294
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2065
2295
  if (permissionChecker2.cannot.delete()) {
2066
2296
  return ctx.forbidden();
2067
2297
  }
2068
2298
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2069
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2299
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2070
2300
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2071
2301
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2072
2302
  populate,
@@ -2087,13 +2317,13 @@ const collectionTypes = {
2087
2317
  async countDraftRelations(ctx) {
2088
2318
  const { userAbility } = ctx.state;
2089
2319
  const { model, id } = ctx.params;
2090
- const documentManager2 = getService$1("document-manager");
2091
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2320
+ const documentManager2 = getService$2("document-manager");
2321
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2092
2322
  if (permissionChecker2.cannot.read()) {
2093
2323
  return ctx.forbidden();
2094
2324
  }
2095
2325
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2096
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2326
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2097
2327
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2098
2328
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2099
2329
  if (!entity) {
@@ -2112,8 +2342,8 @@ const collectionTypes = {
2112
2342
  const ids = ctx.request.query.documentIds;
2113
2343
  const locale = ctx.request.query.locale;
2114
2344
  const { model } = ctx.params;
2115
- const documentManager2 = getService$1("document-manager");
2116
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2345
+ const documentManager2 = getService$2("document-manager");
2346
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2117
2347
  if (permissionChecker2.cannot.read()) {
2118
2348
  return ctx.forbidden();
2119
2349
  }
@@ -2137,13 +2367,13 @@ const collectionTypes = {
2137
2367
  };
2138
2368
  const components$1 = {
2139
2369
  findComponents(ctx) {
2140
- const components2 = getService$1("components").findAllComponents();
2141
- const { toDto } = getService$1("data-mapper");
2370
+ const components2 = getService$2("components").findAllComponents();
2371
+ const { toDto } = getService$2("data-mapper");
2142
2372
  ctx.body = { data: components2.map(toDto) };
2143
2373
  },
2144
2374
  async findComponentConfiguration(ctx) {
2145
2375
  const { uid: uid2 } = ctx.params;
2146
- const componentService = getService$1("components");
2376
+ const componentService = getService$2("components");
2147
2377
  const component = componentService.findComponent(uid2);
2148
2378
  if (!component) {
2149
2379
  return ctx.notFound("component.notFound");
@@ -2160,7 +2390,7 @@ const components$1 = {
2160
2390
  async updateComponentConfiguration(ctx) {
2161
2391
  const { uid: uid2 } = ctx.params;
2162
2392
  const { body } = ctx.request;
2163
- const componentService = getService$1("components");
2393
+ const componentService = getService$2("components");
2164
2394
  const component = componentService.findComponent(uid2);
2165
2395
  if (!component) {
2166
2396
  return ctx.notFound("component.notFound");
@@ -2194,12 +2424,12 @@ const contentTypes = {
2194
2424
  } catch (error) {
2195
2425
  return ctx.send({ error }, 400);
2196
2426
  }
2197
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2198
- const { toDto } = getService$1("data-mapper");
2427
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2428
+ const { toDto } = getService$2("data-mapper");
2199
2429
  ctx.body = { data: contentTypes2.map(toDto) };
2200
2430
  },
2201
2431
  async findContentTypesSettings(ctx) {
2202
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2432
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2203
2433
  const contentTypes2 = await findAllContentTypes();
2204
2434
  const configurations = await Promise.all(
2205
2435
  contentTypes2.map(async (contentType) => {
@@ -2213,7 +2443,7 @@ const contentTypes = {
2213
2443
  },
2214
2444
  async findContentTypeConfiguration(ctx) {
2215
2445
  const { uid: uid2 } = ctx.params;
2216
- const contentTypeService = getService$1("content-types");
2446
+ const contentTypeService = getService$2("content-types");
2217
2447
  const contentType = await contentTypeService.findContentType(uid2);
2218
2448
  if (!contentType) {
2219
2449
  return ctx.notFound("contentType.notFound");
@@ -2235,13 +2465,13 @@ const contentTypes = {
2235
2465
  const { userAbility } = ctx.state;
2236
2466
  const { uid: uid2 } = ctx.params;
2237
2467
  const { body } = ctx.request;
2238
- const contentTypeService = getService$1("content-types");
2239
- const metricsService = getService$1("metrics");
2468
+ const contentTypeService = getService$2("content-types");
2469
+ const metricsService = getService$2("metrics");
2240
2470
  const contentType = await contentTypeService.findContentType(uid2);
2241
2471
  if (!contentType) {
2242
2472
  return ctx.notFound("contentType.notFound");
2243
2473
  }
2244
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2474
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2245
2475
  return ctx.forbidden();
2246
2476
  }
2247
2477
  let input;
@@ -2274,10 +2504,10 @@ const contentTypes = {
2274
2504
  };
2275
2505
  const init = {
2276
2506
  getInitData(ctx) {
2277
- const { toDto } = getService$1("data-mapper");
2278
- const { findAllComponents } = getService$1("components");
2279
- const { getAllFieldSizes } = getService$1("field-sizes");
2280
- const { findAllContentTypes } = getService$1("content-types");
2507
+ const { toDto } = getService$2("data-mapper");
2508
+ const { findAllComponents } = getService$2("components");
2509
+ const { getAllFieldSizes } = getService$2("field-sizes");
2510
+ const { findAllContentTypes } = getService$2("content-types");
2281
2511
  ctx.body = {
2282
2512
  data: {
2283
2513
  fieldSizes: getAllFieldSizes(),
@@ -2313,7 +2543,7 @@ const addFiltersClause = (params, filtersClause) => {
2313
2543
  params.filters.$and.push(filtersClause);
2314
2544
  };
2315
2545
  const sanitizeMainField = (model, mainField, userAbility) => {
2316
- const permissionChecker2 = getService$1("permission-checker").create({
2546
+ const permissionChecker2 = getService$2("permission-checker").create({
2317
2547
  userAbility,
2318
2548
  model: model.uid
2319
2549
  });
@@ -2327,15 +2557,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2327
2557
  }
2328
2558
  return mainField;
2329
2559
  };
2330
- const addStatusToRelations = async (uid2, relations2) => {
2331
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2560
+ const addStatusToRelations = async (targetUid, relations2) => {
2561
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2562
+ return relations2;
2563
+ }
2564
+ const documentMetadata2 = getService$2("document-metadata");
2565
+ if (!relations2.length) {
2332
2566
  return relations2;
2333
2567
  }
2334
- const documentMetadata2 = getService$1("document-metadata");
2335
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2568
+ const firstRelation = relations2[0];
2569
+ const filters = {
2570
+ documentId: { $in: relations2.map((r) => r.documentId) },
2571
+ // NOTE: find the "opposite" status
2572
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2573
+ };
2574
+ const availableStatus = await strapi.query(targetUid).findMany({
2575
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2576
+ filters
2577
+ });
2336
2578
  return relations2.map((relation) => {
2337
- const availableStatuses = documentsAvailableStatus.filter(
2338
- (availableDocument) => availableDocument.documentId === relation.documentId
2579
+ const availableStatuses = availableStatus.filter(
2580
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2339
2581
  );
2340
2582
  return {
2341
2583
  ...relation,
@@ -2356,11 +2598,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2356
2598
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2357
2599
  const isSourceLocalized = isLocalized(sourceModel);
2358
2600
  const isTargetLocalized = isLocalized(targetModel);
2359
- let validatedLocale = locale;
2360
- if (!targetModel || !isTargetLocalized)
2361
- validatedLocale = void 0;
2362
2601
  return {
2363
- locale: validatedLocale,
2602
+ locale,
2364
2603
  isSourceLocalized,
2365
2604
  isTargetLocalized
2366
2605
  };
@@ -2400,7 +2639,7 @@ const relations = {
2400
2639
  ctx.request?.query?.locale
2401
2640
  );
2402
2641
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2403
- const permissionChecker2 = getService$1("permission-checker").create({
2642
+ const permissionChecker2 = getService$2("permission-checker").create({
2404
2643
  userAbility,
2405
2644
  model
2406
2645
  });
@@ -2425,7 +2664,7 @@ const relations = {
2425
2664
  where.id = id;
2426
2665
  }
2427
2666
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2428
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2667
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2429
2668
  const currentEntity = await strapi.db.query(model).findOne({
2430
2669
  where,
2431
2670
  populate
@@ -2440,7 +2679,7 @@ const relations = {
2440
2679
  }
2441
2680
  entryId = currentEntity.id;
2442
2681
  }
2443
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2682
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2444
2683
  const targetSchema = strapi.getModel(targetUid);
2445
2684
  const mainField = flow(
2446
2685
  prop(`metadatas.${targetField}.edit.mainField`),
@@ -2463,7 +2702,7 @@ const relations = {
2463
2702
  attribute,
2464
2703
  fieldsToSelect,
2465
2704
  mainField,
2466
- source: { schema: sourceSchema },
2705
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2467
2706
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2468
2707
  sourceSchema,
2469
2708
  targetSchema,
@@ -2485,7 +2724,8 @@ const relations = {
2485
2724
  fieldsToSelect,
2486
2725
  mainField,
2487
2726
  source: {
2488
- schema: { uid: sourceUid, modelType: sourceModelType }
2727
+ schema: { uid: sourceUid, modelType: sourceModelType },
2728
+ isLocalized: isSourceLocalized
2489
2729
  },
2490
2730
  target: {
2491
2731
  schema: { uid: targetUid },
@@ -2493,7 +2733,7 @@ const relations = {
2493
2733
  }
2494
2734
  } = await this.extractAndValidateRequestInfo(ctx, id);
2495
2735
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2496
- const permissionChecker2 = getService$1("permission-checker").create({
2736
+ const permissionChecker2 = getService$2("permission-checker").create({
2497
2737
  userAbility: ctx.state.userAbility,
2498
2738
  model: targetUid
2499
2739
  });
@@ -2523,12 +2763,16 @@ const relations = {
2523
2763
  } else {
2524
2764
  where.id = id;
2525
2765
  }
2526
- if (status) {
2527
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2766
+ const publishedAt = getPublishedAtClause(status, targetUid);
2767
+ if (!isEmpty(publishedAt)) {
2768
+ where[`${alias}.published_at`] = publishedAt;
2528
2769
  }
2529
- if (filterByLocale) {
2770
+ if (isTargetLocalized && locale) {
2530
2771
  where[`${alias}.locale`] = locale;
2531
2772
  }
2773
+ if (isSourceLocalized && locale) {
2774
+ where.locale = locale;
2775
+ }
2532
2776
  if ((idsToInclude?.length ?? 0) !== 0) {
2533
2777
  where[`${alias}.id`].$notIn = idsToInclude;
2534
2778
  }
@@ -2546,7 +2790,8 @@ const relations = {
2546
2790
  id: { $notIn: uniq(idsToOmit) }
2547
2791
  });
2548
2792
  }
2549
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2793
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2794
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2550
2795
  ctx.body = {
2551
2796
  ...res,
2552
2797
  results: await addStatusToRelations(targetUid, res.results)
@@ -2561,21 +2806,33 @@ const relations = {
2561
2806
  attribute,
2562
2807
  targetField,
2563
2808
  fieldsToSelect,
2564
- source: {
2565
- schema: { uid: sourceUid }
2566
- },
2567
- target: {
2568
- schema: { uid: targetUid }
2569
- }
2809
+ status,
2810
+ source: { schema: sourceSchema },
2811
+ target: { schema: targetSchema }
2570
2812
  } = await this.extractAndValidateRequestInfo(ctx, id);
2571
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2813
+ const { uid: sourceUid } = sourceSchema;
2814
+ const { uid: targetUid } = targetSchema;
2815
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2572
2816
  const dbQuery = strapi.db.query(sourceUid);
2573
2817
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2818
+ const filters = {};
2819
+ if (sourceSchema?.options?.draftAndPublish) {
2820
+ if (targetSchema?.options?.draftAndPublish) {
2821
+ if (status === "published") {
2822
+ filters.publishedAt = { $notNull: true };
2823
+ } else {
2824
+ filters.publishedAt = { $null: true };
2825
+ }
2826
+ }
2827
+ } else if (targetSchema?.options?.draftAndPublish) {
2828
+ filters.publishedAt = { $null: true };
2829
+ }
2574
2830
  const res = await loadRelations({ id: entryId }, targetField, {
2575
- select: ["id", "documentId", "locale", "publishedAt"],
2831
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2576
2832
  ordering: "desc",
2577
2833
  page: ctx.request.query.page,
2578
- pageSize: ctx.request.query.pageSize
2834
+ pageSize: ctx.request.query.pageSize,
2835
+ filters
2579
2836
  });
2580
2837
  const loadedIds = res.results.map((item) => item.id);
2581
2838
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2596,10 +2853,10 @@ const relations = {
2596
2853
  }
2597
2854
  };
2598
2855
  const buildPopulateFromQuery = async (query, model) => {
2599
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2856
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2600
2857
  };
2601
2858
  const findDocument = async (query, uid2, opts = {}) => {
2602
- const documentManager2 = getService$1("document-manager");
2859
+ const documentManager2 = getService$2("document-manager");
2603
2860
  const populate = await buildPopulateFromQuery(query, uid2);
2604
2861
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2605
2862
  };
@@ -2607,8 +2864,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2607
2864
  const { user, userAbility } = ctx.state;
2608
2865
  const { model } = ctx.params;
2609
2866
  const { body, query } = ctx.request;
2610
- const documentManager2 = getService$1("document-manager");
2611
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2867
+ const documentManager2 = getService$2("document-manager");
2868
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2612
2869
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2613
2870
  throw new errors.ForbiddenError();
2614
2871
  }
@@ -2649,7 +2906,7 @@ const singleTypes = {
2649
2906
  const { userAbility } = ctx.state;
2650
2907
  const { model } = ctx.params;
2651
2908
  const { query = {} } = ctx.request;
2652
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2909
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2653
2910
  if (permissionChecker2.cannot.read()) {
2654
2911
  return ctx.forbidden();
2655
2912
  }
@@ -2668,7 +2925,7 @@ const singleTypes = {
2668
2925
  permissionChecker2,
2669
2926
  model,
2670
2927
  // @ts-expect-error - fix types
2671
- { id: document.documentId, locale, publishedAt: null },
2928
+ { documentId: document.documentId, locale, publishedAt: null },
2672
2929
  { availableLocales: true, availableStatus: false }
2673
2930
  );
2674
2931
  ctx.body = { data: {}, meta };
@@ -2683,7 +2940,7 @@ const singleTypes = {
2683
2940
  async createOrUpdate(ctx) {
2684
2941
  const { userAbility } = ctx.state;
2685
2942
  const { model } = ctx.params;
2686
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2943
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2687
2944
  const document = await createOrUpdateDocument(ctx);
2688
2945
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2689
2946
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2692,8 +2949,8 @@ const singleTypes = {
2692
2949
  const { userAbility } = ctx.state;
2693
2950
  const { model } = ctx.params;
2694
2951
  const { query = {} } = ctx.request;
2695
- const documentManager2 = getService$1("document-manager");
2696
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2952
+ const documentManager2 = getService$2("document-manager");
2953
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2697
2954
  if (permissionChecker2.cannot.delete()) {
2698
2955
  return ctx.forbidden();
2699
2956
  }
@@ -2721,8 +2978,8 @@ const singleTypes = {
2721
2978
  const { userAbility } = ctx.state;
2722
2979
  const { model } = ctx.params;
2723
2980
  const { query = {} } = ctx.request;
2724
- const documentManager2 = getService$1("document-manager");
2725
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2981
+ const documentManager2 = getService$2("document-manager");
2982
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2726
2983
  if (permissionChecker2.cannot.publish()) {
2727
2984
  return ctx.forbidden();
2728
2985
  }
@@ -2750,8 +3007,8 @@ const singleTypes = {
2750
3007
  body: { discardDraft, ...body },
2751
3008
  query = {}
2752
3009
  } = ctx.request;
2753
- const documentManager2 = getService$1("document-manager");
2754
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3010
+ const documentManager2 = getService$2("document-manager");
3011
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2755
3012
  if (permissionChecker2.cannot.unpublish()) {
2756
3013
  return ctx.forbidden();
2757
3014
  }
@@ -2785,8 +3042,8 @@ const singleTypes = {
2785
3042
  const { userAbility } = ctx.state;
2786
3043
  const { model } = ctx.params;
2787
3044
  const { body, query = {} } = ctx.request;
2788
- const documentManager2 = getService$1("document-manager");
2789
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3045
+ const documentManager2 = getService$2("document-manager");
3046
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2790
3047
  if (permissionChecker2.cannot.discard()) {
2791
3048
  return ctx.forbidden();
2792
3049
  }
@@ -2809,8 +3066,8 @@ const singleTypes = {
2809
3066
  const { userAbility } = ctx.state;
2810
3067
  const { model } = ctx.params;
2811
3068
  const { query } = ctx.request;
2812
- const documentManager2 = getService$1("document-manager");
2813
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3069
+ const documentManager2 = getService$2("document-manager");
3070
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2814
3071
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2815
3072
  if (permissionChecker2.cannot.read()) {
2816
3073
  return ctx.forbidden();
@@ -2834,7 +3091,7 @@ const uid$1 = {
2834
3091
  const { query = {} } = ctx.request;
2835
3092
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2836
3093
  await validateUIDField(contentTypeUID, field);
2837
- const uidService = getService$1("uid");
3094
+ const uidService = getService$2("uid");
2838
3095
  ctx.body = {
2839
3096
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2840
3097
  };
@@ -2846,7 +3103,7 @@ const uid$1 = {
2846
3103
  const { query = {} } = ctx.request;
2847
3104
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2848
3105
  await validateUIDField(contentTypeUID, field);
2849
- const uidService = getService$1("uid");
3106
+ const uidService = getService$2("uid");
2850
3107
  const isAvailable = await uidService.checkUIDAvailability({
2851
3108
  contentTypeUID,
2852
3109
  field,
@@ -2867,7 +3124,8 @@ const controllers = {
2867
3124
  relations,
2868
3125
  "single-types": singleTypes,
2869
3126
  uid: uid$1,
2870
- ...history.controllers ? history.controllers : {}
3127
+ ...history.controllers ? history.controllers : {},
3128
+ ...preview.controllers ? preview.controllers : {}
2871
3129
  };
2872
3130
  const keys = {
2873
3131
  CONFIGURATION: "configuration"
@@ -3018,12 +3276,12 @@ async function syncMetadatas(configuration, schema) {
3018
3276
  return _.assign(metasWithDefaults, updatedMetas);
3019
3277
  }
3020
3278
  const getTargetSchema = (targetModel) => {
3021
- return getService$1("content-types").findContentType(targetModel);
3279
+ return getService$2("content-types").findContentType(targetModel);
3022
3280
  };
3023
3281
  const DEFAULT_LIST_LENGTH = 4;
3024
3282
  const MAX_ROW_SIZE = 12;
3025
3283
  const isAllowedFieldSize = (type, size) => {
3026
- const { getFieldSize } = getService$1("field-sizes");
3284
+ const { getFieldSize } = getService$2("field-sizes");
3027
3285
  const fieldSize = getFieldSize(type);
3028
3286
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3029
3287
  return false;
@@ -3031,7 +3289,7 @@ const isAllowedFieldSize = (type, size) => {
3031
3289
  return size <= MAX_ROW_SIZE;
3032
3290
  };
3033
3291
  const getDefaultFieldSize = (attribute) => {
3034
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3292
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3035
3293
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3036
3294
  };
3037
3295
  async function createDefaultLayouts(schema) {
@@ -3066,7 +3324,7 @@ function syncLayouts(configuration, schema) {
3066
3324
  for (const el of row) {
3067
3325
  if (!hasEditableAttribute(schema, el.name))
3068
3326
  continue;
3069
- const { hasFieldSize } = getService$1("field-sizes");
3327
+ const { hasFieldSize } = getService$2("field-sizes");
3070
3328
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3071
3329
  if (!isAllowedFieldSize(fieldType, el.size)) {
3072
3330
  elementsToReAppend.push(el.name);
@@ -3206,17 +3464,17 @@ const configurationService$1 = createConfigurationService({
3206
3464
  isComponent: true,
3207
3465
  prefix: STORE_KEY_PREFIX,
3208
3466
  getModels() {
3209
- const { toContentManagerModel } = getService$1("data-mapper");
3467
+ const { toContentManagerModel } = getService$2("data-mapper");
3210
3468
  return mapValues(toContentManagerModel, strapi.components);
3211
3469
  }
3212
3470
  });
3213
3471
  const components = ({ strapi: strapi2 }) => ({
3214
3472
  findAllComponents() {
3215
- const { toContentManagerModel } = getService$1("data-mapper");
3473
+ const { toContentManagerModel } = getService$2("data-mapper");
3216
3474
  return Object.values(strapi2.components).map(toContentManagerModel);
3217
3475
  },
3218
3476
  findComponent(uid2) {
3219
- const { toContentManagerModel } = getService$1("data-mapper");
3477
+ const { toContentManagerModel } = getService$2("data-mapper");
3220
3478
  const component = strapi2.components[uid2];
3221
3479
  return isNil$1(component) ? component : toContentManagerModel(component);
3222
3480
  },
@@ -3267,17 +3525,17 @@ const configurationService = createConfigurationService({
3267
3525
  storeUtils,
3268
3526
  prefix: "content_types",
3269
3527
  getModels() {
3270
- const { toContentManagerModel } = getService$1("data-mapper");
3528
+ const { toContentManagerModel } = getService$2("data-mapper");
3271
3529
  return mapValues(toContentManagerModel, strapi.contentTypes);
3272
3530
  }
3273
3531
  });
3274
3532
  const service = ({ strapi: strapi2 }) => ({
3275
3533
  findAllContentTypes() {
3276
- const { toContentManagerModel } = getService$1("data-mapper");
3534
+ const { toContentManagerModel } = getService$2("data-mapper");
3277
3535
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3278
3536
  },
3279
3537
  findContentType(uid2) {
3280
- const { toContentManagerModel } = getService$1("data-mapper");
3538
+ const { toContentManagerModel } = getService$2("data-mapper");
3281
3539
  const contentType = strapi2.contentTypes[uid2];
3282
3540
  return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
3283
3541
  },
@@ -3306,7 +3564,7 @@ const service = ({ strapi: strapi2 }) => ({
3306
3564
  return this.findConfiguration(contentType);
3307
3565
  },
3308
3566
  findComponentsConfigurations(contentType) {
3309
- return getService$1("components").findComponentsConfigurations(contentType);
3567
+ return getService$2("components").findComponentsConfigurations(contentType);
3310
3568
  },
3311
3569
  syncConfigurations() {
3312
3570
  return configurationService.syncConfigurations();
@@ -3578,7 +3836,7 @@ const permission = ({ strapi: strapi2 }) => ({
3578
3836
  return userAbility.can(action);
3579
3837
  },
3580
3838
  async registerPermissions() {
3581
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3839
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3582
3840
  const contentTypesUids = displayedContentTypes.map(prop("uid"));
3583
3841
  const actions = [
3584
3842
  {
@@ -3854,7 +4112,7 @@ const getQueryPopulate = async (uid2, query) => {
3854
4112
  return populateQuery;
3855
4113
  };
3856
4114
  const buildDeepPopulate = (uid2) => {
3857
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4115
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3858
4116
  };
3859
4117
  const populateBuilder = (uid2) => {
3860
4118
  let getInitialPopulate = async () => {
@@ -4039,7 +4297,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4039
4297
  */
4040
4298
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4041
4299
  const versionsByLocale = groupBy("locale", allVersions);
4042
- delete versionsByLocale[version.locale];
4300
+ if (version.locale) {
4301
+ delete versionsByLocale[version.locale];
4302
+ }
4043
4303
  const model = strapi2.getModel(uid2);
4044
4304
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4045
4305
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4395,7 +4655,8 @@ const services = {
4395
4655
  permission,
4396
4656
  "populate-builder": populateBuilder$1,
4397
4657
  uid,
4398
- ...history.services ? history.services : {}
4658
+ ...history.services ? history.services : {},
4659
+ ...preview.services ? preview.services : {}
4399
4660
  };
4400
4661
  const index = () => {
4401
4662
  return {