@strapi/content-manager 0.0.0-experimental.9df68962083938acba06546a7901c68a63266aec → 0.0.0-experimental.a13c58eec89ab119f0e381fb79c0252979e9c125

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 (205) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js → ComponentConfigurationPage-CB0JNNKL.js} +4 -4
  3. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js.map → ComponentConfigurationPage-CB0JNNKL.js.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs → ComponentConfigurationPage-CTCh51QS.mjs} +4 -4
  5. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs.map → ComponentConfigurationPage-CTCh51QS.mjs.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js → EditConfigurationPage-BxTVjxBG.js} +4 -4
  7. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js.map → EditConfigurationPage-BxTVjxBG.js.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs → EditConfigurationPage-CVyURlPG.mjs} +4 -4
  9. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs.map → EditConfigurationPage-CVyURlPG.mjs.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-zT3fBr4Y.js → EditViewPage-Cg78RUyS.js} +62 -11
  11. package/dist/_chunks/EditViewPage-Cg78RUyS.js.map +1 -0
  12. package/dist/_chunks/{EditViewPage-CPj61RMh.mjs → EditViewPage-M1OkTFHV.mjs} +63 -12
  13. package/dist/_chunks/EditViewPage-M1OkTFHV.mjs.map +1 -0
  14. package/dist/_chunks/{Field-Boxf9Ajp.js → Field-BQoMs_At.js} +271 -154
  15. package/dist/_chunks/Field-BQoMs_At.js.map +1 -0
  16. package/dist/_chunks/{Field-dha5VnIQ.mjs → Field-D1UGGscZ.mjs} +269 -152
  17. package/dist/_chunks/Field-D1UGGscZ.mjs.map +1 -0
  18. package/dist/_chunks/{Form-y5g1SRsh.js → Form-2uPHazrg.js} +36 -17
  19. package/dist/_chunks/Form-2uPHazrg.js.map +1 -0
  20. package/dist/_chunks/{Form-DHrru2AV.mjs → Form-JOjqloMg.mjs} +36 -17
  21. package/dist/_chunks/Form-JOjqloMg.mjs.map +1 -0
  22. package/dist/_chunks/{History-Bru_KoeP.mjs → History-D6LWunSa.mjs} +77 -62
  23. package/dist/_chunks/History-D6LWunSa.mjs.map +1 -0
  24. package/dist/_chunks/{History-CqN6K7SX.js → History-DoIdauuE.js} +76 -61
  25. package/dist/_chunks/History-DoIdauuE.js.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-R_p-SbHZ.js → ListConfigurationPage-C1eYSCV7.js} +21 -9
  27. package/dist/_chunks/ListConfigurationPage-C1eYSCV7.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-D8wGABj0.mjs → ListConfigurationPage-C8J_y4eX.mjs} +21 -9
  29. package/dist/_chunks/ListConfigurationPage-C8J_y4eX.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-pEw_zug9.js → ListViewPage-Nd8_ZHjF.js} +86 -46
  31. package/dist/_chunks/ListViewPage-Nd8_ZHjF.js.map +1 -0
  32. package/dist/_chunks/{ListViewPage-SID6TRb9.mjs → ListViewPage-vkipJOxG.mjs} +84 -44
  33. package/dist/_chunks/ListViewPage-vkipJOxG.mjs.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs → NoContentTypePage-CAxkF2Vg.mjs} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs.map → NoContentTypePage-CAxkF2Vg.mjs.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js → NoContentTypePage-CsI4DiJk.js} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js.map → NoContentTypePage-CsI4DiJk.js.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js → NoPermissionsPage-D7c29n-i.js} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js.map → NoPermissionsPage-D7c29n-i.js.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs → NoPermissionsPage-DA5ACuoK.mjs} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs.map → NoPermissionsPage-DA5ACuoK.mjs.map} +1 -1
  42. package/dist/_chunks/Preview-Bwo9ft4j.mjs +288 -0
  43. package/dist/_chunks/Preview-Bwo9ft4j.mjs.map +1 -0
  44. package/dist/_chunks/Preview-DLxVMS5f.js +307 -0
  45. package/dist/_chunks/Preview-DLxVMS5f.js.map +1 -0
  46. package/dist/_chunks/{Relations-B9Crnhnn.mjs → Relations-Bddj_dxS.mjs} +73 -37
  47. package/dist/_chunks/Relations-Bddj_dxS.mjs.map +1 -0
  48. package/dist/_chunks/{Relations-DjTQ5kGB.js → Relations-CdFEx0mp.js} +72 -36
  49. package/dist/_chunks/Relations-CdFEx0mp.js.map +1 -0
  50. package/dist/_chunks/{en-fbKQxLGn.js → en-CHOp_xJv.js} +27 -16
  51. package/dist/_chunks/{en-fbKQxLGn.js.map → en-CHOp_xJv.js.map} +1 -1
  52. package/dist/_chunks/{en-Ux26r5pl.mjs → en-D_BMf0hT.mjs} +27 -16
  53. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-D_BMf0hT.mjs.map} +1 -1
  54. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  55. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  56. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  57. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  58. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  59. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  60. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  61. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  62. package/dist/_chunks/{index-DVPWZkbS.js → index-CltLAahy.js} +1066 -658
  63. package/dist/_chunks/index-CltLAahy.js.map +1 -0
  64. package/dist/_chunks/{index-DJXJw9V5.mjs → index-DmNeuXH0.mjs} +1086 -679
  65. package/dist/_chunks/index-DmNeuXH0.mjs.map +1 -0
  66. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  67. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  68. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  69. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  70. package/dist/_chunks/{layout-Bau7ZfLV.mjs → layout-D63qmUOu.mjs} +25 -12
  71. package/dist/_chunks/layout-D63qmUOu.mjs.map +1 -0
  72. package/dist/_chunks/{layout-Dm6fbiQj.js → layout-DslPJR5e.js} +24 -11
  73. package/dist/_chunks/layout-DslPJR5e.js.map +1 -0
  74. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  75. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  76. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  77. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  78. package/dist/_chunks/{relations-CKnpRgrN.js → relations-B2h_O2Xw.js} +6 -7
  79. package/dist/_chunks/relations-B2h_O2Xw.js.map +1 -0
  80. package/dist/_chunks/{relations-BH_kBSJ0.mjs → relations-X3M9aO-m.mjs} +6 -7
  81. package/dist/_chunks/relations-X3M9aO-m.mjs.map +1 -0
  82. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  83. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  84. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  85. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  86. package/dist/admin/index.js +2 -1
  87. package/dist/admin/index.js.map +1 -1
  88. package/dist/admin/index.mjs +5 -4
  89. package/dist/admin/src/exports.d.ts +1 -1
  90. package/dist/admin/src/history/index.d.ts +3 -0
  91. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  92. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  93. package/dist/admin/src/index.d.ts +1 -0
  94. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  95. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -0
  96. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +1 -1
  97. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  98. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  99. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  100. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  101. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  102. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  103. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  104. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  105. package/dist/admin/src/preview/constants.d.ts +1 -0
  106. package/dist/admin/src/preview/index.d.ts +4 -0
  107. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  108. package/dist/admin/src/preview/routes.d.ts +3 -0
  109. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  110. package/dist/admin/src/services/api.d.ts +1 -1
  111. package/dist/admin/src/services/components.d.ts +2 -2
  112. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  113. package/dist/admin/src/services/documents.d.ts +19 -17
  114. package/dist/admin/src/services/init.d.ts +1 -1
  115. package/dist/admin/src/services/relations.d.ts +2 -2
  116. package/dist/admin/src/services/uid.d.ts +3 -3
  117. package/dist/admin/src/utils/validation.d.ts +4 -1
  118. package/dist/server/index.js +548 -261
  119. package/dist/server/index.js.map +1 -1
  120. package/dist/server/index.mjs +549 -262
  121. package/dist/server/index.mjs.map +1 -1
  122. package/dist/server/src/bootstrap.d.ts.map +1 -1
  123. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  124. package/dist/server/src/controllers/index.d.ts.map +1 -1
  125. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  126. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  127. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  128. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  129. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  130. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  131. package/dist/server/src/history/services/history.d.ts.map +1 -1
  132. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  133. package/dist/server/src/history/services/utils.d.ts +4 -4
  134. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  135. package/dist/server/src/index.d.ts +4 -4
  136. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  137. package/dist/server/src/preview/constants.d.ts +2 -0
  138. package/dist/server/src/preview/constants.d.ts.map +1 -0
  139. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  140. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  141. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  142. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  143. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  144. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  145. package/dist/server/src/preview/index.d.ts +4 -0
  146. package/dist/server/src/preview/index.d.ts.map +1 -0
  147. package/dist/server/src/preview/routes/index.d.ts +8 -0
  148. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  149. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  150. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  151. package/dist/server/src/preview/services/index.d.ts +15 -0
  152. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  153. package/dist/server/src/preview/services/preview-config.d.ts +30 -0
  154. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  155. package/dist/server/src/preview/services/preview.d.ts +12 -0
  156. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  157. package/dist/server/src/preview/utils.d.ts +18 -0
  158. package/dist/server/src/preview/utils.d.ts.map +1 -0
  159. package/dist/server/src/routes/index.d.ts.map +1 -1
  160. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  161. package/dist/server/src/services/document-metadata.d.ts +8 -8
  162. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  163. package/dist/server/src/services/index.d.ts +4 -4
  164. package/dist/server/src/services/index.d.ts.map +1 -1
  165. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  166. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  167. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  168. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  169. package/dist/server/src/utils/index.d.ts +2 -0
  170. package/dist/server/src/utils/index.d.ts.map +1 -1
  171. package/dist/shared/contracts/collection-types.d.ts +3 -1
  172. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  173. package/dist/shared/contracts/index.d.ts +1 -0
  174. package/dist/shared/contracts/index.d.ts.map +1 -1
  175. package/dist/shared/contracts/preview.d.ts +27 -0
  176. package/dist/shared/contracts/preview.d.ts.map +1 -0
  177. package/dist/shared/index.js +4 -0
  178. package/dist/shared/index.js.map +1 -1
  179. package/dist/shared/index.mjs +4 -0
  180. package/dist/shared/index.mjs.map +1 -1
  181. package/package.json +13 -13
  182. package/dist/_chunks/EditViewPage-CPj61RMh.mjs.map +0 -1
  183. package/dist/_chunks/EditViewPage-zT3fBr4Y.js.map +0 -1
  184. package/dist/_chunks/Field-Boxf9Ajp.js.map +0 -1
  185. package/dist/_chunks/Field-dha5VnIQ.mjs.map +0 -1
  186. package/dist/_chunks/Form-DHrru2AV.mjs.map +0 -1
  187. package/dist/_chunks/Form-y5g1SRsh.js.map +0 -1
  188. package/dist/_chunks/History-Bru_KoeP.mjs.map +0 -1
  189. package/dist/_chunks/History-CqN6K7SX.js.map +0 -1
  190. package/dist/_chunks/ListConfigurationPage-D8wGABj0.mjs.map +0 -1
  191. package/dist/_chunks/ListConfigurationPage-R_p-SbHZ.js.map +0 -1
  192. package/dist/_chunks/ListViewPage-SID6TRb9.mjs.map +0 -1
  193. package/dist/_chunks/ListViewPage-pEw_zug9.js.map +0 -1
  194. package/dist/_chunks/Relations-B9Crnhnn.mjs.map +0 -1
  195. package/dist/_chunks/Relations-DjTQ5kGB.js.map +0 -1
  196. package/dist/_chunks/index-DJXJw9V5.mjs.map +0 -1
  197. package/dist/_chunks/index-DVPWZkbS.js.map +0 -1
  198. package/dist/_chunks/layout-Bau7ZfLV.mjs.map +0 -1
  199. package/dist/_chunks/layout-Dm6fbiQj.js.map +0 -1
  200. package/dist/_chunks/relations-BH_kBSJ0.mjs.map +0 -1
  201. package/dist/_chunks/relations-CKnpRgrN.js.map +0 -1
  202. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  203. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  204. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  205. package/strapi-server.js +0 -3
