@shopgate/pwa-common 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 (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 +207 -6
  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 +17 -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 +213 -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 -3
  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,34 +1,325 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import queryString from'query-string';import{router,ACTION_POP,ACTION_PUSH,ACTION_REPLACE,ACTION_RESET}from'@virtuous/conductor';import Route from'@virtuous/conductor/Route';import{HISTORY_RESET_TO}from'@shopgate/pwa-common/constants/ActionTypes';import{logger}from'@shopgate/pwa-core';import{IS_PAGE_PREVIEW_ACTIVE}from'@shopgate/engage/page/constants';import addCouponsToCart from'@shopgate/pwa-common-commerce/cart/actions/addCouponsToCart';import{getCurrentRoute,getRouterStackIndex}from"../selectors/router";import{LoadingProvider}from"../providers";import{redirects}from"../collections";import{navigate}from"../action-creators";import{historyRedirect,historyPush,windowOpenOverride}from"../actions/router";import*as handler from"./helpers/handleLinks";import{navigate$,userDidLogin$,appWillStart$,windowOpenOverride$}from"../streams";import{isUserLoggedIn}from"../selectors/user";import{getIsConnected}from"../selectors/client";import{INDEX_PATH}from"../constants/RoutePaths";import appConfig from"../helpers/config";import authRoutes from"../collections/AuthRoutes";import ToastProvider from"../providers/toast";/**
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 queryString from 'query-string';
6
+ import { router, ACTION_POP, ACTION_PUSH, ACTION_REPLACE, ACTION_RESET } from '@virtuous/conductor';
7
+ import Route from '@virtuous/conductor/Route';
8
+ import { HISTORY_RESET_TO } from '@shopgate/pwa-common/constants/ActionTypes';
9
+ import { logger } from '@shopgate/pwa-core';
10
+ import { IS_PAGE_PREVIEW_ACTIVE } from '@shopgate/engage/page/constants';
11
+ import addCouponsToCart from '@shopgate/pwa-common-commerce/cart/actions/addCouponsToCart';
12
+ import { getCurrentRoute, getRouterStackIndex } from "../selectors/router";
13
+ import { LoadingProvider } from "../providers";
14
+ import { redirects } from "../collections";
15
+ import { navigate } from "../action-creators";
16
+ import { historyRedirect, historyPush, windowOpenOverride } from "../actions/router";
17
+ import * as handler from "./helpers/handleLinks";
18
+ import { navigate$, userDidLogin$, appWillStart$, windowOpenOverride$ } from "../streams";
19
+ import { isUserLoggedIn } from "../selectors/user";
20
+ import { getIsConnected } from "../selectors/client";
21
+ import { INDEX_PATH } from "../constants/RoutePaths";
22
+ import appConfig from "../helpers/config";
23
+ import authRoutes from "../collections/AuthRoutes";
24
+ import ToastProvider from "../providers/toast";
25
+
26
+ /**
2
27
  * Router subscriptions.
3
28
  * @param {Function} subscribe The subscribe function.
4
- */export default function routerSubscriptions(subscribe){subscribe(navigate$,/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(params){var _parsed$query;var action,dispatch,getState,events,showConnectivityError,_action$params,silent,steps,resetToPathname,historyAction,routeState,location,state,historyLength,historyEmpty,_ref2,currentPathname,protector,_ref3,redirect,matcher,pathParams,queryParams,_getCurrentRoute2,pathname,pattern,_ref5,transform,route,parsedLocation,parsedRedirect,stringifiedQuery,finalRedirect,parsed,hasBase,u,_ref7,_pathname,search;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(!IS_PAGE_PREVIEW_ACTIVE){_context.next=2;break;}return _context.abrupt("return");case 2:action=params.action,dispatch=params.dispatch,getState=params.getState,events=params.events;/**
29
+ */
30
+ export default function routerSubscriptions(subscribe) {
31
+ subscribe(navigate$, async params => {
32
+ if (IS_PAGE_PREVIEW_ACTIVE) {
33
+ // No navigation is allowed in page preview mode.
34
+ return;
35
+ }
36
+ const {
37
+ action,
38
+ dispatch,
39
+ getState,
40
+ events
41
+ } = params;
42
+
43
+ /**
5
44
  * Triggers a connectivity error toast message
6
- */showConnectivityError=function showConnectivityError(){events.emit(ToastProvider.ADD,{id:'navigate.error',message:'error.general'});};_action$params=action.params,silent=_action$params.silent,steps=_action$params.steps,resetToPathname=_action$params.pathname,historyAction=_action$params.action,routeState=_action$params.state;location=action.params.pathname;state=getState();historyLength=getRouterStackIndex(state)+1;historyEmpty=historyLength===1;_ref2=getCurrentRoute(state)||{},currentPathname=_ref2.pathname;if(!(historyEmpty&&[ACTION_POP,ACTION_RESET,HISTORY_RESET_TO].includes(historyAction))){_context.next=15;break;}if(!(currentPathname&&currentPathname===INDEX_PATH)){_context.next=13;break;}return _context.abrupt("return");case 13:/**
45
+ */
46
+ const showConnectivityError = () => {
47
+ events.emit(ToastProvider.ADD, {
48
+ id: 'navigate.error',
49
+ message: 'error.general'
50
+ });
51
+ };
52
+ const {
53
+ params: {
54
+ silent,
55
+ steps,
56
+ pathname: resetToPathname,
57
+ action: historyAction,
58
+ state: routeState
59
+ }
60
+ } = action;
61
+ let {
62
+ pathname: location
63
+ } = action.params;
64
+ const state = getState();
65
+ const historyLength = getRouterStackIndex(state) + 1;
66
+ const historyEmpty = historyLength === 1;
67
+ const {
68
+ pathname: currentPathname
69
+ } = getCurrentRoute(state) || {};
70
+ if (historyEmpty && [ACTION_POP, ACTION_RESET, HISTORY_RESET_TO].includes(historyAction)) {
71
+ if (currentPathname && currentPathname === INDEX_PATH) {
72
+ return;
73
+ }
74
+
75
+ /**
7
76
  * Replace the current route with the index, when a history action is supposed to be
8
77
  * dispatched which reduces the router stack, but the route which triggered the action
9
78
  * is the only one within the stack.
10
- */router.replace({pathname:INDEX_PATH});return _context.abrupt("return");case 15:_context.t0=historyAction;_context.next=_context.t0===ACTION_POP?18:_context.t0===ACTION_RESET?20:_context.t0===HISTORY_RESET_TO?22:27;break;case 18:router.pop(_extends({},typeof steps==='number'&&{steps:steps}));return _context.abrupt("return");case 20:/**
11
- * We don't use the native reset function here, since it contains a bug that causes
12
- * a history pop right after the reset. That can cause side effects when the previous
13
- * route briefly renders - same for HISTORY_RESET_TO
14
- */router.pop({steps:steps||historyLength-1});return _context.abrupt("return");case 22:_context.next=24;return router.pop({steps:historyLength-1,state:routeState,emitBefore:false,emitAfter:false});case 24:_context.next=26;return router.replace({pathname:resetToPathname,state:routeState});case 26:return _context.abrupt("return");case 27:return _context.abrupt("break",28);case 28:// Remove trailing slashes from internal links, since they might break the routing mechanism.
15
- // External links are treated as valid, since we don't know about the requirements at the
16
- // 3rd party server (e.g. google maps links might require trailing slashes).
17
- if(location&&!handler.isExternalLink(location)){location=handler.sanitizeLink(location);}// Stop further processing if the location is empty.
18
- if(location){_context.next=31;break;}return _context.abrupt("return");case 31:if(!(historyAction===ACTION_PUSH&&location===currentPathname)){_context.next=33;break;}return _context.abrupt("return");case 33:if(getIsConnected(state)){_context.next=36;break;}showConnectivityError();return _context.abrupt("return");case 36:if(isUserLoggedIn(state)){_context.next=41;break;}// Determine whether or not this location is protected.
19
- protector=authRoutes.getProtector(location);// If protected then navigate to the protector instead.
20
- if(!protector){_context.next=41;break;}dispatch(navigate({action:historyAction,pathname:protector,state:{redirect:{location:location,state:routeState}}}));return _context.abrupt("return");case 41:/* eslint-disable prefer-const */ // Check for a redirect and change location if one is found.
21
- _ref3=redirects.getRedirectExtended(location)||{},redirect=_ref3.handler,matcher=_ref3.matcher,pathParams=_ref3.pathParams,queryParams=_ref3.queryParams;/* eslint-enable prefer-const */if(!redirect){_context.next=67;break;}if(!(typeof redirect==='function'||redirect instanceof Promise)){_context.next=62;break;}_getCurrentRoute2=getCurrentRoute(state),pathname=_getCurrentRoute2.pathname;LoadingProvider.setLoading(pathname);pattern=router.findPattern(location.split('?')[0]);_ref5=router.patterns[pattern]||{},transform=_ref5.transform;route=new Route({pathname:location,pattern:pattern,state:routeState,transform:transform});_context.prev=49;_context.next=52;return redirect(_extends({},params,{action:_extends({},params.action,{params:_extends({},params.action.params,{// Merge the sanitized location into the redirect handler payload.
22
- pathname:location}),route:route,redirectMeta:{location:location,matcher:matcher,pathParams:pathParams,queryParams:queryParams}})}));case 52:redirect=_context.sent;_context.next=59;break;case 55:_context.prev=55;_context.t1=_context["catch"](49);redirect=null;logger.error(_context.t1);case 59:LoadingProvider.unsetLoading(pathname);if(redirect){_context.next=62;break;}return _context.abrupt("return");case 62:// Add query parameters from the original location to the redirect
23
- parsedLocation=queryString.parseUrl(location);parsedRedirect=queryString.parseUrl(redirect);stringifiedQuery=queryString.stringify(_extends({},parsedLocation.query,{},parsedRedirect.query));finalRedirect=stringifiedQuery?"".concat(parsedRedirect.url,"?").concat(stringifiedQuery):parsedRedirect.url;location=finalRedirect;case 67:parsed=queryString.parseUrl(location);if(parsed.url){_context.next=71;break;}// The URL is not valid - show a toast message
24
- showConnectivityError();return _context.abrupt("return");case 71:if(parsed===null||parsed===void 0?void 0:(_parsed$query=parsed.query)===null||_parsed$query===void 0?void 0:_parsed$query.coupon){hasBase=location.startsWith('http://')||location.startsWith('https://');// Remove the coupon query parameter from internal URLs and redeem the coupon.
25
- if(!hasBase){dispatch(addCouponsToCart([parsed.query.coupon],false));u=new URL(location,hasBase?undefined:'http://example.com');u.searchParams["delete"]('coupon');location=hasBase?u.toString():u.pathname+u.search+u.hash;}}// Override the location if is Shop link is found.
26
- if(handler.isShopLink(location)){_ref7=new URL(location),_pathname=_ref7.pathname,search=_ref7.search;location="".concat(_pathname).concat(search);}// If there is one of the known protocols in the url.
27
- if(!(location&&handler.hasKnownProtocols(location))){_context.next=76;break;}if(handler.isExternalLink(location)){handler.openExternalLink(location,historyAction,state,routeState);}else if(handler.isNativeLink(location)){handler.openNativeLink(location);}return _context.abrupt("return");case 76:if(!(location&&handler.isLegacyPage(location))){_context.next=79;break;}handler.openLegacy(location,historyAction,state);return _context.abrupt("return");case 79:if(!(location&&handler.isLegacyLink(location))){_context.next=82;break;}handler.openLegacyLink(location,historyAction,state);return _context.abrupt("return");case 82:_context.t2=historyAction;_context.next=_context.t2===ACTION_PUSH?85:_context.t2===ACTION_REPLACE?87:89;break;case 85:router.push({pathname:location,state:routeState,emitBefore:silent,emitAfter:silent});return _context.abrupt("break",90);case 87:router.replace({pathname:location,state:routeState,emitBefore:silent,emitAfter:silent});return _context.abrupt("break",90);case 89:return _context.abrupt("break",90);case 90:case"end":return _context.stop();}},_callee,null,[[49,55]]);}));return function(_x){return _ref.apply(this,arguments);};}());/**
79
+ */
80
+ router.replace({
81
+ pathname: INDEX_PATH
82
+ });
83
+ return;
84
+ }
85
+ switch (historyAction) {
86
+ case ACTION_POP:
87
+ {
88
+ router.pop({
89
+ ...(typeof steps === 'number' && {
90
+ steps
91
+ })
92
+ });
93
+ return;
94
+ }
95
+ case ACTION_RESET:
96
+ {
97
+ /**
98
+ * We don't use the native reset function here, since it contains a bug that causes
99
+ * a history pop right after the reset. That can cause side effects when the previous
100
+ * route briefly renders - same for HISTORY_RESET_TO
101
+ */
102
+ router.pop({
103
+ steps: steps || historyLength - 1
104
+ });
105
+ return;
106
+ }
107
+ case HISTORY_RESET_TO:
108
+ {
109
+ await router.pop({
110
+ steps: historyLength - 1,
111
+ state: routeState,
112
+ emitBefore: false,
113
+ emitAfter: false
114
+ });
115
+ await router.replace({
116
+ pathname: resetToPathname,
117
+ state: routeState
118
+ });
119
+ return;
120
+ }
121
+ default:
122
+ break;
123
+ }
124
+
125
+ // Remove trailing slashes from internal links, since they might break the routing mechanism.
126
+ // External links are treated as valid, since we don't know about the requirements at the
127
+ // 3rd party server (e.g. google maps links might require trailing slashes).
128
+ if (location && !handler.isExternalLink(location)) {
129
+ location = handler.sanitizeLink(location);
130
+ }
131
+
132
+ // Stop further processing if the location is empty.
133
+ if (!location) {
134
+ return;
135
+ }
136
+
137
+ // Prevent the current route from being pushed again.
138
+ if (historyAction === ACTION_PUSH && location === currentPathname) {
139
+ return;
140
+ }
141
+
142
+ // Abort navigation when the internet connection got lost.
143
+ if (!getIsConnected(state)) {
144
+ showConnectivityError();
145
+ return;
146
+ }
147
+
148
+ // Route authentication.
149
+ if (!isUserLoggedIn(state)) {
150
+ // Determine whether or not this location is protected.
151
+ const protector = authRoutes.getProtector(location);
152
+
153
+ // If protected then navigate to the protector instead.
154
+ if (protector) {
155
+ dispatch(navigate({
156
+ action: historyAction,
157
+ pathname: protector,
158
+ state: {
159
+ redirect: {
160
+ location,
161
+ state: routeState
162
+ }
163
+ }
164
+ }));
165
+ return;
166
+ }
167
+ }
168
+
169
+ /* eslint-disable prefer-const */
170
+ // Check for a redirect and change location if one is found.
171
+ let {
172
+ handler: redirect,
173
+ matcher,
174
+ pathParams,
175
+ queryParams
176
+ } = redirects.getRedirectExtended(location) || {};
177
+ /* eslint-enable prefer-const */
178
+
179
+ if (redirect) {
180
+ if (typeof redirect === 'function' || redirect instanceof Promise) {
181
+ const {
182
+ pathname
183
+ } = getCurrentRoute(state);
184
+ LoadingProvider.setLoading(pathname);
185
+ const pattern = router.findPattern(location.split('?')[0]);
186
+ const {
187
+ transform
188
+ } = router.patterns[pattern] || {};
189
+ const route = new Route({
190
+ pathname: location,
191
+ pattern,
192
+ state: routeState,
193
+ transform
194
+ });
195
+ try {
196
+ redirect = await redirect({
197
+ ...params,
198
+ action: {
199
+ ...params.action,
200
+ params: {
201
+ ...params.action.params,
202
+ // Merge the sanitized location into the redirect handler payload.
203
+ pathname: location
204
+ },
205
+ route,
206
+ redirectMeta: {
207
+ location,
208
+ matcher,
209
+ pathParams,
210
+ queryParams
211
+ }
212
+ }
213
+ });
214
+ } catch (e) {
215
+ redirect = null;
216
+ logger.error(e);
217
+ }
218
+ LoadingProvider.unsetLoading(pathname);
219
+ if (!redirect) {
220
+ return;
221
+ }
222
+ }
223
+
224
+ // Add query parameters from the original location to the redirect
225
+ const parsedLocation = queryString.parseUrl(location);
226
+ const parsedRedirect = queryString.parseUrl(redirect);
227
+ const stringifiedQuery = queryString.stringify({
228
+ ...parsedLocation.query,
229
+ ...parsedRedirect.query
230
+ });
231
+ const finalRedirect = stringifiedQuery ? `${parsedRedirect.url}?${stringifiedQuery}` : parsedRedirect.url;
232
+ location = finalRedirect;
233
+ }
234
+ const parsed = queryString.parseUrl(location);
235
+ if (!parsed.url) {
236
+ // The URL is not valid - show a toast message
237
+ showConnectivityError();
238
+ return;
239
+ }
240
+ if (parsed?.query?.coupon) {
241
+ const hasBase = location.startsWith('http://') || location.startsWith('https://');
242
+
243
+ // Remove the coupon query parameter from internal URLs and redeem the coupon.
244
+ if (!hasBase) {
245
+ dispatch(addCouponsToCart([parsed.query.coupon], false));
246
+ const u = new URL(location, hasBase ? undefined : 'http://example.com');
247
+ u.searchParams.delete('coupon');
248
+ location = hasBase ? u.toString() : u.pathname + u.search + u.hash;
249
+ }
250
+ }
251
+
252
+ // Override the location if is Shop link is found.
253
+ if (handler.isShopLink(location)) {
254
+ const {
255
+ pathname,
256
+ search
257
+ } = new URL(location);
258
+ location = `${pathname}${search}`;
259
+ }
260
+
261
+ // If there is one of the known protocols in the url.
262
+ if (location && handler.hasKnownProtocols(location)) {
263
+ if (handler.isExternalLink(location)) {
264
+ handler.openExternalLink(location, historyAction, state, routeState);
265
+ } else if (handler.isNativeLink(location)) {
266
+ handler.openNativeLink(location);
267
+ }
268
+ return;
269
+ }
270
+ if (location && handler.isLegacyPage(location)) {
271
+ handler.openLegacy(location, historyAction, state);
272
+ return;
273
+ }
274
+ if (location && handler.isLegacyLink(location)) {
275
+ handler.openLegacyLink(location, historyAction, state);
276
+ return;
277
+ }
278
+ switch (historyAction) {
279
+ case ACTION_PUSH:
280
+ {
281
+ router.push({
282
+ pathname: location,
283
+ state: routeState,
284
+ emitBefore: silent,
285
+ emitAfter: silent
286
+ });
287
+ break;
288
+ }
289
+ case ACTION_REPLACE:
290
+ {
291
+ router.replace({
292
+ pathname: location,
293
+ state: routeState,
294
+ emitBefore: silent,
295
+ emitAfter: silent
296
+ });
297
+ break;
298
+ }
299
+ default:
300
+ break;
301
+ }
302
+ });
303
+
304
+ /**
28
305
  * Added a 100ms delay here to allow the Redux action to complete.
29
306
  * Without it the store would show that the user is still not
30
307
  * logged in during the upcoming navigate() action.
31
- */var redirectUser$=userDidLogin$.delay(100);subscribe(redirectUser$,function(_ref8){var action=_ref8.action,dispatch=_ref8.dispatch;if(appConfig.webCheckoutShopify===null){dispatch(historyRedirect(action.redirect));}});subscribe(appWillStart$,function(_ref9){var dispatch=_ref9.dispatch;var windowOpenOriginal=window.open;/**
308
+ */
309
+ const redirectUser$ = userDidLogin$.delay(100);
310
+ subscribe(redirectUser$, ({
311
+ action,
312
+ dispatch
313
+ }) => {
314
+ if (appConfig.webCheckoutShopify === null) {
315
+ dispatch(historyRedirect(action.redirect));
316
+ }
317
+ });
318
+ subscribe(appWillStart$, ({
319
+ dispatch
320
+ }) => {
321
+ const windowOpenOriginal = window.open;
322
+ /**
32
323
  * Override for the window.open method which is usually used by external SDKs to open URLs.
33
324
  * Calls of this method would usually replace the PWA with the passed url. The override ensures
34
325
  * that the URL is passed through the router system which implements logic for various URL
@@ -43,4 +334,26 @@ if(!(location&&handler.hasKnownProtocols(location))){_context.next=76;break;}if(
43
334
  * @param {boolean} [isInternal=false] Whether the method is called by internal logic. This will
44
335
  * invoke the original window.open with the method parameters.
45
336
  * @returns {null}
46
- */window.open=function(){var url=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';var target=arguments.length>1?arguments[1]:undefined;var windowFeatures=arguments.length>2?arguments[2]:undefined;var isInternal=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;if(!isInternal){dispatch(windowOpenOverride({pathname:url}));}else{windowOpenOriginal(url,target,windowFeatures);}return null;};});subscribe(windowOpenOverride$,function(_ref10){var action=_ref10.action,dispatch=_ref10.dispatch;if(action.pathname){dispatch(historyPush({pathname:action.pathname}));}});}
337
+ */
338
+ window.open = (url = '', target, windowFeatures, isInternal = false) => {
339
+ if (!isInternal) {
340
+ dispatch(windowOpenOverride({
341
+ pathname: url
342
+ }));
343
+ } else {
344
+ windowOpenOriginal(url, target, windowFeatures);
345
+ }
346
+ return null;
347
+ };
348
+ });
349
+ subscribe(windowOpenOverride$, ({
350
+ action,
351
+ dispatch
352
+ }) => {
353
+ if (action.pathname) {
354
+ dispatch(historyPush({
355
+ pathname: action.pathname
356
+ }));
357
+ }
358
+ });
359
+ }
@@ -1,6 +1,96 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import event from'@shopgate/pwa-core/classes/Event';import registerEvents from'@shopgate/pwa-core/commands/registerEvents';import appConfig from"../helpers/config";import{LoadingProvider}from"../providers";import{fetchUser}from"../actions/user";import{successLogin}from"../action-creators";import{historyPush}from"../actions/router";import logout from"../actions/user/logout";import{appDidStart$,userWillLogin$,userLoginResponse$,userDidLogin$,userDidLogout$,userDidInitialize$,legacyConnectRegisterDidFail$,userSessionExpired$}from"../streams";import showModal from"../actions/modal/showModal";import{LOGIN_PATH}from"../constants/RoutePaths";import{LEGACY_URL_CONNECT_REGISTER}from"../constants/Registration";import{EVENT_USER_INITIALIZED}from"../constants/user";/**
1
+ import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
2
+ import event from '@shopgate/pwa-core/classes/Event';
3
+ import registerEvents from '@shopgate/pwa-core/commands/registerEvents';
4
+ import appConfig from "../helpers/config";
5
+ import { LoadingProvider } from "../providers";
6
+ import { fetchUser } from "../actions/user";
7
+ import { successLogin } from "../action-creators";
8
+ import { historyPush } from "../actions/router";
9
+ import logout from "../actions/user/logout";
10
+ import { appDidStart$, userWillLogin$, userLoginResponse$, userDidLogin$, userDidLogout$, userDidInitialize$, legacyConnectRegisterDidFail$, userSessionExpired$ } from "../streams";
11
+ import showModal from "../actions/modal/showModal";
12
+ import { LOGIN_PATH } from "../constants/RoutePaths";
13
+ import { LEGACY_URL_CONNECT_REGISTER } from "../constants/Registration";
14
+ import { EVENT_USER_INITIALIZED } from "../constants/user";
15
+
16
+ /**
2
17
  * User subscriptions.
3
18
  * @param {Function} subscribe The subscribe function.
4
- */export default function user(subscribe){/**
19
+ */
20
+ export default function user(subscribe) {
21
+ /**
5
22
  * Gets triggered when ever the user data need to be updated.
6
- */var userNeedsUpdate$=appDidStart$.merge(userDidLogin$);subscribe(userDidInitialize$,function(_ref){var events=_ref.events;events.emit(EVENT_USER_INITIALIZED);});subscribe(userWillLogin$,function(){LoadingProvider.setLoading(LOGIN_PATH);});subscribe(userLoginResponse$,function(){LoadingProvider.unsetLoading(LOGIN_PATH);});subscribe(userNeedsUpdate$,function(_ref2){var dispatch=_ref2.dispatch;dispatch(fetchUser());});subscribe(userDidLogout$,/*#__PURE__*/function(){var _ref4=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref3){var dispatch,action,isAutoLogout,confirmed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch=_ref3.dispatch,action=_ref3.action;if(!(action.notify===false)){_context.next=3;break;}return _context.abrupt("return");case 3:isAutoLogout=action.autoLogout;if(!(isAutoLogout&&(appConfig===null||appConfig===void 0?void 0:appConfig.disableAutoLogoutModal)===true)){_context.next=6;break;}return _context.abrupt("return");case 6:_context.next=8;return dispatch(showModal(_extends({confirm:'modal.ok',dismiss:null,message:'login.logout_message',title:null},isAutoLogout?{message:'login.auto_logout_message',confirm:'modal.login',dismiss:'modal.close'}:null)));case 8:confirmed=_context.sent;if(isAutoLogout&&confirmed){dispatch(historyPush({pathname:LOGIN_PATH}));}case 10:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref4.apply(this,arguments);};}());subscribe(appDidStart$,function(_ref5){var dispatch=_ref5.dispatch,getState=_ref5.getState;registerEvents(['userLoggedIn']);event.addCallback('userLoggedIn',function(){var _getCurrentRoute=getCurrentRoute(getState()),_getCurrentRoute$stat=_getCurrentRoute.state,_getCurrentRoute$stat2=_getCurrentRoute$stat===void 0?{}:_getCurrentRoute$stat,redirect=_getCurrentRoute$stat2.redirect;dispatch(successLogin(redirect));});});subscribe(legacyConnectRegisterDidFail$,function(_ref6){var dispatch=_ref6.dispatch;dispatch(historyPush({pathname:LEGACY_URL_CONNECT_REGISTER}));});subscribe(userSessionExpired$,function(_ref7){var dispatch=_ref7.dispatch;dispatch(logout(undefined,true));});}
23
+ */
24
+ const userNeedsUpdate$ = appDidStart$.merge(userDidLogin$);
25
+ subscribe(userDidInitialize$, ({
26
+ events
27
+ }) => {
28
+ events.emit(EVENT_USER_INITIALIZED);
29
+ });
30
+ subscribe(userWillLogin$, () => {
31
+ LoadingProvider.setLoading(LOGIN_PATH);
32
+ });
33
+ subscribe(userLoginResponse$, () => {
34
+ LoadingProvider.unsetLoading(LOGIN_PATH);
35
+ });
36
+ subscribe(userNeedsUpdate$, ({
37
+ dispatch
38
+ }) => {
39
+ dispatch(fetchUser());
40
+ });
41
+ subscribe(userDidLogout$, async ({
42
+ dispatch,
43
+ action
44
+ }) => {
45
+ if (action.notify === false) {
46
+ return;
47
+ }
48
+ const isAutoLogout = action.autoLogout;
49
+ if (isAutoLogout && appConfig?.disableAutoLogoutModal === true) {
50
+ // Prevent showing auto logout modal when turned off
51
+ return;
52
+ }
53
+ const confirmed = await dispatch(showModal({
54
+ confirm: 'modal.ok',
55
+ dismiss: null,
56
+ message: 'login.logout_message',
57
+ title: null,
58
+ ...(isAutoLogout ? {
59
+ message: 'login.auto_logout_message',
60
+ confirm: 'modal.login',
61
+ dismiss: 'modal.close'
62
+ } : null)
63
+ }));
64
+ if (isAutoLogout && confirmed) {
65
+ dispatch(historyPush({
66
+ pathname: LOGIN_PATH
67
+ }));
68
+ }
69
+ });
70
+ subscribe(appDidStart$, ({
71
+ dispatch,
72
+ getState
73
+ }) => {
74
+ registerEvents(['userLoggedIn']);
75
+ event.addCallback('userLoggedIn', () => {
76
+ const {
77
+ state: {
78
+ redirect
79
+ } = {}
80
+ } = getCurrentRoute(getState());
81
+ dispatch(successLogin(redirect));
82
+ });
83
+ });
84
+ subscribe(legacyConnectRegisterDidFail$, ({
85
+ dispatch
86
+ }) => {
87
+ dispatch(historyPush({
88
+ pathname: LEGACY_URL_CONNECT_REGISTER
89
+ }));
90
+ });
91
+ subscribe(userSessionExpired$, ({
92
+ dispatch
93
+ }) => {
94
+ dispatch(logout(undefined, true));
95
+ });
96
+ }