@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
@@ -210,7 +210,6 @@ import { CanceledCallError } from '@ama-sdk/core';
210
210
  {
211
211
  key: "delay",
212
212
  value: function delay(countDown) {
213
- var _this = this;
214
213
  return _async_to_generator(function() {
215
214
  var time;
216
215
  return _ts_generator(this, function(_state) {
@@ -218,7 +217,7 @@ import { CanceledCallError } from '@ama-sdk/core';
218
217
  case 0:
219
218
  return [
220
219
  4,
221
- _this.sleepBetweenRetry(countDown)
220
+ this.sleepBetweenRetry(countDown)
222
221
  ];
223
222
  case 1:
224
223
  time = _state.sent();
@@ -230,40 +229,39 @@ import { CanceledCallError } from '@ama-sdk/core';
230
229
  ];
231
230
  }
232
231
  });
233
- })();
232
+ }).call(this);
234
233
  }
235
234
  },
236
235
  {
237
236
  key: "waitAndRetry",
238
237
  value: function waitAndRetry(context, countDown) {
239
- var _this = this;
240
238
  return _async_to_generator(function() {
241
239
  return _ts_generator(this, function(_state) {
242
240
  switch(_state.label){
243
241
  case 0:
244
242
  return [
245
243
  4,
246
- _this.delay(countDown)
244
+ this.delay(countDown)
247
245
  ];
248
246
  case 1:
249
247
  _state.sent();
250
248
  return [
251
249
  2,
252
- _this.retry(context)
250
+ this.retry(context)
253
251
  ];
254
252
  }
255
253
  });
256
- })();
254
+ }).call(this);
257
255
  }
258
256
  },
259
257
  {
260
258
  key: "load",
261
259
  value: /** @inheritDoc */ function load(context) {
262
- var countDown = this.numberOfRetry;
263
260
  var _this = this;
261
+ var countDown = this.numberOfRetry;
264
262
  return {
265
- transform: /*#__PURE__*/ function() {
266
- var _ref = _async_to_generator(function(fetchCall) {
263
+ transform: function(fetchCall) {
264
+ return _async_to_generator(function() {
267
265
  var result, conditionResult, e, conditionResult1;
268
266
  return _ts_generator(this, function(_state) {
269
267
  switch(_state.label){
@@ -286,7 +284,7 @@ import { CanceledCallError } from '@ama-sdk/core';
286
284
  ];
287
285
  return [
288
286
  4,
289
- _this.condition(context, result.clone())
287
+ this.condition(context, result.clone())
290
288
  ];
291
289
  case 2:
292
290
  conditionResult = _state.sent();
@@ -294,7 +292,7 @@ import { CanceledCallError } from '@ama-sdk/core';
294
292
  countDown--;
295
293
  return [
296
294
  2,
297
- _this.waitAndRetry(context, countDown)
295
+ this.waitAndRetry(context, countDown)
298
296
  ];
299
297
  }
300
298
  _state.label = 3;
@@ -311,7 +309,7 @@ import { CanceledCallError } from '@ama-sdk/core';
311
309
  ];
312
310
  return [
313
311
  4,
314
- _this.condition(context, undefined, e)
312
+ this.condition(context, undefined, e)
315
313
  ];
316
314
  case 5:
317
315
  conditionResult1 = _state.sent();
@@ -319,7 +317,7 @@ import { CanceledCallError } from '@ama-sdk/core';
319
317
  countDown--;
320
318
  return [
321
319
  2,
322
- _this.waitAndRetry(context, countDown)
320
+ this.waitAndRetry(context, countDown)
323
321
  ];
324
322
  }
325
323
  _state.label = 6;
@@ -331,11 +329,8 @@ import { CanceledCallError } from '@ama-sdk/core';
331
329
  ];
332
330
  }
333
331
  });
334
- });
335
- return function(fetchCall) {
336
- return _ref.apply(this, arguments);
337
- };
338
- }()
332
+ }).call(_this);
333
+ }
339
334
  };
340
335
  }
341
336
  }
@@ -120,221 +120,233 @@ function _ts_generator(thisArg, body) {
120
120
  }
