@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
@@ -120,77 +120,83 @@ function _ts_generator(thisArg, body) {
120
120
  }
121
121
  import { AbortFetch } from './abort.fetch';
122
122
  describe('Abort Plugin', function() {
123
- it('should trigger the callback', /*#__PURE__*/ _async_to_generator(function() {
124
- var fn, plugin, runner;
125
- return _ts_generator(this, function(_state) {
126
- switch(_state.label){
127
- case 0:
128
- fn = jest.fn();
129
- plugin = new AbortFetch(fn);
130
- runner = plugin.load({});
131
- return [
132
- 4,
133
- runner.transform(Promise.resolve())
134
- ];
135
- case 1:
136
- _state.sent();
137
- expect(fn).toHaveBeenCalled();
138
- return [
139
- 2
140
- ];
141
- }
142
- });
143
- }));
144
- it('should trigger abort signal if true', /*#__PURE__*/ _async_to_generator(function() {
145
- var defaultContext, fn, plugin, runner;
146
- return _ts_generator(this, function(_state) {
147
- switch(_state.label){
148
- case 0:
149
- defaultContext = {
150
- controller: {
151
- abort: jest.fn()
152
- }
153
- };
154
- fn = jest.fn().mockResolvedValue(true);
155
- plugin = new AbortFetch(fn);
156
- runner = plugin.load(defaultContext);
157
- return [
158
- 4,
159
- runner.transform(Promise.resolve())
160
- ];
161
- case 1:
162
- _state.sent();
163
- expect(defaultContext.controller.abort).toHaveBeenCalled();
164
- return [
165
- 2
166
- ];
167
- }
168
- });
169
- }));
170
- it('should not trigger abort signal if false', /*#__PURE__*/ _async_to_generator(function() {
171
- var defaultContext, fn, plugin, runner;
172
- return _ts_generator(this, function(_state) {
173
- switch(_state.label){
174
- case 0:
175
- defaultContext = {
176
- controller: {
177
- abort: jest.fn()
178
- }
179
- };
180
- fn = jest.fn().mockResolvedValue(false);
181
- plugin = new AbortFetch(fn);
182
- runner = plugin.load(defaultContext);
183
- return [
184
- 4,
185
- runner.transform(Promise.resolve())
186
- ];
187
- case 1:
188
- _state.sent();
189
- expect(defaultContext.controller.abort).not.toHaveBeenCalled();
190
- return [
191
- 2
192
- ];
193
- }
194
- });
195
- }));
123
+ it('should trigger the callback', function() {
124
+ return _async_to_generator(function() {
125
+ var fn, plugin, runner;
126
+ return _ts_generator(this, function(_state) {
127
+ switch(_state.label){
128
+ case 0:
129
+ fn = jest.fn();
130
+ plugin = new AbortFetch(fn);
131
+ runner = plugin.load({});
132
+ return [
133
+ 4,
134
+ runner.transform(Promise.resolve())
135
+ ];
136
+ case 1:
137
+ _state.sent();
138
+ expect(fn).toHaveBeenCalled();
139
+ return [
140
+ 2
141
+ ];
142
+ }
143
+ });
144
+ })();
145
+ });
146
+ it('should trigger abort signal if true', function() {
147
+ return _async_to_generator(function() {
148
+ var defaultContext, fn, plugin, runner;
149
+ return _ts_generator(this, function(_state) {
150
+ switch(_state.label){
151
+ case 0:
152
+ defaultContext = {
153
+ controller: {
154
+ abort: jest.fn()
155
+ }
156
+ };
157
+ fn = jest.fn().mockResolvedValue(true);
158
+ plugin = new AbortFetch(fn);
159
+ runner = plugin.load(defaultContext);
160
+ return [
161
+ 4,
162
+ runner.transform(Promise.resolve())
163
+ ];
164
+ case 1:
165
+ _state.sent();
166
+ expect(defaultContext.controller.abort).toHaveBeenCalled();
167
+ return [
168
+ 2
169
+ ];
170
+ }
171
+ });
172
+ })();
173
+ });
174
+ it('should not trigger abort signal if false', function() {
175
+ return _async_to_generator(function() {
176
+ var defaultContext, fn, plugin, runner;
177
+ return _ts_generator(this, function(_state) {
178
+ switch(_state.label){
179
+ case 0:
180
+ defaultContext = {
181
+ controller: {
182
+ abort: jest.fn()
183
+ }
184
+ };
185
+ fn = jest.fn().mockResolvedValue(false);
186
+ plugin = new AbortFetch(fn);
187
+ runner = plugin.load(defaultContext);
188
+ return [
189
+ 4,
190
+ runner.transform(Promise.resolve())
191
+ ];
192
+ case 1:
193
+ _state.sent();
194
+ expect(defaultContext.controller.abort).not.toHaveBeenCalled();
195
+ return [
196
+ 2
197
+ ];
198
+ }
199
+ });
200
+ })();
201
+ });
196
202
  });
