rest-client-sdk 7.2.3 → 7.4.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);
18
- }
19
-
20
- function _classCallCheck(instance, Constructor) {
21
- if (!(instance instanceof Constructor)) {
22
- throw new TypeError("Cannot call a class as a function");
23
- }
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;
24
8
  }
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
- }
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");
34
12
  }
35
-
36
- function _createClass(Constructor, protoProps, staticProps) {
37
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
38
- if (staticProps) _defineProperties(Constructor, staticProps);
39
- return Constructor;
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;
40
16
  }
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;
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));
55
19
  }
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;
20
+ function _checkPrivateRedeclaration(e, t) {
21
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
69
22
  }
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;
23
+ function _classCallCheck(a, n) {
24
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
89
25
  }
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);
26
+ function _classPrivateFieldGet2(s, a) {
27
+ return s.get(_assertClassBrand(s, a));
104
28
  }
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);
29
+ function _classPrivateFieldInitSpec(e, t, a) {
30
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
111
31
  }
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);
32
+ function _classPrivateFieldSet2(s, a, r) {
33
+ return s.set(_assertClassBrand(s, a), r), r;
120
34
  }
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
- }
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;
133
41
  }
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
- };
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);
147
46
  }
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
47
  }
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;
48
+ function _createClass(e, r, t) {
49
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
50
+ writable: false
51
+ }), e;
203
52
  }
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;
224
- }
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;
232
- }
233
-
234
- function _possibleConstructorReturn(self, call) {
235
- if (call && (typeof call === "object" || typeof call === "function")) {
236
- return call;
237
- }
238
-
239
- return _assertThisInitialized(self);
240
- }
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);
268
- }
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
 
