@shopgate/pwa-common-commerce 7.30.0-alpha.6 → 7.30.0-alpha.8

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 (315) hide show
  1. package/cart/action-creators/addCouponsToCart.js +9 -2
  2. package/cart/action-creators/addProductsToCart.js +9 -2
  3. package/cart/action-creators/deleteCouponsFromCart.js +9 -2
  4. package/cart/action-creators/deleteProductsFromCart.js +9 -2
  5. package/cart/action-creators/errorAddCouponsToCart.js +10 -2
  6. package/cart/action-creators/errorAddProductsToCart.js +10 -2
  7. package/cart/action-creators/errorCart.js +8 -2
  8. package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
  9. package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
  10. package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
  11. package/cart/action-creators/receiveCart.js +9 -2
  12. package/cart/action-creators/requestCart.js +8 -2
  13. package/cart/action-creators/setCartProductPendingCount.js +9 -2
  14. package/cart/action-creators/setCouponFieldError.js +9 -2
  15. package/cart/action-creators/setCouponFieldValue.js +9 -2
  16. package/cart/action-creators/setFulfillmentSlot.js +9 -2
  17. package/cart/action-creators/successAddCouponsToCart.js +10 -2
  18. package/cart/action-creators/successAddProductsToCart.js +8 -2
  19. package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
  20. package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
  21. package/cart/action-creators/successUpdateProductsInCart.js +8 -2
  22. package/cart/action-creators/updateProductsInCart.js +9 -2
  23. package/cart/actions/addCouponsToCart.js +52 -8
  24. package/cart/actions/addProductsToCart.js +80 -11
  25. package/cart/actions/deleteCouponsFromCart.js +39 -6
  26. package/cart/actions/deleteProductsFromCart.js +38 -6
  27. package/cart/actions/fetchCart.js +52 -8
  28. package/cart/actions/updateProductsInCart.js +44 -6
  29. package/cart/constants/PipelineErrors.js +6 -1
  30. package/cart/constants/Pipelines.js +6 -1
  31. package/cart/constants/Portals.js +85 -1
  32. package/cart/constants/index.js +39 -2
  33. package/cart/helpers/config.js +47 -2
  34. package/cart/helpers/createPipelineErrorList.js +30 -4
  35. package/cart/helpers/fulfillmentSlots.js +37 -4
  36. package/cart/helpers/index.js +14 -3
  37. package/cart/helpers/quantity.js +23 -4
  38. package/cart/helpers/shipping.js +57 -2
  39. package/cart/helpers/tax.js +26 -2
  40. package/cart/index.js +25 -5
  41. package/cart/mock.js +130 -1
  42. package/cart/reducers/couponField.js +30 -2
  43. package/cart/reducers/data.js +98 -6
  44. package/cart/reducers/index.js +7 -1
  45. package/cart/selectors/index.js +181 -31
  46. package/cart/selectors/spec.js +189 -2
  47. package/cart/streams/index.js +176 -29
  48. package/cart/subscriptions/index.js +307 -30
  49. package/category/action-creators/errorCategory.js +10 -2
  50. package/category/action-creators/errorCategoryChildren.js +9 -2
  51. package/category/action-creators/errorRootCategories.js +8 -2
  52. package/category/action-creators/receiveCategory.js +12 -2
  53. package/category/action-creators/receiveCategoryChildren.js +10 -2
  54. package/category/action-creators/receiveRootCategories.js +9 -2
  55. package/category/action-creators/requestCategory.js +9 -2
  56. package/category/action-creators/requestCategoryChildren.js +9 -2
  57. package/category/action-creators/requestRootCategories.js +8 -2
  58. package/category/actions/fetchCategory.js +47 -5
  59. package/category/actions/fetchCategoryChildren.js +30 -2
  60. package/category/actions/fetchCategoryOrRootCategories.js +16 -2
  61. package/category/actions/fetchCategoryProducts.js +36 -2
  62. package/category/actions/fetchRootCategories.js +31 -2
  63. package/category/actions/getCategory.js +10 -2
  64. package/category/constants/Pipelines.js +3 -1
  65. package/category/constants/Portals.js +56 -3
  66. package/category/constants/index.js +17 -2
  67. package/category/helpers/index.js +27 -3
  68. package/category/index.js +19 -5
  69. package/category/mock.js +176 -1
  70. package/category/reducers/categoriesById.js +65 -3
  71. package/category/reducers/childrenByCategoryId.js +55 -4
  72. package/category/reducers/helpers/handleCategoryCollection.js +24 -3
  73. package/category/reducers/helpers/handleReceivedCategories.js +3 -1
  74. package/category/reducers/index.js +12 -2
  75. package/category/reducers/rootCategories.js +31 -2
  76. package/category/selectors/index.js +115 -16
  77. package/category/streams/index.js +82 -4
  78. package/category/subscriptions/index.js +96 -3
  79. package/checkout/action-creators/successCheckout.js +9 -2
  80. package/checkout/actions/fetchCheckoutUrl.js +28 -3
  81. package/checkout/constants/Pipelines.js +1 -1
  82. package/checkout/constants/index.js +3 -2
  83. package/checkout/index.js +11 -4
  84. package/checkout/selectors/index.js +7 -2
  85. package/checkout/streams/index.js +8 -2
  86. package/checkout/subscriptions/index.js +35 -6
  87. package/favorites/action-creators/index.js +206 -24
  88. package/favorites/actions/addFavorites.js +41 -3
  89. package/favorites/actions/addFavoritesList.js +27 -2
  90. package/favorites/actions/fetchFavoriteIds.js +49 -5
  91. package/favorites/actions/fetchFavorites.js +60 -5
  92. package/favorites/actions/fetchFavoritesList.js +47 -3
  93. package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
  94. package/favorites/actions/getFavorites.js +6 -2
  95. package/favorites/actions/removeFavorites.js +32 -3
  96. package/favorites/actions/removeFavoritesList.js +24 -2
  97. package/favorites/actions/toggleFavorites.js +68 -10
  98. package/favorites/actions/updateFavorites.js +39 -3
  99. package/favorites/actions/updateFavoritesList.js +26 -2
  100. package/favorites/constants/Pipelines.js +9 -1
  101. package/favorites/constants/Portals.js +32 -4
  102. package/favorites/constants/index.js +37 -5
  103. package/favorites/index.js +14 -4
  104. package/favorites/mock.js +89 -4
  105. package/favorites/reducers/index.js +7 -1
  106. package/favorites/reducers/lists.js +74 -2
  107. package/favorites/reducers/products.js +231 -24
  108. package/favorites/selectors/index.js +188 -24
  109. package/favorites/streams/index.js +135 -23
  110. package/favorites/streams/spec.js +517 -8
  111. package/favorites/subscriptions/index.js +260 -25
  112. package/favorites/subscriptions/spec.js +701 -28
  113. package/filter/action-creators/errorFilters.js +9 -2
  114. package/filter/action-creators/index.js +4 -1
  115. package/filter/action-creators/receiveFilters.js +10 -2
  116. package/filter/action-creators/requestFilters.js +9 -2
  117. package/filter/action-creators/updateFilters.js +8 -2
  118. package/filter/actions/fetchFilters.js +46 -3
  119. package/filter/actions/getFilters.js +6 -2
  120. package/filter/actions/helpers/buildFilterParams.js +34 -2
  121. package/filter/actions/helpers/buildRequestFilters.js +35 -2
  122. package/filter/actions/helpers/processFilters.js +10 -2
  123. package/filter/actions/helpers/processParams.js +26 -2
  124. package/filter/constants/Pipelines.js +1 -1
  125. package/filter/constants/Portals.js +39 -3
  126. package/filter/constants/index.js +8 -1
  127. package/filter/index.js +12 -4
  128. package/filter/reducers/helpers/enrichFilters.js +11 -3
  129. package/filter/reducers/index.js +5 -1
  130. package/filter/reducers/resultsByHash.js +43 -3
  131. package/filter/selectors/index.js +47 -6
  132. package/filter/streams/index.js +30 -1
  133. package/filter/subscriptions/index.js +34 -2
  134. package/market/constants/Portals.js +22 -4
  135. package/market/constants/index.js +2 -1
  136. package/market/helpers/showReturnPolicy.js +3 -1
  137. package/market/helpers/showTaxDisclaimer.js +3 -1
  138. package/market/index.js +6 -2
  139. package/orders/constants.js +2 -1
  140. package/package.json +3 -3
  141. package/product/action-creators/deleteProductsByIds.js +10 -2
  142. package/product/action-creators/errorProduct.js +10 -2
  143. package/product/action-creators/errorProductDescription.js +10 -2
  144. package/product/action-creators/errorProductImages.js +10 -2
  145. package/product/action-creators/errorProductMedia.js +10 -2
  146. package/product/action-creators/errorProductOptions.js +10 -2
  147. package/product/action-creators/errorProductProperties.js +10 -2
  148. package/product/action-creators/errorProductRelations.js +9 -2
  149. package/product/action-creators/errorProductShipping.js +10 -2
  150. package/product/action-creators/errorProductVariants.js +10 -2
  151. package/product/action-creators/errorProducts.js +9 -2
  152. package/product/action-creators/expireProductById.js +10 -2
  153. package/product/action-creators/expireProductData.js +11 -2
  154. package/product/action-creators/expireProductsByHash.js +9 -2
  155. package/product/action-creators/productNotAvailable.js +10 -2
  156. package/product/action-creators/provideProduct.js +9 -2
  157. package/product/action-creators/receiveProduct.js +10 -2
  158. package/product/action-creators/receiveProductCached.js +9 -2
  159. package/product/action-creators/receiveProductDescription.js +10 -2
  160. package/product/action-creators/receiveProductImages.js +10 -2
  161. package/product/action-creators/receiveProductMedia.js +10 -2
  162. package/product/action-creators/receiveProductOptions.js +10 -2
  163. package/product/action-creators/receiveProductProperties.js +10 -2
  164. package/product/action-creators/receiveProductRelations.js +12 -2
  165. package/product/action-creators/receiveProductShipping.js +10 -2
  166. package/product/action-creators/receiveProductVariants.js +10 -2
  167. package/product/action-creators/receiveProducts.js +16 -2
  168. package/product/action-creators/receiveProductsCached.js +9 -2
  169. package/product/action-creators/refreshExpiredPDPData.js +8 -2
  170. package/product/action-creators/requestProduct.js +10 -2
  171. package/product/action-creators/requestProductDescription.js +9 -2
  172. package/product/action-creators/requestProductImages.js +9 -2
  173. package/product/action-creators/requestProductMedia.js +9 -2
  174. package/product/action-creators/requestProductOptions.js +9 -2
  175. package/product/action-creators/requestProductProperties.js +9 -2
  176. package/product/action-creators/requestProductRelations.js +10 -2
  177. package/product/action-creators/requestProductShipping.js +9 -2
  178. package/product/action-creators/requestProductVariants.js +9 -2
  179. package/product/action-creators/requestProducts.js +9 -2
  180. package/product/action-creators/setProductId.js +9 -2
  181. package/product/action-creators/setProductQuantity.js +9 -2
  182. package/product/action-creators/setProductVariantId.js +9 -2
  183. package/product/actions/changeSortOrder.js +21 -2
  184. package/product/actions/fetchHighlightProducts.js +18 -2
  185. package/product/actions/fetchLiveshoppingProducts.js +14 -2
  186. package/product/actions/fetchProduct.js +52 -3
  187. package/product/actions/fetchProductDescription.js +30 -2
  188. package/product/actions/fetchProductImages.js +31 -2
  189. package/product/actions/fetchProductMedia.js +35 -2
  190. package/product/actions/fetchProductOptions.js +31 -2
  191. package/product/actions/fetchProductProperties.js +30 -2
  192. package/product/actions/fetchProductRelations.js +63 -2
  193. package/product/actions/fetchProductShipping.js +31 -2
  194. package/product/actions/fetchProductVariants.js +31 -2
  195. package/product/actions/fetchProducts.js +189 -17
  196. package/product/actions/fetchProductsById.js +68 -8
  197. package/product/actions/fetchProductsByQuery.js +102 -18
  198. package/product/actions/getHighlightProducts.js +6 -2
  199. package/product/actions/getLiveshoppingProducts.js +6 -2
  200. package/product/actions/getProduct.js +6 -2
  201. package/product/actions/getProductDescription.js +6 -2
  202. package/product/actions/getProductImages.js +6 -2
  203. package/product/actions/getProductOptions.js +6 -2
  204. package/product/actions/getProductProperties.js +6 -2
  205. package/product/actions/getProductRelations.js +6 -2
  206. package/product/actions/getProductShipping.js +6 -2
  207. package/product/actions/getProductVariants.js +6 -2
  208. package/product/actions/getProducts.js +6 -2
  209. package/product/actions/getProductsById.js +6 -2
  210. package/product/actions/getProductsByQuery.js +6 -2
  211. package/product/actions/processProductFlags.js +35 -3
  212. package/product/actions/updateMetadata.js +17 -2
  213. package/product/collections/ProductImageFormats.js +48 -8
  214. package/product/collections/index.js +1 -1
  215. package/product/constants/Pipelines.js +12 -1
  216. package/product/constants/Portals.js +200 -33
  217. package/product/constants/index.js +90 -18
  218. package/product/helpers/index.js +61 -8
  219. package/product/index.js +36 -6
  220. package/product/mock.js +1002 -2
  221. package/product/reducers/descriptionsByProductId.js +54 -5
  222. package/product/reducers/helpers/formatOptions.js +17 -2
  223. package/product/reducers/helpers/handleProductCollection.js +19 -2
  224. package/product/reducers/imagesByProductId.js +51 -4
  225. package/product/reducers/index.js +23 -1
  226. package/product/reducers/mediaByProductId.js +55 -3
  227. package/product/reducers/optionsByProductId.js +41 -2
  228. package/product/reducers/productRelationsByHash.js +43 -2
  229. package/product/reducers/productsById.js +122 -7
  230. package/product/reducers/propertiesByProductId.js +48 -2
  231. package/product/reducers/resultsByHash.js +125 -9
  232. package/product/reducers/shippingByProductId.js +37 -2
  233. package/product/reducers/variantsByProductId.js +56 -2
  234. package/product/selectors/options.js +90 -13
  235. package/product/selectors/page.js +62 -13
  236. package/product/selectors/price.js +81 -18
  237. package/product/selectors/product.js +549 -59
  238. package/product/selectors/product.mock.js +327 -12
  239. package/product/selectors/relations.js +35 -5
  240. package/product/selectors/variants.js +91 -15
  241. package/product/streams/index.js +167 -13
  242. package/product/subscriptions/index.js +210 -4
  243. package/reviews/action-creators/errorProductReviews.js +9 -2
  244. package/reviews/action-creators/errorReviews.js +9 -2
  245. package/reviews/action-creators/errorSubmitReview.js +9 -2
  246. package/reviews/action-creators/errorUserReview.js +9 -2
  247. package/reviews/action-creators/flushUserReview.js +8 -2
  248. package/reviews/action-creators/receiveProductReviews.js +11 -2
  249. package/reviews/action-creators/receiveReviews.js +12 -2
  250. package/reviews/action-creators/receiveSubmitReview.js +9 -2
  251. package/reviews/action-creators/receiveUserReview.js +10 -2
  252. package/reviews/action-creators/requestProductReviews.js +10 -2
  253. package/reviews/action-creators/requestReviews.js +9 -2
  254. package/reviews/action-creators/requestSubmitReview.js +9 -2
  255. package/reviews/action-creators/requestUserReview.js +9 -2
  256. package/reviews/action-creators/resetSubmittedReview.js +9 -2
  257. package/reviews/action-creators/spec.js +40 -1
  258. package/reviews/actions/fetchProductReviews.js +37 -2
  259. package/reviews/actions/fetchReviews.js +38 -2
  260. package/reviews/actions/fetchUserReview.js +31 -2
  261. package/reviews/actions/flushUserReview.js +5 -1
  262. package/reviews/actions/getProductReviews.js +6 -2
  263. package/reviews/actions/getUserReview.js +6 -2
  264. package/reviews/actions/spec.js +241 -4
  265. package/reviews/actions/submitReview.js +63 -3
  266. package/reviews/constants/Pipelines.js +4 -1
  267. package/reviews/constants/Portals.js +4 -1
  268. package/reviews/constants/index.js +26 -7
  269. package/reviews/index.js +15 -4
  270. package/reviews/mock.js +172 -11
  271. package/reviews/reducers/index.js +11 -1
  272. package/reviews/reducers/mock.js +14 -2
  273. package/reviews/reducers/reviewsByHash.js +52 -6
  274. package/reviews/reducers/reviewsById.js +27 -2
  275. package/reviews/reducers/reviewsByProductId.js +47 -2
  276. package/reviews/reducers/spec.js +211 -2
  277. package/reviews/reducers/userReviewsByProductId.js +68 -2
  278. package/reviews/selectors/index.js +123 -19
  279. package/reviews/selectors/mock.js +100 -1
  280. package/reviews/selectors/spec.js +100 -1
  281. package/reviews/streams/index.js +37 -5
  282. package/reviews/streams/spec.js +25 -1
  283. package/reviews/subscriptions/index.js +27 -2
  284. package/scanner/action-creators/errorHandleScanner.js +11 -2
  285. package/scanner/action-creators/scannerFinished.js +11 -2
  286. package/scanner/action-creators/startScanner.js +8 -2
  287. package/scanner/action-creators/successHandleScanner.js +11 -2
  288. package/scanner/actions/handleBarCode.js +22 -2
  289. package/scanner/actions/handleNoResults.js +23 -2
  290. package/scanner/actions/handleQrCode.js +116 -6
  291. package/scanner/actions/handleSearch.js +33 -2
  292. package/scanner/constants/Portals.js +22 -1
  293. package/scanner/constants/index.js +17 -1
  294. package/scanner/helpers/index.js +115 -5
  295. package/scanner/index.js +19 -5
  296. package/scanner/streams/index.js +36 -1
  297. package/scanner/subscriptions/index.js +78 -8
  298. package/search/action-creators/errorSearchResults.js +10 -2
  299. package/search/action-creators/receiveSearchResults.js +11 -2
  300. package/search/action-creators/receiveSearchSuggestions.js +10 -2
  301. package/search/action-creators/requestSearchResults.js +10 -2
  302. package/search/action-creators/requestSearchSuggestions.js +9 -2
  303. package/search/actions/fetchSearchResults.js +66 -8
  304. package/search/actions/fetchSearchSuggestions.js +36 -2
  305. package/search/constants/Pipelines.js +1 -1
  306. package/search/constants/Portals.js +9 -2
  307. package/search/constants/index.js +10 -2
  308. package/search/helpers/index.js +5 -2
  309. package/search/helpers/removeHighlightingPlaceholders.js +4 -1
  310. package/search/helpers/spec.js +19 -1
  311. package/search/index.js +17 -5
  312. package/search/reducers/index.js +38 -2
  313. package/search/selectors/index.js +23 -4
  314. package/search/streams/index.js +51 -3
  315. package/search/subscriptions/index.js +132 -5
