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