@ama-sdk/client-fetch 12.5.0-prerelease.4 → 12.5.0-prerelease.40
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 +97 -66
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +38 -16
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +36 -0
- package/esm2015/api-fetch-client.js +97 -66
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +38 -16
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +36 -0
- package/package.json +17 -14
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +13 -11
- 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 +13 -11
- package/src/api-fetch-client.js.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts +1 -0
- package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.fetch.js +13 -2
- 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, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
282
|
+
var opts, requestPlugins, _tmp, _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,25 +287,40 @@ 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 (!this.options.requestPlugins) return [
|
|
290
|
+
if (!(typeof this.options.requestPlugins === 'function')) return [
|
|
291
291
|
3,
|
|
292
|
-
|
|
292
|
+
2
|
|
293
|
+
];
|
|
294
|
+
return [
|
|
295
|
+
4,
|
|
296
|
+
this.options.requestPlugins(opts)
|
|
293
297
|
];
|
|
294
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
295
|
-
_state.label = 1;
|
|
296
298
|
case 1:
|
|
299
|
+
_tmp = _state.sent();
|
|
300
|
+
return [
|
|
301
|
+
3,
|
|
302
|
+
3
|
|
303
|
+
];
|
|
304
|
+
case 2:
|
|
305
|
+
_tmp = this.options.requestPlugins;
|
|
306
|
+
_state.label = 3;
|
|
307
|
+
case 3:
|
|
308
|
+
requestPlugins = _tmp;
|
|
309
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
310
|
+
_state.label = 4;
|
|
311
|
+
case 4:
|
|
297
312
|
_state.trys.push([
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
313
|
+
4,
|
|
314
|
+
9,
|
|
315
|
+
10,
|
|
316
|
+
11
|
|
302
317
|
]);
|
|
303
|
-
_iterator =
|
|
304
|
-
_state.label =
|
|
305
|
-
case
|
|
318
|
+
_iterator = requestPlugins[Symbol.iterator]();
|
|
319
|
+
_state.label = 5;
|
|
320
|
+
case 5:
|
|
306
321
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
307
322
|
3,
|
|
308
|
-
|
|
323
|
+
8
|
|
309
324
|
];
|
|
310
325
|
plugin = _step.value;
|
|
311
326
|
return [
|
|
@@ -315,29 +330,29 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
315
330
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
316
331
|
}).transform(opts)
|
|
317
332
|
];
|
|
318
|
-
case
|
|
333
|
+
case 6:
|
|
319
334
|
opts = _state.sent();
|
|
320
|
-
_state.label =
|
|
321
|
-
case
|
|
335
|
+
_state.label = 7;
|
|
336
|
+
case 7:
|
|
322
337
|
_iteratorNormalCompletion = true;
|
|
323
338
|
return [
|
|
324
339
|
3,
|
|
325
|
-
|
|
340
|
+
5
|
|
326
341
|
];
|
|
327
|
-
case
|
|
342
|
+
case 8:
|
|
328
343
|
return [
|
|
329
344
|
3,
|
|
330
|
-
|
|
345
|
+
11
|
|
331
346
|
];
|
|
332
|
-
case
|
|
347
|
+
case 9:
|
|
333
348
|
err = _state.sent();
|
|
334
349
|
_didIteratorError = true;
|
|
335
350
|
_iteratorError = err;
|
|
336
351
|
return [
|
|
337
352
|
3,
|
|
338
|
-
|
|
353
|
+
11
|
|
339
354
|
];
|
|
340
|
-
case
|
|
355
|
+
case 10:
|
|
341
356
|
try {
|
|
342
357
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
343
358
|
_iterator.return();
|
|
@@ -350,7 +365,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
350
365
|
return [
|
|
351
366
|
7
|
|
352
367
|
];
|
|
353
|
-
case
|
|
368
|
+
case 11:
|
|
354
369
|
return [
|
|
355
370
|
2,
|
|
356
371
|
opts
|
|
@@ -401,7 +416,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
401
416
|
key: "processCall",
|
|
402
417
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
403
418
|
return _async_to_generator(function() {
|
|
404
|
-
var _this, response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins,
|
|
419
|
+
var _this, response, asyncResponse, root, body, exception, origin, _loadedPlugins, _options_metadata, metadataSignal, controller, loadedPlugins, fetchPlugins, _tmp, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
405
420
|
return _ts_generator(this, function(_state) {
|
|
406
421
|
switch(_state.label){
|
|
407
422
|
case 0:
|
|
@@ -411,9 +426,9 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
411
426
|
case 1:
|
|
412
427
|
_state.trys.push([
|
|
413
428
|
1,
|
|
414
|
-
|
|
429
|
+
8,
|
|
415
430
|
,
|
|
416
|
-
|
|
431
|
+
9
|
|
417
432
|
]);
|
|
418
433
|
metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
419
434
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
@@ -423,29 +438,45 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
423
438
|
return controller.abort();
|
|
424
439
|
});
|
|
425
440
|
loadedPlugins = [];
|
|
426
|
-
if (this.options.fetchPlugins)
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
441
|
+
if (!(typeof this.options.fetchPlugins === 'function')) return [
|
|
442
|
+
3,
|
|
443
|
+
3
|
|
444
|
+
];
|
|
445
|
+
return [
|
|
446
|
+
4,
|
|
447
|
+
this.options.fetchPlugins(options)
|
|
448
|
+
];
|
|
449
|
+
case 2:
|
|
450
|
+
_tmp = _state.sent();
|
|
451
|
+
return [
|
|
452
|
+
3,
|
|
453
|
+
4
|
|
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
|
+
})));
|
|
439
470
|
return [
|
|
440
471
|
4,
|
|
441
472
|
Promise.all(loadedPlugins.map(function(plugin) {
|
|
442
473
|
return !plugin.canStart || plugin.canStart();
|
|
443
474
|
}))
|
|
444
475
|
];
|
|
445
|
-
case
|
|
476
|
+
case 5:
|
|
446
477
|
canStart = _state.sent();
|
|
447
478
|
isCanceledBy = canStart.indexOf(false);
|
|
448
|
-
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy,
|
|
479
|
+
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, fetchPlugins[isCanceledBy], {
|
|
449
480
|
apiName: apiName,
|
|
450
481
|
operationId: operationId,
|
|
451
482
|
url: url,
|
|
@@ -475,19 +506,19 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
475
506
|
4,
|
|
476
507
|
asyncResponse
|
|
477
508
|
];
|
|
478
|
-
case
|
|
509
|
+
case 6:
|
|
479
510
|
response = _state.sent();
|
|
480
511
|
return [
|
|
481
512
|
4,
|
|
482
513
|
response.text()
|
|
483
514
|
];
|
|
484
|
-
case
|
|
515
|
+
case 7:
|
|
485
516
|
body = _state.sent();
|
|
486
517
|
return [
|
|
487
518
|
3,
|
|
488
|
-
|
|
519
|
+
9
|
|
489
520
|
];
|
|
490
|
-
case
|
|
521
|
+
case 8:
|
|
491
522
|
e = _state.sent();
|
|
492
523
|
if (_instanceof(e, _core.CanceledCallError)) {
|
|
493
524
|
exception = e;
|
|
@@ -508,9 +539,9 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
508
539
|
}
|
|
509
540
|
return [
|
|
510
541
|
3,
|
|
511
|
-
|
|
542
|
+
9
|
|
512
543
|
];
|
|
513
|
-
case
|
|
544
|
+
case 9:
|
|
514
545
|
try {
|
|
515
546
|
root = body ? JSON.parse(body) : undefined;
|
|
516
547
|
} catch (e) {
|
|
@@ -542,49 +573,49 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
542
573
|
}) : [];
|
|
543
574
|
parsedData = root;
|
|
544
575
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
545
|
-
_state.label =
|
|
546
|
-
case
|
|
576
|
+
_state.label = 10;
|
|
577
|
+
case 10:
|
|
547
578
|
_state.trys.push([
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
579
|
+
10,
|
|
580
|
+
15,
|
|
581
|
+
16,
|
|
582
|
+
17
|
|
552
583
|
]);
|
|
553
584
|
_iterator1 = replyPlugins[Symbol.iterator]();
|
|
554
|
-
_state.label =
|
|
555
|
-
case
|
|
585
|
+
_state.label = 11;
|
|
586
|
+
case 11:
|
|
556
587
|
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
557
588
|
3,
|
|
558
|
-
|
|
589
|
+
14
|
|
559
590
|
];
|
|
560
591
|
pluginRunner = _step1.value;
|
|
561
592
|
return [
|
|
562
593
|
4,
|
|
563
594
|
pluginRunner.transform(parsedData)
|
|
564
595
|
];
|
|
565
|
-
case
|
|
596
|
+
case 12:
|
|
566
597
|
parsedData = _state.sent();
|
|
567
|
-
_state.label =
|
|
568
|
-
case
|
|
598
|
+
_state.label = 13;
|
|
599
|
+
case 13:
|
|
569
600
|
_iteratorNormalCompletion1 = true;
|
|
570
601
|
return [
|
|
571
602
|
3,
|
|
572
|
-
|
|
603
|
+
11
|
|
573
604
|
];
|
|
574
|
-
case
|
|
605
|
+
case 14:
|
|
575
606
|
return [
|
|
576
607
|
3,
|
|
577
|
-
|
|
608
|
+
17
|
|
578
609
|
];
|
|
579
|
-
case
|
|
610
|
+
case 15:
|
|
580
611
|
err = _state.sent();
|
|
581
612
|
_didIteratorError1 = true;
|
|
582
613
|
_iteratorError1 = err;
|
|
583
614
|
return [
|
|
584
615
|
3,
|
|
585
|
-
|
|
616
|
+
17
|
|
586
617
|
];
|
|
587
|
-
case
|
|
618
|
+
case 16:
|
|
588
619
|
try {
|
|
589
620
|
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
590
621
|
_iterator1.return();
|
|
@@ -597,7 +628,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
597
628
|
return [
|
|
598
629
|
7
|
|
599
630
|
];
|
|
600
|
-
case
|
|
631
|
+
case 17:
|
|
601
632
|
if (exception) {
|
|
602
633
|
throw exception;
|
|
603
634
|
}
|
|
@@ -173,30 +173,52 @@ 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);
|
|
176
177
|
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
|
+
};
|
|
177
185
|
}
|
|
178
186
|
_create_class(MockInterceptFetch, [
|
|
179
187
|
{
|
|
180
188
|
key: "load",
|
|
181
189
|
value: function load(context) {
|
|
182
190
|
var _this = this;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
191
|
+
var requestPlugins = typeof context.apiClient.options.requestPlugins === 'function' ? context.apiClient.options.requestPlugins(context.requestOptions) : context.apiClient.options.requestPlugins;
|
|
192
|
+
if (Array.isArray(requestPlugins)) {
|
|
193
|
+
this.checkMockInterceptFetchPlugin(requestPlugins);
|
|
187
194
|
}
|
|
188
195
|
return {
|
|
189
196
|
transform: function(fetchCall) {
|
|
190
197
|
return _async_to_generator(function() {
|
|
191
|
-
var responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
198
|
+
var _, _1, responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
192
199
|
return _ts_generator(this, function(_state) {
|
|
193
200
|
switch(_state.label){
|
|
194
201
|
case 0:
|
|
202
|
+
if (!!Array.isArray(requestPlugins)) return [
|
|
203
|
+
3,
|
|
204
|
+
2
|
|
205
|
+
];
|
|
206
|
+
_1 = (_ = this).checkMockInterceptFetchPlugin;
|
|
195
207
|
return [
|
|
196
208
|
4,
|
|
197
|
-
|
|
209
|
+
requestPlugins
|
|
198
210
|
];
|
|
199
211
|
case 1:
|
|
212
|
+
_1.apply(_, [
|
|
213
|
+
_state.sent()
|
|
214
|
+
]);
|
|
215
|
+
_state.label = 2;
|
|
216
|
+
case 2:
|
|
217
|
+
return [
|
|
218
|
+
4,
|
|
219
|
+
this.options.adapter.initialize()
|
|
220
|
+
];
|
|
221
|
+
case 3:
|
|
200
222
|
_state.sent();
|
|
201
223
|
responsePromise = fetchCall;
|
|
202
224
|
if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(_core.CUSTOM_MOCK_OPERATION_ID_HEADER)) {
|
|
@@ -207,40 +229,40 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
207
229
|
}
|
|
208
230
|
if (!(typeof this.options.delayTiming !== 'undefined')) return [
|
|
209
231
|
3,
|
|
210
|
-
|
|
232
|
+
8
|
|
211
233
|
];
|
|
212
234
|
if (!(typeof this.options.delayTiming === 'number')) return [
|
|
213
235
|
3,
|
|
214
|
-
|
|
236
|
+
4
|
|
215
237
|
];
|
|
216
238
|
_tmp = this.options.delayTiming;
|
|
217
239
|
return [
|
|
218
240
|
3,
|
|
219
|
-
|
|
241
|
+
6
|
|
220
242
|
];
|
|
221
|
-
case
|
|
243
|
+
case 4:
|
|
222
244
|
return [
|
|
223
245
|
4,
|
|
224
246
|
this.options.delayTiming(context)
|
|
225
247
|
];
|
|
226
|
-
case
|
|
248
|
+
case 5:
|
|
227
249
|
_tmp = _state.sent();
|
|
228
|
-
_state.label =
|
|
229
|
-
case
|
|
250
|
+
_state.label = 6;
|
|
251
|
+
case 6:
|
|
230
252
|
delay = _tmp;
|
|
231
253
|
return [
|
|
232
254
|
4,
|
|
233
255
|
responsePromise
|
|
234
256
|
];
|
|
235
|
-
case
|
|
257
|
+
case 7:
|
|
236
258
|
resp = _state.sent();
|
|
237
259
|
responsePromise = new Promise(function(resolve) {
|
|
238
260
|
return setTimeout(resolve, delay);
|
|
239
261
|
}).then(function() {
|
|
240
262
|
return resp;
|
|
241
263
|
});
|
|
242
|
-
_state.label =
|
|
243
|
-
case
|
|
264
|
+
_state.label = 8;
|
|
265
|
+
case 8:
|
|
244
266
|
operationId = context.options.headers.get(_core.CUSTOM_MOCK_OPERATION_ID_HEADER);
|
|
245
267
|
try {
|
|
246
268
|
mock = this.options.adapter.getLatestMock(operationId);
|
|
@@ -348,6 +348,42 @@ 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
|
+
});
|
|
351
387
|
});
|
|
352
388
|
});
|
|
353
389
|
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, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
272
|
+
var opts, requestPlugins, _tmp, _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,25 +277,40 @@ var DEFAULT_OPTIONS = {
|
|
|
277
277
|
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
278
278
|
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
279
279
|
});
|
|
280
|
-
if (!this.options.requestPlugins) return [
|
|
280
|
+
if (!(typeof this.options.requestPlugins === 'function')) return [
|
|
281
281
|
3,
|
|
282
|
-
|
|
282
|
+
2
|
|
283
|
+
];
|
|
284
|
+
return [
|
|
285
|
+
4,
|
|
286
|
+
this.options.requestPlugins(opts)
|
|
283
287
|
];
|
|
284
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
285
|
-
_state.label = 1;
|
|
286
288
|
case 1:
|
|
289
|
+
_tmp = _state.sent();
|
|
290
|
+
return [
|
|
291
|
+
3,
|
|
292
|
+
3
|
|
293
|
+
];
|
|
294
|
+
case 2:
|
|
295
|
+
_tmp = this.options.requestPlugins;
|
|
296
|
+
_state.label = 3;
|
|
297
|
+
case 3:
|
|
298
|
+
requestPlugins = _tmp;
|
|
299
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
300
|
+
_state.label = 4;
|
|
301
|
+
case 4:
|
|
287
302
|
_state.trys.push([
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
303
|
+
4,
|
|
304
|
+
9,
|
|
305
|
+
10,
|
|
306
|
+
11
|
|
292
307
|
]);
|
|
293
|
-
_iterator =
|
|
294
|
-
_state.label =
|
|
295
|
-
case
|
|
308
|
+
_iterator = requestPlugins[Symbol.iterator]();
|
|
309
|
+
_state.label = 5;
|
|
310
|
+
case 5:
|
|
296
311
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
297
312
|
3,
|
|
298
|
-
|
|
313
|
+
8
|
|
299
314
|
];
|
|
300
315
|
plugin = _step.value;
|
|
301
316
|
return [
|
|
@@ -305,29 +320,29 @@ var DEFAULT_OPTIONS = {
|
|
|
305
320
|
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
306
321
|
}).transform(opts)
|
|
307
322
|
];
|
|
308
|
-
case
|
|
323
|
+
case 6:
|
|
309
324
|
opts = _state.sent();
|
|
310
|
-
_state.label =
|
|
311
|
-
case
|
|
325
|
+
_state.label = 7;
|
|
326
|
+
case 7:
|
|
312
327
|
_iteratorNormalCompletion = true;
|
|
313
328
|
return [
|
|
314
329
|
3,
|
|
315
|
-
|
|
330
|
+
5
|
|
316
331
|
];
|
|
317
|
-
case
|
|
332
|
+
case 8:
|
|
318
333
|
return [
|
|
319
334
|
3,
|
|
320
|
-
|
|
335
|
+
11
|
|
321
336
|
];
|
|
322
|
-
case
|
|
337
|
+
case 9:
|
|
323
338
|
err = _state.sent();
|
|
324
339
|
_didIteratorError = true;
|
|
325
340
|
_iteratorError = err;
|
|
326
341
|
return [
|
|
327
342
|
3,
|
|
328
|
-
|
|
343
|
+
11
|
|
329
344
|
];
|
|
330
|
-
case
|
|
345
|
+
case 10:
|
|
331
346
|
try {
|
|
332
347
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
333
348
|
_iterator.return();
|
|
@@ -340,7 +355,7 @@ var DEFAULT_OPTIONS = {
|
|
|
340
355
|
return [
|
|
341
356
|
7
|
|
342
357
|
];
|
|
343
|
-
case
|
|
358
|
+
case 11:
|
|
344
359
|
return [
|
|
345
360
|
2,
|
|
346
361
|
opts
|
|
@@ -391,7 +406,7 @@ var DEFAULT_OPTIONS = {
|
|
|
391
406
|
key: "processCall",
|
|
392
407
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
393
408
|
return _async_to_generator(function() {
|
|
394
|
-
var _this, response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins,
|
|
409
|
+
var _this, response, asyncResponse, root, body, exception, origin, _loadedPlugins, _options_metadata, metadataSignal, controller, loadedPlugins, fetchPlugins, _tmp, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
395
410
|
return _ts_generator(this, function(_state) {
|
|
396
411
|
switch(_state.label){
|
|
397
412
|
case 0:
|
|
@@ -401,9 +416,9 @@ var DEFAULT_OPTIONS = {
|
|
|
401
416
|
case 1:
|
|
402
417
|
_state.trys.push([
|
|
403
418
|
1,
|
|
404
|
-
|
|
419
|
+
8,
|
|
405
420
|
,
|
|
406
|
-
|
|
421
|
+
9
|
|
407
422
|
]);
|
|
408
423
|
metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
409
424
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
@@ -413,29 +428,45 @@ var DEFAULT_OPTIONS = {
|
|
|
413
428
|
return controller.abort();
|
|
414
429
|
});
|
|
415
430
|
loadedPlugins = [];
|
|
416
|
-
if (this.options.fetchPlugins)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
431
|
+
if (!(typeof this.options.fetchPlugins === 'function')) return [
|
|
432
|
+
3,
|
|
433
|
+
3
|
|
434
|
+
];
|
|
435
|
+
return [
|
|
436
|
+
4,
|
|
437
|
+
this.options.fetchPlugins(options)
|
|
438
|
+
];
|
|
439
|
+
case 2:
|
|
440
|
+
_tmp = _state.sent();
|
|
441
|
+
return [
|
|
442
|
+
3,
|
|
443
|
+
4
|
|
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
|
+
})));
|
|
429
460
|
return [
|
|
430
461
|
4,
|
|
431
462
|
Promise.all(loadedPlugins.map(function(plugin) {
|
|
432
463
|
return !plugin.canStart || plugin.canStart();
|
|
433
464
|
}))
|
|
434
465
|
];
|
|
435
|
-
case
|
|
466
|
+
case 5:
|
|
436
467
|
canStart = _state.sent();
|
|
437
468
|
isCanceledBy = canStart.indexOf(false);
|
|
438
|
-
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy,
|
|
469
|
+
asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, fetchPlugins[isCanceledBy], {
|
|
439
470
|
apiName: apiName,
|
|
440
471
|
operationId: operationId,
|
|
441
472
|
url: url,
|
|
@@ -465,19 +496,19 @@ var DEFAULT_OPTIONS = {
|
|
|
465
496
|
4,
|
|
466
497
|
asyncResponse
|
|
467
498
|
];
|
|
468
|
-
case
|
|
499
|
+
case 6:
|
|
469
500
|
response = _state.sent();
|
|
470
501
|
return [
|
|
471
502
|
4,
|
|
472
503
|
response.text()
|
|
473
504
|
];
|
|
474
|
-
case
|
|
505
|
+
case 7:
|
|
475
506
|
body = _state.sent();
|
|
476
507
|
return [
|
|
477
508
|
3,
|
|
478
|
-
|
|
509
|
+
9
|
|
479
510
|
];
|
|
480
|
-
case
|
|
511
|
+
case 8:
|
|
481
512
|
e = _state.sent();
|
|
482
513
|
if (_instanceof(e, CanceledCallError)) {
|
|
483
514
|
exception = e;
|
|
@@ -498,9 +529,9 @@ var DEFAULT_OPTIONS = {
|
|
|
498
529
|
}
|
|
499
530
|
return [
|
|
500
531
|
3,
|
|
501
|
-
|
|
532
|
+
9
|
|
502
533
|
];
|
|
503
|
-
case
|
|
534
|
+
case 9:
|
|
504
535
|
try {
|
|
505
536
|
root = body ? JSON.parse(body) : undefined;
|
|
506
537
|
} catch (e) {
|
|
@@ -532,49 +563,49 @@ var DEFAULT_OPTIONS = {
|
|
|
532
563
|
}) : [];
|
|
533
564
|
parsedData = root;
|
|
534
565
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
535
|
-
_state.label =
|
|
536
|
-
case
|
|
566
|
+
_state.label = 10;
|
|
567
|
+
case 10:
|
|
537
568
|
_state.trys.push([
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
569
|
+
10,
|
|
570
|
+
15,
|
|
571
|
+
16,
|
|
572
|
+
17
|
|
542
573
|
]);
|
|
543
574
|
_iterator1 = replyPlugins[Symbol.iterator]();
|
|
544
|
-
_state.label =
|
|
545
|
-
case
|
|
575
|
+
_state.label = 11;
|
|
576
|
+
case 11:
|
|
546
577
|
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
547
578
|
3,
|
|
548
|
-
|
|
579
|
+
14
|
|
549
580
|
];
|
|
550
581
|
pluginRunner = _step1.value;
|
|
551
582
|
return [
|
|
552
583
|
4,
|
|
553
584
|
pluginRunner.transform(parsedData)
|
|
554
585
|
];
|
|
555
|
-
case
|
|
586
|
+
case 12:
|
|
556
587
|
parsedData = _state.sent();
|
|
557
|
-
_state.label =
|
|
558
|
-
case
|
|
588
|
+
_state.label = 13;
|
|
589
|
+
case 13:
|
|
559
590
|
_iteratorNormalCompletion1 = true;
|
|
560
591
|
return [
|
|
561
592
|
3,
|
|
562
|
-
|
|
593
|
+
11
|
|
563
594
|
];
|
|
564
|
-
case
|
|
595
|
+
case 14:
|
|
565
596
|
return [
|
|
566
597
|
3,
|
|
567
|
-
|
|
598
|
+
17
|
|
568
599
|
];
|
|
569
|
-
case
|
|
600
|
+
case 15:
|
|
570
601
|
err = _state.sent();
|
|
571
602
|
_didIteratorError1 = true;
|
|
572
603
|
_iteratorError1 = err;
|
|
573
604
|
return [
|
|
574
605
|
3,
|
|
575
|
-
|
|
606
|
+
17
|
|
576
607
|
];
|
|
577
|
-
case
|
|
608
|
+
case 16:
|
|
578
609
|
try {
|
|
579
610
|
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
580
611
|
_iterator1.return();
|
|
@@ -587,7 +618,7 @@ var DEFAULT_OPTIONS = {
|
|
|
587
618
|
return [
|
|
588
619
|
7
|
|
589
620
|
];
|
|
590
|
-
case
|
|
621
|
+
case 17:
|
|
591
622
|
if (exception) {
|
|
592
623
|
throw exception;
|
|
593
624
|
}
|
|
@@ -168,30 +168,52 @@ 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);
|
|
171
172
|
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
|
+
};
|
|
172
180
|
}
|
|
173
181
|
_create_class(MockInterceptFetch, [
|
|
174
182
|
{
|
|
175
183
|
key: "load",
|
|
176
184
|
value: function load(context) {
|
|
177
185
|
var _this = this;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
186
|
+
var requestPlugins = typeof context.apiClient.options.requestPlugins === 'function' ? context.apiClient.options.requestPlugins(context.requestOptions) : context.apiClient.options.requestPlugins;
|
|
187
|
+
if (Array.isArray(requestPlugins)) {
|
|
188
|
+
this.checkMockInterceptFetchPlugin(requestPlugins);
|
|
182
189
|
}
|
|
183
190
|
return {
|
|
184
191
|
transform: function(fetchCall) {
|
|
185
192
|
return _async_to_generator(function() {
|
|
186
|
-
var responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
193
|
+
var _, _1, responsePromise, delay, _tmp, resp, operationId, mock, response;
|
|
187
194
|
return _ts_generator(this, function(_state) {
|
|
188
195
|
switch(_state.label){
|
|
189
196
|
case 0:
|
|
197
|
+
if (!!Array.isArray(requestPlugins)) return [
|
|
198
|
+
3,
|
|
199
|
+
2
|
|
200
|
+
];
|
|
201
|
+
_1 = (_ = this).checkMockInterceptFetchPlugin;
|
|
190
202
|
return [
|
|
191
203
|
4,
|
|
192
|
-
|
|
204
|
+
requestPlugins
|
|
193
205
|
];
|
|
194
206
|
case 1:
|
|
207
|
+
_1.apply(_, [
|
|
208
|
+
_state.sent()
|
|
209
|
+
]);
|
|
210
|
+
_state.label = 2;
|
|
211
|
+
case 2:
|
|
212
|
+
return [
|
|
213
|
+
4,
|
|
214
|
+
this.options.adapter.initialize()
|
|
215
|
+
];
|
|
216
|
+
case 3:
|
|
195
217
|
_state.sent();
|
|
196
218
|
responsePromise = fetchCall;
|
|
197
219
|
if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
|
|
@@ -202,40 +224,40 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
|
|
|
202
224
|
}
|
|
203
225
|
if (!(typeof this.options.delayTiming !== 'undefined')) return [
|
|
204
226
|
3,
|
|
205
|
-
|
|
227
|
+
8
|
|
206
228
|
];
|
|
207
229
|
if (!(typeof this.options.delayTiming === 'number')) return [
|
|
208
230
|
3,
|
|
209
|
-
|
|
231
|
+
4
|
|
210
232
|
];
|
|
211
233
|
_tmp = this.options.delayTiming;
|
|
212
234
|
return [
|
|
213
235
|
3,
|
|
214
|
-
|
|
236
|
+
6
|
|
215
237
|
];
|
|
216
|
-
case
|
|
238
|
+
case 4:
|
|
217
239
|
return [
|
|
218
240
|
4,
|
|
219
241
|
this.options.delayTiming(context)
|
|
220
242
|
];
|
|
221
|
-
case
|
|
243
|
+
case 5:
|
|
222
244
|
_tmp = _state.sent();
|
|
223
|
-
_state.label =
|
|
224
|
-
case
|
|
245
|
+
_state.label = 6;
|
|
246
|
+
case 6:
|
|
225
247
|
delay = _tmp;
|
|
226
248
|
return [
|
|
227
249
|
4,
|
|
228
250
|
responsePromise
|
|
229
251
|
];
|
|
230
|
-
case
|
|
252
|
+
case 7:
|
|
231
253
|
resp = _state.sent();
|
|
232
254
|
responsePromise = new Promise(function(resolve) {
|
|
233
255
|
return setTimeout(resolve, delay);
|
|
234
256
|
}).then(function() {
|
|
235
257
|
return resp;
|
|
236
258
|
});
|
|
237
|
-
_state.label =
|
|
238
|
-
case
|
|
259
|
+
_state.label = 8;
|
|
260
|
+
case 8:
|
|
239
261
|
operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
|
|
240
262
|
try {
|
|
241
263
|
mock = this.options.adapter.getLatestMock(operationId);
|
|
@@ -344,6 +344,42 @@ 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
|
+
});
|
|
347
383
|
});
|
|
348
384
|
});
|
|
349
385
|
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.40",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,20 +38,21 @@
|
|
|
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.40",
|
|
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.40",
|
|
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.40",
|
|
53
53
|
"@schematics/angular": "^19.0.0",
|
|
54
54
|
"isomorphic-fetch": "^3.0.0",
|
|
55
|
+
"type-fest": "^4.30.1",
|
|
55
56
|
"typescript": "^5.5.4"
|
|
56
57
|
},
|
|
57
58
|
"peerDependenciesMeta": {
|
|
@@ -73,12 +74,15 @@
|
|
|
73
74
|
"isomorphic-fetch": {
|
|
74
75
|
"optional": true
|
|
75
76
|
},
|
|
77
|
+
"type-fest": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
76
80
|
"typescript": {
|
|
77
81
|
"optional": true
|
|
78
82
|
}
|
|
79
83
|
},
|
|
80
84
|
"devDependencies": {
|
|
81
|
-
"@ama-sdk/core": "^12.5.0-prerelease.
|
|
85
|
+
"@ama-sdk/core": "^12.5.0-prerelease.40",
|
|
82
86
|
"@angular-devkit/core": "~19.2.0",
|
|
83
87
|
"@angular-devkit/schematics": "~19.2.0",
|
|
84
88
|
"@angular/common": "~19.2.0",
|
|
@@ -86,9 +90,9 @@
|
|
|
86
90
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
87
91
|
"@nx/eslint-plugin": "~20.8.0",
|
|
88
92
|
"@nx/jest": "~20.8.0",
|
|
89
|
-
"@o3r/build-helpers": "^12.5.0-prerelease.
|
|
90
|
-
"@o3r/eslint-plugin": "^12.5.0-prerelease.
|
|
91
|
-
"@o3r/test-helpers": "^12.5.0-prerelease.
|
|
93
|
+
"@o3r/build-helpers": "^12.5.0-prerelease.40",
|
|
94
|
+
"@o3r/eslint-plugin": "^12.5.0-prerelease.40",
|
|
95
|
+
"@o3r/test-helpers": "^12.5.0-prerelease.40",
|
|
92
96
|
"@schematics/angular": "~19.2.0",
|
|
93
97
|
"@stylistic/eslint-plugin": "~3.1.0",
|
|
94
98
|
"@stylistic/eslint-plugin-ts": "~3.1.0",
|
|
@@ -96,16 +100,15 @@
|
|
|
96
100
|
"@swc/core": "~1.12.0",
|
|
97
101
|
"@types/jest": "~29.5.2",
|
|
98
102
|
"@types/node": "^20.0.0",
|
|
99
|
-
"@
|
|
100
|
-
"@typescript-eslint/parser": "~8.34.0",
|
|
103
|
+
"@typescript-eslint/parser": "~8.37.0",
|
|
101
104
|
"angular-eslint": "~19.4.0",
|
|
102
105
|
"cpy-cli": "^5.0.0",
|
|
103
|
-
"eslint": "~9.
|
|
106
|
+
"eslint": "~9.31.0",
|
|
104
107
|
"eslint-import-resolver-node": "~0.3.9",
|
|
105
108
|
"eslint-import-resolver-typescript": "~3.10.0",
|
|
106
|
-
"eslint-plugin-import": "~2.
|
|
109
|
+
"eslint-plugin-import": "~2.32.0",
|
|
107
110
|
"eslint-plugin-import-newlines": "~1.4.0",
|
|
108
|
-
"eslint-plugin-jest": "~28.
|
|
111
|
+
"eslint-plugin-jest": "~28.14.0",
|
|
109
112
|
"eslint-plugin-jsdoc": "~50.8.0",
|
|
110
113
|
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
111
114
|
"eslint-plugin-unicorn": "~56.0.0",
|
|
@@ -123,7 +126,7 @@
|
|
|
123
126
|
"ts-node": "~10.9.2",
|
|
124
127
|
"type-fest": "^4.30.1",
|
|
125
128
|
"typescript": "~5.8.2",
|
|
126
|
-
"typescript-eslint": "~8.
|
|
129
|
+
"typescript-eslint": "~8.37.0",
|
|
127
130
|
"zone.js": "~0.15.0"
|
|
128
131
|
},
|
|
129
132
|
"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;AA2DlB;;;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");
|
|
8
7
|
const import_map_1 = require("./migration/import-map");
|
|
9
8
|
const devDependenciesToInstall = [];
|
|
9
|
+
const dependenciesToInstall = [];
|
|
10
10
|
/**
|
|
11
11
|
* Add SDk Fetch Client to an Otter Project
|
|
12
12
|
* @param options
|
|
@@ -16,6 +16,7 @@ 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'));
|
|
19
20
|
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
|
|
20
21
|
acc[dep] = {
|
|
21
22
|
inManifest: [{
|
|
@@ -26,22 +27,23 @@ function ngAddFn(options) {
|
|
|
26
27
|
};
|
|
27
28
|
return acc;
|
|
28
29
|
}, (0, schematics_2.getPackageInstallConfig)(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
});
|
|
30
|
+
const externalDependenciesInfo = (0, schematics_2.getExternalDependenciesInfo)({
|
|
31
|
+
devDependenciesToInstall,
|
|
32
|
+
dependenciesToInstall,
|
|
33
|
+
o3rPackageJsonPath: packageJsonPath,
|
|
34
|
+
projectPackageJson,
|
|
35
|
+
projectType: workspaceProject?.projectType
|
|
36
|
+
}, context.logger);
|
|
38
37
|
return (0, schematics_1.chain)([
|
|
39
38
|
// optional custom action dedicated to this module
|
|
40
39
|
options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)(),
|
|
41
40
|
// add the missing Otter modules in the current project
|
|
42
41
|
(0, schematics_2.setupDependencies)({
|
|
43
42
|
projectName: options.projectName,
|
|
44
|
-
dependencies
|
|
43
|
+
dependencies: {
|
|
44
|
+
...dependencies,
|
|
45
|
+
...externalDependenciesInfo
|
|
46
|
+
},
|
|
45
47
|
ngAddToRun: depsInfo.o3rPeerDeps
|
|
46
48
|
}),
|
|
47
49
|
(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[] | ((requestOpts: RequestOptions) => FetchPlugin[] | Promise<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,WA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AE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAO;IAI1F,kBAAkB;IACX,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,qBAAqB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,MAAM;IAIxG,kBAAkB;IACX,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM;IAI9C,kBAAkB;IACL,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IACzJ,WAAW,CAAC,CAAC,EAAE,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;CA6FpC"}
|
package/src/api-fetch-client.js
CHANGED
|
@@ -42,13 +42,14 @@ 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
|
-
|
|
45
|
+
const requestPlugins = typeof this.options.requestPlugins === 'function'
|
|
46
|
+
? await this.options.requestPlugins(opts)
|
|
47
|
+
: this.options.requestPlugins;
|
|
48
|
+
for (const plugin of requestPlugins) {
|
|
49
|
+
opts = await plugin.load({
|
|
50
|
+
logger: this.options.logger,
|
|
51
|
+
apiName: requestOptionsParameters.api?.apiName
|
|
52
|
+
}).transform(opts);
|
|
52
53
|
}
|
|
53
54
|
return opts;
|
|
54
55
|
}
|
|
@@ -93,15 +94,16 @@ export class ApiFetchClient {
|
|
|
93
94
|
options.signal = controller.signal;
|
|
94
95
|
metadataSignal?.addEventListener('abort', () => controller.abort());
|
|
95
96
|
const loadedPlugins = [];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
const fetchPlugins = typeof this.options.fetchPlugins === 'function'
|
|
98
|
+
? await this.options.fetchPlugins(options)
|
|
99
|
+
: this.options.fetchPlugins;
|
|
100
|
+
loadedPlugins.push(...fetchPlugins.map((plugin) => plugin.load({ url, options, fetchPlugins: loadedPlugins, controller, apiClient: this, logger: this.options.logger })));
|
|
99
101
|
const canStart = await Promise.all(loadedPlugins.map((plugin) => !plugin.canStart || plugin.canStart()));
|
|
100
102
|
const isCanceledBy = canStart.indexOf(false);
|
|
101
103
|
asyncResponse = isCanceledBy === -1
|
|
102
104
|
// One of the fetch plugins cancelled the execution of the call
|
|
103
105
|
? fetch(url, options)
|
|
104
|
-
: Promise.reject(new CanceledCallError(`Is canceled by the plugin ${isCanceledBy}`, isCanceledBy,
|
|
106
|
+
: Promise.reject(new CanceledCallError(`Is canceled by the plugin ${isCanceledBy}`, isCanceledBy, fetchPlugins[isCanceledBy], { apiName, operationId, url, origin }));
|
|
105
107
|
for (const plugin of loadedPlugins) {
|
|
106
108
|
asyncResponse = plugin.transform(asyncResponse);
|
|
107
109
|
}
|
|
@@ -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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AAG,wBAAwB;YAC3B,OAAO,EAAE,IAAI,OAAO,CAAC,qBAAqB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;YAC7E,WAAW,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,WAAW,CAAC;SACzE,CAAC;QACF,
|
|
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,GAAG;YACb,GAAG,eAAe;YAClB,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,kBAAkB;IACX,kBAAkB,CAAmC,IAAO,EAAE,KAAkB;QACrF,OAAO,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,kBAAkB;IACX,qBAAqB,CAAuB,IAAO,EAAE,IAAS;QACnE,OAAO,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,kBAAkB;IACX,oBAAoB,CAAkD,WAAc;QACzF,OAAO,oBAAoB,CA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,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3I,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY;YAC5C,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAI;gBACzD,YAAY,EAAE,IAAI,IAAI,IAAI,CAAC,YAAY;gBACvC,QAAQ;gBACR,OAAO;gBACP,OAAO;gBACP,OAAO;gBACP,SAAS;gBACT,WAAW;gBACX,GAAG;gBACH,MAAM;gBACN,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;QAEP,IAAI,UAAU,GAAG,IAAI,CAAC;QACtB,KAAK,MAAM,YAAY,IAAI,YAAY,EAAE,CAAC;YACxC,UAAU,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -10,6 +10,7 @@ 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;
|
|
13
14
|
load(context: FetchPluginContext): PluginAsyncRunner<Response, Promise<Response>> & PluginAsyncStarter;
|
|
14
15
|
}
|
|
15
16
|
//# 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,EAElB,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;IAE3D,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAI5C;IAEK,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,kBAAkB;CA2C9G"}
|
|
@@ -8,13 +8,24 @@ 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
|
+
};
|
|
11
16
|
}
|
|
12
17
|
load(context) {
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
const requestPlugins = typeof context.apiClient.options.requestPlugins === 'function'
|
|
19
|
+
? context.apiClient.options.requestPlugins(context.requestOptions)
|
|
20
|
+
: context.apiClient.options.requestPlugins;
|
|
21
|
+
if (Array.isArray(requestPlugins)) {
|
|
22
|
+
this.checkMockInterceptFetchPlugin(requestPlugins);
|
|
15
23
|
}
|
|
16
24
|
return {
|
|
17
25
|
transform: async (fetchCall) => {
|
|
26
|
+
if (!Array.isArray(requestPlugins)) {
|
|
27
|
+
this.checkMockInterceptFetchPlugin(await requestPlugins);
|
|
28
|
+
}
|
|
18
29
|
await this.options.adapter.initialize();
|
|
19
30
|
let responsePromise = fetchCall;
|
|
20
31
|
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":"AAIA,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAWvB;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAC7B,YAAsB,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;QAE1C,kCAA6B,GAAG,CAAC,cAA+B,EAAE,EAAE;YACnF,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,YAAY,oBAAoB,CAAC,EAAE,CAAC;gBAC7E,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;YACxG,CAAC;QACH,CAAC,CAAC;IAN4D,CAAC;IAQxD,IAAI,CAAC,OAA2B;QACrC,MAAM,cAAc,GAAG,OAAO,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,KAAK,UAAU;YACnF,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC;YAClE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