@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,6 +1,78 @@
1
- import{produce}from'immer';import{RECEIVE_FAVORITES_LISTS,SUCCESS_ADD_FAVORITES_LIST,SUCCESS_UPDATE_FAVORITES_LIST,SUCCESS_REMOVE_FAVORITES_LIST,OPEN_FAVORITE_LIST_CHOOSER,CLOSE_FAVORITE_LIST_CHOOSER,FAVORITES_LIFETIME,OPEN_FAVORITE_COMMENT_DIALOG,CLOSE_FAVORITE_COMMENT_DIALOG}from"../constants";/**
1
+ import { produce } from 'immer';
2
+ import { RECEIVE_FAVORITES_LISTS, SUCCESS_ADD_FAVORITES_LIST, SUCCESS_UPDATE_FAVORITES_LIST, SUCCESS_REMOVE_FAVORITES_LIST, OPEN_FAVORITE_LIST_CHOOSER, CLOSE_FAVORITE_LIST_CHOOSER, FAVORITES_LIFETIME, OPEN_FAVORITE_COMMENT_DIALOG, CLOSE_FAVORITE_COMMENT_DIALOG } from "../constants";
3
+
4
+ /**
2
5
  * Favorites lists reducer.
3
6
  * @param {Object} state Current state.
4
7
  * @param {Object} action Dispatched action.
5
8
  * @returns {Object} New state.
6
- */var lists=function lists(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{expires:0,lists:[],chooser:null,commentDialog:null};var action=arguments.length>1?arguments[1]:undefined;/* eslint-disable no-param-reassign */var newState=produce(state,function(draft){switch(action.type){case OPEN_FAVORITE_LIST_CHOOSER:{draft.chooser={productId:action.productId,withRelatives:action.withRelatives};break;}case CLOSE_FAVORITE_LIST_CHOOSER:{draft.chooser=null;break;}case OPEN_FAVORITE_COMMENT_DIALOG:{draft.commentDialog={productId:action.productId,listId:action.listId};break;}case CLOSE_FAVORITE_COMMENT_DIALOG:{draft.commentDialog=null;break;}case RECEIVE_FAVORITES_LISTS:{draft.expires=Date.now()+FAVORITES_LIFETIME;draft.lists=action.favoritesLists;break;}case SUCCESS_ADD_FAVORITES_LIST:{draft.lists.push({id:action.listId,name:action.name});break;}case SUCCESS_UPDATE_FAVORITES_LIST:{var list=draft.lists.find(function(l){return l.id===action.listId;});list.name=action.name;break;}case SUCCESS_REMOVE_FAVORITES_LIST:{var listIndex=draft.lists.findIndex(function(l){return l.id===action.listId;});draft.lists.splice(listIndex,1);break;}default:break;}});/* eslint-enable no-param-reassign */return newState;};export default lists;
9
+ */
10
+ const lists = (state = {
11
+ expires: 0,
12
+ lists: [],
13
+ chooser: null,
14
+ commentDialog: null
15
+ }, action) => {
16
+ /* eslint-disable no-param-reassign */
17
+ const newState = produce(state, draft => {
18
+ switch (action.type) {
19
+ case OPEN_FAVORITE_LIST_CHOOSER:
20
+ {
21
+ draft.chooser = {
22
+ productId: action.productId,
23
+ withRelatives: action.withRelatives
24
+ };
25
+ break;
26
+ }
27
+ case CLOSE_FAVORITE_LIST_CHOOSER:
28
+ {
29
+ draft.chooser = null;
30
+ break;
31
+ }
32
+ case OPEN_FAVORITE_COMMENT_DIALOG:
33
+ {
34
+ draft.commentDialog = {
35
+ productId: action.productId,
36
+ listId: action.listId
37
+ };
38
+ break;
39
+ }
40
+ case CLOSE_FAVORITE_COMMENT_DIALOG:
41
+ {
42
+ draft.commentDialog = null;
43
+ break;
44
+ }
45
+ case RECEIVE_FAVORITES_LISTS:
46
+ {
47
+ draft.expires = Date.now() + FAVORITES_LIFETIME;
48
+ draft.lists = action.favoritesLists;
49
+ break;
50
+ }
51
+ case SUCCESS_ADD_FAVORITES_LIST:
52
+ {
53
+ draft.lists.push({
54
+ id: action.listId,
55
+ name: action.name
56
+ });
57
+ break;
58
+ }
59
+ case SUCCESS_UPDATE_FAVORITES_LIST:
60
+ {
61
+ const list = draft.lists.find(l => l.id === action.listId);
62
+ list.name = action.name;
63
+ break;
64
+ }
65
+ case SUCCESS_REMOVE_FAVORITES_LIST:
66
+ {
67
+ const listIndex = draft.lists.findIndex(l => l.id === action.listId);
68
+ draft.lists.splice(listIndex, 1);
69
+ break;
70
+ }
71
+ default:
72
+ break;
73
+ }
74
+ });
75
+ /* eslint-enable no-param-reassign */
76
+ return newState;
77
+ };
78
+ export default lists;
@@ -1,28 +1,235 @@
1
- import{produce}from'immer';import isNumber from'lodash/isNumber';import isString from'lodash/isString';import{REQUEST_ADD_FAVORITES,SUCCESS_ADD_FAVORITES,CANCEL_REQUEST_SYNC_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,SUCCESS_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,REQUEST_FAVORITES,ERROR_FETCH_FAVORITES,SUCCESS_REMOVE_FAVORITES_LIST,SUCCESS_ADD_FAVORITES_LIST,RECEIVE_FAVORITES,FAVORITES_LIFETIME,SUCCESS_UPDATE_FAVORITES,REQUEST_UPDATE_FAVORITES,ERROR_UPDATE_FAVORITES,RECEIVE_FAVORITES_LISTS}from"../constants";/**
1
+ import { produce } from 'immer';
2
+ import isNumber from 'lodash/isNumber';
3
+ import isString from 'lodash/isString';
4
+ import { REQUEST_ADD_FAVORITES, SUCCESS_ADD_FAVORITES, CANCEL_REQUEST_SYNC_FAVORITES, ERROR_ADD_FAVORITES, REQUEST_REMOVE_FAVORITES, SUCCESS_REMOVE_FAVORITES, ERROR_REMOVE_FAVORITES, REQUEST_FAVORITES, ERROR_FETCH_FAVORITES, SUCCESS_REMOVE_FAVORITES_LIST, SUCCESS_ADD_FAVORITES_LIST, RECEIVE_FAVORITES, FAVORITES_LIFETIME, SUCCESS_UPDATE_FAVORITES, REQUEST_UPDATE_FAVORITES, ERROR_UPDATE_FAVORITES, RECEIVE_FAVORITES_LISTS } from "../constants";
5
+
6
+ /**
2
7
  * Favorites reducer.
3
8
  * @param {Object} state Current state.
4
9
  * @param {Object} action Dispatched action.
5
10
  * @returns {Object} New state.
6
- */var products=function products(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{byList:{}};var action=arguments.length>1?arguments[1]:undefined;/* eslint-disable no-param-reassign */var producedState=produce(state,function(draft){switch(action.type){// Handle a new favorites request.
7
- case REQUEST_FAVORITES:{var existingList=draft.byList[action.listId];if(!existingList){draft.byList[action.listId]={isFetching:true,lastChange:0,lastFetch:0,expires:0,items:[],syncCount:0};return;}existingList.isFetching=true;existingList.expires=0;break;}// Handle incoming favorite products.
8
- case RECEIVE_FAVORITES:{var list=draft.byList[action.listId];var isSynching=list.syncCount>0;var isOngoing=state.lastChange>action.requestTimestamp;/**
9
- * Note: When favorites are received, an add or remove request can be in progress. In this
10
- * case only fetching state will be updated and the received data will be discarded.
11
- * A new fetch request will be queued as soon as the sync is done, which will recover
12
- * discarded data.
13
- */list.isFetching=false;if(list.ready&&(isSynching||isOngoing)){return;}list.expires=Date.now()+FAVORITES_LIFETIME;list.items=action.items.map(function(_ref){var quantity=_ref.quantity,notes=_ref.notes,product=_ref.product;return{quantity:quantity,notes:notes,productId:product.id};});list.ready=true;// `syncCount` stays untouched because this is not considered to be a sync.
14
- break;}// Handle failed fetching
15
- case ERROR_FETCH_FAVORITES:{var _list=draft.byList[action.listId];_list.isFetching=false;_list.expires=0;_list.ready=true;// `syncCount` stays untouched because this is not considered to be a sync.
16
- break;}// Handle adding favorite list products.
17
- case REQUEST_ADD_FAVORITES:{var _list2=draft.byList[action.listId];var matchingItem=_list2.items.find(function(_ref2){var productId=_ref2.productId;return productId===action.productId;});if(matchingItem){matchingItem.notes=typeof action.notes==='string'?action.notes:matchingItem.notes;matchingItem.quantity=typeof action.quantity==='number'?matchingItem.quantity+action.quantity:matchingItem.quantity+1;}else{_list2.items.push({notes:action.notes||'',quantity:action.quantity||1,productId:action.productId});}_list2.lastChange=Date.now();_list2.syncCount+=1;break;}case REQUEST_UPDATE_FAVORITES:{var _list3=draft.byList[action.listId];var _matchingItem=_list3.items.find(function(_ref3){var productId=_ref3.productId;return productId===action.productId;});if(_matchingItem){if(isNumber(action.quantity)){_matchingItem.quantity=action.quantity;}if(isString(action.notes)){_matchingItem.notes=action.notes;}_list3.lastChange=Date.now();_list3.syncCount+=1;}break;}// Handle removing favorite list products.
18
- case REQUEST_REMOVE_FAVORITES:{var _list4=draft.byList[action.listId];var matchingItemIndex=_list4.items.findIndex(function(_ref4){var productId=_ref4.productId;return productId===action.productId;});if(matchingItemIndex>-1){_list4.items.splice(matchingItemIndex,1);}_list4.lastChange=Date.now();_list4.syncCount+=1;break;}// Handle cancellation of synchronization.
19
- // Sync count needs to be updated, when an add or a remove favorites action is cancelled
20
- // This recovers from invalid sync states when a backend call is detected to be redundant
21
- case CANCEL_REQUEST_SYNC_FAVORITES:{var _list5=draft.byList[action.listId];_list5.syncCount-=action.count;break;}// Handle success of adding favorite list products.
22
- case SUCCESS_ADD_FAVORITES:case SUCCESS_UPDATE_FAVORITES:case SUCCESS_REMOVE_FAVORITES:{var _list6=draft.byList[action.listId];_list6.lastChange=Date.now();_list6.syncCount-=1;break;}// Handle deletion failure by adding the product back in to the list.
23
- case ERROR_REMOVE_FAVORITES:{var _list7=draft.byList[action.listId];_list7.items.push({productId:action.productId,quantity:action.quantity||1,notes:action.notes||''});_list7.lastChange=Date.now();_list7.syncCount-=1;break;}// Handle adding failure by removing the product from the list.
24
- case ERROR_ADD_FAVORITES:{var _list8=draft.byList[action.listId];var _matchingItemIndex=_list8.items.findIndex(function(_ref5){var productId=_ref5.productId;return productId===action.productId;});if(_matchingItemIndex>-1){_list8.items.splice(_matchingItemIndex,1);}_list8.lastChange=Date.now();_list8.syncCount-=1;break;}case ERROR_UPDATE_FAVORITES:{var _list9=draft.byList[action.listId];_list9.lastChange=Date.now();_list9.syncCount-=1;break;}// Handle cleanup after deletion of a list.
25
- case SUCCESS_REMOVE_FAVORITES_LIST:{delete draft.byList[action.listId];break;}// Handle adding new lists.
26
- case SUCCESS_ADD_FAVORITES_LIST:{draft.byList[action.listId]={isFetching:true,lastChange:0,lastFetch:0,expires:0,items:[],syncCount:0,ready:true};break;}// Handle cleanup after lists are updated
27
- case RECEIVE_FAVORITES_LISTS:{var listIds=action.favoritesLists.map(function(_ref6){var id=_ref6.id;return id;});Object.keys(draft.byList).forEach(function(id){if(!listIds.includes(id)){// Remove list items that don't have a list anymore
28
- delete draft.byList[id];}});break;}default:break;}});/* eslint-enable no-param-reassign */return producedState;};export default products;
11
+ */
12
+ const products = (state = {
13
+ byList: {}
14
+ }, action) => {
15
+ /* eslint-disable no-param-reassign */
16
+ const producedState = produce(state, draft => {
17
+ switch (action.type) {
18
+ // Handle a new favorites request.
19
+ case REQUEST_FAVORITES:
20
+ {
21
+ const existingList = draft.byList[action.listId];
22
+ if (!existingList) {
23
+ draft.byList[action.listId] = {
24
+ isFetching: true,
25
+ lastChange: 0,
26
+ lastFetch: 0,
27
+ expires: 0,
28
+ items: [],
29
+ syncCount: 0
30
+ };
31
+ return;
32
+ }
33
+ existingList.isFetching = true;
34
+ existingList.expires = 0;
35
+ break;
36
+ }
37
+
38
+ // Handle incoming favorite products.
39
+ case RECEIVE_FAVORITES:
40
+ {
41
+ const list = draft.byList[action.listId];
42
+ const isSynching = list.syncCount > 0;
43
+ const isOngoing = state.lastChange > action.requestTimestamp;
44
+
45
+ /**
46
+ * Note: When favorites are received, an add or remove request can be in progress. In this
47
+ * case only fetching state will be updated and the received data will be discarded.
48
+ * A new fetch request will be queued as soon as the sync is done, which will recover
49
+ * discarded data.
50
+ */
51
+ list.isFetching = false;
52
+ if (list.ready && (isSynching || isOngoing)) {
53
+ return;
54
+ }
55
+ list.expires = Date.now() + FAVORITES_LIFETIME;
56
+ list.items = action.items.map(({
57
+ quantity,
58
+ notes,
59
+ product
60
+ }) => ({
61
+ quantity,
62
+ notes,
63
+ productId: product.id
64
+ }));
65
+ list.ready = true;
66
+ // `syncCount` stays untouched because this is not considered to be a sync.
67
+ break;
68
+ }
69
+
70
+ // Handle failed fetching
71
+ case ERROR_FETCH_FAVORITES:
72
+ {
73
+ const list = draft.byList[action.listId];
74
+ list.isFetching = false;
75
+ list.expires = 0;
76
+ list.ready = true;
77
+ // `syncCount` stays untouched because this is not considered to be a sync.
78
+ break;
79
+ }
80
+
81
+ // Handle adding favorite list products.
82
+ case REQUEST_ADD_FAVORITES:
83
+ {
84
+ const list = draft.byList[action.listId];
85
+ const matchingItem = list.items.find(({
86
+ productId
87
+ }) => productId === action.productId);
88
+ if (matchingItem) {
89
+ matchingItem.notes = typeof action.notes === 'string' ? action.notes : matchingItem.notes;
90
+ matchingItem.quantity = typeof action.quantity === 'number' ? matchingItem.quantity + action.quantity : matchingItem.quantity + 1;
91
+ } else {
92
+ list.items.push({
93
+ notes: action.notes || '',
94
+ quantity: action.quantity || 1,
95
+ productId: action.productId
96
+ });
97
+ }
98
+ list.lastChange = Date.now();
99
+ list.syncCount += 1;
100
+ break;
101
+ }
102
+ case REQUEST_UPDATE_FAVORITES:
103
+ {
104
+ const list = draft.byList[action.listId];
105
+ const matchingItem = list.items.find(({
106
+ productId
107
+ }) => productId === action.productId);
108
+ if (matchingItem) {
109
+ if (isNumber(action.quantity)) {
110
+ matchingItem.quantity = action.quantity;
111
+ }
112
+ if (isString(action.notes)) {
113
+ matchingItem.notes = action.notes;
114
+ }
115
+ list.lastChange = Date.now();
116
+ list.syncCount += 1;
117
+ }
118
+ break;
119
+ }
120
+
121
+ // Handle removing favorite list products.
122
+ case REQUEST_REMOVE_FAVORITES:
123
+ {
124
+ const list = draft.byList[action.listId];
125
+ const matchingItemIndex = list.items.findIndex(({
126
+ productId
127
+ }) => productId === action.productId);
128
+ if (matchingItemIndex > -1) {
129
+ list.items.splice(matchingItemIndex, 1);
130
+ }
131
+ list.lastChange = Date.now();
132
+ list.syncCount += 1;
133
+ break;
134
+ }
135
+ // Handle cancellation of synchronization.
136
+ // Sync count needs to be updated, when an add or a remove favorites action is cancelled
137
+ // This recovers from invalid sync states when a backend call is detected to be redundant
138
+ case CANCEL_REQUEST_SYNC_FAVORITES:
139
+ {
140
+ const list = draft.byList[action.listId];
141
+ list.syncCount -= action.count;
142
+ break;
143
+ }
144
+
145
+ // Handle success of adding favorite list products.
146
+ case SUCCESS_ADD_FAVORITES:
147
+ case SUCCESS_UPDATE_FAVORITES:
148
+ case SUCCESS_REMOVE_FAVORITES:
149
+ {
150
+ const list = draft.byList[action.listId];
151
+ list.lastChange = Date.now();
152
+ list.syncCount -= 1;
153
+ break;
154
+ }
155
+
156
+ // Handle deletion failure by adding the product back in to the list.
157
+ case ERROR_REMOVE_FAVORITES:
158
+ {
159
+ const list = draft.byList[action.listId];
160
+ list.items.push({
161
+ productId: action.productId,
162
+ quantity: action.quantity || 1,
163
+ notes: action.notes || ''
164
+ });
165
+ list.lastChange = Date.now();
166
+ list.syncCount -= 1;
167
+ break;
168
+ }
169
+
170
+ // Handle adding failure by removing the product from the list.
171
+ case ERROR_ADD_FAVORITES:
172
+ {
173
+ const list = draft.byList[action.listId];
174
+ const matchingItemIndex = list.items.findIndex(({
175
+ productId
176
+ }) => productId === action.productId);
177
+ if (matchingItemIndex > -1) {
178
+ list.items.splice(matchingItemIndex, 1);
179
+ }
180
+ list.lastChange = Date.now();
181
+ list.syncCount -= 1;
182
+ break;
183
+ }
184
+ case ERROR_UPDATE_FAVORITES:
185
+ {
186
+ const list = draft.byList[action.listId];
187
+ list.lastChange = Date.now();
188
+ list.syncCount -= 1;
189
+ break;
190
+ }
191
+
192
+ // Handle cleanup after deletion of a list.
193
+ case SUCCESS_REMOVE_FAVORITES_LIST:
194
+ {
195
+ delete draft.byList[action.listId];
196
+ break;
197
+ }
198
+
199
+ // Handle adding new lists.
200
+ case SUCCESS_ADD_FAVORITES_LIST:
201
+ {
202
+ draft.byList[action.listId] = {
203
+ isFetching: true,
204
+ lastChange: 0,
205
+ lastFetch: 0,
206
+ expires: 0,
207
+ items: [],
208
+ syncCount: 0,
209
+ ready: true
210
+ };
211
+ break;
212
+ }
213
+
214
+ // Handle cleanup after lists are updated
215
+ case RECEIVE_FAVORITES_LISTS:
216
+ {
217
+ const listIds = action.favoritesLists.map(({
218
+ id
219
+ }) => id);
220
+ Object.keys(draft.byList).forEach(id => {
221
+ if (!listIds.includes(id)) {
222
+ // Remove list items that don't have a list anymore
223
+ delete draft.byList[id];
224
+ }
225
+ });
226
+ break;
227
+ }
228
+ default:
229
+ break;
230
+ }
231
+ });
232
+ /* eslint-enable no-param-reassign */
233
+ return producedState;
234
+ };
235
+ export default products;
@@ -1,95 +1,259 @@
1
- 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);}import{createSelector}from'reselect';import uniq from'lodash/uniq';import appConfig from'@shopgate/pwa-common/helpers/config';import{hasNewServices}from'@shopgate/engage/core/helpers';import{getProducts,getProductId}from"../../product/selectors/product";import{getKnownRelatives}from"../../product/selectors/variants";var defaultIds=[];/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { createSelector } from 'reselect';
3
+ import uniq from 'lodash/uniq';
4
+ import appConfig from '@shopgate/pwa-common/helpers/config';
5
+ import { hasNewServices } from '@shopgate/engage/core/helpers';
6
+ import { getProducts, getProductId } from "../../product/selectors/product";
7
+ import { getKnownRelatives } from "../../product/selectors/variants";
8
+ const defaultIds = [];
9
+
10
+ /**
2
11
  * @param {Object} state The global state.
3
12
  * @return {Object}
4
- */export var getFavoritesState=function getFavoritesState(state){return state.favorites||{};};/**
13
+ */
14
+ export const getFavoritesState = state => state.favorites || {};
15
+
16
+ /**
5
17
  * @param {Object} state The global state.
6
18
  * @return {Object}
7
- */export var getFavoritesListState=function getFavoritesListState(state){var _state$favorites;return((_state$favorites=state.favorites)===null||_state$favorites===void 0?void 0:_state$favorites.lists)||{};};/**
19
+ */
20
+ export const getFavoritesListState = state => state.favorites?.lists || {};
21
+
22
+ /**
8
23
  * Returns a list of available wishlists to the user.
9
24
  * @param {Object} state The global state.
10
25
  * @return {Object}
11
- */export var getFavoritesLists=function getFavoritesLists(state){var _getFavoritesListStat;return((_getFavoritesListStat=getFavoritesListState(state))===null||_getFavoritesListStat===void 0?void 0:_getFavoritesListStat.lists)||[];};/**
26
+ */
27
+ export const getFavoritesLists = state => getFavoritesListState(state)?.lists || [];
28
+
29
+ /**
12
30
  * @param {Object} state The global state.
13
31
  * @return {Object|null}
14
- */export var getFavoritesProducts=createSelector(getFavoritesState,function(state){if(!state.products){return null;}return state.products;});export var getFavoritesDefaultList=createSelector(getFavoritesLists,function(lists){var _lists$find;return(_lists$find=lists.find(function(list){return list.id==='DEFAULT';}))!==null&&_lists$find!==void 0?_lists$find:{id:'DEFAULT'};});export var hasMultipleFavoritesList=createSelector(getFavoritesLists,function(lists){return lists.length>1;});/**
32
+ */
33
+ export const getFavoritesProducts = createSelector(getFavoritesState, state => {
34
+ if (!state.products) {
35
+ return null;
36
+ }
37
+ return state.products;
38
+ });
39
+ export const getFavoritesDefaultList = createSelector(getFavoritesLists, lists => lists.find(list => list.id === 'DEFAULT') ?? {
40
+ id: 'DEFAULT'
41
+ });
42
+ export const hasMultipleFavoritesList = createSelector(getFavoritesLists, lists => lists.length > 1);
43
+
44
+ /**
15
45
  * A selector that gets the id of the favorites list by the given name
16
46
  * @param {Object} state The current application state.
17
47
  * @param {Object} props The component props.
18
48
  * @returns {string} the id of the favorites list
19
- */export var getFavoritesListIdByName=createSelector(getFavoritesLists,function(state,props){return props.listName;},function(favLists,listName){var _ref=favLists.find(function(list){return list.name===listName;})||{},id=_ref.id;return id;});/**
49
+ */
50
+ export const getFavoritesListIdByName = createSelector(getFavoritesLists, (state, props) => props.listName, (favLists, listName) => {
51
+ const {
52
+ id
53
+ } = favLists.find(list => list.name === listName) || {};
54
+ return id;
55
+ });
56
+
57
+ /**
20
58
  * @param {Object} state The global state.
21
59
  * @returns {Array}
22
60
  * @deprecated
23
- */export var getFavoritesProductsIds=createSelector(getFavoritesProducts,function(products){if(!products||!products.byList){return defaultIds;}return uniq(Object.values(products.byList).map(function(l){return l.items.map(function(_ref2){var productId=_ref2.productId;return productId;});}).flat());});/**
61
+ */
62
+ export const getFavoritesProductsIds = createSelector(getFavoritesProducts, products => {
63
+ if (!products || !products.byList) {
64
+ return defaultIds;
65
+ }
66
+ return uniq(Object.values(products.byList).map(l => l.items.map(({
67
+ productId
68
+ }) => productId)).flat());
69
+ });
70
+
71
+ /**
24
72
  * @param {Object} state The global state.
25
73
  * @deprecated
26
- */export var getFavorites=createSelector(getFavoritesProductsIds,getProducts,function(productIds,products){return productIds.filter(function(id){return!!products[id]&&products[id].productData;}).map(function(id){return products[id].productData;});});/**
74
+ */
75
+ export const getFavorites = createSelector(getFavoritesProductsIds, getProducts, (productIds, products) => productIds.filter(id => !!products[id] && products[id].productData).map(id => products[id].productData));
76
+
77
+ /**
27
78
  * Creates a selector that selects all ids that belong
28
79
  * to the given favorite list.
29
80
  * @param {Function} getListCode Selects the list code.
30
81
  * @returns {Function}
31
- */export var makeGetFavoritesIdsByList=function makeGetFavoritesIdsByList(getListCode){return createSelector(getFavoritesProducts,getListCode,function(favProducts,listId){var _favProducts$byList$l;return(favProducts===null||favProducts===void 0?void 0:(_favProducts$byList$l=favProducts.byList[listId])===null||_favProducts$byList$l===void 0?void 0:_favProducts$byList$l.items.map(function(_ref3){var productId=_ref3.productId;return productId;}))||[];});};/**
82
+ */
83
+ export const makeGetFavoritesIdsByList = getListCode => createSelector(getFavoritesProducts, getListCode, (favProducts, listId) => favProducts?.byList[listId]?.items.map(({
84
+ productId
85
+ }) => productId) || []);
86
+
87
+ /**
32
88
  * Creates a selector that selects all products that belong
33
89
  * to the given favorite list.
34
90
  * @param {Function} getListCode Selects the list code.
35
91
  * @returns {Function}
36
- */export var makeGetFavorites=function makeGetFavorites(getListCode){return createSelector(getFavoritesProducts,getListCode,getProducts,function(favItems,listId,products){var _favItems$byList$list;var items=(favItems===null||favItems===void 0?void 0:(_favItems$byList$list=favItems.byList[listId])===null||_favItems$byList$list===void 0?void 0:_favItems$byList$list.items)||[];return items.map(function(item){var _products$item$produc;return _extends({},item,{product:(_products$item$produc=products[item.productId])===null||_products$item$produc===void 0?void 0:_products$item$produc.productData});});});};/**
92
+ */
93
+ export const makeGetFavorites = getListCode => createSelector(getFavoritesProducts, getListCode, getProducts, (favItems, listId, products) => {
94
+ const items = favItems?.byList[listId]?.items || [];
95
+ return items.map(item => ({
96
+ ...item,
97
+ product: products[item.productId]?.productData
98
+ }));
99
+ });
100
+
101
+ /**
37
102
  * Creates a selector that retrieves the amount of items on a specific favorites list
38
103
  * to the given favorite list.
39
104
  * @param {Function} getListCode Selects the list code.
40
105
  * @returns {Function}
41
- */export var makeGetFavoritesCountByList=function makeGetFavoritesCountByList(getListCode){var getFavoritesIdsByList=makeGetFavoritesIdsByList(getListCode);return createSelector(getFavoritesIdsByList,function(favorites){return favorites.length;});};/**
106
+ */
107
+ export const makeGetFavoritesCountByList = getListCode => {
108
+ const getFavoritesIdsByList = makeGetFavoritesIdsByList(getListCode);
109
+ return createSelector(getFavoritesIdsByList, favorites => favorites.length);
110
+ };
111
+
112
+ /**
42
113
  * True when favorites where not yet fetched for the first time.
43
114
  * @param {Object} state The global state.
44
115
  * @returns {boolean}
45
- */export var isInitialLoading=createSelector(getFavoritesProducts,function(products){if(!products){return true;}return!Object.values(products===null||products===void 0?void 0:products.byList).every(function(l){return l.ready;});});/**
116
+ */
117
+ export const isInitialLoading = createSelector(getFavoritesProducts, products => {
118
+ if (!products) {
119
+ return true;
120
+ }
121
+ return !Object.values(products?.byList).every(l => l.ready);
122
+ });
123
+
124
+ /**
46
125
  * @param {Object} state The global state.
47
126
  * @param {Object} props The selector props
48
127
  * @param {boolean} [props.useItemQuantity=false] Whether to consider item quantity at calculation
49
128
  * @return {Function}
50
- */export var getFavoritesCount=createSelector(getFavoritesProducts,function(_,props){return(props===null||props===void 0?void 0:props.useItemQuantity)||false;},function(products,useItemQuantity){if(!(products===null||products===void 0?void 0:products.byList)){return 0;}return Object.values(products.byList).reduce(function(prev,list){return prev+list.items.reduce(function(acc,_ref4){var _ref4$quantity=_ref4.quantity,quantity=_ref4$quantity===void 0?1:_ref4$quantity;if(useItemQuantity){return acc+quantity;}return acc+1;},0);},0);});/**
129
+ */
130
+ export const getFavoritesCount = createSelector(getFavoritesProducts, (_, props) => props?.useItemQuantity || false, (products, useItemQuantity) => {
131
+ if (!products?.byList) {
132
+ return 0;
133
+ }
134
+ return Object.values(products.byList).reduce((prev, list) => prev + list.items.reduce((acc, {
135
+ quantity = 1
136
+ }) => {
137
+ if (useItemQuantity) {
138
+ return acc + quantity;
139
+ }
140
+ return acc + 1;
141
+ }, 0), 0);
142
+ });
143
+
144
+ /**
51
145
  * @param {Object} state The global state.
52
146
  * @return {boolean}
53
- */export var hasFavorites=createSelector(getFavoritesCount,function(count){return!!count;});/**
147
+ */
148
+ export const hasFavorites = createSelector(getFavoritesCount, count => !!count);
149
+
150
+ /**
54
151
  * @param {Object} state The global state.
55
152
  * @return {boolean}
56
- */export var isFetching=createSelector(getFavoritesProducts,function(products){if(!products){return false;}return Object.values(products.byList).some(function(l){return l.isFetching;});});/**
153
+ */
154
+ export const isFetching = createSelector(getFavoritesProducts, products => {
155
+ if (!products) {
156
+ return false;
157
+ }
158
+ return Object.values(products.byList).some(l => l.isFetching);
159
+ });
160
+
161
+ /**
57
162
  * @param {Function} getProductCode Reads the product id.
58
163
  * @param {Function} getListCode Reads the list id.
59
164
  * @return {boolean}
60
- */export var makeIsProductOnSpecificFavoriteList=function makeIsProductOnSpecificFavoriteList(getProductCode,getListCode){return createSelector(getProductCode,getListCode,getFavoritesProducts,function(productId,listId,products){var _products$byList$list;return!!((_products$byList$list=products.byList[listId])===null||_products$byList$list===void 0?void 0:_products$byList$list.items.some(function(_ref5){var itemProductId=_ref5.productId;return itemProductId===productId;}));});};/**
165
+ */
166
+ export const makeIsProductOnSpecificFavoriteList = (getProductCode, getListCode) => createSelector(getProductCode, getListCode, getFavoritesProducts, (productId, listId, products) => !!products.byList[listId]?.items.some(({
167
+ productId: itemProductId
168
+ }) => itemProductId === productId));
169
+
170
+ /**
61
171
  * @param {Function} getProductCode Reads the product id.
62
172
  * @return {boolean}
63
- */export var makeIsProductOnFavoriteList=function makeIsProductOnFavoriteList(getProductCode){return createSelector(getProductCode,getFavoritesProducts,function(productId,products){return!!Object.values(products.byList).find(function(list){var _list$items;return!!(list===null||list===void 0?void 0:(_list$items=list.items)===null||_list$items===void 0?void 0:_list$items.find(function(_ref6){var itemProductId=_ref6.productId;return itemProductId===productId;}));});});};/**
173
+ */
174
+ export const makeIsProductOnFavoriteList = getProductCode => createSelector(getProductCode, getFavoritesProducts, (productId, products) => !!Object.values(products.byList).find(list => !!list?.items?.find(({
175
+ productId: itemProductId
176
+ }) => itemProductId === productId)));
177
+ /**
64
178
  * @param {Object} state The global state.
65
179
  * @return {boolean}
66
- */export var isCurrentProductOnFavoriteList=makeIsProductOnFavoriteList(getProductId);/**
180
+ */
181
+ export const isCurrentProductOnFavoriteList = makeIsProductOnFavoriteList(getProductId);
182
+
183
+ /**
67
184
  * Returns all relatives which are on favorites.
68
185
  * @param {Object} state Current state.
69
186
  * @param {string} productId
70
187
  * @returns {Array}
71
- */export var getProductRelativesOnFavorites=createSelector(getKnownRelatives,getFavoritesProducts,function(productRelativesIds,products){return productRelativesIds.filter(function(id){return!!Object.values(products.byList).find(function(list){return!!list.items.find(function(_ref7){var productId=_ref7.productId;return id===productId;});});});});/**
188
+ */
189
+ export const getProductRelativesOnFavorites = createSelector(getKnownRelatives, getFavoritesProducts, (productRelativesIds, products) => productRelativesIds.filter(id => !!Object.values(products.byList).find(list => !!list.items.find(({
190
+ productId
191
+ }) => id === productId))));
192
+
193
+ /**
72
194
  * Returns all relatives which are on a specific favorites list.
73
195
  * @param {Function} getListCode Gets the list code.
74
196
  * @returns {Function}
75
- */export var makeGetProductRelativesOnFavorites=function makeGetProductRelativesOnFavorites(getListCode){return createSelector(getListCode,getKnownRelatives,getFavoritesProducts,function(listId,productRelativesIds,products){return productRelativesIds.filter(function(id){var _products$byList$list2;return(_products$byList$list2=products.byList[listId])===null||_products$byList$list2===void 0?void 0:_products$byList$list2.items.map(function(_ref8){var productId=_ref8.productId;return productId;}).find(function(p){return id===p;});});});};/**
197
+ */
198
+ export const makeGetProductRelativesOnFavorites = getListCode => createSelector(getListCode, getKnownRelatives, getFavoritesProducts, (listId, productRelativesIds, products) => productRelativesIds.filter(id => products.byList[listId]?.items.map(({
199
+ productId
200
+ }) => productId).find(p => id === p)));
201
+
202
+ /**
76
203
  * Checks if product or any relative is on favorites list.
77
204
  * @param {Object} state Current state.
78
205
  * @param {string} productId Product id.
79
206
  * @return {boolean}
80
- */export var isRelativeProductOnList=createSelector(getProductRelativesOnFavorites,function(relativesOnFavorites){return relativesOnFavorites.length>0;});export var getCommentDialogSettings=createSelector(getFavoritesListState,getFavoritesProducts,getProducts,function(_ref9,favItems,products){var _favItems$byList$list2,_products$item$produc2;var commentDialog=_ref9.commentDialog;var _ref10=commentDialog||{},listId=_ref10.listId,productId=_ref10.productId;if(!listId||!productId){return undefined;}var items=((_favItems$byList$list2=favItems.byList[listId])===null||_favItems$byList$list2===void 0?void 0:_favItems$byList$list2.items)||[];var item=items.find(function(_ref11){var itemProductId=_ref11.productId;return productId===itemProductId;});if(!item){return undefined;}return{listId:listId,productId:productId,item:item,product:(_products$item$produc2=products[item.productId])===null||_products$item$produc2===void 0?void 0:_products$item$produc2.productData};});/**
207
+ */
208
+ export const isRelativeProductOnList = createSelector(getProductRelativesOnFavorites, relativesOnFavorites => relativesOnFavorites.length > 0);
209
+ export const getCommentDialogSettings = createSelector(getFavoritesListState, getFavoritesProducts, getProducts, ({
210
+ commentDialog
211
+ }, favItems, products) => {
212
+ const {
213
+ listId,
214
+ productId
215
+ } = commentDialog || {};
216
+ if (!listId || !productId) {
217
+ return undefined;
218
+ }
219
+ const items = favItems.byList[listId]?.items || [];
220
+ const item = items.find(({
221
+ productId: itemProductId
222
+ }) => productId === itemProductId);
223
+ if (!item) {
224
+ return undefined;
225
+ }
226
+ return {
227
+ listId,
228
+ productId,
229
+ item,
230
+ product: products[item.productId]?.productData
231
+ };
232
+ });
233
+
234
+ /**
81
235
  * Creates a selector that selects all products that belong
82
236
  * to the given favorite list.
83
237
  * @param {Function} getListCode Callback that's supposed to return a favorites list code
84
238
  * @returns {Function}
85
- */export var makeGetFavoritesProductsByList=function makeGetFavoritesProductsByList(getListCode){return createSelector(getFavoritesProducts,getListCode,function(favProducts,listId){var products=favProducts.byList[listId]||{};return products;});};/**
239
+ */
240
+ export const makeGetFavoritesProductsByList = getListCode => createSelector(getFavoritesProducts, getListCode, (favProducts, listId) => {
241
+ const products = favProducts.byList[listId] || {};
242
+ return products;
243
+ });
244
+
245
+ /**
86
246
  * Creates a selector to check if the app has support for multiple favorites list.
87
247
  * @returns {Function}
88
- */export var getHasMultipleFavoritesListsSupport=function getHasMultipleFavoritesListsSupport(){var _appConfig$favoritesM;return hasNewServices()||(appConfig===null||appConfig===void 0?void 0:(_appConfig$favoritesM=appConfig.favoritesMode)===null||_appConfig$favoritesM===void 0?void 0:_appConfig$favoritesM.hasMultipleFavoritesLists);};/**
248
+ */
249
+ export const getHasMultipleFavoritesListsSupport = () => hasNewServices() || appConfig?.favoritesMode?.hasMultipleFavoritesLists;
250
+
251
+ /**
89
252
  * Creates a selector the determine if the PWA is supposed to fetch favorite list entries via the
90
253
  * "getFavoriteIds" pipeline instead of "getFavorites".
91
254
  *
92
255
  * This pipeline was introduced in PWA6 when support for more than 100 items per favorite list was
93
256
  * requested. PWA-1877
94
257
  * @returns {Function}
95
- */export var getUseGetFavoriteIdsPipeline=function getUseGetFavoriteIdsPipeline(){return!hasNewServices();};
258
+ */
259
+ export const getUseGetFavoriteIdsPipeline = () => !hasNewServices();