942
- var EXPIRE_LIMIT_SECONDS = 300; // = 5 minutes
943
-
944
- var _tokenStorage = new WeakMap();
945
-
946
- var _isUnitOfWorkEnabled = new WeakMap();
947
-
675
+ var _excluded = ["headers"];
676
+ var EXPIRE_LIMIT_SECONDS = 300; // = 5 minutes
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,57 +811,69 @@ 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) {
1112
817
  var queryParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1113
818
  var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
819
+ return this._update('PUT', entity, queryParam, requestParams);
820
+ }
821
+
822
+ /**
823
+ * partially update an entity using the `PATCH` HTTP verb
824
+ *
825
+ * @param {Record<string, unknown>} entity the entity to update
826
+ * @param {Record<string, unknown>} queryParam query parameters that will be added to the request
827
+ * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
828
+ */
829
+ }, {
830
+ key: "patch",
831
+ value: function patch(entity) {
832
+ var queryParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
833
+ var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
834
+ return this._update('PATCH', entity, queryParam, requestParams);
835
+ }
836
+ }, {
837
+ key: "_update",
838
+ value: function _update(method, entity) {
839
+ var queryParam = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
840
+ var requestParams = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1114
841
  var url = new URI(this.getEntityURI(entity));
1115
842
  url.addSearch(queryParam);
1116
843
  var newSerializedModel = this.serializer.normalizeItem(entity, this.metadata);
1117
-
1118
844
  var identifier = this._getEntityIdentifier(newSerializedModel);
1119
-
1120
845
  var oldModel;
1121
-
1122
846
  if (identifier !== null) {
1123
847
  oldModel = this.sdk.unitOfWork.getDirtyEntity(identifier);
1124
848
  }
1125
-
1126
849
  if (oldModel) {
1127
850
  newSerializedModel = this.sdk.unitOfWork.getDirtyData(newSerializedModel, oldModel, this.metadata);
1128
851
  }
1129
-
1130
852
  return this.deserializeResponse(this.authorizedFetch(url, _objectSpread2({
1131
- method: 'PUT',
853
+ method: method,
1132
854
  body: this.serializer.encodeItem(newSerializedModel, this.metadata)
1133
855
  }, requestParams)), 'item');
1134
856
  }
857
+
1135
858
  /**
1136
859
  * delete an entity
1137
860
  *
1138
861
  * @param {Record<string, unknown>} the entity to delete
1139
862
  * @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call
1140
863
  */
1141
-
1142
864
  }, {
1143
865
  key: "delete",
1144
866
  value: function _delete(entity) {
1145
867
  var _this = this;
1146
-
1147
868
  var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1148
869
  var url = this.getEntityURI(entity);
1149
-
1150
870
  var identifier = this._getEntityIdentifier(entity);
1151
-
1152
871
  return this.authorizedFetch(url, _objectSpread2({
1153
872
  method: 'DELETE'
1154
873
  }, requestParams)).then(function (response) {
1155
874
  if (identifier !== null) {
1156
875
  _this.sdk.unitOfWork.clear(identifier);
1157
876
  }
1158
-
1159
877
  return response;
1160
878
  });
1161
879
  }
@@ -1163,7 +881,6 @@ var AbstractClient = /*#__PURE__*/function () {
1163
881
  key: "deserializeResponse",
1164
882
  value: function deserializeResponse(requestPromise, listOrItem) {
1165
883
  var _this2 = this;
1166
-
1167
884
  return requestPromise.then(function (response) {
1168
885
  return response.text().then(function (text) {
1169
886
  return {
@@ -1173,26 +890,20 @@ var AbstractClient = /*#__PURE__*/function () {
1173
890
  });
1174
891
  }).then(function (_ref) {
1175
892
  var response = _ref.response,
1176
- text = _ref.text;
1177
-
893
+ text = _ref.text;
1178
894
  if (listOrItem === 'list') {
1179
895
  // for list, we need to deserialize the result to get an object
1180
896
  var itemList = _this2.serializer.deserializeList(text, _this2.metadata, response);
1181
-
1182
- if (_classPrivateFieldGet(_this2, _isUnitOfWorkEnabled)) {
1183
- // eslint-disable-next-line no-restricted-syntax
897
+ if (_classPrivateFieldGet2(_isUnitOfWorkEnabled, _this2)) {
1184
898
  var _iterator = _createForOfIteratorHelper(itemList),
1185
- _step;
1186
-
899
+ _step;
1187
900
  try {
1188
901
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
1189
902
  var _decodedItem = _step.value;
1190
-
1191
903
  var _identifier = _this2._getEntityIdentifier(_decodedItem);
904
+ var normalizedItem = _this2.serializer.normalizeItem(_decodedItem, _this2.metadata);
1192
905
 
1193
- var normalizedItem = _this2.serializer.normalizeItem(_decodedItem, _this2.metadata); // then we register the re-normalized item
1194
-
1195
-
906
+ // then we register the re-normalized item
1196
907
  if (_identifier !== null) {
1197
908
  _this2.sdk.unitOfWork.registerClean(_identifier, normalizedItem);
1198
909
  }
@@ -1203,23 +914,20 @@ var AbstractClient = /*#__PURE__*/function () {
1203
914
  _iterator.f();
1204
915
  }
1205
916
  }
1206
-
1207
917
  return itemList;
1208
- } // for items, we can just decode the item (ie. transform it to JS object)
1209
-
1210
-
1211
- var decodedItem = _this2.serializer.decodeItem(text, _this2.metadata, response); // and register it directy without deserializing + renormalizing
1212
-
918
+ }
1213
919
 
1214
- 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);
1215
922
 
923
+ // and register it directy without deserializing + renormalizing
924
+ var identifier = _this2._getEntityIdentifier(decodedItem);
1216
925
 
926
+ // and finally return the denormalized item
1217
927
  var item = _this2.serializer.denormalizeItem(decodedItem, _this2.metadata, response);
1218
-
1219
- if (_classPrivateFieldGet(_this2, _isUnitOfWorkEnabled) && identifier !== null) {
928
+ if (_classPrivateFieldGet2(_isUnitOfWorkEnabled, _this2) && identifier !== null) {
1220
929
  _this2.sdk.unitOfWork.registerClean(identifier, _this2.serializer.normalizeItem(item, _this2.metadata));
1221
930
  }
1222
-
1223
931
  return item;
1224
932
  });
1225
933
  }
@@ -1228,20 +936,16 @@ var AbstractClient = /*#__PURE__*/function () {
1228
936
  value: function makeUri(input) {
1229
937
  var url = input instanceof URI ? input : new URI(input);
1230
938
  url.host(this.sdk.config.path).scheme(this.sdk.config.scheme);
1231
-
1232
939
  if (this.sdk.config.port) {
1233
940
  url.port(String(this.sdk.config.port));
1234
941
  }
1235
-
1236
942
  if (this.sdk.mapping.idPrefix) {
1237
943
  var segments = url.segment();
1238
-
1239
944
  if (!url.pathname().startsWith(this.sdk.mapping.idPrefix)) {
1240
945
  segments.unshift(this.sdk.mapping.idPrefix);
1241
946
  url.segment(segments);
1242
947
  }
1243
948
  }
1244
-
1245
949
  return url;
1246
950
  }
1247
951
  }, {
@@ -1257,17 +961,13 @@ var AbstractClient = /*#__PURE__*/function () {
1257
961
  var pathParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1258
962
  var id = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1259
963
  var params = queryParam;
1260
-
1261
964
  if (this.sdk.config.useDefaultParameters) {
1262
965
  Object.assign(params, this.getDefaultParameters());
1263
966
  }
1264
-
1265
967
  var pathBase = this.getPathBase(pathParameters);
1266
- var url = null;
1267
-
968
+ var url;
1268
969
  if (id) {
1269
970
  var testPathBase = this.sdk.mapping.idPrefix ? "".concat(this.sdk.mapping.idPrefix).concat(pathBase) : pathBase;
1270
-
1271
971
  if (typeof id === 'string' && id.startsWith(testPathBase)) {
1272
972
  url = new URI(id);
1273
973
  } else {
@@ -1276,63 +976,51 @@ var AbstractClient = /*#__PURE__*/function () {
1276
976
  } else {
1277
977
  url = new URI(pathBase);
1278
978
  }
1279
-
1280
979
  if (params) {
1281
980
  url.addSearch(params);
1282
981
  }
1283
-
1284
982
  return url;
1285
983
  }
1286
984
  }, {
1287
985
  key: "_fetchWithToken",
1288
986
  value: function _fetchWithToken(input) {
1289
987
  var _this3 = this;
1290
-
1291
988
  var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1292
-
1293
989
  if (!input) {
1294
990
  throw new Error('input is empty');
1295
991
  }
1296
-
1297
- if (_classPrivateFieldGet(this, _tokenStorage)) {
1298
- return _classPrivateFieldGet(this, _tokenStorage).getCurrentTokenExpiresIn().then(function (accessTokenExpiresIn) {
992
+ if (_classPrivateFieldGet2(_tokenStorage, this)) {
993
+ return _classPrivateFieldGet2(_tokenStorage, this).getCurrentTokenExpiresIn().then(function (accessTokenExpiresIn) {
1299
994
  if (accessTokenExpiresIn !== null && accessTokenExpiresIn <= EXPIRE_LIMIT_SECONDS) {
1300
- return _classPrivateFieldGet(_this3, _tokenStorage).refreshToken().then(function (refreshedTokenObject) {
995
+ return _classPrivateFieldGet2(_tokenStorage, _this3).refreshToken().then(function (refreshedTokenObject) {
1301
996
  return refreshedTokenObject.access_token;
1302
997
  })["catch"](function (e) {
1303
998
  _this3._handleRefreshTokenFailure(e);
1304
-
1305
999
  throw e;
1306
1000
  });
1307
1001
  }
1308
-
1309
- return _classPrivateFieldGet(_this3, _tokenStorage).getAccessToken();
1002
+ return _classPrivateFieldGet2(_tokenStorage, _this3).getAccessToken();
1310
1003
  }).then(function (token) {
1311
1004
  return _this3._doFetch(token, input, requestParams);
1312
1005
  });
1313
1006
  }
1314
-
1315
1007
  return this._doFetch(null, input, requestParams);
1316
1008
  }
1317
1009
  }, {
1318
1010
  key: "_refreshTokenAndRefetch",
1319
1011
  value: function _refreshTokenAndRefetch(input) {
1320
1012
  var _this4 = this;
1321
-
1322
1013
  var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1323
- return _classPrivateFieldGet(this, _tokenStorage).refreshToken().then(function () {
1014
+ return _classPrivateFieldGet2(_tokenStorage, this).refreshToken().then(function () {
1324
1015
  // eslint-disable-next-line prefer-const
1325
1016
  var headers = requestParams.headers,
1326
- rest = _objectWithoutProperties(requestParams, ["headers"]);
1327
-
1017
+ rest = _objectWithoutProperties(requestParams, _excluded);
1328
1018
  var updatedRequestParams = _objectSpread2(_objectSpread2({}, rest), {}, {
1329
1019
  headers: removeAuthorization(headers)
1330
1020
  });
1331
-
1332
1021
  return _this4._fetchWithToken(input, updatedRequestParams);
1333
1022
  })["catch"](function (e) {
1334
1023
  _this4._handleRefreshTokenFailure(e);
1335
-
1336
1024
  throw e;
1337
1025
  });
1338
1026
  }
@@ -1340,33 +1028,28 @@ var AbstractClient = /*#__PURE__*/function () {
1340
1028
  key: "_manageUnauthorized",
1341
1029
  value: function _manageUnauthorized(response, input) {
1342
1030
  var _this5 = this;
1343
-
1344
1031
  var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1345
- var error = getHttpErrorFromResponse(response); // https://tools.ietf.org/html/rfc2617#section-1.2
1032
+ var error = getHttpErrorFromResponse(response);
1346
1033
 
1034
+ // https://tools.ietf.org/html/rfc2617#section-1.2
1347
1035
  var authorizationHeader = response.headers.get('www-authenticate');
1348
-
1349
1036
  if (authorizationHeader) {
1350
1037
  var invalidGrant = authorizationHeader.indexOf('error="invalid_grant"') > -1;
1351
-
1352
- if (invalidGrant && _classPrivateFieldGet(this, _tokenStorage)) {
1038
+ if (invalidGrant && _classPrivateFieldGet2(_tokenStorage, this)) {
1353
1039
  return this._refreshTokenAndRefetch(input, requestParams);
1354
1040
  }
1355
-
1356
1041
  throw error;
1357
1042
  } else {
1358
1043
  // if www-authenticate header is missing, try and read json response
1359
1044
  return response.json().then(function (body) {
1360
- 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')) {
1361
1046
  return _this5._refreshTokenAndRefetch(input, requestParams);
1362
1047
  }
1363
-
1364
1048
  throw error;
1365
1049
  })["catch"](function (err) {
1366
1050
  if (err instanceof OauthError) {
1367
1051
  throw err;
1368
1052
  }
1369
-
1370
1053
  throw error;
1371
1054
  });
1372
1055
  }
@@ -1375,58 +1058,45 @@ var AbstractClient = /*#__PURE__*/function () {
1375
1058
  key: "_doFetch",
1376
1059
  value: function _doFetch(accessToken, input, requestParams) {
1377
1060
  var _this6 = this;
1378
-
1379
1061
  var params = requestParams;
1380
1062
  var baseHeaders = {};
1381
-
1382
1063
  if (params.method !== 'GET' || params.method !== 'GET' && params.method !== 'DELETE') {
1383
1064
  baseHeaders = {
1384
1065
  'Content-Type': 'application/json'
1385
1066
  };
1386
1067
  }
1387
-
1388
1068
  if (accessToken) {
1389
1069
  baseHeaders.Authorization = "".concat(this.sdk.config.authorizationType, " ").concat(accessToken);
1390
1070
  }
1391
-
1392
1071
  if (params) {
1393
1072
  if (!params.headers) {
1394
1073
  params.headers = {};
1395
1074
  }
1396
-
1397
1075
  params.headers = Object.assign(baseHeaders, params.headers);
1398
1076
  } else {
1399
1077
  params = {
1400
1078
  headers: baseHeaders
1401
1079
  };
1402
1080
  }
1403
-
1404
1081
  if (params.headers) {
1405
1082
  params.headers = removeUndefinedHeaders(params.headers);
1406
1083
  }
1407
-
1408
1084
  var logId;
1409
-
1410
1085
  if (this.sdk.logger) {
1411
1086
  logId = this.sdk.logger.logRequest(_objectSpread2({
1412
1087
  url: input
1413
1088
  }, params));
1414
- } // eslint-disable-next-line consistent-return
1415
-
1416
-
1089
+ }
1417
1090
  return fetch(input, params).then(function (response) {
1418
1091
  if (_this6.sdk.logger) {
1419
1092
  _this6.sdk.logger.logResponse(response, logId);
1420
1093
  }
1421
-
1422
1094
  if (response.status < 400) {
1423
1095
  return response;
1424
1096
  }
1425
-
1426
1097
  if (response.status === 401) {
1427
1098
  return _this6._manageUnauthorized(response, input, params);
1428
1099
  }
1429
-
1430
1100
  var httpError = getHttpErrorFromResponse(response);
1431
1101
  throw httpError;
1432
1102
  });
@@ -1434,18 +1104,18 @@ var AbstractClient = /*#__PURE__*/function () {
1434
1104
  }, {
1435
1105
  key: "_getEntityIdentifier",
1436
1106
  value: function _getEntityIdentifier(object) {
1437
- var idKey = this.metadata.getIdentifierAttribute().serializedKey; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1438
- // @ts-ignore
1107
+ var idKey = this.metadata.getIdentifierAttribute().serializedKey;
1439
1108
 
1109
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1110
+ // @ts-ignore
1440
1111
  return object[idKey];
1441
1112
  }
1442
1113
  }, {
1443
1114
  key: "_handleRefreshTokenFailure",
1444
1115
  value: function _handleRefreshTokenFailure(error) {
1445
1116
  var _this7 = this;
1446
-
1447
1117
  if (error instanceof OauthError) {
1448
- _classPrivateFieldGet(this, _tokenStorage).logout().then(function () {
1118
+ _classPrivateFieldGet2(_tokenStorage, this).logout().then(function () {
1449
1119
  if (_this7.sdk.config.onRefreshTokenFailure) {
1450
1120
  _this7.sdk.config.onRefreshTokenFailure(error);
1451
1121
  }
@@ -1453,16 +1123,11 @@ var AbstractClient = /*#__PURE__*/function () {
1453
1123
  }
1454
1124
  }
1455
1125
  }]);
1456
-
1457
- return AbstractClient;
1458
1126
  }();
1459
1127
 
1460
- var _attributeList = new WeakMap();
1461
-
1462
- var _relationList = new WeakMap();
1463
-
1464
- var _identifierAttribute = new WeakMap();
1465
-
1128
+ var _attributeList = /*#__PURE__*/new WeakMap();
1129
+ var _relationList = /*#__PURE__*/new WeakMap();
1130
+ var _identifierAttribute = /*#__PURE__*/new WeakMap();
1466
1131
  var ClassMetadata = /*#__PURE__*/function () {
1467
1132
  /**
1468
1133
  * @param {string} key mandatory, will be passed in your serializer
@@ -1472,86 +1137,59 @@ var ClassMetadata = /*#__PURE__*/function () {
1472
1137
  function ClassMetadata(key) {
1473
1138
  var pathRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1474
1139
  var repositoryClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : AbstractClient;
1475
-
1476
1140
  _classCallCheck(this, ClassMetadata);
1477
-
1478
1141
  _defineProperty(this, "key", void 0);
1479
-
1480
1142
  _defineProperty(this, "pathRoot", void 0);
1481
-
1482
1143
  _defineProperty(this, "repositoryClass", void 0);
1483
-
1484
- _attributeList.set(this, {
1485
- writable: true,
1486
- value: void 0
1487
- });
1488
-
1489
- _relationList.set(this, {
1490
- writable: true,
1491
- value: void 0
1492
- });
1493
-
1494
- _identifierAttribute.set(this, {
1495
- writable: true,
1496
- value: void 0
1497
- });
1498
-
1144
+ _classPrivateFieldInitSpec(this, _attributeList, void 0);
1145
+ _classPrivateFieldInitSpec(this, _relationList, void 0);
1146
+ _classPrivateFieldInitSpec(this, _identifierAttribute, void 0);
1499
1147
  if (!key) {
1500
1148
  throw new TypeError('key attribute are required');
1501
1149
  }
1502
-
1503
1150
  this.key = key;
1504
- this.pathRoot = pathRoot || key; // this.modelName = modelName;
1505
-
1151
+ this.pathRoot = pathRoot || key;
1152
+ // this.modelName = modelName;
1506
1153
  this.repositoryClass = repositoryClass;
1507
-
1508
- _classPrivateFieldSet(this, _attributeList, {});
1509
-
1510
- _classPrivateFieldSet(this, _relationList, {});
1154
+ _classPrivateFieldSet2(_attributeList, this, {});
1155
+ _classPrivateFieldSet2(_relationList, this, {});
1511
1156
  }
1512
-
1513
- _createClass(ClassMetadata, [{
1157
+ return _createClass(ClassMetadata, [{
1514
1158
  key: "getAttribute",
1515
1159
  value: function getAttribute(name) {
1516
- return _classPrivateFieldGet(this, _attributeList)[name];
1160
+ return _classPrivateFieldGet2(_attributeList, this)[name];
1517
1161
  }
1518
1162
  }, {
1519
1163
  key: "hasIdentifierAttribute",
1520
1164
  value: function hasIdentifierAttribute() {
1521
- return !!_classPrivateFieldGet(this, _identifierAttribute);
1165
+ return !!_classPrivateFieldGet2(_identifierAttribute, this);
1522
1166
  }
1523
1167
  }, {
1524
1168
  key: "getIdentifierAttribute",
1525
1169
  value: function getIdentifierAttribute() {
1526
- if (!_classPrivateFieldGet(this, _identifierAttribute)) {
1170
+ if (!_classPrivateFieldGet2(_identifierAttribute, this)) {
1527
1171
  throw new TypeError("\"".concat(this.key, "\" has no identifier attribute set. Did you call \"setAttributeList\" first ?"));
1528
1172
  }
1529
-
1530
- return _classPrivateFieldGet(this, _identifierAttribute);
1173
+ return _classPrivateFieldGet2(_identifierAttribute, this);
1531
1174
  }
1532
1175
  }, {
1533
1176
  key: "getAttributeList",
1534
1177
  value: function getAttributeList() {
1535
- return _classPrivateFieldGet(this, _attributeList);
1178
+ return _classPrivateFieldGet2(_attributeList, this);
1536
1179
  }
1537
1180
  }, {
1538
1181
  key: "setAttributeList",
1539
1182
  value: function setAttributeList(attributeList) {
1540
1183
  var _this = this;
1541
-
1542
- _classPrivateFieldSet(this, _attributeList, {});
1543
-
1544
- _classPrivateFieldSet(this, _identifierAttribute, undefined);
1545
-
1184
+ _classPrivateFieldSet2(_attributeList, this, {});
1185
+ _classPrivateFieldSet2(_identifierAttribute, this, undefined);
1546
1186
  attributeList.forEach(function (attribute) {
1547
- _classPrivateFieldGet(_this, _attributeList)[attribute.serializedKey] = attribute;
1548
-
1187
+ _classPrivateFieldGet2(_attributeList, _this)[attribute.serializedKey] = attribute;
1549
1188
  if (attribute.isIdentifier) {
1550
- _classPrivateFieldSet(_this, _identifierAttribute, attribute);
1189
+ _classPrivateFieldSet2(_identifierAttribute, _this, attribute);
1551
1190
  }
1552
1191
  });
1553
-
1554
- if (!_classPrivateFieldGet(this, _identifierAttribute)) {
1192
+ if (!_classPrivateFieldGet2(_identifierAttribute, this)) {
1555
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\""));
1556
1194
  }
1557
1195
  }
@@ -1559,31 +1197,27 @@ var ClassMetadata = /*#__PURE__*/function () {
1559
1197
  key: "setRelationList",
1560
1198
  value: function setRelationList(relationList) {
1561
1199
  var _this2 = this;
1562
-
1563
- _classPrivateFieldSet(this, _relationList, {});
1564
-
1200
+ _classPrivateFieldSet2(_relationList, this, {});
1565
1201
  relationList.forEach(function (relation) {
1566
- _classPrivateFieldGet(_this2, _relationList)[relation.serializedKey] = relation;
1567
- _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');
1568
1204
  });
1569
1205
  }
1570
1206
  }, {
1571
1207
  key: "getRelation",
1572
1208
  value: function getRelation(key) {
1573
- return _classPrivateFieldGet(this, _relationList)[key];
1209
+ return _classPrivateFieldGet2(_relationList, this)[key];
1574
1210
  }
1575
1211
  }, {
1576
1212
  key: "getDefaultSerializedModel",
1577
1213
  value: function getDefaultSerializedModel() {
1578
1214
  var _this3 = this;
1579
-
1580
1215
  var out = {};
1581
- Object.keys(_classPrivateFieldGet(this, _attributeList)).forEach(function (serializedKey) {
1216
+ Object.keys(_classPrivateFieldGet2(_attributeList, this)).forEach(function (serializedKey) {
1582
1217
  out[serializedKey] = null;
1583
1218
  });
1584
- Object.keys(_classPrivateFieldGet(this, _relationList)).forEach(function (serializedKey) {
1585
- var relation = _classPrivateFieldGet(_this3, _relationList)[serializedKey];
1586
-
1219
+ Object.keys(_classPrivateFieldGet2(_relationList, this)).forEach(function (serializedKey) {
1220
+ var relation = _classPrivateFieldGet2(_relationList, _this3)[serializedKey];
1587
1221
  if (relation.isRelationToMany()) {
1588
1222
  out[serializedKey] = [];
1589
1223
  }
@@ -1591,19 +1225,15 @@ var ClassMetadata = /*#__PURE__*/function () {
1591
1225
  return out;
1592
1226
  }
1593
1227
  }]);
1594
-
1595
- return ClassMetadata;
1596
1228
  }();
1597
1229
 
1598
- var RelationTypes;
1599
-
1600
- (function (RelationTypes) {
1230
+ var RelationTypes = /*#__PURE__*/function (RelationTypes) {
1601
1231
  RelationTypes["ONE_TO_ONE"] = "ONE_TO_ONE";
1602
1232
  RelationTypes["ONE_TO_MANY"] = "ONE_TO_MANY";
1603
1233
  RelationTypes["MANY_TO_MANY"] = "MANY_TO_MANY";
1604
1234
  RelationTypes["MANY_TO_ONE"] = "MANY_TO_ONE";
1605
- })(RelationTypes || (RelationTypes = {}));
1606
-
1235
+ return RelationTypes;
1236
+ }(RelationTypes || {});
1607
1237
  var Relation = /*#__PURE__*/function () {
1608
1238
  /**
1609
1239
  * @param {RelationTypes} type the type of relation
@@ -1613,24 +1243,17 @@ var Relation = /*#__PURE__*/function () {
1613
1243
  */
1614
1244
  function Relation(type, targetMetadataKey, serializedKey) {
1615
1245
  var attributeName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1616
-
1617
1246
  _classCallCheck(this, Relation);
1618
-
1619
1247
  _defineProperty(this, "type", void 0);
1620
-
1621
1248
  _defineProperty(this, "targetMetadataKey", void 0);
1622
-
1623
1249
  _defineProperty(this, "serializedKey", void 0);
1624
-
1625
1250
  _defineProperty(this, "attributeName", void 0);
1626
-
1627
1251
  this.type = type;
1628
1252
  this.targetMetadataKey = targetMetadataKey;
1629
1253
  this.serializedKey = serializedKey;
1630
1254
  this.attributeName = attributeName || this.serializedKey;
1631
1255
  }
1632
-
1633
- _createClass(Relation, [{
1256
+ return _createClass(Relation, [{
1634
1257
  key: "isOneToOne",
1635
1258
  value: function isOneToOne() {
1636
1259
  return this.type === Relation.ONE_TO_ONE;
@@ -1661,16 +1284,10 @@ var Relation = /*#__PURE__*/function () {
1661
1284
  return this.isManyToOne() || this.isOneToOne();
1662
1285
  }
1663
1286
  }]);
1664
-
1665
- return Relation;
1666
1287
  }();
1667
-
1668
1288
  _defineProperty(Relation, "ONE_TO_ONE", RelationTypes.ONE_TO_ONE);
1669
-
1670
1289
  _defineProperty(Relation, "ONE_TO_MANY", RelationTypes.ONE_TO_MANY);
1671
-
1672
1290
  _defineProperty(Relation, "MANY_TO_ONE", RelationTypes.MANY_TO_ONE);
1673
-
1674
1291
  _defineProperty(Relation, "MANY_TO_MANY", RelationTypes.MANY_TO_MANY);
1675
1292
 
1676
1293
  /* eslint-disable */
@@ -1683,6 +1300,7 @@ _defineProperty(Relation, "MANY_TO_MANY", RelationTypes.MANY_TO_MANY);
1683
1300
  * This source code is licensed under the MIT license found in the
1684
1301
  * LICENSE file in the root directory of this source tree.
1685
1302
  */
1303
+
1686
1304
  var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
1687
1305
  var IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@';
1688
1306
  function isImmutable(maybeImmutable) {
@@ -1702,112 +1320,87 @@ function objectDiffers(left, right) {
1702
1320
  var result = diff(left, right);
1703
1321
  return result ? result.length > 0 : false;
1704
1322
  }
1323
+
1705
1324
  /**
1706
1325
  * get the id of an entity or return itself if string
1707
1326
  */
1708
-
1709
-
1710
1327
  function getEntityId(stringOrEntity, idSerializedKey) {
1711
1328
  if (_typeof(stringOrEntity) !== 'object') {
1712
1329
  return stringOrEntity;
1713
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1714
- // @ts-ignore
1715
-
1330
+ }
1716
1331
 
1332
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1333
+ // @ts-ignore
1717
1334
  return stringOrEntity[idSerializedKey];
1718
1335
  }
1336
+
1719
1337
  /**
1720
1338
  * find old relation value from the new relation id
1721
1339
  * if not found, returs the default serilazed model
1722
1340
  */
1723
-
1724
-
1725
1341
  function findOldRelation(newRelationValue, oldRelationValue, classMetadata) {
1726
- 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
1727
1344
  // @ts-ignore
1728
-
1729
1345
  var relationValueId = getEntityId(newRelationValue, idSerializedKey);
1730
1346
  var foundValue = oldRelationValue && oldRelationValue.find(function (innerOldRelationValue) {
1731
1347
  var oldRelationValueId = getEntityId(innerOldRelationValue, idSerializedKey);
1732
1348
  return relationValueId === oldRelationValueId;
1733
1349
  });
1734
-
1735
1350
  if (foundValue) {
1736
1351
  return foundValue;
1737
1352
  }
1738
-
1739
1353
  return classMetadata.getDefaultSerializedModel();
1740
1354
  }
1355
+
1741
1356
  /**
1742
1357
  * add all identifier from one to many relation list
1743
1358
  */
1744
-
1745
-
1746
1359
  function getIdentifierForList(newValue, idSerializedKey) {
1747
1360
  return newValue.map(function (value) {
1748
1361
  if (Object.keys(value).includes(idSerializedKey)) {
1749
1362
  return _defineProperty({}, idSerializedKey, value[idSerializedKey]);
1750
1363
  }
1751
-
1752
1364
  if (typeof value === 'string') {
1753
1365
  return value;
1754
1366
  }
1755
-
1756
1367
  throw new TypeError('new value should include a list of string or objects containing the serialized key');
1757
1368
  });
1758
1369
  }
1759
-
1760
- var _storage = new WeakMap();
1761
-
1762
- var _enabled = new WeakMap();
1763
-
1370
+ var _storage = /*#__PURE__*/new WeakMap();
1371
+ var _enabled = /*#__PURE__*/new WeakMap();
1764
1372
  var UnitOfWork = /*#__PURE__*/function () {
1765
1373
  function UnitOfWork(mapping) {
1766
1374
  var enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1767
-
1768
1375
  _classCallCheck(this, UnitOfWork);
1769
-
1770
1376
  _defineProperty(this, "mapping", void 0);
1771
-
1772
- _storage.set(this, {
1773
- writable: true,
1774
- value: void 0
1775
- });
1776
-
1777
- _enabled.set(this, {
1778
- writable: true,
1779
- value: void 0
1780
- });
1781
-
1377
+ _classPrivateFieldInitSpec(this, _storage, void 0);
1378
+ _classPrivateFieldInitSpec(this, _enabled, void 0);
1782
1379
  this.mapping = mapping;
1783
-
1784
- _classPrivateFieldSet(this, _enabled, enabled);
1785
-
1786
- _classPrivateFieldSet(this, _storage, {});
1380
+ _classPrivateFieldSet2(_enabled, this, enabled);
1381
+ _classPrivateFieldSet2(_storage, this, {});
1787
1382
  }
1788
-
1789
- _createClass(UnitOfWork, [{
1383
+ return _createClass(UnitOfWork, [{
1790
1384
  key: "registerClean",
1791
1385
  value: function registerClean(id, entity) {
1792
- if (!_classPrivateFieldGet(this, _enabled)) {
1386
+ if (!_classPrivateFieldGet2(_enabled, this)) {
1793
1387
  return;
1794
1388
  }
1795
-
1796
1389
  if (isImmutable(entity)) {
1797
- _classPrivateFieldGet(this, _storage)[id] = entity;
1390
+ _classPrivateFieldGet2(_storage, this)[id] = entity;
1798
1391
  } else {
1799
- _classPrivateFieldGet(this, _storage)[id] = _objectSpread2({}, entity);
1392
+ _classPrivateFieldGet2(_storage, this)[id] = _objectSpread2({}, entity);
1800
1393
  }
1801
1394
  }
1802
1395
  }, {
1803
1396
  key: "getDirtyEntity",
1804
1397
  value: function getDirtyEntity(id) {
1805
- return _classPrivateFieldGet(this, _storage)[id];
1398
+ return _classPrivateFieldGet2(_storage, this)[id];
1806
1399
  }
1807
1400
  }, {
1808
1401
  key: "clear",
1809
1402
  value: function clear(id) {
1810
- delete _classPrivateFieldGet(this, _storage)[id];
1403
+ delete _classPrivateFieldGet2(_storage, this)[id];
1811
1404
  }
1812
1405
  }, {
1813
1406
  key: "getDirtyData",
@@ -1818,7 +1411,6 @@ var UnitOfWork = /*#__PURE__*/function () {
1818
1411
  key: "_getDirtyFieldsForAttribute",
1819
1412
  value: function _getDirtyFieldsForAttribute(dirtyFieldsParam, key, attribute, oldValue, newValue) {
1820
1413
  var dirtyFields = dirtyFieldsParam;
1821
-
1822
1414
  if (attribute.type === 'object' || attribute.type === 'array') {
1823
1415
  if (oldValue === undefined || objectDiffers(oldValue, newValue)) {
1824
1416
  dirtyFields[key] = newValue;
@@ -1826,71 +1418,58 @@ var UnitOfWork = /*#__PURE__*/function () {
1826
1418
  } else if (oldValue !== newValue) {
1827
1419
  dirtyFields[key] = newValue;
1828
1420
  }
1829
-
1830
1421
  return dirtyFields;
1831
1422
  }
1832
1423
  }, {
1833
1424
  key: "_getDirtyFieldsForManyToOne",
1834
1425
  value: function _getDirtyFieldsForManyToOne(dirtyFieldsParam, key, oldValue, newValue, relationMetadata, idSerializedKey) {
1835
1426
  var dirtyFields = dirtyFieldsParam;
1836
-
1837
1427
  if (oldValue !== newValue) {
1838
1428
  if (newValue === null) {
1839
1429
  dirtyFields[key] = null;
1840
1430
  return dirtyFields;
1841
1431
  }
1842
-
1843
1432
  if (typeof oldValue === 'string' || typeof newValue === 'string') {
1844
1433
  dirtyFields[key] = newValue;
1845
1434
  }
1846
-
1847
1435
  var recursiveDiff = this._getDirtyFields(newValue, oldValue, relationMetadata);
1848
-
1849
1436
  if (Object.keys(recursiveDiff).length > 0) {
1850
1437
  recursiveDiff[idSerializedKey] = getEntityId(newValue, idSerializedKey);
1851
1438
  dirtyFields[key] = recursiveDiff;
1852
1439
  }
1853
1440
  }
1854
-
1855
1441
  return dirtyFields;
1856
1442
  }
1857
1443
  }, {
1858
1444
  key: "_getDirtyFieldsForOneToMany",
1859
1445
  value: function _getDirtyFieldsForOneToMany(dirtyFieldsParam, key, idSerializedKey, relationMetadata, oldValue, newValue) {
1860
1446
  var _this = this;
1861
-
1862
1447
  var dirtyFields = dirtyFieldsParam;
1863
1448
  var newValueLength = newValue ? newValue.length : 0;
1864
- var oldValueLength = oldValue ? oldValue.length : 0; // number of items changed
1449
+ var oldValueLength = oldValue ? oldValue.length : 0;
1865
1450
 
1451
+ // number of items changed
1866
1452
  if (newValueLength !== oldValueLength) {
1867
1453
  dirtyFields[key] = getIdentifierForList(newValue, idSerializedKey);
1868
1454
  }
1869
-
1870
1455
  if (newValue && newValue.length > 0) {
1871
1456
  if (dirtyFields[key] === undefined) {
1872
1457
  dirtyFields[key] = [];
1873
1458
  }
1874
-
1875
1459
  var relationList = newValue;
1876
1460
  relationList.forEach(function (newRelationValue, relationAttributeName) {
1877
1461
  var oldRelationValue = findOldRelation(newRelationValue, oldValue, relationMetadata);
1878
-
1879
1462
  if (newRelationValue !== oldRelationValue) {
1880
1463
  if (typeof newRelationValue === 'string' || typeof oldRelationValue === 'string') {
1881
1464
  dirtyFields[key][relationAttributeName] = newRelationValue;
1882
1465
  return;
1883
1466
  }
1884
-
1885
1467
  var recursiveDiff = _this._getDirtyFields(newRelationValue, oldRelationValue, relationMetadata);
1886
-
1887
1468
  if (Object.keys(recursiveDiff).length > 0) {
1888
1469
  var entityId = getEntityId(newRelationValue, idSerializedKey);
1889
-
1890
1470
  if (entityId !== null) {
1891
1471
  recursiveDiff[idSerializedKey] = entityId;
1892
1472
  }
1893
-
1894
1473
  if (dirtyFields[key][relationAttributeName]) {
1895
1474
  Object.assign(dirtyFields[key][relationAttributeName], recursiveDiff);
1896
1475
  } else {
@@ -1899,7 +1478,6 @@ var UnitOfWork = /*#__PURE__*/function () {
1899
1478
  }
1900
1479
  }
1901
1480
  });
1902
-
1903
1481
  if (dirtyFields[key].length > 0) {
1904
1482
  // add identifier because one or more object linked has been updated
1905
1483
  // see test: 'get dirty data many to one update item'
@@ -1909,52 +1487,45 @@ var UnitOfWork = /*#__PURE__*/function () {
1909
1487
  delete dirtyFields[key];
1910
1488
  }
1911
1489
  }
1912
-
1913
1490
  return dirtyFields;
1914
1491
  }
1915
1492
  }, {
1916
1493
  key: "_getDirtyFields",
1917
1494
  value: function _getDirtyFields(newSerializedModel, oldSerializedModel, classMetadata) {
1918
1495
  var _this2 = this;
1919
-
1920
1496
  var dirtyFields = {};
1921
1497
  Object.values(classMetadata.getAttributeList()).forEach(function (attribute) {
1922
1498
  var key = attribute.attributeName;
1923
1499
  var newValue = newSerializedModel[key];
1924
1500
  var oldValue = oldSerializedModel ? oldSerializedModel[key] : null;
1925
1501
  var currentRelation = classMetadata.getRelation(attribute.serializedKey);
1926
-
1927
1502
  if (newValue === undefined) {
1928
1503
  return;
1929
- } // not a relation
1930
-
1504
+ }
1931
1505
 
1506
+ // not a relation
1932
1507
  if (!currentRelation) {
1933
1508
  dirtyFields = _this2._getDirtyFieldsForAttribute(dirtyFields, key, attribute, oldValue, newValue);
1934
1509
  return;
1935
1510
  }
1936
-
1937
1511
  var relationMetadata = _this2.mapping.getClassMetadataByKey(currentRelation.targetMetadataKey);
1938
-
1939
1512
  if (!relationMetadata) {
1940
1513
  throw new TypeError("relation metadata is not set for relation ".concat(classMetadata.key, ".").concat(currentRelation.targetMetadataKey));
1941
1514
  }
1515
+ var idSerializedKey = relationMetadata.getIdentifierAttribute().serializedKey;
1942
1516
 
1943
- var idSerializedKey = relationMetadata.getIdentifierAttribute().serializedKey; // MANY_TO_ONE relation
1944
-
1517
+ // MANY_TO_ONE relation
1945
1518
  if (currentRelation.isRelationToOne()) {
1946
1519
  dirtyFields = _this2._getDirtyFieldsForManyToOne(dirtyFields, key, oldValue, newValue, relationMetadata, idSerializedKey);
1947
1520
  return;
1948
- } // *_TO_MANY relation
1949
-
1521
+ }
1950
1522
 
1523
+ // *_TO_MANY relation
1951
1524
  dirtyFields = _this2._getDirtyFieldsForOneToMany(dirtyFields, key, idSerializedKey, relationMetadata, oldValue, newValue);
1952
1525
  });
1953
1526
  return dirtyFields;
1954
1527
  }
1955
1528
  }]);
1956
-
1957
- return UnitOfWork;
1958
1529
  }();
1959
1530
 
1960
1531
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -1962,44 +1533,44 @@ var Serializer = /*#__PURE__*/function () {
1962
1533
  function Serializer() {
1963
1534
  _classCallCheck(this, Serializer);
1964
1535
  }
1965
-
1966
- _createClass(Serializer, [{
1536
+ return _createClass(Serializer, [{
1967
1537
  key: "normalizeItem",
1968
-
1538
+ value:
1969
1539
  /**
1970
1540
  * convert an entity to a plain javascript object
1971
1541
  * @param {object} entity - The entity to convert
1972
1542
  * @param {ClassMetadata} classMetadata - the class metadata
1973
1543
  * @return {object} the object to serialize
1974
1544
  */
1975
- value: function normalizeItem(entity, classMetadata) {
1545
+ function normalizeItem(entity, classMetadata) {
1976
1546
  return entity;
1977
1547
  }
1548
+
1978
1549
  /**
1979
1550
  * convert a plain javascript object to string
1980
1551
  * @param {object} object - The object to convert to convert
1981
1552
  * @param {ClassMetadata} classMetadata - the class metadata
1982
1553
  * @return {string} the content of the request
1983
1554
  */
1984
-
1985
1555
  }, {
1986
1556
  key: "encodeItem",
1987
1557
  value: function encodeItem(object, classMetadata) {
1988
1558
  throw new TypeError('`encodeItem` method must be implemented');
1989
1559
  }
1560
+
1990
1561
  /**
1991
1562
  * convert an entity to string that will be sent as the request content
1992
1563
  * @param {any} entity - The entity to convert
1993
1564
  * @param {ClassMetadata} classMetadata - the class metadata
1994
1565
  * @return {string} the content of the request
1995
1566
  */
1996
-
1997
1567
  }, {
1998
1568
  key: "serializeItem",
1999
1569
  value: function serializeItem(object, classMetadata) {
2000
1570
  var noralizedData = this.normalizeItem(object, classMetadata);
2001
1571
  return this.encodeItem(noralizedData, classMetadata);
2002
1572
  }
1573
+
2003
1574
  /**
2004
1575
  * convert a plain object to an entity
2005
1576
  * @param {object} object - The plain javascript object
@@ -2007,12 +1578,12 @@ var Serializer = /*#__PURE__*/function () {
2007
1578
  * @param {Record<string, unknown>} response - the HTTP response
2008
1579
  * @return {object} an entity
2009
1580
  */
2010
-
2011
1581
  }, {
2012
1582
  key: "denormalizeItem",
2013
1583
  value: function denormalizeItem(object, classMetadata, response) {
2014
1584
  return object;
2015
1585
  }
1586
+
2016
1587
  /**
2017
1588
  * convert a string containing an object to a plain javascript object
2018
1589
  * @param {string} rawData - The string fetched from the response
@@ -2020,12 +1591,12 @@ var Serializer = /*#__PURE__*/function () {
2020
1591
  * @param {Record<string, unknown>} response - the HTTP response
2021
1592
  * @return {object} the normalized object
2022
1593
  */
2023
-
2024
1594
  }, {
2025
1595
  key: "decodeItem",
2026
1596
  value: function decodeItem(rawData, classMetadata, response) {
2027
1597
  throw new TypeError('`decodeItem` method must be implemented');
2028
1598
  }
1599
+
2029
1600
  /**
2030
1601
  * convert a string containing an object to an entity
2031
1602
  * @param {string} rawData - The string fetched from the response
@@ -2033,13 +1604,13 @@ var Serializer = /*#__PURE__*/function () {
2033
1604
  * @param {Record<string, unknown>} response - the HTTP response
2034
1605
  * @return {object} the entity
2035
1606
  */
2036
-
2037
1607
  }, {
2038
1608
  key: "deserializeItem",
2039
1609
  value: function deserializeItem(rawData, classMetadata, response) {
2040
1610
  var object = this.decodeItem(rawData, classMetadata, response);
2041
1611
  return this.denormalizeItem(object, classMetadata, response);
2042
1612
  }
1613
+
2043
1614
  /**
2044
1615
  * convert a plain object list to an entity list
2045
1616
  * @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object)
@@ -2047,12 +1618,12 @@ var Serializer = /*#__PURE__*/function () {
2047
1618
  * @param {Record<string, unknown>} response - the HTTP response
2048
1619
  * @return {Iterable<object>} a list of entities
2049
1620
  */
2050
-
2051
1621
  }, {
2052
1622
  key: "denormalizeList",
2053
1623
  value: function denormalizeList(objectList, classMetadata, response) {
2054
1624
  return objectList; // weird conversion as the declaration of list type is fuzzy
2055
1625
  }
1626
+
2056
1627
  /**
2057
1628
  * convert a string containing a list of objects to a list of plain javascript objects
2058
1629
  * @param {string} rawListData - The string fetched from the response
@@ -2060,12 +1631,12 @@ var Serializer = /*#__PURE__*/function () {
2060
1631
  * @param {Record<string, unknown>} response - the HTTP response
2061
1632
  * @return {Iterable<object>} a list of normalized objects
2062
1633
  */
2063
-
2064
1634
  }, {
2065
1635
  key: "decodeList",
2066
1636
  value: function decodeList(rawListData, classMetadata, response) {
2067
1637
  throw new TypeError('`deserializeList` method must be implemented');
2068
1638
  }
1639
+
2069
1640
  /**
2070
1641
  * convert a string containing a list of objects to a list of entities
2071
1642
  * @param {string} rawListData - The string fetched from the response
@@ -2073,7 +1644,6 @@ var Serializer = /*#__PURE__*/function () {
2073
1644
  * @param {Record<string, unknown>} response - the HTTP response
2074
1645
  * @return {Iterable<object>} a list of entities
2075
1646
  */
2076
-
2077
1647
  }, {
2078
1648
  key: "deserializeList",
2079
1649
  value: function deserializeList(rawListData, classMetadata, response) {
@@ -2081,22 +1651,15 @@ var Serializer = /*#__PURE__*/function () {
2081
1651
  return this.denormalizeList(objectList, classMetadata, response);
2082
1652
  }
2083
1653
  }]);
2084
-
2085
- return Serializer;
2086
1654
  }();
2087
1655
 
2088
1656
  var JsSerializer = /*#__PURE__*/function (_Serializer) {
2089
- _inherits(JsSerializer, _Serializer);
2090
-
2091
- var _super = _createSuper(JsSerializer);
2092
-
2093
1657
  function JsSerializer() {
2094
1658
  _classCallCheck(this, JsSerializer);
2095
-
2096
- return _super.apply(this, arguments);
1659
+ return _callSuper(this, JsSerializer, arguments);
2097
1660
  }
2098
-
2099
- _createClass(JsSerializer, [{
1661
+ _inherits(JsSerializer, _Serializer);
1662
+ return _createClass(JsSerializer, [{
2100
1663
  key: "encodeItem",
2101
1664
  value: function encodeItem(object, classMetadata) {
2102
1665
  return JSON.stringify(object);
@@ -2112,66 +1675,60 @@ var JsSerializer = /*#__PURE__*/function (_Serializer) {
2112
1675
  return JSON.parse(rawListData);
2113
1676
  }
2114
1677
  }]);
2115
-
2116
- return JsSerializer;
2117
1678
  }(Serializer);
2118
1679
 
2119
1680
  function levenshteinDistance(a, b) {
2120
- var matrix = []; // Increment along the first column of each row
1681
+ var matrix = [];
2121
1682
 
1683
+ // Increment along the first column of each row
2122
1684
  for (var i = 0; i <= b.length; i += 1) {
2123
1685
  matrix[i] = [i];
2124
- } // Increment each column in the first row
2125
-
1686
+ }
2126
1687
 
1688
+ // Increment each column in the first row
2127
1689
  for (var j = 0; j <= a.length; j += 1) {
2128
1690
  matrix[0][j] = j;
2129
- } // Fill in the rest of the matrix
2130
-
1691
+ }
2131
1692
 
1693
+ // Fill in the rest of the matrix
2132
1694
  for (var _i = 1; _i <= b.length; _i += 1) {
2133
1695
  for (var _j = 1; _j <= a.length; _j += 1) {
2134
1696
  if (b.charAt(_i - 1) === a.charAt(_j - 1)) {
2135
1697
  matrix[_i][_j] = matrix[_i - 1][_j - 1];
2136
1698
  } else {
2137
- matrix[_i][_j] = Math.min(matrix[_i - 1][_j - 1] + 1, // substitution
2138
- 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
2139
1703
  matrix[_i - 1][_j] + 1 // deletion
2140
1704
  );
2141
1705
  }
2142
1706
  }
2143
1707
  }
2144
-
2145
1708
  return matrix[b.length][a.length];
2146
- } // eslint-disable-next-line import/prefer-default-export
2147
-
2148
-
1709
+ }
2149
1710
  function findClosestWord(word, list) {
2150
1711
  var maxDistance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
2151
1712
  var closestWord = null;
2152
- var minDistance = Infinity; // eslint-disable-next-line no-plusplus
2153
-
1713
+ var minDistance = Infinity;
2154
1714
  for (var i = 0; i < list.length; i += 1) {
2155
1715
  var candidate = list[i];
2156
1716
  var distance = levenshteinDistance(word, candidate);
2157
-
2158
1717
  if (distance < minDistance && distance <= maxDistance) {
2159
1718
  minDistance = distance;
2160
1719
  closestWord = candidate;
2161
1720
  }
2162
1721
  }
2163
-
2164
1722
  return closestWord;
2165
1723
  }
2166
1724
 
1725
+ // type SdkResponse = Partial<Response>;
1726
+
2167
1727
  var generateId = function generateId() {
2168
1728
  return "rest-client-sdk|".concat(Date.now(), "-").concat(Math.floor(Math.random() * (9e12 - 1)) + 1e12);
2169
1729
  };
2170
-
2171
1730
  function serializeRequest(req) {
2172
1731
  var request = _objectSpread2({}, req); // Make a clone, useful for doing destructive things
2173
-
2174
-
2175
1732
  return {
2176
1733
  method: request.method,
2177
1734
  // The Request Method, e.g. GET, POST, DELETE
@@ -2180,31 +1737,20 @@ function serializeRequest(req) {
2180
1737
  headers: request.headers ? convertToRecord(request.headers) : undefined,
2181
1738
  body: typeof request.body === 'string' ? request.body : undefined
2182
1739
  };
2183
- } // eslint-disable-next-line import/prefer-default-export
2184
-
2185
-
2186
- var _history = new WeakMap();
2187
-
1740
+ }
1741
+ var _history = /*#__PURE__*/new WeakMap();
2188
1742
  var Logger = /*#__PURE__*/function () {
2189
- _createClass(Logger, [{
2190
- key: "history",
2191
- get: function get() {
2192
- return _classPrivateFieldGet(this, _history);
2193
- }
2194
- }]);
2195
-
2196
1743
  function Logger() {
2197
1744
  _classCallCheck(this, Logger);
2198
-
2199
- _history.set(this, {
2200
- writable: true,
2201
- value: void 0
2202
- });
2203
-
2204
- _classPrivateFieldSet(this, _history, []);
1745
+ _classPrivateFieldInitSpec(this, _history, void 0);
1746
+ _classPrivateFieldSet2(_history, this, []);
2205
1747
  }
2206
-
2207
- _createClass(Logger, [{
1748
+ return _createClass(Logger, [{
1749
+ key: "history",
1750
+ get: function get() {
1751
+ return _classPrivateFieldGet2(_history, this);
1752
+ }
1753
+ }, {
2208
1754
  key: "logRequest",
2209
1755
  value: function logRequest(params) {
2210
1756
  var log = {
@@ -2214,15 +1760,15 @@ var Logger = /*#__PURE__*/function () {
2214
1760
  request: Date.now()
2215
1761
  }
2216
1762
  };
2217
-
2218
- _classPrivateFieldGet(this, _history).push(log);
2219
-
1763
+ _classPrivateFieldGet2(_history, this).push(log);
2220
1764
  return log.id;
2221
1765
  }
2222
1766
  }, {
2223
1767
  key: "logResponse",
2224
1768
  value: function logResponse(response, requestId) {
2225
- var id = requestId || generateId(); // console.log('clone');
1769
+ var id = requestId || generateId();
1770
+
1771
+ // console.log('clone');
2226
1772
  // const clonedResponse = response.clone(); // THIS IS THE LINE THAT CAUSES THE PROBLEM
2227
1773
  // console.log('after clone', clonedResponse.status);
2228
1774
 
@@ -2231,16 +1777,14 @@ var Logger = /*#__PURE__*/function () {
2231
1777
  // clonedResponse.status,
2232
1778
  headers: Object.fromEntries(response.headers)
2233
1779
  };
2234
-
2235
- var foundLogIndex = _classPrivateFieldGet(this, _history).findIndex(function (log) {
1780
+ var foundLogIndex = _classPrivateFieldGet2(_history, this).findIndex(function (log) {
2236
1781
  return log.id === id;
2237
1782
  });
2238
-
2239
1783
  if (foundLogIndex > -1) {
2240
- _classPrivateFieldGet(this, _history)[foundLogIndex].response = logContent;
2241
- _classPrivateFieldGet(this, _history)[foundLogIndex].logTimes.response = Date.now();
1784
+ _classPrivateFieldGet2(_history, this)[foundLogIndex].response = logContent;
1785
+ _classPrivateFieldGet2(_history, this)[foundLogIndex].logTimes.response = Date.now();
2242
1786
  } else {
2243
- _classPrivateFieldGet(this, _history).push({
1787
+ _classPrivateFieldGet2(_history, this).push({
2244
1788
  id: id,
2245
1789
  response: logContent,
2246
1790
  logTimes: {
@@ -2248,82 +1792,59 @@ var Logger = /*#__PURE__*/function () {
2248
1792
  }
2249
1793
  });
2250
1794
  }
2251
-
2252
1795
  return id;
2253
1796
  }
2254
1797
  }]);
2255
-
2256
- return Logger;
2257
1798
  }();
2258
1799
 
2259
- var _repositoryList = new WeakMap();
1800
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2260
1801
 
1802
+ // export type SdkMetadata = Record<string, [any, Iterable<any>, undefined | any]>;
1803
+ var _repositoryList = /*#__PURE__*/new WeakMap();
2261
1804
  var RestClientSdk = /*#__PURE__*/function () {
2262
1805
  function RestClientSdk(tokenStorage, config, mapping) {
2263
1806
  var serializer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new JsSerializer();
2264
-
2265
1807
  _classCallCheck(this, RestClientSdk);
2266
-
2267
1808
  _defineProperty(this, "config", void 0);
2268
-
2269
1809
  _defineProperty(this, "tokenStorage", void 0);
2270
-
2271
1810
  _defineProperty(this, "serializer", void 0);
2272
-
2273
1811
  _defineProperty(this, "mapping", void 0);
2274
-
2275
1812
  _defineProperty(this, "unitOfWork", void 0);
2276
-
2277
- _repositoryList.set(this, {
2278
- writable: true,
2279
- value: void 0
2280
- });
2281
-
1813
+ _classPrivateFieldInitSpec(this, _repositoryList, void 0);
2282
1814
  _defineProperty(this, "logger", void 0);
2283
-
2284
1815
  this.checkConfigValidity(config);
2285
-
2286
1816
  if (!(mapping instanceof Mapping)) {
2287
1817
  throw new TypeError('mapping should be an instance of `Mapping`');
2288
1818
  }
2289
-
2290
1819
  this.config = this._mergeWithBaseConfig(config);
2291
1820
  this.tokenStorage = tokenStorage;
2292
1821
  this.serializer = serializer;
2293
1822
  this.mapping = mapping;
2294
1823
  this.unitOfWork = new UnitOfWork(this.mapping, this.config.unitOfWorkEnabled);
2295
-
2296
1824
  if (config.loggerEnabled) {
2297
1825
  this.logger = new Logger();
2298
1826
  }
2299
-
2300
- _classPrivateFieldSet(this, _repositoryList, {});
1827
+ _classPrivateFieldSet2(_repositoryList, this, {});
2301
1828
  }
1829
+
2302
1830
  /**
2303
1831
  * get a repository by it's metadata "key" attribute
2304
1832
  *
2305
1833
  * @param {string} key the repository "key" (the first argument of `new ClassMetadata`)
2306
1834
  */
2307
-
2308
-
2309
- _createClass(RestClientSdk, [{
1835
+ return _createClass(RestClientSdk, [{
2310
1836
  key: "getRepository",
2311
1837
  value: function getRepository(key) {
2312
- if (!_classPrivateFieldGet(this, _repositoryList)[key]) {
1838
+ if (!_classPrivateFieldGet2(_repositoryList, this)[key]) {
2313
1839
  var metadata = this.mapping.getClassMetadataByKey(key);
2314
-
2315
1840
  if (!metadata) {
2316
1841
  var closeKey = findClosestWord(key, this.mapping.getMappingKeys(), 5);
2317
1842
  var suggestions = closeKey ? " Did you mean \"".concat(closeKey, "\"?") : '';
2318
1843
  throw new Error("Unable to get metadata for repository \"".concat(key, "\".").concat(suggestions));
2319
- } // eslint-disable-next-line new-cap
2320
-
2321
-
2322
- _classPrivateFieldGet(this, _repositoryList)[key] = generateRepository(this, metadata, this.config.unitOfWorkEnabled);
2323
- } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2324
-
2325
-
2326
- return _classPrivateFieldGet(this, _repositoryList)[key];
1844
+ }
1845
+ _classPrivateFieldGet2(_repositoryList, this)[key] = generateRepository(this, metadata, this.config.unitOfWorkEnabled);
1846
+ }
1847
+ return _classPrivateFieldGet2(_repositoryList, this)[key];
2327
1848
  }
2328
1849
  }, {
2329
1850
  key: "_mergeWithBaseConfig",
@@ -2341,49 +1862,37 @@ var RestClientSdk = /*#__PURE__*/function () {
2341
1862
  }
2342
1863
  }
2343
1864
  }]);
2344
-
2345
- return RestClientSdk;
2346
1865
  }();
2347
1866
 
2348
1867
  var AbstractTokenGenerator = /*#__PURE__*/function () {
2349
1868
  function AbstractTokenGenerator(tokenGeneratorConfig, logger) {
2350
1869
  _classCallCheck(this, AbstractTokenGenerator);
2351
-
2352
1870
  _defineProperty(this, "tokenGeneratorConfig", void 0);
2353
-
2354
1871
  _defineProperty(this, "logger", void 0);
2355
-
2356
1872
  if (logger) {
2357
1873
  this.logger = logger;
2358
1874
  }
2359
-
2360
1875
  this.tokenGeneratorConfig = tokenGeneratorConfig;
2361
-
2362
1876
  if (typeof this.checkTokenGeneratorConfig === 'function') {
2363
1877
  this.checkTokenGeneratorConfig(this.tokenGeneratorConfig);
2364
1878
  }
2365
1879
  }
2366
-
2367
- _createClass(AbstractTokenGenerator, [{
1880
+ return _createClass(AbstractTokenGenerator, [{
2368
1881
  key: "_manageOauthError",
2369
-
2370
- /** @deprecated */
2371
- value: function _manageOauthError(response) {
1882
+ value: /** @deprecated */
1883
+ function _manageOauthError(response) {
2372
1884
  return response.clone().json().then(function (body) {
2373
1885
  if (body.error === 'invalid_grant') {
2374
1886
  throw new InvalidGrantError(body.error, getHttpErrorFromResponse(response));
2375
1887
  }
2376
-
2377
1888
  if (body.error === 'invalid_scope') {
2378
1889
  throw new InvalidScopeError(body.error, getHttpErrorFromResponse(response));
2379
1890
  }
2380
-
2381
1891
  throw new OauthError(body.error, getHttpErrorFromResponse(response));
2382
1892
  })["catch"](function (err) {
2383
1893
  if (!(err instanceof OauthError)) {
2384
1894
  throw new OauthError(err.type, getHttpErrorFromResponse(response));
2385
1895
  }
2386
-
2387
1896
  throw err;
2388
1897
  });
2389
1898
  }
@@ -2391,16 +1900,12 @@ var AbstractTokenGenerator = /*#__PURE__*/function () {
2391
1900
  key: "generateUrlFromConfig",
2392
1901
  value: function generateUrlFromConfig(config) {
2393
1902
  var uri = new URI("".concat(config.scheme, "://").concat(config.path));
2394
-
2395
1903
  if (config.port) {
2396
1904
  uri.port(config.port);
2397
1905
  }
2398
-
2399
1906
  return uri.toString();
2400
1907
  }
2401
1908
  }]);
2402
-
2403
- return AbstractTokenGenerator;
2404
1909
  }();
2405
1910
 
2406
1911
  /**
@@ -2409,25 +1914,19 @@ var AbstractTokenGenerator = /*#__PURE__*/function () {
2409
1914
  * @See {@link https://oauth2.thephpleague.com/authorization-server/auth-code-grant/|the great article of the PHP League} about authorization code flow.
2410
1915
  */
2411
1916
  var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2412
- _inherits(AuthorizationCodeFlowTokenGenerator, _AbstractTokenGenerat);
2413
-
2414
- var _super = _createSuper(AuthorizationCodeFlowTokenGenerator);
2415
-
2416
1917
  function AuthorizationCodeFlowTokenGenerator() {
2417
1918
  _classCallCheck(this, AuthorizationCodeFlowTokenGenerator);
2418
-
2419
- return _super.apply(this, arguments);
1919
+ return _callSuper(this, AuthorizationCodeFlowTokenGenerator, arguments);
2420
1920
  }
2421
-
2422
- _createClass(AuthorizationCodeFlowTokenGenerator, [{
1921
+ _inherits(AuthorizationCodeFlowTokenGenerator, _AbstractTokenGenerat);
1922
+ return _createClass(AuthorizationCodeFlowTokenGenerator, [{
2423
1923
  key: "generateToken",
2424
-
1924
+ value:
2425
1925
  /**
2426
1926
  * This function needs no generate an access token
2427
1927
  */
2428
- value: function generateToken(parameters) {
1928
+ function generateToken(parameters) {
2429
1929
  this._checkGenerateParameters(parameters);
2430
-
2431
1930
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2432
1931
  var params = {
2433
1932
  method: 'POST',
@@ -2443,31 +1942,27 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
2443
1942
  code: parameters.code
2444
1943
  }).toString()
2445
1944
  };
2446
-
2447
1945
  if (this.logger) {
2448
1946
  this.logger.logRequest(_objectSpread2({
2449
1947
  url: url
2450
1948
  }, params));
2451
1949
  }
2452
-
2453
1950
  return fetch(url, params);
2454
1951
  }
1952
+
2455
1953
  /**
2456
1954
  * This function needs to refresh the current possibly expired access token
2457
1955
  * and return a Promise that will be resolved with a fresh access token
2458
1956
  */
2459
-
2460
1957
  }, {
2461
1958
  key: "refreshToken",
2462
1959
  value: function refreshToken(oldAccessToken) {
2463
1960
  if (!oldAccessToken) {
2464
1961
  throw new Error('refresh_token is not set. Did you called `generateToken` before ?');
2465
1962
  }
2466
-
2467
- if (!(oldAccessToken === null || oldAccessToken === void 0 ? void 0 : oldAccessToken.refresh_token)) {
1963
+ if (!(oldAccessToken !== null && oldAccessToken !== void 0 && oldAccessToken.refresh_token)) {
2468
1964
  throw new Error('Unable to refreshToken as there are no refresh_token');
2469
1965
  }
2470
-
2471
1966
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2472
1967
  var params = {
2473
1968
  method: 'POST',
@@ -2481,13 +1976,11 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
2481
1976
  refresh_token: oldAccessToken.refresh_token
2482
1977
  }).toString()
2483
1978
  };
2484
-
2485
1979
  if (this.logger) {
2486
1980
  this.logger.logRequest(_objectSpread2({
2487
1981
  url: url
2488
1982
  }, params));
2489
1983
  }
2490
-
2491
1984
  return fetch(url, params);
2492
1985
  }
2493
1986
  }, {
@@ -2496,15 +1989,12 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
2496
1989
  if (!config || Object.keys(config).length === 0) {
2497
1990
  throw new RangeError('TokenGenerator config must be set');
2498
1991
  }
2499
-
2500
1992
  if (!(config.path && config.scheme)) {
2501
1993
  throw new RangeError('TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter');
2502
1994
  }
2503
-
2504
1995
  if (!(config.clientId && config.clientSecret)) {
2505
1996
  throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter');
2506
1997
  }
2507
-
2508
1998
  if (!config.redirectUri) {
2509
1999
  throw new RangeError('TokenGenerator config is not valid, it should contain a "redirectUri" parameter');
2510
2000
  }
@@ -2515,43 +2005,36 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
2515
2005
  if (!(parameters && Object.keys(parameters).length > 0)) {
2516
2006
  throw new RangeError('parameters must be set');
2517
2007
  }
2518
-
2519
2008
  if (!parameters.code) {
2520
2009
  throw new RangeError('"code" must be passed as parameter');
2521
2010
  }
2522
2011
  }
2523
2012
  }]);
2524
-
2525
- return AuthorizationCodeFlowTokenGenerator;
2526
2013
  }(AbstractTokenGenerator);
2527
2014
 
2528
- /* eslint-disable import/prefer-default-export */
2529
2015
  // memoize promise returning function so that it returns
2530
2016
  // the same promise if called again before resolve / reject
2017
+
2531
2018
  function memoizePromise(callback) {
2532
2019
  var cache = {};
2533
-
2534
2020
  function memoized() {
2535
2021
  for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
2536
2022
  parameters[_key] = arguments[_key];
2537
2023
  }
2538
-
2539
2024
  var cacheKey = JSON.stringify(parameters);
2540
2025
  var cacheValue = cache[cacheKey];
2541
-
2542
2026
  if (cacheValue) {
2543
2027
  return cacheValue;
2544
- } // Get and add the value to the cache
2545
-
2028
+ }
2546
2029
 
2030
+ // Get and add the value to the cache
2547
2031
  var value = callback.apply(this, parameters);
2548
2032
  cache[cacheKey] = value;
2549
-
2550
2033
  if (!value || typeof value.then !== 'function') {
2551
2034
  throw new Error('Memoization Error, Async function returned non-promise value');
2552
- } // Delete the value regardless of whether it resolves or rejects
2553
-
2035
+ }
2554
2036
 
2037
+ // Delete the value regardless of whether it resolves or rejects
2555
2038
  return value.then(function (internalValue) {
2556
2039
  cache[cacheKey] = false;
2557
2040
  return internalValue;
@@ -2560,31 +2043,23 @@ function memoizePromise(callback) {
2560
2043
  throw err;
2561
2044
  });
2562
2045
  }
2563
-
2564
2046
  memoized.cache = cache;
2565
2047
  return memoized;
2566
2048
  }
2567
2049
 
2568
- var ERROR_CONFIG_EMPTY = 'TokenGenerator config must be set';
2569
- var ERROR_CONFIG_PATH_SCHEME = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2570
- var ERROR_CONFIG_CLIENT_INFORMATIONS = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2571
-
2050
+ var ERROR_CONFIG_EMPTY$1 = 'TokenGenerator config must be set';
2051
+ var ERROR_CONFIG_PATH_SCHEME$1 = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2052
+ var ERROR_CONFIG_CLIENT_INFORMATIONS$1 = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2572
2053
  var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2573
- _inherits(ClientCredentialsGenerator, _AbstractTokenGenerat);
2574
-
2575
- var _super = _createSuper(ClientCredentialsGenerator);
2576
-
2577
2054
  function ClientCredentialsGenerator(tokenGeneratorConfig) {
2578
2055
  var _this;
2579
-
2580
2056
  _classCallCheck(this, ClientCredentialsGenerator);
2581
-
2582
- _this = _super.call(this, tokenGeneratorConfig);
2057
+ _this = _callSuper(this, ClientCredentialsGenerator, [tokenGeneratorConfig]);
2583
2058
  _this.generateToken = memoizePromise(_this.generateToken);
2584
2059
  return _this;
2585
2060
  }
2586
-
2587
- _createClass(ClientCredentialsGenerator, [{
2061
+ _inherits(ClientCredentialsGenerator, _AbstractTokenGenerat);
2062
+ return _createClass(ClientCredentialsGenerator, [{
2588
2063
  key: "generateToken",
2589
2064
  value: function generateToken() {
2590
2065
  var baseParameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2593,13 +2068,11 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2593
2068
  client_id: this.tokenGeneratorConfig.clientId,
2594
2069
  client_secret: this.tokenGeneratorConfig.clientSecret
2595
2070
  });
2596
-
2597
2071
  if (baseParameters.scope) {
2598
2072
  body.append('scope', baseParameters.scope);
2599
2073
  } else if (this.tokenGeneratorConfig.scope) {
2600
2074
  body.append('scope', this.tokenGeneratorConfig.scope);
2601
2075
  }
2602
-
2603
2076
  var params = {
2604
2077
  method: 'POST',
2605
2078
  headers: {
@@ -2608,18 +2081,17 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2608
2081
  body: body.toString()
2609
2082
  };
2610
2083
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2611
-
2612
2084
  if (this.logger) {
2613
2085
  this.logger.logRequest(_objectSpread2({
2614
2086
  url: url
2615
2087
  }, params));
2616
2088
  }
2617
-
2618
2089
  return fetch(url, params);
2619
2090
  }
2620
2091
  }, {
2621
2092
  key: "refreshToken",
2622
- value: function refreshToken( // eslint-disable-next-line @typescript-eslint/no-unused-vars
2093
+ value: function refreshToken(
2094
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2623
2095
  accessToken) {
2624
2096
  return this.generateToken({});
2625
2097
  }
@@ -2627,44 +2099,33 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2627
2099
  key: "checkTokenGeneratorConfig",
2628
2100
  value: function checkTokenGeneratorConfig(config) {
2629
2101
  if (!config || Object.keys(config).length === 0) {
2630
- throw new RangeError(ERROR_CONFIG_EMPTY);
2102
+ throw new RangeError(ERROR_CONFIG_EMPTY$1);
2631
2103
  }
2632
-
2633
2104
  if (!(config.path && config.scheme)) {
2634
- throw new RangeError(ERROR_CONFIG_PATH_SCHEME);
2105
+ throw new RangeError(ERROR_CONFIG_PATH_SCHEME$1);
2635
2106
  }
2636
-
2637
2107
  if (!(config.clientId && config.clientSecret)) {
2638
- throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);
2108
+ throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS$1);
2639
2109
  }
2640
2110
  }
2641
2111
  }]);
2642
-
2643
- return ClientCredentialsGenerator;
2644
2112
  }(AbstractTokenGenerator);
2645
2113
 
2646
- var ERROR_CONFIG_EMPTY$1 = 'TokenGenerator config must be set';
2647
- var ERROR_CONFIG_PATH_SCHEME$1 = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2648
- var ERROR_CONFIG_CLIENT_INFORMATIONS$1 = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2114
+ var ERROR_CONFIG_EMPTY = 'TokenGenerator config must be set';
2115
+ var ERROR_CONFIG_PATH_SCHEME = 'TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter';
2116
+ var ERROR_CONFIG_CLIENT_INFORMATIONS = 'TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter';
2649
2117
  var ERROR_TOKEN_EMPTY = 'parameters must be set';
2650
2118
  var ERROR_TOKEN_USERNAME_PASSWORD = 'username and password must be passed as parameters';
2651
-
2652
2119
  var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2653
- _inherits(PasswordGenerator, _AbstractTokenGenerat);
2654
-
2655
- var _super = _createSuper(PasswordGenerator);
2656
-
2657
2120
  function PasswordGenerator() {
2658
2121
  _classCallCheck(this, PasswordGenerator);
2659
-
2660
- return _super.apply(this, arguments);
2122
+ return _callSuper(this, PasswordGenerator, arguments);
2661
2123
  }
2662
-
2663
- _createClass(PasswordGenerator, [{
2124
+ _inherits(PasswordGenerator, _AbstractTokenGenerat);
2125
+ return _createClass(PasswordGenerator, [{
2664
2126
  key: "generateToken",
2665
2127
  value: function generateToken(baseParameters) {
2666
2128
  this._checkGenerateParameters(baseParameters);
2667
-
2668
2129
  var body = new URLSearchParams({
2669
2130
  grant_type: 'password',
2670
2131
  username: baseParameters.username,
@@ -2672,13 +2133,11 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2672
2133
  client_id: this.tokenGeneratorConfig.clientId,
2673
2134
  client_secret: this.tokenGeneratorConfig.clientSecret
2674
2135
  });
2675
-
2676
2136
  if (baseParameters.scope) {
2677
2137
  body.append('scope', baseParameters.scope);
2678
2138
  } else if (this.tokenGeneratorConfig.scope) {
2679
2139
  body.append('scope', this.tokenGeneratorConfig.scope);
2680
2140
  }
2681
-
2682
2141
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2683
2142
  var params = {
2684
2143
  method: 'POST',
@@ -2687,35 +2146,29 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2687
2146
  },
2688
2147
  body: body.toString()
2689
2148
  };
2690
-
2691
2149
  if (this.logger) {
2692
2150
  this.logger.logRequest(_objectSpread2({
2693
2151
  url: url
2694
2152
  }, params));
2695
2153
  }
2696
-
2697
2154
  return fetch(url, params);
2698
2155
  }
2699
2156
  }, {
2700
2157
  key: "refreshToken",
2701
2158
  value: function refreshToken(accessToken) {
2702
2159
  var refreshToken = accessToken === null || accessToken === void 0 ? void 0 : accessToken.refresh_token;
2703
-
2704
2160
  if (!refreshToken) {
2705
2161
  throw new Error('refresh_token is not set. Did you called `generateToken` before ?');
2706
2162
  }
2707
-
2708
2163
  var body = new URLSearchParams({
2709
2164
  grant_type: 'refresh_token',
2710
2165
  client_id: this.tokenGeneratorConfig.clientId,
2711
2166
  client_secret: this.tokenGeneratorConfig.clientSecret,
2712
2167
  refresh_token: refreshToken
2713
2168
  });
2714
-
2715
2169
  if (this.tokenGeneratorConfig.scope) {
2716
2170
  body.append('scope', this.tokenGeneratorConfig.scope);
2717
2171
  }
2718
-
2719
2172
  var url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
2720
2173
  var params = {
2721
2174
  method: 'POST',
@@ -2724,28 +2177,24 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2724
2177
  },
2725
2178
  body: body.toString()
2726
2179
  };
2727
-
2728
2180
  if (this.logger) {
2729
2181
  this.logger.logRequest(_objectSpread2({
2730
2182
  url: url
2731
2183
  }, params));
2732
2184
  }
2733
-
2734
2185
  return fetch(url, params);
2735
2186
  }
2736
2187
  }, {
2737
2188
  key: "checkTokenGeneratorConfig",
2738
2189
  value: function checkTokenGeneratorConfig(config) {
2739
2190
  if (!config || Object.keys(config).length === 0) {
2740
- throw new RangeError(ERROR_CONFIG_EMPTY$1);
2191
+ throw new RangeError(ERROR_CONFIG_EMPTY);
2741
2192
  }
2742
-
2743
2193
  if (!(config.path && config.scheme)) {
2744
- throw new RangeError(ERROR_CONFIG_PATH_SCHEME$1);
2194
+ throw new RangeError(ERROR_CONFIG_PATH_SCHEME);
2745
2195
  }
2746
-
2747
2196
  if (!(config.clientId && config.clientSecret)) {
2748
- throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS$1);
2197
+ throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);
2749
2198
  }
2750
2199
  }
2751
2200
  }, {
@@ -2754,22 +2203,15 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2754
2203
  if (!(parameters && Object.keys(parameters).length > 0)) {
2755
2204
  throw new RangeError(ERROR_TOKEN_EMPTY);
2756
2205
  }
2757
-
2758
2206
  if (!(parameters.username && parameters.password)) {
2759
2207
  throw new RangeError(ERROR_TOKEN_USERNAME_PASSWORD);
2760
2208
  }
2761
2209
  }
2762
2210
  }]);
2763
-
2764
- return PasswordGenerator;
2765
2211
  }(AbstractTokenGenerator);
2766
2212
 
2767
- var _token = new WeakMap();
2768
-
2769
- var _refreshTokenFunc = new WeakMap();
2770
-
2771
- /* eslint-disable camelcase */
2772
-
2213
+ var _token = /*#__PURE__*/new WeakMap();
2214
+ var _refreshTokenFunc = /*#__PURE__*/new WeakMap();
2773
2215
  /**
2774
2216
  * @deprecated ProvidedTokenGenerator is not an Oauth valid generator.
2775
2217
  * You should use one of the official generator or implement your own custom generator.
@@ -2777,38 +2219,28 @@ var _refreshTokenFunc = new WeakMap();
2777
2219
  var ProvidedTokenGenerator = /*#__PURE__*/function () {
2778
2220
  function ProvidedTokenGenerator(token) {
2779
2221
  var refreshTokenFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2780
-
2781
2222
  _classCallCheck(this, ProvidedTokenGenerator);
2782
-
2783
- _token.set(this, {
2784
- writable: true,
2785
- value: void 0
2786
- });
2787
-
2788
- _refreshTokenFunc.set(this, {
2789
- writable: true,
2790
- value: void 0
2791
- });
2792
-
2793
- _classPrivateFieldSet(this, _token, token);
2794
-
2795
- _classPrivateFieldSet(this, _refreshTokenFunc, refreshTokenFunc);
2223
+ _classPrivateFieldInitSpec(this, _token, void 0);
2224
+ _classPrivateFieldInitSpec(this, _refreshTokenFunc, void 0);
2225
+ _classPrivateFieldSet2(_token, this, token);
2226
+ _classPrivateFieldSet2(_refreshTokenFunc, this, refreshTokenFunc);
2796
2227
  }
2797
-
2798
- _createClass(ProvidedTokenGenerator, [{
2228
+ return _createClass(ProvidedTokenGenerator, [{
2229
+ key: "token",
2230
+ set: function set(token) {
2231
+ _classPrivateFieldSet2(_token, this, token);
2232
+ }
2233
+ }, {
2799
2234
  key: "generateToken",
2800
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2801
2235
  value: function generateToken() {
2802
- return Promise.resolve(_classPrivateFieldGet(this, _token));
2803
- } // eslint-disable-next-line @typescript-eslint/no-unused-vars
2804
-
2236
+ return Promise.resolve(_classPrivateFieldGet2(_token, this));
2237
+ }
2805
2238
  }, {
2806
2239
  key: "refreshToken",
2807
2240
  value: function refreshToken(accessToken) {
2808
- if (typeof _classPrivateFieldGet(this, _refreshTokenFunc) === 'function') {
2809
- return _classPrivateFieldGet(this, _refreshTokenFunc).call(this, accessToken);
2241
+ if (typeof _classPrivateFieldGet2(_refreshTokenFunc, this) === 'function') {
2242
+ return _classPrivateFieldGet2(_refreshTokenFunc, this).call(this, accessToken);
2810
2243
  }
2811
-
2812
2244
  return this.generateToken();
2813
2245
  }
2814
2246
  }, {
@@ -2816,100 +2248,60 @@ var ProvidedTokenGenerator = /*#__PURE__*/function () {
2816
2248
  value: function autoGenerateToken() {
2817
2249
  return this.generateToken();
2818
2250
  }
2819
- }, {
2820
- key: "token",
2821
- set: function set(token) {
2822
- _classPrivateFieldSet(this, _token, token);
2823
- }
2824
2251
  }]);
2825
-
2826
- return ProvidedTokenGenerator;
2827
2252
  }();
2828
2253
 
2829
2254
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2830
2255
  function isResponse(response) {
2831
2256
  return typeof (response === null || response === void 0 ? void 0 : response.json) === 'function';
2832
2257
  }
2833
-
2834
2258
  function manageOauthError(body, response) {
2835
2259
  var error;
2836
-
2837
2260
  if (response) {
2838
2261
  error = getHttpErrorFromResponse(response);
2839
2262
  }
2840
-
2841
2263
  if (body.error === 'invalid_grant') {
2842
2264
  throw new InvalidGrantError(body.error, error);
2843
2265
  }
2844
-
2845
2266
  if (body.error === 'invalid_scope') {
2846
2267
  throw new InvalidScopeError(body.error, error);
2847
2268
  }
2848
-
2849
2269
  throw new OauthError(body.error, error);
2850
2270
  }
2851
-
2852
- var _tokenGenerator = new WeakMap();
2853
-
2854
- var _hasATokenBeenGenerated = new WeakMap();
2855
-
2856
- var _asyncStorage = new WeakMap();
2857
-
2858
- var _logger = new WeakMap();
2859
-
2271
+ var _tokenGenerator = /*#__PURE__*/new WeakMap();
2272
+ var _hasATokenBeenGenerated = /*#__PURE__*/new WeakMap();
2273
+ var _asyncStorage = /*#__PURE__*/new WeakMap();
2274
+ var _logger = /*#__PURE__*/new WeakMap();
2860
2275
  var TokenStorage = /*#__PURE__*/function () {
2861
2276
  function TokenStorage(tokenGenerator, asyncStorage) {
2862
2277
  var accessTokenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'rest_client_sdk.api.access_token';
2863
2278
  var logger = arguments.length > 3 ? arguments[3] : undefined;
2864
-
2865
2279
  _classCallCheck(this, TokenStorage);
2866
-
2867
- _tokenGenerator.set(this, {
2868
- writable: true,
2869
- value: void 0
2870
- });
2871
-
2872
- _hasATokenBeenGenerated.set(this, {
2873
- writable: true,
2874
- value: void 0
2875
- });
2876
-
2280
+ _classPrivateFieldInitSpec(this, _tokenGenerator, void 0);
2281
+ _classPrivateFieldInitSpec(this, _hasATokenBeenGenerated, void 0);
2877
2282
  _defineProperty(this, "accessTokenKey", void 0);
2878
-
2879
- _asyncStorage.set(this, {
2880
- writable: true,
2881
- value: void 0
2882
- });
2883
-
2884
- _logger.set(this, {
2885
- writable: true,
2886
- value: void 0
2887
- });
2888
-
2283
+ _classPrivateFieldInitSpec(this, _asyncStorage, void 0);
2284
+ _classPrivateFieldInitSpec(this, _logger, void 0);
2889
2285
  if (logger) {
2890
- _classPrivateFieldSet(this, _logger, logger);
2286
+ _classPrivateFieldSet2(_logger, this, logger);
2891
2287
  }
2892
-
2893
- _classPrivateFieldSet(this, _tokenGenerator, tokenGenerator);
2894
-
2895
- _classPrivateFieldSet(this, _hasATokenBeenGenerated, false);
2896
-
2288
+ _classPrivateFieldSet2(_tokenGenerator, this, tokenGenerator);
2289
+ _classPrivateFieldSet2(_hasATokenBeenGenerated, this, false);
2897
2290
  this.setAsyncStorage(asyncStorage);
2898
2291
  this.accessTokenKey = accessTokenKey;
2899
2292
  this.handleTokenResponse = this.handleTokenResponse.bind(this);
2900
2293
  this.generateToken = memoizePromise(this.generateToken);
2901
2294
  this.refreshToken = memoizePromise(this.refreshToken);
2902
2295
  }
2903
-
2904
- _createClass(TokenStorage, [{
2296
+ return _createClass(TokenStorage, [{
2905
2297
  key: "setAsyncStorage",
2906
2298
  value: function setAsyncStorage(asyncStorage) {
2907
- _classPrivateFieldSet(this, _asyncStorage, asyncStorage);
2299
+ _classPrivateFieldSet2(_asyncStorage, this, asyncStorage);
2908
2300
  }
2909
2301
  }, {
2910
2302
  key: "hasAccessToken",
2911
2303
  value: function hasAccessToken() {
2912
- return _classPrivateFieldGet(this, _asyncStorage).getItem(this.accessTokenKey).then(function (accessToken) {
2304
+ return _classPrivateFieldGet2(_asyncStorage, this).getItem(this.accessTokenKey).then(function (accessToken) {
2913
2305
  return !!accessToken;
2914
2306
  });
2915
2307
  }
@@ -2924,33 +2316,27 @@ var TokenStorage = /*#__PURE__*/function () {
2924
2316
  key: "getAccessTokenObject",
2925
2317
  value: function getAccessTokenObject() {
2926
2318
  var _this = this;
2927
-
2928
- return _classPrivateFieldGet(this, _asyncStorage).getItem(this.accessTokenKey).then(function (token) {
2319
+ return _classPrivateFieldGet2(_asyncStorage, this).getItem(this.accessTokenKey).then(function (token) {
2929
2320
  if (token) {
2930
2321
  var tokenObject = JSON.parse(token);
2931
-
2932
2322
  if (_typeof(tokenObject) !== 'object') {
2933
2323
  return null;
2934
2324
  }
2935
-
2936
2325
  return tokenObject;
2937
2326
  }
2938
-
2939
- if (_classPrivateFieldGet(_this, _hasATokenBeenGenerated)) {
2327
+ if (_classPrivateFieldGet2(_hasATokenBeenGenerated, _this)) {
2940
2328
  return null;
2941
2329
  }
2942
-
2943
- if (typeof _classPrivateFieldGet(_this, _tokenGenerator).autoGenerateToken === 'function') {
2944
- return _classPrivateFieldGet(_this, _tokenGenerator).autoGenerateToken();
2330
+ if (typeof _classPrivateFieldGet2(_tokenGenerator, _this).autoGenerateToken === 'function') {
2331
+ return _classPrivateFieldGet2(_tokenGenerator, _this).autoGenerateToken();
2945
2332
  }
2946
-
2947
2333
  throw new Error('No token has been generated yet.');
2948
2334
  });
2949
2335
  }
2950
2336
  }, {
2951
2337
  key: "logout",
2952
2338
  value: function logout() {
2953
- return _classPrivateFieldGet(this, _asyncStorage).removeItem(this.accessTokenKey);
2339
+ return _classPrivateFieldGet2(_asyncStorage, this).removeItem(this.accessTokenKey);
2954
2340
  }
2955
2341
  }, {
2956
2342
  key: "_addExpiresAtToResponseData",
@@ -2958,30 +2344,25 @@ var TokenStorage = /*#__PURE__*/function () {
2958
2344
  if (!responseData) {
2959
2345
  return responseData;
2960
2346
  }
2961
-
2962
2347
  var updatedResponseData = _objectSpread2(_objectSpread2({}, responseData), {}, {
2963
2348
  expires_at: null
2964
2349
  });
2965
-
2966
- if (typeof updatedResponseData.expires_in !== 'undefined' && updatedResponseData.expires_in !== null // && updatedResponseData.expires_in >= 0
2350
+ if (typeof updatedResponseData.expires_in !== 'undefined' && updatedResponseData.expires_in !== null
2351
+ // && updatedResponseData.expires_in >= 0
2967
2352
  ) {
2968
- updatedResponseData.expires_at = Math.round(callTimestamp / 1000) + updatedResponseData.expires_in;
2969
- }
2970
-
2353
+ updatedResponseData.expires_at = Math.round(callTimestamp / 1000) + updatedResponseData.expires_in;
2354
+ }
2971
2355
  return updatedResponseData;
2972
2356
  }
2973
2357
  }, {
2974
2358
  key: "generateToken",
2975
2359
  value: function generateToken(parameters) {
2976
2360
  var _this2 = this;
2977
-
2978
2361
  var callTimestamp = Date.now();
2979
- return _classPrivateFieldGet(this, _tokenGenerator).generateToken(parameters).then(this.handleTokenResponse).then(function (body) {
2362
+ return _classPrivateFieldGet2(_tokenGenerator, this).generateToken(parameters).then(this.handleTokenResponse).then(function (body) {
2980
2363
  var updatedResponseData = _this2._addExpiresAtToResponseData(body, callTimestamp);
2981
-
2982
2364
  return _this2._storeAccessToken(updatedResponseData).then(function () {
2983
- _classPrivateFieldSet(_this2, _hasATokenBeenGenerated, true);
2984
-
2365
+ _classPrivateFieldSet2(_hasATokenBeenGenerated, _this2, true);
2985
2366
  return updatedResponseData;
2986
2367
  });
2987
2368
  });
@@ -2990,12 +2371,10 @@ var TokenStorage = /*#__PURE__*/function () {
2990
2371
  key: "refreshToken",
2991
2372
  value: function refreshToken() {
2992
2373
  var _this3 = this;
2993
-
2994
- return _classPrivateFieldGet(this, _asyncStorage).getItem(this.accessTokenKey).then(function (token) {
2374
+ return _classPrivateFieldGet2(_asyncStorage, this).getItem(this.accessTokenKey).then(function (token) {
2995
2375
  var callTimestamp = Date.now();
2996
- return _classPrivateFieldGet(_this3, _tokenGenerator).refreshToken(token ? JSON.parse(token) : null).then(_this3.handleTokenResponse).then(function (body) {
2376
+ return _classPrivateFieldGet2(_tokenGenerator, _this3).refreshToken(token ? JSON.parse(token) : null).then(_this3.handleTokenResponse).then(function (body) {
2997
2377
  var updatedResponseData = _this3._addExpiresAtToResponseData(body, callTimestamp);
2998
-
2999
2378
  return _this3._storeAccessToken(updatedResponseData).then(function () {
3000
2379
  return updatedResponseData;
3001
2380
  });
@@ -3008,11 +2387,9 @@ var TokenStorage = /*#__PURE__*/function () {
3008
2387
  if (isResponse(responseOrBody)) {
3009
2388
  var response = responseOrBody;
3010
2389
  var originalResponse = response.clone();
3011
-
3012
- if (_classPrivateFieldGet(this, _logger)) {
3013
- _classPrivateFieldGet(this, _logger).logResponse(response);
2390
+ if (_classPrivateFieldGet2(_logger, this)) {
2391
+ _classPrivateFieldGet2(_logger, this).logResponse(response);
3014
2392
  }
3015
-
3016
2393
  return response.json().then(function (body) {
3017
2394
  if (isOauthError(body)) {
3018
2395
  // throw error if response body is an oauth error
@@ -3021,31 +2398,26 @@ var TokenStorage = /*#__PURE__*/function () {
3021
2398
  // throw an error if response status code is an "error" status code
3022
2399
  throw getHttpErrorFromResponse(originalResponse);
3023
2400
  }
3024
-
3025
2401
  return body;
3026
2402
  })["catch"](function (err) {
3027
2403
  if (!(err instanceof OauthError)) {
3028
2404
  throw new OauthError(err.type, getHttpErrorFromResponse(originalResponse));
3029
2405
  }
3030
-
3031
2406
  throw err;
3032
2407
  });
3033
2408
  }
3034
-
3035
2409
  var body = responseOrBody;
3036
-
3037
2410
  if (isOauthError(body)) {
3038
2411
  // throw error if response body is an oauth error
3039
2412
  manageOauthError(body);
3040
2413
  }
3041
-
3042
2414
  return Promise.resolve(body);
3043
2415
  }
2416
+
3044
2417
  /**
3045
2418
  * Return the number of second when the token will expire
3046
2419
  * return value can be negative if the token is already expired
3047
2420
  */
3048
-
3049
2421
  }, {
3050
2422
  key: "getCurrentTokenExpiresIn",
3051
2423
  value: function getCurrentTokenExpiresIn() {
@@ -3053,11 +2425,9 @@ var TokenStorage = /*#__PURE__*/function () {
3053
2425
  if (accessTokenObject === null) {
3054
2426
  throw new Error('No token has been stored.');
3055
2427
  }
3056
-
3057
2428
  if (typeof accessTokenObject.expires_at === 'undefined' || accessTokenObject.expires_at === null) {
3058
2429
  return null;
3059
2430
  }
3060
-
3061
2431
  var now = Math.round(Date.now() / 1000);
3062
2432
  return accessTokenObject.expires_at - now;
3063
2433
  });
@@ -3065,13 +2435,10 @@ var TokenStorage = /*#__PURE__*/function () {
3065
2435
  }, {
3066
2436
  key: "_storeAccessToken",
3067
2437
  value: function _storeAccessToken(responseData) {
3068
- return _classPrivateFieldGet(this, _asyncStorage).setItem(this.accessTokenKey, JSON.stringify(responseData));
2438
+ return _classPrivateFieldGet2(_asyncStorage, this).setItem(this.accessTokenKey, JSON.stringify(responseData));
3069
2439
  }
3070
2440
  }]);
3071
-
3072
- return TokenStorage;
3073
2441
  }();
3074
2442
 
3075
- export default RestClientSdk;
3076
- export { AbstractClient, AbstractTokenGenerator, Attribute, AuthorizationCodeFlowTokenGenerator, BadRequestError, ClassMetadata, ClientCredentialsGenerator, ConflictError, ForbiddenError, HttpError, InternalServerError, InvalidGrantError, InvalidScopeError, Logger, Mapping, OauthError, PasswordGenerator, ProvidedTokenGenerator, Relation, ResourceNotFoundError, Serializer, TokenStorage, UnauthorizedError };
2443
+ 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 };
3077
2444
  //# sourceMappingURL=index.mjs.map