@ama-sdk/client-fetch 11.6.0-prerelease.7 → 11.6.0-prerelease.9

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 (54) hide show
  1. package/cjs/api-fetch-client.js +13 -22
  2. package/cjs/plugins/concurrent/concurrent.fetch.js +5 -9
  3. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +0 -2
  4. package/cjs/plugins/perf-metric/perf-metric.fetch.js +1 -1
  5. package/cjs/plugins/retry/retry.fetch.js +16 -31
  6. package/cjs/plugins/retry/retry.spec.js +4 -4
  7. package/cjs/plugins/timeout/timeout.fetch.js +10 -3
  8. package/cjs/plugins/wait-for/wait-for.fetch.js +3 -3
  9. package/cjs/plugins/wait-for/wait-for.spec.js +1 -1
  10. package/esm2015/api-fetch-client.js +13 -22
  11. package/esm2015/plugins/concurrent/concurrent.fetch.js +5 -9
  12. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +0 -2
  13. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +1 -1
  14. package/esm2015/plugins/retry/retry.fetch.js +16 -31
  15. package/esm2015/plugins/retry/retry.spec.js +4 -4
  16. package/esm2015/plugins/timeout/timeout.fetch.js +11 -5
  17. package/esm2015/plugins/wait-for/wait-for.fetch.js +3 -3
  18. package/esm2015/plugins/wait-for/wait-for.spec.js +1 -1
  19. package/package.json +20 -15
  20. package/schematics/ng-add/index.d.ts.map +1 -1
  21. package/schematics/ng-add/index.js +1 -1
  22. package/schematics/ng-add/migration/import-map.d.ts.map +1 -1
  23. package/schematics/ng-add/migration/import-map.js +0 -1
  24. package/schematics/ng-add/schema.d.ts.map +1 -1
  25. package/src/api-fetch-client.d.ts.map +1 -1
  26. package/src/api-fetch-client.js +13 -18
  27. package/src/api-fetch-client.js.map +1 -1
  28. package/src/fetch-plugin.d.ts.map +1 -1
  29. package/src/plugins/abort/abort.fetch.d.ts.map +1 -1
  30. package/src/plugins/abort/abort.fetch.js.map +1 -1
  31. package/src/plugins/concurrent/concurrent.fetch.d.ts.map +1 -1
  32. package/src/plugins/concurrent/concurrent.fetch.js +1 -6
  33. package/src/plugins/concurrent/concurrent.fetch.js.map +1 -1
  34. package/src/plugins/keepalive/keepalive.request.d.ts.map +1 -1
  35. package/src/plugins/keepalive/keepalive.request.js +1 -1
  36. package/src/plugins/keepalive/keepalive.request.js.map +1 -1
  37. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts +1 -1
  38. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts.map +1 -1
  39. package/src/plugins/mock-intercept/mock-intercept.fetch.js +1 -3
  40. package/src/plugins/mock-intercept/mock-intercept.fetch.js.map +1 -1
  41. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts.map +1 -1
  42. package/src/plugins/perf-metric/perf-metric.fetch.d.ts.map +1 -1
  43. package/src/plugins/perf-metric/perf-metric.fetch.js +2 -2
  44. package/src/plugins/perf-metric/perf-metric.fetch.js.map +1 -1
  45. package/src/plugins/retry/retry.fetch.d.ts.map +1 -1
  46. package/src/plugins/retry/retry.fetch.js +3 -3
  47. package/src/plugins/retry/retry.fetch.js.map +1 -1
  48. package/src/plugins/timeout/timeout.fetch.d.ts +1 -2
  49. package/src/plugins/timeout/timeout.fetch.d.ts.map +1 -1
  50. package/src/plugins/timeout/timeout.fetch.js +12 -12
  51. package/src/plugins/timeout/timeout.fetch.js.map +1 -1
  52. package/src/plugins/wait-for/wait-for.fetch.d.ts.map +1 -1
  53. package/src/plugins/wait-for/wait-for.fetch.js +2 -2
  54. package/src/plugins/wait-for/wait-for.fetch.js.map +1 -1
