@ama-sdk/client-fetch 12.5.0-prerelease.18 → 12.5.0-prerelease.2
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/cjs/api-fetch-client.js +66 -97
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +16 -38
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +0 -36
- package/esm2015/api-fetch-client.js +66 -97
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +16 -38
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +0 -36
- package/package.json +13 -17
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +11 -13
- package/src/api-fetch-client.d.ts +1 -1
- package/src/api-fetch-client.d.ts.map +1 -1
- package/src/api-fetch-client.js +11 -13
- package/src/api-fetch-client.js.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts +0 -1
- package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.fetch.js +2 -13
- package/src/plugins/mock-intercept/mock-intercept.fetch.js.map +1 -1
package/cjs/api-fetch-client.js
CHANGED
|
@@ -279,7 +279,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
279
279
|
key: "getRequestOptions",
|
|
280
280
|
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
281
281
|
return _async_to_generator(function() {
|
|
282
|
-
var opts,
|
|
282
|
+
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
283
283
|
return _ts_generator(this, function(_state) {
|
|
284
284
|
switch(_state.label){
|
|
285
285
|
case 0:
|
|
@@ -287,40 +287,25 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
287
287
|
headers: new Headers((0, _core.filterUndefinedValues)(requestOptionsParameters.headers)),
|
|
288
288
|
queryParams: (0, _core.filterUndefinedValues)(requestOptionsParameters.queryParams)
|
|
289
289
|
});
|
|
290
|
-
if (!
|
|
290
|
+
if (!this.options.requestPlugins) return [
|
|
291
291
|
3,
|
|
292
|
-
|
|
293
|
-
];
|
|
294
|
-
return [
|
|
295
|
-
4,
|
|
296
|
-
this.options.requestPlugins(opts)
|
|
297
|
-
];
|
|
298
|
-
case 1:
|
|
299
|
-
_tmp = _state.sent();
|
|
300
|
-
return [
|
|
301
|
-
3,
|
|
302
|
-
3
|
|
292
|
+
8
|
|
303
293
|
];
|
|
304
|
-
case 2:
|
|
305
|
-
_tmp = this.options.requestPlugins;
|
|
306
|
-
_state.label = 3;
|
|
307
|
-
case 3:
|
|
308
|
-
requestPlugins = _tmp;
|
|
309
294
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
310
|
-
_state.label =
|
|
311
|
-
case
|
|
295
|
+
_state.label = 1;
|
|
296
|
+
case 1:
|
|
312
297
|
_state.trys.push([
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
298
|
+
1,
|
|
299
|
+
6,
|
|
300
|
+
7,
|
|
301
|
+
8
|
|
317
302
|
]);
|
|
318
|
-
_iterator = requestPlugins[Symbol.iterator]();
|
|
319
|
-
_state.label =
|
|
320
|
-
case
|
|
303
|
+
_iterator = this.options.requestPlugins[Symbol.iterator]();
|
|
304
|
+
_state.label = 2;
|
|
305
|
+
case 2:
|
|
321
306
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
322
307
|
3,
|
|
323
|
-
|
|
308
|
+
5
|
|
324
309
|
];
|
|
325
310
|
plugin = _step.value;
|
|
326
311
|
return [
|
|
@@ -330,29 +315,29 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
330
315
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
331
316
|
}).transform(opts)
|
|
332
317
|
];
|
|
333
|
-
case
|
|
318
|
+
case 3:
|
|
334
319
|
opts = _state.sent();
|
|
335
|
-
_state.label =
|
|
336
|
-
case
|
|
320
|
+
_state.label = 4;
|
|
321
|
+
case 4:
|
|
337
322
|
_iteratorNormalCompletion = true;
|
|
338
323
|
return [
|
|
339
324
|
3,
|
|
340
|
-
|
|
325
|
+
2
|
|
341
326
|
];
|
|
342
|
-
case
|
|
327
|
+
case 5:
|
|
343
328
|
return [
|
|
344
329
|
3,
|
|
345
|
-
|
|
330
|
+
8
|
|
346
331
|
];
|
|
347
|
-
case
|
|
332
|
+
case 6:
|
|
348
333
|
err = _state.sent();
|
|
349
334
|
_didIteratorError = true;
|
|
350
335
|
_iteratorError = err;
|
|
351
336
|
return [
|
|
352
337
|
3,
|
|
353
|
-
|
|
338
|
+
8
|
|
354
339
|
];
|
|
355
|
-
case
|
|
340
|
+
case 7:
|
|
356
341
|
try {
|
|
357
342
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
358
343
|
_iterator.return();
|
|
@@ -365,7 +350,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
365
350
|
return [
|
|
366
351
|
7
|
|
367
352
|
];
|
|
368
|
-
case
|
|
353
|
+
case 8:
|
|
369
354
|
return [
|
|
370
355
|
2,
|
|
371
356
|
opts
|
|
@@ -416,7 +401,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
416
401
|
key: "processCall",
|
|
417
402
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
418
403
|
return _async_to_generator(function() {
|
|
419
|
-
var _this, response, asyncResponse, root, body, exception, origin,
|
|
404
|
+
var _this, response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
420
405
|
return _ts_generator(this, function(_state) {
|
|
421
406
|
switch(_state.label){
|
|
422
407
|
case 0:
|
|
@@ -426,9 +411,9 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
426
411
|
case 1:
|
|
427
412
|
_state.trys.push([
|
|
428
413
|
1,
|
|
429
|
-
|
|
414
|
+
5,
|
|
430
415
|
,
|
|
431
|
-
|
|
416
|
+
6
|
|
432
417
|
]);
|
|
433
418
|
metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
434
419
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
@@ -438,45 +423,29 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
438
423
|
return controller.abort();
|
|
439
424
|
});
|
|
440
425
|
loadedPlugins = [];
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
];
|
|
455
|
-
case 3:
|
|
456
|
-
_tmp = this.options.fetchPlugins;
|
|
457
|
-
_state.label = 4;
|
|
458
|
-
case 4:
|
|
459
|
-
fetchPlugins = _tmp;
|
|
460
|
-
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(fetchPlugins.map(function(plugin) {
|
|
461
|
-
return plugin.load({
|
|
462
|
-
url: url,
|
|
463
|
-
options: options,
|
|
464
|
-
fetchPlugins: loadedPlugins,
|
|
465
|
-
controller: controller,
|
|
466
|
-
apiClient: _this,
|
|
467
|
-
logger: _this.options.logger
|
|
468
|
-
});
|
|
469
|
-
})));
|
|
426
|
+
if (this.options.fetchPlugins) {
|
|
427
|
+
;
|
|
428
|
+
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
|
|
429
|
+
return plugin.load({
|
|
430
|
+
url: url,
|
|
431
|
+
options: options,
|
|
432
|
+
fetchPlugins: loadedPlugins,
|
|
433
|
+
controller: controller,
|
|
434
|
+
apiClient: _this,
|
|
435
|
+
logger: _this.options.logger
|
|
436
|
+
});
|
|
437
|
+
})));
|
|
438
|
+
}
|
|
470
439
|
return [
|
|
471
440
|
4,
|
|
472
441
|
Promise.all(loadedPlugins.map(function(plugin) {
|
|
473
442
|
return !plugin.canStart || plugin.canStart();
|
|
474
443
|
}))
|
|
475
444
|
];
|
|
476
|
-
case
|
|
445
|
+
case 2:
|
|
477
446
|
canStart = _state.sent();
|
|
478
447
|
isCanceledBy = canStart.indexOf(false);
|
|
479
|
-
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, fetchPlugins[isCanceledBy], {
|
|
448
|
+
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, this.options.fetchPlugins[isCanceledBy], {
|
|
480
449
|
apiName: apiName,
|
|
481
450
|
operationId: operationId,
|
|
482
451
|
url: url,
|
|
@@ -506,19 +475,19 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
506
475
|
4,
|
|
507
476
|
asyncResponse
|
|
508
477
|
];
|
|
509
|
-
case
|
|
478
|
+
case 3:
|
|
510
479
|
response = _state.sent();
|
|
511
480
|
return [
|
|
512
481
|
4,
|
|
513
482
|
response.text()
|
|
514
483
|
];
|
|
515
|
-
case
|
|
484
|
+
case 4:
|
|
516
485
|
body = _state.sent();
|
|
517
486
|
return [
|
|
518
487
|
3,
|
|
519
|
-
|
|
488
|
+
6
|
|
520
489
|
];
|
|
521
|
-
case
|
|
490
|
+
case 5:
|
|
522
491
|
e = _state.sent();
|
|
523
492
|
if (_instanceof(e, _core.CanceledCallError)) {
|
|
524
493
|
exception = e;
|
|
@@ -539,9 +508,9 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
539
508
|
}
|
|
540
509
|
return [
|
|
541
510
|
3,
|
|
542
|
-
|
|
511
|
+
6
|
|
543
512
|
];
|
|
544
|
-
case
|
|
513
|
+
case 6:
|
|
545
514
|
try {
|
|
546
515
|
root = body ? JSON.parse(body) : undefined;
|
|
547
516
|
} catch (e) {
|
|
@@ -573,49 +542,49 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
573
542
|
}) : [];
|
|
574
543
|
parsedData = root;
|
|
575
544
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
576
|
-
_state.label =
|
|
577
|
-
case
|
|
545
|
+
_state.label = 7;
|
|
546
|
+
case 7:
|
|
578
547
|
_state.trys.push([
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
548
|
+
7,
|
|
549
|
+
12,
|
|
550
|
+
13,
|
|
551
|
+
14
|
|
583
552
|
]);
|
|
584
553
|
_iterator1 = replyPlugins[Symbol.iterator]();
|
|
585
|
-
_state.label =
|
|
586
|
-
case
|
|
554
|
+
_state.label = 8;
|
|
555
|
+
case 8:
|
|
587
556
|
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
588
557
|
3,
|
|
589
|
-
|
|
558
|
+
11
|
|
590
559
|
];
|
|
591
560
|
pluginRunner = _step1.value;
|
|
592
561
|
return [
|
|
593
562
|
4,
|
|
594
563
|
pluginRunner.transform(parsedData)
|
|
595
564
|
];
|
|
596
|
-
case
|
|
565
|
+
case 9:
|
|
597
566
|
parsedData = _state.sent();
|
|
598
|
-
_state.label =
|
|
599
|
-
case
|
|
567
|
+
_state.label = 10;
|
|
568
|
+
case 10:
|
|
600
569
|
_iteratorNormalCompletion1 = true;
|
|
601
570
|
return [
|
|
602
571
|
3,
|
|
603
|
-
|
|
572
|
+
8
|
|
604
573
|
];
|
|
605
|
-
case
|
|
574
|
+
case 11:
|
|
606
575
|
return [
|
|
607
576
|
3,
|
|
608
|
-
|
|
577
|
+
14
|
|
609
578
|
];
|
|
610
|
-
case
|
|
579
|
+
case 12:
|
|
611
580
|
err = _state.sent();
|
|
612
581
|
_didIteratorError1 = true;
|
|
613
582
|
_iteratorError1 = err;
|
|
614
583
|
return [
|
|
615
584
|
3,
|
|
616
|
-
|
|
585
|
+
14
|
|
617
586
|
];
|
|
618
|
-
case
|
|
587
|
+
case 13:
|
|
619
588
|
try {
|
|
620
589
|
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
621
590
|
_iterator1.return();
|
|
@@ -628,7 +597,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
628
597
|
return [
|
|
629
598
|
7
|
|
630
599
|
];
|
|
631
|
-
case
|
|
600
|
+
case 14:
|
|
632
601
|
if (exception) {
|
|
633
602
|
throw exception;
|
|
634
603
|
}
|
|
@@ -173,52 +173,30 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
173
173
|
function MockInterceptFetch(options) {
|
|
174
174
|
_class_call_check(this, MockInterceptFetch);
|
|
175
175
|
_define_property(this, "options", void 0);
|
|
176
|
-
_define_property(this, "checkMockInterceptFetchPlugin", void 0);
|
|
177
176
|
this.options = options;
|
|
178
|
-
this.checkMockInterceptFetchPlugin = function(requestPlugins) {
|
|
179
|
-
if (!requestPlugins.some(function(plugin) {
|
|
180
|
-
return _instanceof(plugin, _core.MockInterceptRequest);
|
|
181
|
-
})) {
|
|
182
|
-
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
177
|
}
|
|
186
178
|
_create_class(MockInterceptFetch, [
|
|
187
179
|
{
|
|
188
180
|
key: "load",
|
|
189
181
|
value: function load(context) {
|
|
190
182
|
var _this = this;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
if (!context.apiClient.options.requestPlugins.some(function(plugin) {
|
|
184
|
+
return _instanceof(plugin, _core.MockInterceptRequest);
|
|
185
|
+
})) {
|
|
186
|
+
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
194
187
|
}
|
|
195
188
|
return {
|
|
196
189
|
transform: function(fetchCall) {
|
|
197
190
|
return _async_to_generator(function() {
|
|
198
|
-
var
|
|
191
|
+
var responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
199
192
|
return _ts_generator(this, function(_state) {
|
|
200
193
|
switch(_state.label){
|
|
201
194
|
case 0:
|
|
202
|
-
if (!!Array.isArray(requestPlugins)) return [
|
|
203
|
-
3,
|
|
204
|
-
2
|
|
205
|
-
];
|
|
206
|
-
_1 = (_ = this).checkMockInterceptFetchPlugin;
|
|
207
|
-
return [
|
|
208
|
-
4,
|
|
209
|
-
requestPlugins
|
|
210
|
-
];
|
|
211
|
-
case 1:
|
|
212
|
-
_1.apply(_, [
|
|
213
|
-
_state.sent()
|
|
214
|
-
]);
|
|
215
|
-
_state.label = 2;
|
|
216
|
-
case 2:
|
|
217
195
|
return [
|
|
218
196
|
4,
|
|
219
197
|
this.options.adapter.initialize()
|
|
220
198
|
];
|
|
221
|
-
case
|
|
199
|
+
case 1:
|
|
222
200
|
_state.sent();
|
|
223
201
|
responsePromise = fetchCall;
|
|
224
202
|
if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(_core.CUSTOM_MOCK_OPERATION_ID_HEADER)) {
|
|
@@ -229,40 +207,40 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
229
207
|
}
|
|
230
208
|
if (!(typeof this.options.delayTiming !== 'undefined')) return [
|
|
231
209
|
3,
|
|
232
|
-
|
|
210
|
+
6
|
|
233
211
|
];
|
|
234
212
|
if (!(typeof this.options.delayTiming === 'number')) return [
|
|
235
213
|
3,
|
|
236
|
-
|
|
214
|
+
2
|
|
237
215
|
];
|
|
238
216
|
_tmp = this.options.delayTiming;
|
|
239
217
|
return [
|
|
240
218
|
3,
|
|
241
|
-
|
|
219
|
+
4
|
|
242
220
|
];
|
|
243
|
-
case
|
|
221
|
+
case 2:
|
|
244
222
|
return [
|
|
245
223
|
4,
|
|
246
224
|
this.options.delayTiming(context)
|
|
247
225
|
];
|
|
248
|
-
case
|
|
226
|
+
case 3:
|
|
249
227
|
_tmp = _state.sent();
|
|
250
|
-
_state.label =
|
|
251
|
-
case
|
|
228
|
+
_state.label = 4;
|
|
229
|
+
case 4:
|
|
252
230
|
delay = _tmp;
|
|
253
231
|
return [
|
|
254
232
|
4,
|
|
255
233
|
responsePromise
|
|
256
234
|
];
|
|
257
|
-
case
|
|
235
|
+
case 5:
|
|
258
236
|
resp = _state.sent();
|
|
259
237
|
responsePromise = new Promise(function(resolve) {
|
|
260
238
|
return setTimeout(resolve, delay);
|
|
261
239
|
}).then(function() {
|
|
262
240
|
return resp;
|
|
263
241
|
});
|
|
264
|
-
_state.label =
|
|
265
|
-
case
|
|
242
|
+
_state.label = 6;
|
|
243
|
+
case 6:
|
|
266
244
|
operationId = context.options.headers.get(_core.CUSTOM_MOCK_OPERATION_ID_HEADER);
|
|
267
245
|
try {
|
|
268
246
|
mock = this.options.adapter.getLatestMock(operationId);
|
|
@@ -348,42 +348,6 @@ describe('Mock intercept', function() {
|
|
|
348
348
|
return plugin.load(config);
|
|
349
349
|
}).toThrow();
|
|
350
350
|
});
|
|
351
|
-
it('should throw if there is no request plugin when dynamic', function() {
|
|
352
|
-
return _async_to_generator(function() {
|
|
353
|
-
var config;
|
|
354
|
-
return _ts_generator(this, function(_state) {
|
|
355
|
-
switch(_state.label){
|
|
356
|
-
case 0:
|
|
357
|
-
config = {
|
|
358
|
-
controller: jest.fn(),
|
|
359
|
-
fetchPlugins: [],
|
|
360
|
-
url: 'myurl',
|
|
361
|
-
apiClient: {
|
|
362
|
-
options: {
|
|
363
|
-
requestPlugins: function() {
|
|
364
|
-
return Promise.resolve([]);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
options: {
|
|
369
|
-
headers: new Headers(_define_property({}, _core.CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
return [
|
|
373
|
-
4,
|
|
374
|
-
expect(function() {
|
|
375
|
-
return plugin.load(config).transform({});
|
|
376
|
-
}).rejects.toThrow('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin')
|
|
377
|
-
];
|
|
378
|
-
case 1:
|
|
379
|
-
_state.sent();
|
|
380
|
-
return [
|
|
381
|
-
2
|
|
382
|
-
];
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
})();
|
|
386
|
-
});
|
|
387
351
|
});
|
|
388
352
|
});
|
|
389
353
|
describe('with delay', function() {
|
|
@@ -269,7 +269,7 @@ var DEFAULT_OPTIONS = {
|
|
|
269
269
|
key: "getRequestOptions",
|
|
270
270
|
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
271
271
|
return _async_to_generator(function() {
|
|
272
|
-
var opts,
|
|
272
|
+
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
273
273
|
return _ts_generator(this, function(_state) {
|
|
274
274
|
switch(_state.label){
|
|
275
275
|
case 0:
|
|
@@ -277,40 +277,25 @@ var DEFAULT_OPTIONS = {
|
|
|
277
277
|
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
278
278
|
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
279
279
|
});
|
|
280
|
-
if (!
|
|
280
|
+
if (!this.options.requestPlugins) return [
|
|
281
281
|
3,
|
|
282
|
-
|
|
283
|
-
];
|
|
284
|
-
return [
|
|
285
|
-
4,
|
|
286
|
-
this.options.requestPlugins(opts)
|
|
287
|
-
];
|
|
288
|
-
case 1:
|
|
289
|
-
_tmp = _state.sent();
|
|
290
|
-
return [
|
|
291
|
-
3,
|
|
292
|
-
3
|
|
282
|
+
8
|
|
293
283
|
];
|
|
294
|
-
case 2:
|
|
295
|
-
_tmp = this.options.requestPlugins;
|
|
296
|
-
_state.label = 3;
|
|
297
|
-
case 3:
|
|
298
|
-
requestPlugins = _tmp;
|
|
299
284
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
300
|
-
_state.label =
|
|
301
|
-
case
|
|
285
|
+
_state.label = 1;
|
|
286
|
+
case 1:
|
|
302
287
|
_state.trys.push([
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
288
|
+
1,
|
|
289
|
+
6,
|
|
290
|
+
7,
|
|
291
|
+
8
|
|
307
292
|
]);
|
|
308
|
-
_iterator = requestPlugins[Symbol.iterator]();
|
|
309
|
-
_state.label =
|
|
310
|
-
case
|
|
293
|
+
_iterator = this.options.requestPlugins[Symbol.iterator]();
|
|
294
|
+
_state.label = 2;
|
|
295
|
+
case 2:
|
|
311
296
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
312
297
|
3,
|
|
313
|
-
|
|
298
|
+
5
|
|
314
299
|
];
|
|
315
300
|
plugin = _step.value;
|
|
316
301
|
return [
|
|
@@ -320,29 +305,29 @@ var DEFAULT_OPTIONS = {
|
|
|
320
305
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
321
306
|
}).transform(opts)
|
|
322
307
|
];
|
|
323
|
-
case
|
|
308
|
+
case 3:
|
|
324
309
|
opts = _state.sent();
|
|
325
|
-
_state.label =
|
|
326
|
-
case
|
|
310
|
+
_state.label = 4;
|
|
311
|
+
case 4:
|
|
327
312
|
_iteratorNormalCompletion = true;
|
|
328
313
|
return [
|
|
329
314
|
3,
|
|
330
|
-
|
|
315
|
+
2
|
|
331
316
|
];
|
|
332
|
-
case
|
|
317
|
+
case 5:
|
|
333
318
|
return [
|
|
334
319
|
3,
|
|
335
|
-
|
|
320
|
+
8
|
|
336
321
|
];
|
|
337
|
-
case
|
|
322
|
+
case 6:
|
|
338
323
|
err = _state.sent();
|
|
339
324
|
_didIteratorError = true;
|
|
340
325
|
_iteratorError = err;
|
|
341
326
|
return [
|
|
342
327
|
3,
|
|
343
|
-
|
|
328
|
+
8
|
|
344
329
|
];
|
|
345
|
-
case
|
|
330
|
+
case 7:
|
|
346
331
|
try {
|
|
347
332
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
348
333
|
_iterator.return();
|
|
@@ -355,7 +340,7 @@ var DEFAULT_OPTIONS = {
|
|
|
355
340
|
return [
|
|
356
341
|
7
|
|
357
342
|
];
|
|
358
|
-
case
|
|
343
|
+
case 8:
|
|
359
344
|
return [
|
|
360
345
|
2,
|
|
361
346
|
opts
|
|
@@ -406,7 +391,7 @@ var DEFAULT_OPTIONS = {
|
|
|
406
391
|
key: "processCall",
|
|
407
392
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
408
393
|
return _async_to_generator(function() {
|
|
409
|
-
var _this, response, asyncResponse, root, body, exception, origin,
|
|
394
|
+
var _this, response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
410
395
|
return _ts_generator(this, function(_state) {
|
|
411
396
|
switch(_state.label){
|
|
412
397
|
case 0:
|
|
@@ -416,9 +401,9 @@ var DEFAULT_OPTIONS = {
|
|
|
416
401
|
case 1:
|
|
417
402
|
_state.trys.push([
|
|
418
403
|
1,
|
|
419
|
-
|
|
404
|
+
5,
|
|
420
405
|
,
|
|
421
|
-
|
|
406
|
+
6
|
|
422
407
|
]);
|
|
423
408
|
metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
424
409
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
@@ -428,45 +413,29 @@ var DEFAULT_OPTIONS = {
|
|
|
428
413
|
return controller.abort();
|
|
429
414
|
});
|
|
430
415
|
loadedPlugins = [];
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
];
|
|
445
|
-
case 3:
|
|
446
|
-
_tmp = this.options.fetchPlugins;
|
|
447
|
-
_state.label = 4;
|
|
448
|
-
case 4:
|
|
449
|
-
fetchPlugins = _tmp;
|
|
450
|
-
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(fetchPlugins.map(function(plugin) {
|
|
451
|
-
return plugin.load({
|
|
452
|
-
url: url,
|
|
453
|
-
options: options,
|
|
454
|
-
fetchPlugins: loadedPlugins,
|
|
455
|
-
controller: controller,
|
|
456
|
-
apiClient: _this,
|
|
457
|
-
logger: _this.options.logger
|
|
458
|
-
});
|
|
459
|
-
})));
|
|
416
|
+
if (this.options.fetchPlugins) {
|
|
417
|
+
;
|
|
418
|
+
(_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
|
|
419
|
+
return plugin.load({
|
|
420
|
+
url: url,
|
|
421
|
+
options: options,
|
|
422
|
+
fetchPlugins: loadedPlugins,
|
|
423
|
+
controller: controller,
|
|
424
|
+
apiClient: _this,
|
|
425
|
+
logger: _this.options.logger
|
|
426
|
+
});
|
|
427
|
+
})));
|
|
428
|
+
}
|
|
460
429
|
return [
|
|
461
430
|
4,
|
|
462
431
|
Promise.all(loadedPlugins.map(function(plugin) {
|
|
463
432
|
return !plugin.canStart || plugin.canStart();
|
|
464
433
|
}))
|
|
465
434
|
];
|
|
466
|
-
case
|
|
435
|
+
case 2:
|
|
467
436
|
canStart = _state.sent();
|
|
468
437
|
isCanceledBy = canStart.indexOf(false);
|
|
469
|
-
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, fetchPlugins[isCanceledBy], {
|
|
438
|
+
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, this.options.fetchPlugins[isCanceledBy], {
|
|
470
439
|
apiName: apiName,
|
|
471
440
|
operationId: operationId,
|
|
472
441
|
url: url,
|
|
@@ -496,19 +465,19 @@ var DEFAULT_OPTIONS = {
|
|
|
496
465
|
4,
|
|
497
466
|
asyncResponse
|
|
498
467
|
];
|
|
499
|
-
case
|
|
468
|
+
case 3:
|
|
500
469
|
response = _state.sent();
|
|
501
470
|
return [
|
|
502
471
|
4,
|
|
503
472
|
response.text()
|
|
504
473
|
];
|
|
505
|
-
case
|
|
474
|
+
case 4:
|
|
506
475
|
body = _state.sent();
|
|
507
476
|
return [
|
|
508
477
|
3,
|
|
509
|
-
|
|
478
|
+
6
|
|
510
479
|
];
|
|
511
|
-
case
|
|
480
|
+
case 5:
|
|
512
481
|
e = _state.sent();
|
|
513
482
|
if (_instanceof(e, CanceledCallError)) {
|
|
514
483
|
exception = e;
|
|
@@ -529,9 +498,9 @@ var DEFAULT_OPTIONS = {
|
|
|
529
498
|
}
|
|
530
499
|
return [
|
|
531
500
|
3,
|
|
532
|
-
|
|
501
|
+
6
|
|
533
502
|
];
|
|
534
|
-
case
|
|
503
|
+
case 6:
|
|
535
504
|
try {
|
|
536
505
|
root = body ? JSON.parse(body) : undefined;
|
|
537
506
|
} catch (e) {
|
|
@@ -563,49 +532,49 @@ var DEFAULT_OPTIONS = {
|
|
|
563
532
|
}) : [];
|
|
564
533
|
parsedData = root;
|
|
565
534
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
566
|
-
_state.label =
|
|
567
|
-
case
|
|
535
|
+
_state.label = 7;
|
|
536
|
+
case 7:
|
|
568
537
|
_state.trys.push([
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
538
|
+
7,
|
|
539
|
+
12,
|
|
540
|
+
13,
|
|
541
|
+
14
|
|
573
542
|
]);
|
|
574
543
|
_iterator1 = replyPlugins[Symbol.iterator]();
|
|
575
|
-
_state.label =
|
|
576
|
-
case
|
|
544
|
+
_state.label = 8;
|
|
545
|
+
case 8:
|
|
577
546
|
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
578
547
|
3,
|
|
579
|
-
|
|
548
|
+
11
|
|
580
549
|
];
|
|
581
550
|
pluginRunner = _step1.value;
|
|
582
551
|
return [
|
|
583
552
|
4,
|
|
584
553
|
pluginRunner.transform(parsedData)
|
|
585
554
|
];
|
|
586
|
-
case
|
|
555
|
+
case 9:
|
|
587
556
|
parsedData = _state.sent();
|
|
588
|
-
_state.label =
|
|
589
|
-
case
|
|
557
|
+
_state.label = 10;
|
|
558
|
+
case 10:
|
|
590
559
|
_iteratorNormalCompletion1 = true;
|
|
591
560
|
return [
|
|
592
561
|
3,
|
|
593
|
-
|
|
562
|
+
8
|
|
594
563
|
];
|
|
595
|
-
case
|
|
564
|
+
case 11:
|
|
596
565
|
return [
|
|
597
566
|
3,
|
|
598
|
-
|
|
567
|
+
14
|
|
599
568
|
];
|
|
600
|
-
case
|
|
569
|
+
case 12:
|
|
601
570
|
err = _state.sent();
|
|
602
571
|
_didIteratorError1 = true;
|
|
603
572
|
_iteratorError1 = err;
|
|
604
573
|
return [
|
|
605
574
|
3,
|
|
606
|
-
|
|
575
|
+
14
|
|
607
576
|
];
|
|
608
|
-
case
|
|
577
|
+
case 13:
|
|
609
578
|
try {
|
|
610
579
|
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
611
580
|
_iterator1.return();
|
|
@@ -618,7 +587,7 @@ var DEFAULT_OPTIONS = {
|
|
|
618
587
|
return [
|
|
619
588
|
7
|
|
620
589
|
];
|
|
621
|
-
case
|
|
590
|
+
case 14:
|
|
622
591
|
if (exception) {
|
|
623
592
|
throw exception;
|
|
624
593
|
}
|
|
@@ -168,52 +168,30 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
|
|
|
168
168
|
function MockInterceptFetch(options) {
|
|
169
169
|
_class_call_check(this, MockInterceptFetch);
|
|
170
170
|
_define_property(this, "options", void 0);
|
|
171
|
-
_define_property(this, "checkMockInterceptFetchPlugin", void 0);
|
|
172
171
|
this.options = options;
|
|
173
|
-
this.checkMockInterceptFetchPlugin = function(requestPlugins) {
|
|
174
|
-
if (!requestPlugins.some(function(plugin) {
|
|
175
|
-
return _instanceof(plugin, MockInterceptRequest);
|
|
176
|
-
})) {
|
|
177
|
-
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
172
|
}
|
|
181
173
|
_create_class(MockInterceptFetch, [
|
|
182
174
|
{
|
|
183
175
|
key: "load",
|
|
184
176
|
value: function load(context) {
|
|
185
177
|
var _this = this;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
178
|
+
if (!context.apiClient.options.requestPlugins.some(function(plugin) {
|
|
179
|
+
return _instanceof(plugin, MockInterceptRequest);
|
|
180
|
+
})) {
|
|
181
|
+
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
189
182
|
}
|
|
190
183
|
return {
|
|
191
184
|
transform: function(fetchCall) {
|
|
192
185
|
return _async_to_generator(function() {
|
|
193
|
-
var
|
|
186
|
+
var responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
194
187
|
return _ts_generator(this, function(_state) {
|
|
195
188
|
switch(_state.label){
|
|
196
189
|
case 0:
|
|
197
|
-
if (!!Array.isArray(requestPlugins)) return [
|
|
198
|
-
3,
|
|
199
|
-
2
|
|
200
|
-
];
|
|
201
|
-
_1 = (_ = this).checkMockInterceptFetchPlugin;
|
|
202
|
-
return [
|
|
203
|
-
4,
|
|
204
|
-
requestPlugins
|
|
205
|
-
];
|
|
206
|
-
case 1:
|
|
207
|
-
_1.apply(_, [
|
|
208
|
-
_state.sent()
|
|
209
|
-
]);
|
|
210
|
-
_state.label = 2;
|
|
211
|
-
case 2:
|
|
212
190
|
return [
|
|
213
191
|
4,
|
|
214
192
|
this.options.adapter.initialize()
|
|
215
193
|
];
|
|
216
|
-
case
|
|
194
|
+
case 1:
|
|
217
195
|
_state.sent();
|
|
218
196
|
responsePromise = fetchCall;
|
|
219
197
|
if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
|
|
@@ -224,40 +202,40 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
|
|
|
224
202
|
}
|
|
225
203
|
if (!(typeof this.options.delayTiming !== 'undefined')) return [
|
|
226
204
|
3,
|
|
227
|
-
|
|
205
|
+
6
|
|
228
206
|
];
|
|
229
207
|
if (!(typeof this.options.delayTiming === 'number')) return [
|
|
230
208
|
3,
|
|
231
|
-
|
|
209
|
+
2
|
|
232
210
|
];
|
|
233
211
|
_tmp = this.options.delayTiming;
|
|
234
212
|
return [
|
|
235
213
|
3,
|
|
236
|
-
|
|
214
|
+
4
|
|
237
215
|
];
|
|
238
|
-
case
|
|
216
|
+
case 2:
|
|
239
217
|
return [
|
|
240
218
|
4,
|
|
241
219
|
this.options.delayTiming(context)
|
|
242
220
|
];
|
|
243
|
-
case
|
|
221
|
+
case 3:
|
|
244
222
|
_tmp = _state.sent();
|
|
245
|
-
_state.label =
|
|
246
|
-
case
|
|
223
|
+
_state.label = 4;
|
|
224
|
+
case 4:
|
|
247
225
|
delay = _tmp;
|
|
248
226
|
return [
|
|
249
227
|
4,
|
|
250
228
|
responsePromise
|
|
251
229
|
];
|
|
252
|
-
case
|
|
230
|
+
case 5:
|
|
253
231
|
resp = _state.sent();
|
|
254
232
|
responsePromise = new Promise(function(resolve) {
|
|
255
233
|
return setTimeout(resolve, delay);
|
|
256
234
|
}).then(function() {
|
|
257
235
|
return resp;
|
|
258
236
|
});
|
|
259
|
-
_state.label =
|
|
260
|
-
case
|
|
237
|
+
_state.label = 6;
|
|
238
|
+
case 6:
|
|
261
239
|
operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
|
|
262
240
|
try {
|
|
263
241
|
mock = this.options.adapter.getLatestMock(operationId);
|
|
@@ -344,42 +344,6 @@ describe('Mock intercept', function() {
|
|
|
344
344
|
return plugin.load(config);
|
|
345
345
|
}).toThrow();
|
|
346
346
|
});
|
|
347
|
-
it('should throw if there is no request plugin when dynamic', function() {
|
|
348
|
-
return _async_to_generator(function() {
|
|
349
|
-
var config;
|
|
350
|
-
return _ts_generator(this, function(_state) {
|
|
351
|
-
switch(_state.label){
|
|
352
|
-
case 0:
|
|
353
|
-
config = {
|
|
354
|
-
controller: jest.fn(),
|
|
355
|
-
fetchPlugins: [],
|
|
356
|
-
url: 'myurl',
|
|
357
|
-
apiClient: {
|
|
358
|
-
options: {
|
|
359
|
-
requestPlugins: function() {
|
|
360
|
-
return Promise.resolve([]);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
options: {
|
|
365
|
-
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
return [
|
|
369
|
-
4,
|
|
370
|
-
expect(function() {
|
|
371
|
-
return plugin.load(config).transform({});
|
|
372
|
-
}).rejects.toThrow('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin')
|
|
373
|
-
];
|
|
374
|
-
case 1:
|
|
375
|
-
_state.sent();
|
|
376
|
-
return [
|
|
377
|
-
2
|
|
378
|
-
];
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
})();
|
|
382
|
-
});
|
|
383
347
|
});
|
|
384
348
|
});
|
|
385
349
|
describe('with delay', function() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ama-sdk/client-fetch",
|
|
3
|
-
"version": "12.5.0-prerelease.
|
|
3
|
+
"version": "12.5.0-prerelease.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,21 +38,20 @@
|
|
|
38
38
|
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@o3r/schematics": "^12.5.0-prerelease.
|
|
41
|
+
"@o3r/schematics": "^12.5.0-prerelease.2",
|
|
42
42
|
"@swc/helpers": "~0.5.0",
|
|
43
43
|
"ts-node": "~10.9.2",
|
|
44
44
|
"tslib": "^2.6.2",
|
|
45
45
|
"uuid": "^11.0.5"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@ama-sdk/core": "^12.5.0-prerelease.
|
|
48
|
+
"@ama-sdk/core": "^12.5.0-prerelease.2",
|
|
49
49
|
"@angular-devkit/schematics": "^19.0.0",
|
|
50
50
|
"@angular/cli": "^19.0.0",
|
|
51
51
|
"@angular/common": "^19.0.0",
|
|
52
|
-
"@o3r/schematics": "^12.5.0-prerelease.
|
|
52
|
+
"@o3r/schematics": "^12.5.0-prerelease.2",
|
|
53
53
|
"@schematics/angular": "^19.0.0",
|
|
54
54
|
"isomorphic-fetch": "^3.0.0",
|
|
55
|
-
"type-fest": "^4.30.1",
|
|
56
55
|
"typescript": "^5.5.4"
|
|
57
56
|
},
|
|
58
57
|
"peerDependenciesMeta": {
|
|
@@ -74,15 +73,12 @@
|
|
|
74
73
|
"isomorphic-fetch": {
|
|
75
74
|
"optional": true
|
|
76
75
|
},
|
|
77
|
-
"type-fest": {
|
|
78
|
-
"optional": true
|
|
79
|
-
},
|
|
80
76
|
"typescript": {
|
|
81
77
|
"optional": true
|
|
82
78
|
}
|
|
83
79
|
},
|
|
84
80
|
"devDependencies": {
|
|
85
|
-
"@ama-sdk/core": "^12.5.0-prerelease.
|
|
81
|
+
"@ama-sdk/core": "^12.5.0-prerelease.2",
|
|
86
82
|
"@angular-devkit/core": "~19.2.0",
|
|
87
83
|
"@angular-devkit/schematics": "~19.2.0",
|
|
88
84
|
"@angular/common": "~19.2.0",
|
|
@@ -90,9 +86,9 @@
|
|
|
90
86
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
91
87
|
"@nx/eslint-plugin": "~20.8.0",
|
|
92
88
|
"@nx/jest": "~20.8.0",
|
|
93
|
-
"@o3r/build-helpers": "^12.5.0-prerelease.
|
|
94
|
-
"@o3r/eslint-plugin": "^12.5.0-prerelease.
|
|
95
|
-
"@o3r/test-helpers": "^12.5.0-prerelease.
|
|
89
|
+
"@o3r/build-helpers": "^12.5.0-prerelease.2",
|
|
90
|
+
"@o3r/eslint-plugin": "^12.5.0-prerelease.2",
|
|
91
|
+
"@o3r/test-helpers": "^12.5.0-prerelease.2",
|
|
96
92
|
"@schematics/angular": "~19.2.0",
|
|
97
93
|
"@stylistic/eslint-plugin": "~3.1.0",
|
|
98
94
|
"@stylistic/eslint-plugin-ts": "~3.1.0",
|
|
@@ -101,15 +97,15 @@
|
|
|
101
97
|
"@types/jest": "~29.5.2",
|
|
102
98
|
"@types/node": "^20.0.0",
|
|
103
99
|
"@types/uuid": "^10.0.0",
|
|
104
|
-
"@typescript-eslint/parser": "~8.
|
|
100
|
+
"@typescript-eslint/parser": "~8.34.0",
|
|
105
101
|
"angular-eslint": "~19.4.0",
|
|
106
102
|
"cpy-cli": "^5.0.0",
|
|
107
|
-
"eslint": "~9.
|
|
103
|
+
"eslint": "~9.28.0",
|
|
108
104
|
"eslint-import-resolver-node": "~0.3.9",
|
|
109
105
|
"eslint-import-resolver-typescript": "~3.10.0",
|
|
110
|
-
"eslint-plugin-import": "~2.
|
|
106
|
+
"eslint-plugin-import": "~2.31.0",
|
|
111
107
|
"eslint-plugin-import-newlines": "~1.4.0",
|
|
112
|
-
"eslint-plugin-jest": "~28.
|
|
108
|
+
"eslint-plugin-jest": "~28.13.0",
|
|
113
109
|
"eslint-plugin-jsdoc": "~50.8.0",
|
|
114
110
|
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
115
111
|
"eslint-plugin-unicorn": "~56.0.0",
|
|
@@ -127,7 +123,7 @@
|
|
|
127
123
|
"ts-node": "~10.9.2",
|
|
128
124
|
"type-fest": "^4.30.1",
|
|
129
125
|
"typescript": "~5.8.2",
|
|
130
|
-
"typescript-eslint": "~8.
|
|
126
|
+
"typescript-eslint": "~8.34.0",
|
|
131
127
|
"zone.js": "~0.15.0"
|
|
132
128
|
},
|
|
133
129
|
"engines": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,IAAI,EACL,MAAM,4BAA4B,CAAC;AAkBpC,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,IAAI,EACL,MAAM,4BAA4B,CAAC;AAkBpC,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAmDlB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,SAAS,qBAAqB,SAA2C,CAAC"}
|
|
@@ -4,9 +4,9 @@ exports.ngAdd = void 0;
|
|
|
4
4
|
const path = require("node:path");
|
|
5
5
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
6
|
const schematics_2 = require("@o3r/schematics");
|
|
7
|
+
const dependencies_1 = require("@schematics/angular/utility/dependencies");
|
|
7
8
|
const import_map_1 = require("./migration/import-map");
|
|
8
9
|
const devDependenciesToInstall = [];
|
|
9
|
-
const dependenciesToInstall = [];
|
|
10
10
|
/**
|
|
11
11
|
* Add SDk Fetch Client to an Otter Project
|
|
12
12
|
* @param options
|
|
@@ -16,7 +16,6 @@ function ngAddFn(options) {
|
|
|
16
16
|
const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
|
|
17
17
|
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
|
|
18
18
|
const depsInfo = (0, schematics_2.getO3rPeerDeps)(packageJsonPath);
|
|
19
|
-
const projectPackageJson = tree.readJson(path.posix.join(workspaceProject?.root || '.', 'package.json'));
|
|
20
19
|
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
|
|
21
20
|
acc[dep] = {
|
|
22
21
|
inManifest: [{
|
|
@@ -27,23 +26,22 @@ function ngAddFn(options) {
|
|
|
27
26
|
};
|
|
28
27
|
return acc;
|
|
29
28
|
}, (0, schematics_2.getPackageInstallConfig)(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
Object.entries((0, schematics_2.getExternalDependenciesVersionRange)(devDependenciesToInstall, packageJsonPath, context.logger))
|
|
30
|
+
.forEach(([dep, range]) => {
|
|
31
|
+
dependencies[dep] = {
|
|
32
|
+
inManifest: [{
|
|
33
|
+
range,
|
|
34
|
+
types: [dependencies_1.NodeDependencyType.Dev]
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
});
|
|
37
38
|
return (0, schematics_1.chain)([
|
|
38
39
|
// optional custom action dedicated to this module
|
|
39
40
|
options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)(),
|
|
40
41
|
// add the missing Otter modules in the current project
|
|
41
42
|
(0, schematics_2.setupDependencies)({
|
|
42
43
|
projectName: options.projectName,
|
|
43
|
-
dependencies
|
|
44
|
-
...dependencies,
|
|
45
|
-
...externalDependenciesInfo
|
|
46
|
-
},
|
|
44
|
+
dependencies,
|
|
47
45
|
ngAddToRun: depsInfo.o3rPeerDeps
|
|
48
46
|
}),
|
|
49
47
|
(0, schematics_2.updateImports)(import_map_1.mapMigrationFromCoreImports)
|
|
@@ -3,7 +3,7 @@ import type { FetchPlugin } from './fetch-plugin';
|
|
|
3
3
|
/** @see BaseApiClientOptions */
|
|
4
4
|
export interface BaseApiFetchClientOptions extends BaseApiClientOptions {
|
|
5
5
|
/** List of plugins to apply to the fetch call */
|
|
6
|
-
fetchPlugins: FetchPlugin[]
|
|
6
|
+
fetchPlugins: FetchPlugin[];
|
|
7
7
|
}
|
|
8
8
|
/** @see BaseApiConstructor */
|
|
9
9
|
export interface BaseApiFetchClientConstructor extends PartialExcept<BaseApiFetchClientOptions, 'basePath'> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-fetch-client.d.ts","sourceRoot":"","sources":["../../src/api-fetch-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EAEb,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAoBvB,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAExB,gCAAgC;AAChC,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,iDAAiD;IACjD,YAAY,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"api-fetch-client.d.ts","sourceRoot":"","sources":["../../src/api-fetch-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EAEb,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,kBAAkB,EAClB,gBAA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GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;KAAE,EACnL,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CA4FpC"}
|
package/src/api-fetch-client.js
CHANGED
|
@@ -42,14 +42,13 @@ export class ApiFetchClient {
|
|
|
42
42
|
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
43
43
|
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}).transform(opts);
|
|
45
|
+
if (this.options.requestPlugins) {
|
|
46
|
+
for (const plugin of this.options.requestPlugins) {
|
|
47
|
+
opts = await plugin.load({
|
|
48
|
+
logger: this.options.logger,
|
|
49
|
+
apiName: requestOptionsParameters.api?.apiName
|
|
50
|
+
}).transform(opts);
|
|
51
|
+
}
|
|
53
52
|
}
|
|
54
53
|
return opts;
|
|
55
54
|
}
|
|
@@ -94,16 +93,15 @@ export class ApiFetchClient {
|
|
|
94
93
|
options.signal = controller.signal;
|
|
95
94
|
metadataSignal?.addEventListener('abort', () => controller.abort());
|
|
96
95
|
const loadedPlugins = [];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
loadedPlugins.push(...fetchPlugins.map((plugin) => plugin.load({ url, options, fetchPlugins: loadedPlugins, controller, apiClient: this, logger: this.options.logger })));
|
|
96
|
+
if (this.options.fetchPlugins) {
|
|
97
|
+
loadedPlugins.push(...this.options.fetchPlugins.map((plugin) => plugin.load({ url, options, fetchPlugins: loadedPlugins, controller, apiClient: this, logger: this.options.logger })));
|
|
98
|
+
}
|
|
101
99
|
const canStart = await Promise.all(loadedPlugins.map((plugin) => !plugin.canStart || plugin.canStart()));
|
|
102
100
|
const isCanceledBy = canStart.indexOf(false);
|
|
103
101
|
asyncResponse = isCanceledBy === -1
|
|
104
102
|
// One of the fetch plugins cancelled the execution of the call
|
|
105
103
|
? fetch(url, options)
|
|
106
|
-
: Promise.reject(new CanceledCallError(`Is canceled by the plugin ${isCanceledBy}`, isCanceledBy, fetchPlugins[isCanceledBy], { apiName, operationId, url, origin }));
|
|
104
|
+
: Promise.reject(new CanceledCallError(`Is canceled by the plugin ${isCanceledBy}`, isCanceledBy, this.options.fetchPlugins[isCanceledBy], { apiName, operationId, url, origin }));
|
|
107
105
|
for (const plugin of loadedPlugins) {
|
|
108
106
|
asyncResponse = plugin.transform(asyncResponse);
|
|
109
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-fetch-client.js","sourceRoot":"","sources":["../../src/api-fetch-client.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AAiBvB,MAAM,eAAe,GAAG;IACtB,YAAY,EAAE,CAAC,IAAI,YAAY,EAAE,EAAE,IAAI,cAAc,EAAE,CAAC;IACxD,YAAY,EAAE,EAAE;IAChB,cAAc,EAAE,EAAE;IAClB,kBAAkB,EAAE,KAAK;IACzB,eAAe,EAAE,KAAK;IACtB,4BAA4B,EAAE,KAAK;CAC2B,CAAC;AAEjE,4DAA4D;AAC5D,MAAM,OAAO,cAAc;IAIzB;;;OAGG;IACH,YAAY,OAAsC;QAChD,IAAI,CAAC,OAAO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AU,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -10,7 +10,6 @@ import { MockInterceptFetchParameters } from './mock-intercept.interface';
|
|
|
10
10
|
export declare class MockInterceptFetch implements FetchPlugin {
|
|
11
11
|
protected options: MockInterceptFetchParameters;
|
|
12
12
|
constructor(options: MockInterceptFetchParameters);
|
|
13
|
-
private readonly checkMockInterceptFetchPlugin;
|
|
14
13
|
load(context: FetchPluginContext): PluginAsyncRunner<Response, Promise<Response>> & PluginAsyncStarter;
|
|
15
14
|
}
|
|
16
15
|
//# sourceMappingURL=mock-intercept.fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-intercept.fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,
|
|
1
|
+
{"version":3,"file":"mock-intercept.fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAKvB,OAAO,KAAK,EAEV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,4BAA4B,EAC7B,MAAM,4BAA4B,CAAC;AAEpC;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,WAAW;IACxC,SAAS,CAAC,OAAO,EAAE,4BAA4B;gBAArC,OAAO,EAAE,4BAA4B;IAEpD,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,kBAAkB;CAqC9G"}
|
|
@@ -8,24 +8,13 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest, } from '@ama-sdk
|
|
|
8
8
|
export class MockInterceptFetch {
|
|
9
9
|
constructor(options) {
|
|
10
10
|
this.options = options;
|
|
11
|
-
this.checkMockInterceptFetchPlugin = (requestPlugins) => {
|
|
12
|
-
if (!requestPlugins.some((plugin) => plugin instanceof MockInterceptRequest)) {
|
|
13
|
-
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
11
|
}
|
|
17
12
|
load(context) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: context.apiClient.options.requestPlugins;
|
|
21
|
-
if (Array.isArray(requestPlugins)) {
|
|
22
|
-
this.checkMockInterceptFetchPlugin(requestPlugins);
|
|
13
|
+
if (!context.apiClient.options.requestPlugins.some((plugin) => plugin instanceof MockInterceptRequest)) {
|
|
14
|
+
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
23
15
|
}
|
|
24
16
|
return {
|
|
25
17
|
transform: async (fetchCall) => {
|
|
26
|
-
if (!Array.isArray(requestPlugins)) {
|
|
27
|
-
this.checkMockInterceptFetchPlugin(await requestPlugins);
|
|
28
|
-
}
|
|
29
18
|
await this.options.adapter.initialize();
|
|
30
19
|
let responsePromise = fetchCall;
|
|
31
20
|
if (!context.options.headers || !(context.options.headers instanceof Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-intercept.fetch.js","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mock-intercept.fetch.js","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.fetch.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAWvB;;;;;GAKG;AACH,MAAM,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