@ama-sdk/client-fetch 12.3.0-prerelease.70 → 12.3.0-prerelease.72

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.
Files changed (31) hide show
  1. package/cjs/api-fetch-client.js +12 -13
  2. package/cjs/plugins/abort/abort.spec.js +79 -73
  3. package/cjs/plugins/concurrent/concurrent.fetch.js +8 -12
  4. package/cjs/plugins/concurrent/concurrent.spec.js +95 -91
  5. package/cjs/plugins/keepalive/keepalive.request.js +3 -4
  6. package/cjs/plugins/keepalive/keepalive.spec.js +28 -26
  7. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +11 -14
  8. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +243 -231
  9. package/cjs/plugins/perf-metric/perf-metric.fetch.js +7 -10
  10. package/cjs/plugins/retry/retry.fetch.js +14 -19
  11. package/cjs/plugins/retry/retry.spec.js +229 -217
  12. package/cjs/plugins/timeout/timeout.fetch.js +9 -11
  13. package/cjs/plugins/timeout/timeout.spec.js +207 -197
  14. package/cjs/plugins/wait-for/wait-for.fetch.js +15 -21
  15. package/cjs/plugins/wait-for/wait-for.spec.js +207 -195
  16. package/esm2015/api-fetch-client.js +12 -13
  17. package/esm2015/plugins/abort/abort.spec.js +79 -73
  18. package/esm2015/plugins/concurrent/concurrent.fetch.js +8 -12
  19. package/esm2015/plugins/concurrent/concurrent.spec.js +95 -91
  20. package/esm2015/plugins/keepalive/keepalive.request.js +3 -4
  21. package/esm2015/plugins/keepalive/keepalive.spec.js +28 -26
  22. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +11 -14
  23. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +243 -231
  24. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +7 -10
  25. package/esm2015/plugins/retry/retry.fetch.js +14 -19
  26. package/esm2015/plugins/retry/retry.spec.js +229 -217
  27. package/esm2015/plugins/timeout/timeout.fetch.js +9 -11
  28. package/esm2015/plugins/timeout/timeout.spec.js +207 -197
  29. package/esm2015/plugins/wait-for/wait-for.fetch.js +15 -21
  30. package/esm2015/plugins/wait-for/wait-for.spec.js +207 -195
  31. package/package.json +8 -8
@@ -177,203 +177,215 @@ function _ts_generator(thisArg, body) {
177
177
  }
