@ama-sdk/client-fetch 12.3.0-prerelease.9 → 12.4.0-prerelease.0

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 (37) hide show
  1. package/cjs/api-fetch-client.js +18 -22
  2. package/cjs/plugins/abort/abort.spec.js +83 -81
  3. package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
  4. package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
  5. package/cjs/plugins/keepalive/keepalive.request.js +7 -12
  6. package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
  7. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  8. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +247 -239
  9. package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
  10. package/cjs/plugins/retry/retry.fetch.js +18 -27
  11. package/cjs/plugins/retry/retry.spec.js +233 -225
  12. package/cjs/plugins/timeout/timeout.fetch.js +13 -19
  13. package/cjs/plugins/timeout/timeout.spec.js +211 -205
  14. package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
  15. package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
  16. package/esm2015/api-fetch-client.js +18 -22
  17. package/esm2015/plugins/abort/abort.spec.js +83 -81
  18. package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
  19. package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
  20. package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
  21. package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
  22. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  23. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +247 -239
  24. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
  25. package/esm2015/plugins/retry/retry.fetch.js +18 -27
  26. package/esm2015/plugins/retry/retry.spec.js +233 -225
  27. package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
  28. package/esm2015/plugins/timeout/timeout.spec.js +211 -205
  29. package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
  30. package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
  31. package/package.json +15 -15
  32. package/schematics/ng-add/index.d.ts.map +1 -1
  33. package/schematics/ng-add/index.js +11 -21
  34. package/src/api-fetch-client.d.ts +1 -1
  35. package/src/api-fetch-client.d.ts.map +1 -1
  36. package/src/api-fetch-client.js +2 -1
  37. package/src/api-fetch-client.js.map +1 -1
@@ -41,7 +41,7 @@ function _define_property(obj, key, value) {
41
41
  return obj;
42
42
  }
