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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/cart/action-creators/addCouponsToCart.js +9 -2
  2. package/cart/action-creators/addProductsToCart.js +9 -2
  3. package/cart/action-creators/deleteCouponsFromCart.js +9 -2
  4. package/cart/action-creators/deleteProductsFromCart.js +9 -2
  5. package/cart/action-creators/errorAddCouponsToCart.js +10 -2
  6. package/cart/action-creators/errorAddProductsToCart.js +10 -2
  7. package/cart/action-creators/errorCart.js +8 -2
  8. package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
  9. package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
  10. package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
  11. package/cart/action-creators/receiveCart.js +9 -2
  12. package/cart/action-creators/requestCart.js +8 -2
  13. package/cart/action-creators/setCartProductPendingCount.js +9 -2
  14. package/cart/action-creators/setCouponFieldError.js +9 -2
  15. package/cart/action-creators/setCouponFieldValue.js +9 -2
  16. package/cart/action-creators/setFulfillmentSlot.js +9 -2
  17. package/cart/action-creators/successAddCouponsToCart.js +10 -2
  18. package/cart/action-creators/successAddProductsToCart.js +8 -2
  19. package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
  20. package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
  21. package/cart/action-creators/successUpdateProductsInCart.js +8 -2
  22. package/cart/action-creators/updateProductsInCart.js +9 -2
  23. package/cart/actions/addCouponsToCart.js +52 -8
  24. package/cart/actions/addProductsToCart.js +80 -11
  25. package/cart/actions/deleteCouponsFromCart.js +39 -6
  26. package/cart/actions/deleteProductsFromCart.js +38 -6
  27. package/cart/actions/fetchCart.js +52 -8
  28. package/cart/actions/updateProductsInCart.js +44 -6
  29. package/cart/constants/PipelineErrors.js +6 -1
  30. package/cart/constants/Pipelines.js +6 -1
  31. package/cart/constants/Portals.js +85 -1
  32. package/cart/constants/index.js +39 -2
  33. package/cart/helpers/config.js +47 -2
  34. package/cart/helpers/createPipelineErrorList.js +30 -4
  35. package/cart/helpers/fulfillmentSlots.js +37 -4
  36. package/cart/helpers/index.js +14 -3
  37. package/cart/helpers/quantity.js +23 -4
  38. package/cart/helpers/shipping.js +57 -2
  39. package/cart/helpers/tax.js +26 -2
  40. package/cart/index.js +25 -5
  41. package/cart/mock.js +130 -1
  42. package/cart/reducers/couponField.js +30 -2
  43. package/cart/reducers/data.js +98 -6
  44. package/cart/reducers/index.js +7 -1
  45. package/cart/selectors/index.js +181 -31
  46. package/cart/selectors/spec.js +189 -2
  47. package/cart/streams/index.js +176 -29
  48. package/cart/subscriptions/index.js +307 -30
  49. package/category/action-creators/errorCategory.js +10 -2
  50. package/category/action-creators/errorCategoryChildren.js +9 -2
  51. package/category/action-creators/errorRootCategories.js +8 -2
  52. package/category/action-creators/receiveCategory.js +12 -2
  53. package/category/action-creators/receiveCategoryChildren.js +10 -2
  54. package/category/action-creators/receiveRootCategories.js +9 -2
  55. package/category/action-creators/requestCategory.js +9 -2
  56. package/category/action-creators/requestCategoryChildren.js +9 -2
  57. package/category/action-creators/requestRootCategories.js +8 -2
  58. package/category/actions/fetchCategory.js +47 -5
  59. package/category/actions/fetchCategoryChildren.js +30 -2
  60. package/category/actions/fetchCategoryOrRootCategories.js +16 -2
  61. package/category/actions/fetchCategoryProducts.js +36 -2
  62. package/category/actions/fetchRootCategories.js +31 -2
  63. package/category/actions/getCategory.js +10 -2
  64. package/category/constants/Pipelines.js +3 -1
  65. package/category/constants/Portals.js +56 -3
  66. package/category/constants/index.js +17 -2
  67. package/category/helpers/index.js +27 -3
  68. package/category/index.js +19 -5
  69. package/category/mock.js +176 -1
  70. package/category/reducers/categoriesById.js +65 -3
  71. package/category/reducers/childrenByCategoryId.js +55 -4
  72. package/category/reducers/helpers/handleCategoryCollection.js +24 -3
  73. package/category/reducers/helpers/handleReceivedCategories.js +3 -1
  74. package/category/reducers/index.js +12 -2
  75. package/category/reducers/rootCategories.js +31 -2
  76. package/category/selectors/index.js +115 -16
  77. package/category/streams/index.js +82 -4
  78. package/category/subscriptions/index.js +96 -3
  79. package/checkout/action-creators/successCheckout.js +9 -2
  80. package/checkout/actions/fetchCheckoutUrl.js +28 -3
  81. package/checkout/constants/Pipelines.js +1 -1
  82. package/checkout/constants/index.js +3 -2
  83. package/checkout/index.js +11 -4
  84. package/checkout/selectors/index.js +7 -2
  85. package/checkout/streams/index.js +8 -2
  86. package/checkout/subscriptions/index.js +35 -6
  87. package/favorites/action-creators/index.js +206 -24
  88. package/favorites/actions/addFavorites.js +41 -3
  89. package/favorites/actions/addFavoritesList.js +27 -2
  90. package/favorites/actions/fetchFavoriteIds.js +49 -5
  91. package/favorites/actions/fetchFavorites.js +60 -5
  92. package/favorites/actions/fetchFavoritesList.js +47 -3
  93. package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
  94. package/favorites/actions/getFavorites.js +6 -2
  95. package/favorites/actions/removeFavorites.js +32 -3
  96. package/favorites/actions/removeFavoritesList.js +24 -2
  97. package/favorites/actions/toggleFavorites.js +68 -10
  98. package/favorites/actions/updateFavorites.js +39 -3
  99. package/favorites/actions/updateFavoritesList.js +26 -2
  100. package/favorites/constants/Pipelines.js +9 -1
  101. package/favorites/constants/Portals.js +32 -4
  102. package/favorites/constants/index.js +37 -5
  103. package/favorites/index.js +14 -4
  104. package/favorites/mock.js +89 -4
  105. package/favorites/reducers/index.js +7 -1
  106. package/favorites/reducers/lists.js +74 -2
  107. package/favorites/reducers/products.js +231 -24
  108. package/favorites/selectors/index.js +188 -24
  109. package/favorites/streams/index.js +135 -23
  110. package/favorites/streams/spec.js +517 -8
  111. package/favorites/subscriptions/index.js +260 -25
  112. package/favorites/subscriptions/spec.js +701 -28
  113. package/filter/action-creators/errorFilters.js +9 -2
  114. package/filter/action-creators/index.js +4 -1
  115. package/filter/action-creators/receiveFilters.js +10 -2
  116. package/filter/action-creators/requestFilters.js +9 -2
  117. package/filter/action-creators/updateFilters.js +8 -2
  118. package/filter/actions/fetchFilters.js +46 -3
  119. package/filter/actions/getFilters.js +6 -2
  120. package/filter/actions/helpers/buildFilterParams.js +34 -2
  121. package/filter/actions/helpers/buildRequestFilters.js +35 -2
  122. package/filter/actions/helpers/processFilters.js +10 -2
  123. package/filter/actions/helpers/processParams.js +26 -2
  124. package/filter/constants/Pipelines.js +1 -1
  125. package/filter/constants/Portals.js +39 -3
  126. package/filter/constants/index.js +8 -1
  127. package/filter/index.js +12 -4
  128. package/filter/reducers/helpers/enrichFilters.js +11 -3
  129. package/filter/reducers/index.js +5 -1
  130. package/filter/reducers/resultsByHash.js +43 -3
  131. package/filter/selectors/index.js +47 -6
  132. package/filter/streams/index.js +30 -1
  133. package/filter/subscriptions/index.js +34 -2
  134. package/market/constants/Portals.js +22 -4
  135. package/market/constants/index.js +2 -1
  136. package/market/helpers/showReturnPolicy.js +3 -1
  137. package/market/helpers/showTaxDisclaimer.js +3 -1
  138. package/market/index.js +6 -2
  139. package/orders/constants.js +2 -1
  140. package/package.json +3 -3
  141. package/product/action-creators/deleteProductsByIds.js +10 -2
  142. package/product/action-creators/errorProduct.js +10 -2
  143. package/product/action-creators/errorProductDescription.js +10 -2
  144. package/product/action-creators/errorProductImages.js +10 -2
  145. package/product/action-creators/errorProductMedia.js +10 -2
  146. package/product/action-creators/errorProductOptions.js +10 -2
  147. package/product/action-creators/errorProductProperties.js +10 -2
  148. package/product/action-creators/errorProductRelations.js +9 -2
  149. package/product/action-creators/errorProductShipping.js +10 -2
  150. package/product/action-creators/errorProductVariants.js +10 -2
  151. package/product/action-creators/errorProducts.js +9 -2
  152. package/product/action-creators/expireProductById.js +10 -2
  153. package/product/action-creators/expireProductData.js +11 -2
  154. package/product/action-creators/expireProductsByHash.js +9 -2
  155. package/product/action-creators/productNotAvailable.js +10 -2
  156. package/product/action-creators/provideProduct.js +9 -2
  157. package/product/action-creators/receiveProduct.js +10 -2
  158. package/product/action-creators/receiveProductCached.js +9 -2
  159. package/product/action-creators/receiveProductDescription.js +10 -2
  160. package/product/action-creators/receiveProductImages.js +10 -2
  161. package/product/action-creators/receiveProductMedia.js +10 -2
  162. package/product/action-creators/receiveProductOptions.js +10 -2
  163. package/product/action-creators/receiveProductProperties.js +10 -2
  164. package/product/action-creators/receiveProductRelations.js +12 -2
  165. package/product/action-creators/receiveProductShipping.js +10 -2
  166. package/product/action-creators/receiveProductVariants.js +10 -2
  167. package/product/action-creators/receiveProducts.js +16 -2
  168. package/product/action-creators/receiveProductsCached.js +9 -2
  169. package/product/action-creators/refreshExpiredPDPData.js +8 -2
  170. package/product/action-creators/requestProduct.js +10 -2
  171. package/product/action-creators/requestProductDescription.js +9 -2
  172. package/product/action-creators/requestProductImages.js +9 -2
  173. package/product/action-creators/requestProductMedia.js +9 -2
  174. package/product/action-creators/requestProductOptions.js +9 -2
  175. package/product/action-creators/requestProductProperties.js +9 -2
  176. package/product/action-creators/requestProductRelations.js +10 -2
  177. package/product/action-creators/requestProductShipping.js +9 -2
  178. package/product/action-creators/requestProductVariants.js +9 -2
  179. package/product/action-creators/requestProducts.js +9 -2
  180. package/product/action-creators/setProductId.js +9 -2
  181. package/product/action-creators/setProductQuantity.js +9 -2
  182. package/product/action-creators/setProductVariantId.js +9 -2
  183. package/product/actions/changeSortOrder.js +21 -2
  184. package/product/actions/fetchHighlightProducts.js +18 -2
  185. package/product/actions/fetchLiveshoppingProducts.js +14 -2
  186. package/product/actions/fetchProduct.js +52 -3
  187. package/product/actions/fetchProductDescription.js +30 -2
  188. package/product/actions/fetchProductImages.js +31 -2
  189. package/product/actions/fetchProductMedia.js +35 -2
  190. package/product/actions/fetchProductOptions.js +31 -2
  191. package/product/actions/fetchProductProperties.js +30 -2
  192. package/product/actions/fetchProductRelations.js +63 -2
  193. package/product/actions/fetchProductShipping.js +31 -2
  194. package/product/actions/fetchProductVariants.js +31 -2
  195. package/product/actions/fetchProducts.js +189 -17
  196. package/product/actions/fetchProductsById.js +68 -8
  197. package/product/actions/fetchProductsByQuery.js +102 -18
  198. package/product/actions/getHighlightProducts.js +6 -2
  199. package/product/actions/getLiveshoppingProducts.js +6 -2
  200. package/product/actions/getProduct.js +6 -2
  201. package/product/actions/getProductDescription.js +6 -2
  202. package/product/actions/getProductImages.js +6 -2
  203. package/product/actions/getProductOptions.js +6 -2
  204. package/product/actions/getProductProperties.js +6 -2
  205. package/product/actions/getProductRelations.js +6 -2
  206. package/product/actions/getProductShipping.js +6 -2
  207. package/product/actions/getProductVariants.js +6 -2
  208. package/product/actions/getProducts.js +6 -2
  209. package/product/actions/getProductsById.js +6 -2
  210. package/product/actions/getProductsByQuery.js +6 -2
  211. package/product/actions/processProductFlags.js +35 -3
  212. package/product/actions/updateMetadata.js +17 -2
  213. package/product/collections/ProductImageFormats.js +48 -8
  214. package/product/collections/index.js +1 -1
  215. package/product/constants/Pipelines.js +12 -1
  216. package/product/constants/Portals.js +200 -33
  217. package/product/constants/index.js +90 -18
  218. package/product/helpers/index.js +61 -8
  219. package/product/index.js +36 -6
  220. package/product/mock.js +1002 -2
  221. package/product/reducers/descriptionsByProductId.js +54 -5
  222. package/product/reducers/helpers/formatOptions.js +17 -2
  223. package/product/reducers/helpers/handleProductCollection.js +19 -2
  224. package/product/reducers/imagesByProductId.js +51 -4
  225. package/product/reducers/index.js +23 -1
  226. package/product/reducers/mediaByProductId.js +55 -3
  227. package/product/reducers/optionsByProductId.js +41 -2
  228. package/product/reducers/productRelationsByHash.js +43 -2
  229. package/product/reducers/productsById.js +122 -7
  230. package/product/reducers/propertiesByProductId.js +48 -2
  231. package/product/reducers/resultsByHash.js +125 -9
  232. package/product/reducers/shippingByProductId.js +37 -2
  233. package/product/reducers/variantsByProductId.js +56 -2
  234. package/product/selectors/options.js +90 -13
  235. package/product/selectors/page.js +62 -13
  236. package/product/selectors/price.js +81 -18
  237. package/product/selectors/product.js +549 -59
  238. package/product/selectors/product.mock.js +327 -12
  239. package/product/selectors/relations.js +35 -5
  240. package/product/selectors/variants.js +91 -15
  241. package/product/streams/index.js +167 -13
  242. package/product/subscriptions/index.js +210 -4
  243. package/reviews/action-creators/errorProductReviews.js +9 -2
  244. package/reviews/action-creators/errorReviews.js +9 -2
  245. package/reviews/action-creators/errorSubmitReview.js +9 -2
  246. package/reviews/action-creators/errorUserReview.js +9 -2
  247. package/reviews/action-creators/flushUserReview.js +8 -2
  248. package/reviews/action-creators/receiveProductReviews.js +11 -2
  249. package/reviews/action-creators/receiveReviews.js +12 -2
  250. package/reviews/action-creators/receiveSubmitReview.js +9 -2
  251. package/reviews/action-creators/receiveUserReview.js +10 -2
  252. package/reviews/action-creators/requestProductReviews.js +10 -2
  253. package/reviews/action-creators/requestReviews.js +9 -2
  254. package/reviews/action-creators/requestSubmitReview.js +9 -2
  255. package/reviews/action-creators/requestUserReview.js +9 -2
  256. package/reviews/action-creators/resetSubmittedReview.js +9 -2
  257. package/reviews/action-creators/spec.js +40 -1
  258. package/reviews/actions/fetchProductReviews.js +37 -2
  259. package/reviews/actions/fetchReviews.js +38 -2
  260. package/reviews/actions/fetchUserReview.js +31 -2
  261. package/reviews/actions/flushUserReview.js +5 -1
  262. package/reviews/actions/getProductReviews.js +6 -2
  263. package/reviews/actions/getUserReview.js +6 -2
  264. package/reviews/actions/spec.js +241 -4
  265. package/reviews/actions/submitReview.js +63 -3
  266. package/reviews/constants/Pipelines.js +4 -1
  267. package/reviews/constants/Portals.js +4 -1
  268. package/reviews/constants/index.js +26 -7
  269. package/reviews/index.js +15 -4
  270. package/reviews/mock.js +172 -11
  271. package/reviews/reducers/index.js +11 -1
  272. package/reviews/reducers/mock.js +14 -2
  273. package/reviews/reducers/reviewsByHash.js +52 -6
  274. package/reviews/reducers/reviewsById.js +27 -2
  275. package/reviews/reducers/reviewsByProductId.js +47 -2
  276. package/reviews/reducers/spec.js +211 -2
  277. package/reviews/reducers/userReviewsByProductId.js +68 -2
  278. package/reviews/selectors/index.js +123 -19
  279. package/reviews/selectors/mock.js +100 -1
  280. package/reviews/selectors/spec.js +100 -1
  281. package/reviews/streams/index.js +37 -5
  282. package/reviews/streams/spec.js +25 -1
  283. package/reviews/subscriptions/index.js +27 -2
  284. package/scanner/action-creators/errorHandleScanner.js +11 -2
  285. package/scanner/action-creators/scannerFinished.js +11 -2
  286. package/scanner/action-creators/startScanner.js +8 -2
  287. package/scanner/action-creators/successHandleScanner.js +11 -2
  288. package/scanner/actions/handleBarCode.js +22 -2
  289. package/scanner/actions/handleNoResults.js +23 -2
  290. package/scanner/actions/handleQrCode.js +116 -6
  291. package/scanner/actions/handleSearch.js +33 -2
  292. package/scanner/constants/Portals.js +22 -1
  293. package/scanner/constants/index.js +17 -1
  294. package/scanner/helpers/index.js +115 -5
  295. package/scanner/index.js +19 -5
  296. package/scanner/streams/index.js +36 -1
  297. package/scanner/subscriptions/index.js +78 -8
  298. package/search/action-creators/errorSearchResults.js +10 -2
  299. package/search/action-creators/receiveSearchResults.js +11 -2
  300. package/search/action-creators/receiveSearchSuggestions.js +10 -2
  301. package/search/action-creators/requestSearchResults.js +10 -2
  302. package/search/action-creators/requestSearchSuggestions.js +9 -2
  303. package/search/actions/fetchSearchResults.js +66 -8
  304. package/search/actions/fetchSearchSuggestions.js +36 -2
  305. package/search/constants/Pipelines.js +1 -1
  306. package/search/constants/Portals.js +9 -2
  307. package/search/constants/index.js +10 -2
  308. package/search/helpers/index.js +5 -2
  309. package/search/helpers/removeHighlightingPlaceholders.js +4 -1
  310. package/search/helpers/spec.js +19 -1
  311. package/search/index.js +17 -5
  312. package/search/reducers/index.js +38 -2
  313. package/search/selectors/index.js +23 -4
  314. package/search/streams/index.js +51 -3
  315. package/search/subscriptions/index.js +132 -5
