@strapi/content-manager 0.0.0-experimental.da85533897155e719d784f0271223c866d2f69ab → 0.0.0-experimental.dd1d47ef78ef6cfec4ed62576108500bd9f13740

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 (168) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs → ComponentConfigurationPage-BpM_Hc7r.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs.map → ComponentConfigurationPage-BpM_Hc7r.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js → ComponentConfigurationPage-CL9CAMaL.js} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js.map → ComponentConfigurationPage-CL9CAMaL.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-DValmA0m.js → EditConfigurationPage-ILWo0h1e.js} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-DValmA0m.js.map → EditConfigurationPage-ILWo0h1e.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs → EditConfigurationPage-_prbqpTM.mjs} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs.map → EditConfigurationPage-_prbqpTM.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-Dk7Eaft4.js → EditViewPage-BqZvBN4s.js} +15 -5
  10. package/dist/_chunks/EditViewPage-BqZvBN4s.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-DiNFdFqP.mjs → EditViewPage-DAtscabN.mjs} +15 -5
  12. package/dist/_chunks/EditViewPage-DAtscabN.mjs.map +1 -0
  13. package/dist/_chunks/{Field-DH2OaqUP.js → Field-CcoQiiz1.js} +78 -44
  14. package/dist/_chunks/Field-CcoQiiz1.js.map +1 -0
  15. package/dist/_chunks/{Field-Dv_HTFTa.mjs → Field-D-mgn1tH.mjs} +74 -40
  16. package/dist/_chunks/Field-D-mgn1tH.mjs.map +1 -0
  17. package/dist/_chunks/{Form-Dy6P4HgH.mjs → Form-BxyeWiXW.mjs} +16 -8
  18. package/dist/_chunks/Form-BxyeWiXW.mjs.map +1 -0
  19. package/dist/_chunks/{Form-B_dUDizM.js → Form-CmLbZDfi.js} +16 -8
  20. package/dist/_chunks/Form-CmLbZDfi.js.map +1 -0
  21. package/dist/_chunks/{History-DrwsD1Vc.mjs → History-BOhLaq_g.mjs} +38 -41
  22. package/dist/_chunks/History-BOhLaq_g.mjs.map +1 -0
  23. package/dist/_chunks/{History-BT4w83Oa.js → History-uECUbCZB.js} +37 -40
  24. package/dist/_chunks/History-uECUbCZB.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs → ListConfigurationPage-D0vQez6F.mjs} +3 -3
  26. package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs.map → ListConfigurationPage-D0vQez6F.mjs.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js → ListConfigurationPage-D_bBSFNW.js} +3 -3
  28. package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js.map → ListConfigurationPage-D_bBSFNW.js.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-BvpwNur7.js → ListViewPage-BkZ83b1A.js} +40 -17
  30. package/dist/_chunks/ListViewPage-BkZ83b1A.js.map +1 -0
  31. package/dist/_chunks/{ListViewPage-5a1vw-OK.mjs → ListViewPage-ns-bmy5C.mjs} +36 -13
  32. package/dist/_chunks/ListViewPage-ns-bmy5C.mjs.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs → NoContentTypePage-BA5ZKMDR.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs.map → NoContentTypePage-BA5ZKMDR.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js → NoContentTypePage-C1439s4s.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js.map → NoContentTypePage-C1439s4s.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs → NoPermissionsPage-B0GdMw1Q.mjs} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs.map → NoPermissionsPage-B0GdMw1Q.mjs.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js → NoPermissionsPage-CPGwsVfb.js} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js.map → NoPermissionsPage-CPGwsVfb.js.map} +1 -1
  41. package/dist/_chunks/{Relations-C7fPyh5P.mjs → Relations-BIGPMSW4.mjs} +72 -36
  42. package/dist/_chunks/Relations-BIGPMSW4.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-CznVF6LS.js → Relations-d-8Uef_-.js} +71 -35
  44. package/dist/_chunks/Relations-d-8Uef_-.js.map +1 -0
  45. package/dist/_chunks/{en-otD_UBJi.js → en-Bdpa50w3.js} +17 -12
  46. package/dist/_chunks/{en-otD_UBJi.js.map → en-Bdpa50w3.js.map} +1 -1
  47. package/dist/_chunks/{en-CbaIuYoB.mjs → en-CZw4xdPY.mjs} +17 -12
  48. package/dist/_chunks/{en-CbaIuYoB.mjs.map → en-CZw4xdPY.mjs.map} +1 -1
  49. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  50. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  51. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  52. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  53. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  54. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  55. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  56. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  57. package/dist/_chunks/{index-BJ6uTqLL.mjs → index-3_WeHXYp.mjs} +890 -685
  58. package/dist/_chunks/index-3_WeHXYp.mjs.map +1 -0
  59. package/dist/_chunks/{index-D9UmmBcM.js → index-BgaeYWIy.js} +887 -681
  60. package/dist/_chunks/index-BgaeYWIy.js.map +1 -0
  61. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  62. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  63. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  64. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  65. package/dist/_chunks/{layout-kfu5Wtix.js → layout-ByFyQRDH.js} +5 -4
  66. package/dist/_chunks/{layout-kfu5Wtix.js.map → layout-ByFyQRDH.js.map} +1 -1
  67. package/dist/_chunks/{layout-uomiIGbG.mjs → layout-CrTxOnCy.mjs} +5 -4
  68. package/dist/_chunks/{layout-uomiIGbG.mjs.map → layout-CrTxOnCy.mjs.map} +1 -1
  69. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  70. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  71. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  72. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  73. package/dist/_chunks/{relations-DiDufGSA.mjs → relations-BlpLgngh.mjs} +3 -7
  74. package/dist/_chunks/relations-BlpLgngh.mjs.map +1 -0
  75. package/dist/_chunks/{relations-DKENrxko.js → relations-C5RSW926.js} +3 -7
  76. package/dist/_chunks/relations-C5RSW926.js.map +1 -0
  77. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  78. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  79. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  80. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.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 +3 -2
  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/components/Header.d.ts +11 -11
  87. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  88. package/dist/admin/src/preview/constants.d.ts +1 -0
  89. package/dist/admin/src/preview/index.d.ts +4 -0
  90. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  91. package/dist/admin/src/services/documents.d.ts +3 -1
  92. package/dist/server/index.js +378 -162
  93. package/dist/server/index.js.map +1 -1
  94. package/dist/server/index.mjs +378 -162
  95. package/dist/server/index.mjs.map +1 -1
  96. package/dist/server/src/bootstrap.d.ts.map +1 -1
  97. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  98. package/dist/server/src/controllers/index.d.ts.map +1 -1
  99. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  100. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  101. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  102. package/dist/server/src/history/services/history.d.ts.map +1 -1
  103. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  104. package/dist/server/src/history/services/utils.d.ts +2 -3
  105. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  106. package/dist/server/src/index.d.ts +4 -4
  107. package/dist/server/src/preview/constants.d.ts +2 -0
  108. package/dist/server/src/preview/constants.d.ts.map +1 -0
  109. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  110. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  111. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  112. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  113. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  114. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  115. package/dist/server/src/preview/index.d.ts +4 -0
  116. package/dist/server/src/preview/index.d.ts.map +1 -0
  117. package/dist/server/src/preview/routes/index.d.ts +8 -0
  118. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  119. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  120. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  121. package/dist/server/src/preview/services/index.d.ts +15 -0
  122. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  123. package/dist/server/src/preview/services/preview-config.d.ts +30 -0
  124. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  125. package/dist/server/src/preview/services/preview.d.ts +12 -0
  126. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  127. package/dist/server/src/preview/utils.d.ts +18 -0
  128. package/dist/server/src/preview/utils.d.ts.map +1 -0
  129. package/dist/server/src/routes/index.d.ts.map +1 -1
  130. package/dist/server/src/services/document-metadata.d.ts +8 -8
  131. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  132. package/dist/server/src/services/index.d.ts +4 -4
  133. package/dist/server/src/services/index.d.ts.map +1 -1
  134. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  135. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  136. package/dist/server/src/utils/index.d.ts +2 -0
  137. package/dist/server/src/utils/index.d.ts.map +1 -1
  138. package/dist/shared/contracts/collection-types.d.ts +3 -1
  139. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  140. package/dist/shared/contracts/index.d.ts +1 -0
  141. package/dist/shared/contracts/index.d.ts.map +1 -1
  142. package/dist/shared/contracts/preview.d.ts +27 -0
  143. package/dist/shared/contracts/preview.d.ts.map +1 -0
  144. package/dist/shared/index.js +4 -0
  145. package/dist/shared/index.js.map +1 -1
  146. package/dist/shared/index.mjs +4 -0
  147. package/dist/shared/index.mjs.map +1 -1
  148. package/package.json +13 -13
  149. package/dist/_chunks/EditViewPage-DiNFdFqP.mjs.map +0 -1
  150. package/dist/_chunks/EditViewPage-Dk7Eaft4.js.map +0 -1
  151. package/dist/_chunks/Field-DH2OaqUP.js.map +0 -1
  152. package/dist/_chunks/Field-Dv_HTFTa.mjs.map +0 -1
  153. package/dist/_chunks/Form-B_dUDizM.js.map +0 -1
  154. package/dist/_chunks/Form-Dy6P4HgH.mjs.map +0 -1
  155. package/dist/_chunks/History-BT4w83Oa.js.map +0 -1
  156. package/dist/_chunks/History-DrwsD1Vc.mjs.map +0 -1
  157. package/dist/_chunks/ListViewPage-5a1vw-OK.mjs.map +0 -1
  158. package/dist/_chunks/ListViewPage-BvpwNur7.js.map +0 -1
  159. package/dist/_chunks/Relations-C7fPyh5P.mjs.map +0 -1
  160. package/dist/_chunks/Relations-CznVF6LS.js.map +0 -1
  161. package/dist/_chunks/index-BJ6uTqLL.mjs.map +0 -1
  162. package/dist/_chunks/index-D9UmmBcM.js.map +0 -1
  163. package/dist/_chunks/relations-DKENrxko.js.map +0 -1
  164. package/dist/_chunks/relations-DiDufGSA.mjs.map +0 -1
  165. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  166. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  167. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  168. 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,7 +739,7 @@ const getFeature = () => {
713
739
  }
