@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
1
2
|
import { logger } from "../../helpers";
|
|
2
3
|
import event from "../Event";
|
|
3
4
|
import { TYPE_TRUSTED } from "../../constants/Pipeline";
|
|
@@ -9,13 +10,13 @@ const appConfig = process.env.APP_CONFIG || {};
|
|
|
9
10
|
* The BrowserConnector emulates the SGJavaScriptBridge within browser environments.
|
|
10
11
|
* It routes supported app commands to Shopgate Connect which can mimic the behavior of the app.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
let BrowserConnector = /*#__PURE__*/function () {
|
|
13
14
|
/**
|
|
14
15
|
* The constructor.
|
|
15
16
|
* @param {string} [ip=process.env.IP] The IP of the dev server.
|
|
16
17
|
* @param {number} [port=process.env.PORT] The port of the dev server.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
function BrowserConnector(ip = process.env.IP, port = process.env.PORT) {
|
|
19
20
|
/**
|
|
20
21
|
* Builds the GET query.
|
|
21
22
|
* @param {Object} input The input parameters.
|
|
@@ -73,85 +74,12 @@ class BrowserConnector {
|
|
|
73
74
|
this.supportedCommands = [appCommands.COMMAND_SEND_PIPELINE_REQUEST, appCommands.COMMAND_SEND_HTTP_REQUEST, appCommands.COMMAND_SEND_DATA_REQUEST, appCommands.COMMAND_GET_WEBSTORAGE_ENTRY];
|
|
74
75
|
this.appConfig = appConfig;
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
-
* @return {string}
|
|
78
|
-
*/
|
|
79
|
-
get requestType() {
|
|
80
|
-
if (!this.isPipelineRequest) {
|
|
81
|
-
return requestTypes.REQUEST_TYPE_POST;
|
|
82
|
-
}
|
|
83
|
-
const segments = this.command.p.name.split('.');
|
|
84
|
-
if (segments[2].startsWith('get')) {
|
|
85
|
-
return requestTypes.REQUEST_TYPE_GET;
|
|
86
|
-
}
|
|
87
|
-
return requestTypes.REQUEST_TYPE_POST;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @return {boolean}
|
|
92
|
-
*/
|
|
93
|
-
get isGET() {
|
|
94
|
-
return this.requestType === requestTypes.REQUEST_TYPE_GET;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @return {boolean}
|
|
99
|
-
*/
|
|
100
|
-
get isPOST() {
|
|
101
|
-
return this.requestType === requestTypes.REQUEST_TYPE_POST;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @return {string}
|
|
106
|
-
*/
|
|
107
|
-
get connectUrl() {
|
|
108
|
-
const {
|
|
109
|
-
apiUrl = ''
|
|
110
|
-
} = this.appConfig;
|
|
111
|
-
const {
|
|
112
|
-
name,
|
|
113
|
-
type,
|
|
114
|
-
input
|
|
115
|
-
} = this.command.p;
|
|
116
|
-
const queryString = this.buildQueryString(input);
|
|
117
|
-
if (type && type === TYPE_TRUSTED) {
|
|
118
|
-
return `${apiUrl}app/trustedPipelines/${name}${queryString}`;
|
|
119
|
-
}
|
|
120
|
-
return `${apiUrl}app/pipelines/${name}${queryString}`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* @return {boolean}
|
|
125
|
-
*/
|
|
126
|
-
get isPipelineRequest() {
|
|
127
|
-
return this.command.c === appCommands.COMMAND_SEND_PIPELINE_REQUEST;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @return {string}
|
|
132
|
-
*/
|
|
133
|
-
get suffix() {
|
|
134
|
-
if (this.command.c === appCommands.COMMAND_GET_WEBSTORAGE_ENTRY) {
|
|
135
|
-
return 'web_storage';
|
|
136
|
-
}
|
|
137
|
-
if (this.command.c === appCommands.COMMAND_SEND_HTTP_REQUEST) {
|
|
138
|
-
return 'http_request';
|
|
139
|
-
}
|
|
140
|
-
return '';
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @return {string}
|
|
145
|
-
*/
|
|
146
|
-
get localURL() {
|
|
147
|
-
return `http://${this.ip}:${this.port}/${this.suffix}`;
|
|
148
|
-
}
|
|
149
|
-
|
|
77
|
+
var _proto = BrowserConnector.prototype;
|
|
150
78
|
/**
|
|
151
79
|
* @param {string} libVersion The library version.
|
|
152
80
|
* @returns {string}
|
|
153
81
|
*/
|
|
154
|
-
getRequestBody(libVersion) {
|
|
82
|
+
_proto.getRequestBody = function getRequestBody(libVersion) {
|
|
155
83
|
if (this.isPipelineRequest) {
|
|
156
84
|
const {
|
|
157
85
|
p
|
|
@@ -172,8 +100,8 @@ class BrowserConnector {
|
|
|
172
100
|
* @param {Object} command The command to dispatch.
|
|
173
101
|
* @param {string} libVersion The lib version for the command.
|
|
174
102
|
* @return {BrowserConnector}
|
|
175
|
-
|
|
176
|
-
dispatchCommandForVersion(command, libVersion) {
|
|
103
|
+
*/;
|
|
104
|
+
_proto.dispatchCommandForVersion = function dispatchCommandForVersion(command, libVersion) {
|
|
177
105
|
this.command = command;
|
|
178
106
|
const {
|
|
179
107
|
c: name
|
|
@@ -193,6 +121,95 @@ class BrowserConnector {
|
|
|
193
121
|
fetch(URL, options).then(response => response.json()).then(this.processResponse).catch(err => err && logger.error(err));
|
|
194
122
|
}
|
|
195
123
|
return this;
|
|
196
|
-
}
|
|
197
|
-
|
|
124
|
+
};
|
|
125
|
+
return _createClass(BrowserConnector, [{
|
|
126
|
+
key: "requestType",
|
|
127
|
+
get:
|
|
128
|
+
/**
|
|
129
|
+
* @return {string}
|
|
130
|
+
*/
|
|
131
|
+
function () {
|
|
132
|
+
if (!this.isPipelineRequest) {
|
|
133
|
+
return requestTypes.REQUEST_TYPE_POST;
|
|
134
|
+
}
|
|
135
|
+
const segments = this.command.p.name.split('.');
|
|
136
|
+
if (segments[2].startsWith('get')) {
|
|
137
|
+
return requestTypes.REQUEST_TYPE_GET;
|
|
138
|
+
}
|
|
139
|
+
return requestTypes.REQUEST_TYPE_POST;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @return {boolean}
|
|
144
|
+
*/
|
|
145
|
+
}, {
|
|
146
|
+
key: "isGET",
|
|
147
|
+
get: function () {
|
|
148
|
+
return this.requestType === requestTypes.REQUEST_TYPE_GET;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @return {boolean}
|
|
153
|
+
*/
|
|
154
|
+
}, {
|
|
155
|
+
key: "isPOST",
|
|
156
|
+
get: function () {
|
|
157
|
+
return this.requestType === requestTypes.REQUEST_TYPE_POST;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @return {string}
|
|
162
|
+
*/
|
|
163
|
+
}, {
|
|
164
|
+
key: "connectUrl",
|
|
165
|
+
get: function () {
|
|
166
|
+
const {
|
|
167
|
+
apiUrl = ''
|
|
168
|
+
} = this.appConfig;
|
|
169
|
+
const {
|
|
170
|
+
name,
|
|
171
|
+
type,
|
|
172
|
+
input
|
|
173
|
+
} = this.command.p;
|
|
174
|
+
const queryString = this.buildQueryString(input);
|
|
175
|
+
if (type && type === TYPE_TRUSTED) {
|
|
176
|
+
return `${apiUrl}app/trustedPipelines/${name}${queryString}`;
|
|
177
|
+
}
|
|
178
|
+
return `${apiUrl}app/pipelines/${name}${queryString}`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @return {boolean}
|
|
183
|
+
*/
|
|
184
|
+
}, {
|
|
185
|
+
key: "isPipelineRequest",
|
|
186
|
+
get: function () {
|
|
187
|
+
return this.command.c === appCommands.COMMAND_SEND_PIPELINE_REQUEST;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @return {string}
|
|
192
|
+
*/
|
|
193
|
+
}, {
|
|
194
|
+
key: "suffix",
|
|
195
|
+
get: function () {
|
|
196
|
+
if (this.command.c === appCommands.COMMAND_GET_WEBSTORAGE_ENTRY) {
|
|
197
|
+
return 'web_storage';
|
|
198
|
+
}
|
|
199
|
+
if (this.command.c === appCommands.COMMAND_SEND_HTTP_REQUEST) {
|
|
200
|
+
return 'http_request';
|
|
201
|
+
}
|
|
202
|
+
return '';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @return {string}
|
|
207
|
+
*/
|
|
208
|
+
}, {
|
|
209
|
+
key: "localURL",
|
|
210
|
+
get: function () {
|
|
211
|
+
return `http://${this.ip}:${this.port}/${this.suffix}`;
|
|
212
|
+
}
|
|
213
|
+
}]);
|
|
214
|
+
}();
|
|
198
215
|
export default BrowserConnector;
|
|
@@ -3,11 +3,11 @@ import { logger } from "../../helpers";
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates an action handler API.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
let Conditioner = /*#__PURE__*/function () {
|
|
7
7
|
/**
|
|
8
8
|
* @param {Map} conditions conditions
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
function Conditioner(conditions) {
|
|
11
11
|
this.conditions = conditions || new Map();
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -17,7 +17,8 @@ class Conditioner {
|
|
|
17
17
|
* @param {number} priority conditioner priority
|
|
18
18
|
* @return {Conditioner}
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
var _proto = Conditioner.prototype;
|
|
21
|
+
_proto.addConditioner = function addConditioner(name, conditioner, priority = 1) {
|
|
21
22
|
if (typeof conditioner !== 'function') {
|
|
22
23
|
throw new Error(`Conditioners need to be of type function. Received: '${typeof conditioner}'`);
|
|
23
24
|
}
|
|
@@ -31,8 +32,8 @@ class Conditioner {
|
|
|
31
32
|
/**
|
|
32
33
|
* @param {string} name The name of the registered conditioner.
|
|
33
34
|
* @return {Conditioner}
|
|
34
|
-
|
|
35
|
-
removeConditioner(name) {
|
|
35
|
+
*/;
|
|
36
|
+
_proto.removeConditioner = function removeConditioner(name) {
|
|
36
37
|
if (!this.conditions.has(name)) {
|
|
37
38
|
logger.warn(`Couldn't remove conditioner. '${name}' no found.`);
|
|
38
39
|
return this;
|
|
@@ -44,8 +45,8 @@ class Conditioner {
|
|
|
44
45
|
/**
|
|
45
46
|
* @param {string} name The name of the conditioner to eliminate.
|
|
46
47
|
* @return {Conditioner} new instance with cloned conditions
|
|
47
|
-
|
|
48
|
-
without(name) {
|
|
48
|
+
*/;
|
|
49
|
+
_proto.without = function without(name) {
|
|
49
50
|
const clonedConditions = new Map(this.conditions);
|
|
50
51
|
if (clonedConditions.has(name)) {
|
|
51
52
|
clonedConditions.delete(name);
|
|
@@ -56,8 +57,8 @@ class Conditioner {
|
|
|
56
57
|
/**
|
|
57
58
|
* Resolves if all conditions are fulfilled.
|
|
58
59
|
* @return {Promise}
|
|
59
|
-
|
|
60
|
-
check() {
|
|
60
|
+
*/;
|
|
61
|
+
_proto.check = function check() {
|
|
61
62
|
return new Promise(async (resolve, reject) => {
|
|
62
63
|
const sorted = Array.from(this.conditions.values()).sort((a, b) => {
|
|
63
64
|
if (a.priority === b.priority) {
|
|
@@ -73,14 +74,16 @@ class Conditioner {
|
|
|
73
74
|
const conditionResult = await condition.conditioner();
|
|
74
75
|
if (conditionResult === false) {
|
|
75
76
|
logger.warn('conditioner failed', i, condition, this.conditions);
|
|
76
|
-
|
|
77
|
+
resolve(false);
|
|
78
|
+
return;
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
resolve(true);
|
|
80
82
|
} catch (error) {
|
|
81
|
-
|
|
83
|
+
reject(error);
|
|
82
84
|
}
|
|
83
85
|
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
+
};
|
|
87
|
+
return Conditioner;
|
|
88
|
+
}();
|
|
86
89
|
export default Conditioner;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import event from "../Event";
|
|
2
3
|
import AppCommand from "../AppCommand";
|
|
3
4
|
import Request from "../Request";
|
|
@@ -7,18 +8,20 @@ import { logger, ajaxUrl } from "../../helpers";
|
|
|
7
8
|
/**
|
|
8
9
|
* The DataRequest class. It is the interface to the legacy system.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
let DataRequest = /*#__PURE__*/function (_Request) {
|
|
11
12
|
/**
|
|
12
13
|
* Initializes the DataRequest object
|
|
13
14
|
* @param {string} src The source url
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
function DataRequest(src) {
|
|
17
|
+
var _this;
|
|
18
|
+
_this = _Request.call(this) || this;
|
|
19
|
+
_this.src = src;
|
|
20
|
+
_this.payload = {};
|
|
21
|
+
_this.noCache = true;
|
|
22
|
+
_this.createSerial(_this.src);
|
|
23
|
+
_this.createEventCallbackName('dataResponse');
|
|
24
|
+
return _this;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -26,7 +29,9 @@ class DataRequest extends Request {
|
|
|
26
29
|
* @param {Object|string} [payload={}] The payload to send with the request
|
|
27
30
|
* @returns {DataRequest}
|
|
28
31
|
*/
|
|
29
|
-
|
|
32
|
+
_inheritsLoose(DataRequest, _Request);
|
|
33
|
+
var _proto = DataRequest.prototype;
|
|
34
|
+
_proto.setPayload = function setPayload(payload = {}) {
|
|
30
35
|
this.payload = payload;
|
|
31
36
|
return this;
|
|
32
37
|
}
|
|
@@ -35,8 +40,8 @@ class DataRequest extends Request {
|
|
|
35
40
|
* Decides if the response of the DataRequest will be cached
|
|
36
41
|
* @param {boolean} [noCache=true] If set to `true`, then the DataResponse will not be cached
|
|
37
42
|
* @returns {DataRequest} The DataRequest
|
|
38
|
-
|
|
39
|
-
setNoCache(noCache = true) {
|
|
43
|
+
*/;
|
|
44
|
+
_proto.setNoCache = function setNoCache(noCache = true) {
|
|
40
45
|
this.noCache = noCache;
|
|
41
46
|
return this;
|
|
42
47
|
}
|
|
@@ -44,8 +49,8 @@ class DataRequest extends Request {
|
|
|
44
49
|
/**
|
|
45
50
|
* Determines the correct content type for the request payload.
|
|
46
51
|
* @return {string} The content type
|
|
47
|
-
|
|
48
|
-
getContentType() {
|
|
52
|
+
*/;
|
|
53
|
+
_proto.getContentType = function getContentType() {
|
|
49
54
|
let contentType = 'text/plain';
|
|
50
55
|
if (typeof this.payload === 'object' || typeof this.payload === 'string' && this.payload.search(/_method=POST/) === 0) {
|
|
51
56
|
contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
|
|
@@ -56,8 +61,8 @@ class DataRequest extends Request {
|
|
|
56
61
|
/**
|
|
57
62
|
* Creates the data request body from the payload.
|
|
58
63
|
* @return {string} The request body
|
|
59
|
-
|
|
60
|
-
getRequestBody() {
|
|
64
|
+
*/;
|
|
65
|
+
_proto.getRequestBody = function getRequestBody() {
|
|
61
66
|
/**
|
|
62
67
|
* Serializes a JavaScript object for a data request body.
|
|
63
68
|
* @param {Object} obj The object that shall be serialized.
|
|
@@ -94,8 +99,8 @@ class DataRequest extends Request {
|
|
|
94
99
|
* Dispatches the data request.
|
|
95
100
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
96
101
|
* @param {Function} reject The reject() callback of the request promise.
|
|
97
|
-
|
|
98
|
-
onDispatch(resolve, reject) {
|
|
102
|
+
*/;
|
|
103
|
+
_proto.onDispatch = function onDispatch(resolve, reject) {
|
|
99
104
|
// Add the request to the buffer.
|
|
100
105
|
requestBuffer.add(this, this.serial);
|
|
101
106
|
const requestCallbackName = this.getEventCallbackName();
|
|
@@ -137,6 +142,7 @@ class DataRequest extends Request {
|
|
|
137
142
|
bodyContentType: this.getContentType(),
|
|
138
143
|
noCache: this.noCache
|
|
139
144
|
});
|
|
140
|
-
}
|
|
141
|
-
|
|
145
|
+
};
|
|
146
|
+
return DataRequest;
|
|
147
|
+
}(Request);
|
|
142
148
|
export default DataRequest;
|
|
@@ -5,13 +5,13 @@ import event from "../Event";
|
|
|
5
5
|
* The DevServerBridge emulates the SGJavaScriptBridge within browser environments.
|
|
6
6
|
* It routes supported app commands to the Frontend SDK which can mimic the behavior of the app.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
let DevServerBridge = /*#__PURE__*/function () {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor.
|
|
11
11
|
* @param {string} ip The IP of the dev server.
|
|
12
12
|
* @param {number} port The port of the dev server.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
function DevServerBridge(ip = process.env.IP, port = process.env.PORT) {
|
|
15
15
|
this.ip = ip;
|
|
16
16
|
this.port = port;
|
|
17
17
|
this.supportedCommands = ['sendPipelineRequest', 'sendHttpRequest', 'sendDataRequest', 'getWebStorageEntry'];
|
|
@@ -23,7 +23,8 @@ class DevServerBridge {
|
|
|
23
23
|
* @param {string} libVersion The lib version for the command.
|
|
24
24
|
* @return {DevServerBridge}
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
var _proto = DevServerBridge.prototype;
|
|
27
|
+
_proto.dispatchCommandsForVersion = function dispatchCommandsForVersion(commands, libVersion) {
|
|
27
28
|
if (Array.isArray(commands)) {
|
|
28
29
|
commands.forEach(command => {
|
|
29
30
|
this.dispatchCommandForVersion(command, libVersion);
|
|
@@ -37,8 +38,8 @@ class DevServerBridge {
|
|
|
37
38
|
* @param {Object} command The command to dispatch.
|
|
38
39
|
* @param {string} libVersion The lib version for the command.
|
|
39
40
|
* @return {DevServerBridge}
|
|
40
|
-
|
|
41
|
-
dispatchCommandForVersion(command, libVersion) {
|
|
41
|
+
*/;
|
|
42
|
+
_proto.dispatchCommandForVersion = function dispatchCommandForVersion(command, libVersion) {
|
|
42
43
|
const {
|
|
43
44
|
c: name
|
|
44
45
|
} = command || {};
|
|
@@ -70,8 +71,8 @@ class DevServerBridge {
|
|
|
70
71
|
* Handles a response of the dev server.
|
|
71
72
|
* @param {Object} response The server response.
|
|
72
73
|
* @return {DevServerBridge}
|
|
73
|
-
|
|
74
|
-
processDevServerResponse(response) {
|
|
74
|
+
*/;
|
|
75
|
+
_proto.processDevServerResponse = function processDevServerResponse(response) {
|
|
75
76
|
const {
|
|
76
77
|
cmds = []
|
|
77
78
|
} = response || {};
|
|
@@ -100,6 +101,7 @@ class DevServerBridge {
|
|
|
100
101
|
event.call(name, args);
|
|
101
102
|
});
|
|
102
103
|
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
104
|
+
};
|
|
105
|
+
return DevServerBridge;
|
|
106
|
+
}();
|
|
105
107
|
export default DevServerBridge;
|
|
@@ -12,7 +12,7 @@ global.process.env = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
// Mocks of the global Headers class.
|
|
15
|
-
global.Headers =
|
|
15
|
+
global.Headers = function Headers() {};
|
|
16
16
|
|
|
17
17
|
// Create a mock for the fetch method.
|
|
18
18
|
const mockedFetchResponse = {};
|
|
@@ -24,7 +24,7 @@ beforeAll(() => {
|
|
|
24
24
|
// Create a mock for the Event class.
|
|
25
25
|
const mockedEventCall = jest.fn();
|
|
26
26
|
jest.mock("../Event", () => ({
|
|
27
|
-
call: (...args) => mockedEventCall(
|
|
27
|
+
call: (...args) => mockedEventCall.apply(void 0, args)
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
30
|
// Create a mock for the error logger.
|
|
@@ -32,7 +32,7 @@ const mockedLoggerError = jest.fn();
|
|
|
32
32
|
jest.mock("../../helpers", () => ({
|
|
33
33
|
logger: {
|
|
34
34
|
error: (...args) => {
|
|
35
|
-
mockedLoggerError(
|
|
35
|
+
mockedLoggerError.apply(void 0, args);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}));
|
|
@@ -47,7 +47,7 @@ const updateMockedFetch = (throwError = false) => {
|
|
|
47
47
|
mockedFetch = throwError ? jest.fn().mockRejectedValue(new Error()) : jest.fn().mockResolvedValue({
|
|
48
48
|
json: () => mockedFetchResponse
|
|
49
49
|
});
|
|
50
|
-
global.fetch.mockImplementation((...args) => mockedFetch(
|
|
50
|
+
global.fetch.mockImplementation((...args) => mockedFetch.apply(void 0, args));
|
|
51
51
|
};
|
|
52
52
|
describe('DevServerBridge', () => {
|
|
53
53
|
let instance;
|
|
@@ -7,11 +7,11 @@ const pipelineVersionSuffix = /\.v\d+$/;
|
|
|
7
7
|
/**
|
|
8
8
|
* The ErrorManager class.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
let ErrorManager = /*#__PURE__*/function () {
|
|
11
11
|
/**
|
|
12
12
|
* Constructor.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
function ErrorManager() {
|
|
15
15
|
/**
|
|
16
16
|
* Calls dispatch() as an interval.
|
|
17
17
|
*/
|
|
@@ -75,7 +75,8 @@ class ErrorManager {
|
|
|
75
75
|
* @param {{ code: string, context: string, source: string }} error The error object.
|
|
76
76
|
* @returns {string|null}
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
var _proto = ErrorManager.prototype;
|
|
79
|
+
_proto.getMessage = function getMessage(error) {
|
|
79
80
|
if (!this.validate(error)) {
|
|
80
81
|
return null;
|
|
81
82
|
}
|
|
@@ -102,8 +103,8 @@ class ErrorManager {
|
|
|
102
103
|
* @param {string} errorTemplate.message The default error message.
|
|
103
104
|
* @param {string} [errorTemplate.source=SOURCE_PIPELINE] The source of the error.
|
|
104
105
|
* @returns {ErrorManager}
|
|
105
|
-
|
|
106
|
-
setMessage(errorTemplate = {}) {
|
|
106
|
+
*/;
|
|
107
|
+
_proto.setMessage = function setMessage(errorTemplate = {}) {
|
|
107
108
|
const error = {
|
|
108
109
|
source: SOURCE_PIPELINE,
|
|
109
110
|
...errorTemplate
|
|
@@ -127,8 +128,8 @@ class ErrorManager {
|
|
|
127
128
|
* @param {string} error.message The default error message.
|
|
128
129
|
* @param {string} error.source The source of the error.
|
|
129
130
|
* @param {Object} error.meta Some meta data.
|
|
130
|
-
|
|
131
|
-
queue(error = {}) {
|
|
131
|
+
*/;
|
|
132
|
+
_proto.queue = function queue(error = {}) {
|
|
132
133
|
if (!this.validate(error)) {
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
@@ -157,7 +158,8 @@ class ErrorManager {
|
|
|
157
158
|
if (!this.timer) {
|
|
158
159
|
this.startTimer();
|
|
159
160
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
161
|
+
};
|
|
162
|
+
return ErrorManager;
|
|
163
|
+
}();
|
|
162
164
|
/** @type {ErrorManager} */
|
|
163
165
|
export default new ErrorManager();
|
package/classes/Event/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import EventEmitter from 'events';
|
|
2
3
|
import { logger } from "../../helpers";
|
|
3
4
|
const HANDLER_ADD = 'add';
|
|
@@ -8,14 +9,15 @@ const HANDLER_REMOVE = 'remove';
|
|
|
8
9
|
/**
|
|
9
10
|
* Event class.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
let Event = /*#__PURE__*/function (_EventEmitter) {
|
|
12
13
|
/**
|
|
13
14
|
* Constructor.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
function Event() {
|
|
17
|
+
var _this;
|
|
18
|
+
_this = _EventEmitter.call(this) || this;
|
|
19
|
+
_this.events = new Set();
|
|
20
|
+
_this.setMaxListeners(20);
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* A global implementation of the call function to make it accessible to the app.
|
|
@@ -27,21 +29,25 @@ class Event extends EventEmitter {
|
|
|
27
29
|
const legacy = window.SGEvent.__call;
|
|
28
30
|
if (typeof legacy !== 'function') {
|
|
29
31
|
// eslint-disable-next-line no-underscore-dangle
|
|
30
|
-
window.SGEvent.__call =
|
|
32
|
+
window.SGEvent.__call = _this.call.bind(_this);
|
|
31
33
|
} else {
|
|
32
34
|
// eslint-disable-next-line no-underscore-dangle
|
|
33
35
|
window.SGEvent.__call = (...args) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
var _this2;
|
|
37
|
+
legacy.apply(void 0, args);
|
|
38
|
+
(_this2 = _this).call.apply(_this2, args);
|
|
36
39
|
};
|
|
37
40
|
}
|
|
41
|
+
return _this;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Registers a new event
|
|
42
46
|
* @param {string} eventName The new event name
|
|
43
47
|
*/
|
|
44
|
-
|
|
48
|
+
_inheritsLoose(Event, _EventEmitter);
|
|
49
|
+
var _proto = Event.prototype;
|
|
50
|
+
_proto.registerEvent = function registerEvent(eventName) {
|
|
45
51
|
this.events.add(eventName);
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -49,8 +55,8 @@ class Event extends EventEmitter {
|
|
|
49
55
|
* Registers a callback function for one or multiple events.
|
|
50
56
|
* @param {string} events A single event or multiple events separated by comma.
|
|
51
57
|
* @param {Function} callback The callback function.
|
|
52
|
-
|
|
53
|
-
addCallback(events, callback) {
|
|
58
|
+
*/;
|
|
59
|
+
_proto.addCallback = function addCallback(events, callback) {
|
|
54
60
|
this.handleCallbacks(HANDLER_ADD, events, callback);
|
|
55
61
|
}
|
|
56
62
|
|
|
@@ -58,8 +64,8 @@ class Event extends EventEmitter {
|
|
|
58
64
|
* De-registers a callback function for one or multiple events.
|
|
59
65
|
* @param {string} events A single event or multiple events separated by comma.
|
|
60
66
|
* @param {Function} callback The callback function.
|
|
61
|
-
|
|
62
|
-
removeCallback(events, callback) {
|
|
67
|
+
*/;
|
|
68
|
+
_proto.removeCallback = function removeCallback(events, callback) {
|
|
63
69
|
this.handleCallbacks(HANDLER_REMOVE, events, callback);
|
|
64
70
|
}
|
|
65
71
|
|
|
@@ -68,8 +74,8 @@ class Event extends EventEmitter {
|
|
|
68
74
|
* @param {string} type What type of action should be performed.
|
|
69
75
|
* @param {string} events A single event or multiple events separated by comma.
|
|
70
76
|
* @param {Function} callback The callback function.
|
|
71
|
-
|
|
72
|
-
handleCallbacks(type, events, callback) {
|
|
77
|
+
*/;
|
|
78
|
+
_proto.handleCallbacks = function handleCallbacks(type, events, callback) {
|
|
73
79
|
const eventNames = events.split(',');
|
|
74
80
|
eventNames.forEach(event => {
|
|
75
81
|
switch (type) {
|
|
@@ -89,8 +95,8 @@ class Event extends EventEmitter {
|
|
|
89
95
|
* Triggers an event.
|
|
90
96
|
* @param {string} event The event name.
|
|
91
97
|
* @param {Object} params Custom parameters for the event.
|
|
92
|
-
|
|
93
|
-
trigger(event, params = null) {
|
|
98
|
+
*/;
|
|
99
|
+
_proto.trigger = function trigger(event, params = null) {
|
|
94
100
|
setTimeout(() => this.emit(event, params), 0);
|
|
95
101
|
}
|
|
96
102
|
|
|
@@ -98,8 +104,8 @@ class Event extends EventEmitter {
|
|
|
98
104
|
* This function will be called by the app to trigger events.
|
|
99
105
|
* @param {string} event The event name.
|
|
100
106
|
* @param {Array} [parameters=[]] The event parameters.
|
|
101
|
-
|
|
102
|
-
call(event, parameters = []) {
|
|
107
|
+
*/;
|
|
108
|
+
_proto.call = function call(event, parameters = []) {
|
|
103
109
|
let eventName = event;
|
|
104
110
|
|
|
105
111
|
/**
|
|
@@ -113,15 +119,14 @@ class Event extends EventEmitter {
|
|
|
113
119
|
} else if (['dataResponse', 'webStorageResponse'].includes(event) || Array.from(this.events).includes(event)) {
|
|
114
120
|
eventName += `:${parameters[0]}`;
|
|
115
121
|
}
|
|
116
|
-
const calledEvent = this.emit(
|
|
122
|
+
const calledEvent = this.emit.apply(this, [eventName].concat(parameters));
|
|
117
123
|
if (!calledEvent) {
|
|
118
124
|
logger.warn(`Attempt to call unknown event: ${eventName}`);
|
|
119
125
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
};
|
|
127
|
+
return Event;
|
|
128
|
+
}(EventEmitter);
|
|
123
129
|
/* eslint-enable extra-rules/potential-point-free */
|
|
124
|
-
|
|
125
130
|
// TODO:
|
|
126
131
|
// We need this as a temporary solution because of double node_modules form extensions and theme.
|
|
127
132
|
if (!window.TmpEventInstance) {
|