@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
|
@@ -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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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";
|
|
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";
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
128
|
+
*/
|
|
129
|
+
export const disableLogin = value => ({
|
|
130
|
+
type: DISABLE_LOGIN,
|
|
131
|
+
value
|
|
132
|
+
});
|
|
@@ -1,2 +1,186 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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";
|
|
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
|
-
*/
|
|
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
|
|
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
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
*/
|
|
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';
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
11
|
-
|
|
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
|
+
}
|