@ama-sdk/client-fetch 11.3.0-prerelease.33

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 (157) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +33 -0
  3. package/cjs/api-fetch-client.js +581 -0
  4. package/cjs/fetch-plugin.js +4 -0
  5. package/cjs/plugins/abort/abort.fetch.js +84 -0
  6. package/cjs/plugins/abort/abort.spec.js +204 -0
  7. package/cjs/plugins/abort/index.js +18 -0
  8. package/cjs/plugins/concurrent/concurrent.fetch.js +263 -0
  9. package/cjs/plugins/concurrent/concurrent.spec.js +239 -0
  10. package/cjs/plugins/concurrent/index.js +18 -0
  11. package/cjs/plugins/index.js +25 -0
  12. package/cjs/plugins/keepalive/index.js +18 -0
  13. package/cjs/plugins/keepalive/keepalive.request.js +289 -0
  14. package/cjs/plugins/keepalive/keepalive.spec.js +162 -0
  15. package/cjs/plugins/mock-intercept/index.js +19 -0
  16. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +288 -0
  17. package/cjs/plugins/mock-intercept/mock-intercept.interface.js +4 -0
  18. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +445 -0
  19. package/cjs/plugins/perf-metric/index.js +18 -0
  20. package/cjs/plugins/perf-metric/perf-metric.fetch.js +371 -0
  21. package/cjs/plugins/perf-metric/perf-metric.probe.spec.js +60 -0
  22. package/cjs/plugins/retry/index.js +18 -0
  23. package/cjs/plugins/retry/retry.fetch.js +371 -0
  24. package/cjs/plugins/retry/retry.spec.js +348 -0
  25. package/cjs/plugins/timeout/index.js +18 -0
  26. package/cjs/plugins/timeout/timeout.fetch.js +320 -0
  27. package/cjs/plugins/timeout/timeout.spec.js +443 -0
  28. package/cjs/plugins/wait-for/index.js +18 -0
  29. package/cjs/plugins/wait-for/wait-for.fetch.js +350 -0
  30. package/cjs/plugins/wait-for/wait-for.spec.js +383 -0
  31. package/cjs/public_api.js +20 -0
  32. package/collection.json +11 -0
  33. package/esm2015/api-fetch-client.js +571 -0
  34. package/esm2015/fetch-plugin.js +4 -0
  35. package/esm2015/plugins/abort/abort.fetch.js +74 -0
  36. package/esm2015/plugins/abort/abort.spec.js +200 -0
  37. package/esm2015/plugins/abort/index.js +1 -0
  38. package/esm2015/plugins/concurrent/concurrent.fetch.js +255 -0
  39. package/esm2015/plugins/concurrent/concurrent.spec.js +235 -0
  40. package/esm2015/plugins/concurrent/index.js +1 -0
  41. package/esm2015/plugins/index.js +8 -0
  42. package/esm2015/plugins/keepalive/index.js +1 -0
  43. package/esm2015/plugins/keepalive/keepalive.request.js +281 -0
  44. package/esm2015/plugins/keepalive/keepalive.spec.js +158 -0
  45. package/esm2015/plugins/mock-intercept/index.js +2 -0
  46. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +283 -0
  47. package/esm2015/plugins/mock-intercept/mock-intercept.interface.js +1 -0
  48. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +441 -0
  49. package/esm2015/plugins/perf-metric/index.js +1 -0
  50. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +363 -0
  51. package/esm2015/plugins/perf-metric/perf-metric.probe.spec.js +56 -0
  52. package/esm2015/plugins/retry/index.js +1 -0
  53. package/esm2015/plugins/retry/retry.fetch.js +363 -0
  54. package/esm2015/plugins/retry/retry.spec.js +344 -0
  55. package/esm2015/plugins/timeout/index.js +1 -0
  56. package/esm2015/plugins/timeout/timeout.fetch.js +310 -0
  57. package/esm2015/plugins/timeout/timeout.spec.js +439 -0
  58. package/esm2015/plugins/wait-for/index.js +1 -0
  59. package/esm2015/plugins/wait-for/wait-for.fetch.js +379 -0
  60. package/esm2015/plugins/wait-for/wait-for.spec.js +379 -0
  61. package/esm2015/public_api.js +3 -0
  62. package/package.json +196 -0
  63. package/schematics/ng-add/index.d.ts +8 -0
  64. package/schematics/ng-add/index.d.ts.map +1 -0
  65. package/schematics/ng-add/index.js +67 -0
  66. package/schematics/ng-add/migration/import-map.d.ts +6 -0
  67. package/schematics/ng-add/migration/import-map.d.ts.map +1 -0
  68. package/schematics/ng-add/migration/import-map.js +39 -0
  69. package/schematics/ng-add/schema.d.ts +6 -0
  70. package/schematics/ng-add/schema.d.ts.map +1 -0
  71. package/schematics/ng-add/schema.js +3 -0
  72. package/schematics/ng-add/schema.json +18 -0
  73. package/schematics/package.json +3 -0
  74. package/src/api-fetch-client.d.ts +46 -0
  75. package/src/api-fetch-client.d.ts.map +1 -0
  76. package/src/api-fetch-client.js +126 -0
  77. package/src/api-fetch-client.js.map +1 -0
  78. package/src/fetch-plugin.d.ts +38 -0
  79. package/src/fetch-plugin.d.ts.map +1 -0
  80. package/src/fetch-plugin.js +2 -0
  81. package/src/fetch-plugin.js.map +1 -0
  82. package/src/plugins/abort/abort.fetch.d.ts +66 -0
  83. package/src/plugins/abort/abort.fetch.d.ts.map +1 -0
  84. package/src/plugins/abort/abort.fetch.js +32 -0
  85. package/src/plugins/abort/abort.fetch.js.map +1 -0
  86. package/src/plugins/abort/index.d.ts +2 -0
  87. package/src/plugins/abort/index.d.ts.map +1 -0
  88. package/src/plugins/abort/index.js +2 -0
  89. package/src/plugins/abort/index.js.map +1 -0
  90. package/src/plugins/concurrent/concurrent.fetch.d.ts +33 -0
  91. package/src/plugins/concurrent/concurrent.fetch.d.ts.map +1 -0
  92. package/src/plugins/concurrent/concurrent.fetch.js +57 -0
  93. package/src/plugins/concurrent/concurrent.fetch.js.map +1 -0
  94. package/src/plugins/concurrent/index.d.ts +2 -0
  95. package/src/plugins/concurrent/index.d.ts.map +1 -0
  96. package/src/plugins/concurrent/index.js +2 -0
  97. package/src/plugins/concurrent/index.js.map +1 -0
  98. package/src/plugins/index.d.ts +9 -0
  99. package/src/plugins/index.d.ts.map +1 -0
  100. package/src/plugins/index.js +9 -0
  101. package/src/plugins/index.js.map +1 -0
  102. package/src/plugins/keepalive/index.d.ts +2 -0
  103. package/src/plugins/keepalive/index.d.ts.map +1 -0
  104. package/src/plugins/keepalive/index.js +2 -0
  105. package/src/plugins/keepalive/index.js.map +1 -0
  106. package/src/plugins/keepalive/keepalive.request.d.ts +18 -0
  107. package/src/plugins/keepalive/keepalive.request.d.ts.map +1 -0
  108. package/src/plugins/keepalive/keepalive.request.js +39 -0
  109. package/src/plugins/keepalive/keepalive.request.js.map +1 -0
  110. package/src/plugins/mock-intercept/index.d.ts +3 -0
  111. package/src/plugins/mock-intercept/index.d.ts.map +1 -0
  112. package/src/plugins/mock-intercept/index.js +3 -0
  113. package/src/plugins/mock-intercept/index.js.map +1 -0
  114. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts +15 -0
  115. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts.map +1 -0
  116. package/src/plugins/mock-intercept/mock-intercept.fetch.js +47 -0
  117. package/src/plugins/mock-intercept/mock-intercept.fetch.js.map +1 -0
  118. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts +10 -0
  119. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts.map +1 -0
  120. package/src/plugins/mock-intercept/mock-intercept.interface.js +2 -0
  121. package/src/plugins/mock-intercept/mock-intercept.interface.js.map +1 -0
  122. package/src/plugins/perf-metric/index.d.ts +2 -0
  123. package/src/plugins/perf-metric/index.d.ts.map +1 -0
  124. package/src/plugins/perf-metric/index.js +2 -0
  125. package/src/plugins/perf-metric/index.js.map +1 -0
  126. package/src/plugins/perf-metric/perf-metric.fetch.d.ts +133 -0
  127. package/src/plugins/perf-metric/perf-metric.fetch.d.ts.map +1 -0
  128. package/src/plugins/perf-metric/perf-metric.fetch.js +111 -0
  129. package/src/plugins/perf-metric/perf-metric.fetch.js.map +1 -0
  130. package/src/plugins/retry/index.d.ts +2 -0
  131. package/src/plugins/retry/index.d.ts.map +1 -0
  132. package/src/plugins/retry/index.js +2 -0
  133. package/src/plugins/retry/index.js.map +1 -0
  134. package/src/plugins/retry/retry.fetch.d.ts +53 -0
  135. package/src/plugins/retry/retry.fetch.d.ts.map +1 -0
  136. package/src/plugins/retry/retry.fetch.js +66 -0
  137. package/src/plugins/retry/retry.fetch.js.map +1 -0
  138. package/src/plugins/timeout/index.d.ts +2 -0
  139. package/src/plugins/timeout/index.d.ts.map +1 -0
  140. package/src/plugins/timeout/index.js +2 -0
  141. package/src/plugins/timeout/index.js.map +1 -0
  142. package/src/plugins/timeout/timeout.fetch.d.ts +47 -0
  143. package/src/plugins/timeout/timeout.fetch.d.ts.map +1 -0
  144. package/src/plugins/timeout/timeout.fetch.js +105 -0
  145. package/src/plugins/timeout/timeout.fetch.js.map +1 -0
  146. package/src/plugins/wait-for/index.d.ts +2 -0
  147. package/src/plugins/wait-for/index.d.ts.map +1 -0
  148. package/src/plugins/wait-for/index.js +2 -0
  149. package/src/plugins/wait-for/index.js.map +1 -0
  150. package/src/plugins/wait-for/wait-for.fetch.d.ts +78 -0
  151. package/src/plugins/wait-for/wait-for.fetch.d.ts.map +1 -0
  152. package/src/plugins/wait-for/wait-for.fetch.js +104 -0
  153. package/src/plugins/wait-for/wait-for.fetch.js.map +1 -0
  154. package/src/public_api.d.ts +4 -0
  155. package/src/public_api.d.ts.map +1 -0
  156. package/src/public_api.js +4 -0
  157. package/src/public_api.js.map +1 -0
