@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
@@ -278,7 +278,6 @@ var ApiFetchClient = /*#__PURE__*/ function() {
278
278
  {
279
279
  key: "getRequestOptions",
280
280
  value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
281
- var _this = this;
282
281
  return _async_to_generator(function() {
283
282
  var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
284
283
  return _ts_generator(this, function(_state) {
@@ -288,7 +287,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
288
287
  headers: new Headers((0, _core.filterUndefinedValues)(requestOptionsParameters.headers)),
289
288
  queryParams: (0, _core.filterUndefinedValues)(requestOptionsParameters.queryParams)
290
289
  });
291
- if (!_this.options.requestPlugins) return [
290
+ if (!this.options.requestPlugins) return [
292
291
  3,
293
292
  8
294
293
  ];
@@ -301,7 +300,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
301
300
  7,
302
301
  8
303
302
  ]);
304
- _iterator = _this.options.requestPlugins[Symbol.iterator]();
303
+ _iterator = this.options.requestPlugins[Symbol.iterator]();
305
304
  _state.label = 2;
306
305
  case 2:
307
306
  if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
@@ -312,7 +311,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
312
311
  return [
313
312
  4,
314
313
  plugin.load({
315
- logger: _this.options.logger,
314
+ logger: this.options.logger,
316
315
  apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
317
316
  }).transform(opts)
318
317
  ];
@@ -358,7 +357,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
358
357
  ];
359
358
  }
360
359
  });
361
- })();
360
+ }).call(this);
362
361
  }
363
362
  },
