@shopgate/pwa-core 7.30.0-alpha.7 → 7.30.0-alpha.9
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 +85 -9
- package/classes/DevServerBridge/spec.js +230 -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 -2
|
@@ -1,24 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Permission ids.
|
|
3
|
-
*/
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
|
|
3
|
+
*/
|
|
4
|
+
export const PERMISSION_ID_LOCATION = 'location';
|
|
5
|
+
export const PERMISSION_ID_CAMERA = 'camera';
|
|
6
|
+
|
|
7
|
+
// Only available on Android
|
|
8
|
+
export const PERMISSION_ID_PHONE = 'phone';
|
|
9
|
+
export const PERMISSION_ID_BACKGROUND_LOCATION = 'background_location';
|
|
10
|
+
|
|
11
|
+
// Only available in iOS
|
|
12
|
+
export const PERMISSION_ID_PUSH = 'push';
|
|
13
|
+
// Only available on iOS
|
|
14
|
+
export const PERMISSION_ID_BACKGROUND_APP_REFRESH = 'backgroundAppRefresh';
|
|
15
|
+
export const PERMISSION_ID_APP_TRACKING_TRANSPARENCY = 'appTrackingTransparency';
|
|
16
|
+
export const availablePermissionsIds = [PERMISSION_ID_BACKGROUND_APP_REFRESH, PERMISSION_ID_BACKGROUND_LOCATION, PERMISSION_ID_CAMERA, PERMISSION_ID_LOCATION, PERMISSION_ID_PHONE, PERMISSION_ID_PUSH, PERMISSION_ID_APP_TRACKING_TRANSPARENCY];
|
|
17
|
+
|
|
18
|
+
/**
|
|
7
19
|
* Permission usages.
|
|
8
|
-
*/
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
9
23
|
* @deprecated Use PERMISSION_USAGE_ALWAYS instead
|
|
10
|
-
*/
|
|
24
|
+
*/
|
|
25
|
+
export const USAGE_ALWAYS = 'always';
|
|
26
|
+
|
|
27
|
+
/**
|
|
11
28
|
* @deprecated Use PERMISSION_USAGE_WHEN_IN_USE instead
|
|
12
|
-
*/
|
|
29
|
+
*/
|
|
30
|
+
export const USAGE_WHEN_IN_USE = 'whenInUse';
|
|
31
|
+
export const availableUsages = [USAGE_ALWAYS, USAGE_WHEN_IN_USE];
|
|
32
|
+
export const PERMISSION_USAGE_ALWAYS = 'always';
|
|
33
|
+
export const PERMISSION_USAGE_WHEN_IN_USE = 'whenInUse';
|
|
34
|
+
export const availablePermissionUsages = [PERMISSION_USAGE_ALWAYS, PERMISSION_USAGE_WHEN_IN_USE];
|
|
35
|
+
|
|
36
|
+
/**
|
|
13
37
|
* Permission statuses
|
|
14
|
-
*/
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
15
41
|
* @deprecated Use PERMISSION_STATUS_DENIED instead
|
|
16
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
export const STATUS_DENIED = 'denied';
|
|
44
|
+
|
|
45
|
+
/**
|
|
17
46
|
* @deprecated Use PERMISSION_STATUS_GRANTED instead
|
|
18
|
-
*/
|
|
47
|
+
*/
|
|
48
|
+
export const STATUS_GRANTED = 'granted';
|
|
49
|
+
|
|
50
|
+
/**
|
|
19
51
|
* @deprecated Use PERMISSION_STATUS_NOT_DETERMINED instead
|
|
20
|
-
*/
|
|
52
|
+
*/
|
|
53
|
+
export const STATUS_NOT_DETERMINED = 'notDetermined';
|
|
54
|
+
|
|
55
|
+
/**
|
|
21
56
|
* @deprecated Use PERMISSION_STATUS_NOT_SUPPORTED instead
|
|
22
|
-
*/
|
|
57
|
+
*/
|
|
58
|
+
export const STATUS_NOT_SUPPORTED = 'notSupported';
|
|
59
|
+
|
|
60
|
+
/**
|
|
23
61
|
* @deprecated Use availablePermissionStatuses instead
|
|
24
|
-
*/
|
|
62
|
+
*/
|
|
63
|
+
export const availableStatuses = [STATUS_DENIED, STATUS_GRANTED, STATUS_NOT_DETERMINED, STATUS_NOT_SUPPORTED];
|
|
64
|
+
export const PERMISSION_STATUS_DENIED = 'denied';
|
|
65
|
+
export const PERMISSION_STATUS_GRANTED = 'granted';
|
|
66
|
+
export const PERMISSION_STATUS_NOT_DETERMINED = 'notDetermined';
|
|
67
|
+
export const PERMISSION_STATUS_NOT_SUPPORTED = 'notSupported';
|
|
68
|
+
export const availablePermissionStatuses = [PERMISSION_STATUS_DENIED, PERMISSION_STATUS_GRANTED, PERMISSION_STATUS_NOT_DETERMINED, PERMISSION_STATUS_NOT_SUPPORTED];
|
package/constants/Command.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The default app tab of the PWA
|
|
2
|
-
export
|
|
2
|
+
export const PWA_DEFAULT_TAB = 'main';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const ERROR_HANDLE_DEFAULT = 'DEFAULT';
|
|
2
|
+
export const ERROR_HANDLE_SUPPRESS = 'SUPPRESS';
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const DEFAULT_CONTEXT = '*';
|
|
2
|
+
export const SOURCE_APP = 'app';
|
|
3
|
+
export const SOURCE_PIPELINE = 'pipeline';
|
|
4
|
+
export const SOURCE_TRACKING = 'tracking';
|
|
5
|
+
export const SOURCE_CONSOLE = 'console';
|
|
6
|
+
export const CODE_TRACKING = 'ETRACKING';
|
|
7
|
+
export const Severity = {
|
|
8
|
+
Fatal: 'fatal',
|
|
9
|
+
Error: 'error',
|
|
10
|
+
Critical: 'critical',
|
|
11
|
+
Warning: 'warning',
|
|
12
|
+
Info: 'info',
|
|
13
|
+
Debug: 'debug'
|
|
14
|
+
};
|
|
15
|
+
export const DEFAULT_SEVERITY = Severity.Error;
|
package/constants/Pipeline.js
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
1
|
// Pipeline current version.
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
2
|
+
export const CURRENT_VERSION = 1;
|
|
3
|
+
|
|
4
|
+
// Error from native app framework - PipelineRequest timeout
|
|
5
|
+
export const E999 = '-999';
|
|
6
|
+
|
|
7
|
+
// Pipeline timeout error.
|
|
8
|
+
export const ETIMEOUT = 'ETIMEOUT';
|
|
9
|
+
|
|
10
|
+
// Network is unreachable.
|
|
11
|
+
export const ENETUNREACH = 'ENETUNREACH';
|
|
12
|
+
|
|
13
|
+
// A pipeline response was rejected by the request manager.
|
|
14
|
+
export const EPIPELINERESPONSEREJECTED = 'EPIPELINERESPONSEREJECTED';
|
|
15
|
+
|
|
16
|
+
// Pipeline no access.
|
|
17
|
+
export const EACCESS = 'EACCESS';
|
|
18
|
+
|
|
19
|
+
// Pipeline invalid credentials.
|
|
20
|
+
export const EINVALIDCREDENTIALS = 'EINVALIDCREDENTIALS';
|
|
21
|
+
|
|
22
|
+
/**
|
|
9
23
|
* A pipeline can't be called in the given context.
|
|
10
24
|
* For example the login pipeline when the user is already logged in.
|
|
11
|
-
*/
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
25
|
+
*/
|
|
26
|
+
export const EINVALIDCALL = 'EINVALIDCALL';
|
|
27
|
+
export const ELEGACYSGCONNECT = 'ELEGACYSGCONNECT';
|
|
28
|
+
|
|
29
|
+
// Pipeline no data found
|
|
30
|
+
export const EUNKNOWN = 'EUNKNOWN';
|
|
31
|
+
// Pipeline remote API not found
|
|
32
|
+
export const ENOTFOUND = 'ENOTFOUND';
|
|
33
|
+
|
|
34
|
+
// Pipeline found duplicate data.
|
|
35
|
+
export const EEXIST = 'EEXIST';
|
|
36
|
+
|
|
37
|
+
// Trusted pipeline string.
|
|
38
|
+
export const TYPE_TRUSTED = 'trusted';
|
|
39
|
+
|
|
40
|
+
// Errors from favorites pipeline
|
|
41
|
+
export const EFAVORITE = 'EFAVORITE';
|
|
42
|
+
|
|
43
|
+
// General bigapi errors that can occur during multiple pipelines, accessing bigapi data
|
|
44
|
+
export const EBIGAPI = 'EBIGAPI';
|
|
45
|
+
|
|
46
|
+
/**
|
|
18
47
|
* Error that is thrown if login was uncomplete. Used for external identity services.
|
|
19
|
-
*/
|
|
20
|
-
export
|
|
21
|
-
|
|
48
|
+
*/
|
|
49
|
+
export const EINCOMPLETELOGIN = 'EINCOMPLETELOGIN';
|
|
50
|
+
|
|
51
|
+
// Validation errors
|
|
52
|
+
export const EVALIDATION = 'EVALIDATION';
|
|
53
|
+
|
|
54
|
+
// Limits or quotas
|
|
55
|
+
export const ELIMIT = 'ELIMIT';
|
|
56
|
+
export const EUSERNOTFOUND = 'EUSERNOTFOUND';
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const PROCESS_ALWAYS = 'PROCESS_ALWAYS';
|
|
2
|
+
export const PROCESS_LAST = 'PROCESS_LAST';
|
|
3
|
+
export const PROCESS_SEQUENTIAL = 'PROCESS_SEQUENTIAL';
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
// Directly send and receive any request without further processing.
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
2
|
+
export const PROCESS_ANY = 'any';
|
|
3
|
+
|
|
4
|
+
// Handle the first response that was received and ignore any cached request.
|
|
5
|
+
export const PROCESS_FIRST_RESPONSE = 'first_response';
|
|
6
|
+
|
|
7
|
+
// Wait for the result of the last request until processing the queued requests.
|
|
8
|
+
export const PROCESS_LAST_REQUEST = 'last_request';
|
|
9
|
+
|
|
10
|
+
// Process responses in order of request.
|
|
11
|
+
export const PROCESS_ORDERED_REQUEST = 'ordered_request';
|
|
12
|
+
|
|
13
|
+
// Queue requests until the previous response has been received.
|
|
14
|
+
export const PROCESS_SEQUENTIALLY = 'sequentially';
|
|
15
|
+
|
|
16
|
+
// Reject any queued response that is not the awaited one.
|
|
17
|
+
export const PROPAGATE_REJECT = 'reject';
|
|
18
|
+
|
|
19
|
+
// Propagate only the awaited response to all enqueued requests.
|
|
20
|
+
export const PROPAGATE_SINGLE = 'single';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const REQUEST_TYPE_POST = 'POST';
|
|
2
|
+
export const REQUEST_TYPE_GET = 'GET';
|
package/constants/Scanner.js
CHANGED
|
@@ -1,31 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The scanner webview slides in from the left screen edge.
|
|
3
3
|
* @type {string}
|
|
4
|
-
*/
|
|
4
|
+
*/
|
|
5
|
+
export const SCANNER_ANIMATION_FOREGROUND_LEFT = 'foregroundLeft';
|
|
6
|
+
|
|
7
|
+
/**
|
|
5
8
|
* The scanner webview slides in from the right screen edge.
|
|
6
9
|
* @type {string}
|
|
7
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
export const SCANNER_ANIMATION_FOREGROUND_RIGHT = 'foregroundRight';
|
|
12
|
+
|
|
13
|
+
/**
|
|
8
14
|
* The scanner webview slides in from the bottom screen edge.
|
|
9
15
|
* @type {string}
|
|
10
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export const SCANNER_ANIMATION_FOREGROUND_BOTTOM = 'foregroundBottom';
|
|
18
|
+
|
|
19
|
+
/**
|
|
11
20
|
* The scanner webview just appears without animation.
|
|
12
21
|
* @type {string}
|
|
13
|
-
*/
|
|
22
|
+
*/
|
|
23
|
+
export const SCANNER_ANIMATION_NONE = '';
|
|
24
|
+
|
|
25
|
+
/**
|
|
14
26
|
* The scanner mode option for an active scanner functionality.
|
|
15
27
|
* @type {string}
|
|
16
|
-
*/
|
|
28
|
+
*/
|
|
29
|
+
export const SCANNER_MODE_ON = 'on';
|
|
30
|
+
|
|
31
|
+
/**
|
|
17
32
|
* The scanner mode option for an inactive scanner functionality.
|
|
18
33
|
* @type {string}
|
|
19
|
-
*/
|
|
34
|
+
*/
|
|
35
|
+
export const SCANNER_MODE_OFF = 'off';
|
|
36
|
+
|
|
37
|
+
/**
|
|
20
38
|
* The barcode recognition scanner mode.
|
|
21
39
|
* @type {string}
|
|
22
|
-
*/
|
|
40
|
+
*/
|
|
41
|
+
export const SCANNER_TYPE_BARCODE = 'barcodeRecognition';
|
|
42
|
+
|
|
43
|
+
/**
|
|
23
44
|
* The card recognition scanner mode.
|
|
24
45
|
* @type {string}
|
|
25
|
-
*/
|
|
46
|
+
*/
|
|
47
|
+
export const SCANNER_TYPE_CARD = 'cardRecognition';
|
|
48
|
+
|
|
49
|
+
/**
|
|
26
50
|
* The image recognition scanner mode.
|
|
27
51
|
* @type {string}
|
|
28
|
-
*/
|
|
52
|
+
*/
|
|
53
|
+
export const SCANNER_TYPE_IMAGE = 'imageCapturing';
|
|
54
|
+
|
|
55
|
+
/**
|
|
29
56
|
* Default scope for all scanner formats.
|
|
30
57
|
* @type {string}
|
|
31
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
export const SCANNER_SCOPE_DEFAULT = 'default';
|
|
60
|
+
export const SCANNER_MIN_APP_LIB_VERSION = '21.0';
|
package/constants/Trilean.js
CHANGED
package/emitters/ui.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import EventEmitter from'events';
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
export default new EventEmitter();
|
package/helpers/index.js
CHANGED
|
@@ -1,25 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
import { emitter } from "../classes/ErrorManager";
|
|
2
|
+
import { SOURCE_CONSOLE } from "../constants/ErrorManager";
|
|
3
|
+
const csl = console;
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Converts logs into a readable format for Selenium, if testMode is enabled.
|
|
3
7
|
* @param {Array} args Arguments that should be converted
|
|
4
8
|
* @return {Array} converted arguments
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const convertLogArgs = args => {
|
|
11
|
+
if (window.stringifyLogs) {
|
|
12
|
+
return [JSON.stringify(args)];
|
|
13
|
+
}
|
|
14
|
+
return args;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
6
18
|
* The logging wrapper for the console.
|
|
7
19
|
* @type {Object}
|
|
8
|
-
*/
|
|
20
|
+
*/
|
|
21
|
+
export const logger = {
|
|
22
|
+
...console,
|
|
23
|
+
debug: (...args) => csl.debug(...convertLogArgs(args)),
|
|
24
|
+
dir: (...args) => csl.dir(...convertLogArgs(args)),
|
|
25
|
+
dirxml: (...args) => csl.dirxml(...convertLogArgs(args)),
|
|
26
|
+
error: (...args) => {
|
|
27
|
+
emitter.emit(SOURCE_CONSOLE, args);
|
|
28
|
+
csl.error(...convertLogArgs(args));
|
|
29
|
+
},
|
|
30
|
+
info: (...args) => csl.info(...convertLogArgs(args)),
|
|
31
|
+
log: (...args) => csl.log(...convertLogArgs(args)),
|
|
32
|
+
warn: (...args) => csl.warn(...convertLogArgs(args)),
|
|
33
|
+
assert: (...args) => csl.assert(...convertLogArgs(args))
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
9
37
|
* Returns a URL for performing XHR Requests.
|
|
10
38
|
* @param {string} action The action to request on the server.
|
|
11
39
|
* @return {string} The full URL.
|
|
12
|
-
*/
|
|
40
|
+
*/
|
|
41
|
+
export const ajaxUrl = action => action ? `sgapi:${action}` : '';
|
|
42
|
+
|
|
43
|
+
/**
|
|
13
44
|
* Checks if the hasSGJavascriptBridge exists.
|
|
14
45
|
* @return {boolean}
|
|
15
|
-
*/
|
|
46
|
+
*/
|
|
47
|
+
export function hasSGJavaScriptBridge() {
|
|
48
|
+
return typeof SGJavascriptBridge !== 'undefined';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
16
52
|
* Checks whether the web bridge is active.
|
|
17
53
|
* @returns {boolean}
|
|
18
|
-
*/
|
|
54
|
+
*/
|
|
55
|
+
export function hasWebBridgeCore() {
|
|
56
|
+
if (!hasSGJavaScriptBridge()) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return window.SGJavascriptBridge?.type === 'web' || window.SGJavascriptBridge?.type === 'desktop';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
19
63
|
* Checks whether the browser connector should be used.
|
|
20
64
|
* @return {boolean}
|
|
21
|
-
*/
|
|
65
|
+
*/
|
|
66
|
+
export function useBrowserConnector() {
|
|
67
|
+
if (hasSGJavaScriptBridge()) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (process.env.NODE_ENV === 'development' && process.env.IP && process.env.PORT) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
22
77
|
* Logs a deprecation warning.
|
|
23
78
|
* @param {string} element The deprecated element.
|
|
24
79
|
* @param {string} [version='v7.0.0'] The engage version of removal.
|
|
25
|
-
*/
|
|
80
|
+
*/
|
|
81
|
+
export function logDeprecationMessage(element, version = 'v7.0.0') {
|
|
82
|
+
logger.warn(`DEPRECATED: ${element} is deprecated. It will be removed in Engage ${version}`);
|
|
83
|
+
}
|
package/helpers/logGroup.js
CHANGED
|
@@ -1,30 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
import { logger } from "./index";
|
|
2
|
+
const KEY_COLOR = 'gray';
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Repeates a string by a defined amount of times.
|
|
3
6
|
* @param {string} str The string to repeat.
|
|
4
7
|
* @param {number} times How many times the string should be repeated.
|
|
5
8
|
* @return {string}
|
|
6
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const repeat = (str, times) => new Array(times + 1).join(str);
|
|
11
|
+
|
|
12
|
+
/**
|
|
7
13
|
* Creates a string from a number and fills up the gap with 0 to reach a certain length.
|
|
8
14
|
* @param {number} num The number
|
|
9
15
|
* @param {number} maxLength The length of the resulting string.
|
|
10
16
|
* @return {string}
|
|
11
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
const pad = (num, maxLength) => repeat('0', maxLength - num.toString().length) + num;
|
|
19
|
+
|
|
20
|
+
/**
|
|
12
21
|
* Formats a timestamp for the output in the group title.
|
|
13
22
|
* @param {number} time The timestamp to format.
|
|
14
23
|
* @return {string}
|
|
15
|
-
*/
|
|
24
|
+
*/
|
|
25
|
+
const formatTime = () => {
|
|
26
|
+
const time = new Date();
|
|
27
|
+
return `${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
16
31
|
* Creates the style for a console string portion.
|
|
17
32
|
* @param {string} [color='gray'] The text color.
|
|
18
33
|
* @param {string} [fontWeight='lighter'] The front weight.
|
|
19
34
|
* @return {string}
|
|
20
|
-
*/
|
|
35
|
+
*/
|
|
36
|
+
const style = (color = 'gray', fontWeight = 'lighter') => `color: ${color}; font-weight: ${fontWeight};`;
|
|
37
|
+
|
|
38
|
+
/**
|
|
21
39
|
* Returns the biggest length value of an object's keys.
|
|
22
40
|
* @param {Object} prop The object to walk through.
|
|
23
41
|
* @return {number}
|
|
24
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
const maxKeysLength = prop => {
|
|
44
|
+
let maxLength = 0;
|
|
45
|
+
Object.keys(prop).forEach(key => {
|
|
46
|
+
if (key.length + 1 > maxLength) {
|
|
47
|
+
maxLength = key.length + 1;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return maxLength;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
25
54
|
* Logs a group of console logs.
|
|
26
55
|
* @param {string} title The group title.
|
|
27
56
|
* @param {Object} [content={}] The content of the group.
|
|
28
57
|
* @param {string} [actionColor='gray'] The action color.
|
|
29
|
-
*/
|
|
30
|
-
|
|
58
|
+
*/
|
|
59
|
+
const logGroup = (title, content = {}, actionColor = 'gray') => {
|
|
60
|
+
const time = formatTime();
|
|
61
|
+
logger.groupCollapsed(` %c${title} %c@ ${time}`, style(actionColor), style('bold'), style());
|
|
62
|
+
if (Object.keys(content).length) {
|
|
63
|
+
const maxLength = maxKeysLength(content) + 2;
|
|
64
|
+
Object.keys(content).forEach(key => {
|
|
65
|
+
const value = content[key];
|
|
66
|
+
const action = `${key}:`.padEnd(maxLength);
|
|
67
|
+
|
|
68
|
+
// If the content is an object, log all keys individually.
|
|
69
|
+
if (typeof value === 'object' && value !== null && value.constructor === Object) {
|
|
70
|
+
if (!Object.keys(value).length) {
|
|
71
|
+
logger.log(` %c ${action}`, style(KEY_COLOR, 'bold'), 'undefined');
|
|
72
|
+
} else logger.log(` %c ${action}`, style(KEY_COLOR, 'bold'), value);
|
|
73
|
+
} else logger.log(` %c ${action}`, style(KEY_COLOR, 'bold'), value);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
logger.groupEnd();
|
|
77
|
+
};
|
|
78
|
+
export default logGroup;
|