@@ -0,0 +1,283 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _class_call_check(instance, Constructor) {
31
+ if (!(instance instanceof Constructor)) {
32
+ throw new TypeError("Cannot call a class as a function");
33
+ }
34
+ }
35
+ function _defineProperties(target, props) {
36
+ for(var i = 0; i < props.length; i++){
37
+ var descriptor = props[i];
38
+ descriptor.enumerable = descriptor.enumerable || false;
39
+ descriptor.configurable = true;
40
+ if ("value" in descriptor) descriptor.writable = true;
41
+ Object.defineProperty(target, descriptor.key, descriptor);
42
+ }
43
+ }
44
+ function _create_class(Constructor, protoProps, staticProps) {
45
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
46
+ if (staticProps) _defineProperties(Constructor, staticProps);
47
+ return Constructor;
48
+ }
49
+ function _define_property(obj, key, value) {
50
+ if (key in obj) {
51
+ Object.defineProperty(obj, key, {
52
+ value: value,
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true
56
+ });
57
+ } else {
58
+ obj[key] = value;
59
+ }
60
+ return obj;
61
+ }
62
+ function _instanceof(left, right) {
63
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
64
+ return !!right[Symbol.hasInstance](left);
65
+ } else {
66
+ return left instanceof right;
67
+ }
68
+ }
69
+ function _ts_generator(thisArg, body) {
70
+ var f, y, t, g, _ = {
71
+ label: 0,
72
+ sent: function() {
73
+ if (t[0] & 1) throw t[1];
74
+ return t[1];
75
+ },
76
+ trys: [],
77
+ ops: []
78
+ };
79
+ return g = {
80
+ next: verb(0),
81
+ "throw": verb(1),
82
+ "return": verb(2)
83
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
84
+ return this;
85
+ }), g;
86
+ function verb(n) {
87
+ return function(v) {
88
+ return step([
89
+ n,
90
+ v
91
+ ]);
92
+ };
93
+ }
94
+ function step(op) {
95
+ if (f) throw new TypeError("Generator is already executing.");
96
+ while(_)try {
97
+ 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;
98
+ if (y = 0, t) op = [
99
+ op[0] & 2,
100
+ t.value
101
+ ];
102
+ switch(op[0]){
103
+ case 0:
104
+ case 1:
105
+ t = op;
106
+ break;
107
+ case 4:
108
+ _.label++;
109
+ return {
110
+ value: op[1],
111
+ done: false
112
+ };
113
+ case 5:
114
+ _.label++;
115
+ y = op[1];
116
+ op = [
117
+ 0
118
+ ];
119
+ continue;
120
+ case 7:
121
+ op = _.ops.pop();
122
+ _.trys.pop();
123
+ continue;
124
+ default:
125
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
126
+ _ = 0;
127
+ continue;
128
+ }
129
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
130
+ _.label = op[1];
131
+ break;
132
+ }
133
+ if (op[0] === 6 && _.label < t[1]) {
134
+ _.label = t[1];
135
+ t = op;
136
+ break;
137
+ }
138
+ if (t && _.label < t[2]) {
139
+ _.label = t[2];
140
+ _.ops.push(op);
141
+ break;
142
+ }
143
+ if (t[2]) _.ops.pop();
144
+ _.trys.pop();
145
+ continue;
146
+ }
147
+ op = body.call(thisArg, _);
148
+ } catch (e) {
149
+ op = [
150
+ 6,
151
+ e
152
+ ];
153
+ y = 0;
154
+ } finally{
155
+ f = t = 0;
156
+ }
157
+ if (op[0] & 5) throw op[1];
158
+ return {
159
+ value: op[0] ? op[1] : void 0,
160
+ done: true
161
+ };
162
+ }
163
+ }
164
+ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/core';
165
+ /**
166
+ * Plugin to mock and intercept the fetch of SDK
167
+ *
168
+ * This plugin should be used only with the MockInterceptRequest Plugin.
169
+ * It will allow the user to delay the response or to handle the getResponse function provided with the mock (if present).
170
+ */ export var MockInterceptFetch = /*#__PURE__*/ function() {
171
+ "use strict";
172
+ function MockInterceptFetch(options) {
173
+ _class_call_check(this, MockInterceptFetch);
174
+ _define_property(this, "options", void 0);
175
+ this.options = options;
176
+ }
177
+ _create_class(MockInterceptFetch, [
178
+ {
179
+ key: "load",
180
+ value: function load(context) {
181
+ if (!context.apiClient.options.requestPlugins.some(function(plugin) {
182
+ return _instanceof(plugin, MockInterceptRequest);
183
+ })) {
184
+ throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
185
+ }
186
+ var _this = this;
187
+ return {
188
+ transform: function() {
189
+ var _ref = _async_to_generator(function(fetchCall) {
190
+ var responsePromise, delay, _tmp, resp, operationId, mock, response;
191
+ return _ts_generator(this, function(_state) {
192
+ switch(_state.label){
193
+ case 0:
194
+ return [
195
+ 4,
196
+ _this.options.adapter.initialize()
197
+ ];
198
+ case 1:
199
+ _state.sent();
200
+ responsePromise = fetchCall;
201
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
202
+ if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
203
+ return [
204
+ 2,
205
+ responsePromise
206
+ ];
207
+ }
208
+ if (!(typeof _this.options.delayTiming !== 'undefined')) return [
209
+ 3,
210
+ 6
211
+ ];
212
+ if (!(typeof _this.options.delayTiming === 'number')) return [
213
+ 3,
214
+ 2
215
+ ];
216
+ _tmp = _this.options.delayTiming;
217
+ return [
218
+ 3,
219
+ 4
220
+ ];
221
+ case 2:
222
+ return [
223
+ 4,
224
+ _this.options.delayTiming(context)
225
+ ];
226
+ case 3:
227
+ _tmp = _state.sent();
228
+ _state.label = 4;
229
+ case 4:
230
+ delay = _tmp;
231
+ return [
232
+ 4,
233
+ responsePromise
234
+ ];
235
+ case 5:
236
+ resp = _state.sent();
237
+ responsePromise = new Promise(function(resolve) {
238
+ return setTimeout(resolve, delay);
239
+ }).then(function() {
240
+ return resp;
241
+ });
242
+ _state.label = 6;
243
+ case 6:
244
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
245
+ operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
246
+ try {
247
+ mock = _this.options.adapter.getLatestMock(operationId);
248
+ if (!mock.getResponse) {
249
+ return [
250
+ 2,
251
+ responsePromise
252
+ ];
253
+ }
254
+ response = mock.getResponse();
255
+ return [
256
+ 2,
257
+ responsePromise.then(function() {
258
+ return response;
259
+ })
260
+ ];
261
+ } catch (e) {
262
+ (context.logger || console).error("Failed to retrieve the latest mock for Operation ID ".concat(operationId, ", fallback to default mock"));
263
+ return [
264
+ 2,
265
+ responsePromise
266
+ ];
267
+ }
268
+ return [
269
+ 2
270
+ ];
271
+ }
272
+ });
273
+ });
274
+ return function(fetchCall) {
275
+ return _ref.apply(this, arguments);
276
+ };
277
+ }()
278
+ };
279
+ }
280
+ }
281
+ ]);
282
+ return MockInterceptFetch;
283
+ }();
@@ -0,0 +1 @@
1
+ /** Mock Fetch Plugin options */ export { };