@authsignal/browser 0.6.0 → 0.6.2

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.
@@ -1,18 +1,18 @@
1
- import { ApiClientOptions, ChallengeResponse, EnrollResponse, VerifyResponse } from "./types/shared";
1
+ import { ApiClientOptions, AuthsignalResponse, ChallengeResponse, EnrollResponse, VerifyResponse } from "./types/shared";
2
2
  export declare class EmailApiClient {
3
3
  tenantId: string;
4
4
  baseUrl: string;
5
- constructor({ baseUrl, tenantId }: ApiClientOptions);
5
+ onTokenExpired?: () => void;
6
+ constructor({ baseUrl, tenantId, onTokenExpired }: ApiClientOptions);
6
7
  enroll({ token, email }: {
7
8
  token: string;
8
9
  email: string;
9
- }): Promise<EnrollResponse>;
10
+ }): Promise<AuthsignalResponse<EnrollResponse>>;
10
11
  challenge({ token }: {
11
12
  token: string;
12
- }): Promise<ChallengeResponse>;
13
+ }): Promise<AuthsignalResponse<ChallengeResponse>>;
13
14
  verify({ token, code }: {
14
15
  token: string;
15
16
  code: string;
16
- }): Promise<VerifyResponse>;
17
- private buildHeaders;
17
+ }): Promise<AuthsignalResponse<VerifyResponse>>;
18
18
  }
@@ -1,3 +1,4 @@
1
+ import { AuthsignalResponse } from "./types/shared";
1
2
  type BuildHeadersParams = {
2
3
  token?: string;
3
4
  tenantId: string;
@@ -6,4 +7,9 @@ export declare function buildHeaders({ token, tenantId }: BuildHeadersParams): {
6
7
  "Content-Type": string;
7
8
  Authorization: string;
8
9
  };
10
+ type HandleTokenExpiredParams<T> = {
11
+ response: AuthsignalResponse<T>;
12
+ onTokenExpired?: () => void;
13
+ };
14
+ export declare function handleTokenExpired<T extends object>({ response, onTokenExpired }: HandleTokenExpiredParams<T>): void;
9
15
  export {};
@@ -3,17 +3,18 @@ import { ApiClientOptions, AuthsignalResponse, ChallengeResponse } from "./types
3
3
  export declare class PasskeyApiClient {
4
4
  tenantId: string;
5
5
  baseUrl: string;
6
- constructor({ baseUrl, tenantId }: ApiClientOptions);
7
- registrationOptions({ token, username, authenticatorAttachment, }: {
6
+ onTokenExpired?: () => void;
7
+ constructor({ baseUrl, tenantId, onTokenExpired }: ApiClientOptions);
8
+ registrationOptions({ token, username, authenticatorAttachment }: {
8
9
  token: string;
9
10
  } & RegistrationOptsRequest): Promise<AuthsignalResponse<RegistrationOptsResponse>>;
10
- authenticationOptions({ token, challengeId, }: {
11
+ authenticationOptions({ token, challengeId }: {
11
12
  token?: string;
12
13
  } & AuthenticationOptsRequest): Promise<AuthsignalResponse<AuthenticationOptsResponse>>;
13
- addAuthenticator({ token, challengeId, registrationCredential, }: {
14
+ addAuthenticator({ token, challengeId, registrationCredential }: {
14
15
  token: string;
15
16
  } & AddAuthenticatorRequest): Promise<AuthsignalResponse<AddAuthenticatorResponse>>;
16
- verify({ token, challengeId, authenticationCredential, deviceId, }: {
17
+ verify({ token, challengeId, authenticationCredential, deviceId }: {
17
18
  token?: string;
18
19
  } & VerifyRequest): Promise<AuthsignalResponse<VerifyResponse>>;
19
20
  getPasskeyAuthenticator({ credentialIds, }: {
@@ -1,17 +1,18 @@
1
- import { ApiClientOptions, ChallengeResponse, EnrollResponse, VerifyResponse } from "./types/shared";
1
+ import { ApiClientOptions, AuthsignalResponse, ChallengeResponse, EnrollResponse, VerifyResponse } from "./types/shared";
2
2
  export declare class SmsApiClient {
3
3
  tenantId: string;
4
4
  baseUrl: string;
5
- constructor({ baseUrl, tenantId }: ApiClientOptions);
5
+ onTokenExpired?: () => void;
6
+ constructor({ baseUrl, tenantId, onTokenExpired }: ApiClientOptions);
6
7
  enroll({ token, phoneNumber }: {
7
8
  token: string;
8
9
  phoneNumber: string;
9
- }): Promise<EnrollResponse>;
10
+ }): Promise<AuthsignalResponse<EnrollResponse>>;
10
11
  challenge({ token }: {
11
12
  token: string;
12
- }): Promise<ChallengeResponse>;
13
+ }): Promise<AuthsignalResponse<ChallengeResponse>>;
13
14
  verify({ token, code }: {
14
15
  token: string;
15
16
  code: string;
16
- }): Promise<VerifyResponse>;
17
+ }): Promise<AuthsignalResponse<VerifyResponse>>;
17
18
  }
@@ -1,14 +1,15 @@
1
- import { ApiClientOptions, VerifyResponse } from "./types/shared";
1
+ import { ApiClientOptions, AuthsignalResponse, VerifyResponse } from "./types/shared";
2
2
  import { EnrollResponse } from "./types/totp";
3
3
  export declare class TotpApiClient {
4
4
  tenantId: string;
5
5
  baseUrl: string;
6
- constructor({ baseUrl, tenantId }: ApiClientOptions);
6
+ onTokenExpired?: () => void;
7
+ constructor({ baseUrl, tenantId, onTokenExpired }: ApiClientOptions);
7
8
  enroll({ token }: {
8
9
  token: string;
9
- }): Promise<EnrollResponse>;
10
+ }): Promise<AuthsignalResponse<EnrollResponse>>;
10
11
  verify({ token, code }: {
11
12
  token: string;
12
13
  code: string;
13
- }): Promise<VerifyResponse>;
14
+ }): Promise<AuthsignalResponse<VerifyResponse>>;
14
15
  }
@@ -1,6 +1,7 @@
1
1
  export type ApiClientOptions = {
2
2
  baseUrl: string;
3
3
  tenantId: string;
4
+ onTokenExpired?: () => void;
4
5
  };
5
6
  export type EnrollResponse = {
6
7
  userAuthenticatorId: string;
@@ -16,6 +17,7 @@ export type VerifyResponse = {
16
17
  };
17
18
  export type ErrorResponse = {
18
19
  error: string;
20
+ errorCode?: "expired_token" | (string & {});
19
21
  errorDescription?: string;
20
22
  };
21
23
  export type AuthsignalResponse<T> = T | ErrorResponse;
@@ -12,7 +12,7 @@ export declare class Authsignal {
12
12
  totp: Totp;
13
13
  email: Email;
14
14
  sms: Sms;
15
- constructor({ cookieDomain, cookieName, baseUrl, tenantId, }: AuthsignalOptions);
15
+ constructor({ cookieDomain, cookieName, baseUrl, tenantId, onTokenExpired, }: AuthsignalOptions);
16
16
  setToken(token: string): void;
17
17
  launch(url: string, options?: {
18
18
  mode?: "redirect";
package/dist/email.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { AuthsignalResponse, ChallengeResponse, EnrollResponse, VerifyResponse } from "./api/types/shared";
2
1
  type EmailOptions = {
3
2
  baseUrl: string;
4
3
  tenantId: string;
4
+ onTokenExpired?: () => void;
5
5
  };
6
6
  type EnrollParams = {
7
7
  email: string;
@@ -12,9 +12,9 @@ type VerifyParams = {
12
12
  export declare class Email {
13
13
  private api;
14
14
  private cache;
15
- constructor({ baseUrl, tenantId }: EmailOptions);
16
- enroll({ email }: EnrollParams): Promise<AuthsignalResponse<EnrollResponse>>;
17
- challenge(): Promise<AuthsignalResponse<ChallengeResponse>>;
18
- verify({ code }: VerifyParams): Promise<AuthsignalResponse<VerifyResponse>>;
15
+ constructor({ baseUrl, tenantId, onTokenExpired }: EmailOptions);
16
+ enroll({ email }: EnrollParams): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").EnrollResponse>>;
17
+ challenge(): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").ChallengeResponse>>;
18
+ verify({ code }: VerifyParams): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").VerifyResponse>>;
19
19
  }
20
20
  export {};
package/dist/index.js CHANGED
@@ -542,16 +542,23 @@ function buildHeaders(_a) {
542
542
  Authorization: authorizationHeader,
543
543
  };
544
544
  }
545
+ function handleTokenExpired(_a) {
546
+ var response = _a.response, onTokenExpired = _a.onTokenExpired;
547
+ if ("error" in response && response.errorCode === "expired_token" && onTokenExpired) {
548
+ onTokenExpired();
549
+ }
550
+ }
545
551
 
546
552
  var PasskeyApiClient = /** @class */ (function () {
547
553
  function PasskeyApiClient(_a) {
548
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
554
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
549
555
  this.tenantId = tenantId;
550
556
  this.baseUrl = baseUrl;
557
+ this.onTokenExpired = onTokenExpired;
551
558
  }
552
559
  PasskeyApiClient.prototype.registrationOptions = function (_a) {
553
560
  return __awaiter(this, arguments, void 0, function (_b) {
554
- var body, response;
561
+ var body, response, responseJson;
555
562
  var token = _b.token, username = _b.username, authenticatorAttachment = _b.authenticatorAttachment;
556
563
  return __generator(this, function (_c) {
557
564
  switch (_c.label) {
@@ -559,39 +566,49 @@ var PasskeyApiClient = /** @class */ (function () {
559
566
  body = Boolean(authenticatorAttachment)
560
567
  ? { username: username, authenticatorAttachment: authenticatorAttachment }
561
568
  : { username: username };
562
- response = fetch("".concat(this.baseUrl, "/client/user-authenticators/passkey/registration-options"), {
563
- method: "POST",
564
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
565
- body: JSON.stringify(body),
566
- });
567
- return [4 /*yield*/, response];
568
- case 1: return [2 /*return*/, (_c.sent()).json()];
569
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/user-authenticators/passkey/registration-options"), {
570
+ method: "POST",
571
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
572
+ body: JSON.stringify(body),
573
+ })];
574
+ case 1:
575
+ response = _c.sent();
576
+ return [4 /*yield*/, response.json()];
577
+ case 2:
578
+ responseJson = _c.sent();
579
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
580
+ return [2 /*return*/, responseJson];
569
581
  }
570
582
  });
571
583
  });
572
584
  };
573
585
  PasskeyApiClient.prototype.authenticationOptions = function (_a) {
574
586
  return __awaiter(this, arguments, void 0, function (_b) {
575
- var body, response;
587
+ var body, response, responseJson;
576
588
  var token = _b.token, challengeId = _b.challengeId;
577
589
  return __generator(this, function (_c) {
578
590
  switch (_c.label) {
579
591
  case 0:
580
592
  body = { challengeId: challengeId };
581
- response = fetch("".concat(this.baseUrl, "/client/user-authenticators/passkey/authentication-options"), {
582
- method: "POST",
583
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
584
- body: JSON.stringify(body),
585
- });
586
- return [4 /*yield*/, response];
587
- case 1: return [2 /*return*/, (_c.sent()).json()];
593
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/user-authenticators/passkey/authentication-options"), {
594
+ method: "POST",
595
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
596
+ body: JSON.stringify(body),
597
+ })];
598
+ case 1:
599
+ response = _c.sent();
600
+ return [4 /*yield*/, response.json()];
601
+ case 2:
602
+ responseJson = _c.sent();
603
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
604
+ return [2 /*return*/, responseJson];
588
605
  }
589
606
  });
590
607
  });
591
608
  };
592
609
  PasskeyApiClient.prototype.addAuthenticator = function (_a) {
593
610
  return __awaiter(this, arguments, void 0, function (_b) {
594
- var body, response;
611
+ var body, response, responseJson;
595
612
  var token = _b.token, challengeId = _b.challengeId, registrationCredential = _b.registrationCredential;
596
613
  return __generator(this, function (_c) {
597
614
  switch (_c.label) {
@@ -600,32 +617,42 @@ var PasskeyApiClient = /** @class */ (function () {
600
617
  challengeId: challengeId,
601
618
  registrationCredential: registrationCredential,
602
619
  };
603
- response = fetch("".concat(this.baseUrl, "/client/user-authenticators/passkey"), {
604
- method: "POST",
605
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
606
- body: JSON.stringify(body),
607
- });
608
- return [4 /*yield*/, response];
609
- case 1: return [2 /*return*/, (_c.sent()).json()];
620
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/user-authenticators/passkey"), {
621
+ method: "POST",
622
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
623
+ body: JSON.stringify(body),
624
+ })];
625
+ case 1:
626
+ response = _c.sent();
627
+ return [4 /*yield*/, response.json()];
628
+ case 2:
629
+ responseJson = _c.sent();
630
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
631
+ return [2 /*return*/, responseJson];
610
632
  }
611
633
  });
612
634
  });
613
635
  };
614
636
  PasskeyApiClient.prototype.verify = function (_a) {
615
637
  return __awaiter(this, arguments, void 0, function (_b) {
616
- var body, response;
638
+ var body, response, responseJson;
617
639
  var token = _b.token, challengeId = _b.challengeId, authenticationCredential = _b.authenticationCredential, deviceId = _b.deviceId;
618
640
  return __generator(this, function (_c) {
619
641
  switch (_c.label) {
620
642
  case 0:
621
643
  body = { challengeId: challengeId, authenticationCredential: authenticationCredential, deviceId: deviceId };
622
- response = fetch("".concat(this.baseUrl, "/client/verify/passkey"), {
623
- method: "POST",
624
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
625
- body: JSON.stringify(body),
626
- });
627
- return [4 /*yield*/, response];
628
- case 1: return [2 /*return*/, (_c.sent()).json()];
644
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/verify/passkey"), {
645
+ method: "POST",
646
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
647
+ body: JSON.stringify(body),
648
+ })];
649
+ case 1:
650
+ response = _c.sent();
651
+ return [4 /*yield*/, response.json()];
652
+ case 2:
653
+ responseJson = _c.sent();
654
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
655
+ return [2 /*return*/, responseJson];
629
656
  }
630
657
  });
631
658
  });
@@ -652,17 +679,21 @@ var PasskeyApiClient = /** @class */ (function () {
652
679
  };
653
680
  PasskeyApiClient.prototype.challenge = function (action) {
654
681
  return __awaiter(this, void 0, void 0, function () {
655
- var response;
682
+ var response, responseJson;
656
683
  return __generator(this, function (_a) {
657
684
  switch (_a.label) {
658
- case 0:
659
- response = fetch("".concat(this.baseUrl, "/client/challenge"), {
685
+ case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/challenge"), {
660
686
  method: "POST",
661
687
  headers: buildHeaders({ tenantId: this.tenantId }),
662
688
  body: JSON.stringify({ action: action }),
663
- });
664
- return [4 /*yield*/, response];
665
- case 1: return [2 /*return*/, (_a.sent()).json()];
689
+ })];
690
+ case 1:
691
+ response = _a.sent();
692
+ return [4 /*yield*/, response.json()];
693
+ case 2:
694
+ responseJson = _a.sent();
695
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
696
+ return [2 /*return*/, responseJson];
666
697
  }
667
698
  });
668
699
  });
