strapi-plugin-navigation 2.0.11 → 2.1.0-beta.1

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 (268) hide show
  1. package/README.md +254 -41
  2. package/admin/src/components/Alert/styles.d.ts +2 -0
  3. package/admin/src/components/Alert/styles.js +14 -0
  4. package/admin/src/components/CollapseButton/index.d.ts +7 -0
  5. package/admin/src/components/CollapseButton/index.js +21 -22
  6. package/admin/src/components/ConfirmationDialog/index.d.ts +28 -0
  7. package/admin/src/components/ConfirmationDialog/index.js +32 -54
  8. package/admin/src/components/EmptyView/index.d.ts +3 -0
  9. package/admin/src/components/EmptyView/index.js +9 -7
  10. package/admin/src/components/Item/ItemCardBadge/index.d.ts +3 -0
  11. package/admin/src/components/Item/ItemCardBadge/index.js +11 -7
  12. package/admin/src/components/Item/ItemCardHeader/Wrapper.d.ts +3 -0
  13. package/admin/src/components/Item/ItemCardHeader/Wrapper.js +10 -6
  14. package/admin/src/components/Item/ItemCardHeader/index.d.ts +12 -0
  15. package/admin/src/components/Item/ItemCardHeader/index.js +34 -53
  16. package/admin/src/components/Item/ItemCardRemovedOverlay/index.d.ts +2 -0
  17. package/admin/src/components/Item/ItemCardRemovedOverlay/index.js +10 -4
  18. package/admin/src/components/Item/Wrapper.d.ts +3 -0
  19. package/admin/src/components/Item/Wrapper.js +10 -6
  20. package/admin/src/components/Item/index.d.ts +31 -0
  21. package/admin/src/components/Item/index.js +169 -242
  22. package/admin/src/components/NavigationItemList/Wrapper.d.ts +3 -0
  23. package/admin/src/components/NavigationItemList/Wrapper.js +9 -5
  24. package/admin/src/components/NavigationItemList/index.d.ts +35 -0
  25. package/admin/src/components/NavigationItemList/index.js +28 -66
  26. package/admin/src/components/RestartAlert/index.d.ts +3 -0
  27. package/admin/src/components/RestartAlert/index.js +10 -5
  28. package/admin/src/components/Search/index.d.ts +6 -0
  29. package/admin/src/components/Search/index.js +57 -46
  30. package/admin/src/components/icons/navigation.d.ts +6 -0
  31. package/admin/src/components/icons/navigation.js +11 -13
  32. package/admin/src/contexts/DataManagerContext.d.ts +3 -0
  33. package/admin/src/contexts/DataManagerContext.js +6 -5
  34. package/admin/src/hooks/useAllContentTypes.d.ts +6 -0
  35. package/admin/src/hooks/useAllContentTypes.js +10 -11
  36. package/admin/src/hooks/useDataManager.d.ts +3 -0
  37. package/admin/src/hooks/useDataManager.js +10 -6
  38. package/admin/src/hooks/useNavigationConfig.d.ts +10 -0
  39. package/admin/src/hooks/useNavigationConfig.js +52 -56
  40. package/admin/src/index.d.ts +14 -0
  41. package/admin/src/index.js +92 -76
  42. package/admin/src/pages/App/index.d.ts +3 -0
  43. package/admin/src/pages/App/index.js +43 -31
  44. package/admin/src/pages/DataManagerProvider/actions.d.ts +19 -0
  45. package/admin/src/pages/DataManagerProvider/actions.js +22 -26
  46. package/admin/src/pages/DataManagerProvider/index.d.ts +12 -0
  47. package/admin/src/pages/DataManagerProvider/index.js +280 -300
  48. package/admin/src/pages/DataManagerProvider/init.d.ts +3 -0
  49. package/admin/src/pages/DataManagerProvider/init.js +5 -3
  50. package/admin/src/pages/DataManagerProvider/reducer.d.ts +19 -0
  51. package/admin/src/pages/DataManagerProvider/reducer.js +119 -121
  52. package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.d.ts +24 -0
  53. package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.js +88 -0
  54. package/admin/src/pages/SettingsPage/index.d.ts +3 -0
  55. package/admin/src/pages/SettingsPage/index.js +242 -317
  56. package/admin/src/pages/SettingsPage/utils/functions.d.ts +5 -0
  57. package/admin/src/pages/SettingsPage/utils/functions.js +3 -8
  58. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.d.ts +20 -0
  59. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.js +60 -0
  60. package/admin/src/pages/View/components/NavigationContentHeader/index.d.ts +6 -0
  61. package/admin/src/pages/View/components/NavigationContentHeader/index.js +13 -17
  62. package/admin/src/pages/View/components/NavigationHeader/index.d.ts +12 -0
  63. package/admin/src/pages/View/components/NavigationHeader/index.js +74 -65
  64. package/admin/src/pages/View/components/NavigationHeader/styles.d.ts +2 -0
  65. package/admin/src/pages/View/components/NavigationHeader/styles.js +10 -5
  66. package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +51 -0
  67. package/admin/src/pages/View/components/NavigationItemForm/index.js +322 -454
  68. package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +45 -0
  69. package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +81 -52
  70. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.d.ts +23 -0
  71. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +24 -34
  72. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.d.ts +4 -0
  73. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +16 -16
  74. package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +27 -0
  75. package/admin/src/pages/View/components/NavigationItemPopup/index.js +59 -108
  76. package/admin/src/pages/View/index.d.ts +4 -0
  77. package/admin/src/pages/View/index.js +229 -304
  78. package/admin/src/pages/View/utils/enums.d.ts +9 -0
  79. package/admin/src/pages/View/utils/enums.js +11 -8
  80. package/admin/src/pages/View/utils/form.d.ts +2 -0
  81. package/admin/src/pages/View/utils/form.js +15 -12
  82. package/admin/src/pages/View/utils/index.d.ts +2 -0
  83. package/admin/src/pages/View/utils/index.js +11 -3
  84. package/admin/src/pages/View/utils/parsers.d.ts +44 -0
  85. package/admin/src/pages/View/utils/parsers.js +231 -277
  86. package/admin/src/permissions.d.ts +12 -0
  87. package/admin/src/permissions.js +11 -7
  88. package/admin/src/pluginId.d.ts +3 -0
  89. package/admin/src/pluginId.js +2 -2
  90. package/admin/src/translations/en.json +126 -102
  91. package/admin/src/translations/fr.json +44 -44
  92. package/admin/src/translations/index.d.ts +12 -0
  93. package/admin/src/translations/index.js +17 -11
  94. package/admin/src/utils/api.d.ts +8 -0
  95. package/admin/src/utils/api.js +54 -50
  96. package/admin/src/utils/getTrad.d.ts +3 -0
  97. package/admin/src/utils/getTrad.js +9 -5
  98. package/admin/src/utils/index.d.ts +5 -0
  99. package/admin/src/utils/index.js +21 -15
  100. package/package.json +19 -17
  101. package/permissions.d.ts +9 -0
  102. package/permissions.js +5 -4
  103. package/server/bootstrap/index.d.ts +4 -0
  104. package/server/bootstrap/index.js +41 -0
  105. package/server/config/index.d.ts +5 -0
  106. package/server/config/index.js +33 -9
  107. package/server/config/setupStrategy.d.ts +3 -0
  108. package/server/config/setupStrategy.js +38 -0
  109. package/server/content-types/audience/index.d.ts +27 -0
  110. package/server/content-types/audience/index.js +9 -8
  111. package/server/content-types/audience/schema.d.ts +25 -0
  112. package/server/content-types/audience/schema.js +26 -0
  113. package/server/content-types/index.d.ts +255 -0
  114. package/server/content-types/index.js +15 -12
  115. package/server/content-types/navigation/index.d.ts +64 -0
  116. package/server/content-types/navigation/index.js +11 -8
  117. package/server/content-types/navigation/lifecycle.d.ts +9 -0
  118. package/server/content-types/navigation/lifecycle.js +8 -12
  119. package/server/content-types/navigation/schema.d.ts +55 -0
  120. package/server/content-types/navigation/schema.js +56 -0
  121. package/server/content-types/navigation-item/index.d.ts +112 -0
  122. package/server/content-types/navigation-item/index.js +11 -8
  123. package/server/content-types/navigation-item/lifecycle.d.ts +16 -0
  124. package/server/content-types/navigation-item/lifecycle.js +28 -32
  125. package/server/content-types/navigation-item/schema.d.ts +97 -0
  126. package/server/content-types/navigation-item/schema.js +102 -0
  127. package/server/content-types/navigations-items-related/index.d.ts +56 -0
  128. package/server/content-types/navigations-items-related/index.js +11 -8
  129. package/server/content-types/navigations-items-related/lifecycle.d.ts +8 -0
  130. package/server/content-types/navigations-items-related/lifecycle.js +20 -17
  131. package/server/content-types/navigations-items-related/schema.d.ts +49 -0
  132. package/server/content-types/navigations-items-related/schema.js +50 -0
  133. package/server/controllers/admin.d.ts +4 -0
  134. package/server/controllers/admin.js +77 -0
  135. package/server/controllers/client.d.ts +4 -0
  136. package/server/controllers/client.js +34 -0
  137. package/server/controllers/index.d.ts +4 -0
  138. package/server/controllers/index.js +12 -6
  139. package/server/destroy.d.ts +3 -0
  140. package/server/destroy.js +5 -0
  141. package/server/graphql/config.d.ts +4 -0
  142. package/server/graphql/config.js +28 -0
  143. package/server/graphql/index.d.ts +2 -0
  144. package/server/graphql/index.js +18 -22
  145. package/server/graphql/queries/index.d.ts +3 -0
  146. package/server/graphql/queries/index.js +15 -15
  147. package/server/graphql/queries/render-navigation-child.d.ts +15 -0
  148. package/server/graphql/queries/render-navigation-child.js +24 -15
  149. package/server/graphql/queries/render-navigation.d.ts +23 -0
  150. package/server/graphql/queries/render-navigation.js +29 -15
  151. package/server/graphql/resolvers-config.d.ts +10 -0
  152. package/server/graphql/resolvers-config.js +5 -3
  153. package/server/graphql/setupStrategy.d.ts +3 -0
  154. package/server/graphql/setupStrategy.js +15 -0
  155. package/server/graphql/types/content-types-name-fields.d.ts +6 -0
  156. package/server/graphql/types/content-types-name-fields.js +13 -9
  157. package/server/graphql/types/content-types.d.ts +5 -0
  158. package/server/graphql/types/content-types.js +17 -15
  159. package/server/graphql/types/create-navigation-item.d.ts +5 -0
  160. package/server/graphql/types/create-navigation-item.js +18 -16
  161. package/server/graphql/types/create-navigation-related.d.ts +5 -0
  162. package/server/graphql/types/create-navigation-related.js +9 -7
  163. package/server/graphql/types/create-navigation.d.ts +5 -0
  164. package/server/graphql/types/create-navigation.js +8 -6
  165. package/server/graphql/types/index.d.ts +3 -0
  166. package/server/graphql/types/index.js +15 -13
  167. package/server/graphql/types/navigation-config.d.ts +5 -0
  168. package/server/graphql/types/navigation-config.js +10 -8
  169. package/server/graphql/types/navigation-details.d.ts +5 -0
  170. package/server/graphql/types/navigation-details.js +11 -9
  171. package/server/graphql/types/navigation-item-related-data.d.ts +5 -0
  172. package/server/graphql/types/navigation-item-related-data.js +9 -0
  173. package/server/graphql/types/navigation-item-related.d.ts +7 -0
  174. package/server/graphql/types/navigation-item-related.js +25 -0
  175. package/server/graphql/types/navigation-item.d.ts +5 -0
  176. package/server/graphql/types/navigation-item.js +28 -29
  177. package/server/graphql/types/navigation-render-type.d.ts +5 -0
  178. package/server/graphql/types/navigation-render-type.js +7 -4
  179. package/server/graphql/types/navigation.d.ts +5 -0
  180. package/server/graphql/types/navigation.js +10 -8
  181. package/server/i18n/constant.d.ts +2 -0
  182. package/server/i18n/constant.js +5 -0
  183. package/server/i18n/errors.d.ts +7 -0
  184. package/server/i18n/errors.js +14 -0
  185. package/server/i18n/graphQLEnhancers.d.ts +10 -0
  186. package/server/i18n/graphQLEnhancers.js +9 -0
  187. package/server/i18n/index.d.ts +8 -0
  188. package/server/i18n/index.js +23 -0
  189. package/server/i18n/navigationSetupStrategy.d.ts +3 -0
  190. package/server/i18n/navigationSetupStrategy.js +119 -0
  191. package/server/i18n/serviceEnhancers.d.ts +12 -0
  192. package/server/i18n/serviceEnhancers.js +117 -0
  193. package/server/i18n/types.d.ts +54 -0
  194. package/server/i18n/types.js +3 -0
  195. package/server/i18n/utils.d.ts +12 -0
  196. package/server/i18n/utils.js +29 -0
  197. package/server/index.d.ts +273 -0
  198. package/server/index.js +26 -0
  199. package/server/navigation/index.d.ts +2 -0
  200. package/server/navigation/index.js +18 -0
  201. package/server/navigation/setupStrategy.d.ts +3 -0
  202. package/server/navigation/setupStrategy.js +37 -0
  203. package/server/register/index.d.ts +3 -0
  204. package/server/register/index.js +4 -0
  205. package/server/routes/admin.d.ts +4 -0
  206. package/server/routes/admin.js +72 -61
  207. package/server/routes/client.d.ts +4 -0
  208. package/server/routes/client.js +25 -21
  209. package/server/routes/index.d.ts +6 -0
  210. package/server/routes/index.js +13 -4
  211. package/server/services/admin.d.ts +5 -0
  212. package/server/services/admin.js +183 -0
  213. package/server/services/client.d.ts +5 -0
  214. package/server/services/client.js +249 -0
  215. package/server/services/common.d.ts +5 -0
  216. package/server/services/common.js +313 -0
  217. package/server/services/index.d.ts +7 -0
  218. package/server/services/index.js +14 -6
  219. package/server/utils/constant.d.ts +27 -0
  220. package/server/utils/constant.js +24 -0
  221. package/server/utils/functions.d.ts +138 -0
  222. package/server/utils/functions.js +224 -0
  223. package/server/utils/index.d.ts +3 -0
  224. package/server/utils/index.js +19 -0
  225. package/strapi-admin.d.ts +3 -0
  226. package/strapi-admin.js +8 -1
  227. package/strapi-server.d.ts +273 -0
  228. package/strapi-server.js +6 -17
  229. package/tsconfig.tsbuildinfo +1 -0
  230. package/types/bootstrap.d.ts +13 -0
  231. package/types/bootstrap.js +3 -0
  232. package/types/config.d.ts +21 -0
  233. package/types/config.js +3 -0
  234. package/types/contentTypes.d.ts +85 -0
  235. package/types/contentTypes.js +3 -0
  236. package/types/controllers.d.ts +35 -0
  237. package/types/controllers.js +5 -0
  238. package/types/graphQL.d.ts +3 -0
  239. package/types/graphQL.js +3 -0
  240. package/types/i18n.d.ts +9 -0
  241. package/types/i18n.js +3 -0
  242. package/types/index.d.ts +9 -0
  243. package/types/index.js +25 -0
  244. package/types/services.d.ts +68 -0
  245. package/types/services.js +3 -0
  246. package/types/utils.d.ts +58 -0
  247. package/types/utils.js +26 -0
  248. package/utils/InvalidParamNavigationError.d.ts +4 -0
  249. package/utils/InvalidParamNavigationError.js +11 -0
  250. package/utils/NavigationError.d.ts +5 -0
  251. package/utils/NavigationError.js +7 -7
  252. package/__mocks__/pages.settings.json +0 -25
  253. package/__mocks__/strapi.js +0 -207
  254. package/jest.config.js +0 -14
  255. package/server/bootstrap.js +0 -52
  256. package/server/config.js +0 -9
  257. package/server/content-types/audience/lifecycle.js +0 -8
  258. package/server/content-types/audience/schema.json +0 -23
  259. package/server/content-types/navigation/schema.json +0 -45
  260. package/server/content-types/navigation-item/schema.json +0 -99
  261. package/server/content-types/navigations-items-related/schema.json +0 -47
  262. package/server/controllers/navigation.js +0 -105
  263. package/server/graphql/types/navigation-related.js +0 -25
  264. package/server/services/__tests__/functions.test.js +0 -48
  265. package/server/services/__tests__/navigation.test.js +0 -91
  266. package/server/services/navigation.js +0 -788
  267. package/server/services/utils/constant.js +0 -21
  268. package/server/services/utils/functions.js +0 -226
