@livechat/accounts-sdk 2.1.2 → 2.1.4-beta.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.esm.js CHANGED
@@ -28,7 +28,8 @@ var errors = {
28
28
  'Client not found, not provided or incorectly configured.',
29
29
 
30
30
  access_denied:
31
- 'Probably this application is installed on a different account and you do not have access to it.',
31
+ 'Probably this application is installed on a different account ' +
32
+ 'and you do not have access to it.',
32
33
 
33
34
  unsupported_response_type:
34
35
  'Provided response type is incorrect or unavailable for a given client.',
@@ -38,7 +39,6 @@ var errors = {
38
39
  },
39
40
  };
40
41
 
41
- /* eslint-disable require-jsdoc */
42
42
  class Listener {
43
43
  constructor(options = {}) {
44
44
  this.options = options;
@@ -104,7 +104,6 @@ class Listener {
104
104
  * Class for authentication using popup.
105
105
  */
106
106
  class Popup {
107
- // eslint-disable-next-line require-jsdoc
108
107
  constructor(sdk, options) {
109
108
  this.options = options;
110
109
  this.sdk = sdk;
@@ -112,7 +111,7 @@ class Popup {
112
111
 
113
112
  /**
114
113
  * run popup authorization flow, should be called in a click handler to avoid beeing blocked
115
- * @return {Promise} promise that resolves to authorize data or error
114
+ * @returns {Promise} promise that resolves to authorize data or error
116
115
  */
117
116
  authorize() {
118
117
  return new Promise((resolve, reject) => {
@@ -131,7 +130,7 @@ class Popup {
131
130
  resolve(authorizeData);
132
131
  });
133
132
 
134
- var open = function () {
133
+ const open = function () {
135
134
  window.open(
136
135
  url,
137
136
  'livechat-login-popup',
@@ -140,7 +139,7 @@ class Popup {
140
139
  };
141
140
 
142
141
  if (document.requestStorageAccess) {
143
- var promise = document.requestStorageAccess();
142
+ const promise = document.requestStorageAccess();
144
143
  promise.then(open, open);
145
144
  } else {
146
145
  open();
@@ -149,13 +148,13 @@ class Popup {
149
148
  }
150
149
  }
151
150
 
152
- /* eslint-disable require-jsdoc */
153
-
154
- /** @fileOverview
151
+ /**
152
+ * @param {Record<string, unknown>} object Source object to pick properties from.
153
+ * @param {string[]} keys Keys to pick from the source object.
154
+ * @returns {Record<string, unknown>} A new object containing only the picked keys.
155
155
  * @author Auth0 https://github.com/auth0/auth0.js
156
156
  * @license MIT
157
157
  */
158
-
159
158
  function pick(object, keys) {
160
159
  return keys.reduce((prev, key) => {
161
160
  if (object[key]) {
@@ -165,9 +164,7 @@ function pick(object, keys) {
165
164
  }, {});
166
165
  }
167
166
 
168
- // eslint-disable-next-line require-jsdoc
169
167
  class Redirect {
170
- // eslint-disable-next-line require-jsdoc
171
168
  constructor(sdk, options) {
172
169
  this.options = options;
173
170
  this.sdk = sdk;
@@ -183,7 +180,7 @@ class Redirect {
183
180
 
184
181
  /**
185
182
  * this function checks if the current origin was redirected to with authorize data
186
- * @return {Promise} promise that resolves to authorize data or error
183
+ * @returns {Promise} promise that resolves to authorize data or error
187
184
  */
188
185
  authorizeData() {
189
186
  return new Promise((resolve, reject) => {
@@ -205,7 +202,7 @@ class Redirect {
205
202
 
206
203
  if (
207
204
  !requiredFields.every((field) =>
208
- authorizeData.hasOwnProperty(field)
205
+ Object.prototype.hasOwnProperty.call(authorizeData, field)
209
206
  )
210
207
  ) {
211
208
  reject(errors.extend({identity_exception: 'unauthorized'}));
@@ -225,7 +222,7 @@ class Redirect {
225
222
 
226
223
  if (
227
224
  !requiredFields.every((field) =>
228
- authorizeData.hasOwnProperty(field)
225
+ Object.prototype.hasOwnProperty.call(authorizeData, field)
229
226
  )
230
227
  ) {
231
228
  reject(errors.extend({identity_exception: 'unauthorized'}));
@@ -244,7 +241,6 @@ class Redirect {
244
241
  * Class for authentication using Iframe
245
242
  */
246
243
  class Iframe {
247
- // eslint-disable-next-line require-jsdoc
248
244
  constructor(sdk, options) {
249
245
  this.options = options;
250
246
  this.sdk = sdk;
@@ -252,7 +248,7 @@ class Iframe {
252
248
 
253
249
  /**
254
250
  * run iframe authorization flow, not recommended because of ITP 2.0
255
- * @return {Promise} promise that resolves to authorize data or error
251
+ * @returns {Promise} promise that resolves to authorize data or error
256
252
  */
257
253
  authorize() {
258
254
  return new Promise((resolve, reject) => {
@@ -285,12 +281,10 @@ class Iframe {
285
281
  });
286
282
  }
287
283
 
288
- // eslint-disable-next-line require-jsdoc
289
284
  iframeID() {
290
285
  return this.options.client_id + this.options.response_type;
291
286
  }
292
287
 
293
- // eslint-disable-next-line require-jsdoc
294
288
  removeIframe() {
295
289
  const ref = document.getElementById(this.iframeID());
296
290
  if (ref && ref.parentNode) {
@@ -299,13 +293,17 @@ class Iframe {
299
293
  }
300
294
  }
301
295
 
302
- /* eslint-disable require-jsdoc */
303
-
304
- /** @fileOverview
296
+ /**
297
+ * @file
305
298
  * @author Auth0 https://github.com/auth0/auth0.js
306
299
  * @license MIT
307
300
  */
308
301
 
302
+ /**
303
+ * A dummy storage mechanism that does not persist data.
304
+ * It provides methods to get, set, and remove items, but they do not perform any actual storage operations.
305
+ * This can be used as a fallback when no other storage mechanism is available.
306
+ */
309
307
  function DummyStorage() {}
310
308
 
311
309
  DummyStorage.prototype.getItem = function () {
@@ -316,7 +314,16 @@ DummyStorage.prototype.removeItem = function () {};
316
314
 
317
315
  DummyStorage.prototype.setItem = function () {};
318
316
 
319
- /* eslint-disable require-jsdoc */
317
+ /**
318
+ * @file
319
+ * @author Auth0 https://github.com/auth0/auth0.js
320
+ * @license MIT
321
+ */
322
+
323
+
324
+ /**
325
+ * A storage mechanism that uses cookies to store data. It provides methods to get, set, and remove items from cookies.
326
+ */
320
327
  function CookieStorage() {}
321
328
 
322
329
  CookieStorage.prototype.getItem = function (key) {
@@ -342,8 +349,20 @@ CookieStorage.prototype.setItem = function (key, value, options) {
342
349
  Cookie.set(key, value, params);
343
350
  };
344
351
 
345
- /* eslint-disable require-jsdoc */
352
+ /**
353
+ * @file
354
+ * @author Auth0 https://github.com/auth0/auth0.js
355
+ * @license MIT
356
+ */
357
+
346
358
 
359
+ /**
360
+ * A handler that manages the underlying storage mechanism, providing failover capabilities between localStorage, CookieStorage, and DummyStorage.
361
+ * It attempts to use localStorage by default, but falls back to CookieStorage if localStorage is unavailable or throws an error.
362
+ * If both localStorage and CookieStorage fail, it falls back to DummyStorage, which does not persist data.
363
+ * The handler provides methods to get, set, and remove items from the storage, with automatic failover in case of errors.
364
+ * @param {object} options Storage configuration options passed to the underlying StorageHandler.
365
+ */
347
366
  function StorageHandler(options) {
348
367
  this.storage = new CookieStorage();
349
368
  if (options.force_local_storage !== true) {
@@ -405,8 +424,17 @@ StorageHandler.prototype.setItem = function (key, value, options) {
405
424
  }
406
425
  };
407
426
 
408
- /* eslint-disable require-jsdoc */
427
+ /**
428
+ * @file
429
+ * @author Auth0 https://github.com/auth0/auth0.js
430
+ * @license MIT
431
+ */
432
+
409
433
 
434
+ /**
435
+ * A wrapper around the underlying storage mechanism that handles JSON serialization and deserialization.
436
+ * @param {object} options Storage configuration options passed to the underlying StorageHandler.
437
+ */
410
438
  function Storage(options) {
411
439
  this.handler = new StorageHandler(options);
412
440
  }
@@ -415,7 +443,7 @@ Storage.prototype.getItem = function (key) {
415
443
  const value = this.handler.getItem(key);
416
444
  try {
417
445
  return JSON.parse(value);
418
- } catch (_) {
446
+ } catch {
419
447
  return value;
420
448
  }
421
449
  };
@@ -429,7 +457,7 @@ Storage.prototype.setItem = function (key, value, options) {
429
457
  return this.handler.setItem(key, json, options);
430
458
  };
431
459
 
432
- /* eslint-disable require-jsdoc */
460
+ /* internal file */
433
461
 
434
462
  class Transaction {
435
463
  constructor(options) {
@@ -459,15 +487,16 @@ class Transaction {
459
487
  }
460
488
  }
461
489
 
462
- /** @fileOverview Javascript cryptography implementation.
490
+ /**
463
491
  *
492
+ * @file Javascript cryptography implementation.
464
493
  * Crush to remove comments, shorten variable names and
465
494
  * generally reduce transmission size.
466
- *
467
495
  * @author Emily Stark
468
496
  * @author Mike Hamburg
469
497
  * @author Dan Boneh
470
498
  */
499
+
471
500
  /*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
472
501
  /*global document, window, escape, unescape, module, require, Uint32Array */
473
502
 
@@ -476,40 +505,15 @@ class Transaction {
476
505
  * @namespace
477
506
  */
478
507
  var sjcl = {
479
- /**
480
- * Symmetric ciphers.
481
- * @namespace
482
- */
483
- cipher: {},
484
-
485
508
  /**
486
509
  * Hash functions. Right now only SHA256 is implemented.
487
510
  * @namespace
488
511
  */
489
512
  hash: {},
490
513
 
491
- /**
492
- * Key exchange functions. Right now only SRP is implemented.
493
- * @namespace
494
- */
495
- keyexchange: {},
496
-
497
- /**
498
- * Cipher modes of operation.
499
- * @namespace
500
- */
501
- mode: {},
502
-
503
- /**
504
- * Miscellaneous. HMAC and PBKDF2.
505
- * @namespace
506
- */
507
- misc: {},
508
-
509
514
  /**
510
515
  * Bit array encoders and decoders.
511
516
  * @namespace
512
- *
513
517
  * @description
514
518
  * The members of this namespace are functions which translate between
515
519
  * SJCL's bitArrays and other objects (usually strings). Because it
@@ -523,53 +527,21 @@ var sjcl = {
523
527
  * @namespace
524
528
  */
525
529
  exception: {
526
- /**
527
- * Ciphertext is corrupt.
528
- * @constructor
529
- */
530
- corrupt: function (message) {
531
- this.toString = function () {
532
- return 'CORRUPT: ' + this.message;
533
- };
534
- this.message = message;
535
- },
536
-
537
530
  /**
538
531
  * Invalid parameter.
539
- * @constructor
532
+ * @param {string} message Error message describing the invalid parameter.
540
533
  */
541
534
  invalid: function (message) {
542
535
  this.toString = function () {
543
536
  return 'INVALID: ' + this.message;
544
537
  };
545
538
  this.message = message;
546
- },
547
-
548
- /**
549
- * Bug or missing feature in SJCL.
550
- * @constructor
551
- */
552
- bug: function (message) {
553
- this.toString = function () {
554
- return 'BUG: ' + this.message;
555
- };
556
- this.message = message;
557
- },
558
-
559
- /**
560
- * Something isn't ready.
561
- * @constructor
562
- */
563
- notReady: function (message) {
564
- this.toString = function () {
565
- return 'NOT READY: ' + this.message;
566
- };
567
- this.message = message;
568
- },
569
- },
539
+ }},
570
540
  };
571
- /** @fileOverview Arrays of bits, encoded as arrays of Numbers.
541
+
542
+ /**
572
543
  *
544
+ * @file Arrays of bits, encoded as arrays of Numbers.
573
545
  * @author Emily Stark
574
546
  * @author Mike Hamburg
575
547
  * @author Dan Boneh
@@ -599,14 +571,17 @@ var sjcl = {
599
571
  * to ciphers like AES which want arrays of words.
600
572
  * </p>
601
573
  */
574
+ /**
575
+ * @typedef {number[]} bitArray
576
+ */
602
577
  sjcl.bitArray = {
603
578
  /**
604
579
  * Array slices in units of bits.
605
580
  * @param {bitArray} a The array to slice.
606
- * @param {Number} bstart The offset to the start of the slice, in bits.
607
- * @param {Number} bend The offset to the end of the slice, in bits. If this is undefined,
581
+ * @param {number} bstart The offset to the start of the slice, in bits.
582
+ * @param {number} [bend] The offset to the end of the slice, in bits. If this is undefined,
608
583
  * slice until the end of the array.
609
- * @return {bitArray} The requested slice.
584
+ * @returns {bitArray} The requested slice.
610
585
  */
611
586
  bitSlice: function (a, bstart, bend) {
612
587
  a = sjcl.bitArray
@@ -618,9 +593,9 @@ sjcl.bitArray = {
618
593
  /**
619
594
  * Extract a number packed into a bit array.
620
595
  * @param {bitArray} a The array to slice.
621
- * @param {Number} bstart The offset to the start of the slice, in bits.
622
- * @param {Number} blength The length of the number to extract.
623
- * @return {Number} The requested slice.
596
+ * @param {number} bstart The offset to the start of the slice, in bits.
597
+ * @param {number} blength The length of the number to extract.
598
+ * @returns {number} The requested slice.
624
599
  */
625
600
  extract: function (a, bstart, blength) {
626
601
  // FIXME: this Math.floor is not necessary at all, but for some reason
@@ -642,7 +617,7 @@ sjcl.bitArray = {
642
617
  * Concatenate two bit arrays.
643
618
  * @param {bitArray} a1 The first array.
644
619
  * @param {bitArray} a2 The second array.
645
- * @return {bitArray} The concatenation of a1 and a2.
620
+ * @returns {bitArray} The concatenation of a1 and a2.
646
621
  */
647
622
  concat: function (a1, a2) {
648
623
  if (a1.length === 0 || a2.length === 0) {
@@ -666,7 +641,7 @@ sjcl.bitArray = {
666
641
  /**
667
642
  * Find the length of an array of bits.
668
643
  * @param {bitArray} a The array.
669
- * @return {Number} The length of a, in bits.
644
+ * @returns {number} The length of a, in bits.
670
645
  */
671
646
  bitLength: function (a) {
672
647
  var l = a.length,
@@ -681,8 +656,8 @@ sjcl.bitArray = {
681
656
  /**
682
657
  * Truncate an array.
683
658
  * @param {bitArray} a The array.
684
- * @param {Number} len The length to truncate to, in bits.
685
- * @return {bitArray} A new array, truncated to len bits.
659
+ * @param {number} len The length to truncate to, in bits.
660
+ * @returns {bitArray} A new array, truncated to len bits.
686
661
  */
687
662
  clamp: function (a, len) {
688
663
  if (a.length * 32 < len) {
@@ -703,10 +678,10 @@ sjcl.bitArray = {
703
678
 
704
679
  /**
705
680
  * Make a partial word for a bit array.
706
- * @param {Number} len The number of bits in the word.
707
- * @param {Number} x The bits.
708
- * @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
709
- * @return {Number} The partial word.
681
+ * @param {number} len The number of bits in the word.
682
+ * @param {number} x The bits.
683
+ * @param {number} [_end] Pass 1 if x has already been shifted to the high side.
684
+ * @returns {number} The partial word.
710
685
  */
711
686
  partial: function (len, x, _end) {
712
687
  if (len === 32) {
@@ -717,8 +692,8 @@ sjcl.bitArray = {
717
692
 
718
693
  /**
719
694
  * Get the number of bits used by a partial word.
720
- * @param {Number} x The partial word.
721
- * @return {Number} The number of bits used by the partial word.
695
+ * @param {number} x The partial word.
696
+ * @returns {number} The number of bits used by the partial word.
722
697
  */
723
698
  getPartial: function (x) {
724
699
  return Math.round(x / 0x10000000000) || 32;
@@ -728,7 +703,7 @@ sjcl.bitArray = {
728
703
  * Compare two arrays for equality in a predictable amount of time.
729
704
  * @param {bitArray} a The first array.
730
705
  * @param {bitArray} b The second array.
731
- * @return {boolean} true if a == b; false otherwise.
706
+ * @returns {boolean} true if a == b; false otherwise.
732
707
  */
733
708
  equal: function (a, b) {
734
709
  if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) {
@@ -742,11 +717,13 @@ sjcl.bitArray = {
742
717
  return x === 0;
743
718
  },
744
719
 
745
- /** Shift an array right.
720
+ /**
721
+ * Shift an array right.
746
722
  * @param {bitArray} a The array to shift.
747
- * @param {Number} shift The number of bits to shift.
748
- * @param {Number} [carry=0] A byte to carry in
749
- * @param {bitArray} [out=[]] An array to prepend to the output.
723
+ * @param {number} shift The number of bits to shift.
724
+ * @param {number} [carry] A word to carry in (defaults to 0).
725
+ * @param {bitArray} [out] An array to prepend to the output (defaults to []).
726
+ * @returns {bitArray} The shifted bitArray.
750
727
  * @private
751
728
  */
752
729
  _shiftRight: function (a, shift, carry, out) {
@@ -781,17 +758,22 @@ sjcl.bitArray = {
781
758
  return out;
782
759
  },
783
760
 
784
- /** xor a block of 4 words together.
761
+ /**
762
+ * XOR a block of 4 words together.
763
+ * @param {bitArray} x The first 4-word block.
764
+ * @param {bitArray} y The second 4-word block.
765
+ * @returns {bitArray} The XOR result as a 4-word block.
785
766
  * @private
786
767
  */
787
768
  _xor4: function (x, y) {
788
769
  return [x[0] ^ y[0], x[1] ^ y[1], x[2] ^ y[2], x[3] ^ y[3]];
789
770
  },
790
771
 
791
- /** byteswap a word array inplace.
772
+ /**
773
+ * byteswap a word array inplace.
792
774
  * (does not handle partial words)
793
775
  * @param {sjcl.bitArray} a word array
794
- * @return {sjcl.bitArray} byteswapped array
776
+ * @returns {sjcl.bitArray} byteswapped array
795
777
  */
796
778
  byteswapM: function (a) {
797
779
  var i,
@@ -804,11 +786,12 @@ sjcl.bitArray = {
804
786
  return a;
805
787
  },
806
788
  };
807
- /** @fileOverview Bit array codec implementations.
789
+ /**
808
790
  *
791
+ * @file Bit array codec implementations.
809
792
  * @author Emily Stark
810
793
  * @author Mike Hamburg
811
- * @author Dan Boneh
794
+ * @author Dan Boneh
812
795
  */
813
796
 
814
797
  /**
@@ -816,7 +799,11 @@ sjcl.bitArray = {
816
799
  * @namespace
817
800
  */
818
801
  sjcl.codec.utf8String = {
819
- /** Convert from a bitArray to a UTF-8 string. */
802
+ /**
803
+ * Convert from a bitArray to a UTF-8 string.
804
+ * @param {bitArray} arr The input bitArray to decode.
805
+ * @returns {string} The decoded UTF-8 string.
806
+ */
820
807
  fromBits: function (arr) {
821
808
  var out = '',
822
809
  bl = sjcl.bitArray.bitLength(arr),
@@ -832,7 +819,11 @@ sjcl.codec.utf8String = {
832
819
  return decodeURIComponent(escape(out));
833
820
  },
834
821
 
835
- /** Convert from a UTF-8 string to a bitArray. */
822
+ /**
823
+ * Convert from a UTF-8 string to a bitArray.
824
+ * @param {string} str UTF-8 string to encode.
825
+ * @returns {bitArray} The encoded bitArray.
826
+ */
836
827
  toBits: function (str) {
837
828
  str = unescape(encodeURIComponent(str));
838
829
  var out = [],
@@ -851,16 +842,15 @@ sjcl.codec.utf8String = {
851
842
  return out;
852
843
  },
853
844
  };
854
- /** @fileOverview Javascript SHA-256 implementation.
845
+ /**
855
846
  *
847
+ * @file Javascript SHA-256 implementation.
856
848
  * An older version of this implementation is available in the public
857
849
  * domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
858
850
  * Stanford University 2008-2010 and BSD-licensed for liability
859
851
  * reasons.
860
- *
861
852
  * Special thanks to Aldo Cortesi for pointing out several bugs in
862
853
  * this code.
863
- *
864
854
  * @author Emily Stark
865
855
  * @author Mike Hamburg
866
856
  * @author Dan Boneh
@@ -868,7 +858,7 @@ sjcl.codec.utf8String = {
868
858
 
869
859
  /**
870
860
  * Context for a SHA-256 operation in progress.
871
- * @constructor
861
+ * @param {sjcl.hash.sha256} [hash] Optional hash to initialize from.
872
862
  */
873
863
  sjcl.hash.sha256 = function (hash) {
874
864
  if (!this._key[0]) {
@@ -886,8 +876,8 @@ sjcl.hash.sha256 = function (hash) {
886
876
  /**
887
877
  * Hash a string or an array of words.
888
878
  * @static
889
- * @param {bitArray|String} data the data to hash.
890
- * @return {bitArray} The hash value, an array of 16 big-endian words.
879
+ * @param {bitArray | string} data the data to hash.
880
+ * @returns {bitArray} The hash value, an array of 16 big-endian words.
891
881
  */
892
882
  sjcl.hash.sha256.hash = function (data) {
893
883
  return new sjcl.hash.sha256().update(data).finalize();
@@ -902,7 +892,7 @@ sjcl.hash.sha256.prototype = {
902
892
 
903
893
  /**
904
894
  * Reset the hash state.
905
- * @return this
895
+ * @returns {sjcl.hash.sha256} this
906
896
  */
907
897
  reset: function () {
908
898
  this._h = this._init.slice(0);
@@ -913,8 +903,8 @@ sjcl.hash.sha256.prototype = {
913
903
 
914
904
  /**
915
905
  * Input several words to the hash.
916
- * @param {bitArray|String} data the data to hash.
917
- * @return this
906
+ * @param {bitArray | string} data the data to hash.
907
+ * @returns {sjcl.hash.sha256} this
918
908
  */
919
909
  update: function (data) {
920
910
  if (typeof data === 'string') {
@@ -946,7 +936,7 @@ sjcl.hash.sha256.prototype = {
946
936
 
947
937
  /**
948
938
  * Complete hashing and output the hash value.
949
- * @return {bitArray} The hash value, an array of 8 big-endian words.
939
+ * @returns {bitArray} The hash value, an array of 8 big-endian words.
950
940
  */
951
941
  finalize: function () {
952
942
  var i,
@@ -1009,6 +999,11 @@ sjcl.hash.sha256.prototype = {
1009
999
  factor,
1010
1000
  isPrime;
1011
1001
 
1002
+ /**
1003
+ * Get the fractional part of x scaled to a 32-bit word.
1004
+ * @param {number} x Input number.
1005
+ * @returns {number} A signed 32-bit integer representing the scaled fractional part.
1006
+ */
1012
1007
  function frac(x) {
1013
1008
  return ((x - Math.floor(x)) * 0x100000000) | 0;
1014
1009
  }
@@ -1124,7 +1119,11 @@ sjcl.hash.sha256.prototype = {
1124
1119
  },
1125
1120
  };
1126
1121
 
1127
- // eslint-disable-next-line require-jsdoc
1122
+ /**
1123
+ * Encode a string as base64url (RFC 4648 §5).
1124
+ * @param {string} str - The string to encode.
1125
+ * @returns {string} The base64url-encoded string.
1126
+ */
1128
1127
  function base64URLEncode(str) {
1129
1128
  return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
1130
1129
  }
@@ -1133,7 +1132,12 @@ var encoding = {
1133
1132
  base64URLEncode: base64URLEncode,
1134
1133
  };
1135
1134
 
1136
- /* eslint-disable require-jsdoc */
1135
+ /**
1136
+ * @file
1137
+ * @author Auth0 https://github.com/auth0/auth0.js
1138
+ * @license MIT
1139
+ */
1140
+
1137
1141
 
1138
1142
  class Persister {
1139
1143
  constructor(options, type) {
@@ -1160,7 +1164,12 @@ class Persister {
1160
1164
  }
1161
1165
  }
1162
1166
 
1163
- /* eslint-disable require-jsdoc */
1167
+ /**
1168
+ * @file
1169
+ * @author Auth0 https://github.com/auth0/auth0.js
1170
+ * @license MIT
1171
+ */
1172
+
1164
1173
 
1165
1174
  class RedirectUriParamsPersister {
1166
1175
  constructor(options) {
@@ -1169,7 +1178,8 @@ class RedirectUriParamsPersister {
1169
1178
 
1170
1179
  /**
1171
1180
  * Clears query and hash params from redirect_uri and persists them in storage
1172
- * @param {Object} params
1181
+ * @param {object} params Params used to persist and normalize the redirect URI.
1182
+ * @param {string} params.redirect_uri The redirect URI containing query and hash params to persist.
1173
1183
  */
1174
1184
  persist(params) {
1175
1185
  const redirectUrl = new URL(params.redirect_uri);
@@ -1187,7 +1197,7 @@ class RedirectUriParamsPersister {
1187
1197
  /**
1188
1198
  * Retrieves persisted query and hash params from storage and updates current location accordingly.
1189
1199
  * Params returned by global accounts overrides persisted params in case of duplications.
1190
- * @param {Object} state
1200
+ * @param {object} state Storage key used to retrieve persisted redirect URI params.
1191
1201
  */
1192
1202
  retrieve(state) {
1193
1203
  const redirectUriParams = this.persister.get(state, false);
@@ -1220,19 +1230,24 @@ class RedirectUriParamsPersister {
1220
1230
  }
1221
1231
  }
1222
1232
 
1223
- /* eslint-disable require-jsdoc */
1224
-
1225
- /** @fileOverview
1233
+ /**
1234
+ * @file
1226
1235
  * @author Auth0 https://github.com/auth0/auth0.js
1227
1236
  * @license MIT
1228
1237
  */
1229
1238
 
1239
+ /**
1240
+ * Generates a random string of the specified length using characters from a defined set.
1241
+ * @param {number} length The length of the random string to generate.
1242
+ * @returns {string} The generated random string.
1243
+ */
1230
1244
  function string(length) {
1231
1245
  const charset =
1232
1246
  '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~';
1233
1247
  const charsetLength = charset.length;
1234
1248
  const cryptoObj = window.crypto || window.msCrypto;
1235
- const hasCrypto = cryptoObj && typeof cryptoObj.getRandomValues === 'function';
1249
+ const hasCrypto =
1250
+ cryptoObj && typeof cryptoObj.getRandomValues === 'function';
1236
1251
 
1237
1252
  if (!hasCrypto) {
1238
1253
  return generateWithMathRandom(length, charset, charsetLength);
@@ -1263,6 +1278,13 @@ function string(length) {
1263
1278
  return result.join('');
1264
1279
  }
1265
1280
 
1281
+ /**
1282
+ * Generates a random string using `Math.random()` as a fallback when the Web Crypto API is unavailable.
1283
+ * @param {number} length The length of the random string to generate.
1284
+ * @param {string} charset The set of characters to choose from.
1285
+ * @param {number} charsetLength The length of the provided character set.
1286
+ * @returns {string} The generated random string.
1287
+ */
1266
1288
  function generateWithMathRandom(length, charset, charsetLength) {
1267
1289
  let output = '';
1268
1290
  for (let i = 0; i < length; i++) {
@@ -1282,31 +1304,31 @@ var random = {
1282
1304
  class AccountsSDK {
1283
1305
  /**
1284
1306
  * Accounts SDK constructor
1285
- *
1286
- * @constructor
1287
- * @param {Object} options
1288
- * @param {String} options.client_id registered client ID
1289
- * @param {String} options.organization_id organization ID
1290
- * @param {String} [options.prompt=''] use `consent` to force consent prompt in popup and redirect flows
1291
- * @param {String} [options.response_type='token'] OAuth response type, use `token` or `code`
1292
- * @param {String} [options.popup_flow='auto'] `auto` - close popup when not required, `manual` - always show popup
1293
- * @param {String} [options.state=''] OAuth state param
1294
- * @param {Boolean} [options.verify_state=true] check if state matches after redirect
1295
- * @param {String} [options.scope=null] request exact scopes - must be configured for a given client id
1296
- * @param {String} [options.redirect_uri=''] OAuth redirect uri - default current location
1297
- * @param {String} [options.email_hint=''] fill in email in forms
1298
- * @param {String} [options.server_url='https://accounts.livechat.com'] authorization server url
1299
- * @param {String} [options.path=''] option to provide a path when loading accounts, for example '/signup'
1300
- * @param {Object} [options.tracking] tracking querystring params
1301
- * @param {Object} [options.transaction] options for transaction manager
1302
- * @param {String} [options.transaction.namespace='com.livechat.accounts'] transaction keys prefix
1303
- * @param {Number} [options.transaction.key_length=32] transaction random state length
1304
- * @param {Boolean} [options.transaction.force_local_storage=false] try to use local storage instead of cookies
1305
- * @param {Object} [options.pkce] PKCE configuration
1306
- * @param {Boolean} [options.pkce.enabled=true] Oauth 2.1 PKCE extension enabled
1307
- * @param {String} [options.pkce.code_verifier] override auto generated code verifier
1308
- * @param {Number} [options.pkce.code_verifier_length=128] code verifier length, between 43 and 128 characters https://tools.ietf.org/html/rfc7636#section-4.1
1309
- * @param {String} [options.pkce.code_challange_method='S256'] code challange method, use `S256` or `plain`
1307
+ * @class
1308
+ * @param {object} options configuration options for AccountsSDK
1309
+ * @param {string} options.client_id registered client ID
1310
+ * @param {string} options.organization_id organization ID
1311
+ * @param {string} [options.prompt] use `consent` to force consent prompt in popup and redirect flows
1312
+ * @param {string} [options.response_type] OAuth response type, use `token` or `code` (default: `token`)
1313
+ * @param {string} [options.popup_flow] `auto` - close popup when not required, `manual` - always show popup (default: `auto`)
1314
+ * @param {string} [options.state] OAuth state param (default: empty string)
1315
+ * @param {boolean} [options.verify_state] check if state matches after redirect (default: `true`)
1316
+ * @param {string} [options.scope] request exact scopes - must be configured for a given client id (default: `null`)
1317
+ * @param {string} [options.redirect_uri] OAuth redirect uri - default current location (default: empty string)
1318
+ * @param {string} [options.email_hint] fill in email in forms (default: `null`)
1319
+ * @param {string} [options.server_url] authorization server url (default: `https://accounts.livechat.com`)
1320
+ * @param {string} [options.path] option to provide a path when loading accounts, for example '/signup' (default: empty string)
1321
+ * @param {object} [options.tracking] tracking querystring params
1322
+ * @param {object} [options.transaction] options for transaction manager
1323
+ * @param {string} [options.transaction.namespace] transaction keys prefix (default: `com.livechat.accounts`)
1324
+ * @param {number} [options.transaction.key_length] transaction random state length (default: `32`)
1325
+ * @param {boolean} [options.transaction.force_local_storage] try to use local storage instead of cookies (default: `false`)
1326
+ * @param {object} [options.pkce] PKCE configuration
1327
+ * @param {boolean} [options.pkce.enabled] Oauth 2.1 PKCE extension enabled (default: `true`)
1328
+ * @param {string} [options.pkce.code_verifier] override auto generated code verifier
1329
+ * @param {number} [options.pkce.code_verifier_length] code verifier length, between 43 and 128 characters
1330
+ * https://tools.ietf.org/html/rfc7636#section-4.1 (default: `128`)
1331
+ * @param {string} [options.pkce.code_challange_method] code challange method, use `S256` or `plain` (default: `S256`)
1310
1332
  */
1311
1333
  constructor(options = {}) {
1312
1334
  if (options.client_id == null) {
@@ -1350,8 +1372,8 @@ class AccountsSDK {
1350
1372
 
1351
1373
  /**
1352
1374
  * use iframe for authorization
1353
- * @param {Object} options for overriding defaults
1354
- * @return {Iframe} instance of an iframe flow
1375
+ * @param {object} options for overriding defaults
1376
+ * @returns {Iframe} instance of an iframe flow
1355
1377
  */
1356
1378
  iframe(options = {}) {
1357
1379
  const localOptions = Object.assign({}, this.options, options);
@@ -1360,8 +1382,8 @@ class AccountsSDK {
1360
1382
 
1361
1383
  /**
1362
1384
  * use popup for authorization
1363
- * @param {Object} options for overriding defaults
1364
- * @return {Popup} instance of a popup flow
1385
+ * @param {object} options for overriding defaults
1386
+ * @returns {Popup} instance of a popup flow
1365
1387
  */
1366
1388
  popup(options = {}) {
1367
1389
  const localOptions = Object.assign({}, this.options, options);
@@ -1370,8 +1392,8 @@ class AccountsSDK {
1370
1392
 
1371
1393
  /**
1372
1394
  * use redirect for authorization
1373
- * @param {Object} options for overriding defaults
1374
- * @return {Redirect} instance of a redirect flow
1395
+ * @param {object} options for overriding defaults
1396
+ * @returns {Redirect} instance of a redirect flow
1375
1397
  */
1376
1398
  redirect(options = {}) {
1377
1399
  const localOptions = Object.assign({}, this.options, options);
@@ -1380,9 +1402,9 @@ class AccountsSDK {
1380
1402
 
1381
1403
  /**
1382
1404
  * create authorization url
1383
- * @param {Object} options for overriding defaults
1384
- * @param {String} flow set 'button' for popup and iframe
1385
- * @return {string} generated url
1405
+ * @param {object} options for overriding defaults
1406
+ * @param {string} flow set 'button' for popup and iframe
1407
+ * @returns {string} generated url
1386
1408
  */
1387
1409
  authorizeURL(options = {}, flow = '') {
1388
1410
  const localOptions = Object.assign({}, this.options, options);
@@ -1434,7 +1456,7 @@ class AccountsSDK {
1434
1456
  random.string(localOptions.pkce.code_verifier_length);
1435
1457
 
1436
1458
  switch (localOptions.pkce.code_challange_method) {
1437
- case 'S256':
1459
+ case 'S256': {
1438
1460
  const codeChallenge = sjcl.hash.sha256.hash(codeVerifier);
1439
1461
  Object.assign(params, {
1440
1462
  code_verifier: codeVerifier,
@@ -1442,6 +1464,7 @@ class AccountsSDK {
1442
1464
  code_challenge_method: localOptions.pkce.code_challange_method,
1443
1465
  });
1444
1466
  break;
1467
+ }
1445
1468
 
1446
1469
  default:
1447
1470
  Object.assign(params, {
@@ -1462,8 +1485,8 @@ class AccountsSDK {
1462
1485
 
1463
1486
  /**
1464
1487
  * This function verifies if redirect transaction params are valid.
1465
- * @param {Object} authorizeData authorize data to validate and return transaction state - redirect state, pkce code verifier
1466
- * @return {Object} transaction state if valid, null otherwise
1488
+ * @param {object} authorizeData authorize data to validate and return transaction state - redirect state, pkce code verifier
1489
+ * @returns {object | null} transaction state if valid, null otherwise
1467
1490
  */
1468
1491
  verify(authorizeData) {
1469
1492
  const transactionData = this.transaction.get(authorizeData.state);