121
121
  import { RetryFetch } from './retry.fetch';
122
122
  describe('Retry Fetch Plugin', function() {
123
- it('should not retry on success', /*#__PURE__*/ _async_to_generator(function() {
124
- var condition, plugin, runner, call, res, ret;
125
- return _ts_generator(this, function(_state) {
126
- switch(_state.label){
127
- case 0:
128
- condition = jest.fn().mockReturnValue(true);
129
- plugin = new RetryFetch(1, condition);
130
- runner = plugin.load({
131
- url: 'http://www.test.com',
132
- fetchPlugins: []
133
- });
134
- call = Promise.resolve({
135
- text: 'test',
136
- ok: true
137
- });
138
- res = runner.transform(call);
139
- expect(condition).not.toHaveBeenCalled();
140
- return [
141
- 4,
142
- res
143
- ];
144
- case 1:
145
- ret = _state.sent();
146
- expect(ret).toEqual({
147
- text: 'test',
148
- ok: true
149
- });
150
- return [
151
- 2
152
- ];
153
- }
154
- });
155
- }));
156
- it('should not retry if refused by the condition', /*#__PURE__*/ _async_to_generator(function() {
157
- var conditionFalsy, plugin, runner, call, res;
158
- return _ts_generator(this, function(_state) {
159
- switch(_state.label){
160
- case 0:
161
- conditionFalsy = jest.fn().mockReturnValue(false);
162
- plugin = new RetryFetch(3, conditionFalsy);
163
- runner = plugin.load({
164
- url: 'http://www.test.com',
165
- fetchPlugins: []
166
- });
167
- call = Promise.resolve({
168
- text: 'test',
169
- ok: false,
170
- clone: function() {
171
- return {};
172
- }
173
- });
174
- res = runner.transform(call);
175
- return [
176
- 4,
177
- res
178
- ];
179
- case 1:
180
- _state.sent();
181
- expect(conditionFalsy).toHaveBeenCalledTimes(1);
182
- return [
183
- 2
184
- ];
185
- }
186
- });
187
- }));
188
- it('should retry on fetch rejection', /*#__PURE__*/ _async_to_generator(function() {
189
- var condition, plugin, runners, runner, call, callback;
190
- return _ts_generator(this, function(_state) {
191
- switch(_state.label){
192
- case 0:
193
- condition = jest.fn().mockReturnValue(true);
194
- plugin = new RetryFetch(2, condition);
195
- runners = [];
196
- runner = plugin.load({
197
- url: 'not an url',
198
- fetchPlugins: runners
199
- });
200
- runners.push(runner);
201
- call = Promise.reject(new Error(JSON.stringify({
202
- text: 'test',
203
- ok: true
204
- })));
205
- callback = jest.fn();
206
- runner.transform(call).catch(callback);
207
- return [
208
- 4,
209
- jest.runAllTimersAsync()
210
- ];
211
- case 1:
212
- _state.sent();
213
- expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
214
- expect(condition).toHaveBeenCalledTimes(2);
215
- return [
216
- 2
217
- ];
218
- }
219
- });
220
- }));
221
- it('should retry on fetch rejection with wait', /*#__PURE__*/ _async_to_generator(function() {
222
- var condition, delay, plugin, runners, runner, call, callback;
223
- return _ts_generator(this, function(_state) {
224
- switch(_state.label){
225
- case 0:
226
- condition = jest.fn().mockReturnValue(true);
227
- delay = 500;
228
- plugin = new RetryFetch(2, condition, function() {
229
- return delay;
230
- });
231
- runners = [];
232
- runner = plugin.load({
233
- url: 'not an url',
234
- fetchPlugins: runners
235
- });
236
- runners.push(runner);
237
- call = Promise.reject(new Error(JSON.stringify({
238
- text: 'test',
239
- ok: true
240
- })));
241
- callback = jest.fn();
242
- runner.transform(call).catch(callback);
243
- return [
244
- 4,
245
- jest.advanceTimersByTimeAsync(delay)
246
- ];
247
- case 1:
248
- _state.sent();
249
- expect(callback).not.toHaveBeenCalled();
250
- return [
251
- 4,
252
- jest.advanceTimersByTimeAsync(delay)
253
- ];
254
- case 2:
255
- _state.sent();
256
- expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
257
- expect(condition).toHaveBeenCalledTimes(2);
258
- return [
259
- 2
260
- ];
261
- }
262
- });
263
- }));
264
- it('should retry on not ok call', /*#__PURE__*/ _async_to_generator(function() {
265
- var condition, plugin, runners, runner, call, callback;
266
- return _ts_generator(this, function(_state) {
267
- switch(_state.label){
268
- case 0:
269
- condition = jest.fn().mockReturnValue(true);
270
- plugin = new RetryFetch(3, condition);
271
- runners = [];
272
- runner = plugin.load({
273
- url: 'not an url',
274
- fetchPlugins: runners
275
- });
276
- runners.push(runner);
277
- call = Promise.resolve({
278
- text: 'test',
279
- ok: false
280
- });
281
- callback = jest.fn();
282
- runner.transform(call).catch(callback);
283
- return [
284
- 4,
285
- jest.runAllTimersAsync()
286
- ];
287
- case 1:
288
- _state.sent();
289
- expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
290
- expect(condition).toHaveBeenCalledTimes(3);
291
- return [
292
- 2
293
- ];
294
- }
295
- });
296
- }));
297
- it('should retry on not ok call with wait', /*#__PURE__*/ _async_to_generator(function() {
298
- var condition, delay, plugin, runners, runner, call, callback;
299
- return _ts_generator(this, function(_state) {
300
- switch(_state.label){
301
- case 0:
302
- condition = jest.fn().mockReturnValue(true);
303
- delay = 500;
304
- plugin = new RetryFetch(3, condition, function() {
305
- return delay;
306
- });
307
- runners = [];
308
- runner = plugin.load({
309
- url: 'not an url',
310
- fetchPlugins: runners
311
- });
312
- runners.push(runner);
313
- call = Promise.resolve({
314
- text: 'test',
315
- ok: false
316
- });
317
- callback = jest.fn();
318
- runner.transform(call).catch(callback);
319
- return [
320
- 4,
321
- jest.advanceTimersByTimeAsync(2 * delay)
322
- ];
323
- case 1:
324
- _state.sent();
325
- expect(callback).not.toHaveBeenCalled();
326
- return [
327
- 4,
328
- jest.advanceTimersByTimeAsync(delay)
329
- ];
330
- case 2:
331
- _state.sent();
332
- expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
333
- expect(condition).toHaveBeenCalledTimes(3);
334
- return [
335
- 2
336
- ];
337
- }
338
- });
339
- }));
123
+ it('should not retry on success', function() {
124
+ return _async_to_generator(function() {
125
+ var condition, plugin, runner, call, res, ret;
126
+ return _ts_generator(this, function(_state) {
127
+ switch(_state.label){
128
+ case 0:
129
+ condition = jest.fn().mockReturnValue(true);
130
+ plugin = new RetryFetch(1, condition);
131
+ runner = plugin.load({
132
+ url: 'http://www.test.com',
133
+ fetchPlugins: []
134
+ });
135
+ call = Promise.resolve({
136
+ text: 'test',
137
+ ok: true
138
+ });
139
+ res = runner.transform(call);
140
+ expect(condition).not.toHaveBeenCalled();
141
+ return [
142
+ 4,
143
+ res
144
+ ];
145
+ case 1:
146
+ ret = _state.sent();
147
+ expect(ret).toEqual({
148
+ text: 'test',
149
+ ok: true
150
+ });
151
+ return [
152
+ 2
153
+ ];
154
+ }
155
+ });
156
+ })();
157
+ });
158
+ it('should not retry if refused by the condition', function() {
159
+ return _async_to_generator(function() {
160
+ var conditionFalsy, plugin, runner, call, res;
161
+ return _ts_generator(this, function(_state) {
162
+ switch(_state.label){
163
+ case 0:
164
+ conditionFalsy = jest.fn().mockReturnValue(false);
165
+ plugin = new RetryFetch(3, conditionFalsy);
166
+ runner = plugin.load({
167
+ url: 'http://www.test.com',
168
+ fetchPlugins: []
169
+ });
170
+ call = Promise.resolve({
171
+ text: 'test',
172
+ ok: false,
173
+ clone: function() {
174
+ return {};
175
+ }
176
+ });
177
+ res = runner.transform(call);
178
+ return [
179
+ 4,
180
+ res
181
+ ];
182
+ case 1:
183
+ _state.sent();
184
+ expect(conditionFalsy).toHaveBeenCalledTimes(1);
185
+ return [
186
+ 2
187
+ ];
188
+ }
189
+ });
190
+ })();
191
+ });
192
+ it('should retry on fetch rejection', function() {
193
+ return _async_to_generator(function() {
194
+ var condition, plugin, runners, runner, call, callback;
195
+ return _ts_generator(this, function(_state) {
196
+ switch(_state.label){
197
+ case 0:
198
+ condition = jest.fn().mockReturnValue(true);
199
+ plugin = new RetryFetch(2, condition);
200
+ runners = [];
201
+ runner = plugin.load({
202
+ url: 'not an url',
203
+ fetchPlugins: runners
204
+ });
205
+ runners.push(runner);
206
+ call = Promise.reject(new Error(JSON.stringify({
207
+ text: 'test',
208
+ ok: true
209
+ })));
210
+ callback = jest.fn();
211
+ runner.transform(call).catch(callback);
212
+ return [
213
+ 4,
214
+ jest.runAllTimersAsync()
215
+ ];
216
+ case 1:
217
+ _state.sent();
218
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
219
+ expect(condition).toHaveBeenCalledTimes(2);
220
+ return [
221
+ 2
222
+ ];
223
+ }
224
+ });
225
+ })();
226
+ });
227
+ it('should retry on fetch rejection with wait', function() {
228
+ return _async_to_generator(function() {
229
+ var condition, delay, plugin, runners, runner, call, callback;
230
+ return _ts_generator(this, function(_state) {
231
+ switch(_state.label){
232
+ case 0:
233
+ condition = jest.fn().mockReturnValue(true);
234
+ delay = 500;
235
+ plugin = new RetryFetch(2, condition, function() {
236
+ return delay;
237
+ });
238
+ runners = [];
239
+ runner = plugin.load({
240
+ url: 'not an url',
241
+ fetchPlugins: runners
242
+ });
243
+ runners.push(runner);
244
+ call = Promise.reject(new Error(JSON.stringify({
245
+ text: 'test',
246
+ ok: true
247
+ })));
248
+ callback = jest.fn();
249
+ runner.transform(call).catch(callback);
250
+ return [
251
+ 4,
252
+ jest.advanceTimersByTimeAsync(delay)
253
+ ];
254
+ case 1:
255
+ _state.sent();
256
+ expect(callback).not.toHaveBeenCalled();
257
+ return [
258
+ 4,
259
+ jest.advanceTimersByTimeAsync(delay)
260
+ ];
261
+ case 2:
262
+ _state.sent();
263
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
264
+ expect(condition).toHaveBeenCalledTimes(2);
265
+ return [
266
+ 2
267
+ ];
268
+ }
269
+ });
270
+ })();
271
+ });
272
+ it('should retry on not ok call', function() {
273
+ return _async_to_generator(function() {
274
+ var condition, plugin, runners, runner, call, callback;
275
+ return _ts_generator(this, function(_state) {
276
+ switch(_state.label){
277
+ case 0:
278
+ condition = jest.fn().mockReturnValue(true);
279
+ plugin = new RetryFetch(3, condition);
280
+ runners = [];
281
+ runner = plugin.load({
282
+ url: 'not an url',
283
+ fetchPlugins: runners
284
+ });
285
+ runners.push(runner);
286
+ call = Promise.resolve({
287
+ text: 'test',
288
+ ok: false
289
+ });
290
+ callback = jest.fn();
291
+ runner.transform(call).catch(callback);
292
+ return [
293
+ 4,
294
+ jest.runAllTimersAsync()
295
+ ];
296
+ case 1:
297
+ _state.sent();
298
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
299
+ expect(condition).toHaveBeenCalledTimes(3);
300
+ return [
301
+ 2
302
+ ];
303
+ }
304
+ });
305
+ })();
306
+ });
307
+ it('should retry on not ok call with wait', function() {
308
+ return _async_to_generator(function() {
309
+ var condition, delay, plugin, runners, runner, call, callback;
310
+ return _ts_generator(this, function(_state) {
311
+ switch(_state.label){
312
+ case 0:
313
+ condition = jest.fn().mockReturnValue(true);
314
+ delay = 500;
315
+ plugin = new RetryFetch(3, condition, function() {
316
+ return delay;
317
+ });
318
+ runners = [];
319
+ runner = plugin.load({
320
+ url: 'not an url',
321
+ fetchPlugins: runners
322
+ });
323
+ runners.push(runner);
324
+ call = Promise.resolve({
325
+ text: 'test',
326
+ ok: false
327
+ });
328
+ callback = jest.fn();
329
+ runner.transform(call).catch(callback);
330
+ return [
331
+ 4,
332
+ jest.advanceTimersByTimeAsync(2 * delay)
333
+ ];
334
+ case 1:
335
+ _state.sent();
336
+ expect(callback).not.toHaveBeenCalled();
337
+ return [
338
+ 4,
339
+ jest.advanceTimersByTimeAsync(delay)
340
+ ];
341
+ case 2:
342
+ _state.sent();
343
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining({}));
344
+ expect(condition).toHaveBeenCalledTimes(3);
345
+ return [
346
+ 2
347
+ ];
348
+ }
349
+ });
350
+ })();
351
+ });
340
352
  });
