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

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 (210) hide show
  1. package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -1
  2. package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js → ComponentConfigurationPage-BLWQy8ru.js} +5 -6
  4. package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js.map → ComponentConfigurationPage-BLWQy8ru.js.map} +1 -1
  5. package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs → ComponentConfigurationPage-CtIa3aa2.mjs} +4 -4
  6. package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs.map → ComponentConfigurationPage-CtIa3aa2.mjs.map} +1 -1
  7. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
  8. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
  9. package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
  10. package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs → EditConfigurationPage-DsPR2DVk.mjs} +4 -4
  11. package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs.map → EditConfigurationPage-DsPR2DVk.mjs.map} +1 -1
  12. package/dist/_chunks/{EditConfigurationPage-DValmA0m.js → EditConfigurationPage-RQkymxCy.js} +5 -6
  13. package/dist/_chunks/{EditConfigurationPage-DValmA0m.js.map → EditConfigurationPage-RQkymxCy.js.map} +1 -1
  14. package/dist/_chunks/{EditViewPage-Dk7Eaft4.js → EditViewPage-B-kExt8C.js} +50 -11
  15. package/dist/_chunks/EditViewPage-B-kExt8C.js.map +1 -0
  16. package/dist/_chunks/{EditViewPage-DiNFdFqP.mjs → EditViewPage-BPyVuPfM.mjs} +50 -10
  17. package/dist/_chunks/EditViewPage-BPyVuPfM.mjs.map +1 -0
  18. package/dist/_chunks/{Field-DH2OaqUP.js → Field-DPIsQRre.js} +250 -161
  19. package/dist/_chunks/Field-DPIsQRre.js.map +1 -0
  20. package/dist/_chunks/{Field-Dv_HTFTa.mjs → Field-Dltnt1km.mjs} +244 -155
  21. package/dist/_chunks/Field-Dltnt1km.mjs.map +1 -0
  22. package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
  23. package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
  24. package/dist/_chunks/{Form-B_dUDizM.js → Form-BFi4MXMT.js} +19 -12
  25. package/dist/_chunks/Form-BFi4MXMT.js.map +1 -0
  26. package/dist/_chunks/{Form-Dy6P4HgH.mjs → Form-C1IcWm1u.mjs} +17 -9
  27. package/dist/_chunks/Form-C1IcWm1u.mjs.map +1 -0
  28. package/dist/_chunks/{History-DrwsD1Vc.mjs → History-04ChQ4pl.mjs} +71 -104
  29. package/dist/_chunks/History-04ChQ4pl.mjs.map +1 -0
  30. package/dist/_chunks/{History-BT4w83Oa.js → History-wjcK4L0C.js} +70 -104
  31. package/dist/_chunks/History-wjcK4L0C.js.map +1 -0
  32. package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs → ListConfigurationPage-BYqPYLSU.mjs} +7 -6
  33. package/dist/_chunks/ListConfigurationPage-BYqPYLSU.mjs.map +1 -0
  34. package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js → ListConfigurationPage-CRbxIC3J.js} +7 -7
  35. package/dist/_chunks/ListConfigurationPage-CRbxIC3J.js.map +1 -0
  36. package/dist/_chunks/{ListViewPage-BvpwNur7.js → ListViewPage-D5NY9183.js} +88 -54
  37. package/dist/_chunks/ListViewPage-D5NY9183.js.map +1 -0
  38. package/dist/_chunks/{ListViewPage-5a1vw-OK.mjs → ListViewPage-FU2LBuhl.mjs} +83 -48
  39. package/dist/_chunks/ListViewPage-FU2LBuhl.mjs.map +1 -0
  40. package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js → NoContentTypePage-BgQVE_Qb.js} +2 -2
  41. package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js.map → NoContentTypePage-BgQVE_Qb.js.map} +1 -1
  42. package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs → NoContentTypePage-DCKUkwb8.mjs} +2 -2
  43. package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs.map → NoContentTypePage-DCKUkwb8.mjs.map} +1 -1
  44. package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js → NoPermissionsPage-C5jwn70o.js} +2 -2
  45. package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js.map → NoPermissionsPage-C5jwn70o.js.map} +1 -1
  46. package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs → NoPermissionsPage-jqve7C8l.mjs} +2 -2
  47. package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs.map → NoPermissionsPage-jqve7C8l.mjs.map} +1 -1
  48. package/dist/_chunks/Preview-BMYN548c.mjs +294 -0
  49. package/dist/_chunks/Preview-BMYN548c.mjs.map +1 -0
  50. package/dist/_chunks/Preview-DaOihysv.js +312 -0
  51. package/dist/_chunks/Preview-DaOihysv.js.map +1 -0
  52. package/dist/_chunks/{Relations-CznVF6LS.js → Relations-CTGM7Hv5.js} +75 -42
  53. package/dist/_chunks/Relations-CTGM7Hv5.js.map +1 -0
  54. package/dist/_chunks/{Relations-C7fPyh5P.mjs → Relations-gscPkxjF.mjs} +75 -41
  55. package/dist/_chunks/Relations-gscPkxjF.mjs.map +1 -0
  56. package/dist/_chunks/{en-otD_UBJi.js → en-BzQmavmK.js} +32 -14
  57. package/dist/_chunks/{en-otD_UBJi.js.map → en-BzQmavmK.js.map} +1 -1
  58. package/dist/_chunks/{en-CbaIuYoB.mjs → en-CSxLmrh1.mjs} +32 -14
  59. package/dist/_chunks/{en-CbaIuYoB.mjs.map → en-CSxLmrh1.mjs.map} +1 -1
  60. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  61. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  62. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  63. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  64. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  65. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  66. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  67. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  68. package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
  69. package/dist/_chunks/{index-D9UmmBcM.js → index-Ca7YWlAA.js} +1063 -754
  70. package/dist/_chunks/index-Ca7YWlAA.js.map +1 -0
  71. package/dist/_chunks/{index-BJ6uTqLL.mjs → index-DqasUQ6Q.mjs} +1066 -757
  72. package/dist/_chunks/index-DqasUQ6Q.mjs.map +1 -0
  73. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  74. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  75. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  76. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  77. package/dist/_chunks/{layout-kfu5Wtix.js → layout-BW80JSCd.js} +7 -7
  78. package/dist/_chunks/{layout-kfu5Wtix.js.map → layout-BW80JSCd.js.map} +1 -1
  79. package/dist/_chunks/{layout-uomiIGbG.mjs → layout-W3clJSCy.mjs} +6 -5
  80. package/dist/_chunks/{layout-uomiIGbG.mjs.map → layout-W3clJSCy.mjs.map} +1 -1
  81. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  82. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  83. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  84. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  85. package/dist/_chunks/{relations-DiDufGSA.mjs → relations-BlDkoeWh.mjs} +6 -7
  86. package/dist/_chunks/relations-BlDkoeWh.mjs.map +1 -0
  87. package/dist/_chunks/{relations-DKENrxko.js → relations-C9Usz9k5.js} +6 -7
  88. package/dist/_chunks/relations-C9Usz9k5.js.map +1 -0
  89. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  90. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  91. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  92. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  93. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
  94. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
  95. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
  96. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
  97. package/dist/admin/index.js +3 -1
  98. package/dist/admin/index.js.map +1 -1
  99. package/dist/admin/index.mjs +5 -3
  100. package/dist/admin/src/content-manager.d.ts +3 -2
  101. package/dist/admin/src/exports.d.ts +2 -1
  102. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  103. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  104. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  105. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -1
  106. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +3 -3
  107. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
  108. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
  109. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +1 -0
  110. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +4 -1
  111. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +4 -1
  112. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  113. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  114. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  115. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  116. package/dist/admin/src/preview/index.d.ts +4 -0
  117. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  118. package/dist/admin/src/preview/routes.d.ts +3 -0
  119. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  120. package/dist/admin/src/router.d.ts +1 -1
  121. package/dist/admin/src/services/api.d.ts +1 -1
  122. package/dist/admin/src/services/components.d.ts +2 -2
  123. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  124. package/dist/admin/src/services/documents.d.ts +19 -20
  125. package/dist/admin/src/services/init.d.ts +1 -1
  126. package/dist/admin/src/services/relations.d.ts +2 -2
  127. package/dist/admin/src/services/uid.d.ts +3 -3
  128. package/dist/server/index.js +594 -335
  129. package/dist/server/index.js.map +1 -1
  130. package/dist/server/index.mjs +595 -335
  131. package/dist/server/index.mjs.map +1 -1
  132. package/dist/server/src/bootstrap.d.ts.map +1 -1
  133. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  134. package/dist/server/src/controllers/index.d.ts.map +1 -1
  135. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  136. package/dist/server/src/controllers/utils/metadata.d.ts +16 -1
  137. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  138. package/dist/server/src/history/controllers/history-version.d.ts +1 -1
  139. package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
  140. package/dist/server/src/history/services/history.d.ts +3 -3
  141. package/dist/server/src/history/services/history.d.ts.map +1 -1
  142. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  143. package/dist/server/src/history/services/utils.d.ts +6 -11
  144. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  145. package/dist/server/src/index.d.ts +7 -6
  146. package/dist/server/src/index.d.ts.map +1 -1
  147. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  148. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  149. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  150. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  151. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  152. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  153. package/dist/server/src/preview/index.d.ts +4 -0
  154. package/dist/server/src/preview/index.d.ts.map +1 -0
  155. package/dist/server/src/preview/routes/index.d.ts +8 -0
  156. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  157. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  158. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  159. package/dist/server/src/preview/services/index.d.ts +16 -0
  160. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  161. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  162. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  163. package/dist/server/src/preview/services/preview.d.ts +12 -0
  164. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  165. package/dist/server/src/preview/utils.d.ts +19 -0
  166. package/dist/server/src/preview/utils.d.ts.map +1 -0
  167. package/dist/server/src/register.d.ts.map +1 -1
  168. package/dist/server/src/routes/index.d.ts.map +1 -1
  169. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  170. package/dist/server/src/services/document-metadata.d.ts +12 -10
  171. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  172. package/dist/server/src/services/index.d.ts +7 -6
  173. package/dist/server/src/services/index.d.ts.map +1 -1
  174. package/dist/server/src/services/utils/populate.d.ts +2 -2
  175. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  176. package/dist/server/src/utils/index.d.ts +2 -0
  177. package/dist/server/src/utils/index.d.ts.map +1 -1
  178. package/dist/shared/contracts/collection-types.d.ts +3 -1
  179. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  180. package/dist/shared/contracts/index.d.ts +1 -0
  181. package/dist/shared/contracts/index.d.ts.map +1 -1
  182. package/dist/shared/contracts/preview.d.ts +27 -0
  183. package/dist/shared/contracts/preview.d.ts.map +1 -0
  184. package/dist/shared/index.js +4 -0
  185. package/dist/shared/index.js.map +1 -1
  186. package/dist/shared/index.mjs +4 -0
  187. package/dist/shared/index.mjs.map +1 -1
  188. package/package.json +17 -15
  189. package/dist/_chunks/EditViewPage-DiNFdFqP.mjs.map +0 -1
  190. package/dist/_chunks/EditViewPage-Dk7Eaft4.js.map +0 -1
  191. package/dist/_chunks/Field-DH2OaqUP.js.map +0 -1
  192. package/dist/_chunks/Field-Dv_HTFTa.mjs.map +0 -1
  193. package/dist/_chunks/Form-B_dUDizM.js.map +0 -1
  194. package/dist/_chunks/Form-Dy6P4HgH.mjs.map +0 -1
  195. package/dist/_chunks/History-BT4w83Oa.js.map +0 -1
  196. package/dist/_chunks/History-DrwsD1Vc.mjs.map +0 -1
  197. package/dist/_chunks/ListConfigurationPage-BxIP0jRy.mjs.map +0 -1
  198. package/dist/_chunks/ListConfigurationPage-CuYrMcW3.js.map +0 -1
  199. package/dist/_chunks/ListViewPage-5a1vw-OK.mjs.map +0 -1
  200. package/dist/_chunks/ListViewPage-BvpwNur7.js.map +0 -1
  201. package/dist/_chunks/Relations-C7fPyh5P.mjs.map +0 -1
  202. package/dist/_chunks/Relations-CznVF6LS.js.map +0 -1
  203. package/dist/_chunks/index-BJ6uTqLL.mjs.map +0 -1
  204. package/dist/_chunks/index-D9UmmBcM.js.map +0 -1
  205. package/dist/_chunks/relations-DKENrxko.js.map +0 -1
  206. package/dist/_chunks/relations-DiDufGSA.mjs.map +0 -1
  207. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  208. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  209. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  210. package/strapi-server.js +0 -3