178
178
  describe('Wait For Fetch Plugin', function() {
179
179
  var defaultContext = {};
180
- it('should not start if timeout', /*#__PURE__*/ _async_to_generator(function() {
181
- var plugin, runner, canStart;
182
- return _ts_generator(this, function(_state) {
183
- switch(_state.label){
184
- case 0:
185
- plugin = new _waitforfetch.WaitForFetch(function() {
186
- return {
187
- result: new Promise(function(resolve) {
188
- return setTimeout(function() {
189
- return resolve(true);
190
- }, 2000);
191
- })
192
- };
193
- }, 100);
194
- runner = plugin.load(defaultContext);
195
- canStart = runner.canStart();
196
- return [
197
- 4,
198
- jest.runAllTimersAsync()
199
- ];
200
- case 1:
201
- _state.sent();
202
- return [
203
- 4,
204
- canStart
205
- ];
206
- case 2:
207
- expect.apply(void 0, [
208
- _state.sent()
209
- ]).toBe(false);
210
- return [
211
- 2
212
- ];
213
- }
214
- });
215
- }));
216
- it('should start if promise condition passed', /*#__PURE__*/ _async_to_generator(function() {
217
- var plugin, runner, canStart;
218
- return _ts_generator(this, function(_state) {
219
- switch(_state.label){
220
- case 0:
221
- plugin = new _waitforfetch.WaitForFetch(function() {
222
- return {
223
- result: Promise.resolve(true)
224
- };
225
- }, 100);
226
- runner = plugin.load(defaultContext);
227
- return [
228
- 4,
229
- runner.canStart()
230
- ];
231
- case 1:
232
- canStart = _state.sent();
233
- expect(canStart).toBe(true);
234
- return [
235
- 2
236
- ];
237
- }
238
- });
239
- }));
240
- it('should start if condition passed', /*#__PURE__*/ _async_to_generator(function() {
241
- var plugin, runner, canStart;
242
- return _ts_generator(this, function(_state) {
243
- switch(_state.label){
244
- case 0:
245
- plugin = new _waitforfetch.WaitForFetch(function() {
246
- return {
247
- result: true
180
+ it('should not start if timeout', function() {
181
+ return _async_to_generator(function() {
182
+ var plugin, runner, canStart;
183
+ return _ts_generator(this, function(_state) {
184
+ switch(_state.label){
185
+ case 0:
186
+ plugin = new _waitforfetch.WaitForFetch(function() {
187
+ return {
188
+ result: new Promise(function(resolve) {
189
+ return setTimeout(function() {
190
+ return resolve(true);
191
+ }, 2000);
192
+ })
193
+ };
194
+ }, 100);
195
+ runner = plugin.load(defaultContext);
196
+ canStart = runner.canStart();
197
+ return [
198
+ 4,
199
+ jest.runAllTimersAsync()
200
+ ];
201
+ case 1:
202
+ _state.sent();
203
+ return [
204
+ 4,
205
+ canStart
206
+ ];
207
+ case 2:
208
+ expect.apply(void 0, [
209
+ _state.sent()
210
+ ]).toBe(false);
211
+ return [
212
+ 2
213
+ ];
214
+ }
215
+ });
216
+ })();
217
+ });
218
+ it('should start if promise condition passed', function() {
219
+ return _async_to_generator(function() {
220
+ var plugin, runner, canStart;
221
+ return _ts_generator(this, function(_state) {
222
+ switch(_state.label){
223
+ case 0:
224
+ plugin = new _waitforfetch.WaitForFetch(function() {
225
+ return {
226
+ result: Promise.resolve(true)
227
+ };
228
+ }, 100);
229
+ runner = plugin.load(defaultContext);
230
+ return [
231
+ 4,
232
+ runner.canStart()
233
+ ];
234
+ case 1:
235
+ canStart = _state.sent();
236
+ expect(canStart).toBe(true);
237
+ return [
238
+ 2
239
+ ];
240
+ }
241
+ });
242
+ })();
243
+ });
244
+ it('should start if condition passed', function() {
245
+ return _async_to_generator(function() {
246
+ var plugin, runner, canStart;
247
+ return _ts_generator(this, function(_state) {
248
+ switch(_state.label){
249
+ case 0:
250
+ plugin = new _waitforfetch.WaitForFetch(function() {
251
+ return {
252
+ result: true
253
+ };
254
+ }, 100);
255
+ runner = plugin.load(defaultContext);
256
+ return [
257
+ 4,
258
+ runner.canStart()
259
+ ];
260
+ case 1:
261
+ canStart = _state.sent();
262
+ expect(canStart).toBe(true);
263
+ return [
264
+ 2
265
+ ];
266
+ }
267
+ });
268
+ })();
269
+ });
270
+ it('should call the callback function on success', function() {
271
+ return _async_to_generator(function() {
272
+ var callback, plugin, runner, response, fetchCall;
273
+ return _ts_generator(this, function(_state) {
274
+ switch(_state.label){
275
+ case 0:
276
+ callback = jest.fn();
277
+ plugin = new _waitforfetch.WaitForFetch(function() {
278
+ return {
279
+ result: true
280
+ };
281
+ }, 100, callback);
282
+ runner = plugin.load(defaultContext);
283
+ response = {
284
+ test: true
248
285
  };
249
- }, 100);
250
- runner = plugin.load(defaultContext);
251
- return [
252
- 4,
253
- runner.canStart()
254
- ];
255
- case 1:
256
- canStart = _state.sent();
257
- expect(canStart).toBe(true);
258
- return [
259
- 2
260
- ];
261
- }
262
- });
263
- }));
264
- it('should call the callback function on success', /*#__PURE__*/ _async_to_generator(function() {
265
- var callback, plugin, runner, response, fetchCall;
266
- return _ts_generator(this, function(_state) {
267
- switch(_state.label){
268
- case 0:
269
- callback = jest.fn();
270
- plugin = new _waitforfetch.WaitForFetch(function() {
271
- return {
272
- result: true
286
+ fetchCall = Promise.resolve(response);
287
+ return [
288
+ 4,
289
+ runner.transform(fetchCall)
290
+ ];
291
+ case 1:
292
+ _state.sent();
293
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, response);
294
+ return [
295
+ 2
296
+ ];
297
+ }
298
+ });
299
+ })();
300
+ });
301
+ it('should call the callback function with the correct data', function() {
302
+ return _async_to_generator(function() {
303
+ var callback, plugin, runner, response, fetchCall;
304
+ return _ts_generator(this, function(_state) {
305
+ switch(_state.label){
306
+ case 0:
307
+ callback = jest.fn();
308
+ plugin = new _waitforfetch.WaitForFetch(function() {
309
+ return {
310
+ result: true,
311
+ data: 'test'
312
+ };
313
+ }, 100, callback);
314
+ runner = plugin.load(defaultContext);
315
+ response = {
316
+ test: true
273
317
  };
274
- }, 100, callback);
275
- runner = plugin.load(defaultContext);
276
- response = {
277
- test: true
278
- };
279
- fetchCall = Promise.resolve(response);
280
- return [
281
- 4,
282
- runner.transform(fetchCall)
283
- ];
284
- case 1:
285
- _state.sent();
286
- expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, response);
287
- return [
288
- 2
289
- ];
290
- }
291
- });
292
- }));
293
- it('should call the callback function with the correct data', /*#__PURE__*/ _async_to_generator(function() {
294
- var callback, plugin, runner, response, fetchCall;
295
- return _ts_generator(this, function(_state) {
296
- switch(_state.label){
297
- case 0:
298
- callback = jest.fn();
299
- plugin = new _waitforfetch.WaitForFetch(function() {
300
- return {
301
- result: true,
318
+ fetchCall = Promise.resolve(response);
319
+ return [
320
+ 4,
321
+ runner.canStart()
322
+ ];
323
+ case 1:
324
+ _state.sent();
325
+ return [
326
+ 4,
327
+ runner.transform(fetchCall)
328
+ ];
329
+ case 2:
330
+ _state.sent();
331
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(_object_spread_props(_object_spread({}, defaultContext), {
302
332
  data: 'test'
333
+ })), fetchCall, response);
334
+ return [
335
+ 2
336
+ ];
337
+ }
338
+ });
339
+ })();
340
+ });
341
+ it('should call the callback function on failure', function() {
342
+ return _async_to_generator(function() {
343
+ var callback, plugin, runner, response, fetchCall, e;
344
+ return _ts_generator(this, function(_state) {
345
+ switch(_state.label){
346
+ case 0:
347
+ callback = jest.fn();
348
+ plugin = new _waitforfetch.WaitForFetch(function() {
349
+ return {
350
+ result: true
351
+ };
352
+ }, 100, callback);
353
+ runner = plugin.load(defaultContext);
354
+ response = {
355
+ test: true
303
356
  };
304
- }, 100, callback);
305
- runner = plugin.load(defaultContext);
306
- response = {
307
- test: true
308
- };
309
- fetchCall = Promise.resolve(response);
310
- return [
311
- 4,
312
- runner.canStart()
313
- ];
314
- case 1:
315
- _state.sent();
316
- return [
317
- 4,
318
- runner.transform(fetchCall)
319
- ];
320
- case 2:
321
- _state.sent();
322
- expect(callback).toHaveBeenCalledWith(expect.objectContaining(_object_spread_props(_object_spread({}, defaultContext), {
323
- data: 'test'
324
- })), fetchCall, response);
325
- return [
326
- 2
327
- ];
328
- }
329
- });
330
- }));
331
- it('should call the callback function on failure', /*#__PURE__*/ _async_to_generator(function() {
332
- var callback, plugin, runner, response, fetchCall, e;
333
- return _ts_generator(this, function(_state) {
334
- switch(_state.label){
335
- case 0:
336
- callback = jest.fn();
337
- plugin = new _waitforfetch.WaitForFetch(function() {
338
- return {
339
- result: true
340
- };
341
- }, 100, callback);
342
- runner = plugin.load(defaultContext);
343
- response = {
344
- test: true
345
- };
346
- fetchCall = Promise.reject(new Error(JSON.stringify(response)));
347
- _state.label = 1;
348
- case 1:
349
- _state.trys.push([
350
- 1,
351
- 3,
352
- ,
353
- 4
354
- ]);
355
- return [
356
- 4,
357
- runner.transform(fetchCall)
358
- ];
359
- case 2:
360
- _state.sent();
361
- return [
362
- 3,
363
- 4
364
- ];
365
- case 3:
366
- e = _state.sent();
367
- return [
368
- 3,
369
- 4
370
- ];
371
- case 4:
372
- expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, undefined);
373
- return [
374
- 2
375
- ];
376
- }
377
- });
378
- }));
357
+ fetchCall = Promise.reject(new Error(JSON.stringify(response)));
358
+ _state.label = 1;
359
+ case 1:
360
+ _state.trys.push([
361
+ 1,
362
+ 3,
363
+ ,
364
+ 4
365
+ ]);
366
+ return [
367
+ 4,
368
+ runner.transform(fetchCall)
369
+ ];
370
+ case 2:
371
+ _state.sent();
372
+ return [
373
+ 3,
374
+ 4
375
+ ];
376
+ case 3:
377
+ e = _state.sent();
378
+ return [
379
+ 3,
380
+ 4
381
+ ];
382
+ case 4:
383
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(defaultContext), fetchCall, undefined);
384
+ return [
385
+ 2
386
+ ];
387
+ }
388
+ });
389
+ })();
390
+ });
379
391
  });
