strapi-plugin-navigation 2.5.4 → 3.0.0-beta.0

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 (422) hide show
  1. package/README.md +21 -43
  2. package/admin/api/client.js +107 -0
  3. package/admin/api/index.js +1 -0
  4. package/admin/api/validators.js +248 -0
  5. package/admin/components/ConfirmationDialog/index.js +21 -0
  6. package/admin/components/Initializer.js +10 -0
  7. package/admin/components/RestartAlert/index.js +7 -0
  8. package/admin/components/TextArrayInput/index.js +18 -0
  9. package/admin/components/icons/index.js +1 -0
  10. package/admin/components/icons/navigation.js +9 -0
  11. package/admin/components/icons/pluginIcon.js +9 -0
  12. package/admin/index.js +48 -0
  13. package/admin/pages/App.js +10 -0
  14. package/admin/pages/HomePage/components/AdditionalFieldInput/index.js +58 -0
  15. package/admin/pages/HomePage/components/CollapseButton/index.js +15 -0
  16. package/admin/{src → pages/HomePage}/components/DragButton/index.js +9 -16
  17. package/admin/pages/HomePage/components/I18nCopyNavigationItems/index.js +9 -0
  18. package/admin/pages/HomePage/components/NavigationContentHeader/index.js +5 -0
  19. package/admin/pages/HomePage/components/NavigationHeader/hooks.js +14 -0
  20. package/admin/pages/HomePage/components/NavigationHeader/index.js +29 -0
  21. package/admin/pages/HomePage/components/NavigationHeader/styles.js +11 -0
  22. package/admin/pages/HomePage/components/NavigationItemForm/index.js +277 -0
  23. package/admin/pages/HomePage/components/NavigationItemForm/types.js +1 -0
  24. package/admin/pages/HomePage/components/NavigationItemForm/utils/form.js +105 -0
  25. package/admin/pages/HomePage/components/NavigationItemForm/utils/hooks.js +12 -0
  26. package/admin/pages/HomePage/components/NavigationItemForm/utils/properties.js +51 -0
  27. package/admin/pages/HomePage/components/NavigationItemList/Wrapper.js +21 -0
  28. package/admin/pages/HomePage/components/NavigationItemList/index.js +6 -0
  29. package/admin/pages/HomePage/components/NavigationItemListItem/ItemCardBadge/index.js +20 -0
  30. package/admin/pages/HomePage/components/NavigationItemListItem/ItemCardHeader/Wrapper.js +14 -0
  31. package/admin/pages/HomePage/components/NavigationItemListItem/ItemCardHeader/icons.js +6 -0
  32. package/admin/pages/HomePage/components/NavigationItemListItem/ItemCardHeader/index.js +19 -0
  33. package/admin/pages/HomePage/components/NavigationItemListItem/ItemCardRemovedOverlay/index.js +11 -0
  34. package/admin/pages/HomePage/components/NavigationItemListItem/Wrapper.js +38 -0
  35. package/admin/pages/HomePage/components/NavigationItemListItem/index.js +165 -0
  36. package/admin/pages/HomePage/components/NavigationItemPopup/NavigationItemPopupFooter.js +11 -0
  37. package/admin/pages/HomePage/components/NavigationItemPopup/NavigationItemPopupHeader.js +12 -0
  38. package/admin/pages/HomePage/components/NavigationItemPopup/index.js +34 -0
  39. package/admin/pages/HomePage/components/NavigationManager/AllNavigations/icons.js +5 -0
  40. package/admin/pages/HomePage/components/NavigationManager/AllNavigations/index.js +79 -0
  41. package/admin/pages/HomePage/components/NavigationManager/DeletionConfirm/index.js +25 -0
  42. package/admin/pages/HomePage/components/NavigationManager/ErrorDetails/index.js +29 -0
  43. package/admin/pages/HomePage/components/NavigationManager/Footer/index.js +6 -0
  44. package/admin/pages/HomePage/components/NavigationManager/Form/hooks.js +19 -0
  45. package/admin/pages/HomePage/components/NavigationManager/Form/index.js +26 -0
  46. package/admin/pages/HomePage/components/NavigationManager/NavigationUpdate/index.js +32 -0
  47. package/admin/pages/HomePage/components/NavigationManager/NewNavigation/index.js +35 -0
  48. package/admin/pages/HomePage/components/NavigationManager/PurgeCacheConfirm/index.js +25 -0
  49. package/admin/pages/HomePage/components/NavigationManager/index.js +236 -0
  50. package/admin/pages/HomePage/components/NavigationManager/types.js +1 -0
  51. package/admin/pages/HomePage/components/Search/index.js +58 -0
  52. package/admin/pages/HomePage/components/index.js +1 -0
  53. package/admin/pages/HomePage/hooks/index.js +165 -0
  54. package/admin/pages/HomePage/index.js +231 -0
  55. package/admin/pages/HomePage/utils/index.js +16 -0
  56. package/admin/pages/HomePage/utils/parsers.js +187 -0
  57. package/admin/pages/SettingsPage/common/const.js +1 -0
  58. package/admin/pages/SettingsPage/common/index.js +1 -0
  59. package/admin/pages/SettingsPage/components/CustomFieldForm/hooks/index.js +10 -0
  60. package/admin/pages/SettingsPage/components/CustomFieldForm/index.js +36 -0
  61. package/admin/pages/SettingsPage/components/CustomFieldModal/index.js +16 -0
  62. package/admin/pages/SettingsPage/components/CustomFieldTable/index.js +45 -0
  63. package/admin/pages/SettingsPage/hooks/index.js +111 -0
  64. package/admin/pages/SettingsPage/index.js +189 -0
  65. package/admin/pages/SettingsPage/types.js +1 -0
  66. package/admin/pages/SettingsPage/utils/index.js +25 -0
  67. package/admin/pluginId.js +1 -0
  68. package/admin/schemas/config.js +53 -0
  69. package/admin/schemas/content-type.js +14 -0
  70. package/admin/schemas/index.js +2 -0
  71. package/admin/{src/translations → translations}/en.json +7 -9
  72. package/admin/translations/index.js +15 -0
  73. package/admin/types.js +1 -0
  74. package/admin/utils/constants.js +1 -0
  75. package/admin/utils/getTranslation.js +4 -0
  76. package/admin/utils/permissions.js +16 -0
  77. package/admin/utils/prefixPluginTranslations.js +3 -0
  78. package/package.json +13 -11
  79. package/server/app-errors.js +20 -0
  80. package/server/bootstrap.js +13 -0
  81. package/server/cache/index.js +34 -15
  82. package/server/config/index.js +7 -5
  83. package/server/config/{setupStrategy.js → setup.js} +30 -26
  84. package/server/content-types/audience/index.js +0 -1
  85. package/server/content-types/audience/schema.js +0 -1
  86. package/server/content-types/index.js +4 -7
  87. package/server/content-types/navigation/index.js +0 -1
  88. package/server/content-types/navigation/lifecycles.js +1 -2
  89. package/server/content-types/navigation/schema.js +29 -32
  90. package/server/content-types/navigation-item/index.js +0 -1
  91. package/server/content-types/navigation-item/lifecycles.js +1 -2
  92. package/server/content-types/navigation-item/schema.js +51 -58
  93. package/server/controllers/admin.js +119 -158
  94. package/server/controllers/client.js +71 -60
  95. package/server/controllers/index.js +1 -3
  96. package/server/controllers/utils.js +22 -0
  97. package/{admin/src/hooks/useNavigationManager.js → server/controllers/validators.js} +23 -16
  98. package/server/destroy.js +3 -2
  99. package/{types/i18n.js → server/dtos/config.js} +0 -1
  100. package/server/{navigation → dtos}/index.js +3 -2
  101. package/server/dtos/navigation-item.js +2 -0
  102. package/{admin/src/pages/SettingsPage/types.js → server/dtos/navigation.js} +0 -1
  103. package/server/graphql/config.js +14 -16
  104. package/server/graphql/index.js +1 -2
  105. package/server/graphql/queries/index.js +8 -4
  106. package/server/graphql/queries/render-navigation-child.js +19 -8
  107. package/server/graphql/queries/render-navigation.js +30 -14
  108. package/server/graphql/resolvers-config.js +4 -2
  109. package/server/graphql/{setupStrategy.js → setup.js} +4 -5
  110. package/server/graphql/types/content-types-name-fields.js +10 -9
  111. package/server/graphql/types/content-types.js +15 -15
  112. package/server/graphql/types/create-navigation-item.js +16 -16
  113. package/server/graphql/types/create-navigation-related.js +7 -7
  114. package/server/graphql/types/create-navigation.js +6 -6
  115. package/server/graphql/types/index.js +35 -15
  116. package/server/graphql/types/navigation-config.js +8 -8
  117. package/server/graphql/types/navigation-details.js +2 -2
  118. package/server/graphql/types/navigation-item-additional-field-media.js +10 -10
  119. package/server/graphql/types/navigation-item-related-data.js +6 -6
  120. package/server/graphql/types/navigation-item-related.js +3 -3
  121. package/server/graphql/types/navigation-item.js +30 -27
  122. package/server/graphql/types/navigation-render-type.js +4 -5
  123. package/server/graphql/types/navigation.js +8 -8
  124. package/server/i18n/index.js +29 -20
  125. package/server/index.js +15 -8
  126. package/server/middlewares/index.js +3 -0
  127. package/server/permissions/index.js +10 -0
  128. package/{permissions.js → server/permissions/permissions.js} +0 -1
  129. package/server/permissions/setup.js +32 -0
  130. package/server/permissions.js +39 -0
  131. package/server/policies/index.js +3 -0
  132. package/server/register.js +6 -0
  133. package/server/repositories/audience.js +12 -0
  134. package/server/repositories/generic.js +20 -0
  135. package/server/repositories/index.js +11 -0
  136. package/server/repositories/navigation-item.js +51 -0
  137. package/server/repositories/navigation.js +65 -0
  138. package/server/routes/admin.js +86 -79
  139. package/server/routes/client.js +0 -1
  140. package/server/routes/index.js +0 -1
  141. package/server/schemas/config.js +68 -0
  142. package/server/schemas/content-type.js +140 -0
  143. package/{admin/src/pages/SettingsPage/common → server/schemas}/index.js +3 -2
  144. package/server/schemas/navigation.js +107 -0
  145. package/server/services/admin/admin.js +483 -0
  146. package/server/{content-types/navigations-items-related → services/admin}/index.js +2 -5
  147. package/{admin/src/pages/View/components/NavigationItemForm → server/services/admin}/types.js +0 -1
  148. package/server/services/admin/utils.js +84 -0
  149. package/server/services/client/client.js +397 -0
  150. package/server/services/client/index.js +7 -0
  151. package/{admin/src/pages/View/components/NavigationManager → server/services/client}/types.js +0 -1
  152. package/server/services/client/utils.js +88 -0
  153. package/server/services/common/common.js +307 -0
  154. package/server/services/common/index.js +7 -0
  155. package/{admin/src/components/AdditionalFieldInput → server/services/common}/types.js +0 -1
  156. package/server/services/common/utils.js +24 -0
  157. package/server/services/index.js +4 -6
  158. package/server/types.js +2 -0
  159. package/server/utils/constants.js +35 -0
  160. package/server/utils/functions.js +71 -299
  161. package/server/utils/index.js +1 -2
  162. package/strapi-admin.js +5 -8
  163. package/strapi-server.js +3 -7
  164. package/tsconfig.tsbuildinfo +1 -1
  165. package/admin/src/components/AdditionalFieldInput/index.d.ts +0 -5
  166. package/admin/src/components/AdditionalFieldInput/index.js +0 -99
  167. package/admin/src/components/AdditionalFieldInput/types.d.ts +0 -15
  168. package/admin/src/components/Alert/styles.d.ts +0 -2
  169. package/admin/src/components/Alert/styles.js +0 -14
  170. package/admin/src/components/CollapseButton/index.d.ts +0 -7
  171. package/admin/src/components/CollapseButton/index.js +0 -30
  172. package/admin/src/components/ConfirmationDialog/index.d.ts +0 -28
  173. package/admin/src/components/ConfirmationDialog/index.js +0 -34
  174. package/admin/src/components/DragButton/index.d.ts +0 -6
  175. package/admin/src/components/EmptyView/index.d.ts +0 -3
  176. package/admin/src/components/EmptyView/index.js +0 -30
  177. package/admin/src/components/Item/ItemCardBadge/index.d.ts +0 -3
  178. package/admin/src/components/Item/ItemCardBadge/index.js +0 -26
  179. package/admin/src/components/Item/ItemCardHeader/Wrapper.d.ts +0 -3
  180. package/admin/src/components/Item/ItemCardHeader/Wrapper.js +0 -21
  181. package/admin/src/components/Item/ItemCardHeader/icons.d.ts +0 -5
  182. package/admin/src/components/Item/ItemCardHeader/icons.js +0 -13
  183. package/admin/src/components/Item/ItemCardHeader/index.d.ts +0 -17
  184. package/admin/src/components/Item/ItemCardHeader/index.js +0 -38
  185. package/admin/src/components/Item/ItemCardRemovedOverlay/index.d.ts +0 -2
  186. package/admin/src/components/Item/ItemCardRemovedOverlay/index.js +0 -18
  187. package/admin/src/components/Item/Wrapper.d.ts +0 -3
  188. package/admin/src/components/Item/Wrapper.js +0 -43
  189. package/admin/src/components/Item/index.d.ts +0 -31
  190. package/admin/src/components/Item/index.js +0 -188
  191. package/admin/src/components/NavigationItemList/Wrapper.d.ts +0 -3
  192. package/admin/src/components/NavigationItemList/Wrapper.js +0 -26
  193. package/admin/src/components/NavigationItemList/index.d.ts +0 -36
  194. package/admin/src/components/NavigationItemList/index.js +0 -32
  195. package/admin/src/components/RestartAlert/index.d.ts +0 -3
  196. package/admin/src/components/RestartAlert/index.js +0 -13
  197. package/admin/src/components/Search/index.d.ts +0 -12
  198. package/admin/src/components/Search/index.js +0 -97
  199. package/admin/src/components/TextArrayInput/index.d.ts +0 -15
  200. package/admin/src/components/TextArrayInput/index.js +0 -45
  201. package/admin/src/components/icons/navigation.d.ts +0 -6
  202. package/admin/src/components/icons/navigation.js +0 -12
  203. package/admin/src/contexts/DataManagerContext.d.ts +0 -3
  204. package/admin/src/contexts/DataManagerContext.js +0 -6
  205. package/admin/src/hooks/useAllContentTypes.d.ts +0 -3
  206. package/admin/src/hooks/useAllContentTypes.js +0 -8
  207. package/admin/src/hooks/useDataManager.d.ts +0 -3
  208. package/admin/src/hooks/useDataManager.js +0 -10
  209. package/admin/src/hooks/useI18nCopyNavigationItemsModal.d.ts +0 -9
  210. package/admin/src/hooks/useI18nCopyNavigationItemsModal.js +0 -51
  211. package/admin/src/hooks/useNavigationConfig.d.ts +0 -10
  212. package/admin/src/hooks/useNavigationConfig.js +0 -54
  213. package/admin/src/hooks/useNavigationManager.d.ts +0 -6
  214. package/admin/src/index.d.ts +0 -14
  215. package/admin/src/index.js +0 -87
  216. package/admin/src/pages/App/index.d.ts +0 -3
  217. package/admin/src/pages/App/index.js +0 -43
  218. package/admin/src/pages/DataManagerProvider/actions.d.ts +0 -21
  219. package/admin/src/pages/DataManagerProvider/actions.js +0 -24
  220. package/admin/src/pages/DataManagerProvider/index.d.ts +0 -12
  221. package/admin/src/pages/DataManagerProvider/index.js +0 -382
  222. package/admin/src/pages/DataManagerProvider/init.d.ts +0 -3
  223. package/admin/src/pages/DataManagerProvider/init.js +0 -7
  224. package/admin/src/pages/DataManagerProvider/reducer.d.ts +0 -20
  225. package/admin/src/pages/DataManagerProvider/reducer.js +0 -132
  226. package/admin/src/pages/NoAccessPage/index.d.ts +0 -3
  227. package/admin/src/pages/NoAccessPage/index.js +0 -31
  228. package/admin/src/pages/SettingsPage/common/const.d.ts +0 -2
  229. package/admin/src/pages/SettingsPage/common/const.js +0 -5
  230. package/admin/src/pages/SettingsPage/common/index.d.ts +0 -2
  231. package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.d.ts +0 -12
  232. package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.js +0 -129
  233. package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.d.ts +0 -12
  234. package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.js +0 -20
  235. package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.d.ts +0 -11
  236. package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.js +0 -105
  237. package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.d.ts +0 -23
  238. package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.js +0 -86
  239. package/admin/src/pages/SettingsPage/index.d.ts +0 -3
  240. package/admin/src/pages/SettingsPage/index.js +0 -321
  241. package/admin/src/pages/SettingsPage/types.d.ts +0 -35
  242. package/admin/src/pages/SettingsPage/utils/form.d.ts +0 -20
  243. package/admin/src/pages/SettingsPage/utils/form.js +0 -37
  244. package/admin/src/pages/SettingsPage/utils/functions.d.ts +0 -3
  245. package/admin/src/pages/SettingsPage/utils/functions.js +0 -26
  246. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.d.ts +0 -14
  247. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.js +0 -15
  248. package/admin/src/pages/View/components/NavigationContentHeader/index.d.ts +0 -6
  249. package/admin/src/pages/View/components/NavigationContentHeader/index.js +0 -14
  250. package/admin/src/pages/View/components/NavigationHeader/index.d.ts +0 -14
  251. package/admin/src/pages/View/components/NavigationHeader/index.js +0 -92
  252. package/admin/src/pages/View/components/NavigationHeader/styles.d.ts +0 -2
  253. package/admin/src/pages/View/components/NavigationHeader/styles.js +0 -18
  254. package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +0 -5
  255. package/admin/src/pages/View/components/NavigationItemForm/index.js +0 -470
  256. package/admin/src/pages/View/components/NavigationItemForm/types.d.ts +0 -99
  257. package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +0 -28
  258. package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +0 -123
  259. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.d.ts +0 -25
  260. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +0 -31
  261. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.d.ts +0 -5
  262. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +0 -20
  263. package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +0 -33
  264. package/admin/src/pages/View/components/NavigationItemPopup/index.js +0 -90
  265. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.d.ts +0 -4
  266. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.js +0 -12
  267. package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.d.ts +0 -8
  268. package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.js +0 -151
  269. package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.d.ts +0 -8
  270. package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.js +0 -34
  271. package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.d.ts +0 -8
  272. package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.js +0 -53
  273. package/admin/src/pages/View/components/NavigationManager/Footer/index.d.ts +0 -24
  274. package/admin/src/pages/View/components/NavigationManager/Footer/index.js +0 -13
  275. package/admin/src/pages/View/components/NavigationManager/Form/index.d.ts +0 -19
  276. package/admin/src/pages/View/components/NavigationManager/Form/index.js +0 -103
  277. package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.d.ts +0 -8
  278. package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.js +0 -59
  279. package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.d.ts +0 -9
  280. package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.js +0 -62
  281. package/admin/src/pages/View/components/NavigationManager/PurgeCacheConfirm/index.d.ts +0 -8
  282. package/admin/src/pages/View/components/NavigationManager/PurgeCacheConfirm/index.js +0 -34
  283. package/admin/src/pages/View/components/NavigationManager/index.d.ts +0 -10
  284. package/admin/src/pages/View/components/NavigationManager/index.js +0 -203
  285. package/admin/src/pages/View/components/NavigationManager/types.d.ts +0 -44
  286. package/admin/src/pages/View/index.d.ts +0 -4
  287. package/admin/src/pages/View/index.js +0 -269
  288. package/admin/src/pages/View/utils/form.d.ts +0 -2
  289. package/admin/src/pages/View/utils/form.js +0 -16
  290. package/admin/src/pages/View/utils/index.d.ts +0 -2
  291. package/admin/src/pages/View/utils/index.js +0 -11
  292. package/admin/src/pages/View/utils/parsers.d.ts +0 -51
  293. package/admin/src/pages/View/utils/parsers.js +0 -272
  294. package/admin/src/pages/View/utils/types.d.ts +0 -3
  295. package/admin/src/pages/View/utils/types.js +0 -3
  296. package/admin/src/permissions.d.ts +0 -16
  297. package/admin/src/permissions.js +0 -13
  298. package/admin/src/pluginId.d.ts +0 -3
  299. package/admin/src/pluginId.js +0 -5
  300. package/admin/src/translations/index.d.ts +0 -15
  301. package/admin/src/translations/index.js +0 -21
  302. package/admin/src/utils/api.d.ts +0 -9
  303. package/admin/src/utils/api.js +0 -20
  304. package/admin/src/utils/enums.d.ts +0 -25
  305. package/admin/src/utils/enums.js +0 -30
  306. package/admin/src/utils/functions.d.ts +0 -16
  307. package/admin/src/utils/functions.js +0 -46
  308. package/admin/src/utils/index.d.ts +0 -4
  309. package/admin/src/utils/index.js +0 -20
  310. package/permissions.d.ts +0 -10
  311. package/server/bootstrap/index.d.ts +0 -4
  312. package/server/bootstrap/index.js +0 -50
  313. package/server/cache/index.d.ts +0 -2
  314. package/server/cache/serviceEnhancers.d.ts +0 -3
  315. package/server/cache/serviceEnhancers.js +0 -16
  316. package/server/cache/setupStrategy.d.ts +0 -3
  317. package/server/cache/setupStrategy.js +0 -38
  318. package/server/cache/types.d.ts +0 -11
  319. package/server/cache/types.js +0 -3
  320. package/server/cache/utils.d.ts +0 -11
  321. package/server/cache/utils.js +0 -19
  322. package/server/config/index.d.ts +0 -5
  323. package/server/config/setupStrategy.d.ts +0 -3
  324. package/server/content-types/audience/index.d.ts +0 -27
  325. package/server/content-types/audience/schema.d.ts +0 -25
  326. package/server/content-types/index.d.ts +0 -244
  327. package/server/content-types/navigation/index.d.ts +0 -59
  328. package/server/content-types/navigation/lifecycles.d.ts +0 -3
  329. package/server/content-types/navigation/schema.d.ts +0 -56
  330. package/server/content-types/navigation-item/index.d.ts +0 -111
  331. package/server/content-types/navigation-item/lifecycles.d.ts +0 -3
  332. package/server/content-types/navigation-item/schema.d.ts +0 -108
  333. package/server/content-types/navigations-items-related/index.d.ts +0 -51
  334. package/server/content-types/navigations-items-related/schema.d.ts +0 -49
  335. package/server/content-types/navigations-items-related/schema.js +0 -50
  336. package/server/controllers/admin.d.ts +0 -4
  337. package/server/controllers/client.d.ts +0 -4
  338. package/server/controllers/index.d.ts +0 -4
  339. package/server/destroy.d.ts +0 -3
  340. package/server/graphql/config.d.ts +0 -4
  341. package/server/graphql/index.d.ts +0 -2
  342. package/server/graphql/queries/index.d.ts +0 -3
  343. package/server/graphql/queries/render-navigation-child.d.ts +0 -15
  344. package/server/graphql/queries/render-navigation.d.ts +0 -21
  345. package/server/graphql/resolvers-config.d.ts +0 -10
  346. package/server/graphql/setupStrategy.d.ts +0 -3
  347. package/server/graphql/types/content-types-name-fields.d.ts +0 -6
  348. package/server/graphql/types/content-types.d.ts +0 -5
  349. package/server/graphql/types/create-navigation-item.d.ts +0 -5
  350. package/server/graphql/types/create-navigation-related.d.ts +0 -5
  351. package/server/graphql/types/create-navigation.d.ts +0 -5
  352. package/server/graphql/types/index.d.ts +0 -3
  353. package/server/graphql/types/navigation-config.d.ts +0 -5
  354. package/server/graphql/types/navigation-details.d.ts +0 -5
  355. package/server/graphql/types/navigation-item-additional-field-media.d.ts +0 -5
  356. package/server/graphql/types/navigation-item-related-data.d.ts +0 -5
  357. package/server/graphql/types/navigation-item-related.d.ts +0 -7
  358. package/server/graphql/types/navigation-item.d.ts +0 -6
  359. package/server/graphql/types/navigation-render-type.d.ts +0 -5
  360. package/server/graphql/types/navigation.d.ts +0 -5
  361. package/server/i18n/constant.d.ts +0 -2
  362. package/server/i18n/constant.js +0 -5
  363. package/server/i18n/errors.d.ts +0 -7
  364. package/server/i18n/errors.js +0 -14
  365. package/server/i18n/graphQLEnhancers.d.ts +0 -10
  366. package/server/i18n/graphQLEnhancers.js +0 -10
  367. package/server/i18n/index.d.ts +0 -8
  368. package/server/i18n/navigationSetupStrategy.d.ts +0 -3
  369. package/server/i18n/navigationSetupStrategy.js +0 -147
  370. package/server/i18n/serviceEnhancers.d.ts +0 -13
  371. package/server/i18n/serviceEnhancers.js +0 -156
  372. package/server/i18n/types.d.ts +0 -60
  373. package/server/i18n/types.js +0 -3
  374. package/server/i18n/utils.d.ts +0 -13
  375. package/server/i18n/utils.js +0 -33
  376. package/server/index.d.ts +0 -262
  377. package/server/navigation/index.d.ts +0 -2
  378. package/server/navigation/setupStrategy.d.ts +0 -3
  379. package/server/navigation/setupStrategy.js +0 -39
  380. package/server/register/index.d.ts +0 -3
  381. package/server/register/index.js +0 -4
  382. package/server/routes/admin.d.ts +0 -4
  383. package/server/routes/client.d.ts +0 -4
  384. package/server/routes/index.d.ts +0 -6
  385. package/server/services/admin.d.ts +0 -5
  386. package/server/services/admin.js +0 -347
  387. package/server/services/client.d.ts +0 -5
  388. package/server/services/client.js +0 -335
  389. package/server/services/common.d.ts +0 -5
  390. package/server/services/common.js +0 -385
  391. package/server/services/index.d.ts +0 -7
  392. package/server/utils/constant.d.ts +0 -27
  393. package/server/utils/constant.js +0 -43
  394. package/server/utils/functions.d.ts +0 -157
  395. package/server/utils/index.d.ts +0 -3
  396. package/strapi-admin.d.ts +0 -3
  397. package/strapi-server.d.ts +0 -262
  398. package/types/bootstrap.d.ts +0 -16
  399. package/types/bootstrap.js +0 -3
  400. package/types/config.d.ts +0 -27
  401. package/types/config.js +0 -3
  402. package/types/contentTypes.d.ts +0 -112
  403. package/types/contentTypes.js +0 -3
  404. package/types/controllers.d.ts +0 -65
  405. package/types/controllers.js +0 -5
  406. package/types/graphQL.d.ts +0 -3
  407. package/types/graphQL.js +0 -3
  408. package/types/i18n.d.ts +0 -9
  409. package/types/index.d.ts +0 -10
  410. package/types/index.js +0 -26
  411. package/types/lifecycle.d.ts +0 -22
  412. package/types/lifecycle.js +0 -3
  413. package/types/services.d.ts +0 -106
  414. package/types/services.js +0 -3
  415. package/types/utils.d.ts +0 -72
  416. package/types/utils.js +0 -41
  417. package/utils/InvalidParamNavigationError.d.ts +0 -4
  418. package/utils/InvalidParamNavigationError.js +0 -8
  419. package/utils/NavigationError.d.ts +0 -5
  420. package/utils/NavigationError.js +0 -11
  421. /package/admin/{src/translations → translations}/ca.json +0 -0
  422. /package/admin/{src/translations → translations}/fr.json +0 -0
