@shopgate/pwa-common-commerce 7.30.0-alpha.6 → 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,7 +1,16 @@
1
- import{SUCCESS_HANDLE_SCANNER}from"../constants";/**
1
+ import { SUCCESS_HANDLE_SCANNER } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched SUCCESS_HANDLE_SCANNER action object.
3
5
  * @param {string} scope scan scope
4
6
  * @param {string} format data format EAN_13, QR_CODE
5
7
  * @param {Object} payload scan result
6
8
  * @returns {Object}
7
- */var successHandleScanner=function successHandleScanner(scope,format,payload){return{type:SUCCESS_HANDLE_SCANNER,scope:scope,format:format,payload:payload};};export default successHandleScanner;
9
+ */
10
+ const successHandleScanner = (scope, format, payload) => ({
11
+ type: SUCCESS_HANDLE_SCANNER,
12
+ scope,
13
+ format,
14
+ payload
15
+ });
16
+ export default successHandleScanner;
@@ -1,7 +1,27 @@
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{mutable}from'@shopgate/pwa-common/helpers/redux';import handleSearch from"./handleSearch";import handleNoResults from"./handleNoResults";import successHandleScanner from"../action-creators/successHandleScanner";/**
1
+ import { mutable } from '@shopgate/pwa-common/helpers/redux';
2
+ import handleSearch from "./handleSearch";
3
+ import handleNoResults from "./handleNoResults";
4
+ import successHandleScanner from "../action-creators/successHandleScanner";
5
+
6
+ /**
2
7
  * Handle bar code
3
8
  * @param {ScannerEvent} event Scanner event that emitted.
4
9
  * @param {string} format Format of the scanned code.
5
10
  * @param {string} payload Barcode payload.
6
11
  * @return {Function} A redux thunk.
7
- */var handleBarCode=function handleBarCode(event){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var scope,format,payload;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:scope=event.scope,format=event.format,payload=event.payload;_context.next=3;return dispatch(handleSearch(payload));case 3:if(!_context.sent){_context.next=7;break;}dispatch(successHandleScanner(scope,format,payload));_context.next=8;break;case 7:dispatch(handleNoResults(event,'scanner.noResult.barCode'));case 8:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}());};/** @mixes {MutableFunction} */export default mutable(handleBarCode);
12
+ */
13
+ const handleBarCode = event => async dispatch => {
14
+ const {
15
+ scope,
16
+ format,
17
+ payload
18
+ } = event;
19
+ if (await dispatch(handleSearch(payload))) {
20
+ dispatch(successHandleScanner(scope, format, payload));
21
+ } else {
22
+ dispatch(handleNoResults(event, 'scanner.noResult.barCode'));
23
+ }
24
+ };
25
+
26
+ /** @mixes {MutableFunction} */
27
+ export default mutable(handleBarCode);
@@ -1,8 +1,29 @@
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 showModal from'@shopgate/pwa-common/actions/modal/showModal';import{mutable}from'@shopgate/pwa-common/helpers/redux';import Scanner from'@shopgate/pwa-core/classes/Scanner';import errorHandleScanner from"../action-creators/errorHandleScanner";/**
1
+ import showModal from '@shopgate/pwa-common/actions/modal/showModal';
2
+ import { mutable } from '@shopgate/pwa-common/helpers/redux';
3
+ import Scanner from '@shopgate/pwa-core/classes/Scanner';
4
+ import errorHandleScanner from "../action-creators/errorHandleScanner";
5
+
6
+ /**
2
7
  * Handle no results
3
8
  * @param {string} event.scope Scanner scope.
4
9
  * @param {string} event.format Format of the scanned code.
5
10
  * @param {string} event.payload Barcode payload.
6
11
  * @param {string} message The message to display.
7
12
  * @return {Function} A redux thunk.
8
- */var handleNoResult=function handleNoResult(_ref,message){var scope=_ref.scope,format=_ref.format,payload=_ref.payload;return(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch(errorHandleScanner(scope,format,payload));dispatch(showModal({dismiss:null,confirm:'modal.ok',title:'modal.title_error',message:message})).then(function(confirmed){return confirmed&&Scanner.start();});case 2:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());};/** @mixes {MutableFunction} */export default mutable(handleNoResult);
13
+ */
14
+ const handleNoResult = ({
15
+ scope,
16
+ format,
17
+ payload
18
+ }, message) => async dispatch => {
19
+ dispatch(errorHandleScanner(scope, format, payload));
20
+ dispatch(showModal({
21
+ dismiss: null,
22
+ confirm: 'modal.ok',
23
+ title: 'modal.title_error',
24
+ message
25
+ })).then(confirmed => confirmed && Scanner.start());
26
+ };
27
+
28
+ /** @mixes {MutableFunction} */
29
+ export default mutable(handleNoResult);
@@ -1,13 +1,123 @@
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{historyPop,historyReplace,historyPush}from'@shopgate/engage/core/actions';import{fetchPageConfig}from'@shopgate/engage/page/actions';import{makeGetUnifiedCMSPageData}from'@shopgate/engage/page/selectors';import{fetchProductsById}from'@shopgate/engage/product';import{getProductById}from'@shopgate/engage/product/selectors/product';import{fetchCategory}from'@shopgate/engage/category/actions';import{getCategory}from'@shopgate/engage/category/selectors';import{isHTTPS,mutable}from'@shopgate/engage/core/helpers';import successHandleScanner from"../action-creators/successHandleScanner";import{QR_CODE_TYPE_CATEGORY,QR_CODE_TYPE_COUPON,QR_CODE_TYPE_HOMEPAGE,QR_CODE_TYPE_PAGE,QR_CODE_TYPE_PRODUCT,QR_CODE_TYPE_PRODUCT_WITH_COUPON,QR_CODE_TYPE_SEARCH}from"../constants";import{parse2dsQrCode}from"../helpers";import handleSearch from"./handleSearch";import handleNoResults from"./handleNoResults";/**
1
+ import { historyPop, historyReplace, historyPush } from '@shopgate/engage/core/actions';
2
+ import { fetchPageConfig } from '@shopgate/engage/page/actions';
3
+ import { makeGetUnifiedCMSPageData } from '@shopgate/engage/page/selectors';
4
+ import { fetchProductsById } from '@shopgate/engage/product';
5
+ import { getProductById } from '@shopgate/engage/product/selectors/product';
6
+ import { fetchCategory } from '@shopgate/engage/category/actions';
7
+ import { getCategory } from '@shopgate/engage/category/selectors';
8
+ import { isHTTPS, mutable } from '@shopgate/engage/core/helpers';
9
+ import successHandleScanner from "../action-creators/successHandleScanner";
10
+ import { QR_CODE_TYPE_CATEGORY, QR_CODE_TYPE_COUPON, QR_CODE_TYPE_HOMEPAGE, QR_CODE_TYPE_PAGE, QR_CODE_TYPE_PRODUCT, QR_CODE_TYPE_PRODUCT_WITH_COUPON, QR_CODE_TYPE_SEARCH } from "../constants";
11
+ import { parse2dsQrCode } from "../helpers";
12
+ import handleSearch from "./handleSearch";
13
+ import handleNoResults from "./handleNoResults";
14
+
15
+ /**
2
16
  * Handle qr code
3
17
  * @param {string} event.scope Scanner scope.
4
18
  * @param {string} event.format Format of the scanned code.
5
19
  * @param {string} event.payload Barcode payload.
6
20
  * @return {Function} A redux thunk.
7
- */var handleQrCode=function handleQrCode(_ref){var scope=_ref.scope,format=_ref.format,payload=_ref.payload;return(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var _ref3,type,link,data,notFound;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_ref3=parse2dsQrCode(payload)||{},type=_ref3.type,link=_ref3.link,data=_ref3.data;/**
21
+ */
22
+ const handleQrCode = ({
23
+ scope,
24
+ format,
25
+ payload
26
+ }) => async (dispatch, getState) => {
27
+ const {
28
+ type,
29
+ link,
30
+ data
31
+ } = parse2dsQrCode(payload) || {};
32
+
33
+ /**
8
34
  * Helper function to handle no scan results
9
35
  * @return {Function}
10
- */notFound=function notFound(){return dispatch(handleNoResults({scope:scope,format:format,payload:payload},'scanner.noResult.qrCode'));};_context.t0=type;_context.next=_context.t0===QR_CODE_TYPE_HOMEPAGE?5:_context.t0===QR_CODE_TYPE_SEARCH?8:_context.t0===QR_CODE_TYPE_COUPON?16:_context.t0===QR_CODE_TYPE_PRODUCT?20:_context.t0===QR_CODE_TYPE_PRODUCT_WITH_COUPON?20:_context.t0===QR_CODE_TYPE_CATEGORY?24:_context.t0===QR_CODE_TYPE_PAGE?28:32;break;case 5:dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));return _context.abrupt("break",34);case 8:_context.next=10;return dispatch(handleSearch(data.searchPhrase||''));case 10:if(!_context.sent){_context.next=14;break;}dispatch(successHandleScanner(scope,format,payload));_context.next=15;break;case 14:notFound();case 15:return _context.abrupt("break",34);case 16:dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));dispatch(historyPop());return _context.abrupt("break",34);case 20:_context.next=22;return dispatch(fetchProductsById([data.productId]));case 22:// Check from a store
11
- if(!getProductById(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",34);case 24:_context.next=26;return dispatch(fetchCategory(data.categoryId));case 26:if(!getCategory(getState(),data)){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",34);case 28:_context.next=30;return dispatch(fetchPageConfig(data.pageId));case 30:if(!makeGetUnifiedCMSPageData({slug:data.pageId})(getState())){notFound();}else{dispatch(successHandleScanner(scope,format,payload));dispatch(historyReplace({pathname:link}));}return _context.abrupt("break",34);case 32:if(isHTTPS(payload)){dispatch(successHandleScanner(scope,format,payload));// Open external link in in-app browser
12
- dispatch(historyPush({pathname:payload}));// Remove the scanner screen from the history
13
- dispatch(historyPop());}else{notFound();}return _context.abrupt("break",34);case 34:return _context.abrupt("return",null);case 35:case"end":return _context.stop();}},_callee);}));return function(_x,_x2){return _ref2.apply(this,arguments);};}());};/** @mixes {MutableFunction} */export default mutable(handleQrCode);
36
+ */
37
+ const notFound = () => dispatch(handleNoResults({
38
+ scope,
39
+ format,
40
+ payload
41
+ }, 'scanner.noResult.qrCode'));
42
+ switch (type) {
43
+ case QR_CODE_TYPE_HOMEPAGE:
44
+ dispatch(successHandleScanner(scope, format, payload));
45
+ dispatch(historyReplace({
46
+ pathname: link
47
+ }));
48
+ break;
49
+ case QR_CODE_TYPE_SEARCH:
50
+ if (await dispatch(handleSearch(data.searchPhrase || ''))) {
51
+ dispatch(successHandleScanner(scope, format, payload));
52
+ } else {
53
+ notFound();
54
+ }
55
+ break;
56
+ case QR_CODE_TYPE_COUPON:
57
+ dispatch(successHandleScanner(scope, format, payload));
58
+ dispatch(historyReplace({
59
+ pathname: link
60
+ }));
61
+ dispatch(historyPop());
62
+ break;
63
+ case QR_CODE_TYPE_PRODUCT:
64
+ case QR_CODE_TYPE_PRODUCT_WITH_COUPON:
65
+ // Force to fetch missing products
66
+ await dispatch(fetchProductsById([data.productId]));
67
+
68
+ // Check from a store
69
+ if (!getProductById(getState(), data)) {
70
+ notFound();
71
+ } else {
72
+ dispatch(successHandleScanner(scope, format, payload));
73
+ dispatch(historyReplace({
74
+ pathname: link
75
+ }));
76
+ }
77
+ break;
78
+ case QR_CODE_TYPE_CATEGORY:
79
+ await dispatch(fetchCategory(data.categoryId));
80
+ if (!getCategory(getState(), data)) {
81
+ notFound();
82
+ } else {
83
+ dispatch(successHandleScanner(scope, format, payload));
84
+ dispatch(historyReplace({
85
+ pathname: link
86
+ }));
87
+ }
88
+ break;
89
+ case QR_CODE_TYPE_PAGE:
90
+ // Force to fetch missing products
91
+ await dispatch(fetchPageConfig(data.pageId));
92
+ if (!makeGetUnifiedCMSPageData({
93
+ slug: data.pageId
94
+ })(getState())) {
95
+ notFound();
96
+ } else {
97
+ dispatch(successHandleScanner(scope, format, payload));
98
+ dispatch(historyReplace({
99
+ pathname: link
100
+ }));
101
+ }
102
+ break;
103
+ default:
104
+ {
105
+ if (isHTTPS(payload)) {
106
+ dispatch(successHandleScanner(scope, format, payload));
107
+ // Open external link in in-app browser
108
+ dispatch(historyPush({
109
+ pathname: payload
110
+ }));
111
+ // Remove the scanner screen from the history
112
+ dispatch(historyPop());
113
+ } else {
114
+ notFound();
115
+ }
116
+ break;
117
+ }
118
+ }
119
+ return null;
120
+ };
121
+
122
+ /** @mixes {MutableFunction} */
123
+ export default mutable(handleQrCode);
@@ -1,6 +1,37 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{historyReplace}from'@shopgate/pwa-common/actions/router';import{mutable}from'@shopgate/pwa-common/helpers/redux';import fetchProductsByQuery from'@shopgate/pwa-common-commerce/product/actions/fetchProductsByQuery';import{getProductRoute}from'@shopgate/pwa-common-commerce/product/helpers';import{getSearchRoute}from'@shopgate/pwa-common-commerce/search/helpers';/**
1
+ import { historyReplace } from '@shopgate/pwa-common/actions/router';
2
+ import { mutable } from '@shopgate/pwa-common/helpers/redux';
3
+ import fetchProductsByQuery from '@shopgate/pwa-common-commerce/product/actions/fetchProductsByQuery';
4
+ import { getProductRoute } from '@shopgate/pwa-common-commerce/product/helpers';
5
+ import { getSearchRoute } from '@shopgate/pwa-common-commerce/search/helpers';
6
+
7
+ /**
2
8
  * Handle product search. The thunk will return false if nothing was found or true if it processed
3
9
  * the action as it should.
4
10
  * @param {string} searchPhrase The search phrase.
5
11
  * @return {Function} A redux thunk.
6
- */var handleSearch=function handleSearch(searchPhrase){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var _ref2,_ref2$products,products,_products2,first,productId;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.next=2;return dispatch(fetchProductsByQuery(2,searchPhrase));case 2:_ref2=_context.sent;_ref2$products=_ref2.products;products=_ref2$products===void 0?[]:_ref2$products;if(products.length){_context.next=7;break;}return _context.abrupt("return",false);case 7:if(products.length===1){_products2=_slicedToArray(products,1),first=_products2[0];productId=typeof first==='string'?first:first.id;dispatch(historyReplace({pathname:getProductRoute(productId)}));}else{dispatch(historyReplace({pathname:getSearchRoute(searchPhrase)}));}return _context.abrupt("return",true);case 9:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}());};/** @mixes {MutableFunction} */export default mutable(handleSearch);
12
+ */
13
+ const handleSearch = searchPhrase => async dispatch => {
14
+ const {
15
+ products = []
16
+ } = await dispatch(fetchProductsByQuery(2, searchPhrase));
17
+
18
+ // Redirect to product when only one was found and to search for more. Abort on no results.
19
+ if (!products.length) {
20
+ return false;
21
+ }
22
+ if (products.length === 1) {
23
+ const [first] = products;
24
+ const productId = typeof first === 'string' ? first : first.id;
25
+ dispatch(historyReplace({
26
+ pathname: getProductRoute(productId)
27
+ }));
28
+ } else {
29
+ dispatch(historyReplace({
30
+ pathname: getSearchRoute(searchPhrase)
31
+ }));
32
+ }
33
+ return true;
34
+ };
35
+
36
+ /** @mixes {MutableFunction} */
37
+ export default mutable(handleSearch);
@@ -1 +1,22 @@
1
- import{BEFORE,AFTER}from'@shopgate/pwa-common/constants/Portals';var SCANNER='scanner';var ICON='icon';var CAMERA='camera';var BAR='bar';var FLASH='flash';var INSTRUCTIONS='instructions';export var SCANNER_ICON_BEFORE="".concat(SCANNER,".").concat(ICON,".").concat(BEFORE);export var SCANNER_ICON="".concat(SCANNER,".").concat(ICON);export var SCANNER_ICON_AFTER="".concat(SCANNER,".").concat(ICON,".").concat(AFTER);export var SCANNER_CAMERA_BEFORE="".concat(SCANNER,".").concat(CAMERA,".").concat(BEFORE);export var SCANNER_CAMERA="".concat(SCANNER,".").concat(CAMERA);export var SCANNER_CAMERA_AFTER="".concat(SCANNER,".").concat(CAMERA,".").concat(AFTER);export var SCANNER_BAR_BEFORE="".concat(SCANNER,".").concat(BAR,".").concat(BEFORE);export var SCANNER_BAR="".concat(SCANNER,".").concat(BAR);export var SCANNER_BAR_AFTER="".concat(SCANNER,".").concat(BAR,".").concat(AFTER);export var SCANNER_FLASH_BEFORE="".concat(SCANNER,".").concat(FLASH,".").concat(BEFORE);export var SCANNER_FLASH="".concat(SCANNER,".").concat(FLASH);export var SCANNER_FLASH_AFTER="".concat(SCANNER,".").concat(FLASH,".").concat(AFTER);export var SCANNER_INSTRUCTIONS_BEFORE="".concat(SCANNER,".").concat(INSTRUCTIONS,".").concat(BEFORE);export var SCANNER_INSTRUCTIONS="".concat(SCANNER,".").concat(INSTRUCTIONS);export var SCANNER_INSTRUCTIONS_AFTER="".concat(SCANNER,".").concat(INSTRUCTIONS,".").concat(AFTER);
1
+ import { BEFORE, AFTER } from '@shopgate/pwa-common/constants/Portals';
2
+ const SCANNER = 'scanner';
3
+ const ICON = 'icon';
4
+ const CAMERA = 'camera';
5
+ const BAR = 'bar';
6
+ const FLASH = 'flash';
7
+ const INSTRUCTIONS = 'instructions';
8
+ export const SCANNER_ICON_BEFORE = `${SCANNER}.${ICON}.${BEFORE}`;
9
+ export const SCANNER_ICON = `${SCANNER}.${ICON}`;
10
+ export const SCANNER_ICON_AFTER = `${SCANNER}.${ICON}.${AFTER}`;
11
+ export const SCANNER_CAMERA_BEFORE = `${SCANNER}.${CAMERA}.${BEFORE}`;
12
+ export const SCANNER_CAMERA = `${SCANNER}.${CAMERA}`;
13
+ export const SCANNER_CAMERA_AFTER = `${SCANNER}.${CAMERA}.${AFTER}`;
14
+ export const SCANNER_BAR_BEFORE = `${SCANNER}.${BAR}.${BEFORE}`;
15
+ export const SCANNER_BAR = `${SCANNER}.${BAR}`;
16
+ export const SCANNER_BAR_AFTER = `${SCANNER}.${BAR}.${AFTER}`;
17
+ export const SCANNER_FLASH_BEFORE = `${SCANNER}.${FLASH}.${BEFORE}`;
18
+ export const SCANNER_FLASH = `${SCANNER}.${FLASH}`;
19
+ export const SCANNER_FLASH_AFTER = `${SCANNER}.${FLASH}.${AFTER}`;
20
+ export const SCANNER_INSTRUCTIONS_BEFORE = `${SCANNER}.${INSTRUCTIONS}.${BEFORE}`;
21
+ export const SCANNER_INSTRUCTIONS = `${SCANNER}.${INSTRUCTIONS}`;
22
+ export const SCANNER_INSTRUCTIONS_AFTER = `${SCANNER}.${INSTRUCTIONS}.${AFTER}`;
@@ -1 +1,17 @@
1
- export var START_SCANNER='START_SCANNER';export var SCANNER_STARTED='SCANNER_STARTED';export var SCANNER_CANCELLED='SCANNER_CANCELLED';export var SCANNER_FINISHED='SCANNER_FINISHED';export var SUCCESS_HANDLE_SCANNER='SUCCESS_HANDLE_SCANNER';export var ERROR_HANDLE_SCANNER='ERROR_HANDLE_SCANNER';export var SCANNER_PATH='/scanner';export var QR_CODE_TYPE_COUPON='2';export var QR_CODE_TYPE_HOMEPAGE='5';export var QR_CODE_TYPE_PRODUCT='7';export var QR_CODE_TYPE_PRODUCT_WITH_COUPON='9';export var QR_CODE_TYPE_CATEGORY='e';export var QR_CODE_TYPE_SEARCH='b';export var QR_CODE_TYPE_PAGE='1';export var QR_CODE_HOST_2DS='2d.is';export var SCANNER_FORMATS_BARCODE=['UPC_E','CODE_39','EAN_13','EAN_8','CODE_93','CODE_128','PDF_417','ITF','DATA_MATRIX'];export var SCANNER_FORMATS_QR_CODE=['QR_CODE'];
1
+ export const START_SCANNER = 'START_SCANNER';
2
+ export const SCANNER_STARTED = 'SCANNER_STARTED';
3
+ export const SCANNER_CANCELLED = 'SCANNER_CANCELLED';
4
+ export const SCANNER_FINISHED = 'SCANNER_FINISHED';
5
+ export const SUCCESS_HANDLE_SCANNER = 'SUCCESS_HANDLE_SCANNER';
6
+ export const ERROR_HANDLE_SCANNER = 'ERROR_HANDLE_SCANNER';
7
+ export const SCANNER_PATH = '/scanner';
8
+ export const QR_CODE_TYPE_COUPON = '2';
9
+ export const QR_CODE_TYPE_HOMEPAGE = '5';
10
+ export const QR_CODE_TYPE_PRODUCT = '7';
11
+ export const QR_CODE_TYPE_PRODUCT_WITH_COUPON = '9';
12
+ export const QR_CODE_TYPE_CATEGORY = 'e';
13
+ export const QR_CODE_TYPE_SEARCH = 'b';
14
+ export const QR_CODE_TYPE_PAGE = '1';
15
+ export const QR_CODE_HOST_2DS = '2d.is';
16
+ export const SCANNER_FORMATS_BARCODE = ['UPC_E', 'CODE_39', 'EAN_13', 'EAN_8', 'CODE_93', 'CODE_128', 'PDF_417', 'ITF', 'DATA_MATRIX'];
17
+ export const SCANNER_FORMATS_QR_CODE = ['QR_CODE'];
@@ -1,17 +1,127 @@
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;}import{SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE}from'@shopgate/pwa-core/constants/Scanner';import{getCategoryRoute}from'@shopgate/pwa-common-commerce/category';import{getProductRoute}from'@shopgate/pwa-common-commerce/product';import{getSearchRoute}from'@shopgate/pwa-common-commerce/search';import{QR_CODE_TYPE_HOMEPAGE,QR_CODE_TYPE_PRODUCT,QR_CODE_TYPE_PRODUCT_WITH_COUPON,QR_CODE_TYPE_COUPON,QR_CODE_TYPE_CATEGORY,QR_CODE_TYPE_SEARCH,QR_CODE_TYPE_PAGE,QR_CODE_HOST_2DS,SCANNER_PATH}from"../constants";/**
1
+ import "core-js/modules/web.url.js";
2
+ import "core-js/modules/web.url.to-json.js";
3
+ import "core-js/modules/web.url-search-params.js";
4
+ import { SCANNER_SCOPE_DEFAULT, SCANNER_TYPE_BARCODE } from '@shopgate/pwa-core/constants/Scanner';
5
+ import { getCategoryRoute } from '@shopgate/pwa-common-commerce/category';
6
+ import { getProductRoute } from '@shopgate/pwa-common-commerce/product';
7
+ import { getSearchRoute } from '@shopgate/pwa-common-commerce/search';
8
+ import { QR_CODE_TYPE_HOMEPAGE, QR_CODE_TYPE_PRODUCT, QR_CODE_TYPE_PRODUCT_WITH_COUPON, QR_CODE_TYPE_COUPON, QR_CODE_TYPE_CATEGORY, QR_CODE_TYPE_SEARCH, QR_CODE_TYPE_PAGE, QR_CODE_HOST_2DS, SCANNER_PATH } from "../constants";
9
+
10
+ /**
2
11
  * Set of parsers of different types
3
- */var typeParsers=_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},QR_CODE_TYPE_HOMEPAGE,function(){return{link:'/'};}),QR_CODE_TYPE_PRODUCT,function(url){var _url$pathname$split=url.pathname.split('/'),_url$pathname$split2=_slicedToArray(_url$pathname$split,4),paramTwo=_url$pathname$split2[3];var decodedParamTwo=decodeURIComponent(decodeURIComponent(paramTwo));return{link:getProductRoute(decodedParamTwo),data:{productId:decodedParamTwo}};}),QR_CODE_TYPE_PRODUCT_WITH_COUPON,function(url){var _url$pathname$split3=url.pathname.split('/'),_url$pathname$split4=_slicedToArray(_url$pathname$split3,5),paramTwo=_url$pathname$split4[3],paramThree=_url$pathname$split4[4];var decodedParamTwo=decodeURIComponent(decodeURIComponent(paramTwo));var decodedParamThree=decodeURIComponent(decodeURIComponent(paramThree));return{link:"/cart_add_product/".concat(encodeURIComponent(decodedParamTwo),"/").concat(encodeURIComponent(decodedParamThree)),data:{productId:decodedParamTwo,couponCode:decodedParamThree}};}),QR_CODE_TYPE_COUPON,function(url){var _url$pathname$split5=url.pathname.split('/'),_url$pathname$split6=_slicedToArray(_url$pathname$split5,3),paramOne=_url$pathname$split6[2];return{link:"/cart_add_coupon/".concat(paramOne),data:{couponCode:paramOne}};}),QR_CODE_TYPE_CATEGORY,function(url){var _url$pathname$split7=url.pathname.split('/'),_url$pathname$split8=_slicedToArray(_url$pathname$split7,4),paramTwo=_url$pathname$split8[3];var decodedParamTwo=decodeURIComponent(decodeURIComponent(paramTwo));return{link:getCategoryRoute(decodedParamTwo),data:{categoryId:decodedParamTwo}};}),QR_CODE_TYPE_SEARCH,function(url){var _url$pathname$split9=url.pathname.split('/'),_url$pathname$split10=_slicedToArray(_url$pathname$split9,4),paramTwo=_url$pathname$split10[3];var decodedParamTwo=decodeURIComponent(decodeURIComponent(paramTwo));return{link:getSearchRoute(decodedParamTwo),data:{searchPhrase:decodedParamTwo}};}),QR_CODE_TYPE_PAGE,function(url){var _url$pathname$split11=url.pathname.split('/'),_url$pathname$split12=_slicedToArray(_url$pathname$split11,4),paramTwo=_url$pathname$split12[3];var decodedParamTwo=decodeURIComponent(decodeURIComponent(paramTwo));return{link:"/page/".concat(decodedParamTwo),data:{pageId:decodedParamTwo}};});/**
12
+ */
13
+ const typeParsers = {
14
+ [QR_CODE_TYPE_HOMEPAGE]: () => ({
15
+ link: '/'
16
+ }),
17
+ [QR_CODE_TYPE_PRODUCT]: url => {
18
+ const [,,, paramTwo] = url.pathname.split('/');
19
+ const decodedParamTwo = decodeURIComponent(decodeURIComponent(paramTwo));
20
+ return {
21
+ link: getProductRoute(decodedParamTwo),
22
+ data: {
23
+ productId: decodedParamTwo
24
+ }
25
+ };
26
+ },
27
+ [QR_CODE_TYPE_PRODUCT_WITH_COUPON]: url => {
28
+ const [,,, paramTwo, paramThree] = url.pathname.split('/');
29
+ const decodedParamTwo = decodeURIComponent(decodeURIComponent(paramTwo));
30
+ const decodedParamThree = decodeURIComponent(decodeURIComponent(paramThree));
31
+ return {
32
+ link: `/cart_add_product/${encodeURIComponent(decodedParamTwo)}/${encodeURIComponent(decodedParamThree)}`,
33
+ data: {
34
+ productId: decodedParamTwo,
35
+ couponCode: decodedParamThree
36
+ }
37
+ };
38
+ },
39
+ [QR_CODE_TYPE_COUPON]: url => {
40
+ const [,, paramOne] = url.pathname.split('/');
41
+ return {
42
+ link: `/cart_add_coupon/${paramOne}`,
43
+ data: {
44
+ couponCode: paramOne
45
+ }
46
+ };
47
+ },
48
+ [QR_CODE_TYPE_CATEGORY]: url => {
49
+ const [,,, paramTwo] = url.pathname.split('/');
50
+ const decodedParamTwo = decodeURIComponent(decodeURIComponent(paramTwo));
51
+ return {
52
+ link: getCategoryRoute(decodedParamTwo),
53
+ data: {
54
+ categoryId: decodedParamTwo
55
+ }
56
+ };
57
+ },
58
+ [QR_CODE_TYPE_SEARCH]: url => {
59
+ const [,,, paramTwo] = url.pathname.split('/');
60
+ const decodedParamTwo = decodeURIComponent(decodeURIComponent(paramTwo));
61
+ return {
62
+ link: getSearchRoute(decodedParamTwo),
63
+ data: {
64
+ searchPhrase: decodedParamTwo
65
+ }
66
+ };
67
+ },
68
+ [QR_CODE_TYPE_PAGE]: url => {
69
+ const [,,, paramTwo] = url.pathname.split('/');
70
+ const decodedParamTwo = decodeURIComponent(decodeURIComponent(paramTwo));
71
+ return {
72
+ link: `/page/${decodedParamTwo}`,
73
+ data: {
74
+ pageId: decodedParamTwo
75
+ }
76
+ };
77
+ }
78
+ };
79
+
80
+ /**
4
81
  * Check if links is 2ds.
5
82
  * @param {string} code The string from the QR Code
6
83
  * @returns {boolean}
7
- */export var is2dsQrCode=function is2dsQrCode(code){try{return new URL(code).host===QR_CODE_HOST_2DS;}catch(e){return false;}};/**
84
+ */
85
+ export const is2dsQrCode = code => {
86
+ try {
87
+ return new URL(code).host === QR_CODE_HOST_2DS;
88
+ } catch (e) {
89
+ return false;
90
+ }
91
+ };
92
+
93
+ /**
8
94
  * Parses 2ds QR Codes.
9
95
  * Generates a deeplink which can be used to open pages.
10
96
  * @param {string} code The string from the QR Code.
11
97
  * @returns {?{type, link, data}} The parsed type, link, data
12
- */export var parse2dsQrCode=function parse2dsQrCode(code){if(!is2dsQrCode(code)){return null;}var url=new URL(code);var _url$pathname$split13=url.pathname.split('/'),_url$pathname$split14=_slicedToArray(_url$pathname$split13,2),type=_url$pathname$split14[1];var link='/';var data={};var typeParser=typeParsers[type];if(typeParser){var _typeParser=typeParser(url);link=_typeParser.link;var _typeParser$data=_typeParser.data;data=_typeParser$data===void 0?{}:_typeParser$data;}return{type:type,link:link,data:data};};/**
98
+ */
99
+ export const parse2dsQrCode = code => {
100
+ if (!is2dsQrCode(code)) {
101
+ return null;
102
+ }
103
+ const url = new URL(code);
104
+ const [, type] = url.pathname.split('/');
105
+ let link = '/';
106
+ let data = {};
107
+ const typeParser = typeParsers[type];
108
+ if (typeParser) {
109
+ ({
110
+ link,
111
+ data = {}
112
+ } = typeParser(url));
113
+ }
114
+ return {
115
+ type,
116
+ link,
117
+ data
118
+ };
119
+ };
120
+
121
+ /**
13
122
  * Create a link to the scanner route.
14
123
  * @param {string} [scope=SCANNER_SCOPE_DEFAULT] The scanner scope to use for the scanner page
15
124
  * @param {string} [type=SCANNER_TYPE_BARCODE] The scanner type to use on the scanner page
16
125
  * @returns {string}
17
- */export var getScannerRoute=function getScannerRoute(){var scope=arguments.length>0&&arguments[0]!==undefined?arguments[0]:SCANNER_SCOPE_DEFAULT;var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:SCANNER_TYPE_BARCODE;return"".concat(SCANNER_PATH,"?scope=").concat(scope,"&type=").concat(type);};
126
+ */
127
+ export const getScannerRoute = (scope = SCANNER_SCOPE_DEFAULT, type = SCANNER_TYPE_BARCODE) => `${SCANNER_PATH}?scope=${scope}&type=${type}`;
package/scanner/index.js CHANGED
@@ -1,6 +1,20 @@
1
1
  // ACTION-CREATORS
