@shopgate/pwa-core 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.
- package/classes/AppCommand/index.js +115 -11
- package/classes/AppCommand/spec.js +260 -6
- package/classes/AppCommandRequest/index.js +129 -20
- package/classes/AppPermissionsRequest/AppPermissionsRequest.js +45 -7
- package/classes/AppPermissionsRequest/GetAppPermissionsRequest.js +48 -9
- package/classes/AppPermissionsRequest/RequestAppPermissionsRequest.js +54 -9
- package/classes/Bridge/index.js +34 -4
- package/classes/Bridge/spec.js +24 -1
- package/classes/BrightnessRequest/index.js +59 -10
- package/classes/BrightnessRequest/spec.js +111 -6
- package/classes/BrowserConnector/index.js +180 -26
- package/classes/Conditioner/index.js +74 -8
- package/classes/Conditioner/spec.js +75 -1
- package/classes/DataRequest/index.js +116 -13
- package/classes/DevServerBridge/index.js +86 -9
- package/classes/DevServerBridge/spec.js +231 -14
- package/classes/ErrorManager/index.js +144 -20
- package/classes/ErrorManager/spec.js +244 -2
- package/classes/Event/index.js +101 -15
- package/classes/HttpRequest/index.js +182 -21
- package/classes/PipelineDependencies/index.js +42 -6
- package/classes/PipelineDependencies/spec.js +46 -3
- package/classes/PipelineManager/index.js +517 -71
- package/classes/PipelineManager/spec.js +733 -15
- package/classes/PipelineRequest/index.js +167 -19
- package/classes/PipelineRequest/mock.js +118 -21
- package/classes/PipelineRequest/spec.js +333 -2
- package/classes/PipelineSequence/index.js +34 -6
- package/classes/Request/index.js +61 -13
- package/classes/RequestBuffer/index.js +43 -6
- package/classes/RequestManager/index.js +216 -33
- package/classes/RequestManager/spec.js +188 -1
- package/classes/Scanner/index.js +246 -67
- package/classes/ScannerEvent/index.js +23 -9
- package/classes/ScannerEventHandler/index.js +39 -16
- package/classes/ScannerEventListener/index.js +84 -24
- package/classes/ScannerManager/ScanProcessingError.js +11 -3
- package/classes/ScannerManager/index.js +133 -21
- package/classes/WebStorageRequest/index.js +76 -9
- package/commands/analyticsSetCustomValues.js +8 -2
- package/commands/appPermissions.js +10 -3
- package/commands/brightness.js +33 -5
- package/commands/broadcastEvent.js +8 -2
- package/commands/cleanTab.js +11 -3
- package/commands/closeInAppBrowser.js +22 -2
- package/commands/flushTab.js +8 -2
- package/commands/getWebStorageEntry.js +11 -2
- package/commands/hideMenuBar.js +8 -2
- package/commands/hideNavigationBar.js +8 -2
- package/commands/hideSplashScreen.js +8 -2
- package/commands/onload.js +13 -3
- package/commands/openAppSettings.js +8 -2
- package/commands/openPage.js +8 -2
- package/commands/openPageExtern.js +8 -2
- package/commands/performCommandsAfterDelay.js +11 -3
- package/commands/plotProjects.js +65 -7
- package/commands/popTabToRoot.js +11 -3
- package/commands/registerEvents.js +10 -2
- package/commands/scanner.js +76 -7
- package/commands/setCookie.js +8 -2
- package/commands/setDebugLoggingEnabled.js +8 -2
- package/commands/setScrollingEnabled.js +7 -2
- package/commands/setWebStorageEntry.js +8 -2
- package/commands/shareItem.js +18 -2
- package/commands/showNavigationBar.js +8 -2
- package/commands/showTab.js +13 -2
- package/commands/unifiedTracking.js +128 -30
- package/constants/AppCommands.js +6 -1
- package/constants/AppEvents.js +9 -1
- package/constants/AppPermissions.js +57 -13
- package/constants/Command.js +1 -1
- package/constants/ErrorHandleTypes.js +2 -1
- package/constants/ErrorManager.js +15 -1
- package/constants/Pipeline.js +52 -17
- package/constants/ProcessTypes.js +3 -1
- package/constants/RequestManagerModes.js +19 -7
- package/constants/RequestTypes.js +2 -1
- package/constants/Scanner.js +39 -10
- package/constants/Trilean.js +6 -1
- package/emitters/ui.js +2 -1
- package/helpers/index.js +66 -8
- package/helpers/logGroup.js +56 -8
- package/helpers/version.js +216 -22
- package/index.js +60 -5
- package/package.json +1 -1
package/helpers/version.js
CHANGED
|
@@ -1,71 +1,265 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import MobileDetect from 'mobile-detect';
|
|
2
|
+
import detector from 'detector';
|
|
3
|
+
import { logger, hasSGJavaScriptBridge } from "./index";
|
|
4
|
+
import getWebStorageEntry from "../commands/getWebStorageEntry";
|
|
5
|
+
const MODE_AT_MOST = 'at_most';
|
|
6
|
+
const MODE_AT_LEAST = 'at_least';
|
|
7
|
+
export const PLATFORM_ANDROID = 'android';
|
|
8
|
+
export const PLATFORM_IOS = 'ios';
|
|
9
|
+
export const MIN_ANDROID_LIB_VERSION = '13.0';
|
|
10
|
+
let versions = null;
|
|
11
|
+
let requesting = false;
|
|
12
|
+
const md = new MobileDetect(navigator.userAgent);
|
|
13
|
+
export const isAndroidOs = md.is('AndroidOS');
|
|
14
|
+
export const isIOs = md.is('iOS');
|
|
15
|
+
const fullVersion = typeof detector === 'object' && detector.os ? detector.os.fullVersion : null;
|
|
16
|
+
|
|
17
|
+
// Eslint doesn't allow to use one liner here.
|
|
18
|
+
let model = null;
|
|
19
|
+
if (fullVersion) {
|
|
20
|
+
model = isAndroidOs ? 'Android' : `iPhone${fullVersion}`;
|
|
21
|
+
}
|
|
22
|
+
export const defaultClientInformation = {
|
|
23
|
+
libVersion: '21.0',
|
|
24
|
+
appVersion: '5.18.0',
|
|
25
|
+
codebaseVersion: '5.18.0',
|
|
26
|
+
type: !md.tablet() ? 'phone' : 'tablet',
|
|
27
|
+
device: {
|
|
28
|
+
type: !md.tablet() ? 'phone' : 'tablet',
|
|
29
|
+
os: {
|
|
30
|
+
platform: isAndroidOs ? PLATFORM_ANDROID : PLATFORM_IOS,
|
|
31
|
+
ver: fullVersion
|
|
32
|
+
},
|
|
33
|
+
model
|
|
34
|
+
},
|
|
35
|
+
supportedAnalyticsServices: []
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
3
39
|
* Waits till a passed handler function returns TRUE and resolves.
|
|
4
40
|
* @param {Function} handler Handler function which checks a condition to resolve.
|
|
5
41
|
* @return {Promise}
|
|
6
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
const wait = handler => new Promise(resolve => {
|
|
44
|
+
/**
|
|
7
45
|
* Checks the request state.
|
|
8
|
-
*/
|
|
46
|
+
*/
|
|
47
|
+
const check = () => {
|
|
48
|
+
if (handler() === true) {
|
|
49
|
+
resolve();
|
|
50
|
+
} else {
|
|
51
|
+
setTimeout(check, 20);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
check();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
9
58
|
* Splits a version string into it's segments.
|
|
10
59
|
* @param {string} input The string to parse.
|
|
11
60
|
* @return {Array}
|
|
12
|
-
*/
|
|
61
|
+
*/
|
|
62
|
+
const parseVersionSegments = input => {
|
|
63
|
+
if (typeof input !== 'string') {
|
|
64
|
+
return [Number.NaN];
|
|
65
|
+
}
|
|
66
|
+
return input.trim().split('.').map(segment => parseInt(segment, 10));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
13
70
|
* Validates version segments.
|
|
14
71
|
* @param {Array} segments The segments array.
|
|
15
72
|
* @return {boolean}
|
|
16
|
-
*/
|
|
73
|
+
*/
|
|
74
|
+
const validateVersionSegments = segments => segments.filter(entry => Number.isNaN(entry)).length === 0;
|
|
75
|
+
|
|
76
|
+
/**
|
|
17
77
|
* Checks if a required version matches a current version.
|
|
18
78
|
* @param {string} mode The mode for the check.
|
|
19
79
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
20
80
|
* @param {string} currentVersion The current version (same pattern).
|
|
21
81
|
* @return {boolean}
|
|
22
|
-
*/
|
|
23
|
-
|
|
82
|
+
*/
|
|
83
|
+
const check = (mode, requiredVersion = '', currentVersion = '') => {
|
|
84
|
+
const parsedCurrent = parseVersionSegments(currentVersion);
|
|
85
|
+
const parsedRequired = parseVersionSegments(requiredVersion);
|
|
86
|
+
if (!validateVersionSegments(parsedCurrent) || !validateVersionSegments(parsedRequired)) {
|
|
87
|
+
logger.error(`Error parsing version strings (current: ${currentVersion} | required: ${requiredVersion})`);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const [requiredMajor, requiredMinor = 0, requiredMicro = 0] = parsedRequired;
|
|
91
|
+
const [currentMajor, currentMinor = 0, currentMicro = 0] = parsedCurrent;
|
|
92
|
+
if (mode === MODE_AT_LEAST) {
|
|
93
|
+
if (currentMajor !== requiredMajor) {
|
|
94
|
+
return currentMajor > requiredMajor;
|
|
95
|
+
}
|
|
96
|
+
if (currentMinor !== requiredMinor) {
|
|
97
|
+
return currentMinor > requiredMinor;
|
|
98
|
+
}
|
|
99
|
+
return currentMicro >= requiredMicro;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// MODE_AT_MOST - no extra branch necessary, since it's just an internal function right now.
|
|
103
|
+
if (currentMajor !== requiredMajor) {
|
|
104
|
+
return currentMajor < requiredMajor;
|
|
105
|
+
}
|
|
106
|
+
if (currentMinor !== requiredMinor) {
|
|
107
|
+
return currentMinor < requiredMinor;
|
|
108
|
+
}
|
|
109
|
+
return currentMicro <= requiredMicro;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** @returns {string} */
|
|
113
|
+
export const getUserAgent = () => navigator.userAgent;
|
|
114
|
+
|
|
115
|
+
/**
|
|
24
116
|
* Checks if a version string is valid.
|
|
25
117
|
* @param {string} input The string to check - 17[|17.0|17.0.0].
|
|
26
118
|
* @return {boolean}
|
|
27
|
-
*/
|
|
119
|
+
*/
|
|
120
|
+
export const isValidVersion = input => validateVersionSegments(parseVersionSegments(input));
|
|
121
|
+
|
|
122
|
+
/**
|
|
28
123
|
* Checks if a required version matches at least a current version.
|
|
29
124
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
30
125
|
* @param {string} currentVersion The current version (same pattern).
|
|
31
126
|
* @return {boolean}
|
|
32
|
-
*/
|
|
127
|
+
*/
|
|
128
|
+
export const isVersionAtLeast = (requiredVersion, currentVersion) => check(MODE_AT_LEAST, requiredVersion, currentVersion);
|
|
129
|
+
|
|
130
|
+
/**
|
|
33
131
|
* Checks if a required version matches at most a current version.
|
|
34
132
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
35
133
|
* @param {string} currentVersion The current (same pattern).
|
|
36
134
|
* @return {boolean}
|
|
37
|
-
*/
|
|
135
|
+
*/
|
|
136
|
+
export const isVersionAtMost = (requiredVersion, currentVersion) => check(MODE_AT_MOST, requiredVersion, currentVersion);
|
|
137
|
+
|
|
138
|
+
/**
|
|
38
139
|
* Checks if a required version is equal to a current version.
|
|
39
140
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
40
141
|
* @param {string} currentVersion The current (same pattern).
|
|
41
142
|
* @return {boolean}
|
|
42
|
-
*/
|
|
143
|
+
*/
|
|
144
|
+
export const isVersion = (requiredVersion, currentVersion) => isVersionAtLeast(requiredVersion, currentVersion) === true && isVersionAtMost(requiredVersion, currentVersion) === true;
|
|
145
|
+
|
|
146
|
+
/**
|
|
43
147
|
* Fetches versions from the client information webStorage entry.
|
|
44
148
|
* @return {Promise}
|
|
45
|
-
*/
|
|
149
|
+
*/
|
|
150
|
+
const getVersionsFromClientInformation = async () => {
|
|
151
|
+
/**
|
|
46
152
|
* Checks if currently no request is ongoing.
|
|
47
153
|
* @return {boolean}
|
|
48
|
-
*/
|
|
49
|
-
|
|
154
|
+
*/
|
|
155
|
+
const isIdle = () => requesting === false;
|
|
156
|
+
if (!isIdle()) {
|
|
157
|
+
// Wait until the request finished before proceed.
|
|
158
|
+
await wait(isIdle);
|
|
159
|
+
}
|
|
160
|
+
// If a version object is already present, the request can be skipped.
|
|
161
|
+
if (versions !== null) {
|
|
162
|
+
return versions;
|
|
163
|
+
}
|
|
164
|
+
requesting = true;
|
|
165
|
+
let clientInformation;
|
|
166
|
+
|
|
167
|
+
// Fetch the client information.
|
|
168
|
+
if (!hasSGJavaScriptBridge()) {
|
|
169
|
+
clientInformation = {
|
|
170
|
+
value: {
|
|
171
|
+
...defaultClientInformation
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
clientInformation = await getWebStorageEntry({
|
|
176
|
+
name: 'clientInformation'
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Grab all relevant data from the client information.
|
|
181
|
+
let {
|
|
182
|
+
libVersion
|
|
183
|
+
} = clientInformation.value;
|
|
184
|
+
const {
|
|
185
|
+
appVersion,
|
|
186
|
+
codebaseVersion,
|
|
187
|
+
device
|
|
188
|
+
} = clientInformation.value;
|
|
189
|
+
/* istanbul ignore next */
|
|
190
|
+
const {
|
|
191
|
+
os: {
|
|
192
|
+
platform = null
|
|
193
|
+
} = {}
|
|
194
|
+
} = device || {};
|
|
195
|
+
/**
|
|
50
196
|
* Older Android app versions didn't handle the libVersion within the client information like the
|
|
51
197
|
* iOS apps. Those apps usually send a version 2.0. But since they also support most of the PWA
|
|
52
198
|
* related commands, the lib version is corrected here to improve handling within the code.
|
|
53
|
-
*/
|
|
54
|
-
|
|
199
|
+
*/
|
|
200
|
+
if (platform === PLATFORM_ANDROID && !isVersionAtLeast('9.0', libVersion)) {
|
|
201
|
+
libVersion = MIN_ANDROID_LIB_VERSION;
|
|
202
|
+
}
|
|
203
|
+
// Update the version cache.
|
|
204
|
+
versions = {
|
|
205
|
+
libVersion,
|
|
206
|
+
appVersion,
|
|
207
|
+
codebaseVersion
|
|
208
|
+
};
|
|
209
|
+
requesting = false;
|
|
210
|
+
return versions;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
55
214
|
* Clears the local versions cache
|
|
56
|
-
*/
|
|
215
|
+
*/
|
|
216
|
+
export const clearVersionCache = () => {
|
|
217
|
+
versions = null;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
57
221
|
* Checks if a required version matches at least the current lib version.
|
|
58
222
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
59
223
|
* @return {Promise}
|
|
60
|
-
*/
|
|
224
|
+
*/
|
|
225
|
+
export const isLibVersionAtLeast = async requiredVersion => {
|
|
226
|
+
const {
|
|
227
|
+
libVersion
|
|
228
|
+
} = await getVersionsFromClientInformation();
|
|
229
|
+
return isVersionAtLeast(requiredVersion, libVersion);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/**
|
|
61
233
|
* Checks if a required version matches at most the current lib version.
|
|
62
234
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
63
235
|
* @return {Promise}
|
|
64
|
-
*/
|
|
236
|
+
*/
|
|
237
|
+
export const isLibVersionAtMost = async requiredVersion => {
|
|
238
|
+
const {
|
|
239
|
+
libVersion
|
|
240
|
+
} = await getVersionsFromClientInformation();
|
|
241
|
+
return isVersionAtMost(requiredVersion, libVersion);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
65
245
|
* Checks if a required version matches the current lib version.
|
|
66
246
|
* @param {string} requiredVersion The required version - 17[|17.0|17.0.0].
|
|
67
247
|
* @return {Promise}
|
|
68
|
-
*/
|
|
248
|
+
*/
|
|
249
|
+
export const isLibVersion = async requiredVersion => {
|
|
250
|
+
const {
|
|
251
|
+
libVersion
|
|
252
|
+
} = await getVersionsFromClientInformation();
|
|
253
|
+
return isVersion(requiredVersion, libVersion);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
69
257
|
* Returns the current libVersion.
|
|
70
258
|
* @return {Promise}
|
|
71
|
-
*/
|
|
259
|
+
*/
|
|
260
|
+
export const getLibVersion = async () => {
|
|
261
|
+
const {
|
|
262
|
+
libVersion
|
|
263
|
+
} = await getVersionsFromClientInformation();
|
|
264
|
+
return libVersion;
|
|
265
|
+
};
|
package/index.js
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
// Classes
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export{default as
|
|
6
|
-
export
|
|
2
|
+
export { default as AppCommand } from "./classes/AppCommand";
|
|
3
|
+
export { default as GetAppPermissionsRequest } from "./classes/AppPermissionsRequest/GetAppPermissionsRequest";
|
|
4
|
+
export { default as RequestAppPermissionsRequest } from "./classes/AppPermissionsRequest/RequestAppPermissionsRequest";
|
|
5
|
+
export { default as BrightnessRequest } from "./classes/BrightnessRequest";
|
|
6
|
+
export { default as Conditioner } from "./classes/Conditioner";
|
|
7
|
+
export { default as DataRequest } from "./classes/DataRequest";
|
|
8
|
+
export { default as DevServerBridge } from "./classes/DevServerBridge";
|
|
9
|
+
export { default as errorManager, emitter } from "./classes/ErrorManager";
|
|
10
|
+
export { default as event } from "./classes/Event";
|
|
11
|
+
export { default as HttpRequest } from "./classes/HttpRequest";
|
|
12
|
+
export { default as PipelineRequest } from "./classes/PipelineRequest";
|
|
13
|
+
export { default as ScannerManager } from "./classes/ScannerManager";
|
|
14
|
+
export { default as WebStorageRequest } from "./classes/WebStorageRequest";
|
|
15
|
+
|
|
16
|
+
// Commands
|
|
17
|
+
export { default as analyticsSetCustomValues } from "./commands/analyticsSetCustomValues";
|
|
18
|
+
export * from "./commands/appPermissions";
|
|
19
|
+
export * from "./commands/brightness";
|
|
20
|
+
export { default as broadcastEvent } from "./commands/broadcastEvent";
|
|
21
|
+
export { default as cleanTab, cleanTabCmd } from "./commands/cleanTab";
|
|
22
|
+
export { default as closeInAppBrowser } from "./commands/closeInAppBrowser";
|
|
23
|
+
export { default as flushTab } from "./commands/flushTab";
|
|
24
|
+
export { default as hideMenuBar } from "./commands/hideMenuBar";
|
|
25
|
+
export { default as hideNavigationBar } from "./commands/hideNavigationBar";
|
|
26
|
+
export { default as hideSplashScreen } from "./commands/hideSplashScreen";
|
|
27
|
+
export { default as onload } from "./commands/onload";
|
|
28
|
+
export { default as openAppSettings } from "./commands/openAppSettings";
|
|
29
|
+
export { default as openPage } from "./commands/openPage";
|
|
30
|
+
export { default as openPageExtern } from "./commands/openPageExtern";
|
|
31
|
+
export { default as performCommandsAfterDelay, performCommandsAfterDelayCmd } from "./commands/performCommandsAfterDelay";
|
|
32
|
+
export * from "./commands/plotProjects";
|
|
33
|
+
export { default as popTabToRoot, popTabToRootCmd } from "./commands/popTabToRoot";
|
|
34
|
+
export { default as registerEvents } from "./commands/registerEvents";
|
|
35
|
+
export * from "./commands/scanner";
|
|
36
|
+
export { default as setCookie } from "./commands/setCookie";
|
|
37
|
+
export { default as setDebugLoggingEnabled } from "./commands/setDebugLoggingEnabled";
|
|
38
|
+
export { default as setScrollingEnabled } from "./commands/setScrollingEnabled";
|
|
39
|
+
export { default as showNavigationBar } from "./commands/showNavigationBar";
|
|
40
|
+
export { default as showTab } from "./commands/showTab";
|
|
41
|
+
export * from "./commands/unifiedTracking";
|
|
42
|
+
export { default as getWebStorageEntry } from "./commands/getWebStorageEntry";
|
|
43
|
+
export { default as setWebStorageEntry } from "./commands/setWebStorageEntry";
|
|
44
|
+
|
|
45
|
+
// Constants
|
|
46
|
+
export * from "./constants/AppEvents";
|
|
47
|
+
export * from "./constants/AppPermissions";
|
|
48
|
+
export * from "./constants/ErrorHandleTypes";
|
|
49
|
+
export * from "./constants/Pipeline";
|
|
50
|
+
export * from "./constants/ProcessTypes";
|
|
51
|
+
export * from "./constants/Scanner";
|
|
52
|
+
export * from "./constants/ErrorManager";
|
|
53
|
+
export * from "./constants/Trilean";
|
|
54
|
+
|
|
55
|
+
// Emitters
|
|
56
|
+
export { default as UIEvents } from "./emitters/ui";
|
|
57
|
+
|
|
58
|
+
// Helpers
|
|
59
|
+
export * from "./helpers";
|
|
60
|
+
export { default as logGroup } from "./helpers/logGroup";
|
|
61
|
+
export * from "./helpers/version";
|