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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/cart/action-creators/addCouponsToCart.js +9 -2
  2. package/cart/action-creators/addProductsToCart.js +9 -2
  3. package/cart/action-creators/deleteCouponsFromCart.js +9 -2
  4. package/cart/action-creators/deleteProductsFromCart.js +9 -2
  5. package/cart/action-creators/errorAddCouponsToCart.js +10 -2
  6. package/cart/action-creators/errorAddProductsToCart.js +10 -2
  7. package/cart/action-creators/errorCart.js +8 -2
  8. package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
  9. package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
  10. package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
  11. package/cart/action-creators/receiveCart.js +9 -2
  12. package/cart/action-creators/requestCart.js +8 -2
  13. package/cart/action-creators/setCartProductPendingCount.js +9 -2
  14. package/cart/action-creators/setCouponFieldError.js +9 -2
  15. package/cart/action-creators/setCouponFieldValue.js +9 -2
  16. package/cart/action-creators/setFulfillmentSlot.js +9 -2
  17. package/cart/action-creators/successAddCouponsToCart.js +10 -2
  18. package/cart/action-creators/successAddProductsToCart.js +8 -2
  19. package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
  20. package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
  21. package/cart/action-creators/successUpdateProductsInCart.js +8 -2
  22. package/cart/action-creators/updateProductsInCart.js +9 -2
  23. package/cart/actions/addCouponsToCart.js +52 -8
  24. package/cart/actions/addProductsToCart.js +80 -11
  25. package/cart/actions/deleteCouponsFromCart.js +39 -6
  26. package/cart/actions/deleteProductsFromCart.js +38 -6
  27. package/cart/actions/fetchCart.js +52 -8
  28. package/cart/actions/updateProductsInCart.js +44 -6
  29. package/cart/constants/PipelineErrors.js +6 -1
  30. package/cart/constants/Pipelines.js +6 -1
  31. package/cart/constants/Portals.js +85 -1
  32. package/cart/constants/index.js +39 -2
  33. package/cart/helpers/config.js +47 -2
  34. package/cart/helpers/createPipelineErrorList.js +30 -4
  35. package/cart/helpers/fulfillmentSlots.js +37 -4
  36. package/cart/helpers/index.js +14 -3
  37. package/cart/helpers/quantity.js +23 -4
  38. package/cart/helpers/shipping.js +57 -2
  39. package/cart/helpers/tax.js +26 -2
  40. package/cart/index.js +25 -5
  41. package/cart/mock.js +130 -1
  42. package/cart/reducers/couponField.js +30 -2
  43. package/cart/reducers/data.js +98 -6
  44. package/cart/reducers/index.js +7 -1
  45. package/cart/selectors/index.js +181 -31
  46. package/cart/selectors/spec.js +189 -2
  47. package/cart/streams/index.js +176 -29
  48. package/cart/subscriptions/index.js +307 -30
  49. package/category/action-creators/errorCategory.js +10 -2
  50. package/category/action-creators/errorCategoryChildren.js +9 -2
  51. package/category/action-creators/errorRootCategories.js +8 -2
  52. package/category/action-creators/receiveCategory.js +12 -2
  53. package/category/action-creators/receiveCategoryChildren.js +10 -2
  54. package/category/action-creators/receiveRootCategories.js +9 -2
  55. package/category/action-creators/requestCategory.js +9 -2
  56. package/category/action-creators/requestCategoryChildren.js +9 -2
  57. package/category/action-creators/requestRootCategories.js +8 -2
  58. package/category/actions/fetchCategory.js +47 -5
  59. package/category/actions/fetchCategoryChildren.js +30 -2
  60. package/category/actions/fetchCategoryOrRootCategories.js +16 -2
  61. package/category/actions/fetchCategoryProducts.js +36 -2
  62. package/category/actions/fetchRootCategories.js +31 -2
  63. package/category/actions/getCategory.js +10 -2
  64. package/category/constants/Pipelines.js +3 -1
  65. package/category/constants/Portals.js +56 -3
  66. package/category/constants/index.js +17 -2
  67. package/category/helpers/index.js +27 -3
  68. package/category/index.js +19 -5
  69. package/category/mock.js +176 -1
  70. package/category/reducers/categoriesById.js +65 -3
  71. package/category/reducers/childrenByCategoryId.js +55 -4
  72. package/category/reducers/helpers/handleCategoryCollection.js +24 -3
  73. package/category/reducers/helpers/handleReceivedCategories.js +3 -1
  74. package/category/reducers/index.js +12 -2
  75. package/category/reducers/rootCategories.js +31 -2
  76. package/category/selectors/index.js +115 -16
  77. package/category/streams/index.js +82 -4
  78. package/category/subscriptions/index.js +96 -3
  79. package/checkout/action-creators/successCheckout.js +9 -2
  80. package/checkout/actions/fetchCheckoutUrl.js +28 -3
  81. package/checkout/constants/Pipelines.js +1 -1
  82. package/checkout/constants/index.js +3 -2
  83. package/checkout/index.js +11 -4
  84. package/checkout/selectors/index.js +7 -2
  85. package/checkout/streams/index.js +8 -2
  86. package/checkout/subscriptions/index.js +35 -6
  87. package/favorites/action-creators/index.js +206 -24
  88. package/favorites/actions/addFavorites.js +41 -3
  89. package/favorites/actions/addFavoritesList.js +27 -2
  90. package/favorites/actions/fetchFavoriteIds.js +49 -5
  91. package/favorites/actions/fetchFavorites.js +60 -5
  92. package/favorites/actions/fetchFavoritesList.js +47 -3
  93. package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
  94. package/favorites/actions/getFavorites.js +6 -2
  95. package/favorites/actions/removeFavorites.js +32 -3
  96. package/favorites/actions/removeFavoritesList.js +24 -2
  97. package/favorites/actions/toggleFavorites.js +68 -10
  98. package/favorites/actions/updateFavorites.js +39 -3
  99. package/favorites/actions/updateFavoritesList.js +26 -2
  100. package/favorites/constants/Pipelines.js +9 -1
  101. package/favorites/constants/Portals.js +32 -4
  102. package/favorites/constants/index.js +37 -5
  103. package/favorites/index.js +14 -4
  104. package/favorites/mock.js +89 -4
  105. package/favorites/reducers/index.js +7 -1
  106. package/favorites/reducers/lists.js +74 -2
  107. package/favorites/reducers/products.js +231 -24
  108. package/favorites/selectors/index.js +188 -24
  109. package/favorites/streams/index.js +135 -23
  110. package/favorites/streams/spec.js +517 -8
  111. package/favorites/subscriptions/index.js +260 -25
  112. package/favorites/subscriptions/spec.js +700 -28
  113. package/filter/action-creators/errorFilters.js +9 -2
  114. package/filter/action-creators/index.js +4 -1
  115. package/filter/action-creators/receiveFilters.js +10 -2
  116. package/filter/action-creators/requestFilters.js +9 -2
  117. package/filter/action-creators/updateFilters.js +8 -2
  118. package/filter/actions/fetchFilters.js +46 -3
  119. package/filter/actions/getFilters.js +6 -2
  120. package/filter/actions/helpers/buildFilterParams.js +34 -2
  121. package/filter/actions/helpers/buildRequestFilters.js +35 -2
  122. package/filter/actions/helpers/processFilters.js +10 -2
  123. package/filter/actions/helpers/processParams.js +26 -2
  124. package/filter/constants/Pipelines.js +1 -1
  125. package/filter/constants/Portals.js +39 -3
  126. package/filter/constants/index.js +8 -1
  127. package/filter/index.js +12 -4
  128. package/filter/reducers/helpers/enrichFilters.js +11 -3
  129. package/filter/reducers/index.js +5 -1
  130. package/filter/reducers/resultsByHash.js +43 -3
  131. package/filter/selectors/index.js +47 -6
  132. package/filter/streams/index.js +30 -1
  133. package/filter/subscriptions/index.js +34 -2
  134. package/market/constants/Portals.js +22 -4
  135. package/market/constants/index.js +2 -1
  136. package/market/helpers/showReturnPolicy.js +3 -1
  137. package/market/helpers/showTaxDisclaimer.js +3 -1
  138. package/market/index.js +6 -2
  139. package/orders/constants.js +2 -1
  140. package/package.json +4 -4
  141. package/product/action-creators/deleteProductsByIds.js +10 -2
  142. package/product/action-creators/errorProduct.js +10 -2
  143. package/product/action-creators/errorProductDescription.js +10 -2
  144. package/product/action-creators/errorProductImages.js +10 -2
  145. package/product/action-creators/errorProductMedia.js +10 -2
  146. package/product/action-creators/errorProductOptions.js +10 -2
  147. package/product/action-creators/errorProductProperties.js +10 -2
  148. package/product/action-creators/errorProductRelations.js +9 -2
  149. package/product/action-creators/errorProductShipping.js +10 -2
  150. package/product/action-creators/errorProductVariants.js +10 -2
  151. package/product/action-creators/errorProducts.js +9 -2
  152. package/product/action-creators/expireProductById.js +10 -2
  153. package/product/action-creators/expireProductData.js +11 -2
  154. package/product/action-creators/expireProductsByHash.js +9 -2
  155. package/product/action-creators/productNotAvailable.js +10 -2
  156. package/product/action-creators/provideProduct.js +9 -2
  157. package/product/action-creators/receiveProduct.js +10 -2
  158. package/product/action-creators/receiveProductCached.js +9 -2
  159. package/product/action-creators/receiveProductDescription.js +10 -2
  160. package/product/action-creators/receiveProductImages.js +10 -2
  161. package/product/action-creators/receiveProductMedia.js +10 -2
  162. package/product/action-creators/receiveProductOptions.js +10 -2
  163. package/product/action-creators/receiveProductProperties.js +10 -2
  164. package/product/action-creators/receiveProductRelations.js +12 -2
  165. package/product/action-creators/receiveProductShipping.js +10 -2
  166. package/product/action-creators/receiveProductVariants.js +10 -2
  167. package/product/action-creators/receiveProducts.js +16 -2
  168. package/product/action-creators/receiveProductsCached.js +9 -2
  169. package/product/action-creators/refreshExpiredPDPData.js +8 -2
  170. package/product/action-creators/requestProduct.js +10 -2
  171. package/product/action-creators/requestProductDescription.js +9 -2
  172. package/product/action-creators/requestProductImages.js +9 -2
  173. package/product/action-creators/requestProductMedia.js +9 -2
  174. package/product/action-creators/requestProductOptions.js +9 -2
  175. package/product/action-creators/requestProductProperties.js +9 -2
  176. package/product/action-creators/requestProductRelations.js +10 -2
  177. package/product/action-creators/requestProductShipping.js +9 -2
  178. package/product/action-creators/requestProductVariants.js +9 -2
  179. package/product/action-creators/requestProducts.js +9 -2
  180. package/product/action-creators/setProductId.js +9 -2
  181. package/product/action-creators/setProductQuantity.js +9 -2
  182. package/product/action-creators/setProductVariantId.js +9 -2
  183. package/product/actions/changeSortOrder.js +21 -2
  184. package/product/actions/fetchHighlightProducts.js +18 -2
  185. package/product/actions/fetchLiveshoppingProducts.js +14 -2
  186. package/product/actions/fetchProduct.js +52 -3
  187. package/product/actions/fetchProductDescription.js +30 -2
  188. package/product/actions/fetchProductImages.js +31 -2
  189. package/product/actions/fetchProductMedia.js +35 -2
  190. package/product/actions/fetchProductOptions.js +31 -2
  191. package/product/actions/fetchProductProperties.js +30 -2
  192. package/product/actions/fetchProductRelations.js +63 -2
  193. package/product/actions/fetchProductShipping.js +31 -2
  194. package/product/actions/fetchProductVariants.js +31 -2
  195. package/product/actions/fetchProducts.js +189 -17
  196. package/product/actions/fetchProductsById.js +68 -8
  197. package/product/actions/fetchProductsByQuery.js +102 -18
  198. package/product/actions/getHighlightProducts.js +6 -2
  199. package/product/actions/getLiveshoppingProducts.js +6 -2
  200. package/product/actions/getProduct.js +6 -2
  201. package/product/actions/getProductDescription.js +6 -2
  202. package/product/actions/getProductImages.js +6 -2
  203. package/product/actions/getProductOptions.js +6 -2
  204. package/product/actions/getProductProperties.js +6 -2
  205. package/product/actions/getProductRelations.js +6 -2
  206. package/product/actions/getProductShipping.js +6 -2
  207. package/product/actions/getProductVariants.js +6 -2
  208. package/product/actions/getProducts.js +6 -2
  209. package/product/actions/getProductsById.js +6 -2
  210. package/product/actions/getProductsByQuery.js +6 -2
  211. package/product/actions/processProductFlags.js +35 -3
  212. package/product/actions/updateMetadata.js +17 -2
  213. package/product/collections/ProductImageFormats.js +48 -8
  214. package/product/collections/index.js +1 -1
  215. package/product/constants/Pipelines.js +12 -1
  216. package/product/constants/Portals.js +200 -33
  217. package/product/constants/index.js +90 -18
  218. package/product/helpers/index.js +61 -8
  219. package/product/index.js +36 -6
  220. package/product/mock.js +1002 -2
  221. package/product/reducers/descriptionsByProductId.js +54 -5
  222. package/product/reducers/helpers/formatOptions.js +17 -2
  223. package/product/reducers/helpers/handleProductCollection.js +19 -2
  224. package/product/reducers/imagesByProductId.js +51 -4
  225. package/product/reducers/index.js +23 -1
  226. package/product/reducers/mediaByProductId.js +55 -3
  227. package/product/reducers/optionsByProductId.js +41 -2
  228. package/product/reducers/productRelationsByHash.js +43 -2
  229. package/product/reducers/productsById.js +122 -7
  230. package/product/reducers/propertiesByProductId.js +48 -2
  231. package/product/reducers/resultsByHash.js +125 -9
  232. package/product/reducers/shippingByProductId.js +37 -2
  233. package/product/reducers/variantsByProductId.js +56 -2
  234. package/product/selectors/options.js +90 -13
  235. package/product/selectors/page.js +62 -13
  236. package/product/selectors/price.js +81 -18
  237. package/product/selectors/product.js +549 -59
  238. package/product/selectors/product.mock.js +327 -12
  239. package/product/selectors/relations.js +35 -5
  240. package/product/selectors/variants.js +91 -15
  241. package/product/streams/index.js +167 -13
  242. package/product/subscriptions/index.js +210 -4
  243. package/reviews/action-creators/errorProductReviews.js +9 -2
  244. package/reviews/action-creators/errorReviews.js +9 -2
  245. package/reviews/action-creators/errorSubmitReview.js +9 -2
  246. package/reviews/action-creators/errorUserReview.js +9 -2
  247. package/reviews/action-creators/flushUserReview.js +8 -2
  248. package/reviews/action-creators/receiveProductReviews.js +11 -2
  249. package/reviews/action-creators/receiveReviews.js +12 -2
  250. package/reviews/action-creators/receiveSubmitReview.js +9 -2
  251. package/reviews/action-creators/receiveUserReview.js +10 -2
  252. package/reviews/action-creators/requestProductReviews.js +10 -2
  253. package/reviews/action-creators/requestReviews.js +9 -2
  254. package/reviews/action-creators/requestSubmitReview.js +9 -2
  255. package/reviews/action-creators/requestUserReview.js +9 -2
  256. package/reviews/action-creators/resetSubmittedReview.js +9 -2
  257. package/reviews/action-creators/spec.js +40 -1
  258. package/reviews/actions/fetchProductReviews.js +37 -2
  259. package/reviews/actions/fetchReviews.js +38 -2
  260. package/reviews/actions/fetchUserReview.js +31 -2
  261. package/reviews/actions/flushUserReview.js +5 -1
  262. package/reviews/actions/getProductReviews.js +6 -2
  263. package/reviews/actions/getUserReview.js +6 -2
  264. package/reviews/actions/spec.js +241 -4
  265. package/reviews/actions/submitReview.js +63 -3
  266. package/reviews/constants/Pipelines.js +4 -1
  267. package/reviews/constants/Portals.js +4 -1
  268. package/reviews/constants/index.js +26 -7
  269. package/reviews/index.js +15 -4
  270. package/reviews/mock.js +172 -11
  271. package/reviews/reducers/index.js +11 -1
  272. package/reviews/reducers/mock.js +14 -2
  273. package/reviews/reducers/reviewsByHash.js +52 -6
  274. package/reviews/reducers/reviewsById.js +27 -2
  275. package/reviews/reducers/reviewsByProductId.js +47 -2
  276. package/reviews/reducers/spec.js +211 -2
  277. package/reviews/reducers/userReviewsByProductId.js +68 -2
  278. package/reviews/selectors/index.js +123 -19
  279. package/reviews/selectors/mock.js +100 -1
  280. package/reviews/selectors/spec.js +100 -1
  281. package/reviews/streams/index.js +37 -5
  282. package/reviews/streams/spec.js +25 -1
  283. package/reviews/subscriptions/index.js +27 -2
  284. package/scanner/action-creators/errorHandleScanner.js +11 -2
  285. package/scanner/action-creators/scannerFinished.js +11 -2
  286. package/scanner/action-creators/startScanner.js +8 -2
  287. package/scanner/action-creators/successHandleScanner.js +11 -2
  288. package/scanner/actions/handleBarCode.js +22 -2
  289. package/scanner/actions/handleNoResults.js +23 -2
  290. package/scanner/actions/handleQrCode.js +116 -6
  291. package/scanner/actions/handleSearch.js +33 -2
  292. package/scanner/constants/Portals.js +22 -1
  293. package/scanner/constants/index.js +17 -1
  294. package/scanner/helpers/index.js +115 -5
  295. package/scanner/index.js +19 -5
  296. package/scanner/streams/index.js +36 -1
  297. package/scanner/subscriptions/index.js +78 -8
  298. package/search/action-creators/errorSearchResults.js +10 -2
  299. package/search/action-creators/receiveSearchResults.js +11 -2
  300. package/search/action-creators/receiveSearchSuggestions.js +10 -2
  301. package/search/action-creators/requestSearchResults.js +10 -2
  302. package/search/action-creators/requestSearchSuggestions.js +9 -2
  303. package/search/actions/fetchSearchResults.js +66 -8
  304. package/search/actions/fetchSearchSuggestions.js +36 -2
  305. package/search/constants/Pipelines.js +1 -1
  306. package/search/constants/Portals.js +9 -2
  307. package/search/constants/index.js +10 -2
  308. package/search/helpers/index.js +5 -2
  309. package/search/helpers/removeHighlightingPlaceholders.js +4 -1
  310. package/search/helpers/spec.js +19 -1
  311. package/search/index.js +17 -5
  312. package/search/reducers/index.js +38 -2
  313. package/search/selectors/index.js +23 -4
  314. package/search/streams/index.js +51 -3
  315. package/search/subscriptions/index.js +132 -5
