@shopgate/pwa-common 7.30.0-alpha.7 → 7.30.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +48 -6
- package/action-creators/app/index.js +75 -12
- package/action-creators/app/spec.js +96 -1
- package/action-creators/client/index.js +27 -5
- package/action-creators/client/spec.js +44 -1
- package/action-creators/error/index.js +15 -3
- package/action-creators/index.js +9 -1
- package/action-creators/menu/index.js +23 -4
- package/action-creators/menu/spec.js +37 -1
- package/action-creators/modal/index.js +15 -3
- package/action-creators/modal/spec.js +26 -1
- package/action-creators/page/index.js +24 -4
- package/action-creators/page/spec.js +38 -1
- package/action-creators/router/index.js +48 -7
- package/action-creators/url/index.js +24 -4
- package/action-creators/url/spec.js +45 -1
- package/action-creators/user/index.js +90 -13
- package/action-creators/user/spec.js +186 -2
- package/actions/app/handleDeepLink.js +11 -2
- package/actions/app/handleLink.js +62 -6
- package/actions/app/handlePushNotification.js +32 -4
- package/actions/app/handleUniversalLink.js +11 -2
- package/actions/app/registerLinkEvents.js +24 -3
- package/actions/client/fetchClientInformation.js +26 -2
- package/actions/menu/fetchMenu.js +23 -2
- package/actions/modal/closeModal.js +18 -2
- package/actions/modal/promiseMap.js +3 -1
- package/actions/modal/showModal.js +54 -8
- package/actions/page/fetchPageConfig.js +69 -2
- package/actions/page/getPageConfig.js +6 -2
- package/actions/page/index.js +1 -1
- package/actions/router/historyPop.js +12 -2
- package/actions/router/historyPopToRoute.js +27 -2
- package/actions/router/historyPush.js +12 -2
- package/actions/router/historyRedirect.js +21 -2
- package/actions/router/historyReplace.js +20 -3
- package/actions/router/historyReset.js +11 -2
- package/actions/router/historyResetTo.js +12 -2
- package/actions/router/index.js +17 -1
- package/actions/router/routeDidPop.js +11 -2
- package/actions/router/routeDidPush.js +13 -2
- package/actions/router/routeDidReplace.js +11 -2
- package/actions/router/routeDidReset.js +11 -2
- package/actions/router/routeDidUpdate.js +10 -2
- package/actions/router/routeWillPop.js +11 -2
- package/actions/router/routeWillPush.js +13 -2
- package/actions/router/routeWillReplace.js +11 -2
- package/actions/router/routeWillReset.js +11 -2
- package/actions/router/windowOpenOverride.js +10 -2
- package/actions/user/fetchRegisterUrl.js +36 -2
- package/actions/user/fetchUser.js +29 -3
- package/actions/user/getUser.js +6 -2
- package/actions/user/index.js +1 -1
- package/actions/user/login.js +76 -9
- package/actions/user/logout.js +30 -2
- package/collections/AuthRoutes.js +73 -14
- package/collections/Configuration.js +54 -7
- package/collections/EmbeddedMedia.js +84 -11
- package/collections/PersistedReducers.js +41 -6
- package/collections/Redirects.js +103 -17
- package/collections/index.js +5 -1
- package/collections/media-providers/MediaProvider.js +151 -26
- package/collections/media-providers/Vimeo.js +113 -19
- package/collections/media-providers/YouTube.js +74 -14
- package/collections/media-providers/index.js +3 -1
- package/collections/media-providers/style.js +52 -2
- package/components/Backdrop/index.js +95 -6
- package/components/Backdrop/spec.js +23 -1
- package/components/Backdrop/style.js +11 -2
- package/components/Button/index.js +47 -5
- package/components/Button/spec.js +36 -1
- package/components/Button/style.js +6 -1
- package/components/Checkbox/index.js +126 -32
- package/components/Checkbox/spec.js +94 -3
- package/components/Consume/helpers/buildParams.js +13 -2
- package/components/Consume/index.js +14 -2
- package/components/CountdownTimer/index.js +115 -17
- package/components/CountdownTimer/spec.js +126 -12
- package/components/Drawer/index.js +131 -16
- package/components/Drawer/spec.js +76 -1
- package/components/Drawer/style.js +37 -1
- package/components/Dropdown/index.js +65 -6
- package/components/Dropdown/style.js +4 -1
- package/components/Dropdown/transitions.js +34 -1
- package/components/Ellipsis/index.js +16 -2
- package/components/Ellipsis/spec.js +13 -1
- package/components/EmbeddedMedia/index.js +56 -6
- package/components/EmbeddedMedia/spec.js +52 -3
- package/components/ErrorBoundary/connector.js +9 -2
- package/components/ErrorBoundary/index.js +43 -7
- package/components/Grid/components/Item/index.js +40 -4
- package/components/Grid/components/Item/spec.js +23 -1
- package/components/Grid/components/Item/style.js +17 -3
- package/components/Grid/index.js +36 -4
- package/components/Grid/spec.js +23 -1
- package/components/Grid/style.js +11 -2
- package/components/HtmlSanitizer/connector.js +24 -3
- package/components/HtmlSanitizer/index.js +104 -12
- package/components/HtmlSanitizer/spec.js +207 -6
- package/components/I18n/components/FormatDate/index.js +26 -2
- package/components/I18n/components/FormatDate/spec.js +46 -1
- package/components/I18n/components/FormatNumber/index.js +34 -2
- package/components/I18n/components/FormatNumber/spec.js +41 -2
- package/components/I18n/components/FormatPrice/index.js +32 -2
- package/components/I18n/components/FormatPrice/spec.js +46 -1
- package/components/I18n/components/FormatTime/index.js +26 -2
- package/components/I18n/components/FormatTime/spec.js +43 -2
- package/components/I18n/components/I18nProvider/index.js +52 -9
- package/components/I18n/components/I18nProvider/spec.js +39 -1
- package/components/I18n/components/Placeholder/index.js +8 -2
- package/components/I18n/components/Placeholder/spec.js +30 -1
- package/components/I18n/components/Translate/index.js +68 -7
- package/components/I18n/components/Translate/spec.js +30 -1
- package/components/I18n/index.js +16 -1
- package/components/Icon/index.js +25 -2
- package/components/Icon/style.js +6 -1
- package/components/Image/Image.js +176 -19
- package/components/Image/ImageInner.js +48 -2
- package/components/Image/index.js +1 -1
- package/components/Image/style.js +29 -2
- package/components/InfiniteContainer/index.js +381 -49
- package/components/InfiniteContainer/spec.js +199 -10
- package/components/Input/components/DateInput.js +262 -6
- package/components/Input/components/MultiLineInput.js +98 -12
- package/components/Input/components/SimpleInput.js +207 -31
- package/components/Input/index.js +32 -3
- package/components/Input/spec.js +122 -1
- package/components/KeyboardConsumer/index.js +48 -7
- package/components/Link/connector.js +7 -1
- package/components/Link/index.js +96 -11
- package/components/Link/spec.js +56 -1
- package/components/Link/style.js +10 -1
- package/components/List/components/Item/index.js +35 -3
- package/components/List/components/Item/style.js +16 -1
- package/components/List/index.js +20 -2
- package/components/List/spec.js +31 -1
- package/components/Loading/index.js +6 -2
- package/components/Modal/index.js +38 -3
- package/components/Modal/style.js +36 -1
- package/components/ModalContainer/connector.js +17 -3
- package/components/ModalContainer/index.js +36 -3
- package/components/ModalContainer/spec.js +105 -5
- package/components/Picker/components/Button/index.js +34 -2
- package/components/Picker/components/Button/style.js +19 -1
- package/components/Picker/components/List/index.js +33 -2
- package/components/Picker/components/List/style.js +17 -1
- package/components/Picker/components/Modal/index.js +60 -7
- package/components/Picker/components/Modal/style.js +78 -1
- package/components/Picker/index.js +167 -21
- package/components/Picker/spec.js +83 -2
- package/components/Portal/index.js +130 -19
- package/components/ProductCharacteristics/connector.js +33 -4
- package/components/ProductCharacteristics/context.js +2 -1
- package/components/ProductCharacteristics/helpers/index.js +135 -21
- package/components/ProductCharacteristics/index.js +266 -31
- package/components/RangeSlider/components/Handle/index.js +25 -2
- package/components/RangeSlider/components/Handle/style.js +14 -1
- package/components/RangeSlider/helper.js +43 -8
- package/components/RangeSlider/index.js +228 -38
- package/components/RangeSlider/style.js +14 -1
- package/components/Route/RouteNotFound.js +46 -3
- package/components/Route/index.js +78 -10
- package/components/Router/connector.js +9 -2
- package/components/Router/index.js +237 -31
- package/components/ScannerContainer/connector.js +9 -2
- package/components/ScannerContainer/index.js +42 -6
- package/components/Select/components/Item/index.js +20 -4
- package/components/Select/components/Item/style.js +4 -1
- package/components/Select/index.js +149 -28
- package/components/Select/spec.js +86 -2
- package/components/Select/style.js +17 -1
- package/components/SelectBox/components/Item/index.js +47 -5
- package/components/SelectBox/components/Item/style.js +7 -1
- package/components/SelectBox/index.js +173 -17
- package/components/SelectBox/spec.js +59 -3
- package/components/SelectBox/style.js +18 -1
- package/components/Slider/index.js +6 -2
- package/components/SurroundPortals/index.js +26 -2
- package/components/Swiper/components/SwiperItem/index.js +28 -4
- package/components/Swiper/components/SwiperItem/spec.js +17 -1
- package/components/Swiper/components/SwiperItem/styles.js +5 -1
- package/components/Swiper/index.js +210 -18
- package/components/Swiper/styles.js +75 -7
- package/components/Toaster/index.js +10 -2
- package/components/Transition/index.js +89 -13
- package/components/Widgets/components/Widget/index.js +52 -4
- package/components/Widgets/components/Widget/spec.js +68 -3
- package/components/Widgets/components/Widget/style.js +21 -3
- package/components/Widgets/components/WidgetGrid/index.js +52 -7
- package/components/Widgets/components/WidgetGrid/spec.js +46 -2
- package/components/Widgets/components/WidgetGrid/style.js +8 -1
- package/components/Widgets/helpers/shouldShowWidget.js +44 -7
- package/components/Widgets/index.js +127 -15
- package/components/Widgets/spec.js +213 -6
- package/components/index.js +9 -1
- package/constants/ActionTypes.js +97 -19
- package/constants/Configuration.js +12 -2
- package/constants/Device.js +29 -2
- package/constants/DisplayOptions.js +8 -1
- package/constants/MenuIDs.js +2 -1
- package/constants/ModalTypes.js +1 -1
- package/constants/PageIDs.js +1 -1
- package/constants/Pipelines.js +7 -1
- package/constants/Portals.js +136 -3
- package/constants/Registration.js +3 -1
- package/constants/RoutePaths.js +13 -2
- package/constants/Tracking.js +3 -1
- package/constants/client.js +6 -1
- package/constants/ui.js +2 -1
- package/constants/user.js +6 -2
- package/context/index.js +33 -3
- package/helpers/config/index.js +139 -21
- package/helpers/config/mock.js +200 -8
- package/helpers/config/theme.js +50 -4
- package/helpers/data/index.js +204 -29
- package/helpers/data/spec.js +187 -7
- package/helpers/date/index.js +58 -6
- package/helpers/date/spec.js +92 -1
- package/helpers/dom/index.js +48 -11
- package/helpers/environment/index.js +14 -2
- package/helpers/html/decodeHTML.js +7 -1
- package/helpers/html/handleDOM.js +172 -21
- package/helpers/html/parseHTML.js +67 -12
- package/helpers/i18n/getDateFormatter.js +23 -4
- package/helpers/i18n/getNumberFormatter.js +32 -4
- package/helpers/i18n/getPriceFormatter.js +38 -4
- package/helpers/i18n/getTimeFormatter.js +23 -4
- package/helpers/i18n/getTranslator.js +62 -8
- package/helpers/i18n/index.js +5 -1
- package/helpers/i18n/mergeTranslations.js +36 -9
- package/helpers/i18n/messageCache.js +3 -1
- package/helpers/legacy/index.js +47 -9
- package/helpers/modal/withShowModal.js +13 -2
- package/helpers/portals/portalCollection.js +28 -6
- package/helpers/portals/routePortals.js +12 -1
- package/helpers/redux/compareObjects.js +7 -2
- package/helpers/redux/generateResultHash.js +36 -3
- package/helpers/redux/generateSortedHash.js +7 -2
- package/helpers/redux/hasExpired.js +10 -2
- package/helpers/redux/index.js +7 -1
- package/helpers/redux/mutable.js +143 -24
- package/helpers/redux/shouldFetchData.js +46 -10
- package/helpers/redux/shouldFetchFilters.js +17 -4
- package/helpers/router/index.js +49 -5
- package/helpers/style/index.js +43 -4
- package/helpers/style/spec.js +108 -2
- package/helpers/tracking/index.js +52 -9
- package/helpers/validation/index.js +39 -12
- package/helpers/validation/spec.js +10 -1
- package/package.json +3 -3
- package/providers/index.js +4 -1
- package/providers/loading/context.js +2 -1
- package/providers/loading/index.js +137 -22
- package/providers/toast/context.js +2 -1
- package/providers/toast/index.js +105 -11
- package/reducers/client/connectivity.js +22 -2
- package/reducers/client/index.js +7 -1
- package/reducers/client/info.js +27 -2
- package/reducers/index.js +23 -4
- package/reducers/menu/index.js +5 -1
- package/reducers/menu/menusById.js +41 -2
- package/reducers/modal/index.js +14 -2
- package/reducers/page/index.js +68 -5
- package/reducers/router/index.js +48 -2
- package/reducers/url/index.js +42 -3
- package/reducers/user/data.js +27 -2
- package/reducers/user/index.js +7 -1
- package/reducers/user/login.js +65 -2
- package/selectors/client.js +138 -21
- package/selectors/history.js +49 -11
- package/selectors/menu.js +34 -6
- package/selectors/modal.js +15 -4
- package/selectors/page.js +25 -4
- package/selectors/router.js +154 -30
- package/selectors/url.js +25 -4
- package/selectors/user.js +90 -13
- package/store/index.js +60 -6
- package/store/middelwares/logger.js +7 -1
- package/store/middelwares/streams.js +19 -2
- package/streams/app.js +60 -8
- package/streams/client.js +8 -2
- package/streams/error.js +14 -3
- package/streams/index.js +6 -1
- package/streams/interval.js +6 -2
- package/streams/main.js +27 -2
- package/streams/router.js +45 -8
- package/streams/user.js +89 -15
- package/streams/view.js +97 -25
- package/styles/reset/form.js +57 -5
- package/styles/reset/index.js +6 -1
- package/styles/reset/media.js +22 -1
- package/styles/reset/root.js +33 -1
- package/styles/reset/table.js +10 -1
- package/styles/reset/typography.js +26 -1
- package/subscriptions/app.js +148 -17
- package/subscriptions/error.js +292 -13
- package/subscriptions/helpers/buildRegisterUrl.js +25 -6
- package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
- package/subscriptions/helpers/handleLinks.js +267 -25
- package/subscriptions/helpers/pipeline.js +12 -1
- package/subscriptions/history.js +34 -6
- package/subscriptions/index.js +25 -4
- package/subscriptions/menu.js +22 -5
- package/subscriptions/mock.js +39 -7
- package/subscriptions/router.js +336 -23
- package/subscriptions/user.js +93 -3
package/subscriptions/router.js
CHANGED
|
@@ -1,34 +1,325 @@
|
|
|
1
|
-
import
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
+
}
|
package/subscriptions/user.js
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
|
-
import
|
|
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
|
-
*/
|
|
19
|
+
*/
|
|
20
|
+
export default function user(subscribe) {
|
|
21
|
+
/**
|
|
5
22
|
* Gets triggered when ever the user data need to be updated.
|
|
6
|
-
*/
|
|
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
|
+
}
|