@ama-sdk/core 11.3.0-prerelease.2 → 11.3.0-prerelease.21

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 (42) hide show
  1. package/cjs/clients/api-angular-client.js +63 -3
  2. package/cjs/clients/api-fetch-client.js +2 -1
  3. package/cjs/fwk/date.js +12 -33
  4. package/cjs/fwk/errors.js +39 -43
  5. package/cjs/fwk/mocks/random-mock-adapter.js +10 -24
  6. package/cjs/fwk/mocks/sequential-mock-adapter.js +10 -24
  7. package/cjs/plugins/core/angular-plugin.js +4 -0
  8. package/cjs/plugins/mock-intercept/index.js +1 -0
  9. package/cjs/plugins/mock-intercept/mock-intercept.angular.js +347 -0
  10. package/cjs/plugins/si-token/si-token.request.js +21 -34
  11. package/esm2015/clients/api-angular-client.js +63 -3
  12. package/esm2015/clients/api-fetch-client.js +2 -1
  13. package/esm2015/fwk/date.js +12 -33
  14. package/esm2015/fwk/errors.js +39 -43
  15. package/esm2015/fwk/mocks/random-mock-adapter.js +10 -24
  16. package/esm2015/fwk/mocks/sequential-mock-adapter.js +10 -24
  17. package/esm2015/plugins/core/angular-plugin.js +4 -0
  18. package/esm2015/plugins/mock-intercept/index.js +1 -0
  19. package/esm2015/plugins/mock-intercept/mock-intercept.angular.js +342 -0
  20. package/esm2015/plugins/si-token/si-token.request.js +21 -34
  21. package/package.json +16 -5
  22. package/src/clients/api-angular-client.d.ts +4 -0
  23. package/src/clients/api-angular-client.d.ts.map +1 -1
  24. package/src/clients/api-angular-client.js +18 -3
  25. package/src/clients/api-angular-client.js.map +1 -1
  26. package/src/clients/api-fetch-client.d.ts.map +1 -1
  27. package/src/clients/api-fetch-client.js +9 -1
  28. package/src/clients/api-fetch-client.js.map +1 -1
  29. package/src/plugins/core/angular-plugin.d.ts +40 -0
  30. package/src/plugins/core/angular-plugin.d.ts.map +1 -0
  31. package/src/plugins/core/angular-plugin.js +2 -0
  32. package/src/plugins/core/angular-plugin.js.map +1 -0
  33. package/src/plugins/core/fetch-plugin.d.ts +1 -0
  34. package/src/plugins/core/fetch-plugin.d.ts.map +1 -1
  35. package/src/plugins/mock-intercept/index.d.ts +1 -0
  36. package/src/plugins/mock-intercept/index.d.ts.map +1 -1
  37. package/src/plugins/mock-intercept/index.js +1 -0
  38. package/src/plugins/mock-intercept/index.js.map +1 -1
  39. package/src/plugins/mock-intercept/mock-intercept.angular.d.ts +15 -0
  40. package/src/plugins/mock-intercept/mock-intercept.angular.d.ts.map +1 -0
  41. package/src/plugins/mock-intercept/mock-intercept.angular.js +63 -0
  42. package/src/plugins/mock-intercept/mock-intercept.angular.js.map +1 -0
@@ -6,6 +6,10 @@
6
6
  }
7
7
  return self;
8
8
  }
