@strapi/content-manager 0.0.0-experimental.edc24aaa3bb5a90fa5fd4fee208167dd4e2e38d4 → 0.0.0-experimental.f0a0bc26f5ef0693aaea2a616bc6b816cfee54b6

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/{ComponentConfigurationPage-BAgyHiMm.mjs → ComponentConfigurationPage-DhWA-JzT.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-BAgyHiMm.mjs.map → ComponentConfigurationPage-DhWA-JzT.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js → ComponentConfigurationPage-UduDBv3m.js} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js.map → ComponentConfigurationPage-UduDBv3m.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs → EditConfigurationPage-5tmx_7Hp.mjs} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs.map → EditConfigurationPage-5tmx_7Hp.mjs.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js → EditConfigurationPage-Cp9UzUfs.js} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js.map → EditConfigurationPage-Cp9UzUfs.js.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-BLsjc5F-.mjs → EditViewPage-BKoISUOu.mjs} +63 -12
  10. package/dist/_chunks/EditViewPage-BKoISUOu.mjs.map +1 -0
  11. package/dist/_chunks/{EditViewPage-C-ukDOB7.js → EditViewPage-C7l2Emuj.js} +62 -11
  12. package/dist/_chunks/EditViewPage-C7l2Emuj.js.map +1 -0
  13. package/dist/_chunks/{Field-Bfph5SOd.js → Field-BPSJpDfE.js} +211 -120
  14. package/dist/_chunks/Field-BPSJpDfE.js.map +1 -0
  15. package/dist/_chunks/{Field-Cs7duwWd.mjs → Field-BZxzYf1x.mjs} +210 -119
  16. package/dist/_chunks/Field-BZxzYf1x.mjs.map +1 -0
  17. package/dist/_chunks/{Form-Dg_GS5TQ.mjs → Form-8qyOU6YG.mjs} +36 -17
  18. package/dist/_chunks/Form-8qyOU6YG.mjs.map +1 -0
  19. package/dist/_chunks/{Form-CPYqIWDG.js → Form-DLkqDd2G.js} +36 -17
  20. package/dist/_chunks/Form-DLkqDd2G.js.map +1 -0
  21. package/dist/_chunks/{History-DNQkXANT.js → History-DYMicybF.js} +41 -98
  22. package/dist/_chunks/History-DYMicybF.js.map +1 -0
  23. package/dist/_chunks/{History-wrnHqf09.mjs → History-N_kRb1Yr.mjs} +43 -100
  24. package/dist/_chunks/History-N_kRb1Yr.mjs.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-DScmJVkW.mjs → ListConfigurationPage-BM3qVxug.mjs} +18 -7
  26. package/dist/_chunks/ListConfigurationPage-BM3qVxug.mjs.map +1 -0
  27. package/dist/_chunks/{ListConfigurationPage-CUQxfpjT.js → ListConfigurationPage-rUF9iGWq.js} +17 -6
  28. package/dist/_chunks/ListConfigurationPage-rUF9iGWq.js.map +1 -0
  29. package/dist/_chunks/{ListViewPage-BsLiH2-2.js → ListViewPage-BSLzd7cZ.js} +108 -76
  30. package/dist/_chunks/ListViewPage-BSLzd7cZ.js.map +1 -0
  31. package/dist/_chunks/{ListViewPage-C4IvrMgY.mjs → ListViewPage-CWilGbZb.mjs} +106 -74
  32. package/dist/_chunks/ListViewPage-CWilGbZb.mjs.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js → NoContentTypePage-CQccVhIX.js} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js.map → NoContentTypePage-CQccVhIX.js.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs → NoContentTypePage-VWYlePwI.mjs} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs.map → NoContentTypePage-VWYlePwI.mjs.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js → NoPermissionsPage-Af32Gg2m.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js.map → NoPermissionsPage-Af32Gg2m.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs → NoPermissionsPage-CS2tCmfr.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs.map → NoPermissionsPage-CS2tCmfr.mjs.map} +1 -1
  41. package/dist/_chunks/Preview-D4KzuJFL.js +291 -0
  42. package/dist/_chunks/Preview-D4KzuJFL.js.map +1 -0
  43. package/dist/_chunks/Preview-kPkuZbBJ.mjs +272 -0
  44. package/dist/_chunks/Preview-kPkuZbBJ.mjs.map +1 -0
  45. package/dist/_chunks/{Relations-BZr8tL0R.mjs → Relations-5k27Rh54.mjs} +73 -37
  46. package/dist/_chunks/Relations-5k27Rh54.mjs.map +1 -0
  47. package/dist/_chunks/{Relations-CtELXYIK.js → Relations-D_Ki5aVM.js} +72 -36
  48. package/dist/_chunks/Relations-D_Ki5aVM.js.map +1 -0
  49. package/dist/_chunks/{en-uOUIxfcQ.js → en-BK8Xyl5I.js} +28 -15
  50. package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BK8Xyl5I.js.map} +1 -1
  51. package/dist/_chunks/{en-BrCTWlZv.mjs → en-Dtk_ot79.mjs} +28 -15
  52. package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-Dtk_ot79.mjs.map} +1 -1
  53. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  54. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  55. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  56. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  57. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  58. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  59. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  60. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  61. package/dist/_chunks/{index-c_5DdJi-.mjs → index-BLPa8Dq-.mjs} +1201 -924
  62. package/dist/_chunks/index-BLPa8Dq-.mjs.map +1 -0
  63. package/dist/_chunks/{index-OerGjbAN.js → index-DwOsF7wF.js} +1182 -904
  64. package/dist/_chunks/index-DwOsF7wF.js.map +1 -0
  65. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  66. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  67. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  68. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  69. package/dist/_chunks/{layout-oPBiO7RY.mjs → layout-2Si0j0jO.mjs} +22 -9
  70. package/dist/_chunks/layout-2Si0j0jO.mjs.map +1 -0
  71. package/dist/_chunks/{layout-Ci7qHlFb.js → layout-CN2bFL9V.js} +21 -8
  72. package/dist/_chunks/layout-CN2bFL9V.js.map +1 -0
  73. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  74. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  75. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  76. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  77. package/dist/_chunks/{relations-COBpStiF.js → relations-B0E0XUY7.js} +6 -7
  78. package/dist/_chunks/relations-B0E0XUY7.js.map +1 -0
  79. package/dist/_chunks/{relations-BIdWFjdq.mjs → relations-CAxDjUJF.mjs} +6 -7
  80. package/dist/_chunks/relations-CAxDjUJF.mjs.map +1 -0
  81. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  82. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  83. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  84. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  85. package/dist/admin/index.js +2 -1
  86. package/dist/admin/index.js.map +1 -1
  87. package/dist/admin/index.mjs +5 -4
  88. package/dist/admin/src/exports.d.ts +1 -1
  89. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  90. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  91. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  92. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
  93. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  94. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  95. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  96. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  97. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  98. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  99. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  100. package/dist/admin/src/preview/constants.d.ts +1 -0
  101. package/dist/admin/src/preview/index.d.ts +4 -0
  102. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  103. package/dist/admin/src/preview/routes.d.ts +3 -0
  104. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  105. package/dist/admin/src/router.d.ts +1 -1
  106. package/dist/admin/src/services/api.d.ts +1 -1
  107. package/dist/admin/src/services/components.d.ts +2 -2
  108. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  109. package/dist/admin/src/services/documents.d.ts +19 -20
  110. package/dist/admin/src/services/init.d.ts +1 -1
  111. package/dist/admin/src/services/relations.d.ts +2 -2
  112. package/dist/admin/src/services/uid.d.ts +3 -3
  113. package/dist/admin/src/utils/validation.d.ts +4 -1
  114. package/dist/server/index.js +560 -235
  115. package/dist/server/index.js.map +1 -1
  116. package/dist/server/index.mjs +561 -236
  117. package/dist/server/index.mjs.map +1 -1
  118. package/dist/server/src/bootstrap.d.ts.map +1 -1
  119. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  120. package/dist/server/src/controllers/index.d.ts.map +1 -1
  121. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  122. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  123. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  124. package/dist/server/src/history/services/history.d.ts.map +1 -1
  125. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  126. package/dist/server/src/history/services/utils.d.ts +4 -4
  127. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  128. package/dist/server/src/index.d.ts +4 -4
  129. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  130. package/dist/server/src/preview/constants.d.ts +2 -0
  131. package/dist/server/src/preview/constants.d.ts.map +1 -0
  132. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  133. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  134. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  135. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  136. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  137. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  138. package/dist/server/src/preview/index.d.ts +4 -0
  139. package/dist/server/src/preview/index.d.ts.map +1 -0
  140. package/dist/server/src/preview/routes/index.d.ts +8 -0
  141. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  142. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  143. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  144. package/dist/server/src/preview/services/index.d.ts +16 -0
  145. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  146. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  147. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  148. package/dist/server/src/preview/services/preview.d.ts +12 -0
  149. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  150. package/dist/server/src/preview/utils.d.ts +19 -0
  151. package/dist/server/src/preview/utils.d.ts.map +1 -0
  152. package/dist/server/src/register.d.ts.map +1 -1
  153. package/dist/server/src/routes/index.d.ts.map +1 -1
  154. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  155. package/dist/server/src/services/document-metadata.d.ts +8 -8
  156. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  157. package/dist/server/src/services/index.d.ts +4 -4
  158. package/dist/server/src/services/index.d.ts.map +1 -1
  159. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  160. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  161. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  162. package/dist/server/src/utils/index.d.ts +2 -0
  163. package/dist/server/src/utils/index.d.ts.map +1 -1
  164. package/dist/shared/contracts/collection-types.d.ts +3 -1
  165. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  166. package/dist/shared/contracts/index.d.ts +1 -0
  167. package/dist/shared/contracts/index.d.ts.map +1 -1
  168. package/dist/shared/contracts/preview.d.ts +27 -0
  169. package/dist/shared/contracts/preview.d.ts.map +1 -0
  170. package/dist/shared/index.js +4 -0
  171. package/dist/shared/index.js.map +1 -1
  172. package/dist/shared/index.mjs +4 -0
  173. package/dist/shared/index.mjs.map +1 -1
  174. package/package.json +14 -14
  175. package/dist/_chunks/EditViewPage-BLsjc5F-.mjs.map +0 -1
  176. package/dist/_chunks/EditViewPage-C-ukDOB7.js.map +0 -1
  177. package/dist/_chunks/Field-Bfph5SOd.js.map +0 -1
  178. package/dist/_chunks/Field-Cs7duwWd.mjs.map +0 -1
  179. package/dist/_chunks/Form-CPYqIWDG.js.map +0 -1
  180. package/dist/_chunks/Form-Dg_GS5TQ.mjs.map +0 -1
  181. package/dist/_chunks/History-DNQkXANT.js.map +0 -1
  182. package/dist/_chunks/History-wrnHqf09.mjs.map +0 -1
  183. package/dist/_chunks/ListConfigurationPage-CUQxfpjT.js.map +0 -1
  184. package/dist/_chunks/ListConfigurationPage-DScmJVkW.mjs.map +0 -1
  185. package/dist/_chunks/ListViewPage-BsLiH2-2.js.map +0 -1
  186. package/dist/_chunks/ListViewPage-C4IvrMgY.mjs.map +0 -1
  187. package/dist/_chunks/Relations-BZr8tL0R.mjs.map +0 -1
  188. package/dist/_chunks/Relations-CtELXYIK.js.map +0 -1
  189. package/dist/_chunks/index-OerGjbAN.js.map +0 -1
  190. package/dist/_chunks/index-c_5DdJi-.mjs.map +0 -1
  191. package/dist/_chunks/layout-Ci7qHlFb.js.map +0 -1
  192. package/dist/_chunks/layout-oPBiO7RY.mjs.map +0 -1
  193. package/dist/_chunks/relations-BIdWFjdq.mjs.map +0 -1
  194. package/dist/_chunks/relations-COBpStiF.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, intersection, pipe, propOr, isEqual, isEmpty, set, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, isNil as isNil$1, getOr, propEq, merge, groupBy, castArray } 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