@@ -1,347 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@strapi/utils");
4
- const lodash_1 = require("lodash");
5
- const utils_2 = require("../utils");
6
- const i18n_1 = require("../i18n");
7
- const NavigationError_1 = require("../../utils/NavigationError");
8
- const serviceEnhancers_1 = require("../cache/serviceEnhancers");
9
- const adminService = ({ strapi, }) => ({
10
- async config(viaSettingsPage = false) {
11
- const commonService = (0, utils_2.getPluginService)("common");
12
- const { audienceModel } = (0, utils_2.getPluginModels)();
13
- const pluginStore = await commonService.getPluginStore();
14
- const config = await pluginStore.get({
15
- key: "config",
16
- });
17
- const additionalFields = config.additionalFields;
18
- const cascadeMenuAttached = config.cascadeMenuAttached;
19
- const contentTypesNameFields = config.contentTypesNameFields;
20
- const contentTypesPopulate = config.contentTypesPopulate;
21
- const pathDefaultFields = config.pathDefaultFields;
22
- const allowedLevels = config.allowedLevels;
23
- const preferCustomContentTypes = config.preferCustomContentTypes;
24
- const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin("graphql"));
25
- let extendedResult = {
26
- allowedContentTypes: utils_2.ALLOWED_CONTENT_TYPES,
27
- restrictedContentTypes: utils_2.RESTRICTED_CONTENT_TYPES,
28
- };
29
- const configContentTypes = await commonService.configContentTypes();
30
- const result = {
31
- contentTypes: await commonService.configContentTypes(viaSettingsPage),
32
- contentTypesNameFields: {
33
- default: utils_2.CONTENT_TYPES_NAME_FIELDS_DEFAULTS,
34
- ...((0, lodash_1.isObject)(contentTypesNameFields) ? contentTypesNameFields : {}),
35
- },
36
- contentTypesPopulate: (0, lodash_1.isObject)(contentTypesPopulate)
37
- ? contentTypesPopulate
38
- : {},
39
- pathDefaultFields: (0, lodash_1.isObject)(pathDefaultFields) ? pathDefaultFields : {},
40
- allowedLevels,
41
- additionalFields: viaSettingsPage
42
- ? additionalFields
43
- : additionalFields.filter((field) => typeof field === "string" || (0, lodash_1.get)(field, "enabled", false)),
44
- gql: {
45
- navigationItemRelated: configContentTypes.map(({ labelSingular }) => labelSingular.replace(/\s+/g, "")),
46
- },
47
- isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
48
- cascadeMenuAttached,
49
- preferCustomContentTypes,
50
- };
51
- const i18nConfig = await (0, i18n_1.addI18NConfigFields)({
52
- strapi,
53
- viaSettingsPage,
54
- previousConfig: {},
55
- });
56
- const cacheConfig = await (0, serviceEnhancers_1.addCacheConfigFields)({ strapi, previousConfig: {} });
57
- if (additionalFields.includes("audience")) {
58
- const audienceItems = await strapi
59
- .query(audienceModel.uid)
60
- .findMany({
61
- limit: Number.MAX_SAFE_INTEGER,
62
- });
63
- extendedResult = {
64
- ...extendedResult,
65
- availableAudience: audienceItems,
66
- };
67
- }
68
- return {
69
- ...result,
70
- ...extendedResult,
71
- ...i18nConfig,
72
- ...cacheConfig,
73
- };
74
- },
75
- async get(ids, ignoreLocale = false) {
76
- const { masterModel } = (0, utils_2.getPluginModels)();
77
- const { enabled: i18nEnabled, locales } = await (0, i18n_1.getI18nStatus)({ strapi });
78
- const whereClause = {};
79
- if (ids) {
80
- whereClause.id = { $in: ids };
81
- }
82
- let entities = await strapi.query(masterModel.uid).findMany({
83
- limit: Number.MAX_SAFE_INTEGER,
84
- populate: utils_2.DEFAULT_POPULATE,
85
- where: whereClause,
86
- });
87
- if (i18nEnabled && !ignoreLocale) {
88
- entities = entities.reduce((acc, entity) => {
89
- if (entity.localeCode && locales?.includes(entity.localeCode)) {
90
- acc.push({
91
- ...entity,
92
- localizations: entity.localizations?.filter(({ localeCode }) => localeCode && locales?.includes(localeCode)),
93
- });
94
- }
95
- return acc;
96
- }, []);
97
- }
98
- return entities;
99
- },
100
- async getById(id) {
101
- const commonService = (0, utils_2.getPluginService)("common");
102
- const { masterModel, itemModel } = (0, utils_2.getPluginModels)();
103
- const entity = await strapi
104
- .query(masterModel.uid)
105
- .findOne({ where: { id }, populate: utils_2.DEFAULT_POPULATE });
106
- const entityItems = await strapi
107
- .query(itemModel.uid)
108
- .findMany({
109
- where: {
110
- master: id,
111
- },
112
- limit: Number.MAX_SAFE_INTEGER,
113
- orderBy: [{ order: "asc" }],
114
- populate: ["related", "parent", "audience"],
115
- });
116
- const entities = await commonService.getRelatedItems(entityItems);
117
- return {
118
- ...entity,
119
- items: (0, utils_2.buildNestedStructure)(entities),
120
- };
121
- },
122
- async post(payload, auditLog) {
123
- const commonService = (0, utils_2.getPluginService)("common");
124
- const adminService = (0, utils_2.getPluginService)("admin");
125
- const { enabled: i18nEnabled, defaultLocale } = await (0, i18n_1.getI18nStatus)({
126
- strapi,
127
- });
128
- const { masterModel } = (0, utils_2.getPluginModels)();
129
- const { name, visible } = payload;
130
- const data = {
131
- name,
132
- slug: await commonService.getSlug(name),
133
- visible,
134
- localeCode: i18nEnabled && defaultLocale ? defaultLocale : null
135
- };
136
- const existingEntity = await strapi
137
- .query(masterModel.uid)
138
- .create({ data });
139
- const result = await commonService
140
- .createBranch(payload.items, existingEntity, null, {})
141
- .then(() => adminService.getById(existingEntity.id))
142
- .then((newEntity) => {
143
- (0, utils_2.sendAuditLog)(auditLog, "onChangeNavigation", {
144
- actionType: "CREATE",
145
- oldEntity: existingEntity,
146
- newEntity,
147
- });
148
- return newEntity;
149
- });
150
- await commonService.emitEvent(masterModel.uid, "entry.create", existingEntity);
151
- if (i18nEnabled && defaultLocale) {
152
- await (0, i18n_1.i18nNavigationSetupStrategy)({ strapi });
153
- }
154
- return result;
155
- },
156
- async put(id, payload, auditLog) {
157
- const adminService = (0, utils_2.getPluginService)("admin");
158
- const commonService = (0, utils_2.getPluginService)("common");
159
- const { enabled: i18nEnabled } = await (0, i18n_1.getI18nStatus)({ strapi });
160
- const { masterModel } = (0, utils_2.getPluginModels)();
161
- const { name, visible } = payload;
162
- const existingEntity = await adminService.getById(id);
163
- const detailsHaveChanged = existingEntity.name !== name || existingEntity.visible !== visible;
164
- if (detailsHaveChanged) {
165
- const newName = detailsHaveChanged ? name : existingEntity.name;
166
- const newSlug = detailsHaveChanged
167
- ? await commonService.getSlug(name)
168
- : existingEntity.slug;
169
- await strapi.query(masterModel.uid).update({
170
- where: { id },
171
- data: {
172
- name: newName,
173
- slug: newSlug,
174
- visible,
175
- },
176
- });
177
- if (i18nEnabled && existingEntity.localizations) {
178
- for (const locale of existingEntity.localizations) {
179
- await strapi.query(masterModel.uid).update({
180
- where: {
181
- id: locale.id,
182
- },
183
- data: {
184
- name: newName,
185
- slug: `${newSlug}-${locale.localeCode}`,
186
- visible,
187
- },
188
- });
189
- }
190
- }
191
- }
192
- const result = await commonService
193
- .analyzeBranch(payload.items, existingEntity)
194
- .then((auditLogsOperations) => Promise.all([
195
- auditLog
196
- ? (0, utils_2.prepareAuditLog)((auditLogsOperations || []).flat(Number.MAX_SAFE_INTEGER))
197
- : [],
198
- adminService.getById(existingEntity.id),
199
- ]))
200
- .then(([actionType, newEntity]) => {
201
- (0, utils_2.sendAuditLog)(auditLog, "onChangeNavigation", {
202
- actionType,
203
- oldEntity: existingEntity,
204
- newEntity,
205
- });
206
- return newEntity;
207
- });
208
- const navigationEntity = await strapi
209
- .query(masterModel.uid)
210
- .findOne({ where: { id } });
211
- await commonService.emitEvent(masterModel.uid, "entry.update", navigationEntity);
212
- return result;
213
- },
214
- async delete(id, auditLog) {
215
- const { masterModel, itemModel } = (0, utils_2.getPluginModels)();
216
- const entity = await this.getById(id);
217
- const { enabled: i18nEnabled } = await (0, i18n_1.getI18nStatus)({ strapi });
218
- const cleanNavigationItems = async (masterIds) => {
219
- if (masterIds.length < 1) {
220
- return;
221
- }
222
- const navigationItems = await strapi.query(itemModel.uid).findMany({
223
- where: {
224
- $or: masterIds.map((id) => ({ master: id })),
225
- },
226
- limit: Number.MAX_SAFE_INTEGER,
227
- });
228
- await strapi.query(itemModel.uid).deleteMany({
229
- where: {
230
- id: navigationItems.map(({ id }) => (id)),
231
- },
232
- });
233
- };
234
- await cleanNavigationItems([id]);
235
- await strapi.query(masterModel.uid).delete({
236
- where: {
237
- id,
238
- },
239
- });
240
- if (i18nEnabled && entity.localizations) {
241
- await cleanNavigationItems(entity.localizations.map(_ => _.id));
242
- await strapi.query(masterModel.uid).deleteMany({
243
- where: {
244
- id: {
245
- $in: entity.localizations.map((_) => _.id),
246
- },
247
- },
248
- });
249
- }
250
- (0, utils_2.sendAuditLog)(auditLog, "onNavigationDeletion", {
251
- entity,
252
- actionType: "DELETE",
253
- });
254
- },
255
- async restart() {
256
- setImmediate(() => strapi.reload());
257
- },
258
- async restoreConfig() {
259
- const commonService = (0, utils_2.getPluginService)("common", strapi);
260
- const pluginStore = await commonService.getPluginStore();
261
- await pluginStore.delete({ key: "config" });
262
- await commonService.setDefaultConfig();
263
- },
264
- async updateConfig(newConfig) {
265
- const commonService = (0, utils_2.getPluginService)("common");
266
- const pluginStore = await commonService.getPluginStore();
267
- const config = await pluginStore.get({
268
- key: "config",
269
- });
270
- (0, utils_2.validateAdditionalFields)(newConfig.additionalFields);
271
- await pluginStore.set({ key: "config", value: newConfig });
272
- const removedFields = (0, lodash_1.differenceBy)(config.additionalFields, newConfig.additionalFields, "name").filter((i) => i !== "audience");
273
- if (!(0, lodash_1.isEmpty)(removedFields)) {
274
- await commonService.pruneCustomFields(removedFields);
275
- }
276
- },
277
- async fillFromOtherLocale({ target, source, auditLog }) {
278
- const { enabled } = await (0, i18n_1.getI18nStatus)({ strapi });
279
- if (!enabled) {
280
- throw new NavigationError_1.NavigationError("Not yet implemented.");
281
- }
282
- const adminService = (0, utils_2.getPluginService)("admin");
283
- const commonService = (0, utils_2.getPluginService)("common");
284
- const targetEntity = await adminService.getById(target);
285
- return await (0, i18n_1.i18nNavigationContentsCopy)({
286
- source: await adminService.getById(source),
287
- target: targetEntity,
288
- service: commonService,
289
- strapi,
290
- })
291
- .then(() => adminService.getById(target))
292
- .then((updated) => {
293
- (0, utils_2.sendAuditLog)(auditLog, "onChangeNavigation", {
294
- actionType: "UPDATE",
295
- oldEntity: targetEntity,
296
- newEntity: updated,
297
- });
298
- return updated;
299
- });
300
- },
301
- async readNavigationItemFromLocale({ source, target, path }) {
302
- const sourceNavigation = await this.getById(source);
303
- const targetNavigation = await this.getById(target);
304
- if (!sourceNavigation) {
305
- throw new utils_1.errors.NotFoundError("Unable to find source navigation for specified query");
306
- }
307
- if (!targetNavigation) {
308
- throw new utils_1.errors.NotFoundError("Unable to find target navigation for specified query");
309
- }
310
- return await (0, i18n_1.i18nNavigationItemRead)({
311
- path,
312
- source: sourceNavigation,
313
- target: targetNavigation,
314
- strapi,
315
- });
316
- },
317
- async purgeNavigationCache(id, clearLocalisations) {
318
- const entity = await this.getById(id);
319
- const regexps = [];
320
- const mapToRegExp = (id) => new RegExp(`/api/navigation/render/${id}`);
321
- if (!entity) {
322
- throw new utils_1.errors.NotFoundError("Navigation is not defined");
323
- }
324
- if (clearLocalisations) {
325
- const { enabled: isI18nEnabled } = await (0, i18n_1.getI18nStatus)({ strapi });
326
- if (isI18nEnabled) {
327
- entity.localizations?.forEach((navigation) => {
328
- regexps.push(mapToRegExp(navigation.id));
329
- });
330
- }
331
- }
332
- const restCachePlugin = strapi.plugin("rest-cache");
333
- const cacheStore = restCachePlugin.service("cacheStore");
334
- regexps.push(mapToRegExp(id));
335
- await cacheStore.clearByRegexp(regexps);
336
- return { success: true };
337
- },
338
- async purgeNavigationsCache() {
339
- const restCachePlugin = strapi.plugin("rest-cache");
340
- const cacheStore = restCachePlugin.service("cacheStore");
341
- const regex = new RegExp("/api/navigation/render(.*)");
342
- await cacheStore.clearByRegexp([regex]);
343
- return { success: true };
344
- }
345
- });
346
- exports.default = adminService;
347
- //# sourceMappingURL=admin.js.map
@@ -1,5 +0,0 @@
1
- import { StrapiContext } from "strapi-typed";
2
- import { IClientService } from "../../types";
3
- declare const clientService: (context: StrapiContext) => IClientService;
4
- export default clientService;
5
- //# sourceMappingURL=client.d.ts.map
@@ -1,335 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const lodash_1 = require("lodash");
4
- const uuid_1 = require("uuid");
5
- const types_1 = require("../../types");
6
- const utils_1 = require("../utils");
7
- const utils_2 = require("@strapi/utils");
8
- const i18n_1 = require("../i18n");
9
- const NavigationError_1 = require("../../utils/NavigationError");
10
- const fp_1 = require("lodash/fp");
11
- const clientService = ({ strapi }) => ({
12
- async readAll({ locale, orderBy = 'createdAt', orderDirection = "DESC" }) {
13
- const { masterModel } = (0, utils_1.getPluginModels)();
14
- const { enabled: i18nEnabled, locales } = await (0, i18n_1.getI18nStatus)({ strapi });
15
- let navigations = await strapi
16
- .query(masterModel.uid)
17
- .findMany({
18
- where: locale
19
- ? {
20
- localeCode: locale,
21
- }
22
- : undefined,
23
- orderBy: { [orderBy]: orderDirection },
24
- limit: Number.MAX_SAFE_INTEGER,
25
- populate: false
26
- });
27
- if (i18nEnabled) {
28
- navigations = navigations.reduce((acc, navigation) => {
29
- if (navigation.localeCode && locales?.includes(navigation.localeCode)) {
30
- acc.push({
31
- ...navigation,
32
- localizations: navigation.localizations?.filter(({ localeCode }) => localeCode && locales?.includes(localeCode)),
33
- });
34
- }
35
- return acc;
36
- }, []);
37
- }
38
- return navigations;
39
- },
40
- async render({ idOrSlug, type = utils_1.RENDER_TYPES.FLAT, menuOnly = false, rootPath = null, wrapRelated = false, locale, populate, }) {
41
- const clientService = (0, utils_1.getPluginService)('client');
42
- const findById = !isNaN((0, lodash_1.toNumber)(idOrSlug)) || (0, uuid_1.validate)(idOrSlug);
43
- const criteria = findById ? { id: idOrSlug } : { slug: idOrSlug };
44
- const itemCriteria = menuOnly ? { menuAttached: true } : {};
45
- return await clientService.renderType({
46
- type, criteria, itemCriteria, filter: null, rootPath, wrapRelated, locale, populate
47
- });
48
- },
49
- async renderChildren({ idOrSlug, childUIKey, type = utils_1.RENDER_TYPES.FLAT, menuOnly = false, wrapRelated = false, locale, }) {
50
- const clientService = (0, utils_1.getPluginService)('client');
51
- const findById = !isNaN((0, lodash_1.toNumber)(idOrSlug)) || (0, uuid_1.validate)(idOrSlug);
52
- const criteria = findById ? { id: idOrSlug } : { slug: idOrSlug };
53
- const filter = type === utils_1.RENDER_TYPES.FLAT ? null : childUIKey;
54
- const itemCriteria = {
55
- ...(menuOnly && { menuAttached: true }),
56
- ...(type === utils_1.RENDER_TYPES.FLAT ? { uiRouterKey: childUIKey } : {}),
57
- };
58
- return clientService.renderType({ type, criteria, itemCriteria, filter, rootPath: null, wrapRelated, locale });
59
- },
60
- renderRFR({ items, parent = null, parentNavItem = null, contentTypes = [], enabledCustomFieldsNames, }) {
61
- const clientService = (0, utils_1.getPluginService)('client');
62
- let pages = {};
63
- let nav = {};
64
- let navItems = [];
65
- items.forEach(item => {
66
- const { items: itemChilds, ...itemProps } = item;
67
- const itemNav = clientService.renderRFRNav(itemProps);
68
- const itemPage = clientService.renderRFRPage(itemProps, parent, enabledCustomFieldsNames);
69
- if (item.type !== "EXTERNAL") {
70
- pages = {
71
- ...pages,
72
- [itemPage.id]: {
73
- ...itemPage,
74
- },
75
- };
76
- }
77
- if (item.menuAttached) {
78
- navItems.push(itemNav);
79
- }
80
- if (!parent) {
81
- nav = {
82
- ...nav,
83
- root: navItems,
84
- };
85
- }
86
- else {
87
- const navLevel = navItems
88
- .filter(navItem => navItem.type !== "EXTERNAL");
89
- if (!(0, lodash_1.isEmpty)(navLevel))
90
- nav = {
91
- ...nav,
92
- [parent]: navLevel.concat(parentNavItem ? parentNavItem : []),
93
- };
94
- }
95
- if (!(0, lodash_1.isEmpty)(itemChilds)) {
96
- const { nav: nestedNavs } = clientService.renderRFR({
97
- items: itemChilds,
98
- parent: itemPage.id,
99
- parentNavItem: itemNav,
100
- contentTypes,
101
- enabledCustomFieldsNames,
102
- });
103
- const { pages: nestedPages } = clientService.renderRFR({
104
- items: (itemChilds).filter(child => child.type !== "EXTERNAL"),
105
- parent: itemPage.id,
106
- parentNavItem: itemNav,
107
- contentTypes,
108
- enabledCustomFieldsNames,
109
- });
110
- pages = {
111
- ...pages,
112
- ...nestedPages,
113
- };
114
- nav = {
115
- ...nav,
116
- ...nestedNavs,
117
- };
118
- }
119
- });
120
- return {
121
- pages,
122
- nav,
123
- };
124
- },
125
- renderRFRNav(item) {
126
- const { uiRouterKey, title, path, type, audience } = item;
127
- const itemCommon = {
128
- label: title,
129
- type: type,
130
- audience,
131
- };
132
- if (type === "EXTERNAL") {
133
- (0, types_1.assertNotEmpty)(path, new NavigationError_1.NavigationError("External navigation item's path is undefined", item));
134
- return {
135
- ...itemCommon,
136
- url: path
137
- };
138
- }
139
- if (type === "INTERNAL") {
140
- return {
141
- ...itemCommon,
142
- page: uiRouterKey,
143
- };
144
- }
145
- if (type === "WRAPPER") {
146
- return {
147
- ...itemCommon,
148
- };
149
- }
150
- throw new NavigationError_1.NavigationError("Unknown item type", item);
151
- },
152
- renderRFRPage(item, parent, enabledCustomFieldsNames) {
153
- const { uiRouterKey, title, path, slug, related, type, audience, menuAttached } = item;
154
- const { __contentType, id, __templateName } = related || {};
155
- const contentType = __contentType || '';
156
- return {
157
- id: uiRouterKey,
158
- title,
159
- templateName: __templateName,
160
- related: type === "INTERNAL" ? {
161
- contentType,
162
- id,
163
- } : undefined,
164
- path,
165
- slug,
166
- parent,
167
- audience,
168
- menuAttached,
169
- ...enabledCustomFieldsNames.reduce((acc, field) => ({ ...acc, [field]: (0, lodash_1.get)(item, field) }), {})
170
- };
171
- },
172
- async renderTree(items = [], id = null, field = 'parent', path = '', itemParser = (i) => i) {
173
- return (await Promise.all(items
174
- .filter((item) => {
175
- if (item[field] === null && id === null) {
176
- return true;
177
- }
178
- let data = item[field];
179
- if (data && typeof id === 'string') {
180
- data = data.toString();
181
- }
182
- if (!!data && typeof data === 'object' && 'id' in data) {
183
- return data.id === id;
184
- }
185
- return (data && data === id);
186
- })
187
- .filter(utils_1.filterOutUnpublished)
188
- .map(async (item) => itemParser({
189
- ...item,
190
- }, path, field))))
191
- .sort((x, y) => {
192
- if (x.order !== undefined && y.order !== undefined)
193
- return x.order - y.order;
194
- else
195
- return 0;
196
- });
197
- },
198
- async renderType({ type = utils_1.RENDER_TYPES.FLAT, criteria = {}, itemCriteria = {}, filter = null, rootPath = null, wrapRelated = false, locale, populate, }) {
199
- const clientService = (0, utils_1.getPluginService)('client');
200
- const adminService = (0, utils_1.getPluginService)('admin');
201
- const commonService = (0, utils_1.getPluginService)('common');
202
- const entityWhereClause = {
203
- ...criteria,
204
- visible: true,
205
- };
206
- const { masterModel, itemModel } = (0, utils_1.getPluginModels)();
207
- const entity = await (0, i18n_1.i18nAwareEntityReadHandler)({
208
- entity: await strapi
209
- .query(masterModel.uid)
210
- .findOne({
211
- where: entityWhereClause,
212
- }),
213
- entityUid: masterModel.uid,
214
- strapi,
215
- whereClause: entityWhereClause,
216
- localeCode: locale,
217
- });
218
- if (entity && entity.id) {
219
- const entities = await strapi.query(itemModel.uid).findMany({
220
- where: {
221
- master: entity.id,
222
- ...itemCriteria,
223
- },
224
- limit: Number.MAX_SAFE_INTEGER,
225
- orderBy: [{ order: 'asc', }],
226
- populate: ['related', 'audience', 'parent'],
227
- });
228
- if (!entities) {
229
- return [];
230
- }
231
- const items = await commonService.getRelatedItems(entities, populate);
232
- const { contentTypes, contentTypesNameFields, additionalFields } = await adminService.config(false);
233
- const enabledCustomFieldsNames = (0, utils_1.getCustomFields)(additionalFields)
234
- .reduce((acc, curr) => curr.enabled ? [...acc, curr.name] : acc, []);
235
- const wrapContentType = (itemContentType) => wrapRelated && itemContentType ? {
236
- id: itemContentType.id,
237
- attributes: { ...itemContentType }
238
- } : itemContentType;
239
- const pickMediaFields = (0, fp_1.pick)(["name", "url", "mime", "width", "height", "previewUrl"]);
240
- const customFieldsDefinitions = additionalFields.filter(_ => typeof _ !== "string");
241
- switch (type) {
242
- case utils_1.RENDER_TYPES.TREE:
243
- case utils_1.RENDER_TYPES.RFR:
244
- const getTemplateName = await (0, utils_1.templateNameFactory)(items, strapi, contentTypes);
245
- const itemParser = async (item, path = '', field) => {
246
- const isExternal = item.type === "EXTERNAL";
247
- const parentPath = isExternal ? undefined : `${path === '/' ? '' : path}/${(0, lodash_1.first)(item.path) === '/'
248
- ? item.path.substring(1)
249
- : item.path}`;
250
- const slug = (0, lodash_1.isString)(parentPath) ? await commonService.getSlug(((0, lodash_1.first)(parentPath) === '/' ? parentPath.substring(1) : parentPath).replace(/\//g, '-')) : undefined;
251
- const lastRelated = (0, lodash_1.isArray)(item.related) ? (0, lodash_1.last)(item.related) : item.related;
252
- const relatedContentType = wrapContentType(lastRelated);
253
- const customFields = enabledCustomFieldsNames.reduce((acc, field) => {
254
- const mapper = customFieldsDefinitions.find(({ name }) => name === field)?.type === "media"
255
- ? (_) => pickMediaFields(JSON.parse(_))
256
- : fp_1.identity;
257
- const content = (0, lodash_1.get)(item, `additionalFields.${field}`);
258
- return { ...acc, [field]: content ? mapper(content) : content };
259
- }, {});
260
- return {
261
- id: item.id,
262
- title: (0, utils_1.composeItemTitle)(item, contentTypesNameFields, contentTypes),
263
- menuAttached: item.menuAttached,
264
- order: item.order,
265
- path: isExternal ? item.externalPath : parentPath,
266
- type: item.type,
267
- uiRouterKey: item.uiRouterKey,
268
- slug: !slug && item.uiRouterKey ? commonService.getSlug(item.uiRouterKey) : slug,
269
- external: isExternal,
270
- related: isExternal || !lastRelated ? undefined : {
271
- ...relatedContentType,
272
- __templateName: getTemplateName((lastRelated.relatedType || lastRelated.__contentType), lastRelated.id),
273
- },
274
- audience: !(0, lodash_1.isEmpty)(item.audience) ? item.audience.map(({ key }) => key) : undefined,
275
- items: isExternal ? undefined : await clientService.renderTree(items, item.id, field, parentPath, itemParser),
276
- ...customFields
277
- };
278
- };
279
- const { items: itemsFilteredByPath, root: rootElement, } = (0, utils_1.filterByPath)(items, rootPath);
280
- const treeStructure = await clientService.renderTree((0, lodash_1.isNil)(rootPath) ? items : itemsFilteredByPath, (0, lodash_1.get)(rootElement, 'parent.id') ?? null, 'parent', (0, lodash_1.get)(rootElement, 'parent.path'), itemParser);
281
- const filteredStructure = filter
282
- ? treeStructure.filter((item) => item.uiRouterKey === filter)
283
- : treeStructure;
284
- if (type === utils_1.RENDER_TYPES.RFR) {
285
- return clientService.renderRFR({
286
- items: filteredStructure,
287
- contentTypes,
288
- enabledCustomFieldsNames,
289
- });
290
- }
291
- return filteredStructure;
292
- default:
293
- const publishedItems = items.filter(utils_1.filterOutUnpublished);
294
- const result = (0, lodash_1.isNil)(rootPath) ? items : (0, utils_1.filterByPath)(publishedItems, rootPath).items;
295
- const defaultCache = new Map();
296
- const getNestedOrders = (id, cache = defaultCache) => {
297
- const cached = cache.get(id);
298
- if (!(0, lodash_1.isNil)(cached))
299
- return cached;
300
- const item = result.find(item => item.id === id);
301
- if ((0, lodash_1.isNil)(item))
302
- return [0];
303
- const { order, parent } = item;
304
- const nestedOrders = parent
305
- ? getNestedOrders(parent.id, cache).concat(order)
306
- : [order];
307
- cache.set(id, nestedOrders);
308
- return nestedOrders;
309
- };
310
- return result
311
- .map(({ additionalFields, autoSync: _, ...item }) => {
312
- const customFields = enabledCustomFieldsNames.reduce((acc, field) => {
313
- const mapper = customFieldsDefinitions.find(({ name }) => name === field)?.type === "media"
314
- ? (_) => pickMediaFields(JSON.parse(_.toString()))
315
- : fp_1.identity;
316
- const content = (0, lodash_1.get)(additionalFields, field);
317
- return { ...acc, [field]: content ? mapper(content) : content };
318
- }, {});
319
- return ({
320
- ...item,
321
- audience: item.audience?.map(_ => (_).key),
322
- title: (0, utils_1.composeItemTitle)({ ...item, additionalFields }, contentTypesNameFields, contentTypes) || '',
323
- related: wrapContentType(item.related),
324
- items: null,
325
- ...customFields,
326
- });
327
- })
328
- .sort((a, b) => (0, utils_1.compareArraysOfNumbers)(getNestedOrders(a.id), getNestedOrders(b.id)));
329
- }
330
- }
331
- throw new utils_2.errors.NotFoundError();
332
- },
333
- });
334
- exports.default = clientService;
335
- //# sourceMappingURL=client.js.map