@ama-sdk/client-fetch 12.3.0-prerelease.9 → 12.3.0-rc.0

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 (40) hide show
  1. package/cjs/api-fetch-client.js +18 -22
  2. package/cjs/plugins/abort/abort.spec.js +83 -81
  3. package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
  4. package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
  5. package/cjs/plugins/keepalive/keepalive.request.js +7 -12
  6. package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
  7. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  8. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +247 -239
  9. package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
  10. package/cjs/plugins/retry/retry.fetch.js +18 -27
  11. package/cjs/plugins/retry/retry.spec.js +233 -225
  12. package/cjs/plugins/timeout/timeout.fetch.js +13 -19
  13. package/cjs/plugins/timeout/timeout.spec.js +211 -205
  14. package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
  15. package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
  16. package/esm2015/api-fetch-client.js +18 -22
  17. package/esm2015/plugins/abort/abort.spec.js +83 -81
  18. package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
  19. package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
  20. package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
  21. package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
  22. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  23. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +247 -239
  24. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
  25. package/esm2015/plugins/retry/retry.fetch.js +18 -27
  26. package/esm2015/plugins/retry/retry.spec.js +233 -225
  27. package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
  28. package/esm2015/plugins/timeout/timeout.spec.js +211 -205
  29. package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
  30. package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
  31. package/package.json +15 -15
  32. package/schematics/ng-add/index.d.ts.map +1 -1
  33. package/schematics/ng-add/index.js +11 -21
  34. package/schematics/ng-add/index.js.map +1 -0
  35. package/schematics/ng-add/migration/import-map.js.map +1 -0
  36. package/schematics/ng-add/schema.js.map +1 -0
  37. package/src/api-fetch-client.d.ts +1 -1
  38. package/src/api-fetch-client.d.ts.map +1 -1
  39. package/src/api-fetch-client.js +2 -1
  40. package/src/api-fetch-client.js.map +1 -1
@@ -71,7 +71,7 @@ function _type_of(obj) {
71
71
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
72
72
  }