@@ -1,9 +1,58 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{PRODUCT_LIFETIME,REQUEST_PRODUCT_DESCRIPTION,RECEIVE_PRODUCT_DESCRIPTION,ERROR_PRODUCT_DESCRIPTION,EXPIRE_PRODUCT_DATA}from"../constants";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { PRODUCT_LIFETIME, REQUEST_PRODUCT_DESCRIPTION, RECEIVE_PRODUCT_DESCRIPTION, ERROR_PRODUCT_DESCRIPTION, EXPIRE_PRODUCT_DATA } from "../constants";
3
+
4
+ /**
2
5
  * Stores product descriptions by their product ID.
3
6
  * @param {Object} [state={}] The current state.
4
7
  * @param {Object} action The action object.
5
8
  * @return {Object} The new state.
6
- */export default function descriptionsByProductId(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_PRODUCT_DESCRIPTION:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:true,expires:0})));case RECEIVE_PRODUCT_DESCRIPTION:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{description:action.description,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME})));case ERROR_PRODUCT_DESCRIPTION:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:false})));// Mark all product descriptions as expired when action is dispatched with
7
- // the "description" scope
8
- case EXPIRE_PRODUCT_DATA:{if(Array.isArray(action.scopes)&&action.scopes.includes('description')){// Expire all descriptions
9
- return Object.keys(state).reduce(function(acc,productId){acc[productId]=_extends({},state[productId],{expires:0});return acc;},{});}return state;}default:return state;}}
9
+ */
10
+ export default function descriptionsByProductId(state = {}, action) {
11
+ switch (action.type) {
12
+ case REQUEST_PRODUCT_DESCRIPTION:
13
+ return {
14
+ ...state,
15
+ [action.productId]: {
16
+ ...state[action.productId],
17
+ isFetching: true,
18
+ expires: 0
19
+ }
20
+ };
21
+ case RECEIVE_PRODUCT_DESCRIPTION:
22
+ return {
23
+ ...state,
24
+ [action.productId]: {
25
+ ...state[action.productId],
26
+ description: action.description,
27
+ isFetching: false,
28
+ expires: Date.now() + PRODUCT_LIFETIME
29
+ }
30
+ };
31
+ case ERROR_PRODUCT_DESCRIPTION:
32
+ return {
33
+ ...state,
34
+ [action.productId]: {
35
+ ...state[action.productId],
36
+ isFetching: false
37
+ }
38
+ };
39
+ // Mark all product descriptions as expired when action is dispatched with
40
+ // the "description" scope
41
+ case EXPIRE_PRODUCT_DATA:
42
+ {
43
+ if (Array.isArray(action.scopes) && action.scopes.includes('description')) {
44
+ // Expire all descriptions
45
+ return Object.keys(state).reduce((acc, productId) => {
46
+ acc[productId] = {
47
+ ...state[productId],
48
+ expires: 0
49
+ };
50
+ return acc;
51
+ }, {});
52
+ }
53
+ return state;
54
+ }
55
+ default:
56
+ return state;
57
+ }
58
+ }
@@ -1,5 +1,20 @@
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{OPTION_TYPE_TEXT}from"../../constants";/**
1
+ import { OPTION_TYPE_TEXT } from "../../constants";
2
+
3
+ /**
2
4
  * Formats the options from the API to a format our frontend needs.
3
5
  * @param {Object} options Product options
4
6
  * @return {Array} The formatted options
5
- */var formatOptions=function formatOptions(options){return options.map(function(option){return _extends({},option,{},option.values&&{values:option.values.map(function(value){return _extends({},value,{unitPriceModifier:value.unitPriceModifier||0});})},{},option.type===OPTION_TYPE_TEXT&&{unitPriceModifier:option.unitPriceModifier||0});});};export default formatOptions;
7
+ */
8
+ const formatOptions = options => options.map(option => ({
9
+ ...option,
10
+ ...(option.values && {
11
+ values: option.values.map(value => ({
12
+ ...value,
13
+ unitPriceModifier: value.unitPriceModifier || 0
14
+ }))
15
+ }),
16
+ ...(option.type === OPTION_TYPE_TEXT && {
17
+ unitPriceModifier: option.unitPriceModifier || 0
18
+ })
19
+ }));
20
+ export default formatOptions;
@@ -1,5 +1,22 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{PRODUCT_LIFETIME}from"../../constants";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { PRODUCT_LIFETIME } from "../../constants";
3
+
4
+ /**
2
5
  * Builds state entries from a collection of products (Array).
3
6
  * @param {Array} products A products collection.
4
7
  * @return {Object} The product entries for the state.
5
- */var handleProductCollection=function handleProductCollection(products){if(!Array.isArray(products)){return{};}return products.reduce(function(currentProducts,productData){return _extends({},currentProducts,_defineProperty({},productData.id,{productData:productData,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME}));},{});};export default handleProductCollection;
8
+ */
9
+ const handleProductCollection = products => {
10
+ if (!Array.isArray(products)) {
11
+ return {};
12
+ }
13
+ return products.reduce((currentProducts, productData) => ({
14
+ ...currentProducts,
15
+ [productData.id]: {
16
+ productData,
17
+ isFetching: false,
18
+ expires: Date.now() + PRODUCT_LIFETIME
19
+ }
20
+ }), {});
21
+ };
22
+ export default handleProductCollection;
@@ -1,8 +1,55 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{PRODUCT_LIFETIME,REQUEST_PRODUCT_IMAGES,RECEIVE_PRODUCT_IMAGES,ERROR_PRODUCT_IMAGES,EXPIRE_PRODUCT_DATA}from"../constants";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { PRODUCT_LIFETIME, REQUEST_PRODUCT_IMAGES, RECEIVE_PRODUCT_IMAGES, ERROR_PRODUCT_IMAGES, EXPIRE_PRODUCT_DATA } from "../constants";
3
+
4
+ /**
2
5
  * Stores product images by product id
3
6
  * @param {Object} state Current state.
4
7
  * @param {Object} action The action object.
5
8
  * @returns {Object}
6
- */export default function imagesByProductId(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_PRODUCT_IMAGES:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:true,expires:0})));case RECEIVE_PRODUCT_IMAGES:return _extends({},state,_defineProperty({},action.productId,{isFetching:false,expires:Date.now()+PRODUCT_LIFETIME,images:action.productImages}));case ERROR_PRODUCT_IMAGES:return _extends({},state,_defineProperty({},action.productId,{isFetching:false}));// Mark all product images as expired when action is dispatched with the "media" scope
7
- case EXPIRE_PRODUCT_DATA:{if(Array.isArray(action.scopes)&&action.scopes.includes('media')){// Expire all descriptions
8
- return Object.keys(state).reduce(function(acc,productId){acc[productId]=_extends({},state[productId],{expires:0});return acc;},{});}return state;}default:return state;}}
9
+ */
10
+ export default function imagesByProductId(state = {}, action) {
11
+ switch (action.type) {
12
+ case REQUEST_PRODUCT_IMAGES:
13
+ return {
14
+ ...state,
15
+ [action.productId]: {
16
+ ...state[action.productId],
17
+ isFetching: true,
18
+ expires: 0
19
+ }
20
+ };
21
+ case RECEIVE_PRODUCT_IMAGES:
22
+ return {
23
+ ...state,
24
+ [action.productId]: {
25
+ isFetching: false,
26
+ expires: Date.now() + PRODUCT_LIFETIME,
27
+ images: action.productImages
28
+ }
29
+ };
30
+ case ERROR_PRODUCT_IMAGES:
31
+ return {
32
+ ...state,
33
+ [action.productId]: {
34
+ isFetching: false
35
+ }
36
+ };
37
+ // Mark all product images as expired when action is dispatched with the "media" scope
38
+ case EXPIRE_PRODUCT_DATA:
39
+ {
40
+ if (Array.isArray(action.scopes) && action.scopes.includes('media')) {
41
+ // Expire all descriptions
42
+ return Object.keys(state).reduce((acc, productId) => {
43
+ acc[productId] = {
44
+ ...state[productId],
45
+ expires: 0
46
+ };
47
+ return acc;
48
+ }, {});
49
+ }
50
+ return state;
51
+ }
52
+ default:
53
+ return state;
54
+ }
55
+ }
@@ -1 +1,23 @@
1
- import{combineReducers}from'redux';import productsById from"./productsById";import imagesByProductId from"./imagesByProductId";import descriptionsByProductId from"./descriptionsByProductId";import propertiesByProductId from"./propertiesByProductId";import shippingByProductId from"./shippingByProductId";import variantsByProductId from"./variantsByProductId";import optionsByProductId from"./optionsByProductId";import resultsByHash from"./resultsByHash";import productRelationsByHash from"./productRelationsByHash";import mediaByProductId from"./mediaByProductId";export default combineReducers({descriptionsByProductId:descriptionsByProductId,imagesByProductId:imagesByProductId,optionsByProductId:optionsByProductId,productRelationsByHash:productRelationsByHash,productsById:productsById,propertiesByProductId:propertiesByProductId,resultsByHash:resultsByHash,shippingByProductId:shippingByProductId,variantsByProductId:variantsByProductId,mediaByProductId:mediaByProductId});
1
+ import { combineReducers } from 'redux';
2
+ import productsById from "./productsById";
3
+ import imagesByProductId from "./imagesByProductId";
4
+ import descriptionsByProductId from "./descriptionsByProductId";
5
+ import propertiesByProductId from "./propertiesByProductId";
6
+ import shippingByProductId from "./shippingByProductId";
7
+ import variantsByProductId from "./variantsByProductId";
8
+ import optionsByProductId from "./optionsByProductId";
9
+ import resultsByHash from "./resultsByHash";
10
+ import productRelationsByHash from "./productRelationsByHash";
11
+ import mediaByProductId from "./mediaByProductId";
12
+ export default combineReducers({
13
+ descriptionsByProductId,
14
+ imagesByProductId,
15
+ optionsByProductId,
16
+ productRelationsByHash,
17
+ productsById,
18
+ propertiesByProductId,
19
+ resultsByHash,
20
+ shippingByProductId,
21
+ variantsByProductId,
22
+ mediaByProductId
23
+ });
@@ -1,7 +1,59 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{PRODUCT_LIFETIME,REQUEST_PRODUCT_MEDIA,RECEIVE_PRODUCT_MEDIA,ERROR_PRODUCT_MEDIA,EXPIRE_PRODUCT_DATA}from"../constants";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { PRODUCT_LIFETIME, REQUEST_PRODUCT_MEDIA, RECEIVE_PRODUCT_MEDIA, ERROR_PRODUCT_MEDIA, EXPIRE_PRODUCT_DATA } from "../constants";
3
+
4
+ /**
2
5
  * Stores product media by the ID of the related parent product.
3
6
  * @param {Object} [state={}] The current state.
4
7
  * @param {Object} action The action object.
5
8
  * @return {Object} The new state.
6
- */export default function mediaByProductId(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_PRODUCT_MEDIA:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:true,expires:0})));case RECEIVE_PRODUCT_MEDIA:{return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{media:action.media,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME})));}case ERROR_PRODUCT_MEDIA:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:false})));// Mark all product media as expired when action is dispatched with the "media" scope
7
- case EXPIRE_PRODUCT_DATA:{if(Array.isArray(action.scopes)&&action.scopes.includes('media')){return Object.keys(state).reduce(function(acc,productId){acc[productId]=_extends({},state[productId],{expires:0});return acc;},{});}return state;}default:return state;}}
9
+ */
10
+ export default function mediaByProductId(state = {}, action) {
11
+ switch (action.type) {
12
+ case REQUEST_PRODUCT_MEDIA:
13
+ return {
14
+ ...state,
15
+ [action.productId]: {
16
+ ...state[action.productId],
17
+ isFetching: true,
18
+ expires: 0
19
+ }
20
+ };
21
+ case RECEIVE_PRODUCT_MEDIA:
22
+ {
23
+ return {
24
+ ...state,
25
+ [action.productId]: {
26
+ ...state[action.productId],
27
+ media: action.media,
28
+ isFetching: false,
29
+ expires: Date.now() + PRODUCT_LIFETIME
30
+ }
31
+ };
32
+ }
33
+ case ERROR_PRODUCT_MEDIA:
34
+ return {
35
+ ...state,
36
+ [action.productId]: {
37
+ ...state[action.productId],
38
+ isFetching: false
39
+ }
40
+ };
41
+
42
+ // Mark all product media as expired when action is dispatched with the "media" scope
43
+ case EXPIRE_PRODUCT_DATA:
44
+ {
45
+ if (Array.isArray(action.scopes) && action.scopes.includes('media')) {
46
+ return Object.keys(state).reduce((acc, productId) => {
47
+ acc[productId] = {
48
+ ...state[productId],
49
+ expires: 0
50
+ };
51
+ return acc;
52
+ }, {});
53
+ }
54
+ return state;
55
+ }
56
+ default:
57
+ return state;
58
+ }
59
+ }
@@ -1,6 +1,45 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{PRODUCT_LIFETIME,REQUEST_PRODUCT_OPTIONS,RECEIVE_PRODUCT_OPTIONS,ERROR_PRODUCT_OPTIONS}from"../constants";import formatOptions from"./helpers/formatOptions";/**
1
+ import { PRODUCT_LIFETIME, REQUEST_PRODUCT_OPTIONS, RECEIVE_PRODUCT_OPTIONS, ERROR_PRODUCT_OPTIONS } from "../constants";
2
+ import formatOptions from "./helpers/formatOptions";
3
+
4
+ /**
2
5
  * Stores product options by the ID of the related parent product.
3
6
  * @param {Object} [state={}] The current state.
4
7
  * @param {Object} action The action object.
5
8
  * @return {Object} The new state.
6
- */export default function optionsByProductId(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_PRODUCT_OPTIONS:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:true,expires:0})));case RECEIVE_PRODUCT_OPTIONS:{var options=formatOptions(action.options);return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{options:options,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME})));}case ERROR_PRODUCT_OPTIONS:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:false})));default:return state;}}
9
+ */
10
+ export default function optionsByProductId(state = {}, action) {
11
+ switch (action.type) {
12
+ case REQUEST_PRODUCT_OPTIONS:
13
+ return {
14
+ ...state,
15
+ [action.productId]: {
16
+ ...state[action.productId],
17
+ isFetching: true,
18
+ expires: 0
19
+ }
20
+ };
21
+ case RECEIVE_PRODUCT_OPTIONS:
22
+ {
23
+ const options = formatOptions(action.options);
24
+ return {
25
+ ...state,
26
+ [action.productId]: {
27
+ ...state[action.productId],
28
+ options,
29
+ isFetching: false,
30
+ expires: Date.now() + PRODUCT_LIFETIME
31
+ }
32
+ };
33
+ }
34
+ case ERROR_PRODUCT_OPTIONS:
35
+ return {
36
+ ...state,
37
+ [action.productId]: {
38
+ ...state[action.productId],
39
+ isFetching: false
40
+ }
41
+ };
42
+ default:
43
+ return state;
44
+ }
45
+ }
@@ -1,6 +1,47 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{REQUEST_PRODUCT_RELATIONS,RECEIVE_PRODUCT_RELATIONS,ERROR_PRODUCT_RELATIONS,PRODUCT_LIFETIME}from"../constants";/**
1
+ import { REQUEST_PRODUCT_RELATIONS, RECEIVE_PRODUCT_RELATIONS, ERROR_PRODUCT_RELATIONS, PRODUCT_LIFETIME } from "../constants";
2
+
3
+ /**
2
4
  * Product relations reducer.
3
5
  * @param {Object} state State.
4
6
  * @param {Object} action Action.
5
7
  * @returns {Object}
6
- */var productRelationsByHash=function productRelationsByHash(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_PRODUCT_RELATIONS:return _extends({},state,_defineProperty({},action.hash,_extends({},state[action.hash],{isFetching:true,expires:0})));case RECEIVE_PRODUCT_RELATIONS:return _extends({},state,_defineProperty({},action.hash,{productIds:action.payload.relations.map(function(product){if(product.productId){return product.productId;}return product.id;}),isFetching:false,expires:Date.now()+PRODUCT_LIFETIME}));case ERROR_PRODUCT_RELATIONS:return _extends({},state,_defineProperty({},action.hash,_extends({},state[action.hash],{isFetching:false,expires:0})));default:return state;}};export default productRelationsByHash;
8
+ */
9
+ const productRelationsByHash = (state = {}, action) => {
10
+ switch (action.type) {
11
+ case REQUEST_PRODUCT_RELATIONS:
12
+ return {
13
+ ...state,
14
+ [action.hash]: {
15
+ ...state[action.hash],
16
+ isFetching: true,
17
+ expires: 0
18
+ }
19
+ };
20
+ case RECEIVE_PRODUCT_RELATIONS:
21
+ return {
22
+ ...state,
23
+ [action.hash]: {
24
+ productIds: action.payload.relations.map(product => {
25
+ if (product.productId) {
26
+ return product.productId;
27
+ }
28
+ return product.id;
29
+ }),
30
+ isFetching: false,
31
+ expires: Date.now() + PRODUCT_LIFETIME
32
+ }
33
+ };
34
+ case ERROR_PRODUCT_RELATIONS:
35
+ return {
36
+ ...state,
37
+ [action.hash]: {
38
+ ...state[action.hash],
39
+ isFetching: false,
40
+ expires: 0
41
+ }
42
+ };
43
+ default:
44
+ return state;
45
+ }
46
+ };
47
+ export default productRelationsByHash;
@@ -1,11 +1,126 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return _typeof(key)==="symbol"?key:String(key);}function _toPrimitive(input,hint){if(_typeof(input)!=="object"||input===null)return input;var prim=input[Symbol.toPrimitive];if(prim!==undefined){var res=prim.call(input,hint||"default");if(_typeof(res)!=="object")return res;throw new TypeError("@@toPrimitive must return a primitive value.");}return(hint==="string"?String:Number)(input);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{ENOTFOUND}from'@shopgate/pwa-core/constants/Pipeline';import{PRODUCT_LIFETIME,REQUEST_PRODUCT,RECEIVE_PRODUCT,RECEIVE_PRODUCTS,ERROR_PRODUCT,UPDATE_METADATA,EXPIRE_PRODUCT_BY_ID,DELETE_PRODUCTS_BY_IDS,RECEIVE_PRODUCT_RELATIONS,EXPIRE_PRODUCT_DATA}from"../constants";import handleProductCollection from"./helpers/handleProductCollection";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { ENOTFOUND } from '@shopgate/pwa-core/constants/Pipeline';
3
+ import { PRODUCT_LIFETIME, REQUEST_PRODUCT, RECEIVE_PRODUCT, RECEIVE_PRODUCTS, ERROR_PRODUCT, UPDATE_METADATA, EXPIRE_PRODUCT_BY_ID, DELETE_PRODUCTS_BY_IDS, RECEIVE_PRODUCT_RELATIONS, EXPIRE_PRODUCT_DATA } from "../constants";
4
+ import handleProductCollection from "./helpers/handleProductCollection";
5
+
6
+ /**
2
7
  * Stores products by their ID.
3
8
  * @param {Object} [state={}] The current state.
4
9
  * @param {Object} action The action object.
5
10
  * @return {Object} The new state.
6
- */export default function productsById(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case RECEIVE_PRODUCTS:return _extends({},state,{},handleProductCollection(action.products));case RECEIVE_PRODUCT_RELATIONS:return _extends({},state,{},handleProductCollection(action.payload.relations));case REQUEST_PRODUCT:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:true,expires:0})));case RECEIVE_PRODUCT:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{productData:action.productData,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME})));case ERROR_PRODUCT:if(action.errorCode===ENOTFOUND){// Remove the entry from the state when noting was found for the productId.
7
- var _action$productId2=action.productId,ignore=state[_action$productId2],rest=_objectWithoutProperties(state,[_action$productId2].map(_toPropertyKey));return rest;}return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:false})));case UPDATE_METADATA:{var _state$action$product2=state[action.productId].productData,productData=_state$action$product2===void 0?{}:_state$action$product2;// Merge the given metadata with the existing metadata.
8
- var metadata=_extends({},productData.metadata,{},action.metadata);// Put the metadata back into the productData.
9
- var updatedProductData=_extends({},productData,{metadata:metadata});// Put the updated product back into the state.
10
- return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{productData:updatedProductData})));}case EXPIRE_PRODUCT_BY_ID:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{expires:0})));// Mark all product data as expired
11
- case EXPIRE_PRODUCT_DATA:{if(Array.isArray(action.scopes)&&action.scopes.includes('price')){return Object.keys(state).reduce(function(accumulator,productId){accumulator[productId]=_extends({},accumulator[productId],{expires:0});return accumulator;},_extends({},state));}return state;}case DELETE_PRODUCTS_BY_IDS:{var nextState=_extends({},state);if(Array.isArray(action===null||action===void 0?void 0:action.productIds)){action.productIds.forEach(function(productId){delete nextState[productId];});}return nextState;}default:return state;}}
11
+ */
12
+ export default function productsById(state = {}, action) {
13
+ switch (action.type) {
14
+ case RECEIVE_PRODUCTS:
15
+ return {
16
+ ...state,
17
+ ...handleProductCollection(action.products)
18
+ };
19
+ case RECEIVE_PRODUCT_RELATIONS:
20
+ return {
21
+ ...state,
22
+ ...handleProductCollection(action.payload.relations)
23
+ };
24
+ case REQUEST_PRODUCT:
25
+ return {
26
+ ...state,
27
+ [action.productId]: {
28
+ ...state[action.productId],
29
+ isFetching: true,
30
+ expires: 0
31
+ }
32
+ };
33
+ case RECEIVE_PRODUCT:
34
+ return {
35
+ ...state,
36
+ [action.productId]: {
37
+ ...state[action.productId],
38
+ productData: action.productData,
39
+ isFetching: false,
40
+ expires: Date.now() + PRODUCT_LIFETIME
41
+ }
42
+ };
43
+ case ERROR_PRODUCT:
44
+ if (action.errorCode === ENOTFOUND) {
45
+ // Remove the entry from the state when noting was found for the productId.
46
+ const {
47
+ [action.productId]: ignore,
48
+ ...rest
49
+ } = state;
50
+ return rest;
51
+ }
52
+ return {
53
+ ...state,
54
+ [action.productId]: {
55
+ ...state[action.productId],
56
+ isFetching: false
57
+ }
58
+ };
59
+ case UPDATE_METADATA:
60
+ {
61
+ const {
62
+ productData = {}
63
+ } = state[action.productId];
64
+
65
+ // Merge the given metadata with the existing metadata.
66
+ const metadata = {
67
+ ...productData.metadata,
68
+ ...action.metadata
69
+ };
70
+
71
+ // Put the metadata back into the productData.
72
+ const updatedProductData = {
73
+ ...productData,
74
+ metadata
75
+ };
76
+
77
+ // Put the updated product back into the state.
78
+ return {
79
+ ...state,
80
+ [action.productId]: {
81
+ ...state[action.productId],
82
+ productData: updatedProductData
83
+ }
84
+ };
85
+ }
86
+ case EXPIRE_PRODUCT_BY_ID:
87
+ return {
88
+ ...state,
89
+ [action.productId]: {
90
+ ...state[action.productId],
91
+ expires: 0
92
+ }
93
+ };
94
+
95
+ // Mark all product data as expired
96
+ case EXPIRE_PRODUCT_DATA:
97
+ {
98
+ if (Array.isArray(action.scopes) && action.scopes.includes('price')) {
99
+ return Object.keys(state).reduce((accumulator, productId) => {
100
+ accumulator[productId] = {
101
+ ...accumulator[productId],
102
+ expires: 0
103
+ };
104
+ return accumulator;
105
+ }, {
106
+ ...state
107
+ });
108
+ }
109
+ return state;
110
+ }
111
+ case DELETE_PRODUCTS_BY_IDS:
112
+ {
113
+ const nextState = {
114
+ ...state
115
+ };
116
+ if (Array.isArray(action?.productIds)) {
117
+ action.productIds.forEach(productId => {
118
+ delete nextState[productId];
119
+ });
120
+ }
121
+ return nextState;
122
+ }
123
+ default:
124
+ return state;
125
+ }
126
+ }
@@ -1,6 +1,52 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{PRODUCT_LIFETIME,REQUEST_PRODUCT_PROPERTIES,RECEIVE_PRODUCT_PROPERTIES,ERROR_PRODUCT_PROPERTIES,EXPIRE_PRODUCT_DATA}from"../constants";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { PRODUCT_LIFETIME, REQUEST_PRODUCT_PROPERTIES, RECEIVE_PRODUCT_PROPERTIES, ERROR_PRODUCT_PROPERTIES, EXPIRE_PRODUCT_DATA } from "../constants";
3
+
4
+ /**
2
5
  * Stores product properties by their product ID.
3
6
  * @param {Object} [state={}] The current state.
4
7
  * @param {Object} action The action object.
5
8
  * @return {Object} The new state.
6
- */export default function propertiesByProductId(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_PRODUCT_PROPERTIES:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:true,expires:0})));case RECEIVE_PRODUCT_PROPERTIES:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{properties:action.properties,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME})));case ERROR_PRODUCT_PROPERTIES:return _extends({},state,_defineProperty({},action.productId,_extends({},state[action.productId],{isFetching:false})));case EXPIRE_PRODUCT_DATA:{return Object.keys(state).reduce(function(acc,productId){acc[productId]=_extends({},state[productId],{expires:0});return acc;},{});}default:return state;}}
9
+ */
10
+ export default function propertiesByProductId(state = {}, action) {
11
+ switch (action.type) {
12
+ case REQUEST_PRODUCT_PROPERTIES:
13
+ return {
14
+ ...state,
15
+ [action.productId]: {
16
+ ...state[action.productId],
17
+ isFetching: true,
18
+ expires: 0
19
+ }
20
+ };
21
+ case RECEIVE_PRODUCT_PROPERTIES:
22
+ return {
23
+ ...state,
24
+ [action.productId]: {
25
+ ...state[action.productId],
26
+ properties: action.properties,
27
+ isFetching: false,
28
+ expires: Date.now() + PRODUCT_LIFETIME
29
+ }
30
+ };
31
+ case ERROR_PRODUCT_PROPERTIES:
32
+ return {
33
+ ...state,
34
+ [action.productId]: {
35
+ ...state[action.productId],
36
+ isFetching: false
37
+ }
38
+ };
39
+ case EXPIRE_PRODUCT_DATA:
40
+ {
41
+ return Object.keys(state).reduce((acc, productId) => {
42
+ acc[productId] = {
43
+ ...state[productId],
44
+ expires: 0
45
+ };
46
+ return acc;
47
+ }, {});
48
+ }
49
+ default:
50
+ return state;
51
+ }
52
+ }