@authsignal/browser 0.0.15 → 0.0.17

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/cjs/index.js CHANGED
@@ -2,48 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise */
20
-
21
- var extendStatics = function(d, b) {
22
- extendStatics = Object.setPrototypeOf ||
23
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
25
- return extendStatics(d, b);
26
- };
27
-
28
- function __extends(d, b) {
29
- if (typeof b !== "function" && b !== null)
30
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
31
- extendStatics(d, b);
32
- function __() { this.constructor = d; }
33
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
- }
35
-
36
5
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
37
6
  // require the crypto API and do not support built-in fallback to lower quality random number
38
7
  // generators (like Math.random()).
39
- var getRandomValues;
40
- var rnds8 = new Uint8Array(16);
8
+ let getRandomValues;
9
+ const rnds8 = new Uint8Array(16);
41
10
  function rng() {
42
11
  // lazy load so that environments that need to polyfill have a chance to do so
43
12
  if (!getRandomValues) {
44
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
45
- // find the complete implementation of crypto (msCrypto) on IE11.
46
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
13
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
14
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
47
15
 
48
16
  if (!getRandomValues) {
49
17
  throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
@@ -64,27 +32,16 @@ function validate(uuid) {
64
32
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
65
33
  */
66
34
 
67
- var byteToHex = [];
35
+ const byteToHex = [];
68
36
 
69
- for (var i = 0; i < 256; ++i) {
70
- byteToHex.push((i + 0x100).toString(16).substr(1));
37
+ for (let i = 0; i < 256; ++i) {
38
+ byteToHex.push((i + 0x100).toString(16).slice(1));
71
39
  }
72
40
 
73
- function stringify(arr) {
74
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
41
+ function unsafeStringify(arr, offset = 0) {
75
42
  // Note: Be careful editing this code! It's been tuned for performance
76
43
  // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
77
- var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
78
- // of the following:
79
- // - One or more input array values don't map to a hex octet (leading to
80
- // "undefined" in the uuid)
81
- // - Invalid input values for the RFC `version` or `variant` fields
82
-
83
- if (!validate(uuid)) {
84
- throw TypeError('Stringified UUID is invalid');
85
- }
86
-
87
- return uuid;
44
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
88
45
  }
89
46
 
90
47
  function parse(uuid) {
@@ -92,8 +49,8 @@ function parse(uuid) {
92
49
  throw TypeError('Invalid UUID');
93
50
  }
94
51
 
95
- var v;
96
- var arr = new Uint8Array(16); // Parse ########-....-....-....-............
52
+ let v;
53
+ const arr = new Uint8Array(16); // Parse ########-....-....-....-............
97
54
 
98
55
  arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
99
56
  arr[1] = v >>> 16 & 0xff;
@@ -122,19 +79,21 @@ function parse(uuid) {
122
79
  function stringToBytes(str) {
123
80
  str = unescape(encodeURIComponent(str)); // UTF8 escape
124
81
 
125
- var bytes = [];
82
+ const bytes = [];
126
83
 
127
- for (var i = 0; i < str.length; ++i) {
84
+ for (let i = 0; i < str.length; ++i) {
128
85
  bytes.push(str.charCodeAt(i));
129
86
  }
130
87
 
131
88
  return bytes;
132
89
  }
133
90
 
134
- var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
135
- var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
136
- function v35 (name, version, hashfunc) {
91
+ const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
92
+ const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
93
+ function v35(name, version, hashfunc) {
137
94
  function generateUUID(value, namespace, buf, offset) {
95
+ var _namespace;
96
+
138
97
  if (typeof value === 'string') {
139
98
  value = stringToBytes(value);
140
99
  }
@@ -143,14 +102,14 @@ function v35 (name, version, hashfunc) {
143
102
  namespace = parse(namespace);
144
103
  }
145
104
 
146
- if (namespace.length !== 16) {
105
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
147
106
  throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
148
107
  } // Compute hash of namespace and value, Per 4.3
149
108
  // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
150
109
  // hashfunc([...namespace, ... value])`
151
110
 
152
111
 
153
- var bytes = new Uint8Array(16 + value.length);
112
+ let bytes = new Uint8Array(16 + value.length);
154
113
  bytes.set(namespace);
155
114
  bytes.set(value, namespace.length);
156
115
  bytes = hashfunc(bytes);
@@ -160,14 +119,14 @@ function v35 (name, version, hashfunc) {
160
119
  if (buf) {
161
120
  offset = offset || 0;
162
121
 
163
- for (var i = 0; i < 16; ++i) {
122
+ for (let i = 0; i < 16; ++i) {
164
123
  buf[offset + i] = bytes[i];
165
124
  }
166
125
 
167
126
  return buf;
168
127
  }
169
128
 
170
- return stringify(bytes);
129
+ return unsafeStringify(bytes);
171
130
  } // Function#name is not settable on some platforms (#270)
172
131
 
173
132
 
@@ -203,11 +162,11 @@ function v35 (name, version, hashfunc) {
203
162
  */
204
163
  function md5(bytes) {
205
164
  if (typeof bytes === 'string') {
206
- var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
165
+ const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
207
166
 
208
167
  bytes = new Uint8Array(msg.length);
209
168
 
210
- for (var i = 0; i < msg.length; ++i) {
169
+ for (let i = 0; i < msg.length; ++i) {
211
170
  bytes[i] = msg.charCodeAt(i);
212
171
  }
213
172
  }
@@ -220,13 +179,13 @@ function md5(bytes) {
220
179
 
221
180
 
222
181
  function md5ToHexEncodedArray(input) {
223
- var output = [];
224
- var length32 = input.length * 32;
225
- var hexTab = '0123456789abcdef';
182
+ const output = [];
183
+ const length32 = input.length * 32;
184
+ const hexTab = '0123456789abcdef';
226
185
 
227
- for (var i = 0; i < length32; i += 8) {
228
- var x = input[i >> 5] >>> i % 32 & 0xff;
229
- var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
186
+ for (let i = 0; i < length32; i += 8) {
187
+ const x = input[i >> 5] >>> i % 32 & 0xff;
188
+ const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
230
189
  output.push(hex);
231
190
  }
232
191
 
@@ -249,16 +208,16 @@ function wordsToMd5(x, len) {
249
208
  /* append padding */
250
209
  x[len >> 5] |= 0x80 << len % 32;
251
210
  x[getOutputLength(len) - 1] = len;
252
- var a = 1732584193;
253
- var b = -271733879;
254
- var c = -1732584194;
255
- var d = 271733878;
256
-
257
- for (var i = 0; i < x.length; i += 16) {
258
- var olda = a;
259
- var oldb = b;
260
- var oldc = c;
261
- var oldd = d;
211
+ let a = 1732584193;
212
+ let b = -271733879;
213
+ let c = -1732584194;
214
+ let d = 271733878;
215
+
216
+ for (let i = 0; i < x.length; i += 16) {
217
+ const olda = a;
218
+ const oldb = b;
219
+ const oldc = c;
220
+ const oldd = d;
262
221
  a = md5ff(a, b, c, d, x[i], 7, -680876936);
263
222
  d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
264
223
  c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
@@ -342,10 +301,10 @@ function bytesToWords(input) {
342
301
  return [];
343
302
  }
344
303
 
345
- var length8 = input.length * 8;
346
- var output = new Uint32Array(getOutputLength(length8));
304
+ const length8 = input.length * 8;
305
+ const output = new Uint32Array(getOutputLength(length8));
347
306
 
348
- for (var i = 0; i < length8; i += 8) {
307
+ for (let i = 0; i < length8; i += 8) {
349
308
  output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
350
309
  }
351
310
 
@@ -358,8 +317,8 @@ function bytesToWords(input) {
358
317
 
359
318
 
360
319
  function safeAdd(x, y) {
361
- var lsw = (x & 0xffff) + (y & 0xffff);
362
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
320
+ const lsw = (x & 0xffff) + (y & 0xffff);
321
+ const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
363
322
  return msw << 16 | lsw & 0xffff;
364
323
  }
365
324
  /*
@@ -397,9 +356,18 @@ function md5ii(a, b, c, d, x, s, t) {
397
356
 
398
357
  v35('v3', 0x30, md5);
399
358
 
359
+ const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
360
+ var native = {
361
+ randomUUID
362
+ };
363
+
400
364
  function v4(options, buf, offset) {
365
+ if (native.randomUUID && !buf && !options) {
366
+ return native.randomUUID();
367
+ }
368
+
401
369
  options = options || {};
402
- var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
370
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
403
371
 
404
372
  rnds[6] = rnds[6] & 0x0f | 0x40;
405
373
  rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
@@ -407,14 +375,14 @@ function v4(options, buf, offset) {
407
375
  if (buf) {
408
376
  offset = offset || 0;
409
377
 
410
- for (var i = 0; i < 16; ++i) {
378
+ for (let i = 0; i < 16; ++i) {
411
379
  buf[offset + i] = rnds[i];
412
380
  }
413
381
 
414
382
  return buf;
415
383
  }
416
384
 
417
- return stringify(rnds);
385
+ return unsafeStringify(rnds);
418
386
  }
419
387
 
420
388
  // Adapted from Chris Veness' SHA1 code at
@@ -440,15 +408,15 @@ function ROTL(x, n) {
440
408
  }
441
409
 
442
410
  function sha1(bytes) {
443
- var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
444
- var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
411
+ const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
412
+ const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
445
413
 
446
414
  if (typeof bytes === 'string') {
447
- var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
415
+ const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
448
416
 
449
417
  bytes = [];
450
418
 
451
- for (var i = 0; i < msg.length; ++i) {
419
+ for (let i = 0; i < msg.length; ++i) {
452
420
  bytes.push(msg.charCodeAt(i));
453
421
  }
454
422
  } else if (!Array.isArray(bytes)) {
@@ -457,44 +425,44 @@ function sha1(bytes) {
457
425
  }
458
426
 
459
427
  bytes.push(0x80);
460
- var l = bytes.length / 4 + 2;
461
- var N = Math.ceil(l / 16);
462
- var M = new Array(N);
428
+ const l = bytes.length / 4 + 2;
429
+ const N = Math.ceil(l / 16);
430
+ const M = new Array(N);
463
431
 
464
- for (var _i = 0; _i < N; ++_i) {
465
- var arr = new Uint32Array(16);
432
+ for (let i = 0; i < N; ++i) {
433
+ const arr = new Uint32Array(16);
466
434
 
467
- for (var j = 0; j < 16; ++j) {
468
- arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3];
435
+ for (let j = 0; j < 16; ++j) {
436
+ arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
469
437
  }
470
438
 
471
- M[_i] = arr;
439
+ M[i] = arr;
472
440
  }
473
441
 
474
442
  M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
475
443
  M[N - 1][14] = Math.floor(M[N - 1][14]);
476
444
  M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
477
445
 
478
- for (var _i2 = 0; _i2 < N; ++_i2) {
479
- var W = new Uint32Array(80);
446
+ for (let i = 0; i < N; ++i) {
447
+ const W = new Uint32Array(80);
480
448
 
481
- for (var t = 0; t < 16; ++t) {
482
- W[t] = M[_i2][t];
449
+ for (let t = 0; t < 16; ++t) {
450
+ W[t] = M[i][t];
483
451
  }
484
452
 
485
- for (var _t = 16; _t < 80; ++_t) {
486
- W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
453
+ for (let t = 16; t < 80; ++t) {
454
+ W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
487
455
  }
488
456
 
489
- var a = H[0];
490
- var b = H[1];
491
- var c = H[2];
492
- var d = H[3];
493
- var e = H[4];
457
+ let a = H[0];
458
+ let b = H[1];
459
+ let c = H[2];
460
+ let d = H[3];
461
+ let e = H[4];
494
462
 
495
- for (var _t2 = 0; _t2 < 80; ++_t2) {
496
- var s = Math.floor(_t2 / 20);
497
- var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
463
+ for (let t = 0; t < 80; ++t) {
464
+ const s = Math.floor(t / 20);
465
+ const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
498
466
  e = d;
499
467
  d = c;
500
468
  c = ROTL(b, 30) >>> 0;
@@ -556,8 +524,8 @@ var focusableSelectors = [
556
524
  '[tabindex]:not([tabindex^="-"])',
557
525
  ];
558
526
 
559
- var TAB_KEY = 9;
560
- var ESCAPE_KEY = 27;
527
+ var TAB_KEY = 'Tab';
528
+ var ESCAPE_KEY = 'Escape';
561
529
 
562
530
  /**
563
531
  * Define the constructor to instantiate a dialog
@@ -609,9 +577,22 @@ A11yDialog.prototype.create = function () {
609
577
 
610
578
  // Keep a collection of dialog closers, each of which will be bound a click
611
579
  // event listener to close the dialog
612
- this._closers = $$('[data-a11y-dialog-hide]', this.$el).concat(
613
- $$('[data-a11y-dialog-hide="' + this._id + '"]')
614
- );
580
+ const $el = this.$el;
581
+
582
+ this._closers = $$('[data-a11y-dialog-hide]', this.$el)
583
+ // This filter is necessary in case there are nested dialogs, so that
584
+ // only closers from the current dialog are retrieved and effective
585
+ .filter(function (closer) {
586
+ // Testing for `[aria-modal="true"]` is not enough since this attribute
587
+ // and the collect of closers is done at instantation time, when nested
588
+ // dialogs might not have yet been instantiated. Note that if the dialogs
589
+ // are manually instantiated, this could still fail because none of these
590
+ // selectors would match; this would cause closers to close all parent
591
+ // dialogs instead of just the current one
592
+ return closer.closest('[aria-modal="true"], [data-a11y-dialog]') === $el
593
+ })
594
+ .concat($$('[data-a11y-dialog-hide="' + this._id + '"]'));
595
+
615
596
  this._closers.forEach(
616
597
  function (closer) {
617
598
  closer.addEventListener('click', this._hide);
@@ -792,14 +773,15 @@ A11yDialog.prototype._fire = function (type, event) {
792
773
  A11yDialog.prototype._bindKeypress = function (event) {
793
774
  // This is an escape hatch in case there are nested dialogs, so the keypresses
794
775
  // are only reacted to for the most recent one
795
- if (!this.$el.contains(document.activeElement)) return
776
+ const focused = document.activeElement;
777
+ if (focused && focused.closest('[aria-modal="true"]') !== this.$el) return
796
778
 
797
779
  // If the dialog is shown and the ESCAPE key is being pressed, prevent any
798
780
  // further effects from the ESCAPE key and hide the dialog, unless its role
799
781
  // is 'alertdialog', which should be modal
800
782
  if (
801
783
  this.shown &&
802
- event.which === ESCAPE_KEY &&
784
+ event.key === ESCAPE_KEY &&
803
785
  this.$el.getAttribute('role') !== 'alertdialog'
804
786
  ) {
805
787
  event.preventDefault();
@@ -808,7 +790,7 @@ A11yDialog.prototype._bindKeypress = function (event) {
808
790
 
809
791
  // If the dialog is shown and the TAB key is being pressed, make sure the
810
792
  // focus stays trapped within the dialog element
811
- if (this.shown && event.which === TAB_KEY) {
793
+ if (this.shown && event.key === TAB_KEY) {
812
794
  trapTabKey(this.$el, event);
813
795
  }
814
796
  };
@@ -935,16 +917,32 @@ var CONTAINER_ID = "__authsignal-popup-container";
935
917
  var CONTENT_ID = "__authsignal-popup-content";
936
918
  var OVERLAY_ID = "__authsignal-popup-overlay";
937
919
  var STYLE_ID = "__authsignal-popup-style";
920
+ var DEFAULT_WIDTH = "576px";
921
+ var DEFAULT_HEIGHT = "600px";
938
922
  var PopupHandler = /** @class */ (function () {
939
- function PopupHandler() {
923
+ function PopupHandler(_a) {
924
+ var width = _a.width, height = _a.height;
940
925
  this.popup = null;
941
926
  if (document.querySelector("#".concat(CONTAINER_ID))) {
942
927
  throw new Error("Multiple instances of Authsignal popup is not supported.");
943
928
  }
944
- this.create();
929
+ this.create({ width: width, height: height });
945
930
  }
946
- PopupHandler.prototype.create = function () {
931
+ PopupHandler.prototype.create = function (_a) {
947
932
  var _this = this;
933
+ var _b = _a.width, width = _b === void 0 ? DEFAULT_WIDTH : _b, _c = _a.height, height = _c === void 0 ? DEFAULT_HEIGHT : _c;
934
+ var isWidthValidCSSValue = CSS.supports("width", width);
935
+ var isHeightValidCSSValue = CSS.supports("height", height);
936
+ var popupWidth = width;
937
+ var popupHeight = height;
938
+ if (!isWidthValidCSSValue) {
939
+ console.warn("Invalid CSS value for `popupOptions.width`. Using default value instead.");
940
+ popupWidth = DEFAULT_WIDTH;
941
+ }
942
+ if (!isHeightValidCSSValue) {
943
+ console.warn("Invalid CSS value for `popupOptions.height`. Using default value instead.");
944
+ popupHeight = DEFAULT_HEIGHT;
945
+ }
948
946
  // Create dialog container
949
947
  var container = document.createElement("div");
950
948
  container.setAttribute("id", CONTAINER_ID);
@@ -960,7 +958,7 @@ var PopupHandler = /** @class */ (function () {
960
958
  // Create CSS for dialog
961
959
  var style = document.createElement("style");
962
960
  style.setAttribute("id", STYLE_ID);
963
- style.textContent = "\n #".concat(CONTAINER_ID, ",\n #").concat(OVERLAY_ID, " {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(CONTAINER_ID, " {\n z-index: 2147483647;\n display: flex;\n }\n\n #").concat(CONTAINER_ID, "[aria-hidden='true'] {\n display: none;\n }\n\n #").concat(OVERLAY_ID, " {\n background-color: rgba(43, 46, 56, 0.9);\n }\n\n #").concat(CONTENT_ID, " {\n margin: auto;\n z-index: 2147483647;\n position: relative;\n background-color: white;\n height: 600px;\n width: 576px;\n border-radius: 8px;\n }\n\n #").concat(CONTENT_ID, " iframe {\n width: 100%;\n height: 100%;\n }\n ");
961
+ style.textContent = "\n #".concat(CONTAINER_ID, ",\n #").concat(OVERLAY_ID, " {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(CONTAINER_ID, " {\n z-index: 2147483647;\n display: flex;\n }\n\n #").concat(CONTAINER_ID, "[aria-hidden='true'] {\n display: none;\n }\n\n #").concat(OVERLAY_ID, " {\n background-color: rgba(43, 46, 56, 0.9);\n }\n\n #").concat(CONTENT_ID, " {\n margin: auto;\n z-index: 2147483647;\n position: relative;\n background-color: white;\n height: ").concat(popupHeight, ";\n width: ").concat(popupWidth, ";\n border-radius: 8px;\n }\n\n #").concat(CONTENT_ID, " iframe {\n width: 100%;\n height: 100%;\n border-radius: inherit;\n }\n ");
964
962
  // Attach the created elements
965
963
  document.head.insertAdjacentElement("beforeend", style);
966
964
  container.appendChild(overlay);
@@ -1019,6 +1017,7 @@ var Authsignal = /** @class */ (function () {
1019
1017
  this.cookieDomain = "";
1020
1018
  this.anonymousIdCookieName = "";
1021
1019
  this.publishableKey = "";
1020
+ this._token = undefined;
1022
1021
  this.publishableKey = publishableKey;
1023
1022
  this.cookieDomain = cookieDomain || getCookieDomain();
1024
1023
  this.anonymousIdCookieName = cookieName || DEFAULT_COOKIE_NAME;
@@ -1037,37 +1036,32 @@ var Authsignal = /** @class */ (function () {
1037
1036
  });
1038
1037
  }
1039
1038
  }
1040
- Authsignal.prototype.mfa = function (_a) {
1041
- var mode = _a.mode, url = _a.url;
1042
- if (mode === "popup") {
1043
- return this.launch(url, { mode: mode });
1044
- }
1045
- return this.launch(url, { mode: mode });
1046
- };
1047
- Authsignal.prototype.challenge = function (_a) {
1048
- var mode = _a.mode, url = _a.challengeUrl;
1049
- if (mode === "popup") {
1050
- return this.launch(url, { mode: mode });
1051
- }
1052
- return this.launch(url, { mode: mode });
1053
- };
1054
1039
  Authsignal.prototype.launch = function (url, options) {
1055
- var mode = (options === null || options === void 0 ? void 0 : options.mode) || "redirect";
1056
- if (mode === "redirect") {
1040
+ var _this = this;
1041
+ if (!(options === null || options === void 0 ? void 0 : options.mode) || options.mode === "redirect") {
1057
1042
  window.location.href = url;
1058
1043
  }
1059
1044
  else {
1045
+ var popupOptions = options.popupOptions;
1046
+ var Popup_1 = new PopupHandler({ width: popupOptions === null || popupOptions === void 0 ? void 0 : popupOptions.width, height: popupOptions === null || popupOptions === void 0 ? void 0 : popupOptions.height });
1060
1047
  var popupUrl = "".concat(url, "&mode=popup");
1061
- var Popup_1 = new PopupHandler();
1062
1048
  Popup_1.show({ url: popupUrl });
1063
1049
  return new Promise(function (resolve) {
1064
1050
  var onMessage = function (event) {
1065
- if (event.data === exports.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP) {
1051
+ var data = null;
1052
+ try {
1053
+ data = JSON.parse(event.data);
1054
+ }
1055
+ catch (_a) {
1056
+ // Ignore if the event data is not valid JSON
1057
+ }
1058
+ if ((data === null || data === void 0 ? void 0 : data.event) === exports.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP) {
1059
+ _this._token = data.token;
1066
1060
  Popup_1.close();
1067
1061
  }
1068
1062
  };
1069
1063
  Popup_1.on("hide", function () {
1070
- resolve(true);
1064
+ resolve({ token: _this._token });
1071
1065
  });
1072
1066
  window.addEventListener("message", onMessage, false);
1073
1067
  });
@@ -1075,17 +1069,6 @@ var Authsignal = /** @class */ (function () {
1075
1069
  };
1076
1070
  return Authsignal;
1077
1071
  }());
1078
- /**
1079
- * @deprecated Use Authsignal
1080
- */
1081
- var AuthsignalBrowser = /** @class */ (function (_super) {
1082
- __extends(AuthsignalBrowser, _super);
1083
- function AuthsignalBrowser() {
1084
- return _super !== null && _super.apply(this, arguments) || this;
1085
- }
1086
- return AuthsignalBrowser;
1087
- }(Authsignal));
1088
1072
 
1089
1073
  exports.Authsignal = Authsignal;
1090
- exports.AuthsignalBrowser = AuthsignalBrowser;
1091
1074
  //# sourceMappingURL=index.js.map