@jetshop/core 5.13.0 → 5.13.10-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 (547) hide show
  1. package/ChannelHandler/CategoryPathnameRedirectQuery.gql +9 -9
  2. package/ChannelHandler/ChannelHandler.d.ts +50 -50
  3. package/ChannelHandler/ChannelHandler.js +108 -108
  4. package/ChannelHandler/PagePathnameRedirectQuery.gql +9 -9
  5. package/ChannelHandler/PreserveRedirectRouteQuery.gql +19 -19
  6. package/ChannelHandler/ProductPathnameRedirectQuery.gql +9 -9
  7. package/ChannelHandler/StartPagePathnameRedirectQuery.gql +9 -9
  8. package/ChannelHandler/channelUtils.d.ts +68 -68
  9. package/ChannelHandler/channelUtils.js +266 -266
  10. package/ChannelHandler/redirectUtils.d.ts +4 -4
  11. package/ChannelHandler/redirectUtils.js +49 -49
  12. package/ChannelHandler/redirectUtils.test.js +538 -538
  13. package/analytics/Analytics.d.ts +18 -18
  14. package/analytics/Analytics.js +56 -53
  15. package/analytics/Analytics.js.map +1 -1
  16. package/analytics/AnalyticsProvider.d.ts +42 -42
  17. package/analytics/AnalyticsProvider.js +177 -177
  18. package/analytics/deprecatedTracking.d.ts +17 -17
  19. package/analytics/deprecatedTracking.js +32 -32
  20. package/analytics/integrations/ga4.d.ts +23 -23
  21. package/analytics/integrations/ga4.js +145 -145
  22. package/analytics/integrations/gtag/gtag.d.ts +8 -8
  23. package/analytics/integrations/gtag/gtag.js +180 -180
  24. package/analytics/integrations/gtag/index.d.ts +1 -1
  25. package/analytics/integrations/gtag/index.js +1 -1
  26. package/analytics/integrations/gtm/index.d.ts +12 -12
  27. package/analytics/integrations/gtm/index.js +200 -200
  28. package/analytics/integrations/gtm/referrerModifier.d.ts +1 -1
  29. package/analytics/integrations/gtm/referrerModifier.js +61 -61
  30. package/analytics/integrations/releware/index.d.ts +3 -3
  31. package/analytics/integrations/releware/index.js +38 -38
  32. package/analytics/integrations/unslugify.d.ts +1 -1
  33. package/analytics/integrations/unslugify.js +17 -17
  34. package/analytics/trackerRegistry.d.ts +101 -101
  35. package/analytics/trackerRegistry.js +219 -220
  36. package/analytics/trackerRegistry.js.map +1 -1
  37. package/analytics/trackerRegistry.test.js +160 -160
  38. package/analytics/tracking.d.ts +14 -14
  39. package/analytics/tracking.js +71 -71
  40. package/analytics/utils/breadcrumbsWithoutProduct.d.ts +1 -1
  41. package/analytics/utils/breadcrumbsWithoutProduct.js +8 -8
  42. package/analytics/utils/script.d.ts +8 -8
  43. package/analytics/utils/script.js +39 -39
  44. package/analytics/webVitals.d.ts +5 -5
  45. package/analytics/webVitals.js +38 -38
  46. package/boot/AuthHandler.d.ts +14 -14
  47. package/boot/AuthHandler.js +38 -38
  48. package/boot/ChannelsQuery.gql +7 -7
  49. package/boot/PreviewHandler.d.ts +7 -7
  50. package/boot/PreviewHandler.js +13 -13
  51. package/boot/SharedTree.d.ts +25 -25
  52. package/boot/SharedTree.js +28 -28
  53. package/boot/addMissingConfig.d.ts +5 -5
  54. package/boot/addMissingConfig.js +33 -33
  55. package/boot/apollo.d.ts +21 -21
  56. package/boot/apollo.js +197 -197
  57. package/boot/client/entrypoint.d.ts +1 -1
  58. package/boot/client/entrypoint.js +4 -4
  59. package/boot/client/index.d.ts +1 -1
  60. package/boot/client/index.js +1 -1
  61. package/boot/client/startClient.d.ts +4 -4
  62. package/boot/client/startClient.js +142 -142
  63. package/boot/client-schema.gql +59 -59
  64. package/boot/server/IntervalQuery.d.ts +32 -32
  65. package/boot/server/IntervalQuery.js +94 -94
  66. package/boot/server/IntervalQuery.test.js +280 -280
  67. package/boot/server/PersistedApolloClient.d.ts +20 -20
  68. package/boot/server/PersistedApolloClient.js +39 -39
  69. package/boot/server/PersistedApolloClient.test.js +233 -233
  70. package/boot/server/asyncErrorHandler.d.ts +3 -3
  71. package/boot/server/asyncErrorHandler.js +4 -4
  72. package/boot/server/breakpointMiddleware.d.ts +3 -3
  73. package/boot/server/breakpointMiddleware.js +9 -9
  74. package/boot/server/createApolloServer.d.ts +28 -28
  75. package/boot/server/createApolloServer.js +143 -143
  76. package/boot/server/createApolloServer.test.js +114 -114
  77. package/boot/server/createDevServer.d.ts +14 -14
  78. package/boot/server/createDevServer.js +29 -29
  79. package/boot/server/createRenderer.d.ts +28 -28
  80. package/boot/server/createRenderer.js +235 -235
  81. package/boot/server/createServer.d.ts +14 -14
  82. package/boot/server/createServer.js +41 -41
  83. package/boot/server/entrypoint.d.ts +1 -1
  84. package/boot/server/entrypoint.js +35 -35
  85. package/boot/server/getPrefetchFiles.d.ts +10 -10
  86. package/boot/server/getPrefetchFiles.js +19 -19
  87. package/boot/server/getPreloadAssets.d.ts +10 -10
  88. package/boot/server/getPreloadAssets.js +17 -17
  89. package/boot/server/getPreloadAssets.test.js +133 -133
  90. package/boot/server/index.d.ts +9 -9
  91. package/boot/server/index.js +122 -122
  92. package/boot/server/listen.d.ts +13 -13
  93. package/boot/server/listen.js +16 -16
  94. package/boot/server/overwriteServerIntl.js +1 -1
  95. package/boot/server/persistedQueries/PersistedClient.d.ts +22 -22
  96. package/boot/server/persistedQueries/PersistedClient.js +57 -57
  97. package/boot/server/persistedQueries/__tests__/getPersistedQueriesForRequest.test.js +201 -201
  98. package/boot/server/persistedQueries/__tests__/mockQuery.gql +6 -6
  99. package/boot/server/persistedQueries/getPersistedQueriesForRequest.d.ts +3 -3
  100. package/boot/server/persistedQueries/getPersistedQueriesForRequest.js +26 -26
  101. package/boot/server/saleSource.test.js +39 -39
  102. package/boot/server/salesSource.d.ts +8 -8
  103. package/boot/server/salesSource.js +15 -15
  104. package/boot/utils/__tests__/uid.js +47 -47
  105. package/boot/utils/createIntOptions.d.ts +6 -6
  106. package/boot/utils/createIntOptions.js +18 -18
  107. package/boot/utils/queryLoggingMiddleware.d.ts +2 -2
  108. package/boot/utils/queryLoggingMiddleware.js +14 -14
  109. package/boot/utils/uid.d.ts +3 -3
  110. package/boot/utils/uid.js +19 -19
  111. package/cart/AddToCartFormik.d.ts +42 -42
  112. package/cart/AddToCartFormik.js +76 -76
  113. package/cart/useAddToCart.d.ts +88 -88
  114. package/cart/useAddToCart.js +117 -117
  115. package/ci/.gitlab-ci.yml +3 -3
  116. package/components/Auth/CustomerUpdateForm.d.ts +32 -32
  117. package/components/Auth/CustomerUpdateForm.js +121 -121
  118. package/components/Auth/ForgotPasswordProvider.d.ts +71 -71
  119. package/components/Auth/ForgotPasswordProvider.js +56 -56
  120. package/components/Auth/ResetPasswordProvider.d.ts +88 -88
  121. package/components/Auth/ResetPasswordProvider.js +77 -77
  122. package/components/Auth/SSN.d.ts +12 -12
  123. package/components/Auth/SSN.js +34 -34
  124. package/components/Auth/SSNLookupContainer.d.ts +15 -15
  125. package/components/Auth/SSNLookupContainer.js +19 -19
  126. package/components/Auth/SignupFormContainer.d.ts +19 -19
  127. package/components/Auth/SignupFormContainer.js +81 -81
  128. package/components/Auth/UpdatePasswordForm.d.ts +44 -44
  129. package/components/Auth/UpdatePasswordForm.js +97 -97
  130. package/components/Auth/formFieldsFromSettings.d.ts +65 -65
  131. package/components/Auth/formFieldsFromSettings.js +76 -76
  132. package/components/Auth/formatSignupInput.d.ts +8 -8
  133. package/components/Auth/formatSignupInput.js +42 -42
  134. package/components/Auth/signup-context.d.ts +36 -36
  135. package/components/Auth/signup-context.js +71 -71
  136. package/components/Auth/signup-field-translations.d.ts +3 -3
  137. package/components/Auth/signup-field-translations.js +43 -43
  138. package/components/Auth/signupSubmit.d.ts +6 -6
  139. package/components/Auth/signupSubmit.js +56 -56
  140. package/components/Auth/useAddressFields.d.ts +22 -22
  141. package/components/Auth/useAddressFields.js +32 -32
  142. package/components/Auth/useAddressFields.test.js +294 -294
  143. package/components/Auth/useCustomer.d.ts +70 -70
  144. package/components/Auth/useCustomer.js +167 -167
  145. package/components/Auth/useLoginFields.d.ts +20 -20
  146. package/components/Auth/useLoginFields.js +20 -20
  147. package/components/Auth/useSignupForm.d.ts +7 -7
  148. package/components/Auth/useSignupForm.js +14 -14
  149. package/components/AuthContext/AuthContext.d.ts +8 -8
  150. package/components/AuthContext/AuthContext.js +8 -8
  151. package/components/AuthContext/AuthProvider.d.ts +6 -6
  152. package/components/AuthContext/AuthProvider.js +84 -84
  153. package/components/AuthContext/AuthProvider.test.js +66 -66
  154. package/components/AuthContext/LogOut.d.ts +5 -5
  155. package/components/AuthContext/LogOut.js +14 -14
  156. package/components/AuthContext/googleUserIdQuery.gql +6 -6
  157. package/components/AuthContext/useAuth.d.ts +6 -6
  158. package/components/AuthContext/useAuth.js +20 -20
  159. package/components/BreakpointProvider.d.ts +21 -21
  160. package/components/BreakpointProvider.js +23 -23
  161. package/components/Cart/CartIdContext.d.ts +11 -11
  162. package/components/Cart/CartIdContext.js +60 -60
  163. package/components/Cart/CartIdContext.test.js +87 -87
  164. package/components/ChannelContext/ChannelContext.d.ts +20 -20
  165. package/components/ChannelContext/ChannelContext.js +3 -3
  166. package/components/ChannelContext/ChannelProvider.d.ts +10 -10
  167. package/components/ChannelContext/ChannelProvider.js +42 -42
  168. package/components/ChannelContext/ChannelProvider.test.js +112 -112
  169. package/components/ChannelContext/CountrySettingsQuery.gql +34 -34
  170. package/components/ChannelContext/index.d.ts +2 -2
  171. package/components/ChannelContext/index.js +2 -2
  172. package/components/ChannelContext/useCountrySettings.d.ts +8 -8
  173. package/components/ChannelContext/useCountrySettings.js +23 -23
  174. package/components/ConfigProvider.d.ts +108 -108
  175. package/components/ConfigProvider.js +19 -19
  176. package/components/DynamicRoute/ActiveFiltersQuery.gql +21 -21
  177. package/components/DynamicRoute/CategoryRoute.d.ts +13 -13
  178. package/components/DynamicRoute/CategoryRoute.js +55 -55
  179. package/components/DynamicRoute/ContentRoute.d.ts +14 -14
  180. package/components/DynamicRoute/ContentRoute.js +27 -27
  181. package/components/DynamicRoute/PreviewRoute.d.ts +17 -17
  182. package/components/DynamicRoute/PreviewRoute.js +57 -57
  183. package/components/DynamicRoute/ProductByArticlenumber.d.ts +5 -5
  184. package/components/DynamicRoute/ProductByArticlenumber.gql +16 -16
  185. package/components/DynamicRoute/ProductByArticlenumber.js +21 -21
  186. package/components/DynamicRoute/ProductRoute.d.ts +15 -15
  187. package/components/DynamicRoute/ProductRoute.js +57 -57
  188. package/components/DynamicRoute/RouteResolver.d.ts +22 -22
  189. package/components/DynamicRoute/RouteResolver.js +64 -64
  190. package/components/DynamicRoute/Status.d.ts +14 -14
  191. package/components/DynamicRoute/Status.js +19 -19
  192. package/components/DynamicRoute/index.d.ts +17 -17
  193. package/components/DynamicRoute/index.js +95 -95
  194. package/components/Filters/index.d.ts +1 -1
  195. package/components/Filters/index.js +1 -1
  196. package/components/Filters/toggleActiveListItem.gql +15 -15
  197. package/components/Filters/utils/replaceInSearch.d.ts +14 -14
  198. package/components/Filters/utils/replaceInSearch.js +22 -22
  199. package/components/Filters/utils/replaceInSearch.test.js +184 -184
  200. package/components/Filters/utils/updateHistory.d.ts +25 -25
  201. package/components/Filters/utils/updateHistory.js +29 -29
  202. package/components/Filters/utils/updateHistory.test.js +102 -102
  203. package/components/Fonts/CustomFont.d.ts +14 -14
  204. package/components/Fonts/CustomFont.js +16 -16
  205. package/components/Fonts/GoogleFont.d.ts +10 -10
  206. package/components/Fonts/GoogleFont.js +34 -34
  207. package/components/Fonts/TypekitFont.d.ts +16 -16
  208. package/components/Fonts/TypekitFont.js +24 -24
  209. package/components/Fonts/injectFont.d.ts +11 -11
  210. package/components/Fonts/injectFont.js +29 -29
  211. package/components/Head.d.ts +11 -11
  212. package/components/Head.js +74 -74
  213. package/components/Mutation/AddToCart/addToCartUtils.d.ts +18 -18
  214. package/components/Mutation/AddToCart/addToCartUtils.js +51 -51
  215. package/components/Mutation/AddToCartFormik.d.ts +53 -53
  216. package/components/Mutation/AddToCartFormik.js +171 -171
  217. package/components/Mutation/DecrementQuantity.d.ts +4 -4
  218. package/components/Mutation/DecrementQuantity.js +34 -34
  219. package/components/Mutation/IncrementQuantity.d.ts +4 -4
  220. package/components/Mutation/IncrementQuantity.js +34 -34
  221. package/components/Mutation/RemoveFromCart.d.ts +5 -5
  222. package/components/Mutation/RemoveFromCart.js +51 -51
  223. package/components/Mutation/SetQuantity.d.ts +4 -4
  224. package/components/Mutation/SetQuantity.js +36 -36
  225. package/components/Mutation/SubscribeToNewsletter.d.ts +4 -4
  226. package/components/Mutation/SubscribeToNewsletter.js +29 -29
  227. package/components/Mutation/SubscribeToStockNotifications.d.ts +4 -4
  228. package/components/Mutation/SubscribeToStockNotifications.js +30 -30
  229. package/components/Mutation/cartMutationUtils.d.ts +28 -28
  230. package/components/Mutation/cartMutationUtils.js +108 -108
  231. package/components/Mutation/cartMutationUtils.spec.js +142 -142
  232. package/components/Mutation/useDecrementQuantity.d.ts +11 -11
  233. package/components/Mutation/useDecrementQuantity.js +53 -53
  234. package/components/Mutation/useIncrementQuantity.d.ts +11 -11
  235. package/components/Mutation/useIncrementQuantity.js +53 -53
  236. package/components/Mutation/useRemoveFromCart.d.ts +13 -13
  237. package/components/Mutation/useRemoveFromCart.js +49 -49
  238. package/components/Mutation/useSetQuantity.d.ts +12 -12
  239. package/components/Mutation/useSetQuantity.js +37 -37
  240. package/components/Notifications/Notifications.d.ts +15 -15
  241. package/components/Notifications/Notifications.js +26 -26
  242. package/components/Notifications/index.d.ts +2 -2
  243. package/components/Notifications/index.js +2 -2
  244. package/components/Notifications/notificationMachine.d.ts +30 -30
  245. package/components/Notifications/notificationMachine.js +73 -73
  246. package/components/Notifications/notificationsMachine.d.ts +37 -37
  247. package/components/Notifications/notificationsMachine.js +65 -65
  248. package/components/Notifications/useNotification.d.ts +9 -9
  249. package/components/Notifications/useNotification.js +26 -26
  250. package/components/Notifications/useNotification.js.map +1 -1
  251. package/components/OpenGraph/OpenGraph.test.js +180 -180
  252. package/components/OpenGraph/OpenGraphGeneralPageData.d.ts +25 -25
  253. package/components/OpenGraph/OpenGraphGeneralPageData.js +36 -36
  254. package/components/OpenGraph/OpenGraphProductData.d.ts +25 -25
  255. package/components/OpenGraph/OpenGraphProductData.js +48 -48
  256. package/components/OpenGraph/index.d.ts +2 -2
  257. package/components/OpenGraph/index.js +2 -2
  258. package/components/Pagination/PaginationContainer.d.ts +2 -2
  259. package/components/Pagination/PaginationContainer.js +4 -4
  260. package/components/Pagination/PaginationContext.d.ts +14 -14
  261. package/components/Pagination/PaginationContext.js +3 -3
  262. package/components/Pagination/PaginationProvider.d.ts +19 -19
  263. package/components/Pagination/PaginationProvider.js +94 -94
  264. package/components/Pagination/PaginationProvider.test.js +282 -282
  265. package/components/PreviewContext.d.ts +10 -10
  266. package/components/PreviewContext.js +26 -26
  267. package/components/ProductConfigurationProvider/ConfigPrice.gql +22 -22
  268. package/components/ProductConfigurationProvider/ProductConfigurationContext.d.ts +13 -13
  269. package/components/ProductConfigurationProvider/ProductConfigurationContext.js +4 -4
  270. package/components/ProductConfigurationProvider/ProductConfigurationProvider.d.ts +6 -6
  271. package/components/ProductConfigurationProvider/ProductConfigurationProvider.js +49 -49
  272. package/components/Query/CartProvider.d.ts +22 -22
  273. package/components/Query/CartProvider.js +67 -67
  274. package/components/SortOrder/SortOrderContainer.d.ts +40 -40
  275. package/components/SortOrder/SortOrderContainer.js +101 -101
  276. package/components/SortOrder/SortOrderContainer.js.map +1 -1
  277. package/components/SortOrder/SortOrderContext.d.ts +9 -9
  278. package/components/SortOrder/SortOrderContext.js +8 -8
  279. package/components/StructuredData/SiteLinksSearchStructuredData.d.ts +3 -3
  280. package/components/StructuredData/SiteLinksSearchStructuredData.js +24 -24
  281. package/components/StructuredData/StructuredBreadcrumbData.d.ts +12 -12
  282. package/components/StructuredData/StructuredBreadcrumbData.js +54 -54
  283. package/components/StructuredData/StructuredCategoryData.d.ts +16 -16
  284. package/components/StructuredData/StructuredCategoryData.js +17 -17
  285. package/components/StructuredData/StructuredData.d.ts +9 -9
  286. package/components/StructuredData/StructuredData.js +6 -6
  287. package/components/StructuredData/StructuredPageData.d.ts +16 -16
  288. package/components/StructuredData/StructuredPageData.js +16 -16
  289. package/components/StructuredData/StructuredProductData.d.ts +18 -18
  290. package/components/StructuredData/StructuredProductData.js +42 -42
  291. package/components/StructuredData/StructuredProductData.test.js +130 -130
  292. package/components/StructuredData/index.d.ts +5 -5
  293. package/components/StructuredData/index.js +5 -5
  294. package/data/cache.d.ts +3 -3
  295. package/data/cache.js +20 -20
  296. package/data/fragmentTypes.d.ts +8 -8
  297. package/data/fragmentTypes.js +83 -83
  298. package/data/fragments/BadgeFragment.gql +7 -7
  299. package/data/fragments/CartCoreFragment.gql +89 -89
  300. package/data/fragments/ChannelsFragment.gql +58 -58
  301. package/data/fragments/CommentsFragment.gql +6 -6
  302. package/data/fragments/HeadFragment.gql +9 -9
  303. package/data/fragments/PriceFragment.gql +5 -5
  304. package/data/fragments/ProductCampaignFragment.gql +10 -10
  305. package/data/fragments/ProductConfigurationsFragment.gql +24 -24
  306. package/data/fragments/ProductListsFragments.gql +94 -94
  307. package/data/fragments/ProductMetadataFragment.gql +20 -20
  308. package/data/fragments/ProductPriceFragment.gql +10 -10
  309. package/data/fragments/ProductVariantPriceFragment.gql +10 -10
  310. package/data/fragments/RouteCrumbFragment.gql +20 -20
  311. package/data/fragments/RouteMetaFragment.gql +18 -18
  312. package/data/fragments/StockStatusFragment.gql +7 -7
  313. package/data/fragments/index.d.ts +1 -1
  314. package/data/fragments/index.js +1 -1
  315. package/data/mutations/accountMutations.gql +28 -28
  316. package/data/mutations/cartMutations.gql +41 -41
  317. package/data/mutations/productListMutations.gql +18 -18
  318. package/data/mutations/signup.gql +7 -7
  319. package/data/mutations/subscribeToNewsletter.gql +3 -3
  320. package/data/mutations/subscribeToStockNotifications.gql +6 -6
  321. package/data/mutations/updateCustomer.gql +5 -5
  322. package/data/mutations/updatePassword.gql +5 -5
  323. package/data/queries/CartMutationQuery.gql +36 -36
  324. package/data/queries/CartQuery.gql +7 -7
  325. package/data/queries/GetCustomerCountryCode.gql +9 -9
  326. package/data/queries/PersonLookupQuery.gql +28 -28
  327. package/data/queries/ProductLists.gql +8 -8
  328. package/dependencies.d.ts +104 -104
  329. package/errorReporting.browser.d.ts +3 -3
  330. package/errorReporting.browser.js +11 -11
  331. package/errorReporting.d.ts +3 -3
  332. package/errorReporting.js +19 -19
  333. package/errorReporting.server.d.ts +3 -3
  334. package/errorReporting.server.js +11 -11
  335. package/errorReporting.shared.d.ts +5 -5
  336. package/errorReporting.shared.js +16 -16
  337. package/experiments/ExperimentsProvider.d.ts +4 -4
  338. package/experiments/ExperimentsProvider.js +28 -28
  339. package/experiments/ExperimentsProvider.test.js +105 -105
  340. package/experiments/integration.test.js +76 -76
  341. package/experiments/selectExperimentVariant.d.ts +3 -3
  342. package/experiments/selectExperimentVariant.js +34 -34
  343. package/experiments/selectExperimentVariant.test.js +64 -64
  344. package/experiments/useExperiment.d.ts +2 -2
  345. package/experiments/useExperiment.js +10 -10
  346. package/experiments/useExperiment.test.js +100 -100
  347. package/global.d.ts +1 -1
  348. package/helpers/decodeUrlQuery.d.ts +9 -9
  349. package/helpers/decodeUrlQuery.js +26 -26
  350. package/helpers/decodeUrlQuery.test.js +54 -54
  351. package/helpers/distance.d.ts +7 -7
  352. package/helpers/distance.js +12 -12
  353. package/helpers/encodeVariant.d.ts +3 -3
  354. package/helpers/encodeVariant.js +24 -24
  355. package/helpers/getBreakpointsFromValues.d.ts +6 -6
  356. package/helpers/getBreakpointsFromValues.js +14 -14
  357. package/helpers/getBreakpointsFromValues.test.js +47 -47
  358. package/helpers/getCartItemVariant.d.ts +7 -7
  359. package/helpers/getCartItemVariant.js +8 -8
  360. package/helpers/getErrorDetail.d.ts +7 -7
  361. package/helpers/getErrorDetail.js +11 -11
  362. package/helpers/getErrorDetail.test.js +44 -44
  363. package/helpers/getHeaders.d.ts +6 -6
  364. package/helpers/getHeaders.js +3 -3
  365. package/helpers/isRelativeUrl.d.ts +1 -1
  366. package/helpers/isRelativeUrl.js +3 -3
  367. package/helpers/logError.d.ts +1 -1
  368. package/helpers/logError.js +16 -16
  369. package/helpers/logWarningInDev.d.ts +1 -1
  370. package/helpers/logWarningInDev.js +6 -6
  371. package/helpers/throwErrorInDev.d.ts +6 -6
  372. package/helpers/throwErrorInDev.js +14 -14
  373. package/helpers/uniqueId.d.ts +5 -5
  374. package/helpers/uniqueId.js +9 -9
  375. package/hooks/CartCheckoutQuery.gql +5 -5
  376. package/hooks/Channels/useChannelSettings.d.ts +7 -7
  377. package/hooks/Channels/useChannelSettings.js +11 -11
  378. package/hooks/Channels/useChannelSettings.test.js +51 -51
  379. package/hooks/Filters/useBooleanFilter.d.ts +8 -8
  380. package/hooks/Filters/useBooleanFilter.js +20 -20
  381. package/hooks/Filters/useFilters.d.ts +3 -3
  382. package/hooks/Filters/useFilters.js +15 -15
  383. package/hooks/Filters/useListFilter.d.ts +10 -10
  384. package/hooks/Filters/useListFilter.js +37 -37
  385. package/hooks/Filters/useMultiFilter.d.ts +13 -13
  386. package/hooks/Filters/useMultiFilter.js +49 -49
  387. package/hooks/Filters/useRangeFilter.d.ts +10 -10
  388. package/hooks/Filters/useRangeFilter.js +35 -35
  389. package/hooks/Filters/useSortOrder.d.ts +11 -11
  390. package/hooks/Filters/useSortOrder.js +21 -21
  391. package/hooks/FreeShippingQuery.gql +16 -16
  392. package/hooks/PackageProducts/index.d.ts +2 -2
  393. package/hooks/PackageProducts/index.js +2 -2
  394. package/hooks/PackageProducts/packagePriceQuery.gql +29 -29
  395. package/hooks/PackageProducts/usePackageProductItem.d.ts +17 -17
  396. package/hooks/PackageProducts/usePackageProductItem.js +26 -26
  397. package/hooks/PackageProducts/usePackageProducts.d.ts +19 -19
  398. package/hooks/PackageProducts/usePackageProducts.js +345 -345
  399. package/hooks/PackageProducts/usePackageProducts.test.js +383 -383
  400. package/hooks/Product/index.d.ts +1 -1
  401. package/hooks/Product/index.js +1 -1
  402. package/hooks/Product/useStockStatus.d.ts +9 -9
  403. package/hooks/Product/useStockStatus.js +25 -25
  404. package/hooks/Product/useSwitchToVariantImage.d.ts +9 -9
  405. package/hooks/Product/useSwitchToVariantImage.js +20 -20
  406. package/hooks/ProductList/ProductListContext.d.ts +7 -7
  407. package/hooks/ProductList/ProductListContext.js +110 -110
  408. package/hooks/ProductList/action-creators.d.ts +46 -46
  409. package/hooks/ProductList/action-creators.js +296 -296
  410. package/hooks/ProductList/index.d.ts +118 -118
  411. package/hooks/ProductList/index.js +21 -21
  412. package/hooks/ProductList/list-transforms.d.ts +73 -72
  413. package/hooks/ProductList/list-transforms.js +106 -106
  414. package/hooks/ProductList/list-transforms.test.js +489 -489
  415. package/hooks/ProductList/product-list-reducer.d.ts +76 -76
  416. package/hooks/ProductList/product-list-reducer.js +197 -197
  417. package/hooks/ProductList/product-list-reducer.test.js +464 -464
  418. package/hooks/ProductList/useProductList.d.ts +13 -13
  419. package/hooks/ProductList/useProductList.js +93 -93
  420. package/hooks/ProductList/useProductListItems.d.ts +10 -10
  421. package/hooks/ProductList/useProductListItems.js +48 -48
  422. package/hooks/ProductList/validate-product.d.ts +6 -6
  423. package/hooks/ProductList/validate-product.js +40 -40
  424. package/hooks/Subscriptions/useNewsletterSubscription.d.ts +38 -38
  425. package/hooks/Subscriptions/useNewsletterSubscription.js +41 -41
  426. package/hooks/Subscriptions/useStockNotifications.d.ts +36 -36
  427. package/hooks/Subscriptions/useStockNotifications.js +37 -37
  428. package/hooks/Subscriptions/useStoreSubscriptions.d.ts +48 -48
  429. package/hooks/Subscriptions/useStoreSubscriptions.js +150 -150
  430. package/hooks/Subscriptions/useStoresubscriptions.test.js +179 -179
  431. package/hooks/useAddMultipleToCart.d.ts +27 -27
  432. package/hooks/useAddMultipleToCart.js +113 -113
  433. package/hooks/useAddMultipleToCart.test.js +181 -181
  434. package/hooks/useChannelBanner.js +22 -22
  435. package/hooks/useChannelBanner.test.js +77 -77
  436. package/hooks/useCustomerOrders.test.js +176 -176
  437. package/hooks/useCustomerOrdersQuery.d.ts +21 -21
  438. package/hooks/useCustomerOrdersQuery.js +20 -20
  439. package/hooks/useDeleteAccountMutation.d.ts +15 -15
  440. package/hooks/useDeleteAccountMutation.js +38 -38
  441. package/hooks/useDynamicPrice.d.ts +3 -3
  442. package/hooks/useDynamicPrice.js +24 -24
  443. package/hooks/useFreeShippingCheck.d.ts +15 -15
  444. package/hooks/useFreeShippingCheck.js +30 -30
  445. package/hooks/useGeolocation.d.ts +11 -11
  446. package/hooks/useGeolocation.js +33 -33
  447. package/hooks/useInfinitePagination.d.ts +37 -37
  448. package/hooks/useInfinitePagination.js +138 -138
  449. package/hooks/useLogError.d.ts +1 -1
  450. package/hooks/useLogError.js +7 -7
  451. package/hooks/useLoginMutation.d.ts +12 -12
  452. package/hooks/useLoginMutation.js +14 -14
  453. package/hooks/useLoginRedirect.d.ts +4 -4
  454. package/hooks/useLoginRedirect.js +36 -36
  455. package/hooks/useOrderDetailQuery.d.ts +20 -20
  456. package/hooks/useOrderDetailQuery.js +28 -28
  457. package/hooks/usePreconnectLinks.d.ts +10 -10
  458. package/hooks/usePreconnectLinks.js +29 -29
  459. package/hooks/usePreconnectLinks.test.js +95 -95
  460. package/hooks/usePrice.d.ts +39 -39
  461. package/hooks/usePrice.js +71 -71
  462. package/hooks/usePrice.test.js +171 -171
  463. package/hooks/useProductVariants/index.d.ts +1 -1
  464. package/hooks/useProductVariants/index.js +1 -1
  465. package/hooks/useProductVariants/useProductVariants.d.ts +19 -19
  466. package/hooks/useProductVariants/useProductVariants.js +202 -202
  467. package/hooks/useProductVariants/useProductVariants.test.js +415 -415
  468. package/hooks/useProductVariants/useVariantFromUrl.d.ts +5 -5
  469. package/hooks/useProductVariants/useVariantFromUrl.js +15 -15
  470. package/hooks/useProductVariants/useVariantFromUrl.test.js +79 -79
  471. package/hooks/useRoutePreload.d.ts +24 -24
  472. package/hooks/useRoutePreload.js +39 -39
  473. package/hooks/useShopConfig.d.ts +1 -1
  474. package/hooks/useShopConfig.js +10 -10
  475. package/hooks/useThrowErrorInDev.d.ts +1 -1
  476. package/hooks/useThrowErrorInDev.js +7 -7
  477. package/hooks/useThunkReducer.d.ts +7 -7
  478. package/hooks/useThunkReducer.js +23 -23
  479. package/hooks/useWarningInDev.d.ts +1 -1
  480. package/hooks/useWarningInDev.js +9 -9
  481. package/inServer.d.ts +1 -1
  482. package/inServer.js +2 -2
  483. package/index.d.ts +1 -1
  484. package/index.js +1 -1
  485. package/integrations/addwishSchemaExtension.d.ts +35 -35
  486. package/integrations/addwishSchemaExtension.js +140 -140
  487. package/integrations/nostoSchemaExtension.d.ts +5 -5
  488. package/integrations/nostoSchemaExtension.js +76 -76
  489. package/integrations/sluggishSchemaExtension.d.ts +2 -2
  490. package/integrations/sluggishSchemaExtension.js +26 -26
  491. package/package.json +1 -1
  492. package/polyfills.d.ts +1 -1
  493. package/polyfills.js +37 -37
  494. package/registerServiceWorker.js +110 -110
  495. package/resolvers/filters/boolFilter.d.ts +3 -3
  496. package/resolvers/filters/boolFilter.js +84 -84
  497. package/resolvers/filters/defaultActiveFilters.d.ts +3 -3
  498. package/resolvers/filters/defaultActiveFilters.js +8 -8
  499. package/resolvers/filters/filterParams.d.ts +3 -3
  500. package/resolvers/filters/filterParams.js +84 -84
  501. package/resolvers/filters/filters.d.ts +5 -5
  502. package/resolvers/filters/filters.js +78 -78
  503. package/resolvers/filters/index.d.ts +27 -27
  504. package/resolvers/filters/index.js +7 -7
  505. package/resolvers/filters/listFilter.d.ts +7 -7
  506. package/resolvers/filters/listFilter.js +73 -73
  507. package/resolvers/filters/listFilterItem.d.ts +3 -3
  508. package/resolvers/filters/listFilterItem.js +122 -122
  509. package/resolvers/filters/multiListFilter.d.ts +5 -5
  510. package/resolvers/filters/multiListFilter.js +195 -195
  511. package/resolvers/filters/multiListFilterList.d.ts +3 -3
  512. package/resolvers/filters/multiListFilterList.js +55 -55
  513. package/resolvers/filters/rangeFilter.d.ts +5 -5
  514. package/resolvers/filters/rangeFilter.js +137 -137
  515. package/resolvers/filters/updateQueryString.d.ts +12 -12
  516. package/resolvers/filters/updateQueryString.js +116 -114
  517. package/resolvers/filters/updateQueryString.js.map +1 -1
  518. package/resolvers/index.d.ts +37 -37
  519. package/resolvers/index.js +37 -37
  520. package/scripts/dev-apolloServer.js +31 -31
  521. package/sentry/client.d.ts +1 -1
  522. package/sentry/client.js +29 -29
  523. package/sentry/common.d.ts +1 -1
  524. package/sentry/common.js +4 -4
  525. package/sentry/server.d.ts +1 -1
  526. package/sentry/server.js +19 -19
  527. package/sentry/utils.d.ts +1 -1
  528. package/sentry/utils.js +1 -1
  529. package/server/graphql.d.ts +20 -20
  530. package/server/graphql.js +118 -118
  531. package/server/graphql.test.js +123 -123
  532. package/server/index.d.ts +2 -2
  533. package/server/index.js +2 -2
  534. package/server/tracking/facebook.d.ts +5 -5
  535. package/server/tracking/facebook.js +132 -132
  536. package/server/tracking/middleware.d.ts +8 -8
  537. package/server/tracking/middleware.js +14 -14
  538. package/server/tracking/types.d.ts +33 -33
  539. package/setupTests.js +2 -2
  540. package/test-utils/ProviderPyramid.js +45 -45
  541. package/test-utils/mockShopConfig.js +26 -26
  542. package/test-utils/mockedProduct.js +253 -253
  543. package/test-utils/renderWithRouter.js +20 -20
  544. package/test-utils/variables.js +1231 -1231
  545. package/time.d.ts +1 -1
  546. package/time.js +5 -5
  547. package/types.d.ts +78 -4