714
740
  };
715
741
  };
716
- const history = getFeature();
742
+ const history = getFeature$1();
717
743
  const register = async ({ strapi: strapi2 }) => {
718
744
  await history.register?.({ strapi: strapi2 });
719
745
  };
@@ -721,15 +747,165 @@ const ALLOWED_WEBHOOK_EVENTS = {
721
747
  ENTRY_PUBLISH: "entry.publish",
722
748
  ENTRY_UNPUBLISH: "entry.unpublish"
723
749
  };
750
+ const FEATURE_ID = "preview";
751
+ const info = { pluginName: "content-manager", type: "admin" };
752
+ const previewRouter = {
753
+ type: "admin",
754
+ routes: [
755
+ {
756
+ method: "GET",
757
+ info,
758
+ path: "/preview/url/:contentType",
759
+ handler: "preview.getPreviewUrl",
760
+ config: {
761
+ policies: ["admin::isAuthenticatedAdmin"]
762
+ }
763
+ }
764
+ ]
765
+ };
766
+ const routes$1 = {
767
+ preview: previewRouter
768
+ };
769
+ function getService(strapi2, name) {
770
+ return strapi2.service(`plugin::content-manager.${name}`);
771
+ }
772
+ const getPreviewUrlSchema = yup__namespace.object().shape({
773
+ // Will be undefined for single types
774
+ documentId: yup__namespace.string(),
775
+ locale: yup__namespace.string().nullable(),
776
+ status: yup__namespace.string()
777
+ }).required();
778
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
779
+ await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
780
+ const newParams = fp.pick(["documentId", "locale", "status"], params);
781
+ const model = strapi2.getModel(uid2);
782
+ if (!model || model.modelType !== "contentType") {
783
+ throw new strapiUtils.errors.ValidationError("Invalid content type");
784
+ }
785
+ const isSingleType = model?.kind === "singleType";
786
+ if (!isSingleType && !params.documentId) {
787
+ throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
788
+ }
789
+ if (isSingleType) {
790
+ const doc = await strapi2.documents(uid2).findFirst();
791
+ if (!doc) {
792
+ throw new strapiUtils.errors.NotFoundError("Document not found");
793
+ }
794
+ newParams.documentId = doc?.documentId;
795
+ }
796
+ return newParams;
797
+ };
798
+ const createPreviewController = () => {
799
+ return {
800
+ /**
801
+ * Transforms an entry into a preview URL, so that it can be previewed
802
+ * in the Content Manager.
803
+ */
804
+ async getPreviewUrl(ctx) {
805
+ const uid2 = ctx.params.contentType;
806
+ const query = ctx.request.query;
807
+ const params = await validatePreviewUrl(strapi, uid2, query);
808
+ const previewService = getService(strapi, "preview");
809
+ const url = await previewService.getPreviewUrl(uid2, params);
810
+ if (!url) {
811
+ ctx.status = 204;
812
+ }
813
+ return {
814
+ data: { url }
815
+ };
816
+ }
817
+ };
818
+ };
819
+ const controllers$1 = {
820
+ preview: createPreviewController
821
+ /**
822
+ * Casting is needed because the types aren't aware that Strapi supports
823
+ * passing a controller factory as the value, instead of a controller object directly
824
+ */
825
+ };
826
+ const createPreviewService = ({ strapi: strapi2 }) => {
827
+ const config = getService(strapi2, "preview-config");
828
+ return {
829
+ async getPreviewUrl(uid2, params) {
830
+ const handler = config.getPreviewHandler();
831
+ try {
832
+ return handler(uid2, params);
833
+ } catch (error) {
834
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
835
+ throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
836
+ }
837
+ return;
838
+ }
839
+ };
840
+ };
841
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
842
+ return {
843
+ isEnabled() {
844
+ const config = strapi2.config.get("admin.preview");
845
+ if (!config) {
846
+ return false;
847
+ }
848
+ return config?.enabled ?? true;
849
+ },
850
+ /**
851
+ * Validate if the configuration is valid
852
+ */
853
+ validate() {
854
+ if (!this.isEnabled()) {
855
+ return;
856
+ }
857
+ const handler = this.getPreviewHandler();
858
+ if (typeof handler !== "function") {
859
+ throw new strapiUtils.errors.ValidationError(
860
+ "Preview configuration is invalid. Handler must be a function"
861
+ );
862
+ }
863
+ },
864
+ /**
865
+ * Utility to get the preview handler from the configuration
866
+ */
867
+ getPreviewHandler() {
868
+ const config = strapi2.config.get("admin.preview");
869
+ const emptyHandler = () => {
870
+ return void 0;
871
+ };
872
+ if (!this.isEnabled()) {
873
+ return emptyHandler;
874
+ }
875
+ return config?.config?.handler || emptyHandler;
876
+ }
877
+ };
878
+ };
879
+ const services$1 = {
880
+ preview: createPreviewService,
881
+ "preview-config": createPreviewConfigService
882
+ };
883
+ const getFeature = () => {
884
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
885
+ return {};
886
+ }
887
+ return {
888
+ bootstrap() {
889
+ console.log("Bootstrapping preview server");
890
+ const config = getService(strapi, "preview-config");
891
+ config.validate();
892
+ },
893
+ routes: routes$1,
894
+ controllers: controllers$1,
895
+ services: services$1
896
+ };
897
+ };
898
+ const preview = getFeature();
724
899
  const bootstrap = async () => {
725
900
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
726
901
  strapi.get("webhookStore").addAllowedEvent(key, value);
727
902
  });
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();
903
+ getService$2("field-sizes").setCustomFieldInputSizes();
904
+ await getService$2("components").syncConfigurations();
905
+ await getService$2("content-types").syncConfigurations();
906
+ await getService$2("permission").registerPermissions();
732
907
  await history.bootstrap?.({ strapi });
