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