@@ -268,7 +268,6 @@ var DEFAULT_OPTIONS = {
268
268
  {
269
269
  key: "getRequestOptions",
270
270
  value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
271
- var _this = this;
272
271
  return _async_to_generator(function() {
273
272
  var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
274
273
  return _ts_generator(this, function(_state) {
@@ -278,7 +277,7 @@ var DEFAULT_OPTIONS = {
278
277
  headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
279
278
  queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
280
279
  });
281
- if (!_this.options.requestPlugins) return [
280
+ if (!this.options.requestPlugins) return [
282
281
  3,
283
282
  8
284
283
  ];
@@ -291,7 +290,7 @@ var DEFAULT_OPTIONS = {
291
290
  7,
292
291
  8
293
292
  ]);
294
- _iterator = _this.options.requestPlugins[Symbol.iterator]();
293
+ _iterator = this.options.requestPlugins[Symbol.iterator]();
295
294
  _state.label = 2;
296
295
  case 2:
297
296
  if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
@@ -302,7 +301,7 @@ var DEFAULT_OPTIONS = {
302
301
  return [
303
302
  4,
304
303
  plugin.load({
305
- logger: _this.options.logger,
304
+ logger: this.options.logger,
306
305
  apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
307
306
  }).transform(opts)
308
307
  ];
@@ -348,7 +347,7 @@ var DEFAULT_OPTIONS = {
348
347
  ];
349
348
  }
350
349
  });
351
- })();
350
+ }).call(this);
352
351
  }