2
- export{default as startScanner}from"./action-creators/startScanner";export{default as successHandleScanner}from"./action-creators/successHandleScanner";export{default as errorHandleScanner}from"./action-creators/errorHandleScanner";// ACTIONS
3
- export{default as handleBarCode}from"./actions/handleBarCode";export{default as handleQrCode}from"./actions/handleQrCode";export{default as handleSearch}from"./actions/handleSearch";export{default as handleNoResults}from"./actions/handleNoResults";// CONSTANTS
4
- export*from"./constants";export*from"./constants/Portals";// HELPERS
5
- export*from"./helpers";// STREAMS
6
- export*from"./streams";
2
+ export { default as startScanner } from "./action-creators/startScanner";
3
+ export { default as successHandleScanner } from "./action-creators/successHandleScanner";
4
+ export { default as errorHandleScanner } from "./action-creators/errorHandleScanner";
5
+
6
+ // ACTIONS
7
+ export { default as handleBarCode } from "./actions/handleBarCode";
8
+ export { default as handleQrCode } from "./actions/handleQrCode";
9
+ export { default as handleSearch } from "./actions/handleSearch";
10
+ export { default as handleNoResults } from "./actions/handleNoResults";
11
+
12
+ // CONSTANTS
13
+ export * from "./constants";
14
+ export * from "./constants/Portals";
15
+
16
+ // HELPERS
17
+ export * from "./helpers";
18
+
19
+ // STREAMS
20
+ export * from "./streams";
@@ -1 +1,36 @@
1
- import{main$}from'@shopgate/pwa-common/streams/main';import{routeDidEnter$}from'@shopgate/pwa-common/streams/router';import{START_SCANNER,SCANNER_STARTED,SCANNER_CANCELLED,SCANNER_FINISHED,SCANNER_PATH,SCANNER_FORMATS_BARCODE,SCANNER_FORMATS_QR_CODE}from"../constants";/** @type {Observable} */export var scannerDidEnter$=routeDidEnter$.filter(function(_ref){var action=_ref.action;return action.route.pathname===SCANNER_PATH;});export var startScanner$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===START_SCANNER;});/** @type {Observable} */export var scannerStarted$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===SCANNER_STARTED;});/** @type {Observable} */export var scannerCancelled$=main$.filter(function(_ref4){var action=_ref4.action;return action.type===SCANNER_CANCELLED;});/** @type {Observable} */export var scannerFinished$=main$.filter(function(_ref5){var action=_ref5.action;return action.type===SCANNER_FINISHED;});/** @type {Observable} */export var scannerFinishedBarCode$=scannerFinished$.filter(function(_ref6){var action=_ref6.action;return SCANNER_FORMATS_BARCODE.includes(action.format);});/** @type {Observable} */export var scannerFinishedQrCode$=scannerFinished$.filter(function(_ref7){var action=_ref7.action;return SCANNER_FORMATS_QR_CODE.includes(action.format);});
1
+ import { main$ } from '@shopgate/pwa-common/streams/main';
2
+ import { routeDidEnter$ } from '@shopgate/pwa-common/streams/router';
3
+ import { START_SCANNER, SCANNER_STARTED, SCANNER_CANCELLED, SCANNER_FINISHED, SCANNER_PATH, SCANNER_FORMATS_BARCODE, SCANNER_FORMATS_QR_CODE } from "../constants";
4
+
5
+ /** @type {Observable} */
6
+ export const scannerDidEnter$ = routeDidEnter$.filter(({
7
+ action
8
+ }) => action.route.pathname === SCANNER_PATH);
9
+ export const startScanner$ = main$.filter(({
10
+ action
11
+ }) => action.type === START_SCANNER);
12
+
13
+ /** @type {Observable} */
14
+ export const scannerStarted$ = main$.filter(({
15
+ action
16
+ }) => action.type === SCANNER_STARTED);
17
+
18
+ /** @type {Observable} */
19
+ export const scannerCancelled$ = main$.filter(({
20
+ action
21
+ }) => action.type === SCANNER_CANCELLED);
22
+
23
+ /** @type {Observable} */
24
+ export const scannerFinished$ = main$.filter(({
25
+ action
26
+ }) => action.type === SCANNER_FINISHED);
27
+
28
+ /** @type {Observable} */
29
+ export const scannerFinishedBarCode$ = scannerFinished$.filter(({
30
+ action
31
+ }) => SCANNER_FORMATS_BARCODE.includes(action.format));
32
+
33
+ /** @type {Observable} */
34
+ export const scannerFinishedQrCode$ = scannerFinished$.filter(({
35
+ action
36
+ }) => SCANNER_FORMATS_QR_CODE.includes(action.format));
@@ -1,10 +1,80 @@
1
- import Scanner from'@shopgate/pwa-core/classes/Scanner';import ScannerEventListener from'@shopgate/pwa-core/classes/ScannerEventListener';import{SCANNER_SCOPE_DEFAULT}from'@shopgate/pwa-core/constants/Scanner';import{appDidStart$}from'@shopgate/pwa-common/streams';import scannerFinished from"../action-creators/scannerFinished";import handleBarCode from"../actions/handleBarCode";import handleQrCode from"../actions/handleQrCode";import{SCANNER_FORMATS_BARCODE,SCANNER_FORMATS_QR_CODE}from"../constants";import{startScanner$,scannerFinishedBarCode$,scannerFinishedQrCode$}from"../streams";// Scanner payload formats which are handled by the subscriptions.
2
- export var handledFormats=[].concat(SCANNER_FORMATS_BARCODE,SCANNER_FORMATS_QR_CODE);/**
1
+ import Scanner from '@shopgate/pwa-core/classes/Scanner';
2
+ import ScannerEventListener from '@shopgate/pwa-core/classes/ScannerEventListener';
3
+ import { SCANNER_SCOPE_DEFAULT } from '@shopgate/pwa-core/constants/Scanner';
4
+ import { appDidStart$ } from '@shopgate/pwa-common/streams';
5
+ import scannerFinished from "../action-creators/scannerFinished";
6
+ import handleBarCode from "../actions/handleBarCode";
7
+ import handleQrCode from "../actions/handleQrCode";
8
+ import { SCANNER_FORMATS_BARCODE, SCANNER_FORMATS_QR_CODE } from "../constants";
9
+ import { startScanner$, scannerFinishedBarCode$, scannerFinishedQrCode$ } from "../streams";
10
+
11
+ // Scanner payload formats which are handled by the subscriptions.
12
+ export const handledFormats = [...SCANNER_FORMATS_BARCODE, ...SCANNER_FORMATS_QR_CODE];
13
+
14
+ /**
3
15
  * Scanner subscriptions.
4
16
  * @param {Function} subscribe The subscribe function.
5
- */export default(function(subscribe){// Register global listener to convert to stream
6
- subscribe(appDidStart$,function(_ref){var dispatch=_ref.dispatch;Scanner.addListener(new ScannerEventListener('Scanner listener',null,null,handledFormats).setHandler(function(_ref2){var scope=_ref2.scope,_ref2$payload=_ref2.payload,_ref2$payload2=_ref2$payload===void 0?{}:_ref2$payload,format=_ref2$payload2.format,payload=_ref2$payload2.code;dispatch(scannerFinished(scope,format,payload));}));});subscribe(startScanner$,function(){Scanner.start();});// Default scope stream
7
- var scannerFinishedBarCodeDefault$=scannerFinishedBarCode$.filter(function(_ref3){var action=_ref3.action;return action.scope===SCANNER_SCOPE_DEFAULT;});// Default scope bar code handler
8
- subscribe(scannerFinishedBarCodeDefault$,function(_ref4){var dispatch=_ref4.dispatch,action=_ref4.action;var scope=action.scope,format=action.format,payload=action.payload;dispatch(handleBarCode({scope:scope,format:format,payload:payload}));});// Default scope qr code stream
9
- var scannerFinishedQrCodeDefault$=scannerFinishedQrCode$.filter(function(_ref5){var action=_ref5.action;return action.scope===SCANNER_SCOPE_DEFAULT;});// Default scope qr code handler
10
- subscribe(scannerFinishedQrCodeDefault$,function(_ref6){var dispatch=_ref6.dispatch,action=_ref6.action;var scope=action.scope,format=action.format,payload=action.payload;dispatch(handleQrCode({scope:scope,format:format,payload:payload}));});});
17
+ */
18
+ export default subscribe => {
19
+ // Register global listener to convert to stream
20
+ subscribe(appDidStart$, ({
21
+ dispatch
22
+ }) => {
23
+ Scanner.addListener(new ScannerEventListener('Scanner listener', null, null, handledFormats).setHandler(({
24
+ scope,
25
+ payload: {
26
+ format,
27
+ code: payload
28
+ } = {}
29
+ }) => {
30
+ dispatch(scannerFinished(scope, format, payload));
31
+ }));
32
+ });
33
+ subscribe(startScanner$, () => {
34
+ Scanner.start();
35
+ });
36
+
37
+ // Default scope stream
38
+ const scannerFinishedBarCodeDefault$ = scannerFinishedBarCode$.filter(({
39
+ action
40
+ }) => action.scope === SCANNER_SCOPE_DEFAULT);
41
+
42
+ // Default scope bar code handler
43
+ subscribe(scannerFinishedBarCodeDefault$, ({
44
+ dispatch,
45
+ action
46
+ }) => {
47
+ const {
48
+ scope,
49
+ format,
50
+ payload
51
+ } = action;
52
+ dispatch(handleBarCode({
53
+ scope,
54
+ format,
55
+ payload
56
+ }));
57
+ });
58
+
59
+ // Default scope qr code stream
60
+ const scannerFinishedQrCodeDefault$ = scannerFinishedQrCode$.filter(({
61
+ action
62
+ }) => action.scope === SCANNER_SCOPE_DEFAULT);
63
+
64
+ // Default scope qr code handler
65
+ subscribe(scannerFinishedQrCodeDefault$, ({
66
+ dispatch,
67
+ action
68
+ }) => {
69
+ const {
70
+ scope,
71
+ format,
72
+ payload
73
+ } = action;
74
+ dispatch(handleQrCode({
75
+ scope,
76
+ format,
77
+ payload
78
+ }));
79
+ });
80
+ };
@@ -1,6 +1,14 @@
1
- import{ERROR_SEARCH_RESULTS}from"../constants";/**
1
+ import { ERROR_SEARCH_RESULTS } from "../constants";
2
+
3
+ /**
2
4
  * Creates the dispatched ERROR_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 ERROR_SEARCH_RESULTS action.
6
- */var errorSearchResults=function errorSearchResults(searchPhrase,offset){return{type:ERROR_SEARCH_RESULTS,searchPhrase:searchPhrase,offset:offset};};export default errorSearchResults;
8
+ */
9
+ const errorSearchResults = (searchPhrase, offset) => ({
10
+ type: ERROR_SEARCH_RESULTS,
11
+ searchPhrase,
12
+ offset
13
+ });
14
+ export default errorSearchResults;