@@ -413,17 +413,12 @@ var ApiFetchClient = /*#__PURE__*/ function() {
413
413
  case 2:
414
414
  canStart = _state.sent();
415
415
  isCanceledBy = canStart.indexOf(false);
416
- if (isCanceledBy >= 0) {
417
- // One of the fetch plugins cancelled the execution of the call
418
- asyncResponse = Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, _this.options.fetchPlugins[isCanceledBy], {
419
- apiName: apiName,
420
- operationId: operationId,
421
- url: url,
422
- origin: origin
423
- }));
424
- } else {
425
- asyncResponse = fetch(url, options);
426
- }
416
+ asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, _this.options.fetchPlugins[isCanceledBy], {
417
+ apiName: apiName,
418
+ operationId: operationId,
419
+ url: url,
420
+ origin: origin
421
+ }));
427
422
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
428
423
  try {
429
424
  for(_iterator = loadedPlugins[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -462,16 +457,12 @@ var ApiFetchClient = /*#__PURE__*/ function() {
462
457
  ];
463
458
  case 5:
464
459
  e = _state.sent();
465
- if (_instanceof(e, _core.CanceledCallError)) {
466
- exception = e;
467
- } else {
468
- exception = new _core.EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
469
- apiName: apiName,
470
- operationId: operationId,
471
- url: url,
472
- origin: origin
473
- });
474
- }
460
+ exception = _instanceof(e, _core.CanceledCallError) ? e : new _core.EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
461
+ apiName: apiName,
462
+ operationId: operationId,
463
+ url: url,
464
+ origin: origin
465
+ });
475
466
  return [
476
467
  3,
477
468
  6
@@ -487,7 +478,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
487
478
  origin: origin
488
479
  });
489
480
  }