353
352
  },
354
353
  {
@@ -391,12 +390,12 @@ var DEFAULT_OPTIONS = {
391
390
  {
392
391
  key: "processCall",
393
392
  value: function processCall(url, options, apiType, apiName, revivers, operationId) {
394
- var _this = this;
395
393
  return _async_to_generator(function() {
396
- var 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;
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;
397
395
  return _ts_generator(this, function(_state) {
398
396
  switch(_state.label){
399
397
  case 0:
398
+ _this = this;
400
399
  origin = options.headers.get('Origin');
401
400
  _state.label = 1;
402
401
  case 1:
@@ -414,9 +413,9 @@ var DEFAULT_OPTIONS = {
414
413
  return controller.abort();
415
414
  });
416
415
  loadedPlugins = [];
417
- if (_this.options.fetchPlugins) {
416
+ if (this.options.fetchPlugins) {
418
417
  ;
419
- (_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(_this.options.fetchPlugins.map(function(plugin) {
418
+ (_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
420
419
  return plugin.load({
421
420
  url: url,
422
421
  options: options,
@@ -436,7 +435,7 @@ var DEFAULT_OPTIONS = {
436
435
  case 2:
437
436
  canStart = _state.sent();
438
437
  isCanceledBy = canStart.indexOf(false);
439
- asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, _this.options.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], {
440
439
  apiName: apiName,
441
440
  operationId: operationId,
442
441
  url: url,
@@ -514,10 +513,10 @@ var DEFAULT_OPTIONS = {
514
513
  }
515
514
  // eslint-disable-next-line no-console -- `console.error` is supposed to be the default value if the `options` argument is not provided, can be removed in Otter v12.
516
515
  reviver = getResponseReviver(revivers, response, operationId, {
517
- disableFallback: _this.options.disableFallback,
516
+ disableFallback: this.options.disableFallback,
518
517
  log: console.error
519
518
  });
520
- replyPlugins = _this.options.replyPlugins ? _this.options.replyPlugins.map(function(plugin) {
519
+ replyPlugins = this.options.replyPlugins ? this.options.replyPlugins.map(function(plugin) {
521
520
  return plugin.load({
522
521
  dictionaries: root && root.dictionaries,
523
522
  response: response,
@@ -598,7 +597,7 @@ var DEFAULT_OPTIONS = {
598
597
  ];
599
598
  }
600
599
  });
601
- })();
600
+ }).call(this);
602
601
  }
603
602
  }
604
603
  ]);