908
+ await preview.bootstrap?.({ strapi });
733
909
  };
734
910
  const destroy = async ({ strapi: strapi2 }) => {
735
911
  await history.destroy?.({ strapi: strapi2 });
@@ -1219,7 +1395,8 @@ const admin = {
1219
1395
  };
1220
1396
  const routes = {
1221
1397
  admin,
1222
- ...history.routes ? history.routes : {}
1398
+ ...history.routes ? history.routes : {},
1399
+ ...preview.routes ? preview.routes : {}
1223
1400
  };
1224
1401
  const hasPermissionsSchema = strapiUtils.yup.object({
1225
1402
  actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
@@ -1476,7 +1653,7 @@ const createMetadasSchema = (schema) => {
1476
1653
  if (!value) {
1477
1654
  return strapiUtils.yup.string();
1478
1655
  }
1479
- const targetSchema = getService$1("content-types").findContentType(
1656
+ const targetSchema = getService$2("content-types").findContentType(
1480
1657
  schema.attributes[key].targetModel
1481
1658
  );
1482
1659
  if (!targetSchema) {
@@ -1645,7 +1822,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1645
1822
  }
1646
1823
  };
1647
1824
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1648
- const documentMetadata2 = getService$1("document-metadata");
1825
+ const documentMetadata2 = getService$2("document-metadata");
1649
1826
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1650
1827
  let {
1651
1828
  meta: { availableLocales, availableStatus }
@@ -1671,8 +1848,8 @@ const createDocument = async (ctx, opts) => {
1671
1848
  const { userAbility, user } = ctx.state;
1672
1849
  const { model } = ctx.params;
1673
1850
  const { body } = ctx.request;
1674
- const documentManager2 = getService$1("document-manager");
1675
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1851
+ const documentManager2 = getService$2("document-manager");
1852
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1676
1853
  if (permissionChecker2.cannot.create()) {
1677
1854
  throw new strapiUtils.errors.ForbiddenError();
1678
1855
  }
@@ -1692,13 +1869,13 @@ const updateDocument = async (ctx, opts) => {
1692
1869
  const { userAbility, user } = ctx.state;
1693
1870
  const { id, model } = ctx.params;
1694
1871
  const { body } = ctx.request;
1695
- const documentManager2 = getService$1("document-manager");
1696
- 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 });
1697
1874
  if (permissionChecker2.cannot.update()) {
1698
1875
  throw new strapiUtils.errors.ForbiddenError();
1699
1876
  }
1700
1877
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1701
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1878
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1702
1879
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1703
1880
  const [documentVersion, documentExists] = await Promise.all([
1704
1881
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1715,7 +1892,7 @@ const updateDocument = async (ctx, opts) => {
1715
1892
  throw new strapiUtils.errors.ForbiddenError();
1716
1893
  }
1717
1894
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1718
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1895
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1719
1896
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1720
1897
  const sanitizedBody = await sanitizeFn(body);
1721
1898
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1729,14 +1906,14 @@ const collectionTypes = {
1729
1906
  const { userAbility } = ctx.state;
1730
1907
  const { model } = ctx.params;
1731
1908
  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 });
1909
+ const documentMetadata2 = getService$2("document-metadata");
1910
+ const documentManager2 = getService$2("document-manager");
1911
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1735
1912
  if (permissionChecker2.cannot.read()) {
1736
1913
  return ctx.forbidden();
1737
1914
  }
1738
1915
  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();
1916
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1740
1917
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1741
1918
  const { results: documents, pagination } = await documentManager2.findPage(
1742
1919
  { ...permissionQuery, populate, locale, status },
@@ -1765,13 +1942,13 @@ const collectionTypes = {
1765
1942
  async findOne(ctx) {
1766
1943
  const { userAbility } = ctx.state;
1767
1944
  const { model, id } = ctx.params;
1768
- const documentManager2 = getService$1("document-manager");
1769
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1945
+ const documentManager2 = getService$2("document-manager");
1946
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1770
1947
  if (permissionChecker2.cannot.read()) {
1771
1948
  return ctx.forbidden();
1772
1949
  }
1773
1950
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1774
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1951
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1775
1952
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1776
1953
  const version = await documentManager2.findOne(id, model, {
1777
1954
  populate,
@@ -1787,7 +1964,7 @@ const collectionTypes = {
1787
1964
  permissionChecker2,
1788
1965
  model,
1789
1966
  // @ts-expect-error TODO: fix
1790
- { id, locale, publishedAt: null },
1967
+ { documentId: id, locale, publishedAt: null },
1791
1968
  { availableLocales: true, availableStatus: false }
1792
1969
  );
1793
1970
  ctx.body = { data: {}, meta };
@@ -1802,7 +1979,7 @@ const collectionTypes = {
1802
1979
  async create(ctx) {
1803
1980
  const { userAbility } = ctx.state;
1804
1981
  const { model } = ctx.params;
1805
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1982
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1806
1983
  const [totalEntries, document] = await Promise.all([
1807
1984
  strapi.db.query(model).count(),
1808
1985
  createDocument(ctx)
@@ -1823,7 +2000,7 @@ const collectionTypes = {
1823
2000
  async update(ctx) {
1824
2001
  const { userAbility } = ctx.state;
1825
2002
  const { model } = ctx.params;
1826
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2003
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1827
2004
  const updatedVersion = await updateDocument(ctx);
1828
2005
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1829
2006
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1832,13 +2009,13 @@ const collectionTypes = {
1832
2009
  const { userAbility, user } = ctx.state;
1833
2010
  const { model, sourceId: id } = ctx.params;
1834
2011
  const { body } = ctx.request;
1835
- const documentManager2 = getService$1("document-manager");
1836
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2012
+ const documentManager2 = getService$2("document-manager");
2013
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1837
2014
  if (permissionChecker2.cannot.create()) {
1838
2015
  return ctx.forbidden();
1839
2016
  }
1840
2017
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1841
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2018
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1842
2019
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1843
2020
  const document = await documentManager2.findOne(id, model, {
1844
2021
  populate,
@@ -1877,13 +2054,13 @@ const collectionTypes = {
1877
2054
  async delete(ctx) {
1878
2055
  const { userAbility } = ctx.state;
1879
2056
  const { id, model } = ctx.params;
1880
- const documentManager2 = getService$1("document-manager");
1881
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2057
+ const documentManager2 = getService$2("document-manager");
2058
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1882
2059
  if (permissionChecker2.cannot.delete()) {
1883
2060
  return ctx.forbidden();
1884
2061
  }
1885
2062
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1886
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2063
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1887
2064
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1888
2065
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1889
2066
  if (documentLocales.length === 0) {
@@ -1905,14 +2082,14 @@ const collectionTypes = {
1905
2082
  const { userAbility } = ctx.state;
1906
2083
  const { id, model } = ctx.params;
1907
2084
  const { body } = ctx.request;
1908
- const documentManager2 = getService$1("document-manager");
1909
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2085
+ const documentManager2 = getService$2("document-manager");
2086
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1910
2087
  if (permissionChecker2.cannot.publish()) {
1911
2088
  return ctx.forbidden();
1912
2089
  }
1913
2090
  const publishedDocument = await strapi.db.transaction(async () => {
1914
2091
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1915
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2092
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1916
2093
  let document;
1917
2094
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1918
2095
  const isCreate = fp.isNil(id);
@@ -1924,11 +2101,17 @@ const collectionTypes = {
1924
2101
  }
1925
2102
  const isUpdate = !isCreate;
1926
2103
  if (isUpdate) {
1927
- document = await documentManager2.findOne(id, model, { populate, locale });
1928
- if (!document) {
2104
+ const documentExists = documentManager2.exists(model, id);
2105
+ if (!documentExists) {
1929
2106
  throw new strapiUtils.errors.NotFoundError("Document not found");
1930
2107
  }
1931
- if (permissionChecker2.can.update(document)) {
2108
+ document = await documentManager2.findOne(id, model, { populate, locale });
2109
+ if (!document) {
2110
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2111
+ throw new strapiUtils.errors.ForbiddenError();
2112
+ }
2113
+ document = await updateDocument(ctx);
2114
+ } else if (permissionChecker2.can.update(document)) {
1932
2115
  await updateDocument(ctx);
1933
2116
  }
1934
2117
  }
@@ -1954,13 +2137,13 @@ const collectionTypes = {
1954
2137
  const { body } = ctx.request;
1955
2138
  const { documentIds } = body;
1956
2139
  await validateBulkActionInput(body);
1957
- const documentManager2 = getService$1("document-manager");
1958
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2140
+ const documentManager2 = getService$2("document-manager");
2141
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1959
2142
  if (permissionChecker2.cannot.publish()) {
1960
2143
  return ctx.forbidden();
1961
2144
  }
1962
2145
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1963
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2146
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1964
2147
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1965
2148
  allowMultipleLocales: true
1966
2149
  });
@@ -1985,12 +2168,14 @@ const collectionTypes = {
1985
2168
  const { body } = ctx.request;
1986
2169
  const { documentIds } = body;
1987
2170
  await validateBulkActionInput(body);
1988
- const documentManager2 = getService$1("document-manager");
1989
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2171
+ const documentManager2 = getService$2("document-manager");
2172
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1990
2173
  if (permissionChecker2.cannot.unpublish()) {
1991
2174
  return ctx.forbidden();
1992
2175
  }
1993
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2176
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2177
+ allowMultipleLocales: true
2178
+ });
1994
2179
  const entityPromises = documentIds.map(
1995
2180
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1996
2181
  );
@@ -2013,8 +2198,8 @@ const collectionTypes = {
2013
2198
  const {
2014
2199
  body: { discardDraft, ...body }
2015
2200
  } = ctx.request;
2016
- const documentManager2 = getService$1("document-manager");
2017
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2201
+ const documentManager2 = getService$2("document-manager");
2202
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2018
2203
  if (permissionChecker2.cannot.unpublish()) {
2019
2204
  return ctx.forbidden();
2020
2205
  }
@@ -2022,7 +2207,7 @@ const collectionTypes = {
2022
2207
  return ctx.forbidden();
2023
2208
  }
2024
2209
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
2025
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2210
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2026
2211
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2027
2212
  const document = await documentManager2.findOne(id, model, {
2028
2213
  populate,
@@ -2053,13 +2238,13 @@ const collectionTypes = {
2053
2238
  const { userAbility } = ctx.state;
2054
2239
  const { id, model } = ctx.params;
2055
2240
  const { body } = ctx.request;
2056
- const documentManager2 = getService$1("document-manager");
2057
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2241
+ const documentManager2 = getService$2("document-manager");
2242
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2058
2243
  if (permissionChecker2.cannot.discard()) {
2059
2244
  return ctx.forbidden();
2060
2245
  }
2061
2246
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2062
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2247
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2063
2248
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2064
2249
  const document = await documentManager2.findOne(id, model, {
2065
2250
  populate,
@@ -2084,13 +2269,13 @@ const collectionTypes = {
2084
2269
  const { query, body } = ctx.request;
2085
2270
  const { documentIds } = body;
2086
2271
  await validateBulkActionInput(body);
2087
- const documentManager2 = getService$1("document-manager");
2088
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2272
+ const documentManager2 = getService$2("document-manager");
2273
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2089
2274
  if (permissionChecker2.cannot.delete()) {
2090
2275
  return ctx.forbidden();
2091
2276
  }
2092
2277
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2093
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2278
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2094
2279
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2095
2280
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2096
2281
  populate,
@@ -2111,13 +2296,13 @@ const collectionTypes = {
2111
2296
  async countDraftRelations(ctx) {
2112
2297
  const { userAbility } = ctx.state;
2113
2298
  const { model, id } = ctx.params;
2114
- const documentManager2 = getService$1("document-manager");
2115
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2299
+ const documentManager2 = getService$2("document-manager");
2300
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2116
2301
  if (permissionChecker2.cannot.read()) {
2117
2302
  return ctx.forbidden();
2118
2303
  }
2119
2304
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2120
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2305
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2121
2306
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2122
2307
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2123
2308
  if (!entity) {
@@ -2136,8 +2321,8 @@ const collectionTypes = {
2136
2321
  const ids = ctx.request.query.documentIds;
2137
2322
  const locale = ctx.request.query.locale;
2138
2323
  const { model } = ctx.params;
2139
- const documentManager2 = getService$1("document-manager");
2140
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2324
+ const documentManager2 = getService$2("document-manager");
2325
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2141
2326
  if (permissionChecker2.cannot.read()) {
2142
2327
  return ctx.forbidden();
2143
2328
  }
@@ -2161,13 +2346,13 @@ const collectionTypes = {
2161
2346
  };
2162
2347
  const components$1 = {
2163
2348
  findComponents(ctx) {
2164
- const components2 = getService$1("components").findAllComponents();
2165
- const { toDto } = getService$1("data-mapper");
2349
+ const components2 = getService$2("components").findAllComponents();
2350
+ const { toDto } = getService$2("data-mapper");
2166
2351
  ctx.body = { data: components2.map(toDto) };
2167
2352
  },
2168
2353
  async findComponentConfiguration(ctx) {
2169
2354
  const { uid: uid2 } = ctx.params;
2170
- const componentService = getService$1("components");
2355
+ const componentService = getService$2("components");
2171
2356
  const component = componentService.findComponent(uid2);
2172
2357
  if (!component) {
2173
2358
  return ctx.notFound("component.notFound");
@@ -2184,7 +2369,7 @@ const components$1 = {
2184
2369
  async updateComponentConfiguration(ctx) {
2185
2370
  const { uid: uid2 } = ctx.params;
2186
2371
  const { body } = ctx.request;
2187
- const componentService = getService$1("components");
2372
+ const componentService = getService$2("components");
2188
2373
  const component = componentService.findComponent(uid2);
2189
2374
  if (!component) {
2190
2375
  return ctx.notFound("component.notFound");
@@ -2218,12 +2403,12 @@ const contentTypes = {
2218
2403
  } catch (error) {
2219
2404
  return ctx.send({ error }, 400);
2220
2405
  }
2221
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2222
- const { toDto } = getService$1("data-mapper");
2406
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2407
+ const { toDto } = getService$2("data-mapper");
2223
2408
  ctx.body = { data: contentTypes2.map(toDto) };
2224
2409
  },
2225
2410
  async findContentTypesSettings(ctx) {
2226
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2411
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2227
2412
  const contentTypes2 = await findAllContentTypes();
2228
2413
  const configurations = await Promise.all(
2229
2414
  contentTypes2.map(async (contentType) => {
@@ -2237,7 +2422,7 @@ const contentTypes = {
2237
2422
  },
2238
2423
  async findContentTypeConfiguration(ctx) {
2239
2424
  const { uid: uid2 } = ctx.params;
2240
- const contentTypeService = getService$1("content-types");
2425
+ const contentTypeService = getService$2("content-types");
2241
2426
  const contentType = await contentTypeService.findContentType(uid2);
2242
2427
  if (!contentType) {
2243
2428
  return ctx.notFound("contentType.notFound");
@@ -2259,13 +2444,13 @@ const contentTypes = {
2259
2444
  const { userAbility } = ctx.state;
2260
2445
  const { uid: uid2 } = ctx.params;
2261
2446
  const { body } = ctx.request;
2262
- const contentTypeService = getService$1("content-types");
2263
- const metricsService = getService$1("metrics");
2447
+ const contentTypeService = getService$2("content-types");
2448
+ const metricsService = getService$2("metrics");
2264
2449
  const contentType = await contentTypeService.findContentType(uid2);
2265
2450
  if (!contentType) {
2266
2451
  return ctx.notFound("contentType.notFound");
2267
2452
  }
2268
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2453
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2269
2454
  return ctx.forbidden();
2270
2455
  }
2271
2456
  let input;
@@ -2298,10 +2483,10 @@ const contentTypes = {
2298
2483
  };
2299
2484
  const init = {
2300
2485
  getInitData(ctx) {
2301
- const { toDto } = getService$1("data-mapper");
2302
- const { findAllComponents } = getService$1("components");
2303
- const { getAllFieldSizes } = getService$1("field-sizes");
2304
- const { findAllContentTypes } = getService$1("content-types");
2486
+ const { toDto } = getService$2("data-mapper");
2487
+ const { findAllComponents } = getService$2("components");
2488
+ const { getAllFieldSizes } = getService$2("field-sizes");
2489
+ const { findAllContentTypes } = getService$2("content-types");
2305
2490
  ctx.body = {
2306
2491
  data: {
2307
2492
  fieldSizes: getAllFieldSizes(),
@@ -2337,7 +2522,7 @@ const addFiltersClause = (params, filtersClause) => {
2337
2522
  params.filters.$and.push(filtersClause);
2338
2523
  };
2339
2524
  const sanitizeMainField = (model, mainField, userAbility) => {
2340
- const permissionChecker2 = getService$1("permission-checker").create({
2525
+ const permissionChecker2 = getService$2("permission-checker").create({
2341
2526
  userAbility,
2342
2527
  model: model.uid
2343
2528
  });
@@ -2351,15 +2536,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2351
2536
  }
2352
2537
  return mainField;
2353
2538
  };
2354
- const addStatusToRelations = async (uid2, relations2) => {
2355
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2539
+ const addStatusToRelations = async (targetUid, relations2) => {
2540
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2356
2541
  return relations2;
2357
2542
  }
2358
- const documentMetadata2 = getService$1("document-metadata");
2359
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2543
+ const documentMetadata2 = getService$2("document-metadata");
2544
+ if (!relations2.length) {
2545
+ return relations2;
2546
+ }
2547
+ const firstRelation = relations2[0];
2548
+ const filters = {
2549
+ documentId: { $in: relations2.map((r) => r.documentId) },
2550
+ // NOTE: find the "opposite" status
2551
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2552
+ };
2553
+ const availableStatus = await strapi.query(targetUid).findMany({
2554
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2555
+ filters
2556
+ });
2360
2557
  return relations2.map((relation) => {
2361
- const availableStatuses = documentsAvailableStatus.filter(
2362
- (availableDocument) => availableDocument.documentId === relation.documentId
2558
+ const availableStatuses = availableStatus.filter(
2559
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2363
2560
  );
2364
2561
  return {
2365
2562
  ...relation,
@@ -2380,11 +2577,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2380
2577
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2381
2578
  const isSourceLocalized = isLocalized(sourceModel);
2382
2579
  const isTargetLocalized = isLocalized(targetModel);
2383
- let validatedLocale = locale;
2384
- if (!targetModel || !isTargetLocalized)
2385
- validatedLocale = void 0;
2386
2580
  return {
2387
- locale: validatedLocale,
2581
+ locale,
2388
2582
  isSourceLocalized,
2389
2583
  isTargetLocalized
2390
2584
  };
@@ -2424,7 +2618,7 @@ const relations = {
2424
2618
  ctx.request?.query?.locale
2425
2619
  );
2426
2620
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2427
- const permissionChecker2 = getService$1("permission-checker").create({
2621
+ const permissionChecker2 = getService$2("permission-checker").create({
2428
2622
  userAbility,
2429
2623
  model
2430
2624
  });
@@ -2449,7 +2643,7 @@ const relations = {
2449
2643
  where.id = id;
2450
2644
  }
2451
2645
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2452
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2646
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2453
2647
  const currentEntity = await strapi.db.query(model).findOne({
2454
2648
  where,
2455
2649
  populate
@@ -2464,7 +2658,7 @@ const relations = {
2464
2658
  }
2465
2659
  entryId = currentEntity.id;
2466
2660
  }
2467
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2661
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2468
2662
  const targetSchema = strapi.getModel(targetUid);
2469
2663
  const mainField = fp.flow(
2470
2664
  fp.prop(`metadatas.${targetField}.edit.mainField`),
@@ -2487,7 +2681,7 @@ const relations = {
2487
2681
  attribute,
2488
2682
  fieldsToSelect,
2489
2683
  mainField,
2490
- source: { schema: sourceSchema },
2684
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2491
2685
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2492
2686
  sourceSchema,
2493
2687
  targetSchema,
@@ -2509,7 +2703,8 @@ const relations = {
2509
2703
  fieldsToSelect,
2510
2704
  mainField,
2511
2705
  source: {
2512
- schema: { uid: sourceUid, modelType: sourceModelType }
2706
+ schema: { uid: sourceUid, modelType: sourceModelType },
2707
+ isLocalized: isSourceLocalized
2513
2708
  },
2514
2709
  target: {
2515
2710
  schema: { uid: targetUid },
@@ -2517,7 +2712,7 @@ const relations = {
2517
2712
  }
2518
2713
  } = await this.extractAndValidateRequestInfo(ctx, id);
2519
2714
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2520
- const permissionChecker2 = getService$1("permission-checker").create({
2715
+ const permissionChecker2 = getService$2("permission-checker").create({
2521
2716
  userAbility: ctx.state.userAbility,
2522
2717
  model: targetUid
2523
2718
  });
@@ -2547,12 +2742,16 @@ const relations = {
2547
2742
  } else {
2548
2743
  where.id = id;
2549
2744
  }
2550
- if (status) {
2551
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2745
+ const publishedAt = getPublishedAtClause(status, targetUid);
2746
+ if (!fp.isEmpty(publishedAt)) {
2747
+ where[`${alias}.published_at`] = publishedAt;
2552
2748
  }
2553
- if (filterByLocale) {
2749
+ if (isTargetLocalized && locale) {
2554
2750
  where[`${alias}.locale`] = locale;
2555
2751
  }
2752
+ if (isSourceLocalized && locale) {
2753
+ where.locale = locale;
2754
+ }
2556
2755
  if ((idsToInclude?.length ?? 0) !== 0) {
2557
2756
  where[`${alias}.id`].$notIn = idsToInclude;
2558
2757
  }
@@ -2570,7 +2769,8 @@ const relations = {
2570
2769
  id: { $notIn: fp.uniq(idsToOmit) }
2571
2770
  });
2572
2771
  }
2573
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2772
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2773
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2574
2774
  ctx.body = {
2575
2775
  ...res,
2576
2776
  results: await addStatusToRelations(targetUid, res.results)
@@ -2585,21 +2785,33 @@ const relations = {
2585
2785
  attribute,
2586
2786
  targetField,
2587
2787
  fieldsToSelect,
2588
- source: {
2589
- schema: { uid: sourceUid }
2590
- },
2591
- target: {
2592
- schema: { uid: targetUid }
2593
- }
2788
+ status,
2789
+ source: { schema: sourceSchema },
2790
+ target: { schema: targetSchema }
2594
2791
  } = await this.extractAndValidateRequestInfo(ctx, id);
2595
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2792
+ const { uid: sourceUid } = sourceSchema;
2793
+ const { uid: targetUid } = targetSchema;
2794
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2596
2795
  const dbQuery = strapi.db.query(sourceUid);
2597
2796
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2797
+ const filters = {};
2798
+ if (sourceSchema?.options?.draftAndPublish) {
2799
+ if (targetSchema?.options?.draftAndPublish) {
2800
+ if (status === "published") {
2801
+ filters.publishedAt = { $notNull: true };
2802
+ } else {
2803
+ filters.publishedAt = { $null: true };
2804
+ }
2805
+ }
2806
+ } else if (targetSchema?.options?.draftAndPublish) {
2807
+ filters.publishedAt = { $null: true };
2808
+ }
2598
2809
  const res = await loadRelations({ id: entryId }, targetField, {
2599
- select: ["id", "documentId", "locale", "publishedAt"],
2810
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2600
2811
  ordering: "desc",
2601
2812
  page: ctx.request.query.page,
2602
- pageSize: ctx.request.query.pageSize
2813
+ pageSize: ctx.request.query.pageSize,
2814
+ filters
2603
2815
  });
2604
2816
  const loadedIds = res.results.map((item) => item.id);
2605
2817
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2620,10 +2832,10 @@ const relations = {
2620
2832
  }
2621
2833
  };
2622
2834
  const buildPopulateFromQuery = async (query, model) => {
2623
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2835
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2624
2836
  };
2625
2837
  const findDocument = async (query, uid2, opts = {}) => {
2626
- const documentManager2 = getService$1("document-manager");
2838
+ const documentManager2 = getService$2("document-manager");
2627
2839
  const populate = await buildPopulateFromQuery(query, uid2);
2628
2840
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2629
2841
  };
@@ -2631,8 +2843,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2631
2843
  const { user, userAbility } = ctx.state;
2632
2844
  const { model } = ctx.params;
2633
2845
  const { body, query } = ctx.request;
2634
- const documentManager2 = getService$1("document-manager");
2635
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2846
+ const documentManager2 = getService$2("document-manager");
2847
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2636
2848
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2637
2849
  throw new strapiUtils.errors.ForbiddenError();
2638
2850
  }
@@ -2673,7 +2885,7 @@ const singleTypes = {
2673
2885
  const { userAbility } = ctx.state;
2674
2886
  const { model } = ctx.params;
2675
2887
  const { query = {} } = ctx.request;
2676
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2888
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2677
2889
  if (permissionChecker2.cannot.read()) {
2678
2890
  return ctx.forbidden();
2679
2891
  }
@@ -2692,7 +2904,7 @@ const singleTypes = {
2692
2904
  permissionChecker2,
2693
2905
  model,
2694
2906
  // @ts-expect-error - fix types
2695
- { id: document.documentId, locale, publishedAt: null },
2907
+ { documentId: document.documentId, locale, publishedAt: null },
2696
2908
  { availableLocales: true, availableStatus: false }
2697
2909
  );
2698
2910
  ctx.body = { data: {}, meta };
@@ -2707,7 +2919,7 @@ const singleTypes = {
2707
2919
  async createOrUpdate(ctx) {
2708
2920
  const { userAbility } = ctx.state;
2709
2921
  const { model } = ctx.params;
2710
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2922
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2711
2923
  const document = await createOrUpdateDocument(ctx);
2712
2924
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2713
2925
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2716,8 +2928,8 @@ const singleTypes = {
2716
2928
  const { userAbility } = ctx.state;
2717
2929
  const { model } = ctx.params;
2718
2930
  const { query = {} } = ctx.request;
2719
- const documentManager2 = getService$1("document-manager");
2720
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2931
+ const documentManager2 = getService$2("document-manager");
2932
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2721
2933
  if (permissionChecker2.cannot.delete()) {
2722
2934
  return ctx.forbidden();
2723
2935
  }
@@ -2745,8 +2957,8 @@ const singleTypes = {
2745
2957
  const { userAbility } = ctx.state;
2746
2958
  const { model } = ctx.params;
2747
2959
  const { query = {} } = ctx.request;
2748
- const documentManager2 = getService$1("document-manager");
2749
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2960
+ const documentManager2 = getService$2("document-manager");
2961
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2750
2962
  if (permissionChecker2.cannot.publish()) {
2751
2963
  return ctx.forbidden();
2752
2964
  }
@@ -2774,8 +2986,8 @@ const singleTypes = {
2774
2986
  body: { discardDraft, ...body },
2775
2987
  query = {}
2776
2988
  } = ctx.request;
2777
- const documentManager2 = getService$1("document-manager");
2778
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2989
+ const documentManager2 = getService$2("document-manager");
2990
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2779
2991
  if (permissionChecker2.cannot.unpublish()) {
2780
2992
  return ctx.forbidden();
2781
2993
  }
@@ -2809,8 +3021,8 @@ const singleTypes = {
2809
3021
  const { userAbility } = ctx.state;
2810
3022
  const { model } = ctx.params;
2811
3023
  const { body, query = {} } = ctx.request;
2812
- const documentManager2 = getService$1("document-manager");
2813
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3024
+ const documentManager2 = getService$2("document-manager");
3025
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2814
3026
  if (permissionChecker2.cannot.discard()) {
2815
3027
  return ctx.forbidden();
2816
3028
  }
@@ -2833,8 +3045,8 @@ const singleTypes = {
2833
3045
  const { userAbility } = ctx.state;
2834
3046
  const { model } = ctx.params;
2835
3047
  const { query } = ctx.request;
2836
- const documentManager2 = getService$1("document-manager");
2837
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3048
+ const documentManager2 = getService$2("document-manager");
3049
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2838
3050
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2839
3051
  if (permissionChecker2.cannot.read()) {
2840
3052
  return ctx.forbidden();
@@ -2858,7 +3070,7 @@ const uid$1 = {
2858
3070
  const { query = {} } = ctx.request;
2859
3071
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2860
3072
  await validateUIDField(contentTypeUID, field);
2861
- const uidService = getService$1("uid");
3073
+ const uidService = getService$2("uid");
2862
3074
  ctx.body = {
2863
3075
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2864
3076
  };
@@ -2870,7 +3082,7 @@ const uid$1 = {
2870
3082
  const { query = {} } = ctx.request;
2871
3083
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2872
3084
  await validateUIDField(contentTypeUID, field);
2873
- const uidService = getService$1("uid");
3085
+ const uidService = getService$2("uid");
2874
3086
  const isAvailable = await uidService.checkUIDAvailability({
2875
3087
  contentTypeUID,
2876
3088
  field,
@@ -2891,7 +3103,8 @@ const controllers = {
2891
3103
  relations,
2892
3104
  "single-types": singleTypes,
2893
3105
  uid: uid$1,
2894
- ...history.controllers ? history.controllers : {}
3106
+ ...history.controllers ? history.controllers : {},
3107
+ ...preview.controllers ? preview.controllers : {}
2895
3108
  };
2896
3109
  const keys = {
2897
3110
  CONFIGURATION: "configuration"
@@ -3042,12 +3255,12 @@ async function syncMetadatas(configuration, schema) {
3042
3255
  return ___default.default.assign(metasWithDefaults, updatedMetas);
3043
3256
  }
3044
3257
  const getTargetSchema = (targetModel) => {
3045
- return getService$1("content-types").findContentType(targetModel);
3258
+ return getService$2("content-types").findContentType(targetModel);
3046
3259
  };
3047
3260
  const DEFAULT_LIST_LENGTH = 4;
3048
3261
  const MAX_ROW_SIZE = 12;
3049
3262
  const isAllowedFieldSize = (type, size) => {
3050
- const { getFieldSize } = getService$1("field-sizes");
3263
+ const { getFieldSize } = getService$2("field-sizes");
3051
3264
  const fieldSize = getFieldSize(type);
3052
3265
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3053
3266
  return false;
@@ -3055,7 +3268,7 @@ const isAllowedFieldSize = (type, size) => {
3055
3268
  return size <= MAX_ROW_SIZE;
3056
3269
  };
3057
3270
  const getDefaultFieldSize = (attribute) => {
3058
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3271
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3059
3272
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3060
3273
  };
3061
3274
  async function createDefaultLayouts(schema) {
@@ -3090,7 +3303,7 @@ function syncLayouts(configuration, schema) {
3090
3303
  for (const el of row) {
3091
3304
  if (!hasEditableAttribute(schema, el.name))
3092
3305
  continue;
3093
- const { hasFieldSize } = getService$1("field-sizes");
3306
+ const { hasFieldSize } = getService$2("field-sizes");
3094
3307
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3095
3308
  if (!isAllowedFieldSize(fieldType, el.size)) {
3096
3309
  elementsToReAppend.push(el.name);
@@ -3230,17 +3443,17 @@ const configurationService$1 = createConfigurationService({
3230
3443
  isComponent: true,
3231
3444
  prefix: STORE_KEY_PREFIX,
3232
3445
  getModels() {
3233
- const { toContentManagerModel } = getService$1("data-mapper");
3446
+ const { toContentManagerModel } = getService$2("data-mapper");
3234
3447
  return fp.mapValues(toContentManagerModel, strapi.components);
3235
3448
  }
3236
3449
  });
3237
3450
  const components = ({ strapi: strapi2 }) => ({
3238
3451
  findAllComponents() {
3239
- const { toContentManagerModel } = getService$1("data-mapper");
3452
+ const { toContentManagerModel } = getService$2("data-mapper");
3240
3453
  return Object.values(strapi2.components).map(toContentManagerModel);
3241
3454
  },
3242
3455
  findComponent(uid2) {
3243
- const { toContentManagerModel } = getService$1("data-mapper");
3456
+ const { toContentManagerModel } = getService$2("data-mapper");
3244
3457
  const component = strapi2.components[uid2];
3245
3458
  return fp.isNil(component) ? component : toContentManagerModel(component);
3246
3459
  },
@@ -3291,17 +3504,17 @@ const configurationService = createConfigurationService({
3291
3504
  storeUtils,
3292
3505
  prefix: "content_types",
3293
3506
  getModels() {
3294
- const { toContentManagerModel } = getService$1("data-mapper");
3507
+ const { toContentManagerModel } = getService$2("data-mapper");
3295
3508
  return fp.mapValues(toContentManagerModel, strapi.contentTypes);
3296
3509
  }
3297
3510
  });
3298
3511
  const service = ({ strapi: strapi2 }) => ({
3299
3512
  findAllContentTypes() {
3300
- const { toContentManagerModel } = getService$1("data-mapper");
3513
+ const { toContentManagerModel } = getService$2("data-mapper");
3301
3514
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3302
3515
  },
3303
3516
  findContentType(uid2) {
3304
- const { toContentManagerModel } = getService$1("data-mapper");
3517
+ const { toContentManagerModel } = getService$2("data-mapper");
3305
3518
  const contentType = strapi2.contentTypes[uid2];
3306
3519
  return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
3307
3520
  },
@@ -3330,7 +3543,7 @@ const service = ({ strapi: strapi2 }) => ({
3330
3543
  return this.findConfiguration(contentType);
3331
3544
  },
3332
3545
  findComponentsConfigurations(contentType) {
3333
- return getService$1("components").findComponentsConfigurations(contentType);
3546
+ return getService$2("components").findComponentsConfigurations(contentType);
3334
3547
  },
3335
3548
  syncConfigurations() {
3336
3549
  return configurationService.syncConfigurations();
@@ -3602,7 +3815,7 @@ const permission = ({ strapi: strapi2 }) => ({
3602
3815
  return userAbility.can(action);
3603
3816
  },
3604
3817
  async registerPermissions() {
3605
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3818
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3606
3819
  const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
3607
3820
  const actions = [
3608
3821
  {
@@ -3878,7 +4091,7 @@ const getQueryPopulate = async (uid2, query) => {
3878
4091
  return populateQuery;
3879
4092
  };
3880
4093
  const buildDeepPopulate = (uid2) => {
3881
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4094
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3882
4095
  };
3883
4096
  const populateBuilder = (uid2) => {
3884
4097
  let getInitialPopulate = async () => {
@@ -4063,7 +4276,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4063
4276
  */
4064
4277
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4065
4278
  const versionsByLocale = fp.groupBy("locale", allVersions);
4066
- delete versionsByLocale[version.locale];
4279
+ if (version.locale) {
4280
+ delete versionsByLocale[version.locale];
4281
+ }
4067
4282
  const model = strapi2.getModel(uid2);
4068
4283
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4069
4284
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
@@ -4419,7 +4634,8 @@ const services = {
4419
4634
  permission,
4420
4635
  "populate-builder": populateBuilder$1,
4421
4636
  uid,
4422
- ...history.services ? history.services : {}
4637
+ ...history.services ? history.services : {},
4638
+ ...preview.services ? preview.services : {}
4423
4639
  };
4424
4640
  const index = () => {
4425
4641
  return {