@passflow/core 0.13.3 → 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.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +431 -238
- package/dist/index.mjs.map +1 -1
- package/dist/lib/api/axios-client.d.ts.map +1 -1
- package/dist/lib/api/model.d.ts +2 -2
- package/dist/lib/api/model.d.ts.map +1 -1
- package/dist/lib/api/two-factor.d.ts +9 -6
- package/dist/lib/api/two-factor.d.ts.map +1 -1
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/services/two-factor-service.d.ts +4 -4
- package/dist/lib/services/two-factor-service.d.ts.map +1 -1
- package/dist/lib/upgrade/challenge.d.ts +62 -0
- package/dist/lib/upgrade/challenge.d.ts.map +1 -0
- package/dist/lib/upgrade/controller.d.ts +94 -0
- package/dist/lib/upgrade/controller.d.ts.map +1 -0
- package/dist/lib/upgrade/factors.d.ts +97 -0
- package/dist/lib/upgrade/factors.d.ts.map +1 -0
- package/dist/lib/upgrade/index.d.ts +5 -0
- package/dist/lib/upgrade/index.d.ts.map +1 -0
- package/dist/lib/upgrade/select.d.ts +48 -0
- package/dist/lib/upgrade/select.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { v4 as
|
|
3
|
-
import { startAuthentication as
|
|
4
|
-
const
|
|
5
|
-
version:
|
|
6
|
-
},
|
|
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 W = "0.13.3", J = {
|
|
|
18
18
|
}
|
|
19
19
|
return { raw: i, tenants: e };
|
|
20
20
|
};
|
|
21
|
-
function
|
|
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
|
|
28
|
+
class ye {
|
|
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 ?
|
|
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
|
|
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 =
|
|
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" ?
|
|
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 || {}),
|
|
69
|
-
class
|
|
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
|
}
|
|
@@ -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(
|
|
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(
|
|
179
|
+
e && Object.values(H).includes(e) && (this.sessionState = e);
|
|
180
180
|
} catch {
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -217,7 +217,7 @@ class q {
|
|
|
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
|
}
|
|
@@ -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 ===
|
|
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 ===
|
|
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(
|
|
327
|
+
if (e && Object.values(v).includes(e))
|
|
328
328
|
return e;
|
|
329
329
|
} catch {
|
|
330
330
|
}
|
|
@@ -400,9 +400,9 @@ class $ {
|
|
|
400
400
|
return `${this.keyStoragePrefix}${e}`;
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
|
-
class
|
|
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 B {
|
|
|
413
413
|
return e;
|
|
414
414
|
}
|
|
415
415
|
generateUniqueDeviceId() {
|
|
416
|
-
return
|
|
416
|
+
return te();
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
class
|
|
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
|
|
424
|
+
class Se {
|
|
425
425
|
constructor() {
|
|
426
426
|
this.passkeys = {
|
|
427
|
-
startRegistration: (e) =>
|
|
428
|
-
startAuthentication: (e) =>
|
|
427
|
+
startRegistration: (e) => se({ optionsJSON: e }),
|
|
428
|
+
startAuthentication: (e) => re({ 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 ??
|
|
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
|
|
564
|
+
clearInterval(f), u(new W());
|
|
565
565
|
return;
|
|
566
566
|
}
|
|
567
|
-
if (Date.now() - g >
|
|
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
|
|
574
|
-
clearInterval(f), h.close(), d({ callbackSearch:
|
|
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
|
-
},
|
|
578
|
+
}, le);
|
|
579
579
|
}) : (window.location.href = e, new Promise(() => {
|
|
580
580
|
}));
|
|
581
581
|
}
|
|
@@ -633,44 +633,88 @@ class le {
|
|
|
633
633
|
return "web";
|
|
634
634
|
}
|
|
635
635
|
}
|
|
636
|
-
const
|
|
637
|
-
|
|
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
|
+
const e = {};
|
|
638
|
+
K.lastIndex = 0;
|
|
639
|
+
for (const t of i.matchAll(K)) {
|
|
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 ? Ee(s) : o ?? "";
|
|
645
|
+
}
|
|
646
|
+
return e;
|
|
647
|
+
}, J = (i) => {
|
|
648
|
+
const e = typeof i == "number" ? i : Number.parseInt(String(i ?? ""), 10);
|
|
649
|
+
return Number.isFinite(e) && e > 0 ? e : void 0;
|
|
650
|
+
}, Ie = (i, e) => {
|
|
651
|
+
if (!i || !/(^|[\s,])Bearer\b/i.test(i))
|
|
652
|
+
return;
|
|
653
|
+
const t = _e(i);
|
|
654
|
+
if (t.error === we)
|
|
655
|
+
return {
|
|
656
|
+
acrValues: t.acr_values || void 0,
|
|
657
|
+
maxAge: J(t.max_age),
|
|
658
|
+
status: e
|
|
659
|
+
};
|
|
660
|
+
}, be = (i, e) => {
|
|
661
|
+
if (!i || typeof i != "object")
|
|
662
|
+
return;
|
|
663
|
+
const t = i;
|
|
664
|
+
if (t.error === Te)
|
|
665
|
+
return {
|
|
666
|
+
acrValues: typeof t.acr_values == "string" && t.acr_values ? t.acr_values : void 0,
|
|
667
|
+
maxAge: J(t.max_age),
|
|
668
|
+
status: e
|
|
669
|
+
};
|
|
670
|
+
}, Ae = (i, e, t) => {
|
|
671
|
+
if (!(i !== 401 && i !== 403))
|
|
672
|
+
return Ie(e("www-authenticate"), i) ?? be(t, i);
|
|
673
|
+
};
|
|
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 || {});
|
|
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
|
|
644
|
-
function
|
|
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) {
|
|
645
682
|
return i;
|
|
646
683
|
}
|
|
647
|
-
function
|
|
684
|
+
function E(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
|
|
654
|
-
const
|
|
655
|
-
|
|
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
|
+
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 ??
|
|
706
|
+
this._platform = e.platform ?? C, this.url = s || Y, this.storageManager = t ?? new L({
|
|
663
707
|
prefix: n ?? ""
|
|
664
|
-
}), this.deviceService = r ?? new
|
|
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 = {
|
|
665
709
|
...this.defaultHeaders,
|
|
666
|
-
[
|
|
710
|
+
[A]: o
|
|
667
711
|
});
|
|
668
712
|
const h = this.deviceService.getDeviceId();
|
|
669
713
|
this.defaultHeaders = {
|
|
670
714
|
...this.defaultHeaders,
|
|
671
|
-
[
|
|
672
|
-
[
|
|
673
|
-
}, this.detectCookieSupport(), this.instance =
|
|
715
|
+
[ne]: h,
|
|
716
|
+
[ae]: this._platform.getDeviceType()
|
|
717
|
+
}, this.detectCookieSupport(), this.instance = M.create({
|
|
674
718
|
baseURL: this.url,
|
|
675
719
|
headers: { ...this.defaultHeaders }
|
|
676
720
|
}), this.instance.interceptors.request.use(async (d) => {
|
|
@@ -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 (
|
|
738
|
+
if (y(g, j) && 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 && !Pe(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 >=
|
|
823
|
+
if (o >= Me)
|
|
780
824
|
return Promise.reject(e);
|
|
781
|
-
let n =
|
|
825
|
+
let n = De * 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);
|
|
@@ -842,13 +886,13 @@ class w {
|
|
|
842
886
|
setAppId(e) {
|
|
843
887
|
this.appId = e, this.defaultHeaders = {
|
|
844
888
|
...this.defaultHeaders,
|
|
845
|
-
[
|
|
846
|
-
}, this.instance.defaults.headers.common[
|
|
889
|
+
[A]: e
|
|
890
|
+
}, this.instance.defaults.headers.common[A] = e;
|
|
847
891
|
}
|
|
848
892
|
}
|
|
849
|
-
class
|
|
893
|
+
class xe {
|
|
850
894
|
constructor(e, t, r) {
|
|
851
|
-
this.axiosClient = new
|
|
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
|
|
904
|
+
class Ue {
|
|
861
905
|
constructor(e, t, r) {
|
|
862
|
-
this.axiosClient = new
|
|
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 ?
|
|
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() {
|
|
@@ -936,7 +980,7 @@ class ye {
|
|
|
936
980
|
return this.axiosClient.post(c.resetPassword, s, {
|
|
937
981
|
headers: {
|
|
938
982
|
[I]: `Bearer ${r}`,
|
|
939
|
-
[
|
|
983
|
+
[A]: void 0
|
|
940
984
|
}
|
|
941
985
|
});
|
|
942
986
|
}
|
|
@@ -946,7 +990,7 @@ class ye {
|
|
|
946
990
|
create_tenant: o ?? !1,
|
|
947
991
|
device: t,
|
|
948
992
|
os: r
|
|
949
|
-
}, h = s ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 =
|
|
988
|
-
const d = o ? { [
|
|
1031
|
+
!o && s && (h = T.passkeyValidate);
|
|
1032
|
+
const d = o ? { [A]: o } : {};
|
|
989
1033
|
return this.axiosClient.post(h, n, { headers: d });
|
|
990
1034
|
}
|
|
991
1035
|
}
|
|
992
|
-
class
|
|
1036
|
+
class mt {
|
|
993
1037
|
constructor(e, t, r) {
|
|
994
|
-
this.axiosClient = new
|
|
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 =
|
|
1044
|
+
const t = E(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
|
|
1051
|
+
class $e {
|
|
1008
1052
|
constructor(e, t, r) {
|
|
1009
|
-
this.axiosClient = new
|
|
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 =
|
|
1077
|
+
const r = E(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 =
|
|
1091
|
+
const t = E(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 =
|
|
1102
|
+
const t = E(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 =
|
|
1113
|
+
const t = E(c.invitationGetLink, {
|
|
1070
1114
|
invitationID: e
|
|
1071
1115
|
});
|
|
1072
1116
|
return this.axiosClient.get(t);
|
|
1073
1117
|
}
|
|
1074
1118
|
}
|
|
1075
|
-
class
|
|
1119
|
+
class Oe {
|
|
1076
1120
|
constructor(e, t, r) {
|
|
1077
|
-
this.axiosClient = new
|
|
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
|
|
1136
|
+
class Le {
|
|
1093
1137
|
constructor(e, t, r) {
|
|
1094
|
-
this.axiosClient = new
|
|
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
|
|
1369
|
+
class Ne {
|
|
1326
1370
|
constructor(e, t, r) {
|
|
1327
|
-
this.axiosClient = new
|
|
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
|
-
*
|
|
1513
|
-
* POST /v2/user/2fa/
|
|
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
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1562
|
+
startMethodSetup(e, t) {
|
|
1563
|
+
return this.axiosClient.post(c.TwoFactorSetupStart, {
|
|
1564
|
+
...t,
|
|
1565
|
+
method: e
|
|
1566
|
+
});
|
|
1518
1567
|
}
|
|
1519
1568
|
/**
|
|
1520
|
-
*
|
|
1521
|
-
* POST /v2/user/2fa/
|
|
1569
|
+
* Complete 2FA method setup.
|
|
1570
|
+
* POST /v2/user/2fa/setup/complete
|
|
1522
1571
|
*/
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
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 =
|
|
1583
|
+
const t = E(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 =
|
|
1628
|
+
const t = E(c.TwoFactorTrustedDeviceRevoke, { id: e });
|
|
1578
1629
|
return this.axiosClient.delete(t);
|
|
1579
1630
|
}
|
|
1580
1631
|
}
|
|
1581
|
-
class
|
|
1632
|
+
class Ke {
|
|
1582
1633
|
constructor(e, t, r) {
|
|
1583
|
-
this.axiosClient = new
|
|
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
|
|
1678
|
+
class Ge {
|
|
1628
1679
|
constructor() {
|
|
1629
1680
|
this.subscribers = /* @__PURE__ */ new Map();
|
|
1630
1681
|
}
|
|
@@ -1664,42 +1715,42 @@ class Ie {
|
|
|
1664
1715
|
});
|
|
1665
1716
|
}
|
|
1666
1717
|
}
|
|
1667
|
-
function
|
|
1718
|
+
function P(i) {
|
|
1668
1719
|
if (!i || typeof i != "string") return !1;
|
|
1669
1720
|
const e = i.split(".");
|
|
1670
1721
|
if (e.length !== 3) return !1;
|
|
1671
1722
|
const t = /^[A-Za-z0-9_-]+$/;
|
|
1672
1723
|
return e.every((r) => t.test(r) && r.length > 0);
|
|
1673
1724
|
}
|
|
1674
|
-
function
|
|
1675
|
-
return i.replace(/<[^>]*>/g, "").substring(0,
|
|
1725
|
+
function Ve(i) {
|
|
1726
|
+
return i.replace(/<[^>]*>/g, "").substring(0, ke);
|
|
1676
1727
|
}
|
|
1677
|
-
function
|
|
1728
|
+
function x(i) {
|
|
1678
1729
|
if (!i || typeof i != "string") return !1;
|
|
1679
1730
|
const e = i.trim();
|
|
1680
1731
|
return e.length === 0 ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
|
|
1681
1732
|
}
|
|
1682
|
-
function
|
|
1733
|
+
function U(i) {
|
|
1683
1734
|
if (!i || typeof i != "string") return !1;
|
|
1684
1735
|
const e = i.trim();
|
|
1685
1736
|
return /^\+[1-9]\d{1,14}$/.test(e);
|
|
1686
1737
|
}
|
|
1687
|
-
function
|
|
1738
|
+
function qe(i) {
|
|
1688
1739
|
if (!i || typeof i != "string") return !1;
|
|
1689
1740
|
const e = i.trim();
|
|
1690
|
-
return e.length <
|
|
1741
|
+
return e.length < ge || e.length > fe ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
|
|
1691
1742
|
}
|
|
1692
|
-
function
|
|
1743
|
+
function R(i, e = 6) {
|
|
1693
1744
|
return !i || typeof i != "string" ? !1 : (e === 8 ? /^\d{8}$/ : /^\d{6}$/).test(i);
|
|
1694
1745
|
}
|
|
1695
|
-
function
|
|
1746
|
+
function Be(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
|
|
1701
|
-
constructor(e, t, r, s, o, n, h, d, u, g, f,
|
|
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 =
|
|
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();
|
|
1703
1754
|
}
|
|
1704
1755
|
/**
|
|
1705
1756
|
* Initialize session state on page load for cookie/BFF mode
|
|
@@ -1766,7 +1817,7 @@ class Re {
|
|
|
1766
1817
|
throw new Error(`BFF token storage failed: ${t.status}`);
|
|
1767
1818
|
}
|
|
1768
1819
|
async signIn(e) {
|
|
1769
|
-
if ("email" in e && e.email && !
|
|
1820
|
+
if ("email" in e && e.email && !x(e.email)) {
|
|
1770
1821
|
const s = new Error("Invalid email format"), o = {
|
|
1771
1822
|
message: "Invalid email format",
|
|
1772
1823
|
originalError: s,
|
|
@@ -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 && !
|
|
1828
|
+
if ("username" in e && e.username && !qe(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 = {
|
|
@@ -1784,7 +1835,7 @@ class Re {
|
|
|
1784
1835
|
};
|
|
1785
1836
|
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1786
1837
|
}
|
|
1787
|
-
if ("phone" in e && e.phone && !
|
|
1838
|
+
if ("phone" in e && e.phone && !U(e.phone)) {
|
|
1788
1839
|
const s = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), o = {
|
|
1789
1840
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
1790
1841
|
originalError: s,
|
|
@@ -1815,7 +1866,7 @@ class Re {
|
|
|
1815
1866
|
}
|
|
1816
1867
|
}
|
|
1817
1868
|
async signUp(e) {
|
|
1818
|
-
if (e.user.email && !
|
|
1869
|
+
if (e.user.email && !x(e.user.email)) {
|
|
1819
1870
|
const t = new Error("Invalid email format"), r = {
|
|
1820
1871
|
message: "Invalid email format",
|
|
1821
1872
|
originalError: t,
|
|
@@ -1823,7 +1874,7 @@ class Re {
|
|
|
1823
1874
|
};
|
|
1824
1875
|
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1825
1876
|
}
|
|
1826
|
-
if (e.user.phone_number && !
|
|
1877
|
+
if (e.user.phone_number && !U(e.user.phone_number)) {
|
|
1827
1878
|
const t = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), r = {
|
|
1828
1879
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
1829
1880
|
originalError: t,
|
|
@@ -1848,7 +1899,7 @@ class Re {
|
|
|
1848
1899
|
}
|
|
1849
1900
|
}
|
|
1850
1901
|
async passwordlessSignIn(e) {
|
|
1851
|
-
if (e.email && !
|
|
1902
|
+
if (e.email && !x(e.email)) {
|
|
1852
1903
|
const s = new Error("Invalid email format"), o = {
|
|
1853
1904
|
message: "Invalid email format",
|
|
1854
1905
|
originalError: s,
|
|
@@ -1856,7 +1907,7 @@ class Re {
|
|
|
1856
1907
|
};
|
|
1857
1908
|
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1858
1909
|
}
|
|
1859
|
-
if (e.phone && !
|
|
1910
|
+
if (e.phone && !U(e.phone)) {
|
|
1860
1911
|
const s = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), o = {
|
|
1861
1912
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
1862
1913
|
originalError: s,
|
|
@@ -1981,13 +2032,13 @@ class Re {
|
|
|
1981
2032
|
message: r instanceof Error ? r.message : "Token refresh failed",
|
|
1982
2033
|
originalError: r,
|
|
1983
2034
|
code: r instanceof l ? r.id : void 0,
|
|
1984
|
-
details:
|
|
2035
|
+
details: M.isAxiosError(r) && r.response ? {
|
|
1985
2036
|
status: r.response.status,
|
|
1986
2037
|
data: r.response.data
|
|
1987
2038
|
} : void 0
|
|
1988
2039
|
};
|
|
1989
2040
|
this.subscribeStore.notify(a.Error, s);
|
|
1990
|
-
const o =
|
|
2041
|
+
const o = M.isAxiosError(r) && r.response?.status && r.response.status >= 400 && r.response.status < 500;
|
|
1991
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;
|
|
1992
2043
|
}
|
|
1993
2044
|
}
|
|
@@ -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
|
|
2164
|
+
code: o instanceof W ? "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 : !
|
|
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
|
|
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
|
|
2265
|
+
class je {
|
|
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
|
|
2310
|
+
class He {
|
|
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
|
|
2274
|
-
return new
|
|
2324
|
+
function ze() {
|
|
2325
|
+
return new He();
|
|
2275
2326
|
}
|
|
2276
|
-
class
|
|
2327
|
+
class Xe {
|
|
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
|
|
2397
|
+
class We {
|
|
2347
2398
|
constructor(e, t, r) {
|
|
2348
|
-
this.tenantApi = e, this.scopes = t, this.logger = r ||
|
|
2399
|
+
this.tenantApi = e, this.scopes = t, this.logger = r || ze();
|
|
2349
2400
|
}
|
|
2350
2401
|
/**
|
|
2351
2402
|
* Handle Passflow API errors
|
|
@@ -2354,7 +2405,7 @@ class xe {
|
|
|
2354
2405
|
* @throws Formatted error with Passflow API error details
|
|
2355
2406
|
*/
|
|
2356
2407
|
handlePassflowError(e, t) {
|
|
2357
|
-
if (
|
|
2408
|
+
if (M.isAxiosError(e) && e.response?.data) {
|
|
2358
2409
|
const r = e.response.data;
|
|
2359
2410
|
if (typeof r == "object" && r !== null && "error" in r && typeof r.error == "object" && r.error !== null) {
|
|
2360
2411
|
const s = r.error;
|
|
@@ -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
|
|
2469
|
+
return new Xe(t);
|
|
2419
2470
|
} catch (t) {
|
|
2420
2471
|
this.handlePassflowError(t, `Get tenant user membership failed for tenant ID ${e}`);
|
|
2421
2472
|
}
|
|
@@ -2713,8 +2764,8 @@ class xe {
|
|
|
2713
2764
|
}
|
|
2714
2765
|
}
|
|
2715
2766
|
}
|
|
2716
|
-
class
|
|
2717
|
-
constructor(e, t, r, s =
|
|
2767
|
+
class Je {
|
|
2768
|
+
constructor(e, t, r, s = C) {
|
|
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() {
|
|
@@ -2727,7 +2778,7 @@ class Ue {
|
|
|
2727
2778
|
return;
|
|
2728
2779
|
}
|
|
2729
2780
|
const t = m(e.access_token);
|
|
2730
|
-
|
|
2781
|
+
y(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 })) : (this.setTokensCache(e), this.startTokenCheck());
|
|
2731
2782
|
} catch (e) {
|
|
2732
2783
|
const t = {
|
|
2733
2784
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
@@ -2791,7 +2842,7 @@ class Ue {
|
|
|
2791
2842
|
if (!this.tokensCache.access_token)
|
|
2792
2843
|
return this.tokensCache;
|
|
2793
2844
|
const e = m(this.tokensCache.access_token);
|
|
2794
|
-
return
|
|
2845
|
+
return y(e) && !this.tokenExpiredFlag ? (await this.refreshTokensCache(this.tokensCache), this.tokensCache) : this.tokensCache;
|
|
2795
2846
|
} catch (e) {
|
|
2796
2847
|
const t = {
|
|
2797
2848
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
@@ -2809,10 +2860,10 @@ class Ue {
|
|
|
2809
2860
|
if (!this.tokensCache.access_token)
|
|
2810
2861
|
return !1;
|
|
2811
2862
|
const e = m(this.tokensCache.access_token);
|
|
2812
|
-
return
|
|
2863
|
+
return y(e);
|
|
2813
2864
|
}
|
|
2814
2865
|
}
|
|
2815
|
-
class
|
|
2866
|
+
class Ze {
|
|
2816
2867
|
constructor(e, t) {
|
|
2817
2868
|
this.twoFactorApi = e, this.subscribeStore = t, this.PARTIAL_AUTH_TIMEOUT_MS = 300 * 1e3, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6;
|
|
2818
2869
|
const r = {
|
|
@@ -2865,7 +2916,7 @@ class $e {
|
|
|
2865
2916
|
* Returns recovery codes that MUST be displayed to user
|
|
2866
2917
|
*/
|
|
2867
2918
|
async confirmSetup(e) {
|
|
2868
|
-
if (!
|
|
2919
|
+
if (!R(e, this.totpDigits))
|
|
2869
2920
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2870
2921
|
try {
|
|
2871
2922
|
const t = await this.twoFactorApi.confirmSetup({ code: e });
|
|
@@ -2884,7 +2935,7 @@ class $e {
|
|
|
2884
2935
|
* Completes authentication if successful
|
|
2885
2936
|
*/
|
|
2886
2937
|
async verify(e) {
|
|
2887
|
-
if (!
|
|
2938
|
+
if (!R(e, this.totpDigits))
|
|
2888
2939
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2889
2940
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired())
|
|
2890
2941
|
throw new Error("2FA verification expired or not required. User must sign in first.");
|
|
@@ -2906,7 +2957,7 @@ class $e {
|
|
|
2906
2957
|
*/
|
|
2907
2958
|
async useRecoveryCode(e) {
|
|
2908
2959
|
try {
|
|
2909
|
-
const t =
|
|
2960
|
+
const t = Be(e);
|
|
2910
2961
|
if (!t)
|
|
2911
2962
|
throw new Error("Invalid recovery code format. Expected format: XXXX-XXXX or XXXXXXXX (alphanumeric).");
|
|
2912
2963
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired())
|
|
@@ -2932,7 +2983,7 @@ class $e {
|
|
|
2932
2983
|
* Disable 2FA (requires TOTP verification)
|
|
2933
2984
|
*/
|
|
2934
2985
|
async disable(e) {
|
|
2935
|
-
if (!
|
|
2986
|
+
if (!R(e, this.totpDigits))
|
|
2936
2987
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2937
2988
|
try {
|
|
2938
2989
|
const t = await this.twoFactorApi.disable({ code: e });
|
|
@@ -2945,7 +2996,7 @@ class $e {
|
|
|
2945
2996
|
* Regenerate recovery codes
|
|
2946
2997
|
*/
|
|
2947
2998
|
async regenerateRecoveryCodes(e) {
|
|
2948
|
-
if (!
|
|
2999
|
+
if (!R(e, this.totpDigits))
|
|
2949
3000
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2950
3001
|
try {
|
|
2951
3002
|
const t = await this.twoFactorApi.regenerateRecoveryCodes({ code: e }), r = [...t.recovery_codes];
|
|
@@ -3107,29 +3158,29 @@ class $e {
|
|
|
3107
3158
|
}
|
|
3108
3159
|
}
|
|
3109
3160
|
/**
|
|
3110
|
-
*
|
|
3161
|
+
* Start 2FA method setup
|
|
3111
3162
|
*/
|
|
3112
|
-
async
|
|
3163
|
+
async startMethodSetup(e, t) {
|
|
3113
3164
|
try {
|
|
3114
|
-
const
|
|
3115
|
-
return this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: "", method: e }),
|
|
3116
|
-
} catch (
|
|
3117
|
-
this.emitErrorAndThrow(
|
|
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");
|
|
3118
3169
|
}
|
|
3119
3170
|
}
|
|
3120
3171
|
/**
|
|
3121
|
-
*
|
|
3172
|
+
* Complete 2FA method setup
|
|
3122
3173
|
*/
|
|
3123
|
-
async
|
|
3174
|
+
async completeMethodSetup(e, t) {
|
|
3124
3175
|
try {
|
|
3125
|
-
const r = await this.twoFactorApi.
|
|
3176
|
+
const r = await this.twoFactorApi.completeMethodSetup(e, t);
|
|
3126
3177
|
return this.subscribeStore.notify(a.TwoFactorEnabled, {
|
|
3127
3178
|
recoveryCodes: [],
|
|
3128
3179
|
clearRecoveryCodes: () => {
|
|
3129
3180
|
}
|
|
3130
3181
|
}), r;
|
|
3131
3182
|
} catch (r) {
|
|
3132
|
-
this.emitErrorAndThrow(r, "
|
|
3183
|
+
this.emitErrorAndThrow(r, "Complete 2FA method setup");
|
|
3133
3184
|
}
|
|
3134
3185
|
}
|
|
3135
3186
|
/**
|
|
@@ -3209,8 +3260,8 @@ class $e {
|
|
|
3209
3260
|
}
|
|
3210
3261
|
}
|
|
3211
3262
|
}
|
|
3212
|
-
class
|
|
3213
|
-
constructor(e, t, r =
|
|
3263
|
+
class Qe {
|
|
3264
|
+
constructor(e, t, r = C) {
|
|
3214
3265
|
this.userAPI = e, this.deviceService = t, this.platform = r;
|
|
3215
3266
|
}
|
|
3216
3267
|
/**
|
|
@@ -3261,7 +3312,7 @@ class Oe {
|
|
|
3261
3312
|
return await this.userAPI.addUserPasskeyComplete(d, s, n);
|
|
3262
3313
|
}
|
|
3263
3314
|
}
|
|
3264
|
-
const
|
|
3315
|
+
const N = class N {
|
|
3265
3316
|
constructor(e) {
|
|
3266
3317
|
this.doRefreshTokens = !1, this.session = async ({
|
|
3267
3318
|
createSession: o,
|
|
@@ -3271,10 +3322,10 @@ const O = class O {
|
|
|
3271
3322
|
this.createSessionCallback = o, this.expiredSessionCallback = n, this.doRefreshTokens = h, await this.submitSessionCheck();
|
|
3272
3323
|
};
|
|
3273
3324
|
const { url: t, appId: r, scopes: s } = e;
|
|
3274
|
-
this.url = t ||
|
|
3325
|
+
this.url = t || Y, this.appId = r, this.platform = e.platform ?? C, this.storageManager = new L({
|
|
3275
3326
|
prefix: e.keyStoragePrefix ?? "",
|
|
3276
3327
|
storage: this.platform.storage
|
|
3277
|
-
}), this.deviceService = new
|
|
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(
|
|
3278
3329
|
this.authApi,
|
|
3279
3330
|
this.deviceService,
|
|
3280
3331
|
this.storageManager,
|
|
@@ -3290,7 +3341,7 @@ const O = class O {
|
|
|
3290
3341
|
this.appId ?? "",
|
|
3291
3342
|
e.tokenExchange,
|
|
3292
3343
|
this.platform
|
|
3293
|
-
), this.userService = new
|
|
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();
|
|
3294
3345
|
}
|
|
3295
3346
|
get origin() {
|
|
3296
3347
|
return this.platform.getCurrentUrl()?.origin ?? "";
|
|
@@ -3401,7 +3452,7 @@ const O = class O {
|
|
|
3401
3452
|
const s = t.get("access_token"), o = t.get("refresh_token"), n = t.get("id_token"), h = t.get("scopes")?.split(",") ?? this.scopes;
|
|
3402
3453
|
let d;
|
|
3403
3454
|
if (s) {
|
|
3404
|
-
if (!
|
|
3455
|
+
if (!P(s)) {
|
|
3405
3456
|
const u = {
|
|
3406
3457
|
message: "Invalid access token format received",
|
|
3407
3458
|
code: "INVALID_TOKEN_FORMAT"
|
|
@@ -3409,7 +3460,7 @@ const O = class O {
|
|
|
3409
3460
|
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3410
3461
|
return;
|
|
3411
3462
|
}
|
|
3412
|
-
if (o && !
|
|
3463
|
+
if (o && !P(o)) {
|
|
3413
3464
|
const u = {
|
|
3414
3465
|
message: "Invalid refresh token format received",
|
|
3415
3466
|
code: "INVALID_TOKEN_FORMAT"
|
|
@@ -3417,7 +3468,7 @@ const O = class O {
|
|
|
3417
3468
|
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3418
3469
|
return;
|
|
3419
3470
|
}
|
|
3420
|
-
if (n && !
|
|
3471
|
+
if (n && !P(n)) {
|
|
3421
3472
|
const u = {
|
|
3422
3473
|
message: "Invalid ID token format received",
|
|
3423
3474
|
code: "INVALID_TOKEN_FORMAT"
|
|
@@ -3437,7 +3488,7 @@ const O = class O {
|
|
|
3437
3488
|
checkErrorsFromURL() {
|
|
3438
3489
|
const t = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
|
|
3439
3490
|
if (t) {
|
|
3440
|
-
const r =
|
|
3491
|
+
const r = Ve(t);
|
|
3441
3492
|
return new Error(r);
|
|
3442
3493
|
}
|
|
3443
3494
|
}
|
|
@@ -4621,8 +4672,8 @@ const O = class O {
|
|
|
4621
4672
|
this.twoFactorService.clearMagicLinkSession();
|
|
4622
4673
|
}
|
|
4623
4674
|
};
|
|
4624
|
-
|
|
4625
|
-
let
|
|
4675
|
+
N.version = ce;
|
|
4676
|
+
let G = N;
|
|
4626
4677
|
class p extends Error {
|
|
4627
4678
|
constructor(e) {
|
|
4628
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);
|
|
@@ -4718,7 +4769,7 @@ class p extends Error {
|
|
|
4718
4769
|
return this.status && (e += ` (HTTP ${this.status})`), e;
|
|
4719
4770
|
}
|
|
4720
4771
|
}
|
|
4721
|
-
class
|
|
4772
|
+
class V extends p {
|
|
4722
4773
|
constructor(e, t) {
|
|
4723
4774
|
super({
|
|
4724
4775
|
code: "temporarily_unavailable",
|
|
@@ -4728,7 +4779,7 @@ class N extends p {
|
|
|
4728
4779
|
}), this.name = "M2MNetworkError";
|
|
4729
4780
|
}
|
|
4730
4781
|
}
|
|
4731
|
-
class
|
|
4782
|
+
class F extends p {
|
|
4732
4783
|
constructor(e, t) {
|
|
4733
4784
|
super({
|
|
4734
4785
|
code: "invalid_request",
|
|
@@ -4738,7 +4789,7 @@ class R extends p {
|
|
|
4738
4789
|
}), this.name = "M2MTokenParseError";
|
|
4739
4790
|
}
|
|
4740
4791
|
}
|
|
4741
|
-
class
|
|
4792
|
+
class $ extends p {
|
|
4742
4793
|
constructor(e) {
|
|
4743
4794
|
super({
|
|
4744
4795
|
code: "invalid_request",
|
|
@@ -4747,7 +4798,7 @@ class U extends p {
|
|
|
4747
4798
|
}), this.name = "M2MConfigError";
|
|
4748
4799
|
}
|
|
4749
4800
|
}
|
|
4750
|
-
const
|
|
4801
|
+
const vt = {
|
|
4751
4802
|
InvalidRequest: "invalid_request",
|
|
4752
4803
|
InvalidClient: "invalid_client",
|
|
4753
4804
|
InvalidGrant: "invalid_grant",
|
|
@@ -4757,7 +4808,7 @@ const He = {
|
|
|
4757
4808
|
RateLimitExceeded: "rate_limit_exceeded",
|
|
4758
4809
|
ServerError: "server_error",
|
|
4759
4810
|
TemporarilyUnavailable: "temporarily_unavailable"
|
|
4760
|
-
},
|
|
4811
|
+
}, w = {
|
|
4761
4812
|
/** Default token endpoint path */
|
|
4762
4813
|
TOKEN_ENDPOINT: "/oauth2/token",
|
|
4763
4814
|
/** Default request timeout in milliseconds */
|
|
@@ -4771,7 +4822,7 @@ const He = {
|
|
|
4771
4822
|
/** Content-Type for token requests */
|
|
4772
4823
|
CONTENT_TYPE: "application/x-www-form-urlencoded"
|
|
4773
4824
|
};
|
|
4774
|
-
class
|
|
4825
|
+
class et {
|
|
4775
4826
|
constructor() {
|
|
4776
4827
|
this.cache = /* @__PURE__ */ new Map();
|
|
4777
4828
|
}
|
|
@@ -4789,7 +4840,7 @@ class Le {
|
|
|
4789
4840
|
return this.cache.delete(e), Promise.resolve();
|
|
4790
4841
|
}
|
|
4791
4842
|
}
|
|
4792
|
-
const
|
|
4843
|
+
const tt = {
|
|
4793
4844
|
shouldRetry(i, e) {
|
|
4794
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;
|
|
4795
4846
|
},
|
|
@@ -4797,7 +4848,7 @@ const Ne = {
|
|
|
4797
4848
|
return Math.pow(2, i - 1) * 1e3;
|
|
4798
4849
|
}
|
|
4799
4850
|
};
|
|
4800
|
-
class
|
|
4851
|
+
class yt {
|
|
4801
4852
|
/**
|
|
4802
4853
|
* Create a new M2M client
|
|
4803
4854
|
*
|
|
@@ -4815,11 +4866,11 @@ class ze {
|
|
|
4815
4866
|
*/
|
|
4816
4867
|
constructor(e) {
|
|
4817
4868
|
if (!e.url)
|
|
4818
|
-
throw new
|
|
4869
|
+
throw new $("M2M client requires a URL");
|
|
4819
4870
|
if (!e.clientId)
|
|
4820
|
-
throw new
|
|
4871
|
+
throw new $("M2M client requires a clientId");
|
|
4821
4872
|
if (!e.clientSecret)
|
|
4822
|
-
throw new
|
|
4873
|
+
throw new $("M2M client requires a clientSecret");
|
|
4823
4874
|
const t = e.url.replace(/\/$/, "");
|
|
4824
4875
|
this.config = {
|
|
4825
4876
|
url: t,
|
|
@@ -4828,16 +4879,16 @@ class ze {
|
|
|
4828
4879
|
scopes: e.scopes,
|
|
4829
4880
|
audience: e.audience,
|
|
4830
4881
|
autoRefresh: e.autoRefresh ?? !1,
|
|
4831
|
-
refreshThreshold: e.refreshThreshold ??
|
|
4832
|
-
timeout: e.timeout ??
|
|
4833
|
-
retries: e.retries ??
|
|
4834
|
-
retryDelay: e.retryDelay ??
|
|
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,
|
|
4835
4886
|
retryStrategy: e.retryStrategy,
|
|
4836
4887
|
cache: e.cache,
|
|
4837
4888
|
onTokenRequest: e.onTokenRequest,
|
|
4838
4889
|
onTokenResponse: e.onTokenResponse,
|
|
4839
4890
|
onError: e.onError
|
|
4840
|
-
}, this.cache = e.cache ?? new
|
|
4891
|
+
}, this.cache = e.cache ?? new et(), this.retryStrategy = e.retryStrategy ?? tt, this.tokenEndpoint = `${t}${w.TOKEN_ENDPOINT}`;
|
|
4841
4892
|
}
|
|
4842
4893
|
/**
|
|
4843
4894
|
* Get the cache key for this client
|
|
@@ -4928,7 +4979,7 @@ class ze {
|
|
|
4928
4979
|
const o = await fetch(this.tokenEndpoint, {
|
|
4929
4980
|
method: "POST",
|
|
4930
4981
|
headers: {
|
|
4931
|
-
"Content-Type":
|
|
4982
|
+
"Content-Type": w.CONTENT_TYPE,
|
|
4932
4983
|
Accept: "application/json"
|
|
4933
4984
|
},
|
|
4934
4985
|
body: t.toString(),
|
|
@@ -4957,7 +5008,7 @@ class ze {
|
|
|
4957
5008
|
}
|
|
4958
5009
|
return h;
|
|
4959
5010
|
} catch (o) {
|
|
4960
|
-
throw clearTimeout(s), o instanceof Error && o.name === "AbortError" ? new
|
|
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)));
|
|
4961
5012
|
}
|
|
4962
5013
|
}
|
|
4963
5014
|
/**
|
|
@@ -5052,14 +5103,14 @@ class ze {
|
|
|
5052
5103
|
try {
|
|
5053
5104
|
const t = e.split(".");
|
|
5054
5105
|
if (t.length !== 3)
|
|
5055
|
-
throw new
|
|
5106
|
+
throw new F("Invalid JWT format: expected 3 parts");
|
|
5056
5107
|
const r = t[1];
|
|
5057
5108
|
if (!r)
|
|
5058
|
-
throw new
|
|
5109
|
+
throw new F("Invalid JWT format: missing payload");
|
|
5059
5110
|
const s = atob(r.replace(/-/g, "+").replace(/_/g, "/")), o = JSON.parse(s);
|
|
5060
5111
|
return o.scopes && typeof o.scopes == "string" ? o.scopes = o.scopes.split(" ") : o.scopes || (o.scopes = []), o;
|
|
5061
5112
|
} catch (t) {
|
|
5062
|
-
throw t instanceof
|
|
5113
|
+
throw t instanceof F ? t : new F(`Failed to parse token: ${t instanceof Error ? t.message : "Unknown error"}`);
|
|
5063
5114
|
}
|
|
5064
5115
|
}
|
|
5065
5116
|
/**
|
|
@@ -5100,7 +5151,7 @@ class ze {
|
|
|
5100
5151
|
const s = await fetch(t, {
|
|
5101
5152
|
method: "POST",
|
|
5102
5153
|
headers: {
|
|
5103
|
-
"Content-Type":
|
|
5154
|
+
"Content-Type": w.CONTENT_TYPE
|
|
5104
5155
|
},
|
|
5105
5156
|
body: r.toString()
|
|
5106
5157
|
});
|
|
@@ -5144,69 +5195,211 @@ class ze {
|
|
|
5144
5195
|
return this.config.audience;
|
|
5145
5196
|
}
|
|
5146
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
|
+
}
|
|
5147
5325
|
export {
|
|
5148
|
-
|
|
5326
|
+
A as APP_ID_HEADER_KEY,
|
|
5149
5327
|
I as AUTHORIZATION_HEADER_KEY,
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
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,
|
|
5163
5343
|
p as M2MError,
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5344
|
+
vt as M2MErrorCodes,
|
|
5345
|
+
V as M2MNetworkError,
|
|
5346
|
+
F as M2MTokenParseError,
|
|
5347
|
+
w as M2M_DEFAULTS,
|
|
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,
|
|
5356
|
+
T as PassflowAdminEndpointPaths,
|
|
5177
5357
|
c as PassflowEndpointPaths,
|
|
5178
5358
|
l as PassflowError,
|
|
5179
5359
|
a as PassflowEvent,
|
|
5180
|
-
|
|
5181
|
-
|
|
5360
|
+
W as PopupClosedError,
|
|
5361
|
+
Ce as Providers,
|
|
5182
5362
|
_ as RequestMethod,
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
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,
|
|
5371
|
+
v as TokenDeliveryMode,
|
|
5192
5372
|
k as TokenType,
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
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,
|
|
5388
|
+
y as isTokenExpired,
|
|
5389
|
+
x as isValidEmail,
|
|
5390
|
+
P as isValidJWTFormat,
|
|
5391
|
+
U as isValidPhoneNumber,
|
|
5392
|
+
qe as isValidUsername,
|
|
5393
|
+
be as parseChallengeBody,
|
|
5394
|
+
Ie as parseChallengeHeader,
|
|
5207
5395
|
m as parseToken,
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
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
|
|
5211
5404
|
};
|
|
5212
5405
|
//# sourceMappingURL=index.mjs.map
|