@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/accounts-sdk.js +2879 -2299
- package/dist/accounts-sdk.js.map +1 -1
- package/dist/accounts-sdk.min.js +36 -7
- package/dist/accounts-sdk.min.js.map +1 -1
- package/dist/index.cjs.js +211 -193
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +198 -175
- package/dist/index.esm.js.map +1 -1
- package/package.json +23 -18
- package/readme.md +23 -13
package/dist/index.cjs.js
CHANGED
|
@@ -5,11 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var qs = require('qs');
|
|
6
6
|
var Cookie = require('js-cookie');
|
|
7
7
|
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
11
|
-
var Cookie__default = /*#__PURE__*/_interopDefaultLegacy(Cookie);
|
|
12
|
-
|
|
13
8
|
var errors = {
|
|
14
9
|
extend: function (error) {
|
|
15
10
|
if (error.oauth_exception && this.oauth_exception[error.oauth_exception]) {
|
|
@@ -37,7 +32,8 @@ var errors = {
|
|
|
37
32
|
'Client not found, not provided or incorectly configured.',
|
|
38
33
|
|
|
39
34
|
access_denied:
|
|
40
|
-
'Probably this application is installed on a different account
|
|
35
|
+
'Probably this application is installed on a different account ' +
|
|
36
|
+
'and you do not have access to it.',
|
|
41
37
|
|
|
42
38
|
unsupported_response_type:
|
|
43
39
|
'Provided response type is incorrect or unavailable for a given client.',
|
|
@@ -47,7 +43,6 @@ var errors = {
|
|
|
47
43
|
},
|
|
48
44
|
};
|
|
49
45
|
|
|
50
|
-
/* eslint-disable require-jsdoc */
|
|
51
46
|
class Listener {
|
|
52
47
|
constructor(options = {}) {
|
|
53
48
|
this.options = options;
|
|
@@ -113,7 +108,6 @@ class Listener {
|
|
|
113
108
|
* Class for authentication using popup.
|
|
114
109
|
*/
|
|
115
110
|
class Popup {
|
|
116
|
-
// eslint-disable-next-line require-jsdoc
|
|
117
111
|
constructor(sdk, options) {
|
|
118
112
|
this.options = options;
|
|
119
113
|
this.sdk = sdk;
|
|
@@ -121,7 +115,7 @@ class Popup {
|
|
|
121
115
|
|
|
122
116
|
/**
|
|
123
117
|
* run popup authorization flow, should be called in a click handler to avoid beeing blocked
|
|
124
|
-
* @
|
|
118
|
+
* @returns {Promise} promise that resolves to authorize data or error
|
|
125
119
|
*/
|
|
126
120
|
authorize() {
|
|
127
121
|
return new Promise((resolve, reject) => {
|
|
@@ -140,7 +134,7 @@ class Popup {
|
|
|
140
134
|
resolve(authorizeData);
|
|
141
135
|
});
|
|
142
136
|
|
|
143
|
-
|
|
137
|
+
const open = function () {
|
|
144
138
|
window.open(
|
|
145
139
|
url,
|
|
146
140
|
'livechat-login-popup',
|
|
@@ -149,7 +143,7 @@ class Popup {
|
|
|
149
143
|
};
|
|
150
144
|
|
|
151
145
|
if (document.requestStorageAccess) {
|
|
152
|
-
|
|
146
|
+
const promise = document.requestStorageAccess();
|
|
153
147
|
promise.then(open, open);
|
|
154
148
|
} else {
|
|
155
149
|
open();
|
|
@@ -158,13 +152,13 @@ class Popup {
|
|
|
158
152
|
}
|
|
159
153
|
}
|
|
160
154
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
/**
|
|
156
|
+
* @param {Record<string, unknown>} object Source object to pick properties from.
|
|
157
|
+
* @param {string[]} keys Keys to pick from the source object.
|
|
158
|
+
* @returns {Record<string, unknown>} A new object containing only the picked keys.
|
|
164
159
|
* @author Auth0 https://github.com/auth0/auth0.js
|
|
165
160
|
* @license MIT
|
|
166
161
|
*/
|
|
167
|
-
|
|
168
162
|
function pick(object, keys) {
|
|
169
163
|
return keys.reduce((prev, key) => {
|
|
170
164
|
if (object[key]) {
|
|
@@ -174,9 +168,7 @@ function pick(object, keys) {
|
|
|
174
168
|
}, {});
|
|
175
169
|
}
|
|
176
170
|
|
|
177
|
-
// eslint-disable-next-line require-jsdoc
|
|
178
171
|
class Redirect {
|
|
179
|
-
// eslint-disable-next-line require-jsdoc
|
|
180
172
|
constructor(sdk, options) {
|
|
181
173
|
this.options = options;
|
|
182
174
|
this.sdk = sdk;
|
|
@@ -192,7 +184,7 @@ class Redirect {
|
|
|
192
184
|
|
|
193
185
|
/**
|
|
194
186
|
* this function checks if the current origin was redirected to with authorize data
|
|
195
|
-
* @
|
|
187
|
+
* @returns {Promise} promise that resolves to authorize data or error
|
|
196
188
|
*/
|
|
197
189
|
authorizeData() {
|
|
198
190
|
return new Promise((resolve, reject) => {
|
|
@@ -203,7 +195,7 @@ class Redirect {
|
|
|
203
195
|
case 'token':
|
|
204
196
|
requiredFields = ['access_token', 'expires_in', 'token_type'];
|
|
205
197
|
|
|
206
|
-
authorizeData =
|
|
198
|
+
authorizeData = qs.parse(window.location.hash.substring(1));
|
|
207
199
|
authorizeData = pick(authorizeData, [
|
|
208
200
|
'access_token',
|
|
209
201
|
'expires_in',
|
|
@@ -214,7 +206,7 @@ class Redirect {
|
|
|
214
206
|
|
|
215
207
|
if (
|
|
216
208
|
!requiredFields.every((field) =>
|
|
217
|
-
|
|
209
|
+
Object.prototype.hasOwnProperty.call(authorizeData, field)
|
|
218
210
|
)
|
|
219
211
|
) {
|
|
220
212
|
reject(errors.extend({identity_exception: 'unauthorized'}));
|
|
@@ -227,14 +219,14 @@ class Redirect {
|
|
|
227
219
|
case 'code':
|
|
228
220
|
requiredFields = ['code'];
|
|
229
221
|
|
|
230
|
-
authorizeData =
|
|
222
|
+
authorizeData = qs.parse(window.location.search, {
|
|
231
223
|
ignoreQueryPrefix: true,
|
|
232
224
|
});
|
|
233
225
|
authorizeData = pick(authorizeData, ['state', 'code']);
|
|
234
226
|
|
|
235
227
|
if (
|
|
236
228
|
!requiredFields.every((field) =>
|
|
237
|
-
|
|
229
|
+
Object.prototype.hasOwnProperty.call(authorizeData, field)
|
|
238
230
|
)
|
|
239
231
|
) {
|
|
240
232
|
reject(errors.extend({identity_exception: 'unauthorized'}));
|
|
@@ -253,7 +245,6 @@ class Redirect {
|
|
|
253
245
|
* Class for authentication using Iframe
|
|
254
246
|
*/
|
|
255
247
|
class Iframe {
|
|
256
|
-
// eslint-disable-next-line require-jsdoc
|
|
257
248
|
constructor(sdk, options) {
|
|
258
249
|
this.options = options;
|
|
259
250
|
this.sdk = sdk;
|
|
@@ -261,7 +252,7 @@ class Iframe {
|
|
|
261
252
|
|
|
262
253
|
/**
|
|
263
254
|
* run iframe authorization flow, not recommended because of ITP 2.0
|
|
264
|
-
* @
|
|
255
|
+
* @returns {Promise} promise that resolves to authorize data or error
|
|
265
256
|
*/
|
|
266
257
|
authorize() {
|
|
267
258
|
return new Promise((resolve, reject) => {
|
|
@@ -294,12 +285,10 @@ class Iframe {
|
|
|
294
285
|
});
|
|
295
286
|
}
|
|
296
287
|
|
|
297
|
-
// eslint-disable-next-line require-jsdoc
|
|
298
288
|
iframeID() {
|
|
299
289
|
return this.options.client_id + this.options.response_type;
|
|
300
290
|
}
|
|
301
291
|
|
|
302
|
-
// eslint-disable-next-line require-jsdoc
|
|
303
292
|
removeIframe() {
|
|
304
293
|
const ref = document.getElementById(this.iframeID());
|
|
305
294
|
if (ref && ref.parentNode) {
|
|
@@ -308,13 +297,17 @@ class Iframe {
|
|
|
308
297
|
}
|
|
309
298
|
}
|
|
310
299
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/** @fileOverview
|
|
300
|
+
/**
|
|
301
|
+
* @file
|
|
314
302
|
* @author Auth0 https://github.com/auth0/auth0.js
|
|
315
303
|
* @license MIT
|
|
316
304
|
*/
|
|
317
305
|
|
|
306
|
+
/**
|
|
307
|
+
* A dummy storage mechanism that does not persist data.
|
|
308
|
+
* It provides methods to get, set, and remove items, but they do not perform any actual storage operations.
|
|
309
|
+
* This can be used as a fallback when no other storage mechanism is available.
|
|
310
|
+
*/
|
|
318
311
|
function DummyStorage() {}
|
|
319
312
|
|
|
320
313
|
DummyStorage.prototype.getItem = function () {
|
|
@@ -325,15 +318,24 @@ DummyStorage.prototype.removeItem = function () {};
|
|
|
325
318
|
|
|
326
319
|
DummyStorage.prototype.setItem = function () {};
|
|
327
320
|
|
|
328
|
-
|
|
321
|
+
/**
|
|
322
|
+
* @file
|
|
323
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
324
|
+
* @license MIT
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A storage mechanism that uses cookies to store data. It provides methods to get, set, and remove items from cookies.
|
|
330
|
+
*/
|
|
329
331
|
function CookieStorage() {}
|
|
330
332
|
|
|
331
333
|
CookieStorage.prototype.getItem = function (key) {
|
|
332
|
-
return
|
|
334
|
+
return Cookie.get(key);
|
|
333
335
|
};
|
|
334
336
|
|
|
335
337
|
CookieStorage.prototype.removeItem = function (key) {
|
|
336
|
-
|
|
338
|
+
Cookie.remove(key);
|
|
337
339
|
};
|
|
338
340
|
|
|
339
341
|
CookieStorage.prototype.setItem = function (key, value, options) {
|
|
@@ -348,11 +350,23 @@ CookieStorage.prototype.setItem = function (key, value, options) {
|
|
|
348
350
|
},
|
|
349
351
|
options
|
|
350
352
|
);
|
|
351
|
-
|
|
353
|
+
Cookie.set(key, value, params);
|
|
352
354
|
};
|
|
353
355
|
|
|
354
|
-
|
|
356
|
+
/**
|
|
357
|
+
* @file
|
|
358
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
359
|
+
* @license MIT
|
|
360
|
+
*/
|
|
361
|
+
|
|
355
362
|
|
|
363
|
+
/**
|
|
364
|
+
* A handler that manages the underlying storage mechanism, providing failover capabilities between localStorage, CookieStorage, and DummyStorage.
|
|
365
|
+
* It attempts to use localStorage by default, but falls back to CookieStorage if localStorage is unavailable or throws an error.
|
|
366
|
+
* If both localStorage and CookieStorage fail, it falls back to DummyStorage, which does not persist data.
|
|
367
|
+
* The handler provides methods to get, set, and remove items from the storage, with automatic failover in case of errors.
|
|
368
|
+
* @param {object} options Storage configuration options passed to the underlying StorageHandler.
|
|
369
|
+
*/
|
|
356
370
|
function StorageHandler(options) {
|
|
357
371
|
this.storage = new CookieStorage();
|
|
358
372
|
if (options.force_local_storage !== true) {
|
|
@@ -414,8 +428,17 @@ StorageHandler.prototype.setItem = function (key, value, options) {
|
|
|
414
428
|
}
|
|
415
429
|
};
|
|
416
430
|
|
|
417
|
-
|
|
431
|
+
/**
|
|
432
|
+
* @file
|
|
433
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
434
|
+
* @license MIT
|
|
435
|
+
*/
|
|
418
436
|
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* A wrapper around the underlying storage mechanism that handles JSON serialization and deserialization.
|
|
440
|
+
* @param {object} options Storage configuration options passed to the underlying StorageHandler.
|
|
441
|
+
*/
|
|
419
442
|
function Storage(options) {
|
|
420
443
|
this.handler = new StorageHandler(options);
|
|
421
444
|
}
|
|
@@ -424,7 +447,7 @@ Storage.prototype.getItem = function (key) {
|
|
|
424
447
|
const value = this.handler.getItem(key);
|
|
425
448
|
try {
|
|
426
449
|
return JSON.parse(value);
|
|
427
|
-
} catch
|
|
450
|
+
} catch {
|
|
428
451
|
return value;
|
|
429
452
|
}
|
|
430
453
|
};
|
|
@@ -438,7 +461,7 @@ Storage.prototype.setItem = function (key, value, options) {
|
|
|
438
461
|
return this.handler.setItem(key, json, options);
|
|
439
462
|
};
|
|
440
463
|
|
|
441
|
-
/*
|
|
464
|
+
/* internal file */
|
|
442
465
|
|
|
443
466
|
class Transaction {
|
|
444
467
|
constructor(options) {
|
|
@@ -468,15 +491,16 @@ class Transaction {
|
|
|
468
491
|
}
|
|
469
492
|
}
|
|
470
493
|
|
|
471
|
-
/**
|
|
494
|
+
/**
|
|
472
495
|
*
|
|
496
|
+
* @file Javascript cryptography implementation.
|
|
473
497
|
* Crush to remove comments, shorten variable names and
|
|
474
498
|
* generally reduce transmission size.
|
|
475
|
-
*
|
|
476
499
|
* @author Emily Stark
|
|
477
500
|
* @author Mike Hamburg
|
|
478
501
|
* @author Dan Boneh
|
|
479
502
|
*/
|
|
503
|
+
|
|
480
504
|
/*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
|
|
481
505
|
/*global document, window, escape, unescape, module, require, Uint32Array */
|
|
482
506
|
|
|
@@ -485,40 +509,15 @@ class Transaction {
|
|
|
485
509
|
* @namespace
|
|
486
510
|
*/
|
|
487
511
|
var sjcl = {
|
|
488
|
-
/**
|
|
489
|
-
* Symmetric ciphers.
|
|
490
|
-
* @namespace
|
|
491
|
-
*/
|
|
492
|
-
cipher: {},
|
|
493
|
-
|
|
494
512
|
/**
|
|
495
513
|
* Hash functions. Right now only SHA256 is implemented.
|
|
496
514
|
* @namespace
|
|
497
515
|
*/
|
|
498
516
|
hash: {},
|
|
499
517
|
|
|
500
|
-
/**
|
|
501
|
-
* Key exchange functions. Right now only SRP is implemented.
|
|
502
|
-
* @namespace
|
|
503
|
-
*/
|
|
504
|
-
keyexchange: {},
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Cipher modes of operation.
|
|
508
|
-
* @namespace
|
|
509
|
-
*/
|
|
510
|
-
mode: {},
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Miscellaneous. HMAC and PBKDF2.
|
|
514
|
-
* @namespace
|
|
515
|
-
*/
|
|
516
|
-
misc: {},
|
|
517
|
-
|
|
518
518
|
/**
|
|
519
519
|
* Bit array encoders and decoders.
|
|
520
520
|
* @namespace
|
|
521
|
-
*
|
|
522
521
|
* @description
|
|
523
522
|
* The members of this namespace are functions which translate between
|
|
524
523
|
* SJCL's bitArrays and other objects (usually strings). Because it
|
|
@@ -532,53 +531,21 @@ var sjcl = {
|
|
|
532
531
|
* @namespace
|
|
533
532
|
*/
|
|
534
533
|
exception: {
|
|
535
|
-
/**
|
|
536
|
-
* Ciphertext is corrupt.
|
|
537
|
-
* @constructor
|
|
538
|
-
*/
|
|
539
|
-
corrupt: function (message) {
|
|
540
|
-
this.toString = function () {
|
|
541
|
-
return 'CORRUPT: ' + this.message;
|
|
542
|
-
};
|
|
543
|
-
this.message = message;
|
|
544
|
-
},
|
|
545
|
-
|
|
546
534
|
/**
|
|
547
535
|
* Invalid parameter.
|
|
548
|
-
* @
|
|
536
|
+
* @param {string} message Error message describing the invalid parameter.
|
|
549
537
|
*/
|
|
550
538
|
invalid: function (message) {
|
|
551
539
|
this.toString = function () {
|
|
552
540
|
return 'INVALID: ' + this.message;
|
|
553
541
|
};
|
|
554
542
|
this.message = message;
|
|
555
|
-
},
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Bug or missing feature in SJCL.
|
|
559
|
-
* @constructor
|
|
560
|
-
*/
|
|
561
|
-
bug: function (message) {
|
|
562
|
-
this.toString = function () {
|
|
563
|
-
return 'BUG: ' + this.message;
|
|
564
|
-
};
|
|
565
|
-
this.message = message;
|
|
566
|
-
},
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* Something isn't ready.
|
|
570
|
-
* @constructor
|
|
571
|
-
*/
|
|
572
|
-
notReady: function (message) {
|
|
573
|
-
this.toString = function () {
|
|
574
|
-
return 'NOT READY: ' + this.message;
|
|
575
|
-
};
|
|
576
|
-
this.message = message;
|
|
577
|
-
},
|
|
578
|
-
},
|
|
543
|
+
}},
|
|
579
544
|
};
|
|
580
|
-
|
|
545
|
+
|
|
546
|
+
/**
|
|
581
547
|
*
|
|
548
|
+
* @file Arrays of bits, encoded as arrays of Numbers.
|
|
582
549
|
* @author Emily Stark
|
|
583
550
|
* @author Mike Hamburg
|
|
584
551
|
* @author Dan Boneh
|
|
@@ -608,14 +575,17 @@ var sjcl = {
|
|
|
608
575
|
* to ciphers like AES which want arrays of words.
|
|
609
576
|
* </p>
|
|
610
577
|
*/
|
|
578
|
+
/**
|
|
579
|
+
* @typedef {number[]} bitArray
|
|
580
|
+
*/
|
|
611
581
|
sjcl.bitArray = {
|
|
612
582
|
/**
|
|
613
583
|
* Array slices in units of bits.
|
|
614
584
|
* @param {bitArray} a The array to slice.
|
|
615
|
-
* @param {
|
|
616
|
-
* @param {
|
|
585
|
+
* @param {number} bstart The offset to the start of the slice, in bits.
|
|
586
|
+
* @param {number} [bend] The offset to the end of the slice, in bits. If this is undefined,
|
|
617
587
|
* slice until the end of the array.
|
|
618
|
-
* @
|
|
588
|
+
* @returns {bitArray} The requested slice.
|
|
619
589
|
*/
|
|
620
590
|
bitSlice: function (a, bstart, bend) {
|
|
621
591
|
a = sjcl.bitArray
|
|
@@ -627,9 +597,9 @@ sjcl.bitArray = {
|
|
|
627
597
|
/**
|
|
628
598
|
* Extract a number packed into a bit array.
|
|
629
599
|
* @param {bitArray} a The array to slice.
|
|
630
|
-
* @param {
|
|
631
|
-
* @param {
|
|
632
|
-
* @
|
|
600
|
+
* @param {number} bstart The offset to the start of the slice, in bits.
|
|
601
|
+
* @param {number} blength The length of the number to extract.
|
|
602
|
+
* @returns {number} The requested slice.
|
|
633
603
|
*/
|
|
634
604
|
extract: function (a, bstart, blength) {
|
|
635
605
|
// FIXME: this Math.floor is not necessary at all, but for some reason
|
|
@@ -651,7 +621,7 @@ sjcl.bitArray = {
|
|
|
651
621
|
* Concatenate two bit arrays.
|
|
652
622
|
* @param {bitArray} a1 The first array.
|
|
653
623
|
* @param {bitArray} a2 The second array.
|
|
654
|
-
* @
|
|
624
|
+
* @returns {bitArray} The concatenation of a1 and a2.
|
|
655
625
|
*/
|
|
656
626
|
concat: function (a1, a2) {
|
|
657
627
|
if (a1.length === 0 || a2.length === 0) {
|
|
@@ -675,7 +645,7 @@ sjcl.bitArray = {
|
|
|
675
645
|
/**
|
|
676
646
|
* Find the length of an array of bits.
|
|
677
647
|
* @param {bitArray} a The array.
|
|
678
|
-
* @
|
|
648
|
+
* @returns {number} The length of a, in bits.
|
|
679
649
|
*/
|
|
680
650
|
bitLength: function (a) {
|
|
681
651
|
var l = a.length,
|
|
@@ -690,8 +660,8 @@ sjcl.bitArray = {
|
|
|
690
660
|
/**
|
|
691
661
|
* Truncate an array.
|
|
692
662
|
* @param {bitArray} a The array.
|
|
693
|
-
* @param {
|
|
694
|
-
* @
|
|
663
|
+
* @param {number} len The length to truncate to, in bits.
|
|
664
|
+
* @returns {bitArray} A new array, truncated to len bits.
|
|
695
665
|
*/
|
|
696
666
|
clamp: function (a, len) {
|
|
697
667
|
if (a.length * 32 < len) {
|
|
@@ -712,10 +682,10 @@ sjcl.bitArray = {
|
|
|
712
682
|
|
|
713
683
|
/**
|
|
714
684
|
* Make a partial word for a bit array.
|
|
715
|
-
* @param {
|
|
716
|
-
* @param {
|
|
717
|
-
* @param {
|
|
718
|
-
* @
|
|
685
|
+
* @param {number} len The number of bits in the word.
|
|
686
|
+
* @param {number} x The bits.
|
|
687
|
+
* @param {number} [_end] Pass 1 if x has already been shifted to the high side.
|
|
688
|
+
* @returns {number} The partial word.
|
|
719
689
|
*/
|
|
720
690
|
partial: function (len, x, _end) {
|
|
721
691
|
if (len === 32) {
|
|
@@ -726,8 +696,8 @@ sjcl.bitArray = {
|
|
|
726
696
|
|
|
727
697
|
/**
|
|
728
698
|
* Get the number of bits used by a partial word.
|
|
729
|
-
* @param {
|
|
730
|
-
* @
|
|
699
|
+
* @param {number} x The partial word.
|
|
700
|
+
* @returns {number} The number of bits used by the partial word.
|
|
731
701
|
*/
|
|
732
702
|
getPartial: function (x) {
|
|
733
703
|
return Math.round(x / 0x10000000000) || 32;
|
|
@@ -737,7 +707,7 @@ sjcl.bitArray = {
|
|
|
737
707
|
* Compare two arrays for equality in a predictable amount of time.
|
|
738
708
|
* @param {bitArray} a The first array.
|
|
739
709
|
* @param {bitArray} b The second array.
|
|
740
|
-
* @
|
|
710
|
+
* @returns {boolean} true if a == b; false otherwise.
|
|
741
711
|
*/
|
|
742
712
|
equal: function (a, b) {
|
|
743
713
|
if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) {
|
|
@@ -751,11 +721,13 @@ sjcl.bitArray = {
|
|
|
751
721
|
return x === 0;
|
|
752
722
|
},
|
|
753
723
|
|
|
754
|
-
/**
|
|
724
|
+
/**
|
|
725
|
+
* Shift an array right.
|
|
755
726
|
* @param {bitArray} a The array to shift.
|
|
756
|
-
* @param {
|
|
757
|
-
* @param {
|
|
758
|
-
* @param {bitArray} [out
|
|
727
|
+
* @param {number} shift The number of bits to shift.
|
|
728
|
+
* @param {number} [carry] A word to carry in (defaults to 0).
|
|
729
|
+
* @param {bitArray} [out] An array to prepend to the output (defaults to []).
|
|
730
|
+
* @returns {bitArray} The shifted bitArray.
|
|
759
731
|
* @private
|
|
760
732
|
*/
|
|
761
733
|
_shiftRight: function (a, shift, carry, out) {
|
|
@@ -790,17 +762,22 @@ sjcl.bitArray = {
|
|
|
790
762
|
return out;
|
|
791
763
|
},
|
|
792
764
|
|
|
793
|
-
/**
|
|
765
|
+
/**
|
|
766
|
+
* XOR a block of 4 words together.
|
|
767
|
+
* @param {bitArray} x The first 4-word block.
|
|
768
|
+
* @param {bitArray} y The second 4-word block.
|
|
769
|
+
* @returns {bitArray} The XOR result as a 4-word block.
|
|
794
770
|
* @private
|
|
795
771
|
*/
|
|
796
772
|
_xor4: function (x, y) {
|
|
797
773
|
return [x[0] ^ y[0], x[1] ^ y[1], x[2] ^ y[2], x[3] ^ y[3]];
|
|
798
774
|
},
|
|
799
775
|
|
|
800
|
-
/**
|
|
776
|
+
/**
|
|
777
|
+
* byteswap a word array inplace.
|
|
801
778
|
* (does not handle partial words)
|
|
802
779
|
* @param {sjcl.bitArray} a word array
|
|
803
|
-
* @
|
|
780
|
+
* @returns {sjcl.bitArray} byteswapped array
|
|
804
781
|
*/
|
|
805
782
|
byteswapM: function (a) {
|
|
806
783
|
var i,
|
|
@@ -813,11 +790,12 @@ sjcl.bitArray = {
|
|
|
813
790
|
return a;
|
|
814
791
|
},
|
|
815
792
|
};
|
|
816
|
-
/**
|
|
793
|
+
/**
|
|
817
794
|
*
|
|
795
|
+
* @file Bit array codec implementations.
|
|
818
796
|
* @author Emily Stark
|
|
819
797
|
* @author Mike Hamburg
|
|
820
|
-
* @author Dan Boneh
|
|
798
|
+
* @author Dan Boneh
|
|
821
799
|
*/
|
|
822
800
|
|
|
823
801
|
/**
|
|
@@ -825,7 +803,11 @@ sjcl.bitArray = {
|
|
|
825
803
|
* @namespace
|
|
826
804
|
*/
|
|
827
805
|
sjcl.codec.utf8String = {
|
|
828
|
-
/**
|
|
806
|
+
/**
|
|
807
|
+
* Convert from a bitArray to a UTF-8 string.
|
|
808
|
+
* @param {bitArray} arr The input bitArray to decode.
|
|
809
|
+
* @returns {string} The decoded UTF-8 string.
|
|
810
|
+
*/
|
|
829
811
|
fromBits: function (arr) {
|
|
830
812
|
var out = '',
|
|
831
813
|
bl = sjcl.bitArray.bitLength(arr),
|
|
@@ -841,7 +823,11 @@ sjcl.codec.utf8String = {
|
|
|
841
823
|
return decodeURIComponent(escape(out));
|
|
842
824
|
},
|
|
843
825
|
|
|
844
|
-
/**
|
|
826
|
+
/**
|
|
827
|
+
* Convert from a UTF-8 string to a bitArray.
|
|
828
|
+
* @param {string} str UTF-8 string to encode.
|
|
829
|
+
* @returns {bitArray} The encoded bitArray.
|
|
830
|
+
*/
|
|
845
831
|
toBits: function (str) {
|
|
846
832
|
str = unescape(encodeURIComponent(str));
|
|
847
833
|
var out = [],
|
|
@@ -860,16 +846,15 @@ sjcl.codec.utf8String = {
|
|
|
860
846
|
return out;
|
|
861
847
|
},
|
|
862
848
|
};
|
|
863
|
-
/**
|
|
849
|
+
/**
|
|
864
850
|
*
|
|
851
|
+
* @file Javascript SHA-256 implementation.
|
|
865
852
|
* An older version of this implementation is available in the public
|
|
866
853
|
* domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
|
|
867
854
|
* Stanford University 2008-2010 and BSD-licensed for liability
|
|
868
855
|
* reasons.
|
|
869
|
-
*
|
|
870
856
|
* Special thanks to Aldo Cortesi for pointing out several bugs in
|
|
871
857
|
* this code.
|
|
872
|
-
*
|
|
873
858
|
* @author Emily Stark
|
|
874
859
|
* @author Mike Hamburg
|
|
875
860
|
* @author Dan Boneh
|
|
@@ -877,7 +862,7 @@ sjcl.codec.utf8String = {
|
|
|
877
862
|
|
|
878
863
|
/**
|
|
879
864
|
* Context for a SHA-256 operation in progress.
|
|
880
|
-
* @
|
|
865
|
+
* @param {sjcl.hash.sha256} [hash] Optional hash to initialize from.
|
|
881
866
|
*/
|
|
882
867
|
sjcl.hash.sha256 = function (hash) {
|
|
883
868
|
if (!this._key[0]) {
|
|
@@ -895,8 +880,8 @@ sjcl.hash.sha256 = function (hash) {
|
|
|
895
880
|
/**
|
|
896
881
|
* Hash a string or an array of words.
|
|
897
882
|
* @static
|
|
898
|
-
* @param {bitArray|
|
|
899
|
-
* @
|
|
883
|
+
* @param {bitArray | string} data the data to hash.
|
|
884
|
+
* @returns {bitArray} The hash value, an array of 16 big-endian words.
|
|
900
885
|
*/
|
|
901
886
|
sjcl.hash.sha256.hash = function (data) {
|
|
902
887
|
return new sjcl.hash.sha256().update(data).finalize();
|
|
@@ -911,7 +896,7 @@ sjcl.hash.sha256.prototype = {
|
|
|
911
896
|
|
|
912
897
|
/**
|
|
913
898
|
* Reset the hash state.
|
|
914
|
-
* @
|
|
899
|
+
* @returns {sjcl.hash.sha256} this
|
|
915
900
|
*/
|
|
916
901
|
reset: function () {
|
|
917
902
|
this._h = this._init.slice(0);
|
|
@@ -922,8 +907,8 @@ sjcl.hash.sha256.prototype = {
|
|
|
922
907
|
|
|
923
908
|
/**
|
|
924
909
|
* Input several words to the hash.
|
|
925
|
-
* @param {bitArray|
|
|
926
|
-
* @
|
|
910
|
+
* @param {bitArray | string} data the data to hash.
|
|
911
|
+
* @returns {sjcl.hash.sha256} this
|
|
927
912
|
*/
|
|
928
913
|
update: function (data) {
|
|
929
914
|
if (typeof data === 'string') {
|
|
@@ -955,7 +940,7 @@ sjcl.hash.sha256.prototype = {
|
|
|
955
940
|
|
|
956
941
|
/**
|
|
957
942
|
* Complete hashing and output the hash value.
|
|
958
|
-
* @
|
|
943
|
+
* @returns {bitArray} The hash value, an array of 8 big-endian words.
|
|
959
944
|
*/
|
|
960
945
|
finalize: function () {
|
|
961
946
|
var i,
|
|
@@ -1018,6 +1003,11 @@ sjcl.hash.sha256.prototype = {
|
|
|
1018
1003
|
factor,
|
|
1019
1004
|
isPrime;
|
|
1020
1005
|
|
|
1006
|
+
/**
|
|
1007
|
+
* Get the fractional part of x scaled to a 32-bit word.
|
|
1008
|
+
* @param {number} x Input number.
|
|
1009
|
+
* @returns {number} A signed 32-bit integer representing the scaled fractional part.
|
|
1010
|
+
*/
|
|
1021
1011
|
function frac(x) {
|
|
1022
1012
|
return ((x - Math.floor(x)) * 0x100000000) | 0;
|
|
1023
1013
|
}
|
|
@@ -1133,7 +1123,11 @@ sjcl.hash.sha256.prototype = {
|
|
|
1133
1123
|
},
|
|
1134
1124
|
};
|
|
1135
1125
|
|
|
1136
|
-
|
|
1126
|
+
/**
|
|
1127
|
+
* Encode a string as base64url (RFC 4648 §5).
|
|
1128
|
+
* @param {string} str - The string to encode.
|
|
1129
|
+
* @returns {string} The base64url-encoded string.
|
|
1130
|
+
*/
|
|
1137
1131
|
function base64URLEncode(str) {
|
|
1138
1132
|
return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
1139
1133
|
}
|
|
@@ -1142,7 +1136,12 @@ var encoding = {
|
|
|
1142
1136
|
base64URLEncode: base64URLEncode,
|
|
1143
1137
|
};
|
|
1144
1138
|
|
|
1145
|
-
|
|
1139
|
+
/**
|
|
1140
|
+
* @file
|
|
1141
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
1142
|
+
* @license MIT
|
|
1143
|
+
*/
|
|
1144
|
+
|
|
1146
1145
|
|
|
1147
1146
|
class Persister {
|
|
1148
1147
|
constructor(options, type) {
|
|
@@ -1169,7 +1168,12 @@ class Persister {
|
|
|
1169
1168
|
}
|
|
1170
1169
|
}
|
|
1171
1170
|
|
|
1172
|
-
|
|
1171
|
+
/**
|
|
1172
|
+
* @file
|
|
1173
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
1174
|
+
* @license MIT
|
|
1175
|
+
*/
|
|
1176
|
+
|
|
1173
1177
|
|
|
1174
1178
|
class RedirectUriParamsPersister {
|
|
1175
1179
|
constructor(options) {
|
|
@@ -1178,12 +1182,13 @@ class RedirectUriParamsPersister {
|
|
|
1178
1182
|
|
|
1179
1183
|
/**
|
|
1180
1184
|
* Clears query and hash params from redirect_uri and persists them in storage
|
|
1181
|
-
* @param {
|
|
1185
|
+
* @param {object} params Params used to persist and normalize the redirect URI.
|
|
1186
|
+
* @param {string} params.redirect_uri The redirect URI containing query and hash params to persist.
|
|
1182
1187
|
*/
|
|
1183
1188
|
persist(params) {
|
|
1184
1189
|
const redirectUrl = new URL(params.redirect_uri);
|
|
1185
|
-
const queryParams =
|
|
1186
|
-
const hashParams =
|
|
1190
|
+
const queryParams = qs.parse(redirectUrl.search.substring(1));
|
|
1191
|
+
const hashParams = qs.parse(redirectUrl.hash.substring(1));
|
|
1187
1192
|
|
|
1188
1193
|
this.persister.set(params.state, {
|
|
1189
1194
|
query_params: queryParams,
|
|
@@ -1196,7 +1201,7 @@ class RedirectUriParamsPersister {
|
|
|
1196
1201
|
/**
|
|
1197
1202
|
* Retrieves persisted query and hash params from storage and updates current location accordingly.
|
|
1198
1203
|
* Params returned by global accounts overrides persisted params in case of duplications.
|
|
1199
|
-
* @param {
|
|
1204
|
+
* @param {object} state Storage key used to retrieve persisted redirect URI params.
|
|
1200
1205
|
*/
|
|
1201
1206
|
retrieve(state) {
|
|
1202
1207
|
const redirectUriParams = this.persister.get(state, false);
|
|
@@ -1207,41 +1212,46 @@ class RedirectUriParamsPersister {
|
|
|
1207
1212
|
|
|
1208
1213
|
const queryParams = {
|
|
1209
1214
|
...(redirectUriParams.query_params ?? {}),
|
|
1210
|
-
...
|
|
1215
|
+
...qs.parse(window.location.search.substring(1)),
|
|
1211
1216
|
};
|
|
1212
1217
|
|
|
1213
1218
|
const hashParams = {
|
|
1214
1219
|
...(redirectUriParams.hash_params ?? {}),
|
|
1215
|
-
...
|
|
1220
|
+
...qs.parse(window.location.hash.substring(1)),
|
|
1216
1221
|
};
|
|
1217
1222
|
|
|
1218
1223
|
let uri = window.location.origin + window.location.pathname;
|
|
1219
1224
|
|
|
1220
1225
|
if (queryParams) {
|
|
1221
|
-
uri += '?' +
|
|
1226
|
+
uri += '?' + qs.stringify(queryParams);
|
|
1222
1227
|
}
|
|
1223
1228
|
|
|
1224
1229
|
if (hashParams) {
|
|
1225
|
-
uri += '#' +
|
|
1230
|
+
uri += '#' + qs.stringify(hashParams);
|
|
1226
1231
|
}
|
|
1227
1232
|
|
|
1228
1233
|
window.history.replaceState({}, document.title, uri);
|
|
1229
1234
|
}
|
|
1230
1235
|
}
|
|
1231
1236
|
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
/** @fileOverview
|
|
1237
|
+
/**
|
|
1238
|
+
* @file
|
|
1235
1239
|
* @author Auth0 https://github.com/auth0/auth0.js
|
|
1236
1240
|
* @license MIT
|
|
1237
1241
|
*/
|
|
1238
1242
|
|
|
1243
|
+
/**
|
|
1244
|
+
* Generates a random string of the specified length using characters from a defined set.
|
|
1245
|
+
* @param {number} length The length of the random string to generate.
|
|
1246
|
+
* @returns {string} The generated random string.
|
|
1247
|
+
*/
|
|
1239
1248
|
function string(length) {
|
|
1240
1249
|
const charset =
|
|
1241
1250
|
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~';
|
|
1242
1251
|
const charsetLength = charset.length;
|
|
1243
1252
|
const cryptoObj = window.crypto || window.msCrypto;
|
|
1244
|
-
const hasCrypto =
|
|
1253
|
+
const hasCrypto =
|
|
1254
|
+
cryptoObj && typeof cryptoObj.getRandomValues === 'function';
|
|
1245
1255
|
|
|
1246
1256
|
if (!hasCrypto) {
|
|
1247
1257
|
return generateWithMathRandom(length, charset, charsetLength);
|
|
@@ -1272,6 +1282,13 @@ function string(length) {
|
|
|
1272
1282
|
return result.join('');
|
|
1273
1283
|
}
|
|
1274
1284
|
|
|
1285
|
+
/**
|
|
1286
|
+
* Generates a random string using `Math.random()` as a fallback when the Web Crypto API is unavailable.
|
|
1287
|
+
* @param {number} length The length of the random string to generate.
|
|
1288
|
+
* @param {string} charset The set of characters to choose from.
|
|
1289
|
+
* @param {number} charsetLength The length of the provided character set.
|
|
1290
|
+
* @returns {string} The generated random string.
|
|
1291
|
+
*/
|
|
1275
1292
|
function generateWithMathRandom(length, charset, charsetLength) {
|
|
1276
1293
|
let output = '';
|
|
1277
1294
|
for (let i = 0; i < length; i++) {
|
|
@@ -1291,31 +1308,31 @@ var random = {
|
|
|
1291
1308
|
class AccountsSDK {
|
|
1292
1309
|
/**
|
|
1293
1310
|
* Accounts SDK constructor
|
|
1294
|
-
*
|
|
1295
|
-
* @
|
|
1296
|
-
* @param {
|
|
1297
|
-
* @param {
|
|
1298
|
-
* @param {
|
|
1299
|
-
* @param {
|
|
1300
|
-
* @param {
|
|
1301
|
-
* @param {
|
|
1302
|
-
* @param {
|
|
1303
|
-
* @param {
|
|
1304
|
-
* @param {
|
|
1305
|
-
* @param {
|
|
1306
|
-
* @param {
|
|
1307
|
-
* @param {
|
|
1308
|
-
* @param {
|
|
1309
|
-
* @param {
|
|
1310
|
-
* @param {
|
|
1311
|
-
* @param {
|
|
1312
|
-
* @param {
|
|
1313
|
-
* @param {
|
|
1314
|
-
* @param {
|
|
1315
|
-
* @param {
|
|
1316
|
-
* @param {
|
|
1317
|
-
*
|
|
1318
|
-
* @param {
|
|
1311
|
+
* @class
|
|
1312
|
+
* @param {object} options configuration options for AccountsSDK
|
|
1313
|
+
* @param {string} options.client_id registered client ID
|
|
1314
|
+
* @param {string} options.organization_id organization ID
|
|
1315
|
+
* @param {string} [options.prompt] use `consent` to force consent prompt in popup and redirect flows
|
|
1316
|
+
* @param {string} [options.response_type] OAuth response type, use `token` or `code` (default: `token`)
|
|
1317
|
+
* @param {string} [options.popup_flow] `auto` - close popup when not required, `manual` - always show popup (default: `auto`)
|
|
1318
|
+
* @param {string} [options.state] OAuth state param (default: empty string)
|
|
1319
|
+
* @param {boolean} [options.verify_state] check if state matches after redirect (default: `true`)
|
|
1320
|
+
* @param {string} [options.scope] request exact scopes - must be configured for a given client id (default: `null`)
|
|
1321
|
+
* @param {string} [options.redirect_uri] OAuth redirect uri - default current location (default: empty string)
|
|
1322
|
+
* @param {string} [options.email_hint] fill in email in forms (default: `null`)
|
|
1323
|
+
* @param {string} [options.server_url] authorization server url (default: `https://accounts.livechat.com`)
|
|
1324
|
+
* @param {string} [options.path] option to provide a path when loading accounts, for example '/signup' (default: empty string)
|
|
1325
|
+
* @param {object} [options.tracking] tracking querystring params
|
|
1326
|
+
* @param {object} [options.transaction] options for transaction manager
|
|
1327
|
+
* @param {string} [options.transaction.namespace] transaction keys prefix (default: `com.livechat.accounts`)
|
|
1328
|
+
* @param {number} [options.transaction.key_length] transaction random state length (default: `32`)
|
|
1329
|
+
* @param {boolean} [options.transaction.force_local_storage] try to use local storage instead of cookies (default: `false`)
|
|
1330
|
+
* @param {object} [options.pkce] PKCE configuration
|
|
1331
|
+
* @param {boolean} [options.pkce.enabled] Oauth 2.1 PKCE extension enabled (default: `true`)
|
|
1332
|
+
* @param {string} [options.pkce.code_verifier] override auto generated code verifier
|
|
1333
|
+
* @param {number} [options.pkce.code_verifier_length] code verifier length, between 43 and 128 characters
|
|
1334
|
+
* https://tools.ietf.org/html/rfc7636#section-4.1 (default: `128`)
|
|
1335
|
+
* @param {string} [options.pkce.code_challange_method] code challange method, use `S256` or `plain` (default: `S256`)
|
|
1319
1336
|
*/
|
|
1320
1337
|
constructor(options = {}) {
|
|
1321
1338
|
if (options.client_id == null) {
|
|
@@ -1359,8 +1376,8 @@ class AccountsSDK {
|
|
|
1359
1376
|
|
|
1360
1377
|
/**
|
|
1361
1378
|
* use iframe for authorization
|
|
1362
|
-
* @param {
|
|
1363
|
-
* @
|
|
1379
|
+
* @param {object} options for overriding defaults
|
|
1380
|
+
* @returns {Iframe} instance of an iframe flow
|
|
1364
1381
|
*/
|
|
1365
1382
|
iframe(options = {}) {
|
|
1366
1383
|
const localOptions = Object.assign({}, this.options, options);
|
|
@@ -1369,8 +1386,8 @@ class AccountsSDK {
|
|
|
1369
1386
|
|
|
1370
1387
|
/**
|
|
1371
1388
|
* use popup for authorization
|
|
1372
|
-
* @param {
|
|
1373
|
-
* @
|
|
1389
|
+
* @param {object} options for overriding defaults
|
|
1390
|
+
* @returns {Popup} instance of a popup flow
|
|
1374
1391
|
*/
|
|
1375
1392
|
popup(options = {}) {
|
|
1376
1393
|
const localOptions = Object.assign({}, this.options, options);
|
|
@@ -1379,8 +1396,8 @@ class AccountsSDK {
|
|
|
1379
1396
|
|
|
1380
1397
|
/**
|
|
1381
1398
|
* use redirect for authorization
|
|
1382
|
-
* @param {
|
|
1383
|
-
* @
|
|
1399
|
+
* @param {object} options for overriding defaults
|
|
1400
|
+
* @returns {Redirect} instance of a redirect flow
|
|
1384
1401
|
*/
|
|
1385
1402
|
redirect(options = {}) {
|
|
1386
1403
|
const localOptions = Object.assign({}, this.options, options);
|
|
@@ -1389,9 +1406,9 @@ class AccountsSDK {
|
|
|
1389
1406
|
|
|
1390
1407
|
/**
|
|
1391
1408
|
* create authorization url
|
|
1392
|
-
* @param {
|
|
1393
|
-
* @param {
|
|
1394
|
-
* @
|
|
1409
|
+
* @param {object} options for overriding defaults
|
|
1410
|
+
* @param {string} flow set 'button' for popup and iframe
|
|
1411
|
+
* @returns {string} generated url
|
|
1395
1412
|
*/
|
|
1396
1413
|
authorizeURL(options = {}, flow = '') {
|
|
1397
1414
|
const localOptions = Object.assign({}, this.options, options);
|
|
@@ -1443,7 +1460,7 @@ class AccountsSDK {
|
|
|
1443
1460
|
random.string(localOptions.pkce.code_verifier_length);
|
|
1444
1461
|
|
|
1445
1462
|
switch (localOptions.pkce.code_challange_method) {
|
|
1446
|
-
case 'S256':
|
|
1463
|
+
case 'S256': {
|
|
1447
1464
|
const codeChallenge = sjcl.hash.sha256.hash(codeVerifier);
|
|
1448
1465
|
Object.assign(params, {
|
|
1449
1466
|
code_verifier: codeVerifier,
|
|
@@ -1451,6 +1468,7 @@ class AccountsSDK {
|
|
|
1451
1468
|
code_challenge_method: localOptions.pkce.code_challange_method,
|
|
1452
1469
|
});
|
|
1453
1470
|
break;
|
|
1471
|
+
}
|
|
1454
1472
|
|
|
1455
1473
|
default:
|
|
1456
1474
|
Object.assign(params, {
|
|
@@ -1466,13 +1484,13 @@ class AccountsSDK {
|
|
|
1466
1484
|
|
|
1467
1485
|
delete params.code_verifier;
|
|
1468
1486
|
|
|
1469
|
-
return url + '?' +
|
|
1487
|
+
return url + '?' + qs.stringify(params);
|
|
1470
1488
|
}
|
|
1471
1489
|
|
|
1472
1490
|
/**
|
|
1473
1491
|
* This function verifies if redirect transaction params are valid.
|
|
1474
|
-
* @param {
|
|
1475
|
-
* @
|
|
1492
|
+
* @param {object} authorizeData authorize data to validate and return transaction state - redirect state, pkce code verifier
|
|
1493
|
+
* @returns {object | null} transaction state if valid, null otherwise
|
|
1476
1494
|
*/
|
|
1477
1495
|
verify(authorizeData) {
|
|
1478
1496
|
const transactionData = this.transaction.get(authorizeData.state);
|
|
@@ -1487,5 +1505,5 @@ class AccountsSDK {
|
|
|
1487
1505
|
}
|
|
1488
1506
|
}
|
|
1489
1507
|
|
|
1490
|
-
exports
|
|
1508
|
+
exports.default = AccountsSDK;
|
|
1491
1509
|
//# sourceMappingURL=index.cjs.js.map
|