@@ -1,48 +1,325 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";var _excluded=["coupon"];function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import'rxjs/add/operator/debounceTime';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import event from'@shopgate/pwa-core/classes/Event';import pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import{redirects}from'@shopgate/pwa-common/collections';import{userDidUpdate$}from'@shopgate/pwa-common/streams/user';import{appWillStart$,appDidStart$}from'@shopgate/pwa-common/streams/app';import{parseObjectToQueryString}from'@shopgate/pwa-common/helpers/router';import fetchRegisterUrl from'@shopgate/pwa-common/actions/user/fetchRegisterUrl';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{fetchProductsById,getProductRoute,hasProductVariety,getProduct}from'@shopgate/pwa-common-commerce/product';import{historyReplace}from'@shopgate/pwa-common/actions/router';import{checkoutSucceeded$}from'@shopgate/pwa-common-commerce/checkout';import{DIRECT_SHIP,ROPIS,BOPIS,getPreferredLocation,getPreferredFulfillmentMethod}from'@shopgate/engage/locations';import{makeGetEnabledFulfillmentMethods}from'@shopgate/engage/core/config';import{errorBehavior}from'@shopgate/engage/core';import{hasNewServices}from'@shopgate/engage/core/helpers';import*as pipelines from"../constants/Pipelines";import addCouponsToCart from"../actions/addCouponsToCart";import addProductsToCart from"../actions/addProductsToCart";import updateProductsInCart from"../actions/updateProductsInCart";import fetchCart from"../actions/fetchCart";import{cartDidEnter$,cartRequesting$,cartReceived$,productsAdded$,productsModified$,productsUpdated$,productsDeleted$,couponsAdded$,couponsUpdated$,couponsDeleted$,routeWithCouponWillEnter$,remoteCartDidUpdate$,cartUpdateFailed$,routeAddProductNavigate$,setFulfillmentSlot$,cartWillEnterIdle$}from"../streams";import setCartProductPendingCount from"../action-creators/setCartProductPendingCount";import{CART_PATH,DEEPLINK_CART_ADD_COUPON_PATTERN,DEEPLINK_CART_ADD_PRODUCT_PATTERN,CART_ITEM_TYPE_PRODUCT}from"../constants";import{getCartProducts}from"../selectors";/**
1
+ import 'rxjs/add/operator/debounceTime';
2
+ import 'rxjs/add/observable/of';
3
+ import { Observable } from 'rxjs/Observable';
4
+ import event from '@shopgate/pwa-core/classes/Event';
5
+ import pipelineDependencies from '@shopgate/pwa-core/classes/PipelineDependencies';
6
+ import { redirects } from '@shopgate/pwa-common/collections';
7
+ import { userDidUpdate$ } from '@shopgate/pwa-common/streams/user';
8
+ import { appWillStart$, appDidStart$ } from '@shopgate/pwa-common/streams/app';
9
+ import { parseObjectToQueryString } from '@shopgate/pwa-common/helpers/router';
10
+ import fetchRegisterUrl from '@shopgate/pwa-common/actions/user/fetchRegisterUrl';
11
+ import { LoadingProvider } from '@shopgate/pwa-common/providers';
12
+ import { fetchProductsById, getProductRoute, hasProductVariety, getProduct } from '@shopgate/pwa-common-commerce/product';
13
+ import { historyReplace } from '@shopgate/pwa-common/actions/router';
14
+ import { checkoutSucceeded$ } from '@shopgate/pwa-common-commerce/checkout';
15
+ import { DIRECT_SHIP, ROPIS, BOPIS, getPreferredLocation, getPreferredFulfillmentMethod } from '@shopgate/engage/locations';
16
+ import { makeGetEnabledFulfillmentMethods } from '@shopgate/engage/core/config';
17
+ import { errorBehavior } from '@shopgate/engage/core';
18
+ import { hasNewServices } from '@shopgate/engage/core/helpers';
19
+ import * as pipelines from "../constants/Pipelines";
20
+ import addCouponsToCart from "../actions/addCouponsToCart";
21
+ import addProductsToCart from "../actions/addProductsToCart";
22
+ import updateProductsInCart from "../actions/updateProductsInCart";
23
+ import fetchCart from "../actions/fetchCart";
24
+ import { cartDidEnter$, cartRequesting$, cartReceived$, productsAdded$, productsModified$, productsUpdated$, productsDeleted$, couponsAdded$, couponsUpdated$, couponsDeleted$, routeWithCouponWillEnter$, remoteCartDidUpdate$, cartUpdateFailed$, routeAddProductNavigate$, setFulfillmentSlot$, cartWillEnterIdle$ } from "../streams";
25
+ import setCartProductPendingCount from "../action-creators/setCartProductPendingCount";
26
+ import { CART_PATH, DEEPLINK_CART_ADD_COUPON_PATTERN, DEEPLINK_CART_ADD_PRODUCT_PATTERN, CART_ITEM_TYPE_PRODUCT } from "../constants";
27
+ import { getCartProducts } from "../selectors";
28
+
29
+ /**
2
30
  * Cart subscriptions.
3
31
  * @param {Function} subscribe The subscribe function.
4
- */export default function cart(subscribe){/**
32
+ */
33
+ export default function cart(subscribe) {
34
+ /**
5
35
  * Gets triggered when ever the local cart is out of
6
36
  * sync with the remote cart from the server.
7
- */var cartNeedsSync$=userDidUpdate$.merge(remoteCartDidUpdate$,checkoutSucceeded$,cartWillEnterIdle$);/**
37
+ */
38
+ const cartNeedsSync$ = userDidUpdate$.merge(remoteCartDidUpdate$, checkoutSucceeded$, cartWillEnterIdle$);
39
+
40
+ /**
8
41
  * Gets triggered when the app is started or the cart route is entered.
9
- */var cartDidEnterOrAppDidStart$=cartDidEnter$.merge(appDidStart$);var cartBusy$=cartRequesting$.merge(couponsAdded$,couponsDeleted$,productsAdded$,productsModified$,productsDeleted$);var cartIdle$=cartReceived$.merge(couponsUpdated$,productsUpdated$);/**
42
+ */
43
+ const cartDidEnterOrAppDidStart$ = cartDidEnter$.merge(appDidStart$);
44
+ const cartBusy$ = cartRequesting$.merge(couponsAdded$, couponsDeleted$, productsAdded$, productsModified$, productsDeleted$);
45
+ const cartIdle$ = cartReceived$.merge(couponsUpdated$, productsUpdated$);
46
+
47
+ /**
10
48
  * Gets triggered when the app will start.
11
- */subscribe(appWillStart$,function(){// Use the redirect system to handle coupons from deep links.
12
- redirects.set(DEEPLINK_CART_ADD_COUPON_PATTERN,function(_ref){var dispatch=_ref.dispatch,action=_ref.action;var _action$params$pathna=action.params.pathname.split('/'),_action$params$pathna2=_slicedToArray(_action$params$pathna,3),coupon=_action$params$pathna2[2];if(coupon){dispatch(addCouponsToCart([coupon.split('?')[0]],false));}return null;});// This will be handled in 2 deferred subscriptions
13
- redirects.set(DEEPLINK_CART_ADD_PRODUCT_PATTERN,function(){return null;});});/**
49
+ */
50
+ subscribe(appWillStart$, () => {
51
+ // Use the redirect system to handle coupons from deep links.
52
+ redirects.set(DEEPLINK_CART_ADD_COUPON_PATTERN, ({
53
+ dispatch,
54
+ action
55
+ }) => {
56
+ const [,, coupon] = action.params.pathname.split('/');
57
+ if (coupon) {
58
+ dispatch(addCouponsToCart([coupon.split('?')[0]], false));
59
+ }
60
+ return null;
61
+ });
62
+ // This will be handled in 2 deferred subscriptions
63
+ redirects.set(DEEPLINK_CART_ADD_PRODUCT_PATTERN, () => null);
64
+ });
65
+
66
+ /**
14
67
  * Gets triggered when the app starts.
15
- */subscribe(appDidStart$,function(_ref2){var dispatch=_ref2.dispatch;pipelineDependencies.set(pipelines.SHOPGATE_CART_GET_CART,[pipelines.SHOPGATE_CART_ADD_PRODUCTS,pipelines.SHOPGATE_CART_UPDATE_PRODUCTS,pipelines.SHOPGATE_CART_DELETE_PRODUCTS,pipelines.SHOPGATE_CART_ADD_COUPONS,pipelines.SHOPGATE_CART_DELETE_COUPONS]);// Push (deeplink) with coupon concurrent to get cart on app start
16
- pipelineDependencies.set(pipelines.SHOPGATE_CART_ADD_COUPONS,[pipelines.SHOPGATE_CART_ADD_PRODUCTS,pipelines.SHOPGATE_CART_GET_CART]);pipelineDependencies.set(pipelines.SHOPGATE_CART_DELETE_COUPONS,[pipelines.SHOPGATE_CART_ADD_PRODUCTS,pipelines.SHOPGATE_CART_GET_CART]);/**
68
+ */
69
+ subscribe(appDidStart$, ({
70
+ dispatch
71
+ }) => {
72
+ pipelineDependencies.set(pipelines.SHOPGATE_CART_GET_CART, [pipelines.SHOPGATE_CART_ADD_PRODUCTS, pipelines.SHOPGATE_CART_UPDATE_PRODUCTS, pipelines.SHOPGATE_CART_DELETE_PRODUCTS, pipelines.SHOPGATE_CART_ADD_COUPONS, pipelines.SHOPGATE_CART_DELETE_COUPONS]);
73
+
74
+ // Push (deeplink) with coupon concurrent to get cart on app start
75
+ pipelineDependencies.set(pipelines.SHOPGATE_CART_ADD_COUPONS, [pipelines.SHOPGATE_CART_ADD_PRODUCTS, pipelines.SHOPGATE_CART_GET_CART]);
76
+ pipelineDependencies.set(pipelines.SHOPGATE_CART_DELETE_COUPONS, [pipelines.SHOPGATE_CART_ADD_PRODUCTS, pipelines.SHOPGATE_CART_GET_CART]);
77
+
78
+ /**
17
79
  * Reload the cart whenever the WebView becomes visible.
18
80
  * This is needed, for example, when the cart is modified from another inAppBrowser tab like a
19
81
  * web-checkout and the user closes the said tab before reaching the success page.
20
- */event.addCallback('viewWillAppear',function(){dispatch(fetchCart());});// Reset the productPendingCount on app start to avoid a wrong value in the cart badge.
21
- dispatch(setCartProductPendingCount(0));});subscribe(cartNeedsSync$,function(_ref3){var dispatch=_ref3.dispatch;dispatch(fetchCart());});subscribe(cartBusy$,function(){LoadingProvider.setLoading(CART_PATH);});subscribe(setFulfillmentSlot$,function(_ref4){var _action$fulfillmentSl;var dispatch=_ref4.dispatch,getState=_ref4.getState,action=_ref4.action;// When the fulfillment slot is set we need to update all line items.
22
- var products=getCartProducts(getState());if(!products.length||!(action===null||action===void 0?void 0:(_action$fulfillmentSl=action.fulfillmentSlot)===null||_action$fulfillmentSl===void 0?void 0:_action$fulfillmentSl.id)){return;}products=products.filter(function(product){var _product$fulfillment;return[ROPIS,BOPIS].includes(product===null||product===void 0?void 0:(_product$fulfillment=product.fulfillment)===null||_product$fulfillment===void 0?void 0:_product$fulfillment.method);}).map(function(product){return{cartItemId:product.id,fulfillment:{slotId:action.fulfillmentSlot.id}};});if(!products.length){return;}// Update the slot id for ROPE products.
23
- dispatch(updateProductsInCart(products));});subscribe(cartIdle$,function(_ref5){var dispatch=_ref5.dispatch,getState=_ref5.getState;/** Fetch missing products of a cart */var productIds=getCartProducts(getState()).map(function(cartItem){return cartItem.product.id;});if(productIds.length){dispatch(fetchProductsById(productIds));}LoadingProvider.resetLoading(CART_PATH);});subscribe(cartDidEnterOrAppDidStart$,function(_ref6){var dispatch=_ref6.dispatch;dispatch(fetchRegisterUrl())["catch"](function(e){return e;});});subscribe(cartUpdateFailed$,function(_ref7){var dispatch=_ref7.dispatch,action=_ref7.action;/**
82
+ */
83
+ event.addCallback('viewWillAppear', () => {
84
+ dispatch(fetchCart());
85
+ });
86
+
87
+ // Reset the productPendingCount on app start to avoid a wrong value in the cart badge.
88
+ dispatch(setCartProductPendingCount(0));
89
+ });
90
+ subscribe(cartNeedsSync$, ({
91
+ dispatch
92
+ }) => {
93
+ dispatch(fetchCart());
94
+ });
95
+ subscribe(cartBusy$, () => {
96
+ LoadingProvider.setLoading(CART_PATH);
97
+ });
98
+ subscribe(setFulfillmentSlot$, ({
99
+ dispatch,
100
+ getState,
101
+ action
102
+ }) => {
103
+ // When the fulfillment slot is set we need to update all line items.
104
+ let products = getCartProducts(getState());
105
+ if (!products.length || !action?.fulfillmentSlot?.id) {
106
+ return;
107
+ }
108
+ products = products.filter(product => [ROPIS, BOPIS].includes(product?.fulfillment?.method)).map(product => ({
109
+ cartItemId: product.id,
110
+ fulfillment: {
111
+ slotId: action.fulfillmentSlot.id
112
+ }
113
+ }));
114
+ if (!products.length) {
115
+ return;
116
+ }
117
+
118
+ // Update the slot id for ROPE products.
119
+ dispatch(updateProductsInCart(products));
120
+ });
121
+ subscribe(cartIdle$, ({
122
+ dispatch,
123
+ getState
124
+ }) => {
125
+ /** Fetch missing products of a cart */
126
+ const productIds = getCartProducts(getState()).map(cartItem => cartItem.product.id);
127
+ if (productIds.length) {
128
+ dispatch(fetchProductsById(productIds));
129
+ }
130
+ LoadingProvider.resetLoading(CART_PATH);
131
+ });
132
+ subscribe(cartDidEnterOrAppDidStart$, ({
133
+ dispatch
134
+ }) => {
135
+ dispatch(fetchRegisterUrl()).catch(e => e);
136
+ });
137
+ subscribe(cartUpdateFailed$, ({
138
+ dispatch,
139
+ action
140
+ }) => {
141
+ /**
24
142
  * @type {PipelineErrorElement[]} errors
25
- */var _action$errors=action.errors,errors=_action$errors===void 0?[]:_action$errors,_action$couponsIds=action.couponsIds,couponsIds=_action$couponsIds===void 0?[]:_action$couponsIds;if(Array.isArray(errors)&&errors.length){// Supports only one error, because none of the pipelines is ever called with multiple items.
26
- // Multiple errors would cause the this to overlay multiple modals on top of each other.
27
- var _errors$2=errors[0],message=_errors$2.message,handled=_errors$2.handled,code=_errors$2.code,additionalParams=_errors$2.additionalParams,translated=_errors$2.translated,context=_errors$2.context;// Some errors are already handled automatically before
28
- if(handled){return;}errorBehavior.modal()({dispatch:dispatch,error:{code:code,context:context,meta:_extends({message:message,additionalParams:additionalParams,translated:translated},Array.isArray(couponsIds)&&couponsIds.length>0?{input:{couponsIds:couponsIds}}:null)}});}});/**
143
+ */
144
+ const {
145
+ errors = [],
146
+ couponsIds = []
147
+ } = action;
148
+ if (Array.isArray(errors) && errors.length) {
149
+ // Supports only one error, because none of the pipelines is ever called with multiple items.
150
+ // Multiple errors would cause the this to overlay multiple modals on top of each other.
151
+ const {
152
+ message,
153
+ handled,
154
+ code,
155
+ additionalParams,
156
+ translated,
157
+ context
158
+ } = errors[0];
159
+
160
+ // Some errors are already handled automatically before
161
+ if (handled) {
162
+ return;
163
+ }
164
+ errorBehavior.modal()({
165
+ dispatch,
166
+ error: {
167
+ code,
168
+ context,
169
+ meta: {
170
+ message,
171
+ additionalParams,
172
+ translated,
173
+ ...(Array.isArray(couponsIds) && couponsIds.length > 0 ? {
174
+ input: {
175
+ couponsIds
176
+ }
177
+ } : null)
178
+ }
179
+ }
180
+ });
181
+ }
182
+ });
183
+
184
+ /**
29
185
  * Gets triggered when a route with a coupon within its GET parameters will enter.
30
- */subscribe(routeWithCouponWillEnter$,function(_ref8){var dispatch=_ref8.dispatch,action=_ref8.action;var coupon=action.route.query.coupon;if(coupon){dispatch(addCouponsToCart([coupon],false));var _action$route2=action.route,query=_action$route2.query,pathname=_action$route2.pathname;var c=query.coupon,rest=_objectWithoutProperties(query,_excluded);dispatch(historyReplace({pathname:"".concat(pathname).concat(parseObjectToQueryString(rest))}));}});var getFulfillmentMethods=makeGetEnabledFulfillmentMethods();/**
186
+ */
187
+ subscribe(routeWithCouponWillEnter$, ({
188
+ dispatch,
189
+ action
190
+ }) => {
191
+ const {
192
+ coupon
193
+ } = action.route.query;
194
+ if (coupon) {
195
+ dispatch(addCouponsToCart([coupon], false));
196
+ const {
197
+ query,
198
+ pathname
199
+ } = action.route;
200
+ const {
201
+ coupon: c,
202
+ ...rest
203
+ } = query;
204
+ dispatch(historyReplace({
205
+ pathname: `${pathname}${parseObjectToQueryString(rest)}`
206
+ }));
207
+ }
208
+ });
209
+ const getFulfillmentMethods = makeGetEnabledFulfillmentMethods();
210
+
211
+ /**
31
212
  * Deeplink to add product to cart, eg /cart_add_product/123s
32
- */subscribe(routeAddProductNavigate$,/*#__PURE__*/function(){var _ref10=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref9){var dispatch,action,getState,state,redirectToPDP,fulfillment,product,preferredLocation,preferredFulfillmentMethod,shopFulfillmentMethods,activeLocation,activeFulfillmentMethod,availableFulfillmentMethods,_availableFulfillment;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch=_ref9.dispatch,action=_ref9.action,getState=_ref9.getState;state=getState();redirectToPDP=false;fulfillment=null;if(hasProductVariety(state,action)){// Redirect to PDP when the product has variants
33
- redirectToPDP=true;}else if(hasNewServices()){product=getProduct(state,action);preferredLocation=getPreferredLocation(state);preferredFulfillmentMethod=getPreferredFulfillmentMethod(state);shopFulfillmentMethods=getFulfillmentMethods(state);if(preferredFulfillmentMethod!==DIRECT_SHIP){activeLocation=null;if(preferredLocation){activeLocation=preferredLocation;}// Get fulfillment method that is both active for location and product.
34
- activeFulfillmentMethod=preferredFulfillmentMethod;availableFulfillmentMethods=(shopFulfillmentMethods===null||shopFulfillmentMethods===void 0?void 0:shopFulfillmentMethods.filter(function(s){return((product===null||product===void 0?void 0:product.fulfillmentMethods)||[]).includes(s);}))||[];if(activeLocation&&!activeFulfillmentMethod&&availableFulfillmentMethods.length===1){_availableFulfillment=_slicedToArray(availableFulfillmentMethods,1);activeFulfillmentMethod=_availableFulfillment[0];}if(!(product===null||product===void 0?void 0:product.fulfillmentMethods.includes(activeFulfillmentMethod))||false){activeFulfillmentMethod=null;}if(!activeFulfillmentMethod||!activeLocation){redirectToPDP=true;}else{fulfillment={method:preferredFulfillmentMethod,location:{code:preferredLocation.code,name:preferredLocation.name||''}};}}}// NO product or variety
35
- if(redirectToPDP){// Redirect to item page to select options/variant
36
- dispatch(historyReplace({pathname:getProductRoute(action.productId)}));}else{dispatch(addProductsToCart([_extends({productId:action.productId,quantity:1},fulfillment?{fulfillment:fulfillment}:{})]));dispatch(historyReplace({pathname:CART_PATH}));}case 6:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref10.apply(this,arguments);};}());/**
213
+ */
214
+ subscribe(routeAddProductNavigate$, async ({
215
+ dispatch,
216
+ action,
217
+ getState
218
+ }) => {
219
+ const state = getState();
220
+ let redirectToPDP = false;
221
+ let fulfillment = null;
222
+ if (hasProductVariety(state, action)) {
223
+ // Redirect to PDP when the product has variants
224
+ redirectToPDP = true;
225
+ } else if (hasNewServices()) {
226
+ const product = getProduct(state, action);
227
+ const preferredLocation = getPreferredLocation(state);
228
+ const preferredFulfillmentMethod = getPreferredFulfillmentMethod(state);
229
+ const shopFulfillmentMethods = getFulfillmentMethods(state);
230
+ if (preferredFulfillmentMethod !== DIRECT_SHIP) {
231
+ let activeLocation = null;
232
+ if (preferredLocation) {
233
+ activeLocation = preferredLocation;
234
+ }
235
+
236
+ // Get fulfillment method that is both active for location and product.
237
+ let activeFulfillmentMethod = preferredFulfillmentMethod;
238
+ const availableFulfillmentMethods = shopFulfillmentMethods?.filter(s => (product?.fulfillmentMethods || []).includes(s)) || [];
239
+ if (activeLocation && !activeFulfillmentMethod && availableFulfillmentMethods.length === 1) {
240
+ [activeFulfillmentMethod] = availableFulfillmentMethods;
241
+ }
242
+ if (!product?.fulfillmentMethods.includes(activeFulfillmentMethod) || false) {
243
+ activeFulfillmentMethod = null;
244
+ }
245
+ if (!activeFulfillmentMethod || !activeLocation) {
246
+ redirectToPDP = true;
247
+ } else {
248
+ fulfillment = {
249
+ method: preferredFulfillmentMethod,
250
+ location: {
251
+ code: preferredLocation.code,
252
+ name: preferredLocation.name || ''
253
+ }
254
+ };
255
+ }
256
+ }
257
+ }
258
+
259
+ // NO product or variety
260
+ if (redirectToPDP) {
261
+ // Redirect to item page to select options/variant
262
+ dispatch(historyReplace({
263
+ pathname: getProductRoute(action.productId)
264
+ }));
265
+ } else {
266
+ dispatch(addProductsToCart([{
267
+ productId: action.productId,
268
+ quantity: 1,
269
+ ...(fulfillment ? {
270
+ fulfillment
271
+ } : {})
272
+ }]));
273
+ dispatch(historyReplace({
274
+ pathname: CART_PATH
275
+ }));
276
+ }
277
+ });
278
+
279
+ /**
37
280
  * Deffer coupon adding to a cart, until we have the product from the push message inside cart.
38
281
  *
39
282
  * Logic was implemented for PWA 6 in ticket no PWA-1809.
40
- */var addCouponDeferred$=routeAddProductNavigate$// Only if coupon is given
41
- .filter(function(_ref11){var _ref11$action$couponC=_ref11.action.couponCode,couponCode=_ref11$action$couponC===void 0?'':_ref11$action$couponC;return!!couponCode;}).filter(function(){return!hasNewServices();}).withLatestFrom(cartReceived$).switchMap(function(_ref12){var _ref13=_slicedToArray(_ref12,2),navigate=_ref13[0],cartReceived=_ref13[1];if(cartReceived.action.cart.cartItems.find(function(i){return i.type===CART_ITEM_TYPE_PRODUCT;})){// We have items in cart, add coupon immediately
42
- return Observable.of(navigate);}// Wait until first product in cart to add a coupon
43
- return cartReceived$.filter(function(cartReceivedNext){return cartReceivedNext.action.cart.cartItems.find(function(i){return i.type===CART_ITEM_TYPE_PRODUCT;});}).first();},function(_ref14){var _ref15=_slicedToArray(_ref14,1),navigate=_ref15[0];return navigate;});/**
283
+ */
284
+ const addCouponDeferred$ = routeAddProductNavigate$
285
+ // Only if coupon is given
286
+ .filter(({
287
+ action: {
288
+ couponCode = ''
289
+ }
290
+ }) => !!couponCode).filter(() => !hasNewServices()).withLatestFrom(cartReceived$).switchMap(([navigate, cartReceived]) => {
291
+ if (cartReceived.action.cart.cartItems.find(i => i.type === CART_ITEM_TYPE_PRODUCT)) {
292
+ // We have items in cart, add coupon immediately
293
+ return Observable.of(navigate);
294
+ }
295
+ // Wait until first product in cart to add a coupon
296
+ return cartReceived$.filter(cartReceivedNext => cartReceivedNext.action.cart.cartItems.find(i => i.type === CART_ITEM_TYPE_PRODUCT)).first();
297
+ }, ([navigate]) => navigate);
298
+
299
+ /**
44
300
  * With the new services, the coupon is added immediately.
45
- */var addCouponImmediately$=routeAddProductNavigate$// Only if coupon is given
46
- .filter(function(_ref16){var _ref16$action$couponC=_ref16.action.couponCode,couponCode=_ref16$action$couponC===void 0?'':_ref16$action$couponC;return!!couponCode;}).filter(function(){return hasNewServices();});var addCoupon$=addCouponDeferred$.merge(addCouponImmediately$);/**
301
+ */
302
+ const addCouponImmediately$ = routeAddProductNavigate$
303
+ // Only if coupon is given
304
+ .filter(({
305
+ action: {
306
+ couponCode = ''
307
+ }
308
+ }) => !!couponCode).filter(() => hasNewServices());
309
+ const addCoupon$ = addCouponDeferred$.merge(addCouponImmediately$);
310
+
311
+ /**
47
312
  * Deeplink to add product and coupon to cart, eg /cart_add_product/123/COUPON
48
- */subscribe(addCoupon$,/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref17){var dispatch,action,couponCode;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:dispatch=_ref17.dispatch,action=_ref17.action;couponCode=action.couponCode;if(couponCode){dispatch(addCouponsToCart([couponCode],false));}case 3:case"end":return _context2.stop();}},_callee2);}));return function(_x2){return _ref18.apply(this,arguments);};}());}
313
+ */
314
+ subscribe(addCoupon$, async ({
315
+ dispatch,
316
+ action
317
+ }) => {
318
+ const {
319
+ couponCode
320
+ } = action;
321
+ if (couponCode) {
322
+ dispatch(addCouponsToCart([couponCode], false));
323
+ }
324
+ });
325
+ }
@@ -1,6 +1,14 @@
1
- import{ERROR_CATEGORY}from"../constants";/**
1
+ import { ERROR_CATEGORY } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the ERROR_CATEGORY action.
3
5
  * @param {string} categoryId The ID of the received category.
4
6
  * @param {string} errorCode The error code.
5
7
  * @return {Object} The ERROR_CATEGORY action.
6
- */var errorCategory=function errorCategory(categoryId,errorCode){return{type:ERROR_CATEGORY,categoryId:categoryId,errorCode:errorCode};};export default errorCategory;
8
+ */
9
+ const errorCategory = (categoryId, errorCode) => ({
10
+ type: ERROR_CATEGORY,
11
+ categoryId,
12
+ errorCode
13
+ });
14
+ export default errorCategory;
@@ -1,5 +1,12 @@
1
- import{ERROR_CATEGORY_CHILDREN}from"../constants";/**
1
+ import { ERROR_CATEGORY_CHILDREN } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the ERROR_CATEGORY_CHILDREN action.
3
5
  * @param {string} categoryId The ID of the category to receive children for.
4
6
  * @return {Object} The ERROR_CATEGORY_CHILDREN action.
5
- */var errorCategoryChildren=function errorCategoryChildren(categoryId){return{type:ERROR_CATEGORY_CHILDREN,categoryId:categoryId};};export default errorCategoryChildren;
7
+ */
8
+ const errorCategoryChildren = categoryId => ({
9
+ type: ERROR_CATEGORY_CHILDREN,
10
+ categoryId
11
+ });
12
+ export default errorCategoryChildren;
@@ -1,4 +1,10 @@
1
- import{ERROR_ROOT_CATEGORIES}from"../constants";/**
1
+ import { ERROR_ROOT_CATEGORIES } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the ERROR_ROOT_CATEGORIES action.
3
5
  * @return {Object} The ERROR_ROOT_CATEGORIES action.
4
- */var errorRootCategories=function errorRootCategories(){return{type:ERROR_ROOT_CATEGORIES};};export default errorRootCategories;
6
+ */
7
+ const errorRootCategories = () => ({
8
+ type: ERROR_ROOT_CATEGORIES
9
+ });
10
+ export default errorRootCategories;
@@ -1,7 +1,17 @@
1
- import{RECEIVE_CATEGORY}from"../constants";/**
1
+ import { RECEIVE_CATEGORY } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the RECEIVE_CATEGORY action.
3
5
  * @param {string} categoryId The ID of the received category.
4
6
  * @param {Object} categoryData The data of the received category.
5
7
  * @param {Array} categoryChildren The children of received category.
6
8
  * @return {Object} The RECEIVE_CATEGORY action.
7
- */var receiveCategory=function receiveCategory(categoryId,categoryData,categoryChildren){return{type:RECEIVE_CATEGORY,categoryId:categoryId,categoryData:categoryData,categoryChildren:categoryChildren,products:[]};};export default receiveCategory;
9
+ */
10
+ const receiveCategory = (categoryId, categoryData, categoryChildren) => ({
11
+ type: RECEIVE_CATEGORY,
12
+ categoryId,
13
+ categoryData,
14
+ categoryChildren,
15
+ products: []
16
+ });
17
+ export default receiveCategory;
@@ -1,6 +1,14 @@
1
- import{RECEIVE_CATEGORY_CHILDREN}from"../constants";/**
1
+ import { RECEIVE_CATEGORY_CHILDREN } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the RECEIVE_CATEGORY_CHILDREN action.
3
5
  * @param {string} categoryId The ID of the category to receive children for.
4
6
  * @param {Array} categoryChildren The requested category children.
5
7
  * @return {Object} The RECEIVE_CATEGORY_CHILDREN action.
6
- */var receiveCategoryChildren=function receiveCategoryChildren(categoryId,categoryChildren){return{type:RECEIVE_CATEGORY_CHILDREN,categoryId:categoryId,categoryChildren:categoryChildren};};export default receiveCategoryChildren;
8
+ */
9
+ const receiveCategoryChildren = (categoryId, categoryChildren) => ({
10
+ type: RECEIVE_CATEGORY_CHILDREN,
11
+ categoryId,
12
+ categoryChildren
13
+ });
14
+ export default receiveCategoryChildren;
@@ -1,5 +1,12 @@
1
- import{RECEIVE_ROOT_CATEGORIES}from"../constants";/**
1
+ import { RECEIVE_ROOT_CATEGORIES } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the RECEIVE_ROOT_CATEGORIES action.
3
5
  * @param {Array} categories The received root categories.
4
6
  * @return {Object} The RECEIVE_ROOT_CATEGORIES action.
5
- */var receiveRootCategories=function receiveRootCategories(categories){return{type:RECEIVE_ROOT_CATEGORIES,categories:categories};};export default receiveRootCategories;
7
+ */
8
+ const receiveRootCategories = categories => ({
9
+ type: RECEIVE_ROOT_CATEGORIES,
10
+ categories
11
+ });
12
+ export default receiveRootCategories;
@@ -1,5 +1,12 @@
1
- import{REQUEST_CATEGORY}from"../constants";/**
1
+ import { REQUEST_CATEGORY } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the REQUEST_CATEGORY action.
3
5
  * @param {string} categoryId The ID of the category to be requested.
4
6
  * @return {Object} The REQUEST_CATEGORY action.
5
- */var requestCategory=function requestCategory(categoryId){return{type:REQUEST_CATEGORY,categoryId:categoryId};};export default requestCategory;
7
+ */
8
+ const requestCategory = categoryId => ({
9
+ type: REQUEST_CATEGORY,
10
+ categoryId
11
+ });
12
+ export default requestCategory;
@@ -1,5 +1,12 @@
1
- import{REQUEST_CATEGORY_CHILDREN}from"../constants";/**
1
+ import { REQUEST_CATEGORY_CHILDREN } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the REQUEST_CATEGORY_CHILDREN action.
3
5
  * @param {string} categoryId The ID of the category to request children for.
4
6
  * @return {Object} The REQUEST_CATEGORY_CHILDREN action.
5
- */var requestCategoryChildren=function requestCategoryChildren(categoryId){return{type:REQUEST_CATEGORY_CHILDREN,categoryId:categoryId};};export default requestCategoryChildren;
7
+ */
8
+ const requestCategoryChildren = categoryId => ({
9
+ type: REQUEST_CATEGORY_CHILDREN,
10
+ categoryId
11
+ });
12
+ export default requestCategoryChildren;
@@ -1,4 +1,10 @@
1
- import{REQUEST_ROOT_CATEGORIES}from"../constants";/**
1
+ import { REQUEST_ROOT_CATEGORIES } from "../constants";
2
+
3
+ /**
2
4
  * Dispatches the REQUEST_ROOT_CATEGORIES action.
3
5
  * @return {Object} The REQUEST_ROOT_CATEGORIES action.
4
- */var requestRootCategories=function requestRootCategories(){return{type:REQUEST_ROOT_CATEGORIES};};export default requestRootCategories;
6
+ */
7
+ const requestRootCategories = () => ({
8
+ type: REQUEST_ROOT_CATEGORIES
9
+ });
10
+ export default requestRootCategories;
@@ -1,11 +1,53 @@
1
- import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{errorBehavior}from'@shopgate/engage/core';import{SHOPGATE_CATALOG_GET_CATEGORY}from"../constants/Pipelines";import fetchCategoryChildren from"./fetchCategoryChildren";import requestCategory from"../action-creators/requestCategory";import receiveCategory from"../action-creators/receiveCategory";import errorCategory from"../action-creators/errorCategory";import{getCategory}from"../selectors";/**
1
+ import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
2
+ import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
3
+ import { errorBehavior } from '@shopgate/engage/core';
4
+ import { SHOPGATE_CATALOG_GET_CATEGORY } from "../constants/Pipelines";
5
+ import fetchCategoryChildren from "./fetchCategoryChildren";
6
+ import requestCategory from "../action-creators/requestCategory";
7
+ import receiveCategory from "../action-creators/receiveCategory";
8
+ import errorCategory from "../action-creators/errorCategory";
9
+ import { getCategory } from "../selectors";
10
+
11
+ /**
2
12
  * Fetches the data for a given category ID (including child categories).
3
13
  * @param {string} categoryId The category ID.
4
14
  * @return {Function} The dispatched action.
5
- */function fetchCategory(categoryId){return function(dispatch,getState){var category=getCategory(getState(),{categoryId:categoryId});// Check if we need to fetch data
6
- if(!shouldFetchData(category)){/**
15
+ */
16
+ function fetchCategory(categoryId) {
17
+ return (dispatch, getState) => {
18
+ const category = getCategory(getState(), {
19
+ categoryId
20
+ });
21
+
22
+ // Check if we need to fetch data
23
+ if (!shouldFetchData(category)) {
24
+ /**
7
25
  * Child categories are maybe missing.
8
26
  * So we need to check it (check happens inside fetchCategoryChildren).
9
27
  * This is the case if we got categories from getRootCategory
10
- */if(category.childrenCount){dispatch(fetchCategoryChildren(categoryId));}return Promise.resolve(category);}// No data at all. So we have to fetch the category with children included
11
- dispatch(requestCategory(categoryId));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY).setInput({categoryId:categoryId,includeChildren:true}).setResponseBehavior({error:errorBehavior.modal()}).dispatch();request.then(function(result){dispatch(receiveCategory(categoryId,result,result.children||[]));})["catch"](function(error){dispatch(errorCategory(categoryId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchCategory);
28
+ */
29
+ if (category.childrenCount) {
30
+ dispatch(fetchCategoryChildren(categoryId));
31
+ }
32
+ return Promise.resolve(category);
33
+ }
34
+
35
+ // No data at all. So we have to fetch the category with children included
36
+ dispatch(requestCategory(categoryId));
37
+ const request = new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY).setInput({
38
+ categoryId,
39
+ includeChildren: true
40
+ }).setResponseBehavior({
41
+ error: errorBehavior.modal()
42
+ }).dispatch();
43
+ request.then(result => {
44
+ dispatch(receiveCategory(categoryId, result, result.children || []));
45
+ }).catch(error => {
46
+ dispatch(errorCategory(categoryId, error.code));
47
+ });
48
+ return request;
49
+ };
50
+ }
51
+
52
+ /** @mixes {MutableFunction} */
53
+ export default mutable(fetchCategory);
@@ -1,5 +1,33 @@
1
- import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN}from"../constants/Pipelines";import requestCategoryChildren from"../action-creators/requestCategoryChildren";import receiveCategoryChildren from"../action-creators/receiveCategoryChildren";import errorCategoryChildren from"../action-creators/errorCategoryChildren";/**
1
+ import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
2
+ import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
3
+ import { SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN } from "../constants/Pipelines";
4
+ import requestCategoryChildren from "../action-creators/requestCategoryChildren";
5
+ import receiveCategoryChildren from "../action-creators/receiveCategoryChildren";
6
+ import errorCategoryChildren from "../action-creators/errorCategoryChildren";
7
+
8
+ /**
2
9
  * Retrieves category children for a certain category by ID.
3
10
  * @param {string} categoryId The ID of the category to request children for.
4
11
  * @return {Function} The dispatched action.
5
- */function fetchCategoryChildren(categoryId){return function(dispatch,getState){var category=getState().category.childrenByCategoryId[categoryId];if(!shouldFetchData(category,'children')){return Promise.resolve(null);}dispatch(requestCategoryChildren(categoryId));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN).setInput({categoryId:categoryId}).dispatch();request.then(function(result){dispatch(receiveCategoryChildren(categoryId,result.categories));})["catch"](function(){dispatch(errorCategoryChildren(categoryId));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchCategoryChildren);
12
+ */
13
+ function fetchCategoryChildren(categoryId) {
14
+ return (dispatch, getState) => {
15
+ const category = getState().category.childrenByCategoryId[categoryId];
16
+ if (!shouldFetchData(category, 'children')) {
17
+ return Promise.resolve(null);
18
+ }
19
+ dispatch(requestCategoryChildren(categoryId));
20
+ const request = new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN).setInput({
21
+ categoryId
22
+ }).dispatch();
23
+ request.then(result => {
24
+ dispatch(receiveCategoryChildren(categoryId, result.categories));
25
+ }).catch(() => {
26
+ dispatch(errorCategoryChildren(categoryId));
27
+ });
28
+ return request;
29
+ };
30
+ }
31
+
32
+ /** @mixes {MutableFunction} */
33
+ export default mutable(fetchCategoryChildren);
@@ -1,6 +1,20 @@
1
- import{mutable}from'@shopgate/pwa-common/helpers/redux';import fetchRootCategories from"./fetchRootCategories";import fetchCategory from"./fetchCategory";/**
1
+ import { mutable } from '@shopgate/pwa-common/helpers/redux';
2
+ import fetchRootCategories from "./fetchRootCategories";
3
+ import fetchCategory from "./fetchCategory";
4
+
5
+ /**
2
6
  * Retrieves a category from the server when a categoryId is given. Otherwise it will fetch the
3
7
  * root categories.
4
8
  * @param {string} categoryId The category ID.
5
9
  * @return {Function} The dispatched action.
6
- */function fetchCategoryOrRootCategories(categoryId){return function(dispatch){if(!categoryId){dispatch(fetchRootCategories());return;}dispatch(fetchCategory(categoryId));};}export default mutable(fetchCategoryOrRootCategories);
10
+ */
11
+ function fetchCategoryOrRootCategories(categoryId) {
12
+ return dispatch => {
13
+ if (!categoryId) {
14
+ dispatch(fetchRootCategories());
15
+ return;
16
+ }
17
+ dispatch(fetchCategory(categoryId));
18
+ };
19
+ }
20
+ export default mutable(fetchCategoryOrRootCategories);