@@ -1,346 +1,346 @@
1
- import { useApolloClient, useQuery } from '@apollo/react-hooks';
2
- import { useMachine } from '@xstate/react';
3
- import produce from 'immer';
4
- import { useCallback, useEffect, useMemo, useRef } from 'react';
5
- import { assign, Machine } from 'xstate';
6
- import { useAddMultipleToCart } from '../useAddMultipleToCart';
7
- import packagePriceQuery from './packagePriceQuery.gql';
8
- // defaults to valid state if items have no variants
9
- // defaults to invalid if items have variants or are out of stock
10
- // selecting a variant triggers validate
11
- // (validate GUARD validates all items)
12
- // if valid, move to fetching_price state
13
- // once resolved, move to buyable state
14
- // if invalid, remain in invalid state
15
- //
16
- function itemHasVariants(item) {
17
- return item.product.hasVariants;
18
- }
19
- function itemIsOutOfStock(item) {
20
- return !item.product.stockStatus.buyable;
21
- }
22
- const stateMachine = Machine({
23
- id: 'package',
24
- initial: 'loading',
25
- context: { packageProduct: null, items: {}, price: {}, error: null },
26
- on: {
27
- UPDATE_ITEM: {
28
- actions: 'updateItems',
29
- target: 'validating',
30
- cond: context => Object.keys(context.items).length > 0
31
- }
32
- },
33
- states: {
34
- loading: {
35
- // During SSR, we already have the package and can head right on to
36
- // validating.
37
- always: [
38
- {
39
- target: 'validating',
40
- actions: assign({
41
- items: context => {
42
- return getInitialState(context.packageProduct).items;
43
- },
44
- price: context => {
45
- return getInitialState(context.packageProduct).price;
46
- }
47
- }),
48
- cond: context => {
49
- return !!context.packageProduct.package;
50
- }
51
- }
52
- ],
53
- on: {
54
- // On the client, we need to wait for the LOADED event to tell us
55
- // that the package has been retrieved
56
- LOADED: {
57
- target: 'validating',
58
- actions: assign({
59
- items: (_, event) => {
60
- return getInitialState(event.packageProduct).items;
61
- },
62
- price: (_, event) => {
63
- return getInitialState(event.packageProduct).price;
64
- },
65
- packageProduct: (_, event) => {
66
- return event.packageProduct;
67
- }
68
- })
69
- }
70
- }
71
- },
72
- invalid: {},
73
- validating: {
74
- always: [
75
- {
76
- target: 'valid',
77
- cond: context => {
78
- return deriveStatus(context.items) === 'valid';
79
- }
80
- },
81
- {
82
- target: 'invalid',
83
- cond: context => {
84
- return deriveStatus(context.items) !== 'valid';
85
- }
86
- }
87
- ]
88
- },
89
- valid: {
90
- initial: 'fetchingPrice',
91
- states: {
92
- fetchingPrice: {
93
- invoke: {
94
- id: 'fetchPrice',
95
- src: 'fetchPrice',
96
- onDone: {
97
- target: 'buyable',
98
- actions: assign({
99
- price: (_, event) => {
100
- return event.data;
101
- }
102
- })
103
- },
104
- onError: {
105
- target: 'error',
106
- actions: assign({
107
- error: (_, event) => {
108
- const errors = event.data;
109
- return {
110
- fromState: 'fetchingPrice',
111
- messages: errors
112
- .map((err) => err.message)
113
- .filter(Boolean)
114
- };
115
- }
116
- })
117
- }
118
- }
119
- },
120
- buyable: {
121
- on: {
122
- ADD_TO_CART: 'adding',
123
- ERROR: 'error'
124
- }
125
- },
126
- adding: {
127
- invoke: {
128
- id: 'add-to-cart',
129
- src: 'addToCart',
130
- onDone: 'added',
131
- onError: {
132
- target: 'error',
133
- actions: assign({
134
- error: (_, event) => {
135
- const errors = event.data;
136
- return {
137
- fromState: 'adding',
138
- messages: errors
139
- .map((err) => err.message)
140
- .filter(Boolean)
141
- };
142
- }
143
- })
144
- }
145
- }
146
- },
147
- added: {
148
- invoke: {
149
- id: 'added-refetch',
150
- src: () => {
151
- return new Promise(resolve => {
152
- setTimeout(() => {
153
- resolve(400);
154
- }, 800);
155
- });
156
- },
157
- onDone: {
158
- target: '#package.validating'
159
- }
160
- }
161
- },
162
- error: {
163
- on: {
164
- RETRY: '#package.validating'
165
- }
166
- }
167
- }
168
- }
169
- }
170
- }, {
171
- actions: {
172
- updateItems: assign({
173
- items: (context, event) => {
174
- if (event.type === 'UPDATE_ITEM') {
175
- const item = context.items[event.articleNumber];
176
- if (!item) {
177
- throw new Error('article does not exist in package');
178
- }
179
- if (event.variantArticleNumber) {
180
- const match = item.variants.includes(event.variantArticleNumber);
181
- if (!match) {
182
- throw new Error('variant does not exist on article');
183
- }
184
- }
185
- const { articleNumber, valid, variantArticleNumber } = event;
186
- const items = produce(context.items, draft => {
187
- draft[articleNumber] = Object.assign(Object.assign({}, draft[articleNumber]), { valid,
188
- variantArticleNumber });
189
- });
190
- return items;
191
- }
192
- }
193
- })
194
- }
195
- });
196
- function getInitialState(packageProduct) {
197
- var _a, _b;
198
- const items = (_b = (_a = packageProduct === null || packageProduct === void 0 ? void 0 : packageProduct.package) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.reduce((dict, item) => {
199
- var _a;
200
- dict[item.product.articleNumber] = {
201
- product: item.product,
202
- articleNumber: item.product.articleNumber,
203
- hasVariants: item.product.hasVariants,
204
- variantArticleNumber: null,
205
- variants: item.product.hasVariants
206
- ? (_a = item.product.variants) === null || _a === void 0 ? void 0 : _a.values.map(variant => variant.articleNumber)
207
- : null,
208
- valid: !itemHasVariants(item) && !itemIsOutOfStock(item),
209
- quantity: item.minQuantity
210
- };
211
- return dict;
212
- }, {});
213
- const price = packageProduct.package;
214
- return { items, price };
215
- }
216
- function flattenItems(items) {
217
- // perhaps we need the rest of the product detail?
218
- // Or otherwise the types need to be changed
219
- return Object.entries(items).map(entry => {
220
- const { articleNumber, variantArticleNumber, quantity, product } = entry[1];
221
- return Object.assign(Object.assign({}, product), { articleNumber: variantArticleNumber || articleNumber, quantity });
222
- });
223
- }
224
- function deriveStatus(packageItems) {
225
- const packageIsValid = Object.values(packageItems).every(item => item.valid);
226
- if (packageIsValid) {
227
- return 'valid';
228
- }
229
- return 'invalid';
230
- }
231
- function fetchPrice(packageArticleNumber, items, opts) {
232
- return opts.apolloClient
233
- .query({
234
- query: opts.query || packagePriceQuery,
235
- variables: {
236
- articleNumber: packageArticleNumber,
237
- products: Object.entries(items).map(entry => {
238
- // This should be cleaned up - we have to transform to the structure
239
- // that the API expects
240
- const { articleNumber, variantArticleNumber } = entry[1];
241
- return {
242
- product: articleNumber,
243
- // if you want to test error handling, just pass a random string for variant
244
- // variant: 'sdfgsdfg'
245
- variant: variantArticleNumber
246
- };
247
- })
248
- }
249
- })
250
- .then(({ data }) => {
251
- return data.product.package;
252
- }, err => {
253
- return Promise.reject(err.graphQLErrors);
254
- });
255
- }
256
- export function usePackageProduct({ product, packageProductQuery, priceQuery }) {
257
- const mounted = useRef(false);
258
- useEffect(() => {
259
- mounted.current = true;
260
- }, []);
261
- const client = useApolloClient();
262
- const { data } = useQuery(packageProductQuery, {
263
- variables: { articleNumber: product.articleNumber }
264
- });
265
- const [current, send] = useMachine(stateMachine, {
266
- // During SSR, data.product will have resolved, and we can initialise with
267
- // it. Otherwise, use the product passed in
268
- context: { packageProduct: (data === null || data === void 0 ? void 0 : data.product) || product },
269
- services: {
270
- fetchPrice: context => {
271
- return fetchPrice(product.articleNumber, context.items, {
272
- apolloClient: client,
273
- query: priceQuery
274
- });
275
- },
276
- addToCart: (_, event) => {
277
- // eslint-disable-next-line
278
- return addToCartMutation(event.queries).then(result => {
279
- if (result.errors) {
280
- return Promise.reject(result.errors);
281
- }
282
- else {
283
- return result;
284
- }
285
- });
286
- }
287
- }
288
- });
289
- useEffect(() => {
290
- // On the client we send the LOADED event once the package query resolves
291
- if (current.value !== 'loading')
292
- return;
293
- if (!(data === null || data === void 0 ? void 0 : data.product))
294
- return;
295
- send({ type: 'LOADED', packageProduct: data.product });
296
- }, [current.value, data, send]);
297
- const [addToCartMutation] = useAddMultipleToCart(flattenItems(current.context.items));
298
- const addPackageToCart = (queries) => {
299
- // invokes addToCart
300
- send({ type: 'ADD_TO_CART', queries });
301
- };
302
- const updatePackageItem = useCallback(function updatePackageItem(articleNumber, variantArticleNumber, valid) {
303
- send({
304
- type: 'UPDATE_ITEM',
305
- articleNumber,
306
- variantArticleNumber,
307
- valid
308
- });
309
- }, [send]);
310
- // Just doing this to simplify the status we expose
311
- const status = useMemo(() => {
312
- switch (true) {
313
- case current.matches({ valid: 'fetchingPrice' }):
314
- return 'fetching_price';
315
- case current.matches({ valid: 'buyable' }):
316
- return 'buyable';
317
- case current.matches({ valid: 'adding' }):
318
- return 'adding';
319
- case current.matches({ valid: 'added' }):
320
- return 'added';
321
- case current.matches({ valid: 'error' }):
322
- return 'error';
323
- case current.matches('loading'):
324
- return 'loading';
325
- default:
326
- return 'invalid';
327
- }
328
- }, [current]);
329
- const retry = useCallback(function retry() {
330
- if (status === 'error') {
331
- send({
332
- type: 'RETRY'
333
- });
334
- }
335
- }, [send, status]);
336
- return {
337
- status,
338
- price: current.context.price,
339
- addPackageToCart,
340
- updatePackageItem,
341
- packageProduct: current.context.packageProduct,
342
- error: current.context.error,
343
- retry
344
- };
345
- }
1
+ import { useApolloClient, useQuery } from '@apollo/react-hooks';
2
+ import { useMachine } from '@xstate/react';
3
+ import produce from 'immer';
4
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
5
+ import { assign, Machine } from 'xstate';
6
+ import { useAddMultipleToCart } from '../useAddMultipleToCart';
7
+ import packagePriceQuery from './packagePriceQuery.gql';
8
+ // defaults to valid state if items have no variants
9
+ // defaults to invalid if items have variants or are out of stock
10
+ // selecting a variant triggers validate
11
+ // (validate GUARD validates all items)
12
+ // if valid, move to fetching_price state
13
+ // once resolved, move to buyable state
14
+ // if invalid, remain in invalid state
15
+ //
16
+ function itemHasVariants(item) {
17
+ return item.product.hasVariants;
18
+ }
19
+ function itemIsOutOfStock(item) {
20
+ return !item.product.stockStatus.buyable;
21
+ }
22
+ const stateMachine = Machine({
23
+ id: 'package',
24
+ initial: 'loading',
25
+ context: { packageProduct: null, items: {}, price: {}, error: null },
26
+ on: {
27
+ UPDATE_ITEM: {
28
+ actions: 'updateItems',
29
+ target: 'validating',
30
+ cond: context => Object.keys(context.items).length > 0
31
+ }
32
+ },
33
+ states: {
34
+ loading: {
35
+ // During SSR, we already have the package and can head right on to
36
+ // validating.
37
+ always: [
38
+ {
39
+ target: 'validating',
40
+ actions: assign({
41
+ items: context => {
42
+ return getInitialState(context.packageProduct).items;
43
+ },
44
+ price: context => {
45
+ return getInitialState(context.packageProduct).price;
46
+ }
47
+ }),
48
+ cond: context => {
49
+ return !!context.packageProduct.package;
50
+ }
51
+ }
52
+ ],
53
+ on: {
54
+ // On the client, we need to wait for the LOADED event to tell us
55
+ // that the package has been retrieved
56
+ LOADED: {
57
+ target: 'validating',
58
+ actions: assign({
59
+ items: (_, event) => {
60
+ return getInitialState(event.packageProduct).items;
61
+ },
62
+ price: (_, event) => {
63
+ return getInitialState(event.packageProduct).price;
64
+ },
65
+ packageProduct: (_, event) => {
66
+ return event.packageProduct;
67
+ }
68
+ })
69
+ }
70
+ }
71
+ },
72
+ invalid: {},
73
+ validating: {
74
+ always: [
75
+ {
76
+ target: 'valid',
77
+ cond: context => {
78
+ return deriveStatus(context.items) === 'valid';
79
+ }
80
+ },
81
+ {
82
+ target: 'invalid',
83
+ cond: context => {
84
+ return deriveStatus(context.items) !== 'valid';
85
+ }
86
+ }
87
+ ]
88
+ },
89
+ valid: {
90
+ initial: 'fetchingPrice',
91
+ states: {
92
+ fetchingPrice: {
93
+ invoke: {
94
+ id: 'fetchPrice',
95
+ src: 'fetchPrice',
96
+ onDone: {
97
+ target: 'buyable',
98
+ actions: assign({
99
+ price: (_, event) => {
100
+ return event.data;
101
+ }
102
+ })
103
+ },
104
+ onError: {
105
+ target: 'error',
106
+ actions: assign({
107
+ error: (_, event) => {
108
+ const errors = event.data;
109
+ return {
110
+ fromState: 'fetchingPrice',
111
+ messages: errors
112
+ .map((err) => err.message)
113
+ .filter(Boolean)
114
+ };
115
+ }
116
+ })
117
+ }
118
+ }
119
+ },
120
+ buyable: {
121
+ on: {
122
+ ADD_TO_CART: 'adding',
123
+ ERROR: 'error'
124
+ }
125
+ },
126
+ adding: {
127
+ invoke: {
128
+ id: 'add-to-cart',
129
+ src: 'addToCart',
130
+ onDone: 'added',
131
+ onError: {
132
+ target: 'error',
133
+ actions: assign({
134
+ error: (_, event) => {
135
+ const errors = event.data;
136
+ return {
137
+ fromState: 'adding',
138
+ messages: errors
139
+ .map((err) => err.message)
140
+ .filter(Boolean)
141
+ };
142
+ }
143
+ })
144
+ }
145
+ }
146
+ },
147
+ added: {
148
+ invoke: {
149
+ id: 'added-refetch',
150
+ src: () => {
151
+ return new Promise(resolve => {
152
+ setTimeout(() => {
153
+ resolve(400);
154
+ }, 800);
155
+ });
156
+ },
157
+ onDone: {
158
+ target: '#package.validating'
159
+ }
160
+ }
161
+ },
162
+ error: {
163
+ on: {
164
+ RETRY: '#package.validating'
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }, {
171
+ actions: {
172
+ updateItems: assign({
173
+ items: (context, event) => {
174
+ if (event.type === 'UPDATE_ITEM') {
175
+ const item = context.items[event.articleNumber];
176
+ if (!item) {
177
+ throw new Error('article does not exist in package');
178
+ }
179
+ if (event.variantArticleNumber) {
180
+ const match = item.variants.includes(event.variantArticleNumber);
181
+ if (!match) {
182
+ throw new Error('variant does not exist on article');
183
+ }
184
+ }
185
+ const { articleNumber, valid, variantArticleNumber } = event;
186
+ const items = produce(context.items, draft => {
187
+ draft[articleNumber] = Object.assign(Object.assign({}, draft[articleNumber]), { valid,
188
+ variantArticleNumber });
189
+ });
190
+ return items;
191
+ }
192
+ }
193
+ })
194
+ }
195
+ });
196
+ function getInitialState(packageProduct) {
197
+ var _a, _b;
198
+ const items = (_b = (_a = packageProduct === null || packageProduct === void 0 ? void 0 : packageProduct.package) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.reduce((dict, item) => {
199
+ var _a;
200
+ dict[item.product.articleNumber] = {
201
+ product: item.product,
202
+ articleNumber: item.product.articleNumber,
203
+ hasVariants: item.product.hasVariants,
204
+ variantArticleNumber: null,
205
+ variants: item.product.hasVariants
206
+ ? (_a = item.product.variants) === null || _a === void 0 ? void 0 : _a.values.map(variant => variant.articleNumber)
207
+ : null,
208
+ valid: !itemHasVariants(item) && !itemIsOutOfStock(item),
209
+ quantity: item.minQuantity
210
+ };
211
+ return dict;
212
+ }, {});
213
+ const price = packageProduct.package;
214
+ return { items, price };
215
+ }
216
+ function flattenItems(items) {
217
+ // perhaps we need the rest of the product detail?
218
+ // Or otherwise the types need to be changed
219
+ return Object.entries(items).map(entry => {
220
+ const { articleNumber, variantArticleNumber, quantity, product } = entry[1];
221
+ return Object.assign(Object.assign({}, product), { articleNumber: variantArticleNumber || articleNumber, quantity });
222
+ });
223
+ }
224
+ function deriveStatus(packageItems) {
225
+ const packageIsValid = Object.values(packageItems).every(item => item.valid);
226
+ if (packageIsValid) {
227
+ return 'valid';
228
+ }
229
+ return 'invalid';
230
+ }
231
+ function fetchPrice(packageArticleNumber, items, opts) {
232
+ return opts.apolloClient
233
+ .query({
234
+ query: opts.query || packagePriceQuery,
235
+ variables: {
236
+ articleNumber: packageArticleNumber,
237
+ products: Object.entries(items).map(entry => {
238
+ // This should be cleaned up - we have to transform to the structure
239
+ // that the API expects
240
+ const { articleNumber, variantArticleNumber } = entry[1];
241
+ return {
242
+ product: articleNumber,
243
+ // if you want to test error handling, just pass a random string for variant
244
+ // variant: 'sdfgsdfg'
245
+ variant: variantArticleNumber
246
+ };
247
+ })
248
+ }
249
+ })
250
+ .then(({ data }) => {
251
+ return data.product.package;
252
+ }, err => {
253
+ return Promise.reject(err.graphQLErrors);
254
+ });
255
+ }
256
+ export function usePackageProduct({ product, packageProductQuery, priceQuery }) {
257
+ const mounted = useRef(false);
258
+ useEffect(() => {
259
+ mounted.current = true;
260
+ }, []);
261
+ const client = useApolloClient();
262
+ const { data } = useQuery(packageProductQuery, {
263
+ variables: { articleNumber: product.articleNumber }
264
+ });
265
+ const [current, send] = useMachine(stateMachine, {
266
+ // During SSR, data.product will have resolved, and we can initialise with
267
+ // it. Otherwise, use the product passed in
268
+ context: { packageProduct: (data === null || data === void 0 ? void 0 : data.product) || product },
269
+ services: {
270
+ fetchPrice: context => {
271
+ return fetchPrice(product.articleNumber, context.items, {
272
+ apolloClient: client,
273
+ query: priceQuery
274
+ });
275
+ },
276
+ addToCart: (_, event) => {
277
+ // eslint-disable-next-line
278
+ return addToCartMutation(event.queries).then(result => {
279
+ if (result.errors) {
280
+ return Promise.reject(result.errors);
281
+ }
282
+ else {
283
+ return result;
284
+ }
285
+ });
286
+ }
287
+ }
288
+ });
289
+ useEffect(() => {
290
+ // On the client we send the LOADED event once the package query resolves
291
+ if (current.value !== 'loading')
292
+ return;
293
+ if (!(data === null || data === void 0 ? void 0 : data.product))
294
+ return;
295
+ send({ type: 'LOADED', packageProduct: data.product });
296
+ }, [current.value, data, send]);
297
+ const [addToCartMutation] = useAddMultipleToCart(flattenItems(current.context.items));
298
+ const addPackageToCart = (queries) => {
299
+ // invokes addToCart
300
+ send({ type: 'ADD_TO_CART', queries });
301
+ };
302
+ const updatePackageItem = useCallback(function updatePackageItem(articleNumber, variantArticleNumber, valid) {
303
+ send({
304
+ type: 'UPDATE_ITEM',
305
+ articleNumber,
306
+ variantArticleNumber,
307
+ valid
308
+ });
309
+ }, [send]);
310
+ // Just doing this to simplify the status we expose
311
+ const status = useMemo(() => {
312
+ switch (true) {
313
+ case current.matches({ valid: 'fetchingPrice' }):
314
+ return 'fetching_price';
315
+ case current.matches({ valid: 'buyable' }):
316
+ return 'buyable';
317
+ case current.matches({ valid: 'adding' }):
318
+ return 'adding';
319
+ case current.matches({ valid: 'added' }):
320
+ return 'added';
321
+ case current.matches({ valid: 'error' }):
322
+ return 'error';
323
+ case current.matches('loading'):
324
+ return 'loading';
325
+ default:
326
+ return 'invalid';
327
+ }
328
+ }, [current]);
329
+ const retry = useCallback(function retry() {
330
+ if (status === 'error') {
331
+ send({
332
+ type: 'RETRY'
333
+ });
334
+ }
335
+ }, [send, status]);
336
+ return {
337
+ status,
338
+ price: current.context.price,
339
+ addPackageToCart,
340
+ updatePackageItem,
341
+ packageProduct: current.context.packageProduct,
342
+ error: current.context.error,
343
+ retry
344
+ };
345
+ }
346
346
  //# sourceMappingURL=usePackageProducts.js.map