@shopgate/pwa-core 7.30.0-alpha.7 → 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
|
@@ -1,2 +1,333 @@
|
|
|
1
|
-
import PipelineRequest,{DEFAULT_VERSION,DEFAULT_RETRIES,DEFAULT_MAX_RETRIES,DEFAULT_INPUT,DEFAULT_TIMEOUT,DEFAULT_MAX_TIMEOUT,DEFAULT_PROCESSED,DEFAULT_HANDLE_ERROR}
|
|
2
|
-
|
|
1
|
+
import PipelineRequest, { DEFAULT_VERSION, DEFAULT_RETRIES, DEFAULT_MAX_RETRIES, DEFAULT_INPUT, DEFAULT_TIMEOUT, DEFAULT_MAX_TIMEOUT, DEFAULT_PROCESSED, DEFAULT_HANDLE_ERROR } from '.';
|
|
2
|
+
import * as processTypes from "../../constants/ProcessTypes";
|
|
3
|
+
import * as errorHandleTypes from "../../constants/ErrorHandleTypes";
|
|
4
|
+
let request;
|
|
5
|
+
const mockedWarn = jest.fn();
|
|
6
|
+
jest.mock("../../helpers", () => ({
|
|
7
|
+
logger: {
|
|
8
|
+
warn: (...args) => mockedWarn(...args)
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
11
|
+
describe('PipelineRequest', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
request = new PipelineRequest('testPipeline');
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it('should throw if no pipeline name is set', done => {
|
|
17
|
+
try {
|
|
18
|
+
// eslint-disable-next-line no-new
|
|
19
|
+
new PipelineRequest();
|
|
20
|
+
done('Did not throw');
|
|
21
|
+
} catch (e) {
|
|
22
|
+
done();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
it('should be instanciatable', () => {
|
|
26
|
+
expect(request instanceof PipelineRequest).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('has a default version', () => {
|
|
29
|
+
expect(request.version).toEqual(DEFAULT_VERSION);
|
|
30
|
+
});
|
|
31
|
+
it('has a default input', () => {
|
|
32
|
+
expect(request.input).toEqual(DEFAULT_INPUT);
|
|
33
|
+
});
|
|
34
|
+
it('has trusted set to false by default', () => {
|
|
35
|
+
expect(request.trusted).toEqual(false);
|
|
36
|
+
});
|
|
37
|
+
it('has a default retries', () => {
|
|
38
|
+
expect(request.retries).toEqual(DEFAULT_RETRIES);
|
|
39
|
+
});
|
|
40
|
+
it('has a default timeout', () => {
|
|
41
|
+
expect(request.timeout).toEqual(DEFAULT_TIMEOUT);
|
|
42
|
+
});
|
|
43
|
+
it('has a default process handling', () => {
|
|
44
|
+
expect(request.process).toEqual(DEFAULT_PROCESSED);
|
|
45
|
+
});
|
|
46
|
+
it('has a default error handling', () => {
|
|
47
|
+
expect(request.handleErrors).toEqual(DEFAULT_HANDLE_ERROR);
|
|
48
|
+
});
|
|
49
|
+
describe('setVersion()', () => {
|
|
50
|
+
it('should throw if input is not a number', done => {
|
|
51
|
+
try {
|
|
52
|
+
request.setVersion('a string');
|
|
53
|
+
done('Did not throw');
|
|
54
|
+
} catch (e) {
|
|
55
|
+
done();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
it('should throw if it is a negative number', done => {
|
|
59
|
+
try {
|
|
60
|
+
request.setVersion(-1);
|
|
61
|
+
done('Did not throw');
|
|
62
|
+
} catch (e) {
|
|
63
|
+
done();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
it('should throw if the value is 0', done => {
|
|
67
|
+
try {
|
|
68
|
+
request.setVersion(0);
|
|
69
|
+
done('Did not throw');
|
|
70
|
+
} catch (e) {
|
|
71
|
+
done();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
it('should set to default if no parameter supplied', () => {
|
|
75
|
+
request.setVersion();
|
|
76
|
+
expect(request.version).toEqual(DEFAULT_VERSION);
|
|
77
|
+
});
|
|
78
|
+
it('should set the new timeout', () => {
|
|
79
|
+
request.setVersion(2);
|
|
80
|
+
expect(request.version).toEqual(2);
|
|
81
|
+
});
|
|
82
|
+
it('should return a class instance', () => {
|
|
83
|
+
const value = request.setVersion(2);
|
|
84
|
+
expect(value instanceof PipelineRequest).toEqual(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('setInput()', () => {
|
|
88
|
+
it('should throw if input is a string', done => {
|
|
89
|
+
try {
|
|
90
|
+
request.setInput('some input');
|
|
91
|
+
done('Did not throw');
|
|
92
|
+
} catch (e) {
|
|
93
|
+
done();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
it('should throw if input is a number', done => {
|
|
97
|
+
try {
|
|
98
|
+
request.setInput(123);
|
|
99
|
+
done('Did not throw');
|
|
100
|
+
} catch (e) {
|
|
101
|
+
done();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
it('should throw if input is an array', done => {
|
|
105
|
+
try {
|
|
106
|
+
request.setInput(['some value']);
|
|
107
|
+
done('Did not throw');
|
|
108
|
+
} catch (e) {
|
|
109
|
+
done();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
it('should set to default if no parameter supplied', () => {
|
|
113
|
+
request.setInput();
|
|
114
|
+
expect(request.input).toEqual(DEFAULT_INPUT);
|
|
115
|
+
});
|
|
116
|
+
it('should set the new input', () => {
|
|
117
|
+
const input = {
|
|
118
|
+
someKey: 'someValue'
|
|
119
|
+
};
|
|
120
|
+
request.setInput(input);
|
|
121
|
+
expect(request.input).toEqual(input);
|
|
122
|
+
});
|
|
123
|
+
it('should return a class instance', () => {
|
|
124
|
+
const value = request.setInput();
|
|
125
|
+
expect(value instanceof PipelineRequest).toEqual(true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('setTrusted()', () => {
|
|
129
|
+
it('is false by default', () => {
|
|
130
|
+
expect(request.trusted).toEqual(false);
|
|
131
|
+
});
|
|
132
|
+
it('should set it to true', () => {
|
|
133
|
+
request.setTrusted();
|
|
134
|
+
expect(request.trusted).toEqual(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
describe('setRetries()', () => {
|
|
138
|
+
it('should throw if input it not a number', done => {
|
|
139
|
+
try {
|
|
140
|
+
request.setRetries('a string');
|
|
141
|
+
done('Did not throw');
|
|
142
|
+
} catch (e) {
|
|
143
|
+
done();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
it('should throw if its a negative number', done => {
|
|
147
|
+
try {
|
|
148
|
+
request.setRetries(-1);
|
|
149
|
+
done('Did not throw');
|
|
150
|
+
} catch (e) {
|
|
151
|
+
done();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
it('should throw if the value is above max', done => {
|
|
155
|
+
try {
|
|
156
|
+
request.setRetries(DEFAULT_MAX_RETRIES + 1);
|
|
157
|
+
done('Did not throw');
|
|
158
|
+
} catch (e) {
|
|
159
|
+
done();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
it('should set to default if no parameter supplied', () => {
|
|
163
|
+
request.setRetries();
|
|
164
|
+
expect(request.retries).toEqual(DEFAULT_RETRIES);
|
|
165
|
+
});
|
|
166
|
+
it('should set the new retries amount', () => {
|
|
167
|
+
request.setRetries(3);
|
|
168
|
+
expect(request.retries).toEqual(3);
|
|
169
|
+
});
|
|
170
|
+
it('should return a class instance', () => {
|
|
171
|
+
const value = request.setRetries(2);
|
|
172
|
+
expect(value instanceof PipelineRequest).toEqual(true);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe('setTimeout()', () => {
|
|
176
|
+
it('should throw if input it not a number', done => {
|
|
177
|
+
try {
|
|
178
|
+
request.setTimeout('a string');
|
|
179
|
+
done('Did not throw');
|
|
180
|
+
} catch (e) {
|
|
181
|
+
done();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
it('should throw if its a negative number', done => {
|
|
185
|
+
try {
|
|
186
|
+
request.setTimeout(-1);
|
|
187
|
+
done('Did not throw');
|
|
188
|
+
} catch (e) {
|
|
189
|
+
done();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
it('should throw if the value is above max', done => {
|
|
193
|
+
try {
|
|
194
|
+
request.setTimeout(DEFAULT_MAX_TIMEOUT + 1000);
|
|
195
|
+
done('Did not throw');
|
|
196
|
+
} catch (e) {
|
|
197
|
+
done();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
it('should set to default if no parameter supplied', () => {
|
|
201
|
+
request.setTimeout();
|
|
202
|
+
expect(request.timeout).toEqual(DEFAULT_TIMEOUT);
|
|
203
|
+
});
|
|
204
|
+
it('should set the new timeout', () => {
|
|
205
|
+
request.setTimeout(2000);
|
|
206
|
+
expect(request.timeout).toEqual(2000);
|
|
207
|
+
});
|
|
208
|
+
it('should return a class instance', () => {
|
|
209
|
+
const value = request.setTimeout(2);
|
|
210
|
+
expect(value instanceof PipelineRequest).toEqual(true);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe('setResponseProcessed()', () => {
|
|
214
|
+
it('should throw if input is a number', done => {
|
|
215
|
+
try {
|
|
216
|
+
request.setResponseProcessed(123);
|
|
217
|
+
done('Did not throw');
|
|
218
|
+
} catch (e) {
|
|
219
|
+
done();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
it('should throw if input is an array', done => {
|
|
223
|
+
try {
|
|
224
|
+
request.setResponseProcessed(['some value']);
|
|
225
|
+
done('Did not throw');
|
|
226
|
+
} catch (e) {
|
|
227
|
+
done();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
it('should throw if input is an object', done => {
|
|
231
|
+
try {
|
|
232
|
+
request.setResponseProcessed({
|
|
233
|
+
someKey: 'someValue'
|
|
234
|
+
});
|
|
235
|
+
done('Did not throw');
|
|
236
|
+
} catch (e) {
|
|
237
|
+
done();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
it('should throw if input not one of the possible values', done => {
|
|
241
|
+
try {
|
|
242
|
+
request.setResponseProcessed('SOME_WEIRD_THING');
|
|
243
|
+
done('Did not throw');
|
|
244
|
+
} catch (e) {
|
|
245
|
+
done();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
it('should set to default if no parameter supplied', () => {
|
|
249
|
+
request.setResponseProcessed();
|
|
250
|
+
expect(request.process).toEqual(DEFAULT_PROCESSED);
|
|
251
|
+
});
|
|
252
|
+
it('should set the new process', () => {
|
|
253
|
+
request.setResponseProcessed(processTypes.PROCESS_LAST);
|
|
254
|
+
expect(request.process).toEqual(processTypes.PROCESS_LAST);
|
|
255
|
+
});
|
|
256
|
+
it('should return a class instance', () => {
|
|
257
|
+
const value = request.setResponseProcessed();
|
|
258
|
+
expect(value instanceof PipelineRequest).toEqual(true);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
describe('setHandleErrors()', () => {
|
|
262
|
+
it('should throw if input is a number', done => {
|
|
263
|
+
try {
|
|
264
|
+
request.setHandleErrors(123);
|
|
265
|
+
done('Did not throw');
|
|
266
|
+
} catch (e) {
|
|
267
|
+
done();
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
it('should throw if input is an array', done => {
|
|
271
|
+
try {
|
|
272
|
+
request.setHandleErrors(['some value']);
|
|
273
|
+
done('Did not throw');
|
|
274
|
+
} catch (e) {
|
|
275
|
+
done();
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
it('should throw if input is an object', done => {
|
|
279
|
+
try {
|
|
280
|
+
request.setHandleErrors({
|
|
281
|
+
someKey: 'someValue'
|
|
282
|
+
});
|
|
283
|
+
done('Did not throw');
|
|
284
|
+
} catch (e) {
|
|
285
|
+
done();
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
it('should throw if input not one of the possible values', done => {
|
|
289
|
+
try {
|
|
290
|
+
request.setHandleErrors('SOME_WEIRD_THING');
|
|
291
|
+
done('Did not throw');
|
|
292
|
+
} catch (e) {
|
|
293
|
+
done();
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
it('should set to default if no parameter supplied', () => {
|
|
297
|
+
request.setHandleErrors();
|
|
298
|
+
expect(request.handleErrors).toEqual(DEFAULT_HANDLE_ERROR);
|
|
299
|
+
});
|
|
300
|
+
it('should set the new process', () => {
|
|
301
|
+
request.setHandleErrors(errorHandleTypes.ERROR_HANDLE_SUPPRESS);
|
|
302
|
+
expect(request.handleErrors).toEqual(errorHandleTypes.ERROR_HANDLE_SUPPRESS);
|
|
303
|
+
});
|
|
304
|
+
it('should return a class instance', () => {
|
|
305
|
+
const value = request.setHandleErrors();
|
|
306
|
+
expect(value instanceof PipelineRequest).toEqual(true);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
describe('setHandleErrors()', () => {
|
|
310
|
+
it('should set a blacklist of error codes to be not handled', () => {
|
|
311
|
+
const codes = ['ETEST1', 'ETEST2'];
|
|
312
|
+
request.setErrorBlacklist(codes);
|
|
313
|
+
expect(request.errorBlacklist).toEqual(codes);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe('deprecation', () => {
|
|
317
|
+
it('setSuppressErrors', () => {
|
|
318
|
+
request.setSuppressErrors(true);
|
|
319
|
+
expect(request.handleErrors).toEqual(errorHandleTypes.ERROR_HANDLE_SUPPRESS);
|
|
320
|
+
request.setSuppressErrors(false);
|
|
321
|
+
expect(request.handleErrors).toEqual(DEFAULT_HANDLE_ERROR);
|
|
322
|
+
expect(mockedWarn).toHaveBeenCalledTimes(2);
|
|
323
|
+
expect(mockedWarn).toHaveBeenCalledWith('Deprecated: setSuppressErrors() will be removed. Use setHandleErrors() instead!');
|
|
324
|
+
});
|
|
325
|
+
it('setHandledErrors', () => {
|
|
326
|
+
const codes = ['ETEST'];
|
|
327
|
+
request.setHandledErrors(codes);
|
|
328
|
+
expect(request.errorBlacklist).toEqual(codes);
|
|
329
|
+
expect(mockedWarn).toHaveBeenCalledTimes(1);
|
|
330
|
+
expect(mockedWarn).toHaveBeenCalledWith('Deprecated: setHandledErrors() will be removed in favor of setErrorBlacklist()!');
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
@@ -1,14 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* A sequence of pipeline requests.
|
|
3
|
-
*/
|
|
3
|
+
*/
|
|
4
|
+
class PipelineSequence {
|
|
5
|
+
/**
|
|
4
6
|
* Constructor.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
constructor() {
|
|
9
|
+
this.sequence = [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
6
13
|
* Adds a new serial to the sequence.
|
|
7
14
|
* @param {string} serial The pipeline request serial.
|
|
8
|
-
*/
|
|
15
|
+
*/
|
|
16
|
+
set(serial) {
|
|
17
|
+
const index = this.sequence.indexOf(serial);
|
|
18
|
+
if (index < 0) {
|
|
19
|
+
this.sequence.push(serial);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
9
24
|
* Returns the sequence.
|
|
10
25
|
* @return {Array}
|
|
11
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
get() {
|
|
28
|
+
return this.sequence;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
12
32
|
* Removes a serial from the sequence.
|
|
13
33
|
* @param {string} serial The pipeline request serial.
|
|
14
|
-
*/
|
|
34
|
+
*/
|
|
35
|
+
remove(serial) {
|
|
36
|
+
const index = this.sequence.indexOf(serial);
|
|
37
|
+
if (index >= 0) {
|
|
38
|
+
this.sequence.splice(index, 1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export default new PipelineSequence();
|
package/classes/Request/index.js
CHANGED
|
@@ -1,26 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import CryptoJs from 'crypto-js';
|
|
2
|
+
import RequestManager from "../RequestManager";
|
|
3
|
+
import { logger } from "../../helpers";
|
|
4
|
+
|
|
5
|
+
// The default request manager does not cache or treat requests in any special way.
|
|
6
|
+
const defaultRequestManager = new RequestManager();
|
|
7
|
+
|
|
8
|
+
/**
|
|
3
9
|
* The request class.
|
|
4
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
class Request {
|
|
12
|
+
/**
|
|
5
13
|
* The constructor.
|
|
6
14
|
* @param {RequestManager} [manager] The manager for this request.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
*/
|
|
16
|
+
constructor(manager) {
|
|
17
|
+
/**
|
|
18
|
+
* Creates the event callback name from the data request serial.
|
|
19
|
+
* @param {string} callbackKey The callback key to use.
|
|
20
|
+
*/
|
|
21
|
+
this.createEventCallbackName = callbackKey => {
|
|
22
|
+
this.callbackName = `${callbackKey}:${this.serial}`;
|
|
23
|
+
};
|
|
24
|
+
this.serial = null;
|
|
25
|
+
this.callbackName = '';
|
|
26
|
+
this.manager = manager || defaultRequestManager;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
11
30
|
* @return {boolean} Whether there are pending requests of this type.
|
|
12
|
-
*/
|
|
31
|
+
*/
|
|
32
|
+
hasPendingRequests() {
|
|
33
|
+
return this.manager.pendingRequests > 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
13
37
|
* Generates the serial for this data request.
|
|
14
38
|
* @param {string} serialKey The serial key.
|
|
15
|
-
*/
|
|
39
|
+
*/
|
|
40
|
+
createSerial(serialKey) {
|
|
41
|
+
if (!this.serial) {
|
|
42
|
+
this.serial = CryptoJs.MD5(`${serialKey}${Date.now() + Math.random()}`).toString();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
16
46
|
* Returns the event callback name.
|
|
17
47
|
* @returns {string}
|
|
18
|
-
*/
|
|
48
|
+
*/
|
|
49
|
+
getEventCallbackName() {
|
|
50
|
+
return this.callbackName;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
19
54
|
* Dispatches the request.
|
|
20
55
|
* @return {Promise} A promise that is fulfilled when a response is received for this request.
|
|
21
|
-
*/
|
|
56
|
+
*/
|
|
57
|
+
dispatch() {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
this.manager.handleDispatch(this, resolve, reject);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
22
64
|
* On timeout log error. Can be overridden by child classes.
|
|
23
65
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
24
66
|
* @param {Function} reject The reject() callback of the request promise.
|
|
25
|
-
*/
|
|
26
|
-
|
|
67
|
+
*/
|
|
68
|
+
onTimeout(resolve, reject) {
|
|
69
|
+
// eslint-disable-line class-methods-use-this
|
|
70
|
+
logger.error('Request timeout');
|
|
71
|
+
reject('Request timeout');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export default Request;
|
|
@@ -1,16 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { logger } from "../../helpers";
|
|
2
|
+
const REQUEST_BUFFER = 'RequestBuffer';
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* The RequestBuffer class.
|
|
3
6
|
* It stores instances of performing request.
|
|
4
|
-
*/
|
|
5
|
-
|
|
7
|
+
*/
|
|
8
|
+
class RequestBuffer {
|
|
9
|
+
constructor() {
|
|
10
|
+
// Holds the ongoing requests.
|
|
11
|
+
this.requests = {};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
6
14
|
* Adds a new data request to the buffer store.
|
|
7
15
|
* @param {Object} req The request to store.
|
|
8
16
|
* @param {string} serial The serial for the request.
|
|
9
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
add(req, serial) {
|
|
19
|
+
const request = this.requests[serial];
|
|
20
|
+
if (request) {
|
|
21
|
+
logger.error(`${REQUEST_BUFFER}: a request with the serial '${serial}' already exists!`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.requests[serial] = req;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
10
28
|
* Retrieves a data request from the buffer.
|
|
11
29
|
* @param {string} serial The serial for the request.
|
|
12
30
|
* @returns {DataRequest}
|
|
13
|
-
*/
|
|
31
|
+
*/
|
|
32
|
+
get(serial) {
|
|
33
|
+
const request = this.requests[serial];
|
|
34
|
+
if (!request) {
|
|
35
|
+
logger.error(`${REQUEST_BUFFER}: no stored request for the serial '${serial}' found!`);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return request;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
14
42
|
* Removes the data request from the buffer.
|
|
15
43
|
* @param {string} serial The serial for the request.
|
|
16
|
-
*/
|
|
44
|
+
*/
|
|
45
|
+
remove(serial) {
|
|
46
|
+
try {
|
|
47
|
+
delete this.requests[serial];
|
|
48
|
+
} catch (e) {
|
|
49
|
+
logger.error(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export default new RequestBuffer();
|