@@ -689,10 +720,10 @@ var TokenCache = /** @class */ (function () {
689
720
 
690
721
  var Passkey = /** @class */ (function () {
691
722
  function Passkey(_a) {
692
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId, anonymousId = _a.anonymousId;
723
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, anonymousId = _a.anonymousId, onTokenExpired = _a.onTokenExpired;
693
724
  this.passkeyLocalStorageKey = "as_user_passkey_map";
694
725
  this.cache = TokenCache.shared;
695
- this.api = new PasskeyApiClient({ baseUrl: baseUrl, tenantId: tenantId });
726
+ this.api = new PasskeyApiClient({ baseUrl: baseUrl, tenantId: tenantId, onTokenExpired: onTokenExpired });
696
727
  this.anonymousId = anonymousId;
697
728
  }
698
729
  Passkey.prototype.signUp = function (_a) {
@@ -749,7 +780,7 @@ var Passkey = /** @class */ (function () {
749
780
  };
750
781
  Passkey.prototype.signIn = function (params) {
751
782
  return __awaiter(this, void 0, void 0, function () {
752
- var challengeResponse, _a, optionsResponse, authenticationResponse, verifyResponse, token, userId, userAuthenticatorId, userName, userDisplayName;
783
+ var challengeResponse, _a, optionsResponse, authenticationResponse, verifyResponse, token, userId, userAuthenticatorId, userName, userDisplayName, isVerified;
753
784
  return __generator(this, function (_b) {
754
785
  switch (_b.label) {
755
786
  case 0:
@@ -807,8 +838,9 @@ var Passkey = /** @class */ (function () {
807
838
  if (verifyResponse.accessToken) {
808
839
  this.cache.token = verifyResponse.accessToken;
809
840
  }
810
- token = verifyResponse.accessToken, userId = verifyResponse.userId, userAuthenticatorId = verifyResponse.userAuthenticatorId, userName = verifyResponse.username, userDisplayName = verifyResponse.userDisplayName;
841
+ token = verifyResponse.accessToken, userId = verifyResponse.userId, userAuthenticatorId = verifyResponse.userAuthenticatorId, userName = verifyResponse.username, userDisplayName = verifyResponse.userDisplayName, isVerified = verifyResponse.isVerified;
811
842
  return [2 /*return*/, {
843
+ isVerified: isVerified,
812
844
  token: token,
813
845
  userId: userId,
814
846
  userAuthenticatorId: userAuthenticatorId,
@@ -1439,42 +1471,52 @@ function resizeIframe(event) {
1439
1471
 
1440
1472
  var TotpApiClient = /** @class */ (function () {
1441
1473
  function TotpApiClient(_a) {
1442
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
1474
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1443
1475
  this.tenantId = tenantId;
1444
1476
  this.baseUrl = baseUrl;
1477
+ this.onTokenExpired = onTokenExpired;
1445
1478
  }
1446
1479
  TotpApiClient.prototype.enroll = function (_a) {
1447
1480
  return __awaiter(this, arguments, void 0, function (_b) {
1448
- var response;
1481
+ var response, responseJson;
1449
1482
  var token = _b.token;
1450
1483
  return __generator(this, function (_c) {
1451
1484
  switch (_c.label) {
1452
- case 0:
1453
- response = fetch("".concat(this.baseUrl, "/client/user-authenticators/totp"), {
1485
+ case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/user-authenticators/totp"), {
1454
1486
  method: "POST",
1455
1487
  headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1456
- });
1457
- return [4 /*yield*/, response];
1458
- case 1: return [2 /*return*/, (_c.sent()).json()];
1488
+ })];
1489
+ case 1:
1490
+ response = _c.sent();
1491
+ return [4 /*yield*/, response.json()];
1492
+ case 2:
1493
+ responseJson = _c.sent();
1494
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1495
+ return [2 /*return*/, responseJson];
1459
1496
  }
1460
1497
  });
1461
1498
  });
1462
1499
  };
1463
1500
  TotpApiClient.prototype.verify = function (_a) {
1464
1501
  return __awaiter(this, arguments, void 0, function (_b) {
1465
- var body, response;
1502
+ var body, response, responseJson;
1466
1503
  var token = _b.token, code = _b.code;
1467
1504
  return __generator(this, function (_c) {
1468
1505
  switch (_c.label) {
1469
1506
  case 0:
1470
1507
  body = { verificationCode: code };
1471
- response = fetch("".concat(this.baseUrl, "/client/verify/totp"), {
1472
- method: "POST",
1473
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1474
- body: JSON.stringify(body),
1475
- });
1476
- return [4 /*yield*/, response];
1477
- case 1: return [2 /*return*/, (_c.sent()).json()];
1508
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/verify/totp"), {
1509
+ method: "POST",
1510
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1511
+ body: JSON.stringify(body),
1512
+ })];
1513
+ case 1:
1514
+ response = _c.sent();
1515
+ return [4 /*yield*/, response.json()];
1516
+ case 2:
1517
+ responseJson = _c.sent();
1518
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1519
+ return [2 /*return*/, responseJson];
1478
1520
  }
1479
1521
  });
1480
1522
  });
@@ -1484,9 +1526,9 @@ var TotpApiClient = /** @class */ (function () {
1484
1526
 
1485
1527
  var Totp = /** @class */ (function () {
1486
1528
  function Totp(_a) {
1487
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
1529
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1488
1530
  this.cache = TokenCache.shared;
1489
- this.api = new TotpApiClient({ baseUrl: baseUrl, tenantId: tenantId });
1531
+ this.api = new TotpApiClient({ baseUrl: baseUrl, tenantId: tenantId, onTokenExpired: onTokenExpired });
1490
1532
  }
1491
1533
  Totp.prototype.enroll = function () {
1492
1534
  return __awaiter(this, void 0, void 0, function () {
@@ -1511,7 +1553,7 @@ var Totp = /** @class */ (function () {
1511
1553
  return [4 /*yield*/, this.api.verify({ token: this.cache.token, code: code })];
1512
1554
  case 1:
1513
1555
  verifyResponse = _c.sent();
1514
- if (verifyResponse.accessToken) {
1556
+ if ("accessToken" in verifyResponse && verifyResponse.accessToken) {
1515
1557
  this.cache.token = verifyResponse.accessToken;
1516
1558
  }
1517
1559
  return [2 /*return*/, verifyResponse];
@@ -1524,80 +1566,88 @@ var Totp = /** @class */ (function () {
1524
1566
 
1525
1567
  var EmailApiClient = /** @class */ (function () {
1526
1568
  function EmailApiClient(_a) {
1527
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
1569
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1528
1570
  this.tenantId = tenantId;
1529
1571
  this.baseUrl = baseUrl;
1572
+ this.onTokenExpired = onTokenExpired;
1530
1573
  }
1531
1574
  EmailApiClient.prototype.enroll = function (_a) {
1532
1575
  return __awaiter(this, arguments, void 0, function (_b) {
1533
- var body, response;
1576
+ var body, response, responseJson;
1534
1577
  var token = _b.token, email = _b.email;
1535
1578
  return __generator(this, function (_c) {
1536
1579
  switch (_c.label) {
1537
1580
  case 0:
1538
1581
  body = { email: email };
1539
- response = fetch("".concat(this.baseUrl, "/client/user-authenticators/email-otp"), {
1540
- method: "POST",
1541
- headers: this.buildHeaders(token),
1542
- body: JSON.stringify(body),
1543
- });
1544
- return [4 /*yield*/, response];
1545
- case 1: return [2 /*return*/, (_c.sent()).json()];
1582
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/user-authenticators/email-otp"), {
1583
+ method: "POST",
1584
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1585
+ body: JSON.stringify(body),
1586
+ })];
1587
+ case 1:
1588
+ response = _c.sent();
1589
+ return [4 /*yield*/, response.json()];
1590
+ case 2:
1591
+ responseJson = _c.sent();
1592
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1593
+ return [2 /*return*/, responseJson];
1546
1594
  }
1547
1595
  });
1548
1596
  });
1549
1597
  };
1550
1598
  EmailApiClient.prototype.challenge = function (_a) {
1551
1599
  return __awaiter(this, arguments, void 0, function (_b) {
1552
- var response;
1600
+ var response, responseJson;
1553
1601
  var token = _b.token;
1554
1602
  return __generator(this, function (_c) {
1555
1603
  switch (_c.label) {
1556
- case 0:
1557
- response = fetch("".concat(this.baseUrl, "/client/challenge/email-otp"), {
1604
+ case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/challenge/email-otp"), {
1558
1605
  method: "POST",
1559
- headers: this.buildHeaders(token),
1560
- });
1561
- return [4 /*yield*/, response];
1562
- case 1: return [2 /*return*/, (_c.sent()).json()];
1606
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1607
+ })];
1608
+ case 1:
1609
+ response = _c.sent();
1610
+ return [4 /*yield*/, response.json()];
1611
+ case 2:
1612
+ responseJson = _c.sent();
1613
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1614
+ return [2 /*return*/, responseJson];
1563
1615
  }
1564
1616
  });
1565
1617
  });
1566
1618
  };
1567
1619
  EmailApiClient.prototype.verify = function (_a) {
1568
1620
  return __awaiter(this, arguments, void 0, function (_b) {
1569
- var body, response;
1621
+ var body, response, responseJson;
1570
1622
  var token = _b.token, code = _b.code;
1571
1623
  return __generator(this, function (_c) {
1572
1624
  switch (_c.label) {
1573
1625
  case 0:
1574
1626
  body = { verificationCode: code };
1575
- response = fetch("".concat(this.baseUrl, "/client/verify/email-otp"), {
1576
- method: "POST",
1577
- headers: this.buildHeaders(token),
1578
- body: JSON.stringify(body),
1579
- });
1580
- return [4 /*yield*/, response];
1581
- case 1: return [2 /*return*/, (_c.sent()).json()];
1627
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/verify/email-otp"), {
1628
+ method: "POST",
1629
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1630
+ body: JSON.stringify(body),
1631
+ })];
1632
+ case 1:
1633
+ response = _c.sent();
1634
+ return [4 /*yield*/, response.json()];
1635
+ case 2:
1636
+ responseJson = _c.sent();
1637
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1638
+ return [2 /*return*/, responseJson];
1582
1639
  }
1583
1640
  });
1584
1641
  });
1585
1642
  };
1586
- EmailApiClient.prototype.buildHeaders = function (token) {
1587
- var authorizationHeader = token ? "Bearer ".concat(token) : "Basic ".concat(window.btoa(encodeURIComponent(this.tenantId)));
1588
- return {
1589
- "Content-Type": "application/json",
1590
- Authorization: authorizationHeader,
1591
- };
1592
- };
1593
1643
  return EmailApiClient;
1594
1644
  }());
1595
1645
 
1596
1646
  var Email = /** @class */ (function () {
1597
1647
  function Email(_a) {
1598
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
1648
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1599
1649
  this.cache = TokenCache.shared;
1600
- this.api = new EmailApiClient({ baseUrl: baseUrl, tenantId: tenantId });
1650
+ this.api = new EmailApiClient({ baseUrl: baseUrl, tenantId: tenantId, onTokenExpired: onTokenExpired });
1601
1651
  }
1602
1652
  Email.prototype.enroll = function (_a) {
1603
1653
  return __awaiter(this, arguments, void 0, function (_b) {
@@ -1633,7 +1683,7 @@ var Email = /** @class */ (function () {
1633
1683
  return [4 /*yield*/, this.api.verify({ token: this.cache.token, code: code })];
1634
1684
  case 1:
1635
1685
  verifyResponse = _c.sent();
1636
- if (verifyResponse.accessToken) {
1686
+ if ("accessToken" in verifyResponse && verifyResponse.accessToken) {
1637
1687
  this.cache.token = verifyResponse.accessToken;
1638
1688
  }
1639
1689
  return [2 /*return*/, verifyResponse];
@@ -1646,61 +1696,76 @@ var Email = /** @class */ (function () {
1646
1696
 
1647
1697
  var SmsApiClient = /** @class */ (function () {
1648
1698
  function SmsApiClient(_a) {
1649
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
1699
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1650
1700
  this.tenantId = tenantId;
1651
1701
  this.baseUrl = baseUrl;
1702
+ this.onTokenExpired = onTokenExpired;
1652
1703
  }
1653
1704
  SmsApiClient.prototype.enroll = function (_a) {
1654
1705
  return __awaiter(this, arguments, void 0, function (_b) {
1655
- var body, response;
1706
+ var body, response, responseJson;
1656
1707
  var token = _b.token, phoneNumber = _b.phoneNumber;
1657
1708
  return __generator(this, function (_c) {
1658
1709
  switch (_c.label) {
1659
1710
  case 0:
1660
1711
  body = { phoneNumber: phoneNumber };
1661
- response = fetch("".concat(this.baseUrl, "/client/user-authenticators/sms"), {
1662
- method: "POST",
1663
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1664
- body: JSON.stringify(body),
1665
- });
1666
- return [4 /*yield*/, response];
1667
- case 1: return [2 /*return*/, (_c.sent()).json()];
1712
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/user-authenticators/sms"), {
1713
+ method: "POST",
1714
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1715
+ body: JSON.stringify(body),
1716
+ })];
1717
+ case 1:
1718
+ response = _c.sent();
1719
+ return [4 /*yield*/, response.json()];
1720
+ case 2:
1721
+ responseJson = _c.sent();
1722
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1723
+ return [2 /*return*/, responseJson];
1668
1724
  }
1669
1725
  });
1670
1726
  });
1671
1727
  };
1672
1728
  SmsApiClient.prototype.challenge = function (_a) {
1673
1729
  return __awaiter(this, arguments, void 0, function (_b) {
1674
- var response;
1730
+ var response, responseJson;
1675
1731
  var token = _b.token;
1676
1732
  return __generator(this, function (_c) {
1677
1733
  switch (_c.label) {
1678
- case 0:
1679
- response = fetch("".concat(this.baseUrl, "/client/challenge/sms"), {
1734
+ case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/challenge/sms"), {
1680
1735
  method: "POST",
1681
1736
  headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1682
- });
1683
- return [4 /*yield*/, response];
1684
- case 1: return [2 /*return*/, (_c.sent()).json()];
1737
+ })];
1738
+ case 1:
1739
+ response = _c.sent();
1740
+ return [4 /*yield*/, response.json()];
1741
+ case 2:
1742
+ responseJson = _c.sent();
1743
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1744
+ return [2 /*return*/, responseJson];
1685
1745
  }
1686
1746
  });
1687
1747
  });
1688
1748
  };
1689
1749
  SmsApiClient.prototype.verify = function (_a) {
1690
1750
  return __awaiter(this, arguments, void 0, function (_b) {
1691
- var body, response;
1751
+ var body, response, responseJson;
1692
1752
  var token = _b.token, code = _b.code;
1693
1753
  return __generator(this, function (_c) {
1694
1754
  switch (_c.label) {
1695
1755
  case 0:
1696
1756
  body = { verificationCode: code };
1697
- response = fetch("".concat(this.baseUrl, "/client/verify/sms"), {
1698
- method: "POST",
1699
- headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1700
- body: JSON.stringify(body),
1701
- });
1702
- return [4 /*yield*/, response];
1703
- case 1: return [2 /*return*/, (_c.sent()).json()];
1757
+ return [4 /*yield*/, fetch("".concat(this.baseUrl, "/client/verify/sms"), {
1758
+ method: "POST",
1759
+ headers: buildHeaders({ token: token, tenantId: this.tenantId }),
1760
+ body: JSON.stringify(body),
1761
+ })];
1762
+ case 1:
1763
+ response = _c.sent();
1764
+ return [4 /*yield*/, response.json()];
1765
+ case 2:
1766
+ responseJson = _c.sent();
1767
+ handleTokenExpired({ response: responseJson, onTokenExpired: this.onTokenExpired });
1768
+ return [2 /*return*/, responseJson];
1704
1769
  }
1705
1770
  });
1706
1771
  });
@@ -1710,9 +1775,9 @@ var SmsApiClient = /** @class */ (function () {
1710
1775
 
1711
1776
  var Sms = /** @class */ (function () {
1712
1777
  function Sms(_a) {
1713
- var baseUrl = _a.baseUrl, tenantId = _a.tenantId;
1778
+ var baseUrl = _a.baseUrl, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1714
1779
  this.cache = TokenCache.shared;
1715
- this.api = new SmsApiClient({ baseUrl: baseUrl, tenantId: tenantId });
1780
+ this.api = new SmsApiClient({ baseUrl: baseUrl, tenantId: tenantId, onTokenExpired: onTokenExpired });
1716
1781
  }
1717
1782
  Sms.prototype.enroll = function (_a) {
1718
1783
  return __awaiter(this, arguments, void 0, function (_b) {
@@ -1748,7 +1813,7 @@ var Sms = /** @class */ (function () {
1748
1813
  return [4 /*yield*/, this.api.verify({ token: this.cache.token, code: code })];
1749
1814
  case 1:
1750
1815
  verifyResponse = _c.sent();
1751
- if (verifyResponse.accessToken) {
1816
+ if ("accessToken" in verifyResponse && verifyResponse.accessToken) {
1752
1817
  this.cache.token = verifyResponse.accessToken;
1753
1818
  }
1754
1819
  return [2 /*return*/, verifyResponse];
@@ -1765,7 +1830,7 @@ var DEFAULT_BASE_URL = "https://api.authsignal.com/v1";
1765
1830
  var TMX_ORG_ID = "4a08uqve";
1766
1831
  var Authsignal = /** @class */ (function () {
1767
1832
  function Authsignal(_a) {
1768
- var cookieDomain = _a.cookieDomain, _b = _a.cookieName, cookieName = _b === void 0 ? DEFAULT_COOKIE_NAME : _b, _c = _a.baseUrl, baseUrl = _c === void 0 ? DEFAULT_BASE_URL : _c, tenantId = _a.tenantId;
1833
+ var cookieDomain = _a.cookieDomain, _b = _a.cookieName, cookieName = _b === void 0 ? DEFAULT_COOKIE_NAME : _b, _c = _a.baseUrl, baseUrl = _c === void 0 ? DEFAULT_BASE_URL : _c, tenantId = _a.tenantId, onTokenExpired = _a.onTokenExpired;
1769
1834
  this.anonymousId = "";
1770
1835
  this.profilingId = "";
1771
1836
  this.cookieDomain = "";
@@ -1789,10 +1854,10 @@ var Authsignal = /** @class */ (function () {
1789
1854
  secure: document.location.protocol !== "http:",
1790
1855
  });
1791
1856
  }
1792
- this.passkey = new Passkey({ tenantId: tenantId, baseUrl: baseUrl, anonymousId: this.anonymousId });
1793
- this.totp = new Totp({ tenantId: tenantId, baseUrl: baseUrl });
1794
- this.email = new Email({ tenantId: tenantId, baseUrl: baseUrl });
1795
- this.sms = new Sms({ tenantId: tenantId, baseUrl: baseUrl });
1857
+ this.passkey = new Passkey({ tenantId: tenantId, baseUrl: baseUrl, anonymousId: this.anonymousId, onTokenExpired: onTokenExpired });
1858
+ this.totp = new Totp({ tenantId: tenantId, baseUrl: baseUrl, onTokenExpired: onTokenExpired });
1859
+ this.email = new Email({ tenantId: tenantId, baseUrl: baseUrl, onTokenExpired: onTokenExpired });
1860
+ this.sms = new Sms({ tenantId: tenantId, baseUrl: baseUrl, onTokenExpired: onTokenExpired });
1796
1861
  }
1797
1862
  Authsignal.prototype.setToken = function (token) {
1798
1863
  TokenCache.shared.token = token;
package/dist/index.min.js CHANGED
@@ -1 +1 @@
1
- var authsignal=function(t){"use strict";let e;const n=new Uint8Array(16);function o(){if(!e&&(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!e))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(n)}const i=[];for(let t=0;t<256;++t)i.push((t+256).toString(16).slice(1));var r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function a(t,e,n){if(r.randomUUID&&!e&&!t)return r.randomUUID();const a=(t=t||{}).random||(t.rng||o)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,e){n=n||0;for(let t=0;t<16;++t)e[n+t]=a[t];return e}return function(t,e=0){return(i[t[e+0]]+i[t[e+1]]+i[t[e+2]]+i[t[e+3]]+"-"+i[t[e+4]]+i[t[e+5]]+"-"+i[t[e+6]]+i[t[e+7]]+"-"+i[t[e+8]]+i[t[e+9]]+"-"+i[t[e+10]]+i[t[e+11]]+i[t[e+12]]+i[t[e+13]]+i[t[e+14]]+i[t[e+15]]).toLowerCase()}(a)}function s(t){var e=t.name,n=t.value,o=t.expire,i=t.domain,r=t.secure,a=o===1/0?" expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+o;document.cookie=encodeURIComponent(e)+"="+n+"; path=/;"+a+(i?"; domain="+i:"")+(r?"; secure":"")}function c(t){var e;console.error(null!==(e=t.errorDescription)&&void 0!==e?e:t.error)}t.AuthsignalWindowMessage=void 0,(t.AuthsignalWindowMessage||(t.AuthsignalWindowMessage={})).AUTHSIGNAL_CLOSE_POPUP="AUTHSIGNAL_CLOSE_POPUP";var u=function(){return u=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},u.apply(this,arguments)};function l(t,e,n,o){return new(n||(n=Promise))((function(i,r){function a(t){try{c(o.next(t))}catch(t){r(t)}}function s(t){try{c(o.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((o=o.apply(t,e||[])).next())}))}function h(t,e){var n,o,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(r){return function(s){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return a.label++,{value:r[1],done:!1};case 5:a.label++,o=r[1],r=[0];continue;case 7:r=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){a=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){a.label=r[1];break}if(6===r[0]&&a.label<i[1]){a.label=i[1],i=r;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(r);break}i[2]&&a.ops.pop(),a.trys.pop();continue}r=e.call(t,a)}catch(t){r=[6,t],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,s])}}}function d(t){const e=new Uint8Array(t);let n="";for(const t of e)n+=String.fromCharCode(t);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function p(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=(4-e.length%4)%4,o=e.padEnd(e.length+n,"="),i=atob(o),r=new ArrayBuffer(i.length),a=new Uint8Array(r);for(let t=0;t<i.length;t++)a[t]=i.charCodeAt(t);return r}function f(){return void 0!==window?.PublicKeyCredential&&"function"==typeof window.PublicKeyCredential}function m(t){const{id:e}=t;return{...t,id:p(e),transports:t.transports}}function y(t){return"localhost"===t||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(t)}class w extends Error{constructor({message:t,code:e,cause:n,name:o}){super(t,{cause:n}),this.name=o??n.name,this.code=e}}const g=new class{createNewAbortSignal(){if(this.controller){const t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}const t=new AbortController;return this.controller=t,t.signal}cancelCeremony(){if(this.controller){const t=new Error("Manually cancelling existing WebAuthn API call");t.name="AbortError",this.controller.abort(t),this.controller=void 0}}},v=["cross-platform","platform"];function b(t){if(t&&!(v.indexOf(t)<0))return t}async function E(t){if(!f())throw new Error("WebAuthn is not supported in this browser");const e={publicKey:{...t,challenge:p(t.challenge),user:{...t.user,id:p(t.user.id)},excludeCredentials:t.excludeCredentials?.map(m)}};let n;e.signal=g.createNewAbortSignal();try{n=await navigator.credentials.create(e)}catch(t){throw function({error:t,options:e}){const{publicKey:n}=e;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===t.name){if(e.signal instanceof AbortSignal)return new w({message:"Registration ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:t})}else if("ConstraintError"===t.name){if(!0===n.authenticatorSelection?.requireResidentKey)return new w({message:"Discoverable credentials were required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",cause:t});if("required"===n.authenticatorSelection?.userVerification)return new w({message:"User verification was required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",cause:t})}else{if("InvalidStateError"===t.name)return new w({message:"The authenticator was previously registered",code:"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",cause:t});if("NotAllowedError"===t.name)return new w({message:t.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:t});if("NotSupportedError"===t.name)return 0===n.pubKeyCredParams.filter((t=>"public-key"===t.type)).length?new w({message:'No entry in pubKeyCredParams was of type "public-key"',code:"ERROR_MALFORMED_PUBKEYCREDPARAMS",cause:t}):new w({message:"No available authenticator supported any of the specified pubKeyCredParams algorithms",code:"ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",cause:t});if("SecurityError"===t.name){const e=window.location.hostname;if(!y(e))return new w({message:`${window.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:t});if(n.rp.id!==e)return new w({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:t})}else if("TypeError"===t.name){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new w({message:"User ID was not between 1 and 64 characters",code:"ERROR_INVALID_USER_ID_LENGTH",cause:t})}else if("UnknownError"===t.name)return new w({message:"The authenticator was unable to process the specified options, or could not create a new credential",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:t})}return t}({error:t,options:e})}if(!n)throw new Error("Registration was not completed");const{id:o,rawId:i,response:r,type:a}=n;let s,c,u,l;if("function"==typeof r.getTransports&&(s=r.getTransports()),"function"==typeof r.getPublicKeyAlgorithm)try{c=r.getPublicKeyAlgorithm()}catch(t){I("getPublicKeyAlgorithm()",t)}if("function"==typeof r.getPublicKey)try{const t=r.getPublicKey();null!==t&&(u=d(t))}catch(t){I("getPublicKey()",t)}if("function"==typeof r.getAuthenticatorData)try{l=d(r.getAuthenticatorData())}catch(t){I("getAuthenticatorData()",t)}return{id:o,rawId:d(i),response:{attestationObject:d(r.attestationObject),clientDataJSON:d(r.clientDataJSON),transports:s,publicKeyAlgorithm:c,publicKey:u,authenticatorData:l},type:a,clientExtensionResults:n.getClientExtensionResults(),authenticatorAttachment:b(n.authenticatorAttachment)}}function I(t,e){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${t}. You should report this error to them.\n`,e)}async function k(t,e=!1){if(!f())throw new Error("WebAuthn is not supported in this browser");let n;0!==t.allowCredentials?.length&&(n=t.allowCredentials?.map(m));const o={...t,challenge:p(t.challenge),allowCredentials:n},i={};if(e){if(!await function(){if(!f())return new Promise((t=>t(!1)));const t=window.PublicKeyCredential;return void 0===t.isConditionalMediationAvailable?new Promise((t=>t(!1))):t.isConditionalMediationAvailable()}())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete$='webauthn']").length<1)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');i.mediation="conditional",o.allowCredentials=[]}let r;i.publicKey=o,i.signal=g.createNewAbortSignal();try{r=await navigator.credentials.get(i)}catch(t){throw function({error:t,options:e}){const{publicKey:n}=e;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===t.name){if(e.signal instanceof AbortSignal)return new w({message:"Authentication ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:t})}else{if("NotAllowedError"===t.name)return new w({message:t.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:t});if("SecurityError"===t.name){const e=window.location.hostname;if(!y(e))return new w({message:`${window.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:t});if(n.rpId!==e)return new w({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:t})}else if("UnknownError"===t.name)return new w({message:"The authenticator was unable to process the specified options, or could not create a new assertion signature",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:t})}return t}({error:t,options:i})}if(!r)throw new Error("Authentication was not completed");const{id:a,rawId:s,response:c,type:u}=r;let l;return c.userHandle&&(l=d(c.userHandle)),{id:a,rawId:d(s),response:{authenticatorData:d(c.authenticatorData),clientDataJSON:d(c.clientDataJSON),signature:d(c.signature),userHandle:l},type:u,clientExtensionResults:r.getClientExtensionResults(),authenticatorAttachment:b(r.authenticatorAttachment)}}function A(t){var e=t.token,n=t.tenantId;return{"Content-Type":"application/json",Authorization:e?"Bearer ".concat(e):"Basic ".concat(window.btoa(encodeURIComponent(n)))}}var R=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.tenantId=n,this.baseUrl=e}return t.prototype.registrationOptions=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.username,i=t.authenticatorAttachment;return h(this,(function(t){switch(t.label){case 0:return e=Boolean(i)?{username:o,authenticatorAttachment:i}:{username:o},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey/registration-options"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.authenticationOptions=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.challengeId;return h(this,(function(t){switch(t.label){case 0:return e={challengeId:o},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey/authentication-options"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.addAuthenticator=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.challengeId,i=t.registrationCredential;return h(this,(function(t){switch(t.label){case 0:return e={challengeId:o,registrationCredential:i},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.challengeId,i=t.authenticationCredential,r=t.deviceId;return h(this,(function(t){switch(t.label){case 0:return e={challengeId:o,authenticationCredential:i,deviceId:r},[4,fetch("".concat(this.baseUrl,"/client/verify/passkey"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.getPasskeyAuthenticator=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.credentialIds;return h(this,(function(t){switch(t.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey?credentialIds=").concat(n),{method:"GET",headers:A({tenantId:this.tenantId})})];case 1:if(!(e=t.sent()).ok)throw new Error(e.statusText);return[2,e.json()]}}))}))},t.prototype.challenge=function(t){return l(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/challenge"),{method:"POST",headers:A({tenantId:this.tenantId}),body:JSON.stringify({action:t})})];case 1:return[2,e.sent().json()]}}))}))},t}(),S=function(){function t(){this.token=null}return t.prototype.handleTokenNotSetError=function(){var t="A token has not been set. Call 'setToken' first.";return console.error("Error: ".concat(t)),{error:"TOKEN_NOT_SET",errorDescription:t}},t.shared=new t,t}(),O=function(){function t(t){var e=t.baseUrl,n=t.tenantId,o=t.anonymousId;this.passkeyLocalStorageKey="as_user_passkey_map",this.cache=S.shared,this.api=new R({baseUrl:e,tenantId:n}),this.anonymousId=o}return t.prototype.signUp=function(t){return l(this,arguments,void 0,(function(t){var e,n,o,i,r,a=t.userName,s=t.userDisplayName,l=t.token,d=t.authenticatorAttachment,p=void 0===d?"platform":d;return h(this,(function(t){switch(t.label){case 0:return(e=null!=l?l:this.cache.token)?(n={username:a,displayName:s,token:e,authenticatorAttachment:p},[4,this.api.registrationOptions(n)]):[2,this.cache.handleTokenNotSetError()];case 1:return"error"in(o=t.sent())?(c(o),[2,o]):[4,E(o.options)];case 2:return i=t.sent(),[4,this.api.addAuthenticator({challengeId:o.challengeId,registrationCredential:i,token:e})];case 3:return"error"in(r=t.sent())?(c(r),[2,r]):(r.isVerified&&this.storeCredentialAgainstDevice(u(u({},i),{userId:r.userId})),r.accessToken&&(this.cache.token=r.accessToken),[2,{token:r.accessToken,registrationResponse:i}])}}))}))},t.prototype.signIn=function(t){return l(this,void 0,void 0,(function(){var e,n,o,i,r,a,s,l,d,p;return h(this,(function(h){switch(h.label){case 0:if((null==t?void 0:t.token)&&t.autofill)throw new Error("autofill is not supported when providing a token");if((null==t?void 0:t.action)&&t.token)throw new Error("action is not supported when providing a token");return(null==t?void 0:t.action)?[4,this.api.challenge(t.action)]:[3,2];case 1:return n=h.sent(),[3,3];case 2:n=null,h.label=3;case 3:return(e=n)&&"error"in e?(c(e),[2,e]):[4,this.api.authenticationOptions({token:null==t?void 0:t.token,challengeId:null==e?void 0:e.challengeId})];case 4:return"error"in(o=h.sent())?(c(o),[2,o]):[4,k(o.options,null==t?void 0:t.autofill)];case 5:return i=h.sent(),(null==t?void 0:t.onVerificationStarted)&&t.onVerificationStarted(),[4,this.api.verify({challengeId:o.challengeId,authenticationCredential:i,token:null==t?void 0:t.token,deviceId:this.anonymousId})];case 6:return"error"in(r=h.sent())?(c(r),[2,r]):(r.isVerified&&this.storeCredentialAgainstDevice(u(u({},i),{userId:r.userId})),r.accessToken&&(this.cache.token=r.accessToken),a=r.accessToken,s=r.userId,l=r.userAuthenticatorId,d=r.username,p=r.userDisplayName,[2,{token:a,userId:s,userAuthenticatorId:l,userName:d,userDisplayName:p,authenticationResponse:i}])}}))}))},t.prototype.isAvailableOnDevice=function(t){return l(this,arguments,void 0,(function(t){var e,n,o,i,r=t.userId;return h(this,(function(t){switch(t.label){case 0:if(!r)throw new Error("userId is required");if(!(e=localStorage.getItem(this.passkeyLocalStorageKey)))return[2,!1];if(n=JSON.parse(e),0===(o=null!==(i=n[r])&&void 0!==i?i:[]).length)return[2,!1];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.api.getPasskeyAuthenticator({credentialIds:o})];case 2:return t.sent(),[2,!0];case 3:return t.sent(),[2,!1];case 4:return[2]}}))}))},t.prototype.storeCredentialAgainstDevice=function(t){var e=t.id,n=t.authenticatorAttachment,o=t.userId,i=void 0===o?"":o;if("cross-platform"!==n){var r=localStorage.getItem(this.passkeyLocalStorageKey),a=r?JSON.parse(r):{};a[i]?a[i].includes(e)||a[i].push(e):a[i]=[e],localStorage.setItem(this.passkeyLocalStorageKey,JSON.stringify(a))}},t}(),_=function(){function t(){this.windowRef=null}return t.prototype.show=function(t){var e=t.url,n=t.width,o=void 0===n?400:n,i=t.height,r=function(t){var e=t.url,n=t.width,o=t.height,i=t.win;if(!i.top)return null;var r=i.top.outerHeight/2+i.top.screenY-o/2,a=i.top.outerWidth/2+i.top.screenX-n/2;return window.open(e,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=".concat(n,", height=").concat(o,", top=").concat(r,", left=").concat(a))}({url:e,width:o,height:void 0===i?500:i,win:window});if(!r)throw new Error("Window is not initialized");return this.windowRef=r,r},t.prototype.close=function(){if(!this.windowRef)throw new Error("Window is not initialized");this.windowRef.close()},t}();const T=":not([inert]):not([inert] *)",C=':not([tabindex^="-"])',N=":not(:disabled)";var U=[`a[href]${T}${C}`,`area[href]${T}${C}`,`input:not([type="hidden"]):not([type="radio"])${T}${C}${N}`,`input[type="radio"]${T}${C}${N}`,`select${T}${C}${N}`,`textarea${T}${C}${N}`,`button${T}${C}${N}`,`details${T} > summary:first-of-type${C}`,`iframe${T}${C}`,`audio[controls]${T}${C}`,`video[controls]${T}${C}`,`[contenteditable]${T}${C}`,`[tabindex]${T}${C}`];function P(t){(t.querySelector("[autofocus]")||t).focus()}function $(t,e){if(e&&L(t))return t;if(!((n=t).shadowRoot&&"-1"===n.getAttribute("tabindex")||n.matches(":disabled,[hidden],[inert]")))if(t.shadowRoot){let n=D(t.shadowRoot,e);for(;n;){const t=$(n,e);if(t)return t;n=x(n,e)}}else if("slot"===t.localName){const n=t.assignedElements({flatten:!0});e||n.reverse();for(const t of n){const n=$(t,e);if(n)return n}}else{let n=D(t,e);for(;n;){const t=$(n,e);if(t)return t;n=x(n,e)}}var n;return!e&&L(t)?t:null}function D(t,e){return e?t.firstElementChild:t.lastElementChild}function x(t,e){return e?t.nextElementSibling:t.previousElementSibling}const L=t=>!t.shadowRoot?.delegatesFocus&&(t.matches(U.join(","))&&!(t=>!(!t.matches("details:not([open]) *")||t.matches("details>summary:first-of-type"))||!(t.offsetWidth||t.offsetHeight||t.getClientRects().length))(t));function K(t=document){const e=t.activeElement;return e?e.shadowRoot?K(e.shadowRoot)||document.activeElement:e:null}function j(t,e){const[n,o]=function(t){const e=$(t,!0);return[e,e?$(t,!1)||e:null]}(t);if(!n)return e.preventDefault();const i=K();e.shiftKey&&i===n?(o.focus(),e.preventDefault()):e.shiftKey||i!==o||(n.focus(),e.preventDefault())}class H{$el;id;previouslyFocused;shown;constructor(t){this.$el=t,this.id=this.$el.getAttribute("data-a11y-dialog")||this.$el.id,this.previouslyFocused=null,this.shown=!1,this.maintainFocus=this.maintainFocus.bind(this),this.bindKeypress=this.bindKeypress.bind(this),this.handleTriggerClicks=this.handleTriggerClicks.bind(this),this.show=this.show.bind(this),this.hide=this.hide.bind(this),this.$el.setAttribute("aria-hidden","true"),this.$el.setAttribute("aria-modal","true"),this.$el.setAttribute("tabindex","-1"),this.$el.hasAttribute("role")||this.$el.setAttribute("role","dialog"),document.addEventListener("click",this.handleTriggerClicks,!0)}destroy(){return this.hide(),document.removeEventListener("click",this.handleTriggerClicks,!0),this.$el.replaceWith(this.$el.cloneNode(!0)),this.fire("destroy"),this}show(t){return this.shown||(this.shown=!0,this.$el.removeAttribute("aria-hidden"),this.previouslyFocused=K(),"BODY"===this.previouslyFocused?.tagName&&t?.target&&(this.previouslyFocused=t.target),"focus"===t?.type?this.maintainFocus(t):P(this.$el),document.body.addEventListener("focus",this.maintainFocus,!0),this.$el.addEventListener("keydown",this.bindKeypress,!0),this.fire("show",t)),this}hide(t){return this.shown?(this.shown=!1,this.$el.setAttribute("aria-hidden","true"),this.previouslyFocused?.focus?.(),document.body.removeEventListener("focus",this.maintainFocus,!0),this.$el.removeEventListener("keydown",this.bindKeypress,!0),this.fire("hide",t),this):this}on(t,e,n){return this.$el.addEventListener(t,e,n),this}off(t,e,n){return this.$el.removeEventListener(t,e,n),this}fire(t,e){this.$el.dispatchEvent(new CustomEvent(t,{detail:e,cancelable:!0}))}handleTriggerClicks(t){const e=t.target;e.closest(`[data-a11y-dialog-show="${this.id}"]`)&&this.show(t),(e.closest(`[data-a11y-dialog-hide="${this.id}"]`)||e.closest("[data-a11y-dialog-hide]")&&e.closest('[aria-modal="true"]')===this.$el)&&this.hide(t)}bindKeypress(t){if(document.activeElement?.closest('[aria-modal="true"]')!==this.$el)return;let e=!1;try{e=!!this.$el.querySelector('[popover]:not([popover="manual"]):popover-open')}catch{}"Escape"!==t.key||"alertdialog"===this.$el.getAttribute("role")||e||(t.preventDefault(),this.hide(t)),"Tab"===t.key&&j(this.$el,t)}maintainFocus(t){t.target.closest('[aria-modal="true"], [data-a11y-dialog-ignore-focus-trap]')||P(this.$el)}}function W(){for(const t of document.querySelectorAll("[data-a11y-dialog]"))new H(t)}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",W):W());var M="__authsignal-popup-container",J="__authsignal-popup-content",q="__authsignal-popup-overlay",F="__authsignal-popup-style",G="__authsignal-popup-iframe",V="385px",z=function(){function t(t){var e=t.width,n=t.isClosable;if(this.popup=null,document.querySelector("#".concat(M)))throw new Error("Multiple instances of Authsignal popup is not supported.");this.create({width:e,isClosable:n})}return t.prototype.create=function(t){var e=this,n=t.width,o=void 0===n?V:n,i=t.isClosable,r=void 0===i||i,a=o;CSS.supports("width",o)||(console.warn("Invalid CSS value for `popupOptions.width`. Using default value instead."),a=V);var s=document.createElement("div");s.setAttribute("id",M),s.setAttribute("aria-hidden","true"),r||s.setAttribute("role","alertdialog");var c=document.createElement("div");c.setAttribute("id",q),r&&c.setAttribute("data-a11y-dialog-hide","true");var u=document.createElement("div");u.setAttribute("id",J),document.body.appendChild(s);var l=document.createElement("style");l.setAttribute("id",F),l.textContent="\n #".concat(M,",\n #").concat(q," {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(M," {\n z-index: 2147483647;\n display: flex;\n }\n\n #").concat(M,"[aria-hidden='true'] {\n display: none;\n }\n\n #").concat(q," {\n background-color: rgba(0, 0, 0, 0.18);\n }\n\n #").concat(J," {\n margin: auto;\n z-index: 2147483647;\n position: relative;\n background-color: transparent;\n border-radius: 8px;\n width: ").concat(a,";\n }\n\n #").concat(J," iframe {\n width: 1px;\n min-width: 100%;\n border-radius: inherit;\n max-height: 95vh;\n height: ").concat("384px",";\n }\n "),document.head.insertAdjacentElement("beforeend",l),s.appendChild(c),s.appendChild(u),this.popup=new H(s),s.focus(),this.popup.on("hide",(function(){e.destroy()}))},t.prototype.destroy=function(){var t=document.querySelector("#".concat(M)),e=document.querySelector("#".concat(F));t&&e&&(document.body.removeChild(t),document.head.removeChild(e)),window.removeEventListener("message",B)},t.prototype.show=function(t){var e,n=t.url;if(!this.popup)throw new Error("Popup is not initialized");var o=document.createElement("iframe");o.setAttribute("id",G),o.setAttribute("name","authsignal"),o.setAttribute("title","Authsignal multi-factor authentication"),o.setAttribute("src",n),o.setAttribute("frameborder","0"),o.setAttribute("allow","publickey-credentials-get *; publickey-credentials-create *; clipboard-write");var i=document.querySelector("#".concat(J));i&&i.appendChild(o),window.addEventListener("message",B),null===(e=this.popup)||void 0===e||e.show()},t.prototype.close=function(){if(!this.popup)throw new Error("Popup is not initialized");this.popup.hide()},t.prototype.on=function(t,e){if(!this.popup)throw new Error("Popup is not initialized");this.popup.on(t,e)},t}();function B(t){var e=document.querySelector("#".concat(G));e&&t.data.height&&(e.style.height=t.data.height+"px")}var Y=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.tenantId=n,this.baseUrl=e}return t.prototype.enroll=function(t){return l(this,arguments,void 0,(function(t){var e=t.token;return h(this,(function(t){switch(t.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/totp"),{method:"POST",headers:A({token:e,tenantId:this.tenantId})})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.code;return h(this,(function(t){switch(t.label){case 0:return e={verificationCode:o},[4,fetch("".concat(this.baseUrl,"/client/verify/totp"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t}(),X=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.cache=S.shared,this.api=new Y({baseUrl:e,tenantId:n})}return t.prototype.enroll=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return this.cache.token?[2,this.api.enroll({token:this.cache.token})]:[2,this.cache.handleTokenNotSetError()]}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.code;return h(this,(function(t){switch(t.label){case 0:return this.cache.token?[4,this.api.verify({token:this.cache.token,code:n})]:[2,this.cache.handleTokenNotSetError()];case 1:return(e=t.sent()).accessToken&&(this.cache.token=e.accessToken),[2,e]}}))}))},t}(),Q=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.tenantId=n,this.baseUrl=e}return t.prototype.enroll=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.email;return h(this,(function(t){switch(t.label){case 0:return e={email:o},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/email-otp"),{method:"POST",headers:this.buildHeaders(n),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.challenge=function(t){return l(this,arguments,void 0,(function(t){var e=t.token;return h(this,(function(t){switch(t.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/challenge/email-otp"),{method:"POST",headers:this.buildHeaders(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.code;return h(this,(function(t){switch(t.label){case 0:return e={verificationCode:o},[4,fetch("".concat(this.baseUrl,"/client/verify/email-otp"),{method:"POST",headers:this.buildHeaders(n),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.buildHeaders=function(t){return{"Content-Type":"application/json",Authorization:t?"Bearer ".concat(t):"Basic ".concat(window.btoa(encodeURIComponent(this.tenantId)))}},t}(),Z=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.cache=S.shared,this.api=new Q({baseUrl:e,tenantId:n})}return t.prototype.enroll=function(t){return l(this,arguments,void 0,(function(t){var e=t.email;return h(this,(function(t){return this.cache.token?[2,this.api.enroll({token:this.cache.token,email:e})]:[2,this.cache.handleTokenNotSetError()]}))}))},t.prototype.challenge=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return this.cache.token?[2,this.api.challenge({token:this.cache.token})]:[2,this.cache.handleTokenNotSetError()]}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.code;return h(this,(function(t){switch(t.label){case 0:return this.cache.token?[4,this.api.verify({token:this.cache.token,code:n})]:[2,this.cache.handleTokenNotSetError()];case 1:return(e=t.sent()).accessToken&&(this.cache.token=e.accessToken),[2,e]}}))}))},t}(),tt=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.tenantId=n,this.baseUrl=e}return t.prototype.enroll=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.phoneNumber;return h(this,(function(t){switch(t.label){case 0:return e={phoneNumber:o},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/sms"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.challenge=function(t){return l(this,arguments,void 0,(function(t){var e=t.token;return h(this,(function(t){switch(t.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/challenge/sms"),{method:"POST",headers:A({token:e,tenantId:this.tenantId})})];case 1:return[2,t.sent().json()]}}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.token,o=t.code;return h(this,(function(t){switch(t.label){case 0:return e={verificationCode:o},[4,fetch("".concat(this.baseUrl,"/client/verify/sms"),{method:"POST",headers:A({token:n,tenantId:this.tenantId}),body:JSON.stringify(e)})];case 1:return[2,t.sent().json()]}}))}))},t}(),et=function(){function t(t){var e=t.baseUrl,n=t.tenantId;this.cache=S.shared,this.api=new tt({baseUrl:e,tenantId:n})}return t.prototype.enroll=function(t){return l(this,arguments,void 0,(function(t){var e=t.phoneNumber;return h(this,(function(t){return this.cache.token?[2,this.api.enroll({token:this.cache.token,phoneNumber:e})]:[2,this.cache.handleTokenNotSetError()]}))}))},t.prototype.challenge=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return this.cache.token?[2,this.api.challenge({token:this.cache.token})]:[2,this.cache.handleTokenNotSetError()]}))}))},t.prototype.verify=function(t){return l(this,arguments,void 0,(function(t){var e,n=t.code;return h(this,(function(t){switch(t.label){case 0:return this.cache.token?[4,this.api.verify({token:this.cache.token,code:n})]:[2,this.cache.handleTokenNotSetError()];case 1:return(e=t.sent()).accessToken&&(this.cache.token=e.accessToken),[2,e]}}))}))},t}(),nt="4a08uqve",ot=function(){function e(t){var e=t.cookieDomain,n=t.cookieName,o=void 0===n?"__as_aid":n,i=t.baseUrl,r=void 0===i?"https://api.authsignal.com/v1":i,c=t.tenantId;if(this.anonymousId="",this.profilingId="",this.cookieDomain="",this.anonymousIdCookieName="",this.cookieDomain=e||document.location.hostname.replace("www.",""),this.anonymousIdCookieName=o,!c)throw new Error("tenantId is required");var u,l=(u=this.anonymousIdCookieName)&&decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(u).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null;l?this.anonymousId=l:(this.anonymousId=a(),s({name:this.anonymousIdCookieName,value:this.anonymousId,expire:1/0,domain:this.cookieDomain,secure:"http:"!==document.location.protocol})),this.passkey=new O({tenantId:c,baseUrl:r,anonymousId:this.anonymousId}),this.totp=new X({tenantId:c,baseUrl:r}),this.email=new Z({tenantId:c,baseUrl:r}),this.sms=new et({tenantId:c,baseUrl:r})}return e.prototype.setToken=function(t){S.shared.token=t},e.prototype.launch=function(t,e){switch(null==e?void 0:e.mode){case"window":return this.launchWithWindow(t,e);case"popup":return this.launchWithPopup(t,e);default:this.launchWithRedirect(t)}},e.prototype.initAdvancedProfiling=function(t){var e=a();this.profilingId=e,s({name:"__as_pid",value:e,expire:1/0,domain:this.cookieDomain,secure:"http:"!==document.location.protocol});var n=t?"".concat(t,"/fp/tags.js?org_id=").concat(nt,"&session_id=").concat(e):"https://h.online-metrix.net/fp/tags.js?org_id=".concat(nt,"&session_id=").concat(e),o=document.createElement("script");o.src=n,o.async=!1,o.id="as_adv_profile",document.head.appendChild(o);var i=document.createElement("noscript");i.setAttribute("id","as_adv_profile_pixel"),i.setAttribute("aria-hidden","true");var r=document.createElement("iframe"),c=t?"".concat(t,"/fp/tags?org_id=").concat(nt,"&session_id=").concat(e):"https://h.online-metrix.net/fp/tags?org_id=".concat(nt,"&session_id=").concat(e);r.setAttribute("id","as_adv_profile_pixel"),r.setAttribute("src",c),r.setAttribute("style","width: 100px; height: 100px; border: 0; position: absolute; top: -5000px;"),i&&(i.appendChild(r),document.body.prepend(i))},e.prototype.launchWithRedirect=function(t){window.location.href=t},e.prototype.launchWithPopup=function(e,n){var o=n.popupOptions,i=new z({width:null==o?void 0:o.width,isClosable:null==o?void 0:o.isClosable}),r="".concat(e,"&mode=popup");return i.show({url:r}),new Promise((function(e){var n=void 0;i.on("hide",(function(){e({token:n})})),window.addEventListener("message",(function(e){var o=null;try{o=JSON.parse(e.data)}catch(t){}(null==o?void 0:o.event)===t.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP&&(n=o.token,i.close())}),!1)}))},e.prototype.launchWithWindow=function(e,n){var o=n.windowOptions,i=new _,r="".concat(e,"&mode=popup");return i.show({url:r,width:null==o?void 0:o.width,height:null==o?void 0:o.height}),new Promise((function(e){window.addEventListener("message",(function(n){var o=null;try{o=JSON.parse(n.data)}catch(t){}(null==o?void 0:o.event)===t.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP&&(i.close(),e({token:o.token}))}),!1)}))},e}();return t.Authsignal=ot,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
1
+ var authsignal=function(e){"use strict";let t;const n=new Uint8Array(16);function o(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(n)}const i=[];for(let e=0;e<256;++e)i.push((e+256).toString(16).slice(1));var r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function s(e,t,n){if(r.randomUUID&&!t&&!e)return r.randomUUID();const s=(e=e||{}).random||(e.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=s[e];return t}return function(e,t=0){return(i[e[t+0]]+i[e[t+1]]+i[e[t+2]]+i[e[t+3]]+"-"+i[e[t+4]]+i[e[t+5]]+"-"+i[e[t+6]]+i[e[t+7]]+"-"+i[e[t+8]]+i[e[t+9]]+"-"+i[e[t+10]]+i[e[t+11]]+i[e[t+12]]+i[e[t+13]]+i[e[t+14]]+i[e[t+15]]).toLowerCase()}(s)}function a(e){var t=e.name,n=e.value,o=e.expire,i=e.domain,r=e.secure,s=o===1/0?" expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+o;document.cookie=encodeURIComponent(t)+"="+n+"; path=/;"+s+(i?"; domain="+i:"")+(r?"; secure":"")}function c(e){var t;console.error(null!==(t=e.errorDescription)&&void 0!==t?t:e.error)}e.AuthsignalWindowMessage=void 0,(e.AuthsignalWindowMessage||(e.AuthsignalWindowMessage={})).AUTHSIGNAL_CLOSE_POPUP="AUTHSIGNAL_CLOSE_POPUP";var u=function(){return u=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},u.apply(this,arguments)};function l(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}function d(e,t){var n,o,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,o=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=t.call(e,s)}catch(e){r=[6,e],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function h(e){const t=new Uint8Array(e);let n="";for(const e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function p(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),n=(4-t.length%4)%4,o=t.padEnd(t.length+n,"="),i=atob(o),r=new ArrayBuffer(i.length),s=new Uint8Array(r);for(let e=0;e<i.length;e++)s[e]=i.charCodeAt(e);return r}function f(){return void 0!==window?.PublicKeyCredential&&"function"==typeof window.PublicKeyCredential}function m(e){const{id:t}=e;return{...e,id:p(t),transports:e.transports}}function y(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}class w extends Error{constructor({message:e,code:t,cause:n,name:o}){super(e,{cause:n}),this.name=o??n.name,this.code=t}}const g=new class{createNewAbortSignal(){if(this.controller){const e=new Error("Cancelling existing WebAuthn API call for new one");e.name="AbortError",this.controller.abort(e)}const e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){const e=new Error("Manually cancelling existing WebAuthn API call");e.name="AbortError",this.controller.abort(e),this.controller=void 0}}},v=["cross-platform","platform"];function b(e){if(e&&!(v.indexOf(e)<0))return e}async function E(e){if(!f())throw new Error("WebAuthn is not supported in this browser");const t={publicKey:{...e,challenge:p(e.challenge),user:{...e.user,id:p(e.user.id)},excludeCredentials:e.excludeCredentials?.map(m)}};let n;t.signal=g.createNewAbortSignal();try{n=await navigator.credentials.create(t)}catch(e){throw function({error:e,options:t}){const{publicKey:n}=t;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(t.signal instanceof AbortSignal)return new w({message:"Registration ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:e})}else if("ConstraintError"===e.name){if(!0===n.authenticatorSelection?.requireResidentKey)return new w({message:"Discoverable credentials were required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",cause:e});if("required"===n.authenticatorSelection?.userVerification)return new w({message:"User verification was required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",cause:e})}else{if("InvalidStateError"===e.name)return new w({message:"The authenticator was previously registered",code:"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",cause:e});if("NotAllowedError"===e.name)return new w({message:e.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:e});if("NotSupportedError"===e.name)return 0===n.pubKeyCredParams.filter((e=>"public-key"===e.type)).length?new w({message:'No entry in pubKeyCredParams was of type "public-key"',code:"ERROR_MALFORMED_PUBKEYCREDPARAMS",cause:e}):new w({message:"No available authenticator supported any of the specified pubKeyCredParams algorithms",code:"ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",cause:e});if("SecurityError"===e.name){const t=window.location.hostname;if(!y(t))return new w({message:`${window.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:e});if(n.rp.id!==t)return new w({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:e})}else if("TypeError"===e.name){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new w({message:"User ID was not between 1 and 64 characters",code:"ERROR_INVALID_USER_ID_LENGTH",cause:e})}else if("UnknownError"===e.name)return new w({message:"The authenticator was unable to process the specified options, or could not create a new credential",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:e})}return e}({error:e,options:t})}if(!n)throw new Error("Registration was not completed");const{id:o,rawId:i,response:r,type:s}=n;let a,c,u,l;if("function"==typeof r.getTransports&&(a=r.getTransports()),"function"==typeof r.getPublicKeyAlgorithm)try{c=r.getPublicKeyAlgorithm()}catch(e){k("getPublicKeyAlgorithm()",e)}if("function"==typeof r.getPublicKey)try{const e=r.getPublicKey();null!==e&&(u=h(e))}catch(e){k("getPublicKey()",e)}if("function"==typeof r.getAuthenticatorData)try{l=h(r.getAuthenticatorData())}catch(e){k("getAuthenticatorData()",e)}return{id:o,rawId:h(i),response:{attestationObject:h(r.attestationObject),clientDataJSON:h(r.clientDataJSON),transports:a,publicKeyAlgorithm:c,publicKey:u,authenticatorData:l},type:s,clientExtensionResults:n.getClientExtensionResults(),authenticatorAttachment:b(n.authenticatorAttachment)}}function k(e,t){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them.\n`,t)}async function I(e,t=!1){if(!f())throw new Error("WebAuthn is not supported in this browser");let n;0!==e.allowCredentials?.length&&(n=e.allowCredentials?.map(m));const o={...e,challenge:p(e.challenge),allowCredentials:n},i={};if(t){if(!await function(){if(!f())return new Promise((e=>e(!1)));const e=window.PublicKeyCredential;return void 0===e.isConditionalMediationAvailable?new Promise((e=>e(!1))):e.isConditionalMediationAvailable()}())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete$='webauthn']").length<1)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');i.mediation="conditional",o.allowCredentials=[]}let r;i.publicKey=o,i.signal=g.createNewAbortSignal();try{r=await navigator.credentials.get(i)}catch(e){throw function({error:e,options:t}){const{publicKey:n}=t;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(t.signal instanceof AbortSignal)return new w({message:"Authentication ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:e})}else{if("NotAllowedError"===e.name)return new w({message:e.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:e});if("SecurityError"===e.name){const t=window.location.hostname;if(!y(t))return new w({message:`${window.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:e});if(n.rpId!==t)return new w({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:e})}else if("UnknownError"===e.name)return new w({message:"The authenticator was unable to process the specified options, or could not create a new assertion signature",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:e})}return e}({error:e,options:i})}if(!r)throw new Error("Authentication was not completed");const{id:s,rawId:a,response:c,type:u}=r;let l;return c.userHandle&&(l=h(c.userHandle)),{id:s,rawId:h(a),response:{authenticatorData:h(c.authenticatorData),clientDataJSON:h(c.clientDataJSON),signature:h(c.signature),userHandle:l},type:u,clientExtensionResults:r.getClientExtensionResults(),authenticatorAttachment:b(r.authenticatorAttachment)}}function T(e){var t=e.token,n=e.tenantId;return{"Content-Type":"application/json",Authorization:t?"Bearer ".concat(t):"Basic ".concat(window.btoa(encodeURIComponent(n)))}}function A(e){var t=e.response,n=e.onTokenExpired;"error"in t&&"expired_token"===t.errorCode&&n&&n()}var R=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.tenantId=n,this.baseUrl=t,this.onTokenExpired=o}return e.prototype.registrationOptions=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.username,r=e.authenticatorAttachment;return d(this,(function(e){switch(e.label){case 0:return t=Boolean(r)?{username:i,authenticatorAttachment:r}:{username:i},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey/registration-options"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e.prototype.authenticationOptions=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.challengeId;return d(this,(function(e){switch(e.label){case 0:return t={challengeId:i},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey/authentication-options"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e.prototype.addAuthenticator=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.challengeId,r=e.registrationCredential;return d(this,(function(e){switch(e.label){case 0:return t={challengeId:i,registrationCredential:r},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.challengeId,r=e.authenticationCredential,s=e.deviceId;return d(this,(function(e){switch(e.label){case 0:return t={challengeId:i,authenticationCredential:r,deviceId:s},[4,fetch("".concat(this.baseUrl,"/client/verify/passkey"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e.prototype.getPasskeyAuthenticator=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.credentialIds;return d(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/passkey?credentialIds=").concat(n),{method:"GET",headers:T({tenantId:this.tenantId})})];case 1:if(!(t=e.sent()).ok)throw new Error(t.statusText);return[2,t.json()]}}))}))},e.prototype.challenge=function(e){return l(this,void 0,void 0,(function(){var t;return d(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/challenge"),{method:"POST",headers:T({tenantId:this.tenantId}),body:JSON.stringify({action:e})})];case 1:return[4,n.sent().json()];case 2:return A({response:t=n.sent(),onTokenExpired:this.onTokenExpired}),[2,t]}}))}))},e}(),S=function(){function e(){this.token=null}return e.prototype.handleTokenNotSetError=function(){var e="A token has not been set. Call 'setToken' first.";return console.error("Error: ".concat(e)),{error:"TOKEN_NOT_SET",errorDescription:e}},e.shared=new e,e}(),_=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.anonymousId,i=e.onTokenExpired;this.passkeyLocalStorageKey="as_user_passkey_map",this.cache=S.shared,this.api=new R({baseUrl:t,tenantId:n,onTokenExpired:i}),this.anonymousId=o}return e.prototype.signUp=function(e){return l(this,arguments,void 0,(function(e){var t,n,o,i,r,s=e.userName,a=e.userDisplayName,l=e.token,h=e.authenticatorAttachment,p=void 0===h?"platform":h;return d(this,(function(e){switch(e.label){case 0:return(t=null!=l?l:this.cache.token)?(n={username:s,displayName:a,token:t,authenticatorAttachment:p},[4,this.api.registrationOptions(n)]):[2,this.cache.handleTokenNotSetError()];case 1:return"error"in(o=e.sent())?(c(o),[2,o]):[4,E(o.options)];case 2:return i=e.sent(),[4,this.api.addAuthenticator({challengeId:o.challengeId,registrationCredential:i,token:t})];case 3:return"error"in(r=e.sent())?(c(r),[2,r]):(r.isVerified&&this.storeCredentialAgainstDevice(u(u({},i),{userId:r.userId})),r.accessToken&&(this.cache.token=r.accessToken),[2,{token:r.accessToken,registrationResponse:i}])}}))}))},e.prototype.signIn=function(e){return l(this,void 0,void 0,(function(){var t,n,o,i,r,s,a,l,h,p;return d(this,(function(d){switch(d.label){case 0:if((null==e?void 0:e.token)&&e.autofill)throw new Error("autofill is not supported when providing a token");if((null==e?void 0:e.action)&&e.token)throw new Error("action is not supported when providing a token");return(null==e?void 0:e.action)?[4,this.api.challenge(e.action)]:[3,2];case 1:return n=d.sent(),[3,3];case 2:n=null,d.label=3;case 3:return(t=n)&&"error"in t?(c(t),[2,t]):[4,this.api.authenticationOptions({token:null==e?void 0:e.token,challengeId:null==t?void 0:t.challengeId})];case 4:return"error"in(o=d.sent())?(c(o),[2,o]):[4,I(o.options,null==e?void 0:e.autofill)];case 5:return i=d.sent(),(null==e?void 0:e.onVerificationStarted)&&e.onVerificationStarted(),[4,this.api.verify({challengeId:o.challengeId,authenticationCredential:i,token:null==e?void 0:e.token,deviceId:this.anonymousId})];case 6:return"error"in(r=d.sent())?(c(r),[2,r]):(r.isVerified&&this.storeCredentialAgainstDevice(u(u({},i),{userId:r.userId})),r.accessToken&&(this.cache.token=r.accessToken),s=r.accessToken,a=r.userId,l=r.userAuthenticatorId,h=r.username,p=r.userDisplayName,[2,{isVerified:r.isVerified,token:s,userId:a,userAuthenticatorId:l,userName:h,userDisplayName:p,authenticationResponse:i}])}}))}))},e.prototype.isAvailableOnDevice=function(e){return l(this,arguments,void 0,(function(e){var t,n,o,i,r=e.userId;return d(this,(function(e){switch(e.label){case 0:if(!r)throw new Error("userId is required");if(!(t=localStorage.getItem(this.passkeyLocalStorageKey)))return[2,!1];if(n=JSON.parse(t),0===(o=null!==(i=n[r])&&void 0!==i?i:[]).length)return[2,!1];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.api.getPasskeyAuthenticator({credentialIds:o})];case 2:return e.sent(),[2,!0];case 3:return e.sent(),[2,!1];case 4:return[2]}}))}))},e.prototype.storeCredentialAgainstDevice=function(e){var t=e.id,n=e.authenticatorAttachment,o=e.userId,i=void 0===o?"":o;if("cross-platform"!==n){var r=localStorage.getItem(this.passkeyLocalStorageKey),s=r?JSON.parse(r):{};s[i]?s[i].includes(t)||s[i].push(t):s[i]=[t],localStorage.setItem(this.passkeyLocalStorageKey,JSON.stringify(s))}},e}(),O=function(){function e(){this.windowRef=null}return e.prototype.show=function(e){var t=e.url,n=e.width,o=void 0===n?400:n,i=e.height,r=function(e){var t=e.url,n=e.width,o=e.height,i=e.win;if(!i.top)return null;var r=i.top.outerHeight/2+i.top.screenY-o/2,s=i.top.outerWidth/2+i.top.screenX-n/2;return window.open(t,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=".concat(n,", height=").concat(o,", top=").concat(r,", left=").concat(s))}({url:t,width:o,height:void 0===i?500:i,win:window});if(!r)throw new Error("Window is not initialized");return this.windowRef=r,r},e.prototype.close=function(){if(!this.windowRef)throw new Error("Window is not initialized");this.windowRef.close()},e}();const x=":not([inert]):not([inert] *)",C=':not([tabindex^="-"])',N=":not(:disabled)";var U=[`a[href]${x}${C}`,`area[href]${x}${C}`,`input:not([type="hidden"]):not([type="radio"])${x}${C}${N}`,`input[type="radio"]${x}${C}${N}`,`select${x}${C}${N}`,`textarea${x}${C}${N}`,`button${x}${C}${N}`,`details${x} > summary:first-of-type${C}`,`iframe${x}${C}`,`audio[controls]${x}${C}`,`video[controls]${x}${C}`,`[contenteditable]${x}${C}`,`[tabindex]${x}${C}`];function P(e){(e.querySelector("[autofocus]")||e).focus()}function $(e,t){if(t&&K(e))return e;if(!((n=e).shadowRoot&&"-1"===n.getAttribute("tabindex")||n.matches(":disabled,[hidden],[inert]")))if(e.shadowRoot){let n=D(e.shadowRoot,t);for(;n;){const e=$(n,t);if(e)return e;n=L(n,t)}}else if("slot"===e.localName){const n=e.assignedElements({flatten:!0});t||n.reverse();for(const e of n){const n=$(e,t);if(n)return n}}else{let n=D(e,t);for(;n;){const e=$(n,t);if(e)return e;n=L(n,t)}}var n;return!t&&K(e)?e:null}function D(e,t){return t?e.firstElementChild:e.lastElementChild}function L(e,t){return t?e.nextElementSibling:e.previousElementSibling}const K=e=>!e.shadowRoot?.delegatesFocus&&(e.matches(U.join(","))&&!(e=>!(!e.matches("details:not([open]) *")||e.matches("details>summary:first-of-type"))||!(e.offsetWidth||e.offsetHeight||e.getClientRects().length))(e));function j(e=document){const t=e.activeElement;return t?t.shadowRoot?j(t.shadowRoot)||document.activeElement:t:null}function W(e,t){const[n,o]=function(e){const t=$(e,!0);return[t,t?$(e,!1)||t:null]}(e);if(!n)return t.preventDefault();const i=j();t.shiftKey&&i===n?(o.focus(),t.preventDefault()):t.shiftKey||i!==o||(n.focus(),t.preventDefault())}class M{$el;id;previouslyFocused;shown;constructor(e){this.$el=e,this.id=this.$el.getAttribute("data-a11y-dialog")||this.$el.id,this.previouslyFocused=null,this.shown=!1,this.maintainFocus=this.maintainFocus.bind(this),this.bindKeypress=this.bindKeypress.bind(this),this.handleTriggerClicks=this.handleTriggerClicks.bind(this),this.show=this.show.bind(this),this.hide=this.hide.bind(this),this.$el.setAttribute("aria-hidden","true"),this.$el.setAttribute("aria-modal","true"),this.$el.setAttribute("tabindex","-1"),this.$el.hasAttribute("role")||this.$el.setAttribute("role","dialog"),document.addEventListener("click",this.handleTriggerClicks,!0)}destroy(){return this.hide(),document.removeEventListener("click",this.handleTriggerClicks,!0),this.$el.replaceWith(this.$el.cloneNode(!0)),this.fire("destroy"),this}show(e){return this.shown||(this.shown=!0,this.$el.removeAttribute("aria-hidden"),this.previouslyFocused=j(),"BODY"===this.previouslyFocused?.tagName&&e?.target&&(this.previouslyFocused=e.target),"focus"===e?.type?this.maintainFocus(e):P(this.$el),document.body.addEventListener("focus",this.maintainFocus,!0),this.$el.addEventListener("keydown",this.bindKeypress,!0),this.fire("show",e)),this}hide(e){return this.shown?(this.shown=!1,this.$el.setAttribute("aria-hidden","true"),this.previouslyFocused?.focus?.(),document.body.removeEventListener("focus",this.maintainFocus,!0),this.$el.removeEventListener("keydown",this.bindKeypress,!0),this.fire("hide",e),this):this}on(e,t,n){return this.$el.addEventListener(e,t,n),this}off(e,t,n){return this.$el.removeEventListener(e,t,n),this}fire(e,t){this.$el.dispatchEvent(new CustomEvent(e,{detail:t,cancelable:!0}))}handleTriggerClicks(e){const t=e.target;t.closest(`[data-a11y-dialog-show="${this.id}"]`)&&this.show(e),(t.closest(`[data-a11y-dialog-hide="${this.id}"]`)||t.closest("[data-a11y-dialog-hide]")&&t.closest('[aria-modal="true"]')===this.$el)&&this.hide(e)}bindKeypress(e){if(document.activeElement?.closest('[aria-modal="true"]')!==this.$el)return;let t=!1;try{t=!!this.$el.querySelector('[popover]:not([popover="manual"]):popover-open')}catch{}"Escape"!==e.key||"alertdialog"===this.$el.getAttribute("role")||t||(e.preventDefault(),this.hide(e)),"Tab"===e.key&&W(this.$el,e)}maintainFocus(e){e.target.closest('[aria-modal="true"], [data-a11y-dialog-ignore-focus-trap]')||P(this.$el)}}function H(){for(const e of document.querySelectorAll("[data-a11y-dialog]"))new M(e)}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",H):H());var J="__authsignal-popup-container",q="__authsignal-popup-content",V="__authsignal-popup-overlay",F="__authsignal-popup-style",G="__authsignal-popup-iframe",z="385px",B=function(){function e(e){var t=e.width,n=e.isClosable;if(this.popup=null,document.querySelector("#".concat(J)))throw new Error("Multiple instances of Authsignal popup is not supported.");this.create({width:t,isClosable:n})}return e.prototype.create=function(e){var t=this,n=e.width,o=void 0===n?z:n,i=e.isClosable,r=void 0===i||i,s=o;CSS.supports("width",o)||(console.warn("Invalid CSS value for `popupOptions.width`. Using default value instead."),s=z);var a=document.createElement("div");a.setAttribute("id",J),a.setAttribute("aria-hidden","true"),r||a.setAttribute("role","alertdialog");var c=document.createElement("div");c.setAttribute("id",V),r&&c.setAttribute("data-a11y-dialog-hide","true");var u=document.createElement("div");u.setAttribute("id",q),document.body.appendChild(a);var l=document.createElement("style");l.setAttribute("id",F),l.textContent="\n #".concat(J,",\n #").concat(V," {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(J," {\n z-index: 2147483647;\n display: flex;\n }\n\n #").concat(J,"[aria-hidden='true'] {\n display: none;\n }\n\n #").concat(V," {\n background-color: rgba(0, 0, 0, 0.18);\n }\n\n #").concat(q," {\n margin: auto;\n z-index: 2147483647;\n position: relative;\n background-color: transparent;\n border-radius: 8px;\n width: ").concat(s,";\n }\n\n #").concat(q," iframe {\n width: 1px;\n min-width: 100%;\n border-radius: inherit;\n max-height: 95vh;\n height: ").concat("384px",";\n }\n "),document.head.insertAdjacentElement("beforeend",l),a.appendChild(c),a.appendChild(u),this.popup=new M(a),a.focus(),this.popup.on("hide",(function(){t.destroy()}))},e.prototype.destroy=function(){var e=document.querySelector("#".concat(J)),t=document.querySelector("#".concat(F));e&&t&&(document.body.removeChild(e),document.head.removeChild(t)),window.removeEventListener("message",Y)},e.prototype.show=function(e){var t,n=e.url;if(!this.popup)throw new Error("Popup is not initialized");var o=document.createElement("iframe");o.setAttribute("id",G),o.setAttribute("name","authsignal"),o.setAttribute("title","Authsignal multi-factor authentication"),o.setAttribute("src",n),o.setAttribute("frameborder","0"),o.setAttribute("allow","publickey-credentials-get *; publickey-credentials-create *; clipboard-write");var i=document.querySelector("#".concat(q));i&&i.appendChild(o),window.addEventListener("message",Y),null===(t=this.popup)||void 0===t||t.show()},e.prototype.close=function(){if(!this.popup)throw new Error("Popup is not initialized");this.popup.hide()},e.prototype.on=function(e,t){if(!this.popup)throw new Error("Popup is not initialized");this.popup.on(e,t)},e}();function Y(e){var t=document.querySelector("#".concat(G));t&&e.data.height&&(t.style.height=e.data.height+"px")}var X=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.tenantId=n,this.baseUrl=t,this.onTokenExpired=o}return e.prototype.enroll=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.token;return d(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/totp"),{method:"POST",headers:T({token:n,tenantId:this.tenantId})})];case 1:return[4,e.sent().json()];case 2:return A({response:t=e.sent(),onTokenExpired:this.onTokenExpired}),[2,t]}}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.code;return d(this,(function(e){switch(e.label){case 0:return t={verificationCode:i},[4,fetch("".concat(this.baseUrl,"/client/verify/totp"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e}(),Q=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.cache=S.shared,this.api=new X({baseUrl:t,tenantId:n,onTokenExpired:o})}return e.prototype.enroll=function(){return l(this,void 0,void 0,(function(){return d(this,(function(e){return this.cache.token?[2,this.api.enroll({token:this.cache.token})]:[2,this.cache.handleTokenNotSetError()]}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.code;return d(this,(function(e){switch(e.label){case 0:return this.cache.token?[4,this.api.verify({token:this.cache.token,code:n})]:[2,this.cache.handleTokenNotSetError()];case 1:return"accessToken"in(t=e.sent())&&t.accessToken&&(this.cache.token=t.accessToken),[2,t]}}))}))},e}(),Z=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.tenantId=n,this.baseUrl=t,this.onTokenExpired=o}return e.prototype.enroll=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.email;return d(this,(function(e){switch(e.label){case 0:return t={email:i},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/email-otp"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e.prototype.challenge=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.token;return d(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/challenge/email-otp"),{method:"POST",headers:T({token:n,tenantId:this.tenantId})})];case 1:return[4,e.sent().json()];case 2:return A({response:t=e.sent(),onTokenExpired:this.onTokenExpired}),[2,t]}}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.code;return d(this,(function(e){switch(e.label){case 0:return t={verificationCode:i},[4,fetch("".concat(this.baseUrl,"/client/verify/email-otp"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e}(),ee=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.cache=S.shared,this.api=new Z({baseUrl:t,tenantId:n,onTokenExpired:o})}return e.prototype.enroll=function(e){return l(this,arguments,void 0,(function(e){var t=e.email;return d(this,(function(e){return this.cache.token?[2,this.api.enroll({token:this.cache.token,email:t})]:[2,this.cache.handleTokenNotSetError()]}))}))},e.prototype.challenge=function(){return l(this,void 0,void 0,(function(){return d(this,(function(e){return this.cache.token?[2,this.api.challenge({token:this.cache.token})]:[2,this.cache.handleTokenNotSetError()]}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.code;return d(this,(function(e){switch(e.label){case 0:return this.cache.token?[4,this.api.verify({token:this.cache.token,code:n})]:[2,this.cache.handleTokenNotSetError()];case 1:return"accessToken"in(t=e.sent())&&t.accessToken&&(this.cache.token=t.accessToken),[2,t]}}))}))},e}(),te=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.tenantId=n,this.baseUrl=t,this.onTokenExpired=o}return e.prototype.enroll=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.phoneNumber;return d(this,(function(e){switch(e.label){case 0:return t={phoneNumber:i},[4,fetch("".concat(this.baseUrl,"/client/user-authenticators/sms"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e.prototype.challenge=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.token;return d(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(this.baseUrl,"/client/challenge/sms"),{method:"POST",headers:T({token:n,tenantId:this.tenantId})})];case 1:return[4,e.sent().json()];case 2:return A({response:t=e.sent(),onTokenExpired:this.onTokenExpired}),[2,t]}}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n,o=e.token,i=e.code;return d(this,(function(e){switch(e.label){case 0:return t={verificationCode:i},[4,fetch("".concat(this.baseUrl,"/client/verify/sms"),{method:"POST",headers:T({token:o,tenantId:this.tenantId}),body:JSON.stringify(t)})];case 1:return[4,e.sent().json()];case 2:return A({response:n=e.sent(),onTokenExpired:this.onTokenExpired}),[2,n]}}))}))},e}(),ne=function(){function e(e){var t=e.baseUrl,n=e.tenantId,o=e.onTokenExpired;this.cache=S.shared,this.api=new te({baseUrl:t,tenantId:n,onTokenExpired:o})}return e.prototype.enroll=function(e){return l(this,arguments,void 0,(function(e){var t=e.phoneNumber;return d(this,(function(e){return this.cache.token?[2,this.api.enroll({token:this.cache.token,phoneNumber:t})]:[2,this.cache.handleTokenNotSetError()]}))}))},e.prototype.challenge=function(){return l(this,void 0,void 0,(function(){return d(this,(function(e){return this.cache.token?[2,this.api.challenge({token:this.cache.token})]:[2,this.cache.handleTokenNotSetError()]}))}))},e.prototype.verify=function(e){return l(this,arguments,void 0,(function(e){var t,n=e.code;return d(this,(function(e){switch(e.label){case 0:return this.cache.token?[4,this.api.verify({token:this.cache.token,code:n})]:[2,this.cache.handleTokenNotSetError()];case 1:return"accessToken"in(t=e.sent())&&t.accessToken&&(this.cache.token=t.accessToken),[2,t]}}))}))},e}(),oe="4a08uqve",ie=function(){function t(e){var t=e.cookieDomain,n=e.cookieName,o=void 0===n?"__as_aid":n,i=e.baseUrl,r=void 0===i?"https://api.authsignal.com/v1":i,c=e.tenantId,u=e.onTokenExpired;if(this.anonymousId="",this.profilingId="",this.cookieDomain="",this.anonymousIdCookieName="",this.cookieDomain=t||document.location.hostname.replace("www.",""),this.anonymousIdCookieName=o,!c)throw new Error("tenantId is required");var l,d=(l=this.anonymousIdCookieName)&&decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(l).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null;d?this.anonymousId=d:(this.anonymousId=s(),a({name:this.anonymousIdCookieName,value:this.anonymousId,expire:1/0,domain:this.cookieDomain,secure:"http:"!==document.location.protocol})),this.passkey=new _({tenantId:c,baseUrl:r,anonymousId:this.anonymousId,onTokenExpired:u}),this.totp=new Q({tenantId:c,baseUrl:r,onTokenExpired:u}),this.email=new ee({tenantId:c,baseUrl:r,onTokenExpired:u}),this.sms=new ne({tenantId:c,baseUrl:r,onTokenExpired:u})}return t.prototype.setToken=function(e){S.shared.token=e},t.prototype.launch=function(e,t){switch(null==t?void 0:t.mode){case"window":return this.launchWithWindow(e,t);case"popup":return this.launchWithPopup(e,t);default:this.launchWithRedirect(e)}},t.prototype.initAdvancedProfiling=function(e){var t=s();this.profilingId=t,a({name:"__as_pid",value:t,expire:1/0,domain:this.cookieDomain,secure:"http:"!==document.location.protocol});var n=e?"".concat(e,"/fp/tags.js?org_id=").concat(oe,"&session_id=").concat(t):"https://h.online-metrix.net/fp/tags.js?org_id=".concat(oe,"&session_id=").concat(t),o=document.createElement("script");o.src=n,o.async=!1,o.id="as_adv_profile",document.head.appendChild(o);var i=document.createElement("noscript");i.setAttribute("id","as_adv_profile_pixel"),i.setAttribute("aria-hidden","true");var r=document.createElement("iframe"),c=e?"".concat(e,"/fp/tags?org_id=").concat(oe,"&session_id=").concat(t):"https://h.online-metrix.net/fp/tags?org_id=".concat(oe,"&session_id=").concat(t);r.setAttribute("id","as_adv_profile_pixel"),r.setAttribute("src",c),r.setAttribute("style","width: 100px; height: 100px; border: 0; position: absolute; top: -5000px;"),i&&(i.appendChild(r),document.body.prepend(i))},t.prototype.launchWithRedirect=function(e){window.location.href=e},t.prototype.launchWithPopup=function(t,n){var o=n.popupOptions,i=new B({width:null==o?void 0:o.width,isClosable:null==o?void 0:o.isClosable}),r="".concat(t,"&mode=popup");return i.show({url:r}),new Promise((function(t){var n=void 0;i.on("hide",(function(){t({token:n})})),window.addEventListener("message",(function(t){var o=null;try{o=JSON.parse(t.data)}catch(e){}(null==o?void 0:o.event)===e.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP&&(n=o.token,i.close())}),!1)}))},t.prototype.launchWithWindow=function(t,n){var o=n.windowOptions,i=new O,r="".concat(t,"&mode=popup");return i.show({url:r,width:null==o?void 0:o.width,height:null==o?void 0:o.height}),new Promise((function(t){window.addEventListener("message",(function(n){var o=null;try{o=JSON.parse(n.data)}catch(e){}(null==o?void 0:o.event)===e.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP&&(i.close(),t({token:o.token}))}),!1)}))},t}();return e.Authsignal=ie,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
package/dist/passkey.d.ts CHANGED
@@ -5,6 +5,7 @@ type PasskeyOptions = {
5
5
  baseUrl: string;
6
6
  tenantId: string;
7
7
  anonymousId: string;
8
+ onTokenExpired?: () => void;
8
9
  };
9
10
  type SignUpParams = {
10
11
  userName?: string;
@@ -23,6 +24,7 @@ type SignInParams = {
23
24
  onVerificationStarted?: () => unknown;
24
25
  };
25
26
  type SignInResponse = {
27
+ isVerified: boolean;
26
28
  token?: string;
27
29
  userId?: string;
28
30
  userAuthenticatorId?: string;
@@ -35,7 +37,7 @@ export declare class Passkey {
35
37
  private passkeyLocalStorageKey;
36
38
  private anonymousId;
37
39
  private cache;
38
- constructor({ baseUrl, tenantId, anonymousId }: PasskeyOptions);
40
+ constructor({ baseUrl, tenantId, anonymousId, onTokenExpired }: PasskeyOptions);
39
41
  signUp({ userName, userDisplayName, token, authenticatorAttachment, }: SignUpParams): Promise<AuthsignalResponse<SignUpResponse>>;
40
42
  signIn(params?: SignInParams): Promise<AuthsignalResponse<SignInResponse>>;
41
43
  isAvailableOnDevice({ userId }: {
package/dist/sms.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { AuthsignalResponse, ChallengeResponse, EnrollResponse, VerifyResponse } from "./api/types/shared";
2
1
  type SmsOptions = {
3
2
  baseUrl: string;
4
3
  tenantId: string;
4
+ onTokenExpired?: () => void;
5
5
  };
6
6
  type EnrollParams = {
7
7
  phoneNumber: string;
@@ -12,9 +12,9 @@ type VerifyParams = {
12
12
  export declare class Sms {
13
13
  private api;
14
14
  private cache;
15
- constructor({ baseUrl, tenantId }: SmsOptions);
16
- enroll({ phoneNumber }: EnrollParams): Promise<AuthsignalResponse<EnrollResponse>>;
17
- challenge(): Promise<AuthsignalResponse<ChallengeResponse>>;
18
- verify({ code }: VerifyParams): Promise<AuthsignalResponse<VerifyResponse>>;
15
+ constructor({ baseUrl, tenantId, onTokenExpired }: SmsOptions);
16
+ enroll({ phoneNumber }: EnrollParams): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").EnrollResponse>>;
17
+ challenge(): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").ChallengeResponse>>;
18
+ verify({ code }: VerifyParams): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").VerifyResponse>>;
19
19
  }
20
20
  export {};
package/dist/totp.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { AuthsignalResponse, VerifyResponse } from "./api/types/shared";
2
- import { EnrollResponse } from "./api/types/totp";
3
1
  type TotpOptions = {
4
2
  baseUrl: string;
5
3
  tenantId: string;
4
+ onTokenExpired?: () => void;
6
5
  };
7
6
  type VerifyParams = {
8
7
  code: string;
@@ -10,8 +9,8 @@ type VerifyParams = {
10
9
  export declare class Totp {
11
10
  private api;
12
11
  private cache;
13
- constructor({ baseUrl, tenantId }: TotpOptions);
14
- enroll(): Promise<AuthsignalResponse<EnrollResponse>>;
15
- verify({ code }: VerifyParams): Promise<AuthsignalResponse<VerifyResponse>>;
12
+ constructor({ baseUrl, tenantId, onTokenExpired }: TotpOptions);
13
+ enroll(): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/totp").EnrollResponse>>;
14
+ verify({ code }: VerifyParams): Promise<import("./api/types/shared").AuthsignalResponse<import("./api/types/shared").VerifyResponse>>;
16
15
  }
17
16
  export {};
package/dist/types.d.ts CHANGED
@@ -52,6 +52,7 @@ export type AuthsignalOptions = {
52
52
  cookieName?: string;
53
53
  baseUrl?: string;
54
54
  tenantId: string;
55
+ onTokenExpired?: () => void;
55
56
  };
56
57
  export declare enum AuthsignalWindowMessage {
57
58
  AUTHSIGNAL_CLOSE_POPUP = "AUTHSIGNAL_CLOSE_POPUP"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authsignal/browser",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",