@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,5 +1,12 @@
1
- import{ERROR_FILTERS}from"../constants";/**
1
+ import { ERROR_FILTERS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched ERROR_FILTERS action object
3
5
  * @param {string} hash The product list hash.
4
6
  * @return {Object} The ERROR_PRODUCT action.
5
- */var errorFilters=function errorFilters(hash){return{type:ERROR_FILTERS,hash:hash};};export default errorFilters;
7
+ */
8
+ const errorFilters = hash => ({
9
+ type: ERROR_FILTERS,
10
+ hash
11
+ });
12
+ export default errorFilters;
@@ -1 +1,4 @@
1
- export{default as requestFilters}from"./requestFilters";export{default as receiveFilters}from"./receiveFilters";export{default as errorFilters}from"./errorFilters";export*from"./updateFilters";
1
+ export { default as requestFilters } from "./requestFilters";
2
+ export { default as receiveFilters } from "./receiveFilters";
3
+ export { default as errorFilters } from "./errorFilters";
4
+ export * from "./updateFilters";
@@ -1,6 +1,14 @@
1
- import{RECEIVE_FILTERS}from"../constants";/**
1
+ import { RECEIVE_FILTERS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched RECEIVE_FILTERS action object.
3
5
  * @param {string} hash The product list hash.
4
6
  * @param {Object} filters The available filters.
5
7
  * @return {Object} The RECEIVE_PRODUCT action.
6
- */var receiveFilters=function receiveFilters(hash,filters){return{type:RECEIVE_FILTERS,hash:hash,filters:filters};};export default receiveFilters;
8
+ */
9
+ const receiveFilters = (hash, filters) => ({
10
+ type: RECEIVE_FILTERS,
11
+ hash,
12
+ filters
13
+ });
14
+ export default receiveFilters;
@@ -1,5 +1,12 @@
1
- import{REQUEST_FILTERS}from"../constants";/**
1
+ import { REQUEST_FILTERS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched REQUEST_FILTERS action object.
3
5
  * @param {string} hash The product list hash.
4
6
  * @return {Object} The REQUEST_PRODUCT action.
5
- */var requestFilters=function requestFilters(hash){return{type:REQUEST_FILTERS,hash:hash};};export default requestFilters;
7
+ */
8
+ const requestFilters = hash => ({
9
+ type: REQUEST_FILTERS,
10
+ hash
11
+ });
12
+ export default requestFilters;
@@ -1,4 +1,10 @@
1
- import{UPDATE_FILTERS}from"../constants";/**
1
+ import { UPDATE_FILTERS } from "../constants";
2
+
3
+ /**
2
4
  * @param {Object} filters The set filters.
3
5
  * @return {Object}
4
- */export var updateFilters=function updateFilters(filters){return{type:UPDATE_FILTERS,filters:filters};};
6
+ */
7
+ export const updateFilters = filters => ({
8
+ type: UPDATE_FILTERS,
9
+ filters
10
+ });
@@ -1,7 +1,50 @@
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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{logger}from'@shopgate/pwa-core/helpers';import{generateResultHash,shouldFetchFilters}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_CATALOG_GET_FILTERS}from"../constants/Pipelines";import requestFilters from"../action-creators/requestFilters";import receiveFilters from"../action-creators/receiveFilters";import errorFilters from"../action-creators/errorFilters";import{getFilterResults}from"../selectors";import buildFilterParams from"./helpers/buildFilterParams";import processParams from"./helpers/processParams";/**
1
+ import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
2
+ import { logger } from '@shopgate/pwa-core/helpers';
3
+ import { generateResultHash, shouldFetchFilters } from '@shopgate/pwa-common/helpers/redux';
4
+ import { SHOPGATE_CATALOG_GET_FILTERS } from "../constants/Pipelines";
5
+ import requestFilters from "../action-creators/requestFilters";
6
+ import receiveFilters from "../action-creators/receiveFilters";
7
+ import errorFilters from "../action-creators/errorFilters";
8
+ import { getFilterResults } from "../selectors";
9
+ import buildFilterParams from "./helpers/buildFilterParams";
10
+ import processParams from "./helpers/processParams";
11
+
12
+ /**
2
13
  * Retrieves the available filters for a list of products.
3
14
  * @param {Object} options The options for the getProducts request.
4
15
  * @param {Object} [options.filters = null] Filters object for the request
5
16
  * @returns {Function} A redux thunk
6
- */function fetchFilters(){var _ref=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},_ref$filters=_ref.filters,filters=_ref$filters===void 0?null:_ref$filters;return function(dispatch,getState){var state=getState();var params=buildFilterParams(state,filters);var hash=generateResultHash(_extends({pipeline:SHOPGATE_CATALOG_GET_FILTERS},params),false,false);var result=getFilterResults(state)[hash];if(!shouldFetchFilters(result)){return Promise.resolve(null);}// We need to process the params to handle edge cases in the pipeline params.
7
- var requestParams=processParams(params);if(Object.keys(requestParams).length===0){var error="Attempt to call ".concat(SHOPGATE_CATALOG_GET_FILTERS," pipeline without parameters - aborted");logger.error(error);return Promise.reject(new Error(error));}dispatch(requestFilters(hash));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_FILTERS).setInput(requestParams).dispatch();request.then(function(response){dispatch(receiveFilters(hash,response.filters));})["catch"](function(){dispatch(errorFilters(hash));});return request;};}export default fetchFilters;
17
+ */
18
+ function fetchFilters({
19
+ filters = null
20
+ } = {}) {
21
+ return (dispatch, getState) => {
22
+ const state = getState();
23
+ const params = buildFilterParams(state, filters);
24
+ const hash = generateResultHash({
25
+ pipeline: SHOPGATE_CATALOG_GET_FILTERS,
26
+ ...params
27
+ }, false, false);
28
+ const result = getFilterResults(state)[hash];
29
+ if (!shouldFetchFilters(result)) {
30
+ return Promise.resolve(null);
31
+ }
32
+
33
+ // We need to process the params to handle edge cases in the pipeline params.
34
+ const requestParams = processParams(params);
35
+ if (Object.keys(requestParams).length === 0) {
36
+ const error = `Attempt to call ${SHOPGATE_CATALOG_GET_FILTERS} pipeline without parameters - aborted`;
37
+ logger.error(error);
38
+ return Promise.reject(new Error(error));
39
+ }
40
+ dispatch(requestFilters(hash));
41
+ const request = new PipelineRequest(SHOPGATE_CATALOG_GET_FILTERS).setInput(requestParams).dispatch();
42
+ request.then(response => {
43
+ dispatch(receiveFilters(hash, response.filters));
44
+ }).catch(() => {
45
+ dispatch(errorFilters(hash));
46
+ });
47
+ return request;
48
+ };
49
+ }
50
+ export default fetchFilters;
@@ -1,5 +1,9 @@
1
- import fetchFilters from"./fetchFilters";/**
1
+ import fetchFilters from "./fetchFilters";
2
+
3
+ /**
2
4
  * Retrieves the available filters for a list of products.
3
5
  * @returns {Function} A redux thunk
4
6
  * @deprecated
5
- */var getFilters=fetchFilters;export default getFilters;
7
+ */
8
+ const getFilters = fetchFilters;
9
+ export default getFilters;
@@ -1,6 +1,38 @@
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{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{CATEGORY_ALL_PATTERN,CATEGORY_ALL_FILTER_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{hex2bin}from'@shopgate/pwa-common/helpers/data';import buildRequestFilters from"./buildRequestFilters";/**
1
+ import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
2
+ import { CATEGORY_ALL_PATTERN, CATEGORY_ALL_FILTER_PATTERN } from '@shopgate/pwa-common-commerce/category/constants';
3
+ import { hex2bin } from '@shopgate/pwa-common/helpers/data';
4
+ import buildRequestFilters from "./buildRequestFilters";
5
+
6
+ /**
2
7
  * Creates the filter params.
3
8
  * @param {Object} state The application state.
4
9
  * @param {Object} [filters] Optional filters to be sent with the request
5
10
  * @return {Object}
6
- */var buildFilterParams=function buildFilterParams(state,filters){var _getCurrentRoute=getCurrentRoute(state),params=_getCurrentRoute.params,query=_getCurrentRoute.query,pattern=_getCurrentRoute.pattern;var filterParams=_extends({},params.categoryId&&{categoryId:hex2bin(params.categoryId)},{},query.s&&{searchPhrase:query.s});if([CATEGORY_ALL_PATTERN,CATEGORY_ALL_FILTER_PATTERN].includes(pattern)){filterParams={searchPhrase:'*'};}return _extends({},filterParams,{},filters?{filters:buildRequestFilters(filters)}:null);};export default buildFilterParams;
11
+ */
12
+ const buildFilterParams = (state, filters) => {
13
+ const {
14
+ params,
15
+ query,
16
+ pattern
17
+ } = getCurrentRoute(state);
18
+ let filterParams = {
19
+ ...(params.categoryId && {
20
+ categoryId: hex2bin(params.categoryId)
21
+ }),
22
+ ...(query.s && {
23
+ searchPhrase: query.s
24
+ })
25
+ };
26
+ if ([CATEGORY_ALL_PATTERN, CATEGORY_ALL_FILTER_PATTERN].includes(pattern)) {
27
+ filterParams = {
28
+ searchPhrase: '*'
29
+ };
30
+ }
31
+ return {
32
+ ...filterParams,
33
+ ...(filters ? {
34
+ filters: buildRequestFilters(filters)
35
+ } : null)
36
+ };
37
+ };
38
+ export default buildFilterParams;
@@ -1,6 +1,39 @@
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 _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function _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{FILTER_TYPE_SINGLE_SELECT,FILTER_TYPE_MULTISELECT,FILTER_TYPE_RANGE}from'@shopgate/pwa-common-commerce/filter/constants';/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { FILTER_TYPE_SINGLE_SELECT, FILTER_TYPE_MULTISELECT, FILTER_TYPE_RANGE } from '@shopgate/pwa-common-commerce/filter/constants';
3
+
4
+ /**
2
5
  * Converts an active filters object from the current route state
3
6
  * to one that can be used within a pipeline request.
4
7
  * @param {Object} activeFilters The selected filters.
5
8
  * @return {Object|undefined}
6
- */var buildRequestFilters=function buildRequestFilters(activeFilters){var filters;if(activeFilters){filters=Object.keys(activeFilters).reduce(function(result,id){var filter=activeFilters[id];var converted=_extends({label:filter.label,type:filter.type},filter.source&&{source:filter.source});if(filter.type===FILTER_TYPE_RANGE){var _filter$value2=_slicedToArray(filter.value,2),minimum=_filter$value2[0],maximum=_filter$value2[1];converted.minimum=minimum;converted.maximum=maximum;}else if(filter.type===FILTER_TYPE_MULTISELECT){converted.values=filter.value.map(function(entry){return entry.id;});}else if(filter.type===FILTER_TYPE_SINGLE_SELECT){converted.value=filter.value[0].id;}return _extends({},result,_defineProperty({},id,converted));},{});}return filters;};export default buildRequestFilters;
9
+ */
10
+ const buildRequestFilters = activeFilters => {
11
+ let filters;
12
+ if (activeFilters) {
13
+ filters = Object.keys(activeFilters).reduce((result, id) => {
14
+ const filter = activeFilters[id];
15
+ const converted = {
16
+ label: filter.label,
17
+ type: filter.type,
18
+ ...(filter.source && {
19
+ source: filter.source
20
+ })
21
+ };
22
+ if (filter.type === FILTER_TYPE_RANGE) {
23
+ const [minimum, maximum] = filter.value;
24
+ converted.minimum = minimum;
25
+ converted.maximum = maximum;
26
+ } else if (filter.type === FILTER_TYPE_MULTISELECT) {
27
+ converted.values = filter.value.map(entry => entry.id);
28
+ } else if (filter.type === FILTER_TYPE_SINGLE_SELECT) {
29
+ converted.value = filter.value[0].id;
30
+ }
31
+ return {
32
+ ...result,
33
+ [id]: converted
34
+ };
35
+ }, {});
36
+ }
37
+ return filters;
38
+ };
39
+ export default buildRequestFilters;
@@ -1,5 +1,13 @@
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);}/**
1
+ /**
2
2
  * Removes the display_amount filter from the filters list.
3
3
  * @param {Object} filters The filters.
4
4
  * @returns {Object} The processed filters.
5
- */var processFilters=function processFilters(filters){var newFilters=_extends({},filters);delete newFilters.display_amount;return newFilters;};export default processFilters;
5
+ */
6
+ const processFilters = filters => {
7
+ const newFilters = {
8
+ ...filters
9
+ };
10
+ delete newFilters.display_amount;
11
+ return newFilters;
12
+ };
13
+ export default processFilters;
@@ -1,4 +1,7 @@
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 processFilters from"./processFilters";import buildRequestFilters from"./buildRequestFilters";/**
1
+ import processFilters from "./processFilters";
2
+ import buildRequestFilters from "./buildRequestFilters";
3
+
4
+ /**
2
5
  * Process the pipeline params to be compatible with the current API specifications.
3
6
  * Currently the categoryId field cannot be used in combination with the filter field. In order to
4
7
  * use them together the categoryId field has to be extracted into the filter field.
@@ -6,4 +9,25 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
6
9
  * @param {Object} params The request params.
7
10
  * @param {Object} [filters=null] The current active filters.
8
11
  * @returns {Object} A set of compatible params.
9
- */var processParams=function processParams(params){var filters=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var processedFilters=processFilters(buildRequestFilters(filters));var newParams=_extends({},params,{},processedFilters&&Object.keys(processedFilters).length&&{filters:processedFilters});if(params.categoryId&&processedFilters&&Object.keys(processedFilters).length){newParams=_extends({},params,{filters:_extends({categoryId:params.categoryId},processedFilters)});delete newParams.categoryId;}return newParams;};export default processParams;
12
+ */
13
+ const processParams = (params, filters = null) => {
14
+ const processedFilters = processFilters(buildRequestFilters(filters));
15
+ let newParams = {
16
+ ...params,
17
+ ...(processedFilters && Object.keys(processedFilters).length && {
18
+ filters: processedFilters
19
+ })
20
+ };
21
+ if (params.categoryId && processedFilters && Object.keys(processedFilters).length) {
22
+ newParams = {
23
+ ...params,
24
+ filters: {
25
+ categoryId: params.categoryId,
26
+ ...processedFilters
27
+ }
28
+ };
29
+ delete newParams.categoryId;
30
+ }
31
+ return newParams;
32
+ };
33
+ export default processParams;
@@ -1 +1 @@
1
- export var SHOPGATE_CATALOG_GET_FILTERS='shopgate.catalog.getFilters';
1
+ export const SHOPGATE_CATALOG_GET_FILTERS = 'shopgate.catalog.getFilters';
@@ -1,4 +1,40 @@
1
1
  // FEATURES