@@ -231,18 +231,19 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
231
231
  return {
232
232
  transform: function(fetchCall) {
233
233
  return(// eslint-disable-next-line no-async-promise-executor -- all await are handled with a try-catch block
234
- new Promise(/*#__PURE__*/ function() {
235
- var _ref = _async_to_generator(function(resolve, reject) {
236
- 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;
237
237
  return _ts_generator(this, function(_state) {
238
238
  switch(_state.label){
239
239
  case 0:
240
+ _this = this;
240
241
  timeoutCallback = function() {
241
242
  reject(new ResponseTimeoutError("in ".concat(_this.timeout, "ms")));
242
243
  // Fetch abort controller is now supported by all modern browser and node 15+. It should always be defined
243
244
  context.controller.abort();
244
245
  };
245
- timer = _this.timerPauseState === 'timeoutStopped' ? undefined : setTimeout(timeoutCallback, _this.timeout);
246
+ timer = this.timerPauseState === 'timeoutStopped' ? undefined : setTimeout(timeoutCallback, this.timeout);
246
247
  timerCallback = function(pauseStatus) {
247
248
  if (timer && pauseStatus === 'timeoutStopped') {
248
249
  clearTimeout(timer);
@@ -253,7 +254,7 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
253
254
  (context.logger || console).log('[SDK Plugins] Timeout restarted.');
254
255
  }
255
256
  };
256
- _this.timerSubscription.push(timerCallback);
257
+ this.timerSubscription.push(timerCallback);
257
258
  _state.label = 1;
258
259
  case 1:
259
260
  _state.trys.push([
@@ -286,7 +287,7 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
286
287
  if (timer) {
287
288
  clearTimeout(timer);
288
289
  }
289
- _this.timerSubscription = _this.timerSubscription.filter(function(callback) {
290
+ this.timerSubscription = this.timerSubscription.filter(function(callback) {
290
291
  return timerCallback !== callback;
291
292
  });
292
293
  return [
@@ -298,11 +299,8 @@ import { ResponseTimeoutError } from '@ama-sdk/core';
298
299
  ];
299
300
  }
300
301
  });
301
- });
302
- return function(resolve, reject) {
303
- return _ref.apply(this, arguments);
304
- };
305
- }()));
302
+ }).call(_this);
303
+ }));
306
304
  }
307
305
  };
308
306
  }