@shopgate/pwa-common-commerce 7.30.0-alpha.7 → 7.30.0-alpha.9

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 +700 -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 +4 -4
  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,31 +1,266 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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;}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);});};}import pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import appConfig from'@shopgate/pwa-common/helpers/config';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{appDidStart$}from'@shopgate/pwa-common/streams';import groupBy from'lodash/groupBy';import ToastProvider from'@shopgate/pwa-common/providers/toast';import{makeGetRoutePattern}from'@shopgate/engage/core/selectors';import{getLoadWishlistOnAppStartEnabled,getWishlistItemQuantityEnabled}from'@shopgate/engage/core/selectors/shopSettings';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{favoritesWillEnter$,shouldFetchFreshFavorites$,addProductToFavoritesDebounced$,addProductToFavorites$,removeProductFromFavoritesDebounced$,errorFavoritesLimit$,refreshFavorites$,didReceiveFlushFavoritesBuffer$,updateProductInFavoritesDebounced$,favoritesDidAddItem$,favoritesSyncIdle$}from"../streams";import{SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import addFavorites from"../actions/addFavorites";import updateFavorites from"../actions/updateFavorites";import removeFavorites from"../actions/removeFavorites";import fetchFavoritesListsWithItems from"../actions/fetchFavoritesListsWithItems";import fetchFavorites from"../actions/fetchFavorites";import{requestAddFavorites,requestRemoveFavorites,cancelRequestSyncFavorites,errorFavorites,idleSyncFavorites,requestUpdateFavorites}from"../action-creators";import{REQUEST_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,FAVORITES_LIMIT_ERROR,REQUEST_UPDATE_FAVORITES,FAVORITES_PATH}from"../constants";import{getFavoritesCount,makeGetFavoritesCountByList,makeGetProductRelativesOnFavorites,getFavoritesProducts,getUseGetFavoriteIdsPipeline}from"../selectors";import fetchFavoriteIds from"../actions/fetchFavoriteIds";/**
1
+ import pipelineDependencies from '@shopgate/pwa-core/classes/PipelineDependencies';
2
+ import appConfig from '@shopgate/pwa-common/helpers/config';
3
+ import showModal from '@shopgate/pwa-common/actions/modal/showModal';
4
+ import { appDidStart$ } from '@shopgate/pwa-common/streams';
5
+ import groupBy from 'lodash/groupBy';
6
+ import ToastProvider from '@shopgate/pwa-common/providers/toast';
7
+ import { makeGetRoutePattern } from '@shopgate/engage/core/selectors';
8
+ import { getLoadWishlistOnAppStartEnabled, getWishlistItemQuantityEnabled } from '@shopgate/engage/core/selectors/shopSettings';
9
+ import { LoadingProvider } from '@shopgate/pwa-common/providers';
10
+ import { favoritesWillEnter$, shouldFetchFreshFavorites$, addProductToFavoritesDebounced$, addProductToFavorites$, removeProductFromFavoritesDebounced$, errorFavoritesLimit$, refreshFavorites$, didReceiveFlushFavoritesBuffer$, updateProductInFavoritesDebounced$, favoritesDidAddItem$, favoritesSyncIdle$ } from "../streams";
11
+ import { SHOPGATE_USER_ADD_FAVORITES, SHOPGATE_USER_DELETE_FAVORITES } from "../constants/Pipelines";
12
+ import addFavorites from "../actions/addFavorites";
13
+ import updateFavorites from "../actions/updateFavorites";
14
+ import removeFavorites from "../actions/removeFavorites";
15
+ import fetchFavoritesListsWithItems from "../actions/fetchFavoritesListsWithItems";
16
+ import fetchFavorites from "../actions/fetchFavorites";
17
+ import { requestAddFavorites, requestRemoveFavorites, cancelRequestSyncFavorites, errorFavorites, idleSyncFavorites, requestUpdateFavorites } from "../action-creators";
18
+ import { REQUEST_ADD_FAVORITES, REQUEST_REMOVE_FAVORITES, FAVORITES_LIMIT_ERROR, REQUEST_UPDATE_FAVORITES, FAVORITES_PATH } from "../constants";
19
+ import { getFavoritesCount, makeGetFavoritesCountByList, makeGetProductRelativesOnFavorites, getFavoritesProducts, getUseGetFavoriteIdsPipeline } from "../selectors";
20
+ import fetchFavoriteIds from "../actions/fetchFavoriteIds";
21
+
22
+ /**
2
23
  * @param {Function} subscribe Subscribes to an observable.
3
- */export default function favorites(subscribe){if(!appConfig.hasFavorites){return;}/** App start */subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,loadWishlistOnAppStartEnabled;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;// Setup sync pipeline dependencies (concurrency to each other and themselves)
4
- pipelineDependencies.set(SHOPGATE_USER_ADD_FAVORITES,[SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);pipelineDependencies.set(SHOPGATE_USER_DELETE_FAVORITES,[SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());if(!(loadWishlistOnAppStartEnabled&&makeGetRoutePattern()(getState())!==FAVORITES_PATH)){_context.next=7;break;}_context.next=7;return dispatch(fetchFavoritesListsWithItems(false));case 7:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());/** Favorites route enter */subscribe(favoritesWillEnter$,/*#__PURE__*/function(){var _ref4=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3){var dispatch;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:dispatch=_ref3.dispatch;_context2.next=3;return dispatch(fetchFavoritesListsWithItems(true));case 3:case"end":return _context2.stop();}},_callee2);}));return function(_x2){return _ref4.apply(this,arguments);};}());/** User login / logout */subscribe(shouldFetchFreshFavorites$,/*#__PURE__*/function(){var _ref6=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5){var dispatch;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:dispatch=_ref5.dispatch;_context3.next=3;return dispatch(fetchFavoritesListsWithItems(true));case 3:case"end":return _context3.stop();}},_callee3);}));return function(_x3){return _ref6.apply(this,arguments);};}());subscribe(addProductToFavoritesDebounced$,function(_ref7){var _getFavoritesProducts;var action=_ref7.action,dispatch=_ref7.dispatch,getState=_ref7.getState;var state=getState();var wishlistItemQuantityEnabled=getWishlistItemQuantityEnabled(state);// Nothing to do, when the store already contains the item
5
- var activeProductInList=(_getFavoritesProducts=getFavoritesProducts(state).byList[action.listId])===null||_getFavoritesProducts===void 0?void 0:_getFavoritesProducts.items.find(function(_ref8){var productId=_ref8.productId;return productId===action.productId;});if(activeProductInList&&!wishlistItemQuantityEnabled){// Call cancel action with "zero" count, because request was even dispatched
6
- dispatch(cancelRequestSyncFavorites(0,action.listId));return;}var _appConfig$favorites=appConfig.favorites,_appConfig$favorites2=_appConfig$favorites===void 0?{}:_appConfig$favorites,_appConfig$favorites3=_appConfig$favorites2.limit,limit=_appConfig$favorites3===void 0?100:_appConfig$favorites3;var count=makeGetFavoritesCountByList(function(){return action===null||action===void 0?void 0:action.listId;})(state);// When the getFavorites pipeline is used to fetch favorites, the amount of items is limited
7
- // since it returns full product entities. Hence adding more items needs to be prevented.
8
- if(limit&&count>=limit&&!getUseGetFavoriteIdsPipeline(state)){// Dispatch a local error only, because the request to add is prevented
9
- var error=new Error('Limit exceeded');error.code=FAVORITES_LIMIT_ERROR;dispatch(errorFavorites(action.productId,error));}else{dispatch(requestAddFavorites(action.productId,action.listId,action.quantity,action.notes,action.showToast));}});subscribe(updateProductInFavoritesDebounced$,function(_ref9){var action=_ref9.action,dispatch=_ref9.dispatch;dispatch(requestUpdateFavorites(action.productId,action.listId,action.quantity,action.notes));});subscribe(removeProductFromFavoritesDebounced$,function(_ref10){var _getFavoritesProducts2;var action=_ref10.action,dispatch=_ref10.dispatch,getState=_ref10.getState;var count=getFavoritesCount(getState());if(count>0){if(action.withRelatives){// Will only handle ids which are present in the store, no additional check needed
10
- var allOnList=makeGetProductRelativesOnFavorites(function(){return action.listId;})(getState(),{productId:action.productId});allOnList.forEach(function(id){return dispatch(requestRemoveFavorites(id,action.listId));});return;}// Avoids trying to remove something that was already removed (incoming fetch response)
11
- var list=getFavoritesProducts(getState()).byList[action.listId];if(!(list===null||list===void 0?void 0:list.items.find(function(_ref11){var productId=_ref11.productId;return productId===action.productId;}))){// Call cancel action with "zero" count, because request was even dispatched
12
- dispatch(cancelRequestSyncFavorites(0,action.listId));return;}dispatch(requestRemoveFavorites(action.productId,action.listId));}else if(!((_getFavoritesProducts2=getFavoritesProducts(getState()).byList[action.listId])===null||_getFavoritesProducts2===void 0?void 0:_getFavoritesProducts2.isFetching)){// Remove should not be possible when no favorites available
13
- // Refresh to fix inconsistencies, by dispatching an idleSync action when not fetching
14
- dispatch(idleSyncFavorites(action.listId));}});// Catch local limit errors (backend errors are handled autonomously)
15
- subscribe(errorFavoritesLimit$,function(_ref12){var dispatch=_ref12.dispatch;dispatch(showModal({confirm:null,dismiss:'modal.ok',title:'modal.title_error',message:'favorites.error_limit'}));});/**
24
+ */
25
+ export default function favorites(subscribe) {
26
+ if (!appConfig.hasFavorites) {
27
+ return;
28
+ }
29
+
30
+ /** App start */
31
+ subscribe(appDidStart$, async ({
32
+ dispatch,
33
+ getState
34
+ }) => {
35
+ // Setup sync pipeline dependencies (concurrency to each other and themselves)
36
+ pipelineDependencies.set(SHOPGATE_USER_ADD_FAVORITES, [SHOPGATE_USER_ADD_FAVORITES, SHOPGATE_USER_DELETE_FAVORITES]);
37
+ pipelineDependencies.set(SHOPGATE_USER_DELETE_FAVORITES, [SHOPGATE_USER_ADD_FAVORITES, SHOPGATE_USER_DELETE_FAVORITES]);
38
+ const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(getState());
39
+ if (loadWishlistOnAppStartEnabled && makeGetRoutePattern()(getState()) !== FAVORITES_PATH) {
40
+ await dispatch(fetchFavoritesListsWithItems(false));
41
+ }
42
+ });
43
+
44
+ /** Favorites route enter */
45
+ subscribe(favoritesWillEnter$, async ({
46
+ dispatch
47
+ }) => {
48
+ await dispatch(fetchFavoritesListsWithItems(true));
49
+ });
50
+
51
+ /** User login / logout */
52
+ subscribe(shouldFetchFreshFavorites$, async ({
53
+ dispatch
54
+ }) => {
55
+ await dispatch(fetchFavoritesListsWithItems(true));
56
+ });
57
+ subscribe(addProductToFavoritesDebounced$, ({
58
+ action,
59
+ dispatch,
60
+ getState
61
+ }) => {
62
+ const state = getState();
63
+ const wishlistItemQuantityEnabled = getWishlistItemQuantityEnabled(state);
64
+
65
+ // Nothing to do, when the store already contains the item
66
+ const activeProductInList = getFavoritesProducts(state).byList[action.listId]?.items.find(({
67
+ productId
68
+ }) => productId === action.productId);
69
+ if (activeProductInList && !wishlistItemQuantityEnabled) {
70
+ // Call cancel action with "zero" count, because request was even dispatched
71
+ dispatch(cancelRequestSyncFavorites(0, action.listId));
72
+ return;
73
+ }
74
+ const {
75
+ favorites: {
76
+ limit = 100
77
+ } = {}
78
+ } = appConfig;
79
+ const count = makeGetFavoritesCountByList(() => action?.listId)(state);
80
+ // When the getFavorites pipeline is used to fetch favorites, the amount of items is limited
81
+ // since it returns full product entities. Hence adding more items needs to be prevented.
82
+ if (limit && count >= limit && !getUseGetFavoriteIdsPipeline(state)) {
83
+ // Dispatch a local error only, because the request to add is prevented
84
+ const error = new Error('Limit exceeded');
85
+ error.code = FAVORITES_LIMIT_ERROR;
86
+ dispatch(errorFavorites(action.productId, error));
87
+ } else {
88
+ dispatch(requestAddFavorites(action.productId, action.listId, action.quantity, action.notes, action.showToast));
89
+ }
90
+ });
91
+ subscribe(updateProductInFavoritesDebounced$, ({
92
+ action,
93
+ dispatch
94
+ }) => {
95
+ dispatch(requestUpdateFavorites(action.productId, action.listId, action.quantity, action.notes));
96
+ });
97
+ subscribe(removeProductFromFavoritesDebounced$, ({
98
+ action,
99
+ dispatch,
100
+ getState
101
+ }) => {
102
+ const count = getFavoritesCount(getState());
103
+ if (count > 0) {
104
+ if (action.withRelatives) {
105
+ // Will only handle ids which are present in the store, no additional check needed
106
+ const allOnList = makeGetProductRelativesOnFavorites(() => action.listId)(getState(), {
107
+ productId: action.productId
108
+ });
109
+ allOnList.forEach(id => dispatch(requestRemoveFavorites(id, action.listId)));
110
+ return;
111
+ }
112
+
113
+ // Avoids trying to remove something that was already removed (incoming fetch response)
114
+ const list = getFavoritesProducts(getState()).byList[action.listId];
115
+ if (!list?.items.find(({
116
+ productId
117
+ }) => productId === action.productId)) {
118
+ // Call cancel action with "zero" count, because request was even dispatched
119
+ dispatch(cancelRequestSyncFavorites(0, action.listId));
120
+ return;
121
+ }
122
+ dispatch(requestRemoveFavorites(action.productId, action.listId));
123
+ } else if (!getFavoritesProducts(getState()).byList[action.listId]?.isFetching) {
124
+ // Remove should not be possible when no favorites available
125
+ // Refresh to fix inconsistencies, by dispatching an idleSync action when not fetching
126
+ dispatch(idleSyncFavorites(action.listId));
127
+ }
128
+ });
129
+
130
+ // Catch local limit errors (backend errors are handled autonomously)
131
+ subscribe(errorFavoritesLimit$, ({
132
+ dispatch
133
+ }) => {
134
+ dispatch(showModal({
135
+ confirm: null,
136
+ dismiss: 'modal.ok',
137
+ title: 'modal.title_error',
138
+ message: 'favorites.error_limit'
139
+ }));
140
+ });
141
+
142
+ /**
16
143
  * Request after N seconds since last add or remove request to make sure
17
144
  * backend did actually save it
18
- */subscribe(refreshFavorites$,/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref13){var dispatch,action,getState,useGetFavoriteIdsPipeline;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:dispatch=_ref13.dispatch,action=_ref13.action,getState=_ref13.getState;if(!action.listId){_context4.next=5;break;}useGetFavoriteIdsPipeline=getUseGetFavoriteIdsPipeline(getState());if(useGetFavoriteIdsPipeline){dispatch(fetchFavoriteIds(true,action.listId));}else{dispatch(fetchFavorites(true,action.listId));}return _context4.abrupt("return");case 5:_context4.next=7;return dispatch(fetchFavoritesListsWithItems(true));case 7:case"end":return _context4.stop();}},_callee4);}));return function(_x4){return _ref14.apply(this,arguments);};}());/**
145
+ */
146
+ subscribe(refreshFavorites$, async ({
147
+ dispatch,
148
+ action,
149
+ getState
150
+ }) => {
151
+ if (action.listId) {
152
+ const useGetFavoriteIdsPipeline = getUseGetFavoriteIdsPipeline(getState());
153
+ if (useGetFavoriteIdsPipeline) {
154
+ dispatch(fetchFavoriteIds(true, action.listId));
155
+ } else {
156
+ dispatch(fetchFavorites(true, action.listId));
157
+ }
158
+ return;
159
+ }
160
+ await dispatch(fetchFavoritesListsWithItems(true));
161
+ });
162
+
163
+ /**
19
164
  * Takes an action buffer of the request-add, request-remove and request-update favorites actions
20
165
  * and triggers Pipeline requests for all of them. Errors are handled autonomously.
21
166
  * After all pipeline requests are done it resets the favorite page's state to "idle".
22
- */subscribe(didReceiveFlushFavoritesBuffer$,/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(actionBuffer){var dispatch,actions,actionsByListAndProduct,idleLists;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1)switch(_context6.prev=_context6.next){case 0:if(!(!Array.isArray(actionBuffer)||!actionBuffer.length)){_context6.next=2;break;}return _context6.abrupt("return");case 2:LoadingProvider.setLoading(FAVORITES_PATH);// All actions provide the same functionality, just take the first entry
23
- dispatch=actionBuffer[0].dispatch;// Group all buffered actions by listId and productID
24
- actions=actionBuffer.map(function(_ref16){var action=_ref16.action;return action;});actionsByListAndProduct=groupBy(actions,function(_ref17){var listId=_ref17.listId,productId=_ref17.productId;return"".concat(listId,"-").concat(productId,"}");});idleLists=[];_context6.next=9;return Object.values(actionsByListAndProduct).forEach(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(groupedActions){var _groupedActions,_groupedActions$,_groupedActions$2,productId,listId,quantity,notes,showToast,updateActions,addActions,removeActions,_updateActions$slice3,_updateActions$slice4,lastUpdateAction,addRemoveBalance;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:_groupedActions=_slicedToArray(groupedActions,1),_groupedActions$=_groupedActions[0],_groupedActions$2=_groupedActions$===void 0?{}:_groupedActions$,productId=_groupedActions$2.productId,listId=_groupedActions$2.listId,quantity=_groupedActions$2.quantity,notes=_groupedActions$2.notes,showToast=_groupedActions$2.showToast;updateActions=groupedActions.filter(function(action){return action.type===REQUEST_UPDATE_FAVORITES;});addActions=groupedActions.filter(function(action){return action.type===REQUEST_ADD_FAVORITES;});removeActions=groupedActions.filter(function(action){return action.type===REQUEST_REMOVE_FAVORITES;});_context5.prev=4;if(!(updateActions.length>0)){_context5.next=9;break;}_updateActions$slice3=updateActions.slice(-1),_updateActions$slice4=_slicedToArray(_updateActions$slice3,1),lastUpdateAction=_updateActions$slice4[0];_context5.next=9;return dispatch(updateFavorites(lastUpdateAction.productId,lastUpdateAction.listId,lastUpdateAction.quantity,lastUpdateAction.notes));case 9:// Sum up all adds and removes, based on sum dispatch add / remove
25
- addRemoveBalance=addActions.length-removeActions.length;if(!(addRemoveBalance>0)){_context5.next=13;break;}_context5.next=13;return dispatch(addFavorites(productId,listId,quantity,notes,showToast));case 13:if(!(addRemoveBalance<0)){_context5.next=16;break;}_context5.next=16;return dispatch(removeFavorites(productId,listId,quantity,notes));case 16:if(!(updateActions.length===0&&addRemoveBalance===0)){_context5.next=20;break;}dispatch(cancelRequestSyncFavorites(groupedActions.length,listId));_context5.next=24;break;case 20:if(idleLists.includes(listId)){_context5.next=24;break;}idleLists.push(listId);_context5.next=24;return dispatch(idleSyncFavorites(listId));case 24:_context5.next=32;break;case 26:_context5.prev=26;_context5.t0=_context5["catch"](4);if(idleLists.includes(listId)){_context5.next=32;break;}idleLists.push(listId);_context5.next=32;return dispatch(idleSyncFavorites(listId));case 32:case"end":return _context5.stop();}},_callee5,null,[[4,26]]);}));return function(_x6){return _ref18.apply(this,arguments);};}());case 9:case"end":return _context6.stop();}},_callee6);}));return function(_x5){return _ref15.apply(this,arguments);};}());subscribe(favoritesSyncIdle$,function(){LoadingProvider.resetLoading(FAVORITES_PATH);});subscribe(addProductToFavorites$,function(_ref19){var events=_ref19.events,getState=_ref19.getState,action=_ref19.action;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is disabled, toast is shown instantly after the add
26
- // action was dispatched. We don't have to wait for the "debounced" action, since
27
- // removal of wishlist items is not possible.
28
- if(!loadWishlistOnAppStartEnabled&&(action===null||action===void 0?void 0:action.showToast)!==false){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});subscribe(favoritesDidAddItem$,function(_ref20){var events=_ref20.events,getState=_ref20.getState,action=_ref20.action;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is enabled, toast is shown after the add action from
29
- // the buffer system is dispatched. We wait for that since the item might have been removed
30
- // again within the debounce time.
31
- if(loadWishlistOnAppStartEnabled&&(action===null||action===void 0?void 0:action.showToast)!==false){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});}
167
+ */
168
+ subscribe(didReceiveFlushFavoritesBuffer$, async actionBuffer => {
169
+ // This subscription handles bulk actions only
170
+ if (!Array.isArray(actionBuffer) || !actionBuffer.length) {
171
+ return;
172
+ }
173
+ LoadingProvider.setLoading(FAVORITES_PATH);
174
+
175
+ // All actions provide the same functionality, just take the first entry
176
+ const {
177
+ dispatch
178
+ } = actionBuffer[0];
179
+
180
+ // Group all buffered actions by listId and productID
181
+ const actions = actionBuffer.map(({
182
+ action
183
+ }) => action);
184
+ const actionsByListAndProduct = groupBy(actions, ({
185
+ listId,
186
+ productId
187
+ }) => `${listId}-${productId}}`);
188
+ const idleLists = [];
189
+ await Object.values(actionsByListAndProduct).forEach(async groupedActions => {
190
+ const [{
191
+ productId,
192
+ listId,
193
+ quantity,
194
+ notes,
195
+ showToast
196
+ } = {}] = groupedActions;
197
+ const updateActions = groupedActions.filter(action => action.type === REQUEST_UPDATE_FAVORITES);
198
+ const addActions = groupedActions.filter(action => action.type === REQUEST_ADD_FAVORITES);
199
+ const removeActions = groupedActions.filter(action => action.type === REQUEST_REMOVE_FAVORITES);
200
+ try {
201
+ // If there are any update actions we only dispatch the last one
202
+ if (updateActions.length > 0) {
203
+ const [lastUpdateAction] = updateActions.slice(-1);
204
+ await dispatch(updateFavorites(lastUpdateAction.productId, lastUpdateAction.listId, lastUpdateAction.quantity, lastUpdateAction.notes));
205
+ }
206
+
207
+ // Sum up all adds and removes, based on sum dispatch add / remove
208
+ const addRemoveBalance = addActions.length - removeActions.length;
209
+ if (addRemoveBalance > 0) {
210
+ await dispatch(addFavorites(productId, listId, quantity, notes, showToast));
211
+ }
212
+ if (addRemoveBalance < 0) {
213
+ await dispatch(removeFavorites(productId, listId, quantity, notes));
214
+ }
215
+ if (updateActions.length === 0 && addRemoveBalance === 0) {
216
+ dispatch(cancelRequestSyncFavorites(groupedActions.length, listId));
217
+ } else if (!idleLists.includes(listId)) {
218
+ idleLists.push(listId);
219
+ await dispatch(idleSyncFavorites(listId));
220
+ }
221
+ } catch (error) {
222
+ if (!idleLists.includes(listId)) {
223
+ idleLists.push(listId);
224
+ await dispatch(idleSyncFavorites(listId));
225
+ }
226
+ }
227
+ });
228
+ });
229
+ subscribe(favoritesSyncIdle$, () => {
230
+ LoadingProvider.resetLoading(FAVORITES_PATH);
231
+ });
232
+ subscribe(addProductToFavorites$, ({
233
+ events,
234
+ getState,
235
+ action
236
+ }) => {
237
+ const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(getState());
238
+
239
+ // When wish list loading on app start is disabled, toast is shown instantly after the add
240
+ // action was dispatched. We don't have to wait for the "debounced" action, since
241
+ // removal of wishlist items is not possible.
242
+ if (!loadWishlistOnAppStartEnabled && action?.showToast !== false) {
243
+ events.emit(ToastProvider.ADD, {
244
+ id: 'favorites.added',
245
+ message: 'favorites.added'
246
+ });
247
+ }
248
+ });
249
+ subscribe(favoritesDidAddItem$, ({
250
+ events,
251
+ getState,
252
+ action
253
+ }) => {
254
+ const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(getState());
255
+
256
+ // When wish list loading on app start is enabled, toast is shown after the add action from
257
+ // the buffer system is dispatched. We wait for that since the item might have been removed
258
+ // again within the debounce time.
259
+ if (loadWishlistOnAppStartEnabled && action?.showToast !== false) {
260
+ events.emit(ToastProvider.ADD, {
261
+ id: 'favorites.added',
262
+ message: 'favorites.added'
263
+ });
264
+ }
265
+ });
266
+ }