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

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
@@ -126,203 +126,213 @@ var _this = this;
126
126
  import { EmptyResponseError, ResponseTimeoutError } from '@ama-sdk/core';
127
127
  import { impervaCaptchaEventHandlerFactory, TimeoutFetch } from './timeout.fetch';
128
128
  describe('Timeout Fetch Plugin', function() {
129
- it('should reject on timeout', /*#__PURE__*/ _async_to_generator(function() {
130
- var plugin, runner, call, callback;
131
- return _ts_generator(this, function(_state) {
132
- switch(_state.label){
133
- case 0:
134
- plugin = new TimeoutFetch(100);
135
- runner = plugin.load({
136
- controller: new AbortController()
137
- });
138
- call = new Promise(function(resolve) {
139
- return setTimeout(function() {
140
- return resolve(undefined);
141
- }, 1000);
142
- });
143
- callback = jest.fn();
144
- runner.transform(call).catch(callback);
145
- return [
146
- 4,
147
- jest.advanceTimersByTimeAsync(99)
148
- ];
149
- case 1:
150
- _state.sent();
151
- expect(callback).not.toHaveBeenCalled();
152
- return [
153
- 4,
154
- jest.advanceTimersByTimeAsync(1)
155
- ];
156
- case 2:
157
- _state.sent();
158
- expect(callback).toHaveBeenCalledWith(new ResponseTimeoutError('in 100ms'));
159
- return [
160
- 2
161
- ];
162
- }
163
- });
164
- }));
165
- it('should not reject on fetch rejection', /*#__PURE__*/ _async_to_generator(function() {
166
- var plugin, runner, call, callback;
167
- return _ts_generator(this, function(_state) {
168
- switch(_state.label){
169
- case 0:
170
- plugin = new TimeoutFetch(6000);
171
- runner = plugin.load({
172
- controller: new AbortController()
173
- });
174
- call = new Promise(function(_resolve, reject) {
175
- return setTimeout(function() {
176
- return reject(new EmptyResponseError(''));
177
- }, 100);
178
- });
179
- callback = jest.fn();
180
- runner.transform(call).catch(callback);
181
- return [
182
- 4,
183
- jest.advanceTimersByTimeAsync(6000)
184
- ];
185
- case 1:
186
- _state.sent();
187
- expect(callback).toHaveBeenCalledWith(new EmptyResponseError(''));
188
- return [
189
- 2
190
- ];
191
- }
192
- });
193
- }));
194
- it('should forward the fetch response', /*#__PURE__*/ _async_to_generator(function() {
195
- var plugin, runner, call, promise;
196
- return _ts_generator(this, function(_state) {
197
- switch(_state.label){
198
- case 0:
199
- plugin = new TimeoutFetch(2000);
200
- runner = plugin.load({
201
- controller: new AbortController()
202
- });
203
- call = new Promise(function(resolve) {
204
- return setTimeout(function() {
205
- return resolve({
206
- test: true
207
- });
208
- }, 100);
209
- });
210
- promise = runner.transform(call);
211
- return [
212
- 4,
213
- jest.runAllTimersAsync()
214
- ];
215
- case 1:
216
- _state.sent();
217
- return [
218
- 4,
219
- promise
220
- ];
221
- case 2:
222
- expect.apply(void 0, [
223
- _state.sent()
224
- ]).toEqual({
225
- test: true
226
- });
227
- return [
228
- 2
229
- ];
230
- }
231
- });
232
- }));
233
- it('should not reject if the timeout has been paused and reject if restarted', /*#__PURE__*/ _async_to_generator(function() {
234
- var timeoutPauseEvent, plugin, runner, call, callback;
235
- return _ts_generator(this, function(_state) {
236
- switch(_state.label){
237
- case 0:
238
- timeoutPauseEvent = {
239
- emitEvent: function(_status) {},
240
- handler: function(timeoutPauseCallback) {
241
- timeoutPauseEvent.emitEvent = timeoutPauseCallback;
242
- return function() {};
243
- }
244
- };
245
- plugin = new TimeoutFetch(100, timeoutPauseEvent.handler);
246
- runner = plugin.load({
247
- controller: new AbortController()
248
- });
249
- call = new Promise(function(resolve) {
250
- return setTimeout(function() {
251
- return resolve({
252
- test: true
253
- });
254
- }, 500);
255
- });
256
- callback = jest.fn();
257
- runner.transform(call).catch(callback);
258
- timeoutPauseEvent.emitEvent('timeoutStopped');
259
- return [
260
- 4,
261
- jest.advanceTimersByTimeAsync(200)
262
- ];
263
- case 1:
264
- _state.sent();
265
- timeoutPauseEvent.emitEvent('timeoutStarted');
266
- return [
267
- 4,
268
- jest.advanceTimersByTimeAsync(200)
269
- ];
270
- case 2:
271
- _state.sent();
272
- expect(callback).toHaveBeenCalledWith(new ResponseTimeoutError('in 100ms'));
273
- return [
274
- 2
275
- ];
276
- }
277
- });
278
- }));
279
- it('should take into account pause events triggered before the call', /*#__PURE__*/ _async_to_generator(function() {
280
- var timeoutPauseEvent, plugin, runner, call, promise;
281
- return _ts_generator(this, function(_state) {
282
- switch(_state.label){
283
- case 0:
284
- timeoutPauseEvent = {
285
- emitEvent: function(_status) {},
286
- handler: function(timeoutPauseCallback) {
287
- timeoutPauseEvent.emitEvent = timeoutPauseCallback;
288
- return function() {};
289
- }
290
- };
291
- plugin = new TimeoutFetch(250, timeoutPauseEvent.handler);
292
- runner = plugin.load({
293
- controller: new AbortController()
294
- });
295
- call = new Promise(function(resolve) {
296
- return setTimeout(function() {
297
- return resolve({
298
- test: true
299
- });
300
- }, 500);
301
- });
302
- timeoutPauseEvent.emitEvent('timeoutStopped');
303
- promise = runner.transform(call);
304
- return [
305
- 4,
306
- jest.runAllTimersAsync()
307
- ];
308
- case 1:
309
- _state.sent();
310
- return [
311
- 4,
312
- promise
313
- ];
314
- case 2:
315
- expect.apply(void 0, [
316
- _state.sent()
317
- ]).toEqual({
318
- test: true
319
- });
320
- return [
321
- 2
322
- ];
323
- }
324
- });
325
- }));
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
+ });
326
336
  });
