@passflow/core 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import F from "axios";
2
- import { v4 as X } from "uuid";
3
- import { startAuthentication as W, startRegistration as J } from "@simplewebauthn/browser";
4
- const Z = "0.14.0", Q = {
5
- version: Z
6
- }, b = "X-Passflow-Clientid", I = "Authorization", ee = "X-Passflow-DeviceId", te = "X-Passflow-DeviceType", re = Q.version, Qe = ["id", "offline", "openid"], se = ["id", "offline", "tenant", "email", "oidc", "openid", "access:tenant:all"], G = "https://auth.passflow.cloud", et = "default", ie = 500, oe = 600, ne = 100, ae = 6e4, V = 30, ce = 3, he = 30, de = 200, ue = (i) => {
1
+ import M from "axios";
2
+ import { v4 as te } from "uuid";
3
+ import { startAuthentication as re, startRegistration as se } from "@simplewebauthn/browser";
4
+ const ie = "0.14.1", oe = {
5
+ version: ie
6
+ }, A = "X-Passflow-Clientid", I = "Authorization", ne = "X-Passflow-DeviceId", ae = "X-Passflow-DeviceType", ce = oe.version, gt = ["id", "offline", "openid"], he = ["id", "offline", "tenant", "email", "oidc", "openid", "access:tenant:all"], Y = "https://auth.passflow.cloud", ft = "default", de = 500, ue = 600, le = 100, pe = 6e4, j = 30, ge = 3, fe = 30, ke = 200, me = (i) => {
7
7
  const e = [];
8
8
  let t;
9
9
  for (t in i) {
@@ -18,14 +18,14 @@ const Z = "0.14.0", Q = {
18
18
  }
19
19
  return { raw: i, tenants: e };
20
20
  };
21
- function le(i) {
21
+ function ve(i) {
22
22
  if (typeof window < "u" && typeof window.atob == "function")
23
23
  return window.atob(i);
24
24
  if (typeof Buffer < "u")
25
25
  return Buffer.from(i, "base64").toString("utf-8");
26
26
  throw new Error("No Base64 decoding method available in this environment");
27
27
  }
28
- class pe {
28
+ class ye {
29
29
  constructor(e) {
30
30
  this.storageManager = e;
31
31
  }
@@ -54,19 +54,19 @@ class pe {
54
54
  return m(t);
55
55
  }
56
56
  }
57
- function y(i, e = V) {
57
+ function y(i, e = j) {
58
58
  return Math.floor(Date.now() / 1e3) + e > i.exp;
59
59
  }
60
60
  function m(i) {
61
61
  const e = i.split(".")[1];
62
62
  if (!e) throw new Error("Invalid token string");
63
- const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = t + "=".repeat((4 - t.length % 4) % 4), s = le(r), o = decodeURIComponent(
63
+ const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = t + "=".repeat((4 - t.length % 4) % 4), s = ve(r), o = decodeURIComponent(
64
64
  s.split("").map((h) => "%" + ("00" + h.charCodeAt(0).toString(16)).slice(-2)).join("")
65
65
  ), n = JSON.parse(o);
66
- return n.membership = n.passflow_tm && n.type !== "invite" ? ue(n.passflow_tm) : void 0, n;
66
+ return n.membership = n.passflow_tm && n.type !== "invite" ? me(n.passflow_tm) : void 0, n;
67
67
  }
68
- var k = /* @__PURE__ */ ((i) => (i.id_token = "id_token", i.access_token = "access", i.refresh_token = "refresh", i.invite_token = "invite", i.reset_token = "reset", i.web_cookie = "web-cookie", i.management = "management", i.signin = "signin", i.actor = "actor", i.two_factor = "2fa", i))(k || {}), v = /* @__PURE__ */ ((i) => (i.JsonBody = "json_body", i.Cookie = "cookie", i.Mobile = "mobile", i.BFF = "bff", i))(v || {}), q = /* @__PURE__ */ ((i) => (i.Unknown = "unknown", i.Valid = "valid", i.Invalid = "invalid", i))(q || {});
69
- class B {
68
+ var k = /* @__PURE__ */ ((i) => (i.id_token = "id_token", i.access_token = "access", i.refresh_token = "refresh", i.invite_token = "invite", i.reset_token = "reset", i.web_cookie = "web-cookie", i.management = "management", i.signin = "signin", i.actor = "actor", i.two_factor = "2fa", i))(k || {}), v = /* @__PURE__ */ ((i) => (i.JsonBody = "json_body", i.Cookie = "cookie", i.Mobile = "mobile", i.BFF = "bff", i))(v || {}), H = /* @__PURE__ */ ((i) => (i.Unknown = "unknown", i.Valid = "valid", i.Invalid = "invalid", i))(H || {});
69
+ class z {
70
70
  constructor(e) {
71
71
  this.storageManager = e, this.mode = "json_body", this.sessionState = "unknown", this.isInitializedFlag = !1, this.STORAGE_PREFIX = "passflow_", this.DELIVERY_MODE_KEY = `${this.STORAGE_PREFIX}delivery_mode`, this.SESSION_STATE_KEY = `${this.STORAGE_PREFIX}session_state`, this.loadPersistedMode(), this.loadPersistedSessionState();
72
72
  }
@@ -176,7 +176,7 @@ class B {
176
176
  loadPersistedSessionState() {
177
177
  try {
178
178
  const e = this.storageManager.storage.getItem(this.SESSION_STATE_KEY);
179
- e && Object.values(q).includes(e) && (this.sessionState = e);
179
+ e && Object.values(H).includes(e) && (this.sessionState = e);
180
180
  } catch {
181
181
  }
182
182
  }
@@ -217,7 +217,7 @@ class B {
217
217
  }
218
218
  }
219
219
  }
220
- class $ {
220
+ class L {
221
221
  constructor({ storage: e, prefix: t } = {}) {
222
222
  this.keyStoragePrefix = "", this.scopes = `${this.keyStoragePrefix}tokens_scopes`, this.deviceId = `${this.keyStoragePrefix}passflowDeviceId`, this.invitationToken = `${this.keyStoragePrefix}passflowInvitationToken`, this.previousRedirectUrl = `${this.keyStoragePrefix}passflowPreviousRedirectUrl`, this.STORAGE_PREFIX = "passflow_", this.ID_TOKEN_KEY = `${this.STORAGE_PREFIX}id_token`, this.CSRF_TOKEN_KEY = `${this.STORAGE_PREFIX}csrf_token`, this.DELIVERY_MODE_KEY = `${this.STORAGE_PREFIX}delivery_mode`, this.storage = e ?? localStorage, this.keyStoragePrefix = t ? `${t}_` : "";
223
223
  }
@@ -400,9 +400,9 @@ class $ {
400
400
  return `${this.keyStoragePrefix}${e}`;
401
401
  }
402
402
  }
403
- class Y {
403
+ class X {
404
404
  constructor(e) {
405
- this.storageManager = e ?? new $();
405
+ this.storageManager = e ?? new L();
406
406
  }
407
407
  getDeviceId() {
408
408
  const e = this.storageManager.getDeviceId();
@@ -413,19 +413,19 @@ class Y {
413
413
  return e;
414
414
  }
415
415
  generateUniqueDeviceId() {
416
- return X();
416
+ return te();
417
417
  }
418
418
  }
419
- class j extends Error {
419
+ class W extends Error {
420
420
  constructor(e = "Authentication popup was closed") {
421
421
  super(e), this.name = "PopupClosedError";
422
422
  }
423
423
  }
424
- class ge {
424
+ class Se {
425
425
  constructor() {
426
426
  this.passkeys = {
427
- startRegistration: (e) => J({ optionsJSON: e }),
428
- startAuthentication: (e) => W({ optionsJSON: e })
427
+ startRegistration: (e) => se({ optionsJSON: e }),
428
+ startAuthentication: (e) => re({ optionsJSON: e })
429
429
  };
430
430
  }
431
431
  // ----------------------------------------------------------------
@@ -557,25 +557,25 @@ class ge {
557
557
  'openAuthUrl: "deeplink" mode is not supported on web. Use "popup" or "redirect" instead, or provide a native platform adapter.'
558
558
  )
559
559
  );
560
- const s = t.width ?? ie, o = t.height ?? oe, n = t.expectedReturnOrigin ?? window.location.origin, h = window.open(e, "_blank", `width=${s},height=${o}`);
560
+ const s = t.width ?? de, o = t.height ?? ue, n = t.expectedReturnOrigin ?? window.location.origin, h = window.open(e, "_blank", `width=${s},height=${o}`);
561
561
  return h ? new Promise((d, u) => {
562
562
  const g = Date.now(), f = setInterval(() => {
563
563
  if (h.closed) {
564
- clearInterval(f), u(new j());
564
+ clearInterval(f), u(new W());
565
565
  return;
566
566
  }
567
- if (Date.now() - g > ae) {
567
+ if (Date.now() - g > pe) {
568
568
  clearInterval(f), h.close(), u(new Error("Authentication popup timed out"));
569
569
  return;
570
570
  }
571
571
  try {
572
572
  if (h.location.href.startsWith(n)) {
573
- const M = h.location.search, z = h.location.hash;
574
- clearInterval(f), h.close(), d({ callbackSearch: M, callbackHash: z });
573
+ const D = h.location.search, ee = h.location.hash;
574
+ clearInterval(f), h.close(), d({ callbackSearch: D, callbackHash: ee });
575
575
  }
576
576
  } catch {
577
577
  }
578
- }, ne);
578
+ }, le);
579
579
  }) : (window.location.href = e, new Promise(() => {
580
580
  }));
581
581
  }
@@ -633,62 +633,62 @@ class ge {
633
633
  return "web";
634
634
  }
635
635
  }
636
- const A = new ge(), fe = "insufficient_user_authentication", ke = "upgrade_required", L = /([A-Za-z0-9!#$%&'*+\-.^_`|~]+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,]*))/g, me = (i) => i.replace(/\\(.)/g, "$1"), ve = (i) => {
636
+ const C = new Se(), we = "insufficient_user_authentication", Te = "upgrade_required", K = /([A-Za-z0-9!#$%&'*+\-.^_`|~]+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,]*))/g, Ee = (i) => i.replace(/\\(.)/g, "$1"), _e = (i) => {
637
637
  const e = {};
638
- L.lastIndex = 0;
639
- for (const t of i.matchAll(L)) {
638
+ K.lastIndex = 0;
639
+ for (const t of i.matchAll(K)) {
640
640
  const r = t[1];
641
641
  if (!r)
642
642
  continue;
643
643
  const s = t[2], o = t[3];
644
- e[r.toLowerCase()] = s !== void 0 ? me(s) : o ?? "";
644
+ e[r.toLowerCase()] = s !== void 0 ? Ee(s) : o ?? "";
645
645
  }
646
646
  return e;
647
- }, H = (i) => {
647
+ }, J = (i) => {
648
648
  const e = typeof i == "number" ? i : Number.parseInt(String(i ?? ""), 10);
649
649
  return Number.isFinite(e) && e > 0 ? e : void 0;
650
- }, ye = (i, e) => {
650
+ }, Ie = (i, e) => {
651
651
  if (!i || !/(^|[\s,])Bearer\b/i.test(i))
652
652
  return;
653
- const t = ve(i);
654
- if (t.error === fe)
653
+ const t = _e(i);
654
+ if (t.error === we)
655
655
  return {
656
656
  acrValues: t.acr_values || void 0,
657
- maxAge: H(t.max_age),
657
+ maxAge: J(t.max_age),
658
658
  status: e
659
659
  };
660
- }, Se = (i, e) => {
660
+ }, be = (i, e) => {
661
661
  if (!i || typeof i != "object")
662
662
  return;
663
663
  const t = i;
664
- if (t.error === ke)
664
+ if (t.error === Te)
665
665
  return {
666
666
  acrValues: typeof t.acr_values == "string" && t.acr_values ? t.acr_values : void 0,
667
- maxAge: H(t.max_age),
667
+ maxAge: J(t.max_age),
668
668
  status: e
669
669
  };
670
- }, we = (i, e, t) => {
670
+ }, Ae = (i, e, t) => {
671
671
  if (!(i !== 401 && i !== 403))
672
- return ye(e("www-authenticate"), i) ?? Se(t, i);
672
+ return Ie(e("www-authenticate"), i) ?? be(t, i);
673
673
  };
674
- var E = /* @__PURE__ */ ((i) => (i.GET = "get", i.POST = "post", i.PUT = "put", i.PATCH = "patch", i.DELETE = "delete", i))(E || {}), c = /* @__PURE__ */ ((i) => (i.signin = "/auth/login", i.signup = "/auth/register", i.signInWithProvider = "/auth/federated/start/", i.passwordless = "/auth/passwordless/start", i.passwordlessComplete = "/auth/passwordless/complete", i.logout = "/user/logout", i.refresh = "/auth/refresh", i.validateSession = "/user/me", i.sendPasswordResetEmail = "/auth/password/reset", i.resetPassword = "/auth/password/change", i.appSettings = "/app/settings", i.passkeyRegisterStart = "/auth/passkey/register/start", i.passkeyRegisterComplete = "/auth/passkey/register/complete", i.passkeyAuthenticateStart = "/auth/passkey/authenticate/start", i.passkeyAuthenticateComplete = "/auth/passkey/authenticate/complete", i.passkeyValidate = "/auth/validate", i.settingsAll = "/settings", i.settingsPasswordPolicy = "/settings/password", i.settingsPasskey = "/settings/passkey", i.userPasskey = "/user/passkey", i.addUserPasskey = "/user/passkey/add/start", i.completeAddUserPasskey = "/user/passkey/add/complete", i.joinInvitation = "/user/tenant/join", i.tenantPath = "/user/tenant", i.invitationsPath = "/user/tenant/:tenantID/invitations", i.requestInvitation = "/user/invite", i.invitationDelete = "/user/invite/:invitationID", i.invitationResend = "/user/invite/:invitationID/resend", i.invitationGetLink = "/user/invite/:invitationID/link", i.twoFactor = "/user/2fa", i.twoFactorStatus = "/user/2fa/status", i.twoFactorSetupBegin = "/user/2fa/setup/begin", i.twoFactorSetupConfirm = "/user/2fa/setup/confirm", i.twoFactorVerify = "/auth/2fa/verify", i.twoFactorRecovery = "/auth/2fa/recovery", i.twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate", i.twoFactorSetupMagicLink = "/auth/2fa-setup", i.TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available", i.TwoFactorMethodsRegistered = "/v2/user/2fa/methods", i.TwoFactorSetupStart = "/v2/user/2fa/setup/start", i.TwoFactorSetupComplete = "/v2/user/2fa/setup/complete", i.TwoFactorMethodRemove = "/v2/user/2fa/methods/:id", i.TwoFactorChallenge = "/v2/auth/2fa/challenge", i.TwoFactorVerifyV2 = "/v2/auth/2fa/verify", i.TwoFactorAlternative = "/v2/auth/2fa/alternative", i.TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices", i.TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id", i.cliAuthStatus = "/cli/auth/status/:sessionId", i.cliAuthComplete = "/cli/auth/complete", i))(c || {}), T = /* @__PURE__ */ ((i) => (i.passkeyRegisterStart = "/admin/auth/passkey/register/start", i.passkeyRegisterComplete = "/admin/auth/passkey/register/complete", i.passkeyAuthenticateStart = "/admin/auth/passkey/authenticate/start", i.passkeyAuthenticateComplete = "/admin/auth/passkey/authenticate/complete", i.passkeyValidate = "/admin/auth/validate", i.logout = "/admin/auth/logout", i))(T || {});
674
+ var _ = /* @__PURE__ */ ((i) => (i.GET = "get", i.POST = "post", i.PUT = "put", i.PATCH = "patch", i.DELETE = "delete", i))(_ || {}), c = /* @__PURE__ */ ((i) => (i.signin = "/auth/login", i.signup = "/auth/register", i.signInWithProvider = "/auth/federated/start/", i.passwordless = "/auth/passwordless/start", i.passwordlessComplete = "/auth/passwordless/complete", i.logout = "/user/logout", i.refresh = "/auth/refresh", i.validateSession = "/user/me", i.sendPasswordResetEmail = "/auth/password/reset", i.resetPassword = "/auth/password/change", i.appSettings = "/app/settings", i.passkeyRegisterStart = "/auth/passkey/register/start", i.passkeyRegisterComplete = "/auth/passkey/register/complete", i.passkeyAuthenticateStart = "/auth/passkey/authenticate/start", i.passkeyAuthenticateComplete = "/auth/passkey/authenticate/complete", i.passkeyValidate = "/auth/validate", i.settingsAll = "/settings", i.settingsPasswordPolicy = "/settings/password", i.settingsPasskey = "/settings/passkey", i.userPasskey = "/user/passkey", i.addUserPasskey = "/user/passkey/add/start", i.completeAddUserPasskey = "/user/passkey/add/complete", i.joinInvitation = "/user/tenant/join", i.tenantPath = "/user/tenant", i.invitationsPath = "/user/tenant/:tenantID/invitations", i.requestInvitation = "/user/invite", i.invitationDelete = "/user/invite/:invitationID", i.invitationResend = "/user/invite/:invitationID/resend", i.invitationGetLink = "/user/invite/:invitationID/link", i.twoFactor = "/user/2fa", i.twoFactorStatus = "/user/2fa/status", i.twoFactorSetupBegin = "/user/2fa/setup/begin", i.twoFactorSetupConfirm = "/user/2fa/setup/confirm", i.twoFactorVerify = "/auth/2fa/verify", i.twoFactorRecovery = "/auth/2fa/recovery", i.twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate", i.twoFactorSetupMagicLink = "/auth/2fa-setup", i.TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available", i.TwoFactorMethodsRegistered = "/v2/user/2fa/methods", i.TwoFactorSetupStart = "/v2/user/2fa/setup/start", i.TwoFactorSetupComplete = "/v2/user/2fa/setup/complete", i.TwoFactorMethodRemove = "/v2/user/2fa/methods/:id", i.TwoFactorChallenge = "/v2/auth/2fa/challenge", i.TwoFactorVerifyV2 = "/v2/auth/2fa/verify", i.TwoFactorAlternative = "/v2/auth/2fa/alternative", i.TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices", i.TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id", i.cliAuthStatus = "/cli/auth/status/:sessionId", i.cliAuthComplete = "/cli/auth/complete", i))(c || {}), T = /* @__PURE__ */ ((i) => (i.passkeyRegisterStart = "/admin/auth/passkey/register/start", i.passkeyRegisterComplete = "/admin/auth/passkey/register/complete", i.passkeyAuthenticateStart = "/admin/auth/passkey/authenticate/start", i.passkeyAuthenticateComplete = "/admin/auth/passkey/authenticate/complete", i.passkeyValidate = "/admin/auth/validate", i.logout = "/admin/auth/logout", i))(T || {});
675
675
  class l extends Error {
676
676
  constructor(e) {
677
677
  super(), this.id = e?.id ?? "unknown", this.message = e?.message ?? e ?? "Something went wrong", this.status = e?.status ?? 500, this.location = e?.location ?? "unknown", this.time = e?.time ?? (/* @__PURE__ */ new Date()).toISOString();
678
678
  }
679
679
  }
680
- var Te = /* @__PURE__ */ ((i) => (i.google = "google", i.facebook = "facebook", i))(Te || {}), _e = /* @__PURE__ */ ((i) => (i.web = "web", i.ios = "ios", i.android = "android", i))(_e || {});
681
- function tt(i) {
680
+ var Ce = /* @__PURE__ */ ((i) => (i.google = "google", i.facebook = "facebook", i))(Ce || {}), Re = /* @__PURE__ */ ((i) => (i.web = "web", i.ios = "ios", i.android = "android", i))(Re || {});
681
+ function kt(i) {
682
682
  return i;
683
683
  }
684
- function _(i, e) {
684
+ function E(i, e) {
685
685
  let t = i;
686
686
  return Object.entries(e).forEach(([r, s]) => {
687
687
  t = t.replace(`:${r}`, s);
688
688
  }), t;
689
689
  }
690
- var Ee = /* @__PURE__ */ ((i) => (i.Disabled = "disabled", i.Optional = "optional", i.Required = "required", i))(Ee || {});
691
- const Ie = 3, be = 1e3, Ae = (i) => we(
690
+ var Fe = /* @__PURE__ */ ((i) => (i.Disabled = "disabled", i.Optional = "optional", i.Required = "required", i))(Fe || {});
691
+ const Me = 3, De = 1e3, Pe = (i) => Ae(
692
692
  i.status,
693
693
  (e) => {
694
694
  const t = i.headers?.[e] ?? i.headers?.[e.toLowerCase()];
@@ -703,18 +703,18 @@ class S {
703
703
  "Content-Type": "application/json"
704
704
  }, this.nonAccessTokenEndpoints = ["/auth/", "/settings", "/settings/"], this.protectedEndpoints = ["logout", "refresh"];
705
705
  const { url: s, appId: o, keyStoragePrefix: n } = e;
706
- this._platform = e.platform ?? A, this.url = s || G, this.storageManager = t ?? new $({
706
+ this._platform = e.platform ?? C, this.url = s || Y, this.storageManager = t ?? new L({
707
707
  prefix: n ?? ""
708
- }), this.deviceService = r ?? new Y(this.storageManager), this.tokenService = new pe(this.storageManager), this.tokenDeliveryManager = new B(this.storageManager), o && (this.appId = o, this.defaultHeaders = {
708
+ }), this.deviceService = r ?? new X(this.storageManager), this.tokenService = new ye(this.storageManager), this.tokenDeliveryManager = new z(this.storageManager), o && (this.appId = o, this.defaultHeaders = {
709
709
  ...this.defaultHeaders,
710
- [b]: o
710
+ [A]: o
711
711
  });
712
712
  const h = this.deviceService.getDeviceId();
713
713
  this.defaultHeaders = {
714
714
  ...this.defaultHeaders,
715
- [ee]: h,
716
- [te]: this._platform.getDeviceType()
717
- }, this.detectCookieSupport(), this.instance = F.create({
715
+ [ne]: h,
716
+ [ae]: this._platform.getDeviceType()
717
+ }, this.detectCookieSupport(), this.instance = M.create({
718
718
  baseURL: this.url,
719
719
  headers: { ...this.defaultHeaders }
720
720
  }), this.instance.interceptors.request.use(async (d) => {
@@ -735,7 +735,7 @@ class S {
735
735
  const u = this.storageManager.getTokens();
736
736
  if (u?.access_token) {
737
737
  const g = m(u.access_token);
738
- if (y(g, V) && u.refresh_token)
738
+ if (y(g, j) && u.refresh_token)
739
739
  try {
740
740
  if (this.refreshPromise) {
741
741
  const f = await this.refreshPromise;
@@ -756,7 +756,7 @@ class S {
756
756
  return d;
757
757
  }), this.instance.interceptors.response.use(
758
758
  (d) => d,
759
- async (d) => (d.response?.status === 401 && !Ae(d.response) && this.tokenDeliveryManager.setSessionInvalid(), d.response?.status === 429 ? await this.handleRateLimitError(d) : this.handleAxiosError(d))
759
+ async (d) => (d.response?.status === 401 && !Pe(d.response) && this.tokenDeliveryManager.setSessionInvalid(), d.response?.status === 429 ? await this.handleRateLimitError(d) : this.handleAxiosError(d))
760
760
  );
761
761
  }
762
762
  get origin() {
@@ -820,9 +820,9 @@ class S {
820
820
  if (!["GET", "HEAD", "OPTIONS"].includes(r || ""))
821
821
  return Promise.reject(e);
822
822
  const o = t._retryCount || 0;
823
- if (o >= Ie)
823
+ if (o >= Me)
824
824
  return Promise.reject(e);
825
- let n = be * Math.pow(2, o);
825
+ let n = De * Math.pow(2, o);
826
826
  const h = e.response?.headers?.["retry-after"];
827
827
  if (h) {
828
828
  const d = Number.parseInt(h, 10);
@@ -863,19 +863,19 @@ class S {
863
863
  })).data;
864
864
  }
865
865
  get(e, t) {
866
- return this.send(E.GET, e, t);
866
+ return this.send(_.GET, e, t);
867
867
  }
868
868
  post(e, t, r) {
869
- return this.send(E.POST, e, { data: t, ...r });
869
+ return this.send(_.POST, e, { data: t, ...r });
870
870
  }
871
871
  put(e, t, r) {
872
- return this.send(E.PUT, e, { data: t, ...r });
872
+ return this.send(_.PUT, e, { data: t, ...r });
873
873
  }
874
874
  patch(e, t, r) {
875
- return this.send(E.PATCH, e, { data: t, ...r });
875
+ return this.send(_.PATCH, e, { data: t, ...r });
876
876
  }
877
877
  delete(e, t) {
878
- return this.send(E.DELETE, e, t);
878
+ return this.send(_.DELETE, e, t);
879
879
  }
880
880
  /**
881
881
  * Update the appId and propagate it to axios headers.
@@ -886,11 +886,11 @@ class S {
886
886
  setAppId(e) {
887
887
  this.appId = e, this.defaultHeaders = {
888
888
  ...this.defaultHeaders,
889
- [b]: e
890
- }, this.instance.defaults.headers.common[b] = e;
889
+ [A]: e
890
+ }, this.instance.defaults.headers.common[A] = e;
891
891
  }
892
892
  }
893
- class Ce {
893
+ class xe {
894
894
  constructor(e, t, r) {
895
895
  this.axiosClient = new S(e, t, r);
896
896
  }
@@ -901,7 +901,7 @@ class Ce {
901
901
  return this.axiosClient.get(c.appSettings);
902
902
  }
903
903
  }
904
- class Re {
904
+ class Ue {
905
905
  constructor(e, t, r) {
906
906
  this.axiosClient = new S(e, t, r);
907
907
  }
@@ -980,7 +980,7 @@ class Re {
980
980
  return this.axiosClient.post(c.resetPassword, s, {
981
981
  headers: {
982
982
  [I]: `Bearer ${r}`,
983
- [b]: void 0
983
+ [A]: void 0
984
984
  }
985
985
  });
986
986
  }
@@ -1029,11 +1029,11 @@ class Re {
1029
1029
  };
1030
1030
  let h = c.passkeyValidate;
1031
1031
  !o && s && (h = T.passkeyValidate);
1032
- const d = o ? { [b]: o } : {};
1032
+ const d = o ? { [A]: o } : {};
1033
1033
  return this.axiosClient.post(h, n, { headers: d });
1034
1034
  }
1035
1035
  }
1036
- class rt {
1036
+ class mt {
1037
1037
  constructor(e, t, r) {
1038
1038
  this.axiosClient = new S(e, t, r);
1039
1039
  }
@@ -1041,14 +1041,14 @@ class rt {
1041
1041
  this.axiosClient.setAppId(e);
1042
1042
  }
1043
1043
  getCLIAuthStatus(e) {
1044
- const t = _(c.cliAuthStatus, { sessionId: e });
1044
+ const t = E(c.cliAuthStatus, { sessionId: e });
1045
1045
  return this.axiosClient.get(t);
1046
1046
  }
1047
1047
  completeCLIAuth(e) {
1048
1048
  return this.axiosClient.post(c.cliAuthComplete, e);
1049
1049
  }
1050
1050
  }
1051
- class Fe {
1051
+ class $e {
1052
1052
  constructor(e, t, r) {
1053
1053
  this.axiosClient = new S(e, t, r);
1054
1054
  }
@@ -1074,7 +1074,7 @@ class Fe {
1074
1074
  getInvitations(e) {
1075
1075
  const t = {};
1076
1076
  e.groupID && (t.group_id = e.groupID.toString()), e.skip !== void 0 && (t.skip = e.skip.toString()), e.limit !== void 0 && (t.limit = e.limit.toString());
1077
- const r = _(c.invitationsPath, {
1077
+ const r = E(c.invitationsPath, {
1078
1078
  tenantID: e.tenantID
1079
1079
  });
1080
1080
  return this.axiosClient.get(r, { params: t }).then((s) => ({
@@ -1088,7 +1088,7 @@ class Fe {
1088
1088
  * @returns Promise with success response
1089
1089
  */
1090
1090
  deleteInvitation(e) {
1091
- const t = _(c.invitationDelete, {
1091
+ const t = E(c.invitationDelete, {
1092
1092
  invitationID: e
1093
1093
  });
1094
1094
  return this.axiosClient.delete(t);
@@ -1099,7 +1099,7 @@ class Fe {
1099
1099
  * @returns Promise with success response
1100
1100
  */
1101
1101
  resendInvitation(e) {
1102
- const t = _(c.invitationResend, {
1102
+ const t = E(c.invitationResend, {
1103
1103
  invitationID: e
1104
1104
  });
1105
1105
  return this.axiosClient.post(t, {});
@@ -1110,13 +1110,13 @@ class Fe {
1110
1110
  * @returns Promise with the link
1111
1111
  */
1112
1112
  getInvitationLink(e) {
1113
- const t = _(c.invitationGetLink, {
1113
+ const t = E(c.invitationGetLink, {
1114
1114
  invitationID: e
1115
1115
  });
1116
1116
  return this.axiosClient.get(t);
1117
1117
  }
1118
1118
  }
1119
- class Me {
1119
+ class Oe {
1120
1120
  constructor(e, t, r) {
1121
1121
  this.axiosClient = new S(e, t, r);
1122
1122
  }
@@ -1133,7 +1133,7 @@ class Me {
1133
1133
  return this.axiosClient.get(c.settingsPasskey);
1134
1134
  }
1135
1135
  }
1136
- class De {
1136
+ class Le {
1137
1137
  constructor(e, t, r) {
1138
1138
  this.axiosClient = new S(e, t, r);
1139
1139
  }
@@ -1366,7 +1366,7 @@ class De {
1366
1366
  return this.axiosClient.delete(s);
1367
1367
  }
1368
1368
  }
1369
- class Pe {
1369
+ class Ne {
1370
1370
  constructor(e, t, r) {
1371
1371
  this.axiosClient = new S(e, t, r);
1372
1372
  }
@@ -1580,7 +1580,7 @@ class Pe {
1580
1580
  * DELETE /v2/user/2fa/methods/:id
1581
1581
  */
1582
1582
  removeMethod(e) {
1583
- const t = _(c.TwoFactorMethodRemove, { id: e });
1583
+ const t = E(c.TwoFactorMethodRemove, { id: e });
1584
1584
  return this.axiosClient.delete(t);
1585
1585
  }
1586
1586
  /**
@@ -1625,11 +1625,11 @@ class Pe {
1625
1625
  * DELETE /v2/user/2fa/trusted-devices/:id
1626
1626
  */
1627
1627
  revokeTrustedDevice(e) {
1628
- const t = _(c.TwoFactorTrustedDeviceRevoke, { id: e });
1628
+ const t = E(c.TwoFactorTrustedDeviceRevoke, { id: e });
1629
1629
  return this.axiosClient.delete(t);
1630
1630
  }
1631
1631
  }
1632
- class xe {
1632
+ class Ke {
1633
1633
  constructor(e, t, r) {
1634
1634
  this.axiosClient = new S(e, t, r);
1635
1635
  }
@@ -1675,7 +1675,7 @@ class xe {
1675
1675
  }
1676
1676
  }
1677
1677
  var a = /* @__PURE__ */ ((i) => (i.SignIn = "signin", i.SignInStart = "signin:start", i.Register = "register", i.RegisterStart = "register:start", i.SignOut = "signout", i.SessionRestored = "session:restored", i.SessionExpired = "session:expired", i.Error = "error", i.Refresh = "refresh", i.RefreshStart = "refresh:start", i.TokenCacheExpired = "token-cache-expired", i.TwoFactorRequired = "2fa:required", i.TwoFactorSetupStarted = "2fa:setup_started", i.TwoFactorEnabled = "2fa:enabled", i.TwoFactorDisabled = "2fa:disabled", i.TwoFactorVerified = "2fa:verified", i.TwoFactorRecoveryUsed = "2fa:recovery_used", i.TwoFactorRecoveryCodesLow = "2fa:recovery_low", i.TwoFactorRecoveryCodesExhausted = "2fa:recovery_exhausted", i.TwoFactorSetupMagicLinkValidated = "2fa:magic_link_validated", i.TwoFactorSetupMagicLinkFailed = "2fa:magic_link_failed", i.TwoFactorChallengeReceived = "two_factor_challenge_received", i.TwoFactorMethodSwitched = "two_factor_method_switched", i.TwoFactorDeviceTrusted = "two_factor_device_trusted", i))(a || {});
1678
- class Ue {
1678
+ class Ge {
1679
1679
  constructor() {
1680
1680
  this.subscribers = /* @__PURE__ */ new Map();
1681
1681
  }
@@ -1715,42 +1715,42 @@ class Ue {
1715
1715
  });
1716
1716
  }
1717
1717
  }
1718
- function D(i) {
1718
+ function P(i) {
1719
1719
  if (!i || typeof i != "string") return !1;
1720
1720
  const e = i.split(".");
1721
1721
  if (e.length !== 3) return !1;
1722
1722
  const t = /^[A-Za-z0-9_-]+$/;
1723
1723
  return e.every((r) => t.test(r) && r.length > 0);
1724
1724
  }
1725
- function $e(i) {
1726
- return i.replace(/<[^>]*>/g, "").substring(0, de);
1725
+ function Ve(i) {
1726
+ return i.replace(/<[^>]*>/g, "").substring(0, ke);
1727
1727
  }
1728
- function P(i) {
1728
+ function x(i) {
1729
1729
  if (!i || typeof i != "string") return !1;
1730
1730
  const e = i.trim();
1731
1731
  return e.length === 0 ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
1732
1732
  }
1733
- function x(i) {
1733
+ function U(i) {
1734
1734
  if (!i || typeof i != "string") return !1;
1735
1735
  const e = i.trim();
1736
1736
  return /^\+[1-9]\d{1,14}$/.test(e);
1737
1737
  }
1738
- function Oe(i) {
1738
+ function qe(i) {
1739
1739
  if (!i || typeof i != "string") return !1;
1740
1740
  const e = i.trim();
1741
- return e.length < ce || e.length > he ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
1741
+ return e.length < ge || e.length > fe ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
1742
1742
  }
1743
- function C(i, e = 6) {
1743
+ function R(i, e = 6) {
1744
1744
  return !i || typeof i != "string" ? !1 : (e === 8 ? /^\d{8}$/ : /^\d{6}$/).test(i);
1745
1745
  }
1746
- function Le(i) {
1746
+ function Be(i) {
1747
1747
  if (!i || typeof i != "string") return null;
1748
1748
  const e = i.toUpperCase().replace(/\s+/g, "");
1749
1749
  return /^[A-Z0-9-]{4,16}$/.test(e) ? e : null;
1750
1750
  }
1751
- class Ne {
1752
- constructor(e, t, r, s, o, n, h, d, u, g, f, M = A) {
1753
- this.authApi = e, this.deviceService = t, this.storageManager = r, this.subscribeStore = s, this.tokenCacheService = o, this.scopes = n, this.createTenantForNewUser = h, this.url = d, this.sessionCallbacks = u, this.appId = g, this.platform = M, this.tokenExchangeConfig = f, this.tokenDeliveryManager = new B(r), f?.enabled && this.tokenDeliveryManager.setMode(v.BFF), this.initializeSession();
1751
+ class Ye {
1752
+ constructor(e, t, r, s, o, n, h, d, u, g, f, D = C) {
1753
+ this.authApi = e, this.deviceService = t, this.storageManager = r, this.subscribeStore = s, this.tokenCacheService = o, this.scopes = n, this.createTenantForNewUser = h, this.url = d, this.sessionCallbacks = u, this.appId = g, this.platform = D, this.tokenExchangeConfig = f, this.tokenDeliveryManager = new z(r), f?.enabled && this.tokenDeliveryManager.setMode(v.BFF), this.initializeSession();
1754
1754
  }
1755
1755
  /**
1756
1756
  * Initialize session state on page load for cookie/BFF mode
@@ -1817,7 +1817,7 @@ class Ne {
1817
1817
  throw new Error(`BFF token storage failed: ${t.status}`);
1818
1818
  }
1819
1819
  async signIn(e) {
1820
- if ("email" in e && e.email && !P(e.email)) {
1820
+ if ("email" in e && e.email && !x(e.email)) {
1821
1821
  const s = new Error("Invalid email format"), o = {
1822
1822
  message: "Invalid email format",
1823
1823
  originalError: s,
@@ -1825,7 +1825,7 @@ class Ne {
1825
1825
  };
1826
1826
  throw this.subscribeStore.notify(a.Error, o), s;
1827
1827
  }
1828
- if ("username" in e && e.username && !Oe(e.username)) {
1828
+ if ("username" in e && e.username && !qe(e.username)) {
1829
1829
  const s = new Error(
1830
1830
  "Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"
1831
1831
  ), o = {
@@ -1835,7 +1835,7 @@ class Ne {
1835
1835
  };
1836
1836
  throw this.subscribeStore.notify(a.Error, o), s;
1837
1837
  }
1838
- if ("phone" in e && e.phone && !x(e.phone)) {
1838
+ if ("phone" in e && e.phone && !U(e.phone)) {
1839
1839
  const s = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), o = {
1840
1840
  message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
1841
1841
  originalError: s,
@@ -1866,7 +1866,7 @@ class Ne {
1866
1866
  }
1867
1867
  }
1868
1868
  async signUp(e) {
1869
- if (e.user.email && !P(e.user.email)) {
1869
+ if (e.user.email && !x(e.user.email)) {
1870
1870
  const t = new Error("Invalid email format"), r = {
1871
1871
  message: "Invalid email format",
1872
1872
  originalError: t,
@@ -1874,7 +1874,7 @@ class Ne {
1874
1874
  };
1875
1875
  throw this.subscribeStore.notify(a.Error, r), t;
1876
1876
  }
1877
- if (e.user.phone_number && !x(e.user.phone_number)) {
1877
+ if (e.user.phone_number && !U(e.user.phone_number)) {
1878
1878
  const t = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), r = {
1879
1879
  message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
1880
1880
  originalError: t,
@@ -1899,7 +1899,7 @@ class Ne {
1899
1899
  }
1900
1900
  }
1901
1901
  async passwordlessSignIn(e) {
1902
- if (e.email && !P(e.email)) {
1902
+ if (e.email && !x(e.email)) {
1903
1903
  const s = new Error("Invalid email format"), o = {
1904
1904
  message: "Invalid email format",
1905
1905
  originalError: s,
@@ -1907,7 +1907,7 @@ class Ne {
1907
1907
  };
1908
1908
  throw this.subscribeStore.notify(a.Error, o), s;
1909
1909
  }
1910
- if (e.phone && !x(e.phone)) {
1910
+ if (e.phone && !U(e.phone)) {
1911
1911
  const s = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), o = {
1912
1912
  message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
1913
1913
  originalError: s,
@@ -2032,13 +2032,13 @@ class Ne {
2032
2032
  message: r instanceof Error ? r.message : "Token refresh failed",
2033
2033
  originalError: r,
2034
2034
  code: r instanceof l ? r.id : void 0,
2035
- details: F.isAxiosError(r) && r.response ? {
2035
+ details: M.isAxiosError(r) && r.response ? {
2036
2036
  status: r.response.status,
2037
2037
  data: r.response.data
2038
2038
  } : void 0
2039
2039
  };
2040
2040
  this.subscribeStore.notify(a.Error, s);
2041
- const o = F.isAxiosError(r) && r.response?.status && r.response.status >= 400 && r.response.status < 500;
2041
+ const o = M.isAxiosError(r) && r.response?.status && r.response.status >= 400 && r.response.status < 500;
2042
2042
  throw o && (this.tokenCacheService.tokenExpiredFlag = !0, this.tokenCacheService.setTokensCache(void 0), this.storageManager.deleteTokens(), this.subscribeStore.notify(a.SessionExpired, { reason: "refresh_failed" })), r instanceof l ? r : o ? new Error(`Getting unknown error message from server with code:${r.response?.status}`) : r;
2043
2043
  }
2044
2044
  }
@@ -2161,7 +2161,7 @@ class Ne {
2161
2161
  } catch (o) {
2162
2162
  const n = {
2163
2163
  message: o instanceof Error ? o.message : "Authentication failed",
2164
- code: o instanceof j ? "POPUP_CLOSED" : "AUTH_FAILED",
2164
+ code: o instanceof W ? "POPUP_CLOSED" : "AUTH_FAILED",
2165
2165
  originalError: o
2166
2166
  };
2167
2167
  this.subscribeStore.notify(a.Error, n);
@@ -2262,7 +2262,7 @@ class Ne {
2262
2262
  }
2263
2263
  }
2264
2264
  }
2265
- class Ke {
2265
+ class je {
2266
2266
  constructor(e) {
2267
2267
  this.invitationApi = e;
2268
2268
  }
@@ -2307,7 +2307,7 @@ class Ke {
2307
2307
  return this.invitationApi.getInvitationLink(e);
2308
2308
  }
2309
2309
  }
2310
- class Ge {
2310
+ class He {
2311
2311
  error(e, ...t) {
2312
2312
  console.error(e, ...t);
2313
2313
  }
@@ -2321,10 +2321,10 @@ class Ge {
2321
2321
  console.debug(e, ...t);
2322
2322
  }
2323
2323
  }
2324
- function Ve() {
2325
- return new Ge();
2324
+ function ze() {
2325
+ return new He();
2326
2326
  }
2327
- class qe {
2327
+ class Xe {
2328
2328
  constructor(e) {
2329
2329
  this.data = this.normalize(e);
2330
2330
  }
@@ -2394,9 +2394,9 @@ class qe {
2394
2394
  return this.data;
2395
2395
  }
2396
2396
  }
2397
- class Be {
2397
+ class We {
2398
2398
  constructor(e, t, r) {
2399
- this.tenantApi = e, this.scopes = t, this.logger = r || Ve();
2399
+ this.tenantApi = e, this.scopes = t, this.logger = r || ze();
2400
2400
  }
2401
2401
  /**
2402
2402
  * Handle Passflow API errors
@@ -2405,7 +2405,7 @@ class Be {
2405
2405
  * @throws Formatted error with Passflow API error details
2406
2406
  */
2407
2407
  handlePassflowError(e, t) {
2408
- if (F.isAxiosError(e) && e.response?.data) {
2408
+ if (M.isAxiosError(e) && e.response?.data) {
2409
2409
  const r = e.response.data;
2410
2410
  if (typeof r == "object" && r !== null && "error" in r && typeof r.error == "object" && r.error !== null) {
2411
2411
  const s = r.error;
@@ -2466,7 +2466,7 @@ class Be {
2466
2466
  async getTenantUserMembership(e) {
2467
2467
  try {
2468
2468
  const t = await this.tenantApi.getTenantDetails(e);
2469
- return new qe(t);
2469
+ return new Xe(t);
2470
2470
  } catch (t) {
2471
2471
  this.handlePassflowError(t, `Get tenant user membership failed for tenant ID ${e}`);
2472
2472
  }
@@ -2764,8 +2764,8 @@ class Be {
2764
2764
  }
2765
2765
  }
2766
2766
  }
2767
- class Ye {
2768
- constructor(e, t, r, s = A) {
2767
+ class Je {
2768
+ constructor(e, t, r, s = C) {
2769
2769
  this.storageManager = e, this.authApi = t, this.subscribeStore = r, this.platform = s, this.checkInterval = null, this.CHECK_INTERVAL = 6e4, this.unsubscribeForeground = null, this.unsubscribeUnload = null, this.isRefreshing = !1, this.tokenExpiredFlag = !1, this.storageManager = e, this.authApi = t, this.setupLifecycleListeners();
2770
2770
  }
2771
2771
  initialize() {
@@ -2863,7 +2863,7 @@ class Ye {
2863
2863
  return y(e);
2864
2864
  }
2865
2865
  }
2866
- class je {
2866
+ class Ze {
2867
2867
  constructor(e, t) {
2868
2868
  this.twoFactorApi = e, this.subscribeStore = t, this.PARTIAL_AUTH_TIMEOUT_MS = 300 * 1e3, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6;
2869
2869
  const r = {
@@ -2916,7 +2916,7 @@ class je {
2916
2916
  * Returns recovery codes that MUST be displayed to user
2917
2917
  */
2918
2918
  async confirmSetup(e) {
2919
- if (!C(e, this.totpDigits))
2919
+ if (!R(e, this.totpDigits))
2920
2920
  throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
2921
2921
  try {
2922
2922
  const t = await this.twoFactorApi.confirmSetup({ code: e });
@@ -2935,7 +2935,7 @@ class je {
2935
2935
  * Completes authentication if successful
2936
2936
  */
2937
2937
  async verify(e) {
2938
- if (!C(e, this.totpDigits))
2938
+ if (!R(e, this.totpDigits))
2939
2939
  throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
2940
2940
  if (this.recoverPartialAuthState(), !this.isVerificationRequired())
2941
2941
  throw new Error("2FA verification expired or not required. User must sign in first.");
@@ -2957,7 +2957,7 @@ class je {
2957
2957
  */
2958
2958
  async useRecoveryCode(e) {
2959
2959
  try {
2960
- const t = Le(e);
2960
+ const t = Be(e);
2961
2961
  if (!t)
2962
2962
  throw new Error("Invalid recovery code format. Expected format: XXXX-XXXX or XXXXXXXX (alphanumeric).");
2963
2963
  if (this.recoverPartialAuthState(), !this.isVerificationRequired())
@@ -2983,7 +2983,7 @@ class je {
2983
2983
  * Disable 2FA (requires TOTP verification)
2984
2984
  */
2985
2985
  async disable(e) {
2986
- if (!C(e, this.totpDigits))
2986
+ if (!R(e, this.totpDigits))
2987
2987
  throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
2988
2988
  try {
2989
2989
  const t = await this.twoFactorApi.disable({ code: e });
@@ -2996,7 +2996,7 @@ class je {
2996
2996
  * Regenerate recovery codes
2997
2997
  */
2998
2998
  async regenerateRecoveryCodes(e) {
2999
- if (!C(e, this.totpDigits))
2999
+ if (!R(e, this.totpDigits))
3000
3000
  throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
3001
3001
  try {
3002
3002
  const t = await this.twoFactorApi.regenerateRecoveryCodes({ code: e }), r = [...t.recovery_codes];
@@ -3260,8 +3260,8 @@ class je {
3260
3260
  }
3261
3261
  }
3262
3262
  }
3263
- class He {
3264
- constructor(e, t, r = A) {
3263
+ class Qe {
3264
+ constructor(e, t, r = C) {
3265
3265
  this.userAPI = e, this.deviceService = t, this.platform = r;
3266
3266
  }
3267
3267
  /**
@@ -3312,7 +3312,7 @@ class He {
3312
3312
  return await this.userAPI.addUserPasskeyComplete(d, s, n);
3313
3313
  }
3314
3314
  }
3315
- const O = class O {
3315
+ const N = class N {
3316
3316
  constructor(e) {
3317
3317
  this.doRefreshTokens = !1, this.session = async ({
3318
3318
  createSession: o,
@@ -3322,10 +3322,10 @@ const O = class O {
3322
3322
  this.createSessionCallback = o, this.expiredSessionCallback = n, this.doRefreshTokens = h, await this.submitSessionCheck();
3323
3323
  };
3324
3324
  const { url: t, appId: r, scopes: s } = e;
3325
- this.url = t || G, this.appId = r, this.platform = e.platform ?? A, this.storageManager = new $({
3325
+ this.url = t || Y, this.appId = r, this.platform = e.platform ?? C, this.storageManager = new L({
3326
3326
  prefix: e.keyStoragePrefix ?? "",
3327
3327
  storage: this.platform.storage
3328
- }), this.deviceService = new Y(this.storageManager), this.authApi = new Re(e, this.storageManager, this.deviceService), this.appApi = new Ce(e, this.storageManager, this.deviceService), this.userApi = new xe(e, this.storageManager, this.deviceService), this.settingApi = new Me(e, this.storageManager, this.deviceService), this.tenantApi = new De(e, this.storageManager, this.deviceService), this.invitationApi = new Fe(e, this.storageManager, this.deviceService), this.twoFactorApi = new Pe(e, this.storageManager, this.deviceService), this.subscribeStore = new Ue(), this.tokenCacheService = new Ye(this.storageManager, this.authApi, this.subscribeStore, this.platform), this.scopes = s ?? se, this.createTenantForNewUser = e.createTenantForNewUser ?? !1, this.authService = new Ne(
3328
+ }), this.deviceService = new X(this.storageManager), this.authApi = new Ue(e, this.storageManager, this.deviceService), this.appApi = new xe(e, this.storageManager, this.deviceService), this.userApi = new Ke(e, this.storageManager, this.deviceService), this.settingApi = new Oe(e, this.storageManager, this.deviceService), this.tenantApi = new Le(e, this.storageManager, this.deviceService), this.invitationApi = new $e(e, this.storageManager, this.deviceService), this.twoFactorApi = new Ne(e, this.storageManager, this.deviceService), this.subscribeStore = new Ge(), this.tokenCacheService = new Je(this.storageManager, this.authApi, this.subscribeStore, this.platform), this.scopes = s ?? he, this.createTenantForNewUser = e.createTenantForNewUser ?? !1, this.authService = new Ye(
3329
3329
  this.authApi,
3330
3330
  this.deviceService,
3331
3331
  this.storageManager,
@@ -3341,7 +3341,7 @@ const O = class O {
3341
3341
  this.appId ?? "",
3342
3342
  e.tokenExchange,
3343
3343
  this.platform
3344
- ), this.userService = new He(this.userApi, this.deviceService, this.platform), this.tenantService = new Be(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new Ke(this.invitationApi), this.twoFactorService = new je(this.twoFactorApi, this.subscribeStore), this.twoFactor = this.twoFactorService, e.parseQueryParams && this.checkAndSetTokens(), this.setTokensToCacheFromLocalStorage();
3344
+ ), this.userService = new Qe(this.userApi, this.deviceService, this.platform), this.tenantService = new We(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new je(this.invitationApi), this.twoFactorService = new Ze(this.twoFactorApi, this.subscribeStore), this.twoFactor = this.twoFactorService, e.parseQueryParams && this.checkAndSetTokens(), this.setTokensToCacheFromLocalStorage();
3345
3345
  }
3346
3346
  get origin() {
3347
3347
  return this.platform.getCurrentUrl()?.origin ?? "";
@@ -3452,7 +3452,7 @@ const O = class O {
3452
3452
  const s = t.get("access_token"), o = t.get("refresh_token"), n = t.get("id_token"), h = t.get("scopes")?.split(",") ?? this.scopes;
3453
3453
  let d;
3454
3454
  if (s) {
3455
- if (!D(s)) {
3455
+ if (!P(s)) {
3456
3456
  const u = {
3457
3457
  message: "Invalid access token format received",
3458
3458
  code: "INVALID_TOKEN_FORMAT"
@@ -3460,7 +3460,7 @@ const O = class O {
3460
3460
  this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
3461
3461
  return;
3462
3462
  }
3463
- if (o && !D(o)) {
3463
+ if (o && !P(o)) {
3464
3464
  const u = {
3465
3465
  message: "Invalid refresh token format received",
3466
3466
  code: "INVALID_TOKEN_FORMAT"
@@ -3468,7 +3468,7 @@ const O = class O {
3468
3468
  this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
3469
3469
  return;
3470
3470
  }
3471
- if (n && !D(n)) {
3471
+ if (n && !P(n)) {
3472
3472
  const u = {
3473
3473
  message: "Invalid ID token format received",
3474
3474
  code: "INVALID_TOKEN_FORMAT"
@@ -3488,7 +3488,7 @@ const O = class O {
3488
3488
  checkErrorsFromURL() {
3489
3489
  const t = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
3490
3490
  if (t) {
3491
- const r = $e(t);
3491
+ const r = Ve(t);
3492
3492
  return new Error(r);
3493
3493
  }
3494
3494
  }
@@ -4672,8 +4672,8 @@ const O = class O {
4672
4672
  this.twoFactorService.clearMagicLinkSession();
4673
4673
  }
4674
4674
  };
4675
- O.version = re;
4676
- let N = O;
4675
+ N.version = ce;
4676
+ let G = N;
4677
4677
  class p extends Error {
4678
4678
  constructor(e) {
4679
4679
  super(e.message), this.name = "M2MError", this.code = e.code, this.status = e.status ?? 400, this.errorUri = e.errorUri, this.rateLimitInfo = e.rateLimitInfo, this.headers = e.headers, this.cause = e.cause, this.timestamp = (/* @__PURE__ */ new Date()).toISOString(), Error.captureStackTrace && Error.captureStackTrace(this, p);
@@ -4769,7 +4769,7 @@ class p extends Error {
4769
4769
  return this.status && (e += ` (HTTP ${this.status})`), e;
4770
4770
  }
4771
4771
  }
4772
- class K extends p {
4772
+ class V extends p {
4773
4773
  constructor(e, t) {
4774
4774
  super({
4775
4775
  code: "temporarily_unavailable",
@@ -4779,7 +4779,7 @@ class K extends p {
4779
4779
  }), this.name = "M2MNetworkError";
4780
4780
  }
4781
4781
  }
4782
- class R extends p {
4782
+ class F extends p {
4783
4783
  constructor(e, t) {
4784
4784
  super({
4785
4785
  code: "invalid_request",
@@ -4789,7 +4789,7 @@ class R extends p {
4789
4789
  }), this.name = "M2MTokenParseError";
4790
4790
  }
4791
4791
  }
4792
- class U extends p {
4792
+ class $ extends p {
4793
4793
  constructor(e) {
4794
4794
  super({
4795
4795
  code: "invalid_request",
@@ -4798,7 +4798,7 @@ class U extends p {
4798
4798
  }), this.name = "M2MConfigError";
4799
4799
  }
4800
4800
  }
4801
- const st = {
4801
+ const vt = {
4802
4802
  InvalidRequest: "invalid_request",
4803
4803
  InvalidClient: "invalid_client",
4804
4804
  InvalidGrant: "invalid_grant",
@@ -4822,7 +4822,7 @@ const st = {
4822
4822
  /** Content-Type for token requests */
4823
4823
  CONTENT_TYPE: "application/x-www-form-urlencoded"
4824
4824
  };
4825
- class ze {
4825
+ class et {
4826
4826
  constructor() {
4827
4827
  this.cache = /* @__PURE__ */ new Map();
4828
4828
  }
@@ -4840,7 +4840,7 @@ class ze {
4840
4840
  return this.cache.delete(e), Promise.resolve();
4841
4841
  }
4842
4842
  }
4843
- const Xe = {
4843
+ const tt = {
4844
4844
  shouldRetry(i, e) {
4845
4845
  return e >= 3 ? !1 : i.code === "server_error" || i.code === "temporarily_unavailable" || i.code === "rate_limit_exceeded" || i.status !== void 0 && i.status >= 500;
4846
4846
  },
@@ -4848,7 +4848,7 @@ const Xe = {
4848
4848
  return Math.pow(2, i - 1) * 1e3;
4849
4849
  }
4850
4850
  };
4851
- class it {
4851
+ class yt {
4852
4852
  /**
4853
4853
  * Create a new M2M client
4854
4854
  *
@@ -4866,11 +4866,11 @@ class it {
4866
4866
  */
4867
4867
  constructor(e) {
4868
4868
  if (!e.url)
4869
- throw new U("M2M client requires a URL");
4869
+ throw new $("M2M client requires a URL");
4870
4870
  if (!e.clientId)
4871
- throw new U("M2M client requires a clientId");
4871
+ throw new $("M2M client requires a clientId");
4872
4872
  if (!e.clientSecret)
4873
- throw new U("M2M client requires a clientSecret");
4873
+ throw new $("M2M client requires a clientSecret");
4874
4874
  const t = e.url.replace(/\/$/, "");
4875
4875
  this.config = {
4876
4876
  url: t,
@@ -4888,7 +4888,7 @@ class it {
4888
4888
  onTokenRequest: e.onTokenRequest,
4889
4889
  onTokenResponse: e.onTokenResponse,
4890
4890
  onError: e.onError
4891
- }, this.cache = e.cache ?? new ze(), this.retryStrategy = e.retryStrategy ?? Xe, this.tokenEndpoint = `${t}${w.TOKEN_ENDPOINT}`;
4891
+ }, this.cache = e.cache ?? new et(), this.retryStrategy = e.retryStrategy ?? tt, this.tokenEndpoint = `${t}${w.TOKEN_ENDPOINT}`;
4892
4892
  }
4893
4893
  /**
4894
4894
  * Get the cache key for this client
@@ -5008,7 +5008,7 @@ class it {
5008
5008
  }
5009
5009
  return h;
5010
5010
  } catch (o) {
5011
- throw clearTimeout(s), o instanceof Error && o.name === "AbortError" ? new K(`Request timed out after ${this.config.timeout}ms`) : o instanceof TypeError && o.message.includes("fetch") ? new K(`Network error: ${o.message}`, o) : o instanceof p ? o : p.fromError(o instanceof Error ? o : new Error(String(o)));
5011
+ throw clearTimeout(s), o instanceof Error && o.name === "AbortError" ? new V(`Request timed out after ${this.config.timeout}ms`) : o instanceof TypeError && o.message.includes("fetch") ? new V(`Network error: ${o.message}`, o) : o instanceof p ? o : p.fromError(o instanceof Error ? o : new Error(String(o)));
5012
5012
  }
5013
5013
  }
5014
5014
  /**
@@ -5103,14 +5103,14 @@ class it {
5103
5103
  try {
5104
5104
  const t = e.split(".");
5105
5105
  if (t.length !== 3)
5106
- throw new R("Invalid JWT format: expected 3 parts");
5106
+ throw new F("Invalid JWT format: expected 3 parts");
5107
5107
  const r = t[1];
5108
5108
  if (!r)
5109
- throw new R("Invalid JWT format: missing payload");
5109
+ throw new F("Invalid JWT format: missing payload");
5110
5110
  const s = atob(r.replace(/-/g, "+").replace(/_/g, "/")), o = JSON.parse(s);
5111
5111
  return o.scopes && typeof o.scopes == "string" ? o.scopes = o.scopes.split(" ") : o.scopes || (o.scopes = []), o;
5112
5112
  } catch (t) {
5113
- throw t instanceof R ? t : new R(`Failed to parse token: ${t instanceof Error ? t.message : "Unknown error"}`);
5113
+ throw t instanceof F ? t : new F(`Failed to parse token: ${t instanceof Error ? t.message : "Unknown error"}`);
5114
5114
  }
5115
5115
  }
5116
5116
  /**
@@ -5195,69 +5195,211 @@ class it {
5195
5195
  return this.config.audience;
5196
5196
  }
5197
5197
  }
5198
+ class b extends Error {
5199
+ constructor(e, t, r = !1) {
5200
+ super(t), this.name = "UpgradeFactorError", this.factor = e, this.cancelled = r;
5201
+ }
5202
+ }
5203
+ const Z = (i, e) => {
5204
+ const t = e?.trim();
5205
+ if (!t)
5206
+ throw new b(i, "A verification code is required");
5207
+ return t;
5208
+ }, rt = {
5209
+ type: "totp",
5210
+ requiresPrepare: !1,
5211
+ input: "code",
5212
+ assert: async ({ code: i }) => ({ code: Z("totp", i) })
5213
+ }, st = {
5214
+ type: "recovery_codes",
5215
+ requiresPrepare: !1,
5216
+ input: "code",
5217
+ assert: async ({ code: i }) => ({ code: Z("recovery_codes", i) })
5218
+ }, it = {
5219
+ type: "passkey",
5220
+ requiresPrepare: !0,
5221
+ input: "none",
5222
+ assert: async ({ prepared: i, platform: e }) => {
5223
+ if (!i?.webauthn)
5224
+ throw new b("passkey", "The upgrade challenge carried no WebAuthn options");
5225
+ const t = e.passkeys;
5226
+ if (!t)
5227
+ throw new b("passkey", "This platform does not support passkeys");
5228
+ let r;
5229
+ try {
5230
+ r = await t.startAuthentication(i.webauthn);
5231
+ } catch (s) {
5232
+ throw new b("passkey", s?.message || "Passkey verification was cancelled", !0);
5233
+ }
5234
+ if (!r)
5235
+ throw new b("passkey", "Passkey verification was cancelled", !0);
5236
+ return { challenge_id: i.challengeId, credential: r };
5237
+ }
5238
+ }, Q = Object.freeze([
5239
+ rt,
5240
+ it,
5241
+ st
5242
+ ]), ot = (i = Q) => new Map(i.map((e) => [e.type, e])), nt = 3, at = {
5243
+ passkey: 0,
5244
+ totp: 1,
5245
+ email_otp: 2,
5246
+ sms_otp: 3,
5247
+ recovery_codes: 9
5248
+ }, ct = (i) => {
5249
+ if (!i)
5250
+ return;
5251
+ const e = i.split(/\s+/).map((t) => Number.parseInt(t, 10)).filter((t) => Number.isFinite(t));
5252
+ return e.length > 0 ? Math.min(...e) : void 0;
5253
+ }, q = (i, e) => {
5254
+ const t = at[i.type] ?? 5, r = e !== void 0 && e >= nt, s = i.type === "passkey";
5255
+ return (r && !s ? 100 : 0) + t;
5256
+ }, ht = (i, e) => {
5257
+ const t = ct(e.acrValues);
5258
+ return [...i].sort((r, s) => q(r, t) - q(s, t));
5259
+ };
5260
+ class B extends Error {
5261
+ constructor() {
5262
+ super("Upgrade authentication was cancelled"), this.name = "UpgradeCancelledError";
5263
+ }
5264
+ }
5265
+ class O extends Error {
5266
+ constructor(e = "No available authentication factor can satisfy this challenge") {
5267
+ super(e), this.name = "UpgradeUnsatisfiableError";
5268
+ }
5269
+ }
5270
+ const dt = 3;
5271
+ class St {
5272
+ constructor(e) {
5273
+ this.inFlight = null, this.transport = e.transport, this.prompt = e.prompt, this.platform = e.platform, this.available = e.factors ?? Q, this.registry = ot(this.available), this.maxAttempts = e.maxAttempts ?? dt;
5274
+ }
5275
+ /**
5276
+ * Elevates the session so the challenged request can be retried.
5277
+ *
5278
+ * Concurrent callers share one elevation: the first starts it, the rest await
5279
+ * the same promise and all resolve together. Callers retry their own request
5280
+ * once this resolves; it rejects if the user cancelled or ran out of attempts.
5281
+ */
5282
+ elevate(e) {
5283
+ return this.inFlight ? this.inFlight : (this.inFlight = this.run(e).finally(() => {
5284
+ this.inFlight = null;
5285
+ }), this.inFlight);
5286
+ }
5287
+ async run(e) {
5288
+ const t = ht(this.available, e);
5289
+ if (t.length === 0)
5290
+ throw new O();
5291
+ let r;
5292
+ for (let s = 0; s < this.maxAttempts; s++) {
5293
+ const o = await this.prompt({ challenge: e, factors: t, previousError: r });
5294
+ if (o.type === "cancel")
5295
+ throw new B();
5296
+ const n = this.registry.get(o.factor);
5297
+ if (!n) {
5298
+ r = new O(`Unknown authentication factor: ${o.factor}`);
5299
+ continue;
5300
+ }
5301
+ try {
5302
+ await this.proveAndCommit(n, o.code);
5303
+ return;
5304
+ } catch (h) {
5305
+ if (h instanceof b && h.cancelled)
5306
+ throw new B();
5307
+ r = h;
5308
+ }
5309
+ }
5310
+ throw r ?? new O("Upgrade authentication failed");
5311
+ }
5312
+ /**
5313
+ * Runs one full proof for a single factor.
5314
+ *
5315
+ * The prepare round is re-run on every attempt rather than cached: a
5316
+ * challenge is single-use and the server consumes it atomically, so a failed
5317
+ * attempt has already spent it. Reusing the id would fail with
5318
+ * `ErrorUpgradeChallengeInvalid` and look like a bad code to the user.
5319
+ */
5320
+ async proveAndCommit(e, t) {
5321
+ const r = e.requiresPrepare ? await this.transport.prepare(e.type) : void 0, s = await e.assert({ code: t, prepared: r, platform: this.platform });
5322
+ await this.transport.commit(e.type, s);
5323
+ }
5324
+ }
5198
5325
  export {
5199
- b as APP_ID_HEADER_KEY,
5326
+ A as APP_ID_HEADER_KEY,
5200
5327
  I as AUTHORIZATION_HEADER_KEY,
5201
- Ce as AppAPI,
5202
- Re as AuthAPI,
5203
- Ne as AuthService,
5204
- rt as CLIAuthAPI,
5205
- et as DEFAULT_GROUP_NAME,
5206
- se as DEFAULT_SCOPES,
5207
- ee as DEVICE_ID_HEADER_KEY,
5208
- te as DEVICE_TYPE_HEADER_KEY,
5209
- de as ERROR_MESSAGE_MAX_LENGTH,
5210
- Fe as InvitationAPI,
5211
- Ke as InvitationService,
5212
- it as M2MClient,
5213
- U as M2MConfigError,
5328
+ xe as AppAPI,
5329
+ Ue as AuthAPI,
5330
+ Ye as AuthService,
5331
+ mt as CLIAuthAPI,
5332
+ ft as DEFAULT_GROUP_NAME,
5333
+ he as DEFAULT_SCOPES,
5334
+ Q as DEFAULT_UPGRADE_FACTORS,
5335
+ ne as DEVICE_ID_HEADER_KEY,
5336
+ ae as DEVICE_TYPE_HEADER_KEY,
5337
+ ke as ERROR_MESSAGE_MAX_LENGTH,
5338
+ we as INSUFFICIENT_USER_AUTHENTICATION,
5339
+ $e as InvitationAPI,
5340
+ je as InvitationService,
5341
+ yt as M2MClient,
5342
+ $ as M2MConfigError,
5214
5343
  p as M2MError,
5215
- st as M2MErrorCodes,
5216
- K as M2MNetworkError,
5217
- R as M2MTokenParseError,
5344
+ vt as M2MErrorCodes,
5345
+ V as M2MNetworkError,
5346
+ F as M2MTokenParseError,
5218
5347
  w as M2M_DEFAULTS,
5219
- Qe as MINIMAL_DEFAULT_SCOPES,
5220
- _e as OS,
5221
- G as PASSFLOW_CLOUD_URL,
5222
- oe as POPUP_HEIGHT,
5223
- ne as POPUP_POLL_INTERVAL_MS,
5224
- ae as POPUP_TIMEOUT_MS,
5225
- ie as POPUP_WIDTH,
5226
- N as Passflow,
5348
+ gt as MINIMAL_DEFAULT_SCOPES,
5349
+ Re as OS,
5350
+ Y as PASSFLOW_CLOUD_URL,
5351
+ ue as POPUP_HEIGHT,
5352
+ le as POPUP_POLL_INTERVAL_MS,
5353
+ pe as POPUP_TIMEOUT_MS,
5354
+ de as POPUP_WIDTH,
5355
+ G as Passflow,
5227
5356
  T as PassflowAdminEndpointPaths,
5228
5357
  c as PassflowEndpointPaths,
5229
5358
  l as PassflowError,
5230
5359
  a as PassflowEvent,
5231
- j as PopupClosedError,
5232
- Te as Providers,
5233
- E as RequestMethod,
5234
- re as SDK_VERSION,
5235
- q as SessionState,
5236
- Me as SettingAPI,
5237
- V as TOKEN_EXPIRY_BUFFER_SECONDS,
5238
- De as TenantAPI,
5239
- Be as TenantService,
5240
- qe as TenantUserMembership,
5241
- Ye as TokenCacheService,
5360
+ W as PopupClosedError,
5361
+ Ce as Providers,
5362
+ _ as RequestMethod,
5363
+ ce as SDK_VERSION,
5364
+ H as SessionState,
5365
+ Oe as SettingAPI,
5366
+ j as TOKEN_EXPIRY_BUFFER_SECONDS,
5367
+ Le as TenantAPI,
5368
+ We as TenantService,
5369
+ Xe as TenantUserMembership,
5370
+ Je as TokenCacheService,
5242
5371
  v as TokenDeliveryMode,
5243
5372
  k as TokenType,
5244
- Pe as TwoFactorApiClient,
5245
- Ee as TwoFactorPolicy,
5246
- je as TwoFactorService,
5247
- he as USERNAME_MAX_LENGTH,
5248
- ce as USERNAME_MIN_LENGTH,
5249
- xe as UserAPI,
5250
- He as UserService,
5251
- ge as WebAdapter,
5252
- tt as getOSFromDeviceType,
5373
+ Ne as TwoFactorApiClient,
5374
+ Fe as TwoFactorPolicy,
5375
+ Ze as TwoFactorService,
5376
+ Te as UPGRADE_REQUIRED,
5377
+ fe as USERNAME_MAX_LENGTH,
5378
+ ge as USERNAME_MIN_LENGTH,
5379
+ B as UpgradeCancelledError,
5380
+ St as UpgradeController,
5381
+ b as UpgradeFactorError,
5382
+ O as UpgradeUnsatisfiableError,
5383
+ Ke as UserAPI,
5384
+ Qe as UserService,
5385
+ Se as WebAdapter,
5386
+ ot as factorRegistry,
5387
+ kt as getOSFromDeviceType,
5253
5388
  y as isTokenExpired,
5254
- P as isValidEmail,
5255
- D as isValidJWTFormat,
5256
- x as isValidPhoneNumber,
5257
- Oe as isValidUsername,
5389
+ x as isValidEmail,
5390
+ P as isValidJWTFormat,
5391
+ U as isValidPhoneNumber,
5392
+ qe as isValidUsername,
5393
+ be as parseChallengeBody,
5394
+ Ie as parseChallengeHeader,
5258
5395
  m as parseToken,
5259
- _ as pathWithParams,
5260
- $e as sanitizeErrorMessage,
5261
- A as webAdapter
5396
+ Ae as parseUpgradeChallenge,
5397
+ it as passkeyFactor,
5398
+ E as pathWithParams,
5399
+ st as recoveryCodesFactor,
5400
+ Ve as sanitizeErrorMessage,
5401
+ ht as selectFactors,
5402
+ rt as totpFactor,
5403
+ C as webAdapter
5262
5404
  };
5263
5405
  //# sourceMappingURL=index.mjs.map