@passflow/core 0.13.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import F from "axios";
2
- import { v4 as H } from "uuid";
3
- import { startAuthentication as z, startRegistration as X } from "@simplewebauthn/browser";
4
- const W = "0.13.2", J = {
5
- version: W
6
- }, b = "X-Passflow-Clientid", I = "Authorization", Z = "X-Passflow-DeviceId", Q = "X-Passflow-DeviceType", ee = J.version, qe = ["id", "offline", "openid"], te = ["id", "offline", "tenant", "email", "oidc", "openid", "access:tenant:all"], K = "https://auth.passflow.cloud", Be = "default", re = 500, se = 600, ie = 100, oe = 6e4, G = 30, ne = 3, ae = 30, ce = 200, he = (i) => {
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) => {
7
7
  const e = [];
8
8
  let t;
9
9
  for (t in i) {
@@ -18,14 +18,14 @@ const W = "0.13.2", J = {
18
18
  }
19
19
  return { raw: i, tenants: e };
20
20
  };
21
- function de(i) {
21
+ function le(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 ue {
28
+ class pe {
29
29
  constructor(e) {
30
30
  this.storageManager = e;
31
31
  }
@@ -39,7 +39,7 @@ class ue {
39
39
  const t = this.storageManager.getToken(e);
40
40
  if (!t) return !0;
41
41
  const r = m(t);
42
- return r ? S(r) : !0;
42
+ return r ? y(r) : !0;
43
43
  }
44
44
  /**
45
45
  * Parse token from storage by type.
@@ -54,19 +54,19 @@ class ue {
54
54
  return m(t);
55
55
  }
56
56
  }
57
- function S(i, e = G) {
57
+ function y(i, e = V) {
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 = de(r), o = decodeURIComponent(
63
+ const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = t + "=".repeat((4 - t.length % 4) % 4), s = le(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" ? he(n.passflow_tm) : void 0, n;
66
+ return n.membership = n.passflow_tm && n.type !== "invite" ? ue(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 || {}), y = /* @__PURE__ */ ((i) => (i.JsonBody = "json_body", i.Cookie = "cookie", i.Mobile = "mobile", i.BFF = "bff", i))(y || {}), V = /* @__PURE__ */ ((i) => (i.Unknown = "unknown", i.Valid = "valid", i.Invalid = "invalid", i))(V || {});
69
- class q {
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 {
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
  }
@@ -166,7 +166,7 @@ class q {
166
166
  loadPersistedMode() {
167
167
  try {
168
168
  const e = this.storageManager.storage.getItem(this.DELIVERY_MODE_KEY);
169
- e && Object.values(y).includes(e) && (this.mode = e, this.isInitializedFlag = !0);
169
+ e && Object.values(v).includes(e) && (this.mode = e, this.isInitializedFlag = !0);
170
170
  } catch {
171
171
  }
172
172
  }
@@ -176,7 +176,7 @@ class q {
176
176
  loadPersistedSessionState() {
177
177
  try {
178
178
  const e = this.storageManager.storage.getItem(this.SESSION_STATE_KEY);
179
- e && Object.values(V).includes(e) && (this.sessionState = e);
179
+ e && Object.values(q).includes(e) && (this.sessionState = e);
180
180
  } catch {
181
181
  }
182
182
  }
@@ -228,7 +228,7 @@ class $ {
228
228
  */
229
229
  saveTokens(e, t) {
230
230
  const { id_token: r, access_token: s, refresh_token: o, scopes: n } = e;
231
- t === y.Cookie || t === y.BFF ? r && this.storage.setItem(this.ID_TOKEN_KEY, r) : (r && this.storage.setItem(this.getKeyForTokenType(k.id_token), r), s && this.storage.setItem(this.getKeyForTokenType(k.access_token), s), o && this.storage.setItem(this.getKeyForTokenType(k.refresh_token), o), n && this.storage.setItem(this.scopes, n.join(",")));
231
+ t === v.Cookie || t === v.BFF ? r && this.storage.setItem(this.ID_TOKEN_KEY, r) : (r && this.storage.setItem(this.getKeyForTokenType(k.id_token), r), s && this.storage.setItem(this.getKeyForTokenType(k.access_token), s), o && this.storage.setItem(this.getKeyForTokenType(k.refresh_token), o), n && this.storage.setItem(this.scopes, n.join(",")));
232
232
  }
233
233
  getToken(e) {
234
234
  const t = this.getKeyForTokenType(e);
@@ -241,7 +241,7 @@ class $ {
241
241
  */
242
242
  getTokens() {
243
243
  const e = this.getDeliveryMode();
244
- if (e === y.Cookie || e === y.BFF) {
244
+ if (e === v.Cookie || e === v.BFF) {
245
245
  const r = this.storage.getItem(this.ID_TOKEN_KEY);
246
246
  return r ? {
247
247
  id_token: r
@@ -324,7 +324,7 @@ class $ {
324
324
  getDeliveryMode() {
325
325
  try {
326
326
  const e = this.storage.getItem(this.DELIVERY_MODE_KEY);
327
- if (e && Object.values(y).includes(e))
327
+ if (e && Object.values(v).includes(e))
328
328
  return e;
329
329
  } catch {
330
330
  }
@@ -400,7 +400,7 @@ class $ {
400
400
  return `${this.keyStoragePrefix}${e}`;
401
401
  }
402
402
  }
403
- class B {
403
+ class Y {
404
404
  constructor(e) {
405
405
  this.storageManager = e ?? new $();
406
406
  }
@@ -413,19 +413,19 @@ class B {
413
413
  return e;
414
414
  }
415
415
  generateUniqueDeviceId() {
416
- return H();
416
+ return X();
417
417
  }
418
418
  }
419
- class Y extends Error {
419
+ class j extends Error {
420
420
  constructor(e = "Authentication popup was closed") {
421
421
  super(e), this.name = "PopupClosedError";
422
422
  }
423
423
  }
424
- class le {
424
+ class ge {
425
425
  constructor() {
426
426
  this.passkeys = {
427
- startRegistration: (e) => X({ optionsJSON: e }),
428
- startAuthentication: (e) => z({ optionsJSON: e })
427
+ startRegistration: (e) => J({ optionsJSON: e }),
428
+ startAuthentication: (e) => W({ optionsJSON: e })
429
429
  };
430
430
  }
431
431
  // ----------------------------------------------------------------
@@ -557,25 +557,25 @@ class le {
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 ?? re, o = t.height ?? se, n = t.expectedReturnOrigin ?? window.location.origin, h = window.open(e, "_blank", `width=${s},height=${o}`);
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}`);
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 Y());
564
+ clearInterval(f), u(new j());
565
565
  return;
566
566
  }
567
- if (Date.now() - g > oe) {
567
+ if (Date.now() - g > ae) {
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, j = h.location.hash;
574
- clearInterval(f), h.close(), d({ callbackSearch: M, callbackHash: j });
573
+ const M = h.location.search, z = h.location.hash;
574
+ clearInterval(f), h.close(), d({ callbackSearch: M, callbackHash: z });
575
575
  }
576
576
  } catch {
577
577
  }
578
- }, ie);
578
+ }, ne);
579
579
  }) : (window.location.href = e, new Promise(() => {
580
580
  }));
581
581
  }
@@ -633,43 +633,87 @@ class le {
633
633
  return "web";
634
634
  }
635
635
  }
636
- const A = new le();
637
- 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.TwoFactorMethodSetupBegin = "/v2/user/2fa/methods/:method/setup/begin", i.TwoFactorMethodSetupConfirm = "/v2/user/2fa/methods/:method/setup/confirm", 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 || {}), E = /* @__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))(E || {});
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) => {
637
+ const e = {};
638
+ L.lastIndex = 0;
639
+ for (const t of i.matchAll(L)) {
640
+ const r = t[1];
641
+ if (!r)
642
+ continue;
643
+ const s = t[2], o = t[3];
644
+ e[r.toLowerCase()] = s !== void 0 ? me(s) : o ?? "";
645
+ }
646
+ return e;
647
+ }, H = (i) => {
648
+ const e = typeof i == "number" ? i : Number.parseInt(String(i ?? ""), 10);
649
+ return Number.isFinite(e) && e > 0 ? e : void 0;
650
+ }, ye = (i, e) => {
651
+ if (!i || !/(^|[\s,])Bearer\b/i.test(i))
652
+ return;
653
+ const t = ve(i);
654
+ if (t.error === fe)
655
+ return {
656
+ acrValues: t.acr_values || void 0,
657
+ maxAge: H(t.max_age),
658
+ status: e
659
+ };
660
+ }, Se = (i, e) => {
661
+ if (!i || typeof i != "object")
662
+ return;
663
+ const t = i;
664
+ if (t.error === ke)
665
+ return {
666
+ acrValues: typeof t.acr_values == "string" && t.acr_values ? t.acr_values : void 0,
667
+ maxAge: H(t.max_age),
668
+ status: e
669
+ };
670
+ }, we = (i, e, t) => {
671
+ if (!(i !== 401 && i !== 403))
672
+ return ye(e("www-authenticate"), i) ?? Se(t, i);
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 || {});
638
675
  class l extends Error {
639
676
  constructor(e) {
640
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();
641
678
  }
642
679
  }
643
- var pe = /* @__PURE__ */ ((i) => (i.google = "google", i.facebook = "facebook", i))(pe || {}), ge = /* @__PURE__ */ ((i) => (i.web = "web", i.ios = "ios", i.android = "android", i))(ge || {});
644
- function Ye(i) {
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) {
645
682
  return i;
646
683
  }
647
- function v(i, e) {
684
+ function _(i, e) {
648
685
  let t = i;
649
686
  return Object.entries(e).forEach(([r, s]) => {
650
687
  t = t.replace(`:${r}`, s);
651
688
  }), t;
652
689
  }
653
- var fe = /* @__PURE__ */ ((i) => (i.Disabled = "disabled", i.Optional = "optional", i.Required = "required", i))(fe || {});
654
- const ke = 3, me = 1e3;
655
- class w {
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(
692
+ i.status,
693
+ (e) => {
694
+ const t = i.headers?.[e] ?? i.headers?.[e.toLowerCase()];
695
+ return Array.isArray(t) ? t.join(", ") : t;
696
+ },
697
+ i.data
698
+ ) !== void 0;
699
+ class S {
656
700
  constructor(e, t, r) {
657
701
  this.refreshPromise = null, this.isRefreshing = !1, this.defaultHeaders = {
658
702
  Accept: "application/json",
659
703
  "Content-Type": "application/json"
660
704
  }, this.nonAccessTokenEndpoints = ["/auth/", "/settings", "/settings/"], this.protectedEndpoints = ["logout", "refresh"];
661
705
  const { url: s, appId: o, keyStoragePrefix: n } = e;
662
- this._platform = e.platform ?? A, this.url = s || K, this.storageManager = t ?? new $({
706
+ this._platform = e.platform ?? A, this.url = s || G, this.storageManager = t ?? new $({
663
707
  prefix: n ?? ""
664
- }), this.deviceService = r ?? new B(this.storageManager), this.tokenService = new ue(this.storageManager), this.tokenDeliveryManager = new q(this.storageManager), o && (this.appId = o, this.defaultHeaders = {
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 = {
665
709
  ...this.defaultHeaders,
666
710
  [b]: o
667
711
  });
668
712
  const h = this.deviceService.getDeviceId();
669
713
  this.defaultHeaders = {
670
714
  ...this.defaultHeaders,
671
- [Z]: h,
672
- [Q]: this._platform.getDeviceType()
715
+ [ee]: h,
716
+ [te]: this._platform.getDeviceType()
673
717
  }, this.detectCookieSupport(), this.instance = F.create({
674
718
  baseURL: this.url,
675
719
  headers: { ...this.defaultHeaders }
@@ -691,7 +735,7 @@ class w {
691
735
  const u = this.storageManager.getTokens();
692
736
  if (u?.access_token) {
693
737
  const g = m(u.access_token);
694
- if (S(g, G) && u.refresh_token)
738
+ if (y(g, V) && u.refresh_token)
695
739
  try {
696
740
  if (this.refreshPromise) {
697
741
  const f = await this.refreshPromise;
@@ -712,7 +756,7 @@ class w {
712
756
  return d;
713
757
  }), this.instance.interceptors.response.use(
714
758
  (d) => d,
715
- async (d) => (d.response?.status === 401 && this.tokenDeliveryManager.setSessionInvalid(), d.response?.status === 429 ? await this.handleRateLimitError(d) : this.handleAxiosError(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))
716
760
  );
717
761
  }
718
762
  get origin() {
@@ -776,9 +820,9 @@ class w {
776
820
  if (!["GET", "HEAD", "OPTIONS"].includes(r || ""))
777
821
  return Promise.reject(e);
778
822
  const o = t._retryCount || 0;
779
- if (o >= ke)
823
+ if (o >= Ie)
780
824
  return Promise.reject(e);
781
- let n = me * Math.pow(2, o);
825
+ let n = be * Math.pow(2, o);
782
826
  const h = e.response?.headers?.["retry-after"];
783
827
  if (h) {
784
828
  const d = Number.parseInt(h, 10);
@@ -819,19 +863,19 @@ class w {
819
863
  })).data;
820
864
  }
821
865
  get(e, t) {
822
- return this.send(_.GET, e, t);
866
+ return this.send(E.GET, e, t);
823
867
  }
824
868
  post(e, t, r) {
825
- return this.send(_.POST, e, { data: t, ...r });
869
+ return this.send(E.POST, e, { data: t, ...r });
826
870
  }
827
871
  put(e, t, r) {
828
- return this.send(_.PUT, e, { data: t, ...r });
872
+ return this.send(E.PUT, e, { data: t, ...r });
829
873
  }
830
874
  patch(e, t, r) {
831
- return this.send(_.PATCH, e, { data: t, ...r });
875
+ return this.send(E.PATCH, e, { data: t, ...r });
832
876
  }
833
877
  delete(e, t) {
834
- return this.send(_.DELETE, e, t);
878
+ return this.send(E.DELETE, e, t);
835
879
  }
836
880
  /**
837
881
  * Update the appId and propagate it to axios headers.
@@ -846,9 +890,9 @@ class w {
846
890
  }, this.instance.defaults.headers.common[b] = e;
847
891
  }
848
892
  }
849
- class ve {
893
+ class Ce {
850
894
  constructor(e, t, r) {
851
- this.axiosClient = new w(e, t, r);
895
+ this.axiosClient = new S(e, t, r);
852
896
  }
853
897
  setAppId(e) {
854
898
  this.axiosClient.setAppId(e);
@@ -857,9 +901,9 @@ class ve {
857
901
  return this.axiosClient.get(c.appSettings);
858
902
  }
859
903
  }
860
- class ye {
904
+ class Re {
861
905
  constructor(e, t, r) {
862
- this.axiosClient = new w(e, t, r);
906
+ this.axiosClient = new S(e, t, r);
863
907
  }
864
908
  setAppId(e) {
865
909
  this.axiosClient.setAppId(e);
@@ -916,7 +960,7 @@ class ye {
916
960
  );
917
961
  }
918
962
  logOut(e, t, r = !1) {
919
- const s = r ? void 0 : { refresh_token: t, device: e }, o = r ? E.logout : c.logout;
963
+ const s = r ? void 0 : { refresh_token: t, device: e }, o = r ? T.logout : c.logout;
920
964
  return this.axiosClient.post(o, s);
921
965
  }
922
966
  validateSession() {
@@ -946,7 +990,7 @@ class ye {
946
990
  create_tenant: o ?? !1,
947
991
  device: t,
948
992
  os: r
949
- }, h = s ? E.passkeyRegisterStart : c.passkeyRegisterStart;
993
+ }, h = s ? T.passkeyRegisterStart : c.passkeyRegisterStart;
950
994
  return this.axiosClient.post(h, n);
951
995
  }
952
996
  passkeyRegisterComplete(e, t, r, s = !1) {
@@ -954,7 +998,7 @@ class ye {
954
998
  challenge_id: r,
955
999
  device: t,
956
1000
  passkey_data: e
957
- }, n = s ? E.passkeyRegisterComplete : c.passkeyRegisterComplete;
1001
+ }, n = s ? T.passkeyRegisterComplete : c.passkeyRegisterComplete;
958
1002
  return this.axiosClient.post(n, o);
959
1003
  }
960
1004
  passkeyAuthenticateStart(e, t, r, s = !1) {
@@ -963,7 +1007,7 @@ class ye {
963
1007
  user_id: e.user_id ?? "",
964
1008
  device: t,
965
1009
  os: r
966
- }, n = s ? E.passkeyAuthenticateStart : c.passkeyAuthenticateStart;
1010
+ }, n = s ? T.passkeyAuthenticateStart : c.passkeyAuthenticateStart;
967
1011
  return this.axiosClient.post(
968
1012
  n,
969
1013
  o
@@ -974,7 +1018,7 @@ class ye {
974
1018
  challenge_id: r,
975
1019
  device: t,
976
1020
  passkey_data: e
977
- }, n = s ? E.passkeyAuthenticateComplete : c.passkeyAuthenticateComplete;
1021
+ }, n = s ? T.passkeyAuthenticateComplete : c.passkeyAuthenticateComplete;
978
1022
  return this.axiosClient.post(n, o);
979
1023
  }
980
1024
  passkeyValidate(e, t, r, s = !1, o) {
@@ -984,29 +1028,29 @@ class ye {
984
1028
  challenge_id: r
985
1029
  };
986
1030
  let h = c.passkeyValidate;
987
- !o && s && (h = E.passkeyValidate);
1031
+ !o && s && (h = T.passkeyValidate);
988
1032
  const d = o ? { [b]: o } : {};
989
1033
  return this.axiosClient.post(h, n, { headers: d });
990
1034
  }
991
1035
  }
992
- class je {
1036
+ class rt {
993
1037
  constructor(e, t, r) {
994
- this.axiosClient = new w(e, t, r);
1038
+ this.axiosClient = new S(e, t, r);
995
1039
  }
996
1040
  setAppId(e) {
997
1041
  this.axiosClient.setAppId(e);
998
1042
  }
999
1043
  getCLIAuthStatus(e) {
1000
- const t = v(c.cliAuthStatus, { sessionId: e });
1044
+ const t = _(c.cliAuthStatus, { sessionId: e });
1001
1045
  return this.axiosClient.get(t);
1002
1046
  }
1003
1047
  completeCLIAuth(e) {
1004
1048
  return this.axiosClient.post(c.cliAuthComplete, e);
1005
1049
  }
1006
1050
  }
1007
- class Se {
1051
+ class Fe {
1008
1052
  constructor(e, t, r) {
1009
- this.axiosClient = new w(e, t, r);
1053
+ this.axiosClient = new S(e, t, r);
1010
1054
  }
1011
1055
  setAppId(e) {
1012
1056
  this.axiosClient.setAppId(e);
@@ -1030,7 +1074,7 @@ class Se {
1030
1074
  getInvitations(e) {
1031
1075
  const t = {};
1032
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());
1033
- const r = v(c.invitationsPath, {
1077
+ const r = _(c.invitationsPath, {
1034
1078
  tenantID: e.tenantID
1035
1079
  });
1036
1080
  return this.axiosClient.get(r, { params: t }).then((s) => ({
@@ -1044,7 +1088,7 @@ class Se {
1044
1088
  * @returns Promise with success response
1045
1089
  */
1046
1090
  deleteInvitation(e) {
1047
- const t = v(c.invitationDelete, {
1091
+ const t = _(c.invitationDelete, {
1048
1092
  invitationID: e
1049
1093
  });
1050
1094
  return this.axiosClient.delete(t);
@@ -1055,7 +1099,7 @@ class Se {
1055
1099
  * @returns Promise with success response
1056
1100
  */
1057
1101
  resendInvitation(e) {
1058
- const t = v(c.invitationResend, {
1102
+ const t = _(c.invitationResend, {
1059
1103
  invitationID: e
1060
1104
  });
1061
1105
  return this.axiosClient.post(t, {});
@@ -1066,15 +1110,15 @@ class Se {
1066
1110
  * @returns Promise with the link
1067
1111
  */
1068
1112
  getInvitationLink(e) {
1069
- const t = v(c.invitationGetLink, {
1113
+ const t = _(c.invitationGetLink, {
1070
1114
  invitationID: e
1071
1115
  });
1072
1116
  return this.axiosClient.get(t);
1073
1117
  }
1074
1118
  }
1075
- class we {
1119
+ class Me {
1076
1120
  constructor(e, t, r) {
1077
- this.axiosClient = new w(e, t, r);
1121
+ this.axiosClient = new S(e, t, r);
1078
1122
  }
1079
1123
  setAppId(e) {
1080
1124
  this.axiosClient.setAppId(e);
@@ -1089,9 +1133,9 @@ class we {
1089
1133
  return this.axiosClient.get(c.settingsPasskey);
1090
1134
  }
1091
1135
  }
1092
- class Te {
1136
+ class De {
1093
1137
  constructor(e, t, r) {
1094
- this.axiosClient = new w(e, t, r);
1138
+ this.axiosClient = new S(e, t, r);
1095
1139
  }
1096
1140
  setAppId(e) {
1097
1141
  this.axiosClient.setAppId(e);
@@ -1322,9 +1366,9 @@ class Te {
1322
1366
  return this.axiosClient.delete(s);
1323
1367
  }
1324
1368
  }
1325
- class Ee {
1369
+ class Pe {
1326
1370
  constructor(e, t, r) {
1327
- this.axiosClient = new w(e, t, r);
1371
+ this.axiosClient = new S(e, t, r);
1328
1372
  }
1329
1373
  setAppId(e) {
1330
1374
  this.axiosClient.setAppId(e);
@@ -1509,27 +1553,34 @@ class Ee {
1509
1553
  return this.axiosClient.get(c.TwoFactorMethodsRegistered);
1510
1554
  }
1511
1555
  /**
1512
- * Begin 2FA method setup
1513
- * POST /v2/user/2fa/methods/:method/setup/begin
1556
+ * Start 2FA method setup.
1557
+ * POST /v2/user/2fa/setup/start
1558
+ *
1559
+ * The method travels in the body: at this point it is a parameter of the
1560
+ * request, not the identity of an enrolled resource.
1514
1561
  */
1515
- beginMethodSetup(e) {
1516
- const t = v(c.TwoFactorMethodSetupBegin, { method: e });
1517
- return this.axiosClient.post(t, {});
1562
+ startMethodSetup(e, t) {
1563
+ return this.axiosClient.post(c.TwoFactorSetupStart, {
1564
+ ...t,
1565
+ method: e
1566
+ });
1518
1567
  }
1519
1568
  /**
1520
- * Confirm 2FA method setup
1521
- * POST /v2/user/2fa/methods/:method/setup/confirm
1569
+ * Complete 2FA method setup.
1570
+ * POST /v2/user/2fa/setup/complete
1522
1571
  */
1523
- confirmMethodSetup(e, t) {
1524
- const r = v(c.TwoFactorMethodSetupConfirm, { method: e });
1525
- return this.axiosClient.post(r, t);
1572
+ completeMethodSetup(e, t) {
1573
+ return this.axiosClient.post(c.TwoFactorSetupComplete, {
1574
+ ...t,
1575
+ method: e
1576
+ });
1526
1577
  }
1527
1578
  /**
1528
1579
  * Remove registered 2FA method
1529
1580
  * DELETE /v2/user/2fa/methods/:id
1530
1581
  */
1531
1582
  removeMethod(e) {
1532
- const t = v(c.TwoFactorMethodRemove, { id: e });
1583
+ const t = _(c.TwoFactorMethodRemove, { id: e });
1533
1584
  return this.axiosClient.delete(t);
1534
1585
  }
1535
1586
  /**
@@ -1574,13 +1625,13 @@ class Ee {
1574
1625
  * DELETE /v2/user/2fa/trusted-devices/:id
1575
1626
  */
1576
1627
  revokeTrustedDevice(e) {
1577
- const t = v(c.TwoFactorTrustedDeviceRevoke, { id: e });
1628
+ const t = _(c.TwoFactorTrustedDeviceRevoke, { id: e });
1578
1629
  return this.axiosClient.delete(t);
1579
1630
  }
1580
1631
  }
1581
- class _e {
1632
+ class xe {
1582
1633
  constructor(e, t, r) {
1583
- this.axiosClient = new w(e, t, r);
1634
+ this.axiosClient = new S(e, t, r);
1584
1635
  }
1585
1636
  setAppId(e) {
1586
1637
  this.axiosClient.setAppId(e);
@@ -1624,7 +1675,7 @@ class _e {
1624
1675
  }
1625
1676
  }
1626
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 || {});
1627
- class Ie {
1678
+ class Ue {
1628
1679
  constructor() {
1629
1680
  this.subscribers = /* @__PURE__ */ new Map();
1630
1681
  }
@@ -1671,8 +1722,8 @@ function D(i) {
1671
1722
  const t = /^[A-Za-z0-9_-]+$/;
1672
1723
  return e.every((r) => t.test(r) && r.length > 0);
1673
1724
  }
1674
- function be(i) {
1675
- return i.replace(/<[^>]*>/g, "").substring(0, ce);
1725
+ function $e(i) {
1726
+ return i.replace(/<[^>]*>/g, "").substring(0, de);
1676
1727
  }
1677
1728
  function P(i) {
1678
1729
  if (!i || typeof i != "string") return !1;
@@ -1684,22 +1735,22 @@ function x(i) {
1684
1735
  const e = i.trim();
1685
1736
  return /^\+[1-9]\d{1,14}$/.test(e);
1686
1737
  }
1687
- function Ae(i) {
1738
+ function Oe(i) {
1688
1739
  if (!i || typeof i != "string") return !1;
1689
1740
  const e = i.trim();
1690
- return e.length < ne || e.length > ae ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
1741
+ return e.length < ce || e.length > he ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
1691
1742
  }
1692
1743
  function C(i, e = 6) {
1693
1744
  return !i || typeof i != "string" ? !1 : (e === 8 ? /^\d{8}$/ : /^\d{6}$/).test(i);
1694
1745
  }
1695
- function Ce(i) {
1746
+ function Le(i) {
1696
1747
  if (!i || typeof i != "string") return null;
1697
1748
  const e = i.toUpperCase().replace(/\s+/g, "");
1698
1749
  return /^[A-Z0-9-]{4,16}$/.test(e) ? e : null;
1699
1750
  }
1700
- class Re {
1751
+ class Ne {
1701
1752
  constructor(e, t, r, s, o, n, h, d, u, g, f, M = A) {
1702
- 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 q(r), f?.enabled && this.tokenDeliveryManager.setMode(y.BFF), this.initializeSession();
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();
1703
1754
  }
1704
1755
  /**
1705
1756
  * Initialize session state on page load for cookie/BFF mode
@@ -1774,7 +1825,7 @@ class Re {
1774
1825
  };
1775
1826
  throw this.subscribeStore.notify(a.Error, o), s;
1776
1827
  }
1777
- if ("username" in e && e.username && !Ae(e.username)) {
1828
+ if ("username" in e && e.username && !Oe(e.username)) {
1778
1829
  const s = new Error(
1779
1830
  "Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"
1780
1831
  ), o = {
@@ -2110,7 +2161,7 @@ class Re {
2110
2161
  } catch (o) {
2111
2162
  const n = {
2112
2163
  message: o instanceof Error ? o.message : "Authentication failed",
2113
- code: o instanceof Y ? "POPUP_CLOSED" : "AUTH_FAILED",
2164
+ code: o instanceof j ? "POPUP_CLOSED" : "AUTH_FAILED",
2114
2165
  originalError: o
2115
2166
  };
2116
2167
  this.subscribeStore.notify(a.Error, n);
@@ -2161,7 +2212,7 @@ class Re {
2161
2212
  const t = !!e?.id_token || !!this.storageManager.getIdToken(), r = this.tokenDeliveryManager.isSessionValid(), s = this.tokenDeliveryManager.isSessionUnknown();
2162
2213
  return t && (r || s);
2163
2214
  }
2164
- return !e || !e.access_token ? !1 : !S(e.access_token) || e.refresh_token !== void 0 && !S(e.refresh_token);
2215
+ return !e || !e.access_token ? !1 : !y(e.access_token) || e.refresh_token !== void 0 && !y(e.refresh_token);
2165
2216
  } catch (t) {
2166
2217
  const r = {
2167
2218
  message: t instanceof Error ? t.message : "Failed to check authentication status",
@@ -2200,7 +2251,7 @@ class Re {
2200
2251
  const t = this.storageManager.getTokens();
2201
2252
  if (!t || !t.access_token) return;
2202
2253
  const r = m(t.access_token);
2203
- return S(r) ? e ? await this.refreshToken() : void 0 : t;
2254
+ return y(r) ? e ? await this.refreshToken() : void 0 : t;
2204
2255
  } catch (t) {
2205
2256
  const r = {
2206
2257
  message: t instanceof Error ? t.message : "Failed to get tokens",
@@ -2211,7 +2262,7 @@ class Re {
2211
2262
  }
2212
2263
  }
2213
2264
  }
2214
- class Fe {
2265
+ class Ke {
2215
2266
  constructor(e) {
2216
2267
  this.invitationApi = e;
2217
2268
  }
@@ -2256,7 +2307,7 @@ class Fe {
2256
2307
  return this.invitationApi.getInvitationLink(e);
2257
2308
  }
2258
2309
  }
2259
- class Me {
2310
+ class Ge {
2260
2311
  error(e, ...t) {
2261
2312
  console.error(e, ...t);
2262
2313
  }
@@ -2270,10 +2321,10 @@ class Me {
2270
2321
  console.debug(e, ...t);
2271
2322
  }
2272
2323
  }
2273
- function De() {
2274
- return new Me();
2324
+ function Ve() {
2325
+ return new Ge();
2275
2326
  }
2276
- class Pe {
2327
+ class qe {
2277
2328
  constructor(e) {
2278
2329
  this.data = this.normalize(e);
2279
2330
  }
@@ -2343,9 +2394,9 @@ class Pe {
2343
2394
  return this.data;
2344
2395
  }
2345
2396
  }
2346
- class xe {
2397
+ class Be {
2347
2398
  constructor(e, t, r) {
2348
- this.tenantApi = e, this.scopes = t, this.logger = r || De();
2399
+ this.tenantApi = e, this.scopes = t, this.logger = r || Ve();
2349
2400
  }
2350
2401
  /**
2351
2402
  * Handle Passflow API errors
@@ -2415,7 +2466,7 @@ class xe {
2415
2466
  async getTenantUserMembership(e) {
2416
2467
  try {
2417
2468
  const t = await this.tenantApi.getTenantDetails(e);
2418
- return new Pe(t);
2469
+ return new qe(t);
2419
2470
  } catch (t) {
2420
2471
  this.handlePassflowError(t, `Get tenant user membership failed for tenant ID ${e}`);
2421
2472
  }
@@ -2713,23 +2764,21 @@ class xe {
2713
2764
  }
2714
2765
  }
2715
2766
  }
2716
- class Ue {
2767
+ class Ye {
2717
2768
  constructor(e, t, r, s = A) {
2718
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();
2719
2770
  }
2720
2771
  initialize() {
2721
2772
  try {
2722
2773
  const e = this.storageManager.getTokens();
2723
- if (!e) {
2724
- this.startTokenCheck();
2774
+ if (!e)
2725
2775
  return;
2726
- }
2727
2776
  if (!e.access_token) {
2728
2777
  this.setTokensCache(e), this.startTokenCheck();
2729
2778
  return;
2730
2779
  }
2731
2780
  const t = m(e.access_token);
2732
- S(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 })) : (this.setTokensCache(e), this.startTokenCheck());
2781
+ y(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 })) : (this.setTokensCache(e), this.startTokenCheck());
2733
2782
  } catch (e) {
2734
2783
  const t = {
2735
2784
  message: e instanceof Error ? e.message : "Failed to get tokens",
@@ -2793,7 +2842,7 @@ class Ue {
2793
2842
  if (!this.tokensCache.access_token)
2794
2843
  return this.tokensCache;
2795
2844
  const e = m(this.tokensCache.access_token);
2796
- return S(e) && !this.tokenExpiredFlag ? (await this.refreshTokensCache(this.tokensCache), this.tokensCache) : this.tokensCache;
2845
+ return y(e) && !this.tokenExpiredFlag ? (await this.refreshTokensCache(this.tokensCache), this.tokensCache) : this.tokensCache;
2797
2846
  } catch (e) {
2798
2847
  const t = {
2799
2848
  message: e instanceof Error ? e.message : "Failed to get tokens",
@@ -2811,10 +2860,10 @@ class Ue {
2811
2860
  if (!this.tokensCache.access_token)
2812
2861
  return !1;
2813
2862
  const e = m(this.tokensCache.access_token);
2814
- return S(e);
2863
+ return y(e);
2815
2864
  }
2816
2865
  }
2817
- class $e {
2866
+ class je {
2818
2867
  constructor(e, t) {
2819
2868
  this.twoFactorApi = e, this.subscribeStore = t, this.PARTIAL_AUTH_TIMEOUT_MS = 300 * 1e3, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6;
2820
2869
  const r = {
@@ -2908,7 +2957,7 @@ class $e {
2908
2957
  */
2909
2958
  async useRecoveryCode(e) {
2910
2959
  try {
2911
- const t = Ce(e);
2960
+ const t = Le(e);
2912
2961
  if (!t)
2913
2962
  throw new Error("Invalid recovery code format. Expected format: XXXX-XXXX or XXXXXXXX (alphanumeric).");
2914
2963
  if (this.recoverPartialAuthState(), !this.isVerificationRequired())
@@ -3109,29 +3158,29 @@ class $e {
3109
3158
  }
3110
3159
  }
3111
3160
  /**
3112
- * Begin 2FA method setup
3161
+ * Start 2FA method setup
3113
3162
  */
3114
- async beginMethodSetup(e) {
3163
+ async startMethodSetup(e, t) {
3115
3164
  try {
3116
- const t = await this.twoFactorApi.beginMethodSetup(e);
3117
- return this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: "", method: e }), t;
3118
- } catch (t) {
3119
- this.emitErrorAndThrow(t, "Begin 2FA method setup");
3165
+ const r = await this.twoFactorApi.startMethodSetup(e, t);
3166
+ return this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: "", method: e }), r;
3167
+ } catch (r) {
3168
+ this.emitErrorAndThrow(r, "Start 2FA method setup");
3120
3169
  }
3121
3170
  }
3122
3171
  /**
3123
- * Confirm 2FA method setup
3172
+ * Complete 2FA method setup
3124
3173
  */
3125
- async confirmMethodSetup(e, t) {
3174
+ async completeMethodSetup(e, t) {
3126
3175
  try {
3127
- const r = await this.twoFactorApi.confirmMethodSetup(e, t);
3176
+ const r = await this.twoFactorApi.completeMethodSetup(e, t);
3128
3177
  return this.subscribeStore.notify(a.TwoFactorEnabled, {
3129
3178
  recoveryCodes: [],
3130
3179
  clearRecoveryCodes: () => {
3131
3180
  }
3132
3181
  }), r;
3133
3182
  } catch (r) {
3134
- this.emitErrorAndThrow(r, "Confirm 2FA method setup");
3183
+ this.emitErrorAndThrow(r, "Complete 2FA method setup");
3135
3184
  }
3136
3185
  }
3137
3186
  /**
@@ -3211,7 +3260,7 @@ class $e {
3211
3260
  }
3212
3261
  }
3213
3262
  }
3214
- class Oe {
3263
+ class He {
3215
3264
  constructor(e, t, r = A) {
3216
3265
  this.userAPI = e, this.deviceService = t, this.platform = r;
3217
3266
  }
@@ -3273,10 +3322,10 @@ const O = class O {
3273
3322
  this.createSessionCallback = o, this.expiredSessionCallback = n, this.doRefreshTokens = h, await this.submitSessionCheck();
3274
3323
  };
3275
3324
  const { url: t, appId: r, scopes: s } = e;
3276
- this.url = t || K, this.appId = r, this.platform = e.platform ?? A, this.storageManager = new $({
3325
+ this.url = t || G, this.appId = r, this.platform = e.platform ?? A, this.storageManager = new $({
3277
3326
  prefix: e.keyStoragePrefix ?? "",
3278
3327
  storage: this.platform.storage
3279
- }), this.deviceService = new B(this.storageManager), this.authApi = new ye(e, this.storageManager, this.deviceService), this.appApi = new ve(e, this.storageManager, this.deviceService), this.userApi = new _e(e, this.storageManager, this.deviceService), this.settingApi = new we(e, this.storageManager, this.deviceService), this.tenantApi = new Te(e, this.storageManager, this.deviceService), this.invitationApi = new Se(e, this.storageManager, this.deviceService), this.twoFactorApi = new Ee(e, this.storageManager, this.deviceService), this.subscribeStore = new Ie(), this.tokenCacheService = new Ue(this.storageManager, this.authApi, this.subscribeStore, this.platform), this.scopes = s ?? te, this.createTenantForNewUser = e.createTenantForNewUser ?? !1, this.authService = new Re(
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(
3280
3329
  this.authApi,
3281
3330
  this.deviceService,
3282
3331
  this.storageManager,
@@ -3292,7 +3341,7 @@ const O = class O {
3292
3341
  this.appId ?? "",
3293
3342
  e.tokenExchange,
3294
3343
  this.platform
3295
- ), this.userService = new Oe(this.userApi, this.deviceService, this.platform), this.tenantService = new xe(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new Fe(this.invitationApi), this.twoFactorService = new $e(this.twoFactorApi, this.subscribeStore), this.twoFactor = this.twoFactorService, e.parseQueryParams && this.checkAndSetTokens(), this.setTokensToCacheFromLocalStorage();
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();
3296
3345
  }
3297
3346
  get origin() {
3298
3347
  return this.platform.getCurrentUrl()?.origin ?? "";
@@ -3439,7 +3488,7 @@ const O = class O {
3439
3488
  checkErrorsFromURL() {
3440
3489
  const t = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
3441
3490
  if (t) {
3442
- const r = be(t);
3491
+ const r = $e(t);
3443
3492
  return new Error(r);
3444
3493
  }
3445
3494
  }
@@ -4623,8 +4672,8 @@ const O = class O {
4623
4672
  this.twoFactorService.clearMagicLinkSession();
4624
4673
  }
4625
4674
  };
4626
- O.version = ee;
4627
- let L = O;
4675
+ O.version = re;
4676
+ let N = O;
4628
4677
  class p extends Error {
4629
4678
  constructor(e) {
4630
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);
@@ -4720,7 +4769,7 @@ class p extends Error {
4720
4769
  return this.status && (e += ` (HTTP ${this.status})`), e;
4721
4770
  }
4722
4771
  }
4723
- class N extends p {
4772
+ class K extends p {
4724
4773
  constructor(e, t) {
4725
4774
  super({
4726
4775
  code: "temporarily_unavailable",
@@ -4749,7 +4798,7 @@ class U extends p {
4749
4798
  }), this.name = "M2MConfigError";
4750
4799
  }
4751
4800
  }
4752
- const He = {
4801
+ const st = {
4753
4802
  InvalidRequest: "invalid_request",
4754
4803
  InvalidClient: "invalid_client",
4755
4804
  InvalidGrant: "invalid_grant",
@@ -4759,7 +4808,7 @@ const He = {
4759
4808
  RateLimitExceeded: "rate_limit_exceeded",
4760
4809
  ServerError: "server_error",
4761
4810
  TemporarilyUnavailable: "temporarily_unavailable"
4762
- }, T = {
4811
+ }, w = {
4763
4812
  /** Default token endpoint path */
4764
4813
  TOKEN_ENDPOINT: "/oauth2/token",
4765
4814
  /** Default request timeout in milliseconds */
@@ -4773,7 +4822,7 @@ const He = {
4773
4822
  /** Content-Type for token requests */
4774
4823
  CONTENT_TYPE: "application/x-www-form-urlencoded"
4775
4824
  };
4776
- class Le {
4825
+ class ze {
4777
4826
  constructor() {
4778
4827
  this.cache = /* @__PURE__ */ new Map();
4779
4828
  }
@@ -4791,7 +4840,7 @@ class Le {
4791
4840
  return this.cache.delete(e), Promise.resolve();
4792
4841
  }
4793
4842
  }
4794
- const Ne = {
4843
+ const Xe = {
4795
4844
  shouldRetry(i, e) {
4796
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;
4797
4846
  },
@@ -4799,7 +4848,7 @@ const Ne = {
4799
4848
  return Math.pow(2, i - 1) * 1e3;
4800
4849
  }
4801
4850
  };
4802
- class ze {
4851
+ class it {
4803
4852
  /**
4804
4853
  * Create a new M2M client
4805
4854
  *
@@ -4830,16 +4879,16 @@ class ze {
4830
4879
  scopes: e.scopes,
4831
4880
  audience: e.audience,
4832
4881
  autoRefresh: e.autoRefresh ?? !1,
4833
- refreshThreshold: e.refreshThreshold ?? T.REFRESH_THRESHOLD,
4834
- timeout: e.timeout ?? T.TIMEOUT,
4835
- retries: e.retries ?? T.RETRIES,
4836
- retryDelay: e.retryDelay ?? T.RETRY_DELAY,
4882
+ refreshThreshold: e.refreshThreshold ?? w.REFRESH_THRESHOLD,
4883
+ timeout: e.timeout ?? w.TIMEOUT,
4884
+ retries: e.retries ?? w.RETRIES,
4885
+ retryDelay: e.retryDelay ?? w.RETRY_DELAY,
4837
4886
  retryStrategy: e.retryStrategy,
4838
4887
  cache: e.cache,
4839
4888
  onTokenRequest: e.onTokenRequest,
4840
4889
  onTokenResponse: e.onTokenResponse,
4841
4890
  onError: e.onError
4842
- }, this.cache = e.cache ?? new Le(), this.retryStrategy = e.retryStrategy ?? Ne, this.tokenEndpoint = `${t}${T.TOKEN_ENDPOINT}`;
4891
+ }, this.cache = e.cache ?? new ze(), this.retryStrategy = e.retryStrategy ?? Xe, this.tokenEndpoint = `${t}${w.TOKEN_ENDPOINT}`;
4843
4892
  }
4844
4893
  /**
4845
4894
  * Get the cache key for this client
@@ -4930,7 +4979,7 @@ class ze {
4930
4979
  const o = await fetch(this.tokenEndpoint, {
4931
4980
  method: "POST",
4932
4981
  headers: {
4933
- "Content-Type": T.CONTENT_TYPE,
4982
+ "Content-Type": w.CONTENT_TYPE,
4934
4983
  Accept: "application/json"
4935
4984
  },
4936
4985
  body: t.toString(),
@@ -4959,7 +5008,7 @@ class ze {
4959
5008
  }
4960
5009
  return h;
4961
5010
  } catch (o) {
4962
- throw clearTimeout(s), o instanceof Error && o.name === "AbortError" ? new N(`Request timed out after ${this.config.timeout}ms`) : o instanceof TypeError && o.message.includes("fetch") ? new N(`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 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)));
4963
5012
  }
4964
5013
  }
4965
5014
  /**
@@ -5102,7 +5151,7 @@ class ze {
5102
5151
  const s = await fetch(t, {
5103
5152
  method: "POST",
5104
5153
  headers: {
5105
- "Content-Type": T.CONTENT_TYPE
5154
+ "Content-Type": w.CONTENT_TYPE
5106
5155
  },
5107
5156
  body: r.toString()
5108
5157
  });
@@ -5149,66 +5198,66 @@ class ze {
5149
5198
  export {
5150
5199
  b as APP_ID_HEADER_KEY,
5151
5200
  I as AUTHORIZATION_HEADER_KEY,
5152
- ve as AppAPI,
5153
- ye as AuthAPI,
5154
- Re as AuthService,
5155
- je as CLIAuthAPI,
5156
- Be as DEFAULT_GROUP_NAME,
5157
- te as DEFAULT_SCOPES,
5158
- Z as DEVICE_ID_HEADER_KEY,
5159
- Q as DEVICE_TYPE_HEADER_KEY,
5160
- ce as ERROR_MESSAGE_MAX_LENGTH,
5161
- Se as InvitationAPI,
5162
- Fe as InvitationService,
5163
- ze as M2MClient,
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,
5164
5213
  U as M2MConfigError,
5165
5214
  p as M2MError,
5166
- He as M2MErrorCodes,
5167
- N as M2MNetworkError,
5215
+ st as M2MErrorCodes,
5216
+ K as M2MNetworkError,
5168
5217
  R as M2MTokenParseError,
5169
- T as M2M_DEFAULTS,
5170
- qe as MINIMAL_DEFAULT_SCOPES,
5171
- ge as OS,
5172
- K as PASSFLOW_CLOUD_URL,
5173
- se as POPUP_HEIGHT,
5174
- ie as POPUP_POLL_INTERVAL_MS,
5175
- oe as POPUP_TIMEOUT_MS,
5176
- re as POPUP_WIDTH,
5177
- L as Passflow,
5178
- E as PassflowAdminEndpointPaths,
5218
+ 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,
5227
+ T as PassflowAdminEndpointPaths,
5179
5228
  c as PassflowEndpointPaths,
5180
5229
  l as PassflowError,
5181
5230
  a as PassflowEvent,
5182
- Y as PopupClosedError,
5183
- pe as Providers,
5184
- _ as RequestMethod,
5185
- ee as SDK_VERSION,
5186
- V as SessionState,
5187
- we as SettingAPI,
5188
- G as TOKEN_EXPIRY_BUFFER_SECONDS,
5189
- Te as TenantAPI,
5190
- xe as TenantService,
5191
- Pe as TenantUserMembership,
5192
- Ue as TokenCacheService,
5193
- y as TokenDeliveryMode,
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,
5242
+ v as TokenDeliveryMode,
5194
5243
  k as TokenType,
5195
- Ee as TwoFactorApiClient,
5196
- fe as TwoFactorPolicy,
5197
- $e as TwoFactorService,
5198
- ae as USERNAME_MAX_LENGTH,
5199
- ne as USERNAME_MIN_LENGTH,
5200
- _e as UserAPI,
5201
- Oe as UserService,
5202
- le as WebAdapter,
5203
- Ye as getOSFromDeviceType,
5204
- S as isTokenExpired,
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,
5253
+ y as isTokenExpired,
5205
5254
  P as isValidEmail,
5206
5255
  D as isValidJWTFormat,
5207
5256
  x as isValidPhoneNumber,
5208
- Ae as isValidUsername,
5257
+ Oe as isValidUsername,
5209
5258
  m as parseToken,
5210
- v as pathWithParams,
5211
- be as sanitizeErrorMessage,
5259
+ _ as pathWithParams,
5260
+ $e as sanitizeErrorMessage,
5212
5261
  A as webAdapter
5213
5262
  };
5214
5263
  //# sourceMappingURL=index.mjs.map