@@ -1,61 +1,72 @@
1
- module.exports = {
2
- type: 'admin',
3
- routes: [
4
- {
5
- method: 'GET',
6
- path: '/',
7
- handler: 'navigation.get',
8
- },
9
- {
10
- method: 'POST',
11
- path: '/',
12
- handler: 'navigation.post',
13
- },
14
- {
15
- method: 'GET',
16
- path: '/config',
17
- handler: 'navigation.config',
18
- },
19
- {
20
- method: 'PUT',
21
- path: '/config',
22
- handler: 'navigation.updateConfig',
23
- },
24
- {
25
- method: 'DELETE',
26
- path: '/config',
27
- handler: 'navigation.restoreConfig',
28
- },
29
- {
30
- method: 'GET',
31
- path: '/:id',
32
- handler: 'navigation.getById',
33
- },
34
- {
35
- method: 'PUT',
36
- path: '/:id',
37
- handler: 'navigation.put',
38
- },
39
- {
40
- method: 'GET',
41
- path: '/content-type-items/:model',
42
- handler: 'navigation.getContentTypeItems',
43
- policies: [
44
- 'admin::isAuthenticatedAdmin'
45
- ]
46
- },
47
- {
48
- method: 'GET',
49
- path: '/settings/config',
50
- handler: 'navigation.settingsConfig',
51
- },
52
- {
53
- method: 'GET',
54
- path: '/settings/restart',
55
- handler: 'navigation.settingsRestart',
56
- config: {
57
- policies: [],
58
- },
59
- },
60
- ]
61
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const routes = {
4
+ type: 'admin',
5
+ routes: [
6
+ {
7
+ method: 'GET',
8
+ path: '/',
9
+ handler: 'admin.get',
10
+ },
11
+ {
12
+ method: 'POST',
13
+ path: '/',
14
+ handler: 'admin.post',
15
+ },
16
+ {
17
+ method: 'GET',
18
+ path: '/config',
19
+ handler: 'admin.config',
20
+ },
21
+ {
22
+ method: 'PUT',
23
+ path: '/config',
24
+ handler: 'admin.updateConfig',
25
+ },
26
+ {
27
+ method: 'DELETE',
28
+ path: '/config',
29
+ handler: 'admin.restoreConfig',
30
+ },
31
+ {
32
+ method: 'GET',
33
+ path: '/:id',
34
+ handler: 'admin.getById',
35
+ },
36
+ {
37
+ method: 'PUT',
38
+ path: '/:id',
39
+ handler: 'admin.put',
40
+ },
41
+ {
42
+ method: 'GET',
43
+ path: '/content-type-items/:model',
44
+ handler: 'admin.getContentTypeItems',
45
+ config: {
46
+ policies: [
47
+ 'admin::isAuthenticatedAdmin'
48
+ ]
49
+ }
50
+ },
51
+ {
52
+ method: 'GET',
53
+ path: '/settings/config',
54
+ handler: 'admin.settingsConfig',
55
+ },
56
+ {
57
+ method: 'GET',
58
+ path: '/settings/restart',
59
+ handler: 'admin.settingsRestart',
60
+ config: {
61
+ policies: [],
62
+ },
63
+ },
64
+ {
65
+ method: 'PUT',
66
+ path: '/i18n/copy/:source/:target',
67
+ handler: 'admin.fillFromOtherLocale',
68
+ },
69
+ ]
70
+ };
71
+ exports.default = routes;
72
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1,4 @@
1
+ import { StrapiRoutes } from "../../types";
2
+ declare const routes: StrapiRoutes;
3
+ export default routes;
4
+ //# sourceMappingURL=client.d.ts.map
@@ -1,21 +1,25 @@
1
- module.exports = {
2
- type: 'content-api',
3
- routes: [
4
- {
5
- method: "GET",
6
- path: "/render/:idOrSlug",
7
- handler: "navigation.render",
8
- config: {
9
- policies: []
10
- }
11
- },
12
- {
13
- method: "GET",
14
- path: "/render/:idOrSlug/:childUIKey",
15
- handler: "navigation.renderChild",
16
- config: {
17
- policies: []
18
- }
19
- }
20
- ]
21
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const routes = {
4
+ type: 'content-api',
5
+ routes: [
6
+ {
7
+ method: "GET",
8
+ path: "/render/:idOrSlug",
9
+ handler: "client.render",
10
+ config: {
11
+ policies: []
12
+ }
13
+ },
14
+ {
15
+ method: "GET",
16
+ path: "/render/:idOrSlug/:childUIKey",
17
+ handler: "client.renderChild",
18
+ config: {
19
+ policies: []
20
+ }
21
+ }
22
+ ]
23
+ };
24
+ exports.default = routes;
25
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,6 @@
1
+ declare const routes: {
2
+ admin: import("../../types").StrapiRoutes;
3
+ 'content-api': import("../../types").StrapiRoutes;
4
+ };
5
+ export default routes;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,13 @@
1
- module.exports = {
2
- 'admin': require('./admin'),
3
- 'content-api': require('./client'),
4
- };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const admin_1 = __importDefault(require("./admin"));
7
+ const client_1 = __importDefault(require("./client"));
8
+ const routes = {
9
+ admin: admin_1.default,
10
+ 'content-api': client_1.default,
11
+ };
12
+ exports.default = routes;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ import { StrapiContext } from "strapi-typed";
2
+ import { IAdminService } from "../../types";
3
+ declare const adminService: (context: StrapiContext) => IAdminService;
4
+ export default adminService;
5
+ //# sourceMappingURL=admin.d.ts.map
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const slugify_1 = __importDefault(require("slugify"));
7
+ const lodash_1 = require("lodash");
8
+ const utils_1 = require("../utils");
9
+ const i18n_1 = require("../i18n");
10
+ const NavigationError_1 = require("../../utils/NavigationError");
11
+ const adminService = ({ strapi }) => ({
12
+ async config(viaSettingsPage = false) {
13
+ const commonService = (0, utils_1.getPluginService)('common');
14
+ const { audienceModel } = (0, utils_1.extractMeta)(strapi.plugins);
15
+ const pluginStore = await commonService.getPluginStore();
16
+ const config = await pluginStore.get({ key: 'config' });
17
+ const additionalFields = config.additionalFields;
18
+ const contentTypesNameFields = config.contentTypesNameFields;
19
+ const contentTypesPopulate = config.contentTypesPopulate;
20
+ const allowedLevels = config.allowedLevels;
21
+ const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin('graphql'));
22
+ let extendedResult = {
23
+ allowedContentTypes: utils_1.ALLOWED_CONTENT_TYPES,
24
+ restrictedContentTypes: utils_1.RESTRICTED_CONTENT_TYPES,
25
+ };
26
+ const configContentTypes = await commonService.configContentTypes();
27
+ const result = {
28
+ contentTypes: await commonService.configContentTypes(viaSettingsPage),
29
+ contentTypesNameFields: {
30
+ default: utils_1.CONTENT_TYPES_NAME_FIELDS_DEFAULTS,
31
+ ...((0, lodash_1.isObject)(contentTypesNameFields) ? contentTypesNameFields : {}),
32
+ },
33
+ contentTypesPopulate: {
34
+ ...((0, lodash_1.isObject)(contentTypesPopulate) ? contentTypesPopulate : {}),
35
+ },
36
+ allowedLevels,
37
+ additionalFields,
38
+ gql: {
39
+ navigationItemRelated: configContentTypes.map(({ labelSingular }) => labelSingular.replace(/\s+/g, ''))
40
+ },
41
+ isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
42
+ };
43
+ const i18nConfig = await (0, i18n_1.addI18NConfigFields)({ strapi, viaSettingsPage, previousConfig: {} });
44
+ if (additionalFields.includes(utils_1.ADDITIONAL_FIELDS.AUDIENCE)) {
45
+ const audienceItems = await strapi
46
+ .query(audienceModel.uid)
47
+ .findMany({
48
+ limit: Number.MAX_SAFE_INTEGER,
49
+ });
50
+ extendedResult = {
51
+ ...extendedResult,
52
+ availableAudience: audienceItems,
53
+ };
54
+ }
55
+ return {
56
+ ...result,
57
+ ...extendedResult,
58
+ ...i18nConfig,
59
+ };
60
+ },
61
+ async get() {
62
+ const { masterModel } = (0, utils_1.extractMeta)(strapi.plugins);
63
+ const entities = await strapi
64
+ .query(masterModel.uid)
65
+ .findMany({
66
+ limit: Number.MAX_SAFE_INTEGER,
67
+ populate: utils_1.DEFAULT_POPULATE,
68
+ });
69
+ return entities;
70
+ },
71
+ async getById(id) {
72
+ const commonService = (0, utils_1.getPluginService)('common');
73
+ const { masterModel, itemModel } = (0, utils_1.extractMeta)(strapi.plugins);
74
+ const entity = await strapi
75
+ .query(masterModel.uid)
76
+ .findOne({ where: { id }, populate: utils_1.DEFAULT_POPULATE });
77
+ const entityItems = await strapi
78
+ .query(itemModel.uid)
79
+ .findMany({
80
+ where: {
81
+ master: id,
82
+ },
83
+ limit: Number.MAX_SAFE_INTEGER,
84
+ orderBy: [{ order: 'asc', }],
85
+ populate: ['related', 'parent', 'audience']
86
+ });
87
+ const entities = await commonService.getRelatedItems(entityItems);
88
+ return {
89
+ ...entity,
90
+ items: (0, utils_1.buildNestedStructure)(entities),
91
+ };
92
+ },
93
+ async post(payload, auditLog) {
94
+ const commonService = (0, utils_1.getPluginService)('common');
95
+ const adminService = (0, utils_1.getPluginService)('admin');
96
+ const { masterModel } = (0, utils_1.extractMeta)(strapi.plugins);
97
+ const { name, visible } = payload;
98
+ const data = {
99
+ name,
100
+ slug: (0, slugify_1.default)(name).toLowerCase(),
101
+ visible,
102
+ };
103
+ const existingEntity = await strapi
104
+ .query(masterModel.uid)
105
+ .create({ data });
106
+ const result = commonService
107
+ .createBranch(payload.items, existingEntity, null, {})
108
+ .then(() => adminService.getById(existingEntity.id))
109
+ .then((newEntity) => {
110
+ (0, utils_1.sendAuditLog)(auditLog, 'onChangeNavigation', { actionType: 'CREATE', oldEntity: existingEntity, newEntity });
111
+ return newEntity;
112
+ });
113
+ await commonService.emitEvent(masterModel.uid, 'entry.create', existingEntity);
114
+ return result;
115
+ },
116
+ async put(id, payload, auditLog) {
117
+ const adminService = (0, utils_1.getPluginService)('admin');
118
+ const commonService = (0, utils_1.getPluginService)('common');
119
+ const { masterModel } = (0, utils_1.extractMeta)(strapi.plugins);
120
+ const { name, visible } = payload;
121
+ const existingEntity = await adminService.getById(id);
122
+ const entityNameHasChanged = existingEntity.name !== name || existingEntity.visible !== visible;
123
+ if (entityNameHasChanged) {
124
+ await strapi.query(masterModel.uid).update({
125
+ where: { id },
126
+ data: {
127
+ name: entityNameHasChanged ? name : existingEntity.name,
128
+ slug: entityNameHasChanged ? (0, slugify_1.default)(name).toLowerCase() : existingEntity.slug,
129
+ visible,
130
+ },
131
+ });
132
+ }
133
+ const result = commonService
134
+ .analyzeBranch(payload.items, existingEntity)
135
+ .then((auditLogsOperations) => Promise.all([
136
+ auditLog ? (0, utils_1.prepareAuditLog)((auditLogsOperations || []).flat(Number.MAX_SAFE_INTEGER)) : [],
137
+ adminService.getById(existingEntity.id)
138
+ ]))
139
+ .then(([actionType, newEntity]) => {
140
+ (0, utils_1.sendAuditLog)(auditLog, 'onChangeNavigation', { actionType, oldEntity: existingEntity, newEntity });
141
+ return newEntity;
142
+ });
143
+ const navigationEntity = await strapi.query(masterModel.uid).findOne({ where: { id } });
144
+ await commonService.emitEvent(masterModel.uid, 'entry.update', navigationEntity);
145
+ return result;
146
+ },
147
+ async restart() {
148
+ setImmediate(() => strapi.reload());
149
+ },
150
+ async restoreConfig() {
151
+ const commonService = (0, utils_1.getPluginService)('common');
152
+ const pluginStore = await commonService.getPluginStore();
153
+ await pluginStore.delete({ key: 'config' });
154
+ await commonService.setDefaultConfig();
155
+ },
156
+ async updateConfig(newConfig) {
157
+ const commonService = (0, utils_1.getPluginService)('common');
158
+ const pluginStore = await commonService.getPluginStore();
159
+ await pluginStore.set({ key: 'config', value: newConfig });
160
+ },
161
+ async fillFromOtherLocale({ target, source, auditLog }) {
162
+ const { enabled } = await (0, i18n_1.getI18nStatus)({ strapi });
163
+ if (!enabled) {
164
+ throw new NavigationError_1.NavigationError("Not yet implemented.");
165
+ }
166
+ const adminService = (0, utils_1.getPluginService)('admin');
167
+ const commonService = (0, utils_1.getPluginService)('common');
168
+ const targetEntity = await adminService.getById(target);
169
+ return await (0, i18n_1.i18nNavigationContentsCopy)({
170
+ source: await adminService.getById(source),
171
+ target: targetEntity,
172
+ service: commonService,
173
+ strapi,
174
+ })
175
+ .then(() => adminService.getById(target))
176
+ .then((updated) => {
177
+ (0, utils_1.sendAuditLog)(auditLog, 'onChangeNavigation', { actionType: 'UPDATE', oldEntity: targetEntity, newEntity: updated });
178
+ return updated;
179
+ });
180
+ },
181
+ });
182
+ exports.default = adminService;
183
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_1 = require("lodash");
7
+ const slugify_1 = __importDefault(require("slugify"));
8
+ const uuid_1 = require("uuid");
9
+ const types_1 = require("../../types");
10
+ const utils_1 = require("../utils");
11
+ const utils_2 = require("@strapi/utils");
12
+ const i18n_1 = require("../i18n");
13
+ const NavigationError_1 = require("../../utils/NavigationError");
14
+ const clientService = ({ strapi }) => ({
15
+ async render({ idOrSlug, type = utils_1.RENDER_TYPES.FLAT, menuOnly = false, rootPath = null, wrapRelated = false, locale, }) {
16
+ const clientService = (0, utils_1.getPluginService)('client');
17
+ const findById = !isNaN((0, lodash_1.toNumber)(idOrSlug)) || (0, uuid_1.validate)(idOrSlug);
18
+ const criteria = findById ? { id: idOrSlug } : { slug: idOrSlug };
19
+ const itemCriteria = menuOnly ? { menuAttached: true } : {};
20
+ return await clientService.renderType({
21
+ type, criteria, itemCriteria, filter: null, rootPath, wrapRelated, locale,
22
+ });
23
+ },
24
+ async renderChildren({ idOrSlug, childUIKey, type = utils_1.RENDER_TYPES.FLAT, menuOnly = false, wrapRelated = false, locale, }) {
25
+ const clientService = (0, utils_1.getPluginService)('client');
26
+ const findById = !isNaN((0, lodash_1.toNumber)(idOrSlug)) || (0, uuid_1.validate)(idOrSlug);
27
+ const criteria = findById ? { id: idOrSlug } : { slug: idOrSlug };
28
+ const filter = type === utils_1.RENDER_TYPES.FLAT ? null : childUIKey;
29
+ const itemCriteria = {
30
+ ...(menuOnly && { menuAttached: true }),
31
+ ...(type === utils_1.RENDER_TYPES.FLAT ? { uiRouterKey: childUIKey } : {}),
32
+ };
33
+ return clientService.renderType({ type, criteria, itemCriteria, filter, rootPath: null, wrapRelated, locale });
34
+ },
35
+ renderRFR(items, parent = null, parentNavItem = null, contentTypes = []) {
36
+ const clientService = (0, utils_1.getPluginService)('client');
37
+ let pages = {};
38
+ let nav = {};
39
+ let navItems = [];
40
+ items.forEach(item => {
41
+ const { items: itemChilds, ...itemProps } = item;
42
+ const itemNav = clientService.renderRFRNav(itemProps);
43
+ const itemPage = clientService.renderRFRPage(itemProps, parent);
44
+ if (item.type === "INTERNAL") {
45
+ pages = {
46
+ ...pages,
47
+ [itemPage.id]: {
48
+ ...itemPage,
49
+ },
50
+ };
51
+ }
52
+ if (item.menuAttached) {
53
+ navItems.push(itemNav);
54
+ }
55
+ if (!parent) {
56
+ nav = {
57
+ ...nav,
58
+ root: navItems,
59
+ };
60
+ }
61
+ else {
62
+ const navLevel = navItems
63
+ .filter(navItem => navItem.type === "INTERNAL");
64
+ if (!(0, lodash_1.isEmpty)(navLevel))
65
+ nav = {
66
+ ...nav,
67
+ [parent]: navLevel.concat(parentNavItem ? parentNavItem : []),
68
+ };
69
+ }
70
+ if (!(0, lodash_1.isEmpty)(itemChilds)) {
71
+ const { nav: nestedNavs } = clientService.renderRFR(itemChilds, itemPage.id, itemNav, contentTypes);
72
+ const { pages: nestedPages } = clientService.renderRFR((itemChilds).filter(child => child.type === "INTERNAL"), itemPage.id, itemNav, contentTypes);
73
+ pages = {
74
+ ...pages,
75
+ ...nestedPages,
76
+ };
77
+ nav = {
78
+ ...nav,
79
+ ...nestedNavs,
80
+ };
81
+ }
82
+ });
83
+ return {
84
+ pages,
85
+ nav,
86
+ };
87
+ },
88
+ renderRFRNav(item) {
89
+ const { uiRouterKey, title, path, type, audience } = item;
90
+ const itemCommon = {
91
+ label: title,
92
+ type: type,
93
+ audience,
94
+ };
95
+ if (type === "EXTERNAL") {
96
+ (0, types_1.assertNotEmpty)(path, new NavigationError_1.NavigationError("External navigation item's path is undefined", item));
97
+ return {
98
+ ...itemCommon,
99
+ url: path
100
+ };
101
+ }
102
+ if (type === "INTERNAL") {
103
+ return {
104
+ ...itemCommon,
105
+ page: uiRouterKey,
106
+ };
107
+ }
108
+ throw new NavigationError_1.NavigationError("Unknown item type", item);
109
+ },
110
+ renderRFRPage(item, parent) {
111
+ const { uiRouterKey, title, path, slug, related, type, audience, menuAttached } = item;
112
+ const { __contentType, id, __templateName } = related || {};
113
+ const contentType = __contentType || '';
114
+ return {
115
+ id: uiRouterKey,
116
+ title,
117
+ templateName: __templateName,
118
+ related: type === "INTERNAL" ? {
119
+ contentType,
120
+ id,
121
+ } : undefined,
122
+ path,
123
+ slug,
124
+ parent,
125
+ audience,
126
+ menuAttached,
127
+ };
128
+ },
129
+ renderTree(items = [], id = null, field = 'parent', path = '', itemParser = (i) => i) {
130
+ return items
131
+ .filter((item) => {
132
+ if (item[field] === null && id === null) {
133
+ return true;
134
+ }
135
+ let data = item[field];
136
+ if (data && typeof id === 'string') {
137
+ data = data.toString();
138
+ }
139
+ if (!!data && typeof data === 'object' && 'id' in data) {
140
+ return data.id === id;
141
+ }
142
+ return (data && data === id);
143
+ })
144
+ .filter(utils_1.filterOutUnpublished)
145
+ .map(item => itemParser({
146
+ ...item,
147
+ }, path, field))
148
+ .sort((x, y) => {
149
+ if (x.order !== undefined && y.order !== undefined)
150
+ return x.order - y.order;
151
+ else
152
+ return 0;
153
+ });
154
+ },
155
+ async renderType({ type = utils_1.RENDER_TYPES.FLAT, criteria = {}, itemCriteria = {}, filter = null, rootPath = null, wrapRelated = false, locale, }) {
156
+ const clientService = (0, utils_1.getPluginService)('client');
157
+ const adminService = (0, utils_1.getPluginService)('admin');
158
+ const commonService = (0, utils_1.getPluginService)('common');
159
+ const entityWhereClause = {
160
+ ...criteria,
161
+ visible: true,
162
+ };
163
+ const { masterModel, itemModel } = (0, utils_1.extractMeta)(strapi.plugins);
164
+ const entity = await (0, i18n_1.i18nAwareEntityReadHandler)({
165
+ entity: await strapi
166
+ .query(masterModel.uid)
167
+ .findOne({
168
+ where: entityWhereClause,
169
+ }),
170
+ entityUid: masterModel.uid,
171
+ strapi,
172
+ whereClause: entityWhereClause,
173
+ localeCode: locale,
174
+ });
175
+ if (entity && entity.id) {
176
+ const entities = await strapi.query(itemModel.uid).findMany({
177
+ where: {
178
+ master: entity.id,
179
+ ...itemCriteria,
180
+ },
181
+ limit: Number.MAX_SAFE_INTEGER,
182
+ orderBy: [{ order: 'asc', }],
183
+ populate: ['related', 'audience', 'parent'],
184
+ });
185
+ if (!entities) {
186
+ return [];
187
+ }
188
+ const items = await commonService.getRelatedItems(entities);
189
+ const { contentTypes, contentTypesNameFields } = await adminService.config(false);
190
+ const wrapContentType = (itemContentType) => wrapRelated && itemContentType ? {
191
+ id: itemContentType.id,
192
+ attributes: { ...itemContentType }
193
+ } : itemContentType;
194
+ switch (type) {
195
+ case utils_1.RENDER_TYPES.TREE:
196
+ case utils_1.RENDER_TYPES.RFR:
197
+ const getTemplateName = await (0, utils_1.templateNameFactory)(items, strapi, contentTypes);
198
+ const itemParser = (item, path = '', field) => {
199
+ const isExternal = item.type === "EXTERNAL";
200
+ const parentPath = isExternal ? undefined : `${path === '/' ? '' : path}/${(0, lodash_1.first)(item.path) === '/'
201
+ ? item.path.substring(1)
202
+ : item.path}`;
203
+ const slug = (0, lodash_1.isString)(parentPath) ? (0, slugify_1.default)(((0, lodash_1.first)(parentPath) === '/' ? parentPath.substring(1) : parentPath).replace(/\//g, '-')) : undefined;
204
+ const lastRelated = (0, lodash_1.isArray)(item.related) ? (0, lodash_1.last)(item.related) : item.related;
205
+ const relatedContentType = wrapContentType(lastRelated);
206
+ return {
207
+ id: item.id,
208
+ title: (0, utils_1.composeItemTitle)(item, contentTypesNameFields, contentTypes),
209
+ menuAttached: item.menuAttached,
210
+ order: item.order,
211
+ path: isExternal ? item.externalPath : parentPath,
212
+ type: item.type,
213
+ uiRouterKey: item.uiRouterKey,
214
+ slug: !slug && item.uiRouterKey ? (0, slugify_1.default)(item.uiRouterKey) : slug,
215
+ external: isExternal,
216
+ related: isExternal || !lastRelated ? undefined : {
217
+ ...relatedContentType,
218
+ __templateName: getTemplateName((lastRelated.relatedType || lastRelated.__contentType), lastRelated.id),
219
+ },
220
+ audience: !(0, lodash_1.isEmpty)(item.audience) ? item.audience.map(aItem => (aItem).key) : undefined,
221
+ items: isExternal ? undefined : clientService.renderTree(items, item.id, field, parentPath, itemParser),
222
+ };
223
+ };
224
+ const { items: itemsFilteredByPath, root: rootElement, } = (0, utils_1.filterByPath)(items, rootPath);
225
+ const treeStructure = clientService.renderTree((0, lodash_1.isNil)(rootPath) ? items : itemsFilteredByPath, (0, lodash_1.get)(rootElement, 'parent.id'), 'parent', (0, lodash_1.get)(rootElement, 'parent.path'), itemParser);
226
+ const filteredStructure = filter
227
+ ? treeStructure.filter((item) => item.uiRouterKey === filter)
228
+ : treeStructure;
229
+ if (type === utils_1.RENDER_TYPES.RFR) {
230
+ return clientService.renderRFR(filteredStructure, null, null, contentTypes);
231
+ }
232
+ return filteredStructure;
233
+ default:
234
+ const publishedItems = items.filter(utils_1.filterOutUnpublished);
235
+ const result = (0, lodash_1.isNil)(rootPath) ? items : (0, utils_1.filterByPath)(publishedItems, rootPath).items;
236
+ return result.map((item) => ({
237
+ ...item,
238
+ audience: item.audience?.map(_ => (_).key),
239
+ title: (0, utils_1.composeItemTitle)(item, contentTypesNameFields, contentTypes) || '',
240
+ related: wrapContentType(item.related),
241
+ items: null,
242
+ }));
243
+ }
244
+ }
245
+ throw new utils_2.errors.NotFoundError();
246
+ },
247
+ });
248
+ exports.default = clientService;
249
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,5 @@
1
+ import { StrapiContext } from "strapi-typed";
2
+ import { ICommonService } from "../../types";
3
+ declare const commonService: (context: StrapiContext) => ICommonService;
4
+ export default commonService;
5
+ //# sourceMappingURL=common.d.ts.map