327
337
  describe('impervaCaptchaEventHandlerFactory', function() {
328
338
  var postMessageTemp;
@@ -243,23 +243,23 @@ function _ts_generator(thisArg, body) {
243
243
  {
244
244
  key: "load",
245
245
  value: /** @inheritDoc */ function load(context) {
246
- var data;
247
246
  var _this = this;
247
+ var data;
248
248
  return {
249
249
  // eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
250
250
  canStart: function() {
251
- return new Promise(/*#__PURE__*/ function() {
252
- var _ref = _async_to_generator(function(resolve) {
251
+ return new Promise(function(resolve) {
252
+ return _async_to_generator(function() {
253
253
  var didTimeOut, timer, canStartCondition, canStart, e;
254
254
  return _ts_generator(this, function(_state) {
255
255
  switch(_state.label){
256
256
  case 0:
257
257
  didTimeOut = false;
258
- if (_this.timeout) {
258
+ if (this.timeout) {
259
259
  timer = setTimeout(function() {
260
260
  didTimeOut = true;
261
261
  resolve(false);
262
- }, _this.timeout);
262
+ }, this.timeout);
263
263
  }
264
264
  _state.label = 1;
265
265
  case 1:
@@ -271,7 +271,7 @@ function _ts_generator(thisArg, body) {
271
271
  ]);
272
272
  return [
273
273
  4,
274
- _this.canStartCondition(context)
274
+ this.canStartCondition(context)
275
275
  ];
276
276
  case 2:
277
277
  canStartCondition = _state.sent();
@@ -311,19 +311,16 @@ function _ts_generator(thisArg, body) {
311
311
  ];
312
312
  }
313
313
  });
314
- });
315
- return function(resolve) {
316
- return _ref.apply(this, arguments);
317
- };
318
- }());
314
+ }).call(_this);
315
+ });
319
316
  },
320
- transform: /*#__PURE__*/ function() {
321
- var _ref = _async_to_generator(function(fetchCall) {
317
+ transform: function(fetchCall) {
318
+ return _async_to_generator(function() {
322
319
  var response, e;
323
320
  return _ts_generator(this, function(_state) {
324
321
  switch(_state.label){
325
322
  case 0:
326
- if (!_this.callback) {
323
+ if (!this.callback) {
327
324
  return [
328
325
  2,
329
326
  fetchCall
@@ -343,7 +340,7 @@ function _ts_generator(thisArg, body) {
343
340
  ];
344
341
  case 2:
345
342
  response = _state.sent();
346
- _this.callback(_object_spread_props(_object_spread({}, context), {
343
+ this.callback(_object_spread_props(_object_spread({}, context), {
347
344
  data: data
348
345
  }), fetchCall, response);
349
346
  return [
@@ -352,7 +349,7 @@ function _ts_generator(thisArg, body) {
352
349
  ];
353
350
  case 3:
354
351
  e = _state.sent();
355
- _this.callback(_object_spread_props(_object_spread({}, context), {
352
+ this.callback(_object_spread_props(_object_spread({}, context), {
356
353
  data: data
357
354
  }), fetchCall, response);
358
355
  throw e;
@@ -362,11 +359,8 @@ function _ts_generator(thisArg, body) {
362
359
  ];
363
360
  }
364
361
  });
365
- });
366
- return function(fetchCall) {
367
- return _ref.apply(this, arguments);
368
- };
369
- }()
362
+ }).call(_this);
363
+ }
370
364
  };
371
365
  }
372
366
  }