@shopgate/pwa-common 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 (306) hide show
  1. package/App.js +48 -6
  2. package/action-creators/app/index.js +75 -12
  3. package/action-creators/app/spec.js +96 -1
  4. package/action-creators/client/index.js +27 -5
  5. package/action-creators/client/spec.js +44 -1
  6. package/action-creators/error/index.js +15 -3
  7. package/action-creators/index.js +9 -1
  8. package/action-creators/menu/index.js +23 -4
  9. package/action-creators/menu/spec.js +37 -1
  10. package/action-creators/modal/index.js +15 -3
  11. package/action-creators/modal/spec.js +26 -1
  12. package/action-creators/page/index.js +24 -4
  13. package/action-creators/page/spec.js +38 -1
  14. package/action-creators/router/index.js +48 -7
  15. package/action-creators/url/index.js +24 -4
  16. package/action-creators/url/spec.js +45 -1
  17. package/action-creators/user/index.js +90 -13
  18. package/action-creators/user/spec.js +186 -2
  19. package/actions/app/handleDeepLink.js +11 -2
  20. package/actions/app/handleLink.js +62 -6
  21. package/actions/app/handlePushNotification.js +32 -4
  22. package/actions/app/handleUniversalLink.js +11 -2
  23. package/actions/app/registerLinkEvents.js +24 -3
  24. package/actions/client/fetchClientInformation.js +26 -2
  25. package/actions/menu/fetchMenu.js +23 -2
  26. package/actions/modal/closeModal.js +18 -2
  27. package/actions/modal/promiseMap.js +3 -1
  28. package/actions/modal/showModal.js +54 -8
  29. package/actions/page/fetchPageConfig.js +69 -2
  30. package/actions/page/getPageConfig.js +6 -2
  31. package/actions/page/index.js +1 -1
  32. package/actions/router/historyPop.js +12 -2
  33. package/actions/router/historyPopToRoute.js +27 -2
  34. package/actions/router/historyPush.js +12 -2
  35. package/actions/router/historyRedirect.js +21 -2
  36. package/actions/router/historyReplace.js +20 -3
  37. package/actions/router/historyReset.js +11 -2
  38. package/actions/router/historyResetTo.js +12 -2
  39. package/actions/router/index.js +17 -1
  40. package/actions/router/routeDidPop.js +11 -2
  41. package/actions/router/routeDidPush.js +13 -2
  42. package/actions/router/routeDidReplace.js +11 -2
  43. package/actions/router/routeDidReset.js +11 -2
  44. package/actions/router/routeDidUpdate.js +10 -2
  45. package/actions/router/routeWillPop.js +11 -2
  46. package/actions/router/routeWillPush.js +13 -2
  47. package/actions/router/routeWillReplace.js +11 -2
  48. package/actions/router/routeWillReset.js +11 -2
  49. package/actions/router/windowOpenOverride.js +10 -2
  50. package/actions/user/fetchRegisterUrl.js +36 -2
  51. package/actions/user/fetchUser.js +29 -3
  52. package/actions/user/getUser.js +6 -2
  53. package/actions/user/index.js +1 -1
  54. package/actions/user/login.js +76 -9
  55. package/actions/user/logout.js +30 -2
  56. package/collections/AuthRoutes.js +73 -14
  57. package/collections/Configuration.js +54 -7
  58. package/collections/EmbeddedMedia.js +84 -11
  59. package/collections/PersistedReducers.js +41 -6
  60. package/collections/Redirects.js +103 -17
  61. package/collections/index.js +5 -1
  62. package/collections/media-providers/MediaProvider.js +151 -26
  63. package/collections/media-providers/Vimeo.js +113 -19
  64. package/collections/media-providers/YouTube.js +74 -14
  65. package/collections/media-providers/index.js +3 -1
  66. package/collections/media-providers/style.js +52 -2
  67. package/components/Backdrop/index.js +95 -6
  68. package/components/Backdrop/spec.js +23 -1
  69. package/components/Backdrop/style.js +11 -2
  70. package/components/Button/index.js +47 -5
  71. package/components/Button/spec.js +36 -1
  72. package/components/Button/style.js +6 -1
  73. package/components/Checkbox/index.js +126 -32
  74. package/components/Checkbox/spec.js +94 -3
  75. package/components/Consume/helpers/buildParams.js +13 -2
  76. package/components/Consume/index.js +14 -2
  77. package/components/CountdownTimer/index.js +115 -17
  78. package/components/CountdownTimer/spec.js +126 -12
  79. package/components/Drawer/index.js +131 -16
  80. package/components/Drawer/spec.js +76 -1
  81. package/components/Drawer/style.js +37 -1
  82. package/components/Dropdown/index.js +65 -6
  83. package/components/Dropdown/style.js +4 -1
  84. package/components/Dropdown/transitions.js +34 -1
  85. package/components/Ellipsis/index.js +16 -2
  86. package/components/Ellipsis/spec.js +13 -1
  87. package/components/EmbeddedMedia/index.js +56 -6
  88. package/components/EmbeddedMedia/spec.js +52 -3
  89. package/components/ErrorBoundary/connector.js +9 -2
  90. package/components/ErrorBoundary/index.js +43 -7
  91. package/components/Grid/components/Item/index.js +40 -4
  92. package/components/Grid/components/Item/spec.js +23 -1
  93. package/components/Grid/components/Item/style.js +17 -3
  94. package/components/Grid/index.js +36 -4
  95. package/components/Grid/spec.js +23 -1
  96. package/components/Grid/style.js +11 -2
  97. package/components/HtmlSanitizer/connector.js +24 -3
  98. package/components/HtmlSanitizer/index.js +104 -12
  99. package/components/HtmlSanitizer/spec.js +214 -7
  100. package/components/I18n/components/FormatDate/index.js +26 -2
  101. package/components/I18n/components/FormatDate/spec.js +46 -1
  102. package/components/I18n/components/FormatNumber/index.js +34 -2
  103. package/components/I18n/components/FormatNumber/spec.js +41 -2
  104. package/components/I18n/components/FormatPrice/index.js +32 -2
  105. package/components/I18n/components/FormatPrice/spec.js +46 -1
  106. package/components/I18n/components/FormatTime/index.js +26 -2
  107. package/components/I18n/components/FormatTime/spec.js +43 -2
  108. package/components/I18n/components/I18nProvider/index.js +52 -9
  109. package/components/I18n/components/I18nProvider/spec.js +39 -1
  110. package/components/I18n/components/Placeholder/index.js +8 -2
  111. package/components/I18n/components/Placeholder/spec.js +30 -1
  112. package/components/I18n/components/Translate/index.js +68 -7
  113. package/components/I18n/components/Translate/spec.js +30 -1
  114. package/components/I18n/index.js +16 -1
  115. package/components/Icon/index.js +25 -2
  116. package/components/Icon/style.js +6 -1
  117. package/components/Image/Image.js +176 -19
  118. package/components/Image/ImageInner.js +48 -2
  119. package/components/Image/index.js +1 -1
  120. package/components/Image/style.js +29 -2
  121. package/components/InfiniteContainer/index.js +381 -49
  122. package/components/InfiniteContainer/spec.js +199 -10
  123. package/components/Input/components/DateInput.js +262 -6
  124. package/components/Input/components/MultiLineInput.js +98 -12
  125. package/components/Input/components/SimpleInput.js +207 -31
  126. package/components/Input/index.js +32 -3
  127. package/components/Input/spec.js +122 -1
  128. package/components/KeyboardConsumer/index.js +48 -7
  129. package/components/Link/connector.js +7 -1
  130. package/components/Link/index.js +96 -11
  131. package/components/Link/spec.js +56 -1
  132. package/components/Link/style.js +10 -1
  133. package/components/List/components/Item/index.js +35 -3
  134. package/components/List/components/Item/style.js +16 -1
  135. package/components/List/index.js +20 -2
  136. package/components/List/spec.js +31 -1
  137. package/components/Loading/index.js +6 -2
  138. package/components/Modal/index.js +38 -3
  139. package/components/Modal/style.js +36 -1
  140. package/components/ModalContainer/connector.js +17 -3
  141. package/components/ModalContainer/index.js +36 -3
  142. package/components/ModalContainer/spec.js +105 -5
  143. package/components/Picker/components/Button/index.js +34 -2
  144. package/components/Picker/components/Button/style.js +19 -1
  145. package/components/Picker/components/List/index.js +33 -2
  146. package/components/Picker/components/List/style.js +17 -1
  147. package/components/Picker/components/Modal/index.js +60 -7
  148. package/components/Picker/components/Modal/style.js +78 -1
  149. package/components/Picker/index.js +167 -21
  150. package/components/Picker/spec.js +83 -2
  151. package/components/Portal/index.js +130 -19
  152. package/components/ProductCharacteristics/connector.js +33 -4
  153. package/components/ProductCharacteristics/context.js +2 -1
  154. package/components/ProductCharacteristics/helpers/index.js +135 -21
  155. package/components/ProductCharacteristics/index.js +266 -31
  156. package/components/RangeSlider/components/Handle/index.js +25 -2
  157. package/components/RangeSlider/components/Handle/style.js +14 -1
  158. package/components/RangeSlider/helper.js +43 -8
  159. package/components/RangeSlider/index.js +228 -38
  160. package/components/RangeSlider/style.js +14 -1
  161. package/components/Route/RouteNotFound.js +46 -3
  162. package/components/Route/index.js +78 -10
  163. package/components/Router/connector.js +9 -2
  164. package/components/Router/index.js +237 -31
  165. package/components/ScannerContainer/connector.js +9 -2
  166. package/components/ScannerContainer/index.js +42 -6
  167. package/components/Select/components/Item/index.js +20 -4
  168. package/components/Select/components/Item/style.js +4 -1
  169. package/components/Select/index.js +149 -28
  170. package/components/Select/spec.js +86 -2
  171. package/components/Select/style.js +17 -1
  172. package/components/SelectBox/components/Item/index.js +47 -5
  173. package/components/SelectBox/components/Item/style.js +7 -1
  174. package/components/SelectBox/index.js +173 -17
  175. package/components/SelectBox/spec.js +59 -3
  176. package/components/SelectBox/style.js +18 -1
  177. package/components/Slider/index.js +6 -2
  178. package/components/SurroundPortals/index.js +26 -2
  179. package/components/Swiper/components/SwiperItem/index.js +28 -4
  180. package/components/Swiper/components/SwiperItem/spec.js +21 -1
  181. package/components/Swiper/components/SwiperItem/styles.js +5 -1
  182. package/components/Swiper/index.js +210 -18
  183. package/components/Swiper/styles.js +75 -7
  184. package/components/Toaster/index.js +10 -2
  185. package/components/Transition/index.js +89 -13
  186. package/components/Widgets/components/Widget/index.js +52 -4
  187. package/components/Widgets/components/Widget/spec.js +68 -3
  188. package/components/Widgets/components/Widget/style.js +21 -3
  189. package/components/Widgets/components/WidgetGrid/index.js +52 -7
  190. package/components/Widgets/components/WidgetGrid/spec.js +46 -2
  191. package/components/Widgets/components/WidgetGrid/style.js +8 -1
  192. package/components/Widgets/helpers/shouldShowWidget.js +44 -7
  193. package/components/Widgets/index.js +127 -15
  194. package/components/Widgets/spec.js +228 -6
  195. package/components/index.js +9 -1
  196. package/constants/ActionTypes.js +97 -19
  197. package/constants/Configuration.js +12 -2
  198. package/constants/Device.js +29 -2
  199. package/constants/DisplayOptions.js +8 -1
  200. package/constants/MenuIDs.js +2 -1
  201. package/constants/ModalTypes.js +1 -1
  202. package/constants/PageIDs.js +1 -1
  203. package/constants/Pipelines.js +7 -1
  204. package/constants/Portals.js +136 -3
  205. package/constants/Registration.js +3 -1
  206. package/constants/RoutePaths.js +13 -2
  207. package/constants/Tracking.js +3 -1
  208. package/constants/client.js +6 -1
  209. package/constants/ui.js +2 -1
  210. package/constants/user.js +6 -2
  211. package/context/index.js +33 -3
  212. package/helpers/config/index.js +139 -21
  213. package/helpers/config/mock.js +200 -8
  214. package/helpers/config/theme.js +50 -4
  215. package/helpers/data/index.js +204 -29
  216. package/helpers/data/spec.js +187 -7
  217. package/helpers/date/index.js +58 -6
  218. package/helpers/date/spec.js +92 -1
  219. package/helpers/dom/index.js +48 -11
  220. package/helpers/environment/index.js +14 -2
  221. package/helpers/html/decodeHTML.js +7 -1
  222. package/helpers/html/handleDOM.js +172 -21
  223. package/helpers/html/parseHTML.js +67 -12
  224. package/helpers/i18n/getDateFormatter.js +23 -4
  225. package/helpers/i18n/getNumberFormatter.js +32 -4
  226. package/helpers/i18n/getPriceFormatter.js +38 -4
  227. package/helpers/i18n/getTimeFormatter.js +23 -4
  228. package/helpers/i18n/getTranslator.js +62 -8
  229. package/helpers/i18n/index.js +5 -1
  230. package/helpers/i18n/mergeTranslations.js +36 -9
  231. package/helpers/i18n/messageCache.js +3 -1
  232. package/helpers/legacy/index.js +47 -9
  233. package/helpers/modal/withShowModal.js +13 -2
  234. package/helpers/portals/portalCollection.js +28 -6
  235. package/helpers/portals/routePortals.js +12 -1
  236. package/helpers/redux/compareObjects.js +7 -2
  237. package/helpers/redux/generateResultHash.js +36 -3
  238. package/helpers/redux/generateSortedHash.js +7 -2
  239. package/helpers/redux/hasExpired.js +10 -2
  240. package/helpers/redux/index.js +7 -1
  241. package/helpers/redux/mutable.js +143 -24
  242. package/helpers/redux/shouldFetchData.js +46 -10
  243. package/helpers/redux/shouldFetchFilters.js +17 -4
  244. package/helpers/router/index.js +49 -5
  245. package/helpers/style/index.js +43 -4
  246. package/helpers/style/spec.js +108 -2
  247. package/helpers/tracking/index.js +52 -9
  248. package/helpers/validation/index.js +39 -12
  249. package/helpers/validation/spec.js +10 -1
  250. package/package.json +3 -4
  251. package/providers/index.js +4 -1
  252. package/providers/loading/context.js +2 -1
  253. package/providers/loading/index.js +137 -22
  254. package/providers/toast/context.js +2 -1
  255. package/providers/toast/index.js +105 -11
  256. package/reducers/client/connectivity.js +22 -2
  257. package/reducers/client/index.js +7 -1
  258. package/reducers/client/info.js +27 -2
  259. package/reducers/index.js +23 -4
  260. package/reducers/menu/index.js +5 -1
  261. package/reducers/menu/menusById.js +41 -2
  262. package/reducers/modal/index.js +14 -2
  263. package/reducers/page/index.js +68 -5
  264. package/reducers/router/index.js +48 -2
  265. package/reducers/url/index.js +42 -3
  266. package/reducers/user/data.js +27 -2
  267. package/reducers/user/index.js +7 -1
  268. package/reducers/user/login.js +65 -2
  269. package/selectors/client.js +138 -21
  270. package/selectors/history.js +49 -11
  271. package/selectors/menu.js +34 -6
  272. package/selectors/modal.js +15 -4
  273. package/selectors/page.js +25 -4
  274. package/selectors/router.js +154 -30
  275. package/selectors/url.js +25 -4
  276. package/selectors/user.js +90 -13
  277. package/store/index.js +60 -6
  278. package/store/middelwares/logger.js +7 -1
  279. package/store/middelwares/streams.js +19 -2
  280. package/streams/app.js +60 -8
  281. package/streams/client.js +8 -2
  282. package/streams/error.js +14 -3
  283. package/streams/index.js +6 -1
  284. package/streams/interval.js +6 -2
  285. package/streams/main.js +27 -2
  286. package/streams/router.js +45 -8
  287. package/streams/user.js +89 -15
  288. package/streams/view.js +97 -25
  289. package/styles/reset/form.js +57 -5
  290. package/styles/reset/index.js +6 -1
  291. package/styles/reset/media.js +22 -1
  292. package/styles/reset/root.js +33 -1
  293. package/styles/reset/table.js +10 -1
  294. package/styles/reset/typography.js +26 -1
  295. package/subscriptions/app.js +148 -17
  296. package/subscriptions/error.js +292 -13
  297. package/subscriptions/helpers/buildRegisterUrl.js +25 -6
  298. package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
  299. package/subscriptions/helpers/handleLinks.js +267 -25
  300. package/subscriptions/helpers/pipeline.js +12 -1
  301. package/subscriptions/history.js +34 -6
  302. package/subscriptions/index.js +25 -4
  303. package/subscriptions/menu.js +22 -5
  304. package/subscriptions/mock.js +39 -7
  305. package/subscriptions/router.js +336 -23
  306. package/subscriptions/user.js +93 -3
