@strapi/content-manager 0.0.0-experimental.e14656d3b8681880212c13260b9a2b340c182f2d → 0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02

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 (198) 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-D_M8iBw5.js → ComponentConfigurationPage-BTR_hQow.js} +5 -6
  4. package/dist/_chunks/{ComponentConfigurationPage-D_M8iBw5.js.map → ComponentConfigurationPage-BTR_hQow.js.map} +1 -1
  5. package/dist/_chunks/{ComponentConfigurationPage-qemkOlnj.mjs → ComponentConfigurationPage-bLQr82ce.mjs} +4 -4
  6. package/dist/_chunks/{ComponentConfigurationPage-qemkOlnj.mjs.map → ComponentConfigurationPage-bLQr82ce.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-CjUrEewK.mjs → EditConfigurationPage-BhRSnUsL.mjs} +4 -4
  11. package/dist/_chunks/{EditConfigurationPage-CjUrEewK.mjs.map → EditConfigurationPage-BhRSnUsL.mjs.map} +1 -1
  12. package/dist/_chunks/{EditConfigurationPage-BePwPuHy.js → EditConfigurationPage-z39Wv3E6.js} +5 -6
  13. package/dist/_chunks/{EditConfigurationPage-BePwPuHy.js.map → EditConfigurationPage-z39Wv3E6.js.map} +1 -1
  14. package/dist/_chunks/{EditViewPage-De8GyU8P.mjs → EditViewPage-BCjNxNlY.mjs} +50 -10
  15. package/dist/_chunks/EditViewPage-BCjNxNlY.mjs.map +1 -0
  16. package/dist/_chunks/{EditViewPage-B-RJeiJD.js → EditViewPage-wujOq90c.js} +50 -11
  17. package/dist/_chunks/EditViewPage-wujOq90c.js.map +1 -0
  18. package/dist/_chunks/{Field-dq8Tg1M_.js → Field-B5QXnctJ.js} +238 -153
  19. package/dist/_chunks/Field-B5QXnctJ.js.map +1 -0
  20. package/dist/_chunks/{Field-pb2o8uBe.mjs → Field-Byr3mPTl.mjs} +232 -147
  21. package/dist/_chunks/Field-Byr3mPTl.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-DJn0Dxha.mjs → Form-BZgvE8C8.mjs} +17 -9
  25. package/dist/_chunks/Form-BZgvE8C8.mjs.map +1 -0
  26. package/dist/_chunks/{Form-DGIf4jQU.js → Form-D7mexvm3.js} +19 -12
  27. package/dist/_chunks/Form-D7mexvm3.js.map +1 -0
  28. package/dist/_chunks/{History-BowL3JKP.mjs → History-CqNgxkqK.mjs} +43 -100
  29. package/dist/_chunks/History-CqNgxkqK.mjs.map +1 -0
  30. package/dist/_chunks/{History-Dh2NEHnR.js → History-DYl2A8Z_.js} +42 -100
  31. package/dist/_chunks/History-DYl2A8Z_.js.map +1 -0
  32. package/dist/_chunks/{ListConfigurationPage-BxYCWz9e.js → ListConfigurationPage-BXnu_OoY.js} +7 -7
  33. package/dist/_chunks/ListConfigurationPage-BXnu_OoY.js.map +1 -0
  34. package/dist/_chunks/{ListConfigurationPage-BpVOB-hn.mjs → ListConfigurationPage-BbQjzKkQ.mjs} +7 -6
  35. package/dist/_chunks/ListConfigurationPage-BbQjzKkQ.mjs.map +1 -0
  36. package/dist/_chunks/{ListViewPage-4XsciqHZ.js → ListViewPage-BtSi8C1l.js} +103 -77
  37. package/dist/_chunks/ListViewPage-BtSi8C1l.js.map +1 -0
  38. package/dist/_chunks/{ListViewPage-CXFUjZQC.mjs → ListViewPage-D4ofkbjR.mjs} +99 -72
  39. package/dist/_chunks/ListViewPage-D4ofkbjR.mjs.map +1 -0
  40. package/dist/_chunks/{NoContentTypePage-C8OpoHeU.js → NoContentTypePage-CitJeOq4.js} +2 -2
  41. package/dist/_chunks/{NoContentTypePage-C8OpoHeU.js.map → NoContentTypePage-CitJeOq4.js.map} +1 -1
  42. package/dist/_chunks/{NoContentTypePage-DuhOTp3x.mjs → NoContentTypePage-DyUx5mXh.mjs} +2 -2
  43. package/dist/_chunks/{NoContentTypePage-DuhOTp3x.mjs.map → NoContentTypePage-DyUx5mXh.mjs.map} +1 -1
  44. package/dist/_chunks/{NoPermissionsPage-DVz3mzDz.mjs → NoPermissionsPage-DhIiyWkk.mjs} +2 -2
  45. package/dist/_chunks/{NoPermissionsPage-DVz3mzDz.mjs.map → NoPermissionsPage-DhIiyWkk.mjs.map} +1 -1
  46. package/dist/_chunks/{NoPermissionsPage-y_r7DVA2.js → NoPermissionsPage-DzgWz0M-.js} +2 -2
  47. package/dist/_chunks/{NoPermissionsPage-y_r7DVA2.js.map → NoPermissionsPage-DzgWz0M-.js.map} +1 -1
  48. package/dist/_chunks/Preview-BaYGJ0nb.mjs +293 -0
  49. package/dist/_chunks/Preview-BaYGJ0nb.mjs.map +1 -0
  50. package/dist/_chunks/Preview-DfNx8Ke-.js +311 -0
  51. package/dist/_chunks/Preview-DfNx8Ke-.js.map +1 -0
  52. package/dist/_chunks/{Relations-CVNLrn1Y.mjs → Relations-DM2yUTST.mjs} +75 -41
  53. package/dist/_chunks/Relations-DM2yUTST.mjs.map +1 -0
  54. package/dist/_chunks/{Relations-DPFCAa7b.js → Relations-DuKCaXrv.js} +75 -42
  55. package/dist/_chunks/Relations-DuKCaXrv.js.map +1 -0
  56. package/dist/_chunks/{en-uOUIxfcQ.js → en-BK8Xyl5I.js} +28 -15
  57. package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BK8Xyl5I.js.map} +1 -1
  58. package/dist/_chunks/{en-BrCTWlZv.mjs → en-Dtk_ot79.mjs} +28 -15
  59. package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-Dtk_ot79.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-C3fJE-1-.js → index-BUWEmX8m.js} +1273 -996
  70. package/dist/_chunks/index-BUWEmX8m.js.map +1 -0
  71. package/dist/_chunks/{index-DiMrfcfy.mjs → index-DVAIIsOs.mjs} +1276 -999
  72. package/dist/_chunks/index-DVAIIsOs.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-ls3gxfpH.mjs → layout-Bxsv5mP7.mjs} +6 -5
  78. package/dist/_chunks/{layout-ls3gxfpH.mjs.map → layout-Bxsv5mP7.mjs.map} +1 -1
  79. package/dist/_chunks/{layout-C788OmNr.js → layout-C3fN7Ejz.js} +7 -7
  80. package/dist/_chunks/{layout-C788OmNr.js.map → layout-C3fN7Ejz.js.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-DYeotliT.js → relations-BPZKAoEY.js} +6 -7
  86. package/dist/_chunks/relations-BPZKAoEY.js.map +1 -0
  87. package/dist/_chunks/{relations-CLcOmGO0.mjs → relations-o3pPhzY4.mjs} +6 -7
  88. package/dist/_chunks/relations-o3pPhzY4.mjs.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 +2 -1
  98. package/dist/admin/index.js.map +1 -1
  99. package/dist/admin/index.mjs +4 -3
  100. package/dist/admin/src/content-manager.d.ts +3 -2
  101. package/dist/admin/src/exports.d.ts +1 -1
  102. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  103. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  104. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -1
  105. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
  106. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
  107. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
  108. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +1 -0
  109. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +0 -32
  110. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  111. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  112. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  113. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  114. package/dist/admin/src/preview/index.d.ts +4 -0
  115. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  116. package/dist/admin/src/preview/routes.d.ts +3 -0
  117. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  118. package/dist/admin/src/router.d.ts +1 -1
  119. package/dist/admin/src/services/documents.d.ts +3 -4
  120. package/dist/server/index.js +453 -201
  121. package/dist/server/index.js.map +1 -1
  122. package/dist/server/index.mjs +453 -200
  123. package/dist/server/index.mjs.map +1 -1
  124. package/dist/server/src/bootstrap.d.ts.map +1 -1
  125. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  126. package/dist/server/src/controllers/index.d.ts.map +1 -1
  127. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  128. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  129. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  130. package/dist/server/src/history/services/history.d.ts.map +1 -1
  131. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  132. package/dist/server/src/history/services/utils.d.ts +3 -3
  133. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  134. package/dist/server/src/index.d.ts +4 -4
  135. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  136. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  137. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  138. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  139. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  140. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  141. package/dist/server/src/preview/index.d.ts +4 -0
  142. package/dist/server/src/preview/index.d.ts.map +1 -0
  143. package/dist/server/src/preview/routes/index.d.ts +8 -0
  144. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  145. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  146. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  147. package/dist/server/src/preview/services/index.d.ts +16 -0
  148. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  149. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  150. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  151. package/dist/server/src/preview/services/preview.d.ts +12 -0
  152. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  153. package/dist/server/src/preview/utils.d.ts +19 -0
  154. package/dist/server/src/preview/utils.d.ts.map +1 -0
  155. package/dist/server/src/register.d.ts.map +1 -1
  156. package/dist/server/src/routes/index.d.ts.map +1 -1
  157. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  158. package/dist/server/src/services/document-metadata.d.ts +8 -8
  159. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  160. package/dist/server/src/services/index.d.ts +4 -4
  161. package/dist/server/src/services/index.d.ts.map +1 -1
  162. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  163. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  164. package/dist/server/src/utils/index.d.ts +2 -0
  165. package/dist/server/src/utils/index.d.ts.map +1 -1
  166. package/dist/shared/contracts/collection-types.d.ts +3 -1
  167. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  168. package/dist/shared/contracts/index.d.ts +1 -0
  169. package/dist/shared/contracts/index.d.ts.map +1 -1
  170. package/dist/shared/contracts/preview.d.ts +27 -0
  171. package/dist/shared/contracts/preview.d.ts.map +1 -0
  172. package/dist/shared/index.js +4 -0
  173. package/dist/shared/index.js.map +1 -1
  174. package/dist/shared/index.mjs +4 -0
  175. package/dist/shared/index.mjs.map +1 -1
  176. package/package.json +17 -15
  177. package/dist/_chunks/EditViewPage-B-RJeiJD.js.map +0 -1
  178. package/dist/_chunks/EditViewPage-De8GyU8P.mjs.map +0 -1
  179. package/dist/_chunks/Field-dq8Tg1M_.js.map +0 -1
  180. package/dist/_chunks/Field-pb2o8uBe.mjs.map +0 -1
  181. package/dist/_chunks/Form-DGIf4jQU.js.map +0 -1
  182. package/dist/_chunks/Form-DJn0Dxha.mjs.map +0 -1
  183. package/dist/_chunks/History-BowL3JKP.mjs.map +0 -1
  184. package/dist/_chunks/History-Dh2NEHnR.js.map +0 -1
  185. package/dist/_chunks/ListConfigurationPage-BpVOB-hn.mjs.map +0 -1
  186. package/dist/_chunks/ListConfigurationPage-BxYCWz9e.js.map +0 -1
  187. package/dist/_chunks/ListViewPage-4XsciqHZ.js.map +0 -1
  188. package/dist/_chunks/ListViewPage-CXFUjZQC.mjs.map +0 -1
  189. package/dist/_chunks/Relations-CVNLrn1Y.mjs.map +0 -1
  190. package/dist/_chunks/Relations-DPFCAa7b.js.map +0 -1
  191. package/dist/_chunks/index-C3fJE-1-.js.map +0 -1
  192. package/dist/_chunks/index-DiMrfcfy.mjs.map +0 -1
  193. package/dist/_chunks/relations-CLcOmGO0.mjs.map +0 -1
  194. package/dist/_chunks/relations-DYeotliT.js.map +0 -1
  195. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  196. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  197. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  198. package/strapi-server.js +0 -3