@@ -1,5 +1,5 @@
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";
1
+ import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, traverseEntity, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, pagination } from "@strapi/utils";
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
@@ -141,8 +141,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
141
141
  };
142
142
  const getRelationRestoreValue = async (versionRelationData, attribute) => {
143
143
  if (Array.isArray(versionRelationData)) {
144
- if (versionRelationData.length === 0)
145
- return versionRelationData;
144
+ if (versionRelationData.length === 0) return versionRelationData;
146
145
  const existingAndMissingRelations = await Promise.all(
147
146
  versionRelationData.map((relation) => {
148
147
  return strapi2.documents(attribute.target).findOne({
@@ -151,19 +150,16 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
151
150
  });
152
151
  })
153
152
  );
154
- return existingAndMissingRelations.filter(
155
- (relation) => relation !== null
156
- );
153
+ return existingAndMissingRelations.filter((relation) => relation !== null);
157
154
  }
158
155
  return strapi2.documents(attribute.target).findOne({
159
156
  documentId: versionRelationData.documentId,
160
157
  locale: versionRelationData.locale || void 0
161
158
  });
162
159
  };
163
- const getMediaRestoreValue = async (versionRelationData, attribute) => {
164
- if (attribute.multiple) {
160
+ const getMediaRestoreValue = async (versionRelationData) => {
161
+ if (Array.isArray(versionRelationData)) {
165
162
  const existingAndMissingMedias = await Promise.all(
166
- // @ts-expect-error Fix the type definitions so this isn't any
167
163
  versionRelationData.map((media) => {
168
164
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: media.id } });
169
165
  })
@@ -177,8 +173,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
177
173
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
178
174
  const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
179
175
  const getLocaleDictionary = async () => {
180
- if (!localesService)
181
- return {};
176
+ if (!localesService) return {};
182
177
  const locales = await localesService.find() || [];
183
178
  return locales.reduce(
184
179
  (acc, locale) => {
@@ -202,6 +197,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
202
197
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
203
198
  return documentMetadataService.getStatus(document, meta.availableStatus);
204
199
  };
200
+ const getComponentFields = (componentUID) => {
201
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
202
+ (fieldsAcc, [key, attribute]) => {
203
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
204
+ fieldsAcc.push(key);
205
+ }
206
+ return fieldsAcc;
207
+ },
208
+ []
209
+ );
210
+ };
205
211
  const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
206
212
  const model = strapi2.getModel(uid2);
207
213
  const attributes = Object.entries(model.attributes);
@@ -225,13 +231,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
225
231
  }
226
232
  case "component": {
227
233
  const populate = getDeepPopulate2(attribute.component);
228
- acc[attributeName] = { populate };
234
+ acc[attributeName] = {
235
+ populate,
236
+ [fieldSelector]: getComponentFields(attribute.component)
237
+ };
229
238
  break;
230
239
  }
231
240
  case "dynamiczone": {
232
241
  const populatedComponents = (attribute.components || []).reduce(
233
242
  (acc2, componentUID) => {
234
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
243
+ acc2[componentUID] = {
244
+ populate: getDeepPopulate2(componentUID),
245
+ [fieldSelector]: getComponentFields(componentUID)
246
+ };
235
247
  return acc2;
236
248
  },
237
249
  {}
@@ -316,8 +328,8 @@ const createHistoryService = ({ strapi: strapi2 }) => {
316
328
  });
317
329
  },
318
330
  async findVersionsPage(params) {
319
- const model = strapi2.getModel(params.query.contentType);
320
- const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
331
+ const schema = strapi2.getModel(params.query.contentType);
332
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(schema);
321
333
  const defaultLocale = await serviceUtils.getDefaultLocale();
322
334
  let locale = null;
323
335
  if (isLocalizedContentType) {
@@ -338,78 +350,76 @@ const createHistoryService = ({ strapi: strapi2 }) => {
338
350
  }),
339
351
  serviceUtils.getLocaleDictionary()
340
352
  ]);