@@ -173,7 +173,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
173
173
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
174
174
  };
175
175
  const localesService = strapi2.plugin("i18n")?.service("locales");
176
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
176
177
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
178
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
177
179
  const getLocaleDictionary = async () => {
178
180
  if (!localesService)
179
181
  return {};
@@ -200,9 +202,21 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
202
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
203
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
204
  };
203
- const getDeepPopulate2 = (uid2) => {
205
+ const getComponentFields = (componentUID) => {
206
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
207
+ (fieldsAcc, [key, attribute]) => {
208
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
209
+ fieldsAcc.push(key);
210
+ }
211
+ return fieldsAcc;
212
+ },
213
+ []
214
+ );
215
+ };
216
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
217
  const model = strapi2.getModel(uid2);
205
218
  const attributes = Object.entries(model.attributes);
219
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
206
220
  return attributes.reduce((acc, [attributeName, attribute]) => {
207
221
  switch (attribute.type) {
208
222
  case "relation": {
@@ -212,23 +226,29 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
212
226
  }
213
227
  const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
214
228
  if (isVisible2) {
215
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
229
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
216
230
  }
217
231
  break;
218
232
  }
219
233
  case "media": {
220
- acc[attributeName] = { fields: ["id"] };
234
+ acc[attributeName] = { [fieldSelector]: ["id"] };
221
235
  break;
222
236
  }
223
237
  case "component": {
224
238
  const populate = getDeepPopulate2(attribute.component);
225
- acc[attributeName] = { populate };
239
+ acc[attributeName] = {
240
+ populate,
241
+ [fieldSelector]: getComponentFields(attribute.component)
242
+ };
226
243
  break;
227
244
  }
228
245
  case "dynamiczone": {
229
246
  const populatedComponents = (attribute.components || []).reduce(
230
247
  (acc2, componentUID) => {
231
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
248
+ acc2[componentUID] = {
249
+ populate: getDeepPopulate2(componentUID),
250
+ [fieldSelector]: getComponentFields(componentUID)
251
+ };
232
252
  return acc2;
233
253
  },
234
254
  {}
@@ -290,6 +310,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
290
310
  getRelationRestoreValue,
291
311
  getMediaRestoreValue,
292
312
  getDefaultLocale,
313
+ isLocalizedContentType,
293
314
  getLocaleDictionary,
294
315
  getRetentionDays,
295
316
  getVersionStatus,
@@ -312,7 +333,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
312
333
  });
313
334
  },
314
335
  async findVersionsPage(params) {
315
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
336
+ const model = strapi2.getModel(params.query.contentType);
337
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
338
+ const defaultLocale = await serviceUtils.getDefaultLocale();
339
+ let locale = null;
340
+ if (isLocalizedContentType) {
341
+ locale = params.query.locale || defaultLocale;
342
+ }
316
343
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
317
344
  query.findPage({
318
345
  ...params.query,
@@ -334,7 +361,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
334
361
  const attributeValue = entry.data[attributeKey];
335
362
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
336
363
  if (attributeSchema.type === "media") {
337
- const permissionChecker2 = getService$1("permission-checker").create({
364
+ const permissionChecker2 = getService$2("permission-checker").create({
338
365
  userAbility: params.state.userAbility,
339
366
  model: "plugin::upload.file"
340
367
  });
@@ -357,7 +384,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
357
384
  if (userToPopulate == null) {
358
385
  return null;
359
386
  }
360
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
387
+ return strapi2.query("admin::user").findOne({
388
+ where: {
389
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
390
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
391
+ }
392
+ });
361
393
  })
362
394
  );
363
395
  return {
@@ -370,7 +402,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
370
402
  [attributeKey]: adminUsers
371
403
  };
372
404
  }
373
- const permissionChecker2 = getService$1("permission-checker").create({
405
+ const permissionChecker2 = getService$2("permission-checker").create({
374
406
  userAbility: params.state.userAbility,
375
407
  model: attributeSchema.target
376
408
  });
@@ -468,6 +500,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
468
500
  }
469
501
  };
470
502
  };
503
+ const shouldCreateHistoryVersion = (context) => {
504
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
505
+ return false;
506
+ }
507
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
508
+ return false;
509
+ }
510
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
511
+ return false;
512
+ }
513
+ if (!context.contentType.uid.startsWith("api::")) {
514
+ return false;
515
+ }
516
+ return true;
517
+ };
518
+ const getSchemas = (uid2) => {
519
+ const attributesSchema = strapi.getModel(uid2).attributes;
520
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
521
+ (currentComponentSchemas, key) => {
522
+ const fieldSchema = attributesSchema[key];
523
+ if (fieldSchema.type === "component") {
524
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
525
+ return {
526
+ ...currentComponentSchemas,
527
+ [fieldSchema.component]: componentSchema
528
+ };
529
+ }
530
+ return currentComponentSchemas;
531
+ },
532
+ {}
533
+ );
534
+ return {
535
+ schema: omit(FIELDS_TO_IGNORE, attributesSchema),
536
+ componentsSchemas
537
+ };
538
+ };
471
539
  const createLifecyclesService = ({ strapi: strapi2 }) => {
472
540
  const state = {
473
541
  deleteExpiredJob: null,
@@ -480,76 +548,62 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
480
548
  return;
481
549
  }
482
550
  strapi2.documents.use(async (context, next) => {
483
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
484
- return next();
485
- }
486
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
487
- return next();
488
- }
489
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
490
- return next();
491
- }
492
- const contentTypeUid = context.contentType.uid;
493
- if (!contentTypeUid.startsWith("api::")) {
494
- return next();
495
- }
496
551
  const result = await next();
