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