341
- const populateEntryRelations = async (entry) => {
342
- const entryWithRelations = await Object.entries(entry.schema).reduce(
343
- async (currentDataWithRelations, [attributeKey, attributeSchema]) => {
344
- const attributeValue = entry.data[attributeKey];
345
- const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
346
- if (attributeSchema.type === "media") {
347
- const permissionChecker2 = getService$1("permission-checker").create({
348
- userAbility: params.state.userAbility,
349
- model: "plugin::upload.file"
350
- });
351
- const response = await serviceUtils.buildMediaResponse(attributeValues);
352
- const sanitizedResults = await Promise.all(
353
- response.results.map((media) => permissionChecker2.sanitizeOutput(media))
354
- );
355
- return {
356
- ...await currentDataWithRelations,
357
- [attributeKey]: {
358
- results: sanitizedResults,
359
- meta: response.meta
360
- }
361
- };
353
+ const populateEntry = async (entry) => {
354
+ return traverseEntity(
355
+ async (options, utils) => {
356
+ if (!options.attribute) return;
357
+ if (!options.value) return;
358
+ const currentValue = Array.isArray(options.value) ? options.value : [options.value];
359
+ if (options.attribute.type === "component") {
360
+ utils.remove("id");
362
361
  }
363
- if (attributeSchema.type === "relation" && attributeSchema.relation !== "morphToOne" && attributeSchema.relation !== "morphToMany") {
364
- if (attributeSchema.target === "admin::user") {
362
+ if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
363
+ options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
364
+ if (options.attribute.target === "admin::user") {
365
365
  const adminUsers = await Promise.all(
366
- attributeValues.map((userToPopulate) => {
366
+ currentValue.map((userToPopulate) => {
367
367
  if (userToPopulate == null) {
368
368
  return null;
369
369
  }
370
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
370
+ return strapi2.query("admin::user").findOne({
371
+ where: {
372
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
373
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
374
+ }
375
+ });
371
376
  })
372
377
  );
373
- return {
374
- ...await currentDataWithRelations,
375
- /**
376
- * Ideally we would return the same "{results: [], meta: {}}" shape, however,
377
- * when sanitizing the data as a whole in the controller before sending to the client,
378
- * the data for admin relation user is completely sanitized if we return an object here as opposed to an array.
379
- */
380
- [attributeKey]: adminUsers
381
- };
378
+ utils.set(options.key, adminUsers);
382
379
  }
383
- const permissionChecker2 = getService$1("permission-checker").create({
380
+ const permissionChecker2 = getService$2("permission-checker").create({
384
381
  userAbility: params.state.userAbility,
385
- model: attributeSchema.target
382
+ model: options.attribute.target
386
383
  });
387
384
  const response = await serviceUtils.buildRelationReponse(
388
- attributeValues,
389
- attributeSchema
385
+ currentValue,
386
+ options.attribute
390
387
  );
391
388
  const sanitizedResults = await Promise.all(
392
389
  response.results.map((media) => permissionChecker2.sanitizeOutput(media))
393
390
  );
394
- return {
395
- ...await currentDataWithRelations,
396
- [attributeKey]: {
397
- results: sanitizedResults,
398
- meta: response.meta
399
- }
400
- };
391
+ utils.set(options.key, {
392
+ results: sanitizedResults,
393
+ meta: response.meta
394
+ });
395
+ }
396
+ if (options.attribute.type === "media") {
397
+ const permissionChecker2 = getService$2("permission-checker").create({
398
+ userAbility: params.state.userAbility,
399
+ model: "plugin::upload.file"
400
+ });
401
+ const response = await serviceUtils.buildMediaResponse(currentValue);
402
+ const sanitizedResults = await Promise.all(
403
+ response.results.map((media) => permissionChecker2.sanitizeOutput(media))
404
+ );
405
+ utils.set(options.key, {
406
+ results: sanitizedResults,
407
+ meta: response.meta
408
+ });
401
409
  }
402
- return currentDataWithRelations;
403
410
  },
404
- Promise.resolve(entry.data)
411
+ {
412
+ schema,
413
+ getModel: strapi2.getModel.bind(strapi2)
414
+ },
415
+ entry.data
405
416
  );
406
- return entryWithRelations;
407
417
  };
408
418
  const formattedResults = await Promise.all(
409
419
  results.map(async (result) => {
410
420
  return {
411
421
  ...result,
412
- data: await populateEntryRelations(result),
422
+ data: await populateEntry(result),
413
423
  meta: {
414
424
  unknownAttributes: serviceUtils.getSchemaAttributesDiff(
415
425
  result.schema,
@@ -440,30 +450,44 @@ const createHistoryService = ({ strapi: strapi2 }) => {
440
450
  // Clone to avoid mutating the original version data
441
451
  structuredClone(version.data)
442
452
  );
443
- const sanitizedSchemaAttributes = omit(
444
- FIELDS_TO_IGNORE,
445
- contentTypeSchemaAttributes
446
- );
447
- const reducer = async.reduce(Object.entries(sanitizedSchemaAttributes));
448
- const dataWithoutMissingRelations = await reducer(
449
- async (previousRelationAttributes, [name, attribute]) => {
450
- const versionRelationData = version.data[name];
451
- if (!versionRelationData) {
452
- return previousRelationAttributes;
453
+ const schema = structuredClone(version.schema);
454
+ schema.attributes = omit(FIELDS_TO_IGNORE, contentTypeSchemaAttributes);
455
+ const dataWithoutMissingRelations = await traverseEntity(
456
+ async (options, utils) => {
457
+ if (!options.attribute) return;
458
+ if (options.attribute.type === "component") {
459
+ utils.remove("id");
460
+ if (options.attribute.repeatable && options.value === null) {
461
+ utils.set(options.key, []);
462
+ }
463
+ }
464
+ if (options.attribute.type === "dynamiczone") {
465
+ if (options.value === null) {
466
+ utils.set(options.key, []);
467
+ }
453
468
  }
454
- if (attribute.type === "relation" && // TODO: handle polymorphic relations
455
- attribute.relation !== "morphToOne" && attribute.relation !== "morphToMany") {
456
- const data2 = await serviceUtils.getRelationRestoreValue(versionRelationData, attribute);
457
- previousRelationAttributes[name] = data2;
469
+ if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
470
+ options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
471
+ if (!options.value) return;
472
+ const data2 = await serviceUtils.getRelationRestoreValue(
473
+ options.value,
474
+ options.attribute
475
+ );
476
+ utils.set(options.key, data2);
458
477
  }
459
- if (attribute.type === "media") {
460
- const data2 = await serviceUtils.getMediaRestoreValue(versionRelationData, attribute);
461
- previousRelationAttributes[name] = data2;
478
+ if (options.attribute.type === "media") {
479
+ if (!options.value) return;
480
+ const data2 = await serviceUtils.getMediaRestoreValue(
481
+ options.value
482
+ );
483
+ utils.set(options.key, data2);
462
484
  }
463
- return previousRelationAttributes;
464
485
  },
465
- // Clone to avoid mutating the original version data
466
- structuredClone(dataWithoutAddedAttributes)
486
+ {
487
+ schema,
488
+ getModel: strapi2.getModel.bind(strapi2)
489
+ },
490
+ dataWithoutAddedAttributes
467
491
  );
468
492
  const data = omit(["id", ...Object.keys(schemaDiff.removed)], dataWithoutMissingRelations);
469
493
  const restoredDocument = await strapi2.documents(version.contentType).update({
@@ -556,7 +580,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
556
580
  onCommit(async () => {
557
581
  for (const entry of localeEntries) {
558
582
  const status = await serviceUtils.getVersionStatus(uid2, entry);
559
- await getService(strapi2, "history").createVersion({
583
+ await getService$1(strapi2, "history").createVersion({
560
584
  contentType: uid2,
561
585
  data: omit(FIELDS_TO_IGNORE, entry),
562
586
  relatedDocumentId: documentId,
@@ -569,15 +593,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
569
593
  });
570
594
  return result;
571
595
  });
572
- state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
596
+ state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
573
597
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
574
598
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
575
599
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
576
600
  where: {
577
601
  created_at: {
578
- $lt: expirationDate.toISOString()
602
+ $lt: expirationDate
579
603
  }
580
604
  }
605
+ }).catch((error) => {
606
+ if (error instanceof Error) {
607
+ strapi2.log.error("Error deleting expired history versions", error.message);
608
+ }
581
609
  });
582
610
  });
583
611
  state.isInitialized = true;
@@ -589,17 +617,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
589
617
  }
590
618
  };
591
619
  };
592
- const services$1 = {
620
+ const services$2 = {
593
621
  history: createHistoryService,
594
622
  lifecycles: createLifecyclesService
595
623
  };
596
- const info = { pluginName: "content-manager", type: "admin" };
624
+ const info$1 = { pluginName: "content-manager", type: "admin" };
597
625
  const historyVersionRouter = {
598
626
  type: "admin",
599
627
  routes: [
600
628
  {
601
629
  method: "GET",
602
- info,
630
+ info: info$1,
603
631
  path: "/history-versions",
604
632
  handler: "history-version.findMany",
605
633
  config: {
@@ -608,7 +636,7 @@ const historyVersionRouter = {
608
636
  },
609
637
  {
610
638
  method: "PUT",
611
- info,
639
+ info: info$1,
612
640
  path: "/history-versions/:versionId/restore",
613
641
  handler: "history-version.restoreVersion",
614
642
  config: {
@@ -617,7 +645,7 @@ const historyVersionRouter = {
617
645
  }
618
646
  ]
619
647
  };
620
- const routes$1 = {
648
+ const routes$2 = {
621
649
  "history-version": historyVersionRouter
622
650
  };
623
651
  const historyVersion = {
@@ -664,21 +692,21 @@ const historyVersion = {
664
692
  }
665
693
  }
666
694
  };
667
- const getFeature = () => {
695
+ const getFeature$1 = () => {
668
696
  if (strapi.ee.features.isEnabled("cms-content-history")) {
669
697
  return {
670
698
  register({ strapi: strapi2 }) {
671
699
  strapi2.get("models").add(historyVersion);
672
700
  },
673
701
  bootstrap({ strapi: strapi2 }) {
674
- getService(strapi2, "lifecycles").bootstrap();
702
+ getService$1(strapi2, "lifecycles").bootstrap();
675
703
  },
676
704
  destroy({ strapi: strapi2 }) {
677
- getService(strapi2, "lifecycles").destroy();
705
+ getService$1(strapi2, "lifecycles").destroy();
678
706
  },
679
- controllers: controllers$1,
680
- services: services$1,
681
- routes: routes$1
707
+ controllers: controllers$2,
708
+ services: services$2,
709
+ routes: routes$2
682
710
  };
683
711
  }
684
712
  return {
@@ -687,9 +715,201 @@ const getFeature = () => {
687
715
  }
688
716
  };
689
717
  };
690
- const history = getFeature();
718
+ const history = getFeature$1();
719
+ const info = { pluginName: "content-manager", type: "admin" };
720
+ const previewRouter = {
721
+ type: "admin",
722
+ routes: [
723
+ {
724
+ method: "GET",
725
+ info,
726
+ path: "/preview/url/:contentType",
727
+ handler: "preview.getPreviewUrl",
728
+ config: {
729
+ policies: ["admin::isAuthenticatedAdmin"]
730
+ }
731
+ }
732
+ ]
733
+ };
734
+ const routes$1 = {
735
+ preview: previewRouter
736
+ };
737
+ function getService(strapi2, name) {
738
+ return strapi2.service(`plugin::content-manager.${name}`);
739
+ }
740
+ const getPreviewUrlSchema = yup.object().shape({
741
+ // Will be undefined for single types
742
+ documentId: yup.string(),
743
+ locale: yup.string().nullable(),
744
+ status: yup.string()
745
+ }).required();
746
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
747
+ await validateYupSchema(getPreviewUrlSchema)(params);
748
+ const newParams = pick(["documentId", "locale", "status"], params);
749
+ const model = strapi2.getModel(uid2);
750
+ if (!model || model.modelType !== "contentType") {
751
+ throw new errors.ValidationError("Invalid content type");
752
+ }
753
+ const isSingleType = model?.kind === "singleType";
754
+ if (!isSingleType && !params.documentId) {
755
+ throw new errors.ValidationError("documentId is required for Collection Types");
756
+ }
757
+ if (isSingleType) {
758
+ const doc = await strapi2.documents(uid2).findFirst();
759
+ if (!doc) {
760
+ throw new errors.NotFoundError("Document not found");
761
+ }
762
+ newParams.documentId = doc?.documentId;
763
+ }
764
+ if (!newParams.status) {
765
+ const isDPEnabled = model?.options?.draftAndPublish;
766
+ newParams.status = isDPEnabled ? "draft" : "published";
767
+ }
768
+ return newParams;
769
+ };
770
+ const createPreviewController = () => {
771
+ return {
772
+ /**
773
+ * Transforms an entry into a preview URL, so that it can be previewed
774
+ * in the Content Manager.
775
+ */
776
+ async getPreviewUrl(ctx) {
777
+ const uid2 = ctx.params.contentType;
778
+ const query = ctx.request.query;
779
+ const params = await validatePreviewUrl(strapi, uid2, query);
780
+ const previewService = getService(strapi, "preview");
781
+ const url = await previewService.getPreviewUrl(uid2, params);
782
+ if (!url) {
783
+ ctx.status = 204;
784
+ }
785
+ return {
786
+ data: { url }
787
+ };
788
+ }
789
+ };
790
+ };
791
+ const controllers$1 = {
792
+ preview: createPreviewController
793
+ /**
794
+ * Casting is needed because the types aren't aware that Strapi supports
795
+ * passing a controller factory as the value, instead of a controller object directly
796
+ */
797
+ };
798
+ const createPreviewService = ({ strapi: strapi2 }) => {
799
+ const config = getService(strapi2, "preview-config");
800
+ return {
801
+ async getPreviewUrl(uid2, params) {
802
+ const handler = config.getPreviewHandler();
803
+ try {
804
+ return handler(uid2, params);
805
+ } catch (error) {
806
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
807
+ throw new errors.ApplicationError("Failed to get preview URL");
808
+ }
809
+ return;
810
+ }
811
+ };
812
+ };
813
+ const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
814
+ const middlewares = strapi.config.get("middlewares");
815
+ const configuredMiddlewares = middlewares.map((currentMiddleware) => {
816
+ if (currentMiddleware === middleware.name) {
817
+ return middleware;
818
+ }
819
+ if (currentMiddleware.name === middleware.name) {
820
+ return mergeWith(
821
+ (objValue, srcValue) => {
822
+ if (Array.isArray(objValue)) {
823
+ return objValue.concat(srcValue);
824
+ }
825
+ return void 0;
826
+ },
827
+ currentMiddleware,
828
+ middleware
829
+ );
830
+ }
831
+ return currentMiddleware;
832
+ });
833
+ strapi.config.set("middlewares", configuredMiddlewares);
834
+ };
835
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
836
+ return {
837
+ register() {
838
+ if (!this.isEnabled()) {
839
+ return;
840
+ }
841
+ const config = strapi2.config.get("admin.preview");
842
+ if (config.config?.allowedOrigins) {
843
+ extendMiddlewareConfiguration({
844
+ name: "strapi::security",
845
+ config: {
846
+ contentSecurityPolicy: {
847
+ directives: {
848
+ "frame-src": config.config.allowedOrigins
849
+ }
850
+ }
851
+ }
852
+ });
853
+ }
854
+ },
855
+ isEnabled() {
856
+ const config = strapi2.config.get("admin.preview");
857
+ if (!config) {
858
+ return false;
859
+ }
860
+ return config?.enabled ?? true;
861
+ },
862
+ /**
863
+ * Validate if the configuration is valid
864
+ */
865
+ validate() {
866
+ if (!this.isEnabled()) {
867
+ return;
868
+ }
869
+ const handler = this.getPreviewHandler();
870
+ if (typeof handler !== "function") {
871
+ throw new errors.ValidationError(
872
+ "Preview configuration is invalid. Handler must be a function"
873
+ );
874
+ }
875
+ },
876
+ /**
877
+ * Utility to get the preview handler from the configuration
878
+ */
879
+ getPreviewHandler() {
880
+ const config = strapi2.config.get("admin.preview");
881
+ const emptyHandler = () => {
882
+ return void 0;
883
+ };
884
+ if (!this.isEnabled()) {
885
+ return emptyHandler;
886
+ }
887
+ return config?.config?.handler || emptyHandler;
888
+ }
889
+ };
890
+ };
891
+ const services$1 = {
892
+ preview: createPreviewService,
893
+ "preview-config": createPreviewConfigService
894
+ };
895
+ const getFeature = () => {
896
+ return {
897
+ register() {
898
+ const config = getService(strapi, "preview-config");
899
+ config.validate();
900
+ config.register();
901
+ },
902
+ bootstrap() {
903
+ },
904
+ routes: routes$1,
905
+ controllers: controllers$1,
906
+ services: services$1
907
+ };
908
+ };
909
+ const preview = getFeature();
691
910
  const register = async ({ strapi: strapi2 }) => {
692
911
  await history.register?.({ strapi: strapi2 });
912
+ await preview.register?.({ strapi: strapi2 });
693
913
  };
694
914
  const ALLOWED_WEBHOOK_EVENTS = {
695
915
  ENTRY_PUBLISH: "entry.publish",
@@ -699,11 +919,12 @@ const bootstrap = async () => {
699
919
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
700
920
  strapi.get("webhookStore").addAllowedEvent(key, value);
701
921
  });
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();
922
+ getService$2("field-sizes").setCustomFieldInputSizes();
923
+ await getService$2("components").syncConfigurations();
924
+ await getService$2("content-types").syncConfigurations();
925
+ await getService$2("permission").registerPermissions();
706
926
  await history.bootstrap?.({ strapi });
927
+ await preview.bootstrap?.({ strapi });
707
928
  };
708
929
  const destroy = async ({ strapi: strapi2 }) => {
709
930
  await history.destroy?.({ strapi: strapi2 });
@@ -1193,7 +1414,8 @@ const admin = {
1193
1414
  };
1194
1415
  const routes = {
1195
1416
  admin,
1196
- ...history.routes ? history.routes : {}
1417
+ ...history.routes ? history.routes : {},
1418
+ ...preview.routes ? preview.routes : {}
1197
1419
  };
1198
1420
  const hasPermissionsSchema = yup$1.object({
1199
1421
  actions: yup$1.array().of(yup$1.string()),
@@ -1256,8 +1478,7 @@ const isSortable = (schema, name) => {
1256
1478
  if (!_.has(schema.attributes, name)) {
1257
1479
  return false;
1258
1480
  }
1259
- if (schema.modelType === "component" && name === "id")
1260
- return false;
1481
+ if (schema.modelType === "component" && name === "id") return false;
1261
1482
  const attribute = schema.attributes[name];
1262
1483
  if (NON_SORTABLES.includes(attribute.type)) {
1263
1484
  return false;
@@ -1402,8 +1623,7 @@ const createDefaultSettings = async (schema) => {
1402
1623
  };
1403
1624
  };
1404
1625
  const syncSettings = async (configuration, schema) => {
1405
- if (isEmpty(configuration.settings))
1406
- return createDefaultSettings(schema);
1626
+ if (isEmpty(configuration.settings)) return createDefaultSettings(schema);
1407
1627
  const defaultField = getDefaultMainField(schema);
1408
1628
  const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
1409
1629
  return {
@@ -1450,7 +1670,7 @@ const createMetadasSchema = (schema) => {
1450
1670
  if (!value) {
1451
1671
  return yup$1.string();
1452
1672
  }
1453
- const targetSchema = getService$1("content-types").findContentType(
1673
+ const targetSchema = getService$2("content-types").findContentType(
1454
1674
  schema.attributes[key].targetModel
1455
1675
  );
1456
1676
  if (!targetSchema) {
@@ -1579,8 +1799,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1579
1799
  }
1580
1800
  switch (attribute.type) {
1581
1801
  case "relation": {
1582
- if (canCreate(attributePath))
1583
- return body2;
1802
+ if (canCreate(attributePath)) return body2;
1584
1803
  return set(attributePath, { set: [] }, body2);
1585
1804
  }
1586
1805
  case "component": {
@@ -1590,8 +1809,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1590
1809
  ]);
1591
1810
  }
1592
1811
  default: {
1593
- if (canCreate(attributePath))
1594
- return body2;
1812
+ if (canCreate(attributePath)) return body2;
1595
1813
  return set(attributePath, null, body2);
1596
1814
  }
1597
1815
  }
@@ -1619,7 +1837,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1619
1837
  }
1620
1838
  };
1621
1839
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1622
- const documentMetadata2 = getService$1("document-metadata");
1840
+ const documentMetadata2 = getService$2("document-metadata");
1623
1841
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1624
1842
  let {
1625
1843
  meta: { availableLocales, availableStatus }
@@ -1645,8 +1863,8 @@ const createDocument = async (ctx, opts) => {
1645
1863
  const { userAbility, user } = ctx.state;
1646
1864
  const { model } = ctx.params;
1647
1865
  const { body } = ctx.request;
1648
- const documentManager2 = getService$1("document-manager");
1649
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1866
+ const documentManager2 = getService$2("document-manager");
1867
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1650
1868
  if (permissionChecker2.cannot.create()) {
1651
1869
  throw new errors.ForbiddenError();
1652
1870
  }
@@ -1666,13 +1884,13 @@ const updateDocument = async (ctx, opts) => {
1666
1884
  const { userAbility, user } = ctx.state;
1667
1885
  const { id, model } = ctx.params;
1668
1886
  const { body } = ctx.request;
1669
- const documentManager2 = getService$1("document-manager");
1670
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1887
+ const documentManager2 = getService$2("document-manager");
1888
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1671
1889
  if (permissionChecker2.cannot.update()) {
1672
1890
  throw new errors.ForbiddenError();
1673
1891
  }
1674
1892
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1675
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1893
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1676
1894
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1677
1895
  const [documentVersion, documentExists] = await Promise.all([
1678
1896
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1689,7 +1907,7 @@ const updateDocument = async (ctx, opts) => {
1689
1907
  throw new errors.ForbiddenError();
1690
1908
  }
1691
1909
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1692
- const setCreator = setCreatorFields({ user, isEdition: true });
1910
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1693
1911
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1694
1912
  const sanitizedBody = await sanitizeFn(body);
1695
1913
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1703,14 +1921,14 @@ const collectionTypes = {
1703
1921
  const { userAbility } = ctx.state;
1704
1922
  const { model } = ctx.params;
1705
1923
  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 });
1924
+ const documentMetadata2 = getService$2("document-metadata");
1925
+ const documentManager2 = getService$2("document-manager");
1926
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1709
1927
  if (permissionChecker2.cannot.read()) {
1710
1928
  return ctx.forbidden();
1711
1929
  }
1712
1930
  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();
1931
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1714
1932
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1715
1933
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1716
1934
  { ...permissionQuery, populate, locale, status },
@@ -1739,13 +1957,13 @@ const collectionTypes = {
1739
1957
  async findOne(ctx) {
1740
1958
  const { userAbility } = ctx.state;
1741
1959
  const { model, id } = ctx.params;
1742
- const documentManager2 = getService$1("document-manager");
1743
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1960
+ const documentManager2 = getService$2("document-manager");
1961
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1744
1962
  if (permissionChecker2.cannot.read()) {
1745
1963
  return ctx.forbidden();
1746
1964
  }
1747
1965
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1748
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1966
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1749
1967
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1750
1968
  const version = await documentManager2.findOne(id, model, {
1751
1969
  populate,
@@ -1761,7 +1979,7 @@ const collectionTypes = {
1761
1979
  permissionChecker2,
1762
1980
  model,
1763
1981
  // @ts-expect-error TODO: fix
1764
- { id, locale, publishedAt: null },
1982
+ { documentId: id, locale, publishedAt: null },
1765
1983
  { availableLocales: true, availableStatus: false }
1766
1984
  );
1767
1985
  ctx.body = { data: {}, meta };
@@ -1776,7 +1994,7 @@ const collectionTypes = {
1776
1994
  async create(ctx) {
1777
1995
  const { userAbility } = ctx.state;
1778
1996
  const { model } = ctx.params;
1779
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1997
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1780
1998
  const [totalEntries, document] = await Promise.all([
1781
1999
  strapi.db.query(model).count(),
1782
2000
  createDocument(ctx)
@@ -1797,7 +2015,7 @@ const collectionTypes = {
1797
2015
  async update(ctx) {
1798
2016
  const { userAbility } = ctx.state;
1799
2017
  const { model } = ctx.params;
1800
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2018
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1801
2019
  const updatedVersion = await updateDocument(ctx);
1802
2020
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1803
2021
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1806,13 +2024,13 @@ const collectionTypes = {
1806
2024
  const { userAbility, user } = ctx.state;
1807
2025
  const { model, sourceId: id } = ctx.params;
1808
2026
  const { body } = ctx.request;
1809
- const documentManager2 = getService$1("document-manager");
1810
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2027
+ const documentManager2 = getService$2("document-manager");
2028
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1811
2029
  if (permissionChecker2.cannot.create()) {
1812
2030
  return ctx.forbidden();
1813
2031
  }
1814
2032
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1815
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2033
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1816
2034
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1817
2035
  const document = await documentManager2.findOne(id, model, {
1818
2036
  populate,
@@ -1851,13 +2069,13 @@ const collectionTypes = {
1851
2069
  async delete(ctx) {
1852
2070
  const { userAbility } = ctx.state;
1853
2071
  const { id, model } = ctx.params;
1854
- const documentManager2 = getService$1("document-manager");
1855
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2072
+ const documentManager2 = getService$2("document-manager");
2073
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1856
2074
  if (permissionChecker2.cannot.delete()) {
1857
2075
  return ctx.forbidden();
1858
2076
  }
1859
2077
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1860
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2078
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1861
2079
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1862
2080
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1863
2081
  if (documentLocales.length === 0) {
@@ -1879,14 +2097,14 @@ const collectionTypes = {
1879
2097
  const { userAbility } = ctx.state;
1880
2098
  const { id, model } = ctx.params;
1881
2099
  const { body } = ctx.request;
1882
- const documentManager2 = getService$1("document-manager");
1883
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2100
+ const documentManager2 = getService$2("document-manager");
2101
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1884
2102
  if (permissionChecker2.cannot.publish()) {
1885
2103
  return ctx.forbidden();
1886
2104
  }
1887
2105
  const publishedDocument = await strapi.db.transaction(async () => {
1888
2106
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1889
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2107
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1890
2108
  let document;
1891
2109
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1892
2110
  const isCreate = isNil$1(id);
@@ -1898,11 +2116,17 @@ const collectionTypes = {
1898
2116
  }
1899
2117
  const isUpdate = !isCreate;
1900
2118
  if (isUpdate) {
1901
- document = await documentManager2.findOne(id, model, { populate, locale });
1902
- if (!document) {
2119
+ const documentExists = documentManager2.exists(model, id);
2120
+ if (!documentExists) {
1903
2121
  throw new errors.NotFoundError("Document not found");
1904
2122
  }
1905
- if (permissionChecker2.can.update(document)) {
2123
+ document = await documentManager2.findOne(id, model, { populate, locale });
2124
+ if (!document) {
2125
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2126
+ throw new errors.ForbiddenError();
2127
+ }
2128
+ document = await updateDocument(ctx);
2129
+ } else if (permissionChecker2.can.update(document)) {
1906
2130
  await updateDocument(ctx);
1907
2131
  }
1908
2132
  }
@@ -1928,13 +2152,13 @@ const collectionTypes = {
1928
2152
  const { body } = ctx.request;
1929
2153
  const { documentIds } = body;
1930
2154
  await validateBulkActionInput(body);
1931
- const documentManager2 = getService$1("document-manager");
1932
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2155
+ const documentManager2 = getService$2("document-manager");
2156
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1933
2157
  if (permissionChecker2.cannot.publish()) {
1934
2158
  return ctx.forbidden();
1935
2159
  }
1936
2160
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1937
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2161
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1938
2162
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1939
2163
  allowMultipleLocales: true
1940
2164
  });
@@ -1959,12 +2183,14 @@ const collectionTypes = {
1959
2183
  const { body } = ctx.request;
1960
2184
  const { documentIds } = body;
1961
2185
  await validateBulkActionInput(body);
1962
- const documentManager2 = getService$1("document-manager");
1963
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2186
+ const documentManager2 = getService$2("document-manager");
2187
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1964
2188
  if (permissionChecker2.cannot.unpublish()) {
1965
2189
  return ctx.forbidden();
1966
2190
  }
1967
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2191
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2192
+ allowMultipleLocales: true
2193
+ });
1968
2194
  const entityPromises = documentIds.map(
1969
2195
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1970
2196
  );
@@ -1987,8 +2213,8 @@ const collectionTypes = {
1987
2213
  const {
1988
2214
  body: { discardDraft, ...body }
1989
2215
  } = ctx.request;
1990
- const documentManager2 = getService$1("document-manager");
1991
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2216
+ const documentManager2 = getService$2("document-manager");
2217
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1992
2218
  if (permissionChecker2.cannot.unpublish()) {
1993
2219
  return ctx.forbidden();
1994
2220
  }
@@ -1996,7 +2222,7 @@ const collectionTypes = {
1996
2222
  return ctx.forbidden();
1997
2223
  }
1998
2224
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1999
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2225
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2000
2226
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2001
2227
  const document = await documentManager2.findOne(id, model, {
2002
2228
  populate,
@@ -2027,13 +2253,13 @@ const collectionTypes = {
2027
2253
  const { userAbility } = ctx.state;
2028
2254
  const { id, model } = ctx.params;
2029
2255
  const { body } = ctx.request;
2030
- const documentManager2 = getService$1("document-manager");
2031
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2256
+ const documentManager2 = getService$2("document-manager");
2257
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2032
2258
  if (permissionChecker2.cannot.discard()) {
2033
2259
  return ctx.forbidden();
2034
2260
  }
2035
2261
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2036
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2262
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2037
2263
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2038
2264
  const document = await documentManager2.findOne(id, model, {
2039
2265
  populate,
@@ -2058,13 +2284,13 @@ const collectionTypes = {
2058
2284
  const { query, body } = ctx.request;
2059
2285
  const { documentIds } = body;
2060
2286
  await validateBulkActionInput(body);
2061
- const documentManager2 = getService$1("document-manager");
2062
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2287
+ const documentManager2 = getService$2("document-manager");
2288
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2063
2289
  if (permissionChecker2.cannot.delete()) {
2064
2290
  return ctx.forbidden();
2065
2291
  }
2066
2292
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2067
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2293
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2068
2294
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2069
2295
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2070
2296
  populate,
@@ -2085,13 +2311,13 @@ const collectionTypes = {
2085
2311
  async countDraftRelations(ctx) {
2086
2312
  const { userAbility } = ctx.state;
2087
2313
  const { model, id } = ctx.params;
2088
- const documentManager2 = getService$1("document-manager");
2089
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2314
+ const documentManager2 = getService$2("document-manager");
2315
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2090
2316
  if (permissionChecker2.cannot.read()) {
2091
2317
  return ctx.forbidden();
2092
2318
  }
2093
2319
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2094
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2320
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2095
2321
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2096
2322
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2097
2323
  if (!entity) {
@@ -2110,8 +2336,8 @@ const collectionTypes = {
2110
2336
  const ids = ctx.request.query.documentIds;
2111
2337
  const locale = ctx.request.query.locale;
2112
2338
  const { model } = ctx.params;
2113
- const documentManager2 = getService$1("document-manager");
2114
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2339
+ const documentManager2 = getService$2("document-manager");
2340
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2115
2341
  if (permissionChecker2.cannot.read()) {
2116
2342
  return ctx.forbidden();
2117
2343
  }
@@ -2135,13 +2361,13 @@ const collectionTypes = {
2135
2361
  };
2136
2362
  const components$1 = {
2137
2363
  findComponents(ctx) {
2138
- const components2 = getService$1("components").findAllComponents();
2139
- const { toDto } = getService$1("data-mapper");
2364
+ const components2 = getService$2("components").findAllComponents();
2365
+ const { toDto } = getService$2("data-mapper");
2140
2366
  ctx.body = { data: components2.map(toDto) };
2141
2367
  },
2142
2368
  async findComponentConfiguration(ctx) {
2143
2369
  const { uid: uid2 } = ctx.params;
2144
- const componentService = getService$1("components");
2370
+ const componentService = getService$2("components");
2145
2371
  const component = componentService.findComponent(uid2);
2146
2372
  if (!component) {
2147
2373
  return ctx.notFound("component.notFound");
@@ -2158,7 +2384,7 @@ const components$1 = {
2158
2384
  async updateComponentConfiguration(ctx) {
2159
2385
  const { uid: uid2 } = ctx.params;
2160
2386
  const { body } = ctx.request;
2161
- const componentService = getService$1("components");
2387
+ const componentService = getService$2("components");
2162
2388
  const component = componentService.findComponent(uid2);
2163
2389
  if (!component) {
2164
2390
  return ctx.notFound("component.notFound");
@@ -2192,12 +2418,12 @@ const contentTypes = {
2192
2418
  } catch (error) {
2193
2419
  return ctx.send({ error }, 400);
2194
2420
  }
2195
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2196
- const { toDto } = getService$1("data-mapper");
2421
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2422
+ const { toDto } = getService$2("data-mapper");
2197
2423
  ctx.body = { data: contentTypes2.map(toDto) };
2198
2424
  },
2199
2425
  async findContentTypesSettings(ctx) {
2200
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2426
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2201
2427
  const contentTypes2 = await findAllContentTypes();
2202
2428
  const configurations = await Promise.all(
2203
2429
  contentTypes2.map(async (contentType) => {
@@ -2211,7 +2437,7 @@ const contentTypes = {
2211
2437
  },
2212
2438
  async findContentTypeConfiguration(ctx) {
2213
2439
  const { uid: uid2 } = ctx.params;
2214
- const contentTypeService = getService$1("content-types");
2440
+ const contentTypeService = getService$2("content-types");
2215
2441
  const contentType = await contentTypeService.findContentType(uid2);
2216
2442
  if (!contentType) {
2217
2443
  return ctx.notFound("contentType.notFound");
@@ -2233,13 +2459,13 @@ const contentTypes = {
2233
2459
  const { userAbility } = ctx.state;
2234
2460
  const { uid: uid2 } = ctx.params;
2235
2461
  const { body } = ctx.request;
2236
- const contentTypeService = getService$1("content-types");
2237
- const metricsService = getService$1("metrics");
2462
+ const contentTypeService = getService$2("content-types");
2463
+ const metricsService = getService$2("metrics");
2238
2464
  const contentType = await contentTypeService.findContentType(uid2);
2239
2465
  if (!contentType) {
2240
2466
  return ctx.notFound("contentType.notFound");
2241
2467
  }
2242
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2468
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2243
2469
  return ctx.forbidden();
2244
2470
  }
2245
2471
  let input;
@@ -2272,10 +2498,10 @@ const contentTypes = {
2272
2498
  };
2273
2499
  const init = {
2274
2500
  getInitData(ctx) {
2275
- const { toDto } = getService$1("data-mapper");
2276
- const { findAllComponents } = getService$1("components");
2277
- const { getAllFieldSizes } = getService$1("field-sizes");
2278
- const { findAllContentTypes } = getService$1("content-types");
2501
+ const { toDto } = getService$2("data-mapper");
2502
+ const { findAllComponents } = getService$2("components");
2503
+ const { getAllFieldSizes } = getService$2("field-sizes");
2504
+ const { findAllContentTypes } = getService$2("content-types");
2279
2505
  ctx.body = {
2280
2506
  data: {
2281
2507
  fieldSizes: getAllFieldSizes(),
@@ -2311,7 +2537,7 @@ const addFiltersClause = (params, filtersClause) => {
2311
2537
  params.filters.$and.push(filtersClause);
2312
2538
  };
2313
2539
  const sanitizeMainField = (model, mainField, userAbility) => {
2314
- const permissionChecker2 = getService$1("permission-checker").create({
2540
+ const permissionChecker2 = getService$2("permission-checker").create({
2315
2541
  userAbility,
2316
2542
  model: model.uid
2317
2543
  });
@@ -2325,15 +2551,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2325
2551
  }
2326
2552
  return mainField;
2327
2553
  };
2328
- const addStatusToRelations = async (uid2, relations2) => {
2329
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2554
+ const addStatusToRelations = async (targetUid, relations2) => {
2555
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2330
2556
  return relations2;
2331
2557
  }
2332
- const documentMetadata2 = getService$1("document-metadata");
2333
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2558
+ const documentMetadata2 = getService$2("document-metadata");
2559
+ if (!relations2.length) {
2560
+ return relations2;
2561
+ }
2562
+ const firstRelation = relations2[0];
2563
+ const filters = {
2564
+ documentId: { $in: relations2.map((r) => r.documentId) },
2565
+ // NOTE: find the "opposite" status
2566
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2567
+ };
2568
+ const availableStatus = await strapi.query(targetUid).findMany({
2569
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2570
+ filters
2571
+ });
2334
2572
  return relations2.map((relation) => {
2335
- const availableStatuses = documentsAvailableStatus.filter(
2336
- (availableDocument) => availableDocument.documentId === relation.documentId
2573
+ const availableStatuses = availableStatus.filter(
2574
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2337
2575
  );
2338
2576
  return {
2339
2577
  ...relation,
@@ -2354,11 +2592,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2354
2592
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2355
2593
  const isSourceLocalized = isLocalized(sourceModel);
2356
2594
  const isTargetLocalized = isLocalized(targetModel);
2357
- let validatedLocale = locale;
2358
- if (!targetModel || !isTargetLocalized)
2359
- validatedLocale = void 0;
2360
2595
  return {
2361
- locale: validatedLocale,
2596
+ locale,
2362
2597
  isSourceLocalized,
2363
2598
  isTargetLocalized
2364
2599
  };
@@ -2367,8 +2602,7 @@ const validateStatus = (sourceUid, status) => {
2367
2602
  const sourceModel = strapi.getModel(sourceUid);
2368
2603
  const isDP = contentTypes$1.hasDraftAndPublish;
2369
2604
  const isSourceDP = isDP(sourceModel);
2370
- if (!isSourceDP)
2371
- return { status: void 0 };
2605
+ if (!isSourceDP) return { status: void 0 };
2372
2606
  switch (status) {
2373
2607
  case "published":
2374
2608
  return { status: "published" };
@@ -2398,7 +2632,7 @@ const relations = {
2398
2632
  ctx.request?.query?.locale
2399
2633
  );
2400
2634
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2401
- const permissionChecker2 = getService$1("permission-checker").create({
2635
+ const permissionChecker2 = getService$2("permission-checker").create({
2402
2636
  userAbility,
2403
2637
  model
2404
2638
  });
@@ -2423,7 +2657,7 @@ const relations = {
2423
2657
  where.id = id;
2424
2658
  }
2425
2659
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2426
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2660
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2427
2661
  const currentEntity = await strapi.db.query(model).findOne({
2428
2662
  where,
2429
2663
  populate
@@ -2438,7 +2672,7 @@ const relations = {
2438
2672
  }
2439
2673
  entryId = currentEntity.id;
2440
2674
  }
2441
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2675
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2442
2676
  const targetSchema = strapi.getModel(targetUid);
2443
2677
  const mainField = flow(
2444
2678
  prop(`metadatas.${targetField}.edit.mainField`),
@@ -2461,7 +2695,7 @@ const relations = {
2461
2695
  attribute,
2462
2696
  fieldsToSelect,
2463
2697
  mainField,
2464
- source: { schema: sourceSchema },
2698
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2465
2699
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2466
2700
  sourceSchema,
2467
2701
  targetSchema,
@@ -2483,7 +2717,8 @@ const relations = {
2483
2717
  fieldsToSelect,
2484
2718
  mainField,
2485
2719
  source: {
2486
- schema: { uid: sourceUid, modelType: sourceModelType }
2720
+ schema: { uid: sourceUid, modelType: sourceModelType },
2721
+ isLocalized: isSourceLocalized
2487
2722
  },
2488
2723
  target: {
2489
2724
  schema: { uid: targetUid },
@@ -2491,7 +2726,7 @@ const relations = {
2491
2726
  }
2492
2727
  } = await this.extractAndValidateRequestInfo(ctx, id);
2493
2728
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2494
- const permissionChecker2 = getService$1("permission-checker").create({
2729
+ const permissionChecker2 = getService$2("permission-checker").create({
2495
2730
  userAbility: ctx.state.userAbility,
2496
2731
  model: targetUid
2497
2732
  });
@@ -2521,12 +2756,16 @@ const relations = {
2521
2756
  } else {
2522
2757
  where.id = id;
2523
2758
  }
2524
- if (status) {
2525
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2759
+ const publishedAt = getPublishedAtClause(status, targetUid);
2760
+ if (!isEmpty(publishedAt)) {
2761
+ where[`${alias}.published_at`] = publishedAt;
2526
2762
  }
2527
- if (filterByLocale) {
2763
+ if (isTargetLocalized && locale) {
2528
2764
  where[`${alias}.locale`] = locale;
2529
2765
  }
2766
+ if (isSourceLocalized && locale) {
2767
+ where.locale = locale;
2768
+ }
2530
2769
  if ((idsToInclude?.length ?? 0) !== 0) {
2531
2770
  where[`${alias}.id`].$notIn = idsToInclude;
2532
2771
  }
@@ -2544,7 +2783,8 @@ const relations = {
2544
2783
  id: { $notIn: uniq(idsToOmit) }
2545
2784
  });
2546
2785
  }
2547
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2786
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2787
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2548
2788
  ctx.body = {
2549
2789
  ...res,
2550
2790
  results: await addStatusToRelations(targetUid, res.results)
@@ -2559,21 +2799,33 @@ const relations = {
2559
2799
  attribute,
2560
2800
  targetField,
2561
2801
  fieldsToSelect,
2562
- source: {
2563
- schema: { uid: sourceUid }
2564
- },
2565
- target: {
2566
- schema: { uid: targetUid }
2567
- }
2802
+ status,
2803
+ source: { schema: sourceSchema },
2804
+ target: { schema: targetSchema }
2568
2805
  } = await this.extractAndValidateRequestInfo(ctx, id);
2569
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2806
+ const { uid: sourceUid } = sourceSchema;
2807
+ const { uid: targetUid } = targetSchema;
2808
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2570
2809
  const dbQuery = strapi.db.query(sourceUid);
2571
2810
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2811
+ const filters = {};
2812
+ if (sourceSchema?.options?.draftAndPublish) {
2813
+ if (targetSchema?.options?.draftAndPublish) {
2814
+ if (status === "published") {
2815
+ filters.publishedAt = { $notNull: true };
2816
+ } else {
2817
+ filters.publishedAt = { $null: true };
2818
+ }
2819
+ }
2820
+ } else if (targetSchema?.options?.draftAndPublish) {
2821
+ filters.publishedAt = { $null: true };
2822
+ }
2572
2823
  const res = await loadRelations({ id: entryId }, targetField, {
2573
- select: ["id", "documentId", "locale", "publishedAt"],
2824
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2574
2825
  ordering: "desc",
2575
2826
  page: ctx.request.query.page,
2576
- pageSize: ctx.request.query.pageSize
2827
+ pageSize: ctx.request.query.pageSize,
2828
+ filters
2577
2829
  });
2578
2830
  const loadedIds = res.results.map((item) => item.id);
2579
2831
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2594,10 +2846,10 @@ const relations = {
2594
2846
  }
2595
2847
  };
2596
2848
  const buildPopulateFromQuery = async (query, model) => {
2597
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2849
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2598
2850
  };
2599
2851
  const findDocument = async (query, uid2, opts = {}) => {
2600
- const documentManager2 = getService$1("document-manager");
2852
+ const documentManager2 = getService$2("document-manager");
2601
2853
  const populate = await buildPopulateFromQuery(query, uid2);
2602
2854
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2603
2855
  };
@@ -2605,8 +2857,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2605
2857
  const { user, userAbility } = ctx.state;
2606
2858
  const { model } = ctx.params;
2607
2859
  const { body, query } = ctx.request;
2608
- const documentManager2 = getService$1("document-manager");
2609
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2860
+ const documentManager2 = getService$2("document-manager");
2861
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2610
2862
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2611
2863
  throw new errors.ForbiddenError();
2612
2864
  }
@@ -2647,7 +2899,7 @@ const singleTypes = {
2647
2899
  const { userAbility } = ctx.state;
2648
2900
  const { model } = ctx.params;
2649
2901
  const { query = {} } = ctx.request;
2650
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2902
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2651
2903
  if (permissionChecker2.cannot.read()) {
2652
2904
  return ctx.forbidden();
2653
2905
  }
@@ -2666,7 +2918,7 @@ const singleTypes = {
2666
2918
  permissionChecker2,
2667
2919
  model,
2668
2920
  // @ts-expect-error - fix types
2669
- { id: document.documentId, locale, publishedAt: null },
2921
+ { documentId: document.documentId, locale, publishedAt: null },
2670
2922
  { availableLocales: true, availableStatus: false }
2671
2923
  );
2672
2924
  ctx.body = { data: {}, meta };
@@ -2681,7 +2933,7 @@ const singleTypes = {
2681
2933
  async createOrUpdate(ctx) {
2682
2934
  const { userAbility } = ctx.state;
2683
2935
  const { model } = ctx.params;
2684
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2936
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2685
2937
  const document = await createOrUpdateDocument(ctx);
2686
2938
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2687
2939
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2690,8 +2942,8 @@ const singleTypes = {
2690
2942
  const { userAbility } = ctx.state;
2691
2943
  const { model } = ctx.params;
2692
2944
  const { query = {} } = ctx.request;
2693
- const documentManager2 = getService$1("document-manager");
2694
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2945
+ const documentManager2 = getService$2("document-manager");
2946
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2695
2947
  if (permissionChecker2.cannot.delete()) {
2696
2948
  return ctx.forbidden();
2697
2949
  }
@@ -2719,8 +2971,8 @@ const singleTypes = {
2719
2971
  const { userAbility } = ctx.state;
2720
2972
  const { model } = ctx.params;
2721
2973
  const { query = {} } = ctx.request;
2722
- const documentManager2 = getService$1("document-manager");
2723
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2974
+ const documentManager2 = getService$2("document-manager");
2975
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2724
2976
  if (permissionChecker2.cannot.publish()) {
2725
2977
  return ctx.forbidden();
2726
2978
  }
@@ -2748,8 +3000,8 @@ const singleTypes = {
2748
3000
  body: { discardDraft, ...body },
2749
3001
  query = {}
2750
3002
  } = ctx.request;
2751
- const documentManager2 = getService$1("document-manager");
2752
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3003
+ const documentManager2 = getService$2("document-manager");
3004
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2753
3005
  if (permissionChecker2.cannot.unpublish()) {
2754
3006
  return ctx.forbidden();
2755
3007
  }
@@ -2783,8 +3035,8 @@ const singleTypes = {
2783
3035
  const { userAbility } = ctx.state;
2784
3036
  const { model } = ctx.params;
2785
3037
  const { body, query = {} } = ctx.request;
2786
- const documentManager2 = getService$1("document-manager");
2787
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3038
+ const documentManager2 = getService$2("document-manager");
3039
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2788
3040
  if (permissionChecker2.cannot.discard()) {
2789
3041
  return ctx.forbidden();
2790
3042
  }
@@ -2807,8 +3059,8 @@ const singleTypes = {
2807
3059
  const { userAbility } = ctx.state;
2808
3060
  const { model } = ctx.params;
2809
3061
  const { query } = ctx.request;
2810
- const documentManager2 = getService$1("document-manager");
2811
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3062
+ const documentManager2 = getService$2("document-manager");
3063
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2812
3064
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2813
3065
  if (permissionChecker2.cannot.read()) {
2814
3066
  return ctx.forbidden();
@@ -2832,7 +3084,7 @@ const uid$1 = {
2832
3084
  const { query = {} } = ctx.request;
2833
3085
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2834
3086
  await validateUIDField(contentTypeUID, field);
2835
- const uidService = getService$1("uid");
3087
+ const uidService = getService$2("uid");
2836
3088
  ctx.body = {
2837
3089
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2838
3090
  };
@@ -2844,7 +3096,7 @@ const uid$1 = {
2844
3096
  const { query = {} } = ctx.request;
2845
3097
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2846
3098
  await validateUIDField(contentTypeUID, field);
2847
- const uidService = getService$1("uid");
3099
+ const uidService = getService$2("uid");
2848
3100
  const isAvailable = await uidService.checkUIDAvailability({
2849
3101
  contentTypeUID,
2850
3102
  field,
@@ -2865,7 +3117,8 @@ const controllers = {
2865
3117
  relations,
2866
3118
  "single-types": singleTypes,
2867
3119
  uid: uid$1,
2868
- ...history.controllers ? history.controllers : {}
3120
+ ...history.controllers ? history.controllers : {},
3121
+ ...preview.controllers ? preview.controllers : {}
2869
3122
  };
2870
3123
  const keys = {
2871
3124
  CONFIGURATION: "configuration"
@@ -2994,18 +3247,15 @@ async function syncMetadatas(configuration, schema) {
2994
3247
  _.set(updatedMeta, ["list", "searchable"], false);
2995
3248
  _.set(acc, [key], updatedMeta);
2996
3249
  }
2997
- if (!_.has(edit, "mainField"))
2998
- return acc;
3250
+ if (!_.has(edit, "mainField")) return acc;
2999
3251
  if (!isRelation$1(attr)) {
3000
3252
  _.set(updatedMeta, "edit", _.omit(edit, ["mainField"]));
3001
3253
  _.set(acc, [key], updatedMeta);
3002
3254
  return acc;
3003
3255
  }
3004
- if (edit.mainField === "id")
3005
- return acc;
3256
+ if (edit.mainField === "id") return acc;
3006
3257
  const targetSchema = getTargetSchema(attr.targetModel);
3007
- if (!targetSchema)
3008
- return acc;
3258
+ if (!targetSchema) return acc;
3009
3259
  if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
3010
3260
  _.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
3011
3261
  _.set(acc, [key], updatedMeta);
@@ -3016,12 +3266,12 @@ async function syncMetadatas(configuration, schema) {
3016
3266
  return _.assign(metasWithDefaults, updatedMetas);
3017
3267
  }
3018
3268
  const getTargetSchema = (targetModel) => {
3019
- return getService$1("content-types").findContentType(targetModel);
3269
+ return getService$2("content-types").findContentType(targetModel);
3020
3270
  };
3021
3271
  const DEFAULT_LIST_LENGTH = 4;
3022
3272
  const MAX_ROW_SIZE = 12;
3023
3273
  const isAllowedFieldSize = (type, size) => {
3024
- const { getFieldSize } = getService$1("field-sizes");
3274
+ const { getFieldSize } = getService$2("field-sizes");
3025
3275
  const fieldSize = getFieldSize(type);
3026
3276
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3027
3277
  return false;
@@ -3029,7 +3279,7 @@ const isAllowedFieldSize = (type, size) => {
3029
3279
  return size <= MAX_ROW_SIZE;
3030
3280
  };
3031
3281
  const getDefaultFieldSize = (attribute) => {
3032
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3282
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3033
3283
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3034
3284
  };
3035
3285
  async function createDefaultLayouts(schema) {
@@ -3050,8 +3300,7 @@ function createDefaultEditLayout(schema) {
3050
3300
  return appendToEditLayout([], keys2, schema);
3051
3301
  }
3052
3302
  function syncLayouts(configuration, schema) {
3053
- if (_.isEmpty(configuration.layouts))
3054
- return createDefaultLayouts(schema);
3303
+ if (_.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
3055
3304
  const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
3056
3305
  let cleanList = list.filter((attr) => isListable(schema, attr));
3057
3306
  const cleanEditRelations = editRelations.filter(
@@ -3062,9 +3311,8 @@ function syncLayouts(configuration, schema) {
3062
3311
  for (const row of edit) {
3063
3312
  const newRow = [];
3064
3313
  for (const el of row) {
3065
- if (!hasEditableAttribute(schema, el.name))
3066
- continue;
3067
- const { hasFieldSize } = getService$1("field-sizes");
3314
+ if (!hasEditableAttribute(schema, el.name)) continue;
3315
+ const { hasFieldSize } = getService$2("field-sizes");
3068
3316
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3069
3317
  if (!isAllowedFieldSize(fieldType, el.size)) {
3070
3318
  elementsToReAppend.push(el.name);
@@ -3094,8 +3342,7 @@ function syncLayouts(configuration, schema) {
3094
3342
  };
3095
3343
  }
3096
3344
  const appendToEditLayout = (layout = [], keysToAppend, schema) => {
3097
- if (keysToAppend.length === 0)
3098
- return layout;
3345
+ if (keysToAppend.length === 0) return layout;
3099
3346
  let currentRowIndex = Math.max(layout.length - 1, 0);
3100
3347
  if (!layout[currentRowIndex]) {
3101
3348
  layout[currentRowIndex] = [];
@@ -3204,17 +3451,17 @@ const configurationService$1 = createConfigurationService({
3204
3451
  isComponent: true,
3205
3452
  prefix: STORE_KEY_PREFIX,
3206
3453
  getModels() {
3207
- const { toContentManagerModel } = getService$1("data-mapper");
3454
+ const { toContentManagerModel } = getService$2("data-mapper");
3208
3455
  return mapValues(toContentManagerModel, strapi.components);
3209
3456
  }
3210
3457
  });
3211
3458
  const components = ({ strapi: strapi2 }) => ({
3212
3459
  findAllComponents() {
3213
- const { toContentManagerModel } = getService$1("data-mapper");
3460
+ const { toContentManagerModel } = getService$2("data-mapper");
3214
3461
  return Object.values(strapi2.components).map(toContentManagerModel);
3215
3462
  },
3216
3463
  findComponent(uid2) {
3217
- const { toContentManagerModel } = getService$1("data-mapper");
3464
+ const { toContentManagerModel } = getService$2("data-mapper");
3218
3465
  const component = strapi2.components[uid2];
3219
3466
  return isNil$1(component) ? component : toContentManagerModel(component);
3220
3467
  },
@@ -3265,17 +3512,17 @@ const configurationService = createConfigurationService({
3265
3512
  storeUtils,
3266
3513
  prefix: "content_types",
3267
3514
  getModels() {
3268
- const { toContentManagerModel } = getService$1("data-mapper");
3515
+ const { toContentManagerModel } = getService$2("data-mapper");
3269
3516
  return mapValues(toContentManagerModel, strapi.contentTypes);
3270
3517
  }
3271
3518
  });
3272
3519
  const service = ({ strapi: strapi2 }) => ({
3273
3520
  findAllContentTypes() {
3274
- const { toContentManagerModel } = getService$1("data-mapper");
3521
+ const { toContentManagerModel } = getService$2("data-mapper");
3275
3522
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3276
3523
  },
3277
3524
  findContentType(uid2) {
3278
- const { toContentManagerModel } = getService$1("data-mapper");
3525
+ const { toContentManagerModel } = getService$2("data-mapper");
3279
3526
  const contentType = strapi2.contentTypes[uid2];
3280
3527
  return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
3281
3528
  },
@@ -3304,7 +3551,7 @@ const service = ({ strapi: strapi2 }) => ({
3304
3551
  return this.findConfiguration(contentType);
3305
3552
  },
3306
3553
  findComponentsConfigurations(contentType) {
3307
- return getService$1("components").findComponentsConfigurations(contentType);
3554
+ return getService$2("components").findComponentsConfigurations(contentType);
3308
3555
  },
3309
3556
  syncConfigurations() {
3310
3557
  return configurationService.syncConfigurations();
@@ -3576,7 +3823,7 @@ const permission = ({ strapi: strapi2 }) => ({
3576
3823
  return userAbility.can(action);
3577
3824
  },
3578
3825
  async registerPermissions() {
3579
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3826
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3580
3827
  const contentTypesUids = displayedContentTypes.map(prop("uid"));
3581
3828
  const actions = [
3582
3829
  {
@@ -3661,6 +3908,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
3661
3908
  if (initialPopulate) {
3662
3909
  return initialPopulate;
3663
3910
  }
3911
+ if (attributeName === "localizations") {
3912
+ const validationPopulate = getPopulateForValidation(model.uid);
3913
+ return {
3914
+ populate: validationPopulate.populate
3915
+ };
3916
+ }
3664
3917
  if (!isVisibleAttribute$1(model, attributeName)) {
3665
3918
  return true;
3666
3919
  }
@@ -3720,6 +3973,9 @@ const getDeepPopulate = (uid2, {
3720
3973
  return {};
3721
3974
  }
3722
3975
  const model = strapi.getModel(uid2);
3976
+ if (!model) {
3977
+ return {};
3978
+ }
3723
3979
  return Object.keys(model.attributes).reduce(
3724
3980
  (populateAcc, attributeName) => merge(
3725
3981
  populateAcc,
@@ -3739,40 +3995,46 @@ const getDeepPopulate = (uid2, {
3739
3995
  {}
3740
3996
  );
3741
3997
  };
3742
- const getValidatableFieldsPopulate = (uid2, {
3743
- initialPopulate = {},
3744
- countMany = false,
3745
- countOne = false,
3746
- maxLevel = Infinity
3747
- } = {}, level = 1) => {
3748
- if (level > maxLevel) {
3998
+ const getPopulateForValidation = (uid2) => {
3999
+ const model = strapi.getModel(uid2);
4000
+ if (!model) {
3749
4001
  return {};
3750
4002
  }
3751
- const model = strapi.getModel(uid2);
3752
4003
  return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
3753
- if (!getDoesAttributeRequireValidation(attribute)) {
4004
+ if (isScalarAttribute(attribute)) {
4005
+ if (getDoesAttributeRequireValidation(attribute)) {
4006
+ populateAcc.fields = populateAcc.fields || [];
4007
+ populateAcc.fields.push(attributeName);
4008
+ }
3754
4009
  return populateAcc;
3755
4010
  }
3756
- if (isScalarAttribute(attribute)) {
3757
- return merge(populateAcc, {
3758
- [attributeName]: true
3759
- });
4011
+ if (isComponent(attribute)) {
4012
+ const component = attribute.component;
4013
+ const componentResult = getPopulateForValidation(component);
4014
+ if (Object.keys(componentResult).length > 0) {
4015
+ populateAcc.populate = populateAcc.populate || {};
4016
+ populateAcc.populate[attributeName] = componentResult;
4017
+ }
4018
+ return populateAcc;
3760
4019
  }
3761
- return merge(
3762
- populateAcc,
3763
- getPopulateFor(
3764
- attributeName,
3765
- model,
3766
- {
3767
- // @ts-expect-error - improve types
3768
- initialPopulate: initialPopulate?.[attributeName],
3769
- countMany,
3770
- countOne,
3771
- maxLevel
4020
+ if (isDynamicZone(attribute)) {
4021
+ const components2 = attribute.components;
4022
+ const componentsResult = (components2 || []).reduce(
4023
+ (acc, componentUID) => {
4024
+ const componentResult = getPopulateForValidation(componentUID);
4025
+ if (Object.keys(componentResult).length > 0) {
4026
+ acc[componentUID] = componentResult;
4027
+ }
4028
+ return acc;
3772
4029
  },
3773
- level
3774
- )
3775
- );
4030
+ {}
4031
+ );
4032
+ if (Object.keys(componentsResult).length > 0) {
4033
+ populateAcc.populate = populateAcc.populate || {};
4034
+ populateAcc.populate[attributeName] = { on: componentsResult };
4035
+ }
4036
+ }
4037
+ return populateAcc;
3776
4038
  }, {});
3777
4039
  };
3778
4040
  const getDeepPopulateDraftCount = (uid2) => {
@@ -3852,7 +4114,7 @@ const getQueryPopulate = async (uid2, query) => {
3852
4114
  return populateQuery;
3853
4115
  };
3854
4116
  const buildDeepPopulate = (uid2) => {
3855
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4117
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3856
4118
  };
3857
4119
  const populateBuilder = (uid2) => {
3858
4120
  let getInitialPopulate = async () => {
@@ -4014,7 +4276,6 @@ const AVAILABLE_LOCALES_FIELDS = [
4014
4276
  "locale",
4015
4277
  "updatedAt",
4016
4278
  "createdAt",
4017
- "status",
4018
4279
  "publishedAt",
4019
4280
  "documentId"
4020
4281
  ];
@@ -4035,34 +4296,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4035
4296
  /**
4036
4297
  * Returns available locales of a document for the current status
4037
4298
  */
4038
- async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4299
+ async getAvailableLocales(uid2, version, allVersions) {
4039
4300
  const versionsByLocale = groupBy("locale", allVersions);
4040
- delete versionsByLocale[version.locale];
4301
+ if (version.locale) {
4302
+ delete versionsByLocale[version.locale];
4303
+ }
4041
4304
  const model = strapi2.getModel(uid2);
4042
- const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4043
- const traversalFunction = async (localeVersion) => traverseEntity(
4044
- ({ key }, { remove }) => {
4045
- if (keysToKeep.includes(key)) {
4046
- return;
4047
- }
4048
- remove(key);
4049
- },
4050
- { schema: model, getModel: strapi2.getModel.bind(strapi2) },
4051
- // @ts-expect-error fix types DocumentVersion incompatible with Data
4052
- localeVersion
4053
- );
4054
4305
  const mappingResult = await async.map(
4055
4306
  Object.values(versionsByLocale),
4056
4307
  async (localeVersions) => {
4057
- const mappedLocaleVersions = await async.map(
4058
- localeVersions,
4059
- traversalFunction
4060
- );
4061
4308
  if (!contentTypes$1.hasDraftAndPublish(model)) {
4062
- return mappedLocaleVersions[0];
4309
+ return localeVersions[0];
4063
4310
  }
4064
- const draftVersion = mappedLocaleVersions.find((v) => v.publishedAt === null);
4065
- const otherVersions = mappedLocaleVersions.filter((v) => v.id !== draftVersion?.id);
4311
+ const draftVersion = localeVersions.find((v) => v.publishedAt === null);
4312
+ const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
4066
4313
  if (!draftVersion) {
4067
4314
  return;
4068
4315
  }
@@ -4084,8 +4331,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4084
4331
  const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
4085
4332
  return matchLocale && matchStatus;
4086
4333
  });
4087
- if (!availableStatus)
4088
- return availableStatus;
4334
+ if (!availableStatus) return availableStatus;
4089
4335
  return pick(AVAILABLE_STATUS_FIELDS, availableStatus);
4090
4336
  },
4091
4337
  /**
@@ -4095,18 +4341,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4095
4341
  * @returns
4096
4342
  */
4097
4343
  async getManyAvailableStatus(uid2, documents) {
4098
- if (!documents.length)
4099
- return [];
4344
+ if (!documents.length) return [];
4100
4345
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4101
- const locale = documents[0]?.locale;
4102
- const otherStatus = status === "published" ? "draft" : "published";
4103
- return strapi2.documents(uid2).findMany({
4104
- filters: {
4105
- documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) }
4106
- },
4107
- status: otherStatus,
4108
- locale,
4109
- fields: ["documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
4346
+ const locales = documents.map((d) => d.locale).filter(Boolean);
4347
+ const where = {
4348
+ documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
4349
+ publishedAt: { $null: status === "published" }
4350
+ };
4351
+ if (locales.length) {
4352
+ where.locale = { $in: locales };
4353
+ }
4354
+ return strapi2.query(uid2).findMany({
4355
+ where,
4356
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
4110
4357
  });
4111
4358
  },
4112
4359
  getStatus(version, otherDocumentStatuses) {
@@ -4123,10 +4370,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4123
4370
  } else if (otherVersion) {
4124
4371
  draftVersion = otherVersion;
4125
4372
  }
4126
- if (!draftVersion)
4127
- return CONTENT_MANAGER_STATUS.PUBLISHED;
4128
- if (!publishedVersion)
4129
- return CONTENT_MANAGER_STATUS.DRAFT;
4373
+ if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
4374
+ if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
4130
4375
  const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
4131
4376
  return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
4132
4377
  },
@@ -4134,11 +4379,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4134
4379
  // We could refactor this so the locales are only loaded when they're
4135
4380
  // needed. e.g. in the bulk locale action modal.
4136
4381
  async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
4137
- const populate = getValidatableFieldsPopulate(uid2);
4138
- const versions = await strapi2.db.query(uid2).findMany({
4139
- where: { documentId: version.documentId },
4382
+ const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
4383
+ const params = {
4140
4384
  populate: {
4141
- // Populate only fields that require validation for bulk locale actions
4142
4385
  ...populate,
4143
4386
  // NOTE: creator fields are selected in this way to avoid exposing sensitive data
4144
4387
  createdBy: {
@@ -4147,9 +4390,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4147
4390
  updatedBy: {
4148
4391
  select: ["id", "firstname", "lastname", "email"]
4149
4392
  }
4393
+ },
4394
+ fields: uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
4395
+ filters: {
4396
+ documentId: version.documentId
4150
4397
  }
4151
- });
4152
- const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions, Object.keys(populate)) : [];
4398
+ };
4399
+ const dbParams = strapi2.get("query-params").transform(uid2, params);
4400
+ const versions = await strapi2.db.query(uid2).findMany(dbParams);
4401
+ const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
4153
4402
  const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
4154
4403
  return {
4155
4404
  availableLocales: availableLocalesResult,
@@ -4176,6 +4425,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4176
4425
  opts.availableStatus = false;
4177
4426
  }
4178
4427
  const meta = await this.getMetadata(uid2, document, opts);
4428
+ if (document.localizations) {
4429
+ const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
4430
+ document.localizations = document.localizations.map((d) => {
4431
+ const status = otherStatus.find((s) => s.documentId === d.documentId);
4432
+ return {
4433
+ ...d,
4434
+ status: this.getStatus(d, status ? [status] : [])
4435
+ };
4436
+ });
4437
+ }
4179
4438
  return {
4180
4439
  data: {
4181
4440
  ...document,
@@ -4393,7 +4652,8 @@ const services = {
4393
4652
  permission,
4394
4653
  "populate-builder": populateBuilder$1,
4395
4654
  uid,
4396
- ...history.services ? history.services : {}
4655
+ ...history.services ? history.services : {},
4656
+ ...preview.services ? preview.services : {}
4397
4657
  };
4398
4658
  const index = () => {
4399
4659
  return {