497
- const documentContext = {
498
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
499
- locale: context.params?.locale
500
- };
552
+ if (!shouldCreateHistoryVersion(context)) {
553
+ return result;
554
+ }
555
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
501
556
  const defaultLocale = await serviceUtils.getDefaultLocale();
502
- const locale = documentContext.locale || defaultLocale;
503
- if (Array.isArray(locale)) {
504
- strapi2.log.warn(
505
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
506
- );
507
- return next();
557
+ const locales = castArray(context.params?.locale || defaultLocale);
558
+ if (!locales.length) {
559
+ return result;
508
560
  }
509
- const document = await strapi2.documents(contentTypeUid).findOne({
510
- documentId: documentContext.documentId,
511
- locale,
512
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
561
+ const uid2 = context.contentType.uid;
562
+ const schemas = getSchemas(uid2);
563
+ const model = strapi2.getModel(uid2);
564
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
565
+ const localeEntries = await strapi2.db.query(uid2).findMany({
566
+ where: {
567
+ documentId,
568
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
569
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
570
+ },
571
+ populate: serviceUtils.getDeepPopulate(
572
+ uid2,
573
+ true
574
+ /* use database syntax */
575
+ )
513
576
  });
514
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
515
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
516
- const componentsSchemas = Object.keys(
517
- attributesSchema
518
- ).reduce((currentComponentSchemas, key) => {
519
- const fieldSchema = attributesSchema[key];
520
- if (fieldSchema.type === "component") {
521
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
522
- return {
523
- ...currentComponentSchemas,
524
- [fieldSchema.component]: componentSchema
525
- };
526
- }
527
- return currentComponentSchemas;
528
- }, {});
529
577
  await strapi2.db.transaction(async ({ onCommit }) => {
530
- onCommit(() => {
531
- getService(strapi2, "history").createVersion({
532
- contentType: contentTypeUid,
533
- data: omit(FIELDS_TO_IGNORE, document),
534
- schema: omit(FIELDS_TO_IGNORE, attributesSchema),
535
- componentsSchemas,
536
- relatedDocumentId: documentContext.documentId,
537
- locale,
538
- status
539
- });
578
+ onCommit(async () => {
579
+ for (const entry of localeEntries) {
580
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
581
+ await getService$1(strapi2, "history").createVersion({
582
+ contentType: uid2,
583
+ data: omit(FIELDS_TO_IGNORE, entry),
584
+ relatedDocumentId: documentId,
585
+ locale: entry.locale,
586
+ status,
587
+ ...schemas
588
+ });
589
+ }
540
590
  });
541
591
  });
542
592
  return result;
543
593
  });
544
- state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
594
+ state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
545
595
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
546
596
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
547
597
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
548
598
  where: {
549
599
  created_at: {
550
- $lt: expirationDate.toISOString()
600
+ $lt: expirationDate
551
601
  }
552
602
  }
603
+ }).catch((error) => {
604
+ if (error instanceof Error) {
605
+ strapi2.log.error("Error deleting expired history versions", error.message);
606
+ }
553
607
  });
554
608
  });
555
609
  state.isInitialized = true;
@@ -561,17 +615,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
561
615
  }
562
616
  };
563
617
  };