@@ -187,20 +187,19 @@ function _ts_generator(thisArg, body) {
187
187
  value: /** @inheritDoc */ function load(_context) {
188
188
  var _this = this;
189
189
  this.poolSize++;
190
- var _this1 = this;
191
190
  return {
192
191
  canStart: function() {
193
192
  return new Promise(function(resolve) {
194
193
  return _this.canStart() ? resolve(true) : _this.waitingResolvers.push(resolve);
195
194
  });
196
195
  },
197
- transform: /*#__PURE__*/ function() {
198
- var _ref = _async_to_generator(function(fetchCall) {
196
+ transform: function(fetchCall) {
197
+ return _async_to_generator(function() {
199
198
  var fetchResponse;
200
199
  return _ts_generator(this, function(_state) {
201
200
  switch(_state.label){
202
201
  case 0:
203
- _this1.pool.push(fetchCall);
202
+ this.pool.push(fetchCall);
204
203
  _state.label = 1;
205
204
  case 1:
206
205
  _state.trys.push([
@@ -220,11 +219,11 @@ function _ts_generator(thisArg, body) {
220
219
  fetchResponse
221
220
  ];
222
221
  case 3:
223
- _this1.pool = _this1.pool.filter(function(call) {
222
+ this.pool = this.pool.filter(function(call) {
224
223
  return call !== fetchCall;
225
224
  });
226
- _this1.poolSize--;
227
- _this1.unstackResolve();
225
+ this.poolSize--;
226
+ this.unstackResolve();
228
227
  return [
229
228
  7
230
229
  ];
@@ -234,11 +233,8 @@ function _ts_generator(thisArg, body) {
234
233
  ];
235
234
  }
236
235
  });
237
- });
238
- return function(fetchCall) {
239
- return _ref.apply(this, arguments);
240
- };
241
- }()
236
+ }).call(_this);
237
+ }
242
238
  };
243
239
  }
244
240
  }
@@ -120,27 +120,29 @@ function _ts_generator(thisArg, body) {
120
120
  }
121
121
  import { ConcurrentFetch } from './concurrent.fetch';
122
122
  describe('Concurrent Fetch Plugin', function() {
123
- it('should start if the limit is not reach', /*#__PURE__*/ _async_to_generator(function() {
124
- var plugin, runner, canStart;
125
- return _ts_generator(this, function(_state) {
126
- switch(_state.label){
127
- case 0:
128
- plugin = new ConcurrentFetch(3);
129
- plugin.load({});
130
- runner = plugin.load({});
131
- return [
132
- 4,
133
- runner.canStart()
134
- ];
135
- case 1:
136
- canStart = _state.sent();
137
- expect(canStart).toBe(true);
138
- return [
139
- 2
140
- ];
141
- }
142
- });
143
- }));
123
+ it('should start if the limit is not reach', function() {
124
+ return _async_to_generator(function() {
125
+ var plugin, runner, canStart;
126
+ return _ts_generator(this, function(_state) {
127
+ switch(_state.label){
128
+ case 0:
129
+ plugin = new ConcurrentFetch(3);
130
+ plugin.load({});
131
+ runner = plugin.load({});
132
+ return [
133
+ 4,
134
+ runner.canStart()
135
+ ];
136
+ case 1:
137
+ canStart = _state.sent();
138
+ expect(canStart).toBe(true);
139
+ return [
140
+ 2
141
+ ];
142
+ }
143
+ });
144
+ })();
145
+ });
144
146
  it('should retrieve the fetch call in the pool', function() {
145
147
  var plugin = new ConcurrentFetch(3);
146
148
  var call = new Promise(function(resolve) {
@@ -158,74 +160,76 @@ describe('Concurrent Fetch Plugin', function() {
158
160
  void plugin.load({}).transform(test);
159
161
  expect(plugin.pool[2]).toBe(test);
160
162
  });
161
- it('should start only when the pool is available', /*#__PURE__*/ _async_to_generator(function() {
162
- var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
163
- return _ts_generator(this, function(_state) {
164
- switch(_state.label){
165
- case 0:
166
- plugin = new ConcurrentFetch(2);
167
- resolves = [
168
- null,
169
- null
170
- ];
171
- call0 = new Promise(function(resolve) {
172
- return resolves[0] = resolve;
173
- });
174
- call1 = new Promise(function(resolve) {
175
- return resolves[1] = resolve;
176
- });
177
- result = {
178
- res: false
179
- };
180
- void plugin.load({}).transform(call0);
181
- runner1 = plugin.load({});
182
- canStart1 = runner1.canStart();
183
- return [
184
- 4,
185
- jest.runAllTimersAsync()
186
- ];
187
- case 1:
188
- _state.sent();
189
- return [
190
- 4,
191
- canStart1
192
- ];
193
- case 2:
194
- expect.apply(void 0, [
195
- _state.sent()
196
- ]).toBe(true);
197
- void runner1.transform(call1);
198
- runner2 = plugin.load({});
199
- pCanStart2 = runner2.canStart();
200
- return [
201
- 4,
202
- jest.runAllTimersAsync()
203
- ];
204
- case 3:
205
- _state.sent();
206
- expect(plugin.waitingResolvers.length).toBe(1);
207
- result.res = true;
208
- resolves[0]();
209
- return [
210
- 4,
211
- pCanStart2
212
- ];
213
- case 4:
214
- expect.apply(void 0, [
215
- _state.sent()
216
- ]).toBe(true);
217
- resolves[1]();
218
- return [
219
- 4,
220
- jest.advanceTimersByTimeAsync(500)
221
- ];
222
- case 5:
223
- _state.sent();
224
- expect(plugin.waitingResolvers.length).toBe(0);
225
- return [
226
- 2
227
- ];
228
- }
229
- });
230
- }));
163
+ it('should start only when the pool is available', function() {
164
+ return _async_to_generator(function() {
165
+ var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
166
+ return _ts_generator(this, function(_state) {
167
+ switch(_state.label){
168
+ case 0:
169
+ plugin = new ConcurrentFetch(2);
170
+ resolves = [
171
+ null,
172
+ null
173
+ ];
174
+ call0 = new Promise(function(resolve) {
175
+ return resolves[0] = resolve;
176
+ });
177
+ call1 = new Promise(function(resolve) {
178
+ return resolves[1] = resolve;
179
+ });
180
+ result = {
181
+ res: false
182
+ };
183
+ void plugin.load({}).transform(call0);
184
+ runner1 = plugin.load({});
185
+ canStart1 = runner1.canStart();
186
+ return [
187
+ 4,
188
+ jest.runAllTimersAsync()
189
+ ];
190
+ case 1:
191
+ _state.sent();
192
+ return [
193
+ 4,
194
+ canStart1
195
+ ];
196
+ case 2:
197
+ expect.apply(void 0, [
198
+ _state.sent()
199
+ ]).toBe(true);
200
+ void runner1.transform(call1);
201
+ runner2 = plugin.load({});
202
+ pCanStart2 = runner2.canStart();
203
+ return [
204
+ 4,
205
+ jest.runAllTimersAsync()
206
+ ];
207
+ case 3:
208
+ _state.sent();
209
+ expect(plugin.waitingResolvers.length).toBe(1);
210
+ result.res = true;
211
+ resolves[0]();
212
+ return [
213
+ 4,
214
+ pCanStart2
215
+ ];
216
+ case 4:
217
+ expect.apply(void 0, [
218
+ _state.sent()
219
+ ]).toBe(true);
220
+ resolves[1]();
221
+ return [
222
+ 4,
223
+ jest.advanceTimersByTimeAsync(500)
224
+ ];
225
+ case 5:
226
+ _state.sent();
227
+ expect(plugin.waitingResolvers.length).toBe(0);
228
+ return [
229
+ 2
230
+ ];
231
+ }
232
+ });
233
+ })();
234
+ });
231
235
  });
@@ -213,7 +213,6 @@ function _ts_generator(thisArg, body) {
213
213
  * https://bugs.chromium.org/p/chromium/issues/detail?id=835821
214
214
  * To avoid this issue we do a fake fetch call to check whether we can activate it or not in the browser.
215
215
  */ function testKeepAlive() {
216
- var _this = this;
217
216
  return _async_to_generator(function() {
218
217
  var customHeaders, e;
219
218
  return _ts_generator(this, function(_state) {
@@ -238,14 +237,14 @@ function _ts_generator(thisArg, body) {
238
237
  ];
239
238
  case 2:
240
239
  _state.sent();
241
- _this.active = true;
240
+ this.active = true;
242
241
  return [
243
242
  3,
244
243
  4
245
244
  ];
246
245
  case 3:
247
246
  e = _state.sent();
248
- _this.active = false;
247
+ this.active = false;
249
248
  return [
250
249
  3,
251
250
  4
@@ -256,7 +255,7 @@ function _ts_generator(thisArg, body) {
256
255
  ];
257
256
  }
258
257
  });
259
- })();
258
+ }).call(this);
260
259
  }
261
260
  },
262
261
  {
@@ -125,30 +125,32 @@ describe('Keepalive Request Plugin', function() {
125
125
  basePath: 'http://test.com/truc',
126
126
  method: 'get'
127
127
  };
128
- it('keepalive should be set to true', /*#__PURE__*/ _async_to_generator(function() {
129
- var plugin, runner, keepalive;
130
- return _ts_generator(this, function(_state) {
131
- switch(_state.label){
132
- case 0:
133
- plugin = new KeepaliveRequest(true);
134
- runner = plugin.load();
135
- return [
136
- 4,
137
- runner.transform(options)
138
- ];
139
- case 1:
140
- _state.sent();
141
- return [
142
- 4,
143
- plugin.load().transform(options)
144
- ];
145
- case 2:
146
- keepalive = _state.sent().keepalive;
147
- expect(keepalive).toBe(true);
148
- return [
149
- 2
150
- ];
151
- }
152
- });
153
- }));
128
+ it('keepalive should be set to true', function() {
129
+ return _async_to_generator(function() {
130
+ var plugin, runner, keepalive;
131
+ return _ts_generator(this, function(_state) {
132
+ switch(_state.label){
133
+ case 0:
134
+ plugin = new KeepaliveRequest(true);
135
+ runner = plugin.load();
136
+ return [
137
+ 4,
138
+ runner.transform(options)
139
+ ];
140
+ case 1:
141
+ _state.sent();
142
+ return [
143
+ 4,
144
+ plugin.load().transform(options)
145
+ ];
146
+ case 2:
147
+ keepalive = _state.sent().keepalive;
148
+ expect(keepalive).toBe(true);
149
+ return [
150
+ 2
151
+ ];
152
+ }
153
+ });
154
+ })();
155
+ });
154
156
  });
@@ -174,22 +174,22 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
174
174
  {
175
175
  key: "load",
176
176
  value: function load(context) {
177
+ var _this = this;
177
178
  if (!context.apiClient.options.requestPlugins.some(function(plugin) {
178
179
  return _instanceof(plugin, MockInterceptRequest);
179
180
  })) {
180
181
  throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
181
182
  }
182
- var _this = this;
183
183
  return {
184
- transform: /*#__PURE__*/ function() {
185
- var _ref = _async_to_generator(function(fetchCall) {
184
+ transform: function(fetchCall) {
185
+ return _async_to_generator(function() {
186
186
  var responsePromise, delay, _tmp, resp, operationId, mock, response;
187
187
  return _ts_generator(this, function(_state) {
188
188
  switch(_state.label){
189
189
  case 0:
190
190
  return [
191
191
  4,
192
- _this.options.adapter.initialize()
192
+ this.options.adapter.initialize()
193
193
  ];
194
194
  case 1:
195
195
  _state.sent();
@@ -200,15 +200,15 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
200
200
  responsePromise
201
201
  ];
202
202
  }
203
- if (!(typeof _this.options.delayTiming !== 'undefined')) return [
203
+ if (!(typeof this.options.delayTiming !== 'undefined')) return [
204
204
  3,
205
205
  6
206
206
  ];
207
- if (!(typeof _this.options.delayTiming === 'number')) return [
207
+ if (!(typeof this.options.delayTiming === 'number')) return [
208
208
  3,
209
209
  2
210
210
  ];
211
- _tmp = _this.options.delayTiming;
211
+ _tmp = this.options.delayTiming;
212
212
  return [
213
213
  3,
214
214
  4
@@ -216,7 +216,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
216
216
  case 2:
217
217
  return [
218
218
  4,
219
- _this.options.delayTiming(context)
219
+ this.options.delayTiming(context)
220
220
  ];
221
221
  case 3:
222
222
  _tmp = _state.sent();
@@ -238,7 +238,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
238
238
  case 6:
239
239
  operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
240
240
  try {
241
- mock = _this.options.adapter.getLatestMock(operationId);
241
+ mock = this.options.adapter.getLatestMock(operationId);
242
242
  if (!mock.getResponse) {
243
243
  return [
244
244
  2,
@@ -264,11 +264,8 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/
264
264
  ];
265
265
  }
266
266
  });
267
- });
268
- return function(fetchCall) {
269
- return _ref.apply(this, arguments);
270
- };
271
- }()
267
+ }).call(_this);
268
+ }
272
269
  };
273
270
  }
274
271
  }