9
+ function _call_super(_this, derived, args) {
10
+ derived = _get_prototype_of(derived);
11
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
12
+ }
9
13
  function _class_call_check(instance, Constructor) {
10
14
  if (!(instance instanceof Constructor)) {
11
15
  throw new TypeError("Cannot call a class as a function");
@@ -107,41 +111,26 @@ function _wrap_native_super(Class) {
107
111
  return _wrap_native_super(Class);
108
112
  }
109
113
  function _is_native_reflect_construct() {
110
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
111
- if (Reflect.construct.sham) return false;
112
- if (typeof Proxy === "function") return true;
113
114
  try {
114
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
115
- return true;
116
- } catch (e) {
117
- return false;
118
- }
119
- }
120
- function _create_super(Derived) {
121
- var hasNativeReflectConstruct = _is_native_reflect_construct();
122
- return function _createSuperInternal() {
123
- var Super = _get_prototype_of(Derived), result;
124
- if (hasNativeReflectConstruct) {
125
- var NewTarget = _get_prototype_of(this).constructor;
126
- result = Reflect.construct(Super, arguments, NewTarget);
127
- } else {
128
- result = Super.apply(this, arguments);
129
- }
130
- return _possible_constructor_return(this, result);
131
- };
115
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
116
+ } catch (_) {}
117
+ return (_is_native_reflect_construct = function() {
118
+ return !!result;
119
+ })();
132
120
  }
133
121
  /**
134
122
  * Generic error class
135
123
  */ export var GenericError = /*#__PURE__*/ function(Error1) {
136
124
  "use strict";
137
125
  _inherits(GenericError, Error1);
138
- var _super = _create_super(GenericError);
139
126
  function GenericError(message, context) {
140
127
  _class_call_check(this, GenericError);
141
128
  var httpRegexp = /^https?:\/\//;
142
129
  var baseUrl = (context === null || context === void 0 ? void 0 : context.url) ? context.url.replace(httpRegexp, '') : 'unknown';
143
130
  var origin = (context === null || context === void 0 ? void 0 : context.origin) ? context.origin.replace(httpRegexp, '') : 'unknown';
144
- return _super.call(this, context ? "[SDK] [apiName: ".concat(context.apiName || 'unknown', "] [operationId: ").concat(context.operationId || 'unknown', "] [baseUrl: ").concat(baseUrl, "] [origin: ").concat(origin, "] [errorType: SDK] ").concat(message) : "[SDK] ".concat(message));
131
+ return _call_super(this, GenericError, [
132
+ context ? "[SDK] [apiName: ".concat(context.apiName || 'unknown', "] [operationId: ").concat(context.operationId || 'unknown', "] [baseUrl: ").concat(baseUrl, "] [origin: ").concat(origin, "] [errorType: SDK] ").concat(message) : "[SDK] ".concat(message)
133
+ ]);
145
134
  }
146
135
  return GenericError;
147
136
  }(_wrap_native_super(Error));
@@ -150,17 +139,17 @@ function _create_super(Derived) {
150
139
  */ export var RequestFailedError = /*#__PURE__*/ function(GenericError) {
151
140
  "use strict";
152
141
  _inherits(RequestFailedError, GenericError);
153
- var _super = _create_super(RequestFailedError);
154
142
  function RequestFailedError(message, statusCode, data, context) {
155
143
  _class_call_check(this, RequestFailedError);
156
144
  var _this;
157
- _this = _super.call(this, "[status: ".concat(statusCode, "] ").concat(message), context);
158
- /**
145
+ _this = _call_super(this, RequestFailedError, [
146
+ "[status: ".concat(statusCode, "] ").concat(message),
147
+ context
148
+ ]), /**
159
149
  * Request status code
160
- */ _define_property(_assert_this_initialized(_this), "statusCode", void 0);
161
- /**
150
+ */ _define_property(_this, "statusCode", void 0), /**
162
151
  * Data decoded from the response body
163
- */ _define_property(_assert_this_initialized(_this), "data", void 0);
152
+ */ _define_property(_this, "data", void 0);
164
153
  _this.statusCode = statusCode;
165
154
  _this.data = data;
166
155
  return _this;
@@ -172,14 +161,15 @@ function _create_super(Derived) {
172
161
  */ export var EmptyResponseError = /*#__PURE__*/ function(GenericError) {
173
162
  "use strict";
174
163
  _inherits(EmptyResponseError, GenericError);
175
- var _super = _create_super(EmptyResponseError);
176
164
  function EmptyResponseError(message, data, context) {
177
165
  _class_call_check(this, EmptyResponseError);
178
166
  var _this;
179
- _this = _super.call(this, "[Empty response] ".concat(message), context);
180
- /**
167
+ _this = _call_super(this, EmptyResponseError, [
168
+ "[Empty response] ".concat(message),
169
+ context
170
+ ]), /**
181
171
  * Data decoded from the response body
182
- */ _define_property(_assert_this_initialized(_this), "data", void 0);
172
+ */ _define_property(_this, "data", void 0);
183
173
  _this.data = data;
184
174
  return _this;
185
175
  }
@@ -190,10 +180,12 @@ function _create_super(Derived) {
190
180
  */ export var ResponseTimeoutError = /*#__PURE__*/ function(GenericError) {
191
181
  "use strict";
192
182
  _inherits(ResponseTimeoutError, GenericError);
193
- var _super = _create_super(ResponseTimeoutError);
194
183
  function ResponseTimeoutError(message, context) {
195
184
  _class_call_check(this, ResponseTimeoutError);
196
- return _super.call(this, "[Response timeout] ".concat(message), context);
185
+ return _call_super(this, ResponseTimeoutError, [
186
+ "[Response timeout] ".concat(message),
187
+ context
188
+ ]);
197
189
  }
198
190
  return ResponseTimeoutError;
199
191
  }(GenericError);
@@ -202,10 +194,14 @@ function _create_super(Derived) {
202
194
  */ export var ResponseJSONParseError = /*#__PURE__*/ function(RequestFailedError) {
203
195
  "use strict";
204
196
  _inherits(ResponseJSONParseError, RequestFailedError);
205
- var _super = _create_super(ResponseJSONParseError);
206
197
  function ResponseJSONParseError(message, httpStatus, bodyContent, context) {
207
198
  _class_call_check(this, ResponseJSONParseError);
208
- return _super.call(this, "[Response JSON parse error] ".concat(message), httpStatus, bodyContent, context);
199
+ return _call_super(this, ResponseJSONParseError, [
200
+ "[Response JSON parse error] ".concat(message),
201
+ httpStatus,
202
+ bodyContent,
203
+ context
204
+ ]);
209
205
  }
210
206
  return ResponseJSONParseError;
211
207
  }(RequestFailedError);
@@ -214,17 +210,17 @@ function _create_super(Derived) {
214
210
  */ export var CanceledCallError = /*#__PURE__*/ function(GenericError) {
215
211
  "use strict";
216
212
  _inherits(CanceledCallError, GenericError);
217
- var _super = _create_super(CanceledCallError);
218
213
  function CanceledCallError(message, pluginIndex, pluginCanceling, context) {
219
214
  _class_call_check(this, CanceledCallError);
220
215
  var _this;
221
- _this = _super.call(this, "[Canceled call] ".concat(message), context);
222
- /**
216
+ _this = _call_super(this, CanceledCallError, [
217
+ "[Canceled call] ".concat(message),
218
+ context
219
+ ]), /**
223
220
  * First plugin canceling the call
224
- */ _define_property(_assert_this_initialized(_this), "pluginCanceling", void 0);
225
- /**
221
+ */ _define_property(_this, "pluginCanceling", void 0), /**
226
222
  * Index of the first plugin canceling the call
227
- */ _define_property(_assert_this_initialized(_this), "pluginIndex", void 0);
223
+ */ _define_property(_this, "pluginIndex", void 0);
228
224
  _this.pluginIndex = pluginIndex;
229
225
  _this.pluginCanceling = pluginCanceling;
230
226
  return _this;
@@ -4,6 +4,10 @@ function _assert_this_initialized(self) {
4
4
  }
5
5
  return self;
6
6
  }
7
+ function _call_super(_this, derived, args) {
8
+ derived = _get_prototype_of(derived);
9
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
10
+ }
7
11
  function _class_call_check(instance, Constructor) {
8
12
  if (!(instance instanceof Constructor)) {
9
13
  throw new TypeError("Cannot call a class as a function");
@@ -73,28 +77,12 @@ function _type_of(obj) {
73
77
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
74
78
  }
75
79
  function _is_native_reflect_construct() {
76
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
77
- if (Reflect.construct.sham) return false;
78
- if (typeof Proxy === "function") return true;
79
80
  try {
80
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
81
- return true;
82
- } catch (e) {
83
- return false;
84
- }
85
- }
86
- function _create_super(Derived) {
87
- var hasNativeReflectConstruct = _is_native_reflect_construct();
88
- return function _createSuperInternal() {
89
- var Super = _get_prototype_of(Derived), result;
90
- if (hasNativeReflectConstruct) {
91
- var NewTarget = _get_prototype_of(this).constructor;
92
- result = Reflect.construct(Super, arguments, NewTarget);
93
- } else {
94
- result = Super.apply(this, arguments);
95
- }
96
- return _possible_constructor_return(this, result);
97
- };
81
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
82
+ } catch (_) {}
83
+ return (_is_native_reflect_construct = function() {
84
+ return !!result;
85
+ })();
98
86
  }
99
87
  import { BaseMockAdapter } from './base-mock-adapter';
100
88
  /**
@@ -102,12 +90,10 @@ import { BaseMockAdapter } from './base-mock-adapter';
102
90
  */ export var RandomMockAdapter = /*#__PURE__*/ function(BaseMockAdapter) {
103
91
  "use strict";
104
92
  _inherits(RandomMockAdapter, BaseMockAdapter);
105
- var _super = _create_super(RandomMockAdapter);
106
93
  function RandomMockAdapter() {
107
94
  _class_call_check(this, RandomMockAdapter);
108
95
  var _this;
109
- _this = _super.apply(this, arguments);
110
- _define_property(_assert_this_initialized(_this), "cache", {});
96
+ _this = _call_super(this, RandomMockAdapter, arguments), _define_property(_this, "cache", {});
111
97
  return _this;
112
98
  }
113
99
  _create_class(RandomMockAdapter, [
@@ -4,6 +4,10 @@ function _assert_this_initialized(self) {
4
4
  }
5
5
  return self;
6
6
  }
7
+ function _call_super(_this, derived, args) {
8
+ derived = _get_prototype_of(derived);
9
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
10
+ }
7
11
  function _class_call_check(instance, Constructor) {
8
12
  if (!(instance instanceof Constructor)) {
9
13
  throw new TypeError("Cannot call a class as a function");
@@ -73,28 +77,12 @@ function _type_of(obj) {
73
77
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
74
78
  }
75
79
  function _is_native_reflect_construct() {
76
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
77
- if (Reflect.construct.sham) return false;
78
- if (typeof Proxy === "function") return true;
79
80
  try {
80
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
81
- return true;
82
- } catch (e) {
83
- return false;
84
- }
85
- }
86
- function _create_super(Derived) {
87
- var hasNativeReflectConstruct = _is_native_reflect_construct();
88
- return function _createSuperInternal() {
89
- var Super = _get_prototype_of(Derived), result;
90
- if (hasNativeReflectConstruct) {
91
- var NewTarget = _get_prototype_of(this).constructor;
92
- result = Reflect.construct(Super, arguments, NewTarget);
93
- } else {
94
- result = Super.apply(this, arguments);
95
- }
96
- return _possible_constructor_return(this, result);
97
- };
81
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
82
+ } catch (_) {}
83
+ return (_is_native_reflect_construct = function() {
84
+ return !!result;
85
+ })();
98
86
  }
99
87
  import { BaseMockAdapter } from './base-mock-adapter';
100
88
  /**
@@ -103,12 +91,10 @@ import { BaseMockAdapter } from './base-mock-adapter';
103
91
  */ export var SequentialMockAdapter = /*#__PURE__*/ function(BaseMockAdapter) {
104
92
  "use strict";
105
93
  _inherits(SequentialMockAdapter, BaseMockAdapter);
106
- var _super = _create_super(SequentialMockAdapter);
107
94
  function SequentialMockAdapter() {
108
95
  _class_call_check(this, SequentialMockAdapter);
109
96
  var _this;
110
- _this = _super.apply(this, arguments);
111
- _define_property(_assert_this_initialized(_this), "operationCounter", {});
97
+ _this = _call_super(this, SequentialMockAdapter, arguments), _define_property(_this, "operationCounter", {});
112
98
  return _this;
113
99
  }
114
100
  _create_class(SequentialMockAdapter, [
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Interface of a Angular plugin.
3
+ * The plugin will be run around the Angular Http call
4
+ */ export { };
@@ -1,2 +1,3 @@
1
1
  export * from './mock-intercept.request';
2
2
  export * from './mock-intercept.fetch';
3
+ export * from './mock-intercept.interface';
@@ -0,0 +1,342 @@
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 _object_spread(target) {
70
+ for(var i = 1; i < arguments.length; i++){
71
+ var source = arguments[i] != null ? arguments[i] : {};
72
+ var ownKeys = Object.keys(source);
73
+ if (typeof Object.getOwnPropertySymbols === "function") {
74
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
75
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
76
+ }));
77
+ }
78
+ ownKeys.forEach(function(key) {
79
+ _define_property(target, key, source[key]);
80
+ });
81
+ }
82
+ return target;
83
+ }
84
+ function ownKeys(object, enumerableOnly) {
85
+ var keys = Object.keys(object);
86
+ if (Object.getOwnPropertySymbols) {
87
+ var symbols = Object.getOwnPropertySymbols(object);
88
+ if (enumerableOnly) {
89
+ symbols = symbols.filter(function(sym) {
90
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
91
+ });
92
+ }
93
+ keys.push.apply(keys, symbols);
94
+ }
95
+ return keys;
96
+ }
97
+ function _object_spread_props(target, source) {
98
+ source = source != null ? source : {};
99
+ if (Object.getOwnPropertyDescriptors) {
100
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
101
+ } else {
102
+ ownKeys(Object(source)).forEach(function(key) {
103
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
104
+ });
105
+ }
106
+ return target;
107
+ }
108
+ function _ts_generator(thisArg, body) {
109
+ var f, y, t, g, _ = {
110
+ label: 0,
111
+ sent: function() {
112
+ if (t[0] & 1) throw t[1];
113
+ return t[1];
114
+ },
115
+ trys: [],
116
+ ops: []
117
+ };
118
+ return g = {
119
+ next: verb(0),
120
+ "throw": verb(1),
121
+ "return": verb(2)
122
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
123
+ return this;
124
+ }), g;
125
+ function verb(n) {
126
+ return function(v) {
127
+ return step([
128
+ n,
129
+ v
130
+ ]);
131
+ };
132
+ }
133
+ function step(op) {
134
+ if (f) throw new TypeError("Generator is already executing.");
135
+ while(_)try {
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;
137
+ if (y = 0, t) op = [
138
+ op[0] & 2,
139
+ t.value
140
+ ];
141
+ switch(op[0]){
142
+ case 0:
143
+ case 1:
144
+ t = op;
145
+ break;
146
+ case 4:
147
+ _.label++;
148
+ return {
149
+ value: op[1],
150
+ done: false
151
+ };
152
+ case 5:
153
+ _.label++;
154
+ y = op[1];
155
+ op = [
156
+ 0
157
+ ];
158
+ continue;
159
+ case 7:
160
+ op = _.ops.pop();
161
+ _.trys.pop();
162
+ continue;
163
+ default:
164
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
165
+ _ = 0;
166
+ continue;
167
+ }
168
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
169
+ _.label = op[1];
170
+ break;
171
+ }
172
+ if (op[0] === 6 && _.label < t[1]) {
173
+ _.label = t[1];
174
+ t = op;
175
+ break;
176
+ }
177
+ if (t && _.label < t[2]) {
178
+ _.label = t[2];
179
+ _.ops.push(op);
180
+ break;
181
+ }
182
+ if (t[2]) _.ops.pop();
183
+ _.trys.pop();
184
+ continue;
185
+ }
186
+ op = body.call(thisArg, _);
187
+ } catch (e) {
188
+ op = [
189
+ 6,
190
+ e
191
+ ];
192
+ y = 0;
193
+ } finally{
194
+ f = t = 0;
195
+ }
196
+ if (op[0] & 5) throw op[1];
197
+ return {
198
+ value: op[0] ? op[1] : void 0,
199
+ done: true
200
+ };
201
+ }
202
+ }
203
+ import { delay, from, mergeMap } from 'rxjs';
204
+ import { CUSTOM_MOCK_OPERATION_ID_HEADER } from './mock-intercept.interface';
205
+ import { MockInterceptRequest } from './mock-intercept.request';
206
+ import { HttpResponse } from '@angular/common/http';
207
+ /**
208
+ * Plugin to mock and intercept the call of SDK
209
+ *
210
+ * This plugin should be used only with the MockInterceptRequest Plugin.
211
+ * It will allow the user to delay the response or to handle the getResponse function provided with the mock (if present).
212
+ */ export var MockInterceptAngular = /*#__PURE__*/ function() {
213
+ "use strict";
214
+ function MockInterceptAngular(options) {
215
+ _class_call_check(this, MockInterceptAngular);
216
+ _define_property(this, "options", void 0);
217
+ this.options = options;
218
+ }
219
+ _create_class(MockInterceptAngular, [
220
+ {
221
+ key: "load",
222
+ value: function load(context) {
223
+ var _this = this;
224
+ if (!context.apiClient.options.requestPlugins.some(function(plugin) {
225
+ return _instanceof(plugin, MockInterceptRequest);
226
+ })) {
227
+ throw new Error('MockInterceptAngular plugin should be used only with the MockInterceptRequest plugin');
228
+ }
229
+ return {
230
+ transform: function(call) {
231
+ var _this1 = _this;
232
+ return from(_async_to_generator(function() {
233
+ var originalCall, delayTime, _tmp, operationId, mock, response;
234
+ return _ts_generator(this, function(_state) {
235
+ switch(_state.label){
236
+ case 0:
237
+ return [
238
+ 4,
239
+ _this1.options.adapter.initialize()
240
+ ];
241
+ case 1:
242
+ _state.sent();
243
+ originalCall = call;
244
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
245
+ if (!context.options.headers || !_instanceof(context.options.headers, Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
246
+ return [
247
+ 2,
248
+ originalCall
249
+ ];
250
+ }
251
+ if (!(typeof _this1.options.delayTiming !== 'undefined')) return [
252
+ 3,
253
+ 5
254
+ ];
255
+ if (!(typeof _this1.options.delayTiming === 'number')) return [
256
+ 3,
257
+ 2
258
+ ];
259
+ _tmp = _this1.options.delayTiming;
260
+ return [
261
+ 3,
262
+ 4
263
+ ];
264
+ case 2:
265
+ return [
266
+ 4,
267
+ _this1.options.delayTiming(_object_spread_props(_object_spread({}, context), {
268
+ fetchPlugins: [],
269
+ options: context.requestOptions
270
+ }))
271
+ ];
272
+ case 3:
273
+ _tmp = _state.sent();
274
+ _state.label = 4;
275
+ case 4:
276
+ delayTime = _tmp;
277
+ originalCall = originalCall.pipe(delay(delayTime));
278
+ _state.label = 5;
279
+ case 5:
280
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
281
+ operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
282
+ try {
283
+ mock = _this1.options.adapter.getLatestMock(operationId);
284
+ if (!mock.getResponse) {
285
+ return [
286
+ 2,
287
+ originalCall
288
+ ];
289
+ }
290
+ response = mock.getResponse();
291
+ return [
292
+ 2,
293
+ originalCall.pipe(mergeMap(function() {
294
+ var _ref = _async_to_generator(function(res) {
295
+ var body, responseCloned;
296
+ return _ts_generator(this, function(_state) {
297
+ switch(_state.label){
298
+ case 0:
299
+ return [
300
+ 4,
301
+ response.json()
302
+ ];
303
+ case 1:
304
+ body = _state.sent();
305
+ responseCloned = res.clone();
306
+ return [
307
+ 2,
308
+ new HttpResponse(_object_spread_props(_object_spread({}, responseCloned), {
309
+ body: body,
310
+ url: responseCloned.url || undefined
311
+ }))
312
+ ];
313
+ }
314
+ });
315
+ });
316
+ return function(res) {
317
+ return _ref.apply(this, arguments);
318
+ };
319
+ }()))
320
+ ];
321
+ } catch (e) {
322
+ (context.logger || console).error("Failed to retrieve the latest mock for Operation ID ".concat(operationId, ", fallback to default mock"));
323
+ return [
324
+ 2,
325
+ originalCall
326
+ ];
327
+ }
328
+ return [
329
+ 2
330
+ ];
331
+ }
332
+ });
333
+ })()).pipe(mergeMap(function(res) {
334
+ return res;
335
+ }));
336
+ }
337
+ };
338
+ }
339
+ }
340
+ ]);
341
+ return MockInterceptAngular;
342
+ }();