43
43
  function _ts_generator(thisArg, body) {
44
- var f, y, t, g, _ = {
44
+ var f, y, t, _ = {
45
45
  label: 0,
46
46
  sent: function() {
47
47
  if (t[0] & 1) throw t[1];
@@ -49,12 +49,8 @@ function _ts_generator(thisArg, body) {
49
49
  },
50
50
  trys: [],
51
51
  ops: []
52
- };
53
- return g = {
54
- next: verb(0),
55
- "throw": verb(1),
56
- "return": verb(2)
57
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
52
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
53
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
58
54
  return this;
59
55
  }), g;
60
56
  function verb(n) {
@@ -67,7 +63,7 @@ function _ts_generator(thisArg, body) {
67
63
  }
68
64
  function step(op) {
69
65
  if (f) throw new TypeError("Generator is already executing.");
70
- while(_)try {
66
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
71
67
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
72
68
  if (y = 0, t) op = [
73
69
  op[0] & 2,
@@ -167,113 +163,119 @@ describe('Mock intercept', function() {
167
163
  return jest.clearAllMocks();
168
164
  });
169
165
  describe('request plugin', function() {
170
- it('should do nothing if disabled is true', /*#__PURE__*/ _async_to_generator(function() {
171
- var plugin, originalRequest, loaded;
172
- return _ts_generator(this, function(_state) {
173
- switch(_state.label){
174
- case 0:
175
- plugin = new MockInterceptRequest({
176
- disabled: true,
177
- adapter: testMockAdapter
178
- });
179
- originalRequest = {
180
- method: 'get',
181
- headers: new Headers({
182
- test: 'true'
183
- }),
184
- basePath: 'myurl'
185
- };
186
- loaded = plugin.load();
187
- return [
188
- 4,
189
- loaded.transform(originalRequest)
190
- ];
191
- case 1:
192
- expect.apply(void 0, [
193
- _state.sent()
194
- ]).toEqual(originalRequest);
195
- expect(initializeSpy).toHaveBeenCalled();
196
- return [
197
- 2
198
- ];
199
- }
200
- });
201
- }));
202
- it('should not stringify provided api', /*#__PURE__*/ _async_to_generator(function() {
203
- var plugin, loaded, originalRequest;
204
- return _ts_generator(this, function(_state) {
205
- switch(_state.label){
206
- case 0:
207
- plugin = new MockInterceptRequest({
208
- disabled: false,
209
- adapter: testMockAdapter
210
- });
211
- loaded = plugin.load();
212
- originalRequest = {
213
- method: 'get',
214
- headers: new Headers({
215
- test: 'true'
216
- }),
217
- basePath: 'myurl',
218
- api: 'should not exist'
219
- };
220
- return [
221
- 4,
222
- loaded.transform(originalRequest)
223
- ];
224
- case 1:
225
- _state.sent();
226
- expect(originalRequest.headers.has(CUSTOM_MOCK_REQUEST_HEADER)).toBe(true);
227
- expect(Object.keys(JSON.parse(originalRequest.headers.get(CUSTOM_MOCK_REQUEST_HEADER)))).not.toContainEqual('api');
228
- return [
229
- 2
230
- ];
231
- }
232
- });
233
- }));
234
- it('should intercept the request', /*#__PURE__*/ _async_to_generator(function() {
235
- var plugin, originalRequest, loaded, transformed, res;
236
- return _ts_generator(this, function(_state) {
237
- switch(_state.label){
238
- case 0:
239
- // Disabled because Blob URL is not supported on NodeJS
240
- plugin = new MockInterceptRequest({
241
- adapter: testMockAdapter
242
- });
243
- originalRequest = {
244
- headers: new Headers({
245
- test: 'true'
246
- }),
247
- basePath: 'myurl',
248
- method: 'PATCH'
249
- };
250
- loaded = plugin.load();
251
- return [
252
- 4,
253
- loaded.transform(originalRequest)
254
- ];
255
- case 1:
256
- transformed = _state.sent();
257
- return [
258
- 4,
259
- fetch(transformed.basePath, transformed)
260
- ];
261
- case 2:
262
- return [
263
- 4,
264
- _state.sent().text()
265
- ];
266
- case 3:
267
- res = _state.sent();
268
- expect(getMockSpy).toHaveBeenCalled();
269
- expect(res).toBe(JSON.stringify(testMock.mockData));
270
- expect(initializeSpy).toHaveBeenCalled();
271
- return [
272
- 2
273
- ];
274
- }
275
- });
276
- }));
166
+ it('should do nothing if disabled is true', function() {
167
+ return _async_to_generator(function() {
168
+ var plugin, originalRequest, loaded;
169
+ return _ts_generator(this, function(_state) {
170
+ switch(_state.label){
171
+ case 0:
172
+ plugin = new MockInterceptRequest({
173
+ disabled: true,
174
+ adapter: testMockAdapter
175
+ });
176
+ originalRequest = {
177
+ method: 'get',
178
+ headers: new Headers({
179
+ test: 'true'
180
+ }),
181
+ basePath: 'myurl'
182
+ };
183
+ loaded = plugin.load();
184
+ return [
185
+ 4,
186
+ loaded.transform(originalRequest)
187
+ ];
188
+ case 1:
189
+ expect.apply(void 0, [
190
+ _state.sent()
191
+ ]).toEqual(originalRequest);
192
+ expect(initializeSpy).toHaveBeenCalled();
193
+ return [
194
+ 2
195
+ ];
196
+ }
197
+ });
198
+ })();
199
+ });
200
+ it('should not stringify provided api', function() {
201
+ return _async_to_generator(function() {
202
+ var plugin, loaded, originalRequest;
203
+ return _ts_generator(this, function(_state) {
204
+ switch(_state.label){
205
+ case 0:
206
+ plugin = new MockInterceptRequest({
207
+ disabled: false,
208
+ adapter: testMockAdapter
209
+ });
210
+ loaded = plugin.load();
211
+ originalRequest = {
212
+ method: 'get',
213
+ headers: new Headers({
214
+ test: 'true'
215
+ }),
216
+ basePath: 'myurl',
217
+ api: 'should not exist'
218
+ };
219
+ return [
220
+ 4,
221
+ loaded.transform(originalRequest)
222
+ ];
223
+ case 1:
224
+ _state.sent();
225
+ expect(originalRequest.headers.has(CUSTOM_MOCK_REQUEST_HEADER)).toBe(true);
226
+ expect(Object.keys(JSON.parse(originalRequest.headers.get(CUSTOM_MOCK_REQUEST_HEADER)))).not.toContainEqual('api');
227
+ return [
228
+ 2
229
+ ];
230
+ }
231
+ });
232
+ })();
233
+ });
234
+ it('should intercept the request', function() {
235
+ return _async_to_generator(function() {
236
+ var plugin, originalRequest, loaded, transformed, res;
237
+ return _ts_generator(this, function(_state) {
238
+ switch(_state.label){
239
+ case 0:
240
+ // Disabled because Blob URL is not supported on NodeJS
241
+ plugin = new MockInterceptRequest({
242
+ adapter: testMockAdapter
243
+ });
244
+ originalRequest = {
245
+ headers: new Headers({
246
+ test: 'true'
247
+ }),
248
+ basePath: 'myurl',
249
+ method: 'PATCH'
250
+ };
251
+ loaded = plugin.load();
252
+ return [
253
+ 4,
254
+ loaded.transform(originalRequest)
255
+ ];
256
+ case 1:
257
+ transformed = _state.sent();
258
+ return [
259
+ 4,
260
+ fetch(transformed.basePath, transformed)
261
+ ];
262
+ case 2:
263
+ return [
264
+ 4,
265
+ _state.sent().text()
266
+ ];
267
+ case 3:
268
+ res = _state.sent();
269
+ expect(getMockSpy).toHaveBeenCalled();
270
+ expect(res).toBe(JSON.stringify(testMock.mockData));
271
+ expect(initializeSpy).toHaveBeenCalled();
272
+ return [
273
+ 2
274
+ ];
275
+ }
276
+ });
277
+ })();
278
+ });
277
279
  });
278
280
  describe('fetch plugin', function() {
279
281
  describe('when using an initialization function', function() {
@@ -290,152 +292,158 @@ describe('Mock intercept', function() {
290
292
  adapter: asyncMockAdapter
291
293
  });
292
294
  });
293
- it('should call initialize fn', /*#__PURE__*/ _async_to_generator(function() {
294
- var loadedPlugin, testData;
295
+ it('should call initialize fn', function() {
296
+ return _async_to_generator(function() {
297
+ var loadedPlugin, testData;
298
+ return _ts_generator(this, function(_state) {
299
+ switch(_state.label){
300
+ case 0:
301
+ loadedPlugin = plugin.load({
302
+ controller: jest.fn(),
303
+ fetchPlugins: [],
304
+ url: 'myurl',
305
+ apiClient: apiClient,
306
+ options: {
307
+ headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
308
+ }
309
+ });
310
+ testData = {
311
+ test: true
312
+ };
313
+ return [
314
+ 4,
315
+ loadedPlugin.transform(Promise.resolve(testData))
316
+ ];
317
+ case 1:
318
+ _state.sent();
319
+ expect(initializeSpy).toHaveBeenCalled();
320
+ expect(getMockSpy).not.toHaveBeenCalled();
321
+ expect(getLatestMockSpy).toHaveBeenCalledWith('testOperation');
322
+ return [
323
+ 2
324
+ ];
325
+ }
326
+ });
327
+ })();
328
+ });
329
+ it('should throw if there is no request plugin', function() {
330
+ var config = {
331
+ controller: jest.fn(),
332
+ fetchPlugins: [],
333
+ url: 'myurl',
334
+ apiClient: {
335
+ options: {
336
+ requestPlugins: []
337
+ }
338
+ },
339
+ options: {
340
+ headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
341
+ }
342
+ };
343
+ expect(function() {
344
+ return plugin.load(config);
345
+ }).toThrow();
346
+ });
347
+ });
348
+ });
349
+ describe('with delay', function() {
350
+ it('should delay the response of the specific number', function() {
351
+ return _async_to_generator(function() {
352
+ var plugin, loadedPlugin, callback, run;
295
353
  return _ts_generator(this, function(_state) {
296
354
  switch(_state.label){
297
355
  case 0:
356
+ plugin = new MockInterceptFetch({
357
+ adapter: testMockAdapter,
358
+ delayTiming: 700
359
+ });
298
360
  loadedPlugin = plugin.load({
299
361
  controller: jest.fn(),
300
362
  fetchPlugins: [],
301
- url: 'myurl',
363
+ url: '',
302
364
  apiClient: apiClient,
303
365
  options: {
304
366
  headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
305
367
  }
306
368
  });
307
- testData = {
308
- test: true
309
- };
369
+ callback = jest.fn();
370
+ run = loadedPlugin.transform(Promise.resolve({})).then(callback);
310
371
  return [
311
372
  4,
312
- loadedPlugin.transform(Promise.resolve(testData))
373
+ jest.advanceTimersByTimeAsync(699)
313
374
  ];
314
375
  case 1:
315
376
  _state.sent();
316
- expect(initializeSpy).toHaveBeenCalled();
317
- expect(getMockSpy).not.toHaveBeenCalled();
318
- expect(getLatestMockSpy).toHaveBeenCalledWith('testOperation');
377
+ expect(callback).not.toHaveBeenCalled();
378
+ return [
379
+ 4,
380
+ jest.advanceTimersByTimeAsync(1)
381
+ ];
382
+ case 2:
383
+ _state.sent();
384
+ expect(callback).toHaveBeenCalled();
385
+ return [
386
+ 4,
387
+ run
388
+ ];
389
+ case 3:
390
+ _state.sent();
319
391
  return [
320
392
  2
321
393
  ];
322
394
  }
323
395
  });
324
- }));
325
- it('should throw if there is no request plugin', function() {
326
- var config = {
327
- controller: jest.fn(),
328
- fetchPlugins: [],
329
- url: 'myurl',
330
- apiClient: {
331
- options: {
332
- requestPlugins: []
333
- }
334
- },
335
- options: {
336
- headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
396
+ })();
397
+ });
398
+ it('should delay the response based on callback', function() {
399
+ return _async_to_generator(function() {
400
+ var plugin, loadedPlugin, callback, run;
401
+ return _ts_generator(this, function(_state) {
402
+ switch(_state.label){
403
+ case 0:
404
+ plugin = new MockInterceptFetch({
405
+ adapter: testMockAdapter,
406
+ delayTiming: function() {
407
+ return 800;
408
+ }
409
+ });
410
+ loadedPlugin = plugin.load({
411
+ controller: jest.fn(),
412
+ fetchPlugins: [],
413
+ url: '',
414
+ apiClient: apiClient,
415
+ options: {
416
+ headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
417
+ }
418
+ });
419
+ callback = jest.fn();
420
+ run = loadedPlugin.transform(Promise.resolve({})).then(callback);
421
+ return [
422
+ 4,
423
+ jest.advanceTimersByTimeAsync(799)
424
+ ];
425
+ case 1:
426
+ _state.sent();
427
+ expect(callback).not.toHaveBeenCalled();
428
+ return [
429
+ 4,
430
+ jest.advanceTimersByTimeAsync(1)
431
+ ];
432
+ case 2:
433
+ _state.sent();
434
+ expect(callback).toHaveBeenCalled();
435
+ return [
436
+ 4,
437
+ run
438
+ ];
439
+ case 3:
440
+ _state.sent();
441
+ return [
442
+ 2
443
+ ];
337
444
  }
338
- };
339
- expect(function() {
340
- return plugin.load(config);
341
- }).toThrow();
342
- });
445
+ });
446
+ })();
343
447
  });
344
448
  });
345
- describe('with delay', function() {
346
- it('should delay the response of the specific number', /*#__PURE__*/ _async_to_generator(function() {
347
- var plugin, loadedPlugin, callback, run;
348
- return _ts_generator(this, function(_state) {
349
- switch(_state.label){
350
- case 0:
351
- plugin = new MockInterceptFetch({
352
- adapter: testMockAdapter,
353
- delayTiming: 700
354
- });
355
- loadedPlugin = plugin.load({
356
- controller: jest.fn(),
357
- fetchPlugins: [],
358
- url: '',
359
- apiClient: apiClient,
360
- options: {
361
- headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
362
- }
363
- });
364
- callback = jest.fn();
365
- run = loadedPlugin.transform(Promise.resolve({})).then(callback);
366
- return [
367
- 4,
368
- jest.advanceTimersByTimeAsync(699)
369
- ];
370
- case 1:
371
- _state.sent();
372
- expect(callback).not.toHaveBeenCalled();
373
- return [
374
- 4,
375
- jest.advanceTimersByTimeAsync(1)
376
- ];
377
- case 2:
378
- _state.sent();
379
- expect(callback).toHaveBeenCalled();
380
- return [
381
- 4,
382
- run
383
- ];
384
- case 3:
385
- _state.sent();
386
- return [
387
- 2
388
- ];
389
- }
390
- });
391
- }));
392
- it('should delay the response based on callback', /*#__PURE__*/ _async_to_generator(function() {
393
- var plugin, loadedPlugin, callback, run;
394
- return _ts_generator(this, function(_state) {
395
- switch(_state.label){
396
- case 0:
397
- plugin = new MockInterceptFetch({
398
- adapter: testMockAdapter,
399
- delayTiming: function() {
400
- return 800;
401
- }
402
- });
403
- loadedPlugin = plugin.load({
404
- controller: jest.fn(),
405
- fetchPlugins: [],
406
- url: '',
407
- apiClient: apiClient,
408
- options: {
409
- headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
410
- }
411
- });
412
- callback = jest.fn();
413
- run = loadedPlugin.transform(Promise.resolve({})).then(callback);
414
- return [
415
- 4,
416
- jest.advanceTimersByTimeAsync(799)
417
- ];
418
- case 1:
419
- _state.sent();
420
- expect(callback).not.toHaveBeenCalled();
421
- return [
422
- 4,
423
- jest.advanceTimersByTimeAsync(1)
424
- ];
425
- case 2:
426
- _state.sent();
427
- expect(callback).toHaveBeenCalled();
428
- return [
429
- 4,
430
- run
431
- ];
432
- case 3:
433
- _state.sent();
434
- return [
435
- 2
436
- ];
437
- }
438
- });
439
- }));
440
- });
441
449
  });
@@ -99,7 +99,7 @@ function _object_spread_props(target, source) {
99
99
  return target;
100
100
  }
101
101
  function _ts_generator(thisArg, body) {
102
- var f, y, t, g, _ = {
102
+ var f, y, t, _ = {
103
103
  label: 0,
104
104
  sent: function() {
105
105
  if (t[0] & 1) throw t[1];
@@ -107,12 +107,8 @@ function _ts_generator(thisArg, body) {
107
107
  },
108
108
  trys: [],
109
109
  ops: []
110
- };
111
- return g = {
112
- next: verb(0),
113
- "throw": verb(1),
114
- "return": verb(2)
115
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
110
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
111
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
116
112
  return this;
117
113
  }), g;
118
114
  function verb(n) {
@@ -125,7 +121,7 @@ function _ts_generator(thisArg, body) {
125
121
  }
126
122
  function step(op) {
127
123
  if (f) throw new TypeError("Generator is already executing.");
128
- while(_)try {
124
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
129
125
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
130
126
  if (y = 0, t) op = [
131
127
  op[0] & 2,
@@ -314,13 +310,13 @@ import { v4 } from 'uuid';
314
310
  value: /** @inheritDoc */ function load(context) {
315
311
  var _this = this;
316
312
  return {
317
- transform: /*#__PURE__*/ function() {
318
- var _ref = _async_to_generator(function(fetchCall) {
313
+ transform: function(fetchCall) {
314
+ return _async_to_generator(function() {
319
315
  var markId, response, exception;
320
316
  return _ts_generator(this, function(_state) {
321
317
  switch(_state.label){
322
318
  case 0:
323
- markId = _this.openMark(context.url, context.options);
319
+ markId = this.openMark(context.url, context.options);
324
320
  _state.label = 1;
325
321
  case 1:
326
322
  _state.trys.push([
@@ -335,14 +331,14 @@ import { v4 } from 'uuid';
335
331
  ];
336
332
  case 2:
337
333
  response = _state.sent();
338
- _this.closeMark(markId, response);
334
+ this.closeMark(markId, response);
339
335
  return [
340
336
  2,
341
337
  response
342
338
  ];
343
339
  case 3:
344
340
  exception = _state.sent();
345
- _this.closeMarkWithError(markId, exception);
341
+ this.closeMarkWithError(markId, exception);
346
342
  throw exception;
347
343
  case 4:
348
344
  return [
@@ -350,11 +346,8 @@ import { v4 } from 'uuid';
350
346
  ];
351
347
  }
352
348
  });
353
- });
354
- return function(fetchCall) {
355
- return _ref.apply(this, arguments);
356
- };
357
- }()
349
+ }).call(_this);
350
+ }
358
351
  };
359
352
  }
360
353
  }