2
- var FILTER='filter';// CONTENTS
3
- var PRICE_RANGE='price-range';var SORT='sort-options';var SELECTOR='selector';var APPLY_BUTTON='apply-button';var RESET_BUTTON='reset-button';var PAGE_CONTENT='page-content';// POSITIONS
4
- var BEFORE='before';var AFTER='after';/** @deprecated Use PORTAL_FILTER_PRICE_RANGE instead */export var FILTER_PRICE_RANGE="".concat(FILTER,".").concat(PRICE_RANGE);/** @deprecated Use PORTAL_FILTER_PRICE_RANGE_BEFORE instead */export var FILTER_PRICE_RANGE_BEFORE="".concat(FILTER,".").concat(PRICE_RANGE,".").concat(BEFORE);/** @deprecated Use PORTAL_FILTER_PRICE_RANGE_AFTER instead */export var FILTER_PRICE_RANGE_AFTER="".concat(FILTER,".").concat(PRICE_RANGE,".").concat(AFTER);/** @deprecated Use PORTAL_FILTER_SORT_OPTIONS instead */export var FILTER_SORT_OPTIONS="".concat(FILTER,".").concat(SORT);export var PORTAL_FILTER_PRICE_RANGE=FILTER_PRICE_RANGE;export var PORTAL_FILTER_PRICE_RANGE_BEFORE=FILTER_PRICE_RANGE_BEFORE;export var PORTAL_FILTER_PRICE_RANGE_AFTER=FILTER_PRICE_RANGE_AFTER;export var PORTAL_FILTER_SORT_OPTIONS=FILTER_SORT_OPTIONS;export var PORTAL_FILTER_SELECTOR="".concat(FILTER,".").concat(SELECTOR);export var PORTAL_FILTER_SELECTOR_BEFORE="".concat(FILTER,".").concat(SELECTOR,".").concat(BEFORE);export var PORTAL_FILTER_SELECTOR_AFTER="".concat(FILTER,".").concat(SELECTOR,".").concat(AFTER);export var PORTAL_FILTER_APPLY_BUTTON="".concat(FILTER,".").concat(APPLY_BUTTON);export var PORTAL_FILTER_APPLY_BUTTON_BEFORE="".concat(FILTER,".").concat(APPLY_BUTTON,".").concat(BEFORE);export var PORTAL_FILTER_APPLY_BUTTON_AFTER="".concat(FILTER,".").concat(APPLY_BUTTON,".").concat(AFTER);export var PORTAL_FILTER_RESET_BUTTON="".concat(FILTER,".").concat(RESET_BUTTON);export var PORTAL_FILTER_RESET_BUTTON_BEFORE="".concat(FILTER,".").concat(RESET_BUTTON,".").concat(BEFORE);export var PORTAL_FILTER_RESET_BUTTON_AFTER="".concat(FILTER,".").concat(RESET_BUTTON,".").concat(AFTER);export var PORTAL_FILTER_PAGE_CONTENT="".concat(FILTER,".").concat(PAGE_CONTENT);export var PORTAL_FILTER_PAGE_CONTENT_BEFORE="".concat(FILTER,".").concat(PAGE_CONTENT,".").concat(BEFORE);export var PORTAL_FILTER_PAGE_CONTENT_AFTER="".concat(FILTER,".").concat(PAGE_CONTENT,".").concat(AFTER);
2
+ const FILTER = 'filter';
3
+
4
+ // CONTENTS
5
+ const PRICE_RANGE = 'price-range';
6
+ const SORT = 'sort-options';
7
+ const SELECTOR = 'selector';
8
+ const APPLY_BUTTON = 'apply-button';
9
+ const RESET_BUTTON = 'reset-button';
10
+ const PAGE_CONTENT = 'page-content';
11
+
12
+ // POSITIONS
13
+ const BEFORE = 'before';
14
+ const AFTER = 'after';
15
+
16
+ /** @deprecated Use PORTAL_FILTER_PRICE_RANGE instead */
17
+ export const FILTER_PRICE_RANGE = `${FILTER}.${PRICE_RANGE}`;
18
+ /** @deprecated Use PORTAL_FILTER_PRICE_RANGE_BEFORE instead */
19
+ export const FILTER_PRICE_RANGE_BEFORE = `${FILTER}.${PRICE_RANGE}.${BEFORE}`;
20
+ /** @deprecated Use PORTAL_FILTER_PRICE_RANGE_AFTER instead */
21
+ export const FILTER_PRICE_RANGE_AFTER = `${FILTER}.${PRICE_RANGE}.${AFTER}`;
22
+
23
+ /** @deprecated Use PORTAL_FILTER_SORT_OPTIONS instead */
24
+ export const FILTER_SORT_OPTIONS = `${FILTER}.${SORT}`;
25
+ export const PORTAL_FILTER_PRICE_RANGE = FILTER_PRICE_RANGE;
26
+ export const PORTAL_FILTER_PRICE_RANGE_BEFORE = FILTER_PRICE_RANGE_BEFORE;
27
+ export const PORTAL_FILTER_PRICE_RANGE_AFTER = FILTER_PRICE_RANGE_AFTER;
28
+ export const PORTAL_FILTER_SORT_OPTIONS = FILTER_SORT_OPTIONS;
29
+ export const PORTAL_FILTER_SELECTOR = `${FILTER}.${SELECTOR}`;
30
+ export const PORTAL_FILTER_SELECTOR_BEFORE = `${FILTER}.${SELECTOR}.${BEFORE}`;
31
+ export const PORTAL_FILTER_SELECTOR_AFTER = `${FILTER}.${SELECTOR}.${AFTER}`;
32
+ export const PORTAL_FILTER_APPLY_BUTTON = `${FILTER}.${APPLY_BUTTON}`;
33
+ export const PORTAL_FILTER_APPLY_BUTTON_BEFORE = `${FILTER}.${APPLY_BUTTON}.${BEFORE}`;
34
+ export const PORTAL_FILTER_APPLY_BUTTON_AFTER = `${FILTER}.${APPLY_BUTTON}.${AFTER}`;
35
+ export const PORTAL_FILTER_RESET_BUTTON = `${FILTER}.${RESET_BUTTON}`;
36
+ export const PORTAL_FILTER_RESET_BUTTON_BEFORE = `${FILTER}.${RESET_BUTTON}.${BEFORE}`;
37
+ export const PORTAL_FILTER_RESET_BUTTON_AFTER = `${FILTER}.${RESET_BUTTON}.${AFTER}`;
38
+ export const PORTAL_FILTER_PAGE_CONTENT = `${FILTER}.${PAGE_CONTENT}`;
39
+ export const PORTAL_FILTER_PAGE_CONTENT_BEFORE = `${FILTER}.${PAGE_CONTENT}.${BEFORE}`;
40
+ export const PORTAL_FILTER_PAGE_CONTENT_AFTER = `${FILTER}.${PAGE_CONTENT}.${AFTER}`;
@@ -1 +1,8 @@
1
- export var FILTER_PATH='/filter';export var REQUEST_FILTERS='REQUEST_FILTERS';export var RECEIVE_FILTERS='RECEIVE_FILTERS';export var ERROR_FILTERS='ERROR_FILTERS';export var UPDATE_FILTERS='UPDATE_FILTERS';export var FILTER_TYPE_SINGLE_SELECT='single_select';export var FILTER_TYPE_MULTISELECT='multiselect';export var FILTER_TYPE_RANGE='range';
1
+ export const FILTER_PATH = '/filter';
2
+ export const REQUEST_FILTERS = 'REQUEST_FILTERS';
3
+ export const RECEIVE_FILTERS = 'RECEIVE_FILTERS';
4
+ export const ERROR_FILTERS = 'ERROR_FILTERS';
5
+ export const UPDATE_FILTERS = 'UPDATE_FILTERS';
6
+ export const FILTER_TYPE_SINGLE_SELECT = 'single_select';
7
+ export const FILTER_TYPE_MULTISELECT = 'multiselect';
8
+ export const FILTER_TYPE_RANGE = 'range';
package/filter/index.js CHANGED
@@ -1,5 +1,13 @@
1
1
  // ACTIONS
