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