@shopgate/pwa-common 7.30.1-beta.4 → 7.30.1
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/collections/Redirects.js
CHANGED
|
@@ -10,7 +10,6 @@ let Redirects = /*#__PURE__*/function () {
|
|
|
10
10
|
*/
|
|
11
11
|
function Redirects() {
|
|
12
12
|
this.redirects = new Map();
|
|
13
|
-
this.redirectOptions = new Map();
|
|
14
13
|
this.matcher = pathMatch({
|
|
15
14
|
sensitive: false,
|
|
16
15
|
strict: false,
|
|
@@ -100,11 +99,6 @@ let Redirects = /*#__PURE__*/function () {
|
|
|
100
99
|
result.matcher = patternMatch;
|
|
101
100
|
result.pathParams = matcherResult;
|
|
102
101
|
}
|
|
103
|
-
const options = {
|
|
104
|
-
showLoading: true,
|
|
105
|
-
...this.redirectOptions.get(pathname)
|
|
106
|
-
};
|
|
107
|
-
result.options = options;
|
|
108
102
|
return result;
|
|
109
103
|
}
|
|
110
104
|
|
|
@@ -112,31 +106,29 @@ let Redirects = /*#__PURE__*/function () {
|
|
|
112
106
|
* Adds a redirect handler to the collection.
|
|
113
107
|
* @param {string} from The link to redirect from. Route patterns are also supported.
|
|
114
108
|
* @param {string|Function|Promise} to redirect / handle to create a dynamic link.
|
|
115
|
-
* @param {
|
|
109
|
+
* @param {boolean} force Whether or not to forcefully set the redirect.
|
|
116
110
|
*/;
|
|
117
|
-
_proto.set = function set(from = null, to = null,
|
|
111
|
+
_proto.set = function set(from = null, to = null, force = false) {
|
|
118
112
|
if (!from || !to) {
|
|
119
113
|
return;
|
|
120
114
|
}
|
|
121
|
-
|
|
122
|
-
const forceFlag = typeof forceOrOptions === 'boolean' ? forceOrOptions : forceOrOptions?.override;
|
|
123
|
-
if (!forceFlag && this.redirects.has(from)) {
|
|
115
|
+
if (!force && this.redirects.has(from)) {
|
|
124
116
|
return;
|
|
125
117
|
}
|
|
126
118
|
this.redirects.set(from, to);
|
|
127
|
-
if (options) {
|
|
128
|
-
this.redirectOptions.set(from, options);
|
|
129
|
-
}
|
|
130
119
|
}
|
|
131
120
|
|
|
121
|
+
/* eslint-disable extra-rules/potential-point-free */
|
|
122
|
+
|
|
132
123
|
/**
|
|
133
124
|
* Removes a specified element from the internal "redirects" Map object.
|
|
134
125
|
* @param {string} pathname The pathname to remove.
|
|
135
126
|
*/;
|
|
136
127
|
_proto.unset = function unset(pathname) {
|
|
137
128
|
this.redirects.delete(pathname);
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* eslint-enable extra-rules/potential-point-free */;
|
|
140
132
|
return Redirects;
|
|
141
133
|
}();
|
|
142
134
|
export default new Redirects();
|
|
@@ -4,11 +4,13 @@ const ENV_KEY_TEST = 'test';
|
|
|
4
4
|
const ENV_KEY_STAGING = 'staging';
|
|
5
5
|
const ENV_KEY_PRODUCTION = 'production';
|
|
6
6
|
const env = process.env.NODE_ENV || ENV_KEY_DEVELOPMENT;
|
|
7
|
+
const userAgent = window?.navigator?.userAgent ?? '';
|
|
7
8
|
module.exports = {
|
|
8
9
|
env,
|
|
9
10
|
isDev: env === ENV_KEY_DEVELOPMENT || env === ENV_KEY_TEST,
|
|
10
11
|
isProd: env === ENV_KEY_PRODUCTION,
|
|
11
12
|
isStaging: env === ENV_KEY_STAGING,
|
|
12
13
|
isRemote: !!process.env.REMOTE,
|
|
13
|
-
isWindows: (
|
|
14
|
+
isWindows: /win/i.test(userAgent),
|
|
15
|
+
isLinux: /linux/i.test(userAgent) && !/android/i.test(userAgent)
|
|
14
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common",
|
|
3
|
-
"version": "7.30.1
|
|
3
|
+
"version": "7.30.1",
|
|
4
4
|
"description": "Common library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@redux-devtools/extension": "^3.3.0",
|
|
19
19
|
"@sentry/browser": "6.0.1",
|
|
20
|
-
"@shopgate/pwa-benchmark": "7.30.1
|
|
20
|
+
"@shopgate/pwa-benchmark": "7.30.1",
|
|
21
21
|
"@virtuous/conductor": "~2.5.0",
|
|
22
22
|
"@virtuous/react-conductor": "~2.5.0",
|
|
23
23
|
"@virtuous/redux-persister": "1.1.0-beta.7",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"swiper": "12.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@shopgate/pwa-core": "7.30.1
|
|
43
|
+
"@shopgate/pwa-core": "7.30.1",
|
|
44
44
|
"@types/react-portal": "^3.0.9",
|
|
45
45
|
"lodash": "^4.17.23",
|
|
46
46
|
"prop-types": "~15.8.1",
|
package/selectors/client.js
CHANGED
|
@@ -98,62 +98,24 @@ export const getDeviceModel = createSelector(getDeviceInformation, deviceInforma
|
|
|
98
98
|
return model;
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
/**
|
|
102
|
-
* Selector to check if the PWA is currently running inside the Android app.
|
|
103
|
-
* Unlike the `getIsAndroid` selector, this selector will return false if the PWA
|
|
104
|
-
* is running in a web browser on an Android device.
|
|
105
|
-
* @param {Object} state The application state.
|
|
106
|
-
* @return {boolean}
|
|
107
|
-
*/
|
|
108
|
-
export const getIsAndroidApp = createSelector(getPlatform, platform => {
|
|
109
|
-
if (hasWebBridge()) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
return platform === OS_ANDROID;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
101
|
/**
|
|
116
102
|
* Check if the platform is Android.
|
|
117
103
|
* @param {Object} state The application state.
|
|
118
104
|
* @return {boolean}
|
|
119
105
|
*/
|
|
120
|
-
export const
|
|
106
|
+
export const isAndroid = createSelector(getPlatform, platform => {
|
|
121
107
|
if (hasWebBridge()) {
|
|
122
108
|
return md.os() === 'AndroidOS';
|
|
123
109
|
}
|
|
124
110
|
return platform === OS_ANDROID;
|
|
125
111
|
});
|
|
126
112
|
|
|
127
|
-
/**
|
|
128
|
-
* @deprecated Use `getIsAndroid` instead.
|
|
129
|
-
*/
|
|
130
|
-
export const isAndroid = getIsAndroid;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Selector to check if the PWA is currently running inside the iOS app.
|
|
134
|
-
* Unlike the `getIsIos` selector, this selector will return false if the PWA
|
|
135
|
-
* is running in a web browser on an iOS device.
|
|
136
|
-
* @param {Object} state The application state.
|
|
137
|
-
* @return {boolean}
|
|
138
|
-
*/
|
|
139
|
-
export const getIsIosApp = createSelector(getPlatform, platform => {
|
|
140
|
-
if (hasWebBridge()) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
return platform === OS_IOS;
|
|
144
|
-
});
|
|
145
|
-
|
|
146
113
|
/**
|
|
147
114
|
* Check if the platform is iOS.
|
|
148
115
|
* @param {Object} state The application state.
|
|
149
116
|
* @return {boolean}
|
|
150
117
|
*/
|
|
151
|
-
export const
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @deprecated Use `getIsIos` instead.
|
|
155
|
-
*/
|
|
156
|
-
export const isIos = getIsIos;
|
|
118
|
+
export const isIos = createSelector(getPlatform, platform => platform === OS_IOS);
|
|
157
119
|
|
|
158
120
|
/**
|
|
159
121
|
* Checks if the currently stored lib version is one that supports the scanner.
|
package/subscriptions/router.js
CHANGED
|
@@ -172,8 +172,7 @@ export default function routerSubscriptions(subscribe) {
|
|
|
172
172
|
handler: redirect,
|
|
173
173
|
matcher,
|
|
174
174
|
pathParams,
|
|
175
|
-
queryParams
|
|
176
|
-
options
|
|
175
|
+
queryParams
|
|
177
176
|
} = redirects.getRedirectExtended(location) || {};
|
|
178
177
|
/* eslint-enable prefer-const */
|
|
179
178
|
|
|
@@ -182,9 +181,7 @@ export default function routerSubscriptions(subscribe) {
|
|
|
182
181
|
const {
|
|
183
182
|
pathname
|
|
184
183
|
} = getCurrentRoute(state);
|
|
185
|
-
|
|
186
|
-
LoadingProvider.setLoading(pathname);
|
|
187
|
-
}
|
|
184
|
+
LoadingProvider.setLoading(pathname);
|
|
188
185
|
const pattern = router.findPattern(location.split('?')[0]);
|
|
189
186
|
const {
|
|
190
187
|
transform
|
|
@@ -218,9 +215,7 @@ export default function routerSubscriptions(subscribe) {
|
|
|
218
215
|
redirect = null;
|
|
219
216
|
logger.error(e);
|
|
220
217
|
}
|
|
221
|
-
|
|
222
|
-
LoadingProvider.unsetLoading(pathname);
|
|
223
|
-
}
|
|
218
|
+
LoadingProvider.unsetLoading(pathname);
|
|
224
219
|
if (!redirect) {
|
|
225
220
|
return;
|
|
226
221
|
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export type RedirectHandler =
|
|
2
|
-
| string
|
|
3
|
-
| Promise<string>
|
|
4
|
-
| ((...args: any[]) => string | Promise<string>);
|
|
5
|
-
|
|
6
|
-
export type RedirectOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* Whether to show a loading indicator while the redirect is being processed.
|
|
9
|
-
* @default true
|
|
10
|
-
*/
|
|
11
|
-
showLoading?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Whether to override an existing redirect.
|
|
14
|
-
* @default false
|
|
15
|
-
*/
|
|
16
|
-
override?: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export interface RedirectExtendedData {
|
|
20
|
-
/**
|
|
21
|
-
* The value passed as "from" to set()
|
|
22
|
-
*/
|
|
23
|
-
matcher?: string;
|
|
24
|
-
/**
|
|
25
|
-
* The value passed as "to" to set()
|
|
26
|
-
*/
|
|
27
|
-
handler: RedirectHandler;
|
|
28
|
-
/**
|
|
29
|
-
* Decoded params from the pathname - defined within the matcher
|
|
30
|
-
*/
|
|
31
|
-
pathParams?: Record<string, any> | null;
|
|
32
|
-
/**
|
|
33
|
-
* Decoded query params from the pathname
|
|
34
|
-
*/
|
|
35
|
-
queryParams: Record<string, any>;
|
|
36
|
-
/**
|
|
37
|
-
* Additional options for the redirect, passed as the third argument to set()
|
|
38
|
-
*/
|
|
39
|
-
options?: RedirectOptions | null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class Redirects {
|
|
43
|
-
/**
|
|
44
|
-
* Returns a specified element from the internal "redirects" Map object.
|
|
45
|
-
* @param pathname The pathname to lookup.
|
|
46
|
-
*/
|
|
47
|
-
get(pathname: string): RedirectHandler | null;
|
|
48
|
-
/**
|
|
49
|
-
* Returns the redirect for a passed pathname.
|
|
50
|
-
* @param {string} pathname The pathname to check.
|
|
51
|
-
*/
|
|
52
|
-
getRedirect(pathname: string): RedirectHandler | null;
|
|
53
|
-
/**
|
|
54
|
-
* Unlike "getRedirect" which only returns a matching handler for a passed pathname, this method
|
|
55
|
-
* returns an object that contains some extended data.
|
|
56
|
-
* @param pathname The pathname to check.
|
|
57
|
-
*/
|
|
58
|
-
getRedirectExtended(pathname: string): RedirectExtendedData | null;
|
|
59
|
-
/**
|
|
60
|
-
* Adds a redirect handler to the collection.
|
|
61
|
-
* @param from The link to redirect from. Route patterns are also supported.
|
|
62
|
-
* @param to redirect / handle to create a dynamic link
|
|
63
|
-
* @param force Whether or not to forcefully set the redirect.
|
|
64
|
-
*/
|
|
65
|
-
set(from?: string | null, to?: RedirectHandler | null, force?: boolean): void;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Adds a redirect handler to the collection.
|
|
69
|
-
* @param from The link to redirect from. Route patterns are also supported.
|
|
70
|
-
* @param to redirect / handle to create a dynamic link
|
|
71
|
-
* @param options Additional options for the redirect.
|
|
72
|
-
* @param force Whether or not to forcefully set the redirect.
|
|
73
|
-
*/
|
|
74
|
-
set(from?: string | null, to?: RedirectHandler | null, options?: RedirectOptions, force?: boolean): void;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Removes a specified element from the internal "redirects" Map object.
|
|
78
|
-
* @param pathname The pathname to remove.
|
|
79
|
-
*/
|
|
80
|
-
unset(pathname: string): void;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
declare const redirects: Redirects;
|
|
84
|
-
export default redirects;
|