rest-client-sdk 7.3.0 → 7.5.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.
package/dist/index.mjs CHANGED
@@ -1,847 +1,600 @@
1
1
  import URI from 'urijs';
2
2
  import diff from 'deep-diff';
3
3
 
4
- function _typeof(obj) {
5
- "@babel/helpers - typeof";
6
-
7
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
8
- _typeof = function (obj) {
9
- return typeof obj;
10
- };
11
- } else {
12
- _typeof = function (obj) {
13
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
14
- };
15
- }
16
-
17
- return _typeof(obj);
4
+ function _arrayLikeToArray(r, a) {
5
+ (null == a || a > r.length) && (a = r.length);
6
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
7
+ return n;
18
8
  }
19
-
20
- function _classCallCheck(instance, Constructor) {
21
- if (!(instance instanceof Constructor)) {
22
- throw new TypeError("Cannot call a class as a function");
23
- }
9
+ function _assertClassBrand(e, t, n) {
10
+ if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
11
+ throw new TypeError("Private element is not present on this object");
24
12
  }
25
-
26
- function _defineProperties(target, props) {
27
- for (var i = 0; i < props.length; i++) {
28
- var descriptor = props[i];
29
- descriptor.enumerable = descriptor.enumerable || false;
30
- descriptor.configurable = true;
31
- if ("value" in descriptor) descriptor.writable = true;
32
- Object.defineProperty(target, descriptor.key, descriptor);
33
- }
13
+ function _assertThisInitialized(e) {
14
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
15
+ return e;
34
16
  }
35
-
36
- function _createClass(Constructor, protoProps, staticProps) {
37
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
38
- if (staticProps) _defineProperties(Constructor, staticProps);
39
- return Constructor;
17
+ function _callSuper(t, o, e) {
18
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
40
19
  }
41
-
42
- function _defineProperty(obj, key, value) {
43
- if (key in obj) {
44
- Object.defineProperty(obj, key, {
45
- value: value,
46
- enumerable: true,
47
- configurable: true,
48
- writable: true
49
- });
50
- } else {
51
- obj[key] = value;
52
- }
53
-
54
- return obj;
20
+ function _checkPrivateRedeclaration(e, t) {
21
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
55
22
  }
56
-
57
- function ownKeys(object, enumerableOnly) {
58
- var keys = Object.keys(object);
59
-
60
- if (Object.getOwnPropertySymbols) {
61
- var symbols = Object.getOwnPropertySymbols(object);
62
- if (enumerableOnly) symbols = symbols.filter(function (sym) {
63
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
64
- });
65
- keys.push.apply(keys, symbols);
66
- }
67
-
68
- return keys;
23
+ function _classCallCheck(a, n) {
24
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
69
25
  }
70
-
71
- function _objectSpread2(target) {
72
- for (var i = 1; i < arguments.length; i++) {
73
- var source = arguments[i] != null ? arguments[i] : {};
74
-
75
- if (i % 2) {
76
- ownKeys(Object(source), true).forEach(function (key) {
77
- _defineProperty(target, key, source[key]);
78
- });
79
- } else if (Object.getOwnPropertyDescriptors) {
80
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
81
- } else {
82
- ownKeys(Object(source)).forEach(function (key) {
83
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
84
- });
85
- }
86
- }
87
-
88
- return target;
26
+ function _classPrivateFieldGet2(s, a) {
27
+ return s.get(_assertClassBrand(s, a));
89
28
  }
90
-
91
- function _inherits(subClass, superClass) {
92
- if (typeof superClass !== "function" && superClass !== null) {
93
- throw new TypeError("Super expression must either be null or a function");
94
- }
95
-
96
- subClass.prototype = Object.create(superClass && superClass.prototype, {
97
- constructor: {
98
- value: subClass,
99
- writable: true,
100
- configurable: true
101
- }
102
- });
103
- if (superClass) _setPrototypeOf(subClass, superClass);
104
- }
105
-
106
- function _getPrototypeOf(o) {
107
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
108
- return o.__proto__ || Object.getPrototypeOf(o);
109
- };
110
- return _getPrototypeOf(o);
111
- }
112
-
113
- function _setPrototypeOf(o, p) {
114
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
115
- o.__proto__ = p;
116
- return o;
117
- };
118
-
119
- return _setPrototypeOf(o, p);
120
- }
121
-
122
- function _isNativeReflectConstruct() {
123
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
124
- if (Reflect.construct.sham) return false;
125
- if (typeof Proxy === "function") return true;
126
-
127
- try {
128
- Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
129
- return true;
130
- } catch (e) {
131
- return false;
132
- }
133
- }
134
-
135
- function _construct(Parent, args, Class) {
136
- if (_isNativeReflectConstruct()) {
137
- _construct = Reflect.construct;
138
- } else {
139
- _construct = function _construct(Parent, args, Class) {
140
- var a = [null];
141
- a.push.apply(a, args);
142
- var Constructor = Function.bind.apply(Parent, a);
143
- var instance = new Constructor();
144
- if (Class) _setPrototypeOf(instance, Class.prototype);
145
- return instance;
146
- };
147
- }
148
-
149
- return _construct.apply(null, arguments);
150
- }
151
-
152
- function _isNativeFunction(fn) {
153
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
154
- }
155
-
156
- function _wrapNativeSuper(Class) {
157
- var _cache = typeof Map === "function" ? new Map() : undefined;
158
-
159
- _wrapNativeSuper = function _wrapNativeSuper(Class) {
160
- if (Class === null || !_isNativeFunction(Class)) return Class;
161
-
162
- if (typeof Class !== "function") {
163
- throw new TypeError("Super expression must either be null or a function");
164
- }
165
-
166
- if (typeof _cache !== "undefined") {
167
- if (_cache.has(Class)) return _cache.get(Class);
168
-
169
- _cache.set(Class, Wrapper);
170
- }
171
-
172
- function Wrapper() {
173
- return _construct(Class, arguments, _getPrototypeOf(this).constructor);
174
- }
175
-
176
- Wrapper.prototype = Object.create(Class.prototype, {
177
- constructor: {
178
- value: Wrapper,
179
- enumerable: false,
180
- writable: true,
181
- configurable: true
182
- }
183
- });
184
- return _setPrototypeOf(Wrapper, Class);
185
- };
186
-
187
- return _wrapNativeSuper(Class);
188
- }
189
-
190
- function _objectWithoutPropertiesLoose(source, excluded) {
191
- if (source == null) return {};
192
- var target = {};
193
- var sourceKeys = Object.keys(source);
194
- var key, i;
195
-
196
- for (i = 0; i < sourceKeys.length; i++) {
197
- key = sourceKeys[i];
198
- if (excluded.indexOf(key) >= 0) continue;
199
- target[key] = source[key];
200
- }
201
-
202
- return target;
29
+ function _classPrivateFieldInitSpec(e, t, a) {
30
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
203
31
  }
204
-
205
- function _objectWithoutProperties(source, excluded) {
206
- if (source == null) return {};
207
-
208
- var target = _objectWithoutPropertiesLoose(source, excluded);
209
-
210
- var key, i;
211
-
212
- if (Object.getOwnPropertySymbols) {
213
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
214
-
215
- for (i = 0; i < sourceSymbolKeys.length; i++) {
216
- key = sourceSymbolKeys[i];
217
- if (excluded.indexOf(key) >= 0) continue;
218
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
219
- target[key] = source[key];
220
- }
221
- }
222
-
223
- return target;
32
+ function _classPrivateFieldSet2(s, a, r) {
33
+ return s.set(_assertClassBrand(s, a), r), r;
224
34
  }
225
-
226
- function _assertThisInitialized(self) {
227
- if (self === void 0) {
228
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
229
- }
230
-
231
- return self;
35
+ function _construct(t, e, r) {
36
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
37
+ var o = [null];
38
+ o.push.apply(o, e);
39
+ var p = new (t.bind.apply(t, o))();
40
+ return r && _setPrototypeOf(p, r.prototype), p;
232
41
  }
233
-
234
- function _possibleConstructorReturn(self, call) {
235
- if (call && (typeof call === "object" || typeof call === "function")) {
236
- return call;
42
+ function _defineProperties(e, r) {
43
+ for (var t = 0; t < r.length; t++) {
44
+ var o = r[t];
45
+ o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
237
46
  }
238
-
239
- return _assertThisInitialized(self);
240
47
  }
241
-
242
- function _createSuper(Derived) {
243
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
244
-
245
- return function _createSuperInternal() {
246
- var Super = _getPrototypeOf(Derived),
247
- result;
248
-
249
- if (hasNativeReflectConstruct) {
250
- var NewTarget = _getPrototypeOf(this).constructor;
251
-
252
- result = Reflect.construct(Super, arguments, NewTarget);
253
- } else {
254
- result = Super.apply(this, arguments);
255
- }
256
-
257
- return _possibleConstructorReturn(this, result);
258
- };
259
- }
260
-
261
- function _unsupportedIterableToArray(o, minLen) {
262
- if (!o) return;
263
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
264
- var n = Object.prototype.toString.call(o).slice(8, -1);
265
- if (n === "Object" && o.constructor) n = o.constructor.name;
266
- if (n === "Map" || n === "Set") return Array.from(o);
267
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
48
+ function _createClass(e, r, t) {
49
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
50
+ writable: false
51
+ }), e;
268
52
  }
269
-
270
- function _arrayLikeToArray(arr, len) {
271
- if (len == null || len > arr.length) len = arr.length;
272
-
273
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
274
-
275
- return arr2;
276
- }
277
-
278
- function _createForOfIteratorHelper(o, allowArrayLike) {
279
- var it;
280
-
281
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
282
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
283
- if (it) o = it;
284
- var i = 0;
285
-
286
- var F = function () {};
287
-
53
+ function _createForOfIteratorHelper(r, e) {
54
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
55
+ if (!t) {
56
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
57
+ t && (r = t);
58
+ var n = 0,
59
+ F = function () {};
288
60
  return {
289
61
  s: F,
290
62
  n: function () {
291
- if (i >= o.length) return {
63
+ return n >= r.length ? {
292
64
  done: true
293
- };
294
- return {
65
+ } : {
295
66
  done: false,
296
- value: o[i++]
67
+ value: r[n++]
297
68
  };
298
69
  },
299
- e: function (e) {
300
- throw e;
70
+ e: function (r) {
71
+ throw r;
301
72
  },
302
73
  f: F
303
74
  };
304
75
  }
305
-
306
76
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
307
77
  }
308
-
309
- var normalCompletion = true,
310
- didErr = false,
311
- err;
78
+ var o,
79
+ a = true,
80
+ u = false;
312
81
  return {
313
82
  s: function () {
314
- it = o[Symbol.iterator]();
83
+ t = t.call(r);
315
84
  },
316
85
  n: function () {
317
- var step = it.next();
318
- normalCompletion = step.done;
319
- return step;
86
+ var r = t.next();
87
+ return a = r.done, r;
320
88
  },
321
- e: function (e) {
322
- didErr = true;
323
- err = e;
89
+ e: function (r) {
90
+ u = true, o = r;
324
91
  },
325
92
  f: function () {
326
93
  try {
327
- if (!normalCompletion && it.return != null) it.return();
94
+ a || null == t.return || t.return();
328
95
  } finally {
329
- if (didErr) throw err;
96
+ if (u) throw o;
330
97
  }
331
98
  }
332
99
  };
333
100
  }
334
-
335
- function _classPrivateFieldGet(receiver, privateMap) {
336
- var descriptor = privateMap.get(receiver);
337
-
338
- if (!descriptor) {
339
- throw new TypeError("attempted to get private field on non-instance");
101
+ function _defineProperty(e, r, t) {
102
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
103
+ value: t,
104
+ enumerable: true,
105
+ configurable: true,
106
+ writable: true
107
+ }) : e[r] = t, e;
108
+ }
109
+ function _getPrototypeOf(t) {
110
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
111
+ return t.__proto__ || Object.getPrototypeOf(t);
112
+ }, _getPrototypeOf(t);
113
+ }
114
+ function _inherits(t, e) {
115
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
116
+ t.prototype = Object.create(e && e.prototype, {
117
+ constructor: {
118
+ value: t,
119
+ writable: true,
120
+ configurable: true
121
+ }
122
+ }), Object.defineProperty(t, "prototype", {
123
+ writable: false
124
+ }), e && _setPrototypeOf(t, e);
125
+ }
126
+ function _isNativeFunction(t) {
127
+ try {
128
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
129
+ } catch (n) {
130
+ return "function" == typeof t;
340
131
  }
341
-
342
- if (descriptor.get) {
343
- return descriptor.get.call(receiver);
132
+ }
133
+ function _isNativeReflectConstruct() {
134
+ try {
135
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
136
+ } catch (t) {}
137
+ return (_isNativeReflectConstruct = function () {
138
+ return !!t;
139
+ })();
140
+ }
141
+ function ownKeys(e, r) {
142
+ var t = Object.keys(e);
143
+ if (Object.getOwnPropertySymbols) {
144
+ var o = Object.getOwnPropertySymbols(e);
145
+ r && (o = o.filter(function (r) {
146
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
147
+ })), t.push.apply(t, o);
344
148
  }
345
-
346
- return descriptor.value;
149
+ return t;
347
150
  }
348
-
349
- function _classPrivateFieldSet(receiver, privateMap, value) {
350
- var descriptor = privateMap.get(receiver);
351
-
352
- if (!descriptor) {
353
- throw new TypeError("attempted to set private field on non-instance");
151
+ function _objectSpread2(e) {
152
+ for (var r = 1; r < arguments.length; r++) {
153
+ var t = null != arguments[r] ? arguments[r] : {};
154
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
155
+ _defineProperty(e, r, t[r]);
156
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
157
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
158
+ });
354
159
  }
355
-
356
- if (descriptor.set) {
357
- descriptor.set.call(receiver, value);
358
- } else {
359
- if (!descriptor.writable) {
360
- throw new TypeError("attempted to set read only private field");
361
- }
362
-
363
- descriptor.value = value;
160
+ return e;
161
+ }
162
+ function _objectWithoutProperties(e, t) {
163
+ if (null == e) return {};
164
+ var o,
165
+ r,
166
+ i = _objectWithoutPropertiesLoose(e, t);
167
+ if (Object.getOwnPropertySymbols) {
168
+ var n = Object.getOwnPropertySymbols(e);
169
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
364
170
  }
365
-
366
- return value;
171
+ return i;
367
172
  }
173
+ function _objectWithoutPropertiesLoose(r, e) {
174
+ if (null == r) return {};
175
+ var t = {};
176
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
177
+ if (-1 !== e.indexOf(n)) continue;
178
+ t[n] = r[n];
179
+ }
180
+ return t;
181
+ }
182
+ function _possibleConstructorReturn(t, e) {
183
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
184
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
185
+ return _assertThisInitialized(t);
186
+ }
187
+ function _setPrototypeOf(t, e) {
188
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
189
+ return t.__proto__ = e, t;
190
+ }, _setPrototypeOf(t, e);
191
+ }
192
+ function _toPrimitive(t, r) {
193
+ if ("object" != typeof t || !t) return t;
194
+ var e = t[Symbol.toPrimitive];
195
+ if (void 0 !== e) {
196
+ var i = e.call(t, r);
197
+ if ("object" != typeof i) return i;
198
+ throw new TypeError("@@toPrimitive must return a primitive value.");
199
+ }
200
+ return ("string" === r ? String : Number)(t);
201
+ }
202
+ function _toPropertyKey(t) {
203
+ var i = _toPrimitive(t, "string");
204
+ return "symbol" == typeof i ? i : i + "";
205
+ }
206
+ function _typeof(o) {
207
+ "@babel/helpers - typeof";
368
208
 
369
- /* eslint-disable max-classes-per-file, no-use-before-define */
209
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
210
+ return typeof o;
211
+ } : function (o) {
212
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
213
+ }, _typeof(o);
214
+ }
215
+ function _unsupportedIterableToArray(r, a) {
216
+ if (r) {
217
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
218
+ var t = {}.toString.call(r).slice(8, -1);
219
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
220
+ }
221
+ }
222
+ function _wrapNativeSuper(t) {
223
+ var r = "function" == typeof Map ? new Map() : void 0;
224
+ return _wrapNativeSuper = function (t) {
225
+ if (null === t || !_isNativeFunction(t)) return t;
226
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
227
+ if (void 0 !== r) {
228
+ if (r.has(t)) return r.get(t);
229
+ r.set(t, Wrapper);
230
+ }
231
+ function Wrapper() {
232
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
233
+ }
234
+ return Wrapper.prototype = Object.create(t.prototype, {
235
+ constructor: {
236
+ value: Wrapper,
237
+ enumerable: false,
238
+ writable: true,
239
+ configurable: true
240
+ }
241
+ }), _setPrototypeOf(Wrapper, t);
242
+ }, _wrapNativeSuper(t);
243
+ }
370
244
 
371
245
  /**
372
246
  * It's a bit tricky to extends native errors
373
247
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
374
248
  */
375
249
  var HttpError = /*#__PURE__*/function (_Error) {
376
- _inherits(HttpError, _Error);
377
-
378
- var _super = _createSuper(HttpError);
379
-
380
250
  function HttpError(message, baseResponse) {
381
251
  var _this;
382
-
383
252
  _classCallCheck(this, HttpError);
253
+ _this = _callSuper(this, HttpError, [message || 'Http errort']);
384
254
 
385
- _this = _super.call(this, message || 'Http errort'); // Set the prototype explicitly.
386
-
387
- _defineProperty(_assertThisInitialized(_this), "baseResponse", void 0);
388
-
389
- Object.setPrototypeOf(_assertThisInitialized(_this), OauthError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
255
+ // Set the prototype explicitly.
256
+ _defineProperty(_this, "baseResponse", void 0);
257
+ Object.setPrototypeOf(_this, OauthError.prototype);
390
258
 
259
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
391
260
  if (Error.captureStackTrace) {
392
- Error.captureStackTrace(_assertThisInitialized(_this), OauthError);
261
+ Error.captureStackTrace(_this, OauthError);
393
262
  }
394
-
395
263
  _this.name = 'HttpError';
396
264
  _this.baseResponse = baseResponse;
397
265
  return _this;
398
266
  }
267
+
399
268
  /**
400
269
  * Get the JSON of the baseResponse directly, if possible
401
270
  */
402
-
403
-
404
- _createClass(HttpError, [{
271
+ _inherits(HttpError, _Error);
272
+ return _createClass(HttpError, [{
405
273
  key: "responseJson",
406
274
  value: function responseJson() {
407
275
  return this.baseResponse.json();
408
276
  }
409
277
  }]);
410
-
411
- return HttpError;
412
- }( /*#__PURE__*/_wrapNativeSuper(Error));
413
-
278
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
414
279
  var OauthError = /*#__PURE__*/function (_Error2) {
415
- _inherits(OauthError, _Error2);
416
-
417
- var _super2 = _createSuper(OauthError);
418
-
419
280
  function OauthError(message, previousError) {
420
281
  var _this2;
421
-
422
282
  _classCallCheck(this, OauthError);
283
+ _this2 = _callSuper(this, OauthError, [message || 'Oauth error']);
423
284
 
424
- _this2 = _super2.call(this, message || 'Oauth error'); // Set the prototype explicitly.
425
-
426
- _defineProperty(_assertThisInitialized(_this2), "previousError", void 0);
427
-
428
- Object.setPrototypeOf(_assertThisInitialized(_this2), OauthError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
285
+ // Set the prototype explicitly.
286
+ _defineProperty(_this2, "previousError", void 0);
287
+ Object.setPrototypeOf(_this2, OauthError.prototype);
429
288
 
289
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
430
290
  if (Error.captureStackTrace) {
431
- Error.captureStackTrace(_assertThisInitialized(_this2), OauthError);
291
+ Error.captureStackTrace(_this2, OauthError);
432
292
  }
433
-
434
293
  _this2.name = 'OauthError';
435
294
  _this2.previousError = previousError;
436
295
  return _this2;
437
296
  }
438
-
439
- return OauthError;
440
- }( /*#__PURE__*/_wrapNativeSuper(Error));
441
-
442
- var InvalidGrantError = /*#__PURE__*/function (_OauthError) {
443
- _inherits(InvalidGrantError, _OauthError);
444
-
445
- var _super3 = _createSuper(InvalidGrantError);
446
-
297
+ _inherits(OauthError, _Error2);
298
+ return _createClass(OauthError);
299
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
300
+ var InvalidGrantError = /*#__PURE__*/function (_OauthError2) {
447
301
  function InvalidGrantError(message, previousError) {
448
302
  var _this3;
449
-
450
303
  _classCallCheck(this, InvalidGrantError);
304
+ _this3 = _callSuper(this, InvalidGrantError, [message || 'Invalid grant error', previousError]);
451
305
 
452
- _this3 = _super3.call(this, message || 'Invalid grant error', previousError); // Set the prototype explicitly.
453
-
454
- _defineProperty(_assertThisInitialized(_this3), "previousError", void 0);
455
-
456
- Object.setPrototypeOf(_assertThisInitialized(_this3), InvalidGrantError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
306
+ // Set the prototype explicitly.
307
+ _defineProperty(_this3, "previousError", void 0);
308
+ Object.setPrototypeOf(_this3, InvalidGrantError.prototype);
457
309
 
310
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
458
311
  if (Error.captureStackTrace) {
459
- Error.captureStackTrace(_assertThisInitialized(_this3), InvalidGrantError);
312
+ Error.captureStackTrace(_this3, InvalidGrantError);
460
313
  }
461
-
462
314
  _this3.name = 'InvalidGrantError';
463
315
  _this3.previousError = previousError;
464
316
  return _this3;
465
317
  }
466
-
467
- return InvalidGrantError;
318
+ _inherits(InvalidGrantError, _OauthError2);
319
+ return _createClass(InvalidGrantError);
468
320
  }(OauthError);
469
-
470
- var InvalidScopeError = /*#__PURE__*/function (_OauthError2) {
471
- _inherits(InvalidScopeError, _OauthError2);
472
-
473
- var _super4 = _createSuper(InvalidScopeError);
474
-
321
+ var InvalidScopeError = /*#__PURE__*/function (_OauthError3) {
475
322
  function InvalidScopeError(message, previousError) {
476
323
  var _this4;
477
-
478
324
  _classCallCheck(this, InvalidScopeError);
325
+ _this4 = _callSuper(this, InvalidScopeError, [message || 'Invalid scope error', previousError]);
479
326
 
480
- _this4 = _super4.call(this, message || 'Invalid scope error', previousError); // Set the prototype explicitly.
481
-
482
- _defineProperty(_assertThisInitialized(_this4), "previousError", void 0);
483
-
484
- Object.setPrototypeOf(_assertThisInitialized(_this4), InvalidScopeError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
327
+ // Set the prototype explicitly.
328
+ _defineProperty(_this4, "previousError", void 0);
329
+ Object.setPrototypeOf(_this4, InvalidScopeError.prototype);
485
330
 
331
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
486
332
  if (Error.captureStackTrace) {
487
- Error.captureStackTrace(_assertThisInitialized(_this4), InvalidScopeError);
333
+ Error.captureStackTrace(_this4, InvalidScopeError);
488
334
  }
489
-
490
335
  _this4.name = 'InvalidScopeError';
491
336
  _this4.previousError = previousError;
492
337
  return _this4;
493
338
  }
494
-
495
- return InvalidScopeError;
339
+ _inherits(InvalidScopeError, _OauthError3);
340
+ return _createClass(InvalidScopeError);
496
341
  }(OauthError); // 400
497
-
498
-
499
- var BadRequestError = /*#__PURE__*/function (_HttpError) {
500
- _inherits(BadRequestError, _HttpError);
501
-
502
- var _super5 = _createSuper(BadRequestError);
503
-
342
+ var BadRequestError = /*#__PURE__*/function (_HttpError2) {
504
343
  function BadRequestError(message, baseResponse) {
505
344
  var _this5;
506
-
507
345
  _classCallCheck(this, BadRequestError);
346
+ _this5 = _callSuper(this, BadRequestError, [message || 'Bad request', baseResponse]);
508
347
 
509
- _this5 = _super5.call(this, message || 'Bad request', baseResponse); // Set the prototype explicitly.
510
-
511
- _defineProperty(_assertThisInitialized(_this5), "baseResponse", void 0);
512
-
513
- Object.setPrototypeOf(_assertThisInitialized(_this5), BadRequestError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
348
+ // Set the prototype explicitly.
349
+ _defineProperty(_this5, "baseResponse", void 0);
350
+ Object.setPrototypeOf(_this5, BadRequestError.prototype);
514
351
 
352
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
515
353
  if (Error.captureStackTrace) {
516
- Error.captureStackTrace(_assertThisInitialized(_this5), BadRequestError);
354
+ Error.captureStackTrace(_this5, BadRequestError);
517
355
  }
518
-
519
356
  _this5.name = 'BadRequestError';
520
357
  _this5.baseResponse = baseResponse;
521
358
  return _this5;
522
359
  }
523
-
524
- return BadRequestError;
360
+ _inherits(BadRequestError, _HttpError2);
361
+ return _createClass(BadRequestError);
525
362
  }(HttpError); // 401
526
-
527
-
528
- var UnauthorizedError = /*#__PURE__*/function (_BadRequestError) {
529
- _inherits(UnauthorizedError, _BadRequestError);
530
-
531
- var _super6 = _createSuper(UnauthorizedError);
532
-
363
+ var UnauthorizedError = /*#__PURE__*/function (_BadRequestError2) {
533
364
  function UnauthorizedError(message, baseResponse) {
534
365
  var _this6;
535
-
536
366
  _classCallCheck(this, UnauthorizedError);
367
+ _this6 = _callSuper(this, UnauthorizedError, [message || 'Unauthorized', baseResponse]);
537
368
 
538
- _this6 = _super6.call(this, message || 'Unauthorized', baseResponse); // Set the prototype explicitly.
539
-
540
- _defineProperty(_assertThisInitialized(_this6), "baseResponse", void 0);
541
-
542
- Object.setPrototypeOf(_assertThisInitialized(_this6), UnauthorizedError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
369
+ // Set the prototype explicitly.
370
+ _defineProperty(_this6, "baseResponse", void 0);
371
+ Object.setPrototypeOf(_this6, UnauthorizedError.prototype);
543
372
 
373
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
544
374
  if (Error.captureStackTrace) {
545
- Error.captureStackTrace(_assertThisInitialized(_this6), UnauthorizedError);
375
+ Error.captureStackTrace(_this6, UnauthorizedError);
546
376
  }
547
-
548
377
  _this6.name = 'UnauthorizedError';
549
378
  _this6.baseResponse = baseResponse;
550
379
  return _this6;
551
380
  }
552
-
553
- return UnauthorizedError;
381
+ _inherits(UnauthorizedError, _BadRequestError2);
382
+ return _createClass(UnauthorizedError);
554
383
  }(BadRequestError); // 403
555
-
556
-
557
- var ForbiddenError = /*#__PURE__*/function (_BadRequestError2) {
558
- _inherits(ForbiddenError, _BadRequestError2);
559
-
560
- var _super7 = _createSuper(ForbiddenError);
561
-
384
+ var ForbiddenError = /*#__PURE__*/function (_BadRequestError3) {
562
385
  function ForbiddenError(message, baseResponse) {
563
386
  var _this7;
564
-
565
387
  _classCallCheck(this, ForbiddenError);
388
+ _this7 = _callSuper(this, ForbiddenError, [message || 'Forbidden', baseResponse]);
566
389
 
567
- _this7 = _super7.call(this, message || 'Forbidden', baseResponse); // Set the prototype explicitly.
568
-
569
- _defineProperty(_assertThisInitialized(_this7), "baseResponse", void 0);
570
-
571
- Object.setPrototypeOf(_assertThisInitialized(_this7), ForbiddenError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
390
+ // Set the prototype explicitly.
391
+ _defineProperty(_this7, "baseResponse", void 0);
392
+ Object.setPrototypeOf(_this7, ForbiddenError.prototype);
572
393
 
394
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
573
395
  if (Error.captureStackTrace) {
574
- Error.captureStackTrace(_assertThisInitialized(_this7), ForbiddenError);
396
+ Error.captureStackTrace(_this7, ForbiddenError);
575
397
  }
576
-
577
398
  _this7.name = 'ForbiddenError';
578
399
  _this7.baseResponse = baseResponse;
579
400
  return _this7;
580
401
  }
581
-
582
- return ForbiddenError;
402
+ _inherits(ForbiddenError, _BadRequestError3);
403
+ return _createClass(ForbiddenError);
583
404
  }(BadRequestError); // 404
584
-
585
-
586
- var ResourceNotFoundError = /*#__PURE__*/function (_BadRequestError3) {
587
- _inherits(ResourceNotFoundError, _BadRequestError3);
588
-
589
- var _super8 = _createSuper(ResourceNotFoundError);
590
-
405
+ var ResourceNotFoundError = /*#__PURE__*/function (_BadRequestError4) {
591
406
  function ResourceNotFoundError(message, baseResponse) {
592
407
  var _this8;
593
-
594
408
  _classCallCheck(this, ResourceNotFoundError);
409
+ _this8 = _callSuper(this, ResourceNotFoundError, [message || 'Resource is not found', baseResponse]);
595
410
 
596
- _this8 = _super8.call(this, message || 'Resource is not found', baseResponse); // Set the prototype explicitly.
597
-
598
- _defineProperty(_assertThisInitialized(_this8), "baseResponse", void 0);
599
-
600
- Object.setPrototypeOf(_assertThisInitialized(_this8), ResourceNotFoundError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
411
+ // Set the prototype explicitly.
412
+ _defineProperty(_this8, "baseResponse", void 0);
413
+ Object.setPrototypeOf(_this8, ResourceNotFoundError.prototype);
601
414
 
415
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
602
416
  if (Error.captureStackTrace) {
603
- Error.captureStackTrace(_assertThisInitialized(_this8), ResourceNotFoundError);
417
+ Error.captureStackTrace(_this8, ResourceNotFoundError);
604
418
  }
605
-
606
419
  _this8.name = 'ResourceNotFoundError';
607
420
  _this8.baseResponse = baseResponse;
608
421
  return _this8;
609
422
  }
610
-
611
- return ResourceNotFoundError;
423
+ _inherits(ResourceNotFoundError, _BadRequestError4);
424
+ return _createClass(ResourceNotFoundError);
612
425
  }(BadRequestError); // 409
613
-
614
-
615
- var ConflictError = /*#__PURE__*/function (_BadRequestError4) {
616
- _inherits(ConflictError, _BadRequestError4);
617
-
618
- var _super9 = _createSuper(ConflictError);
619
-
426
+ var ConflictError = /*#__PURE__*/function (_BadRequestError5) {
620
427
  function ConflictError(message, baseResponse) {
621
428
  var _this9;
622
-
623
429
  _classCallCheck(this, ConflictError);
430
+ _this9 = _callSuper(this, ConflictError, [message || 'Conflict detected', baseResponse]);
624
431
 
625
- _this9 = _super9.call(this, message || 'Conflict detected', baseResponse); // Set the prototype explicitly.
626
-
627
- _defineProperty(_assertThisInitialized(_this9), "baseResponse", void 0);
628
-
629
- Object.setPrototypeOf(_assertThisInitialized(_this9), ConflictError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
432
+ // Set the prototype explicitly.
433
+ _defineProperty(_this9, "baseResponse", void 0);
434
+ Object.setPrototypeOf(_this9, ConflictError.prototype);
630
435
 
436
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
631
437
  if (Error.captureStackTrace) {
632
- Error.captureStackTrace(_assertThisInitialized(_this9), ConflictError);
438
+ Error.captureStackTrace(_this9, ConflictError);
633
439
  }
634
-
635
440
  _this9.name = 'ConflictError';
636
441
  _this9.baseResponse = baseResponse;
637
442
  return _this9;
638
443
  }
639
-
640
- return ConflictError;
444
+ _inherits(ConflictError, _BadRequestError5);
445
+ return _createClass(ConflictError);
641
446
  }(BadRequestError); // 500
642
-
643
-
644
- var InternalServerError = /*#__PURE__*/function (_HttpError2) {
645
- _inherits(InternalServerError, _HttpError2);
646
-
647
- var _super10 = _createSuper(InternalServerError);
648
-
447
+ var InternalServerError = /*#__PURE__*/function (_HttpError3) {
649
448
  function InternalServerError(message, baseResponse) {
650
- var _this10;
651
-
449
+ var _this0;
652
450
  _classCallCheck(this, InternalServerError);
451
+ _this0 = _callSuper(this, InternalServerError, [message || 'Internal server error', baseResponse]);
653
452
 
654
- _this10 = _super10.call(this, message || 'Internal server error', baseResponse); // Set the prototype explicitly.
655
-
656
- _defineProperty(_assertThisInitialized(_this10), "baseResponse", void 0);
657
-
658
- Object.setPrototypeOf(_assertThisInitialized(_this10), InternalServerError.prototype); // Maintains proper stack trace for where our error was thrown (only available on V8)
453
+ // Set the prototype explicitly.
454
+ _defineProperty(_this0, "baseResponse", void 0);
455
+ Object.setPrototypeOf(_this0, InternalServerError.prototype);
659
456
 
457
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
660
458
  if (Error.captureStackTrace) {
661
- Error.captureStackTrace(_assertThisInitialized(_this10), InternalServerError);
459
+ Error.captureStackTrace(_this0, InternalServerError);
662
460
  }
663
-
664
- _this10.name = 'InternalServerError';
665
- _this10.baseResponse = baseResponse;
666
- return _this10;
461
+ _this0.name = 'InternalServerError';
462
+ _this0.baseResponse = baseResponse;
463
+ return _this0;
667
464
  }
668
-
669
- return InternalServerError;
465
+ _inherits(InternalServerError, _HttpError3);
466
+ return _createClass(InternalServerError);
670
467
  }(HttpError);
671
468
  /**
672
469
  * @returns {HttpError}
673
470
  */
674
-
675
-
676
471
  function getHttpErrorFromResponse(originalResponse) {
677
472
  var response = originalResponse.clone();
678
-
679
473
  switch (true) {
680
474
  case response.status === 401:
681
475
  return new UnauthorizedError(null, response);
682
-
683
476
  case response.status === 403:
684
477
  return new ForbiddenError(null, response);
685
-
686
478
  case response.status === 404:
687
479
  return new ResourceNotFoundError(null, response);
688
-
689
480
  case response.status === 409:
690
481
  return new ConflictError(null, response);
691
-
692
482
  case response.status >= 400 && response.status < 500:
693
483
  return new BadRequestError(null, response);
694
-
695
484
  case response.status >= 500 && response.status < 600:
696
485
  return new InternalServerError(null, response);
697
-
698
486
  default:
699
487
  return new HttpError(null, response);
700
488
  }
701
489
  }
702
-
703
490
  function isOauthError(body) {
704
- var _ref;
705
-
706
- return typeof ((_ref = body) === null || _ref === void 0 ? void 0 : _ref.error) === 'string';
491
+ return typeof (body === null || body === void 0 ? void 0 : body.error) === 'string';
707
492
  }
708
493
 
709
494
  var DEFAULT_CONFIG = {
710
495
  collectionKey: 'hydra:member'
711
496
  };
712
-
713
- var _config = new WeakMap();
714
-
715
- var _classMetadataList = new WeakMap();
716
-
497
+ var _config = /*#__PURE__*/new WeakMap();
498
+ var _classMetadataList = /*#__PURE__*/new WeakMap();
717
499
  var Mapping = /*#__PURE__*/function () {
718
500
  function Mapping() {
719
501
  var idPrefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
720
502
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
721
-
722
503
  _classCallCheck(this, Mapping);
723
-
724
504
  _defineProperty(this, "idPrefix", void 0);
725
-
726
- _config.set(this, {
727
- writable: true,
728
- value: void 0
729
- });
730
-
731
- _classMetadataList.set(this, {
732
- writable: true,
733
- value: void 0
734
- });
735
-
505
+ _classPrivateFieldInitSpec(this, _config, void 0);
506
+ _classPrivateFieldInitSpec(this, _classMetadataList, void 0);
736
507
  this.idPrefix = idPrefix;
737
-
738
- _classPrivateFieldSet(this, _classMetadataList, []);
739
-
508
+ _classPrivateFieldSet2(_classMetadataList, this, []);
740
509
  this.setConfig(config);
741
510
  }
742
-
743
- _createClass(Mapping, [{
511
+ return _createClass(Mapping, [{
744
512
  key: "getConfig",
745
513
  value: function getConfig() {
746
- return _classPrivateFieldGet(this, _config);
514
+ return _classPrivateFieldGet2(_config, this);
747
515
  }
748
516
  }, {
749
517
  key: "setConfig",
750
518
  value: function setConfig(config) {
751
- _classPrivateFieldSet(this, _config, _objectSpread2(_objectSpread2({}, DEFAULT_CONFIG), config));
519
+ _classPrivateFieldSet2(_config, this, _objectSpread2(_objectSpread2({}, DEFAULT_CONFIG), config));
752
520
  }
753
521
  }, {
754
522
  key: "setMapping",
755
523
  value: function setMapping() {
756
524
  var classMetadataList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
757
-
758
- _classPrivateFieldSet(this, _classMetadataList, classMetadataList);
525
+ _classPrivateFieldSet2(_classMetadataList, this, classMetadataList);
759
526
  }
760
527
  }, {
761
528
  key: "getMappingKeys",
762
529
  value: function getMappingKeys() {
763
- return _classPrivateFieldGet(this, _classMetadataList).map(function (classMetadata) {
530
+ return _classPrivateFieldGet2(_classMetadataList, this).map(function (classMetadata) {
764
531
  return classMetadata.key;
765
532
  });
766
533
  }
767
534
  }, {
768
535
  key: "getClassMetadataByKey",
769
536
  value: function getClassMetadataByKey(key) {
770
- var filterList = _classPrivateFieldGet(this, _classMetadataList).filter(function (classMetadata) {
537
+ var filterList = _classPrivateFieldGet2(_classMetadataList, this).filter(function (classMetadata) {
771
538
  return classMetadata.key === key;
772
539
  });
773
-
774
540
  return filterList.length > 0 ? filterList[0] : null;
775
541
  }
776
542
  }, {
777
543
  key: "isMappingValid",
778
544
  value: function isMappingValid() {
779
545
  var _this = this;
780
-
781
- return !_classPrivateFieldGet(this, _classMetadataList).some(function (classMetadata) {
546
+ return !_classPrivateFieldGet2(_classMetadataList, this).some(function (classMetadata) {
782
547
  // check that the relations exists
783
548
  var errorList = Object.values(classMetadata.getAttributeList()).map(function (attribute) {
784
549
  var relation = classMetadata.getRelation(attribute.serializedKey);
785
-
786
550
  if (!relation) {
787
551
  // attribute can not be "invalid" (for now ?)
788
552
  return false;
789
553
  }
554
+ var relationMetadata = _this.getClassMetadataByKey(relation.targetMetadataKey);
790
555
 
791
- var relationMetadata = _this.getClassMetadataByKey(relation.targetMetadataKey); // relation name seems weird
792
-
793
-
556
+ // relation name seems weird
794
557
  if (relation.isRelationToOne() && attribute.attributeName.endsWith('List')) {
795
558
  return "\"".concat(classMetadata.key, ".").concat(attribute.serializedKey, " is defined as a MANY_TO_ONE relation, but the attribute name ends with \"List\".");
796
559
  }
797
-
798
560
  if (relation.isRelationToMany()) {
799
561
  var message = "\"".concat(classMetadata.key, ".").concat(attribute.serializedKey, " is defined as a ").concat(relation.type, " relation, but the attribute name is nor plural not ends with \"List\".");
800
562
  var endsWithList = attribute.attributeName.endsWith('List');
801
-
802
563
  try {
803
- // eslint-disable-next-line global-require, import/no-extraneous-dependencies, @typescript-eslint/no-var-requires
564
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
804
565
  var pluralize = require('pluralize');
805
-
806
566
  if (!endsWithList && !pluralize.isPlural(attribute.attributeName)) {
807
567
  return message;
808
568
  }
809
- } catch (e) {
569
+ } catch (_unused) {
810
570
  if (!endsWithList) {
811
571
  return "".concat(message, ".\nIf your keys does not ends with \"List\", then you should install the \"pluralize\" package.");
812
572
  }
813
573
  }
814
- } // no error if there is metadata linked
815
-
574
+ }
816
575
 
576
+ // no error if there is metadata linked
817
577
  if (!relationMetadata) {
818
578
  return "\"".concat(classMetadata.key, ".").concat(attribute.serializedKey, "\" defined a relation to the metadata named \"").concat(relation.targetMetadataKey, "\" but this metadata is not knowned by the mapping");
819
579
  }
820
-
821
580
  return false;
822
581
  });
823
-
824
582
  if (!classMetadata.hasIdentifierAttribute()) {
825
583
  errorList.push("\"".concat(classMetadata.key, "\" has no identifier attribute set"));
826
584
  }
827
-
828
585
  var nbError = errorList.filter(function (error) {
829
586
  if (error) {
830
- // eslint-disable-next-line no-console
831
587
  console.warn(error);
832
588
  }
833
-
834
589
  return error;
835
590
  });
836
591
  return nbError.length > 0;
837
592
  });
838
593
  }
839
594
  }]);
840
-
841
- return Mapping;
842
595
  }();
843
596
 
844
- var Attribute =
597
+ var Attribute = /*#__PURE__*/_createClass(
845
598
  /**
846
599
  * @param {string} serializedKey the key returned from your API
847
600
  * @param {null|string} attributeName the name in your entity, default to the `serializedKey` attribute
@@ -852,143 +605,104 @@ function Attribute(serializedKey) {
852
605
  var attributeName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
853
606
  var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'string';
854
607
  var isIdentifier = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
855
-
856
608
  _classCallCheck(this, Attribute);
857
-
858
609
  _defineProperty(this, "serializedKey", void 0);
859
-
860
610
  _defineProperty(this, "attributeName", void 0);
861
-
862
611
  _defineProperty(this, "type", void 0);
863
-
864
612
  _defineProperty(this, "isIdentifier", void 0);
865
-
866
613
  if (!serializedKey) {
867
614
  throw new TypeError('`serializedKey` must not be empty');
868
615
  }
869
-
870
616
  this.serializedKey = serializedKey;
871
617
  this.attributeName = attributeName || this.serializedKey;
872
618
  this.type = type;
873
619
  this.isIdentifier = isIdentifier;
874
- };
620
+ });
875
621
 
876
- /* eslint-disable import/prefer-default-export */
877
- // eslint-disable-next-line import/no-duplicates
878
- // eslint-disable-next-line import/no-duplicates
879
622
  function generateRepository(sdk, metadata) {
880
623
  var isUnitOfWorkEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
881
624
  // eslint-disable-next-line new-cap
882
625
  return new metadata.repositoryClass(sdk, metadata, isUnitOfWorkEnabled);
883
626
  }
884
627
 
885
- /* eslint-disable consistent-return */
886
628
  function removeAuthorization(headers) {
887
629
  if (!headers) {
888
630
  return;
889
631
  }
890
-
891
632
  if (headers instanceof Headers) {
892
633
  headers["delete"]('Authorization');
893
634
  return headers;
894
635
  }
895
-
896
636
  var filterAuthorization = function filterAuthorization(entries) {
897
637
  return entries.filter(function (header) {
898
638
  return header[0] !== 'Authorization';
899
639
  });
900
640
  };
901
-
902
641
  if (Array.isArray(headers)) {
903
642
  return filterAuthorization(headers);
904
643
  }
905
-
906
644
  return Object.fromEntries(filterAuthorization(Object.entries(headers)));
907
645
  }
646
+
908
647
  /**
909
648
  * remove undefined key, usefull to remove Content-Type for example.
910
649
  * Does not apply on "Headers" instance as values are string in there.
911
650
  */
912
-
913
651
  function removeUndefinedHeaders(headers) {
914
652
  if (headers instanceof Headers) {
915
653
  return headers;
916
654
  }
917
-
918
655
  var filterEntries = function filterEntries(entries) {
919
656
  return entries.filter(function (header) {
920
657
  return header[1] !== undefined;
921
658
  });
922
659
  };
923
-
924
660
  if (Array.isArray(headers)) {
925
661
  return filterEntries(headers);
926
662
  }
927
-
928
663
  return Object.fromEntries(filterEntries(Object.entries(headers)));
929
664
  }
930
665
  function convertToRecord(headers) {
931
666
  if (headers instanceof Headers) {
932
667
  return Object.fromEntries(headers.entries());
933
668
  }
934
-
935
669
  if (Array.isArray(headers)) {
936
670
  return Object.fromEntries(headers);
937
671
  }
938
-
939
672
  return headers;
940
673
  }
941
674
 
675
+ var _excluded = ["headers"];
942
676
  var EXPIRE_LIMIT_SECONDS = 300; // = 5 minutes
943
-
944
- var _tokenStorage = new WeakMap();
945
-
946
- var _isUnitOfWorkEnabled = new WeakMap();
947
-
677
+ var _tokenStorage = /*#__PURE__*/new WeakMap();
678
+ var _isUnitOfWorkEnabled = /*#__PURE__*/new WeakMap();
948
679
  var AbstractClient = /*#__PURE__*/function () {
949
680
  function AbstractClient(sdk, metadata) {
950
681
  var isUnitOfWorkEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
951
-
952
682
  _classCallCheck(this, AbstractClient);
953
-
954
683
  _defineProperty(this, "sdk", void 0);
955
-
956
- _tokenStorage.set(this, {
957
- writable: true,
958
- value: void 0
959
- });
960
-
684
+ _classPrivateFieldInitSpec(this, _tokenStorage, void 0);
961
685
  _defineProperty(this, "serializer", void 0);
962
-
963
686
  _defineProperty(this, "metadata", void 0);
964
-
965
- _isUnitOfWorkEnabled.set(this, {
966
- writable: true,
967
- value: void 0
968
- });
969
-
687
+ _classPrivateFieldInitSpec(this, _isUnitOfWorkEnabled, void 0);
970
688
  this.sdk = sdk;
971
-
972
- _classPrivateFieldSet(this, _tokenStorage, sdk.tokenStorage);
973
-
689
+ _classPrivateFieldSet2(_tokenStorage, this, sdk.tokenStorage);
974
690
  this.serializer = sdk.serializer;
975
691
  this.metadata = metadata;
976
-
977
- _classPrivateFieldSet(this, _isUnitOfWorkEnabled, isUnitOfWorkEnabled);
692
+ _classPrivateFieldSet2(_isUnitOfWorkEnabled, this, isUnitOfWorkEnabled);
978
693
  }
979
-
980
- _createClass(AbstractClient, [{
694
+ return _createClass(AbstractClient, [{
981
695
  key: "withUnitOfWork",
982
696
  value: function withUnitOfWork(enabled) {
983
- // eslint-disable-next-line new-cap
984
697
  return generateRepository(this.sdk, this.metadata, enabled);
985
698
  }
986
699
  }, {
987
700
  key: "getDefaultParameters",
988
701
  value: function getDefaultParameters() {
989
702
  return {};
990
- } // eslint-disable-next-line @typescript-eslint/no-unused-vars
703
+ }
991
704
 
705
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
992
706
  }, {
993
707
  key: "getPathBase",
994
708
  value: function getPathBase(pathParameters) {
@@ -998,11 +712,9 @@ var AbstractClient = /*#__PURE__*/function () {
998
712
  key: "getEntityURI",
999
713
  value: function getEntityURI(entity) {
1000
714
  var idValue = this._getEntityIdentifier(entity);
1001
-
1002
715
  if (idValue === null) {
1003
716
  throw new Error('Cannot call `getEntityURI for entity without id.`');
1004
717
  }
1005
-
1006
718
  if (typeof idValue === 'number') {
1007
719
  if (Number.isFinite(idValue)) {
1008
720
  idValue = idValue.toString();
@@ -1010,15 +722,13 @@ var AbstractClient = /*#__PURE__*/function () {
1010
722
  throw new Error('Unable to handle non-finite number');
1011
723
  }
1012
724
  }
1013
-
1014
725
  var pathBase = this.getPathBase({});
1015
-
1016
726
  if (idValue.indexOf(pathBase) > -1) {
1017
727
  return idValue;
1018
728
  }
1019
-
1020
729
  return "".concat(pathBase, "/").concat(idValue);
1021
730
  }
731
+
1022
732
  /**
1023
733
  * get an entity by its id
1024
734
  *
@@ -1027,18 +737,16 @@ var AbstractClient = /*#__PURE__*/function () {
1027
737
  * @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
1028
738
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1029
739
  */
1030
-
1031
740
  }, {
1032
741
  key: "find",
1033
742
  value: function find(id) {
1034
743
  var queryParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1035
744
  var pathParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1036
745
  var requestParams = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1037
-
1038
746
  var url = this._generateUrlFromParams(queryParam, pathParameters, id);
1039
-
1040
747
  return this.deserializeResponse(this.authorizedFetch(url, requestParams), 'item');
1041
748
  }
749
+
1042
750
  /**
1043
751
  * get a list of entities by some parameters
1044
752
  *
@@ -1046,17 +754,15 @@ var AbstractClient = /*#__PURE__*/function () {
1046
754
  * @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
1047
755
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1048
756
  */
1049
-
1050
757
  }, {
1051
758
  key: "findBy",
1052
759
  value: function findBy(queryParam) {
1053
760
  var pathParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1054
761
  var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1055
-
1056
762
  var url = this._generateUrlFromParams(queryParam, pathParameters);
1057
-
1058
763
  return this.deserializeResponse(this.authorizedFetch(url, requestParams), 'list');
1059
764
  }
765
+
1060
766
  /**
1061
767
  * get a list of all entities
1062
768
  *
@@ -1064,7 +770,6 @@ var AbstractClient = /*#__PURE__*/function () {
1064
770
  * @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
1065
771
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1066
772
  */
1067
-
1068
773
  }, {
1069
774
  key: "findAll",
1070
775
  value: function findAll() {
@@ -1073,6 +778,7 @@ var AbstractClient = /*#__PURE__*/function () {
1073
778
  var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1074
779
  return this.findBy(queryParam, pathParameters, requestParams);
1075
780
  }
781
+
1076
782
  /**
1077
783
  * create an entity
1078
784
  *
@@ -1081,7 +787,6 @@ var AbstractClient = /*#__PURE__*/function () {
1081
787
  * @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method
1082
788
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1083
789
  */
1084
-
1085
790
  }, {
1086
791
  key: "create",
1087
792
  value: function create(entity) {
@@ -1098,6 +803,7 @@ var AbstractClient = /*#__PURE__*/function () {
1098
803
  body: this.serializer.encodeItem(diff, this.metadata)
1099
804
  }, requestParams)), 'item');
1100
805
  }
806
+
1101
807
  /**
1102
808
  * update an entity
1103
809
  *
@@ -1105,7 +811,6 @@ var AbstractClient = /*#__PURE__*/function () {
1105
811
  * @param {Record<string, unknown>} queryParam query parameters that will be added to the request
1106
812
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1107
813
  */
1108
-
1109
814
  }, {
1110
815
  key: "update",
1111
816
  value: function update(entity) {
@@ -1113,6 +818,7 @@ var AbstractClient = /*#__PURE__*/function () {
1113
818
  var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1114
819
  return this._update('PUT', entity, queryParam, requestParams);
1115
820
  }
821
+
1116
822
  /**
1117
823
  * partially update an entity using the `PATCH` HTTP verb
1118
824
  *
@@ -1120,7 +826,6 @@ var AbstractClient = /*#__PURE__*/function () {
1120
826
  * @param {Record<string, unknown>} queryParam query parameters that will be added to the request
1121
827
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1122
828
  */
1123
-
1124
829
  }, {
1125
830
  key: "patch",
1126
831
  value: function patch(entity) {
@@ -1136,48 +841,39 @@ var AbstractClient = /*#__PURE__*/function () {
1136
841
  var url = new URI(this.getEntityURI(entity));
1137
842
  url.addSearch(queryParam);
1138
843
  var newSerializedModel = this.serializer.normalizeItem(entity, this.metadata);
1139
-
1140
844
  var identifier = this._getEntityIdentifier(newSerializedModel);
1141
-
1142
845
  var oldModel;
1143
-
1144
846
  if (identifier !== null) {
1145
847
  oldModel = this.sdk.unitOfWork.getDirtyEntity(identifier);
1146
848
  }
1147
-
1148
849
  if (oldModel) {
1149
850
  newSerializedModel = this.sdk.unitOfWork.getDirtyData(newSerializedModel, oldModel, this.metadata);
1150
851
  }
1151
-
1152
852
  return this.deserializeResponse(this.authorizedFetch(url, _objectSpread2({
1153
853
  method: method,
1154
854
  body: this.serializer.encodeItem(newSerializedModel, this.metadata)
1155
855
  }, requestParams)), 'item');
1156
856
  }
857
+
1157
858
  /**
1158
859
  * delete an entity
1159
860
  *
1160
861
  * @param {Record<string, unknown>} the entity to delete
1161
862
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1162
863
  */
1163
-
1164
864
  }, {
1165
865
  key: "delete",
1166
866
  value: function _delete(entity) {
1167
867
  var _this = this;
1168
-
1169
868
  var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1170
869
  var url = this.getEntityURI(entity);
1171
-
1172
870
  var identifier = this._getEntityIdentifier(entity);
1173
-
1174
871
  return this.authorizedFetch(url, _objectSpread2({
1175
872
  method: 'DELETE'
1176
873
  }, requestParams)).then(function (response) {
1177
874
  if (identifier !== null) {
1178
875
  _this.sdk.unitOfWork.clear(identifier);
1179
876
  }
1180
-
1181
877
  return response;
1182
878
  });
1183
879
  }
@@ -1185,7 +881,6 @@ var AbstractClient = /*#__PURE__*/function () {
1185
881
  key: "deserializeResponse",
1186
882
  value: function deserializeResponse(requestPromise, listOrItem) {
1187
883
  var _this2 = this;
1188
-
1189
884
  return requestPromise.then(function (response) {
1190
885
  return response.text().then(function (text) {
1191
886
  return {
@@ -1195,26 +890,20 @@ var AbstractClient = /*#__PURE__*/function () {
1195
890
  });
1196
891
  }).then(function (_ref) {
1197
892
  var response = _ref.response,
1198
- text = _ref.text;
1199
-
893
+ text = _ref.text;
1200
894
  if (listOrItem === 'list') {
1201
895
  // for list, we need to deserialize the result to get an object
1202
896
  var itemList = _this2.serializer.deserializeList(text, _this2.metadata, response);
1203
-
1204
- if (_classPrivateFieldGet(_this2, _isUnitOfWorkEnabled)) {
1205
- // eslint-disable-next-line no-restricted-syntax
897
+ if (_classPrivateFieldGet2(_isUnitOfWorkEnabled, _this2)) {
1206
898
  var _iterator = _createForOfIteratorHelper(itemList),
1207
- _step;
1208
-
899
+ _step;
1209
900
  try {
1210
901
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
1211
902
  var _decodedItem = _step.value;
1212
-
1213
903
  var _identifier = _this2._getEntityIdentifier(_decodedItem);
904
+ var normalizedItem = _this2.serializer.normalizeItem(_decodedItem, _this2.metadata);
1214
905
 
1215
- var normalizedItem = _this2.serializer.normalizeItem(_decodedItem, _this2.metadata); // then we register the re-normalized item
1216
-
1217
-
906
+ // then we register the re-normalized item
1218
907
  if (_identifier !== null) {
1219
908
  _this2.sdk.unitOfWork.registerClean(_identifier, normalizedItem);
1220
909
  }
@@ -1225,23 +914,20 @@ var AbstractClient = /*#__PURE__*/function () {
1225
914
  _iterator.f();
1226
915
  }
1227
916
  }
1228
-
1229
917
  return itemList;
1230
- } // for items, we can just decode the item (ie. transform it to JS object)
1231
-
1232
-
1233
- var decodedItem = _this2.serializer.decodeItem(text, _this2.metadata, response); // and register it directy without deserializing + renormalizing
1234
-
918
+ }
1235
919
 
1236
- var identifier = _this2._getEntityIdentifier(decodedItem); // and finally return the denormalized item
920
+ // for items, we can just decode the item (ie. transform it to JS object)
921
+ var decodedItem = _this2.serializer.decodeItem(text, _this2.metadata, response);
1237
922
 
923
+ // and register it directy without deserializing + renormalizing
924
+ var identifier = _this2._getEntityIdentifier(decodedItem);
1238
925
 
926
+ // and finally return the denormalized item
1239
927
  var item = _this2.serializer.denormalizeItem(decodedItem, _this2.metadata, response);
1240
-
1241
- if (_classPrivateFieldGet(_this2, _isUnitOfWorkEnabled) && identifier !== null) {
928
+ if (_classPrivateFieldGet2(_isUnitOfWorkEnabled, _this2) && identifier !== null) {
1242
929
  _this2.sdk.unitOfWork.registerClean(identifier, _this2.serializer.normalizeItem(item, _this2.metadata));
1243
930
  }
1244
-
1245
931
  return item;
1246
932
  });
1247
933
  }
@@ -1250,20 +936,16 @@ var AbstractClient = /*#__PURE__*/function () {
1250
936
  value: function makeUri(input) {
1251
937
  var url = input instanceof URI ? input : new URI(input);
1252
938
  url.host(this.sdk.config.path).scheme(this.sdk.config.scheme);
1253
-
1254
939
  if (this.sdk.config.port) {
1255
940
  url.port(String(this.sdk.config.port));
1256
941
  }
1257
-
1258
942
  if (this.sdk.mapping.idPrefix) {
1259
943
  var segments = url.segment();
1260
-
1261
944
  if (!url.pathname().startsWith(this.sdk.mapping.idPrefix)) {
1262
945
  segments.unshift(this.sdk.mapping.idPrefix);
1263
946
  url.segment(segments);
1264
947
  }
1265
948
  }
1266
-
1267
949
  return url;
1268
950
  }
1269
951
  }, {
@@ -1279,17 +961,13 @@ var AbstractClient = /*#__PURE__*/function () {
1279
961
  var pathParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1280
962
  var id = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1281
963
  var params = queryParam;
1282
-
1283
964
  if (this.sdk.config.useDefaultParameters) {
1284
965
  Object.assign(params, this.getDefaultParameters());
1285
966
  }
1286
-
1287
967
  var pathBase = this.getPathBase(pathParameters);
1288
- var url = null;
1289
-
968
+ var url;
1290
969
  if (id) {
1291
970
  var testPathBase = this.sdk.mapping.idPrefix ? "".concat(this.sdk.mapping.idPrefix).concat(pathBase) : pathBase;
1292
-
1293
971
  if (typeof id === 'string' && id.startsWith(testPathBase)) {
1294
972
  url = new URI(id);
1295
973
  } else {
@@ -1298,63 +976,51 @@ var AbstractClient = /*#__PURE__*/function () {
1298
976
  } else {
1299
977
  url = new URI(pathBase);
1300
978
  }
1301
-
1302
979
  if (params) {
1303
980
  url.addSearch(params);
1304
981
  }
1305
-
1306
982
  return url;
1307
983
  }
1308
984
  }, {
1309
985
  key: "_fetchWithToken",
1310
986
  value: function _fetchWithToken(input) {
1311
987
  var _this3 = this;
1312
-
1313
988
  var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1314
-
1315
989
  if (!input) {
1316
990
  throw new Error('input is empty');
1317
991
  }
1318
-
1319
- if (_classPrivateFieldGet(this, _tokenStorage)) {
1320
- return _classPrivateFieldGet(this, _tokenStorage).getCurrentTokenExpiresIn().then(function (accessTokenExpiresIn) {
992
+ if (_classPrivateFieldGet2(_tokenStorage, this)) {
993
+ return _classPrivateFieldGet2(_tokenStorage, this).getCurrentTokenExpiresIn().then(function (accessTokenExpiresIn) {
1321
994
  if (accessTokenExpiresIn !== null && accessTokenExpiresIn <= EXPIRE_LIMIT_SECONDS) {
1322
- return _classPrivateFieldGet(_this3, _tokenStorage).refreshToken().then(function (refreshedTokenObject) {
995
+ return _classPrivateFieldGet2(_tokenStorage, _this3).refreshToken().then(function (refreshedTokenObject) {
1323
996
  return refreshedTokenObject.access_token;
1324
997
  })["catch"](function (e) {
1325
998
  _this3._handleRefreshTokenFailure(e);
1326
-
1327
999
  throw e;
1328
1000
  });
1329
1001
  }
1330
-
1331
- return _classPrivateFieldGet(_this3, _tokenStorage).getAccessToken();
1002
+ return _classPrivateFieldGet2(_tokenStorage, _this3).getAccessToken();
1332
1003
  }).then(function (token) {
1333
1004
  return _this3._doFetch(token, input, requestParams);
1334
1005
  });
1335
1006
  }
1336
-
1337
1007
  return this._doFetch(null, input, requestParams);
1338
1008
  }
1339
1009
  }, {
1340
1010
  key: "_refreshTokenAndRefetch",
1341
1011
  value: function _refreshTokenAndRefetch(input) {
1342
1012
  var _this4 = this;
1343
-
1344
1013
  var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1345
- return _classPrivateFieldGet(this, _tokenStorage).refreshToken().then(function () {
1014
+ return _classPrivateFieldGet2(_tokenStorage, this).refreshToken().then(function () {
1346
1015
  // eslint-disable-next-line prefer-const
1347
1016
  var headers = requestParams.headers,
1348
- rest = _objectWithoutProperties(requestParams, ["headers"]);
1349
-
1017
+ rest = _objectWithoutProperties(requestParams, _excluded);
1350
1018
  var updatedRequestParams = _objectSpread2(_objectSpread2({}, rest), {}, {
1351
1019
  headers: removeAuthorization(headers)
1352
1020
  });
1353
-
1354
1021
  return _this4._fetchWithToken(input, updatedRequestParams);
1355
1022
  })["catch"](function (e) {
1356
1023
  _this4._handleRefreshTokenFailure(e);
1357
-
1358
1024
  throw e;
1359
1025
  });
1360
1026
  }
@@ -1362,33 +1028,28 @@ var AbstractClient = /*#__PURE__*/function () {
1362
1028
  key: "_manageUnauthorized",
1363
1029
  value: function _manageUnauthorized(response, input) {
1364
1030
  var _this5 = this;
1365
-
1366
1031
  var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1367
- var error = getHttpErrorFromResponse(response); // https://tools.ietf.org/html/rfc2617#section-1.2
1032
+ var error = getHttpErrorFromResponse(response);
1368
1033
 
1034
+ // https://tools.ietf.org/html/rfc2617#section-1.2
1369
1035
  var authorizationHeader = response.headers.get('www-authenticate');
1370
-
1371
1036
  if (authorizationHeader) {
1372
1037
  var invalidGrant = authorizationHeader.indexOf('error="invalid_grant"') > -1;
1373
-
1374
- if (invalidGrant && _classPrivateFieldGet(this, _tokenStorage)) {
1038
+ if (invalidGrant && _classPrivateFieldGet2(_tokenStorage, this)) {
1375
1039
  return this._refreshTokenAndRefetch(input, requestParams);
1376
1040
  }
1377
-
1378
1041
  throw error;
1379
1042
  } else {
1380
1043
  // if www-authenticate header is missing, try and read json response
1381
1044
  return response.json().then(function (body) {
1382
- if (_classPrivateFieldGet(_this5, _tokenStorage) && (body.error === 'invalid_scope' || body.error === 'access_denied')) {
1045
+ if (_classPrivateFieldGet2(_tokenStorage, _this5) && (body.error === 'invalid_scope' || body.error === 'access_denied')) {
1383
1046
  return _this5._refreshTokenAndRefetch(input, requestParams);
1384
1047
  }
1385
-
1386
1048
  throw error;
1387
1049
  })["catch"](function (err) {
1388
1050
  if (err instanceof OauthError) {
1389
1051
  throw err;
1390
1052
  }
1391
-
1392
1053
  throw error;
1393
1054
  });
1394
1055
  }
@@ -1397,58 +1058,45 @@ var AbstractClient = /*#__PURE__*/function () {
1397
1058
  key: "_doFetch",
1398
1059
  value: function _doFetch(accessToken, input, requestParams) {
1399
1060
  var _this6 = this;
1400
-
1401
1061
  var params = requestParams;
1402
1062
  var baseHeaders = {};
1403
-
1404
1063
  if (params.method !== 'GET' || params.method !== 'GET' && params.method !== 'DELETE') {
1405
1064
  baseHeaders = {
1406
1065
  'Content-Type': 'application/json'
1407
1066
  };
1408
1067
  }
1409
-
1410
1068
  if (accessToken) {
1411
1069
  baseHeaders.Authorization = "".concat(this.sdk.config.authorizationType, " ").concat(accessToken);
1412
1070
  }
1413
-
1414
1071
  if (params) {
1415
1072
  if (!params.headers) {
1416
1073
  params.headers = {};
1417
1074
  }
1418
-
1419
1075
  params.headers = Object.assign(baseHeaders, params.headers);
1420
1076
  } else {
1421
1077
  params = {
1422
1078
  headers: baseHeaders
1423
1079
  };
1424
1080
  }
1425
-
1426
1081
  if (params.headers) {
1427
1082
  params.headers = removeUndefinedHeaders(params.headers);
1428
1083
  }
1429
-
1430
1084
  var logId;
1431
-
1432
1085
  if (this.sdk.logger) {
1433
1086
  logId = this.sdk.logger.logRequest(_objectSpread2({
1434
1087
  url: input
1435
1088
  }, params));
1436
- } // eslint-disable-next-line consistent-return
1437
-
1438
-
1089
+ }
1439
1090
  return fetch(input, params).then(function (response) {
1440
1091
  if (_this6.sdk.logger) {
1441
1092
  _this6.sdk.logger.logResponse(response, logId);
1442
1093
  }
1443
-
1444
1094
  if (response.status < 400) {
1445
1095
  return response;
1446
1096
  }
1447
-
1448
1097
  if (response.status === 401) {
1449
1098
  return _this6._manageUnauthorized(response, input, params);
1450
1099
  }
1451
-
1452
1100
  var httpError = getHttpErrorFromResponse(response);
1453
1101
  throw httpError;
1454
1102
  });
@@ -1456,18 +1104,18 @@ var AbstractClient = /*#__PURE__*/function () {
1456
1104
  }, {
1457
1105
  key: "_getEntityIdentifier",
1458
1106
  value: function _getEntityIdentifier(object) {
1459
- var idKey = this.metadata.getIdentifierAttribute().serializedKey; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1460
- // @ts-ignore
1107
+ var idKey = this.metadata.getIdentifierAttribute().serializedKey;
1461
1108
 
1109
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1110
+ // @ts-ignore
1462
1111
  return object[idKey];
1463
1112
  }
1464
1113
  }, {
1465
1114
  key: "_handleRefreshTokenFailure",
1466
1115
  value: function _handleRefreshTokenFailure(error) {
1467
1116
  var _this7 = this;
1468
-
1469
1117
  if (error instanceof OauthError) {
1470
- _classPrivateFieldGet(this, _tokenStorage).logout().then(function () {
1118
+ _classPrivateFieldGet2(_tokenStorage, this).logout().then(function () {
1471
1119
  if (_this7.sdk.config.onRefreshTokenFailure) {
1472
1120
  _this7.sdk.config.onRefreshTokenFailure(error);
1473
1121
  }
@@ -1475,16 +1123,11 @@ var AbstractClient = /*#__PURE__*/function () {
1475
1123
  }
1476
1124
  }
1477
1125
  }]);
1478
-
1479
- return AbstractClient;
1480
1126
  }();
1481
1127
 
1482
- var _attributeList = new WeakMap();
1483
-
1484
- var _relationList = new WeakMap();
1485
-
1486
- var _identifierAttribute = new WeakMap();
1487
-
1128
+ var _attributeList = /*#__PURE__*/new WeakMap();
1129
+ var _relationList = /*#__PURE__*/new WeakMap();
1130
+ var _identifierAttribute = /*#__PURE__*/new WeakMap();
1488
1131
  var ClassMetadata = /*#__PURE__*/function () {
1489
1132
  /**
1490
1133
  * @param {string} key mandatory, will be passed in your serializer
@@ -1494,86 +1137,59 @@ var ClassMetadata = /*#__PURE__*/function () {
1494
1137
  function ClassMetadata(key) {
1495
1138
  var pathRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1496
1139
  var repositoryClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : AbstractClient;
1497
-
1498
1140
  _classCallCheck(this, ClassMetadata);
1499
-
1500
1141
  _defineProperty(this, "key", void 0);
1501
-
1502
1142
  _defineProperty(this, "pathRoot", void 0);
1503
-
1504
1143
  _defineProperty(this, "repositoryClass", void 0);
1505
-
1506
- _attributeList.set(this, {
1507
- writable: true,
1508
- value: void 0
1509
- });
1510
-
1511
- _relationList.set(this, {
1512
- writable: true,
1513
- value: void 0
1514
- });
1515
-
1516
- _identifierAttribute.set(this, {
1517
- writable: true,
1518
- value: void 0
1519
- });
1520
-
1144
+ _classPrivateFieldInitSpec(this, _attributeList, void 0);
1145
+ _classPrivateFieldInitSpec(this, _relationList, void 0);
1146
+ _classPrivateFieldInitSpec(this, _identifierAttribute, void 0);
1521
1147
  if (!key) {
1522
1148
  throw new TypeError('key attribute are required');
1523
1149
  }
1524
-
1525
1150
  this.key = key;
1526
- this.pathRoot = pathRoot || key; // this.modelName = modelName;
1527
-
1151
+ this.pathRoot = pathRoot || key;
1152
+ // this.modelName = modelName;
1528
1153
  this.repositoryClass = repositoryClass;
1529
-
1530
- _classPrivateFieldSet(this, _attributeList, {});
1531
-
1532
- _classPrivateFieldSet(this, _relationList, {});
1154
+ _classPrivateFieldSet2(_attributeList, this, {});
1155
+ _classPrivateFieldSet2(_relationList, this, {});
1533
1156
  }
1534
-
1535
- _createClass(ClassMetadata, [{
1157
+ return _createClass(ClassMetadata, [{
1536
1158
  key: "getAttribute",
1537
1159
  value: function getAttribute(name) {
1538
- return _classPrivateFieldGet(this, _attributeList)[name];
1160
+ return _classPrivateFieldGet2(_attributeList, this)[name];
1539
1161
  }
1540
1162
  }, {
1541
1163
  key: "hasIdentifierAttribute",
1542
1164
  value: function hasIdentifierAttribute() {
1543
- return !!_classPrivateFieldGet(this, _identifierAttribute);
1165
+ return !!_classPrivateFieldGet2(_identifierAttribute, this);
1544
1166
  }
1545
1167
  }, {
1546
1168
  key: "getIdentifierAttribute",
1547
1169
  value: function getIdentifierAttribute() {
1548
- if (!_classPrivateFieldGet(this, _identifierAttribute)) {
1170
+ if (!_classPrivateFieldGet2(_identifierAttribute, this)) {
1549
1171
  throw new TypeError("\"".concat(this.key, "\" has no identifier attribute set. Did you call \"setAttributeList\" first ?"));
1550
1172
  }
1551
-
1552
- return _classPrivateFieldGet(this, _identifierAttribute);
1173
+ return _classPrivateFieldGet2(_identifierAttribute, this);
1553
1174
  }
1554
1175
  }, {
1555
1176
  key: "getAttributeList",
1556
1177
  value: function getAttributeList() {
1557
- return _classPrivateFieldGet(this, _attributeList);
1178
+ return _classPrivateFieldGet2(_attributeList, this);
1558
1179
  }
1559
1180
  }, {
1560
1181
  key: "setAttributeList",
1561
1182
  value: function setAttributeList(attributeList) {
1562
1183
  var _this = this;
1563
-
1564
- _classPrivateFieldSet(this, _attributeList, {});
1565
-
1566
- _classPrivateFieldSet(this, _identifierAttribute, undefined);
1567
-
1184
+ _classPrivateFieldSet2(_attributeList, this, {});
1185
+ _classPrivateFieldSet2(_identifierAttribute, this, undefined);
1568
1186
  attributeList.forEach(function (attribute) {
1569
- _classPrivateFieldGet(_this, _attributeList)[attribute.serializedKey] = attribute;
1570
-
1187
+ _classPrivateFieldGet2(_attributeList, _this)[attribute.serializedKey] = attribute;
1571
1188
  if (attribute.isIdentifier) {
1572
- _classPrivateFieldSet(_this, _identifierAttribute, attribute);
1189
+ _classPrivateFieldSet2(_identifierAttribute, _this, attribute);
1573
1190
  }
1574
1191
  });
1575
-
1576
- if (!_classPrivateFieldGet(this, _identifierAttribute)) {
1192
+ if (!_classPrivateFieldGet2(_identifierAttribute, this)) {
1577
1193
  throw new TypeError("\"".concat(this.key, "\" has no identifier attribute set. You must set all your attributes in one time and send an attribute with \"isIdentifier=true\""));
1578
1194
  }
1579
1195
  }
@@ -1581,31 +1197,27 @@ var ClassMetadata = /*#__PURE__*/function () {
1581
1197
  key: "setRelationList",
1582
1198
  value: function setRelationList(relationList) {
1583
1199
  var _this2 = this;
1584
-
1585
- _classPrivateFieldSet(this, _relationList, {});
1586
-
1200
+ _classPrivateFieldSet2(_relationList, this, {});
1587
1201
  relationList.forEach(function (relation) {
1588
- _classPrivateFieldGet(_this2, _relationList)[relation.serializedKey] = relation;
1589
- _classPrivateFieldGet(_this2, _attributeList)[relation.serializedKey] = new Attribute(relation.serializedKey, relation.serializedKey, relation.isRelationToMany() ? 'array' : 'object');
1202
+ _classPrivateFieldGet2(_relationList, _this2)[relation.serializedKey] = relation;
1203
+ _classPrivateFieldGet2(_attributeList, _this2)[relation.serializedKey] = new Attribute(relation.serializedKey, relation.serializedKey, relation.isRelationToMany() ? 'array' : 'object');
1590
1204
  });
1591
1205
  }
1592
1206
  }, {
1593
1207
  key: "getRelation",
1594
1208
  value: function getRelation(key) {
1595
- return _classPrivateFieldGet(this, _relationList)[key];
1209
+ return _classPrivateFieldGet2(_relationList, this)[key];
1596
1210
  }
1597
1211
  }, {
1598
1212
  key: "getDefaultSerializedModel",
1599
1213
  value: function getDefaultSerializedModel() {
1600
1214
  var _this3 = this;
1601
-
1602
1215
  var out = {};
1603
- Object.keys(_classPrivateFieldGet(this, _attributeList)).forEach(function (serializedKey) {
1216
+ Object.keys(_classPrivateFieldGet2(_attributeList, this)).forEach(function (serializedKey) {
1604
1217
  out[serializedKey] = null;
1605
1218
  });
1606
- Object.keys(_classPrivateFieldGet(this, _relationList)).forEach(function (serializedKey) {
1607
- var relation = _classPrivateFieldGet(_this3, _relationList)[serializedKey];
1608
-
1219
+ Object.keys(_classPrivateFieldGet2(_relationList, this)).forEach(function (serializedKey) {
1220
+ var relation = _classPrivateFieldGet2(_relationList, _this3)[serializedKey];
1609
1221
  if (relation.isRelationToMany()) {
1610
1222
  out[serializedKey] = [];
1611
1223
  }
@@ -1613,19 +1225,15 @@ var ClassMetadata = /*#__PURE__*/function () {
1613
1225
  return out;
1614
1226
  }
1615
1227
  }]);
1616
-
1617
- return ClassMetadata;
1618
1228
  }();
1619
1229
 
1620
- var RelationTypes;
1621
-
1622
- (function (RelationTypes) {
1230
+ var RelationTypes = /*#__PURE__*/function (RelationTypes) {
1623
1231
  RelationTypes["ONE_TO_ONE"] = "ONE_TO_ONE";
1624
1232
  RelationTypes["ONE_TO_MANY"] = "ONE_TO_MANY";
1625
1233
  RelationTypes["MANY_TO_MANY"] = "MANY_TO_MANY";
1626
1234
  RelationTypes["MANY_TO_ONE"] = "MANY_TO_ONE";
1627
- })(RelationTypes || (RelationTypes = {}));
1628
-
1235
+ return RelationTypes;
1236
+ }(RelationTypes || {});
1629
1237
  var Relation = /*#__PURE__*/function () {
1630
1238
  /**
1631
1239
  * @param {RelationTypes} type the type of relation
@@ -1635,24 +1243,17 @@ var Relation = /*#__PURE__*/function () {
1635
1243
  */
1636
1244
  function Relation(type, targetMetadataKey, serializedKey) {
1637
1245
  var attributeName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1638
-
1639
1246
  _classCallCheck(this, Relation);
1640
-
1641
1247
  _defineProperty(this, "type", void 0);
1642
-
1643
1248
  _defineProperty(this, "targetMetadataKey", void 0);
1644
-
1645
1249
  _defineProperty(this, "serializedKey", void 0);
1646
-
1647
1250
  _defineProperty(this, "attributeName", void 0);
1648
-
1649
1251
  this.type = type;
1650
1252
  this.targetMetadataKey = targetMetadataKey;
1651
1253
  this.serializedKey = serializedKey;
1652
1254
  this.attributeName = attributeName || this.serializedKey;
1653
1255
  }
1654
-
1655
- _createClass(Relation, [{
1256
+ return _createClass(Relation, [{
1656
1257
  key: "isOneToOne",
1657
1258
  value: function isOneToOne() {
1658
1259
  return this.type === Relation.ONE_TO_ONE;
@@ -1683,16 +1284,10 @@ var Relation = /*#__PURE__*/function () {
1683
1284
  return this.isManyToOne() || this.isOneToOne();
1684
1285
  }
1685
1286
  }]);
1686
-
1687
- return Relation;
1688
1287
  }();
1689
-
1690
1288
  _defineProperty(Relation, "ONE_TO_ONE", RelationTypes.ONE_TO_ONE);
1691
-
1692
1289
  _defineProperty(Relation, "ONE_TO_MANY", RelationTypes.ONE_TO_MANY);
1693
-
1694
1290
  _defineProperty(Relation, "MANY_TO_ONE", RelationTypes.MANY_TO_ONE);
1695
-
1696
1291
  _defineProperty(Relation, "MANY_TO_MANY", RelationTypes.MANY_TO_MANY);
1697
1292
 
1698
1293
  /* eslint-disable */
@@ -1705,6 +1300,7 @@ _defineProperty(Relation, "MANY_TO_MANY", RelationTypes.MANY_TO_MANY);
1705
1300
  * This source code is licensed under the MIT license found in the
1706
1301
  * LICENSE file in the root directory of this source tree.
1707
1302
  */
1303
+
1708
1304
  var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
1709
1305
  var IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@';
1710
1306
  function isImmutable(maybeImmutable) {
@@ -1724,112 +1320,87 @@ function objectDiffers(left, right) {
1724
1320
  var result = diff(left, right);
1725
1321
  return result ? result.length > 0 : false;
1726
1322
  }
1323
+
1727
1324
  /**
1728
1325
  * get the id of an entity or return itself if string
1729
1326
  */
1730
-
1731
-
1732
1327
  function getEntityId(stringOrEntity, idSerializedKey) {
1733
1328
  if (_typeof(stringOrEntity) !== 'object') {
1734
1329
  return stringOrEntity;
1735
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1736
- // @ts-ignore
1737
-
1330
+ }
1738
1331
 
1332
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1333
+ // @ts-ignore
1739
1334
  return stringOrEntity[idSerializedKey];
1740
1335
  }
1336
+
1741
1337
  /**
1742
1338
  * find old relation value from the new relation id
1743
1339
  * if not found, returs the default serilazed model
1744
1340
  */
1745
-
1746
-
1747
1341
  function findOldRelation(newRelationValue, oldRelationValue, classMetadata) {
1748
- var idSerializedKey = classMetadata.getIdentifierAttribute().serializedKey; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1342
+ var idSerializedKey = classMetadata.getIdentifierAttribute().serializedKey;
1343
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1749
1344
  // @ts-ignore
1750
-
1751
1345
  var relationValueId = getEntityId(newRelationValue, idSerializedKey);
1752
1346
  var foundValue = oldRelationValue && oldRelationValue.find(function (innerOldRelationValue) {
1753
1347
  var oldRelationValueId = getEntityId(innerOldRelationValue, idSerializedKey);
1754
1348
  return relationValueId === oldRelationValueId;
1755
1349
  });
1756
-
1757
1350
  if (foundValue) {
1758
1351
  return foundValue;
1759
1352
  }
1760
-
1761
1353
  return classMetadata.getDefaultSerializedModel();
1762
1354
  }
1355
+
1763
1356
  /**
1764
1357
  * add all identifier from one to many relation list
1765
1358
  */
1766
-
1767
-
1768
1359
  function getIdentifierForList(newValue, idSerializedKey) {
1769
1360
  return newValue.map(function (value) {
1770
1361
  if (Object.keys(value).includes(idSerializedKey)) {
1771
1362
  return _defineProperty({}, idSerializedKey, value[idSerializedKey]);
1772
1363
  }
1773
-
1774
1364
  if (typeof value === 'string') {
1775
1365
  return value;
1776
1366
  }
1777
-
1778
1367
  throw new TypeError('new value should include a list of string or objects containing the serialized key');
1779
1368
  });
1780
1369
  }
1781
-
1782
- var _storage = new WeakMap();
1783
-
1784
- var _enabled = new WeakMap();
1785
-
1370
+ var _storage = /*#__PURE__*/new WeakMap();
1371
+ var _enabled = /*#__PURE__*/new WeakMap();
1786
1372
  var UnitOfWork = /*#__PURE__*/function () {
1787
1373
  function UnitOfWork(mapping) {
1788
1374
  var enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1789
-
1790
1375
  _classCallCheck(this, UnitOfWork);
1791
-
1792
1376
  _defineProperty(this, "mapping", void 0);
1793
-
1794
- _storage.set(this, {
1795
- writable: true,
1796
- value: void 0
1797
- });
1798
-
1799
- _enabled.set(this, {
1800
- writable: true,
1801
- value: void 0
1802
- });
1803
-
1377
+ _classPrivateFieldInitSpec(this, _storage, void 0);
1378
+ _classPrivateFieldInitSpec(this, _enabled, void 0);
1804
1379
  this.mapping = mapping;
1805
-
1806
- _classPrivateFieldSet(this, _enabled, enabled);
1807
-
1808
- _classPrivateFieldSet(this, _storage, {});
1380
+ _classPrivateFieldSet2(_enabled, this, enabled);
1381
+ _classPrivateFieldSet2(_storage, this, {});
1809
1382
  }
1810
-
1811
- _createClass(UnitOfWork, [{
1383
+ return _createClass(UnitOfWork, [{
1812
1384
  key: "registerClean",
1813
1385
  value: function registerClean(id, entity) {
1814
- if (!_classPrivateFieldGet(this, _enabled)) {
1386
+ if (!_classPrivateFieldGet2(_enabled, this)) {
1815
1387
  return;
1816
1388
  }
1817
-
1818
1389
  if (isImmutable(entity)) {
1819
- _classPrivateFieldGet(this, _storage)[id] = entity;
1390
+ _classPrivateFieldGet2(_storage, this)[id] = entity;
1820
1391
  } else {
1821
- _classPrivateFieldGet(this, _storage)[id] = _objectSpread2({}, entity);
1392
+ _classPrivateFieldGet2(_storage, this)[id] = _objectSpread2({}, entity);
1822
1393
  }
1823
1394
  }
1824
1395
  }, {
1825
1396
  key: "getDirtyEntity",
1826
1397
  value: function getDirtyEntity(id) {
1827
- return _classPrivateFieldGet(this, _storage)[id];
1398
+ return _classPrivateFieldGet2(_storage, this)[id];
1828
1399
  }
1829
1400
  }, {
1830
1401
  key: "clear",
1831
1402
  value: function clear(id) {
1832
- delete _classPrivateFieldGet(this, _storage)[id];
1403
+ delete _classPrivateFieldGet2(_storage, this)[id];
1833
1404
  }
1834
1405
  }, {
1835
1406
  key: "getDirtyData",
@@ -1840,7 +1411,6 @@ var UnitOfWork = /*#__PURE__*/function () {
1840
1411
  key: "_getDirtyFieldsForAttribute",
1841
1412
  value: function _getDirtyFieldsForAttribute(dirtyFieldsParam, key, attribute, oldValue, newValue) {
1842
1413
  var dirtyFields = dirtyFieldsParam;
1843
-
1844
1414
  if (attribute.type === 'object' || attribute.type === 'array') {
1845
1415
  if (oldValue === undefined || objectDiffers(oldValue, newValue)) {
1846
1416
  dirtyFields[key] = newValue;
@@ -1848,71 +1418,58 @@ var UnitOfWork = /*#__PURE__*/function () {
1848
1418
  } else if (oldValue !== newValue) {
1849
1419
  dirtyFields[key] = newValue;
1850
1420
  }
1851
-
1852
1421
  return dirtyFields;
1853
1422
  }
1854
1423
  }, {
1855
1424
  key: "_getDirtyFieldsForManyToOne",
1856
1425
  value: function _getDirtyFieldsForManyToOne(dirtyFieldsParam, key, oldValue, newValue, relationMetadata, idSerializedKey) {
1857
1426
  var dirtyFields = dirtyFieldsParam;
1858
-
1859
1427
  if (oldValue !== newValue) {
1860
1428
  if (newValue === null) {
1861
1429
  dirtyFields[key] = null;
1862
1430
  return dirtyFields;
1863
1431
  }
1864
-
1865
1432
  if (typeof oldValue === 'string' || typeof newValue === 'string') {
1866
1433
  dirtyFields[key] = newValue;
1867
1434
  }
1868
-
1869
1435
  var recursiveDiff = this._getDirtyFields(newValue, oldValue, relationMetadata);
1870
-
1871
1436
  if (Object.keys(recursiveDiff).length > 0) {
1872
1437
  recursiveDiff[idSerializedKey] = getEntityId(newValue, idSerializedKey);
1873
1438
  dirtyFields[key] = recursiveDiff;
1874
1439
  }
1875
1440
  }
1876
-
1877
1441
  return dirtyFields;
1878
1442
  }
1879
1443
  }, {
1880
1444
  key: "_getDirtyFieldsForOneToMany",
1881
1445
  value: function _getDirtyFieldsForOneToMany(dirtyFieldsParam, key, idSerializedKey, relationMetadata, oldValue, newValue) {
1882
1446
  var _this = this;
1883
-
1884
1447
  var dirtyFields = dirtyFieldsParam;
1885
1448
  var newValueLength = newValue ? newValue.length : 0;
1886
- var oldValueLength = oldValue ? oldValue.length : 0; // number of items changed
1449
+ var oldValueLength = oldValue ? oldValue.length : 0;
1887
1450
 
1451
+ // number of items changed
1888
1452
  if (newValueLength !== oldValueLength) {
1889
1453
  dirtyFields[key] = getIdentifierForList(newValue, idSerializedKey);
1890
1454
  }
1891
-
1892
1455
  if (newValue && newValue.length > 0) {
1893
1456
  if (dirtyFields[key] === undefined) {
1894
1457
  dirtyFields[key] = [];
1895
1458
  }
1896
-
1897
1459
  var relationList = newValue;
1898
1460
  relationList.forEach(function (newRelationValue, relationAttributeName) {
1899
1461
  var oldRelationValue = findOldRelation(newRelationValue, oldValue, relationMetadata);
1900
-
1901
1462
  if (newRelationValue !== oldRelationValue) {
1902
1463
  if (typeof newRelationValue === 'string' || typeof oldRelationValue === 'string') {
1903
1464
  dirtyFields[key][relationAttributeName] = newRelationValue;
1904
1465
  return;
1905
1466
  }
1906
-
1907
1467
  var recursiveDiff = _this._getDirtyFields(newRelationValue, oldRelationValue, relationMetadata);
1908
-
1909
1468
  if (Object.keys(recursiveDiff).length > 0) {
1910
1469
  var entityId = getEntityId(newRelationValue, idSerializedKey);
1911
-
1912
1470
  if (entityId !== null) {
1913
1471
  recursiveDiff[idSerializedKey] = entityId;
1914
1472
  }
1915
-
1916
1473
  if (dirtyFields[key][relationAttributeName]) {
1917
1474
  Object.assign(dirtyFields[key][relationAttributeName], recursiveDiff);
1918
1475
  } else {
@@ -1921,7 +1478,6 @@ var UnitOfWork = /*#__PURE__*/function () {
1921
1478
  }
1922
1479
  }
1923
1480
  });
1924
-
1925
1481
  if (dirtyFields[key].length > 0) {
1926
1482
  // add identifier because one or more object linked has been updated
1927
1483
  // see test: 'get dirty data many to one update item'
@@ -1931,52 +1487,45 @@ var UnitOfWork = /*#__PURE__*/function () {
1931
1487
  delete dirtyFields[key];
1932
1488
  }
1933
1489
  }
1934
-
1935
1490
  return dirtyFields;
1936
1491
  }
1937
1492
  }, {
1938
1493
  key: "_getDirtyFields",
1939
1494
  value: function _getDirtyFields(newSerializedModel, oldSerializedModel, classMetadata) {
1940
1495
  var _this2 = this;
1941
-
1942
1496
  var dirtyFields = {};
1943
1497
  Object.values(classMetadata.getAttributeList()).forEach(function (attribute) {
1944
1498
  var key = attribute.attributeName;
1945
1499
  var newValue = newSerializedModel[key];
1946
1500
  var oldValue = oldSerializedModel ? oldSerializedModel[key] : null;
1947
1501
  var currentRelation = classMetadata.getRelation(attribute.serializedKey);
1948
-
1949
1502
  if (newValue === undefined) {
1950
1503
  return;
1951
- } // not a relation
1952
-
1504
+ }
1953
1505
 
1506
+ // not a relation
1954
1507
  if (!currentRelation) {
1955
1508
  dirtyFields = _this2._getDirtyFieldsForAttribute(dirtyFields, key, attribute, oldValue, newValue);
1956
1509
  return;
1957
1510
  }
1958
-
1959
1511
  var relationMetadata = _this2.mapping.getClassMetadataByKey(currentRelation.targetMetadataKey);
1960
-
1961
1512
  if (!relationMetadata) {
1962
1513
  throw new TypeError("relation metadata is not set for relation ".concat(classMetadata.key, ".").concat(currentRelation.targetMetadataKey));
1963
1514
  }
1515
+ var idSerializedKey = relationMetadata.getIdentifierAttribute().serializedKey;
1964
1516
 
1965
- var idSerializedKey = relationMetadata.getIdentifierAttribute().serializedKey; // MANY_TO_ONE relation
1966
-
1517
+ // MANY_TO_ONE relation
1967
1518
  if (currentRelation.isRelationToOne()) {
1968
1519
  dirtyFields = _this2._getDirtyFieldsForManyToOne(dirtyFields, key, oldValue, newValue, relationMetadata, idSerializedKey);
1969
1520
  return;
1970
- } // *_TO_MANY relation
1971
-
1521
+ }
1972
1522
 
1523
+ // *_TO_MANY relation
1973
1524
  dirtyFields = _this2._getDirtyFieldsForOneToMany(dirtyFields, key, idSerializedKey, relationMetadata, oldValue, newValue);
1974
1525
  });
1975
1526
  return dirtyFields;
1976
1527
  }
1977
1528
  }]);
1978
-
1979
- return UnitOfWork;
1980
1529
  }();
1981
1530
 
1982
1531
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -1984,44 +1533,44 @@ var Serializer = /*#__PURE__*/function () {
1984
1533
  function Serializer() {
1985
1534
  _classCallCheck(this, Serializer);
1986
1535
  }
1987
-
1988
- _createClass(Serializer, [{
1536
+ return _createClass(Serializer, [{
1989
1537
  key: "normalizeItem",
1990
-
1538
+ value:
1991
1539
  /**
1992
1540
  * convert an entity to a plain javascript object
1993
1541
  * @param {object} entity - The entity to convert
1994
1542
  * @param {ClassMetadata} classMetadata - the class metadata
1995
1543
  * @return {object} the object to serialize
1996
1544
  */
1997
- value: function normalizeItem(entity, classMetadata) {
1545
+ function normalizeItem(entity, classMetadata) {
1998
1546
  return entity;
1999
1547
  }
1548
+
2000
1549
  /**
2001
1550
  * convert a plain javascript object to string
2002
1551
  * @param {object} object - The object to convert to convert
2003
1552
  * @param {ClassMetadata} classMetadata - the class metadata
2004
1553
  * @return {string} the content of the request
2005
1554
  */
2006
-
2007
1555
  }, {
2008
1556
  key: "encodeItem",
2009
1557
  value: function encodeItem(object, classMetadata) {
2010
1558
  throw new TypeError('`encodeItem` method must be implemented');
2011
1559
  }
1560
+
2012
1561
  /**
2013
1562
  * convert an entity to string that will be sent as the request content
2014
1563
  * @param {any} entity - The entity to convert
2015
1564
  * @param {ClassMetadata} classMetadata - the class metadata
2016
1565
  * @return {string} the content of the request
2017
1566
  */
2018
-
2019
1567
  }, {
2020
1568
  key: "serializeItem",
2021
1569
  value: function serializeItem(object, classMetadata) {
2022
1570
  var noralizedData = this.normalizeItem(object, classMetadata);
2023
1571
  return this.encodeItem(noralizedData, classMetadata);
2024
1572
  }
1573
+
2025
1574
  /**
2026
1575
  * convert a plain object to an entity
2027
1576
  * @param {object} object - The plain javascript object
@@ -2029,12 +1578,12 @@ var Serializer = /*#__PURE__*/function () {
2029
1578
  * @param {Record<string, unknown>} response - the HTTP response
2030
1579
  * @return {object} an entity
2031
1580
  */
2032
-
2033
1581
  }, {
2034
1582
  key: "denormalizeItem",
2035
1583
  value: function denormalizeItem(object, classMetadata, response) {
2036
1584
  return object;
2037
1585
  }
1586
+
2038
1587
  /**
2039
1588
  * convert a string containing an object to a plain javascript object
2040
1589
  * @param {string} rawData - The string fetched from the response
@@ -2042,12 +1591,12 @@ var Serializer = /*#__PURE__*/function () {
2042
1591
  * @param {Record<string, unknown>} response - the HTTP response
2043
1592
  * @return {object} the normalized object
2044
1593
  */
2045
-
2046
1594
  }, {
2047
1595
  key: "decodeItem",
2048
1596
  value: function decodeItem(rawData, classMetadata, response) {
2049
1597
  throw new TypeError('`decodeItem` method must be implemented');
2050
1598
  }
1599
+
2051
1600
  /**
2052
1601
  * convert a string containing an object to an entity
2053
1602
  * @param {string} rawData - The string fetched from the response
@@ -2055,13 +1604,13 @@ var Serializer = /*#__PURE__*/function () {
2055
1604
  * @param {Record<string, unknown>} response - the HTTP response
2056
1605
  * @return {object} the entity
2057
1606
  */
2058
-
2059
1607
  }, {
2060
1608
  key: "deserializeItem",
2061
1609
  value: function deserializeItem(rawData, classMetadata, response) {
2062
1610
  var object = this.decodeItem(rawData, classMetadata, response);
2063
1611
  return this.denormalizeItem(object, classMetadata, response);
2064
1612
  }
1613
+
2065
1614
  /**
2066
1615
  * convert a plain object list to an entity list
2067
1616
  * @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object)
@@ -2069,12 +1618,12 @@ var Serializer = /*#__PURE__*/function () {
2069
1618
  * @param {Record<string, unknown>} response - the HTTP response
2070
1619
  * @return {Iterable<object>} a list of entities
2071
1620
  */
2072
-
2073
1621
  }, {
2074
1622
  key: "denormalizeList",
2075
1623
  value: function denormalizeList(objectList, classMetadata, response) {
2076
1624
  return objectList; // weird conversion as the declaration of list type is fuzzy
2077
1625
  }
1626
+
2078
1627
  /**
2079
1628
  * convert a string containing a list of objects to a list of plain javascript objects
2080
1629
  * @param {string} rawListData - The string fetched from the response
@@ -2082,12 +1631,12 @@ var Serializer = /*#__PURE__*/function () {
2082
1631
  * @param {Record<string, unknown>} response - the HTTP response
2083
1632
  * @return {Iterable<object>} a list of normalized objects
2084
1633
  */
2085
-
2086
1634
  }, {
2087
1635
  key: "decodeList",
2088
1636
  value: function decodeList(rawListData, classMetadata, response) {
2089
1637
  throw new TypeError('`deserializeList` method must be implemented');
2090
1638
  }
1639
+
2091
1640
  /**
2092
1641
  * convert a string containing a list of objects to a list of entities
2093
1642
  * @param {string} rawListData - The string fetched from the response
@@ -2095,7 +1644,6 @@ var Serializer = /*#__PURE__*/function () {
2095
1644
  * @param {Record<string, unknown>} response - the HTTP response
2096
1645
  * @return {Iterable<object>} a list of entities
2097
1646
  */
2098
-
2099
1647
  }, {
2100
1648
  key: "deserializeList",
2101
1649
  value: function deserializeList(rawListData, classMetadata, response) {
@@ -2103,22 +1651,15 @@ var Serializer = /*#__PURE__*/function () {
2103
1651
  return this.denormalizeList(objectList, classMetadata, response);
2104
1652
  }
2105
1653
  }]);
2106
-
2107
- return Serializer;
2108
1654
  }();
2109
1655
 
2110
1656
  var JsSerializer = /*#__PURE__*/function (_Serializer) {
2111
- _inherits(JsSerializer, _Serializer);
2112
-
2113
- var _super = _createSuper(JsSerializer);
2114
-
2115
1657
  function JsSerializer() {
2116
1658
  _classCallCheck(this, JsSerializer);
2117
-
2118
- return _super.apply(this, arguments);
1659
+ return _callSuper(this, JsSerializer, arguments);
2119
1660
  }
2120
-
2121
- _createClass(JsSerializer, [{
1661
+ _inherits(JsSerializer, _Serializer);
1662
+ return _createClass(JsSerializer, [{
2122
1663
  key: "encodeItem",
2123
1664
  value: function encodeItem(object, classMetadata) {
2124
1665
  return JSON.stringify(object);
@@ -2134,66 +1675,60 @@ var JsSerializer = /*#__PURE__*/function (_Serializer) {
2134
1675
  return JSON.parse(rawListData);
2135
1676
  }
2136
1677
  }]);
2137
-
2138
- return JsSerializer;
2139
1678
  }(Serializer);
2140
1679
 
2141
1680
  function levenshteinDistance(a, b) {
2142
- var matrix = []; // Increment along the first column of each row
1681
+ var matrix = [];
2143
1682
 
1683
+ // Increment along the first column of each row
2144
1684
  for (var i = 0; i <= b.length; i += 1) {
2145
1685
  matrix[i] = [i];
2146
- } // Increment each column in the first row
2147
-
1686
+ }
2148
1687
 
1688
+ // Increment each column in the first row
2149
1689
  for (var j = 0; j <= a.length; j += 1) {
2150
1690
  matrix[0][j] = j;
2151
- } // Fill in the rest of the matrix
2152
-
1691
+ }
2153
1692
 
1693
+ // Fill in the rest of the matrix
2154
1694
  for (var _i = 1; _i <= b.length; _i += 1) {
2155
1695
  for (var _j = 1; _j <= a.length; _j += 1) {
2156
1696
  if (b.charAt(_i - 1) === a.charAt(_j - 1)) {
2157
1697
  matrix[_i][_j] = matrix[_i - 1][_j - 1];
2158
1698
  } else {
2159
- matrix[_i][_j] = Math.min(matrix[_i - 1][_j - 1] + 1, // substitution
2160
- matrix[_i][_j - 1] + 1, // insertion
1699
+ matrix[_i][_j] = Math.min(matrix[_i - 1][_j - 1] + 1,
1700
+ // substitution
1701
+ matrix[_i][_j - 1] + 1,
1702
+ // insertion
2161
1703
  matrix[_i - 1][_j] + 1 // deletion
2162
1704
  );
2163
1705
  }
2164
1706
  }
2165
1707
  }
2166
-
2167
1708
  return matrix[b.length][a.length];
2168
- } // eslint-disable-next-line import/prefer-default-export
2169
-
2170
-
1709
+ }
2171
1710
  function findClosestWord(word, list) {
2172
1711
  var maxDistance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
2173
1712
  var closestWord = null;
2174
- var minDistance = Infinity; // eslint-disable-next-line no-plusplus
2175
-
1713
+ var minDistance = Infinity;
2176
1714
  for (var i = 0; i < list.length; i += 1) {
2177
1715
  var candidate = list[i];
2178
1716
  var distance = levenshteinDistance(word, candidate);
2179
-
2180
1717
  if (distance < minDistance && distance <= maxDistance) {
2181
1718
  minDistance = distance;
2182
1719
  closestWord = candidate;
2183
1720
  }
2184
1721
  }
2185
-
2186
1722
  return closestWord;
2187
1723
  }
2188
1724
 
1725
+ // type SdkResponse = Partial<Response>;
1726
+
2189
1727
  var generateId = function generateId() {
2190
1728
  return "rest-client-sdk|".concat(Date.now(), "-").concat(Math.floor(Math.random() * (9e12 - 1)) + 1e12);
2191
1729
  };
2192
-
2193
1730
  function serializeRequest(req) {
2194
1731
  var request = _objectSpread2({}, req); // Make a clone, useful for doing destructive things
2195
-
2196
-
2197
1732
  return {
2198
1733
  method: request.method,
2199
1734
  // The Request Method, e.g. GET, POST, DELETE
@@ -2202,31 +1737,20 @@ function serializeRequest(req) {
2202
1737
  headers: request.headers ? convertToRecord(request.headers) : undefined,
2203
1738
  body: typeof request.body === 'string' ? request.body : undefined
2204
1739
  };
2205
- } // eslint-disable-next-line import/prefer-default-export
2206
-
2207
-
2208
- var _history = new WeakMap();
2209
-
1740
+ }
1741
+ var _history = /*#__PURE__*/new WeakMap();
2210
1742
  var Logger = /*#__PURE__*/function () {
2211
- _createClass(Logger, [{
2212
- key: "history",
2213
- get: function get() {
2214
- return _classPrivateFieldGet(this, _history);
2215
- }
2216
- }]);
2217
-
2218
1743
  function Logger() {
2219
1744
  _classCallCheck(this, Logger);
2220
-
2221
- _history.set(this, {
2222
- writable: true,
2223
- value: void 0
2224
- });
2225
-
2226
- _classPrivateFieldSet(this, _history, []);
1745
+ _classPrivateFieldInitSpec(this, _history, void 0);
1746
+ _classPrivateFieldSet2(_history, this, []);
2227
1747
  }
2228
-
2229
- _createClass(Logger, [{
1748
+ return _createClass(Logger, [{
1749
+ key: "history",
1750
+ get: function get() {
1751
+ return _classPrivateFieldGet2(_history, this);
1752
+ }
1753
+ }, {
2230
1754
  key: "logRequest",
2231
1755
  value: function logRequest(params) {
2232
1756
  var log = {
@@ -2236,15 +1760,15 @@ var Logger = /*#__PURE__*/function () {
2236
1760
  request: Date.now()
2237
1761
  }
2238
1762
  };
2239
-
2240
- _classPrivateFieldGet(this, _history).push(log);
2241
-
1763
+ _classPrivateFieldGet2(_history, this).push(log);
2242
1764
  return log.id;
2243
1765
  }
2244
1766
  }, {
2245
1767
  key: "logResponse",
2246
1768
  value: function logResponse(response, requestId) {
2247
- var id = requestId || generateId(); // console.log('clone');
1769
+ var id = requestId || generateId();
1770
+
1771
+ // console.log('clone');
2248
1772
  // const clonedResponse = response.clone(); // THIS IS THE LINE THAT CAUSES THE PROBLEM
2249
1773
  // console.log('after clone', clonedResponse.status);
2250
1774
 
@@ -2253,16 +1777,14 @@ var Logger = /*#__PURE__*/function () {
2253
1777
  // clonedResponse.status,
2254
1778
  headers: Object.fromEntries(response.headers)
2255
1779
  };
2256
-
2257
- var foundLogIndex = _classPrivateFieldGet(this, _history).findIndex(function (log) {
1780
+ var foundLogIndex = _classPrivateFieldGet2(_history, this).findIndex(function (log) {
2258
1781
  return log.id === id;
2259
1782
  });
2260
-
2261
1783
  if (foundLogIndex > -1) {
2262
- _classPrivateFieldGet(this, _history)[foundLogIndex].response = logContent;
2263
- _classPrivateFieldGet(this, _history)[foundLogIndex].logTimes.response = Date.now();
1784
+ _classPrivateFieldGet2(_history, this)[foundLogIndex].response = logContent;
1785
+ _classPrivateFieldGet2(_history, this)[foundLogIndex].logTimes.response = Date.now();
2264
1786
  } else {
2265
- _classPrivateFieldGet(this, _history).push({
1787
+ _classPrivateFieldGet2(_history, this).push({
2266
1788
  id: id,
2267
1789
  response: logContent,
2268
1790
  logTimes: {
@@ -2270,82 +1792,59 @@ var Logger = /*#__PURE__*/function () {
2270
1792
  }
2271
1793
  });
2272
1794
  }
2273
-
2274
1795
  return id;
2275
1796
  }
2276
1797
  }]);
2277
-
2278
- return Logger;
2279
1798
  }();
2280
1799
 
2281
- var _repositoryList = new WeakMap();
1800
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2282
1801
 
1802
+ // export type SdkMetadata = Record<string, [any, Iterable<any>, undefined | any]>;
1803
+ var _repositoryList = /*#__PURE__*/new WeakMap();
2283
1804
  var RestClientSdk = /*#__PURE__*/function () {
2284
1805
  function RestClientSdk(tokenStorage, config, mapping) {
2285
1806
  var serializer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new JsSerializer();
2286
-
2287
1807
  _classCallCheck(this, RestClientSdk);
2288
-
2289
1808
  _defineProperty(this, "config", void 0);
2290
-
2291
1809
  _defineProperty(this, "tokenStorage", void 0);
2292
-
2293
1810
  _defineProperty(this, "serializer", void 0);
2294
-
2295
1811
  _defineProperty(this, "mapping", void 0);
2296
-
2297
1812
  _defineProperty(this, "unitOfWork", void 0);
2298
-
2299
- _repositoryList.set(this, {
2300
- writable: true,
2301
- value: void 0
2302
- });
2303
-
1813
+ _classPrivateFieldInitSpec(this, _repositoryList, void 0);
2304
1814
  _defineProperty(this, "logger", void 0);
2305
-
2306
1815
  this.checkConfigValidity(config);
2307
-
2308
1816
  if (!(mapping instanceof Mapping)) {
2309
1817
  throw new TypeError('mapping should be an instance of `Mapping`');
2310
1818
  }
2311
-
2312
1819
  this.config = this._mergeWithBaseConfig(config);
2313
1820
  this.tokenStorage = tokenStorage;
2314
1821
  this.serializer = serializer;
2315
1822
  this.mapping = mapping;
2316
1823
  this.unitOfWork = new UnitOfWork(this.mapping, this.config.unitOfWorkEnabled);
2317
-
2318
1824
  if (config.loggerEnabled) {
2319
1825
  this.logger = new Logger();
2320
1826
  }
2321
-
2322
- _classPrivateFieldSet(this, _repositoryList, {});
1827
+ _classPrivateFieldSet2(_repositoryList, this, {});
2323
1828
  }
1829
+
2324
1830
  /**
2325
1831
  * get a repository by it's metadata "key" attribute
2326
1832
  *
2327
1833
  * @param {string} key the repository "key" (the first argument of `new ClassMetadata`)
2328
1834
  */
2329
-
2330
-
2331
- _createClass(RestClientSdk, [{
1835
+ return _createClass(RestClientSdk, [{
2332
1836
  key: "getRepository",
2333
1837
  value: function getRepository(key) {
2334
- if (!_classPrivateFieldGet(this, _repositoryList)[key]) {
1838
+ if (!_classPrivateFieldGet2(_repositoryList, this)[key]) {
2335
1839
  var metadata = this.mapping.getClassMetadataByKey(key);
2336
-
2337
1840
  if (!metadata) {
2338
1841
  var closeKey = findClosestWord(key, this.mapping.getMappingKeys(), 5);
2339
1842
  var suggestions = closeKey ? " Did you mean \"".concat(closeKey, "\"?") : '';
2340
1843
  throw new Error("Unable to get metadata for repository \"".concat(key, "\".").concat(suggestions));
2341
- } // eslint-disable-next-line new-cap
2342
-
2343
-
2344
- _classPrivateFieldGet(this, _repositoryList)[key] = generateRepository(this, metadata, this.config.unitOfWorkEnabled);
2345
- } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2346
-
2347
-
2348
- return _classPrivateFieldGet(this, _repositoryList)[key];
1844
+ }
1845
+ _classPrivateFieldGet2(_repositoryList, this)[key] = generateRepository(this, metadata, this.config.unitOfWorkEnabled);
1846
+ }
1847
+ return _classPrivateFieldGet2(_repositoryList, this)[key];
2349
1848
  }
2350
1849
  }, {
2351
1850
  key: "_mergeWithBaseConfig",
@@ -2363,49 +1862,37 @@ var RestClientSdk = /*#__PURE__*/function () {
2363
1862
  }
2364
1863
  }
2365
1864
  }]);
2366
-
2367
- return RestClientSdk;
2368
1865
  }();
2369
1866
 
2370
1867
  var AbstractTokenGenerator = /*#__PURE__*/function () {
2371
1868
  function AbstractTokenGenerator(tokenGeneratorConfig, logger) {
2372
1869
  _classCallCheck(this, AbstractTokenGenerator);
2373
-
2374
1870
  _defineProperty(this, "tokenGeneratorConfig", void 0);
2375
-
2376
1871
  _defineProperty(this, "logger", void 0);
2377
-
2378
1872
  if (logger) {
2379
1873
  this.logger = logger;
2380
1874
  }
2381
-
2382
1875
  this.tokenGeneratorConfig = tokenGeneratorConfig;
2383
-
2384
1876
  if (typeof this.checkTokenGeneratorConfig === 'function') {
2385
1877
  this.checkTokenGeneratorConfig(this.tokenGeneratorConfig);
2386
1878
  }
2387
1879
  }
2388
-
2389
- _createClass(AbstractTokenGenerator, [{
1880
+ return _createClass(AbstractTokenGenerator, [{
2390
1881
  key: "_manageOauthError",
2391
-
2392
- /** @deprecated */
2393
- value: function _manageOauthError(response) {
1882
+ value: /** @deprecated */
1883
+ function _manageOauthError(response) {
2394
1884
  return response.clone().json().then(function (body) {
2395
1885
  if (body.error === 'invalid_grant') {
2396
1886
  throw new InvalidGrantError(body.error, getHttpErrorFromResponse(response));
2397
1887
  }
2398
-
2399
1888
  if (body.error === 'invalid_scope') {
2400
1889
  throw new InvalidScopeError(body.error, getHttpErrorFromResponse(response));
2401
1890
  }
2402
-
2403
1891
  throw new OauthError(body.error, getHttpErrorFromResponse(response));
2404
1892
  })["catch"](function (err) {
2405
1893
  if (!(err instanceof OauthError)) {
2406
1894
  throw new OauthError(err.type, getHttpErrorFromResponse(response));
2407
1895
  }
2408
-
2409
1896
  throw err;
2410
1897
  });
2411
1898
  }
@@ -2413,16 +1900,12 @@ var AbstractTokenGenerator = /*#__PURE__*/function () {
2413
1900
  key: "generateUrlFromConfig",
2414
1901
  value: function generateUrlFromConfig(config) {
2415
1902
  var uri = new URI("".concat(config.scheme, "://").concat(config.path));
2416
-
2417
1903
  if (config.port) {
2418
1904
  uri.port(config.port);
2419
1905
  }
2420
-
2421
1906
  return uri.toString();
2422
1907
  }
2423
1908
  }]);
2424
-
2425
- return AbstractTokenGenerator;
2426
1909
  }();
2427
1910
 
2428
1911
  /**
@@ -2431,85 +1914,74 @@ var AbstractTokenGenerator = /*#__PURE__*/function () {
2431
1914
  * @See {@link https://oauth2.thephpleague.com/authorization-server/auth-code-grant/|the great article of the PHP League} about authorization code flow.
2432
1915
  */
2433
1916
  var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2434
- _inherits(AuthorizationCodeFlowTokenGenerator, _AbstractTokenGenerat);
2435
-
2436
- var _super = _createSuper(AuthorizationCodeFlowTokenGenerator);
2437
-
2438
1917
  function AuthorizationCodeFlowTokenGenerator() {
2439
1918
  _classCallCheck(this, AuthorizationCodeFlowTokenGenerator);
2440
-
2441
- return _super.apply(this, arguments);
1919
+ return _callSuper(this, AuthorizationCodeFlowTokenGenerator, arguments);
2442
1920
  }
2443
-
2444
- _createClass(AuthorizationCodeFlowTokenGenerator, [{
1921
+ _inherits(AuthorizationCodeFlowTokenGenerator, _AbstractTokenGenerat);
1922
+ return _createClass(AuthorizationCodeFlowTokenGenerator, [{
2445
1923
  key: "generateToken",
2446
-
1924
+ value:
2447
1925
  /**
2448
1926
  * This function needs no generate an access token
2449
1927
  */
2450
- value: function generateToken(parameters) {
1928
+ function generateToken(parameters) {
2451
1929
  this._checkGenerateParameters(parameters);
2452
-
2453
1930
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2454
1931
  var params = {
2455
1932
  method: 'POST',
2456
1933
  headers: {
2457
1934
  'Content-Type': 'application/x-www-form-urlencoded'
2458
1935
  },
2459
- body: new URLSearchParams({
1936
+ body: new URLSearchParams(_objectSpread2(_objectSpread2({
2460
1937
  grant_type: 'authorization_code',
2461
- client_id: this.tokenGeneratorConfig.clientId,
2462
- client_secret: this.tokenGeneratorConfig.clientSecret,
2463
- // TODO : secure this ?
1938
+ client_id: this.tokenGeneratorConfig.clientId
1939
+ }, this._clientSecretParameter()), {}, {
2464
1940
  redirect_uri: this.tokenGeneratorConfig.redirectUri,
2465
1941
  code: parameters.code
2466
- }).toString()
1942
+ }, parameters.codeVerifier ? {
1943
+ code_verifier: parameters.codeVerifier
1944
+ } : {})).toString()
2467
1945
  };
2468
-
2469
1946
  if (this.logger) {
2470
1947
  this.logger.logRequest(_objectSpread2({
2471
1948
  url: url
2472
1949
  }, params));
2473
1950
  }
2474
-
2475
1951
  return fetch(url, params);
2476
1952
  }
1953
+
2477
1954
  /**
2478
1955
  * This function needs to refresh the current possibly expired access token
2479
1956
  * and return a Promise that will be resolved with a fresh access token
2480
1957
  */
2481
-
2482
1958
  }, {
2483
1959
  key: "refreshToken",
2484
1960
  value: function refreshToken(oldAccessToken) {
2485
1961
  if (!oldAccessToken) {
2486
1962
  throw new Error('refresh_token is not set. Did you called `generateToken` before ?');
2487
1963
  }
2488
-
2489
- if (!(oldAccessToken === null || oldAccessToken === void 0 ? void 0 : oldAccessToken.refresh_token)) {
1964
+ if (!(oldAccessToken !== null && oldAccessToken !== void 0 && oldAccessToken.refresh_token)) {
2490
1965
  throw new Error('Unable to refreshToken as there are no refresh_token');
2491
1966
  }
2492
-
2493
1967
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2494
1968
  var params = {
2495
1969
  method: 'POST',
2496
1970
  headers: {
2497
1971
  'Content-Type': 'application/x-www-form-urlencoded'
2498
1972
  },
2499
- body: new URLSearchParams({
1973
+ body: new URLSearchParams(_objectSpread2(_objectSpread2({
2500
1974
  grant_type: 'refresh_token',
2501
- client_id: this.tokenGeneratorConfig.clientId,
2502
- client_secret: this.tokenGeneratorConfig.clientSecret,
1975
+ client_id: this.tokenGeneratorConfig.clientId
1976
+ }, this._clientSecretParameter()), {}, {
2503
1977
  refresh_token: oldAccessToken.refresh_token
2504
- }).toString()
1978
+ })).toString()
2505
1979
  };
2506
-
2507
1980
  if (this.logger) {
2508
1981
  this.logger.logRequest(_objectSpread2({
2509
1982
  url: url
2510
1983
  }, params));
2511
1984
  }
2512
-
2513
1985
  return fetch(url, params);
2514
1986
  }
2515
1987
  }, {
@@ -2518,62 +1990,60 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
2518
1990
  if (!config || Object.keys(config).length === 0) {
2519
1991
  throw new RangeError('TokenGenerator config must be set');
2520
1992
  }
2521
-
2522
1993
  if (!(config.path && config.scheme)) {
2523
1994
  throw new RangeError('TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter');
2524
1995
  }
2525
-
2526
- if (!(config.clientId && config.clientSecret)) {
2527
- throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter');
1996
+ if (!config.clientId) {
1997
+ throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId" parameter');
2528
1998
  }
2529
-
2530
1999
  if (!config.redirectUri) {
2531
2000
  throw new RangeError('TokenGenerator config is not valid, it should contain a "redirectUri" parameter');
2532
2001
  }
2533
2002
  }
2003
+ }, {
2004
+ key: "_clientSecretParameter",
2005
+ value: function _clientSecretParameter() {
2006
+ var clientSecret = this.tokenGeneratorConfig.clientSecret;
2007
+ return clientSecret ? {
2008
+ client_secret: clientSecret
2009
+ } : {};
2010
+ }
2534
2011
  }, {
2535
2012
  key: "_checkGenerateParameters",
2536
2013
  value: function _checkGenerateParameters(parameters) {
2537
2014
  if (!(parameters && Object.keys(parameters).length > 0)) {
2538
2015
  throw new RangeError('parameters must be set');
2539
2016
  }
2540
-
2541
2017
  if (!parameters.code) {
2542
2018
  throw new RangeError('"code" must be passed as parameter');
2543
2019
  }
2544
2020
  }
2545
2021
  }]);
2546
-
2547
- return AuthorizationCodeFlowTokenGenerator;
2548
2022
  }(AbstractTokenGenerator);
2549
2023
 
2550
- /* eslint-disable import/prefer-default-export */
2551
2024
  // memoize promise returning function so that it returns
2552
2025
  // the same promise if called again before resolve / reject
2026
+
2553
2027
  function memoizePromise(callback) {
2554
2028
  var cache = {};
2555
-
2556
2029
  function memoized() {
2557
2030
  for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
2558
2031
  parameters[_key] = arguments[_key];
2559
2032
  }
2560
-
2561
2033
  var cacheKey = JSON.stringify(parameters);
2562
2034
  var cacheValue = cache[cacheKey];
2563
-
2564
2035
  if (cacheValue) {
2565
2036
  return cacheValue;
2566
- } // Get and add the value to the cache
2567
-
2037
+ }
2568
2038
 
2039
+ // Get and add the value to the cache
2569
2040
  var value = callback.apply(this, parameters);
2570
2041
  cache[cacheKey] = value;
2571
-
2572
2042
  if (!value || typeof value.then !== 'function') {
2573
2043
  throw new Error('Memoization Error, Async function returned non-promise value');
2574
- } // Delete the value regardless of whether it resolves or rejects
2575
-
2044
+ }
2576
2045
 
2046
+ // Delete the value regardless of whether it resolves or rejects
2577
2047
  return value.then(function (internalValue) {
2578
2048
  cache[cacheKey] = false;
2579
2049
  return internalValue;
@@ -2582,31 +2052,23 @@ function memoizePromise(callback) {
2582
2052
  throw err;
2583
2053
  });
2584
2054
  }
2585
-
2586
2055
  memoized.cache = cache;
2587
2056
  return memoized;
2588
2057
  }
2589
2058
 
2590
- var ERROR_CONFIG_EMPTY = 'TokenGenerator config must be set';
2591
- var ERROR_CONFIG_PATH_SCHEME = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2592
- var ERROR_CONFIG_CLIENT_INFORMATIONS = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2593
-
2059
+ var ERROR_CONFIG_EMPTY$1 = 'TokenGenerator config must be set';
2060
+ var ERROR_CONFIG_PATH_SCHEME$1 = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2061
+ var ERROR_CONFIG_CLIENT_INFORMATIONS$1 = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2594
2062
  var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2595
- _inherits(ClientCredentialsGenerator, _AbstractTokenGenerat);
2596
-
2597
- var _super = _createSuper(ClientCredentialsGenerator);
2598
-
2599
2063
  function ClientCredentialsGenerator(tokenGeneratorConfig) {
2600
2064
  var _this;
2601
-
2602
2065
  _classCallCheck(this, ClientCredentialsGenerator);
2603
-
2604
- _this = _super.call(this, tokenGeneratorConfig);
2066
+ _this = _callSuper(this, ClientCredentialsGenerator, [tokenGeneratorConfig]);
2605
2067
  _this.generateToken = memoizePromise(_this.generateToken);
2606
2068
  return _this;
2607
2069
  }
2608
-
2609
- _createClass(ClientCredentialsGenerator, [{
2070
+ _inherits(ClientCredentialsGenerator, _AbstractTokenGenerat);
2071
+ return _createClass(ClientCredentialsGenerator, [{
2610
2072
  key: "generateToken",
2611
2073
  value: function generateToken() {
2612
2074
  var baseParameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2615,13 +2077,11 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2615
2077
  client_id: this.tokenGeneratorConfig.clientId,
2616
2078
  client_secret: this.tokenGeneratorConfig.clientSecret
2617
2079
  });
2618
-
2619
2080
  if (baseParameters.scope) {
2620
2081
  body.append('scope', baseParameters.scope);
2621
2082
  } else if (this.tokenGeneratorConfig.scope) {
2622
2083
  body.append('scope', this.tokenGeneratorConfig.scope);
2623
2084
  }
2624
-
2625
2085
  var params = {
2626
2086
  method: 'POST',
2627
2087
  headers: {
@@ -2630,18 +2090,17 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2630
2090
  body: body.toString()
2631
2091
  };
2632
2092
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2633
-
2634
2093
  if (this.logger) {
2635
2094
  this.logger.logRequest(_objectSpread2({
2636
2095
  url: url
2637
2096
  }, params));
2638
2097
  }
2639
-
2640
2098
  return fetch(url, params);
2641
2099
  }
2642
2100
  }, {
2643
2101
  key: "refreshToken",
2644
- value: function refreshToken( // eslint-disable-next-line @typescript-eslint/no-unused-vars
2102
+ value: function refreshToken(
2103
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2645
2104
  accessToken) {
2646
2105
  return this.generateToken({});
2647
2106
  }
@@ -2649,44 +2108,33 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2649
2108
  key: "checkTokenGeneratorConfig",
2650
2109
  value: function checkTokenGeneratorConfig(config) {
2651
2110
  if (!config || Object.keys(config).length === 0) {
2652
- throw new RangeError(ERROR_CONFIG_EMPTY);
2111
+ throw new RangeError(ERROR_CONFIG_EMPTY$1);
2653
2112
  }
2654
-
2655
2113
  if (!(config.path && config.scheme)) {
2656
- throw new RangeError(ERROR_CONFIG_PATH_SCHEME);
2114
+ throw new RangeError(ERROR_CONFIG_PATH_SCHEME$1);
2657
2115
  }
2658
-
2659
2116
  if (!(config.clientId && config.clientSecret)) {
2660
- throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);
2117
+ throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS$1);
2661
2118
  }
2662
2119
  }
2663
2120
  }]);
2664
-
2665
- return ClientCredentialsGenerator;
2666
2121
  }(AbstractTokenGenerator);
2667
2122
 
2668
- var ERROR_CONFIG_EMPTY$1 = 'TokenGenerator config must be set';
2669
- var ERROR_CONFIG_PATH_SCHEME$1 = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2670
- var ERROR_CONFIG_CLIENT_INFORMATIONS$1 = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2123
+ var ERROR_CONFIG_EMPTY = 'TokenGenerator config must be set';
2124
+ var ERROR_CONFIG_PATH_SCHEME = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2125
+ var ERROR_CONFIG_CLIENT_INFORMATIONS = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2671
2126
  var ERROR_TOKEN_EMPTY = 'parameters must be set';
2672
2127
  var ERROR_TOKEN_USERNAME_PASSWORD = 'username and password must be passed as parameters';
2673
-
2674
2128
  var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2675
- _inherits(PasswordGenerator, _AbstractTokenGenerat);
2676
-
2677
- var _super = _createSuper(PasswordGenerator);
2678
-
2679
2129
  function PasswordGenerator() {
2680
2130
  _classCallCheck(this, PasswordGenerator);
2681
-
2682
- return _super.apply(this, arguments);
2131
+ return _callSuper(this, PasswordGenerator, arguments);
2683
2132
  }
2684
-
2685
- _createClass(PasswordGenerator, [{
2133
+ _inherits(PasswordGenerator, _AbstractTokenGenerat);
2134
+ return _createClass(PasswordGenerator, [{
2686
2135
  key: "generateToken",
2687
2136
  value: function generateToken(baseParameters) {
2688
2137
  this._checkGenerateParameters(baseParameters);
2689
-
2690
2138
  var body = new URLSearchParams({
2691
2139
  grant_type: 'password',
2692
2140
  username: baseParameters.username,
@@ -2694,13 +2142,11 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2694
2142
  client_id: this.tokenGeneratorConfig.clientId,
2695
2143
  client_secret: this.tokenGeneratorConfig.clientSecret
2696
2144
  });
2697
-
2698
2145
  if (baseParameters.scope) {
2699
2146
  body.append('scope', baseParameters.scope);
2700
2147
  } else if (this.tokenGeneratorConfig.scope) {
2701
2148
  body.append('scope', this.tokenGeneratorConfig.scope);
2702
2149
  }
2703
-
2704
2150
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2705
2151
  var params = {
2706
2152
  method: 'POST',
@@ -2709,35 +2155,29 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2709
2155
  },
2710
2156
  body: body.toString()
2711
2157
  };
2712
-
2713
2158
  if (this.logger) {
2714
2159
  this.logger.logRequest(_objectSpread2({
2715
2160
  url: url
2716
2161
  }, params));
2717
2162
  }
2718
-
2719
2163
  return fetch(url, params);
2720
2164
  }
2721
2165
  }, {
2722
2166
  key: "refreshToken",
2723
2167
  value: function refreshToken(accessToken) {
2724
2168
  var refreshToken = accessToken === null || accessToken === void 0 ? void 0 : accessToken.refresh_token;
2725
-
2726
2169
  if (!refreshToken) {
2727
2170
  throw new Error('refresh_token is not set. Did you called `generateToken` before ?');
2728
2171
  }
2729
-
2730
2172
  var body = new URLSearchParams({
2731
2173
  grant_type: 'refresh_token',
2732
2174
  client_id: this.tokenGeneratorConfig.clientId,
2733
2175
  client_secret: this.tokenGeneratorConfig.clientSecret,
2734
2176
  refresh_token: refreshToken
2735
2177
  });
2736
-
2737
2178
  if (this.tokenGeneratorConfig.scope) {
2738
2179
  body.append('scope', this.tokenGeneratorConfig.scope);
2739
2180
  }
2740
-
2741
2181
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2742
2182
  var params = {
2743
2183
  method: 'POST',
@@ -2746,28 +2186,24 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2746
2186
  },
2747
2187
  body: body.toString()
2748
2188
  };
2749
-
2750
2189
  if (this.logger) {
2751
2190
  this.logger.logRequest(_objectSpread2({
2752
2191
  url: url
2753
2192
  }, params));
2754
2193
  }
2755
-
2756
2194
  return fetch(url, params);
2757
2195
  }
2758
2196
  }, {
2759
2197
  key: "checkTokenGeneratorConfig",
2760
2198
  value: function checkTokenGeneratorConfig(config) {
2761
2199
  if (!config || Object.keys(config).length === 0) {
2762
- throw new RangeError(ERROR_CONFIG_EMPTY$1);
2200
+ throw new RangeError(ERROR_CONFIG_EMPTY);
2763
2201
  }
2764
-
2765
2202
  if (!(config.path && config.scheme)) {
2766
- throw new RangeError(ERROR_CONFIG_PATH_SCHEME$1);
2203
+ throw new RangeError(ERROR_CONFIG_PATH_SCHEME);
2767
2204
  }
2768
-
2769
2205
  if (!(config.clientId && config.clientSecret)) {
2770
- throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS$1);
2206
+ throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);
2771
2207
  }
2772
2208
  }
2773
2209
  }, {
@@ -2776,22 +2212,15 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2776
2212
  if (!(parameters && Object.keys(parameters).length > 0)) {
2777
2213
  throw new RangeError(ERROR_TOKEN_EMPTY);
2778
2214
  }
2779
-
2780
2215
  if (!(parameters.username && parameters.password)) {
2781
2216
  throw new RangeError(ERROR_TOKEN_USERNAME_PASSWORD);
2782
2217
  }
2783
2218
  }
2784
2219
  }]);
2785
-
2786
- return PasswordGenerator;
2787
2220
  }(AbstractTokenGenerator);
2788
2221
 
2789
- var _token = new WeakMap();
2790
-
2791
- var _refreshTokenFunc = new WeakMap();
2792
-
2793
- /* eslint-disable camelcase */
2794
-
2222
+ var _token = /*#__PURE__*/new WeakMap();
2223
+ var _refreshTokenFunc = /*#__PURE__*/new WeakMap();
2795
2224
  /**
2796
2225
  * @deprecated ProvidedTokenGenerator is not an Oauth valid generator.
2797
2226
  * You should use one of the official generator or implement your own custom generator.
@@ -2799,38 +2228,28 @@ var _refreshTokenFunc = new WeakMap();
2799
2228
  var ProvidedTokenGenerator = /*#__PURE__*/function () {
2800
2229
  function ProvidedTokenGenerator(token) {
2801
2230
  var refreshTokenFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2802
-
2803
2231
  _classCallCheck(this, ProvidedTokenGenerator);
2804
-
2805
- _token.set(this, {
2806
- writable: true,
2807
- value: void 0
2808
- });
2809
-
2810
- _refreshTokenFunc.set(this, {
2811
- writable: true,
2812
- value: void 0
2813
- });
2814
-
2815
- _classPrivateFieldSet(this, _token, token);
2816
-
2817
- _classPrivateFieldSet(this, _refreshTokenFunc, refreshTokenFunc);
2232
+ _classPrivateFieldInitSpec(this, _token, void 0);
2233
+ _classPrivateFieldInitSpec(this, _refreshTokenFunc, void 0);
2234
+ _classPrivateFieldSet2(_token, this, token);
2235
+ _classPrivateFieldSet2(_refreshTokenFunc, this, refreshTokenFunc);
2818
2236
  }
2819
-
2820
- _createClass(ProvidedTokenGenerator, [{
2237
+ return _createClass(ProvidedTokenGenerator, [{
2238
+ key: "token",
2239
+ set: function set(token) {
2240
+ _classPrivateFieldSet2(_token, this, token);
2241
+ }
2242
+ }, {
2821
2243
  key: "generateToken",
2822
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2823
2244
  value: function generateToken() {
2824
- return Promise.resolve(_classPrivateFieldGet(this, _token));
2825
- } // eslint-disable-next-line @typescript-eslint/no-unused-vars
2826
-
2245
+ return Promise.resolve(_classPrivateFieldGet2(_token, this));
2246
+ }
2827
2247
  }, {
2828
2248
  key: "refreshToken",
2829
2249
  value: function refreshToken(accessToken) {
2830
- if (typeof _classPrivateFieldGet(this, _refreshTokenFunc) === 'function') {
2831
- return _classPrivateFieldGet(this, _refreshTokenFunc).call(this, accessToken);
2250
+ if (typeof _classPrivateFieldGet2(_refreshTokenFunc, this) === 'function') {
2251
+ return _classPrivateFieldGet2(_refreshTokenFunc, this).call(this, accessToken);
2832
2252
  }
2833
-
2834
2253
  return this.generateToken();
2835
2254
  }
2836
2255
  }, {
@@ -2838,100 +2257,60 @@ var ProvidedTokenGenerator = /*#__PURE__*/function () {
2838
2257
  value: function autoGenerateToken() {
2839
2258
  return this.generateToken();
2840
2259
  }
2841
- }, {
2842
- key: "token",
2843
- set: function set(token) {
2844
- _classPrivateFieldSet(this, _token, token);
2845
- }
2846
2260
  }]);
2847
-
2848
- return ProvidedTokenGenerator;
2849
2261
  }();
2850
2262
 
2851
2263
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2852
2264
  function isResponse(response) {
2853
2265
  return typeof (response === null || response === void 0 ? void 0 : response.json) === 'function';
2854
2266
  }
2855
-
2856
2267
  function manageOauthError(body, response) {
2857
2268
  var error;
2858
-
2859
2269
  if (response) {
2860
2270
  error = getHttpErrorFromResponse(response);
2861
2271
  }
2862
-
2863
2272
  if (body.error === 'invalid_grant') {
2864
2273
  throw new InvalidGrantError(body.error, error);
2865
2274
  }
2866
-
2867
2275
  if (body.error === 'invalid_scope') {
2868
2276
  throw new InvalidScopeError(body.error, error);
2869
2277
  }
2870
-
2871
2278
  throw new OauthError(body.error, error);
2872
2279
  }
2873
-
2874
- var _tokenGenerator = new WeakMap();
2875
-
2876
- var _hasATokenBeenGenerated = new WeakMap();
2877
-
2878
- var _asyncStorage = new WeakMap();
2879
-
2880
- var _logger = new WeakMap();
2881
-
2280
+ var _tokenGenerator = /*#__PURE__*/new WeakMap();
2281
+ var _hasATokenBeenGenerated = /*#__PURE__*/new WeakMap();
2282
+ var _asyncStorage = /*#__PURE__*/new WeakMap();
2283
+ var _logger = /*#__PURE__*/new WeakMap();
2882
2284
  var TokenStorage = /*#__PURE__*/function () {
2883
2285
  function TokenStorage(tokenGenerator, asyncStorage) {
2884
2286
  var accessTokenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'rest_client_sdk.api.access_token';
2885
2287
  var logger = arguments.length > 3 ? arguments[3] : undefined;
2886
-
2887
2288
  _classCallCheck(this, TokenStorage);
2888
-
2889
- _tokenGenerator.set(this, {
2890
- writable: true,
2891
- value: void 0
2892
- });
2893
-
2894
- _hasATokenBeenGenerated.set(this, {
2895
- writable: true,
2896
- value: void 0
2897
- });
2898
-
2289
+ _classPrivateFieldInitSpec(this, _tokenGenerator, void 0);
2290
+ _classPrivateFieldInitSpec(this, _hasATokenBeenGenerated, void 0);
2899
2291
  _defineProperty(this, "accessTokenKey", void 0);
2900
-
2901
- _asyncStorage.set(this, {
2902
- writable: true,
2903
- value: void 0
2904
- });
2905
-
2906
- _logger.set(this, {
2907
- writable: true,
2908
- value: void 0
2909
- });
2910
-
2292
+ _classPrivateFieldInitSpec(this, _asyncStorage, void 0);
2293
+ _classPrivateFieldInitSpec(this, _logger, void 0);
2911
2294
  if (logger) {
2912
- _classPrivateFieldSet(this, _logger, logger);
2295
+ _classPrivateFieldSet2(_logger, this, logger);
2913
2296
  }
2914
-
2915
- _classPrivateFieldSet(this, _tokenGenerator, tokenGenerator);
2916
-
2917
- _classPrivateFieldSet(this, _hasATokenBeenGenerated, false);
2918
-
2297
+ _classPrivateFieldSet2(_tokenGenerator, this, tokenGenerator);
2298
+ _classPrivateFieldSet2(_hasATokenBeenGenerated, this, false);
2919
2299
  this.setAsyncStorage(asyncStorage);
2920
2300
  this.accessTokenKey = accessTokenKey;
2921
2301
  this.handleTokenResponse = this.handleTokenResponse.bind(this);
2922
2302
  this.generateToken = memoizePromise(this.generateToken);
2923
2303
  this.refreshToken = memoizePromise(this.refreshToken);
2924
2304
  }
2925
-
2926
- _createClass(TokenStorage, [{
2305
+ return _createClass(TokenStorage, [{
2927
2306
  key: "setAsyncStorage",
2928
2307
  value: function setAsyncStorage(asyncStorage) {
2929
- _classPrivateFieldSet(this, _asyncStorage, asyncStorage);
2308
+ _classPrivateFieldSet2(_asyncStorage, this, asyncStorage);
2930
2309
  }
2931
2310
  }, {
2932
2311
  key: "hasAccessToken",
2933
2312
  value: function hasAccessToken() {
2934
- return _classPrivateFieldGet(this, _asyncStorage).getItem(this.accessTokenKey).then(function (accessToken) {
2313
+ return _classPrivateFieldGet2(_asyncStorage, this).getItem(this.accessTokenKey).then(function (accessToken) {
2935
2314
  return !!accessToken;
2936
2315
  });
2937
2316
  }
@@ -2946,33 +2325,27 @@ var TokenStorage = /*#__PURE__*/function () {
2946
2325
  key: "getAccessTokenObject",
2947
2326
  value: function getAccessTokenObject() {
2948
2327
  var _this = this;
2949
-
2950
- return _classPrivateFieldGet(this, _asyncStorage).getItem(this.accessTokenKey).then(function (token) {
2328
+ return _classPrivateFieldGet2(_asyncStorage, this).getItem(this.accessTokenKey).then(function (token) {
2951
2329
  if (token) {
2952
2330
  var tokenObject = JSON.parse(token);
2953
-
2954
2331
  if (_typeof(tokenObject) !== 'object') {
2955
2332
  return null;
2956
2333
  }
2957
-
2958
2334
  return tokenObject;
2959
2335
  }
2960
-
2961
- if (_classPrivateFieldGet(_this, _hasATokenBeenGenerated)) {
2336
+ if (_classPrivateFieldGet2(_hasATokenBeenGenerated, _this)) {
2962
2337
  return null;
2963
2338
  }
2964
-
2965
- if (typeof _classPrivateFieldGet(_this, _tokenGenerator).autoGenerateToken === 'function') {
2966
- return _classPrivateFieldGet(_this, _tokenGenerator).autoGenerateToken();
2339
+ if (typeof _classPrivateFieldGet2(_tokenGenerator, _this).autoGenerateToken === 'function') {
2340
+ return _classPrivateFieldGet2(_tokenGenerator, _this).autoGenerateToken();
2967
2341
  }
2968
-
2969
2342
  throw new Error('No token has been generated yet.');
2970
2343
  });
2971
2344
  }
2972
2345
  }, {
2973
2346
  key: "logout",
2974
2347
  value: function logout() {
2975
- return _classPrivateFieldGet(this, _asyncStorage).removeItem(this.accessTokenKey);
2348
+ return _classPrivateFieldGet2(_asyncStorage, this).removeItem(this.accessTokenKey);
2976
2349
  }
2977
2350
  }, {
2978
2351
  key: "_addExpiresAtToResponseData",
@@ -2980,30 +2353,25 @@ var TokenStorage = /*#__PURE__*/function () {
2980
2353
  if (!responseData) {
2981
2354
  return responseData;
2982
2355
  }
2983
-
2984
2356
  var updatedResponseData = _objectSpread2(_objectSpread2({}, responseData), {}, {
2985
2357
  expires_at: null
2986
2358
  });
2987
-
2988
- if (typeof updatedResponseData.expires_in !== 'undefined' && updatedResponseData.expires_in !== null // && updatedResponseData.expires_in >= 0
2359
+ if (typeof updatedResponseData.expires_in !== 'undefined' && updatedResponseData.expires_in !== null
2360
+ // && updatedResponseData.expires_in >= 0
2989
2361
  ) {
2990
- updatedResponseData.expires_at = Math.round(callTimestamp / 1000) + updatedResponseData.expires_in;
2991
- }
2992
-
2362
+ updatedResponseData.expires_at = Math.round(callTimestamp / 1000) + updatedResponseData.expires_in;
2363
+ }
2993
2364
  return updatedResponseData;
2994
2365
  }
2995
2366
  }, {
2996
2367
  key: "generateToken",
2997
2368
  value: function generateToken(parameters) {
2998
2369
  var _this2 = this;
2999
-
3000
2370
  var callTimestamp = Date.now();
3001
- return _classPrivateFieldGet(this, _tokenGenerator).generateToken(parameters).then(this.handleTokenResponse).then(function (body) {
2371
+ return _classPrivateFieldGet2(_tokenGenerator, this).generateToken(parameters).then(this.handleTokenResponse).then(function (body) {
3002
2372
  var updatedResponseData = _this2._addExpiresAtToResponseData(body, callTimestamp);
3003
-
3004
2373
  return _this2._storeAccessToken(updatedResponseData).then(function () {
3005
- _classPrivateFieldSet(_this2, _hasATokenBeenGenerated, true);
3006
-
2374
+ _classPrivateFieldSet2(_hasATokenBeenGenerated, _this2, true);
3007
2375
  return updatedResponseData;
3008
2376
  });
3009
2377
  });
@@ -3012,12 +2380,10 @@ var TokenStorage = /*#__PURE__*/function () {
3012
2380
  key: "refreshToken",
3013
2381
  value: function refreshToken() {
3014
2382
  var _this3 = this;
3015
-
3016
- return _classPrivateFieldGet(this, _asyncStorage).getItem(this.accessTokenKey).then(function (token) {
2383
+ return _classPrivateFieldGet2(_asyncStorage, this).getItem(this.accessTokenKey).then(function (token) {
3017
2384
  var callTimestamp = Date.now();
3018
- return _classPrivateFieldGet(_this3, _tokenGenerator).refreshToken(token ? JSON.parse(token) : null).then(_this3.handleTokenResponse).then(function (body) {
2385
+ return _classPrivateFieldGet2(_tokenGenerator, _this3).refreshToken(token ? JSON.parse(token) : null).then(_this3.handleTokenResponse).then(function (body) {
3019
2386
  var updatedResponseData = _this3._addExpiresAtToResponseData(body, callTimestamp);
3020
-
3021
2387
  return _this3._storeAccessToken(updatedResponseData).then(function () {
3022
2388
  return updatedResponseData;
3023
2389
  });
@@ -3030,11 +2396,9 @@ var TokenStorage = /*#__PURE__*/function () {
3030
2396
  if (isResponse(responseOrBody)) {
3031
2397
  var response = responseOrBody;
3032
2398
  var originalResponse = response.clone();
3033
-
3034
- if (_classPrivateFieldGet(this, _logger)) {
3035
- _classPrivateFieldGet(this, _logger).logResponse(response);
2399
+ if (_classPrivateFieldGet2(_logger, this)) {
2400
+ _classPrivateFieldGet2(_logger, this).logResponse(response);
3036
2401
  }
3037
-
3038
2402
  return response.json().then(function (body) {
3039
2403
  if (isOauthError(body)) {
3040
2404
  // throw error if response body is an oauth error
@@ -3043,31 +2407,26 @@ var TokenStorage = /*#__PURE__*/function () {
3043
2407
  // throw an error if response status code is an "error" status code
3044
2408
  throw getHttpErrorFromResponse(originalResponse);
3045
2409
  }
3046
-
3047
2410
  return body;
3048
2411
  })["catch"](function (err) {
3049
2412
  if (!(err instanceof OauthError)) {
3050
2413
  throw new OauthError(err.type, getHttpErrorFromResponse(originalResponse));
3051
2414
  }
3052
-
3053
2415
  throw err;
3054
2416
  });
3055
2417
  }
3056
-
3057
2418
  var body = responseOrBody;
3058
-
3059
2419
  if (isOauthError(body)) {
3060
2420
  // throw error if response body is an oauth error
3061
2421
  manageOauthError(body);
3062
2422
  }
3063
-
3064
2423
  return Promise.resolve(body);
3065
2424
  }
2425
+
3066
2426
  /**
3067
2427
  * Return the number of second when the token will expire
3068
2428
  * return value can be negative if the token is already expired
3069
2429
  */
3070
-
3071
2430
  }, {
3072
2431
  key: "getCurrentTokenExpiresIn",
3073
2432
  value: function getCurrentTokenExpiresIn() {
@@ -3075,11 +2434,9 @@ var TokenStorage = /*#__PURE__*/function () {
3075
2434
  if (accessTokenObject === null) {
3076
2435
  throw new Error('No token has been stored.');
3077
2436
  }
3078
-
3079
2437
  if (typeof accessTokenObject.expires_at === 'undefined' || accessTokenObject.expires_at === null) {
3080
2438
  return null;
3081
2439
  }
3082
-
3083
2440
  var now = Math.round(Date.now() / 1000);
3084
2441
  return accessTokenObject.expires_at - now;
3085
2442
  });
@@ -3087,13 +2444,10 @@ var TokenStorage = /*#__PURE__*/function () {
3087
2444
  }, {
3088
2445
  key: "_storeAccessToken",
3089
2446
  value: function _storeAccessToken(responseData) {
3090
- return _classPrivateFieldGet(this, _asyncStorage).setItem(this.accessTokenKey, JSON.stringify(responseData));
2447
+ return _classPrivateFieldGet2(_asyncStorage, this).setItem(this.accessTokenKey, JSON.stringify(responseData));
3091
2448
  }
3092
2449
  }]);
3093
-
3094
- return TokenStorage;
3095
2450
  }();
3096
2451
 
3097
- export default RestClientSdk;
3098
- export { AbstractClient, AbstractTokenGenerator, Attribute, AuthorizationCodeFlowTokenGenerator, BadRequestError, ClassMetadata, ClientCredentialsGenerator, ConflictError, ForbiddenError, HttpError, InternalServerError, InvalidGrantError, InvalidScopeError, Logger, Mapping, OauthError, PasswordGenerator, ProvidedTokenGenerator, Relation, ResourceNotFoundError, Serializer, TokenStorage, UnauthorizedError };
2452
+ export { AbstractClient, AbstractTokenGenerator, Attribute, AuthorizationCodeFlowTokenGenerator, BadRequestError, ClassMetadata, ClientCredentialsGenerator, ConflictError, ForbiddenError, HttpError, InternalServerError, InvalidGrantError, InvalidScopeError, Logger, Mapping, OauthError, PasswordGenerator, ProvidedTokenGenerator, Relation, ResourceNotFoundError, Serializer, TokenStorage, UnauthorizedError, RestClientSdk as default };
3099
2453
  //# sourceMappingURL=index.mjs.map