@commercetools-frontend/application-shell 21.23.10 → 21.24.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 (208) hide show
  1. package/dist/application-entry-point-2a64a561.cjs.dev.js +116 -0
  2. package/dist/application-entry-point-3bb7f8bd.cjs.prod.js +99 -0
  3. package/dist/application-entry-point-58dd4b7f.esm.js +101 -0
  4. package/dist/{box-dd9e7e68.esm.js → box-4395623b.esm.js} +1 -3
  5. package/dist/{box-fdb2ccb6.cjs.dev.js → box-6b5be9a9.cjs.dev.js} +1 -3
  6. package/dist/{box-d849ea03.cjs.prod.js → box-8850277f.cjs.prod.js} +1 -3
  7. package/dist/{cart-ad0aba9b.cjs.prod.js → cart-0698b97d.cjs.prod.js} +1 -3
  8. package/dist/{cart-b92f3a8e.cjs.dev.js → cart-41f0b7bc.cjs.dev.js} +1 -3
  9. package/dist/{cart-167fea3b.esm.js → cart-a49faf67.esm.js} +1 -3
  10. package/dist/commercetools-frontend-application-shell.cjs.dev.js +49 -68
  11. package/dist/commercetools-frontend-application-shell.cjs.prod.js +49 -68
  12. package/dist/commercetools-frontend-application-shell.esm.js +39 -58
  13. package/dist/configure-apollo-1f39e35a.cjs.dev.js +930 -0
  14. package/dist/configure-apollo-5f1fd942.esm.js +873 -0
  15. package/dist/configure-apollo-d11de242.cjs.prod.js +922 -0
  16. package/dist/{connected-square-4743b7de.esm.js → connected-square-3cac6bd7.esm.js} +1 -3
  17. package/dist/connected-square-47233754.cjs.dev.js +32 -0
  18. package/dist/connected-square-b2e25621.cjs.prod.js +32 -0
  19. package/dist/{constants-69249abd.esm.js → constants-7f04db3f.esm.js} +9 -9
  20. package/dist/{constants-88fb9ef8.cjs.prod.js → constants-e6409334.cjs.prod.js} +8 -8
  21. package/dist/{constants-c2d56f3d.cjs.dev.js → constants-e6f058e5.cjs.dev.js} +8 -8
  22. package/dist/declarations/src/apollo-links/utils.d.ts +2 -2
  23. package/dist/declarations/src/components/application-entry-point/application-entry-point.d.ts +4 -4
  24. package/dist/declarations/src/components/application-shell/application-shell.d.ts +7 -15
  25. package/dist/declarations/src/components/application-shell-authenticated/application-shell-authenticated.d.ts +21 -0
  26. package/dist/declarations/src/components/application-shell-provider/application-shell-provider.d.ts +6 -7
  27. package/dist/declarations/src/components/application-shell-provider/use-coerced-environment-values.d.ts +1 -23
  28. package/dist/declarations/src/components/authenticated/authenticated.d.ts +2 -2
  29. package/dist/declarations/src/components/authenticated/oidc-callback.async.d.ts +6 -0
  30. package/dist/declarations/src/components/authenticated/oidc-callback.d.ts +2 -2
  31. package/dist/declarations/src/components/configure-intl-provider/configure-intl-provider.d.ts +1 -1
  32. package/dist/declarations/src/components/error-apologizer/index.d.ts +6 -1
  33. package/dist/declarations/src/components/fetch-project/fetch-project.d.ts +4 -4
  34. package/dist/declarations/src/components/fetch-user/fetch-user.d.ts +3 -3
  35. package/dist/declarations/src/components/inject-reducers/inject-reducers.d.ts +1 -1
  36. package/dist/declarations/src/components/navbar/index.d.ts +100 -1
  37. package/dist/declarations/src/components/navbar/loading-navbar.d.ts +5 -0
  38. package/dist/declarations/src/components/navbar/menu-items.d.ts +99 -0
  39. package/dist/declarations/src/components/navbar/navbar.d.ts +6 -15
  40. package/dist/declarations/src/components/project-container/index.d.ts +78 -1
  41. package/dist/declarations/src/components/project-container/project-container.d.ts +6 -8
  42. package/dist/declarations/src/components/quick-access/butler-command/butler-command.d.ts +1 -1
  43. package/dist/declarations/src/components/quick-access/index.d.ts +2 -2
  44. package/dist/declarations/src/components/quick-access/types.d.ts +1 -1
  45. package/dist/declarations/src/components/redirect-to-login/index.d.ts +6 -0
  46. package/dist/declarations/src/components/redirect-to-logout/index.d.ts +5 -0
  47. package/dist/declarations/src/components/redirect-to-project-create/index.d.ts +6 -1
  48. package/dist/declarations/src/components/requests-in-flight-loader/index.d.ts +6 -1
  49. package/dist/declarations/src/components/route-catch-all/index.d.ts +3 -1
  50. package/dist/declarations/src/components/setup-flop-flip-provider/setup-flop-flip-provider.d.ts +3 -3
  51. package/dist/declarations/src/components/suspended-route/suspended-route.d.ts +1 -1
  52. package/dist/declarations/src/components/user-settings-menu/index.d.ts +12 -1
  53. package/dist/declarations/src/components/version-tracker/index.d.ts +6 -1
  54. package/dist/declarations/src/hooks/apollo-hooks/apollo-hooks.d.ts +1 -1
  55. package/dist/declarations/src/test-utils/test-utils.d.ts +2 -2
  56. package/dist/declarations/src/types/generated/mc.d.ts +3 -3
  57. package/dist/declarations/src/utils/get-mc-origin/get-mc-origin.d.ts +2 -0
  58. package/dist/declarations/src/utils/get-mc-origin/index.d.ts +1 -0
  59. package/dist/error-apologizer-c336db61.cjs.dev.js +56 -0
  60. package/dist/error-apologizer-c55ec6f7.cjs.prod.js +56 -0
  61. package/dist/error-apologizer-f8772b68.esm.js +42 -0
  62. package/dist/gear-2890f7fb.cjs.prod.js +32 -0
  63. package/dist/{gear-8418cd46.esm.js → gear-300dd24c.esm.js} +1 -3
  64. package/dist/gear-e8014c5a.cjs.dev.js +32 -0
  65. package/dist/get-mc-origin-314b77a2.cjs.dev.js +57 -0
  66. package/dist/get-mc-origin-5df60933.esm.js +50 -0
  67. package/dist/get-mc-origin-7968e04f.cjs.prod.js +57 -0
  68. package/dist/heart-000a023d.cjs.prod.js +32 -0
  69. package/dist/{heart-48c28091.esm.js → heart-dded66b4.esm.js} +1 -3
  70. package/dist/heart-f21b7d39.cjs.dev.js +32 -0
  71. package/dist/index-5048bf47.cjs.dev.js +3054 -0
  72. package/dist/index-b002eca6.esm.js +2970 -0
  73. package/dist/index-e0ab178f.cjs.prod.js +2870 -0
  74. package/dist/{list-with-search-c154a56e.esm.js → list-with-search-a3302710.esm.js} +1 -3
  75. package/dist/list-with-search-a5b72b33.cjs.prod.js +32 -0
  76. package/dist/list-with-search-ee796e9e.cjs.dev.js +32 -0
  77. package/dist/navbar-40650ed4.cjs.dev.js +670 -0
  78. package/dist/navbar-997b4a36.cjs.prod.js +649 -0
  79. package/dist/navbar-f4b482d0.esm.js +650 -0
  80. package/dist/oidc-0638d0c8.cjs.dev.js +67 -0
  81. package/dist/oidc-10fa96f0.esm.js +59 -0
  82. package/dist/oidc-540a091a.cjs.prod.js +67 -0
  83. package/dist/oidc-callback-1047744c.cjs.dev.js +254 -0
  84. package/dist/oidc-callback-b32405ab.cjs.prod.js +251 -0
  85. package/dist/oidc-callback-e2ca889b.esm.js +240 -0
  86. package/dist/paperclip-23d1e69c.cjs.prod.js +32 -0
  87. package/dist/{paperclip-18785dda.esm.js → paperclip-a61112e8.esm.js} +1 -3
  88. package/dist/paperclip-d653c134.cjs.dev.js +32 -0
  89. package/dist/plugin-0ee6aee4.cjs.dev.js +32 -0
  90. package/dist/{plugin-53c047bb.esm.js → plugin-3d353a5b.esm.js} +1 -3
  91. package/dist/plugin-7e57f237.cjs.prod.js +32 -0
  92. package/dist/project-container-05a4e261.esm.js +368 -0
  93. package/dist/project-container-1cf9964e.cjs.dev.js +387 -0
  94. package/dist/project-container-65fccf05.cjs.prod.js +369 -0
  95. package/dist/{project-expired-d8eaa253.esm.js → project-expired-0d18d9ef.esm.js} +47 -68
  96. package/dist/{project-expired-adce523b.cjs.dev.js → project-expired-b8480245.cjs.dev.js} +47 -68
  97. package/dist/{project-expired-576a8329.cjs.prod.js → project-expired-e757e66c.cjs.prod.js} +47 -68
  98. package/dist/{project-not-found-9a9753f2.cjs.dev.js → project-not-found-1b4527b4.cjs.dev.js} +42 -61
  99. package/dist/{project-not-found-8208c8f1.esm.js → project-not-found-4bc57bab.esm.js} +42 -61
  100. package/dist/{project-not-found-daa5200b.cjs.prod.js → project-not-found-6808c525.cjs.prod.js} +42 -61
  101. package/dist/{project-not-initialized-4aeafe19.cjs.dev.js → project-not-initialized-3351f8b7.cjs.prod.js} +47 -68
  102. package/dist/{project-not-initialized-3408e87f.esm.js → project-not-initialized-5eef98f9.esm.js} +47 -68
  103. package/dist/{project-not-initialized-5b416bcf.cjs.prod.js → project-not-initialized-d13a6be3.cjs.dev.js} +47 -68
  104. package/dist/{project-suspended-d3a6001d.cjs.dev.js → project-suspended-4ed362c3.cjs.prod.js} +44 -63
  105. package/dist/{project-suspended-a7edc962.esm.js → project-suspended-7843e028.esm.js} +44 -63
  106. package/dist/{project-suspended-dc9ace34.cjs.prod.js → project-suspended-c5b996b0.cjs.dev.js} +44 -63
  107. package/dist/quick-access-3acb2b6a.cjs.dev.js +1937 -0
  108. package/dist/{quick-access-f42a8e0a.cjs.prod.js → quick-access-5c5074c7.cjs.prod.js} +573 -957
  109. package/dist/quick-access-fdb9024d.esm.js +1907 -0
  110. package/dist/redirect-to-login-5ac864e2.cjs.prod.js +149 -0
  111. package/dist/redirect-to-login-80d7ff2f.cjs.dev.js +149 -0
  112. package/dist/redirect-to-login-824d52b9.esm.js +147 -0
  113. package/dist/redirect-to-logout-6df9b79c.esm.js +138 -0
  114. package/dist/redirect-to-logout-7d5c817e.cjs.prod.js +151 -0
  115. package/dist/redirect-to-logout-a78f7193.cjs.dev.js +151 -0
  116. package/dist/redirect-to-project-create-048efa71.cjs.prod.js +61 -0
  117. package/dist/redirect-to-project-create-052f293e.esm.js +52 -0
  118. package/dist/redirect-to-project-create-f0e7b35e.cjs.dev.js +61 -0
  119. package/dist/{gear-28ff4f04.cjs.dev.js → redirector-0d98f9df.cjs.dev.js} +44 -5
  120. package/dist/redirector-47a6be71.esm.js +58 -0
  121. package/dist/{gear-6f8c30e3.cjs.prod.js → redirector-77ce2f5c.cjs.prod.js} +44 -5
  122. package/dist/requests-in-flight-loader-3bc8dd8a.cjs.dev.js +144 -0
  123. package/dist/requests-in-flight-loader-c3e4205b.cjs.prod.js +144 -0
  124. package/dist/requests-in-flight-loader-fe4c165f.esm.js +129 -0
  125. package/dist/rocket-3e3f0a98.cjs.prod.js +32 -0
  126. package/dist/{rocket-ba116b5e.esm.js → rocket-4b088727.esm.js} +1 -3
  127. package/dist/rocket-95b6858d.cjs.dev.js +32 -0
  128. package/dist/route-catch-all-01cf0095.esm.js +41 -0
  129. package/dist/route-catch-all-3b490df1.cjs.prod.js +43 -0
  130. package/dist/route-catch-all-9ac99936.cjs.dev.js +43 -0
  131. package/dist/{service-page-project-switcher-49afafeb.cjs.prod.js → service-page-project-switcher-6865e150.cjs.prod.js} +5 -7
  132. package/dist/{service-page-project-switcher-866b2139.cjs.dev.js → service-page-project-switcher-e8a7e5d7.cjs.dev.js} +6 -8
  133. package/dist/{service-page-project-switcher-365c4c10.esm.js → service-page-project-switcher-fcc8d186.esm.js} +6 -8
  134. package/dist/{speedometer-c1b94505.esm.js → speedometer-08a11d5a.esm.js} +1 -3
  135. package/dist/speedometer-2881cef6.cjs.prod.js +32 -0
  136. package/dist/speedometer-54f872f2.cjs.dev.js +32 -0
  137. package/dist/{star-da9123e0.esm.js → star-15244db1.esm.js} +1 -3
  138. package/dist/star-52bf7a64.cjs.dev.js +32 -0
  139. package/dist/star-f8502efb.cjs.prod.js +32 -0
  140. package/dist/tag-multi-1d1553b6.cjs.dev.js +32 -0
  141. package/dist/{tag-multi-c650b738.esm.js → tag-multi-3be995ac.esm.js} +1 -3
  142. package/dist/tag-multi-f9acb1c2.cjs.prod.js +32 -0
  143. package/dist/tree-structure-4650688d.cjs.dev.js +32 -0
  144. package/dist/{tree-structure-6af6fc3a.esm.js → tree-structure-c8753526.esm.js} +1 -3
  145. package/dist/tree-structure-f24ee3f6.cjs.prod.js +32 -0
  146. package/dist/use-applications-menu-1925f36a.esm.js +172 -0
  147. package/dist/use-applications-menu-7e438b2a.cjs.prod.js +188 -0
  148. package/dist/use-applications-menu-f6f68bf7.cjs.dev.js +188 -0
  149. package/dist/use-is-served-by-proxy-2b4916e5.cjs.dev.js +42 -0
  150. package/dist/use-is-served-by-proxy-499bfa16.esm.js +39 -0
  151. package/dist/use-is-served-by-proxy-51e76976.cjs.prod.js +42 -0
  152. package/dist/{user-filled-41729d77.esm.js → user-filled-2dc4e79e.esm.js} +1 -3
  153. package/dist/user-filled-2e6cb25e.cjs.dev.js +32 -0
  154. package/dist/user-filled-815b49a0.cjs.prod.js +32 -0
  155. package/dist/user-settings-menu-96de467a.cjs.prod.js +496 -0
  156. package/dist/user-settings-menu-d831de89.esm.js +497 -0
  157. package/dist/user-settings-menu-e38c73ac.cjs.dev.js +523 -0
  158. package/dist/version-tracker-51646901.cjs.prod.js +107 -0
  159. package/dist/version-tracker-57ea3aa1.cjs.dev.js +107 -0
  160. package/dist/version-tracker-afb522da.esm.js +101 -0
  161. package/dist/world-973090a5.cjs.dev.js +32 -0
  162. package/dist/{world-d91df1ee.esm.js → world-c5ea311a.esm.js} +1 -3
  163. package/dist/world-e1f9dbf8.cjs.prod.js +32 -0
  164. package/package.json +27 -27
  165. package/ssr/dist/commercetools-frontend-application-shell-ssr.cjs.dev.js +2 -3
  166. package/ssr/dist/commercetools-frontend-application-shell-ssr.cjs.prod.js +2 -3
  167. package/ssr/dist/commercetools-frontend-application-shell-ssr.esm.js +2 -3
  168. package/test-utils/dist/commercetools-frontend-application-shell-test-utils.cjs.dev.js +182 -215
  169. package/test-utils/dist/commercetools-frontend-application-shell-test-utils.cjs.prod.js +182 -215
  170. package/test-utils/dist/commercetools-frontend-application-shell-test-utils.esm.js +173 -206
  171. package/dist/application-entry-point-307baa50.cjs.prod.js +0 -1225
  172. package/dist/application-entry-point-3e14d46d.cjs.dev.js +0 -1250
  173. package/dist/application-entry-point-8d923438.esm.js +0 -1180
  174. package/dist/connected-square-abf36852.cjs.prod.js +0 -34
  175. package/dist/connected-square-ac52014f.cjs.dev.js +0 -34
  176. package/dist/declarations/src/components/application-shell/helpers.d.ts +0 -1
  177. package/dist/heart-33cd94c6.cjs.prod.js +0 -34
  178. package/dist/heart-fb31cf30.cjs.dev.js +0 -34
  179. package/dist/index-284fb405.esm.js +0 -4809
  180. package/dist/index-37414a3f.cjs.prod.js +0 -4643
  181. package/dist/index-ea32a85e.cjs.dev.js +0 -4888
  182. package/dist/list-with-search-34cd926c.cjs.dev.js +0 -34
  183. package/dist/list-with-search-a0b22169.cjs.prod.js +0 -34
  184. package/dist/oidc-1c91f5ee.cjs.prod.js +0 -67
  185. package/dist/oidc-5b2e4f8f.cjs.dev.js +0 -67
  186. package/dist/oidc-77749f1b.esm.js +0 -59
  187. package/dist/paperclip-2cd45b86.cjs.dev.js +0 -34
  188. package/dist/paperclip-b1b806ab.cjs.prod.js +0 -34
  189. package/dist/plugin-7cb7827e.cjs.dev.js +0 -34
  190. package/dist/plugin-e97ae3e6.cjs.prod.js +0 -34
  191. package/dist/quick-access-457a9f41.esm.js +0 -2290
  192. package/dist/quick-access-d553524e.cjs.dev.js +0 -2321
  193. package/dist/rocket-37c1aa11.cjs.dev.js +0 -34
  194. package/dist/rocket-b2dbda7f.cjs.prod.js +0 -34
  195. package/dist/speedometer-13b393fb.cjs.dev.js +0 -34
  196. package/dist/speedometer-1e69fd13.cjs.prod.js +0 -34
  197. package/dist/star-ab4be629.cjs.prod.js +0 -34
  198. package/dist/star-e165111e.cjs.dev.js +0 -34
  199. package/dist/tag-multi-5f498a7d.cjs.dev.js +0 -34
  200. package/dist/tag-multi-fb817131.cjs.prod.js +0 -34
  201. package/dist/tree-structure-779fcc36.cjs.prod.js +0 -34
  202. package/dist/tree-structure-ed6cdff8.cjs.dev.js +0 -34
  203. package/dist/user-filled-384a2eaf.cjs.prod.js +0 -34
  204. package/dist/user-filled-53d2eae0.cjs.dev.js +0 -34
  205. package/dist/world-12528632.cjs.prod.js +0 -34
  206. package/dist/world-6471d9f6.cjs.dev.js +0 -34
  207. /package/dist/declarations/src/components/{application-shell → redirect-to-login}/redirect-to-login.d.ts +0 -0
  208. /package/dist/declarations/src/components/{application-shell → redirect-to-logout}/redirect-to-logout.d.ts +0 -0