564
- const services$1 = {
618
+ const services$2 = {
565
619
  history: createHistoryService,
566
620
  lifecycles: createLifecyclesService
567
621
  };
568
- const info = { pluginName: "content-manager", type: "admin" };
622
+ const info$1 = { pluginName: "content-manager", type: "admin" };
569
623
  const historyVersionRouter = {
570
624
  type: "admin",
571
625
  routes: [
572
626
  {
573
627
  method: "GET",
574
- info,
628
+ info: info$1,
575
629
  path: "/history-versions",
576
630
  handler: "history-version.findMany",
577
631
  config: {
@@ -580,7 +634,7 @@ const historyVersionRouter = {
580
634
  },
581
635
  {
582
636
  method: "PUT",
583
- info,
637
+ info: info$1,
584
638
  path: "/history-versions/:versionId/restore",
585
639
  handler: "history-version.restoreVersion",
586
640
  config: {
@@ -589,7 +643,7 @@ const historyVersionRouter = {
589
643
  }
590
644
  ]
591
645
  };
592
- const routes$1 = {
646
+ const routes$2 = {
593
647
  "history-version": historyVersionRouter
594
648
  };
595
649
  const historyVersion = {
@@ -636,21 +690,21 @@ const historyVersion = {
636
690
  }
637
691
  }
638
692
  };
639
- const getFeature = () => {
693
+ const getFeature$1 = () => {
640
694
  if (strapi.ee.features.isEnabled("cms-content-history")) {
641
695
  return {
642
696
  register({ strapi: strapi2 }) {
643
697
  strapi2.get("models").add(historyVersion);
644
698
  },
645
699
  bootstrap({ strapi: strapi2 }) {
646
- getService(strapi2, "lifecycles").bootstrap();
700
+ getService$1(strapi2, "lifecycles").bootstrap();
647
701
  },
648
702
  destroy({ strapi: strapi2 }) {
649
- getService(strapi2, "lifecycles").destroy();
703
+ getService$1(strapi2, "lifecycles").destroy();
650
704
  },
651
- controllers: controllers$1,
652
- services: services$1,
653
- routes: routes$1
705
+ controllers: controllers$2,
706
+ services: services$2,
707
+ routes: routes$2
654
708
  };
655
709
  }
656
710
  return {
@@ -659,9 +713,205 @@ const getFeature = () => {
659
713
  }
660
714
  };
661
715
  };
662
- const history = getFeature();
716
+ const history = getFeature$1();
717
+ const FEATURE_ID = "preview";
718
+ const info = { pluginName: "content-manager", type: "admin" };
719
+ const previewRouter = {
720
+ type: "admin",
721
+ routes: [
722
+ {
723
+ method: "GET",
724
+ info,
725
+ path: "/preview/url/:contentType",
726
+ handler: "preview.getPreviewUrl",
727
+ config: {
728
+ policies: ["admin::isAuthenticatedAdmin"]
729
+ }
730
+ }
731
+ ]
732
+ };
733
+ const routes$1 = {
734
+ preview: previewRouter
735
+ };
736
+ function getService(strapi2, name) {
737
+ return strapi2.service(`plugin::content-manager.${name}`);
738
+ }
739
+ const getPreviewUrlSchema = yup.object().shape({
740
+ // Will be undefined for single types
741
+ documentId: yup.string(),
742
+ locale: yup.string().nullable(),
743
+ status: yup.string()
744
+ }).required();
745
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
746
+ await validateYupSchema(getPreviewUrlSchema)(params);
747
+ const newParams = pick(["documentId", "locale", "status"], params);
748
+ const model = strapi2.getModel(uid2);
749
+ if (!model || model.modelType !== "contentType") {
750
+ throw new errors.ValidationError("Invalid content type");
751
+ }
752
+ const isSingleType = model?.kind === "singleType";
753
+ if (!isSingleType && !params.documentId) {
754
+ throw new errors.ValidationError("documentId is required for Collection Types");
755
+ }
756
+ if (isSingleType) {
757
+ const doc = await strapi2.documents(uid2).findFirst();
758
+ if (!doc) {
759
+ throw new errors.NotFoundError("Document not found");
760
+ }
761
+ newParams.documentId = doc?.documentId;
762
+ }
763
+ if (!newParams.status) {
764
+ const isDPEnabled = model?.options?.draftAndPublish;
765
+ newParams.status = isDPEnabled ? "draft" : "published";
766
+ }
767
+ return newParams;
768
+ };
769
+ const createPreviewController = () => {
770
+ return {
771
+ /**
772
+ * Transforms an entry into a preview URL, so that it can be previewed
773
+ * in the Content Manager.
774
+ */
775
+ async getPreviewUrl(ctx) {
776
+ const uid2 = ctx.params.contentType;
777
+ const query = ctx.request.query;
778
+ const params = await validatePreviewUrl(strapi, uid2, query);
779
+ const previewService = getService(strapi, "preview");
780
+ const url = await previewService.getPreviewUrl(uid2, params);
781
+ if (!url) {
782
+ ctx.status = 204;
783
+ }
784
+ return {
785
+ data: { url }
786
+ };
787
+ }
788
+ };
789
+ };
790
+ const controllers$1 = {
791
+ preview: createPreviewController
792
+ /**
793
+ * Casting is needed because the types aren't aware that Strapi supports
794
+ * passing a controller factory as the value, instead of a controller object directly
795
+ */
796
+ };
797
+ const createPreviewService = ({ strapi: strapi2 }) => {
798
+ const config = getService(strapi2, "preview-config");
799
+ return {
800
+ async getPreviewUrl(uid2, params) {
801
+ const handler = config.getPreviewHandler();
802
+ try {
803
+ return handler(uid2, params);
804
+ } catch (error) {
805
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
806
+ throw new errors.ApplicationError("Failed to get preview URL");
807
+ }
808
+ return;
809
+ }
810
+ };
811
+ };
812
+ const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
813
+ const middlewares = strapi.config.get("middlewares");
814
+ const configuredMiddlewares = middlewares.map((currentMiddleware) => {
815
+ if (currentMiddleware === middleware.name) {
816
+ return middleware;
817
+ }
818
+ if (currentMiddleware.name === middleware.name) {
819
+ return mergeWith(
820
+ (objValue, srcValue) => {
821
+ if (Array.isArray(objValue)) {
822
+ return objValue.concat(srcValue);
823
+ }
824
+ return void 0;
825
+ },
826
+ currentMiddleware,
827
+ middleware
828
+ );
829
+ }
830
+ return currentMiddleware;
831
+ });
832
+ strapi.config.set("middlewares", configuredMiddlewares);
833
+ };
834
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
835
+ return {
836
+ register() {
837
+ if (!this.isEnabled()) {
838
+ return;
839
+ }
840
+ const config = strapi2.config.get("admin.preview");
841
+ if (config.config?.allowedOrigins) {
842
+ extendMiddlewareConfiguration({
843
+ name: "strapi::security",
844
+ config: {
845
+ contentSecurityPolicy: {
846
+ directives: {
847
+ "frame-src": config.config.allowedOrigins
848
+ }
849
+ }
850
+ }
851
+ });
852
+ }
853
+ },
854
+ isEnabled() {
855
+ const config = strapi2.config.get("admin.preview");
856
+ if (!config) {
857
+ return false;
858
+ }
859
+ return config?.enabled ?? true;
860
+ },
861
+ /**
862
+ * Validate if the configuration is valid
863
+ */
864
+ validate() {
865
+ if (!this.isEnabled()) {
866
+ return;
867
+ }
868
+ const handler = this.getPreviewHandler();
869
+ if (typeof handler !== "function") {
870
+ throw new errors.ValidationError(
871
+ "Preview configuration is invalid. Handler must be a function"
872
+ );
873
+ }
874
+ },
875
+ /**
876
+ * Utility to get the preview handler from the configuration
877
+ */
878
+ getPreviewHandler() {
879
+ const config = strapi2.config.get("admin.preview");
880
+ const emptyHandler = () => {
881
+ return void 0;
882
+ };
883
+ if (!this.isEnabled()) {
884
+ return emptyHandler;
885
+ }
886
+ return config?.config?.handler || emptyHandler;
887
+ }
888
+ };
889
+ };
890
+ const services$1 = {
891
+ preview: createPreviewService,
892
+ "preview-config": createPreviewConfigService
893
+ };
894
+ const getFeature = () => {
895
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
896
+ return {};
897
+ }
898
+ return {
899
+ register() {
900
+ const config = getService(strapi, "preview-config");
901
+ config.validate();
902
+ config.register();
903
+ },
904
+ bootstrap() {
905
+ },
906
+ routes: routes$1,
907
+ controllers: controllers$1,
908
+ services: services$1
909
+ };
910
+ };
911
+ const preview = getFeature();
663
912
  const register = async ({ strapi: strapi2 }) => {
664
913
  await history.register?.({ strapi: strapi2 });
914
+ await preview.register?.({ strapi: strapi2 });
665
915
  };
666
916
  const ALLOWED_WEBHOOK_EVENTS = {
667
917
  ENTRY_PUBLISH: "entry.publish",
@@ -671,11 +921,12 @@ const bootstrap = async () => {
671
921
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
672
922
  strapi.get("webhookStore").addAllowedEvent(key, value);
673
923
  });
674
- getService$1("field-sizes").setCustomFieldInputSizes();
675
- await getService$1("components").syncConfigurations();
676
- await getService$1("content-types").syncConfigurations();
677
- await getService$1("permission").registerPermissions();
924
+ getService$2("field-sizes").setCustomFieldInputSizes();
925
+ await getService$2("components").syncConfigurations();
926
+ await getService$2("content-types").syncConfigurations();
927
+ await getService$2("permission").registerPermissions();
678
928
  await history.bootstrap?.({ strapi });
929
+ await preview.bootstrap?.({ strapi });
679
930
  };
680
931
  const destroy = async ({ strapi: strapi2 }) => {
681
932
  await history.destroy?.({ strapi: strapi2 });
@@ -1165,7 +1416,8 @@ const admin = {
1165
1416
  };
1166
1417
  const routes = {
1167
1418
  admin,
1168
- ...history.routes ? history.routes : {}
1419
+ ...history.routes ? history.routes : {},
1420
+ ...preview.routes ? preview.routes : {}
1169
1421
  };
1170
1422
  const hasPermissionsSchema = yup$1.object({
1171
1423
  actions: yup$1.array().of(yup$1.string()),
@@ -1176,6 +1428,11 @@ const { createPolicy } = policy;
1176
1428
  const hasPermissions = createPolicy({
1177
1429
  name: "plugin::content-manager.hasPermissions",
1178
1430
  validator: validateHasPermissionsInput,
1431
+ /**
1432
+ * NOTE: Action aliases are currently not checked at this level (policy).
1433
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1434
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1435
+ */
1179
1436
  handler(ctx, config = {}) {
1180
1437
  const { actions = [], hasAtLeastOne = false } = config;
1181
1438
  const { userAbility } = ctx.state;
@@ -1417,7 +1674,7 @@ const createMetadasSchema = (schema) => {
1417
1674
  if (!value) {
1418
1675
  return yup$1.string();
1419
1676
  }
1420
- const targetSchema = getService$1("content-types").findContentType(
1677
+ const targetSchema = getService$2("content-types").findContentType(
1421
1678
  schema.attributes[key].targetModel
1422
1679
  );
1423
1680
  if (!targetSchema) {
@@ -1586,7 +1843,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1586
1843
  }
1587
1844
  };
1588
1845
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1589
- const documentMetadata2 = getService$1("document-metadata");
1846
+ const documentMetadata2 = getService$2("document-metadata");
1590
1847
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1591
1848
  let {
1592
1849
  meta: { availableLocales, availableStatus }
@@ -1612,8 +1869,8 @@ const createDocument = async (ctx, opts) => {
1612
1869
  const { userAbility, user } = ctx.state;
1613
1870
  const { model } = ctx.params;
1614
1871
  const { body } = ctx.request;
1615
- const documentManager2 = getService$1("document-manager");
1616
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1872
+ const documentManager2 = getService$2("document-manager");
1873
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1617
1874
  if (permissionChecker2.cannot.create()) {
1618
1875
  throw new errors.ForbiddenError();
1619
1876
  }
@@ -1633,13 +1890,13 @@ const updateDocument = async (ctx, opts) => {
1633
1890
  const { userAbility, user } = ctx.state;
1634
1891
  const { id, model } = ctx.params;
1635
1892
  const { body } = ctx.request;
1636
- const documentManager2 = getService$1("document-manager");
1637
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1893
+ const documentManager2 = getService$2("document-manager");
1894
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1638
1895
  if (permissionChecker2.cannot.update()) {
1639
1896
  throw new errors.ForbiddenError();
1640
1897
  }
1641
1898
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1642
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1899
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1643
1900
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1644
1901
  const [documentVersion, documentExists] = await Promise.all([
1645
1902
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1656,7 +1913,7 @@ const updateDocument = async (ctx, opts) => {
1656
1913
  throw new errors.ForbiddenError();
1657
1914
  }
1658
1915
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1659
- const setCreator = setCreatorFields({ user, isEdition: true });
1916
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1660
1917
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1661
1918
  const sanitizedBody = await sanitizeFn(body);
1662
1919
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1670,14 +1927,14 @@ const collectionTypes = {
1670
1927
  const { userAbility } = ctx.state;
1671
1928
  const { model } = ctx.params;
1672
1929
  const { query } = ctx.request;
1673
- const documentMetadata2 = getService$1("document-metadata");
1674
- const documentManager2 = getService$1("document-manager");
1675
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1930
+ const documentMetadata2 = getService$2("document-metadata");
1931
+ const documentManager2 = getService$2("document-manager");
1932
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1676
1933
  if (permissionChecker2.cannot.read()) {
1677
1934
  return ctx.forbidden();
1678
1935
  }
1679
1936
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1680
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1937
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1681
1938
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1682
1939
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1683
1940
  { ...permissionQuery, populate, locale, status },
@@ -1706,13 +1963,13 @@ const collectionTypes = {
1706
1963
  async findOne(ctx) {
1707
1964
  const { userAbility } = ctx.state;
1708
1965
  const { model, id } = ctx.params;
1709
- const documentManager2 = getService$1("document-manager");
1710
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1966
+ const documentManager2 = getService$2("document-manager");
1967
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1711
1968
  if (permissionChecker2.cannot.read()) {
1712
1969
  return ctx.forbidden();
1713
1970
  }
1714
1971
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1715
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1972
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1716
1973
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1717
1974
  const version = await documentManager2.findOne(id, model, {
1718
1975
  populate,
@@ -1728,7 +1985,7 @@ const collectionTypes = {
1728
1985
  permissionChecker2,
1729
1986
  model,
1730
1987
  // @ts-expect-error TODO: fix
1731
- { id, locale, publishedAt: null },
1988
+ { documentId: id, locale, publishedAt: null },
1732
1989
  { availableLocales: true, availableStatus: false }
1733
1990
  );
1734
1991
  ctx.body = { data: {}, meta };
@@ -1743,7 +2000,7 @@ const collectionTypes = {
1743
2000
  async create(ctx) {
1744
2001
  const { userAbility } = ctx.state;
1745
2002
  const { model } = ctx.params;
1746
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2003
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1747
2004
  const [totalEntries, document] = await Promise.all([
1748
2005
  strapi.db.query(model).count(),
1749
2006
  createDocument(ctx)
@@ -1764,7 +2021,7 @@ const collectionTypes = {
1764
2021
  async update(ctx) {
1765
2022
  const { userAbility } = ctx.state;
1766
2023
  const { model } = ctx.params;
1767
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2024
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1768
2025
  const updatedVersion = await updateDocument(ctx);
1769
2026
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1770
2027
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1773,13 +2030,13 @@ const collectionTypes = {
1773
2030
  const { userAbility, user } = ctx.state;
1774
2031
  const { model, sourceId: id } = ctx.params;
1775
2032
  const { body } = ctx.request;
1776
- const documentManager2 = getService$1("document-manager");
1777
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2033
+ const documentManager2 = getService$2("document-manager");
2034
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1778
2035
  if (permissionChecker2.cannot.create()) {
1779
2036
  return ctx.forbidden();
1780
2037
  }
1781
2038
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1782
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2039
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1783
2040
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1784
2041
  const document = await documentManager2.findOne(id, model, {
1785
2042
  populate,
@@ -1818,13 +2075,13 @@ const collectionTypes = {
1818
2075
  async delete(ctx) {
1819
2076
  const { userAbility } = ctx.state;
1820
2077
  const { id, model } = ctx.params;
1821
- const documentManager2 = getService$1("document-manager");
1822
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2078
+ const documentManager2 = getService$2("document-manager");
2079
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1823
2080
  if (permissionChecker2.cannot.delete()) {
1824
2081
  return ctx.forbidden();
1825
2082
  }
1826
2083
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1827
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2084
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1828
2085
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1829
2086
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1830
2087
  if (documentLocales.length === 0) {
@@ -1846,19 +2103,42 @@ const collectionTypes = {
1846
2103
  const { userAbility } = ctx.state;
1847
2104
  const { id, model } = ctx.params;
1848
2105
  const { body } = ctx.request;
1849
- const documentManager2 = getService$1("document-manager");
1850
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2106
+ const documentManager2 = getService$2("document-manager");
2107
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1851
2108
  if (permissionChecker2.cannot.publish()) {
1852
2109
  return ctx.forbidden();
1853
2110
  }
1854
2111
  const publishedDocument = await strapi.db.transaction(async () => {
1855
2112
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1856
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1857
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
2113
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2114
+ let document;
2115
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2116
+ const isCreate = isNil$1(id);
2117
+ if (isCreate) {
2118
+ if (permissionChecker2.cannot.create()) {
2119
+ throw new errors.ForbiddenError();
2120
+ }
2121
+ document = await createDocument(ctx, { populate });
2122
+ }
2123
+ const isUpdate = !isCreate;
2124
+ if (isUpdate) {
2125
+ const documentExists = documentManager2.exists(model, id);
2126
+ if (!documentExists) {
2127
+ throw new errors.NotFoundError("Document not found");
2128
+ }
2129
+ document = await documentManager2.findOne(id, model, { populate, locale });
2130
+ if (!document) {
2131
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2132
+ throw new errors.ForbiddenError();
2133
+ }
2134
+ document = await updateDocument(ctx);
2135
+ } else if (permissionChecker2.can.update(document)) {
2136
+ await updateDocument(ctx);
2137
+ }
2138
+ }
1858
2139
  if (permissionChecker2.cannot.publish(document)) {
1859
2140
  throw new errors.ForbiddenError();
1860
2141
  }
1861
- const { locale } = await getDocumentLocaleAndStatus(body, model);
1862
2142
  const publishResult = await documentManager2.publish(document.documentId, model, {
1863
2143
  locale
1864
2144
  // TODO: Allow setting creator fields on publish
@@ -1878,13 +2158,13 @@ const collectionTypes = {
1878
2158
  const { body } = ctx.request;
1879
2159
  const { documentIds } = body;
1880
2160
  await validateBulkActionInput(body);
1881
- const documentManager2 = getService$1("document-manager");
1882
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2161
+ const documentManager2 = getService$2("document-manager");
2162
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1883
2163
  if (permissionChecker2.cannot.publish()) {
1884
2164
  return ctx.forbidden();
1885
2165
  }
1886
2166
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1887
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2167
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1888
2168
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1889
2169
  allowMultipleLocales: true
1890
2170
  });
@@ -1909,12 +2189,14 @@ const collectionTypes = {
1909
2189
  const { body } = ctx.request;
1910
2190
  const { documentIds } = body;
1911
2191
  await validateBulkActionInput(body);
1912
- const documentManager2 = getService$1("document-manager");
1913
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2192
+ const documentManager2 = getService$2("document-manager");
2193
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1914
2194
  if (permissionChecker2.cannot.unpublish()) {
1915
2195
  return ctx.forbidden();
1916
2196
  }
1917
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2197
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2198
+ allowMultipleLocales: true
2199
+ });
1918
2200
  const entityPromises = documentIds.map(
1919
2201
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1920
2202
  );
@@ -1937,8 +2219,8 @@ const collectionTypes = {
1937
2219
  const {
1938
2220
  body: { discardDraft, ...body }
1939
2221
  } = ctx.request;
1940
- const documentManager2 = getService$1("document-manager");
1941
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2222
+ const documentManager2 = getService$2("document-manager");
2223
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1942
2224
  if (permissionChecker2.cannot.unpublish()) {
1943
2225
  return ctx.forbidden();
1944
2226
  }
@@ -1946,7 +2228,7 @@ const collectionTypes = {
1946
2228
  return ctx.forbidden();
1947
2229
  }
1948
2230
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1949
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2231
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1950
2232
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1951
2233
  const document = await documentManager2.findOne(id, model, {
1952
2234
  populate,
@@ -1977,13 +2259,13 @@ const collectionTypes = {
1977
2259
  const { userAbility } = ctx.state;
1978
2260
  const { id, model } = ctx.params;
1979
2261
  const { body } = ctx.request;
1980
- const documentManager2 = getService$1("document-manager");
1981
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2262
+ const documentManager2 = getService$2("document-manager");
2263
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1982
2264
  if (permissionChecker2.cannot.discard()) {
1983
2265
  return ctx.forbidden();
1984
2266
  }
1985
2267
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
1986
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2268
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1987
2269
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1988
2270
  const document = await documentManager2.findOne(id, model, {
1989
2271
  populate,
@@ -2008,13 +2290,13 @@ const collectionTypes = {
2008
2290
  const { query, body } = ctx.request;
2009
2291
  const { documentIds } = body;
2010
2292
  await validateBulkActionInput(body);
2011
- const documentManager2 = getService$1("document-manager");
2012
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2293
+ const documentManager2 = getService$2("document-manager");
2294
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2013
2295
  if (permissionChecker2.cannot.delete()) {
2014
2296
  return ctx.forbidden();
2015
2297
  }
2016
2298
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2017
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2299
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2018
2300
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2019
2301
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2020
2302
  populate,
@@ -2035,13 +2317,13 @@ const collectionTypes = {
2035
2317
  async countDraftRelations(ctx) {
2036
2318
  const { userAbility } = ctx.state;
2037
2319
  const { model, id } = ctx.params;
2038
- const documentManager2 = getService$1("document-manager");
2039
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2320
+ const documentManager2 = getService$2("document-manager");
2321
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2040
2322
  if (permissionChecker2.cannot.read()) {
2041
2323
  return ctx.forbidden();
2042
2324
  }
2043
2325
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2044
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2326
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2045
2327
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2046
2328
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2047
2329
  if (!entity) {
@@ -2060,8 +2342,8 @@ const collectionTypes = {
2060
2342
  const ids = ctx.request.query.documentIds;
2061
2343
  const locale = ctx.request.query.locale;
2062
2344
  const { model } = ctx.params;
2063
- const documentManager2 = getService$1("document-manager");
2064
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2345
+ const documentManager2 = getService$2("document-manager");
2346
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2065
2347
  if (permissionChecker2.cannot.read()) {
2066
2348
  return ctx.forbidden();
2067
2349
  }
@@ -2085,13 +2367,13 @@ const collectionTypes = {
2085
2367
  };
2086
2368
  const components$1 = {
2087
2369
  findComponents(ctx) {
2088
- const components2 = getService$1("components").findAllComponents();
2089
- const { toDto } = getService$1("data-mapper");
2370
+ const components2 = getService$2("components").findAllComponents();
2371
+ const { toDto } = getService$2("data-mapper");
2090
2372
  ctx.body = { data: components2.map(toDto) };
2091
2373
  },
2092
2374
  async findComponentConfiguration(ctx) {
2093
2375
  const { uid: uid2 } = ctx.params;
2094
- const componentService = getService$1("components");
2376
+ const componentService = getService$2("components");
2095
2377
  const component = componentService.findComponent(uid2);
2096
2378
  if (!component) {
2097
2379
  return ctx.notFound("component.notFound");
@@ -2108,7 +2390,7 @@ const components$1 = {
2108
2390
  async updateComponentConfiguration(ctx) {
2109
2391
  const { uid: uid2 } = ctx.params;
2110
2392
  const { body } = ctx.request;
2111
- const componentService = getService$1("components");
2393
+ const componentService = getService$2("components");
2112
2394
  const component = componentService.findComponent(uid2);
2113
2395
  if (!component) {
2114
2396
  return ctx.notFound("component.notFound");
@@ -2142,12 +2424,12 @@ const contentTypes = {
2142
2424
  } catch (error) {
2143
2425
  return ctx.send({ error }, 400);
2144
2426
  }
2145
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2146
- const { toDto } = getService$1("data-mapper");
2427
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2428
+ const { toDto } = getService$2("data-mapper");
2147
2429
  ctx.body = { data: contentTypes2.map(toDto) };
2148
2430
  },
2149
2431
  async findContentTypesSettings(ctx) {
2150
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2432
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2151
2433
  const contentTypes2 = await findAllContentTypes();
2152
2434
  const configurations = await Promise.all(
2153
2435
  contentTypes2.map(async (contentType) => {
@@ -2161,7 +2443,7 @@ const contentTypes = {
2161
2443
  },
2162
2444
  async findContentTypeConfiguration(ctx) {
2163
2445
  const { uid: uid2 } = ctx.params;
2164
- const contentTypeService = getService$1("content-types");
2446
+ const contentTypeService = getService$2("content-types");
2165
2447
  const contentType = await contentTypeService.findContentType(uid2);
2166
2448
  if (!contentType) {
2167
2449
  return ctx.notFound("contentType.notFound");
@@ -2183,13 +2465,13 @@ const contentTypes = {
2183
2465
  const { userAbility } = ctx.state;
2184
2466
  const { uid: uid2 } = ctx.params;
2185
2467
  const { body } = ctx.request;
2186
- const contentTypeService = getService$1("content-types");
2187
- const metricsService = getService$1("metrics");
2468
+ const contentTypeService = getService$2("content-types");
2469
+ const metricsService = getService$2("metrics");
2188
2470
  const contentType = await contentTypeService.findContentType(uid2);
2189
2471
  if (!contentType) {
2190
2472
  return ctx.notFound("contentType.notFound");
2191
2473
  }
2192
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2474
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2193
2475
  return ctx.forbidden();
2194
2476
  }
2195
2477
  let input;
@@ -2222,10 +2504,10 @@ const contentTypes = {
2222
2504
  };
2223
2505
  const init = {
2224
2506
  getInitData(ctx) {
2225
- const { toDto } = getService$1("data-mapper");
2226
- const { findAllComponents } = getService$1("components");
2227
- const { getAllFieldSizes } = getService$1("field-sizes");
2228
- const { findAllContentTypes } = getService$1("content-types");
2507
+ const { toDto } = getService$2("data-mapper");
2508
+ const { findAllComponents } = getService$2("components");
2509
+ const { getAllFieldSizes } = getService$2("field-sizes");
2510
+ const { findAllContentTypes } = getService$2("content-types");
2229
2511
  ctx.body = {
2230
2512
  data: {
2231
2513
  fieldSizes: getAllFieldSizes(),
@@ -2261,36 +2543,41 @@ const addFiltersClause = (params, filtersClause) => {
2261
2543
  params.filters.$and.push(filtersClause);
2262
2544
  };
2263
2545
  const sanitizeMainField = (model, mainField, userAbility) => {
2264
- const permissionChecker2 = getService$1("permission-checker").create({
2546
+ const permissionChecker2 = getService$2("permission-checker").create({
2265
2547
  userAbility,
2266
2548
  model: model.uid
2267
2549
  });
2268
- if (!isListable(model, mainField)) {
2550
+ const isMainFieldListable = isListable(model, mainField);
2551
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2552
+ if (!isMainFieldListable || !canReadMainField) {
2269
2553
  return "id";
2270
2554
  }
2271
- if (permissionChecker2.cannot.read(null, mainField)) {
2272
- if (model.uid === "plugin::users-permissions.role") {
2273
- const userPermissionChecker = getService$1("permission-checker").create({
2274
- userAbility,
2275
- model: "plugin::users-permissions.user"
2276
- });
2277
- if (userPermissionChecker.can.read()) {
2278
- return "name";
2279
- }
2280
- }
2281
- return "id";
2555
+ if (model.uid === "plugin::users-permissions.role") {
2556
+ return "name";
2282
2557
  }
2283
2558
  return mainField;
2284
2559
  };
2285
- const addStatusToRelations = async (uid2, relations2) => {
2286
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2560
+ const addStatusToRelations = async (targetUid, relations2) => {
2561
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2287
2562
  return relations2;
2288
2563
  }
2289
- const documentMetadata2 = getService$1("document-metadata");
2290
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2564
+ const documentMetadata2 = getService$2("document-metadata");
2565
+ if (!relations2.length) {
2566
+ return relations2;
2567
+ }
2568
+ const firstRelation = relations2[0];
2569
+ const filters = {
2570
+ documentId: { $in: relations2.map((r) => r.documentId) },
2571
+ // NOTE: find the "opposite" status
2572
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2573
+ };
2574
+ const availableStatus = await strapi.query(targetUid).findMany({
2575
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2576
+ filters
2577
+ });
2291
2578
  return relations2.map((relation) => {
2292
- const availableStatuses = documentsAvailableStatus.filter(
2293
- (availableDocument) => availableDocument.documentId === relation.documentId
2579
+ const availableStatuses = availableStatus.filter(
2580
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2294
2581
  );
2295
2582
  return {
2296
2583
  ...relation,
@@ -2311,11 +2598,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2311
2598
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2312
2599
  const isSourceLocalized = isLocalized(sourceModel);
2313
2600
  const isTargetLocalized = isLocalized(targetModel);
2314
- let validatedLocale = locale;
2315
- if (!targetModel || !isTargetLocalized)
2316
- validatedLocale = void 0;
2317
2601
  return {
2318
- locale: validatedLocale,
2602
+ locale,
2319
2603
  isSourceLocalized,
2320
2604
  isTargetLocalized
2321
2605
  };
@@ -2355,7 +2639,7 @@ const relations = {
2355
2639
  ctx.request?.query?.locale
2356
2640
  );
2357
2641
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2358
- const permissionChecker2 = getService$1("permission-checker").create({
2642
+ const permissionChecker2 = getService$2("permission-checker").create({
2359
2643
  userAbility,
2360
2644
  model
2361
2645
  });
@@ -2380,7 +2664,7 @@ const relations = {
2380
2664
  where.id = id;
2381
2665
  }
2382
2666
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2383
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2667
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2384
2668
  const currentEntity = await strapi.db.query(model).findOne({
2385
2669
  where,
2386
2670
  populate
@@ -2395,7 +2679,7 @@ const relations = {
2395
2679
  }
2396
2680
  entryId = currentEntity.id;
2397
2681
  }
2398
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2682
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2399
2683
  const targetSchema = strapi.getModel(targetUid);
2400
2684
  const mainField = flow(
2401
2685
  prop(`metadatas.${targetField}.edit.mainField`),
@@ -2418,7 +2702,7 @@ const relations = {
2418
2702
  attribute,
2419
2703
  fieldsToSelect,
2420
2704
  mainField,
2421
- source: { schema: sourceSchema },
2705
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2422
2706
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2423
2707
  sourceSchema,
2424
2708
  targetSchema,
@@ -2440,7 +2724,8 @@ const relations = {
2440
2724
  fieldsToSelect,
2441
2725
  mainField,
2442
2726
  source: {
2443
- schema: { uid: sourceUid, modelType: sourceModelType }
2727
+ schema: { uid: sourceUid, modelType: sourceModelType },
2728
+ isLocalized: isSourceLocalized
2444
2729
  },
2445
2730
  target: {
2446
2731
  schema: { uid: targetUid },
@@ -2448,7 +2733,7 @@ const relations = {
2448
2733
  }
2449
2734
  } = await this.extractAndValidateRequestInfo(ctx, id);
2450
2735
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2451
- const permissionChecker2 = getService$1("permission-checker").create({
2736
+ const permissionChecker2 = getService$2("permission-checker").create({
2452
2737
  userAbility: ctx.state.userAbility,
2453
2738
  model: targetUid
2454
2739
  });
@@ -2478,12 +2763,16 @@ const relations = {
2478
2763
  } else {
2479
2764
  where.id = id;
2480
2765
  }
2481
- if (status) {
2482
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2766
+ const publishedAt = getPublishedAtClause(status, targetUid);
2767
+ if (!isEmpty(publishedAt)) {
2768
+ where[`${alias}.published_at`] = publishedAt;
2483
2769
  }
2484
- if (filterByLocale) {
2770
+ if (isTargetLocalized && locale) {
2485
2771
  where[`${alias}.locale`] = locale;
2486
2772
  }
2773
+ if (isSourceLocalized && locale) {
2774
+ where.locale = locale;
2775
+ }
2487
2776
  if ((idsToInclude?.length ?? 0) !== 0) {
2488
2777
  where[`${alias}.id`].$notIn = idsToInclude;
2489
2778
  }
@@ -2501,7 +2790,8 @@ const relations = {
2501
2790
  id: { $notIn: uniq(idsToOmit) }
2502
2791
  });
2503
2792
  }
2504
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2793
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2794
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2505
2795
  ctx.body = {
2506
2796
  ...res,
2507
2797
  results: await addStatusToRelations(targetUid, res.results)
@@ -2516,29 +2806,39 @@ const relations = {
2516
2806
  attribute,
2517
2807
  targetField,
2518
2808
  fieldsToSelect,
2519
- source: {
2520
- schema: { uid: sourceUid }
2521
- },
2522
- target: {
2523
- schema: { uid: targetUid }
2524
- }
2809
+ status,
2810
+ source: { schema: sourceSchema },
2811
+ target: { schema: targetSchema }
2525
2812
  } = await this.extractAndValidateRequestInfo(ctx, id);
2526
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2813
+ const { uid: sourceUid } = sourceSchema;
2814
+ const { uid: targetUid } = targetSchema;
2815
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2527
2816
  const dbQuery = strapi.db.query(sourceUid);
2528
2817
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2818
+ const filters = {};
2819
+ if (sourceSchema?.options?.draftAndPublish) {
2820
+ if (targetSchema?.options?.draftAndPublish) {
2821
+ if (status === "published") {
2822
+ filters.publishedAt = { $notNull: true };
2823
+ } else {
2824
+ filters.publishedAt = { $null: true };
2825
+ }
2826
+ }
2827
+ } else if (targetSchema?.options?.draftAndPublish) {
2828
+ filters.publishedAt = { $null: true };
2829
+ }
2529
2830
  const res = await loadRelations({ id: entryId }, targetField, {
2530
- select: ["id", "documentId", "locale", "publishedAt"],
2831
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2531
2832
  ordering: "desc",
2532
2833
  page: ctx.request.query.page,
2533
- pageSize: ctx.request.query.pageSize
2834
+ pageSize: ctx.request.query.pageSize,
2835
+ filters
2534
2836
  });
2535
2837
  const loadedIds = res.results.map((item) => item.id);
2536
2838
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2537
2839
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2538
2840
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2539
- ordering: "desc",
2540
- page: ctx.request.query.page,
2541
- pageSize: ctx.request.query.pageSize
2841
+ ordering: "desc"
2542
2842
  });
2543
2843
  const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
2544
2844
  ctx.body = {
@@ -2553,10 +2853,10 @@ const relations = {
2553
2853
  }
2554
2854
  };
2555
2855
  const buildPopulateFromQuery = async (query, model) => {
2556
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2856
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2557
2857
  };
2558
2858
  const findDocument = async (query, uid2, opts = {}) => {
2559
- const documentManager2 = getService$1("document-manager");
2859
+ const documentManager2 = getService$2("document-manager");
2560
2860
  const populate = await buildPopulateFromQuery(query, uid2);
2561
2861
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2562
2862
  };
@@ -2564,8 +2864,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2564
2864
  const { user, userAbility } = ctx.state;
2565
2865
  const { model } = ctx.params;
2566
2866
  const { body, query } = ctx.request;
2567
- const documentManager2 = getService$1("document-manager");
2568
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2867
+ const documentManager2 = getService$2("document-manager");
2868
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2569
2869
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2570
2870
  throw new errors.ForbiddenError();
2571
2871
  }
@@ -2606,7 +2906,7 @@ const singleTypes = {
2606
2906
  const { userAbility } = ctx.state;
2607
2907
  const { model } = ctx.params;
2608
2908
  const { query = {} } = ctx.request;
2609
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2909
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2610
2910
  if (permissionChecker2.cannot.read()) {
2611
2911
  return ctx.forbidden();
2612
2912
  }
@@ -2625,7 +2925,7 @@ const singleTypes = {
2625
2925
  permissionChecker2,
2626
2926
  model,
2627
2927
  // @ts-expect-error - fix types
2628
- { id: document.documentId, locale, publishedAt: null },
2928
+ { documentId: document.documentId, locale, publishedAt: null },
2629
2929
  { availableLocales: true, availableStatus: false }
2630
2930
  );
2631
2931
  ctx.body = { data: {}, meta };
@@ -2640,7 +2940,7 @@ const singleTypes = {
2640
2940
  async createOrUpdate(ctx) {
2641
2941
  const { userAbility } = ctx.state;
2642
2942
  const { model } = ctx.params;
2643
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2943
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2644
2944
  const document = await createOrUpdateDocument(ctx);
2645
2945
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2646
2946
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2649,8 +2949,8 @@ const singleTypes = {
2649
2949
  const { userAbility } = ctx.state;
2650
2950
  const { model } = ctx.params;
2651
2951
  const { query = {} } = ctx.request;
2652
- const documentManager2 = getService$1("document-manager");
2653
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2952
+ const documentManager2 = getService$2("document-manager");
2953
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2654
2954
  if (permissionChecker2.cannot.delete()) {
2655
2955
  return ctx.forbidden();
2656
2956
  }
@@ -2678,8 +2978,8 @@ const singleTypes = {
2678
2978
  const { userAbility } = ctx.state;
2679
2979
  const { model } = ctx.params;
2680
2980
  const { query = {} } = ctx.request;
2681
- const documentManager2 = getService$1("document-manager");
2682
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2981
+ const documentManager2 = getService$2("document-manager");
2982
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2683
2983
  if (permissionChecker2.cannot.publish()) {
2684
2984
  return ctx.forbidden();
2685
2985
  }
@@ -2707,8 +3007,8 @@ const singleTypes = {
2707
3007
  body: { discardDraft, ...body },
2708
3008
  query = {}
2709
3009
  } = ctx.request;
2710
- const documentManager2 = getService$1("document-manager");
2711
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3010
+ const documentManager2 = getService$2("document-manager");
3011
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2712
3012
  if (permissionChecker2.cannot.unpublish()) {
2713
3013
  return ctx.forbidden();
2714
3014
  }
@@ -2742,8 +3042,8 @@ const singleTypes = {
2742
3042
  const { userAbility } = ctx.state;
2743
3043
  const { model } = ctx.params;
2744
3044
  const { body, query = {} } = ctx.request;
2745
- const documentManager2 = getService$1("document-manager");
2746
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3045
+ const documentManager2 = getService$2("document-manager");
3046
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2747
3047
  if (permissionChecker2.cannot.discard()) {
2748
3048
  return ctx.forbidden();
2749
3049
  }
@@ -2766,8 +3066,8 @@ const singleTypes = {
2766
3066
  const { userAbility } = ctx.state;
2767
3067
  const { model } = ctx.params;
2768
3068
  const { query } = ctx.request;
2769
- const documentManager2 = getService$1("document-manager");
2770
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3069
+ const documentManager2 = getService$2("document-manager");
3070
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2771
3071
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2772
3072
  if (permissionChecker2.cannot.read()) {
2773
3073
  return ctx.forbidden();
@@ -2791,7 +3091,7 @@ const uid$1 = {
2791
3091
  const { query = {} } = ctx.request;
2792
3092
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2793
3093
  await validateUIDField(contentTypeUID, field);
2794
- const uidService = getService$1("uid");
3094
+ const uidService = getService$2("uid");
2795
3095
  ctx.body = {
2796
3096
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2797
3097
  };
@@ -2803,7 +3103,7 @@ const uid$1 = {
2803
3103
  const { query = {} } = ctx.request;
2804
3104
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2805
3105
  await validateUIDField(contentTypeUID, field);
2806
- const uidService = getService$1("uid");
3106
+ const uidService = getService$2("uid");
2807
3107
  const isAvailable = await uidService.checkUIDAvailability({
2808
3108
  contentTypeUID,
2809
3109
  field,
@@ -2824,7 +3124,8 @@ const controllers = {
2824
3124
  relations,
2825
3125
  "single-types": singleTypes,
2826
3126
  uid: uid$1,
2827
- ...history.controllers ? history.controllers : {}
3127
+ ...history.controllers ? history.controllers : {},
3128
+ ...preview.controllers ? preview.controllers : {}
2828
3129
  };
2829
3130
  const keys = {
2830
3131
  CONFIGURATION: "configuration"
@@ -2975,12 +3276,12 @@ async function syncMetadatas(configuration, schema) {
2975
3276
  return _.assign(metasWithDefaults, updatedMetas);
2976
3277
  }
2977
3278
  const getTargetSchema = (targetModel) => {
2978
- return getService$1("content-types").findContentType(targetModel);
3279
+ return getService$2("content-types").findContentType(targetModel);
2979
3280
  };
2980
3281
  const DEFAULT_LIST_LENGTH = 4;
2981
3282
  const MAX_ROW_SIZE = 12;
2982
3283
  const isAllowedFieldSize = (type, size) => {
2983
- const { getFieldSize } = getService$1("field-sizes");
3284
+ const { getFieldSize } = getService$2("field-sizes");
2984
3285
  const fieldSize = getFieldSize(type);
2985
3286
  if (!fieldSize.isResizable && size !== fieldSize.default) {
2986
3287
  return false;
@@ -2988,7 +3289,7 @@ const isAllowedFieldSize = (type, size) => {
2988
3289
  return size <= MAX_ROW_SIZE;
2989
3290
  };
2990
3291
  const getDefaultFieldSize = (attribute) => {
2991
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3292
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
2992
3293
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
2993
3294
  };
2994
3295
  async function createDefaultLayouts(schema) {
@@ -3023,7 +3324,7 @@ function syncLayouts(configuration, schema) {
3023
3324
  for (const el of row) {
3024
3325
  if (!hasEditableAttribute(schema, el.name))
3025
3326
  continue;
3026
- const { hasFieldSize } = getService$1("field-sizes");
3327
+ const { hasFieldSize } = getService$2("field-sizes");
3027
3328
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3028
3329
  if (!isAllowedFieldSize(fieldType, el.size)) {
3029
3330
  elementsToReAppend.push(el.name);
@@ -3163,17 +3464,17 @@ const configurationService$1 = createConfigurationService({
3163
3464
  isComponent: true,
3164
3465
  prefix: STORE_KEY_PREFIX,
3165
3466
  getModels() {
3166
- const { toContentManagerModel } = getService$1("data-mapper");
3467
+ const { toContentManagerModel } = getService$2("data-mapper");
3167
3468
  return mapValues(toContentManagerModel, strapi.components);
3168
3469
  }
3169
3470
  });
3170
3471
  const components = ({ strapi: strapi2 }) => ({
3171
3472
  findAllComponents() {
3172
- const { toContentManagerModel } = getService$1("data-mapper");
3473
+ const { toContentManagerModel } = getService$2("data-mapper");
3173
3474
  return Object.values(strapi2.components).map(toContentManagerModel);
3174
3475
  },
3175
3476
  findComponent(uid2) {
3176
- const { toContentManagerModel } = getService$1("data-mapper");
3477
+ const { toContentManagerModel } = getService$2("data-mapper");
3177
3478
  const component = strapi2.components[uid2];
3178
3479
  return isNil$1(component) ? component : toContentManagerModel(component);
3179
3480
  },
@@ -3224,17 +3525,17 @@ const configurationService = createConfigurationService({
3224
3525
  storeUtils,
3225
3526
  prefix: "content_types",
3226
3527
  getModels() {
3227
- const { toContentManagerModel } = getService$1("data-mapper");
3528
+ const { toContentManagerModel } = getService$2("data-mapper");
3228
3529
  return mapValues(toContentManagerModel, strapi.contentTypes);
3229
3530
  }
3230
3531
  });
3231
3532
  const service = ({ strapi: strapi2 }) => ({
3232
3533
  findAllContentTypes() {
3233
- const { toContentManagerModel } = getService$1("data-mapper");
3534
+ const { toContentManagerModel } = getService$2("data-mapper");
3234
3535
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3235
3536
  },
3236
3537
  findContentType(uid2) {
3237
- const { toContentManagerModel } = getService$1("data-mapper");
3538
+ const { toContentManagerModel } = getService$2("data-mapper");
3238
3539
  const contentType = strapi2.contentTypes[uid2];
3239
3540
  return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
3240
3541
  },
@@ -3263,7 +3564,7 @@ const service = ({ strapi: strapi2 }) => ({
3263
3564
  return this.findConfiguration(contentType);
3264
3565
  },
3265
3566
  findComponentsConfigurations(contentType) {
3266
- return getService$1("components").findComponentsConfigurations(contentType);
3567
+ return getService$2("components").findComponentsConfigurations(contentType);
3267
3568
  },
3268
3569
  syncConfigurations() {
3269
3570
  return configurationService.syncConfigurations();
@@ -3444,12 +3745,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3444
3745
  ability: userAbility,
3445
3746
  model
3446
3747
  });
3447
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3748
+ const { actionProvider } = strapi2.service("admin::permission");
3749
+ const toSubject = (entity) => {
3750
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3751
+ };
3448
3752
  const can = (action, entity, field) => {
3449
- return userAbility.can(action, toSubject(entity), field);
3753
+ const subject = toSubject(entity);
3754
+ const aliases = actionProvider.unstable_aliases(action, model);
3755
+ return (
3756
+ // Test the original action to see if it passes
3757
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3758
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3759
+ );
3450
3760
  };
3451
3761
  const cannot = (action, entity, field) => {
3452
- return userAbility.cannot(action, toSubject(entity), field);
3762
+ const subject = toSubject(entity);
3763
+ const aliases = actionProvider.unstable_aliases(action, model);
3764
+ return (
3765
+ // Test both the original action
3766
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3767
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3768
+ );
3453
3769
  };
3454
3770
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3455
3771
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3520,7 +3836,7 @@ const permission = ({ strapi: strapi2 }) => ({
3520
3836
  return userAbility.can(action);
3521
3837
  },
3522
3838
  async registerPermissions() {
3523
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3839
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3524
3840
  const contentTypesUids = displayedContentTypes.map(prop("uid"));
3525
3841
  const actions = [
3526
3842
  {
@@ -3796,7 +4112,7 @@ const getQueryPopulate = async (uid2, query) => {
3796
4112
  return populateQuery;
3797
4113
  };
3798
4114
  const buildDeepPopulate = (uid2) => {
3799
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4115
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3800
4116
  };
3801
4117
  const populateBuilder = (uid2) => {
3802
4118
  let getInitialPopulate = async () => {
@@ -3981,7 +4297,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
3981
4297
  */
3982
4298
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
3983
4299
  const versionsByLocale = groupBy("locale", allVersions);
3984
- delete versionsByLocale[version.locale];
4300
+ if (version.locale) {
4301
+ delete versionsByLocale[version.locale];
4302
+ }
3985
4303
  const model = strapi2.getModel(uid2);
3986
4304
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
3987
4305
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4107,7 +4425,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4107
4425
  */
4108
4426
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4109
4427
  if (!document) {
4110
- return document;
4428
+ return {
4429
+ data: document,
4430
+ meta: {
4431
+ availableLocales: [],
4432
+ availableStatus: []
4433
+ }
4434
+ };
4111
4435
  }
4112
4436
  const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
4113
4437
  if (!hasDraftAndPublish) {
@@ -4331,7 +4655,8 @@ const services = {
4331
4655
  permission,
4332
4656
  "populate-builder": populateBuilder$1,
4333
4657
  uid,
4334
- ...history.services ? history.services : {}
4658
+ ...history.services ? history.services : {},
4659
+ ...preview.services ? preview.services : {}
4335
4660
  };
4336
4661
  const index = () => {
4337
4662
  return {