@shopgate/pwa-core 7.30.0-alpha.10 → 7.30.0-alpha.11
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 +17 -15
- package/classes/AppCommand/spec.js +11 -8
- package/classes/AppCommandRequest/index.js +38 -34
- package/classes/AppPermissionsRequest/AppPermissionsRequest.js +21 -15
- package/classes/AppPermissionsRequest/GetAppPermissionsRequest.js +12 -8
- package/classes/AppPermissionsRequest/RequestAppPermissionsRequest.js +12 -8
- package/classes/Bridge/index.js +7 -5
- package/classes/BrightnessRequest/index.js +7 -5
- package/classes/BrightnessRequest/spec.js +2 -2
- package/classes/BrowserConnector/index.js +98 -81
- package/classes/Conditioner/index.js +17 -14
- package/classes/DataRequest/index.js +25 -19
- package/classes/DevServerBridge/index.js +11 -9
- package/classes/DevServerBridge/spec.js +4 -4
- package/classes/ErrorManager/index.js +11 -9
- package/classes/Event/index.js +29 -24
- package/classes/HttpRequest/index.js +39 -33
- package/classes/PipelineDependencies/index.js +11 -9
- package/classes/PipelineDependencies/spec.js +1 -1
- package/classes/PipelineManager/index.js +48 -46
- package/classes/PipelineRequest/index.js +50 -44
- package/classes/PipelineRequest/mock.js +52 -39
- package/classes/PipelineRequest/spec.js +1 -1
- package/classes/PipelineSequence/index.js +11 -9
- package/classes/Request/index.js +15 -13
- package/classes/RequestBuffer/index.js +11 -9
- package/classes/RequestManager/index.js +20 -15
- package/classes/RequestManager/spec.js +40 -25
- package/classes/Scanner/index.js +218 -219
- package/classes/ScannerEvent/index.js +22 -22
- package/classes/ScannerEventHandler/index.js +35 -35
- package/classes/ScannerEventListener/index.js +77 -78
- package/classes/ScannerManager/ScanProcessingError.js +11 -5
- package/classes/ScannerManager/index.js +16 -14
- package/classes/WebStorageRequest/index.js +18 -12
- package/helpers/index.js +8 -8
- package/package.json +1 -1
|
@@ -4,86 +4,85 @@ import AppScanner from "../Scanner";
|
|
|
4
4
|
/**
|
|
5
5
|
* Allows anyone to listen for scan results based on scope, type or both.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
let ScannerEventListener =
|
|
8
|
+
/**
|
|
9
|
+
* @param {string|null} name A name for the listener object to refer to.
|
|
10
|
+
* @param {string|null} scope The scanner scope to listen for.
|
|
11
|
+
* @param {string|null} type THe type of scanner events to listen for.
|
|
12
|
+
* @param {Array} formats The formats which can be processed by the listener.
|
|
13
|
+
*/
|
|
14
|
+
function ScannerEventListener(name = null, scope = null, type = null, formats = []) {
|
|
15
|
+
/**
|
|
16
|
+
* Callback for an instance of an event listener. It is expected to return no value on success.
|
|
17
|
+
* Throw an Error() to force the scanner to restart.
|
|
18
|
+
*
|
|
19
|
+
* @callback ScannerEventListener~Handler
|
|
20
|
+
* @param {ScannerEvent} event The event which is emitted, when something was scanned.
|
|
21
|
+
* @returns {undefined|null} The return value is ignored. Returning a value will cause a warning.
|
|
22
|
+
* @throws {Error} Throwing an error will cause the Scanner to restart and scan again.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @param {Handler} handler The function which is called when a scan is done.
|
|
26
|
+
* @returns {ScannerEventListener}
|
|
27
|
+
*/
|
|
28
|
+
this.setHandler = handler => {
|
|
29
|
+
if (typeof handler !== 'function') {
|
|
30
|
+
logger.error(new Error('The ScannerEventListener handler must be a function!'));
|
|
31
|
+
}
|
|
32
|
+
this.handler = handler;
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the event fits to the handler.
|
|
37
|
+
* @param {ScannerEvent} event The scanner event which was emitted.
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
this.canHandleEvent = event => {
|
|
41
|
+
if (!this.handler) {
|
|
42
|
+
logger.warn(`No event handler defined for eventListener "${this.name}"`);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (this.type && this.type !== event.getType()) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (this.scope && this.scope !== event.getScope()) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const {
|
|
52
|
+
format
|
|
53
|
+
} = event.getPayload() || {};
|
|
54
|
+
if (this.formats.length && !this.formats.includes(format)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Attach the current event listener to the app scanner.
|
|
61
|
+
*/
|
|
62
|
+
this.attach = () => {
|
|
63
|
+
AppScanner.addListener(this);
|
|
64
|
+
};
|
|
8
65
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {string|null} type THe type of scanner events to listen for.
|
|
12
|
-
* @param {Array} formats The formats which can be processed by the listener.
|
|
66
|
+
* Checks the event to see, if the listener is interested in it and call it's handler.
|
|
67
|
+
* @param {ScannerEvent} event The scanner event which was emitted.
|
|
13
68
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
* @callback ScannerEventListener~Handler
|
|
20
|
-
* @param {ScannerEvent} event The event which is emitted, when something was scanned.
|
|
21
|
-
* @returns {undefined|null} The return value is ignored. Returning a value will cause a warning.
|
|
22
|
-
* @throws {Error} Throwing an error will cause the Scanner to restart and scan again.
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* @param {Handler} handler The function which is called when a scan is done.
|
|
26
|
-
* @returns {ScannerEventListener}
|
|
27
|
-
*/
|
|
28
|
-
this.setHandler = handler => {
|
|
29
|
-
if (typeof handler !== 'function') {
|
|
30
|
-
logger.error(new Error('The ScannerEventListener handler must be a function!'));
|
|
31
|
-
}
|
|
32
|
-
this.handler = handler;
|
|
33
|
-
return this;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Checks if the event fits to the handler.
|
|
37
|
-
* @param {ScannerEvent} event The scanner event which was emitted.
|
|
38
|
-
* @returns {boolean}
|
|
39
|
-
*/
|
|
40
|
-
this.canHandleEvent = event => {
|
|
41
|
-
if (!this.handler) {
|
|
42
|
-
logger.warn(`No event handler defined for eventListener "${this.name}"`);
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (this.type && this.type !== event.getType()) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
if (this.scope && this.scope !== event.getScope()) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const {
|
|
52
|
-
format
|
|
53
|
-
} = event.getPayload() || {};
|
|
54
|
-
if (this.formats.length && !this.formats.includes(format)) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Attach the current event listener to the app scanner.
|
|
61
|
-
*/
|
|
62
|
-
this.attach = () => {
|
|
63
|
-
AppScanner.addListener(this);
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Checks the event to see, if the listener is interested in it and call it's handler.
|
|
67
|
-
* @param {ScannerEvent} event The scanner event which was emitted.
|
|
68
|
-
*/
|
|
69
|
-
this.notify = async event => {
|
|
70
|
-
if (!this.canHandleEvent(event)) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
69
|
+
this.notify = async event => {
|
|
70
|
+
if (!this.canHandleEvent(event)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
// Call the listener which was previously registered
|
|
75
|
+
const handlerResult = await this.handler(event);
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
77
|
+
// Don't expect anything else than undefined or null
|
|
78
|
+
if (handlerResult !== undefined && handlerResult !== null) {
|
|
79
|
+
logger.warn(`Expected the ScannerEventListener::Handler "${this.name}" to return no value,`, `but it returned "${handlerResult}"`);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
this.name = name || 'unnamed';
|
|
83
|
+
this.scope = scope || null;
|
|
84
|
+
this.type = type || null;
|
|
85
|
+
this.formats = formats || [];
|
|
86
|
+
this.handler = null;
|
|
87
|
+
};
|
|
89
88
|
export default ScannerEventListener;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
1
3
|
/**
|
|
2
4
|
* The ScanProcessingError is supposed to be thrown in case of a processing error of the scanned
|
|
3
5
|
* content. It's properties will be used to display an error message to the user.
|
|
4
6
|
* @extends Error
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
let ScanProcessingError = /*#__PURE__*/function (_Error) {
|
|
7
9
|
/**
|
|
8
10
|
* Constructor for the ScanProcessingError
|
|
9
11
|
* @param {string} message The message of the error.
|
|
10
12
|
* @param {string} [title=null] The title of the error.
|
|
11
13
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
function ScanProcessingError(message, title = null) {
|
|
15
|
+
var _this;
|
|
16
|
+
_this = _Error.call(this, message) || this;
|
|
17
|
+
_this.title = title;
|
|
18
|
+
return _this;
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
_inheritsLoose(ScanProcessingError, _Error);
|
|
21
|
+
return ScanProcessingError;
|
|
22
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
17
23
|
export default ScanProcessingError;
|
|
@@ -3,7 +3,7 @@ import event from "../Event";
|
|
|
3
3
|
import registerEvents from "../../commands/registerEvents";
|
|
4
4
|
import broadcastEvent from "../../commands/broadcastEvent";
|
|
5
5
|
import { SCANNER_MODE_ON, SCANNER_TYPE_BARCODE, SCANNER_TYPE_IMAGE } from "../../constants/Scanner";
|
|
6
|
-
import { openScanner, closeScanner, startScanner } from "../../commands/scanner";
|
|
6
|
+
import { openScanner as _openScanner, closeScanner as _closeScanner, startScanner } from "../../commands/scanner";
|
|
7
7
|
export const APP_EVENT_CLOSE_SCANNER = 'closeScanner';
|
|
8
8
|
export const APP_EVENT_SCANNER_DID_SCAN = 'scannerDidScan';
|
|
9
9
|
export const APP_EVENT_SCANNER_ERROR_CONFIRMED = 'scannerErrorConfirmed';
|
|
@@ -22,14 +22,14 @@ let eventsRegistered = false;
|
|
|
22
22
|
* register a handler callback to process the scanned content.
|
|
23
23
|
* @deprecated This is a legacy implementation. Use Scanner instead.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
let ScannerManager = /*#__PURE__*/function () {
|
|
26
26
|
/**
|
|
27
27
|
* The ScannerManager constructor.
|
|
28
28
|
* @param {Object} options Options for the ScannerManager.
|
|
29
29
|
* @param {boolean} [options.autoClose=true] If set to TRUE, the app scanner will close
|
|
30
30
|
* automatically after a successful scan.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
function ScannerManager(options = {}) {
|
|
33
33
|
this.autoClose = true;
|
|
34
34
|
if (typeof options.autoClose === 'boolean') {
|
|
35
35
|
this.autoClose = options.autoClose;
|
|
@@ -55,7 +55,8 @@ class ScannerManager {
|
|
|
55
55
|
* @private
|
|
56
56
|
* @param {Object} payload The event payload.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
var _proto = ScannerManager.prototype;
|
|
59
|
+
_proto.scannerDidScanListener = function scannerDidScanListener(payload) {
|
|
59
60
|
/**
|
|
60
61
|
* Trigger a scannerResultProcessed event to inform the scanner view
|
|
61
62
|
* about the outcome of the scan payload processing.
|
|
@@ -114,8 +115,8 @@ class ScannerManager {
|
|
|
114
115
|
* since it provides the possibility to set a message and a title for the notification.
|
|
115
116
|
* @param {scanHandler} handler The callback - async functions are supported.
|
|
116
117
|
* @return {ScannerManager}
|
|
117
|
-
|
|
118
|
-
registerScanHandler(handler) {
|
|
118
|
+
*/;
|
|
119
|
+
_proto.registerScanHandler = function registerScanHandler(handler) {
|
|
119
120
|
if (typeof handler === 'function') {
|
|
120
121
|
this.scanHandler = handler;
|
|
121
122
|
}
|
|
@@ -127,8 +128,8 @@ class ScannerManager {
|
|
|
127
128
|
* is active. For the image scanner user interaction is necessary.
|
|
128
129
|
* @param {string} type The initially activated scanner type.
|
|
129
130
|
* @return {ScannerManager}
|
|
130
|
-
|
|
131
|
-
openScanner(type = SCANNER_TYPE_BARCODE) {
|
|
131
|
+
*/;
|
|
132
|
+
_proto.openScanner = function openScanner(type = SCANNER_TYPE_BARCODE) {
|
|
132
133
|
if (!this.supportedTypes.includes(type)) {
|
|
133
134
|
logger.error(`Scanner opening failed. ${type} is a not supported scanner type.`);
|
|
134
135
|
return this;
|
|
@@ -141,7 +142,7 @@ class ScannerManager {
|
|
|
141
142
|
// Add a listener to restart the scanner recognition after the user accepted the notification.
|
|
142
143
|
event.addCallback(APP_EVENT_SCANNER_ERROR_CONFIRMED, startScanner);
|
|
143
144
|
// Open the scanner webview.
|
|
144
|
-
|
|
145
|
+
_openScanner({
|
|
145
146
|
modes: {
|
|
146
147
|
[type]: SCANNER_MODE_ON
|
|
147
148
|
}
|
|
@@ -152,16 +153,17 @@ class ScannerManager {
|
|
|
152
153
|
/**
|
|
153
154
|
* Close the scanner webview.
|
|
154
155
|
* @return {ScannerManager}
|
|
155
|
-
|
|
156
|
-
closeScanner() {
|
|
156
|
+
*/;
|
|
157
|
+
_proto.closeScanner = function closeScanner() {
|
|
157
158
|
// Remove the listeners to avoid further execution by other instances.
|
|
158
159
|
event.removeCallback(APP_EVENT_CLOSE_SCANNER, this.closeScanner);
|
|
159
160
|
event.removeCallback(APP_EVENT_SCANNER_DID_SCAN, this.scannerDidScanListener);
|
|
160
161
|
event.removeCallback(APP_EVENT_SCANNER_ERROR_CONFIRMED, startScanner);
|
|
161
162
|
|
|
162
163
|
// Close the scanner webview.
|
|
163
|
-
|
|
164
|
+
_closeScanner();
|
|
164
165
|
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
166
|
+
};
|
|
167
|
+
return ScannerManager;
|
|
168
|
+
}();
|
|
167
169
|
export default ScannerManager;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import event from "../Event";
|
|
2
3
|
import { logger } from "../../helpers";
|
|
3
4
|
import logGroup from "../../helpers/logGroup";
|
|
@@ -9,23 +10,27 @@ let localSerial = 0;
|
|
|
9
10
|
/**
|
|
10
11
|
* The WebStorageRequest class.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
let WebStorageRequest = /*#__PURE__*/function (_Request) {
|
|
13
14
|
/**
|
|
14
15
|
* @param {string} name The name of the WebStorage entry.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
function WebStorageRequest(name = '') {
|
|
18
|
+
var _this;
|
|
19
|
+
_this = _Request.call(this) || this;
|
|
20
|
+
_this.name = name;
|
|
21
|
+
_this.params = null;
|
|
22
|
+
_this.createSerial(_this.name);
|
|
23
|
+
_this.createEventCallbackName('webStorageResponse');
|
|
24
|
+
return _this;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Generates the serial for this web storage request. Since the setWebStorageEntry expects
|
|
26
29
|
* a number value here, the default createSerial method cannot be used by now.
|
|
27
30
|
*/
|
|
28
|
-
|
|
31
|
+
_inheritsLoose(WebStorageRequest, _Request);
|
|
32
|
+
var _proto = WebStorageRequest.prototype;
|
|
33
|
+
_proto.createSerial = function createSerial() {
|
|
29
34
|
// Increase the local serial and use it for the request
|
|
30
35
|
localSerial += 1;
|
|
31
36
|
this.serial = localSerial;
|
|
@@ -35,8 +40,8 @@ class WebStorageRequest extends Request {
|
|
|
35
40
|
* Dispatches the web storage request.
|
|
36
41
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
37
42
|
* @return {boolean}
|
|
38
|
-
|
|
39
|
-
onDispatch(resolve) {
|
|
43
|
+
*/;
|
|
44
|
+
_proto.onDispatch = function onDispatch(resolve) {
|
|
40
45
|
// Add the request to the buffer.
|
|
41
46
|
requestBuffer.add(this, this.serial);
|
|
42
47
|
const requestCallbackName = this.getEventCallbackName();
|
|
@@ -82,6 +87,7 @@ class WebStorageRequest extends Request {
|
|
|
82
87
|
return false;
|
|
83
88
|
}
|
|
84
89
|
return true;
|
|
85
|
-
}
|
|
86
|
-
|
|
90
|
+
};
|
|
91
|
+
return WebStorageRequest;
|
|
92
|
+
}(Request);
|
|
87
93
|
export default WebStorageRequest;
|
package/helpers/index.js
CHANGED
|
@@ -20,17 +20,17 @@ const convertLogArgs = args => {
|
|
|
20
20
|
*/
|
|
21
21
|
export const logger = {
|
|
22
22
|
...console,
|
|
23
|
-
debug: (...args) => csl.debug(
|
|
24
|
-
dir: (...args) => csl.dir(
|
|
25
|
-
dirxml: (...args) => csl.dirxml(
|
|
23
|
+
debug: (...args) => csl.debug.apply(csl, convertLogArgs(args)),
|
|
24
|
+
dir: (...args) => csl.dir.apply(csl, convertLogArgs(args)),
|
|
25
|
+
dirxml: (...args) => csl.dirxml.apply(csl, convertLogArgs(args)),
|
|
26
26
|
error: (...args) => {
|
|
27
27
|
emitter.emit(SOURCE_CONSOLE, args);
|
|
28
|
-
csl.error(
|
|
28
|
+
csl.error.apply(csl, convertLogArgs(args));
|
|
29
29
|
},
|
|
30
|
-
info: (...args) => csl.info(
|
|
31
|
-
log: (...args) => csl.log(
|
|
32
|
-
warn: (...args) => csl.warn(
|
|
33
|
-
assert: (...args) => csl.assert(
|
|
30
|
+
info: (...args) => csl.info.apply(csl, convertLogArgs(args)),
|
|
31
|
+
log: (...args) => csl.log.apply(csl, convertLogArgs(args)),
|
|
32
|
+
warn: (...args) => csl.warn.apply(csl, convertLogArgs(args)),
|
|
33
|
+
assert: (...args) => csl.assert.apply(csl, convertLogArgs(args))
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|