73
73
  function _ts_generator(thisArg, body) {
74
- var f, y, t, g, _ = {
74
+ var f, y, t, _ = {
75
75
  label: 0,
76
76
  sent: function() {
77
77
  if (t[0] & 1) throw t[1];
@@ -79,12 +79,8 @@ function _ts_generator(thisArg, body) {
79
79
  },
80
80
  trys: [],
81
81
  ops: []
82
- };
83
- return g = {
84
- next: verb(0),
85
- "throw": verb(1),
86
- "return": verb(2)
87
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
82
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
83
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
88
84
  return this;
89
85
  }), g;
90
86
  function verb(n) {
@@ -97,7 +93,7 @@ function _ts_generator(thisArg, body) {
97
93
  }
98
94
  function step(op) {
99
95
  if (f) throw new TypeError("Generator is already executing.");
100
- while(_)try {
96
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
101
97
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
102
98
  if (y = 0, t) op = [
103
99
  op[0] & 2,
@@ -235,18 +231,19 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
235
231
  return {
236
232
  transform: function(fetchCall) {
237
233
  return(// eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
238
- new Promise(/*#__PURE__*/ function() {
239
- var _ref = _async_to_generator(function(resolve, reject) {
240
- var timeoutCallback, timer, timerCallback, response, ex;
234
+ new Promise(function(resolve, reject) {
235
+ return _async_to_generator(function() {
236
+ var _this, timeoutCallback, timer, timerCallback, response, ex;
241
237
  return _ts_generator(this, function(_state) {
242
238
  switch(_state.label){
243
239
  case 0:
240
+ _this = this;
244
241
  timeoutCallback = function() {
245
242
  reject(new ResponseTimeoutError("in ".concat(_this.timeout, "ms")));
246
243
  // Fetch abort controller is now supported by all modern browser and node 15+. It should always be defined
247
244
  context.controller.abort();
248
245
  };
249
- timer = _this.timerPauseState === 'timeoutStopped' ? undefined : setTimeout(timeoutCallback, _this.timeout);
246
+ timer = this.timerPauseState === 'timeoutStopped' ? undefined : setTimeout(timeoutCallback, this.timeout);
250
247
  timerCallback = function(pauseStatus) {
251
248
  if (timer && pauseStatus === 'timeoutStopped') {
252
249
  clearTimeout(timer);
@@ -257,7 +254,7 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
257
254
  (context.logger || console).log('[SDK Plugins] Timeout restarted.');
258
255
  }
259
256
  };
260
- _this.timerSubscription.push(timerCallback);
257
+ this.timerSubscription.push(timerCallback);
261
258
  _state.label = 1;
262
259
  case 1:
263
260
  _state.trys.push([
@@ -290,7 +287,7 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
290
287
  if (timer) {
291
288
  clearTimeout(timer);
292
289
  }
293
- _this.timerSubscription = _this.timerSubscription.filter(function(callback) {
290
+ this.timerSubscription = this.timerSubscription.filter(function(callback) {
294
291
  return timerCallback !== callback;
295
292
  });
296
293
  return [
@@ -302,11 +299,8 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
302
299
  ];
303
300
  }
304
301
  });
305
- });
306
- return function(resolve, reject) {
307
- return _ref.apply(this, arguments);
308
- };
309
- }()));
302
+ }).call(_this);
303
+ }));
310
304
  }
311
305
  };
312
306
  }
@@ -32,7 +32,7 @@ function _type_of(obj) {
32
32
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
33
33
  }
34
34
  function _ts_generator(thisArg, body) {
35
- var f, y, t, g, _ = {
35
+ var f, y, t, _ = {
36
36
  label: 0,
37
37
  sent: function() {
38
38
  if (t[0] & 1) throw t[1];
@@ -40,12 +40,8 @@ function _ts_generator(thisArg, body) {
40
40
  },
41
41
  trys: [],
42
42
  ops: []
43
- };
44
- return g = {
45
- next: verb(0),
46
- "throw": verb(1),
47
- "return": verb(2)
48
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
43
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
44
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
49
45
  return this;
50
46
  }), g;
51
47
  function verb(n) {
@@ -58,7 +54,7 @@ function _ts_generator(thisArg, body) {
58
54
  }
59
55
  function step(op) {
60
56
  if (f) throw new TypeError("Generator is already executing.");
61
- while(_)try {
57
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
62
58
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
59
  if (y = 0, t) op = [
64
60
  op[0] & 2,
@@ -130,203 +126,213 @@ var _this = this;
130
126
  import { EmptyResponseError, ResponseTimeoutError } from '@ama-sdk/core';
131
127
  import { impervaCaptchaEventHandlerFactory, TimeoutFetch } from './timeout.fetch';
132
128
  describe('Timeout Fetch Plugin', function() {
133
- it('should reject on timeout', /*#__PURE__*/ _async_to_generator(function() {
134
- var plugin, runner, call, callback;
135
- return _ts_generator(this, function(_state) {
136
- switch(_state.label){
137
- case 0:
138
- plugin = new TimeoutFetch(100);
139
- runner = plugin.load({
140
- controller: new AbortController()
141
- });
142
- call = new Promise(function(resolve) {
143
- return setTimeout(function() {
144
- return resolve(undefined);
145
- }, 1000);
146
- });
147
- callback = jest.fn();
148
- runner.transform(call).catch(callback);
149
- return [
150
- 4,
151
- jest.advanceTimersByTimeAsync(99)
152
- ];
153
- case 1:
154
- _state.sent();
155
- expect(callback).not.toHaveBeenCalled();
156
- return [
157
- 4,
158
- jest.advanceTimersByTimeAsync(1)
159
- ];
160
- case 2:
161
- _state.sent();
162
- expect(callback).toHaveBeenCalledWith(new ResponseTimeoutError('in 100ms'));
163
- return [
164
- 2
165
- ];
166
- }
167
- });
168
- }));
169
- it('should not reject on fetch rejection', /*#__PURE__*/ _async_to_generator(function() {
170
- var plugin, runner, call, callback;
171
- return _ts_generator(this, function(_state) {
172
- switch(_state.label){
173
- case 0:
174
- plugin = new TimeoutFetch(6000);
175
- runner = plugin.load({
176
- controller: new AbortController()
177
- });
178
- call = new Promise(function(_resolve, reject) {
179
- return setTimeout(function() {
180
- return reject(new EmptyResponseError(''));
181
- }, 100);
182
- });
183
- callback = jest.fn();
184
- runner.transform(call).catch(callback);
185
- return [
186
- 4,
187
- jest.advanceTimersByTimeAsync(6000)
188
- ];
189
- case 1:
190
- _state.sent();
191
- expect(callback).toHaveBeenCalledWith(new EmptyResponseError(''));
192
- return [
193
- 2
194
- ];
195
- }
196
- });
197
- }));
198
- it('should forward the fetch response', /*#__PURE__*/ _async_to_generator(function() {
199
- var plugin, runner, call, promise;
200
- return _ts_generator(this, function(_state) {
201
- switch(_state.label){
202
- case 0:
203
- plugin = new TimeoutFetch(2000);
204
- runner = plugin.load({
205
- controller: new AbortController()
206
- });
207
- call = new Promise(function(resolve) {
208
- return setTimeout(function() {
209
- return resolve({
210
- test: true
211
- });
212
- }, 100);
213
- });
214
- promise = runner.transform(call);
215
- return [
216
- 4,
217
- jest.runAllTimersAsync()
218
- ];
219
- case 1:
220
- _state.sent();
221
- return [
222
- 4,
223
- promise
224
- ];
225
- case 2:
226
- expect.apply(void 0, [
227
- _state.sent()
228
- ]).toEqual({
229
- test: true
230
- });
231
- return [
232
- 2
233
- ];
234
- }
235
- });
236
- }));
237
- it('should not reject if the timeout has been paused and reject if restarted', /*#__PURE__*/ _async_to_generator(function() {
238
- var timeoutPauseEvent, plugin, runner, call, callback;
239
- return _ts_generator(this, function(_state) {
240
- switch(_state.label){
241
- case 0:
242
- timeoutPauseEvent = {
243
- emitEvent: function(_status) {},
244
- handler: function(timeoutPauseCallback) {
245
- timeoutPauseEvent.emitEvent = timeoutPauseCallback;
246
- return function() {};
247
- }
248
- };
249
- plugin = new TimeoutFetch(100, timeoutPauseEvent.handler);
250
- runner = plugin.load({
251
- controller: new AbortController()
252
- });
253
- call = new Promise(function(resolve) {
254
- return setTimeout(function() {
255
- return resolve({
256
- test: true
257
- });
258
- }, 500);
259
- });
260
- callback = jest.fn();
261
- runner.transform(call).catch(callback);
262
- timeoutPauseEvent.emitEvent('timeoutStopped');
263
- return [
264
- 4,
265
- jest.advanceTimersByTimeAsync(200)
266
- ];
267
- case 1:
268
- _state.sent();
269
- timeoutPauseEvent.emitEvent('timeoutStarted');
270
- return [
271
- 4,
272
- jest.advanceTimersByTimeAsync(200)
273
- ];
274
- case 2:
275
- _state.sent();
276
- expect(callback).toHaveBeenCalledWith(new ResponseTimeoutError('in 100ms'));
277
- return [
278
- 2
279
- ];
280
- }
281
- });
282
- }));
283
- it('should take into account pause events triggered before the call', /*#__PURE__*/ _async_to_generator(function() {
284
- var timeoutPauseEvent, plugin, runner, call, promise;
285
- return _ts_generator(this, function(_state) {
286
- switch(_state.label){
287
- case 0:
288
- timeoutPauseEvent = {
289
- emitEvent: function(_status) {},
290
- handler: function(timeoutPauseCallback) {
291
- timeoutPauseEvent.emitEvent = timeoutPauseCallback;
292
- return function() {};
293
- }
294
- };
295
- plugin = new TimeoutFetch(250, timeoutPauseEvent.handler);
296
- runner = plugin.load({
297
- controller: new AbortController()
298
- });
299
- call = new Promise(function(resolve) {
300
- return setTimeout(function() {
301
- return resolve({
302
- test: true
303
- });
304
- }, 500);
305
- });
306
- timeoutPauseEvent.emitEvent('timeoutStopped');
307
- promise = runner.transform(call);
308
- return [
309
- 4,
310
- jest.runAllTimersAsync()
311
- ];
312
- case 1:
313
- _state.sent();
314
- return [
315
- 4,
316
- promise
317
- ];
318
- case 2:
319
- expect.apply(void 0, [
320
- _state.sent()
321
- ]).toEqual({
322
- test: true
323
- });
324
- return [
325
- 2
326
- ];
327
- }
328
- });
329
- }));
129
+ it('should reject on timeout', function() {
130
+ return _async_to_generator(function() {
131
+ var plugin, runner, call, callback;
132
+ return _ts_generator(this, function(_state) {
133
+ switch(_state.label){
134
+ case 0:
135
+ plugin = new TimeoutFetch(100);
136
+ runner = plugin.load({
137
+ controller: new AbortController()
138
+ });
139
+ call = new Promise(function(resolve) {
140
+ return setTimeout(function() {
141
+ return resolve(undefined);
142
+ }, 1000);
143
+ });
144
+ callback = jest.fn();
145
+ runner.transform(call).catch(callback);
146
+ return [
147
+ 4,
148
+ jest.advanceTimersByTimeAsync(99)
149
+ ];
150
+ case 1:
151
+ _state.sent();
152
+ expect(callback).not.toHaveBeenCalled();
153
+ return [
154
+ 4,
155
+ jest.advanceTimersByTimeAsync(1)
156
+ ];
157
+ case 2:
158
+ _state.sent();
159
+ expect(callback).toHaveBeenCalledWith(new ResponseTimeoutError('in 100ms'));
160
+ return [
161
+ 2
162
+ ];
163
+ }
164
+ });
165
+ })();
166
+ });
167
+ it('should not reject on fetch rejection', function() {
168
+ return _async_to_generator(function() {
169
+ var plugin, runner, call, callback;
170
+ return _ts_generator(this, function(_state) {
171
+ switch(_state.label){
172
+ case 0:
173
+ plugin = new TimeoutFetch(6000);
174
+ runner = plugin.load({
175
+ controller: new AbortController()
176
+ });
177
+ call = new Promise(function(_resolve, reject) {
178
+ return setTimeout(function() {
179
+ return reject(new EmptyResponseError(''));
180
+ }, 100);
181
+ });
182
+ callback = jest.fn();
183
+ runner.transform(call).catch(callback);
184
+ return [
185
+ 4,
186
+ jest.advanceTimersByTimeAsync(6000)
187
+ ];
188
+ case 1:
189
+ _state.sent();
190
+ expect(callback).toHaveBeenCalledWith(new EmptyResponseError(''));
191
+ return [
192
+ 2
193
+ ];
194
+ }
195
+ });
196
+ })();
197
+ });
198
+ it('should forward the fetch response', function() {
199
+ return _async_to_generator(function() {
200
+ var plugin, runner, call, promise;
201
+ return _ts_generator(this, function(_state) {
202
+ switch(_state.label){
203
+ case 0:
204
+ plugin = new TimeoutFetch(2000);
205
+ runner = plugin.load({
206
+ controller: new AbortController()
207
+ });
208
+ call = new Promise(function(resolve) {
209
+ return setTimeout(function() {
210
+ return resolve({
211
+ test: true
212
+ });
213
+ }, 100);
214
+ });
215
+ promise = runner.transform(call);
216
+ return [
217
+ 4,
218
+ jest.runAllTimersAsync()
219
+ ];
220
+ case 1:
221
+ _state.sent();
222
+ return [
223
+ 4,
224
+ promise
225
+ ];
226
+ case 2:
227
+ expect.apply(void 0, [
228
+ _state.sent()
229
+ ]).toEqual({
230
+ test: true
231
+ });
232
+ return [
233
+ 2
234
+ ];
235
+ }
236
+ });
237
+ })();
238
+ });
239
+ it('should not reject if the timeout has been paused and reject if restarted', function() {
240
+ return _async_to_generator(function() {
241
+ var timeoutPauseEvent, plugin, runner, call, callback;
242
+ return _ts_generator(this, function(_state) {
243
+ switch(_state.label){
244
+ case 0:
245
+ timeoutPauseEvent = {
246
+ emitEvent: function(_status) {},
247
+ handler: function(timeoutPauseCallback) {
248
+ timeoutPauseEvent.emitEvent = timeoutPauseCallback;
249
+ return function() {};
250
+ }
251
+ };
252
+ plugin = new TimeoutFetch(100, timeoutPauseEvent.handler);
253
+ runner = plugin.load({
254
+ controller: new AbortController()
255
+ });
256
+ call = new Promise(function(resolve) {
257
+ return setTimeout(function() {
258
+ return resolve({
259
+ test: true
260
+ });
261
+ }, 500);
262
+ });
263
+ callback = jest.fn();
264
+ runner.transform(call).catch(callback);
265
+ timeoutPauseEvent.emitEvent('timeoutStopped');
266
+ return [
267
+ 4,
268
+ jest.advanceTimersByTimeAsync(200)
269
+ ];
270
+ case 1:
271
+ _state.sent();
272
+ timeoutPauseEvent.emitEvent('timeoutStarted');
273
+ return [
274
+ 4,
275
+ jest.advanceTimersByTimeAsync(200)
276
+ ];
277
+ case 2:
278
+ _state.sent();
279
+ expect(callback).toHaveBeenCalledWith(new ResponseTimeoutError('in 100ms'));
280
+ return [
281
+ 2
282
+ ];
283
+ }
284
+ });
285
+ })();
286
+ });
287
+ it('should take into account pause events triggered before the call', function() {
288
+ return _async_to_generator(function() {
289
+ var timeoutPauseEvent, plugin, runner, call, promise;
290
+ return _ts_generator(this, function(_state) {
291
+ switch(_state.label){
292
+ case 0:
293
+ timeoutPauseEvent = {
294
+ emitEvent: function(_status) {},
295
+ handler: function(timeoutPauseCallback) {
296
+ timeoutPauseEvent.emitEvent = timeoutPauseCallback;
297
+ return function() {};
298
+ }
299
+ };
300
+ plugin = new TimeoutFetch(250, timeoutPauseEvent.handler);
301
+ runner = plugin.load({
302
+ controller: new AbortController()
303
+ });
304
+ call = new Promise(function(resolve) {
305
+ return setTimeout(function() {
306
+ return resolve({
307
+ test: true
308
+ });
309
+ }, 500);
310
+ });
311
+ timeoutPauseEvent.emitEvent('timeoutStopped');
312
+ promise = runner.transform(call);
313
+ return [
314
+ 4,
315
+ jest.runAllTimersAsync()
316
+ ];
317
+ case 1:
318
+ _state.sent();
319
+ return [
320
+ 4,
321
+ promise
322
+ ];
323
+ case 2:
324
+ expect.apply(void 0, [
325
+ _state.sent()
326
+ ]).toEqual({
327
+ test: true
328
+ });
329
+ return [
330
+ 2
331
+ ];
332
+ }
333
+ });
334
+ })();
335
+ });
330
336
  });
331
337
  describe('impervaCaptchaEventHandlerFactory', function() {
332
338
  var postMessageTemp;