@@ -1,7 +1,16 @@
1
- import{RECEIVE_SEARCH_RESULTS}from"../constants";/**
1
+ import { RECEIVE_SEARCH_RESULTS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched RECEIVE_SEARCH_RESULTS action object.
3
5
  * @param {string} searchPhrase The search phrase.
4
6
  * @param {number} offset The result offset.
5
7
  * @param {Object} results The search results.
6
8
  * @return {Object} The RECEIVE_SEARCH_RESULTS action.
7
- */var receiveSearchResults=function receiveSearchResults(searchPhrase,offset,results){return{type:RECEIVE_SEARCH_RESULTS,searchPhrase:searchPhrase,offset:offset,results:results};};export default receiveSearchResults;
9
+ */
10
+ const receiveSearchResults = (searchPhrase, offset, results) => ({
11
+ type: RECEIVE_SEARCH_RESULTS,
12
+ searchPhrase,
13
+ offset,
14
+ results
15
+ });
16
+ export default receiveSearchResults;
@@ -1,6 +1,14 @@
1
- import{RECEIVE_SEARCH_SUGGESTIONS}from"../constants";/**
1
+ import { RECEIVE_SEARCH_SUGGESTIONS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched RECEIVE_SEARCH_SUGGESTIONS action object.
3
5
  * @param {string} searchPhrase The search phrase.
4
6
  * @param {Array} suggestions Array of strings. The suggestions for the search phrase.
5
7
  * @return {Object} The RECEIVE_SEARCH_SUGGESTIONS action.
6
- */var receiveSearchSuggestions=function receiveSearchSuggestions(searchPhrase,suggestions){return{type:RECEIVE_SEARCH_SUGGESTIONS,searchPhrase:searchPhrase,suggestions:suggestions};};export default receiveSearchSuggestions;
8
+ */
9
+ const receiveSearchSuggestions = (searchPhrase, suggestions) => ({
10
+ type: RECEIVE_SEARCH_SUGGESTIONS,
11
+ searchPhrase,
12
+ suggestions
13
+ });
14
+ export default receiveSearchSuggestions;
@@ -1,6 +1,14 @@
1
- import{REQUEST_SEARCH_RESULTS}from"../constants";/**
1
+ import { REQUEST_SEARCH_RESULTS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched REQUEST_SEARCH_RESULTS action object.
3
5
  * @param {string} searchPhrase The search phrase.
4
6
  * @param {number} offset The result offset.
5
7
  * @return {Object} The REQUEST_SEARCH_RESULTS action.
6
- */var requestSearchResults=function requestSearchResults(searchPhrase,offset){return{type:REQUEST_SEARCH_RESULTS,searchPhrase:searchPhrase,offset:offset};};export default requestSearchResults;
8
+ */
9
+ const requestSearchResults = (searchPhrase, offset) => ({
10
+ type: REQUEST_SEARCH_RESULTS,
11
+ searchPhrase,
12
+ offset
13
+ });
14
+ export default requestSearchResults;
@@ -1,5 +1,12 @@
1
- import{REQUEST_SEARCH_SUGGESTIONS}from"../constants";/**
1
+ import { REQUEST_SEARCH_SUGGESTIONS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched REQUEST_SEARCH_SUGGESTIONS action object.
3
5
  * @param {string} searchPhrase The search phrase.
4
6
  * @return {Object} The REQUEST_SEARCH_SUGGESTIONS action.
5
- */var requestSearchSuggestions=function requestSearchSuggestions(searchPhrase){return{type:REQUEST_SEARCH_SUGGESTIONS,searchPhrase:searchPhrase};};export default requestSearchSuggestions;
7
+ */
8
+ const requestSearchSuggestions = searchPhrase => ({
9
+ type: REQUEST_SEARCH_SUGGESTIONS,
10
+ searchPhrase
11
+ });
12
+ export default requestSearchSuggestions;
@@ -1,4 +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);}import{ITEMS_PER_LOAD}from'@shopgate/pwa-common/constants/DisplayOptions';import{mutable}from'@shopgate/pwa-common/helpers/redux';import{makeGetDefaultSortOrder}from'@shopgate/engage/filter/selectors';import fetchProducts from"../../product/actions/fetchProducts";import requestSearchResults from"../action-creators/requestSearchResults";import receiveSearchResults from"../action-creators/receiveSearchResults";import errorSearchResults from"../action-creators/errorSearchResults";var getDefaultSortOrder=makeGetDefaultSortOrder();/**
1
+ import { ITEMS_PER_LOAD } from '@shopgate/pwa-common/constants/DisplayOptions';
2
+ import { mutable } from '@shopgate/pwa-common/helpers/redux';
3
+ import { makeGetDefaultSortOrder } from '@shopgate/engage/filter/selectors';
4
+ import fetchProducts from "../../product/actions/fetchProducts";
5
+ import requestSearchResults from "../action-creators/requestSearchResults";
6
+ import receiveSearchResults from "../action-creators/receiveSearchResults";
7
+ import errorSearchResults from "../action-creators/errorSearchResults";
8
+ const getDefaultSortOrder = makeGetDefaultSortOrder();
9
+
10
+ /**
2
11
  * Retrieves products for a certain search query.
3
12
  * @param {Object} params The params for the search products to request.
4
13
  * @param {string} params.searchPhrase Search phrase for the request
@@ -11,13 +20,62 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
11
20
  * @param {boolean} [params.resolveCachedProducts=false] Whether to resolve with products even
12
21
  * when no actual request was done due to cached data.
13
22
  * @return {Function} The dispatched action.
14
- */var fetchSearchResults=function fetchSearchResults(params){return function(dispatch,getState){var defaultSortOrder=getDefaultSortOrder(getState(),{searchPhrase:params.searchPhrase});var _params$offset=params.offset,offset=_params$offset===void 0?0:_params$offset,searchPhrase=params.searchPhrase,_params$limit=params.limit,limit=_params$limit===void 0?ITEMS_PER_LOAD:_params$limit,_params$sort=params.sort,sort=_params$sort===void 0?defaultSortOrder:_params$sort,_params$filters=params.filters,filters=_params$filters===void 0?null:_params$filters,_params$params=params.params,searchParams=_params$params===void 0?null:_params$params,_params$cachedTime=params.cachedTime,cachedTime=_params$cachedTime===void 0?null:_params$cachedTime,_params$resolveCached=params.resolveCachedProducts,resolveCachedProducts=_params$resolveCached===void 0?false:_params$resolveCached;if(!searchPhrase){return;}var promise=dispatch(fetchProducts({cachedTime:cachedTime,params:_extends({searchPhrase:searchPhrase,offset:offset,limit:limit,sort:sort},searchParams),filters:filters,resolveCachedProducts:resolveCachedProducts,onBeforeDispatch:function onBeforeDispatch(){// Dispatch the request action before the related pipeline request is executed.
15
- dispatch(requestSearchResults(searchPhrase,offset));}}));/**
23
+ */
24
+ const fetchSearchResults = params => (dispatch, getState) => {
25
+ const defaultSortOrder = getDefaultSortOrder(getState(), {
26
+ searchPhrase: params.searchPhrase
27
+ });
28
+ const {
29
+ offset = 0,
30
+ searchPhrase,
31
+ limit = ITEMS_PER_LOAD,
32
+ sort = defaultSortOrder,
33
+ filters = null,
34
+ params: searchParams = null,
35
+ cachedTime = null,
36
+ resolveCachedProducts = false
37
+ } = params;
38
+ if (!searchPhrase) {
39
+ return;
40
+ }
41
+ const promise = dispatch(fetchProducts({
42
+ cachedTime,
43
+ params: {
44
+ searchPhrase,
45
+ offset,
46
+ limit,
47
+ sort,
48
+ ...searchParams
49
+ },
50
+ filters,
51
+ resolveCachedProducts,
52
+ onBeforeDispatch: () => {
53
+ // Dispatch the request action before the related pipeline request is executed.
54
+ dispatch(requestSearchResults(searchPhrase, offset));
55
+ }
56
+ }));
57
+
58
+ /**
16
59
  * Whenever fetchProducts is able to deliver product data
17
60
  * - either via a request or from the cache -
18
61
  * it returns a promise which will be resolved with the response data.
19
- */if(promise instanceof Promise){promise.then(function(response){// Inspect the response object to determine, if it represents a search result, or an error.
20
- if(response&&response.products&&Array.isArray(response.products)){// Dispatch the receive action when the response contains valid data.s
21
- dispatch(receiveSearchResults(searchPhrase,offset,response));}else{// If no valid data is delivered within the response the error action is dispatched.
22
- dispatch(errorSearchResults(searchPhrase,offset));}});}// eslint-disable-next-line consistent-return
23
- return promise;};};/** @mixes {MutableFunction} */export default mutable(fetchSearchResults);
62
+ */
63
+ if (promise instanceof Promise) {
64
+ promise.then(response => {
65
+ // Inspect the response object to determine, if it represents a search result, or an error.
66
+ if (response && response.products && Array.isArray(response.products)) {
67
+ // Dispatch the receive action when the response contains valid data.s
68
+ dispatch(receiveSearchResults(searchPhrase, offset, response));
69
+ } else {
70
+ // If no valid data is delivered within the response the error action is dispatched.
71
+ dispatch(errorSearchResults(searchPhrase, offset));
72
+ }
73
+ });
74
+ }
75
+
76
+ // eslint-disable-next-line consistent-return
77
+ return promise;
78
+ };
79
+
80
+ /** @mixes {MutableFunction} */
81
+ export default mutable(fetchSearchResults);
@@ -1,5 +1,39 @@
1
- import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{mutable}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_CATALOG_GET_SEARCH_SUGGESTIONS}from"../constants/Pipelines";import requestSearchSuggestions from"../action-creators/requestSearchSuggestions";import receiveSearchSuggestions from"../action-creators/receiveSearchSuggestions";import{getSuggestionsState}from"../selectors";import removeHighlightingPlaceholders from"../helpers/removeHighlightingPlaceholders";/**
1
+ import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
2
+ import { mutable } from '@shopgate/pwa-common/helpers/redux';
3
+ import { SHOPGATE_CATALOG_GET_SEARCH_SUGGESTIONS } from "../constants/Pipelines";
4
+ import requestSearchSuggestions from "../action-creators/requestSearchSuggestions";
5
+ import receiveSearchSuggestions from "../action-creators/receiveSearchSuggestions";
6
+ import { getSuggestionsState } from "../selectors";
7
+ import removeHighlightingPlaceholders from "../helpers/removeHighlightingPlaceholders";
8
+
9
+ /**
2
10
  * Get suggestions from cache or pipeline.
3
11
  * @param {string} searchPhrase The search phrase.
4
12
  * @returns {Function} A redux thunk.
5
- */function fetchSearchSuggestions(searchPhrase){return function(dispatch,getState){if(searchPhrase.length<3){return Promise.resolve(null);}var cached=getSuggestionsState(getState())[searchPhrase];if(cached&&(cached.isFetching||cached.expires>=Date.now())){return Promise.resolve(null);}dispatch(requestSearchSuggestions(searchPhrase));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_SEARCH_SUGGESTIONS).setInput({searchPhrase:searchPhrase}).dispatch();request.then(function(result){var suggestions=result.suggestions;var suggestionsWithoutPlaceholders=removeHighlightingPlaceholders(suggestions);dispatch(receiveSearchSuggestions(searchPhrase,suggestionsWithoutPlaceholders));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchSearchSuggestions);
13
+ */
14
+ function fetchSearchSuggestions(searchPhrase) {
15
+ return (dispatch, getState) => {
16
+ if (searchPhrase.length < 3) {
17
+ return Promise.resolve(null);
18
+ }
19
+ const cached = getSuggestionsState(getState())[searchPhrase];
20
+ if (cached && (cached.isFetching || cached.expires >= Date.now())) {
21
+ return Promise.resolve(null);
22
+ }
23
+ dispatch(requestSearchSuggestions(searchPhrase));
24
+ const request = new PipelineRequest(SHOPGATE_CATALOG_GET_SEARCH_SUGGESTIONS).setInput({
25
+ searchPhrase
26
+ }).dispatch();
27
+ request.then(result => {
28
+ const {
29
+ suggestions
30
+ } = result;
31
+ const suggestionsWithoutPlaceholders = removeHighlightingPlaceholders(suggestions);
32
+ dispatch(receiveSearchSuggestions(searchPhrase, suggestionsWithoutPlaceholders));
33
+ });
34
+ return request;
35
+ };
36
+ }
37
+
38
+ /** @mixes {MutableFunction} */
39
+ export default mutable(fetchSearchSuggestions);
@@ -1 +1 @@
1
- export var SHOPGATE_CATALOG_GET_SEARCH_SUGGESTIONS='shopgate.catalog.getSearchSuggestions';
1
+ export const SHOPGATE_CATALOG_GET_SEARCH_SUGGESTIONS = 'shopgate.catalog.getSearchSuggestions';
@@ -1,3 +1,10 @@
1
1
  // FEATURES
2
- var SEARCH='search';// CONTENTS
3
- var SUGGESTIONS='suggestions';var SUGGESTION_ITEM='suggestion-item';var SUGGESTION_ITEM_CONTENT='suggestion-item-content';export var SEARCH_SUGGESTIONS="".concat(SEARCH,".").concat(SUGGESTIONS);export var SEARCH_SUGGESTION_ITEM="".concat(SEARCH,".").concat(SUGGESTION_ITEM);export var SEARCH_SUGGESTION_ITEM_CONTENT="".concat(SEARCH,".").concat(SUGGESTION_ITEM_CONTENT);
2
+ const SEARCH = 'search';
3
+
4
+ // CONTENTS
5
+ const SUGGESTIONS = 'suggestions';
6
+ const SUGGESTION_ITEM = 'suggestion-item';
7
+ const SUGGESTION_ITEM_CONTENT = 'suggestion-item-content';
8
+ export const SEARCH_SUGGESTIONS = `${SEARCH}.${SUGGESTIONS}`;
9
+ export const SEARCH_SUGGESTION_ITEM = `${SEARCH}.${SUGGESTION_ITEM}`;
10
+ export const SEARCH_SUGGESTION_ITEM_CONTENT = `${SEARCH}.${SUGGESTION_ITEM_CONTENT}`;
@@ -1,2 +1,10 @@
1
- export var SEARCH_PATH='/search';export var SEARCH_PATTERN=SEARCH_PATH;export var SEARCH_FILTER_PATTERN="".concat(SEARCH_PATH,"/filter");export var SEARCH_SUGGESTIONS_LIFETIME=86400000;// 24 hours in milliseconds
2
- export var REQUEST_SEARCH_RESULTS='REQUEST_SEARCH_RESULTS';export var RECEIVE_SEARCH_RESULTS='RECEIVE_SEARCH_RESULTS';export var ERROR_SEARCH_RESULTS='ERROR_SEARCH_RESULTS';export var REQUEST_SEARCH_SUGGESTIONS='REQUEST_SEARCH_SUGGESTIONS';export var RECEIVE_SEARCH_SUGGESTIONS='RECEIVE_SEARCH_SUGGESTIONS';
1
+ export const SEARCH_PATH = '/search';
2
+ export const SEARCH_PATTERN = SEARCH_PATH;
3
+ export const SEARCH_FILTER_PATTERN = `${SEARCH_PATH}/filter`;
4
+ export const SEARCH_SUGGESTIONS_LIFETIME = 86400000; // 24 hours in milliseconds
5
+
6
+ export const REQUEST_SEARCH_RESULTS = 'REQUEST_SEARCH_RESULTS';
7
+ export const RECEIVE_SEARCH_RESULTS = 'RECEIVE_SEARCH_RESULTS';
8
+ export const ERROR_SEARCH_RESULTS = 'ERROR_SEARCH_RESULTS';
9
+ export const REQUEST_SEARCH_SUGGESTIONS = 'REQUEST_SEARCH_SUGGESTIONS';
10
+ export const RECEIVE_SEARCH_SUGGESTIONS = 'RECEIVE_SEARCH_SUGGESTIONS';
@@ -1,5 +1,8 @@
1
- import{SEARCH_PATH}from"../constants";/**
1
+ import { SEARCH_PATH } from "../constants";
2
+
3
+ /**
2
4
  * Generate product route for navigation.
3
5
  * @param {string} query search term
4
6
  * @returns {string}
5
- */export var getSearchRoute=function getSearchRoute(query){return"".concat(SEARCH_PATH,"?s=").concat(encodeURIComponent(query));};
7
+ */
8
+ export const getSearchRoute = query => `${SEARCH_PATH}?s=${encodeURIComponent(query)}`;
@@ -1,3 +1,4 @@
1
+ import "core-js/modules/es.string.replace.js";
1
2
  /**
2
3
  * Pipeline call adds $start$ and $end$ placeholders for higlighting purposes.
3
4
  *
@@ -6,4 +7,6 @@
6
7
  *
7
8
  * @param {Array} suggestions An array of strings.
8
9
  * @returns {Array}
9
- */var removeHighlightingPlaceholers=function removeHighlightingPlaceholers(suggestions){return suggestions.map(function(item){return item.replace(/\$start\$|\$end\$/g,'');});};export default removeHighlightingPlaceholers;
10
+ */
11
+ const removeHighlightingPlaceholers = suggestions => suggestions.map(item => item.replace(/\$start\$|\$end\$/g, ''));
12
+ export default removeHighlightingPlaceholers;
@@ -1 +1,19 @@
1
- import removeHighlightingPlaceholders from"./removeHighlightingPlaceholders";describe('search/helpers',function(){describe('removeHighlightingPlaceholers test',function(){it('should not change string without placeholders',function(){var result=removeHighlightingPlaceholders(['foo','bar']);expect(result[0]).toBe('foo');});it('should remove $start$ and $end$',function(){var testArray=['$start$foo$end$','$start$$end$','$end$$start$','$start$foo$end$'];var result=removeHighlightingPlaceholders(testArray);result.forEach(function(item,key){expect(item.indexOf('start')).toBe(-1);expect(item.indexOf('end')).toBe(-1);expect(item.indexOf('$')).toBe(-1);expect(item.length).toBe(Math.max(testArray[key].length-12,0));});});});});
1
+ import removeHighlightingPlaceholders from "./removeHighlightingPlaceholders";
2
+ describe('search/helpers', () => {
3
+ describe('removeHighlightingPlaceholers test', () => {
4
+ it('should not change string without placeholders', () => {
5
+ const result = removeHighlightingPlaceholders(['foo', 'bar']);
6
+ expect(result[0]).toBe('foo');
7
+ });
8
+ it('should remove $start$ and $end$', () => {
9
+ const testArray = ['$start$foo$end$', '$start$$end$', '$end$$start$', '$start$foo$end$'];
10
+ const result = removeHighlightingPlaceholders(testArray);
11
+ result.forEach((item, key) => {
12
+ expect(item.indexOf('start')).toBe(-1);
13
+ expect(item.indexOf('end')).toBe(-1);
14
+ expect(item.indexOf('$')).toBe(-1);
15
+ expect(item.length).toBe(Math.max(testArray[key].length - 12, 0));
16
+ });
17
+ });
18
+ });
19
+ });
package/search/index.js CHANGED
@@ -1,6 +1,18 @@
1
1
  // ACTIONS
2
- export{default as fetchSearchResults}from"./actions/fetchSearchResults";export{default as fetchSearchSuggestions}from"./actions/fetchSearchSuggestions";// CONSTANTS
3
- export*from"./constants/index";export*from"./constants/Pipelines";export*from"./constants/Portals";// HELPERS
4
- export{default as removeHighlightingPlaceholers}from"./helpers/removeHighlightingPlaceholders";export*from"./helpers";// SELECTORS
5
- export*from"./selectors";// STREAMS
6
- export*from"./streams";
2
+ export { default as fetchSearchResults } from "./actions/fetchSearchResults";
3
+ export { default as fetchSearchSuggestions } from "./actions/fetchSearchSuggestions";
4
+
5
+ // CONSTANTS
6
+ export * from "./constants/index";
7
+ export * from "./constants/Pipelines";
8
+ export * from "./constants/Portals";
9
+
10
+ // HELPERS
11
+ export { default as removeHighlightingPlaceholers } from "./helpers/removeHighlightingPlaceholders";
12
+ export * from "./helpers";
13
+
14
+ // SELECTORS
15
+ export * from "./selectors";
16
+
17
+ // STREAMS
18
+ export * from "./streams";
@@ -1,6 +1,42 @@
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_SEARCH_SUGGESTIONS,RECEIVE_SEARCH_SUGGESTIONS,SEARCH_SUGGESTIONS_LIFETIME}from"../constants";var initialState={suggestions:{}};/**
1
+ import { REQUEST_SEARCH_SUGGESTIONS, RECEIVE_SEARCH_SUGGESTIONS, SEARCH_SUGGESTIONS_LIFETIME } from "../constants";
2
+ const initialState = {
3
+ suggestions: {}
4
+ };
5
+
6
+ /**
2
7
  * The search suggestions reducer.
3
8
  * @param {Object} [state={}] The current search suggestions state.
4
9
  * @param {Object} action The action object.
5
10
  * @return {Object} The updated search suggestions data.
6
- */var search=function search(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:initialState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_SEARCH_SUGGESTIONS:return _extends({},state,{suggestions:_extends({},state.suggestions,_defineProperty({},action.searchPhrase,{isFetching:true,suggestions:[],expires:0}))});case RECEIVE_SEARCH_SUGGESTIONS:return _extends({},state,{suggestions:_extends({},state.suggestions,_defineProperty({},action.searchPhrase,{isFetching:false,suggestions:action.suggestions,expires:Date.now()+SEARCH_SUGGESTIONS_LIFETIME}))});default:return state;}};export default search;
11
+ */
12
+ const search = (state = initialState, action) => {
13
+ switch (action.type) {
14
+ case REQUEST_SEARCH_SUGGESTIONS:
15
+ return {
16
+ ...state,
17
+ suggestions: {
18
+ ...state.suggestions,
19
+ [action.searchPhrase]: {
20
+ isFetching: true,
21
+ suggestions: [],
22
+ expires: 0
23
+ }
24
+ }
25
+ };
26
+ case RECEIVE_SEARCH_SUGGESTIONS:
27
+ return {
28
+ ...state,
29
+ suggestions: {
30
+ ...state.suggestions,
31
+ [action.searchPhrase]: {
32
+ isFetching: false,
33
+ suggestions: action.suggestions,
34
+ expires: Date.now() + SEARCH_SUGGESTIONS_LIFETIME
35
+ }
36
+ }
37
+ };
38
+ default:
39
+ return state;
40
+ }
41
+ };
42
+ export default search;
@@ -1,14 +1,33 @@
1
- import{createSelector}from'reselect';/**
1
+ import { createSelector } from 'reselect';
2
+
3
+ /**
2
4
  * @param {Object} state The appllication state.
3
5
  * @return {Object}
4
- */export var getSuggestionsState=function getSuggestionsState(state){return state.search.suggestions;};/**
6
+ */
7
+ export const getSuggestionsState = state => state.search.suggestions;
8
+
9
+ /**
5
10
  * Retrieves the search suggestions for a passed search phrase.
6
11
  * @param {Object} state The application state.
7
12
  * @param {Object} props The component props.
8
13
  * @returns {Object|null} The suggestions
9
- */export var getSuggestions=createSelector(getSuggestionsState,function(state,props){return props.searchPhrase;},function(suggestions,phrase){if(!phrase||!suggestions[phrase]){return null;}return suggestions[phrase].suggestions;});/**
14
+ */
15
+ export const getSuggestions = createSelector(getSuggestionsState, (state, props) => props.searchPhrase, (suggestions, phrase) => {
16
+ if (!phrase || !suggestions[phrase]) {
17
+ return null;
18
+ }
19
+ return suggestions[phrase].suggestions;
20
+ });
21
+
22
+ /**
10
23
  * Detects if suggestions for a passed search phrase are currently fetching.
11
24
  * @param {Object} state The application state.
12
25
  * @param {Object} props The component props.
13
26
  * @returns {boolean}
14
- */export var getSuggestionsFetchingState=createSelector(getSuggestionsState,function(state,props){return props.searchPhrase;},function(suggestions,phrase){if(!phrase||!suggestions[phrase]){return false;}return suggestions[phrase].isFetching;});
27
+ */
28
+ export const getSuggestionsFetchingState = createSelector(getSuggestionsState, (state, props) => props.searchPhrase, (suggestions, phrase) => {
29
+ if (!phrase || !suggestions[phrase]) {
30
+ return false;
31
+ }
32
+ return suggestions[phrase].isFetching;
33
+ });
@@ -1,7 +1,55 @@
1
- import{ACTION_REPLACE}from'@virtuous/conductor';import{main$}from'@shopgate/pwa-common/streams/main';import{routeWillEnter$,routeDidEnter$,routeWillLeave$,routeDidUpdate$}from'@shopgate/pwa-common/streams/router';import{HISTORY_POP_ACTION}from'@shopgate/pwa-common/constants/ActionTypes';import{filtersDidUpdate$}from'@shopgate/pwa-common-commerce/filter/streams';import{SEARCH_PATH}from'@shopgate/pwa-common-commerce/search/constants';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{preferredLocationDidUpdate$,preferredLocationDidUpdateGlobalNotOnSearch$,preferredLocationDidUpdateGlobalOnSearch$}from'@shopgate/engage/locations/locations.streams';import{CATEGORY_ALL_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{filterWillLeave$}from"../../filter/streams";import{REQUEST_SEARCH_RESULTS,RECEIVE_SEARCH_RESULTS,ERROR_SEARCH_RESULTS,SEARCH_PATTERN}from"../constants";/**
1
+ import { ACTION_REPLACE } from '@virtuous/conductor';
2
+ import { main$ } from '@shopgate/pwa-common/streams/main';
3
+ import { routeWillEnter$, routeDidEnter$, routeWillLeave$, routeDidUpdate$ } from '@shopgate/pwa-common/streams/router';
4
+ import { HISTORY_POP_ACTION } from '@shopgate/pwa-common/constants/ActionTypes';
5
+ import { filtersDidUpdate$ } from '@shopgate/pwa-common-commerce/filter/streams';
6
+ import { SEARCH_PATH } from '@shopgate/pwa-common-commerce/search/constants';
7
+ import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
8
+ import { preferredLocationDidUpdate$, preferredLocationDidUpdateGlobalNotOnSearch$, preferredLocationDidUpdateGlobalOnSearch$ } from '@shopgate/engage/locations/locations.streams';
9
+ import { CATEGORY_ALL_PATTERN } from '@shopgate/pwa-common-commerce/category/constants';
10
+ import { filterWillLeave$ } from "../../filter/streams";
11
+ import { REQUEST_SEARCH_RESULTS, RECEIVE_SEARCH_RESULTS, ERROR_SEARCH_RESULTS, SEARCH_PATTERN } from "../constants";
12
+
13
+ /**
2
14
  * Gets triggered when search results are requested.
3
15
  * @type {Observable}
4
- */export var searchRequesting$=main$.filter(function(_ref){var action=_ref.action;return action.type===REQUEST_SEARCH_RESULTS;});/**
16
+ */
17
+ export const searchRequesting$ = main$.filter(({
18
+ action
19
+ }) => action.type === REQUEST_SEARCH_RESULTS);
20
+
21
+ /**
5
22
  * Gets triggered when search results are received.
6
23
  * @type {Observable}
7
- */export var searchReceived$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===RECEIVE_SEARCH_RESULTS||action.type===ERROR_SEARCH_RESULTS;});export var searchWillEnter$=routeWillEnter$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===SEARCH_PATTERN;});export var searchDidEnter$=routeDidEnter$.filter(function(_ref4){var action=_ref4.action;return action.route.pattern===SEARCH_PATTERN;});export var searchWillLeave$=routeWillLeave$.filter(function(_ref5){var action=_ref5.action;return action.route.pattern===SEARCH_PATTERN;});export var searchWillUpdate$=routeWillEnter$.filter(function(_ref6){var action=_ref6.action;return action.route.pattern===SEARCH_PATTERN&&action.historyAction===ACTION_REPLACE;});export var searchDidBackEntered$=searchDidEnter$.filter(function(_ref7){var action=_ref7.action;return action.historyAction===HISTORY_POP_ACTION;});export var searchFiltersDidUpdate$=filtersDidUpdate$.filter(function(_ref8){var getState=_ref8.getState;var _getCurrentRoute=getCurrentRoute(getState()),pattern=_getCurrentRoute.pattern;return pattern===SEARCH_PATH||pattern===CATEGORY_ALL_PATTERN;});export var searchProductsNeedUpdate$=preferredLocationDidUpdate$.merge(preferredLocationDidUpdateGlobalNotOnSearch$).switchMap(function(){return searchDidBackEntered$.first();}).merge(searchFiltersDidUpdate$).merge(preferredLocationDidUpdateGlobalOnSearch$);export var searchDidUpdate$=routeDidUpdate$.filter(function(_ref9){var _action$route;var action=_ref9.action;return(action===null||action===void 0?void 0:(_action$route=action.route)===null||_action$route===void 0?void 0:_action$route.pattern)===SEARCH_PATTERN;});export var searchFiltersDidUpdateFromFilterPage$=searchDidUpdate$.switchMap(function(){return filterWillLeave$.first();}).switchMap(function(){return searchWillEnter$.first();});
24
+ */
25
+ export const searchReceived$ = main$.filter(({
26
+ action
27
+ }) => action.type === RECEIVE_SEARCH_RESULTS || action.type === ERROR_SEARCH_RESULTS);
28
+ export const searchWillEnter$ = routeWillEnter$.filter(({
29
+ action
30
+ }) => action.route.pattern === SEARCH_PATTERN);
31
+ export const searchDidEnter$ = routeDidEnter$.filter(({
32
+ action
33
+ }) => action.route.pattern === SEARCH_PATTERN);
34
+ export const searchWillLeave$ = routeWillLeave$.filter(({
35
+ action
36
+ }) => action.route.pattern === SEARCH_PATTERN);
37
+ export const searchWillUpdate$ = routeWillEnter$.filter(({
38
+ action
39
+ }) => action.route.pattern === SEARCH_PATTERN && action.historyAction === ACTION_REPLACE);
40
+ export const searchDidBackEntered$ = searchDidEnter$.filter(({
41
+ action
42
+ }) => action.historyAction === HISTORY_POP_ACTION);
43
+ export const searchFiltersDidUpdate$ = filtersDidUpdate$.filter(({
44
+ getState
45
+ }) => {
46
+ const {
47
+ pattern
48
+ } = getCurrentRoute(getState());
49
+ return pattern === SEARCH_PATH || pattern === CATEGORY_ALL_PATTERN;
50
+ });
51
+ export const searchProductsNeedUpdate$ = preferredLocationDidUpdate$.merge(preferredLocationDidUpdateGlobalNotOnSearch$).switchMap(() => searchDidBackEntered$.first()).merge(searchFiltersDidUpdate$).merge(preferredLocationDidUpdateGlobalOnSearch$);
52
+ export const searchDidUpdate$ = routeDidUpdate$.filter(({
53
+ action
54
+ }) => action?.route?.pattern === SEARCH_PATTERN);
55
+ export const searchFiltersDidUpdateFromFilterPage$ = searchDidUpdate$.switchMap(() => filterWillLeave$.first()).switchMap(() => searchWillEnter$.first());
@@ -1,7 +1,134 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function 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{LoadingProvider}from'@shopgate/pwa-common/providers';import{ACTION_PUSH,ACTION_REPLACE}from'@virtuous/conductor';import{buildFetchSearchResultsParams,getProductsResult}from'@shopgate/engage/product';import{hex2bin,router}from'@shopgate/engage/core';import{CATEGORY_ALL_PATTERN,fetchCategory,getShowAllProductsFilters}from'@shopgate/engage/category';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import expireProductsByHash from'@shopgate/pwa-common-commerce/product/action-creators/expireProductsByHash';import fetchSearchResults from'@shopgate/pwa-common-commerce/search/actions/fetchSearchResults';import fetchFilters from'@shopgate/pwa-common-commerce/filter/actions/fetchFilters';import{buildFilterParamsForFetchFiltersRequest}from'@shopgate/engage/filter/helpers';import{categoryAllWillEnter$,categoryAllFiltersDidUpdateFromFilterPage$}from'@shopgate/pwa-common-commerce/category/streams';import{searchWillEnter$,searchFiltersDidUpdateFromFilterPage$,searchRequesting$,searchReceived$,searchProductsNeedUpdate$}from"../streams";import{SEARCH_PATTERN}from"../constants";var searchBasedRouteWillEnter$=searchWillEnter$.merge(categoryAllWillEnter$);var searchBasedFiltersDidUpdateFromFilterPage$=searchFiltersDidUpdateFromFilterPage$.merge(categoryAllFiltersDidUpdateFromFilterPage$);/**
1
+ import { LoadingProvider } from '@shopgate/pwa-common/providers';
2
+ import { ACTION_PUSH, ACTION_REPLACE } from '@virtuous/conductor';
3
+ import { buildFetchSearchResultsParams, getProductsResult } from '@shopgate/engage/product';
4
+ import { hex2bin, router } from '@shopgate/engage/core';
5
+ import { CATEGORY_ALL_PATTERN, fetchCategory, getShowAllProductsFilters } from '@shopgate/engage/category';
6
+ import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
7
+ import expireProductsByHash from '@shopgate/pwa-common-commerce/product/action-creators/expireProductsByHash';
8
+ import fetchSearchResults from '@shopgate/pwa-common-commerce/search/actions/fetchSearchResults';
9
+ import fetchFilters from '@shopgate/pwa-common-commerce/filter/actions/fetchFilters';
10
+ import { buildFilterParamsForFetchFiltersRequest } from '@shopgate/engage/filter/helpers';
11
+ import { categoryAllWillEnter$, categoryAllFiltersDidUpdateFromFilterPage$ } from '@shopgate/pwa-common-commerce/category/streams';
12
+ import { searchWillEnter$, searchFiltersDidUpdateFromFilterPage$, searchRequesting$, searchReceived$, searchProductsNeedUpdate$ } from "../streams";
13
+ import { SEARCH_PATTERN } from "../constants";
14
+ const searchBasedRouteWillEnter$ = searchWillEnter$.merge(categoryAllWillEnter$);
15
+ const searchBasedFiltersDidUpdateFromFilterPage$ = searchFiltersDidUpdateFromFilterPage$.merge(categoryAllFiltersDidUpdateFromFilterPage$);
16
+
17
+ /**
2
18
  * Search subscriptions.
3
19
  * @param {Function} subscribe The subscribe function.
4
- */export default function search(subscribe){subscribe(searchRequesting$,function(){LoadingProvider.setLoading(SEARCH_PATTERN);});subscribe(searchReceived$,function(){LoadingProvider.unsetLoading(SEARCH_PATTERN);});subscribe(searchBasedRouteWillEnter$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var _action$route;var action,dispatch,getState,filters,searchPhrase,sort,category,_getProductsResult,hash,expired;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:action=_ref.action,dispatch=_ref.dispatch,getState=_ref.getState;if([ACTION_PUSH,ACTION_REPLACE].includes(action===null||action===void 0?void 0:action.historyAction)){_context.next=3;break;}return _context.abrupt("return");case 3:filters=action.route.state.filters;searchPhrase=action.route.query.s;sort=action.route.query.sort;if(!(action.route.pattern===CATEGORY_ALL_PATTERN)){_context.next=14;break;}searchPhrase='*';if(filters){_context.next=14;break;}_context.next=11;return dispatch(fetchCategory(hex2bin(action.route.params.categoryId)));case 11:category=_context.sent;filters=getShowAllProductsFilters(category);router.update(action.route.id,{filters:filters,categoryName:category.name});case 14:_getProductsResult=getProductsResult(getState(),_extends({searchPhrase:searchPhrase,routeId:action===null||action===void 0?void 0:(_action$route=action.route)===null||_action$route===void 0?void 0:_action$route.id},buildFetchSearchResultsParams())),hash=_getProductsResult.hash,expired=_getProductsResult.expired;if(expired){dispatch(expireProductsByHash(hash));}dispatch(fetchSearchResults(_extends({filters:filters,searchPhrase:searchPhrase,sort:sort},buildFetchSearchResultsParams())));dispatch(fetchFilters({filters:buildFilterParamsForFetchFiltersRequest(filters)}));case 18:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());// No logic related to "show all products" necessary here, since stream only emits when
5
- // location based shopping is active. That's currently only supported when new services are
6
- // used, but the new services don't support "show all products".
7
- subscribe(searchProductsNeedUpdate$,function(_ref3){var dispatch=_ref3.dispatch,getState=_ref3.getState;var _getCurrentRoute=getCurrentRoute(getState()),query=_getCurrentRoute.query,filters=_getCurrentRoute.state.filters,pattern=_getCurrentRoute.pattern;var sort=query.sort;var searchPhrase=query.s;if(pattern===CATEGORY_ALL_PATTERN){searchPhrase='*';}dispatch(fetchSearchResults(_extends({filters:filters,searchPhrase:searchPhrase,sort:sort},buildFetchSearchResultsParams())));});subscribe(searchBasedFiltersDidUpdateFromFilterPage$,function(_ref4){var dispatch=_ref4.dispatch,action=_ref4.action;var filters=action.route.state.filters;var pattern=action.route.pattern;var sort=action.route.query.sort;var searchPhrase=action.route.query.s;if(pattern===CATEGORY_ALL_PATTERN){searchPhrase='*';}dispatch(fetchSearchResults(_extends({filters:filters,searchPhrase:searchPhrase,sort:sort},buildFetchSearchResultsParams())));});}
20
+ */
21
+ export default function search(subscribe) {
22
+ subscribe(searchRequesting$, () => {
23
+ LoadingProvider.setLoading(SEARCH_PATTERN);
24
+ });
25
+ subscribe(searchReceived$, () => {
26
+ LoadingProvider.unsetLoading(SEARCH_PATTERN);
27
+ });
28
+ subscribe(searchBasedRouteWillEnter$, async ({
29
+ action,
30
+ dispatch,
31
+ getState
32
+ }) => {
33
+ if (![ACTION_PUSH, ACTION_REPLACE].includes(action?.historyAction)) {
34
+ return;
35
+ }
36
+ let {
37
+ filters
38
+ } = action.route.state;
39
+ let {
40
+ s: searchPhrase
41
+ } = action.route.query;
42
+ const {
43
+ sort
44
+ } = action.route.query;
45
+ if (action.route.pattern === CATEGORY_ALL_PATTERN) {
46
+ searchPhrase = '*';
47
+ if (!filters) {
48
+ const category = await dispatch(fetchCategory(hex2bin(action.route.params.categoryId)));
49
+ filters = getShowAllProductsFilters(category);
50
+ router.update(action.route.id, {
51
+ filters,
52
+ categoryName: category.name
53
+ });
54
+ }
55
+ }
56
+ const {
57
+ hash,
58
+ expired
59
+ } = getProductsResult(getState(), {
60
+ searchPhrase,
61
+ routeId: action?.route?.id,
62
+ ...buildFetchSearchResultsParams()
63
+ });
64
+ if (expired) {
65
+ dispatch(expireProductsByHash(hash));
66
+ }
67
+ dispatch(fetchSearchResults({
68
+ filters,
69
+ searchPhrase,
70
+ sort,
71
+ ...buildFetchSearchResultsParams()
72
+ }));
73
+ dispatch(fetchFilters({
74
+ filters: buildFilterParamsForFetchFiltersRequest(filters)
75
+ }));
76
+ });
77
+
78
+ // No logic related to "show all products" necessary here, since stream only emits when
79
+ // location based shopping is active. That's currently only supported when new services are
80
+ // used, but the new services don't support "show all products".
81
+ subscribe(searchProductsNeedUpdate$, ({
82
+ dispatch,
83
+ getState
84
+ }) => {
85
+ const {
86
+ query,
87
+ state: {
88
+ filters
89
+ },
90
+ pattern
91
+ } = getCurrentRoute(getState());
92
+ const {
93
+ sort
94
+ } = query;
95
+ let {
96
+ s: searchPhrase
97
+ } = query;
98
+ if (pattern === CATEGORY_ALL_PATTERN) {
99
+ searchPhrase = '*';
100
+ }
101
+ dispatch(fetchSearchResults({
102
+ filters,
103
+ searchPhrase,
104
+ sort,
105
+ ...buildFetchSearchResultsParams()
106
+ }));
107
+ });
108
+ subscribe(searchBasedFiltersDidUpdateFromFilterPage$, ({
109
+ dispatch,
110
+ action
111
+ }) => {
112
+ const {
113
+ filters
114
+ } = action.route.state;
115
+ const {
116
+ pattern
117
+ } = action.route;
118
+ const {
119
+ sort
120
+ } = action.route.query;
121
+ let {
122
+ s: searchPhrase
123
+ } = action.route.query;
124
+ if (pattern === CATEGORY_ALL_PATTERN) {
125
+ searchPhrase = '*';
126
+ }
127
+ dispatch(fetchSearchResults({
128
+ filters,
129
+ searchPhrase,
130
+ sort,
131
+ ...buildFetchSearchResultsParams()
132
+ }));
133
+ });
134
+ }