490
- // eslint-disable-next-line no-console
481
+ // 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.
491
482
  reviver = (0, _core.getResponseReviver)(revivers, response, operationId, {
492
483
  disableFallback: _this.options.disableFallback,
493
484
  log: console.error
@@ -189,7 +189,7 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
189
189
  value: /**
190
190
  * Unstack and resolve the promise stopping the call to start
191
191
  */ function unstackResolve() {
192
- if (this.canStart() && this.waitingResolvers.length) {
192
+ if (this.canStart() && this.waitingResolvers.length > 0) {
193
193
  this.waitingResolvers.shift()(true);
194
194
  }
195
195
  }
@@ -208,7 +208,7 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
208
208
  },
209
209
  transform: /*#__PURE__*/ function() {
210
210
  var _ref = _async_to_generator(function(fetchCall) {
211
- var fetchResponse, e;
211
+ var fetchResponse;
212
212
  return _ts_generator(this, function(_state) {
213
213
  switch(_state.label){
214
214
  case 0:
@@ -217,9 +217,9 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
217
217
  case 1:
218
218
  _state.trys.push([
219
219
  1,
220
+ ,
220
221
  3,
221
- 4,
222
- 5
222
+ 4
223
223
  ]);
224
224
  return [
225
225
  4,
@@ -232,10 +232,6 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
232
232
  fetchResponse
233
233
  ];
234
234
  case 3:
235
- e = _state.sent();
236
- throw e;
237
- case 4:
238
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
239
235
  _this1.pool = _this1.pool.filter(function(call) {
240
236
  return call !== fetchCall;
241
237
  });
@@ -244,7 +240,7 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
244
240
  return [
245
241
  7
246
242
  ];
247
- case 5:
243
+ case 4:
248
244
  return [
249
245
  2
250
246
  ];
@@ -203,7 +203,6 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
203
203
  case 1:
204
204
  _state.sent();
205
205
  responsePromise = fetchCall;
206
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
207
206
  if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(_core.CUSTOM_MOCK_OPERATION_ID_HEADER)) {
208
207
  return [
209
208
  2,
@@ -246,7 +245,6 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
246
245
  });
247
246
  _state.label = 6;
248
247
  case 6:
249
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
250
248
  operationId = context.options.headers.get(_core.CUSTOM_MOCK_OPERATION_ID_HEADER);
251
249
  try {
252
250
  mock = _this.options.adapter.getLatestMock(operationId);
@@ -236,7 +236,7 @@ var PerformanceMetricPlugin = /*#__PURE__*/ function() {
236
236
  return "sdk:".concat(status, ":").concat(markId);
237
237
  });
238
238
  this.getPerformanceTag = (options === null || options === void 0 ? void 0 : options.getPerformanceTag) || this.getPerformanceTag;
239
- this.performance = (options === null || options === void 0 ? void 0 : options.performance) || (typeof window !== 'undefined' ? window.performance : undefined);
239
+ this.performance = (options === null || options === void 0 ? void 0 : options.performance) || (typeof window === 'undefined' ? undefined : window.performance);
240
240
  this.onMarkComplete = options ? options.onMarkComplete : this.onMarkComplete;
241
241
  this.onMarkError = options ? options.onMarkError : this.onMarkError;
242
242
  this.onMarkOpen = options ? options.onMarkOpen : this.onMarkOpen;
@@ -224,38 +224,23 @@ var RetryFetch = /*#__PURE__*/ function() {
224
224
  value: function delay(countDown) {
225
225
  var _this = this;
226
226
  return _async_to_generator(function() {
227
+ var time;
227
228
  return _ts_generator(this, function(_state) {
228
- // eslint-disable-next-line no-async-promise-executor
229
- return [
230
- 2,
231
- new Promise(/*#__PURE__*/ function() {
232
- var _ref = _async_to_generator(function(resolve) {
233
- var _tmp;
234
- return _ts_generator(this, function(_state) {
235
- switch(_state.label){
236
- case 0:
237
- _tmp = [
238
- resolve
239
- ];
240
- return [
241
- 4,
242
- _this.sleepBetweenRetry(countDown)
243
- ];
244
- case 1:
245
- return [
246
- 2,
247
- setTimeout.apply(void 0, _tmp.concat([
248
- _state.sent()
249
- ]))
250
- ];
251
- }
252
- });
253
- });
254
- return function(resolve) {
255
- return _ref.apply(this, arguments);
256
- };
257
- }())
258
- ];
229
+ switch(_state.label){
230
+ case 0:
231
+ return [
232
+ 4,
233
+ _this.sleepBetweenRetry(countDown)
234
+ ];
235
+ case 1:
236
+ time = _state.sent();
237
+ return [
238
+ 2,
239
+ new Promise(function(resolve) {
240
+ return setTimeout(resolve, time);
241
+ })
242
+ ];
243
+ }
259
244
  });
260
245
  })();
261
246
  }
@@ -206,10 +206,10 @@ describe('Retry Fetch Plugin', function() {
206
206
  fetchPlugins: runners
207
207
  });
208
208
  runners.push(runner);
209
- call = Promise.reject({
209
+ call = Promise.reject(new Error(JSON.stringify({
210
210
  text: 'test',
211
211
  ok: true
212
- });
212
+ })));
213
213
  callback = jest.fn();
214
214
  runner.transform(call).catch(callback);
215
215
  return [
@@ -242,10 +242,10 @@ describe('Retry Fetch Plugin', function() {
242
242
  fetchPlugins: runners
243
243
  });
244
244
  runners.push(runner);
245
- call = Promise.reject({
245
+ call = Promise.reject(new Error(JSON.stringify({
246
246
  text: 'test',
247
247
  ok: true
248
- });
248
+ })));
249
249
  callback = jest.fn();
250
250
  runner.transform(call).catch(callback);
251
251
  return [
@@ -78,6 +78,13 @@ function _define_property(obj, key, value) {
78
78
  }
79
79
  return obj;
80
80
  }
81
+ function _instanceof(left, right) {
82
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
83
+ return !!right[Symbol.hasInstance](left);
84
+ } else {
85
+ return left instanceof right;
86
+ }
87
+ }
81
88
  function _type_of(obj) {
82
89
  "@swc/helpers - typeof";
83
90
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -187,7 +194,7 @@ var impervaCaptchaEventHandlerFactory = function(config) {
187
194
  return function(timeoutPauseCallback) {
188
195
  var onImpervaCaptcha = function(event) {
189
196
  var originHostname = new URL(event.origin).hostname;
190
- if (originHostname !== location.hostname && ((config === null || config === void 0 ? void 0 : config.whiteListedHostNames) || []).indexOf(originHostname) === -1) {
197
+ if (originHostname !== location.hostname && !((config === null || config === void 0 ? void 0 : config.whiteListedHostNames) || []).includes(originHostname)) {
191
198
  return;
192
199
  }
193
200
  var message = event.data;
@@ -238,7 +245,7 @@ var TimeoutFetch = /*#__PURE__*/ function() {
238
245
  var _this = this;
239
246
  return {
240
247
  transform: function(fetchCall) {
241
- return(// eslint-disable-next-line no-async-promise-executor
248
+ return(// eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
242
249
  new Promise(/*#__PURE__*/ function() {
243
250
  var _ref = _async_to_generator(function(resolve, reject) {
244
251
  var timeoutCallback, timer, timerCallback, response, ex;
@@ -285,7 +292,7 @@ var TimeoutFetch = /*#__PURE__*/ function() {
285
292
  ];
286
293
  case 3:
287
294
  ex = _state.sent();
288
- reject(ex);
295
+ reject(_instanceof(ex, Error) ? ex : new Error(ex.toString()));
289
296
  return [
290
297
  3,
291
298
  5
@@ -221,11 +221,11 @@ var WaitForFetch = /*#__PURE__*/ function() {
221
221
  var data;
222
222
  var _this = this;
223
223
  return {
224
- // eslint-disable-next-line no-async-promise-executor
224
+ // eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
225
225
  canStart: function() {
226
226
  return new Promise(/*#__PURE__*/ function() {
227
227
  var _ref = _async_to_generator(function(resolve) {
228
- var didTimeOut, timer, canStartCondition, canStart, ex;
228
+ var didTimeOut, timer, canStartCondition, canStart, e;
229
229
  return _ts_generator(this, function(_state) {
230
230
  switch(_state.label){
231
231
  case 0:
@@ -265,7 +265,7 @@ var WaitForFetch = /*#__PURE__*/ function() {
265
265
  6
266
266
  ];
267
267
  case 4:
268
- ex = _state.sent();
268
+ e = _state.sent();
269
269
  if (!didTimeOut) {
270
270
  resolve(false);
271
271
  }
@@ -347,7 +347,7 @@ describe('Wait For Fetch Plugin', function() {
347
347
  response = {
348
348
  test: true
349
349
  };
350
- fetchCall = Promise.reject(response);
350
+ fetchCall = Promise.reject(new Error(JSON.stringify(response)));
351
351
  _state.label = 1;
352
352
  case 1:
353
353
  _state.trys.push([
@@ -403,17 +403,12 @@ var DEFAULT_OPTIONS = {
403
403
  case 2:
404
404
  canStart = _state.sent();
405
405
  isCanceledBy = canStart.indexOf(false);
406
- if (isCanceledBy >= 0) {
407
- // One of the fetch plugins cancelled the execution of the call
408
- asyncResponse = Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, _this.options.fetchPlugins[isCanceledBy], {
409
- apiName: apiName,
410
- operationId: operationId,
411
- url: url,
412
- origin: origin
413
- }));
414
- } else {
415
- asyncResponse = fetch(url, options);
416
- }
406
+ asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, _this.options.fetchPlugins[isCanceledBy], {
407
+ apiName: apiName,
408
+ operationId: operationId,
409
+ url: url,
410
+ origin: origin
411
+ }));
417
412
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
418
413
  try {
419
414
  for(_iterator = loadedPlugins[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -452,16 +447,12 @@ var DEFAULT_OPTIONS = {
452
447
  ];
453
448
  case 5:
454
449
  e = _state.sent();
455
- if (_instanceof(e, CanceledCallError)) {
456
- exception = e;
457
- } else {
458
- exception = new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
459
- apiName: apiName,
460
- operationId: operationId,
461
- url: url,
462
- origin: origin
463
- });
464
- }
450
+ exception = _instanceof(e, CanceledCallError) ? e : new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
451
+ apiName: apiName,
452
+ operationId: operationId,
453
+ url: url,
454
+ origin: origin
455
+ });
465
456
  return [
466
457
  3,
467
458
  6
@@ -477,7 +468,7 @@ var DEFAULT_OPTIONS = {
477
468
  origin: origin
478
469
  });
479
470
  }
480
- // eslint-disable-next-line no-console
471
+ // 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.
481
472
  reviver = getResponseReviver(revivers, response, operationId, {
482
473
  disableFallback: _this.options.disableFallback,
483
474
  log: console.error
@@ -181,7 +181,7 @@ function _ts_generator(thisArg, body) {
181
181
  value: /**
182
182
  * Unstack and resolve the promise stopping the call to start
183
183
  */ function unstackResolve() {
184
- if (this.canStart() && this.waitingResolvers.length) {
184
+ if (this.canStart() && this.waitingResolvers.length > 0) {
185
185
  this.waitingResolvers.shift()(true);
186
186
  }
187
187
  }
@@ -200,7 +200,7 @@ function _ts_generator(thisArg, body) {
200
200
  },
201
201
  transform: /*#__PURE__*/ function() {
202
202
  var _ref = _async_to_generator(function(fetchCall) {
203
- var fetchResponse, e;
203
+ var fetchResponse;
204
204
  return _ts_generator(this, function(_state) {
205
205
  switch(_state.label){
206
206
  case 0:
@@ -209,9 +209,9 @@ function _ts_generator(thisArg, body) {
209
209
  case 1:
210
210
  _state.trys.push([
211
211
  1,
212
+ ,
212
213
  3,
213
- 4,
214
- 5
214
+ 4
215
215
  ]);
216
216
  return [
217
217
  4,
@@ -224,10 +224,6 @@ function _ts_generator(thisArg, body) {
224
224
  fetchResponse
225
225
  ];
226
226
  case 3:
227
- e = _state.sent();
228
- throw e;
229
- case 4:
230
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
231
227
  _this1.pool = _this1.pool.filter(function(call) {
232
228
  return call !== fetchCall;
233
229
  });
@@ -236,7 +232,7 @@ function _ts_generator(thisArg, body) {
236
232
  return [
237
233
  7
238
234
  ];
239
- case 5:
235
+ case 4:
240
236
  return [
241
237
  2
242
238
  ];
@@ -198,7 +198,6 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
198
198
  case 1:
199
199
  _state.sent();
200
200
  responsePromise = fetchCall;
201
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
202
201
  if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
203
202
  return [
204
203
  2,
@@ -241,7 +240,6 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
241
240
  });
242
241
  _state.label = 6;
243
242
  case 6:
244
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
245
243
  operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
246
244
  try {
247
245
  mock = _this.options.adapter.getLatestMock(operationId);
@@ -228,7 +228,7 @@ import { v4 } from 'uuid';
228
228
  return "sdk:".concat(status, ":").concat(markId);
229
229
  });
230
230
  this.getPerformanceTag = (options === null || options === void 0 ? void 0 : options.getPerformanceTag) || this.getPerformanceTag;
231
- this.performance = (options === null || options === void 0 ? void 0 : options.performance) || (typeof window !== 'undefined' ? window.performance : undefined);
231
+ this.performance = (options === null || options === void 0 ? void 0 : options.performance) || (typeof window === 'undefined' ? undefined : window.performance);
232
232
  this.onMarkComplete = options ? options.onMarkComplete : this.onMarkComplete;
233
233
  this.onMarkError = options ? options.onMarkError : this.onMarkError;
234
234
  this.onMarkOpen = options ? options.onMarkOpen : this.onMarkOpen;
@@ -216,38 +216,23 @@ import { CanceledCallError } from '@ama-sdk/core';
216
216
  value: function delay(countDown) {
217
217
  var _this = this;
218
218
  return _async_to_generator(function() {
219
+ var time;
219
220
  return _ts_generator(this, function(_state) {
220
- // eslint-disable-next-line no-async-promise-executor
221
- return [
222
- 2,
223
- new Promise(/*#__PURE__*/ function() {
224
- var _ref = _async_to_generator(function(resolve) {
225
- var _tmp;
226
- return _ts_generator(this, function(_state) {
227
- switch(_state.label){
228
- case 0:
229
- _tmp = [
230
- resolve
231
- ];
232
- return [
233
- 4,
234
- _this.sleepBetweenRetry(countDown)
235
- ];
236
- case 1:
237
- return [
238
- 2,
239
- setTimeout.apply(void 0, _tmp.concat([
240
- _state.sent()
241
- ]))
242
- ];
243
- }
244
- });
245
- });
246
- return function(resolve) {
247
- return _ref.apply(this, arguments);
248
- };
249
- }())
250
- ];
221
+ switch(_state.label){
222
+ case 0:
223
+ return [
224
+ 4,
225
+ _this.sleepBetweenRetry(countDown)
226
+ ];
227
+ case 1:
228
+ time = _state.sent();
229
+ return [
230
+ 2,
231
+ new Promise(function(resolve) {
232
+ return setTimeout(resolve, time);
233
+ })
234
+ ];
235
+ }
251
236
  });
252
237
  })();
253
238
  }
@@ -202,10 +202,10 @@ describe('Retry Fetch Plugin', function() {
202
202
  fetchPlugins: runners
203
203
  });
204
204
  runners.push(runner);
205
- call = Promise.reject({
205
+ call = Promise.reject(new Error(JSON.stringify({
206
206
  text: 'test',
207
207
  ok: true
208
- });
208
+ })));
209
209
  callback = jest.fn();
210
210
  runner.transform(call).catch(callback);
211
211
  return [
@@ -238,10 +238,10 @@ describe('Retry Fetch Plugin', function() {
238
238
  fetchPlugins: runners
239
239
  });
240
240
  runners.push(runner);
241
- call = Promise.reject({
241
+ call = Promise.reject(new Error(JSON.stringify({
242
242
  text: 'test',
243
243
  ok: true
244
- });
244
+ })));
245
245
  callback = jest.fn();
246
246
  runner.transform(call).catch(callback);
247
247
  return [
@@ -59,6 +59,13 @@ function _define_property(obj, key, value) {
59
59
  }
60
60
  return obj;
61
61
  }
62
+ function _instanceof(left, right) {
63
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
64
+ return !!right[Symbol.hasInstance](left);
65
+ } else {
66
+ return left instanceof right;
67
+ }
68
+ }
62
69
  function _type_of(obj) {
63
70
  "@swc/helpers - typeof";
64
71
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -168,14 +175,13 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
168
175
  /**
169
176
  * Captures Imperva captcha events and calls the event callback
170
177
  * It can only be used for browser's integrating imperva captcha
171
- * @param config: list of host names that can trigger a captcha event
172
- * @param config
178
+ * @param config list of host names that can trigger a captcha event
173
179
  * @returns removeEventListener
174
180
  */ export var impervaCaptchaEventHandlerFactory = function(config) {
175
181
  return function(timeoutPauseCallback) {
176
182
  var onImpervaCaptcha = function(event) {
177
183
  var originHostname = new URL(event.origin).hostname;
178
- if (originHostname !== location.hostname && ((config === null || config === void 0 ? void 0 : config.whiteListedHostNames) || []).indexOf(originHostname) === -1) {
184
+ if (originHostname !== location.hostname && !((config === null || config === void 0 ? void 0 : config.whiteListedHostNames) || []).includes(originHostname)) {
179
185
  return;
180
186
  }
181
187
  var message = event.data;
@@ -228,7 +234,7 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
228
234
  var _this = this;
229
235
  return {
230
236
  transform: function(fetchCall) {
231
- return(// eslint-disable-next-line no-async-promise-executor
237
+ return(// eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
232
238
  new Promise(/*#__PURE__*/ function() {
233
239
  var _ref = _async_to_generator(function(resolve, reject) {
234
240
  var timeoutCallback, timer, timerCallback, response, ex;
@@ -275,7 +281,7 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
275
281
  ];
276
282
  case 3:
277
283
  ex = _state.sent();
278
- reject(ex);
284
+ reject(_instanceof(ex, Error) ? ex : new Error(ex.toString()));
279
285
  return [
280
286
  3,
281
287
  5
@@ -250,11 +250,11 @@ function _ts_generator(thisArg, body) {
250
250
  var data;
251
251
  var _this = this;
252
252
  return {
253
- // eslint-disable-next-line no-async-promise-executor
253
+ // eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
254
254
  canStart: function() {
255
255
  return new Promise(/*#__PURE__*/ function() {
256
256
  var _ref = _async_to_generator(function(resolve) {
257
- var didTimeOut, timer, canStartCondition, canStart, ex;
257
+ var didTimeOut, timer, canStartCondition, canStart, e;
258
258
  return _ts_generator(this, function(_state) {
259
259
  switch(_state.label){
260
260
  case 0:
@@ -294,7 +294,7 @@ function _ts_generator(thisArg, body) {
294
294
  6
295
295
  ];
296
296
  case 4:
297
- ex = _state.sent();
297
+ e = _state.sent();
298
298
  if (!didTimeOut) {
299
299
  resolve(false);
300
300
  }
@@ -343,7 +343,7 @@ describe('Wait For Fetch Plugin', function() {
343
343
  response = {
344
344
  test: true
345
345
  };
346
- fetchCall = Promise.reject(response);
346
+ fetchCall = Promise.reject(new Error(JSON.stringify(response)));
347
347
  _state.label = 1;
348
348
  case 1:
349
349
  _state.trys.push([