@@ -33,10 +33,10 @@ const isNil__default = /* @__PURE__ */ _interopDefault(isNil);
33
33
  const ___default = /* @__PURE__ */ _interopDefault(_);
34
34
  const qs__default = /* @__PURE__ */ _interopDefault(qs);
35
35
  const slugify__default = /* @__PURE__ */ _interopDefault(slugify);
36
- const getService$1 = (name) => {
36
+ const getService$2 = (name) => {
37
37
  return strapi.plugin("content-manager").service(name);
38
38
  };
39
- function getService(strapi2, name) {
39
+ function getService$1(strapi2, name) {
40
40
  return strapi2.service(`plugin::content-manager.${name}`);
41
41
  }
42
42
  const historyRestoreVersionSchema = yup__namespace.object().shape({
@@ -72,7 +72,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
72
72
  if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
73
73
  throw new strapiUtils.errors.ForbiddenError("contentType and documentId are required");
74
74
  }
75
- const permissionChecker2 = getService$1("permission-checker").create({
75
+ const permissionChecker2 = getService$2("permission-checker").create({
76
76
  userAbility: ctx.state.userAbility,
77
77
  model: ctx.query.contentType
78
78
  });
@@ -80,7 +80,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
80
80
  return ctx.forbidden();
81
81
  }
82
82
  const query = await permissionChecker2.sanitizeQuery(ctx.query);
83
- const { results, pagination } = await getService(strapi2, "history").findVersionsPage({
83
+ const { results, pagination } = await getService$1(strapi2, "history").findVersionsPage({
84
84
  query: {
85
85
  ...query,
86
86
  ...getValidPagination({ page: query.page, pageSize: query.pageSize })
@@ -105,14 +105,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
105
105
  async restoreVersion(ctx) {
106
106
  const request = ctx.request;
107
107
  await validateRestoreVersion(request.body, "contentType is required");
108
- const permissionChecker2 = getService$1("permission-checker").create({
108
+ const permissionChecker2 = getService$2("permission-checker").create({
109
109
  userAbility: ctx.state.userAbility,
110
110
  model: request.body.contentType
111
111
  });
112
112
  if (permissionChecker2.cannot.update()) {
113
113
  throw new strapiUtils.errors.ForbiddenError();
114
114
  }
115
- const restoredDocument = await getService(strapi2, "history").restoreVersion(
115
+ const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
116
116
  request.params.versionId
117
117
  );
118
118
  return {
@@ -121,7 +121,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
121
121
  }
122
122
  };
123
123
  };
124
- const controllers$1 = {
124
+ const controllers$2 = {
125
125
  "history-version": createHistoryVersionController
126
126
  /**
127
127
  * Casting is needed because the types aren't aware that Strapi supports
@@ -199,7 +199,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
199
199
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
200
200
  };
201
201
  const localesService = strapi2.plugin("i18n")?.service("locales");
202
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
202
203
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
204
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
203
205
  const getLocaleDictionary = async () => {
204
206
  if (!localesService)
205
207
  return {};
@@ -226,31 +228,53 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
226
228
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
227
229
  return documentMetadataService.getStatus(document, meta.availableStatus);
228
230
  };
229
- const getDeepPopulate2 = (uid2) => {
231
+ const getComponentFields = (componentUID) => {
232
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
233
+ (fieldsAcc, [key, attribute]) => {
234
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
235
+ fieldsAcc.push(key);
236
+ }
237
+ return fieldsAcc;
238
+ },
239
+ []
240
+ );
241
+ };
242
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
230
243
  const model = strapi2.getModel(uid2);
231
244
  const attributes = Object.entries(model.attributes);
245
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
232
246
  return attributes.reduce((acc, [attributeName, attribute]) => {
233
247
  switch (attribute.type) {
234
248
  case "relation": {
249
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
250
+ if (isMorphRelation) {
251
+ break;
252
+ }
235
253
  const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
236
254
  if (isVisible2) {
237
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
255
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
238
256
  }
239
257
  break;
240
258
  }
241
259
  case "media": {
242
- acc[attributeName] = { fields: ["id"] };
260
+ acc[attributeName] = { [fieldSelector]: ["id"] };
243
261
  break;
244
262
  }
245
263
  case "component": {
246
264
  const populate = getDeepPopulate2(attribute.component);
247
- acc[attributeName] = { populate };
265
+ acc[attributeName] = {
266
+ populate,
267
+ [fieldSelector]: getComponentFields(attribute.component)
268
+ };
248
269
  break;
249
270
  }
250
271
  case "dynamiczone": {
251
272
  const populatedComponents = (attribute.components || []).reduce(
252
273
  (acc2, componentUID) => {
253
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
274
+ acc2[componentUID] = {
275
+ populate: getDeepPopulate2(componentUID),
276
+ [fieldSelector]: getComponentFields(componentUID)
277
+ };
254
278
  return acc2;
255
279
  },
256
280
  {}
@@ -312,6 +336,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
312
336
  getRelationRestoreValue,
313
337
  getMediaRestoreValue,
314
338
  getDefaultLocale,
339
+ isLocalizedContentType,
315
340
  getLocaleDictionary,
316
341
  getRetentionDays,
317
342
  getVersionStatus,
@@ -334,7 +359,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
334
359
  });
335
360
  },
336
361
  async findVersionsPage(params) {
337
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
362
+ const model = strapi2.getModel(params.query.contentType);
363
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
364
+ const defaultLocale = await serviceUtils.getDefaultLocale();
365
+ let locale = null;
366
+ if (isLocalizedContentType) {
367
+ locale = params.query.locale || defaultLocale;
368
+ }
338
369
  const [{ results, pagination }, localeDictionary] = await Promise.all([
339
370
  query.findPage({
340
371
  ...params.query,
@@ -356,7 +387,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
356
387
  const attributeValue = entry.data[attributeKey];
357
388
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
358
389
  if (attributeSchema.type === "media") {
359
- const permissionChecker2 = getService$1("permission-checker").create({
390
+ const permissionChecker2 = getService$2("permission-checker").create({
360
391
  userAbility: params.state.userAbility,
361
392
  model: "plugin::upload.file"
362
393
  });
@@ -379,7 +410,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
379
410
  if (userToPopulate == null) {
380
411
  return null;
381
412
  }
382
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
413
+ return strapi2.query("admin::user").findOne({
414
+ where: {
415
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
416
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
417
+ }
418
+ });
383
419
  })
384
420
  );
385
421
  return {
@@ -392,7 +428,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
392
428
  [attributeKey]: adminUsers
393
429
  };
394
430
  }
395
- const permissionChecker2 = getService$1("permission-checker").create({
431
+ const permissionChecker2 = getService$2("permission-checker").create({
396
432
  userAbility: params.state.userAbility,
397
433
  model: attributeSchema.target
398
434
  });
@@ -490,6 +526,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
490
526
  }
491
527
  };
492
528
  };
529
+ const shouldCreateHistoryVersion = (context) => {
530
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
531
+ return false;
532
+ }
533
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
534
+ return false;
535
+ }
536
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
537
+ return false;
538
+ }
539
+ if (!context.contentType.uid.startsWith("api::")) {
540
+ return false;
541
+ }
542
+ return true;
543
+ };
544
+ const getSchemas = (uid2) => {
545
+ const attributesSchema = strapi.getModel(uid2).attributes;
546
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
547
+ (currentComponentSchemas, key) => {
548
+ const fieldSchema = attributesSchema[key];
549
+ if (fieldSchema.type === "component") {
550
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
551
+ return {
552
+ ...currentComponentSchemas,
553
+ [fieldSchema.component]: componentSchema
554
+ };
555
+ }
556
+ return currentComponentSchemas;
557
+ },
558
+ {}
559
+ );
560
+ return {
561
+ schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
562
+ componentsSchemas
563
+ };
564
+ };
493
565
  const createLifecyclesService = ({ strapi: strapi2 }) => {
494
566
  const state = {
495
567
  deleteExpiredJob: null,
@@ -502,76 +574,62 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
502
574
  return;
503
575
  }
504
576
  strapi2.documents.use(async (context, next) => {
505
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
506
- return next();
507
- }
508
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
509
- return next();
510
- }
511
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
512
- return next();
513
- }
514
- const contentTypeUid = context.contentType.uid;
515
- if (!contentTypeUid.startsWith("api::")) {
516
- return next();
517
- }
518
577
  const result = await next();
519
- const documentContext = {
520
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
521
- locale: context.params?.locale
522
- };
578
+ if (!shouldCreateHistoryVersion(context)) {
579
+ return result;
580
+ }
581
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
523
582
  const defaultLocale = await serviceUtils.getDefaultLocale();
524
- const locale = documentContext.locale || defaultLocale;
525
- if (Array.isArray(locale)) {
526
- strapi2.log.warn(
527
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
528
- );
529
- return next();
583
+ const locales = fp.castArray(context.params?.locale || defaultLocale);
584
+ if (!locales.length) {
585
+ return result;
530
586
  }
531
- const document = await strapi2.documents(contentTypeUid).findOne({
532
- documentId: documentContext.documentId,
533
- locale,
534
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
587
+ const uid2 = context.contentType.uid;
588
+ const schemas = getSchemas(uid2);
589
+ const model = strapi2.getModel(uid2);
590
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
591
+ const localeEntries = await strapi2.db.query(uid2).findMany({
592
+ where: {
593
+ documentId,
594
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
595
+ ...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
596
+ },
597
+ populate: serviceUtils.getDeepPopulate(
598
+ uid2,
599
+ true
600
+ /* use database syntax */
601
+ )
535
602
  });
536
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
537
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
538
- const componentsSchemas = Object.keys(
539
- attributesSchema
540
- ).reduce((currentComponentSchemas, key) => {
541
- const fieldSchema = attributesSchema[key];
542
- if (fieldSchema.type === "component") {
543
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
544
- return {
545
- ...currentComponentSchemas,
546
- [fieldSchema.component]: componentSchema
547
- };
548
- }
549
- return currentComponentSchemas;
550
- }, {});
551
603
  await strapi2.db.transaction(async ({ onCommit }) => {
552
- onCommit(() => {
553
- getService(strapi2, "history").createVersion({
554
- contentType: contentTypeUid,
555
- data: fp.omit(FIELDS_TO_IGNORE, document),
556
- schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
557
- componentsSchemas,
558
- relatedDocumentId: documentContext.documentId,
559
- locale,
560
- status
561
- });
604
+ onCommit(async () => {
605
+ for (const entry of localeEntries) {
606
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
607
+ await getService$1(strapi2, "history").createVersion({
608
+ contentType: uid2,
609
+ data: fp.omit(FIELDS_TO_IGNORE, entry),
610
+ relatedDocumentId: documentId,
611
+ locale: entry.locale,
612
+ status,
613
+ ...schemas
614
+ });
615
+ }
562
616
  });
563
617
  });
564
618
  return result;
565
619
  });
566
- state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
620
+ state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
567
621
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
568
622
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
569
623
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
570
624
  where: {
571
625
  created_at: {
572
- $lt: expirationDate.toISOString()
626
+ $lt: expirationDate
573
627
  }
574
628
  }
629
+ }).catch((error) => {
630
+ if (error instanceof Error) {
631
+ strapi2.log.error("Error deleting expired history versions", error.message);
632
+ }
575
633
  });
576
634
  });
577
635
  state.isInitialized = true;
@@ -583,17 +641,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
583
641
  }
584
642
  };
585
643
  };
586
- const services$1 = {
644
+ const services$2 = {
587
645
  history: createHistoryService,
588
646
  lifecycles: createLifecyclesService
589
647
  };
590
- const info = { pluginName: "content-manager", type: "admin" };
648
+ const info$1 = { pluginName: "content-manager", type: "admin" };
591
649
  const historyVersionRouter = {
592
650
  type: "admin",
593
651
  routes: [
594
652
  {
595
653
  method: "GET",
596
- info,
654
+ info: info$1,
597
655
  path: "/history-versions",
598
656
  handler: "history-version.findMany",
599
657
  config: {
@@ -602,7 +660,7 @@ const historyVersionRouter = {
602
660
  },
603
661
  {
604
662
  method: "PUT",
605
- info,
663
+ info: info$1,
606
664
  path: "/history-versions/:versionId/restore",
607
665
  handler: "history-version.restoreVersion",
608
666
  config: {
@@ -611,7 +669,7 @@ const historyVersionRouter = {
611
669
  }
612
670
  ]
613
671
  };
614
- const routes$1 = {
672
+ const routes$2 = {
615
673
  "history-version": historyVersionRouter
616
674
  };
617
675
  const historyVersion = {
@@ -658,21 +716,21 @@ const historyVersion = {
658
716
  }
659
717
  }
660
718
  };
661
- const getFeature = () => {
719
+ const getFeature$1 = () => {
662
720
  if (strapi.ee.features.isEnabled("cms-content-history")) {
663
721
  return {
664
722
  register({ strapi: strapi2 }) {
665
723
  strapi2.get("models").add(historyVersion);
666
724
  },
667
725
  bootstrap({ strapi: strapi2 }) {
668
- getService(strapi2, "lifecycles").bootstrap();
726
+ getService$1(strapi2, "lifecycles").bootstrap();
669
727
  },
670
728
  destroy({ strapi: strapi2 }) {
671
- getService(strapi2, "lifecycles").destroy();
729
+ getService$1(strapi2, "lifecycles").destroy();
672
730
  },
673
- controllers: controllers$1,
674
- services: services$1,
675
- routes: routes$1
731
+ controllers: controllers$2,
732
+ services: services$2,
733
+ routes: routes$2
676
734
  };
677
735
  }
678
736
  return {
@@ -681,7 +739,7 @@ const getFeature = () => {
681
739
  }
682
740
  };
683
741
  };
684
- const history = getFeature();
742
+ const history = getFeature$1();
685
743
  const register = async ({ strapi: strapi2 }) => {
686
744
  await history.register?.({ strapi: strapi2 });
687
745
  };
@@ -689,15 +747,165 @@ const ALLOWED_WEBHOOK_EVENTS = {
689
747
  ENTRY_PUBLISH: "entry.publish",
690
748
  ENTRY_UNPUBLISH: "entry.unpublish"
691
749
  };
750
+ const FEATURE_ID = "preview";
751
+ const info = { pluginName: "content-manager", type: "admin" };
752
+ const previewRouter = {
753
+ type: "admin",
754
+ routes: [
755
+ {
756
+ method: "GET",
757
+ info,
758
+ path: "/preview/url/:contentType",
759
+ handler: "preview.getPreviewUrl",
760
+ config: {
761
+ policies: ["admin::isAuthenticatedAdmin"]
762
+ }
763
+ }
764
+ ]
765
+ };
766
+ const routes$1 = {
767
+ preview: previewRouter
768
+ };
769
+ function getService(strapi2, name) {
770
+ return strapi2.service(`plugin::content-manager.${name}`);
771
+ }
772
+ const getPreviewUrlSchema = yup__namespace.object().shape({
773
+ // Will be undefined for single types
774
+ documentId: yup__namespace.string(),
775
+ locale: yup__namespace.string().nullable(),
776
+ status: yup__namespace.string()
777
+ }).required();
778
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
779
+ await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
780
+ const newParams = fp.pick(["documentId", "locale", "status"], params);
781
+ const model = strapi2.getModel(uid2);
782
+ if (!model || model.modelType !== "contentType") {
783
+ throw new strapiUtils.errors.ValidationError("Invalid content type");
784
+ }
785
+ const isSingleType = model?.kind === "singleType";
786
+ if (!isSingleType && !params.documentId) {
787
+ throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
788
+ }
789
+ if (isSingleType) {
790
+ const doc = await strapi2.documents(uid2).findFirst();
791
+ if (!doc) {
792
+ throw new strapiUtils.errors.NotFoundError("Document not found");
793
+ }
794
+ newParams.documentId = doc?.documentId;
795
+ }
796
+ return newParams;
797
+ };
798
+ const createPreviewController = () => {
799
+ return {
800
+ /**
801
+ * Transforms an entry into a preview URL, so that it can be previewed
802
+ * in the Content Manager.
803
+ */
804
+ async getPreviewUrl(ctx) {
805
+ const uid2 = ctx.params.contentType;
806
+ const query = ctx.request.query;
807
+ const params = await validatePreviewUrl(strapi, uid2, query);
808
+ const previewService = getService(strapi, "preview");
809
+ const url = await previewService.getPreviewUrl(uid2, params);
810
+ if (!url) {
811
+ ctx.status = 204;
812
+ }
813
+ return {
814
+ data: { url }
815
+ };
816
+ }
817
+ };
818
+ };
819
+ const controllers$1 = {
820
+ preview: createPreviewController
821
+ /**
822
+ * Casting is needed because the types aren't aware that Strapi supports
823
+ * passing a controller factory as the value, instead of a controller object directly
824
+ */
825
+ };
826
+ const createPreviewService = ({ strapi: strapi2 }) => {
827
+ const config = getService(strapi2, "preview-config");
828
+ return {
829
+ async getPreviewUrl(uid2, params) {
830
+ const handler = config.getPreviewHandler();
831
+ try {
832
+ return handler(uid2, params);
833
+ } catch (error) {
834
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
835
+ throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
836
+ }
837
+ return;
838
+ }
839
+ };
840
+ };
841
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
842
+ return {
843
+ isEnabled() {
844
+ const config = strapi2.config.get("admin.preview");
845
+ if (!config) {
846
+ return false;
847
+ }
848
+ return config?.enabled ?? true;
849
+ },
850
+ /**
851
+ * Validate if the configuration is valid
852
+ */
853
+ validate() {
854
+ if (!this.isEnabled()) {
855
+ return;
856
+ }
857
+ const handler = this.getPreviewHandler();
858
+ if (typeof handler !== "function") {
859
+ throw new strapiUtils.errors.ValidationError(
860
+ "Preview configuration is invalid. Handler must be a function"
861
+ );
862
+ }
863
+ },
864
+ /**
865
+ * Utility to get the preview handler from the configuration
866
+ */
867
+ getPreviewHandler() {
868
+ const config = strapi2.config.get("admin.preview");
869
+ const emptyHandler = () => {
870
+ return void 0;
871
+ };
872
+ if (!this.isEnabled()) {
873
+ return emptyHandler;
874
+ }
875
+ return config?.config?.handler || emptyHandler;
876
+ }
877
+ };
878
+ };
879
+ const services$1 = {
880
+ preview: createPreviewService,
881
+ "preview-config": createPreviewConfigService
882
+ };
883
+ const getFeature = () => {
884
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
885
+ return {};
886
+ }
887
+ return {
888
+ bootstrap() {
889
+ console.log("Bootstrapping preview server");
890
+ const config = getService(strapi, "preview-config");
891
+ config.validate();
892
+ },
893
+ routes: routes$1,
894
+ controllers: controllers$1,
895
+ services: services$1
896
+ };
897
+ };
898
+ const preview = getFeature();
692
899
  const bootstrap = async () => {
693
900
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
694
901
  strapi.get("webhookStore").addAllowedEvent(key, value);
695
902
  });
696
- getService$1("field-sizes").setCustomFieldInputSizes();
697
- await getService$1("components").syncConfigurations();
698
- await getService$1("content-types").syncConfigurations();
699
- await getService$1("permission").registerPermissions();
903
+ getService$2("field-sizes").setCustomFieldInputSizes();
904
+ await getService$2("components").syncConfigurations();
905
+ await getService$2("content-types").syncConfigurations();
906
+ await getService$2("permission").registerPermissions();
700
907
  await history.bootstrap?.({ strapi });
908
+ await preview.bootstrap?.({ strapi });
701
909
  };
702
910
  const destroy = async ({ strapi: strapi2 }) => {
703
911
  await history.destroy?.({ strapi: strapi2 });
@@ -1187,7 +1395,8 @@ const admin = {
1187
1395
  };
1188
1396
  const routes = {
1189
1397
  admin,
1190
- ...history.routes ? history.routes : {}
1398
+ ...history.routes ? history.routes : {},
1399
+ ...preview.routes ? preview.routes : {}
1191
1400
  };
1192
1401
  const hasPermissionsSchema = strapiUtils.yup.object({
1193
1402
  actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
@@ -1198,6 +1407,11 @@ const { createPolicy } = strapiUtils.policy;
1198
1407
  const hasPermissions = createPolicy({
1199
1408
  name: "plugin::content-manager.hasPermissions",
1200
1409
  validator: validateHasPermissionsInput,
1410
+ /**
1411
+ * NOTE: Action aliases are currently not checked at this level (policy).
1412
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1413
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1414
+ */
1201
1415
  handler(ctx, config = {}) {
1202
1416
  const { actions = [], hasAtLeastOne = false } = config;
1203
1417
  const { userAbility } = ctx.state;
@@ -1439,7 +1653,7 @@ const createMetadasSchema = (schema) => {
1439
1653
  if (!value) {
1440
1654
  return strapiUtils.yup.string();
1441
1655
  }
1442
- const targetSchema = getService$1("content-types").findContentType(
1656
+ const targetSchema = getService$2("content-types").findContentType(
1443
1657
  schema.attributes[key].targetModel
1444
1658
  );
1445
1659
  if (!targetSchema) {
@@ -1591,9 +1805,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
1591
1805
  (value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1592
1806
  );
1593
1807
  const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
1594
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1808
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1595
1809
  const { allowMultipleLocales } = opts;
1596
- const { locale, status, ...rest } = request || {};
1810
+ const { locale, status: providedStatus, ...rest } = request || {};
1811
+ const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1812
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1597
1813
  const schema = strapiUtils.yup.object().shape({
1598
1814
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1599
1815
  status: statusSchema
@@ -1606,7 +1822,7 @@ const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales
1606
1822
  }
1607
1823
  };
1608
1824
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1609
- const documentMetadata2 = getService$1("document-metadata");
1825
+ const documentMetadata2 = getService$2("document-metadata");
1610
1826
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1611
1827
  let {
1612
1828
  meta: { availableLocales, availableStatus }
@@ -1632,8 +1848,8 @@ const createDocument = async (ctx, opts) => {
1632
1848
  const { userAbility, user } = ctx.state;
1633
1849
  const { model } = ctx.params;
1634
1850
  const { body } = ctx.request;
1635
- const documentManager2 = getService$1("document-manager");
1636
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1851
+ const documentManager2 = getService$2("document-manager");
1852
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1637
1853
  if (permissionChecker2.cannot.create()) {
1638
1854
  throw new strapiUtils.errors.ForbiddenError();
1639
1855
  }
@@ -1641,7 +1857,7 @@ const createDocument = async (ctx, opts) => {
1641
1857
  const setCreator = strapiUtils.setCreatorFields({ user });
1642
1858
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1643
1859
  const sanitizedBody = await sanitizeFn(body);
1644
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1860
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1645
1861
  return documentManager2.create(model, {
1646
1862
  data: sanitizedBody,
1647
1863
  locale,
@@ -1653,14 +1869,14 @@ const updateDocument = async (ctx, opts) => {
1653
1869
  const { userAbility, user } = ctx.state;
1654
1870
  const { id, model } = ctx.params;
1655
1871
  const { body } = ctx.request;
1656
- const documentManager2 = getService$1("document-manager");
1657
- 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 });
1658
1874
  if (permissionChecker2.cannot.update()) {
1659
1875
  throw new strapiUtils.errors.ForbiddenError();
1660
1876
  }
1661
1877
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1662
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1663
- const { locale } = await getDocumentLocaleAndStatus(body);
1878
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1879
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1664
1880
  const [documentVersion, documentExists] = await Promise.all([
1665
1881
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1666
1882
  documentManager2.exists(model, id)
@@ -1676,7 +1892,7 @@ const updateDocument = async (ctx, opts) => {
1676
1892
  throw new strapiUtils.errors.ForbiddenError();
1677
1893
  }
1678
1894
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1679
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1895
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1680
1896
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1681
1897
  const sanitizedBody = await sanitizeFn(body);
1682
1898
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1690,15 +1906,15 @@ const collectionTypes = {
1690
1906
  const { userAbility } = ctx.state;
1691
1907
  const { model } = ctx.params;
1692
1908
  const { query } = ctx.request;
1693
- const documentMetadata2 = getService$1("document-metadata");
1694
- const documentManager2 = getService$1("document-manager");
1695
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1909
+ const documentMetadata2 = getService$2("document-metadata");
1910
+ const documentManager2 = getService$2("document-manager");
1911
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1696
1912
  if (permissionChecker2.cannot.read()) {
1697
1913
  return ctx.forbidden();
1698
1914
  }
1699
1915
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1700
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1701
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1916
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1917
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1702
1918
  const { results: documents, pagination } = await documentManager2.findPage(
1703
1919
  { ...permissionQuery, populate, locale, status },
1704
1920
  model
@@ -1726,14 +1942,14 @@ const collectionTypes = {
1726
1942
  async findOne(ctx) {
1727
1943
  const { userAbility } = ctx.state;
1728
1944
  const { model, id } = ctx.params;
1729
- const documentManager2 = getService$1("document-manager");
1730
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1945
+ const documentManager2 = getService$2("document-manager");
1946
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1731
1947
  if (permissionChecker2.cannot.read()) {
1732
1948
  return ctx.forbidden();
1733
1949
  }
1734
1950
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1735
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1736
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1951
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1952
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1737
1953
  const version = await documentManager2.findOne(id, model, {
1738
1954
  populate,
1739
1955
  locale,
@@ -1748,7 +1964,7 @@ const collectionTypes = {
1748
1964
  permissionChecker2,
1749
1965
  model,
1750
1966
  // @ts-expect-error TODO: fix
1751
- { id, locale, publishedAt: null },
1967
+ { documentId: id, locale, publishedAt: null },
1752
1968
  { availableLocales: true, availableStatus: false }
1753
1969
  );
1754
1970
  ctx.body = { data: {}, meta };
@@ -1763,7 +1979,7 @@ const collectionTypes = {
1763
1979
  async create(ctx) {
1764
1980
  const { userAbility } = ctx.state;
1765
1981
  const { model } = ctx.params;
1766
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1982
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1767
1983
  const [totalEntries, document] = await Promise.all([
1768
1984
  strapi.db.query(model).count(),
1769
1985
  createDocument(ctx)
@@ -1784,7 +2000,7 @@ const collectionTypes = {
1784
2000
  async update(ctx) {
1785
2001
  const { userAbility } = ctx.state;
1786
2002
  const { model } = ctx.params;
1787
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2003
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1788
2004
  const updatedVersion = await updateDocument(ctx);
1789
2005
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1790
2006
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1793,14 +2009,14 @@ const collectionTypes = {
1793
2009
  const { userAbility, user } = ctx.state;
1794
2010
  const { model, sourceId: id } = ctx.params;
1795
2011
  const { body } = ctx.request;
1796
- const documentManager2 = getService$1("document-manager");
1797
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2012
+ const documentManager2 = getService$2("document-manager");
2013
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1798
2014
  if (permissionChecker2.cannot.create()) {
1799
2015
  return ctx.forbidden();
1800
2016
  }
1801
2017
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1802
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1803
- const { locale } = await getDocumentLocaleAndStatus(body);
2018
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2019
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1804
2020
  const document = await documentManager2.findOne(id, model, {
1805
2021
  populate,
1806
2022
  locale,
@@ -1838,14 +2054,14 @@ const collectionTypes = {
1838
2054
  async delete(ctx) {
1839
2055
  const { userAbility } = ctx.state;
1840
2056
  const { id, model } = ctx.params;
1841
- const documentManager2 = getService$1("document-manager");
1842
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2057
+ const documentManager2 = getService$2("document-manager");
2058
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1843
2059
  if (permissionChecker2.cannot.delete()) {
1844
2060
  return ctx.forbidden();
1845
2061
  }
1846
2062
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1847
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1848
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
2063
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2064
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1849
2065
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1850
2066
  if (documentLocales.length === 0) {
1851
2067
  return ctx.notFound();
@@ -1866,19 +2082,42 @@ const collectionTypes = {
1866
2082
  const { userAbility } = ctx.state;
1867
2083
  const { id, model } = ctx.params;
1868
2084
  const { body } = ctx.request;
1869
- const documentManager2 = getService$1("document-manager");
1870
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2085
+ const documentManager2 = getService$2("document-manager");
2086
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1871
2087
  if (permissionChecker2.cannot.publish()) {
1872
2088
  return ctx.forbidden();
1873
2089
  }
1874
2090
  const publishedDocument = await strapi.db.transaction(async () => {
1875
2091
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1876
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1877
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
2092
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2093
+ let document;
2094
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2095
+ const isCreate = fp.isNil(id);
2096
+ if (isCreate) {
2097
+ if (permissionChecker2.cannot.create()) {
2098
+ throw new strapiUtils.errors.ForbiddenError();
2099
+ }
2100
+ document = await createDocument(ctx, { populate });
2101
+ }
2102
+ const isUpdate = !isCreate;
2103
+ if (isUpdate) {
2104
+ const documentExists = documentManager2.exists(model, id);
2105
+ if (!documentExists) {
2106
+ throw new strapiUtils.errors.NotFoundError("Document not found");
2107
+ }
2108
+ document = await documentManager2.findOne(id, model, { populate, locale });
2109
+ if (!document) {
2110
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2111
+ throw new strapiUtils.errors.ForbiddenError();
2112
+ }
2113
+ document = await updateDocument(ctx);
2114
+ } else if (permissionChecker2.can.update(document)) {
2115
+ await updateDocument(ctx);
2116
+ }
2117
+ }
1878
2118
  if (permissionChecker2.cannot.publish(document)) {
1879
2119
  throw new strapiUtils.errors.ForbiddenError();
1880
2120
  }
1881
- const { locale } = await getDocumentLocaleAndStatus(body);
1882
2121
  const publishResult = await documentManager2.publish(document.documentId, model, {
1883
2122
  locale
1884
2123
  // TODO: Allow setting creator fields on publish
@@ -1898,14 +2137,16 @@ const collectionTypes = {
1898
2137
  const { body } = ctx.request;
1899
2138
  const { documentIds } = body;
1900
2139
  await validateBulkActionInput(body);
1901
- const documentManager2 = getService$1("document-manager");
1902
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2140
+ const documentManager2 = getService$2("document-manager");
2141
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1903
2142
  if (permissionChecker2.cannot.publish()) {
1904
2143
  return ctx.forbidden();
1905
2144
  }
1906
2145
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1907
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1908
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
2146
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2147
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2148
+ allowMultipleLocales: true
2149
+ });
1909
2150
  const entityPromises = documentIds.map(
1910
2151
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1911
2152
  );
@@ -1927,12 +2168,14 @@ const collectionTypes = {
1927
2168
  const { body } = ctx.request;
1928
2169
  const { documentIds } = body;
1929
2170
  await validateBulkActionInput(body);
1930
- const documentManager2 = getService$1("document-manager");
1931
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2171
+ const documentManager2 = getService$2("document-manager");
2172
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1932
2173
  if (permissionChecker2.cannot.unpublish()) {
1933
2174
  return ctx.forbidden();
1934
2175
  }
1935
- const { locale } = await getDocumentLocaleAndStatus(body);
2176
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2177
+ allowMultipleLocales: true
2178
+ });
1936
2179
  const entityPromises = documentIds.map(
1937
2180
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1938
2181
  );
@@ -1955,8 +2198,8 @@ const collectionTypes = {
1955
2198
  const {
1956
2199
  body: { discardDraft, ...body }
1957
2200
  } = ctx.request;
1958
- const documentManager2 = getService$1("document-manager");
1959
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2201
+ const documentManager2 = getService$2("document-manager");
2202
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1960
2203
  if (permissionChecker2.cannot.unpublish()) {
1961
2204
  return ctx.forbidden();
1962
2205
  }
@@ -1964,8 +2207,8 @@ const collectionTypes = {
1964
2207
  return ctx.forbidden();
1965
2208
  }
1966
2209
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1967
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1968
- const { locale } = await getDocumentLocaleAndStatus(body);
2210
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2211
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1969
2212
  const document = await documentManager2.findOne(id, model, {
1970
2213
  populate,
1971
2214
  locale,
@@ -1995,14 +2238,14 @@ const collectionTypes = {
1995
2238
  const { userAbility } = ctx.state;
1996
2239
  const { id, model } = ctx.params;
1997
2240
  const { body } = ctx.request;
1998
- const documentManager2 = getService$1("document-manager");
1999
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2241
+ const documentManager2 = getService$2("document-manager");
2242
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2000
2243
  if (permissionChecker2.cannot.discard()) {
2001
2244
  return ctx.forbidden();
2002
2245
  }
2003
2246
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2004
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2005
- const { locale } = await getDocumentLocaleAndStatus(body);
2247
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2248
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2006
2249
  const document = await documentManager2.findOne(id, model, {
2007
2250
  populate,
2008
2251
  locale,
@@ -2026,14 +2269,14 @@ const collectionTypes = {
2026
2269
  const { query, body } = ctx.request;
2027
2270
  const { documentIds } = body;
2028
2271
  await validateBulkActionInput(body);
2029
- const documentManager2 = getService$1("document-manager");
2030
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2272
+ const documentManager2 = getService$2("document-manager");
2273
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2031
2274
  if (permissionChecker2.cannot.delete()) {
2032
2275
  return ctx.forbidden();
2033
2276
  }
2034
2277
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2035
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2036
- const { locale } = await getDocumentLocaleAndStatus(body);
2278
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2279
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2037
2280
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2038
2281
  populate,
2039
2282
  locale
@@ -2053,14 +2296,14 @@ const collectionTypes = {
2053
2296
  async countDraftRelations(ctx) {
2054
2297
  const { userAbility } = ctx.state;
2055
2298
  const { model, id } = ctx.params;
2056
- const documentManager2 = getService$1("document-manager");
2057
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2299
+ const documentManager2 = getService$2("document-manager");
2300
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2058
2301
  if (permissionChecker2.cannot.read()) {
2059
2302
  return ctx.forbidden();
2060
2303
  }
2061
2304
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2062
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2063
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2305
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2306
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2064
2307
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2065
2308
  if (!entity) {
2066
2309
  return ctx.notFound();
@@ -2078,8 +2321,8 @@ const collectionTypes = {
2078
2321
  const ids = ctx.request.query.documentIds;
2079
2322
  const locale = ctx.request.query.locale;
2080
2323
  const { model } = ctx.params;
2081
- const documentManager2 = getService$1("document-manager");
2082
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2324
+ const documentManager2 = getService$2("document-manager");
2325
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2083
2326
  if (permissionChecker2.cannot.read()) {
2084
2327
  return ctx.forbidden();
2085
2328
  }
@@ -2103,13 +2346,13 @@ const collectionTypes = {
2103
2346
  };
2104
2347
  const components$1 = {
2105
2348
  findComponents(ctx) {
2106
- const components2 = getService$1("components").findAllComponents();
2107
- const { toDto } = getService$1("data-mapper");
2349
+ const components2 = getService$2("components").findAllComponents();
2350
+ const { toDto } = getService$2("data-mapper");
2108
2351
  ctx.body = { data: components2.map(toDto) };
2109
2352
  },
2110
2353
  async findComponentConfiguration(ctx) {
2111
2354
  const { uid: uid2 } = ctx.params;
2112
- const componentService = getService$1("components");
2355
+ const componentService = getService$2("components");
2113
2356
  const component = componentService.findComponent(uid2);
2114
2357
  if (!component) {
2115
2358
  return ctx.notFound("component.notFound");
@@ -2126,7 +2369,7 @@ const components$1 = {
2126
2369
  async updateComponentConfiguration(ctx) {
2127
2370
  const { uid: uid2 } = ctx.params;
2128
2371
  const { body } = ctx.request;
2129
- const componentService = getService$1("components");
2372
+ const componentService = getService$2("components");
2130
2373
  const component = componentService.findComponent(uid2);
2131
2374
  if (!component) {
2132
2375
  return ctx.notFound("component.notFound");
@@ -2160,12 +2403,12 @@ const contentTypes = {
2160
2403
  } catch (error) {
2161
2404
  return ctx.send({ error }, 400);
2162
2405
  }
2163
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2164
- const { toDto } = getService$1("data-mapper");
2406
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2407
+ const { toDto } = getService$2("data-mapper");
2165
2408
  ctx.body = { data: contentTypes2.map(toDto) };
2166
2409
  },
2167
2410
  async findContentTypesSettings(ctx) {
2168
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2411
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2169
2412
  const contentTypes2 = await findAllContentTypes();
2170
2413
  const configurations = await Promise.all(
2171
2414
  contentTypes2.map(async (contentType) => {
@@ -2179,7 +2422,7 @@ const contentTypes = {
2179
2422
  },
2180
2423
  async findContentTypeConfiguration(ctx) {
2181
2424
  const { uid: uid2 } = ctx.params;
2182
- const contentTypeService = getService$1("content-types");
2425
+ const contentTypeService = getService$2("content-types");
2183
2426
  const contentType = await contentTypeService.findContentType(uid2);
2184
2427
  if (!contentType) {
2185
2428
  return ctx.notFound("contentType.notFound");
@@ -2201,13 +2444,13 @@ const contentTypes = {
2201
2444
  const { userAbility } = ctx.state;
2202
2445
  const { uid: uid2 } = ctx.params;
2203
2446
  const { body } = ctx.request;
2204
- const contentTypeService = getService$1("content-types");
2205
- const metricsService = getService$1("metrics");
2447
+ const contentTypeService = getService$2("content-types");
2448
+ const metricsService = getService$2("metrics");
2206
2449
  const contentType = await contentTypeService.findContentType(uid2);
2207
2450
  if (!contentType) {
2208
2451
  return ctx.notFound("contentType.notFound");
2209
2452
  }
2210
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2453
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2211
2454
  return ctx.forbidden();
2212
2455
  }
2213
2456
  let input;
@@ -2240,10 +2483,10 @@ const contentTypes = {
2240
2483
  };
2241
2484
  const init = {
2242
2485
  getInitData(ctx) {
2243
- const { toDto } = getService$1("data-mapper");
2244
- const { findAllComponents } = getService$1("components");
2245
- const { getAllFieldSizes } = getService$1("field-sizes");
2246
- const { findAllContentTypes } = getService$1("content-types");
2486
+ const { toDto } = getService$2("data-mapper");
2487
+ const { findAllComponents } = getService$2("components");
2488
+ const { getAllFieldSizes } = getService$2("field-sizes");
2489
+ const { findAllContentTypes } = getService$2("content-types");
2247
2490
  ctx.body = {
2248
2491
  data: {
2249
2492
  fieldSizes: getAllFieldSizes(),
@@ -2279,36 +2522,41 @@ const addFiltersClause = (params, filtersClause) => {
2279
2522
  params.filters.$and.push(filtersClause);
2280
2523
  };
2281
2524
  const sanitizeMainField = (model, mainField, userAbility) => {
2282
- const permissionChecker2 = getService$1("permission-checker").create({
2525
+ const permissionChecker2 = getService$2("permission-checker").create({
2283
2526
  userAbility,
2284
2527
  model: model.uid
2285
2528
  });
2286
- if (!isListable(model, mainField)) {
2529
+ const isMainFieldListable = isListable(model, mainField);
2530
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2531
+ if (!isMainFieldListable || !canReadMainField) {
2287
2532
  return "id";
2288
2533
  }
2289
- if (permissionChecker2.cannot.read(null, mainField)) {
2290
- if (model.uid === "plugin::users-permissions.role") {
2291
- const userPermissionChecker = getService$1("permission-checker").create({
2292
- userAbility,
2293
- model: "plugin::users-permissions.user"
2294
- });
2295
- if (userPermissionChecker.can.read()) {
2296
- return "name";
2297
- }
2298
- }
2299
- return "id";
2534
+ if (model.uid === "plugin::users-permissions.role") {
2535
+ return "name";
2300
2536
  }
2301
2537
  return mainField;
2302
2538
  };
2303
- const addStatusToRelations = async (uid2, relations2) => {
2304
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2539
+ const addStatusToRelations = async (targetUid, relations2) => {
2540
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2305
2541
  return relations2;
2306
2542
  }
2307
- const documentMetadata2 = getService$1("document-metadata");
2308
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2543
+ const documentMetadata2 = getService$2("document-metadata");
2544
+ if (!relations2.length) {
2545
+ return relations2;
2546
+ }
2547
+ const firstRelation = relations2[0];
2548
+ const filters = {
2549
+ documentId: { $in: relations2.map((r) => r.documentId) },
2550
+ // NOTE: find the "opposite" status
2551
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2552
+ };
2553
+ const availableStatus = await strapi.query(targetUid).findMany({
2554
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2555
+ filters
2556
+ });
2309
2557
  return relations2.map((relation) => {
2310
- const availableStatuses = documentsAvailableStatus.filter(
2311
- (availableDocument) => availableDocument.documentId === relation.documentId
2558
+ const availableStatuses = availableStatus.filter(
2559
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2312
2560
  );
2313
2561
  return {
2314
2562
  ...relation,
@@ -2329,11 +2577,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2329
2577
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2330
2578
  const isSourceLocalized = isLocalized(sourceModel);
2331
2579
  const isTargetLocalized = isLocalized(targetModel);
2332
- let validatedLocale = locale;
2333
- if (!targetModel || !isTargetLocalized)
2334
- validatedLocale = void 0;
2335
2580
  return {
2336
- locale: validatedLocale,
2581
+ locale,
2337
2582
  isSourceLocalized,
2338
2583
  isTargetLocalized
2339
2584
  };
@@ -2373,7 +2618,7 @@ const relations = {
2373
2618
  ctx.request?.query?.locale
2374
2619
  );
2375
2620
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2376
- const permissionChecker2 = getService$1("permission-checker").create({
2621
+ const permissionChecker2 = getService$2("permission-checker").create({
2377
2622
  userAbility,
2378
2623
  model
2379
2624
  });
@@ -2398,7 +2643,7 @@ const relations = {
2398
2643
  where.id = id;
2399
2644
  }
2400
2645
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2401
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2646
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2402
2647
  const currentEntity = await strapi.db.query(model).findOne({
2403
2648
  where,
2404
2649
  populate
@@ -2413,7 +2658,7 @@ const relations = {
2413
2658
  }
2414
2659
  entryId = currentEntity.id;
2415
2660
  }
2416
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2661
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2417
2662
  const targetSchema = strapi.getModel(targetUid);
2418
2663
  const mainField = fp.flow(
2419
2664
  fp.prop(`metadatas.${targetField}.edit.mainField`),
@@ -2436,7 +2681,7 @@ const relations = {
2436
2681
  attribute,
2437
2682
  fieldsToSelect,
2438
2683
  mainField,
2439
- source: { schema: sourceSchema },
2684
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2440
2685
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2441
2686
  sourceSchema,
2442
2687
  targetSchema,
@@ -2458,7 +2703,8 @@ const relations = {
2458
2703
  fieldsToSelect,
2459
2704
  mainField,
2460
2705
  source: {
2461
- schema: { uid: sourceUid, modelType: sourceModelType }
2706
+ schema: { uid: sourceUid, modelType: sourceModelType },
2707
+ isLocalized: isSourceLocalized
2462
2708
  },
2463
2709
  target: {
2464
2710
  schema: { uid: targetUid },
@@ -2466,7 +2712,7 @@ const relations = {
2466
2712
  }
2467
2713
  } = await this.extractAndValidateRequestInfo(ctx, id);
2468
2714
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2469
- const permissionChecker2 = getService$1("permission-checker").create({
2715
+ const permissionChecker2 = getService$2("permission-checker").create({
2470
2716
  userAbility: ctx.state.userAbility,
2471
2717
  model: targetUid
2472
2718
  });
@@ -2496,12 +2742,16 @@ const relations = {
2496
2742
  } else {
2497
2743
  where.id = id;
2498
2744
  }
2499
- if (status) {
2500
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2745
+ const publishedAt = getPublishedAtClause(status, targetUid);
2746
+ if (!fp.isEmpty(publishedAt)) {
2747
+ where[`${alias}.published_at`] = publishedAt;
2501
2748
  }
2502
- if (filterByLocale) {
2749
+ if (isTargetLocalized && locale) {
2503
2750
  where[`${alias}.locale`] = locale;
2504
2751
  }
2752
+ if (isSourceLocalized && locale) {
2753
+ where.locale = locale;
2754
+ }
2505
2755
  if ((idsToInclude?.length ?? 0) !== 0) {
2506
2756
  where[`${alias}.id`].$notIn = idsToInclude;
2507
2757
  }
@@ -2519,7 +2769,8 @@ const relations = {
2519
2769
  id: { $notIn: fp.uniq(idsToOmit) }
2520
2770
  });
2521
2771
  }
2522
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2772
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2773
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2523
2774
  ctx.body = {
2524
2775
  ...res,
2525
2776
  results: await addStatusToRelations(targetUid, res.results)
@@ -2534,29 +2785,39 @@ const relations = {
2534
2785
  attribute,
2535
2786
  targetField,
2536
2787
  fieldsToSelect,
2537
- source: {
2538
- schema: { uid: sourceUid }
2539
- },
2540
- target: {
2541
- schema: { uid: targetUid }
2542
- }
2788
+ status,
2789
+ source: { schema: sourceSchema },
2790
+ target: { schema: targetSchema }
2543
2791
  } = await this.extractAndValidateRequestInfo(ctx, id);
2544
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2792
+ const { uid: sourceUid } = sourceSchema;
2793
+ const { uid: targetUid } = targetSchema;
2794
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2545
2795
  const dbQuery = strapi.db.query(sourceUid);
2546
2796
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2797
+ const filters = {};
2798
+ if (sourceSchema?.options?.draftAndPublish) {
2799
+ if (targetSchema?.options?.draftAndPublish) {
2800
+ if (status === "published") {
2801
+ filters.publishedAt = { $notNull: true };
2802
+ } else {
2803
+ filters.publishedAt = { $null: true };
2804
+ }
2805
+ }
2806
+ } else if (targetSchema?.options?.draftAndPublish) {
2807
+ filters.publishedAt = { $null: true };
2808
+ }
2547
2809
  const res = await loadRelations({ id: entryId }, targetField, {
2548
- select: ["id", "documentId", "locale", "publishedAt"],
2810
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2549
2811
  ordering: "desc",
2550
2812
  page: ctx.request.query.page,
2551
- pageSize: ctx.request.query.pageSize
2813
+ pageSize: ctx.request.query.pageSize,
2814
+ filters
2552
2815
  });
2553
2816
  const loadedIds = res.results.map((item) => item.id);
2554
2817
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2555
2818
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2556
2819
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2557
- ordering: "desc",
2558
- page: ctx.request.query.page,
2559
- pageSize: ctx.request.query.pageSize
2820
+ ordering: "desc"
2560
2821
  });
2561
2822
  const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
2562
2823
  ctx.body = {
@@ -2571,10 +2832,10 @@ const relations = {
2571
2832
  }
2572
2833
  };
2573
2834
  const buildPopulateFromQuery = async (query, model) => {
2574
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2835
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2575
2836
  };
2576
2837
  const findDocument = async (query, uid2, opts = {}) => {
2577
- const documentManager2 = getService$1("document-manager");
2838
+ const documentManager2 = getService$2("document-manager");
2578
2839
  const populate = await buildPopulateFromQuery(query, uid2);
2579
2840
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2580
2841
  };
@@ -2582,13 +2843,13 @@ const createOrUpdateDocument = async (ctx, opts) => {
2582
2843
  const { user, userAbility } = ctx.state;
2583
2844
  const { model } = ctx.params;
2584
2845
  const { body, query } = ctx.request;
2585
- const documentManager2 = getService$1("document-manager");
2586
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2846
+ const documentManager2 = getService$2("document-manager");
2847
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2587
2848
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2588
2849
  throw new strapiUtils.errors.ForbiddenError();
2589
2850
  }
2590
2851
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2591
- const { locale } = await getDocumentLocaleAndStatus(body);
2852
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2592
2853
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2593
2854
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2594
2855
  // Find the first document to check if it exists
@@ -2624,12 +2885,12 @@ const singleTypes = {
2624
2885
  const { userAbility } = ctx.state;
2625
2886
  const { model } = ctx.params;
2626
2887
  const { query = {} } = ctx.request;
2627
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2888
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2628
2889
  if (permissionChecker2.cannot.read()) {
2629
2890
  return ctx.forbidden();
2630
2891
  }
2631
2892
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2632
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2893
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2633
2894
  const version = await findDocument(permissionQuery, model, { locale, status });
2634
2895
  if (!version) {
2635
2896
  if (permissionChecker2.cannot.create()) {
@@ -2643,7 +2904,7 @@ const singleTypes = {
2643
2904
  permissionChecker2,
2644
2905
  model,
2645
2906
  // @ts-expect-error - fix types
2646
- { id: document.documentId, locale, publishedAt: null },
2907
+ { documentId: document.documentId, locale, publishedAt: null },
2647
2908
  { availableLocales: true, availableStatus: false }
2648
2909
  );
2649
2910
  ctx.body = { data: {}, meta };
@@ -2658,7 +2919,7 @@ const singleTypes = {
2658
2919
  async createOrUpdate(ctx) {
2659
2920
  const { userAbility } = ctx.state;
2660
2921
  const { model } = ctx.params;
2661
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2922
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2662
2923
  const document = await createOrUpdateDocument(ctx);
2663
2924
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2664
2925
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2667,14 +2928,14 @@ const singleTypes = {
2667
2928
  const { userAbility } = ctx.state;
2668
2929
  const { model } = ctx.params;
2669
2930
  const { query = {} } = ctx.request;
2670
- const documentManager2 = getService$1("document-manager");
2671
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2931
+ const documentManager2 = getService$2("document-manager");
2932
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2672
2933
  if (permissionChecker2.cannot.delete()) {
2673
2934
  return ctx.forbidden();
2674
2935
  }
2675
2936
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2676
2937
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2677
- const { locale } = await getDocumentLocaleAndStatus(query);
2938
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2678
2939
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2679
2940
  populate,
2680
2941
  locale
@@ -2696,8 +2957,8 @@ const singleTypes = {
2696
2957
  const { userAbility } = ctx.state;
2697
2958
  const { model } = ctx.params;
2698
2959
  const { query = {} } = ctx.request;
2699
- const documentManager2 = getService$1("document-manager");
2700
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2960
+ const documentManager2 = getService$2("document-manager");
2961
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2701
2962
  if (permissionChecker2.cannot.publish()) {
2702
2963
  return ctx.forbidden();
2703
2964
  }
@@ -2711,7 +2972,7 @@ const singleTypes = {
2711
2972
  if (permissionChecker2.cannot.publish(document)) {
2712
2973
  throw new strapiUtils.errors.ForbiddenError();
2713
2974
  }
2714
- const { locale } = await getDocumentLocaleAndStatus(document);
2975
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2715
2976
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2716
2977
  return publishResult.at(0);
2717
2978
  });
@@ -2725,8 +2986,8 @@ const singleTypes = {
2725
2986
  body: { discardDraft, ...body },
2726
2987
  query = {}
2727
2988
  } = ctx.request;
2728
- const documentManager2 = getService$1("document-manager");
2729
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2989
+ const documentManager2 = getService$2("document-manager");
2990
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2730
2991
  if (permissionChecker2.cannot.unpublish()) {
2731
2992
  return ctx.forbidden();
2732
2993
  }
@@ -2734,7 +2995,7 @@ const singleTypes = {
2734
2995
  return ctx.forbidden();
2735
2996
  }
2736
2997
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2737
- const { locale } = await getDocumentLocaleAndStatus(body);
2998
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2738
2999
  const document = await findDocument(sanitizedQuery, model, { locale });
2739
3000
  if (!document) {
2740
3001
  return ctx.notFound();
@@ -2760,13 +3021,13 @@ const singleTypes = {
2760
3021
  const { userAbility } = ctx.state;
2761
3022
  const { model } = ctx.params;
2762
3023
  const { body, query = {} } = ctx.request;
2763
- const documentManager2 = getService$1("document-manager");
2764
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3024
+ const documentManager2 = getService$2("document-manager");
3025
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2765
3026
  if (permissionChecker2.cannot.discard()) {
2766
3027
  return ctx.forbidden();
2767
3028
  }
2768
3029
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2769
- const { locale } = await getDocumentLocaleAndStatus(body);
3030
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2770
3031
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2771
3032
  if (!document) {
2772
3033
  return ctx.notFound();
@@ -2784,9 +3045,9 @@ const singleTypes = {
2784
3045
  const { userAbility } = ctx.state;
2785
3046
  const { model } = ctx.params;
2786
3047
  const { query } = ctx.request;
2787
- const documentManager2 = getService$1("document-manager");
2788
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2789
- const { locale } = await getDocumentLocaleAndStatus(query);
3048
+ const documentManager2 = getService$2("document-manager");
3049
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
3050
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2790
3051
  if (permissionChecker2.cannot.read()) {
2791
3052
  return ctx.forbidden();
2792
3053
  }
@@ -2807,9 +3068,9 @@ const uid$1 = {
2807
3068
  async generateUID(ctx) {
2808
3069
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2809
3070
  const { query = {} } = ctx.request;
2810
- const { locale } = await getDocumentLocaleAndStatus(query);
3071
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2811
3072
  await validateUIDField(contentTypeUID, field);
2812
- const uidService = getService$1("uid");
3073
+ const uidService = getService$2("uid");
2813
3074
  ctx.body = {
2814
3075
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2815
3076
  };
@@ -2819,9 +3080,9 @@ const uid$1 = {
2819
3080
  ctx.request.body
2820
3081
  );
2821
3082
  const { query = {} } = ctx.request;
2822
- const { locale } = await getDocumentLocaleAndStatus(query);
3083
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2823
3084
  await validateUIDField(contentTypeUID, field);
2824
- const uidService = getService$1("uid");
3085
+ const uidService = getService$2("uid");
2825
3086
  const isAvailable = await uidService.checkUIDAvailability({
2826
3087
  contentTypeUID,
2827
3088
  field,
@@ -2842,7 +3103,8 @@ const controllers = {
2842
3103
  relations,
2843
3104
  "single-types": singleTypes,
2844
3105
  uid: uid$1,
2845
- ...history.controllers ? history.controllers : {}
3106
+ ...history.controllers ? history.controllers : {},
3107
+ ...preview.controllers ? preview.controllers : {}
2846
3108
  };
2847
3109
  const keys = {
2848
3110
  CONFIGURATION: "configuration"
@@ -2993,12 +3255,12 @@ async function syncMetadatas(configuration, schema) {
2993
3255
  return ___default.default.assign(metasWithDefaults, updatedMetas);
2994
3256
  }
2995
3257
  const getTargetSchema = (targetModel) => {
2996
- return getService$1("content-types").findContentType(targetModel);
3258
+ return getService$2("content-types").findContentType(targetModel);
2997
3259
  };
2998
3260
  const DEFAULT_LIST_LENGTH = 4;
2999
3261
  const MAX_ROW_SIZE = 12;
3000
3262
  const isAllowedFieldSize = (type, size) => {
3001
- const { getFieldSize } = getService$1("field-sizes");
3263
+ const { getFieldSize } = getService$2("field-sizes");
3002
3264
  const fieldSize = getFieldSize(type);
3003
3265
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3004
3266
  return false;
@@ -3006,7 +3268,7 @@ const isAllowedFieldSize = (type, size) => {
3006
3268
  return size <= MAX_ROW_SIZE;
3007
3269
  };
3008
3270
  const getDefaultFieldSize = (attribute) => {
3009
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3271
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3010
3272
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3011
3273
  };
3012
3274
  async function createDefaultLayouts(schema) {
@@ -3041,7 +3303,7 @@ function syncLayouts(configuration, schema) {
3041
3303
  for (const el of row) {
3042
3304
  if (!hasEditableAttribute(schema, el.name))
3043
3305
  continue;
3044
- const { hasFieldSize } = getService$1("field-sizes");
3306
+ const { hasFieldSize } = getService$2("field-sizes");
3045
3307
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3046
3308
  if (!isAllowedFieldSize(fieldType, el.size)) {
3047
3309
  elementsToReAppend.push(el.name);
@@ -3181,17 +3443,17 @@ const configurationService$1 = createConfigurationService({
3181
3443
  isComponent: true,
3182
3444
  prefix: STORE_KEY_PREFIX,
3183
3445
  getModels() {
3184
- const { toContentManagerModel } = getService$1("data-mapper");
3446
+ const { toContentManagerModel } = getService$2("data-mapper");
3185
3447
  return fp.mapValues(toContentManagerModel, strapi.components);
3186
3448
  }
3187
3449
  });
3188
3450
  const components = ({ strapi: strapi2 }) => ({
3189
3451
  findAllComponents() {
3190
- const { toContentManagerModel } = getService$1("data-mapper");
3452
+ const { toContentManagerModel } = getService$2("data-mapper");
3191
3453
  return Object.values(strapi2.components).map(toContentManagerModel);
3192
3454
  },
3193
3455
  findComponent(uid2) {
3194
- const { toContentManagerModel } = getService$1("data-mapper");
3456
+ const { toContentManagerModel } = getService$2("data-mapper");
3195
3457
  const component = strapi2.components[uid2];
3196
3458
  return fp.isNil(component) ? component : toContentManagerModel(component);
3197
3459
  },
@@ -3242,17 +3504,17 @@ const configurationService = createConfigurationService({
3242
3504
  storeUtils,
3243
3505
  prefix: "content_types",
3244
3506
  getModels() {
3245
- const { toContentManagerModel } = getService$1("data-mapper");
3507
+ const { toContentManagerModel } = getService$2("data-mapper");
3246
3508
  return fp.mapValues(toContentManagerModel, strapi.contentTypes);
3247
3509
  }
3248
3510
  });
3249
3511
  const service = ({ strapi: strapi2 }) => ({
3250
3512
  findAllContentTypes() {
3251
- const { toContentManagerModel } = getService$1("data-mapper");
3513
+ const { toContentManagerModel } = getService$2("data-mapper");
3252
3514
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3253
3515
  },
3254
3516
  findContentType(uid2) {
3255
- const { toContentManagerModel } = getService$1("data-mapper");
3517
+ const { toContentManagerModel } = getService$2("data-mapper");
3256
3518
  const contentType = strapi2.contentTypes[uid2];
3257
3519
  return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
3258
3520
  },
@@ -3281,7 +3543,7 @@ const service = ({ strapi: strapi2 }) => ({
3281
3543
  return this.findConfiguration(contentType);
3282
3544
  },
3283
3545
  findComponentsConfigurations(contentType) {
3284
- return getService$1("components").findComponentsConfigurations(contentType);
3546
+ return getService$2("components").findComponentsConfigurations(contentType);
3285
3547
  },
3286
3548
  syncConfigurations() {
3287
3549
  return configurationService.syncConfigurations();
@@ -3462,12 +3724,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3462
3724
  ability: userAbility,
3463
3725
  model
3464
3726
  });
3465
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3727
+ const { actionProvider } = strapi2.service("admin::permission");
3728
+ const toSubject = (entity) => {
3729
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3730
+ };
3466
3731
  const can = (action, entity, field) => {
3467
- return userAbility.can(action, toSubject(entity), field);
3732
+ const subject = toSubject(entity);
3733
+ const aliases = actionProvider.unstable_aliases(action, model);
3734
+ return (
3735
+ // Test the original action to see if it passes
3736
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3737
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3738
+ );
3468
3739
  };
3469
3740
  const cannot = (action, entity, field) => {
3470
- return userAbility.cannot(action, toSubject(entity), field);
3741
+ const subject = toSubject(entity);
3742
+ const aliases = actionProvider.unstable_aliases(action, model);
3743
+ return (
3744
+ // Test both the original action
3745
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3746
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3747
+ );
3471
3748
  };
3472
3749
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3473
3750
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3538,7 +3815,7 @@ const permission = ({ strapi: strapi2 }) => ({
3538
3815
  return userAbility.can(action);
3539
3816
  },
3540
3817
  async registerPermissions() {
3541
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3818
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3542
3819
  const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
3543
3820
  const actions = [
3544
3821
  {
@@ -3744,6 +4021,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3744
4021
  const attribute = model.attributes[attributeName];
3745
4022
  switch (attribute.type) {
3746
4023
  case "relation": {
4024
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
4025
+ if (isMorphRelation) {
4026
+ break;
4027
+ }
3747
4028
  if (isVisibleAttribute$1(model, attributeName)) {
3748
4029
  populateAcc[attributeName] = {
3749
4030
  count: true,
@@ -3810,7 +4091,7 @@ const getQueryPopulate = async (uid2, query) => {
3810
4091
  return populateQuery;
3811
4092
  };
3812
4093
  const buildDeepPopulate = (uid2) => {
3813
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4094
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3814
4095
  };
3815
4096
  const populateBuilder = (uid2) => {
3816
4097
  let getInitialPopulate = async () => {
@@ -3995,7 +4276,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
3995
4276
  */
3996
4277
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
3997
4278
  const versionsByLocale = fp.groupBy("locale", allVersions);
3998
- delete versionsByLocale[version.locale];
4279
+ if (version.locale) {
4280
+ delete versionsByLocale[version.locale];
4281
+ }
3999
4282
  const model = strapi2.getModel(uid2);
4000
4283
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4001
4284
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
@@ -4121,7 +4404,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4121
4404
  */
4122
4405
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4123
4406
  if (!document) {
4124
- return document;
4407
+ return {
4408
+ data: document,
4409
+ meta: {
4410
+ availableLocales: [],
4411
+ availableStatus: []
4412
+ }
4413
+ };
4125
4414
  }
4126
4415
  const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
4127
4416
  if (!hasDraftAndPublish) {
@@ -4229,10 +4518,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4229
4518
  async clone(id, body, uid2) {
4230
4519
  const populate = await buildDeepPopulate(uid2);
4231
4520
  const params = {
4232
- data: {
4233
- ...omitIdField(body),
4234
- [PUBLISHED_AT_ATTRIBUTE]: null
4235
- },
4521
+ data: omitIdField(body),
4236
4522
  populate
4237
4523
  };
4238
4524
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
@@ -4348,7 +4634,8 @@ const services = {
4348
4634
  permission,
4349
4635
  "populate-builder": populateBuilder$1,
4350
4636
  uid,
4351
- ...history.services ? history.services : {}
4637
+ ...history.services ? history.services : {},
4638
+ ...preview.services ? preview.services : {}
4352
4639
  };
4353
4640
  const index = () => {
4354
4641
  return {