364
363
  {
@@ -401,12 +400,12 @@ var ApiFetchClient = /*#__PURE__*/ function() {
401
400
  {
402
401
  key: "processCall",
403
402
  value: function processCall(url, options, apiType, apiName, revivers, operationId) {
404
- var _this = this;
405
403
  return _async_to_generator(function() {
406
- var response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
404
+ var _this, response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
407
405
  return _ts_generator(this, function(_state) {
408
406
  switch(_state.label){
409
407
  case 0:
408
+ _this = this;
410
409
  origin = options.headers.get('Origin');
411
410
  _state.label = 1;
412
411
  case 1:
@@ -424,9 +423,9 @@ var ApiFetchClient = /*#__PURE__*/ function() {
424
423
  return controller.abort();
425
424
  });
426
425
  loadedPlugins = [];
427
- if (_this.options.fetchPlugins) {
426
+ if (this.options.fetchPlugins) {
428
427
  ;
429
- (_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(_this.options.fetchPlugins.map(function(plugin) {
428
+ (_loadedPlugins = loadedPlugins).push.apply(_loadedPlugins, _to_consumable_array(this.options.fetchPlugins.map(function(plugin) {
430
429
  return plugin.load({
431
430
  url: url,
432
431
  options: options,
@@ -446,7 +445,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
446
445
  case 2:
447
446
  canStart = _state.sent();
448
447
  isCanceledBy = canStart.indexOf(false);
449
- asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, _this.options.fetchPlugins[isCanceledBy], {
448
+ asyncResponse = isCanceledBy === -1 ? fetch(url, options) : Promise.reject(new _core.CanceledCallError("Is canceled by the plugin ".concat(isCanceledBy), isCanceledBy, this.options.fetchPlugins[isCanceledBy], {
450
449
  apiName: apiName,
451
450
  operationId: operationId,
452
451
  url: url,
@@ -524,10 +523,10 @@ var ApiFetchClient = /*#__PURE__*/ function() {
524
523
  }
525
524
  // eslint-disable-next-line no-console -- `console.error` is supposed to be the default value if the `options` argument is not provided, can be removed in Otter v12.
526
525
  reviver = (0, _core.getResponseReviver)(revivers, response, operationId, {
527
- disableFallback: _this.options.disableFallback,
526
+ disableFallback: this.options.disableFallback,
528
527
  log: console.error
529
528
  });
530
- replyPlugins = _this.options.replyPlugins ? _this.options.replyPlugins.map(function(plugin) {
529
+ replyPlugins = this.options.replyPlugins ? this.options.replyPlugins.map(function(plugin) {
531
530
  return plugin.load({
532
531
  dictionaries: root && root.dictionaries,
533
532
  response: response,
@@ -608,7 +607,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
608
607
  ];
609
608
  }
610
609
  });
611
- })();
610
+ }).call(this);
612
611
  }
613
612
  }
614
613
  ]);
@@ -124,77 +124,83 @@ function _ts_generator(thisArg, body) {
124
124
  }
125
125
  }
126
126
  describe('Abort Plugin', function() {
127
- it('should trigger the callback', /*#__PURE__*/ _async_to_generator(function() {
128
- var fn, plugin, runner;
129
- return _ts_generator(this, function(_state) {
130
- switch(_state.label){
131
- case 0:
132
- fn = jest.fn();
133
- plugin = new _abortfetch.AbortFetch(fn);
134
- runner = plugin.load({});
135
- return [
136
- 4,
137
- runner.transform(Promise.resolve())
138
- ];
139
- case 1:
140
- _state.sent();
141
- expect(fn).toHaveBeenCalled();
142
- return [
143
- 2
144
- ];
145
- }
146
- });
147
- }));
148
- it('should trigger abort signal if true', /*#__PURE__*/ _async_to_generator(function() {
149
- var defaultContext, fn, plugin, runner;
150
- return _ts_generator(this, function(_state) {
151
- switch(_state.label){
152
- case 0:
153
- defaultContext = {
154
- controller: {
155
- abort: jest.fn()
156
- }
157
- };
158
- fn = jest.fn().mockResolvedValue(true);
159
- plugin = new _abortfetch.AbortFetch(fn);
160
- runner = plugin.load(defaultContext);
161
- return [
162
- 4,
163
- runner.transform(Promise.resolve())
164
- ];
165
- case 1:
166
- _state.sent();
167
- expect(defaultContext.controller.abort).toHaveBeenCalled();
168
- return [
169
- 2
170
- ];
171
- }
172
- });
173
- }));
174
- it('should not trigger abort signal if false', /*#__PURE__*/ _async_to_generator(function() {
175
- var defaultContext, fn, plugin, runner;
176
- return _ts_generator(this, function(_state) {
177
- switch(_state.label){
178
- case 0:
179
- defaultContext = {
180
- controller: {
181
- abort: jest.fn()
182
- }
183
- };
184
- fn = jest.fn().mockResolvedValue(false);
185
- plugin = new _abortfetch.AbortFetch(fn);
186
- runner = plugin.load(defaultContext);
187
- return [
188
- 4,
189
- runner.transform(Promise.resolve())
190
- ];
191
- case 1:
192
- _state.sent();
193
- expect(defaultContext.controller.abort).not.toHaveBeenCalled();
194
- return [
195
- 2
196
- ];
197
- }
198
- });
199
- }));
127
+ it('should trigger the callback', function() {
128
+ return _async_to_generator(function() {
129
+ var fn, plugin, runner;
130
+ return _ts_generator(this, function(_state) {
131
+ switch(_state.label){
132
+ case 0:
133
+ fn = jest.fn();
134
+ plugin = new _abortfetch.AbortFetch(fn);
135
+ runner = plugin.load({});
136
+ return [
137
+ 4,
138
+ runner.transform(Promise.resolve())
139
+ ];
140
+ case 1:
141
+ _state.sent();
142
+ expect(fn).toHaveBeenCalled();
143
+ return [
144
+ 2
145
+ ];
146
+ }
147
+ });
148
+ })();
149
+ });
150
+ it('should trigger abort signal if true', function() {
151
+ return _async_to_generator(function() {
152
+ var defaultContext, fn, plugin, runner;
153
+ return _ts_generator(this, function(_state) {
154
+ switch(_state.label){
155
+ case 0:
156
+ defaultContext = {
157
+ controller: {
158
+ abort: jest.fn()
159
+ }
160
+ };
161
+ fn = jest.fn().mockResolvedValue(true);
162
+ plugin = new _abortfetch.AbortFetch(fn);
163
+ runner = plugin.load(defaultContext);
164
+ return [
165
+ 4,
166
+ runner.transform(Promise.resolve())
167
+ ];
168
+ case 1:
169
+ _state.sent();
170
+ expect(defaultContext.controller.abort).toHaveBeenCalled();
171
+ return [
172
+ 2
173
+ ];
174
+ }
175
+ });
176
+ })();
177
+ });
178
+ it('should not trigger abort signal if false', function() {
179
+ return _async_to_generator(function() {
180
+ var defaultContext, fn, plugin, runner;
181
+ return _ts_generator(this, function(_state) {
182
+ switch(_state.label){
183
+ case 0:
184
+ defaultContext = {
185
+ controller: {
186
+ abort: jest.fn()
187
+ }
188
+ };
189
+ fn = jest.fn().mockResolvedValue(false);
190
+ plugin = new _abortfetch.AbortFetch(fn);
191
+ runner = plugin.load(defaultContext);
192
+ return [
193
+ 4,
194
+ runner.transform(Promise.resolve())
195
+ ];
196
+ case 1:
197
+ _state.sent();
198
+ expect(defaultContext.controller.abort).not.toHaveBeenCalled();
199
+ return [
200
+ 2
201
+ ];
202
+ }
203
+ });
204
+ })();
205
+ });
200
206
  });
@@ -195,20 +195,19 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
195
195
  value: /** @inheritDoc */ function load(_context) {
196
196
  var _this = this;
197
197
  this.poolSize++;
198
- var _this1 = this;
199
198
  return {
200
199
  canStart: function() {
201
200
  return new Promise(function(resolve) {
202
201
  return _this.canStart() ? resolve(true) : _this.waitingResolvers.push(resolve);
203
202
  });
204
203
  },
205
- transform: /*#__PURE__*/ function() {
206
- var _ref = _async_to_generator(function(fetchCall) {
204
+ transform: function(fetchCall) {
205
+ return _async_to_generator(function() {
207
206
  var fetchResponse;
208
207
  return _ts_generator(this, function(_state) {
209
208
  switch(_state.label){
210
209
  case 0:
211
- _this1.pool.push(fetchCall);
210
+ this.pool.push(fetchCall);
212
211
  _state.label = 1;
213
212
  case 1:
214
213
  _state.trys.push([
@@ -228,11 +227,11 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
228
227
  fetchResponse
229
228
  ];
230
229
  case 3:
231
- _this1.pool = _this1.pool.filter(function(call) {
230
+ this.pool = this.pool.filter(function(call) {
232
231
  return call !== fetchCall;
233
232
  });
234
- _this1.poolSize--;
235
- _this1.unstackResolve();
233
+ this.poolSize--;
234
+ this.unstackResolve();
236
235
  return [
237
236
  7
238
237
  ];
@@ -242,11 +241,8 @@ var ConcurrentFetch = /*#__PURE__*/ function() {
242
241
  ];
243
242
  }
244
243
  });
245
- });
246
- return function(fetchCall) {
247
- return _ref.apply(this, arguments);
248
- };
249
- }()
244
+ }).call(_this);
245
+ }
250
246
  };
251
247
  }
252
248
  }
@@ -124,27 +124,29 @@ function _ts_generator(thisArg, body) {
124
124
  }
125
125
  }
126
126
  describe('Concurrent Fetch Plugin', function() {
127
- it('should start if the limit is not reach', /*#__PURE__*/ _async_to_generator(function() {
128
- var plugin, runner, canStart;
129
- return _ts_generator(this, function(_state) {
130
- switch(_state.label){
131
- case 0:
132
- plugin = new _concurrentfetch.ConcurrentFetch(3);
133
- plugin.load({});
134
- runner = plugin.load({});
135
- return [
136
- 4,
137
- runner.canStart()
138
- ];
139
- case 1:
140
- canStart = _state.sent();
141
- expect(canStart).toBe(true);
142
- return [
143
- 2
144
- ];
145
- }
146
- });
147
- }));
127
+ it('should start if the limit is not reach', function() {
128
+ return _async_to_generator(function() {
129
+ var plugin, runner, canStart;
130
+ return _ts_generator(this, function(_state) {
131
+ switch(_state.label){
132
+ case 0:
133
+ plugin = new _concurrentfetch.ConcurrentFetch(3);
134
+ plugin.load({});
135
+ runner = plugin.load({});
136
+ return [
137
+ 4,
138
+ runner.canStart()
139
+ ];
140
+ case 1:
141
+ canStart = _state.sent();
142
+ expect(canStart).toBe(true);
143
+ return [
144
+ 2
145
+ ];
146
+ }
147
+ });
148
+ })();
149
+ });
148
150
  it('should retrieve the fetch call in the pool', function() {
149
151
  var plugin = new _concurrentfetch.ConcurrentFetch(3);
150
152
  var call = new Promise(function(resolve) {
@@ -162,74 +164,76 @@ describe('Concurrent Fetch Plugin', function() {
162
164
  void plugin.load({}).transform(test);
163
165
  expect(plugin.pool[2]).toBe(test);
164
166
  });
165
- it('should start only when the pool is available', /*#__PURE__*/ _async_to_generator(function() {
166
- var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
167
- return _ts_generator(this, function(_state) {
168
- switch(_state.label){
169
- case 0:
170
- plugin = new _concurrentfetch.ConcurrentFetch(2);
171
- resolves = [
172
- null,
173
- null
174
- ];
175
- call0 = new Promise(function(resolve) {
176
- return resolves[0] = resolve;
177
- });
178
- call1 = new Promise(function(resolve) {
179
- return resolves[1] = resolve;
180
- });
181
- result = {
182
- res: false
183
- };
184
- void plugin.load({}).transform(call0);
185
- runner1 = plugin.load({});
186
- canStart1 = runner1.canStart();
187
- return [
188
- 4,
189
- jest.runAllTimersAsync()
190
- ];
191
- case 1:
192
- _state.sent();
193
- return [
194
- 4,
195
- canStart1
196
- ];
197
- case 2:
198
- expect.apply(void 0, [
199
- _state.sent()
200
- ]).toBe(true);
201
- void runner1.transform(call1);
202
- runner2 = plugin.load({});
203
- pCanStart2 = runner2.canStart();
204
- return [
205
- 4,
206
- jest.runAllTimersAsync()
207
- ];
208
- case 3:
209
- _state.sent();
210
- expect(plugin.waitingResolvers.length).toBe(1);
211
- result.res = true;
212
- resolves[0]();
213
- return [
214
- 4,
215
- pCanStart2
216
- ];
217
- case 4:
218
- expect.apply(void 0, [
219
- _state.sent()
220
- ]).toBe(true);
221
- resolves[1]();
222
- return [
223
- 4,
224
- jest.advanceTimersByTimeAsync(500)
225
- ];
226
- case 5:
227
- _state.sent();
228
- expect(plugin.waitingResolvers.length).toBe(0);
229
- return [
230
- 2
231
- ];
232
- }
233
- });
234
- }));
167
+ it('should start only when the pool is available', function() {
168
+ return _async_to_generator(function() {
169
+ var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
170
+ return _ts_generator(this, function(_state) {
171
+ switch(_state.label){
172
+ case 0:
173
+ plugin = new _concurrentfetch.ConcurrentFetch(2);
174
+ resolves = [
175
+ null,
176
+ null
177
+ ];
178
+ call0 = new Promise(function(resolve) {
179
+ return resolves[0] = resolve;
180
+ });
181
+ call1 = new Promise(function(resolve) {
182
+ return resolves[1] = resolve;
183
+ });
184
+ result = {
185
+ res: false
186
+ };
187
+ void plugin.load({}).transform(call0);
188
+ runner1 = plugin.load({});
189
+ canStart1 = runner1.canStart();
190
+ return [
191
+ 4,
192
+ jest.runAllTimersAsync()
193
+ ];
194
+ case 1:
195
+ _state.sent();
196
+ return [
197
+ 4,
198
+ canStart1
199
+ ];
200
+ case 2:
201
+ expect.apply(void 0, [
202
+ _state.sent()
203
+ ]).toBe(true);
204
+ void runner1.transform(call1);
205
+ runner2 = plugin.load({});
206
+ pCanStart2 = runner2.canStart();
207
+ return [
208
+ 4,
209
+ jest.runAllTimersAsync()
210
+ ];
211
+ case 3:
212
+ _state.sent();
213
+ expect(plugin.waitingResolvers.length).toBe(1);
214
+ result.res = true;
215
+ resolves[0]();
216
+ return [
217
+ 4,
218
+ pCanStart2
219
+ ];
220
+ case 4:
221
+ expect.apply(void 0, [
222
+ _state.sent()
223
+ ]).toBe(true);
224
+ resolves[1]();
225
+ return [
226
+ 4,
227
+ jest.advanceTimersByTimeAsync(500)
228
+ ];
229
+ case 5:
230
+ _state.sent();
231
+ expect(plugin.waitingResolvers.length).toBe(0);
232
+ return [
233
+ 2
234
+ ];
235
+ }
236
+ });
237
+ })();
238
+ });
235
239
  });
@@ -221,7 +221,6 @@ var KeepaliveRequest = /*#__PURE__*/ function() {
221
221
  * https://bugs.chromium.org/p/chromium/issues/detail?id=835821
222
222
  * To avoid this issue we do a fake fetch call to check whether we can activate it or not in the browser.
223
223
  */ function testKeepAlive() {
224
- var _this = this;
225
224
  return _async_to_generator(function() {
226
225
  var customHeaders, e;
227
226
  return _ts_generator(this, function(_state) {
@@ -246,14 +245,14 @@ var KeepaliveRequest = /*#__PURE__*/ function() {
246
245
  ];
247
246
  case 2:
248
247
  _state.sent();
249
- _this.active = true;
248
+ this.active = true;
250
249
  return [
251
250
  3,
252
251
  4
253
252
  ];
254
253
  case 3:
255
254
  e = _state.sent();
256
- _this.active = false;
255
+ this.active = false;
257
256
  return [
258
257
  3,
259
258
  4
@@ -264,7 +263,7 @@ var KeepaliveRequest = /*#__PURE__*/ function() {
264
263
  ];
265
264
  }
266
265
  });
267
- })();
266
+ }).call(this);
268
267
  }
269
268
  },
270
269
  {
@@ -129,30 +129,32 @@ describe('Keepalive Request Plugin', function() {
129
129
  basePath: 'http://test.com/truc',
130
130
  method: 'get'
131
131
  };
132
- it('keepalive should be set to true', /*#__PURE__*/ _async_to_generator(function() {
133
- var plugin, runner, keepalive;
134
- return _ts_generator(this, function(_state) {
135
- switch(_state.label){
136
- case 0:
137
- plugin = new _keepaliverequest.KeepaliveRequest(true);
138
- runner = plugin.load();
139
- return [
140
- 4,
141
- runner.transform(options)
142
- ];
143
- case 1:
144
- _state.sent();
145
- return [
146
- 4,
147
- plugin.load().transform(options)
148
- ];
149
- case 2:
150
- keepalive = _state.sent().keepalive;
151
- expect(keepalive).toBe(true);
152
- return [
153
- 2
154
- ];
155
- }
156
- });
157
- }));
132
+ it('keepalive should be set to true', function() {
133
+ return _async_to_generator(function() {
134
+ var plugin, runner, keepalive;
135
+ return _ts_generator(this, function(_state) {
136
+ switch(_state.label){
137
+ case 0:
138
+ plugin = new _keepaliverequest.KeepaliveRequest(true);
139
+ runner = plugin.load();
140
+ return [
141
+ 4,
142
+ runner.transform(options)
143
+ ];
144
+ case 1:
145
+ _state.sent();
146
+ return [
147
+ 4,
148
+ plugin.load().transform(options)
149
+ ];
150
+ case 2:
151
+ keepalive = _state.sent().keepalive;
152
+ expect(keepalive).toBe(true);
153
+ return [
154
+ 2
155
+ ];
156
+ }
157
+ });
158
+ })();
159
+ });
158
160
  });