@@ -1,5 +1,5 @@
1
1
  import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
2
- import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
2
+ import { pick, omit, difference, castArray, mergeWith, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
3
3
  import "@strapi/types";
4
4
  import * as yup from "yup";
5
5
  import { scheduleJob } from "node-schedule";
@@ -7,10 +7,10 @@ import isNil from "lodash/isNil";
7
7
  import _, { intersection as intersection$1, difference as difference$1 } from "lodash";
8
8
  import qs from "qs";
9
9
  import slugify from "@sindresorhus/slugify";
10
- const getService$1 = (name) => {
10
+ const getService$2 = (name) => {
11
11
  return strapi.plugin("content-manager").service(name);
12
12
  };
13
- function getService(strapi2, name) {
13
+ function getService$1(strapi2, name) {
14
14
  return strapi2.service(`plugin::content-manager.${name}`);
15
15
  }
16
16
  const historyRestoreVersionSchema = yup.object().shape({
@@ -46,7 +46,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
46
46
  if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
47
47
  throw new errors.ForbiddenError("contentType and documentId are required");
48
48
  }
49
- const permissionChecker2 = getService$1("permission-checker").create({
49
+ const permissionChecker2 = getService$2("permission-checker").create({
50
50
  userAbility: ctx.state.userAbility,
51
51
  model: ctx.query.contentType
52
52
  });
@@ -54,7 +54,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
54
54
  return ctx.forbidden();
55
55
  }
56
56
  const query = await permissionChecker2.sanitizeQuery(ctx.query);
57
- const { results, pagination: pagination2 } = await getService(strapi2, "history").findVersionsPage({
57
+ const { results, pagination: pagination2 } = await getService$1(strapi2, "history").findVersionsPage({
58
58
  query: {
59
59
  ...query,
60
60
  ...getValidPagination({ page: query.page, pageSize: query.pageSize })
@@ -79,14 +79,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
79
79
  async restoreVersion(ctx) {
80
80
  const request = ctx.request;
81
81
  await validateRestoreVersion(request.body, "contentType is required");
82
- const permissionChecker2 = getService$1("permission-checker").create({
82
+ const permissionChecker2 = getService$2("permission-checker").create({
83
83
  userAbility: ctx.state.userAbility,
84
84
  model: request.body.contentType
85
85
  });
86
86
  if (permissionChecker2.cannot.update()) {
87
87
  throw new errors.ForbiddenError();
88
88
  }
89
- const restoredDocument = await getService(strapi2, "history").restoreVersion(
89
+ const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
90
90
  request.params.versionId
91
91
  );
92
92
  return {
@@ -95,7 +95,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
95
95
  }
96
96
  };
97
97
  };
98
- const controllers$1 = {
98
+ const controllers$2 = {
99
99
  "history-version": createHistoryVersionController
100
100
  /**
101
101
  * Casting is needed because the types aren't aware that Strapi supports
@@ -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({
@@ -173,10 +172,11 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
173
172
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
174
173
  };
175
174
  const localesService = strapi2.plugin("i18n")?.service("locales");
175
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
176
176
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
177
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
177
178
  const getLocaleDictionary = async () => {
178
- if (!localesService)
179
- return {};
179
+ if (!localesService) return {};
180
180
  const locales = await localesService.find() || [];
181
181
  return locales.reduce(
182
182
  (acc, locale) => {
@@ -200,6 +200,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
200
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
201
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
202
  };
203
+ const getComponentFields = (componentUID) => {
204
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
205
+ (fieldsAcc, [key, attribute]) => {
206
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
207
+ fieldsAcc.push(key);
208
+ }
209
+ return fieldsAcc;
210
+ },
211
+ []
212
+ );
213
+ };
203
214
  const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
215
  const model = strapi2.getModel(uid2);
205
216
  const attributes = Object.entries(model.attributes);
@@ -223,13 +234,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
223
234
  }
224
235
  case "component": {
225
236
  const populate = getDeepPopulate2(attribute.component);
226
- acc[attributeName] = { populate };
237
+ acc[attributeName] = {
238
+ populate,
239
+ [fieldSelector]: getComponentFields(attribute.component)
240
+ };
227
241
  break;
228
242
  }
229
243
  case "dynamiczone": {
230
244
  const populatedComponents = (attribute.components || []).reduce(
231
245
  (acc2, componentUID) => {
232
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
246
+ acc2[componentUID] = {
247
+ populate: getDeepPopulate2(componentUID),
248
+ [fieldSelector]: getComponentFields(componentUID)
249
+ };
233
250
  return acc2;
234
251
  },
235
252
  {}
@@ -291,6 +308,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
291
308
  getRelationRestoreValue,
292
309
  getMediaRestoreValue,
293
310
  getDefaultLocale,
311
+ isLocalizedContentType,
294
312
  getLocaleDictionary,
295
313
  getRetentionDays,
296
314
  getVersionStatus,
@@ -313,7 +331,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
313
331
  });
314
332
  },
315
333
  async findVersionsPage(params) {
316
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
334
+ const model = strapi2.getModel(params.query.contentType);
335
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
336
+ const defaultLocale = await serviceUtils.getDefaultLocale();
337
+ let locale = null;
338
+ if (isLocalizedContentType) {
339
+ locale = params.query.locale || defaultLocale;
340
+ }
317
341
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
318
342
  query.findPage({
319
343
  ...params.query,
@@ -335,7 +359,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
335
359
  const attributeValue = entry.data[attributeKey];
336
360
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
337
361
  if (attributeSchema.type === "media") {
338
- const permissionChecker2 = getService$1("permission-checker").create({
362
+ const permissionChecker2 = getService$2("permission-checker").create({
339
363
  userAbility: params.state.userAbility,
340
364
  model: "plugin::upload.file"
341
365
  });
@@ -358,7 +382,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
358
382
  if (userToPopulate == null) {
359
383
  return null;
360
384
  }
361
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
385
+ return strapi2.query("admin::user").findOne({
386
+ where: {
387
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
388
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
389
+ }
390
+ });
362
391
  })
363
392
  );
364
393
  return {
@@ -371,7 +400,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
371
400
  [attributeKey]: adminUsers
372
401
  };
373
402
  }
374
- const permissionChecker2 = getService$1("permission-checker").create({
403
+ const permissionChecker2 = getService$2("permission-checker").create({
375
404
  userAbility: params.state.userAbility,
376
405
  model: attributeSchema.target
377
406
  });
@@ -529,11 +558,13 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
529
558
  }
530
559
  const uid2 = context.contentType.uid;
531
560
  const schemas = getSchemas(uid2);
561
+ const model = strapi2.getModel(uid2);
562
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
532
563
  const localeEntries = await strapi2.db.query(uid2).findMany({
533
564
  where: {
534
565
  documentId,
535
- locale: { $in: locales },
536
- publishedAt: null
566
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
567
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
537
568
  },
538
569
  populate: serviceUtils.getDeepPopulate(
539
570
  uid2,
@@ -545,7 +576,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
545
576
  onCommit(async () => {
546
577
  for (const entry of localeEntries) {
547
578
  const status = await serviceUtils.getVersionStatus(uid2, entry);
548
- await getService(strapi2, "history").createVersion({
579
+ await getService$1(strapi2, "history").createVersion({
549
580
  contentType: uid2,
550
581
  data: omit(FIELDS_TO_IGNORE, entry),
551
582
  relatedDocumentId: documentId,
@@ -558,15 +589,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
558
589
  });
559
590
  return result;
560
591
  });
561
- state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
592
+ state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
562
593
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
563
594
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
564
595
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
565
596
  where: {
566
597
  created_at: {
567
- $lt: expirationDate.toISOString()
598
+ $lt: expirationDate
568
599
  }
569
600
  }
601
+ }).catch((error) => {
602
+ if (error instanceof Error) {
603
+ strapi2.log.error("Error deleting expired history versions", error.message);
604
+ }
570
605
  });
571
606
  });
572
607
  state.isInitialized = true;
@@ -578,17 +613,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
578
613
  }
579
614
  };
580
615
  };
581
- const services$1 = {
616
+ const services$2 = {
582
617
  history: createHistoryService,
583
618
  lifecycles: createLifecyclesService
584
619
  };
585
- const info = { pluginName: "content-manager", type: "admin" };
620
+ const info$1 = { pluginName: "content-manager", type: "admin" };
586
621
  const historyVersionRouter = {
587
622
  type: "admin",
588
623
  routes: [
589
624
  {
590
625
  method: "GET",
591
- info,
626
+ info: info$1,
592
627
  path: "/history-versions",
593
628
  handler: "history-version.findMany",
594
629
  config: {
@@ -597,7 +632,7 @@ const historyVersionRouter = {
597
632
  },
598
633
  {
599
634
  method: "PUT",
600
- info,
635
+ info: info$1,
601
636
  path: "/history-versions/:versionId/restore",
602
637
  handler: "history-version.restoreVersion",
603
638
  config: {
@@ -606,7 +641,7 @@ const historyVersionRouter = {
606
641
  }
607
642
  ]
608
643
  };
609
- const routes$1 = {
644
+ const routes$2 = {
610
645
  "history-version": historyVersionRouter
611
646
  };
612
647
  const historyVersion = {
@@ -653,21 +688,21 @@ const historyVersion = {
653
688
  }
654
689
  }
655
690
  };
656
- const getFeature = () => {
691
+ const getFeature$1 = () => {
657
692
  if (strapi.ee.features.isEnabled("cms-content-history")) {
658
693
  return {
659
694
  register({ strapi: strapi2 }) {
660
695
  strapi2.get("models").add(historyVersion);
661
696
  },
662
697
  bootstrap({ strapi: strapi2 }) {
663
- getService(strapi2, "lifecycles").bootstrap();
698
+ getService$1(strapi2, "lifecycles").bootstrap();
664
699
  },
665
700
  destroy({ strapi: strapi2 }) {
666
- getService(strapi2, "lifecycles").destroy();
701
+ getService$1(strapi2, "lifecycles").destroy();
667
702
  },
668
- controllers: controllers$1,
669
- services: services$1,
670
- routes: routes$1
703
+ controllers: controllers$2,
704
+ services: services$2,
705
+ routes: routes$2
671
706
  };
672
707
  }
673
708
  return {
@@ -676,9 +711,201 @@ const getFeature = () => {
676
711
  }
677
712
  };
678
713
  };
679
- const history = getFeature();
714
+ const history = getFeature$1();
715
+ const info = { pluginName: "content-manager", type: "admin" };
716
+ const previewRouter = {
717
+ type: "admin",
718
+ routes: [
719
+ {
720
+ method: "GET",
721
+ info,
722
+ path: "/preview/url/:contentType",
723
+ handler: "preview.getPreviewUrl",
724
+ config: {
725
+ policies: ["admin::isAuthenticatedAdmin"]
726
+ }
727
+ }
728
+ ]
729
+ };
730
+ const routes$1 = {
731
+ preview: previewRouter
732
+ };
733
+ function getService(strapi2, name) {
734
+ return strapi2.service(`plugin::content-manager.${name}`);
735
+ }
736
+ const getPreviewUrlSchema = yup.object().shape({
737
+ // Will be undefined for single types
738
+ documentId: yup.string(),
739
+ locale: yup.string().nullable(),
740
+ status: yup.string()
741
+ }).required();
742
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
743
+ await validateYupSchema(getPreviewUrlSchema)(params);
744
+ const newParams = pick(["documentId", "locale", "status"], params);
745
+ const model = strapi2.getModel(uid2);
746
+ if (!model || model.modelType !== "contentType") {
747
+ throw new errors.ValidationError("Invalid content type");
748
+ }
749
+ const isSingleType = model?.kind === "singleType";
750
+ if (!isSingleType && !params.documentId) {
751
+ throw new errors.ValidationError("documentId is required for Collection Types");
752
+ }
753
+ if (isSingleType) {
754
+ const doc = await strapi2.documents(uid2).findFirst();
755
+ if (!doc) {
756
+ throw new errors.NotFoundError("Document not found");
757
+ }
758
+ newParams.documentId = doc?.documentId;
759
+ }
760
+ if (!newParams.status) {
761
+ const isDPEnabled = model?.options?.draftAndPublish;
762
+ newParams.status = isDPEnabled ? "draft" : "published";
763
+ }
764
+ return newParams;
765
+ };
766
+ const createPreviewController = () => {
767
+ return {
768
+ /**
769
+ * Transforms an entry into a preview URL, so that it can be previewed
770
+ * in the Content Manager.
771
+ */
772
+ async getPreviewUrl(ctx) {
773
+ const uid2 = ctx.params.contentType;
774
+ const query = ctx.request.query;
775
+ const params = await validatePreviewUrl(strapi, uid2, query);
776
+ const previewService = getService(strapi, "preview");
777
+ const url = await previewService.getPreviewUrl(uid2, params);
778
+ if (!url) {
779
+ ctx.status = 204;
780
+ }
781
+ return {
782
+ data: { url }
783
+ };
784
+ }
785
+ };
786
+ };
787
+ const controllers$1 = {
788
+ preview: createPreviewController
789
+ /**
790
+ * Casting is needed because the types aren't aware that Strapi supports
791
+ * passing a controller factory as the value, instead of a controller object directly
792
+ */
793
+ };
794
+ const createPreviewService = ({ strapi: strapi2 }) => {
795
+ const config = getService(strapi2, "preview-config");
796
+ return {
797
+ async getPreviewUrl(uid2, params) {
798
+ const handler = config.getPreviewHandler();
799
+ try {
800
+ return handler(uid2, params);
801
+ } catch (error) {
802
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
803
+ throw new errors.ApplicationError("Failed to get preview URL");
804
+ }
805
+ return;
806
+ }
807
+ };
808
+ };
809
+ const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
810
+ const middlewares = strapi.config.get("middlewares");
811
+ const configuredMiddlewares = middlewares.map((currentMiddleware) => {
812
+ if (currentMiddleware === middleware.name) {
813
+ return middleware;
814
+ }
815
+ if (currentMiddleware.name === middleware.name) {
816
+ return mergeWith(
817
+ (objValue, srcValue) => {
818
+ if (Array.isArray(objValue)) {
819
+ return objValue.concat(srcValue);
820
+ }
821
+ return void 0;
822
+ },
823
+ currentMiddleware,
824
+ middleware
825
+ );
826
+ }
827
+ return currentMiddleware;
828
+ });
829
+ strapi.config.set("middlewares", configuredMiddlewares);
830
+ };
831
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
832
+ return {
833
+ register() {
834
+ if (!this.isEnabled()) {
835
+ return;
836
+ }
837
+ const config = strapi2.config.get("admin.preview");
838
+ if (config.config?.allowedOrigins) {
839
+ extendMiddlewareConfiguration({
840
+ name: "strapi::security",
841
+ config: {
842
+ contentSecurityPolicy: {
843
+ directives: {
844
+ "frame-src": config.config.allowedOrigins
845
+ }
846
+ }
847
+ }
848
+ });
849
+ }
850
+ },
851
+ isEnabled() {
852
+ const config = strapi2.config.get("admin.preview");
853
+ if (!config) {
854
+ return false;
855
+ }
856
+ return config?.enabled ?? true;
857
+ },
858
+ /**
859
+ * Validate if the configuration is valid
860
+ */
861
+ validate() {
862
+ if (!this.isEnabled()) {
863
+ return;
864
+ }
865
+ const handler = this.getPreviewHandler();
866
+ if (typeof handler !== "function") {
867
+ throw new errors.ValidationError(
868
+ "Preview configuration is invalid. Handler must be a function"
869
+ );
870
+ }
871
+ },
872
+ /**
873
+ * Utility to get the preview handler from the configuration
874
+ */
875
+ getPreviewHandler() {
876
+ const config = strapi2.config.get("admin.preview");
877
+ const emptyHandler = () => {
878
+ return void 0;
879
+ };
880
+ if (!this.isEnabled()) {
881
+ return emptyHandler;
882
+ }
883
+ return config?.config?.handler || emptyHandler;
884
+ }
885
+ };
886
+ };
887
+ const services$1 = {
888
+ preview: createPreviewService,
889
+ "preview-config": createPreviewConfigService
890
+ };
891
+ const getFeature = () => {
892
+ return {
893
+ register() {
894
+ const config = getService(strapi, "preview-config");
895
+ config.validate();
896
+ config.register();
897
+ },
898
+ bootstrap() {
899
+ },
900
+ routes: routes$1,
901
+ controllers: controllers$1,
902
+ services: services$1
903
+ };
904
+ };
905
+ const preview = getFeature();
680
906
  const register = async ({ strapi: strapi2 }) => {
681
907
  await history.register?.({ strapi: strapi2 });
908
+ await preview.register?.({ strapi: strapi2 });
682
909
  };
683
910
  const ALLOWED_WEBHOOK_EVENTS = {
684
911
  ENTRY_PUBLISH: "entry.publish",
@@ -688,11 +915,12 @@ const bootstrap = async () => {
688
915
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
689
916
  strapi.get("webhookStore").addAllowedEvent(key, value);
690
917
  });
691
- getService$1("field-sizes").setCustomFieldInputSizes();
692
- await getService$1("components").syncConfigurations();
693
- await getService$1("content-types").syncConfigurations();
694
- await getService$1("permission").registerPermissions();
918
+ getService$2("field-sizes").setCustomFieldInputSizes();
919
+ await getService$2("components").syncConfigurations();
920
+ await getService$2("content-types").syncConfigurations();
921
+ await getService$2("permission").registerPermissions();
695
922
  await history.bootstrap?.({ strapi });
923
+ await preview.bootstrap?.({ strapi });
696
924
  };
697
925
  const destroy = async ({ strapi: strapi2 }) => {
698
926
  await history.destroy?.({ strapi: strapi2 });
@@ -1182,7 +1410,8 @@ const admin = {
1182
1410
  };
1183
1411
  const routes = {
1184
1412
  admin,
1185
- ...history.routes ? history.routes : {}
1413
+ ...history.routes ? history.routes : {},
1414
+ ...preview.routes ? preview.routes : {}
1186
1415
  };
1187
1416
  const hasPermissionsSchema = yup$1.object({
1188
1417
  actions: yup$1.array().of(yup$1.string()),
@@ -1245,8 +1474,7 @@ const isSortable = (schema, name) => {
1245
1474
  if (!_.has(schema.attributes, name)) {
1246
1475
  return false;
1247
1476
  }
1248
- if (schema.modelType === "component" && name === "id")
1249
- return false;
1477
+ if (schema.modelType === "component" && name === "id") return false;
1250
1478
  const attribute = schema.attributes[name];
1251
1479
  if (NON_SORTABLES.includes(attribute.type)) {
1252
1480
  return false;
@@ -1391,8 +1619,7 @@ const createDefaultSettings = async (schema) => {
1391
1619
  };
1392
1620
  };
1393
1621
  const syncSettings = async (configuration, schema) => {
1394
- if (isEmpty(configuration.settings))
1395
- return createDefaultSettings(schema);
1622
+ if (isEmpty(configuration.settings)) return createDefaultSettings(schema);
1396
1623
  const defaultField = getDefaultMainField(schema);
1397
1624
  const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
1398
1625
  return {
@@ -1439,7 +1666,7 @@ const createMetadasSchema = (schema) => {
1439
1666
  if (!value) {
1440
1667
  return yup$1.string();
1441
1668
  }
1442
- const targetSchema = getService$1("content-types").findContentType(
1669
+ const targetSchema = getService$2("content-types").findContentType(
1443
1670
  schema.attributes[key].targetModel
1444
1671
  );
1445
1672
  if (!targetSchema) {
@@ -1568,8 +1795,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1568
1795
  }
1569
1796
  switch (attribute.type) {
1570
1797
  case "relation": {
1571
- if (canCreate(attributePath))
1572
- return body2;
1798
+ if (canCreate(attributePath)) return body2;
1573
1799
  return set(attributePath, { set: [] }, body2);
1574
1800
  }
1575
1801
  case "component": {
@@ -1579,8 +1805,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1579
1805
  ]);
1580
1806
  }
1581
1807
  default: {
1582
- if (canCreate(attributePath))
1583
- return body2;
1808
+ if (canCreate(attributePath)) return body2;
1584
1809
  return set(attributePath, null, body2);
1585
1810
  }
1586
1811
  }
@@ -1608,7 +1833,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1608
1833
  }
1609
1834
  };
1610
1835
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1611
- const documentMetadata2 = getService$1("document-metadata");
1836
+ const documentMetadata2 = getService$2("document-metadata");
1612
1837
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1613
1838
  let {
1614
1839
  meta: { availableLocales, availableStatus }
@@ -1634,8 +1859,8 @@ const createDocument = async (ctx, opts) => {
1634
1859
  const { userAbility, user } = ctx.state;
1635
1860
  const { model } = ctx.params;
1636
1861
  const { body } = ctx.request;
1637
- const documentManager2 = getService$1("document-manager");
1638
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1862
+ const documentManager2 = getService$2("document-manager");
1863
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1639
1864
  if (permissionChecker2.cannot.create()) {
1640
1865
  throw new errors.ForbiddenError();
1641
1866
  }
@@ -1655,13 +1880,13 @@ const updateDocument = async (ctx, opts) => {
1655
1880
  const { userAbility, user } = ctx.state;
1656
1881
  const { id, model } = ctx.params;
1657
1882
  const { body } = ctx.request;
1658
- const documentManager2 = getService$1("document-manager");
1659
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1883
+ const documentManager2 = getService$2("document-manager");
1884
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1660
1885
  if (permissionChecker2.cannot.update()) {
1661
1886
  throw new errors.ForbiddenError();
1662
1887
  }
1663
1888
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1664
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1889
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1665
1890
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1666
1891
  const [documentVersion, documentExists] = await Promise.all([
1667
1892
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1678,7 +1903,7 @@ const updateDocument = async (ctx, opts) => {
1678
1903
  throw new errors.ForbiddenError();
1679
1904
  }
1680
1905
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1681
- const setCreator = setCreatorFields({ user, isEdition: true });
1906
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1682
1907
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1683
1908
  const sanitizedBody = await sanitizeFn(body);
1684
1909
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1692,14 +1917,14 @@ const collectionTypes = {
1692
1917
  const { userAbility } = ctx.state;
1693
1918
  const { model } = ctx.params;
1694
1919
  const { query } = ctx.request;
1695
- const documentMetadata2 = getService$1("document-metadata");
1696
- const documentManager2 = getService$1("document-manager");
1697
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1920
+ const documentMetadata2 = getService$2("document-metadata");
1921
+ const documentManager2 = getService$2("document-manager");
1922
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1698
1923
  if (permissionChecker2.cannot.read()) {
1699
1924
  return ctx.forbidden();
1700
1925
  }
1701
1926
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1702
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1927
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1703
1928
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1704
1929
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1705
1930
  { ...permissionQuery, populate, locale, status },
@@ -1728,13 +1953,13 @@ const collectionTypes = {
1728
1953
  async findOne(ctx) {
1729
1954
  const { userAbility } = ctx.state;
1730
1955
  const { model, id } = ctx.params;
1731
- const documentManager2 = getService$1("document-manager");
1732
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1956
+ const documentManager2 = getService$2("document-manager");
1957
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1733
1958
  if (permissionChecker2.cannot.read()) {
1734
1959
  return ctx.forbidden();
1735
1960
  }
1736
1961
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1737
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1962
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1738
1963
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1739
1964
  const version = await documentManager2.findOne(id, model, {
1740
1965
  populate,
@@ -1750,7 +1975,7 @@ const collectionTypes = {
1750
1975
  permissionChecker2,
1751
1976
  model,
1752
1977
  // @ts-expect-error TODO: fix
1753
- { id, locale, publishedAt: null },
1978
+ { documentId: id, locale, publishedAt: null },
1754
1979
  { availableLocales: true, availableStatus: false }
1755
1980
  );
1756
1981
  ctx.body = { data: {}, meta };
@@ -1765,7 +1990,7 @@ const collectionTypes = {
1765
1990
  async create(ctx) {
1766
1991
  const { userAbility } = ctx.state;
1767
1992
  const { model } = ctx.params;
1768
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1993
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1769
1994
  const [totalEntries, document] = await Promise.all([
1770
1995
  strapi.db.query(model).count(),
1771
1996
  createDocument(ctx)
@@ -1786,7 +2011,7 @@ const collectionTypes = {
1786
2011
  async update(ctx) {
1787
2012
  const { userAbility } = ctx.state;
1788
2013
  const { model } = ctx.params;
1789
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2014
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1790
2015
  const updatedVersion = await updateDocument(ctx);
1791
2016
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1792
2017
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1795,13 +2020,13 @@ const collectionTypes = {
1795
2020
  const { userAbility, user } = ctx.state;
1796
2021
  const { model, sourceId: id } = ctx.params;
1797
2022
  const { body } = ctx.request;
1798
- const documentManager2 = getService$1("document-manager");
1799
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2023
+ const documentManager2 = getService$2("document-manager");
2024
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1800
2025
  if (permissionChecker2.cannot.create()) {
1801
2026
  return ctx.forbidden();
1802
2027
  }
1803
2028
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1804
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2029
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1805
2030
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1806
2031
  const document = await documentManager2.findOne(id, model, {
1807
2032
  populate,
@@ -1840,13 +2065,13 @@ const collectionTypes = {
1840
2065
  async delete(ctx) {
1841
2066
  const { userAbility } = ctx.state;
1842
2067
  const { id, model } = ctx.params;
1843
- const documentManager2 = getService$1("document-manager");
1844
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2068
+ const documentManager2 = getService$2("document-manager");
2069
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1845
2070
  if (permissionChecker2.cannot.delete()) {
1846
2071
  return ctx.forbidden();
1847
2072
  }
1848
2073
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1849
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2074
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1850
2075
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1851
2076
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1852
2077
  if (documentLocales.length === 0) {
@@ -1868,14 +2093,14 @@ const collectionTypes = {
1868
2093
  const { userAbility } = ctx.state;
1869
2094
  const { id, model } = ctx.params;
1870
2095
  const { body } = ctx.request;
1871
- const documentManager2 = getService$1("document-manager");
1872
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2096
+ const documentManager2 = getService$2("document-manager");
2097
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1873
2098
  if (permissionChecker2.cannot.publish()) {
1874
2099
  return ctx.forbidden();
1875
2100
  }
1876
2101
  const publishedDocument = await strapi.db.transaction(async () => {
1877
2102
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1878
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2103
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1879
2104
  let document;
1880
2105
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1881
2106
  const isCreate = isNil$1(id);
@@ -1887,11 +2112,17 @@ const collectionTypes = {
1887
2112
  }
1888
2113
  const isUpdate = !isCreate;
1889
2114
  if (isUpdate) {
1890
- document = await documentManager2.findOne(id, model, { populate, locale });
1891
- if (!document) {
2115
+ const documentExists = documentManager2.exists(model, id);
2116
+ if (!documentExists) {
1892
2117
  throw new errors.NotFoundError("Document not found");
1893
2118
  }
1894
- if (permissionChecker2.can.update(document)) {
2119
+ document = await documentManager2.findOne(id, model, { populate, locale });
2120
+ if (!document) {
2121
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2122
+ throw new errors.ForbiddenError();
2123
+ }
2124
+ document = await updateDocument(ctx);
2125
+ } else if (permissionChecker2.can.update(document)) {
1895
2126
  await updateDocument(ctx);
1896
2127
  }
1897
2128
  }
@@ -1917,13 +2148,13 @@ const collectionTypes = {
1917
2148
  const { body } = ctx.request;
1918
2149
  const { documentIds } = body;
1919
2150
  await validateBulkActionInput(body);
1920
- const documentManager2 = getService$1("document-manager");
1921
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2151
+ const documentManager2 = getService$2("document-manager");
2152
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1922
2153
  if (permissionChecker2.cannot.publish()) {
1923
2154
  return ctx.forbidden();
1924
2155
  }
1925
2156
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1926
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2157
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1927
2158
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1928
2159
  allowMultipleLocales: true
1929
2160
  });
@@ -1948,12 +2179,14 @@ const collectionTypes = {
1948
2179
  const { body } = ctx.request;
1949
2180
  const { documentIds } = body;
1950
2181
  await validateBulkActionInput(body);
1951
- const documentManager2 = getService$1("document-manager");
1952
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2182
+ const documentManager2 = getService$2("document-manager");
2183
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1953
2184
  if (permissionChecker2.cannot.unpublish()) {
1954
2185
  return ctx.forbidden();
1955
2186
  }
1956
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2187
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2188
+ allowMultipleLocales: true
2189
+ });
1957
2190
  const entityPromises = documentIds.map(
1958
2191
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1959
2192
  );
@@ -1976,8 +2209,8 @@ const collectionTypes = {
1976
2209
  const {
1977
2210
  body: { discardDraft, ...body }
1978
2211
  } = ctx.request;
1979
- const documentManager2 = getService$1("document-manager");
1980
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2212
+ const documentManager2 = getService$2("document-manager");
2213
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1981
2214
  if (permissionChecker2.cannot.unpublish()) {
1982
2215
  return ctx.forbidden();
1983
2216
  }
@@ -1985,7 +2218,7 @@ const collectionTypes = {
1985
2218
  return ctx.forbidden();
1986
2219
  }
1987
2220
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1988
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2221
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1989
2222
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1990
2223
  const document = await documentManager2.findOne(id, model, {
1991
2224
  populate,
@@ -2016,13 +2249,13 @@ const collectionTypes = {
2016
2249
  const { userAbility } = ctx.state;
2017
2250
  const { id, model } = ctx.params;
2018
2251
  const { body } = ctx.request;
2019
- const documentManager2 = getService$1("document-manager");
2020
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2252
+ const documentManager2 = getService$2("document-manager");
2253
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2021
2254
  if (permissionChecker2.cannot.discard()) {
2022
2255
  return ctx.forbidden();
2023
2256
  }
2024
2257
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2025
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2258
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2026
2259
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2027
2260
  const document = await documentManager2.findOne(id, model, {
2028
2261
  populate,
@@ -2047,13 +2280,13 @@ const collectionTypes = {
2047
2280
  const { query, body } = ctx.request;
2048
2281
  const { documentIds } = body;
2049
2282
  await validateBulkActionInput(body);
2050
- const documentManager2 = getService$1("document-manager");
2051
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2283
+ const documentManager2 = getService$2("document-manager");
2284
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2052
2285
  if (permissionChecker2.cannot.delete()) {
2053
2286
  return ctx.forbidden();
2054
2287
  }
2055
2288
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2056
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2289
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2057
2290
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2058
2291
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2059
2292
  populate,
@@ -2074,13 +2307,13 @@ const collectionTypes = {
2074
2307
  async countDraftRelations(ctx) {
2075
2308
  const { userAbility } = ctx.state;
2076
2309
  const { model, id } = ctx.params;
2077
- const documentManager2 = getService$1("document-manager");
2078
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2310
+ const documentManager2 = getService$2("document-manager");
2311
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2079
2312
  if (permissionChecker2.cannot.read()) {
2080
2313
  return ctx.forbidden();
2081
2314
  }
2082
2315
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2083
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2316
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2084
2317
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2085
2318
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2086
2319
  if (!entity) {
@@ -2099,8 +2332,8 @@ const collectionTypes = {
2099
2332
  const ids = ctx.request.query.documentIds;
2100
2333
  const locale = ctx.request.query.locale;
2101
2334
  const { model } = ctx.params;
2102
- const documentManager2 = getService$1("document-manager");
2103
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2335
+ const documentManager2 = getService$2("document-manager");
2336
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2104
2337
  if (permissionChecker2.cannot.read()) {
2105
2338
  return ctx.forbidden();
2106
2339
  }
@@ -2124,13 +2357,13 @@ const collectionTypes = {
2124
2357
  };
2125
2358
  const components$1 = {
2126
2359
  findComponents(ctx) {
2127
- const components2 = getService$1("components").findAllComponents();
2128
- const { toDto } = getService$1("data-mapper");
2360
+ const components2 = getService$2("components").findAllComponents();
2361
+ const { toDto } = getService$2("data-mapper");
2129
2362
  ctx.body = { data: components2.map(toDto) };
2130
2363
  },
2131
2364
  async findComponentConfiguration(ctx) {
2132
2365
  const { uid: uid2 } = ctx.params;
2133
- const componentService = getService$1("components");
2366
+ const componentService = getService$2("components");
2134
2367
  const component = componentService.findComponent(uid2);
2135
2368
  if (!component) {
2136
2369
  return ctx.notFound("component.notFound");
@@ -2147,7 +2380,7 @@ const components$1 = {
2147
2380
  async updateComponentConfiguration(ctx) {
2148
2381
  const { uid: uid2 } = ctx.params;
2149
2382
  const { body } = ctx.request;
2150
- const componentService = getService$1("components");
2383
+ const componentService = getService$2("components");
2151
2384
  const component = componentService.findComponent(uid2);
2152
2385
  if (!component) {
2153
2386
  return ctx.notFound("component.notFound");
@@ -2181,12 +2414,12 @@ const contentTypes = {
2181
2414
  } catch (error) {
2182
2415
  return ctx.send({ error }, 400);
2183
2416
  }
2184
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2185
- const { toDto } = getService$1("data-mapper");
2417
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2418
+ const { toDto } = getService$2("data-mapper");
2186
2419
  ctx.body = { data: contentTypes2.map(toDto) };
2187
2420
  },
2188
2421
  async findContentTypesSettings(ctx) {
2189
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2422
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2190
2423
  const contentTypes2 = await findAllContentTypes();
2191
2424
  const configurations = await Promise.all(
2192
2425
  contentTypes2.map(async (contentType) => {
@@ -2200,7 +2433,7 @@ const contentTypes = {
2200
2433
  },
2201
2434
  async findContentTypeConfiguration(ctx) {
2202
2435
  const { uid: uid2 } = ctx.params;
2203
- const contentTypeService = getService$1("content-types");
2436
+ const contentTypeService = getService$2("content-types");
2204
2437
  const contentType = await contentTypeService.findContentType(uid2);
2205
2438
  if (!contentType) {
2206
2439
  return ctx.notFound("contentType.notFound");
@@ -2222,13 +2455,13 @@ const contentTypes = {
2222
2455
  const { userAbility } = ctx.state;
2223
2456
  const { uid: uid2 } = ctx.params;
2224
2457
  const { body } = ctx.request;
2225
- const contentTypeService = getService$1("content-types");
2226
- const metricsService = getService$1("metrics");
2458
+ const contentTypeService = getService$2("content-types");
2459
+ const metricsService = getService$2("metrics");
2227
2460
  const contentType = await contentTypeService.findContentType(uid2);
2228
2461
  if (!contentType) {
2229
2462
  return ctx.notFound("contentType.notFound");
2230
2463
  }
2231
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2464
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2232
2465
  return ctx.forbidden();
2233
2466
  }
2234
2467
  let input;
@@ -2261,10 +2494,10 @@ const contentTypes = {
2261
2494
  };
2262
2495
  const init = {
2263
2496
  getInitData(ctx) {
2264
- const { toDto } = getService$1("data-mapper");
2265
- const { findAllComponents } = getService$1("components");
2266
- const { getAllFieldSizes } = getService$1("field-sizes");
2267
- const { findAllContentTypes } = getService$1("content-types");
2497
+ const { toDto } = getService$2("data-mapper");
2498
+ const { findAllComponents } = getService$2("components");
2499
+ const { getAllFieldSizes } = getService$2("field-sizes");
2500
+ const { findAllContentTypes } = getService$2("content-types");
2268
2501
  ctx.body = {
2269
2502
  data: {
2270
2503
  fieldSizes: getAllFieldSizes(),
@@ -2300,7 +2533,7 @@ const addFiltersClause = (params, filtersClause) => {
2300
2533
  params.filters.$and.push(filtersClause);
2301
2534
  };
2302
2535
  const sanitizeMainField = (model, mainField, userAbility) => {
2303
- const permissionChecker2 = getService$1("permission-checker").create({
2536
+ const permissionChecker2 = getService$2("permission-checker").create({
2304
2537
  userAbility,
2305
2538
  model: model.uid
2306
2539
  });
@@ -2314,15 +2547,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2314
2547
  }
2315
2548
  return mainField;
2316
2549
  };
2317
- const addStatusToRelations = async (uid2, relations2) => {
2318
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2550
+ const addStatusToRelations = async (targetUid, relations2) => {
2551
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2552
+ return relations2;
2553
+ }
2554
+ const documentMetadata2 = getService$2("document-metadata");
2555
+ if (!relations2.length) {
2319
2556
  return relations2;
2320
2557
  }
2321
- const documentMetadata2 = getService$1("document-metadata");
2322
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2558
+ const firstRelation = relations2[0];
2559
+ const filters = {
2560
+ documentId: { $in: relations2.map((r) => r.documentId) },
2561
+ // NOTE: find the "opposite" status
2562
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2563
+ };
2564
+ const availableStatus = await strapi.query(targetUid).findMany({
2565
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2566
+ filters
2567
+ });
2323
2568
  return relations2.map((relation) => {
2324
- const availableStatuses = documentsAvailableStatus.filter(
2325
- (availableDocument) => availableDocument.documentId === relation.documentId
2569
+ const availableStatuses = availableStatus.filter(
2570
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2326
2571
  );
2327
2572
  return {
2328
2573
  ...relation,
@@ -2343,11 +2588,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2343
2588
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2344
2589
  const isSourceLocalized = isLocalized(sourceModel);
2345
2590
  const isTargetLocalized = isLocalized(targetModel);
2346
- let validatedLocale = locale;
2347
- if (!targetModel || !isTargetLocalized)
2348
- validatedLocale = void 0;
2349
2591
  return {
2350
- locale: validatedLocale,
2592
+ locale,
2351
2593
  isSourceLocalized,
2352
2594
  isTargetLocalized
2353
2595
  };
@@ -2356,8 +2598,7 @@ const validateStatus = (sourceUid, status) => {
2356
2598
  const sourceModel = strapi.getModel(sourceUid);
2357
2599
  const isDP = contentTypes$1.hasDraftAndPublish;
2358
2600
  const isSourceDP = isDP(sourceModel);
2359
- if (!isSourceDP)
2360
- return { status: void 0 };
2601
+ if (!isSourceDP) return { status: void 0 };
2361
2602
  switch (status) {
2362
2603
  case "published":
2363
2604
  return { status: "published" };
@@ -2387,7 +2628,7 @@ const relations = {
2387
2628
  ctx.request?.query?.locale
2388
2629
  );
2389
2630
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2390
- const permissionChecker2 = getService$1("permission-checker").create({
2631
+ const permissionChecker2 = getService$2("permission-checker").create({
2391
2632
  userAbility,
2392
2633
  model
2393
2634
  });
@@ -2412,7 +2653,7 @@ const relations = {
2412
2653
  where.id = id;
2413
2654
  }
2414
2655
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2415
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2656
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2416
2657
  const currentEntity = await strapi.db.query(model).findOne({
2417
2658
  where,
2418
2659
  populate
@@ -2427,7 +2668,7 @@ const relations = {
2427
2668
  }
2428
2669
  entryId = currentEntity.id;
2429
2670
  }
2430
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2671
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2431
2672
  const targetSchema = strapi.getModel(targetUid);
2432
2673
  const mainField = flow(
2433
2674
  prop(`metadatas.${targetField}.edit.mainField`),
@@ -2450,7 +2691,7 @@ const relations = {
2450
2691
  attribute,
2451
2692
  fieldsToSelect,
2452
2693
  mainField,
2453
- source: { schema: sourceSchema },
2694
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2454
2695
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2455
2696
  sourceSchema,
2456
2697
  targetSchema,
@@ -2472,7 +2713,8 @@ const relations = {
2472
2713
  fieldsToSelect,
2473
2714
  mainField,
2474
2715
  source: {
2475
- schema: { uid: sourceUid, modelType: sourceModelType }
2716
+ schema: { uid: sourceUid, modelType: sourceModelType },
2717
+ isLocalized: isSourceLocalized
2476
2718
  },
2477
2719
  target: {
2478
2720
  schema: { uid: targetUid },
@@ -2480,7 +2722,7 @@ const relations = {
2480
2722
  }
2481
2723
  } = await this.extractAndValidateRequestInfo(ctx, id);
2482
2724
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2483
- const permissionChecker2 = getService$1("permission-checker").create({
2725
+ const permissionChecker2 = getService$2("permission-checker").create({
2484
2726
  userAbility: ctx.state.userAbility,
2485
2727
  model: targetUid
2486
2728
  });
@@ -2510,12 +2752,16 @@ const relations = {
2510
2752
  } else {
2511
2753
  where.id = id;
2512
2754
  }
2513
- if (status) {
2514
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2755
+ const publishedAt = getPublishedAtClause(status, targetUid);
2756
+ if (!isEmpty(publishedAt)) {
2757
+ where[`${alias}.published_at`] = publishedAt;
2515
2758
  }
2516
- if (filterByLocale) {
2759
+ if (isTargetLocalized && locale) {
2517
2760
  where[`${alias}.locale`] = locale;
2518
2761
  }
2762
+ if (isSourceLocalized && locale) {
2763
+ where.locale = locale;
2764
+ }
2519
2765
  if ((idsToInclude?.length ?? 0) !== 0) {
2520
2766
  where[`${alias}.id`].$notIn = idsToInclude;
2521
2767
  }
@@ -2533,7 +2779,8 @@ const relations = {
2533
2779
  id: { $notIn: uniq(idsToOmit) }
2534
2780
  });
2535
2781
  }
2536
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2782
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2783
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2537
2784
  ctx.body = {
2538
2785
  ...res,
2539
2786
  results: await addStatusToRelations(targetUid, res.results)
@@ -2548,21 +2795,33 @@ const relations = {
2548
2795
  attribute,
2549
2796
  targetField,
2550
2797
  fieldsToSelect,
2551
- source: {
2552
- schema: { uid: sourceUid }
2553
- },
2554
- target: {
2555
- schema: { uid: targetUid }
2556
- }
2798
+ status,
2799
+ source: { schema: sourceSchema },
2800
+ target: { schema: targetSchema }
2557
2801
  } = await this.extractAndValidateRequestInfo(ctx, id);
2558
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2802
+ const { uid: sourceUid } = sourceSchema;
2803
+ const { uid: targetUid } = targetSchema;
2804
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2559
2805
  const dbQuery = strapi.db.query(sourceUid);
2560
2806
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2807
+ const filters = {};
2808
+ if (sourceSchema?.options?.draftAndPublish) {
2809
+ if (targetSchema?.options?.draftAndPublish) {
2810
+ if (status === "published") {
2811
+ filters.publishedAt = { $notNull: true };
2812
+ } else {
2813
+ filters.publishedAt = { $null: true };
2814
+ }
2815
+ }
2816
+ } else if (targetSchema?.options?.draftAndPublish) {
2817
+ filters.publishedAt = { $null: true };
2818
+ }
2561
2819
  const res = await loadRelations({ id: entryId }, targetField, {
2562
- select: ["id", "documentId", "locale", "publishedAt"],
2820
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2563
2821
  ordering: "desc",
2564
2822
  page: ctx.request.query.page,
2565
- pageSize: ctx.request.query.pageSize
2823
+ pageSize: ctx.request.query.pageSize,
2824
+ filters
2566
2825
  });
2567
2826
  const loadedIds = res.results.map((item) => item.id);
2568
2827
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2583,10 +2842,10 @@ const relations = {
2583
2842
  }
2584
2843
  };
2585
2844
  const buildPopulateFromQuery = async (query, model) => {
2586
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2845
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2587
2846
  };
2588
2847
  const findDocument = async (query, uid2, opts = {}) => {
2589
- const documentManager2 = getService$1("document-manager");
2848
+ const documentManager2 = getService$2("document-manager");
2590
2849
  const populate = await buildPopulateFromQuery(query, uid2);
2591
2850
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2592
2851
  };
@@ -2594,8 +2853,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2594
2853
  const { user, userAbility } = ctx.state;
2595
2854
  const { model } = ctx.params;
2596
2855
  const { body, query } = ctx.request;
2597
- const documentManager2 = getService$1("document-manager");
2598
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2856
+ const documentManager2 = getService$2("document-manager");
2857
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2599
2858
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2600
2859
  throw new errors.ForbiddenError();
2601
2860
  }
@@ -2636,7 +2895,7 @@ const singleTypes = {
2636
2895
  const { userAbility } = ctx.state;
2637
2896
  const { model } = ctx.params;
2638
2897
  const { query = {} } = ctx.request;
2639
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2898
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2640
2899
  if (permissionChecker2.cannot.read()) {
2641
2900
  return ctx.forbidden();
2642
2901
  }
@@ -2655,7 +2914,7 @@ const singleTypes = {
2655
2914
  permissionChecker2,
2656
2915
  model,
2657
2916
  // @ts-expect-error - fix types
2658
- { id: document.documentId, locale, publishedAt: null },
2917
+ { documentId: document.documentId, locale, publishedAt: null },
2659
2918
  { availableLocales: true, availableStatus: false }
2660
2919
  );
2661
2920
  ctx.body = { data: {}, meta };
@@ -2670,7 +2929,7 @@ const singleTypes = {
2670
2929
  async createOrUpdate(ctx) {
2671
2930
  const { userAbility } = ctx.state;
2672
2931
  const { model } = ctx.params;
2673
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2932
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2674
2933
  const document = await createOrUpdateDocument(ctx);
2675
2934
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2676
2935
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2679,8 +2938,8 @@ const singleTypes = {
2679
2938
  const { userAbility } = ctx.state;
2680
2939
  const { model } = ctx.params;
2681
2940
  const { query = {} } = ctx.request;
2682
- const documentManager2 = getService$1("document-manager");
2683
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2941
+ const documentManager2 = getService$2("document-manager");
2942
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2684
2943
  if (permissionChecker2.cannot.delete()) {
2685
2944
  return ctx.forbidden();
2686
2945
  }
@@ -2708,8 +2967,8 @@ const singleTypes = {
2708
2967
  const { userAbility } = ctx.state;
2709
2968
  const { model } = ctx.params;
2710
2969
  const { query = {} } = ctx.request;
2711
- const documentManager2 = getService$1("document-manager");
2712
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2970
+ const documentManager2 = getService$2("document-manager");
2971
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2713
2972
  if (permissionChecker2.cannot.publish()) {
2714
2973
  return ctx.forbidden();
2715
2974
  }
@@ -2737,8 +2996,8 @@ const singleTypes = {
2737
2996
  body: { discardDraft, ...body },
2738
2997
  query = {}
2739
2998
  } = ctx.request;
2740
- const documentManager2 = getService$1("document-manager");
2741
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2999
+ const documentManager2 = getService$2("document-manager");
3000
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2742
3001
  if (permissionChecker2.cannot.unpublish()) {
2743
3002
  return ctx.forbidden();
2744
3003
  }
@@ -2772,8 +3031,8 @@ const singleTypes = {
2772
3031
  const { userAbility } = ctx.state;
2773
3032
  const { model } = ctx.params;
2774
3033
  const { body, query = {} } = ctx.request;
2775
- const documentManager2 = getService$1("document-manager");
2776
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3034
+ const documentManager2 = getService$2("document-manager");
3035
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2777
3036
  if (permissionChecker2.cannot.discard()) {
2778
3037
  return ctx.forbidden();
2779
3038
  }
@@ -2796,8 +3055,8 @@ const singleTypes = {
2796
3055
  const { userAbility } = ctx.state;
2797
3056
  const { model } = ctx.params;
2798
3057
  const { query } = ctx.request;
2799
- const documentManager2 = getService$1("document-manager");
2800
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3058
+ const documentManager2 = getService$2("document-manager");
3059
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2801
3060
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2802
3061
  if (permissionChecker2.cannot.read()) {
2803
3062
  return ctx.forbidden();
@@ -2821,7 +3080,7 @@ const uid$1 = {
2821
3080
  const { query = {} } = ctx.request;
2822
3081
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2823
3082
  await validateUIDField(contentTypeUID, field);
2824
- const uidService = getService$1("uid");
3083
+ const uidService = getService$2("uid");
2825
3084
  ctx.body = {
2826
3085
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2827
3086
  };
@@ -2833,7 +3092,7 @@ const uid$1 = {
2833
3092
  const { query = {} } = ctx.request;
2834
3093
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2835
3094
  await validateUIDField(contentTypeUID, field);
2836
- const uidService = getService$1("uid");
3095
+ const uidService = getService$2("uid");
2837
3096
  const isAvailable = await uidService.checkUIDAvailability({
2838
3097
  contentTypeUID,
2839
3098
  field,
@@ -2854,7 +3113,8 @@ const controllers = {
2854
3113
  relations,
2855
3114
  "single-types": singleTypes,
2856
3115
  uid: uid$1,
2857
- ...history.controllers ? history.controllers : {}
3116
+ ...history.controllers ? history.controllers : {},
3117
+ ...preview.controllers ? preview.controllers : {}
2858
3118
  };
2859
3119
  const keys = {
2860
3120
  CONFIGURATION: "configuration"
@@ -2983,18 +3243,15 @@ async function syncMetadatas(configuration, schema) {
2983
3243
  _.set(updatedMeta, ["list", "searchable"], false);
2984
3244
  _.set(acc, [key], updatedMeta);
2985
3245
  }
2986
- if (!_.has(edit, "mainField"))
2987
- return acc;
3246
+ if (!_.has(edit, "mainField")) return acc;
2988
3247
  if (!isRelation$1(attr)) {
2989
3248
  _.set(updatedMeta, "edit", _.omit(edit, ["mainField"]));
2990
3249
  _.set(acc, [key], updatedMeta);
2991
3250
  return acc;
2992
3251
  }
2993
- if (edit.mainField === "id")
2994
- return acc;
3252
+ if (edit.mainField === "id") return acc;
2995
3253
  const targetSchema = getTargetSchema(attr.targetModel);
2996
- if (!targetSchema)
2997
- return acc;
3254
+ if (!targetSchema) return acc;
2998
3255
  if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
2999
3256
  _.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
3000
3257
  _.set(acc, [key], updatedMeta);
@@ -3005,12 +3262,12 @@ async function syncMetadatas(configuration, schema) {
3005
3262
  return _.assign(metasWithDefaults, updatedMetas);
3006
3263
  }
3007
3264
  const getTargetSchema = (targetModel) => {
3008
- return getService$1("content-types").findContentType(targetModel);
3265
+ return getService$2("content-types").findContentType(targetModel);
3009
3266
  };
3010
3267
  const DEFAULT_LIST_LENGTH = 4;
3011
3268
  const MAX_ROW_SIZE = 12;
3012
3269
  const isAllowedFieldSize = (type, size) => {
3013
- const { getFieldSize } = getService$1("field-sizes");
3270
+ const { getFieldSize } = getService$2("field-sizes");
3014
3271
  const fieldSize = getFieldSize(type);
3015
3272
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3016
3273
  return false;
@@ -3018,7 +3275,7 @@ const isAllowedFieldSize = (type, size) => {
3018
3275
  return size <= MAX_ROW_SIZE;
3019
3276
  };
3020
3277
  const getDefaultFieldSize = (attribute) => {
3021
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3278
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3022
3279
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3023
3280
  };
3024
3281
  async function createDefaultLayouts(schema) {
@@ -3039,8 +3296,7 @@ function createDefaultEditLayout(schema) {
3039
3296
  return appendToEditLayout([], keys2, schema);
3040
3297
  }
3041
3298
  function syncLayouts(configuration, schema) {
3042
- if (_.isEmpty(configuration.layouts))
3043
- return createDefaultLayouts(schema);
3299
+ if (_.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
3044
3300
  const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
3045
3301
  let cleanList = list.filter((attr) => isListable(schema, attr));
3046
3302
  const cleanEditRelations = editRelations.filter(
@@ -3051,9 +3307,8 @@ function syncLayouts(configuration, schema) {
3051
3307
  for (const row of edit) {
3052
3308
  const newRow = [];
3053
3309
  for (const el of row) {
3054
- if (!hasEditableAttribute(schema, el.name))
3055
- continue;
3056
- const { hasFieldSize } = getService$1("field-sizes");
3310
+ if (!hasEditableAttribute(schema, el.name)) continue;
3311
+ const { hasFieldSize } = getService$2("field-sizes");
3057
3312
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3058
3313
  if (!isAllowedFieldSize(fieldType, el.size)) {
3059
3314
  elementsToReAppend.push(el.name);
@@ -3083,8 +3338,7 @@ function syncLayouts(configuration, schema) {
3083
3338
  };
3084
3339
  }
3085
3340
  const appendToEditLayout = (layout = [], keysToAppend, schema) => {
3086
- if (keysToAppend.length === 0)
3087
- return layout;
3341
+ if (keysToAppend.length === 0) return layout;
3088
3342
  let currentRowIndex = Math.max(layout.length - 1, 0);
3089
3343
  if (!layout[currentRowIndex]) {
3090
3344
  layout[currentRowIndex] = [];
@@ -3193,17 +3447,17 @@ const configurationService$1 = createConfigurationService({
3193
3447
  isComponent: true,
3194
3448
  prefix: STORE_KEY_PREFIX,
3195
3449
  getModels() {
3196
- const { toContentManagerModel } = getService$1("data-mapper");
3450
+ const { toContentManagerModel } = getService$2("data-mapper");
3197
3451
  return mapValues(toContentManagerModel, strapi.components);
3198
3452
  }
3199
3453
  });
3200
3454
  const components = ({ strapi: strapi2 }) => ({
3201
3455
  findAllComponents() {
3202
- const { toContentManagerModel } = getService$1("data-mapper");
3456
+ const { toContentManagerModel } = getService$2("data-mapper");
3203
3457
  return Object.values(strapi2.components).map(toContentManagerModel);
3204
3458
  },
3205
3459
  findComponent(uid2) {
3206
- const { toContentManagerModel } = getService$1("data-mapper");
3460
+ const { toContentManagerModel } = getService$2("data-mapper");
3207
3461
  const component = strapi2.components[uid2];
3208
3462
  return isNil$1(component) ? component : toContentManagerModel(component);
3209
3463
  },
@@ -3254,17 +3508,17 @@ const configurationService = createConfigurationService({
3254
3508
  storeUtils,
3255
3509
  prefix: "content_types",
3256
3510
  getModels() {
3257
- const { toContentManagerModel } = getService$1("data-mapper");
3511
+ const { toContentManagerModel } = getService$2("data-mapper");
3258
3512
  return mapValues(toContentManagerModel, strapi.contentTypes);
3259
3513
  }
3260
3514
  });
3261
3515
  const service = ({ strapi: strapi2 }) => ({
3262
3516
  findAllContentTypes() {
3263
- const { toContentManagerModel } = getService$1("data-mapper");
3517
+ const { toContentManagerModel } = getService$2("data-mapper");
3264
3518
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3265
3519
  },
3266
3520
  findContentType(uid2) {
3267
- const { toContentManagerModel } = getService$1("data-mapper");
3521
+ const { toContentManagerModel } = getService$2("data-mapper");
3268
3522
  const contentType = strapi2.contentTypes[uid2];
3269
3523
  return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
3270
3524
  },
@@ -3293,7 +3547,7 @@ const service = ({ strapi: strapi2 }) => ({
3293
3547
  return this.findConfiguration(contentType);
3294
3548
  },
3295
3549
  findComponentsConfigurations(contentType) {
3296
- return getService$1("components").findComponentsConfigurations(contentType);
3550
+ return getService$2("components").findComponentsConfigurations(contentType);
3297
3551
  },
3298
3552
  syncConfigurations() {
3299
3553
  return configurationService.syncConfigurations();
@@ -3565,7 +3819,7 @@ const permission = ({ strapi: strapi2 }) => ({
3565
3819
  return userAbility.can(action);
3566
3820
  },
3567
3821
  async registerPermissions() {
3568
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3822
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3569
3823
  const contentTypesUids = displayedContentTypes.map(prop("uid"));
3570
3824
  const actions = [
3571
3825
  {
@@ -3841,7 +4095,7 @@ const getQueryPopulate = async (uid2, query) => {
3841
4095
  return populateQuery;
3842
4096
  };
3843
4097
  const buildDeepPopulate = (uid2) => {
3844
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4098
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3845
4099
  };
3846
4100
  const populateBuilder = (uid2) => {
3847
4101
  let getInitialPopulate = async () => {
@@ -4026,7 +4280,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4026
4280
  */
4027
4281
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4028
4282
  const versionsByLocale = groupBy("locale", allVersions);
4029
- delete versionsByLocale[version.locale];
4283
+ if (version.locale) {
4284
+ delete versionsByLocale[version.locale];
4285
+ }
4030
4286
  const model = strapi2.getModel(uid2);
4031
4287
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4032
4288
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4073,8 +4329,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4073
4329
  const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
4074
4330
  return matchLocale && matchStatus;
4075
4331
  });
4076
- if (!availableStatus)
4077
- return availableStatus;
4332
+ if (!availableStatus) return availableStatus;
4078
4333
  return pick(AVAILABLE_STATUS_FIELDS, availableStatus);
4079
4334
  },
4080
4335
  /**
@@ -4084,8 +4339,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4084
4339
  * @returns
4085
4340
  */
4086
4341
  async getManyAvailableStatus(uid2, documents) {
4087
- if (!documents.length)
4088
- return [];
4342
+ if (!documents.length) return [];
4089
4343
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4090
4344
  const locale = documents[0]?.locale;
4091
4345
  const otherStatus = status === "published" ? "draft" : "published";
@@ -4112,10 +4366,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4112
4366
  } else if (otherVersion) {
4113
4367
  draftVersion = otherVersion;
4114
4368
  }
4115
- if (!draftVersion)
4116
- return CONTENT_MANAGER_STATUS.PUBLISHED;
4117
- if (!publishedVersion)
4118
- return CONTENT_MANAGER_STATUS.DRAFT;
4369
+ if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
4370
+ if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
4119
4371
  const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
4120
4372
  return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
4121
4373
  },
@@ -4382,7 +4634,8 @@ const services = {
4382
4634
  permission,
4383
4635
  "populate-builder": populateBuilder$1,
4384
4636
  uid,
4385
- ...history.services ? history.services : {}
4637
+ ...history.services ? history.services : {},
4638
+ ...preview.services ? preview.services : {}
4386
4639
  };
4387
4640
  const index = () => {
4388
4641
  return {