2
- export{default as fetchFilters}from"./actions/fetchFilters";// CONSTANTS
3
- export*from"./constants/index";export*from"./constants/Pipelines";export*from"./constants/Portals";// SELECTORS
4
- export*from"./selectors";// STREAMS
5
- export*from"./streams";
2
+ export { default as fetchFilters } from "./actions/fetchFilters";
3
+
4
+ // CONSTANTS
5
+ export * from "./constants/index";
6
+ export * from "./constants/Pipelines";
7
+ export * from "./constants/Portals";
8
+
9
+ // SELECTORS
10
+ export * from "./selectors";
11
+
12
+ // STREAMS
13
+ export * from "./streams";
@@ -1,6 +1,14 @@
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 kebabCase from'lodash/kebabCase';import{FILTER_PATH}from"../../constants";/**
1
+ import kebabCase from 'lodash/kebabCase';
2
+ import { FILTER_PATH } from "../../constants";
3
+
4
+ /**
2
5
  * Enriches a filter object with additional properties.
3
6
  * @param {Array} filters The filters collection.
4
7
  * @return {Array} The new collection of enriched filters.
5
- */var enrichFilters=function enrichFilters(filters){return filters.map(function(filter){return _extends({},filter,{// The route url of this filter.
6
- url:"".concat(FILTER_PATH,"/").concat(kebabCase(filter.id))});});};export default enrichFilters;
8
+ */
9
+ const enrichFilters = filters => filters.map(filter => ({
10
+ ...filter,
11
+ // The route url of this filter.
12
+ url: `${FILTER_PATH}/${kebabCase(filter.id)}`
13
+ }));
14
+ export default enrichFilters;
@@ -1 +1,5 @@
1
- import{combineReducers}from'redux';import resultsByHash from"./resultsByHash";export default combineReducers({resultsByHash:resultsByHash});
1
+ import { combineReducers } from 'redux';
2
+ import resultsByHash from "./resultsByHash";
3
+ export default combineReducers({
4
+ resultsByHash
5
+ });
@@ -1,6 +1,46 @@
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_FILTERS,RECEIVE_FILTERS,ERROR_FILTERS}from'@shopgate/pwa-common-commerce/filter/constants';// TODO: Remove dependency to product
2
- import{PRODUCT_LIFETIME}from'@shopgate/pwa-common-commerce/product/constants';import enrichFilters from"./helpers/enrichFilters";/**
1
+ import { REQUEST_FILTERS, RECEIVE_FILTERS, ERROR_FILTERS } from '@shopgate/pwa-common-commerce/filter/constants';
2
+ // TODO: Remove dependency to product
3
+ import { PRODUCT_LIFETIME } from '@shopgate/pwa-common-commerce/product/constants';
4
+ import enrichFilters from "./helpers/enrichFilters";
5
+
6
+ /**
3
7
  * @param {Object} [state={}] The current state.
4
8
  * @param {Object} action The current redux action.
5
9
  * @return {Object} The new state.
6
- */export default function resultsByHash(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_FILTERS:{return _extends({},state,_defineProperty({},action.hash,{filters:null,isFetching:true,expires:0}));}case RECEIVE_FILTERS:{return _extends({},state,_defineProperty({},action.hash,{filters:enrichFilters(action.filters),isFetching:false,expires:Date.now()+PRODUCT_LIFETIME}));}case ERROR_FILTERS:return _extends({},state,_defineProperty({},action.hash,_extends({},state[action.hash],{isFetching:false})));default:return state;}}
10
+ */
11
+ export default function resultsByHash(state = {}, action) {
12
+ switch (action.type) {
13
+ case REQUEST_FILTERS:
14
+ {
15
+ return {
16
+ ...state,
17
+ [action.hash]: {
18
+ filters: null,
19
+ isFetching: true,
20
+ expires: 0
21
+ }
22
+ };
23
+ }
24
+ case RECEIVE_FILTERS:
25
+ {
26
+ return {
27
+ ...state,
28
+ [action.hash]: {
29
+ filters: enrichFilters(action.filters),
30
+ isFetching: false,
31
+ expires: Date.now() + PRODUCT_LIFETIME
32
+ }
33
+ };
34
+ }
35
+ case ERROR_FILTERS:
36
+ return {
37
+ ...state,
38
+ [action.hash]: {
39
+ ...state[action.hash],
40
+ isFetching: false
41
+ }
42
+ };
43
+ default:
44
+ return state;
45
+ }
46
+ }
@@ -1,21 +1,62 @@
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{hex2bin}from'@shopgate/pwa-common/helpers/data';import{generateResultHash}from'@shopgate/pwa-common/helpers/redux';import{getCurrentState}from'@shopgate/pwa-common/selectors/router';import*as pipelines from"../constants/Pipelines";import buildRequestFilters from"../actions/helpers/buildRequestFilters";/**
1
+ import { createSelector } from 'reselect';
2
+ import { hex2bin } from '@shopgate/pwa-common/helpers/data';
3
+ import { generateResultHash } from '@shopgate/pwa-common/helpers/redux';
4
+ import { getCurrentState } from '@shopgate/pwa-common/selectors/router';
5
+ import * as pipelines from "../constants/Pipelines";
6
+ import buildRequestFilters from "../actions/helpers/buildRequestFilters";
7
+
8
+ /**
2
9
  * Gets the filters reducer.
3
10
  * @param {Object} state The application state.
4
11
  * @return {Object}
5
- */export var getFilters=function getFilters(state){return state.filter;};/**
12
+ */
13
+ export const getFilters = state => state.filter;
14
+
15
+ /**
6
16
  * Gets the filter results.
7
17
  * @param {Object} state The current application state.
8
18
  * @return {Object}
9
- */export var getFilterResults=createSelector(getFilters,function(filter){return filter.resultsByHash;});/**
19
+ */
20
+ export const getFilterResults = createSelector(getFilters, filter => filter.resultsByHash);
21
+
22
+ /**
10
23
  * Gets filters by a result hash.
11
24
  * @param {Object} state The current application state.
12
25
  * @param {Object} props The props.
13
26
  * @return {Object}
14
- */export var getFiltersByHash=createSelector(getFilterResults,function(state,props){return props.categoryId;},function(state,props){return props.searchPhrase;},function(state,props){return props.filters;},function(results,categoryId,searchPhrase,filters){var hash=generateResultHash(_extends({pipeline:pipelines.SHOPGATE_CATALOG_GET_FILTERS},categoryId&&{categoryId:hex2bin(categoryId)},{},searchPhrase&&{searchPhrase:searchPhrase},{},filters&&{filters:buildRequestFilters(filters)}),false,false);return results[hash]&&results[hash].filters||null;});/**
27
+ */
28
+ export const getFiltersByHash = createSelector(getFilterResults, (state, props) => props.categoryId, (state, props) => props.searchPhrase, (state, props) => props.filters, (results, categoryId, searchPhrase, filters) => {
29
+ const hash = generateResultHash({
30
+ pipeline: pipelines.SHOPGATE_CATALOG_GET_FILTERS,
31
+ ...(categoryId && {
32
+ categoryId: hex2bin(categoryId)
33
+ }),
34
+ ...(searchPhrase && {
35
+ searchPhrase
36
+ }),
37
+ ...(filters && {
38
+ filters: buildRequestFilters(filters)
39
+ })
40
+ }, false, false);
41
+ return results[hash] && results[hash].filters || null;
42
+ });
43
+
44
+ /**
15
45
  * Gets the currently active filters.
16
46
  * @returns {Object|null}
17
- */export var getActiveFilters=createSelector(getCurrentState,function(_ref){var filters=_ref.filters;if(!filters){return null;}return filters;});/**
47
+ */
48
+ export const getActiveFilters = createSelector(getCurrentState, ({
49
+ filters
50
+ }) => {
51
+ if (!filters) {
52
+ return null;
53
+ }
54
+ return filters;
55
+ });
56
+
57
+ /**
18
58
  * Checks if currently filters are active.
19
59
  * @param {Object} state The application state.
20
60
  * @returns {boolean}
21
- */export var hasActiveFilters=createSelector(getActiveFilters,function(activeFilters){return activeFilters!==null&&!!Object.keys(activeFilters).length;});
61
+ */
62
+ export const hasActiveFilters = createSelector(getActiveFilters, activeFilters => activeFilters !== null && !!Object.keys(activeFilters).length);
@@ -1 +1,30 @@
1
- import{main$}from'@shopgate/pwa-common/streams/main';import{ACTION_PUSH,ACTION_POP}from'@virtuous/conductor';import{routeWillEnter$,routeDidEnter$,routeWillLeave$,routeDidLeave$}from'@shopgate/pwa-common/streams';import{CATEGORY_PATH,CATEGORY_ALL_PATTERN,CATEGORY_ALL_FILTER_PATTERN}from"../../category/constants";import{SEARCH_PATH}from"../../search/constants";import{FILTER_PATH,UPDATE_FILTERS}from"../constants";export var filterWillEnter$=routeWillEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId").concat(FILTER_PATH)||action.route.pattern===CATEGORY_ALL_FILTER_PATTERN||action.route.pattern==="".concat(SEARCH_PATH).concat(FILTER_PATH);});export var filterDidEnter$=routeDidEnter$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId").concat(FILTER_PATH)||action.route.pattern===CATEGORY_ALL_FILTER_PATTERN||action.route.pattern==="".concat(SEARCH_PATH).concat(FILTER_PATH);});export var filterWillLeave$=routeWillLeave$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId").concat(FILTER_PATH)||action.route.pattern===CATEGORY_ALL_FILTER_PATTERN||action.route.pattern==="".concat(SEARCH_PATH).concat(FILTER_PATH);});export var filterDidLeave$=routeDidLeave$.filter(function(_ref4){var action=_ref4.action;return action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId").concat(FILTER_PATH)||action.route.pattern===CATEGORY_ALL_FILTER_PATTERN||action.route.pattern==="".concat(SEARCH_PATH).concat(FILTER_PATH);});export var filterableRoutesWillEnter$=routeWillEnter$.filter(function(_ref5){var action=_ref5.action;return action.historyAction===ACTION_PUSH&&(action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId")||action.route.pattern===CATEGORY_ALL_PATTERN||action.route.pattern===SEARCH_PATH);});export var filterableRoutesWillReenter$=routeWillEnter$.filter(function(_ref6){var action=_ref6.action;return action.historyAction===ACTION_POP&&(action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId")||action.route.pattern===CATEGORY_ALL_PATTERN||action.route.pattern===SEARCH_PATH);});export var filterableRoutesWillLeave$=routeWillLeave$.filter(function(_ref7){var action=_ref7.action;return action.historyAction===ACTION_POP&&(action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId")||action.route.pattern===CATEGORY_ALL_PATTERN||action.route.pattern===SEARCH_PATH);});export var filtersDidUpdate$=main$.filter(function(_ref8){var action=_ref8.action;return action.type===UPDATE_FILTERS;});
1
+ import { main$ } from '@shopgate/pwa-common/streams/main';
2
+ import { ACTION_PUSH, ACTION_POP } from '@virtuous/conductor';
3
+ import { routeWillEnter$, routeDidEnter$, routeWillLeave$, routeDidLeave$ } from '@shopgate/pwa-common/streams';
4
+ import { CATEGORY_PATH, CATEGORY_ALL_PATTERN, CATEGORY_ALL_FILTER_PATTERN } from "../../category/constants";
5
+ import { SEARCH_PATH } from "../../search/constants";
6
+ import { FILTER_PATH, UPDATE_FILTERS } from "../constants";
7
+ export const filterWillEnter$ = routeWillEnter$.filter(({
8
+ action
9
+ }) => action.route.pattern === `${CATEGORY_PATH}/:categoryId${FILTER_PATH}` || action.route.pattern === CATEGORY_ALL_FILTER_PATTERN || action.route.pattern === `${SEARCH_PATH}${FILTER_PATH}`);
10
+ export const filterDidEnter$ = routeDidEnter$.filter(({
11
+ action
12
+ }) => action.route.pattern === `${CATEGORY_PATH}/:categoryId${FILTER_PATH}` || action.route.pattern === CATEGORY_ALL_FILTER_PATTERN || action.route.pattern === `${SEARCH_PATH}${FILTER_PATH}`);
13
+ export const filterWillLeave$ = routeWillLeave$.filter(({
14
+ action
15
+ }) => action.route.pattern === `${CATEGORY_PATH}/:categoryId${FILTER_PATH}` || action.route.pattern === CATEGORY_ALL_FILTER_PATTERN || action.route.pattern === `${SEARCH_PATH}${FILTER_PATH}`);
16
+ export const filterDidLeave$ = routeDidLeave$.filter(({
17
+ action
18
+ }) => action.route.pattern === `${CATEGORY_PATH}/:categoryId${FILTER_PATH}` || action.route.pattern === CATEGORY_ALL_FILTER_PATTERN || action.route.pattern === `${SEARCH_PATH}${FILTER_PATH}`);
19
+ export const filterableRoutesWillEnter$ = routeWillEnter$.filter(({
20
+ action
21
+ }) => action.historyAction === ACTION_PUSH && (action.route.pattern === `${CATEGORY_PATH}/:categoryId` || action.route.pattern === CATEGORY_ALL_PATTERN || action.route.pattern === SEARCH_PATH));
22
+ export const filterableRoutesWillReenter$ = routeWillEnter$.filter(({
23
+ action
24
+ }) => action.historyAction === ACTION_POP && (action.route.pattern === `${CATEGORY_PATH}/:categoryId` || action.route.pattern === CATEGORY_ALL_PATTERN || action.route.pattern === SEARCH_PATH));
25
+ export const filterableRoutesWillLeave$ = routeWillLeave$.filter(({
26
+ action
27
+ }) => action.historyAction === ACTION_POP && (action.route.pattern === `${CATEGORY_PATH}/:categoryId` || action.route.pattern === CATEGORY_ALL_PATTERN || action.route.pattern === SEARCH_PATH));
28
+ export const filtersDidUpdate$ = main$.filter(({
29
+ action
30
+ }) => action.type === UPDATE_FILTERS);
@@ -1,4 +1,36 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{router}from'@shopgate/pwa-common/helpers/router';import{hex2bin}from'@shopgate/pwa-common/helpers/data';import{buildFilterParamsForFetchFiltersRequest}from'@shopgate/engage/filter/helpers';import{CATEGORY_ALL_FILTER_PATTERN}from"../../category/constants";import fetchCategory from"../../category/actions/fetchCategory";import{getShowAllProductsFilters}from"../../category/helpers";import fetchFilters from"../actions/fetchFilters";import{filterDidEnter$}from"../streams";/**
1
+ import { router } from '@shopgate/pwa-common/helpers/router';
2
+ import { hex2bin } from '@shopgate/pwa-common/helpers/data';
3
+ import { buildFilterParamsForFetchFiltersRequest } from '@shopgate/engage/filter/helpers';
4
+ import { CATEGORY_ALL_FILTER_PATTERN } from "../../category/constants";
5
+ import fetchCategory from "../../category/actions/fetchCategory";
6
+ import { getShowAllProductsFilters } from "../../category/helpers";
7
+ import fetchFilters from "../actions/fetchFilters";
8
+ import { filterDidEnter$ } from "../streams";
9
+
10
+ /**
2
11
  * Filters subscriptions.
3
12
  * @param {Function} subscribe The subscribe function.
4
- */export default function filters(subscribe){subscribe(filterDidEnter$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var _action$route,_action$route2;var dispatch,action,_ref3,routeFilters,category;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,action=_ref.action;_ref3=(action===null||action===void 0?void 0:(_action$route=action.route)===null||_action$route===void 0?void 0:_action$route.state)||{},routeFilters=_ref3.filters;if(!((action===null||action===void 0?void 0:(_action$route2=action.route)===null||_action$route2===void 0?void 0:_action$route2.pattern)===CATEGORY_ALL_FILTER_PATTERN)){_context.next=9;break;}if(routeFilters){_context.next=9;break;}_context.next=6;return dispatch(fetchCategory(hex2bin(action.route.params.categoryId)));case 6:category=_context.sent;routeFilters=getShowAllProductsFilters(category);router.update(action.route.id,{filters:routeFilters,categoryName:category.name});case 9:dispatch(fetchFilters({filters:buildFilterParamsForFetchFiltersRequest(routeFilters)}));case 10:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());}
13
+ */
14
+ export default function filters(subscribe) {
15
+ subscribe(filterDidEnter$, async ({
16
+ dispatch,
17
+ action
18
+ }) => {
19
+ let {
20
+ filters: routeFilters
21
+ } = action?.route?.state || {};
22
+ if (action?.route?.pattern === CATEGORY_ALL_FILTER_PATTERN) {
23
+ if (!routeFilters) {
24
+ const category = await dispatch(fetchCategory(hex2bin(action.route.params.categoryId)));
25
+ routeFilters = getShowAllProductsFilters(category);
26
+ router.update(action.route.id, {
27
+ filters: routeFilters,
28
+ categoryName: category.name
29
+ });
30
+ }
31
+ }
32
+ dispatch(fetchFilters({
33
+ filters: buildFilterParamsForFetchFiltersRequest(routeFilters)
34
+ }));
35
+ });
36
+ }
@@ -3,7 +3,25 @@
3
3
  *
4
4
  * This source code is licensed under the Apache 2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
- */ // FEATURES
7
- var NAV_MENU='nav-menu';// CONTENTS
8
- var SHIPPING='shipping';var PAYMENT='payment';var RETURN_POLICY='return-policy';// POSITIONS
9
- var BEFORE='before';var AFTER='after';export var NAV_MENU_SHIPPING_BEFORE="".concat(NAV_MENU,".").concat(SHIPPING,".").concat(BEFORE);export var NAV_MENU_SHIPPING="".concat(NAV_MENU,".").concat(SHIPPING);export var NAV_MENU_SHIPPING_AFTER="".concat(NAV_MENU,".").concat(SHIPPING,".").concat(AFTER);export var NAV_MENU_PAYMENT_BEFORE="".concat(NAV_MENU,".").concat(PAYMENT,".").concat(BEFORE);export var NAV_MENU_PAYMENT="".concat(NAV_MENU,".").concat(PAYMENT);export var NAV_MENU_PAYMENT_AFTER="".concat(NAV_MENU,".").concat(PAYMENT,".").concat(AFTER);export var NAV_MENU_RETURN_POLICY_BEFORE="".concat(NAV_MENU,".").concat(RETURN_POLICY,".").concat(BEFORE);export var NAV_MENU_RETURN_POLICY="".concat(NAV_MENU,".").concat(RETURN_POLICY);export var NAV_MENU_RETURN_POLICY_AFTER="".concat(NAV_MENU,".").concat(RETURN_POLICY,".").concat(AFTER);
6
+ */
7
+
8
+ // FEATURES
9
+ const NAV_MENU = 'nav-menu';
10
+
11
+ // CONTENTS
12
+ const SHIPPING = 'shipping';
13
+ const PAYMENT = 'payment';
14
+ const RETURN_POLICY = 'return-policy';
15
+
16
+ // POSITIONS
17
+ const BEFORE = 'before';
18
+ const AFTER = 'after';
19
+ export const NAV_MENU_SHIPPING_BEFORE = `${NAV_MENU}.${SHIPPING}.${BEFORE}`;
20
+ export const NAV_MENU_SHIPPING = `${NAV_MENU}.${SHIPPING}`;
21
+ export const NAV_MENU_SHIPPING_AFTER = `${NAV_MENU}.${SHIPPING}.${AFTER}`;
22
+ export const NAV_MENU_PAYMENT_BEFORE = `${NAV_MENU}.${PAYMENT}.${BEFORE}`;
23
+ export const NAV_MENU_PAYMENT = `${NAV_MENU}.${PAYMENT}`;
24
+ export const NAV_MENU_PAYMENT_AFTER = `${NAV_MENU}.${PAYMENT}.${AFTER}`;
25
+ export const NAV_MENU_RETURN_POLICY_BEFORE = `${NAV_MENU}.${RETURN_POLICY}.${BEFORE}`;
26
+ export const NAV_MENU_RETURN_POLICY = `${NAV_MENU}.${RETURN_POLICY}`;
27
+ export const NAV_MENU_RETURN_POLICY_AFTER = `${NAV_MENU}.${RETURN_POLICY}.${AFTER}`;
@@ -1 +1,2 @@
1
- export var MARKET_AUSTRIA='AT';export var MARKET_GERMANY='DE';
1
+ export const MARKET_AUSTRIA = 'AT';
2
+ export const MARKET_GERMANY = 'DE';