@@ -1,4 +1,6 @@
1
- import{NAVIGATE,ROUTE_WILL_ENTER,ROUTE_DID_ENTER,ROUTE_WILL_LEAVE,ROUTE_DID_LEAVE,ROUTE_DID_UPDATE}from"../../constants/ActionTypes";/**
1
+ import { NAVIGATE, ROUTE_WILL_ENTER, ROUTE_DID_ENTER, ROUTE_WILL_LEAVE, ROUTE_DID_LEAVE, ROUTE_DID_UPDATE } from "../../constants/ActionTypes";
2
+
3
+ /**
2
4
  * Creates the dispatched NAVIGATE action object.
3
5
  * @param {Object} params The history params.
4
6
  * @param {string} params.action The history action.
@@ -7,29 +9,68 @@ import{NAVIGATE,ROUTE_WILL_ENTER,ROUTE_DID_ENTER,ROUTE_WILL_LEAVE,ROUTE_DID_LEAV
7
9
  * @param {Object} params.state The history state.
8
10
  * @param {number} params.steps The number of steps to navigate by.
9
11
  * @return {Object} The dispatched action object.
10
- */export var navigate=function navigate(params){return{type:NAVIGATE,params:params};};/**
12
+ */
13
+ export const navigate = params => ({
14
+ type: NAVIGATE,
15
+ params
16
+ });
17
+
18
+ /**
11
19
  * Creates the dispatched ROUTE_WILL_ENTER action object.
12
20
  * @param {Object} route The route object.
13
21
  * @param {string} historyAction The history action.
14
22
  * @return {Object} The dispatched action object.
15
- */export var routeWillEnter=function routeWillEnter(route,historyAction){return{type:ROUTE_WILL_ENTER,route:route,historyAction:historyAction};};/**
23
+ */
24
+ export const routeWillEnter = (route, historyAction) => ({
25
+ type: ROUTE_WILL_ENTER,
26
+ route,
27
+ historyAction
28
+ });
29
+
30
+ /**
16
31
  * Creates the dispatched ROUTE_DID_ENTER action object.
17
32
  * @param {Object} route The route object.
18
33
  * @param {string} historyAction The history action.
19
34
  * @return {Object} The dispatched action object.
20
- */export var routeDidEnter=function routeDidEnter(route,historyAction){return{type:ROUTE_DID_ENTER,route:route,historyAction:historyAction};};/**
35
+ */
36
+ export const routeDidEnter = (route, historyAction) => ({
37
+ type: ROUTE_DID_ENTER,
38
+ route,
39
+ historyAction
40
+ });
41
+
42
+ /**
21
43
  * Creates the dispatched ROUTE_WILL_LEAVE action object.
22
44
  * @param {Object} route The route object.
23
45
  * @param {string} historyAction The history action.
24
46
  * @return {Object} The dispatched action object.
25
- */export var routeWillLeave=function routeWillLeave(route,historyAction){return{type:ROUTE_WILL_LEAVE,route:route,historyAction:historyAction};};/**
47
+ */
48
+ export const routeWillLeave = (route, historyAction) => ({
49
+ type: ROUTE_WILL_LEAVE,
50
+ route,
51
+ historyAction
52
+ });
53
+
54
+ /**
26
55
  * Creates the dispatched ROUTE_DID_LEAVE action object.
27
56
  * @param {Object} route The route object.
28
57
  * @param {string} historyAction The history action.
29
58
  * @return {Object} The dispatched action object.
30
- */export var routeDidLeave=function routeDidLeave(route,historyAction){return{type:ROUTE_DID_LEAVE,route:route,historyAction:historyAction};};/**
59
+ */
60
+ export const routeDidLeave = (route, historyAction) => ({
61
+ type: ROUTE_DID_LEAVE,
62
+ route,
63
+ historyAction
64
+ });
65
+
66
+ /**
31
67
  * Creates the dispatched ROUTE_DID_UPDATE action object.
32
68
  * @param {Object} route The route object.
33
69
  * @param {string} historyAction The history action.
34
70
  * @return {Object} The dispatched action object.
35
- */export var routeDidUpdate=function routeDidUpdate(route,historyAction){return{type:ROUTE_DID_UPDATE,route:route,historyAction:historyAction};};
71
+ */
72
+ export const routeDidUpdate = (route, historyAction) => ({
73
+ type: ROUTE_DID_UPDATE,
74
+ route,
75
+ historyAction
76
+ });
@@ -1,15 +1,35 @@
1
- import{RECEIVE_URL,REQUEST_URL,ERROR_URL}from"../../constants/ActionTypes";/**
1
+ import { RECEIVE_URL, REQUEST_URL, ERROR_URL } from "../../constants/ActionTypes";
2
+
3
+ /**
2
4
  * Creates the dispatched RECEIVE_URL action object.
3
5
  * @param {string} urlType The url type.
4
6
  * @param {string} url The requested url.
5
7
  * @param {number|null} [expires=null] The expires date of the url.
6
8
  * @returns {Object} The dispatched action object.
7
- */export var receiveUrl=function receiveUrl(urlType,url){var expires=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;return{type:RECEIVE_URL,url:url,urlType:urlType,expires:expires};};/**
9
+ */
10
+ export const receiveUrl = (urlType, url, expires = null) => ({
11
+ type: RECEIVE_URL,
12
+ url,
13
+ urlType,
14
+ expires
15
+ });
16
+
17
+ /**
8
18
  * Creates the dispatched REQUEST_URL action object.
9
19
  * @param {string} urlType The url type.
10
20
  * @returns {Object} The dispatched action object.
11
- */export var requestUrl=function requestUrl(urlType){return{type:REQUEST_URL,urlType:urlType};};/**
21
+ */
22
+ export const requestUrl = urlType => ({
23
+ type: REQUEST_URL,
24
+ urlType
25
+ });
26
+
27
+ /**
12
28
  * Creates the dispatched ERROR_URL action object.
13
29
  * @param {string} urlType The url type.
14
30
  * @returns {Object} The dispatched action object.
15
- */export var errorUrl=function errorUrl(urlType){return{type:ERROR_URL,urlType:urlType};};
31
+ */
32
+ export const errorUrl = urlType => ({
33
+ type: ERROR_URL,
34
+ urlType
35
+ });
@@ -1 +1,45 @@
1
- import{RECEIVE_URL,REQUEST_URL,ERROR_URL}from"../../constants/ActionTypes";import{receiveUrl,requestUrl,errorUrl}from"./index";var url='https://www.myshop.com/checkout';var urlType='checkout';var expires=123456;describe('Action Creators: url',function(){describe('receiveUrl()',function(){it('should work as expected',function(){var expected={type:RECEIVE_URL,url:url,urlType:urlType,expires:expires};expect(receiveUrl(urlType,url,expires)).toEqual(expected);});it('should work as expected when no expires parameter is passed',function(){var expected={type:RECEIVE_URL,url:url,urlType:urlType,expires:null};expect(receiveUrl(urlType,url)).toEqual(expected);});});describe('requestUrl()',function(){it('should work as expected',function(){var expected={type:REQUEST_URL,urlType:urlType};expect(requestUrl(urlType)).toEqual(expected);});});describe('errorUrl()',function(){it('should work as expected',function(){var expected={type:ERROR_URL,urlType:urlType};expect(errorUrl(urlType)).toEqual(expected);});});});
1
+ import { RECEIVE_URL, REQUEST_URL, ERROR_URL } from "../../constants/ActionTypes";
2
+ import { receiveUrl, requestUrl, errorUrl } from "./index";
3
+ const url = 'https://www.myshop.com/checkout';
4
+ const urlType = 'checkout';
5
+ const expires = 123456;
6
+ describe('Action Creators: url', () => {
7
+ describe('receiveUrl()', () => {
8
+ it('should work as expected', () => {
9
+ const expected = {
10
+ type: RECEIVE_URL,
11
+ url,
12
+ urlType,
13
+ expires
14
+ };
15
+ expect(receiveUrl(urlType, url, expires)).toEqual(expected);
16
+ });
17
+ it('should work as expected when no expires parameter is passed', () => {
18
+ const expected = {
19
+ type: RECEIVE_URL,
20
+ url,
21
+ urlType,
22
+ expires: null
23
+ };
24
+ expect(receiveUrl(urlType, url)).toEqual(expected);
25
+ });
26
+ });
27
+ describe('requestUrl()', () => {
28
+ it('should work as expected', () => {
29
+ const expected = {
30
+ type: REQUEST_URL,
31
+ urlType
32
+ };
33
+ expect(requestUrl(urlType)).toEqual(expected);
34
+ });
35
+ });
36
+ describe('errorUrl()', () => {
37
+ it('should work as expected', () => {
38
+ const expected = {
39
+ type: ERROR_URL,
40
+ urlType
41
+ };
42
+ expect(errorUrl(urlType)).toEqual(expected);
43
+ });
44
+ });
45
+ });
@@ -1,4 +1,7 @@
1
- import{REQUEST_LOGIN,SUCCESS_LOGIN,ERROR_LOGIN,ERROR_LEGACY_CONNECT_REGISTER,REQUEST_LOGOUT,SUCCESS_LOGOUT,ERROR_LOGOUT,REQUEST_USER,RECEIVE_USER,ERROR_USER,TOGGLE_LOGGED_IN,DISABLE_LOGIN}from"../../constants/ActionTypes";import{DEFAULT_LOGIN_STRATEGY}from"../../constants/user";/**
1
+ import { REQUEST_LOGIN, SUCCESS_LOGIN, ERROR_LOGIN, ERROR_LEGACY_CONNECT_REGISTER, REQUEST_LOGOUT, SUCCESS_LOGOUT, ERROR_LOGOUT, REQUEST_USER, RECEIVE_USER, ERROR_USER, TOGGLE_LOGGED_IN, DISABLE_LOGIN } from "../../constants/ActionTypes";
2
+ import { DEFAULT_LOGIN_STRATEGY } from "../../constants/user";
3
+
4
+ /**
2
5
  * Creates the dispatched REQUEST_LOGIN action object.
3
6
  * It also passes login credentials to the action,
4
7
  * in order to may access it within a stream subscription.
@@ -6,50 +9,124 @@ import{REQUEST_LOGIN,SUCCESS_LOGIN,ERROR_LOGIN,ERROR_LEGACY_CONNECT_REGISTER,REQ
6
9
  * @param {string} password The user password.
7
10
  * @param {string} strategy login strategy
8
11
  * @returns {Object} The dispatched action object.
9
- */export var requestLogin=function requestLogin(user,password){var strategy=arguments.length>2&&arguments[2]!==undefined?arguments[2]:DEFAULT_LOGIN_STRATEGY;return{type:REQUEST_LOGIN,user:user,password:password,strategy:strategy};};/**
12
+ */
13
+ export const requestLogin = (user, password, strategy = DEFAULT_LOGIN_STRATEGY) => ({
14
+ type: REQUEST_LOGIN,
15
+ user,
16
+ password,
17
+ strategy
18
+ });
19
+
20
+ /**
10
21
  * Creates the dispatched RECEIVE_LOGIN action object.
11
22
  * @param {string} redirect The location to redirect to.
12
23
  * @param {string} strategy The login strategy.
13
24
  * @param {number} [sessionLifetimeInSeconds] The session lifetime in seconds
14
25
  * @returns {Object} The dispatched action object.
15
- */export var successLogin=function successLogin(redirect){var strategy=arguments.length>1&&arguments[1]!==undefined?arguments[1]:DEFAULT_LOGIN_STRATEGY;var sessionLifetimeInSeconds=arguments.length>2?arguments[2]:undefined;return{type:SUCCESS_LOGIN,redirect:redirect,strategy:strategy,sessionLifetimeInSeconds:sessionLifetimeInSeconds};};/**
26
+ */
27
+ export const successLogin = (redirect, strategy = DEFAULT_LOGIN_STRATEGY, sessionLifetimeInSeconds) => ({
28
+ type: SUCCESS_LOGIN,
29
+ redirect,
30
+ strategy,
31
+ sessionLifetimeInSeconds
32
+ });
33
+
34
+ /**
16
35
  * Creates the dispatched ERROR_LOGIN action object.
17
36
  * @param {Array} [messages=[]] Array of error messages.
18
37
  * @param {string} code The specific error code.
19
38
  * @returns {Object} The dispatched action object.
20
- */export var errorLogin=function errorLogin(){var messages=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var code=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'';return{type:ERROR_LOGIN,messages:messages,code:code};};/**
39
+ */
40
+ export const errorLogin = (messages = [], code = '') => ({
41
+ type: ERROR_LOGIN,
42
+ messages,
43
+ code
44
+ });
45
+
46
+ /**
21
47
  * Creates the dispatched ERROR_LEGACY_CONNECT_REGISTER action object.
22
48
  * @returns {Object} The dispatched action object.
23
- */export var errorLegacyConnectRegister=function errorLegacyConnectRegister(){return{type:ERROR_LEGACY_CONNECT_REGISTER};};/**
49
+ */
50
+ export const errorLegacyConnectRegister = () => ({
51
+ type: ERROR_LEGACY_CONNECT_REGISTER
52
+ });
53
+
54
+ /**
24
55
  * Creates the dispatched REQUEST_LOGOUT action object.
25
56
  * @returns {Object} The dispatched action object.
26
- */export var requestLogout=function requestLogout(){return{type:REQUEST_LOGOUT};};/**
57
+ */
58
+ export const requestLogout = () => ({
59
+ type: REQUEST_LOGOUT
60
+ });
61
+
62
+ /**
27
63
  * Creates the dispatched RECEIVE_LOGOUT action object.
28
64
  * @param {boolean} [notify=true] If set to TRUE users are notified when the logout was successful.
29
65
  * @param {boolean} [autoLogout=false] Whether the logout happened because e.g. session expired
30
66
  * @returns {Object} The dispatched action object.
31
- */export var successLogout=function successLogout(){var notify=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var autoLogout=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return{type:SUCCESS_LOGOUT,notify:notify,autoLogout:autoLogout};};/**
67
+ */
68
+ export const successLogout = (notify = true, autoLogout = false) => ({
69
+ type: SUCCESS_LOGOUT,
70
+ notify,
71
+ autoLogout
72
+ });
73
+
74
+ /**
32
75
  * Creates the dispatched ERROR_LOGOUT action object.
33
76
  * @param {Array} [messages=[]] Array of error messages
34
77
  * @param {boolean} [autoLogout=false] Whether the logout happened because e.g. session expired
35
78
  * @returns {Object} The dispatched action object.
36
- */export var errorLogout=function errorLogout(){var messages=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var autoLogout=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return{type:ERROR_LOGOUT,messages:messages,autoLogout:autoLogout};};/**
79
+ */
80
+ export const errorLogout = (messages = [], autoLogout = false) => ({
81
+ type: ERROR_LOGOUT,
82
+ messages,
83
+ autoLogout
84
+ });
85
+
86
+ /**
37
87
  * Creates the dispatched REQUEST_USER action object.
38
88
  * @returns {Object} The dispatched action object.
39
- */export var requestUser=function requestUser(){return{type:REQUEST_USER};};/**
89
+ */
90
+ export const requestUser = () => ({
91
+ type: REQUEST_USER
92
+ });
93
+
94
+ /**
40
95
  * Creates the dispatched RECEIVE_USER action object.
41
96
  * @param {Object} user The user data
42
97
  * @returns {Object} The dispatched action object.
43
- */export var receiveUser=function receiveUser(user){return{type:RECEIVE_USER,user:user};};/**
98
+ */
99
+ export const receiveUser = user => ({
100
+ type: RECEIVE_USER,
101
+ user
102
+ });
103
+
104
+ /**
44
105
  * Creates the dispatched ERROR_USER action object.
45
106
  * @param {Object} error error
46
107
  @returns {Object} The dispatched action object.
47
- */export var errorUser=function errorUser(error){return{type:ERROR_USER,error:error};};/**
108
+ */
109
+ export const errorUser = error => ({
110
+ type: ERROR_USER,
111
+ error
112
+ });
113
+
114
+ /**
48
115
  * Creates the dispatched TOGGLE_LOGGED_IN action object.
49
116
  * @param {boolean} value The updated logged in state.
50
117
  * @returns {Object} The dispatched action object.
51
- */export var toggleLoggedIn=function toggleLoggedIn(value){return{type:TOGGLE_LOGGED_IN,value:value};};/**
118
+ */
119
+ export const toggleLoggedIn = value => ({
120
+ type: TOGGLE_LOGGED_IN,
121
+ value
122
+ });
123
+
124
+ /**
52
125
  * Creates the dispatched DISABLE_LOGIN action object.
53
126
  * @param {boolean} value Whether it is enabled or disabled.
54
127
  * @returns {Object}
55
- */export var disableLogin=function disableLogin(value){return{type:DISABLE_LOGIN,value:value};};
128
+ */
129
+ export const disableLogin = value => ({
130
+ type: DISABLE_LOGIN,
131
+ value
132
+ });
@@ -1,2 +1,186 @@
1
- import{requestLogin,successLogin,errorLogin,requestLogout,successLogout,errorLogout,requestUser,receiveUser,errorUser,toggleLoggedIn}from"./index";import{REQUEST_LOGIN,SUCCESS_LOGIN,ERROR_LOGIN,REQUEST_LOGOUT,SUCCESS_LOGOUT,ERROR_LOGOUT,REQUEST_USER,RECEIVE_USER,ERROR_USER,TOGGLE_LOGGED_IN}from"../../constants/ActionTypes";import{DEFAULT_LOGIN_STRATEGY}from"../../constants/user";var messages=[{type:'EUNKNOWN',message:'Something went wrong',code:1337}];describe('Action Creators: user',function(){describe('requestLogin()',function(){it('should work as expected',function(){var user='super@user.com';var password='super#password';var expected={type:REQUEST_LOGIN,user:user,password:password,strategy:DEFAULT_LOGIN_STRATEGY};expect(requestLogin(user,password)).toEqual(expected);});});describe('successLogin()',function(){it('should work as expected with no parameters',function(){var expected={type:SUCCESS_LOGIN,redirect:undefined,strategy:DEFAULT_LOGIN_STRATEGY};expect(successLogin()).toEqual(expected);});it('should work as expected with parameters',function(){var redirect='/some/url';var strategy='custom';var expected={type:SUCCESS_LOGIN,redirect:redirect,strategy:strategy};expect(successLogin(redirect,strategy)).toEqual(expected);});});describe('errorLogin()',function(){it('should work as expected',function(){var expected={type:ERROR_LOGIN,code:'EUNKNOWN',messages:messages};expect(errorLogin(messages,'EUNKNOWN')).toEqual(expected);});it('should work as expected when the messages parameter is empty',function(){var expected={type:ERROR_LOGIN,code:'EUNKNOWN',messages:[]};expect(errorLogin(undefined,'EUNKNOWN')).toEqual(expected);});it('should work as expected when the code paramter is empty',function(){var expected={type:ERROR_LOGIN,code:'',messages:messages};expect(errorLogin(messages)).toEqual(expected);});});describe('requestLogout()',function(){it('should work as expected',function(){var expected={type:REQUEST_LOGOUT};expect(requestLogout()).toEqual(expected);});});describe('successLogout()',function(){it('should work as expected when called without parameter',function(){var expected={type:SUCCESS_LOGOUT,notify:true,autoLogout:false};expect(successLogout()).toEqual(expected);});it('should work as expected when called with true',function(){var expected={type:SUCCESS_LOGOUT,notify:true,autoLogout:false};expect(successLogout(true)).toEqual(expected);});it('should work as expected when called with false',function(){var expected={type:SUCCESS_LOGOUT,notify:false,autoLogout:false};expect(successLogout(false)).toEqual(expected);});it('should work as expected when called with autoLogout parameter',function(){var expected={type:SUCCESS_LOGOUT,notify:true,autoLogout:true};expect(successLogout(undefined,true)).toEqual(expected);});});describe('errorLogout()',function(){it('should work as expected',function(){var expected={type:ERROR_LOGOUT,messages:messages,autoLogout:false};expect(errorLogout(messages)).toEqual(expected);});it('should work as expected when the messages parameter is empty',function(){var expected={type:ERROR_LOGOUT,messages:[],autoLogout:false};expect(errorLogout()).toEqual(expected);});it('should work as expected when called with autoLogout parameter',function(){var expected={type:ERROR_LOGOUT,messages:messages,autoLogout:true};expect(errorLogout(messages,true)).toEqual(expected);});});describe('requestUser()',function(){it('should work as expected',function(){var expected={type:REQUEST_USER};expect(requestUser()).toEqual(expected);});});describe('receiveUser()',function(){it('should work as expected',function(){var user={firstName:'John',lastName:'Doe',mail:'john@doe.com'};var expected={type:RECEIVE_USER,user:user};expect(receiveUser(user)).toEqual(expected);});});describe('errorUser()',function(){it('should work as expected',function(){var err=new Error();// eslint-disable-next-line extra-rules/no-single-line-objects
2
- var expected={type:ERROR_USER,error:err};expect(errorUser(err)).toEqual(expected);});});describe('toggleLoggedIn()',function(){it('should toggle to true',function(){var expected={type:TOGGLE_LOGGED_IN,value:true};expect(toggleLoggedIn(true)).toEqual(expected);});it('should toggle to false',function(){var expected={type:TOGGLE_LOGGED_IN,value:false};expect(toggleLoggedIn(false)).toEqual(expected);});});});
1
+ import { requestLogin, successLogin, errorLogin, requestLogout, successLogout, errorLogout, requestUser, receiveUser, errorUser, toggleLoggedIn } from "./index";
2
+ import { REQUEST_LOGIN, SUCCESS_LOGIN, ERROR_LOGIN, REQUEST_LOGOUT, SUCCESS_LOGOUT, ERROR_LOGOUT, REQUEST_USER, RECEIVE_USER, ERROR_USER, TOGGLE_LOGGED_IN } from "../../constants/ActionTypes";
3
+ import { DEFAULT_LOGIN_STRATEGY } from "../../constants/user";
4
+ const messages = [{
5
+ type: 'EUNKNOWN',
6
+ message: 'Something went wrong',
7
+ code: 1337
8
+ }];
9
+ describe('Action Creators: user', () => {
10
+ describe('requestLogin()', () => {
11
+ it('should work as expected', () => {
12
+ const user = 'super@user.com';
13
+ const password = 'super#password';
14
+ const expected = {
15
+ type: REQUEST_LOGIN,
16
+ user,
17
+ password,
18
+ strategy: DEFAULT_LOGIN_STRATEGY
19
+ };
20
+ expect(requestLogin(user, password)).toEqual(expected);
21
+ });
22
+ });
23
+ describe('successLogin()', () => {
24
+ it('should work as expected with no parameters', () => {
25
+ const expected = {
26
+ type: SUCCESS_LOGIN,
27
+ redirect: undefined,
28
+ strategy: DEFAULT_LOGIN_STRATEGY
29
+ };
30
+ expect(successLogin()).toEqual(expected);
31
+ });
32
+ it('should work as expected with parameters', () => {
33
+ const redirect = '/some/url';
34
+ const strategy = 'custom';
35
+ const expected = {
36
+ type: SUCCESS_LOGIN,
37
+ redirect,
38
+ strategy
39
+ };
40
+ expect(successLogin(redirect, strategy)).toEqual(expected);
41
+ });
42
+ });
43
+ describe('errorLogin()', () => {
44
+ it('should work as expected', () => {
45
+ const expected = {
46
+ type: ERROR_LOGIN,
47
+ code: 'EUNKNOWN',
48
+ messages
49
+ };
50
+ expect(errorLogin(messages, 'EUNKNOWN')).toEqual(expected);
51
+ });
52
+ it('should work as expected when the messages parameter is empty', () => {
53
+ const expected = {
54
+ type: ERROR_LOGIN,
55
+ code: 'EUNKNOWN',
56
+ messages: []
57
+ };
58
+ expect(errorLogin(undefined, 'EUNKNOWN')).toEqual(expected);
59
+ });
60
+ it('should work as expected when the code paramter is empty', () => {
61
+ const expected = {
62
+ type: ERROR_LOGIN,
63
+ code: '',
64
+ messages
65
+ };
66
+ expect(errorLogin(messages)).toEqual(expected);
67
+ });
68
+ });
69
+ describe('requestLogout()', () => {
70
+ it('should work as expected', () => {
71
+ const expected = {
72
+ type: REQUEST_LOGOUT
73
+ };
74
+ expect(requestLogout()).toEqual(expected);
75
+ });
76
+ });
77
+ describe('successLogout()', () => {
78
+ it('should work as expected when called without parameter', () => {
79
+ const expected = {
80
+ type: SUCCESS_LOGOUT,
81
+ notify: true,
82
+ autoLogout: false
83
+ };
84
+ expect(successLogout()).toEqual(expected);
85
+ });
86
+ it('should work as expected when called with true', () => {
87
+ const expected = {
88
+ type: SUCCESS_LOGOUT,
89
+ notify: true,
90
+ autoLogout: false
91
+ };
92
+ expect(successLogout(true)).toEqual(expected);
93
+ });
94
+ it('should work as expected when called with false', () => {
95
+ const expected = {
96
+ type: SUCCESS_LOGOUT,
97
+ notify: false,
98
+ autoLogout: false
99
+ };
100
+ expect(successLogout(false)).toEqual(expected);
101
+ });
102
+ it('should work as expected when called with autoLogout parameter', () => {
103
+ const expected = {
104
+ type: SUCCESS_LOGOUT,
105
+ notify: true,
106
+ autoLogout: true
107
+ };
108
+ expect(successLogout(undefined, true)).toEqual(expected);
109
+ });
110
+ });
111
+ describe('errorLogout()', () => {
112
+ it('should work as expected', () => {
113
+ const expected = {
114
+ type: ERROR_LOGOUT,
115
+ messages,
116
+ autoLogout: false
117
+ };
118
+ expect(errorLogout(messages)).toEqual(expected);
119
+ });
120
+ it('should work as expected when the messages parameter is empty', () => {
121
+ const expected = {
122
+ type: ERROR_LOGOUT,
123
+ messages: [],
124
+ autoLogout: false
125
+ };
126
+ expect(errorLogout()).toEqual(expected);
127
+ });
128
+ it('should work as expected when called with autoLogout parameter', () => {
129
+ const expected = {
130
+ type: ERROR_LOGOUT,
131
+ messages,
132
+ autoLogout: true
133
+ };
134
+ expect(errorLogout(messages, true)).toEqual(expected);
135
+ });
136
+ });
137
+ describe('requestUser()', () => {
138
+ it('should work as expected', () => {
139
+ const expected = {
140
+ type: REQUEST_USER
141
+ };
142
+ expect(requestUser()).toEqual(expected);
143
+ });
144
+ });
145
+ describe('receiveUser()', () => {
146
+ it('should work as expected', () => {
147
+ const user = {
148
+ firstName: 'John',
149
+ lastName: 'Doe',
150
+ mail: 'john@doe.com'
151
+ };
152
+ const expected = {
153
+ type: RECEIVE_USER,
154
+ user
155
+ };
156
+ expect(receiveUser(user)).toEqual(expected);
157
+ });
158
+ });
159
+ describe('errorUser()', () => {
160
+ it('should work as expected', () => {
161
+ const err = new Error();
162
+ // eslint-disable-next-line extra-rules/no-single-line-objects
163
+ const expected = {
164
+ type: ERROR_USER,
165
+ error: err
166
+ };
167
+ expect(errorUser(err)).toEqual(expected);
168
+ });
169
+ });
170
+ describe('toggleLoggedIn()', () => {
171
+ it('should toggle to true', () => {
172
+ const expected = {
173
+ type: TOGGLE_LOGGED_IN,
174
+ value: true
175
+ };
176
+ expect(toggleLoggedIn(true)).toEqual(expected);
177
+ });
178
+ it('should toggle to false', () => {
179
+ const expected = {
180
+ type: TOGGLE_LOGGED_IN,
181
+ value: false
182
+ };
183
+ expect(toggleLoggedIn(false)).toEqual(expected);
184
+ });
185
+ });
186
+ });
@@ -1,5 +1,14 @@
1
- import{openDeepLink}from"../../action-creators/app";import handleLink from"./handleLink";/**
1
+ import { openDeepLink } from "../../action-creators/app";
2
+ import handleLink from "./handleLink";
3
+
4
+ /**
2
5
  * Opens a DeepLink.
3
6
  * @param {Object} [payload={}] The deep link event payload.
4
7
  * @return {Function} A redux thunk.
5
- */export default function handleDeepLink(){var payload=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){dispatch(handleLink(payload));dispatch(openDeepLink(payload));};}
8
+ */
9
+ export default function handleDeepLink(payload = {}) {
10
+ return dispatch => {
11
+ dispatch(handleLink(payload));
12
+ dispatch(openDeepLink(payload));
13
+ };
14
+ }
@@ -1,13 +1,69 @@
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{logger}from'@shopgate/pwa-core/helpers';import{DEEPLINK_CART_ADD_PRODUCT_PATTERN}from'@shopgate/pwa-common-commerce/cart/constants';import fetchProduct from'@shopgate/pwa-common-commerce/product/actions/fetchProduct';import{historyPush,historyReset}from"../router";import{INDEX_PATH_DEEPLINK,INDEX_PATH}from"../../constants/RoutePaths";/**
1
+ import "core-js/modules/es.string.replace.js";
2
+ import "core-js/modules/web.url.js";
3
+ import "core-js/modules/web.url.to-json.js";
4
+ import "core-js/modules/web.url-search-params.js";
5
+ import { logger } from '@shopgate/pwa-core/helpers';
6
+ import { DEEPLINK_CART_ADD_PRODUCT_PATTERN } from '@shopgate/pwa-common-commerce/cart/constants';
7
+ import fetchProduct from '@shopgate/pwa-common-commerce/product/actions/fetchProduct';
8
+ import { historyPush, historyReset } from "../router";
9
+ import { INDEX_PATH_DEEPLINK, INDEX_PATH } from "../../constants/RoutePaths";
10
+
11
+ /**
2
12
  * @param {Object} payload The link payload.
3
13
  * @param {boolean} allowExternalLinks Wether the function should open external links or should try
4
14
  * to convert them to internal links
5
15
  * @return {Function}
6
- */export default function handleLink(payload){var allowExternalLinks=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var link,pathname,_ref2,_pathname$split3,_pathname$split4,productId;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:link=payload.link;if(link){_context.next=3;break;}return _context.abrupt("return");case 3:// cast to string
7
- link=String(link);if(!link.startsWith('http')){_context.next=11;break;}if(!allowExternalLinks){_context.next=8;break;}dispatch(historyPush({pathname:link}));return _context.abrupt("return");case 8:try{_ref2=new URL(link);pathname=_ref2.pathname;}catch(linkParseError){logger.error("Could not parse link ".concat(link),linkParseError);}_context.next=13;break;case 11:// Remove the deeplink protocol from the link.
8
- pathname=link.replace(/^(.*:)(\/\/)?/,'/');if(!pathname.startsWith('/')){// Take care that pathname starts with a slash. Otherwise routing can break
9
- pathname="/".concat(pathname);}case 13:if(!(!pathname||pathname===INDEX_PATH||pathname.startsWith(INDEX_PATH_DEEPLINK))){_context.next=16;break;}/**
16
+ */
17
+ export default function handleLink(payload, allowExternalLinks = false) {
18
+ return async dispatch => {
19
+ let {
20
+ link
21
+ } = payload;
22
+ if (!link) {
23
+ return;
24
+ }
25
+
26
+ // cast to string
27
+ link = String(link);
28
+ let pathname;
29
+ if (link.startsWith('http')) {
30
+ // Link is common URL schema.
31
+ if (allowExternalLinks) {
32
+ dispatch(historyPush({
33
+ pathname: link
34
+ }));
35
+ return;
36
+ }
37
+ try {
38
+ ({
39
+ pathname
40
+ } = new URL(link));
41
+ } catch (linkParseError) {
42
+ logger.error(`Could not parse link ${link}`, linkParseError);
43
+ }
44
+ } else {
45
+ // Remove the deeplink protocol from the link.
46
+ pathname = link.replace(/^(.*:)(\/\/)?/, '/');
47
+ if (!pathname.startsWith('/')) {
48
+ // Take care that pathname starts with a slash. Otherwise routing can break
49
+ pathname = `/${pathname}`;
50
+ }
51
+ }
52
+ if (!pathname || pathname === INDEX_PATH || pathname.startsWith(INDEX_PATH_DEEPLINK)) {
53
+ /**
10
54
  * Special treatment for the index page. To avoid multiple index pages within the history,
11
55
  * the parsed link helper will only emit the openLink events for the link to inform the
12
56
  * streams, but not open a real page. Additionally the history is reset.
13
- */dispatch(historyReset());return _context.abrupt("return");case 16:if(!pathname.includes(DEEPLINK_CART_ADD_PRODUCT_PATTERN.split('/')[1])){_context.next=20;break;}_pathname$split3=pathname.split('/'),_pathname$split4=_slicedToArray(_pathname$split3,3),productId=_pathname$split4[2];_context.next=20;return dispatch(fetchProduct(decodeURIComponent(productId)));case 20:dispatch(historyPush({pathname:pathname}));case 21:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}());}
57
+ */
58
+ dispatch(historyReset());
59
+ return;
60
+ }
61
+ if (pathname.includes(DEEPLINK_CART_ADD_PRODUCT_PATTERN.split('/')[1])) {
62
+ const [,, productId] = pathname.split('/');
63
+ await dispatch(fetchProduct(decodeURIComponent(productId)));
64
+ }
65
+ dispatch(historyPush({
66
+ pathname
67
+ }));
68
+ };
69
+ }
@@ -1,11 +1,39 @@
1
- import{DataRequest}from'@shopgate/pwa-core';import{openPushNotification}from"../../action-creators/app";import handleLink from"./handleLink";var PUSH_MESSAGE_OPENED='ajax_push_message_opened';/**
1
+ import { DataRequest } from '@shopgate/pwa-core';
2
+ import { openPushNotification } from "../../action-creators/app";
3
+ import handleLink from "./handleLink";
4
+ const PUSH_MESSAGE_OPENED = 'ajax_push_message_opened';
5
+
6
+ /**
2
7
  * Handles the opening of a push notification. If the payload contains a link, it calls
3
8
  * the openDeepLink actions additionally.
4
9
  * @param {Object} payload The push notification payload.
5
10
  * @return {Function} A redux thunk.
6
- */export default function handlePushNotification(){var payload=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){var _payload$link=payload.link,link=_payload$link===void 0?'':_payload$link,_payload$notification=payload.notificationId,notificationId=_payload$notification===void 0?null:_payload$notification,nativeNotificationNotShown=payload.nativeNotificationNotShown;/**
11
+ */
12
+ export default function handlePushNotification(payload = {}) {
13
+ return dispatch => {
14
+ const {
15
+ link = '',
16
+ notificationId = null,
17
+ nativeNotificationNotShown
18
+ } = payload;
19
+
20
+ /**
7
21
  * The following property is only available on iOS. A value of TRUE indicates that the push
8
22
  * message came in, while the app was open. Since the app would instantly open the link of the
9
23
  * message in those situations, the link handling is suppressed to not distract the user.
10
- */if(nativeNotificationNotShown===true){return;}if(notificationId){var id=notificationId.toString();// Send tracking event to the backend
11
- new DataRequest(PUSH_MESSAGE_OPENED).setPayload({notificationId:id}).dispatch();}dispatch(handleLink(payload,true));dispatch(openPushNotification(notificationId,link));};}
24
+ */
25
+ if (nativeNotificationNotShown === true) {
26
+ return;
27
+ }
28
+ if (notificationId) {
29
+ const id = notificationId.toString();
30
+
31
+ // Send tracking event to the backend
32
+ new DataRequest(PUSH_MESSAGE_OPENED).setPayload({
33
+ notificationId: id
34
+ }).dispatch();
35
+ }
36
+ dispatch(handleLink(payload, true));
37
+ dispatch(openPushNotification(notificationId, link));
38
+ };
39
+ }