@@ -0,0 +1,172 @@
1
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
2
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
3
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
5
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
6
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
7
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
8
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
9
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
10
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
11
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
12
+ import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
13
+ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
14
+ import { useState, useEffect } from 'react';
15
+ import { useApolloClient } from '@apollo/client';
16
+ import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
17
+ import { u as useMcQuery } from './index-b002eca6.esm.js';
18
+
19
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
+
21
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
22
+ var FetchApplicationsMenu = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchApplicationsMenu" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "applicationsMenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "navBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "submenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "appBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 823, source: { body: "query FetchApplicationsMenu {\n applicationsMenu {\n navBar {\n key\n uriPath\n icon\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n dataFences {\n group\n name\n type\n }\n actionRights {\n group\n name\n }\n submenu {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n actionRights {\n group\n name\n }\n dataFences {\n group\n name\n type\n }\n }\n }\n appBar {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n permissions\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
23
+ const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'];
24
+ const defaultApiUrl = window.location.origin;
25
+
26
+ const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
27
+ let mappedLabelAllLocales = labelAllLocales;
28
+
29
+ if (defaultLabel) {
30
+ // Map all supported locales with the given localized labels.
31
+ // If a locale is not defined in the config, we use the `default` label as the value.
32
+ // This is only needed for development as we're trying to map two different schemas.
33
+ mappedLabelAllLocales = _mapInstanceProperty(supportedLocales).call(supportedLocales, supportedLocale => {
34
+ const existingField = _findInstanceProperty(labelAllLocales).call(labelAllLocales, field => field.locale === supportedLocale);
35
+
36
+ if (existingField) return existingField;
37
+ return {
38
+ locale: supportedLocale,
39
+ value: defaultLabel
40
+ };
41
+ });
42
+ } // Add the `__typename`.
43
+
44
+
45
+ return _mapInstanceProperty(mappedLabelAllLocales).call(mappedLabelAllLocales, field => _objectSpread({
46
+ __typename: 'LocalizedField'
47
+ }, field));
48
+ };
49
+ /**
50
+ * Transform menu links defined in the `custom-application-config.json` to the `FetchApplicationsMenu` schema.
51
+ * This is only needed for development.
52
+ */
53
+
54
+
55
+ const mapApplicationMenuConfigToGraqhQLQueryResult = applicationConfig => {
56
+ var _applicationConfig$__, _ref, _applicationConfig$__2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context;
57
+
58
+ const entryPointUriPath = applicationConfig.entryPointUriPath;
59
+ const menuLinks = (_applicationConfig$__ = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__ === void 0 ? void 0 : _applicationConfig$__.menuLinks; // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
60
+
61
+ const accountLinks = (_ref = (_applicationConfig$__2 = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__2 === void 0 ? void 0 : _applicationConfig$__2.accountLinks) !== null && _ref !== void 0 ? _ref : [];
62
+ return {
63
+ applicationsMenu: {
64
+ __typename: 'ApplicationsMenu',
65
+ navBar: menuLinks ? [{
66
+ __typename: 'NavbarMenu',
67
+ key: entryPointUriPath,
68
+ uriPath: entryPointUriPath,
69
+ icon: menuLinks.icon,
70
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks.labelAllLocales, menuLinks.defaultLabel),
71
+ permissions: menuLinks.permissions,
72
+ // @ts-ignore: not defined in schema, as it's only used internally.
73
+ featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
74
+ // @ts-ignore: not defined in schema, as it's only used internally.
75
+ menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
76
+ // @ts-ignore: not defined in schema, as it's only used internally.
77
+ actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
78
+ // @ts-ignore: not defined in schema, as it's only used internally.
79
+ dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
80
+ submenu: _mapInstanceProperty(_context = menuLinks.submenuLinks).call(_context, submenuLink => {
81
+ var _context2, _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
82
+
83
+ return {
84
+ __typename: 'BaseMenu',
85
+ key: _concatInstanceProperty(_context2 = "".concat(entryPointUriPath, "-")).call(_context2, submenuLink.uriPath),
86
+ uriPath: submenuLink.uriPath,
87
+ labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
88
+ permissions: submenuLink.permissions,
89
+ // @ts-ignore: not defined in schema, as it's only used internally.
90
+ featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
91
+ // @ts-ignore: not defined in schema, as it's only used internally.
92
+ menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
93
+ // @ts-ignore: not defined in schema, as it's only used internally.
94
+ actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
95
+ // @ts-ignore: not defined in schema, as it's only used internally.
96
+ dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
97
+ };
98
+ })
99
+ }] : [],
100
+ appBar: _mapInstanceProperty(accountLinks).call(accountLinks, menuLink => {
101
+ var _menuLink$featureTogg;
102
+
103
+ return {
104
+ __typename: 'BaseMenu',
105
+ key: menuLink.uriPath,
106
+ uriPath: menuLink.uriPath,
107
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
108
+ permissions: menuLink.permissions,
109
+ // @ts-ignore: not defined in schema, as it's only used internally.
110
+ featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
111
+ };
112
+ })
113
+ }
114
+ };
115
+ };
116
+
117
+ function useApplicationsMenu(menuKey, config) {
118
+ var _config$queryOptions;
119
+
120
+ const apolloClient = useApolloClient();
121
+ const mcProxyApiUrl = useApplicationContext(context => context.environment.mcProxyApiUrl);
122
+
123
+ const _useState = useState(false),
124
+ _useState2 = _slicedToArray(_useState, 2),
125
+ hasWrittenToCache = _useState2[0],
126
+ setHasWrittenToCache = _useState2[1]; // Fetch all menu links from the GraphQL API in the Merchant Center Proxy.
127
+ // For local development, we don't fetch data from the remote server but use
128
+ // only the configuration for the menu links defined for the application.
129
+ // To do so, we manually write the data in the Apollo cache and use the
130
+ // `fetchPolicy: cache-only` to instruct Apollo to read the data from the cache.
131
+ // NOTE: In development, we skip the query as long as the data hasn't been written
132
+ // into the cache. If not, Apollo throws an error like
133
+ // `Can't find field 'applicationMenu' on ROOT_QUERY object`.
134
+
135
+
136
+ const _useMcQuery = useMcQuery(FetchApplicationsMenu, {
137
+ skip: config.environment.servedByProxy ? // Production environment
138
+ false : // Development environment
139
+ !hasWrittenToCache,
140
+ onError: (_config$queryOptions = config.queryOptions) === null || _config$queryOptions === void 0 ? void 0 : _config$queryOptions.onError,
141
+ fetchPolicy: config.environment.servedByProxy ? 'cache-first' : 'cache-only',
142
+ context: {
143
+ // Allow to overwrite the API url from application config
144
+ uri: "".concat(mcProxyApiUrl || defaultApiUrl, "/api/graphql"),
145
+ skipGraphQlTargetCheck: true
146
+ }
147
+ }),
148
+ menuQueryResult = _useMcQuery.data; // For development, we read the menu data from the configuration file and
149
+ // write it into the Apollo cache.
150
+
151
+
152
+ useEffect(() => {
153
+ if (config.environment.__DEVELOPMENT__ && (config.environment.__DEVELOPMENT__.menuLinks || // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
154
+ config.environment.__DEVELOPMENT__.accountLinks) && !hasWrittenToCache) {
155
+ const applicationMenu = mapApplicationMenuConfigToGraqhQLQueryResult(config.environment);
156
+ apolloClient.writeQuery({
157
+ query: FetchApplicationsMenu,
158
+ data: applicationMenu
159
+ });
160
+ setHasWrittenToCache(true);
161
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
162
+
163
+ }, [hasWrittenToCache]); // Only subscribe to state changes.
164
+
165
+ if (menuQueryResult && menuQueryResult.applicationsMenu) {
166
+ return menuQueryResult.applicationsMenu[menuKey];
167
+ }
168
+
169
+ return;
170
+ }
171
+
172
+ export { useApplicationsMenu as u };
@@ -0,0 +1,188 @@
1
+ 'use strict';
2
+
3
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
4
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
5
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
7
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
8
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
9
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
10
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
11
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
12
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
13
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
14
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
15
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
16
+ var react = require('react');
17
+ var client = require('@apollo/client');
18
+ var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
19
+ var dist_commercetoolsFrontendApplicationShell = require('./index-e0ab178f.cjs.prod.js');
20
+
21
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
22
+
23
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
24
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
25
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
26
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
27
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
28
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
29
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
30
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
31
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
32
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
33
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
34
+
35
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
36
+
37
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
38
+ var FetchApplicationsMenu = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchApplicationsMenu" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "applicationsMenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "navBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "submenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "appBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 823, source: { body: "query FetchApplicationsMenu {\n applicationsMenu {\n navBar {\n key\n uriPath\n icon\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n dataFences {\n group\n name\n type\n }\n actionRights {\n group\n name\n }\n submenu {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n actionRights {\n group\n name\n }\n dataFences {\n group\n name\n type\n }\n }\n }\n appBar {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n permissions\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
39
+ const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'];
40
+ const defaultApiUrl = window.location.origin;
41
+
42
+ const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
43
+ let mappedLabelAllLocales = labelAllLocales;
44
+
45
+ if (defaultLabel) {
46
+ // Map all supported locales with the given localized labels.
47
+ // If a locale is not defined in the config, we use the `default` label as the value.
48
+ // This is only needed for development as we're trying to map two different schemas.
49
+ mappedLabelAllLocales = _mapInstanceProperty__default["default"](supportedLocales).call(supportedLocales, supportedLocale => {
50
+ const existingField = _findInstanceProperty__default["default"](labelAllLocales).call(labelAllLocales, field => field.locale === supportedLocale);
51
+
52
+ if (existingField) return existingField;
53
+ return {
54
+ locale: supportedLocale,
55
+ value: defaultLabel
56
+ };
57
+ });
58
+ } // Add the `__typename`.
59
+
60
+
61
+ return _mapInstanceProperty__default["default"](mappedLabelAllLocales).call(mappedLabelAllLocales, field => _objectSpread({
62
+ __typename: 'LocalizedField'
63
+ }, field));
64
+ };
65
+ /**
66
+ * Transform menu links defined in the `custom-application-config.json` to the `FetchApplicationsMenu` schema.
67
+ * This is only needed for development.
68
+ */
69
+
70
+
71
+ const mapApplicationMenuConfigToGraqhQLQueryResult = applicationConfig => {
72
+ var _applicationConfig$__, _ref, _applicationConfig$__2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context;
73
+
74
+ const entryPointUriPath = applicationConfig.entryPointUriPath;
75
+ const menuLinks = (_applicationConfig$__ = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__ === void 0 ? void 0 : _applicationConfig$__.menuLinks; // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
76
+
77
+ const accountLinks = (_ref = (_applicationConfig$__2 = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__2 === void 0 ? void 0 : _applicationConfig$__2.accountLinks) !== null && _ref !== void 0 ? _ref : [];
78
+ return {
79
+ applicationsMenu: {
80
+ __typename: 'ApplicationsMenu',
81
+ navBar: menuLinks ? [{
82
+ __typename: 'NavbarMenu',
83
+ key: entryPointUriPath,
84
+ uriPath: entryPointUriPath,
85
+ icon: menuLinks.icon,
86
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks.labelAllLocales, menuLinks.defaultLabel),
87
+ permissions: menuLinks.permissions,
88
+ // @ts-ignore: not defined in schema, as it's only used internally.
89
+ featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
90
+ // @ts-ignore: not defined in schema, as it's only used internally.
91
+ menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
92
+ // @ts-ignore: not defined in schema, as it's only used internally.
93
+ actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
94
+ // @ts-ignore: not defined in schema, as it's only used internally.
95
+ dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
96
+ submenu: _mapInstanceProperty__default["default"](_context = menuLinks.submenuLinks).call(_context, submenuLink => {
97
+ var _context2, _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
98
+
99
+ return {
100
+ __typename: 'BaseMenu',
101
+ key: _concatInstanceProperty__default["default"](_context2 = "".concat(entryPointUriPath, "-")).call(_context2, submenuLink.uriPath),
102
+ uriPath: submenuLink.uriPath,
103
+ labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
104
+ permissions: submenuLink.permissions,
105
+ // @ts-ignore: not defined in schema, as it's only used internally.
106
+ featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
107
+ // @ts-ignore: not defined in schema, as it's only used internally.
108
+ menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
109
+ // @ts-ignore: not defined in schema, as it's only used internally.
110
+ actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
111
+ // @ts-ignore: not defined in schema, as it's only used internally.
112
+ dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
113
+ };
114
+ })
115
+ }] : [],
116
+ appBar: _mapInstanceProperty__default["default"](accountLinks).call(accountLinks, menuLink => {
117
+ var _menuLink$featureTogg;
118
+
119
+ return {
120
+ __typename: 'BaseMenu',
121
+ key: menuLink.uriPath,
122
+ uriPath: menuLink.uriPath,
123
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
124
+ permissions: menuLink.permissions,
125
+ // @ts-ignore: not defined in schema, as it's only used internally.
126
+ featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
127
+ };
128
+ })
129
+ }
130
+ };
131
+ };
132
+
133
+ function useApplicationsMenu(menuKey, config) {
134
+ var _config$queryOptions;
135
+
136
+ const apolloClient = client.useApolloClient();
137
+ const mcProxyApiUrl = applicationShellConnectors.useApplicationContext(context => context.environment.mcProxyApiUrl);
138
+
139
+ const _useState = react.useState(false),
140
+ _useState2 = _slicedToArray(_useState, 2),
141
+ hasWrittenToCache = _useState2[0],
142
+ setHasWrittenToCache = _useState2[1]; // Fetch all menu links from the GraphQL API in the Merchant Center Proxy.
143
+ // For local development, we don't fetch data from the remote server but use
144
+ // only the configuration for the menu links defined for the application.
145
+ // To do so, we manually write the data in the Apollo cache and use the
146
+ // `fetchPolicy: cache-only` to instruct Apollo to read the data from the cache.
147
+ // NOTE: In development, we skip the query as long as the data hasn't been written
148
+ // into the cache. If not, Apollo throws an error like
149
+ // `Can't find field 'applicationMenu' on ROOT_QUERY object`.
150
+
151
+
152
+ const _useMcQuery = dist_commercetoolsFrontendApplicationShell.useMcQuery(FetchApplicationsMenu, {
153
+ skip: config.environment.servedByProxy ? // Production environment
154
+ false : // Development environment
155
+ !hasWrittenToCache,
156
+ onError: (_config$queryOptions = config.queryOptions) === null || _config$queryOptions === void 0 ? void 0 : _config$queryOptions.onError,
157
+ fetchPolicy: config.environment.servedByProxy ? 'cache-first' : 'cache-only',
158
+ context: {
159
+ // Allow to overwrite the API url from application config
160
+ uri: "".concat(mcProxyApiUrl || defaultApiUrl, "/api/graphql"),
161
+ skipGraphQlTargetCheck: true
162
+ }
163
+ }),
164
+ menuQueryResult = _useMcQuery.data; // For development, we read the menu data from the configuration file and
165
+ // write it into the Apollo cache.
166
+
167
+
168
+ react.useEffect(() => {
169
+ if (config.environment.__DEVELOPMENT__ && (config.environment.__DEVELOPMENT__.menuLinks || // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
170
+ config.environment.__DEVELOPMENT__.accountLinks) && !hasWrittenToCache) {
171
+ const applicationMenu = mapApplicationMenuConfigToGraqhQLQueryResult(config.environment);
172
+ apolloClient.writeQuery({
173
+ query: FetchApplicationsMenu,
174
+ data: applicationMenu
175
+ });
176
+ setHasWrittenToCache(true);
177
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
178
+
179
+ }, [hasWrittenToCache]); // Only subscribe to state changes.
180
+
181
+ if (menuQueryResult && menuQueryResult.applicationsMenu) {
182
+ return menuQueryResult.applicationsMenu[menuKey];
183
+ }
184
+
185
+ return;
186
+ }
187
+
188
+ exports.useApplicationsMenu = useApplicationsMenu;
@@ -0,0 +1,188 @@
1
+ 'use strict';
2
+
3
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
4
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
5
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
7
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
8
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
9
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
10
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
11
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
12
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
13
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
14
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
15
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
16
+ var react = require('react');
17
+ var client = require('@apollo/client');
18
+ var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
19
+ var dist_commercetoolsFrontendApplicationShell = require('./index-5048bf47.cjs.dev.js');
20
+
21
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
22
+
23
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
24
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
25
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
26
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
27
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
28
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
29
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
30
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
31
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
32
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
33
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
34
+
35
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
36
+
37
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
38
+ var FetchApplicationsMenu = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchApplicationsMenu" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "applicationsMenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "navBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "submenu" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "menuVisibility" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "actionRights" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "dataFences" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "group" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "appBar" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "key" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "featureToggle" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 823, source: { body: "query FetchApplicationsMenu {\n applicationsMenu {\n navBar {\n key\n uriPath\n icon\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n dataFences {\n group\n name\n type\n }\n actionRights {\n group\n name\n }\n submenu {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n menuVisibility\n permissions\n actionRights {\n group\n name\n }\n dataFences {\n group\n name\n type\n }\n }\n }\n appBar {\n key\n uriPath\n labelAllLocales {\n locale\n value\n }\n featureToggle\n permissions\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
39
+ const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'];
40
+ const defaultApiUrl = window.location.origin;
41
+
42
+ const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
43
+ let mappedLabelAllLocales = labelAllLocales;
44
+
45
+ if (defaultLabel) {
46
+ // Map all supported locales with the given localized labels.
47
+ // If a locale is not defined in the config, we use the `default` label as the value.
48
+ // This is only needed for development as we're trying to map two different schemas.
49
+ mappedLabelAllLocales = _mapInstanceProperty__default["default"](supportedLocales).call(supportedLocales, supportedLocale => {
50
+ const existingField = _findInstanceProperty__default["default"](labelAllLocales).call(labelAllLocales, field => field.locale === supportedLocale);
51
+
52
+ if (existingField) return existingField;
53
+ return {
54
+ locale: supportedLocale,
55
+ value: defaultLabel
56
+ };
57
+ });
58
+ } // Add the `__typename`.
59
+
60
+
61
+ return _mapInstanceProperty__default["default"](mappedLabelAllLocales).call(mappedLabelAllLocales, field => _objectSpread({
62
+ __typename: 'LocalizedField'
63
+ }, field));
64
+ };
65
+ /**
66
+ * Transform menu links defined in the `custom-application-config.json` to the `FetchApplicationsMenu` schema.
67
+ * This is only needed for development.
68
+ */
69
+
70
+
71
+ const mapApplicationMenuConfigToGraqhQLQueryResult = applicationConfig => {
72
+ var _applicationConfig$__, _ref, _applicationConfig$__2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context;
73
+
74
+ const entryPointUriPath = applicationConfig.entryPointUriPath;
75
+ const menuLinks = (_applicationConfig$__ = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__ === void 0 ? void 0 : _applicationConfig$__.menuLinks; // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
76
+
77
+ const accountLinks = (_ref = (_applicationConfig$__2 = applicationConfig.__DEVELOPMENT__) === null || _applicationConfig$__2 === void 0 ? void 0 : _applicationConfig$__2.accountLinks) !== null && _ref !== void 0 ? _ref : [];
78
+ return {
79
+ applicationsMenu: {
80
+ __typename: 'ApplicationsMenu',
81
+ navBar: menuLinks ? [{
82
+ __typename: 'NavbarMenu',
83
+ key: entryPointUriPath,
84
+ uriPath: entryPointUriPath,
85
+ icon: menuLinks.icon,
86
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks.labelAllLocales, menuLinks.defaultLabel),
87
+ permissions: menuLinks.permissions,
88
+ // @ts-ignore: not defined in schema, as it's only used internally.
89
+ featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
90
+ // @ts-ignore: not defined in schema, as it's only used internally.
91
+ menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
92
+ // @ts-ignore: not defined in schema, as it's only used internally.
93
+ actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
94
+ // @ts-ignore: not defined in schema, as it's only used internally.
95
+ dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
96
+ submenu: _mapInstanceProperty__default["default"](_context = menuLinks.submenuLinks).call(_context, submenuLink => {
97
+ var _context2, _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
98
+
99
+ return {
100
+ __typename: 'BaseMenu',
101
+ key: _concatInstanceProperty__default["default"](_context2 = "".concat(entryPointUriPath, "-")).call(_context2, submenuLink.uriPath),
102
+ uriPath: submenuLink.uriPath,
103
+ labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
104
+ permissions: submenuLink.permissions,
105
+ // @ts-ignore: not defined in schema, as it's only used internally.
106
+ featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
107
+ // @ts-ignore: not defined in schema, as it's only used internally.
108
+ menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
109
+ // @ts-ignore: not defined in schema, as it's only used internally.
110
+ actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
111
+ // @ts-ignore: not defined in schema, as it's only used internally.
112
+ dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
113
+ };
114
+ })
115
+ }] : [],
116
+ appBar: _mapInstanceProperty__default["default"](accountLinks).call(accountLinks, menuLink => {
117
+ var _menuLink$featureTogg;
118
+
119
+ return {
120
+ __typename: 'BaseMenu',
121
+ key: menuLink.uriPath,
122
+ uriPath: menuLink.uriPath,
123
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
124
+ permissions: menuLink.permissions,
125
+ // @ts-ignore: not defined in schema, as it's only used internally.
126
+ featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
127
+ };
128
+ })
129
+ }
130
+ };
131
+ };
132
+
133
+ function useApplicationsMenu(menuKey, config) {
134
+ var _config$queryOptions;
135
+
136
+ const apolloClient = client.useApolloClient();
137
+ const mcProxyApiUrl = applicationShellConnectors.useApplicationContext(context => context.environment.mcProxyApiUrl);
138
+
139
+ const _useState = react.useState(false),
140
+ _useState2 = _slicedToArray(_useState, 2),
141
+ hasWrittenToCache = _useState2[0],
142
+ setHasWrittenToCache = _useState2[1]; // Fetch all menu links from the GraphQL API in the Merchant Center Proxy.
143
+ // For local development, we don't fetch data from the remote server but use
144
+ // only the configuration for the menu links defined for the application.
145
+ // To do so, we manually write the data in the Apollo cache and use the
146
+ // `fetchPolicy: cache-only` to instruct Apollo to read the data from the cache.
147
+ // NOTE: In development, we skip the query as long as the data hasn't been written
148
+ // into the cache. If not, Apollo throws an error like
149
+ // `Can't find field 'applicationMenu' on ROOT_QUERY object`.
150
+
151
+
152
+ const _useMcQuery = dist_commercetoolsFrontendApplicationShell.useMcQuery(FetchApplicationsMenu, {
153
+ skip: config.environment.servedByProxy ? // Production environment
154
+ false : // Development environment
155
+ !hasWrittenToCache,
156
+ onError: (_config$queryOptions = config.queryOptions) === null || _config$queryOptions === void 0 ? void 0 : _config$queryOptions.onError,
157
+ fetchPolicy: config.environment.servedByProxy ? 'cache-first' : 'cache-only',
158
+ context: {
159
+ // Allow to overwrite the API url from application config
160
+ uri: "".concat(mcProxyApiUrl || defaultApiUrl, "/api/graphql"),
161
+ skipGraphQlTargetCheck: true
162
+ }
163
+ }),
164
+ menuQueryResult = _useMcQuery.data; // For development, we read the menu data from the configuration file and
165
+ // write it into the Apollo cache.
166
+
167
+
168
+ react.useEffect(() => {
169
+ if (config.environment.__DEVELOPMENT__ && (config.environment.__DEVELOPMENT__.menuLinks || // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
170
+ config.environment.__DEVELOPMENT__.accountLinks) && !hasWrittenToCache) {
171
+ const applicationMenu = mapApplicationMenuConfigToGraqhQLQueryResult(config.environment);
172
+ apolloClient.writeQuery({
173
+ query: FetchApplicationsMenu,
174
+ data: applicationMenu
175
+ });
176
+ setHasWrittenToCache(true);
177
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
178
+
179
+ }, [hasWrittenToCache]); // Only subscribe to state changes.
180
+
181
+ if (menuQueryResult && menuQueryResult.applicationsMenu) {
182
+ return menuQueryResult.applicationsMenu[menuKey];
183
+ }
184
+
185
+ return;
186
+ }
187
+
188
+ exports.useApplicationsMenu = useApplicationsMenu;
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
4
+
5
+ /**
6
+ * NOTE
7
+ * This module wraps `replace` and `reload` from the window's location.
8
+ * This mainly helps in tests as we often expect that a reload or
9
+ * replace on the location happened.
10
+ * In previous code we could just overwrite the properties by:
11
+ * `window.location.replace = jest.fn()`
12
+ * This will fail in never versions of JSDOM (e.g. v16) as these
13
+ * properties are not writable anymore. JSDOM follows the browser standards
14
+ * which also state that these should not be writable.
15
+ * There are different options to solve this:
16
+ * 1. Extract those functions as a module an use `jest.mock` to mock them under test
17
+ * 2. Use `Object.defineProperty` to overwrite the property
18
+ * - The community opinion is that this is not preferred and does
19
+ * not work in all cases
20
+ * 3. Delete the property via `delete window.location` to re-create it after
21
+ * - This is quite repetiive and noisy in tests and can also remote
22
+ * other properties from under location
23
+ * Given option 2. and 3. being quite noisy on tests and against working with
24
+ * the stndards of the browser we will use 1. Here we only utilise the module
25
+ * mocking system of Jest and no other trickery.
26
+ * */
27
+ const replace = url => window.location.replace(url);
28
+
29
+ const reload = () => window.location.reload();
30
+
31
+ const location = {
32
+ replace,
33
+ reload
34
+ };
35
+
36
+ const useIsServedByProxy = () => {
37
+ const servedByProxy = applicationShellConnectors.useApplicationContext(context => context.environment.servedByProxy);
38
+ return servedByProxy;
39
+ };
40
+
41
+ exports.location = location;
42
+ exports.useIsServedByProxy = useIsServedByProxy;