@passflow/core 0.21.1 → 0.22.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/README.md +65 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -4
- package/dist/index.d.ts +104 -4
- package/dist/index.mjs +619 -543
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import e from "axios";
|
|
2
2
|
import { startAuthentication as t, startRegistration as n } from "@simplewebauthn/browser";
|
|
3
3
|
// package.json
|
|
4
|
-
var r = "0.
|
|
4
|
+
var r = "0.22.0", i = "X-Passflow-Clientid", a = "Authorization", o = "X-Passflow-DeviceId", s = "X-Passflow-DeviceType", c = r, l = [
|
|
5
5
|
"id",
|
|
6
6
|
"offline",
|
|
7
7
|
"openid"
|
|
@@ -581,30 +581,30 @@ var j = /* @__PURE__ */ function(e) {
|
|
|
581
581
|
} catch {
|
|
582
582
|
return null;
|
|
583
583
|
}
|
|
584
|
-
}, B = class extends Error {
|
|
584
|
+
}, Ae = (e) => typeof e == "object" && !!e && e.email_verification_required === !0, B = class extends Error {
|
|
585
585
|
constructor(e) {
|
|
586
586
|
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();
|
|
587
587
|
}
|
|
588
|
-
},
|
|
588
|
+
}, je = /* @__PURE__ */ function(e) {
|
|
589
589
|
return e.google = "google", e.facebook = "facebook", e;
|
|
590
|
-
}({}),
|
|
590
|
+
}({}), Me = /* @__PURE__ */ function(e) {
|
|
591
591
|
return e.web = "web", e.ios = "ios", e.android = "android", e;
|
|
592
592
|
}({});
|
|
593
|
-
function
|
|
593
|
+
function Ne(e) {
|
|
594
594
|
return e;
|
|
595
595
|
}
|
|
596
|
-
function
|
|
596
|
+
function Pe(e, t) {
|
|
597
597
|
let n = e;
|
|
598
598
|
return Object.entries(t).forEach(([e, t]) => {
|
|
599
599
|
n = n.replace(`:${e}`, t);
|
|
600
600
|
}), n;
|
|
601
601
|
}
|
|
602
|
-
var
|
|
602
|
+
var Fe = /* @__PURE__ */ function(e) {
|
|
603
603
|
return e.Disabled = "disabled", e.Optional = "optional", e.Required = "required", e;
|
|
604
|
-
}({}),
|
|
604
|
+
}({}), Ie = 3, Le = 1e3, Re = (e) => (t) => {
|
|
605
605
|
let n = e.headers?.[t] ?? e.headers?.[t.toLowerCase()];
|
|
606
606
|
return Array.isArray(n) ? n.join(", ") : n;
|
|
607
|
-
},
|
|
607
|
+
}, ze = (e) => ye(e.status, Re(e), e.data), Be = (e) => ze(e) !== void 0, Ve = (e) => e?.includes(z.refresh) ?? !1, He = (e) => e?.includes("logout") ?? !1, V = class {
|
|
608
608
|
get origin() {
|
|
609
609
|
return this._platform.getCurrentUrl()?.origin ?? "";
|
|
610
610
|
}
|
|
@@ -641,11 +641,11 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
641
641
|
let t = this.storageManager.getCsrfToken();
|
|
642
642
|
return t && (e.headers["X-CSRF-Token"] = t), e;
|
|
643
643
|
}
|
|
644
|
-
if (
|
|
644
|
+
if (Ve(e.url)) return e;
|
|
645
645
|
let t = this.storageManager.getTokens();
|
|
646
646
|
if (!t?.access_token) return e;
|
|
647
647
|
let n = t.access_token;
|
|
648
|
-
if (this.refreshHandler && t.refresh_token && !
|
|
648
|
+
if (this.refreshHandler && t.refresh_token && !He(e.url)) {
|
|
649
649
|
let e = A(t.access_token);
|
|
650
650
|
if (k(e, 30)) {
|
|
651
651
|
let t = !k(e, 0);
|
|
@@ -661,8 +661,8 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
661
661
|
}
|
|
662
662
|
return e.headers[a] = `Bearer ${n}`, e;
|
|
663
663
|
}), this.instance.interceptors.response.use((e) => e, async (e) => {
|
|
664
|
-
if (e.response?.status === 401 && !
|
|
665
|
-
let t =
|
|
664
|
+
if (e.response?.status === 401 && !Ve(e.config?.url) && !this.isUpgradeTransactionError(e) && this.tokenDeliveryManager.setSessionInvalid(), e.response && this.upgradeHandler) {
|
|
665
|
+
let t = ze(e.response);
|
|
666
666
|
if (t) try {
|
|
667
667
|
return await this.upgradeHandler(e, t);
|
|
668
668
|
} catch (t) {
|
|
@@ -673,7 +673,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
673
673
|
});
|
|
674
674
|
}
|
|
675
675
|
isUpgradeTransactionError(e) {
|
|
676
|
-
return we(e.config) || e.response !== void 0 &&
|
|
676
|
+
return we(e.config) || e.response !== void 0 && Be(e.response);
|
|
677
677
|
}
|
|
678
678
|
setUpgradeInterceptor(e) {
|
|
679
679
|
this.upgradeHandler = e;
|
|
@@ -695,7 +695,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
695
695
|
}
|
|
696
696
|
async handleRateLimitError(e) {
|
|
697
697
|
let t = e.config;
|
|
698
|
-
if (!t ||
|
|
698
|
+
if (!t || Ve(t.url)) return Promise.reject(e);
|
|
699
699
|
let n = t.method?.toUpperCase();
|
|
700
700
|
if (![
|
|
701
701
|
"GET",
|
|
@@ -703,8 +703,8 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
703
703
|
"OPTIONS"
|
|
704
704
|
].includes(n || "")) return Promise.reject(e);
|
|
705
705
|
let r = t._retryCount || 0;
|
|
706
|
-
if (r >=
|
|
707
|
-
let i =
|
|
706
|
+
if (r >= Ie) return Promise.reject(e);
|
|
707
|
+
let i = Le * 2 ** r, a = e.response?.headers?.["retry-after"];
|
|
708
708
|
if (a) {
|
|
709
709
|
let e = Number.parseInt(a, 10);
|
|
710
710
|
if (!Number.isNaN(e)) i = e * 1e3;
|
|
@@ -767,7 +767,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
767
767
|
[i]: e
|
|
768
768
|
}, this.instance.defaults.headers.common[i] = e;
|
|
769
769
|
}
|
|
770
|
-
},
|
|
770
|
+
}, Ue = class {
|
|
771
771
|
constructor(e, t, n) {
|
|
772
772
|
this.axiosClient = new V(e, t, n);
|
|
773
773
|
}
|
|
@@ -777,7 +777,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
777
777
|
getAppSettings() {
|
|
778
778
|
return this.axiosClient.get(z.appSettings);
|
|
779
779
|
}
|
|
780
|
-
},
|
|
780
|
+
}, We = { withCredentials: !0 }, Ge = class {
|
|
781
781
|
constructor(e, t, n) {
|
|
782
782
|
this.axiosClient = new V(e, t, n);
|
|
783
783
|
}
|
|
@@ -798,7 +798,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
798
798
|
device: t,
|
|
799
799
|
os: n
|
|
800
800
|
};
|
|
801
|
-
return this.axiosClient.post(z.signin, r,
|
|
801
|
+
return this.axiosClient.post(z.signin, r, We);
|
|
802
802
|
}
|
|
803
803
|
signUp(e) {
|
|
804
804
|
let { create_tenant: t, anonymous: n } = e, r = {
|
|
@@ -806,13 +806,13 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
806
806
|
create_tenant: t ?? !1,
|
|
807
807
|
anonymous: n ?? !1
|
|
808
808
|
};
|
|
809
|
-
return this.axiosClient.post(z.signup, r,
|
|
809
|
+
return this.axiosClient.post(z.signup, r, We);
|
|
810
810
|
}
|
|
811
811
|
pkceExchange(e, t) {
|
|
812
812
|
return this.axiosClient.post(z.pkceExchange, {
|
|
813
813
|
authz_code: e,
|
|
814
814
|
verifier: t
|
|
815
|
-
},
|
|
815
|
+
}, We);
|
|
816
816
|
}
|
|
817
817
|
passwordlessSignIn(e, t, n) {
|
|
818
818
|
let { create_tenant: r } = e, i = {
|
|
@@ -824,7 +824,13 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
824
824
|
return this.axiosClient.post(z.passwordless, i);
|
|
825
825
|
}
|
|
826
826
|
passwordlessSignInComplete(e) {
|
|
827
|
-
return this.axiosClient.post(z.passwordlessComplete, e,
|
|
827
|
+
return this.axiosClient.post(z.passwordlessComplete, e, We);
|
|
828
|
+
}
|
|
829
|
+
validateEmailCode(e) {
|
|
830
|
+
return this.axiosClient.post(z.passkeyValidate, {
|
|
831
|
+
challenge_id: e.challenge_id,
|
|
832
|
+
otp: e.otp
|
|
833
|
+
}, We);
|
|
828
834
|
}
|
|
829
835
|
logOut(e, t, n = !1) {
|
|
830
836
|
let r = n ? void 0 : {
|
|
@@ -865,7 +871,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
865
871
|
device: t,
|
|
866
872
|
passkey_data: e
|
|
867
873
|
}, a = r ? Oe.passkeyRegisterComplete : z.passkeyRegisterComplete;
|
|
868
|
-
return this.axiosClient.post(a, i,
|
|
874
|
+
return this.axiosClient.post(a, i, We);
|
|
869
875
|
}
|
|
870
876
|
passkeyAuthenticateStart(e, t, n, r = !1) {
|
|
871
877
|
let i = {
|
|
@@ -882,7 +888,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
882
888
|
device: t,
|
|
883
889
|
passkey_data: e
|
|
884
890
|
}, a = r ? Oe.passkeyAuthenticateComplete : z.passkeyAuthenticateComplete;
|
|
885
|
-
return this.axiosClient.post(a, i,
|
|
891
|
+
return this.axiosClient.post(a, i, We);
|
|
886
892
|
}
|
|
887
893
|
passkeyValidate(e, t, n, r = !1, a) {
|
|
888
894
|
let o = {
|
|
@@ -894,7 +900,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
894
900
|
let c = a ? { [i]: a } : {};
|
|
895
901
|
return this.axiosClient.post(s, o, { headers: c });
|
|
896
902
|
}
|
|
897
|
-
},
|
|
903
|
+
}, Ke = class {
|
|
898
904
|
constructor(e, t, n) {
|
|
899
905
|
this.axiosClient = new V(e, t, n);
|
|
900
906
|
}
|
|
@@ -902,13 +908,13 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
902
908
|
this.axiosClient.setAppId(e);
|
|
903
909
|
}
|
|
904
910
|
getCLIAuthStatus(e) {
|
|
905
|
-
let t =
|
|
911
|
+
let t = Pe(z.cliAuthStatus, { sessionId: e });
|
|
906
912
|
return this.axiosClient.get(t);
|
|
907
913
|
}
|
|
908
914
|
completeCLIAuth(e) {
|
|
909
915
|
return this.axiosClient.post(z.cliAuthComplete, e);
|
|
910
916
|
}
|
|
911
|
-
},
|
|
917
|
+
}, qe = class {
|
|
912
918
|
constructor(e, t, n) {
|
|
913
919
|
this.axiosClient = new V(e, t, n);
|
|
914
920
|
}
|
|
@@ -921,25 +927,25 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
921
927
|
getInvitations(e) {
|
|
922
928
|
let t = {};
|
|
923
929
|
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());
|
|
924
|
-
let n =
|
|
930
|
+
let n = Pe(z.invitationsPath, { tenantID: e.tenantID });
|
|
925
931
|
return this.axiosClient.get(n, { params: t }).then((e) => ({
|
|
926
932
|
invites: e.invites,
|
|
927
933
|
nextPageSkip: e.next_page_skip
|
|
928
934
|
}));
|
|
929
935
|
}
|
|
930
936
|
deleteInvitation(e) {
|
|
931
|
-
let t =
|
|
937
|
+
let t = Pe(z.invitationDelete, { invitationID: e });
|
|
932
938
|
return this.axiosClient.delete(t);
|
|
933
939
|
}
|
|
934
940
|
resendInvitation(e) {
|
|
935
|
-
let t =
|
|
941
|
+
let t = Pe(z.invitationResend, { invitationID: e });
|
|
936
942
|
return this.axiosClient.post(t, {});
|
|
937
943
|
}
|
|
938
944
|
getInvitationLink(e) {
|
|
939
|
-
let t =
|
|
945
|
+
let t = Pe(z.invitationGetLink, { invitationID: e });
|
|
940
946
|
return this.axiosClient.get(t);
|
|
941
947
|
}
|
|
942
|
-
},
|
|
948
|
+
}, Je = class {
|
|
943
949
|
constructor(e, t, n) {
|
|
944
950
|
this.axiosClient = new V(e, t, n);
|
|
945
951
|
}
|
|
@@ -955,7 +961,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
955
961
|
getPasskeySettings() {
|
|
956
962
|
return this.axiosClient.get(z.settingsPasskey);
|
|
957
963
|
}
|
|
958
|
-
},
|
|
964
|
+
}, Ye = class {
|
|
959
965
|
constructor(e, t, n) {
|
|
960
966
|
this.axiosClient = new V(e, t, n);
|
|
961
967
|
}
|
|
@@ -1071,10 +1077,10 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1071
1077
|
let r = `${z.tenantPath}/${e}/group/${t}/invite/email/${n}`;
|
|
1072
1078
|
return this.axiosClient.delete(r);
|
|
1073
1079
|
}
|
|
1074
|
-
},
|
|
1080
|
+
}, Xe = (e) => e ? { headers: { Authorization: `Bearer ${e}` } } : {}, Ze = (e) => ({
|
|
1075
1081
|
withCredentials: !0,
|
|
1076
|
-
...
|
|
1077
|
-
}),
|
|
1082
|
+
...Xe(e)
|
|
1083
|
+
}), Qe = class {
|
|
1078
1084
|
constructor(e, t, n) {
|
|
1079
1085
|
this.axiosClient = new V(e, t, n);
|
|
1080
1086
|
}
|
|
@@ -1095,14 +1101,14 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1095
1101
|
return this.axiosClient.post(z.twoFactorVerify, {
|
|
1096
1102
|
code: n,
|
|
1097
1103
|
...r ? { trust_device: !0 } : {}
|
|
1098
|
-
},
|
|
1104
|
+
}, Ze(t));
|
|
1099
1105
|
}
|
|
1100
1106
|
useRecoveryCode(e) {
|
|
1101
1107
|
let { tfa_token: t, recovery_code: n, trust_device: r } = e;
|
|
1102
1108
|
return this.axiosClient.post(z.twoFactorRecovery, {
|
|
1103
1109
|
recovery_code: n,
|
|
1104
1110
|
...r ? { trust_device: !0 } : {}
|
|
1105
|
-
},
|
|
1111
|
+
}, Ze(t));
|
|
1106
1112
|
}
|
|
1107
1113
|
disable(e) {
|
|
1108
1114
|
return this.axiosClient.delete(z.twoFactor, { data: e });
|
|
@@ -1179,30 +1185,30 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1179
1185
|
});
|
|
1180
1186
|
}
|
|
1181
1187
|
removeMethod(e) {
|
|
1182
|
-
let t =
|
|
1188
|
+
let t = Pe(z.TwoFactorMethodRemove, { id: e });
|
|
1183
1189
|
return this.axiosClient.delete(t);
|
|
1184
1190
|
}
|
|
1185
1191
|
requestChallenge(e, t) {
|
|
1186
|
-
return this.axiosClient.post(z.TwoFactorChallenge, e,
|
|
1192
|
+
return this.axiosClient.post(z.TwoFactorChallenge, e, Xe(t));
|
|
1187
1193
|
}
|
|
1188
1194
|
verifyV2(e, t) {
|
|
1189
1195
|
let { trust_device: n, ...r } = e;
|
|
1190
1196
|
return this.axiosClient.post(z.TwoFactorVerifyV2, {
|
|
1191
1197
|
...r,
|
|
1192
1198
|
...n ? { trust_device: !0 } : {}
|
|
1193
|
-
},
|
|
1199
|
+
}, Ze(t));
|
|
1194
1200
|
}
|
|
1195
1201
|
switchToAlternative(e, t) {
|
|
1196
|
-
return this.axiosClient.post(z.TwoFactorAlternative, e,
|
|
1202
|
+
return this.axiosClient.post(z.TwoFactorAlternative, e, Xe(t));
|
|
1197
1203
|
}
|
|
1198
1204
|
async getTrustedDevices() {
|
|
1199
1205
|
return (await this.axiosClient.get(z.TwoFactorTrustedDevices, { withCredentials: !0 }))?.devices ?? [];
|
|
1200
1206
|
}
|
|
1201
1207
|
revokeTrustedDevice(e) {
|
|
1202
|
-
let t =
|
|
1208
|
+
let t = Pe(z.TwoFactorTrustedDeviceRevoke, { id: e });
|
|
1203
1209
|
return this.axiosClient.delete(t);
|
|
1204
1210
|
}
|
|
1205
|
-
},
|
|
1211
|
+
}, $e = class {
|
|
1206
1212
|
constructor(e, t, n) {
|
|
1207
1213
|
this.axiosClient = new V(e, t, n);
|
|
1208
1214
|
}
|
|
@@ -1212,7 +1218,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1212
1218
|
startUpgrade(e) {
|
|
1213
1219
|
return this.axiosClient.post(z.upgradeStart, e, Ce({}));
|
|
1214
1220
|
}
|
|
1215
|
-
},
|
|
1221
|
+
}, et = class {
|
|
1216
1222
|
constructor(e, t, n) {
|
|
1217
1223
|
this.axiosClient = new V(e, t, n);
|
|
1218
1224
|
}
|
|
@@ -1245,48 +1251,48 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1245
1251
|
passkey_data: e
|
|
1246
1252
|
});
|
|
1247
1253
|
}
|
|
1248
|
-
},
|
|
1254
|
+
}, tt = 10, nt = 20, rt = class extends Error {
|
|
1249
1255
|
constructor(e) {
|
|
1250
1256
|
super(`Passflow fetch middleware '${e}' resolved without calling next(). Every registered middleware must delegate exactly once; swallowing a request would drop a caller's fetch inside the Passflow wrapper.`), this.name = "FetchMiddlewareContractError", this.middlewareName = e;
|
|
1251
1257
|
}
|
|
1252
|
-
},
|
|
1258
|
+
}, it = [], at = 0, ot = !1, st, ct, lt = (e, t) => e.priority - t.priority || e.seq - t.seq, ut = () => typeof globalThis > "u" ? void 0 : globalThis, dt = async (e, t, n, r) => {
|
|
1253
1259
|
if (t >= e.length) {
|
|
1254
|
-
let e =
|
|
1260
|
+
let e = st;
|
|
1255
1261
|
if (!e) throw Error("Passflow fetch registry: no captured fetch to delegate to.");
|
|
1256
1262
|
return e(n, r);
|
|
1257
1263
|
}
|
|
1258
1264
|
let i = e[t];
|
|
1259
|
-
if (!i) return
|
|
1260
|
-
let a = !1, o = await i.middleware((n, r) => (a = !0,
|
|
1261
|
-
if (!a) throw new
|
|
1265
|
+
if (!i) return dt(e, e.length, n, r);
|
|
1266
|
+
let a = !1, o = await i.middleware((n, r) => (a = !0, dt(e, t + 1, n, r)), n, r);
|
|
1267
|
+
if (!a) throw new rt(i.name);
|
|
1262
1268
|
return o;
|
|
1263
|
-
}, dt = () => {
|
|
1264
|
-
let e = lt();
|
|
1265
|
-
if (!e || typeof e.fetch != "function") return !1;
|
|
1266
|
-
let t = e.fetch.bind(e), n = (e, t) => ut([...rt].sort(ct), 0, e, t);
|
|
1267
|
-
return ot = t, st = n, e.fetch = n, at = !0, !0;
|
|
1268
1269
|
}, ft = () => {
|
|
1269
|
-
let e =
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1270
|
+
let e = ut();
|
|
1271
|
+
if (!e || typeof e.fetch != "function") return !1;
|
|
1272
|
+
let t = e.fetch.bind(e), n = (e, t) => dt([...it].sort(lt), 0, e, t);
|
|
1273
|
+
return st = t, ct = n, e.fetch = n, ot = !0, !0;
|
|
1274
|
+
}, pt = () => {
|
|
1275
|
+
let e = ut();
|
|
1276
|
+
e && ct && e.fetch === ct && (st && (e.fetch = st), ot = !1, ct = void 0, st = void 0);
|
|
1277
|
+
}, mt = (e, t) => {
|
|
1278
|
+
if (!ot && !ft()) return () => {};
|
|
1273
1279
|
let n = {
|
|
1274
1280
|
middleware: e,
|
|
1275
1281
|
name: t.name,
|
|
1276
1282
|
priority: t.priority,
|
|
1277
|
-
seq:
|
|
1283
|
+
seq: at++
|
|
1278
1284
|
};
|
|
1279
|
-
|
|
1285
|
+
it.push(n);
|
|
1280
1286
|
let r = !1;
|
|
1281
1287
|
return () => {
|
|
1282
|
-
r || (r = !0,
|
|
1288
|
+
r || (r = !0, it = it.filter((e) => e !== n), it.length === 0 && pt());
|
|
1283
1289
|
};
|
|
1284
|
-
},
|
|
1285
|
-
let e =
|
|
1290
|
+
}, ht = () => {
|
|
1291
|
+
let e = ut();
|
|
1286
1292
|
return {
|
|
1287
|
-
installed:
|
|
1288
|
-
names: [...
|
|
1289
|
-
foreignPatch:
|
|
1293
|
+
installed: ot,
|
|
1294
|
+
names: [...it].sort(lt).map((e) => e.name),
|
|
1295
|
+
foreignPatch: ot && !!e && !!ct && e.fetch !== ct
|
|
1290
1296
|
};
|
|
1291
1297
|
}, H = class e extends Error {
|
|
1292
1298
|
constructor(t) {
|
|
@@ -1357,7 +1363,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1357
1363
|
let e = `M2MError [${this.code}]: ${this.message}`;
|
|
1358
1364
|
return this.status && (e += ` (HTTP ${this.status})`), e;
|
|
1359
1365
|
}
|
|
1360
|
-
},
|
|
1366
|
+
}, gt = class extends H {
|
|
1361
1367
|
constructor(e, t) {
|
|
1362
1368
|
super({
|
|
1363
1369
|
code: "temporarily_unavailable",
|
|
@@ -1366,7 +1372,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1366
1372
|
cause: t
|
|
1367
1373
|
}), this.name = "M2MNetworkError";
|
|
1368
1374
|
}
|
|
1369
|
-
},
|
|
1375
|
+
}, _t = class extends H {
|
|
1370
1376
|
constructor(e, t) {
|
|
1371
1377
|
super({
|
|
1372
1378
|
code: "invalid_request",
|
|
@@ -1375,7 +1381,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1375
1381
|
cause: t
|
|
1376
1382
|
}), this.name = "M2MTokenParseError";
|
|
1377
1383
|
}
|
|
1378
|
-
},
|
|
1384
|
+
}, vt = class extends H {
|
|
1379
1385
|
constructor(e) {
|
|
1380
1386
|
super({
|
|
1381
1387
|
code: "invalid_request",
|
|
@@ -1383,7 +1389,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1383
1389
|
status: 400
|
|
1384
1390
|
}), this.name = "M2MConfigError";
|
|
1385
1391
|
}
|
|
1386
|
-
},
|
|
1392
|
+
}, yt = {
|
|
1387
1393
|
InvalidRequest: "invalid_request",
|
|
1388
1394
|
InvalidClient: "invalid_client",
|
|
1389
1395
|
InvalidGrant: "invalid_grant",
|
|
@@ -1393,14 +1399,14 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1393
1399
|
RateLimitExceeded: "rate_limit_exceeded",
|
|
1394
1400
|
ServerError: "server_error",
|
|
1395
1401
|
TemporarilyUnavailable: "temporarily_unavailable"
|
|
1396
|
-
},
|
|
1402
|
+
}, bt = {
|
|
1397
1403
|
TOKEN_ENDPOINT: "/oauth2/token",
|
|
1398
1404
|
TIMEOUT: 1e4,
|
|
1399
1405
|
RETRIES: 3,
|
|
1400
1406
|
RETRY_DELAY: 1e3,
|
|
1401
1407
|
REFRESH_THRESHOLD: 30,
|
|
1402
1408
|
CONTENT_TYPE: "application/x-www-form-urlencoded"
|
|
1403
|
-
},
|
|
1409
|
+
}, xt = class {
|
|
1404
1410
|
constructor() {
|
|
1405
1411
|
this.cache = /* @__PURE__ */ new Map();
|
|
1406
1412
|
}
|
|
@@ -1417,18 +1423,18 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1417
1423
|
delete(e) {
|
|
1418
1424
|
return this.cache.delete(e), Promise.resolve();
|
|
1419
1425
|
}
|
|
1420
|
-
},
|
|
1426
|
+
}, St = {
|
|
1421
1427
|
shouldRetry(e, t) {
|
|
1422
1428
|
return t >= 3 ? !1 : e.code === "server_error" || e.code === "temporarily_unavailable" || e.code === "rate_limit_exceeded" || e.status !== void 0 && e.status >= 500;
|
|
1423
1429
|
},
|
|
1424
1430
|
getDelay(e) {
|
|
1425
1431
|
return 2 ** (e - 1) * 1e3;
|
|
1426
1432
|
}
|
|
1427
|
-
},
|
|
1433
|
+
}, Ct = class {
|
|
1428
1434
|
constructor(e) {
|
|
1429
|
-
if (!e.url) throw new
|
|
1430
|
-
if (!e.clientId) throw new
|
|
1431
|
-
if (!e.clientSecret) throw new
|
|
1435
|
+
if (!e.url) throw new vt("M2M client requires a URL");
|
|
1436
|
+
if (!e.clientId) throw new vt("M2M client requires a clientId");
|
|
1437
|
+
if (!e.clientSecret) throw new vt("M2M client requires a clientSecret");
|
|
1432
1438
|
let t = e.url.replace(/\/$/, "");
|
|
1433
1439
|
this.config = {
|
|
1434
1440
|
url: t,
|
|
@@ -1437,16 +1443,16 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1437
1443
|
scopes: e.scopes,
|
|
1438
1444
|
audience: e.audience,
|
|
1439
1445
|
autoRefresh: e.autoRefresh ?? !1,
|
|
1440
|
-
refreshThreshold: e.refreshThreshold ??
|
|
1441
|
-
timeout: e.timeout ??
|
|
1442
|
-
retries: e.retries ??
|
|
1443
|
-
retryDelay: e.retryDelay ??
|
|
1446
|
+
refreshThreshold: e.refreshThreshold ?? bt.REFRESH_THRESHOLD,
|
|
1447
|
+
timeout: e.timeout ?? bt.TIMEOUT,
|
|
1448
|
+
retries: e.retries ?? bt.RETRIES,
|
|
1449
|
+
retryDelay: e.retryDelay ?? bt.RETRY_DELAY,
|
|
1444
1450
|
retryStrategy: e.retryStrategy,
|
|
1445
1451
|
cache: e.cache,
|
|
1446
1452
|
onTokenRequest: e.onTokenRequest,
|
|
1447
1453
|
onTokenResponse: e.onTokenResponse,
|
|
1448
1454
|
onError: e.onError
|
|
1449
|
-
}, this.cache = e.cache ?? new
|
|
1455
|
+
}, this.cache = e.cache ?? new xt(), this.retryStrategy = e.retryStrategy ?? St, this.tokenEndpoint = `${t}${bt.TOKEN_ENDPOINT}`;
|
|
1450
1456
|
}
|
|
1451
1457
|
getCacheKey(e, t) {
|
|
1452
1458
|
let n = e?.sort().join(",") || "", r = t?.sort().join(",") || "";
|
|
@@ -1491,7 +1497,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1491
1497
|
let e = await fetch(this.tokenEndpoint, {
|
|
1492
1498
|
method: "POST",
|
|
1493
1499
|
headers: {
|
|
1494
|
-
"Content-Type":
|
|
1500
|
+
"Content-Type": bt.CONTENT_TYPE,
|
|
1495
1501
|
Accept: "application/json"
|
|
1496
1502
|
},
|
|
1497
1503
|
body: t.toString(),
|
|
@@ -1516,7 +1522,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1516
1522
|
}
|
|
1517
1523
|
return a;
|
|
1518
1524
|
} catch (e) {
|
|
1519
|
-
throw clearTimeout(r), e instanceof Error && e.name === "AbortError" ? new
|
|
1525
|
+
throw clearTimeout(r), e instanceof Error && e.name === "AbortError" ? new gt(`Request timed out after ${this.config.timeout}ms`) : e instanceof TypeError && e.message.includes("fetch") ? new gt(`Network error: ${e.message}`, e) : e instanceof H ? e : H.fromError(e instanceof Error ? e : Error(String(e)));
|
|
1520
1526
|
}
|
|
1521
1527
|
}
|
|
1522
1528
|
async executeWithRetry(e) {
|
|
@@ -1559,13 +1565,13 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1559
1565
|
parseToken(e) {
|
|
1560
1566
|
try {
|
|
1561
1567
|
let t = e.split(".");
|
|
1562
|
-
if (t.length !== 3) throw new
|
|
1568
|
+
if (t.length !== 3) throw new _t("Invalid JWT format: expected 3 parts");
|
|
1563
1569
|
let n = t[1];
|
|
1564
|
-
if (!n) throw new
|
|
1570
|
+
if (!n) throw new _t("Invalid JWT format: missing payload");
|
|
1565
1571
|
let r = atob(n.replace(/-/g, "+").replace(/_/g, "/")), i = JSON.parse(r);
|
|
1566
1572
|
return i.scopes && typeof i.scopes == "string" ? i.scopes = i.scopes.split(" ") : i.scopes || (i.scopes = []), i;
|
|
1567
1573
|
} catch (e) {
|
|
1568
|
-
throw e instanceof
|
|
1574
|
+
throw e instanceof _t ? e : new _t(`Failed to parse token: ${e instanceof Error ? e.message : "Unknown error"}`);
|
|
1569
1575
|
}
|
|
1570
1576
|
}
|
|
1571
1577
|
clearCache() {
|
|
@@ -1580,7 +1586,7 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1580
1586
|
try {
|
|
1581
1587
|
let e = await fetch(t, {
|
|
1582
1588
|
method: "POST",
|
|
1583
|
-
headers: { "Content-Type":
|
|
1589
|
+
headers: { "Content-Type": bt.CONTENT_TYPE },
|
|
1584
1590
|
body: n.toString()
|
|
1585
1591
|
});
|
|
1586
1592
|
if (!e.ok && e.status !== 200) {
|
|
@@ -1607,101 +1613,101 @@ var Pe = /* @__PURE__ */ function(e) {
|
|
|
1607
1613
|
get audience() {
|
|
1608
1614
|
return this.config.audience;
|
|
1609
1615
|
}
|
|
1610
|
-
},
|
|
1616
|
+
}, wt = "error", Tt = /* @__PURE__ */ new WeakMap(), Et = (e, t) => {
|
|
1611
1617
|
if (typeof t != "object" && typeof t != "function" || t === null) return !0;
|
|
1612
|
-
let n =
|
|
1613
|
-
return n || (n = /* @__PURE__ */ new WeakSet(),
|
|
1614
|
-
}, U = (e, t) =>
|
|
1618
|
+
let n = Tt.get(e);
|
|
1619
|
+
return n || (n = /* @__PURE__ */ new WeakSet(), Tt.set(e, n)), !n.has(t) && (n.add(t), !0);
|
|
1620
|
+
}, U = (e, t) => Et(e, t.originalError) ? (e.notify(wt, t), !0) : !1, Dt = "passflow-refresh", Ot = "passflow-refresh-takeover", kt = "passflow-auth", At = Object.freeze([
|
|
1615
1621
|
1e3,
|
|
1616
1622
|
3e3,
|
|
1617
1623
|
1e4,
|
|
1618
1624
|
3e4,
|
|
1619
1625
|
6e4
|
|
1620
|
-
]),
|
|
1626
|
+
]), jt = .2, Mt = 6e5, Nt = 5e3, W = 2e4, Pt = 2e4, Ft = 1e3, It = 2e3, Lt = 1e3, Rt = 1e4, zt = 5e3;
|
|
1621
1627
|
// lib/refresh/protocol.ts
|
|
1622
|
-
function
|
|
1628
|
+
function Bt(e) {
|
|
1623
1629
|
let t = e ? `:${e}` : "";
|
|
1624
1630
|
return {
|
|
1625
|
-
lock: `${
|
|
1626
|
-
takeoverLock: `${
|
|
1627
|
-
channel: `${
|
|
1631
|
+
lock: `${Dt}${t}`,
|
|
1632
|
+
takeoverLock: `${Ot}${t}`,
|
|
1633
|
+
channel: `${kt}${t}`
|
|
1628
1634
|
};
|
|
1629
1635
|
}
|
|
1630
1636
|
function G(e) {
|
|
1631
1637
|
return typeof e == "string" && e !== "" ? e : void 0;
|
|
1632
1638
|
}
|
|
1633
|
-
function
|
|
1639
|
+
function Vt(e) {
|
|
1634
1640
|
return typeof e == "number" && Number.isFinite(e) ? e : void 0;
|
|
1635
1641
|
}
|
|
1636
|
-
function
|
|
1642
|
+
function Ht(e) {
|
|
1637
1643
|
return typeof e == "object" && !!e;
|
|
1638
1644
|
}
|
|
1639
|
-
function
|
|
1645
|
+
function Ut(e, t) {
|
|
1640
1646
|
for (let [n, r] of Object.entries(t)) r !== void 0 && (e[n] = r);
|
|
1641
1647
|
return e;
|
|
1642
1648
|
}
|
|
1643
|
-
function
|
|
1644
|
-
if (!
|
|
1649
|
+
function Wt(e) {
|
|
1650
|
+
if (!Ht(e)) return null;
|
|
1645
1651
|
let t = Array.isArray(e.scopes) ? e.scopes.filter((e) => typeof e == "string") : void 0;
|
|
1646
|
-
return
|
|
1652
|
+
return Ut({}, {
|
|
1647
1653
|
access_token: G(e.access_token),
|
|
1648
1654
|
refresh_token: G(e.refresh_token),
|
|
1649
1655
|
id_token: G(e.id_token),
|
|
1650
1656
|
scopes: Array.isArray(e.scopes) && t?.length === e.scopes.length ? t : void 0
|
|
1651
1657
|
});
|
|
1652
1658
|
}
|
|
1653
|
-
function
|
|
1654
|
-
if (!
|
|
1659
|
+
function Gt(e) {
|
|
1660
|
+
if (!Ht(e)) return null;
|
|
1655
1661
|
let { kind: t, attempt: n, nextAt: r, strikes: i } = e;
|
|
1656
|
-
return t !== "transient" && t !== "auth" || typeof n != "number" || !Number.isInteger(n) || n < 1 ||
|
|
1662
|
+
return t !== "transient" && t !== "auth" || typeof n != "number" || !Number.isInteger(n) || n < 1 || Vt(r) === void 0 || typeof i != "number" || !Number.isFinite(i) || i < 0 ? null : Ut({
|
|
1657
1663
|
kind: t,
|
|
1658
1664
|
attempt: n,
|
|
1659
1665
|
nextAt: r,
|
|
1660
1666
|
strikes: i
|
|
1661
1667
|
}, {
|
|
1662
1668
|
from: G(e.from),
|
|
1663
|
-
failingSince:
|
|
1669
|
+
failingSince: Vt(e.failingSince)
|
|
1664
1670
|
});
|
|
1665
1671
|
}
|
|
1666
|
-
function
|
|
1667
|
-
return
|
|
1672
|
+
function Kt(e) {
|
|
1673
|
+
return Ut({}, {
|
|
1668
1674
|
fp: G(e.fp),
|
|
1669
1675
|
sub: G(e.sub),
|
|
1670
1676
|
sid: G(e.sid),
|
|
1671
|
-
iat:
|
|
1677
|
+
iat: Vt(e.iat)
|
|
1672
1678
|
});
|
|
1673
1679
|
}
|
|
1674
|
-
function
|
|
1675
|
-
if (!
|
|
1680
|
+
function qt(e) {
|
|
1681
|
+
if (!Ht(e)) return null;
|
|
1676
1682
|
let t = e;
|
|
1677
1683
|
if (t.v !== void 0 && t.v !== 1) return null;
|
|
1678
1684
|
let n = G(t.tabId);
|
|
1679
1685
|
if (!n) return null;
|
|
1680
1686
|
switch (t.type) {
|
|
1681
1687
|
case "tokens-refreshed": {
|
|
1682
|
-
let e =
|
|
1683
|
-
return !e || !r || !i ? null :
|
|
1688
|
+
let e = Wt(t.tokens), r = G(t.from), i = G(t.to);
|
|
1689
|
+
return !e || !r || !i ? null : Ut({
|
|
1684
1690
|
type: t.type,
|
|
1685
1691
|
tabId: n,
|
|
1686
1692
|
tokens: e,
|
|
1687
1693
|
from: r,
|
|
1688
1694
|
to: i
|
|
1689
1695
|
}, {
|
|
1690
|
-
fromIat:
|
|
1696
|
+
fromIat: Vt(t.fromIat),
|
|
1691
1697
|
fromSid: typeof t.fromSid == "string" ? t.fromSid : void 0,
|
|
1692
|
-
sentAt:
|
|
1698
|
+
sentAt: Vt(t.sentAt)
|
|
1693
1699
|
});
|
|
1694
1700
|
}
|
|
1695
1701
|
case "session-refreshed": {
|
|
1696
|
-
let e =
|
|
1697
|
-
return e === void 0 ? null :
|
|
1702
|
+
let e = Vt(t.at);
|
|
1703
|
+
return e === void 0 ? null : Ut({
|
|
1698
1704
|
type: t.type,
|
|
1699
1705
|
tabId: n,
|
|
1700
1706
|
at: e
|
|
1701
1707
|
}, { sub: G(t.sub) });
|
|
1702
1708
|
}
|
|
1703
1709
|
case "still-refreshing": {
|
|
1704
|
-
let e = t.retry === void 0 ? null :
|
|
1710
|
+
let e = t.retry === void 0 ? null : Gt(t.retry);
|
|
1705
1711
|
return e ? {
|
|
1706
1712
|
type: t.type,
|
|
1707
1713
|
tabId: n,
|
|
@@ -1712,7 +1718,7 @@ function Kt(e) {
|
|
|
1712
1718
|
};
|
|
1713
1719
|
}
|
|
1714
1720
|
case "retry-scheduled": {
|
|
1715
|
-
let e =
|
|
1721
|
+
let e = Gt(t);
|
|
1716
1722
|
return e ? {
|
|
1717
1723
|
type: t.type,
|
|
1718
1724
|
tabId: n,
|
|
@@ -1733,10 +1739,10 @@ function Kt(e) {
|
|
|
1733
1739
|
case "signed-out": return {
|
|
1734
1740
|
type: t.type,
|
|
1735
1741
|
tabId: n,
|
|
1736
|
-
...
|
|
1742
|
+
...Kt(t)
|
|
1737
1743
|
};
|
|
1738
1744
|
case "rate-limited": {
|
|
1739
|
-
let e =
|
|
1745
|
+
let e = Vt(t.until);
|
|
1740
1746
|
return e === void 0 ? null : {
|
|
1741
1747
|
type: t.type,
|
|
1742
1748
|
tabId: n,
|
|
@@ -1755,22 +1761,22 @@ function Kt(e) {
|
|
|
1755
1761
|
default: return null;
|
|
1756
1762
|
}
|
|
1757
1763
|
}
|
|
1758
|
-
function
|
|
1764
|
+
function Jt(e, t) {
|
|
1759
1765
|
let n = {
|
|
1760
1766
|
v: 1,
|
|
1761
1767
|
tabId: e
|
|
1762
1768
|
};
|
|
1763
1769
|
if (t.type === "retry-scheduled") {
|
|
1764
1770
|
let { retry: e, ...r } = t;
|
|
1765
|
-
return
|
|
1771
|
+
return Ut(n, {
|
|
1766
1772
|
...r,
|
|
1767
1773
|
...e
|
|
1768
1774
|
});
|
|
1769
1775
|
}
|
|
1770
|
-
return
|
|
1776
|
+
return Ut(n, { ...t });
|
|
1771
1777
|
}
|
|
1772
1778
|
// lib/refresh/resolve.ts
|
|
1773
|
-
var
|
|
1779
|
+
var Yt = "[passflow] navigator.locks or BroadcastChannel is unavailable (they need a secure context); each tab refreshes on its own, with the save checks only", Xt = {
|
|
1774
1780
|
now: () => Date.now(),
|
|
1775
1781
|
random: () => Math.random(),
|
|
1776
1782
|
setTimeout: (e, t) => {
|
|
@@ -1778,28 +1784,28 @@ var Jt = "[passflow] navigator.locks or BroadcastChannel is unavailable (they ne
|
|
|
1778
1784
|
return n.unref?.(), () => clearTimeout(n);
|
|
1779
1785
|
}
|
|
1780
1786
|
};
|
|
1781
|
-
function
|
|
1787
|
+
function Zt() {
|
|
1782
1788
|
let e = globalThis.crypto;
|
|
1783
1789
|
return typeof e?.randomUUID == "function" ? e.randomUUID() : `tab-${Math.random().toString(36).slice(2)}-${Date.now()}`;
|
|
1784
1790
|
}
|
|
1785
|
-
function
|
|
1791
|
+
function Qt(e) {
|
|
1786
1792
|
return e ? {
|
|
1787
1793
|
now: () => e.now(),
|
|
1788
1794
|
setTimeout: (t, n) => e.setTimeout(t, n),
|
|
1789
|
-
random: e.random ? () => e.random?.() ?? Math.random() :
|
|
1790
|
-
} :
|
|
1795
|
+
random: e.random ? () => e.random?.() ?? Math.random() : Xt.random
|
|
1796
|
+
} : Xt;
|
|
1791
1797
|
}
|
|
1792
|
-
function
|
|
1798
|
+
function $t(e) {
|
|
1793
1799
|
return typeof window < "u" && typeof document < "u" && e.getDeviceType() === "web";
|
|
1794
1800
|
}
|
|
1795
|
-
function
|
|
1801
|
+
function en(e) {
|
|
1796
1802
|
try {
|
|
1797
1803
|
return e.storageSharedAcrossTabs === !0;
|
|
1798
1804
|
} catch {
|
|
1799
1805
|
return !1;
|
|
1800
1806
|
}
|
|
1801
1807
|
}
|
|
1802
|
-
function
|
|
1808
|
+
function tn() {
|
|
1803
1809
|
try {
|
|
1804
1810
|
let e = globalThis.navigator?.locks;
|
|
1805
1811
|
return e && typeof e.request == "function" ? e : void 0;
|
|
@@ -1807,7 +1813,7 @@ function en() {
|
|
|
1807
1813
|
return;
|
|
1808
1814
|
}
|
|
1809
1815
|
}
|
|
1810
|
-
function
|
|
1816
|
+
function nn(e) {
|
|
1811
1817
|
return (t) => {
|
|
1812
1818
|
let n = (n) => {
|
|
1813
1819
|
let r = n.key;
|
|
@@ -1816,20 +1822,20 @@ function tn(e) {
|
|
|
1816
1822
|
return window.addEventListener("storage", n), () => window.removeEventListener("storage", n);
|
|
1817
1823
|
};
|
|
1818
1824
|
}
|
|
1819
|
-
function
|
|
1825
|
+
function rn(e) {
|
|
1820
1826
|
return {
|
|
1821
1827
|
transports: null,
|
|
1822
|
-
names:
|
|
1823
|
-
clock:
|
|
1828
|
+
names: Bt(e),
|
|
1829
|
+
clock: Xt,
|
|
1824
1830
|
warnOnFirstCycle: !1
|
|
1825
1831
|
};
|
|
1826
1832
|
}
|
|
1827
|
-
function
|
|
1828
|
-
let i =
|
|
1833
|
+
function an(e, t, n, r) {
|
|
1834
|
+
let i = Bt(n), a = $t(t), o = a ? nn(r.tokenKeys) : void 0, s = (e) => {
|
|
1829
1835
|
let t = {
|
|
1830
1836
|
transports: null,
|
|
1831
1837
|
names: i,
|
|
1832
|
-
clock:
|
|
1838
|
+
clock: Xt,
|
|
1833
1839
|
warnOnFirstCycle: e
|
|
1834
1840
|
};
|
|
1835
1841
|
return o && (t.onStorageChange = o), t;
|
|
@@ -1839,16 +1845,16 @@ function rn(e, t, n, r) {
|
|
|
1839
1845
|
transports: {
|
|
1840
1846
|
locks: e.locks,
|
|
1841
1847
|
channel: e.channel,
|
|
1842
|
-
tabId: e.tabId ??
|
|
1848
|
+
tabId: e.tabId ?? Zt()
|
|
1843
1849
|
},
|
|
1844
1850
|
names: i,
|
|
1845
|
-
clock:
|
|
1851
|
+
clock: Qt(e.clock),
|
|
1846
1852
|
warnOnFirstCycle: !1
|
|
1847
1853
|
};
|
|
1848
1854
|
return e.onStorageChange && (t.onStorageChange = e.onStorageChange), t;
|
|
1849
1855
|
}
|
|
1850
|
-
if (e === "none" || !a ||
|
|
1851
|
-
let c =
|
|
1856
|
+
if (e === "none" || !a || !en(t)) return s(!1);
|
|
1857
|
+
let c = tn();
|
|
1852
1858
|
if (!c || typeof BroadcastChannel != "function") return s(!0);
|
|
1853
1859
|
let l;
|
|
1854
1860
|
try {
|
|
@@ -1860,36 +1866,36 @@ function rn(e, t, n, r) {
|
|
|
1860
1866
|
transports: {
|
|
1861
1867
|
locks: c,
|
|
1862
1868
|
channel: l,
|
|
1863
|
-
tabId:
|
|
1869
|
+
tabId: Zt()
|
|
1864
1870
|
},
|
|
1865
1871
|
names: i,
|
|
1866
|
-
clock:
|
|
1872
|
+
clock: Xt,
|
|
1867
1873
|
warnOnFirstCycle: !1
|
|
1868
1874
|
};
|
|
1869
1875
|
return o && (u.onStorageChange = o), u;
|
|
1870
1876
|
}
|
|
1871
1877
|
// lib/pkce.ts
|
|
1872
|
-
var
|
|
1878
|
+
var on = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", sn = 32, cn = (e) => {
|
|
1873
1879
|
let t = "";
|
|
1874
1880
|
for (let n = 0; n < e.length; n += 3) {
|
|
1875
1881
|
let r = e[n], i = e[n + 1], a = e[n + 2];
|
|
1876
|
-
t +=
|
|
1882
|
+
t += on.charAt(r >> 2), t += on.charAt((r & 3) << 4 | (i ?? 0) >> 4), i !== void 0 && (t += on.charAt((i & 15) << 2 | (a ?? 0) >> 6)), a !== void 0 && (t += on.charAt(a & 63));
|
|
1877
1883
|
}
|
|
1878
1884
|
return t;
|
|
1879
|
-
},
|
|
1885
|
+
}, ln = () => {
|
|
1880
1886
|
let e = globalThis.crypto;
|
|
1881
1887
|
if (!e?.subtle) throw Error("PKCE needs the Web Crypto API, which is available only in a secure context (https or localhost)");
|
|
1882
1888
|
return e;
|
|
1883
|
-
},
|
|
1884
|
-
let t = await
|
|
1885
|
-
return
|
|
1886
|
-
},
|
|
1887
|
-
let e =
|
|
1889
|
+
}, un = async (e) => {
|
|
1890
|
+
let t = await ln().subtle.digest("SHA-256", new TextEncoder().encode(e));
|
|
1891
|
+
return cn(new Uint8Array(t));
|
|
1892
|
+
}, dn = async () => {
|
|
1893
|
+
let e = cn(ln().getRandomValues(new Uint8Array(sn)));
|
|
1888
1894
|
return {
|
|
1889
1895
|
verifier: e,
|
|
1890
|
-
challenge: await
|
|
1896
|
+
challenge: await un(e)
|
|
1891
1897
|
};
|
|
1892
|
-
},
|
|
1898
|
+
}, fn = class {
|
|
1893
1899
|
error(e, ...t) {
|
|
1894
1900
|
console.error(e, ...t);
|
|
1895
1901
|
}
|
|
@@ -1903,10 +1909,10 @@ var an = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", on
|
|
|
1903
1909
|
console.debug(e, ...t);
|
|
1904
1910
|
}
|
|
1905
1911
|
};
|
|
1906
|
-
function
|
|
1907
|
-
return new
|
|
1912
|
+
function pn() {
|
|
1913
|
+
return new fn();
|
|
1908
1914
|
}
|
|
1909
|
-
var
|
|
1915
|
+
var mn = Object.freeze([
|
|
1910
1916
|
"error.token.invalid.error",
|
|
1911
1917
|
"error.api.token.parse.error",
|
|
1912
1918
|
"error.api.user.blocked",
|
|
@@ -1914,25 +1920,25 @@ var pn = Object.freeze([
|
|
|
1914
1920
|
"error.validation.token.invalid.subject",
|
|
1915
1921
|
"error.not.found"
|
|
1916
1922
|
]);
|
|
1917
|
-
function
|
|
1923
|
+
function hn(e) {
|
|
1918
1924
|
if (typeof e != "object" || !e) return;
|
|
1919
1925
|
let t = e;
|
|
1920
1926
|
return typeof t.get == "function" ? t.get("retry-after") : t["retry-after"] ?? t["Retry-After"];
|
|
1921
1927
|
}
|
|
1922
|
-
function
|
|
1923
|
-
if (typeof e == "number") return !Number.isFinite(e) || e < 0 ? void 0 : Math.min(
|
|
1928
|
+
function gn(e, t) {
|
|
1929
|
+
if (typeof e == "number") return !Number.isFinite(e) || e < 0 ? void 0 : Math.min(Mt, Math.floor(e) * 1e3);
|
|
1924
1930
|
if (typeof e != "string") return;
|
|
1925
1931
|
let n = e.trim();
|
|
1926
1932
|
if (n === "") return;
|
|
1927
|
-
if (/^\d+$/.test(n)) return Math.min(
|
|
1933
|
+
if (/^\d+$/.test(n)) return Math.min(Mt, Number.parseInt(n, 10) * 1e3);
|
|
1928
1934
|
if (!/[a-z]/i.test(n)) return;
|
|
1929
1935
|
let r = Date.parse(n);
|
|
1930
|
-
if (!Number.isNaN(r)) return Math.min(
|
|
1936
|
+
if (!Number.isNaN(r)) return Math.min(Mt, Math.max(0, r - t));
|
|
1931
1937
|
}
|
|
1932
|
-
function
|
|
1938
|
+
function _n(e) {
|
|
1933
1939
|
return typeof e == "number" && Number.isInteger(e) && e >= 100 && e <= 599 ? e : void 0;
|
|
1934
1940
|
}
|
|
1935
|
-
function
|
|
1941
|
+
function vn(e) {
|
|
1936
1942
|
if (typeof e.id == "string" && e.id !== "") return e.id;
|
|
1937
1943
|
let t = e.response?.data;
|
|
1938
1944
|
if (typeof t != "object" || !t) return;
|
|
@@ -1941,14 +1947,14 @@ function _n(e) {
|
|
|
1941
1947
|
let r = n.id;
|
|
1942
1948
|
return typeof r == "string" && r !== "" ? r : void 0;
|
|
1943
1949
|
}
|
|
1944
|
-
function
|
|
1950
|
+
function yn(e, t = Date.now()) {
|
|
1945
1951
|
if (typeof e != "object" || !e) return { kind: "transient" };
|
|
1946
|
-
let n = e, r =
|
|
1952
|
+
let n = e, r = vn(n), i = _n(n.response?.status) ?? _n(n.status), a = {};
|
|
1947
1953
|
if (i !== void 0 && (a.status = i), r !== void 0 && (a.id = r), r === "error.token.blocked") return {
|
|
1948
1954
|
kind: "blocked",
|
|
1949
1955
|
...a
|
|
1950
1956
|
};
|
|
1951
|
-
if (r !== void 0 &&
|
|
1957
|
+
if (r !== void 0 && mn.includes(r) || i !== void 0 && i >= 400 && i <= 499 && i !== 429) return {
|
|
1952
1958
|
kind: "auth",
|
|
1953
1959
|
...a
|
|
1954
1960
|
};
|
|
@@ -1956,7 +1962,7 @@ function vn(e, t = Date.now()) {
|
|
|
1956
1962
|
kind: "transient",
|
|
1957
1963
|
...a
|
|
1958
1964
|
};
|
|
1959
|
-
let o =
|
|
1965
|
+
let o = gn(n.retryAfter ?? hn(n.response?.headers), t);
|
|
1960
1966
|
return o === void 0 ? {
|
|
1961
1967
|
kind: "transient",
|
|
1962
1968
|
...a
|
|
@@ -1966,19 +1972,19 @@ function vn(e, t = Date.now()) {
|
|
|
1966
1972
|
retryAfterMs: o
|
|
1967
1973
|
};
|
|
1968
1974
|
}
|
|
1969
|
-
function
|
|
1970
|
-
let r =
|
|
1971
|
-
return Math.max(o, n !== void 0 && Number.isFinite(n) ? Math.min(Math.max(n, 0),
|
|
1975
|
+
function bn(e, t, n) {
|
|
1976
|
+
let r = At.length, i = At[(Number.isFinite(e) ? Math.min(Math.max(Math.floor(e), 1), r) : 1) - 1] ?? At[r - 1] ?? 6e4, a = Number.isFinite(t) ? Math.min(Math.max(t, 0), .999) : 0, o = i + Math.floor(i * jt * a);
|
|
1977
|
+
return Math.max(o, n !== void 0 && Number.isFinite(n) ? Math.min(Math.max(n, 0), Mt) : 0);
|
|
1972
1978
|
}
|
|
1973
1979
|
// lib/refresh/coordinator.ts
|
|
1974
|
-
var
|
|
1980
|
+
var xn = {
|
|
1975
1981
|
onGranted: () => !1,
|
|
1976
1982
|
onLockLost: () => void 0,
|
|
1977
1983
|
onMessage: () => void 0
|
|
1978
1984
|
};
|
|
1979
|
-
function
|
|
1980
|
-
let { locks: t, channel: n, tabId: r, names: i, clock: a } = e, o =
|
|
1981
|
-
g || n.postMessage(
|
|
1985
|
+
function Sn(e) {
|
|
1986
|
+
let { locks: t, channel: n, tabId: r, names: i, clock: a } = e, o = xn, s = null, c = null, l = null, u = null, d = null, f = null, p = 0, m, h = !1, g = !1, _ = (e) => {
|
|
1987
|
+
g || n.postMessage(Jt(r, e));
|
|
1982
1988
|
}, v = () => s !== null && c === null, y = () => {
|
|
1983
1989
|
f?.(), f = null;
|
|
1984
1990
|
}, b = (e) => {
|
|
@@ -1993,7 +1999,7 @@ function xn(e) {
|
|
|
1993
1999
|
type: "still-refreshing",
|
|
1994
2000
|
retry: m
|
|
1995
2001
|
} : { type: "still-refreshing" }), S());
|
|
1996
|
-
},
|
|
2002
|
+
}, Nt);
|
|
1997
2003
|
}, C = () => {
|
|
1998
2004
|
y(), x(), u?.(), u = null;
|
|
1999
2005
|
let e = s;
|
|
@@ -2044,7 +2050,7 @@ function xn(e) {
|
|
|
2044
2050
|
});
|
|
2045
2051
|
}, ee = (e) => {
|
|
2046
2052
|
if (g) return;
|
|
2047
|
-
let t =
|
|
2053
|
+
let t = qt(e.data);
|
|
2048
2054
|
if (t && t.tabId !== r) {
|
|
2049
2055
|
switch (t.type) {
|
|
2050
2056
|
case "still-refreshing":
|
|
@@ -2087,8 +2093,8 @@ function xn(e) {
|
|
|
2087
2093
|
}
|
|
2088
2094
|
};
|
|
2089
2095
|
}
|
|
2090
|
-
function
|
|
2091
|
-
let t =
|
|
2096
|
+
function Cn(e = "local") {
|
|
2097
|
+
let t = xn, n = !1, r = !1, i = 0, a = !1, o = () => {
|
|
2092
2098
|
n = !1, r = !1, i += 1;
|
|
2093
2099
|
};
|
|
2094
2100
|
return {
|
|
@@ -2136,7 +2142,7 @@ var K = {
|
|
|
2136
2142
|
successorTimeout: "error.refresh.successor_timeout",
|
|
2137
2143
|
identityChanged: "error.refresh.identity_changed",
|
|
2138
2144
|
disposed: "error.refresh.disposed"
|
|
2139
|
-
},
|
|
2145
|
+
}, wn = {
|
|
2140
2146
|
"error.refresh.unavailable": 503,
|
|
2141
2147
|
"error.refresh.auth_retry": 401,
|
|
2142
2148
|
"error.refresh.session_ended": 401,
|
|
@@ -2144,7 +2150,7 @@ var K = {
|
|
|
2144
2150
|
"error.refresh.successor_timeout": 401,
|
|
2145
2151
|
"error.refresh.identity_changed": 401,
|
|
2146
2152
|
"error.refresh.disposed": 499
|
|
2147
|
-
},
|
|
2153
|
+
}, Tn = {
|
|
2148
2154
|
"error.refresh.unavailable": "Token refresh is unavailable; a retry is scheduled",
|
|
2149
2155
|
"error.refresh.auth_retry": "Token refresh was refused; a retry is scheduled",
|
|
2150
2156
|
"error.refresh.session_ended": "The session has ended",
|
|
@@ -2156,13 +2162,13 @@ var K = {
|
|
|
2156
2162
|
constructor(e, t = {}) {
|
|
2157
2163
|
super({
|
|
2158
2164
|
id: e,
|
|
2159
|
-
message: t.message ??
|
|
2160
|
-
status:
|
|
2165
|
+
message: t.message ?? Tn[e],
|
|
2166
|
+
status: wn[e],
|
|
2161
2167
|
location: "/auth/refresh",
|
|
2162
2168
|
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
2163
2169
|
}), this.name = "PassflowRefreshError", t.nextRetryAt !== void 0 && (this.nextRetryAt = t.nextRetryAt), t.cause !== void 0 && (this.cause = t.cause);
|
|
2164
2170
|
}
|
|
2165
|
-
},
|
|
2171
|
+
}, En = class extends Error {
|
|
2166
2172
|
constructor(e, t) {
|
|
2167
2173
|
super(t ?? (e === "lock-timeout" ? "Step-up commit could not take the refresh lock in time" : "Step-up commit answer arrived after the stored session moved on")), this.name = "UpgradeCommitInterruptedError", this.reason = e;
|
|
2168
2174
|
}
|
|
@@ -2177,7 +2183,7 @@ function J(e) {
|
|
|
2177
2183
|
}
|
|
2178
2184
|
return t = Math.imul(t ^ t >>> 16, 2246822507), t ^= Math.imul(n ^ n >>> 13, 3266489909), n = Math.imul(n ^ n >>> 16, 2246822507), n ^= Math.imul(t ^ t >>> 13, 3266489909), (4294967296 * (2097151 & n) + (t >>> 0)).toString(16);
|
|
2179
2185
|
}
|
|
2180
|
-
function
|
|
2186
|
+
function Dn(e) {
|
|
2181
2187
|
return typeof e == "string" && e !== "" ? e : void 0;
|
|
2182
2188
|
}
|
|
2183
2189
|
function Y(e) {
|
|
@@ -2188,13 +2194,13 @@ function Y(e) {
|
|
|
2188
2194
|
let t = A(e);
|
|
2189
2195
|
typeof t == "object" && t && (n = t);
|
|
2190
2196
|
} catch {}
|
|
2191
|
-
let r = typeof n.iat == "number" && Number.isFinite(n.iat) ? n.iat : void 0, i = { fp: t }, a =
|
|
2197
|
+
let r = typeof n.iat == "number" && Number.isFinite(n.iat) ? n.iat : void 0, i = { fp: t }, a = Dn(n.sub), o = Dn(n.sid);
|
|
2192
2198
|
return a !== void 0 && (i.sub = a), o !== void 0 && (i.sid = o), r !== void 0 && (i.iat = r), i;
|
|
2193
2199
|
}
|
|
2194
|
-
var
|
|
2195
|
-
function
|
|
2200
|
+
var On = "[passflow] A refresh token carries no iat claim: it is never taken over an ordered one, and cross-tab adoption falls back to fingerprints";
|
|
2201
|
+
function kn(e = (e) => pn().warn(e)) {
|
|
2196
2202
|
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = !1, i = [], a = !1, o = () => {
|
|
2197
|
-
a || (a = !0, e(
|
|
2203
|
+
a || (a = !0, e(On));
|
|
2198
2204
|
}, s = (e, t) => e.has(t) ? !0 : e.size >= 32 ? !1 : (e.add(t), !0), c = (e) => {
|
|
2199
2205
|
if (!e) return;
|
|
2200
2206
|
if (e.iat === void 0) {
|
|
@@ -2235,16 +2241,16 @@ function On(e = (e) => fn().warn(e)) {
|
|
|
2235
2241
|
};
|
|
2236
2242
|
}
|
|
2237
2243
|
// lib/refresh/fence.ts
|
|
2238
|
-
var
|
|
2244
|
+
var An = class extends Error {
|
|
2239
2245
|
constructor(e) {
|
|
2240
2246
|
super(e === "emptied" ? "The shared token storage was emptied" : "The stored refresh token belongs to an ended session"), this.name = "SessionEnded", this.cause = e;
|
|
2241
2247
|
}
|
|
2242
|
-
},
|
|
2248
|
+
}, jn = class extends Error {
|
|
2243
2249
|
constructor() {
|
|
2244
2250
|
super("The shared token storage holds another user's tokens"), this.name = "IdentityChanged";
|
|
2245
2251
|
}
|
|
2246
2252
|
};
|
|
2247
|
-
function
|
|
2253
|
+
function Mn(e) {
|
|
2248
2254
|
if (e) try {
|
|
2249
2255
|
let t = A(e).sub;
|
|
2250
2256
|
return typeof t == "string" && t !== "" ? t : void 0;
|
|
@@ -2253,16 +2259,16 @@ function jn(e) {
|
|
|
2253
2259
|
}
|
|
2254
2260
|
}
|
|
2255
2261
|
function X(e) {
|
|
2256
|
-
return
|
|
2262
|
+
return Mn(e?.access_token) ?? Mn(e?.refresh_token) ?? Mn(e?.id_token);
|
|
2257
2263
|
}
|
|
2258
|
-
function
|
|
2264
|
+
function Nn(e, t) {
|
|
2259
2265
|
return !t || e.iat === void 0 || t.iat === void 0 ? !1 : e.sid === t.sid && e.iat < t.iat;
|
|
2260
2266
|
}
|
|
2261
|
-
function
|
|
2267
|
+
function Pn(e) {
|
|
2262
2268
|
return typeof e == "object" && !!e;
|
|
2263
2269
|
}
|
|
2264
|
-
function
|
|
2265
|
-
let { storage: t, cache: n, schedule: r } = e, i = e.identity ?? (() => void 0), a = e.warn ?? ((e) =>
|
|
2270
|
+
function Fn(e) {
|
|
2271
|
+
let { storage: t, cache: n, schedule: r } = e, i = e.identity ?? (() => void 0), a = e.warn ?? ((e) => pn().warn(e)), o = e.lineage ?? kn(a), s = e.onSessionLost, c, l = 0, u = [], d = [], f = 0, p, m = 0, h, g, _, v, y = () => {
|
|
2266
2272
|
let e = t.getTokens(), n = e?.refresh_token;
|
|
2267
2273
|
if (!n) return p = l, e;
|
|
2268
2274
|
p !== void 0 && (f = Math.max(f, p, m), p = void 0);
|
|
@@ -2299,7 +2305,7 @@ function Pn(e) {
|
|
|
2299
2305
|
let t = E();
|
|
2300
2306
|
t === "wait" && e && (t = "end"), t !== "wait" && D(), t === "wait" && !h && (h = r(() => {
|
|
2301
2307
|
h = void 0, y()?.refresh_token ? N() : O(!0) === "end" && s?.("emptied");
|
|
2302
|
-
},
|
|
2308
|
+
}, It));
|
|
2303
2309
|
let n = t === "keep" ? T() : void 0;
|
|
2304
2310
|
return n && (m = Math.max(m, n.seq)), n && g !== n.fp && (g = n.fp, a(`[passflow] The shared token storage was emptied by the end of the session of ${n.fp}, a refresh token the ${b()?.fp ?? "(none)"} this tab holds is ahead of: keeping it. Nothing is refreshed until the storage holds a token again.`)), t;
|
|
2305
2311
|
}, ee = (e) => e.held !== void 0 && b()?.fp === e.held.cachedFp, k = (e) => {
|
|
@@ -2323,7 +2329,7 @@ function Pn(e) {
|
|
|
2323
2329
|
kind: "superseded",
|
|
2324
2330
|
adopted: !1
|
|
2325
2331
|
};
|
|
2326
|
-
let r =
|
|
2332
|
+
let r = Mn(t.access_token) ?? Mn(n);
|
|
2327
2333
|
if (e.sub && r && e.sub !== r) return {
|
|
2328
2334
|
kind: "identity-changed",
|
|
2329
2335
|
saved: !1
|
|
@@ -2363,22 +2369,22 @@ function Pn(e) {
|
|
|
2363
2369
|
}, re = !!s || !!e.onStoredSessionSeen, ie = re && e.onStorageChange ? e.onStorageChange(N) : void 0, ae = re && e.onWake ? e.onWake(N) : void 0, P = () => {
|
|
2364
2370
|
let e = y();
|
|
2365
2371
|
if (!e?.refresh_token) {
|
|
2366
|
-
if (O() === "end") throw new
|
|
2372
|
+
if (O() === "end") throw new An("emptied");
|
|
2367
2373
|
return "held";
|
|
2368
2374
|
}
|
|
2369
2375
|
let t = n.getTokens();
|
|
2370
2376
|
if (e.refresh_token === t?.refresh_token) return "send";
|
|
2371
2377
|
let r = i() ?? X(t), a = X(e);
|
|
2372
|
-
if (r && a && r !== a) throw new
|
|
2378
|
+
if (r && a && r !== a) throw new jn();
|
|
2373
2379
|
let s = Y(e.refresh_token);
|
|
2374
2380
|
if (o.isEnded(s)) {
|
|
2375
2381
|
if (s && C(s)) return "held";
|
|
2376
|
-
throw new
|
|
2382
|
+
throw new An("ended");
|
|
2377
2383
|
}
|
|
2378
2384
|
let c = Y(t?.refresh_token);
|
|
2379
2385
|
return j(s, c) ? (M(e), "adopted") : s && c && s.sid !== c.sid ? "send" : s && k(s) ? "held" : "send";
|
|
2380
2386
|
}, oe = (e) => {
|
|
2381
|
-
let t = i(), r =
|
|
2387
|
+
let t = i(), r = Mn(e);
|
|
2382
2388
|
if (t && r && t !== r) return { kind: "identity-changed" };
|
|
2383
2389
|
let a = Y(e) ?? { fp: e };
|
|
2384
2390
|
if (o.isEnded(a)) return C(a) ? { kind: "superseded" } : { kind: "ended" };
|
|
@@ -2386,7 +2392,7 @@ function Pn(e) {
|
|
|
2386
2392
|
let s = {
|
|
2387
2393
|
refreshToken: e,
|
|
2388
2394
|
order: a
|
|
2389
|
-
}, c = t ?? r ??
|
|
2395
|
+
}, c = t ?? r ?? Mn(n.getTokens()?.access_token);
|
|
2390
2396
|
return c !== void 0 && (s.sub = c), v && v.fp === a.fp && (s.held = { cachedFp: v.cachedFp }), {
|
|
2391
2397
|
kind: "send",
|
|
2392
2398
|
sent: s
|
|
@@ -2405,7 +2411,7 @@ function Pn(e) {
|
|
|
2405
2411
|
saved: !0
|
|
2406
2412
|
};
|
|
2407
2413
|
let c = Y(r.refresh_token);
|
|
2408
|
-
return c && (
|
|
2414
|
+
return c && (Nn(c, e.order) || Nn(c, b())) ? (a(`[passflow] Refused to save a refresh result older than the token this tab holds: ${e.order.fp} was answered with ${c.fp}. Neither saved nor adopted.`), {
|
|
2409
2415
|
kind: "superseded",
|
|
2410
2416
|
adopted: !1
|
|
2411
2417
|
}) : (o.retire(e.order), t.saveTokens(r), n.setTokensCache(r), { kind: "saved" });
|
|
@@ -2417,7 +2423,7 @@ function Pn(e) {
|
|
|
2417
2423
|
kind: "superseded",
|
|
2418
2424
|
adopted: !1
|
|
2419
2425
|
};
|
|
2420
|
-
let r =
|
|
2426
|
+
let r = yn(t), i = r.kind === "blocked" || r.kind === "auth";
|
|
2421
2427
|
return ee(e) && i ? (o.retire(e.order), _ = e.order, {
|
|
2422
2428
|
kind: "own",
|
|
2423
2429
|
failure: r,
|
|
@@ -2428,9 +2434,9 @@ function Pn(e) {
|
|
|
2428
2434
|
heldRefused: !1
|
|
2429
2435
|
});
|
|
2430
2436
|
}, I = (e) => {
|
|
2431
|
-
if (!
|
|
2437
|
+
if (!Pn(e)) return !1;
|
|
2432
2438
|
let { from: t, fromIat: r, fromSid: a, to: c, tokens: l } = e;
|
|
2433
|
-
if (typeof t != "string" || typeof c != "string" || !
|
|
2439
|
+
if (typeof t != "string" || typeof c != "string" || !Pn(l)) return !1;
|
|
2434
2440
|
let u = l;
|
|
2435
2441
|
if (typeof u.access_token != "string" || u.access_token === "" || typeof u.refresh_token != "string" || u.refresh_token === "" || J(u.refresh_token) !== c) return !1;
|
|
2436
2442
|
let d = y();
|
|
@@ -2515,7 +2521,7 @@ function Pn(e) {
|
|
|
2515
2521
|
};
|
|
2516
2522
|
}
|
|
2517
2523
|
// lib/refresh/controller.ts
|
|
2518
|
-
function
|
|
2524
|
+
function In() {
|
|
2519
2525
|
let e, t, n = new Promise((n, r) => {
|
|
2520
2526
|
e = n, t = r;
|
|
2521
2527
|
});
|
|
@@ -2525,7 +2531,7 @@ function Fn() {
|
|
|
2525
2531
|
reject: t
|
|
2526
2532
|
};
|
|
2527
2533
|
}
|
|
2528
|
-
var
|
|
2534
|
+
var Ln = {
|
|
2529
2535
|
strikes: K.sessionEnded,
|
|
2530
2536
|
"session-ended": K.sessionEnded,
|
|
2531
2537
|
"stored-ended": K.sessionEnded,
|
|
@@ -2536,42 +2542,42 @@ var In = {
|
|
|
2536
2542
|
"identity-changed": K.identityChanged,
|
|
2537
2543
|
disposed: K.disposed
|
|
2538
2544
|
};
|
|
2539
|
-
function
|
|
2545
|
+
function Rn(e) {
|
|
2540
2546
|
throw Error(`Unexpected refresh state: ${JSON.stringify(e)}`);
|
|
2541
2547
|
}
|
|
2542
|
-
function
|
|
2548
|
+
function zn(e) {
|
|
2543
2549
|
if (e === void 0 || !Number.isFinite(e)) return 3;
|
|
2544
2550
|
let t = Math.floor(e);
|
|
2545
2551
|
return t >= 1 ? t : 3;
|
|
2546
2552
|
}
|
|
2547
|
-
function
|
|
2553
|
+
function Bn(e, t) {
|
|
2548
2554
|
return e instanceof Error && e.message ? e.message : t;
|
|
2549
2555
|
}
|
|
2550
|
-
function
|
|
2556
|
+
function Vn(e) {
|
|
2551
2557
|
if (typeof e != "object" || !e) return;
|
|
2552
2558
|
let t = e.id;
|
|
2553
2559
|
return typeof t == "string" || typeof t == "number" ? t : void 0;
|
|
2554
2560
|
}
|
|
2555
|
-
function
|
|
2561
|
+
function Hn(e) {
|
|
2556
2562
|
let t = {};
|
|
2557
2563
|
return e?.access_token && (t.access_token = e.access_token), e?.refresh_token && (t.refresh_token = e.refresh_token), e?.id_token && (t.id_token = e.id_token), e?.scopes && (t.scopes = [...e.scopes]), t;
|
|
2558
2564
|
}
|
|
2559
|
-
function
|
|
2565
|
+
function Un(e, t) {
|
|
2560
2566
|
let n = {};
|
|
2561
2567
|
e.access_token && (n.access_token = e.access_token), e.refresh_token && (n.refresh_token = e.refresh_token), e.id_token && (n.id_token = e.id_token);
|
|
2562
2568
|
let r = t?.scopes ?? e.scopes;
|
|
2563
2569
|
return r && (n.scopes = r), n;
|
|
2564
2570
|
}
|
|
2565
|
-
function
|
|
2566
|
-
let { emit: t, storage: n, cache: r, transport: i, coordination: a } = e, o = a.clock, s = e.logger ??
|
|
2571
|
+
function Wn(e) {
|
|
2572
|
+
let { emit: t, storage: n, cache: r, transport: i, coordination: a } = e, o = a.clock, s = e.logger ?? pn(), c = zn(e.strikes), l = a.transports ? Sn({
|
|
2567
2573
|
locks: a.transports.locks,
|
|
2568
2574
|
channel: a.transports.channel,
|
|
2569
2575
|
tabId: a.transports.tabId,
|
|
2570
2576
|
names: a.names,
|
|
2571
2577
|
clock: o
|
|
2572
|
-
}) :
|
|
2578
|
+
}) : Cn(), u = { kind: "idle" }, d = 0, f = !1, p = !a.warnOnFirstCycle, m = 0, h = 0, g, _, v, y, b, x, S, C, w = !1, T = () => o.now(), E = () => i.mode(), D = () => J(r.getTokens()?.refresh_token), O = () => ({ ...r.getTokens() ?? {} }), ee = () => i.opaqueMarker ? i.opaqueMarker() : n.getTokens()?.id_token, k = () => (S === void 0 && (S = X(r.getTokens() ?? n.getTokens())), S), A = /* @__PURE__ */ new Set(), j = /* @__PURE__ */ new Set(), M = (e) => () => {
|
|
2573
2579
|
for (let t of Array.from(e)) t();
|
|
2574
|
-
}, te = a.onStorageChange?.(M(A)), ne = e.platform?.onForeground(M(j)), N =
|
|
2580
|
+
}, te = a.onStorageChange?.(M(A)), ne = e.platform?.onForeground(M(j)), N = Fn({
|
|
2575
2581
|
storage: n,
|
|
2576
2582
|
cache: r,
|
|
2577
2583
|
identity: k,
|
|
@@ -2586,13 +2592,13 @@ function Un(e) {
|
|
|
2586
2592
|
}), re = (e) => ({
|
|
2587
2593
|
trigger: e,
|
|
2588
2594
|
startedAt: T(),
|
|
2589
|
-
plain:
|
|
2595
|
+
plain: In(),
|
|
2590
2596
|
fresh: []
|
|
2591
2597
|
}), ie = (e) => e.kind === "idle" || e.kind === "ended" ? void 0 : e.pending, ae = (e, t) => {
|
|
2592
2598
|
if (t === void 0) return e.plain.promise;
|
|
2593
2599
|
let n = {
|
|
2594
2600
|
callTime: t,
|
|
2595
|
-
deferred:
|
|
2601
|
+
deferred: In()
|
|
2596
2602
|
};
|
|
2597
2603
|
return e.fresh.push(n), n.deferred.promise;
|
|
2598
2604
|
}, P = (e, t, n = !1) => {
|
|
@@ -2611,11 +2617,11 @@ function Un(e) {
|
|
|
2611
2617
|
}
|
|
2612
2618
|
}, F = (e, n, r, i) => {
|
|
2613
2619
|
let a = {
|
|
2614
|
-
message:
|
|
2620
|
+
message: Bn(r, "Token refresh failed"),
|
|
2615
2621
|
originalError: r,
|
|
2616
2622
|
operation: e,
|
|
2617
2623
|
source: n
|
|
2618
|
-
}, o =
|
|
2624
|
+
}, o = Vn(r);
|
|
2619
2625
|
o !== void 0 && (a.code = o), i && (a.refresh = i), t("error", a);
|
|
2620
2626
|
}, I = (e, t) => {
|
|
2621
2627
|
let n = {
|
|
@@ -2648,7 +2654,7 @@ function Un(e) {
|
|
|
2648
2654
|
let n = r.getTokens(), i = J(n?.refresh_token);
|
|
2649
2655
|
e.fp && i && l.post({
|
|
2650
2656
|
type: "tokens-refreshed",
|
|
2651
|
-
tokens:
|
|
2657
|
+
tokens: Hn(n),
|
|
2652
2658
|
from: e.fp,
|
|
2653
2659
|
...e.iat === void 0 ? {} : { fromIat: e.iat },
|
|
2654
2660
|
fromSid: e.sid ?? "",
|
|
@@ -2656,7 +2662,7 @@ function Un(e) {
|
|
|
2656
2662
|
...t === void 0 ? {} : { sentAt: t }
|
|
2657
2663
|
});
|
|
2658
2664
|
}, ue = () => {
|
|
2659
|
-
p || (p = !0, s.warn(
|
|
2665
|
+
p || (p = !0, s.warn(Yt));
|
|
2660
2666
|
}, de = (e) => {
|
|
2661
2667
|
(e.kind === "backoff" || e.kind === "blocked-wait") && e.cancel();
|
|
2662
2668
|
}, R = (e, n) => {
|
|
@@ -2670,7 +2676,7 @@ function Un(e) {
|
|
|
2670
2676
|
}, e !== "disposed" && N.dropSession(), (e === "strikes" || e === "successor-timeout") && E() !== "json" && i.invalidate(), u = {
|
|
2671
2677
|
kind: "ended",
|
|
2672
2678
|
cause: e
|
|
2673
|
-
}, se(r, n ?? new q(
|
|
2679
|
+
}, se(r, n ?? new q(Ln[e])), e) {
|
|
2674
2680
|
case "strikes":
|
|
2675
2681
|
t("session:expired", {
|
|
2676
2682
|
reason: "refresh_failed",
|
|
@@ -2705,7 +2711,7 @@ function Un(e) {
|
|
|
2705
2711
|
break;
|
|
2706
2712
|
case "signed-out-here":
|
|
2707
2713
|
case "disposed": break;
|
|
2708
|
-
default:
|
|
2714
|
+
default: Rn(e);
|
|
2709
2715
|
}
|
|
2710
2716
|
}, fe = () => {
|
|
2711
2717
|
if (u.kind !== "ended" || u.cause === "disposed" || f || E() !== "json") return;
|
|
@@ -2722,7 +2728,7 @@ function Un(e) {
|
|
|
2722
2728
|
}, pe = (e) => {
|
|
2723
2729
|
u.kind === "ended" || f || E() === "json" && (R(e === "emptied" ? "emptied" : "identity-changed"), e === "identity-changed" && fe());
|
|
2724
2730
|
}, me = (e) => {
|
|
2725
|
-
e instanceof
|
|
2731
|
+
e instanceof jn ? (R("identity-changed"), fe()) : e instanceof An ? R(e.cause === "emptied" ? "emptied" : "stored-ended") : R("stored-ended", e);
|
|
2726
2732
|
}, he = () => {
|
|
2727
2733
|
u = { kind: "idle" }, w || l.release();
|
|
2728
2734
|
}, ge = (e) => !e.from || E() !== "json" || e.from === D() || e.from === J(n.getTokens()?.refresh_token), _e = (e) => {
|
|
@@ -2791,14 +2797,14 @@ function Un(e) {
|
|
|
2791
2797
|
case "ended": return N.endHeldSend(), R("stored-ended"), !1;
|
|
2792
2798
|
case "identity-changed": return N.endHeldSend(), R("identity-changed"), fe(), !1;
|
|
2793
2799
|
case "send": return Ce(e, t, a.sent, r);
|
|
2794
|
-
default: return
|
|
2800
|
+
default: return Rn(a);
|
|
2795
2801
|
}
|
|
2796
2802
|
}, Ce = (e, n, r, a) => {
|
|
2797
2803
|
let o = {
|
|
2798
2804
|
generation: d,
|
|
2799
2805
|
sentAt: T(),
|
|
2800
2806
|
trigger: n,
|
|
2801
|
-
settled:
|
|
2807
|
+
settled: In()
|
|
2802
2808
|
};
|
|
2803
2809
|
r ? o.sent = r : o.marker = ee(), a && (o.stored = a), u = {
|
|
2804
2810
|
kind: "refreshing",
|
|
@@ -2835,7 +2841,7 @@ function Un(e) {
|
|
|
2835
2841
|
if (!we(e)) return;
|
|
2836
2842
|
r.setTokensCache({
|
|
2837
2843
|
...n.getTokens() ?? {},
|
|
2838
|
-
...
|
|
2844
|
+
...Un(t, void 0)
|
|
2839
2845
|
}), L("refresh", "this-tab");
|
|
2840
2846
|
let c = k();
|
|
2841
2847
|
l.post(c === void 0 ? {
|
|
@@ -2848,7 +2854,7 @@ function Un(e) {
|
|
|
2848
2854
|
}), he(), P(a, e.sentAt);
|
|
2849
2855
|
return;
|
|
2850
2856
|
}
|
|
2851
|
-
let o = D(), s = N.commitSave(e.sent,
|
|
2857
|
+
let o = D(), s = N.commitSave(e.sent, Un(t, e.stored));
|
|
2852
2858
|
switch (s.kind) {
|
|
2853
2859
|
case "saved":
|
|
2854
2860
|
L("refresh", "this-tab"), le(e.sent.order, e.sentAt), he(), P(a, e.sentAt);
|
|
@@ -2866,7 +2872,7 @@ function Un(e) {
|
|
|
2866
2872
|
F("refresh", e.trigger, t, I("auth")), R("identity-changed", t), fe();
|
|
2867
2873
|
return;
|
|
2868
2874
|
}
|
|
2869
|
-
default:
|
|
2875
|
+
default: Rn(s);
|
|
2870
2876
|
}
|
|
2871
2877
|
}, Ee = (e, t) => {
|
|
2872
2878
|
if (e.sent?.held && N.endHeldSend(), !we(e) || u.kind !== "refreshing") return;
|
|
@@ -2886,9 +2892,9 @@ function Un(e) {
|
|
|
2886
2892
|
case "own":
|
|
2887
2893
|
r = o.failure, i = o.heldRefused;
|
|
2888
2894
|
break;
|
|
2889
|
-
default:
|
|
2895
|
+
default: Rn(o);
|
|
2890
2896
|
}
|
|
2891
|
-
} else r =
|
|
2897
|
+
} else r = yn(t, T());
|
|
2892
2898
|
if (i) F("refresh", e.trigger, t, I(r.kind)), L("adopted", "other-tab"), he(), P(n, void 0, !0);
|
|
2893
2899
|
else switch (r.kind) {
|
|
2894
2900
|
case "blocked":
|
|
@@ -2904,10 +2910,10 @@ function Un(e) {
|
|
|
2904
2910
|
case "transient":
|
|
2905
2911
|
m += 1, De(e, n, t, r);
|
|
2906
2912
|
return;
|
|
2907
|
-
default:
|
|
2913
|
+
default: Rn(r.kind);
|
|
2908
2914
|
}
|
|
2909
2915
|
}, De = (e, t, n, r) => {
|
|
2910
|
-
let i = T() +
|
|
2916
|
+
let i = T() + bn(m, o.random(), r.retryAfterMs), a = r.kind === "auth" ? "auth" : "transient";
|
|
2911
2917
|
F("refresh", e.trigger, n, I(a, i)), a === "transient" && ce(T(), i, "this-tab");
|
|
2912
2918
|
let s = {
|
|
2913
2919
|
kind: a,
|
|
@@ -2917,7 +2923,7 @@ function Un(e) {
|
|
|
2917
2923
|
}, c = e.sent?.order.fp;
|
|
2918
2924
|
c && (s.from = c), _ && (s.failingSince = _.since), g = s, l.holding && l.post({
|
|
2919
2925
|
type: "retry-scheduled",
|
|
2920
|
-
message:
|
|
2926
|
+
message: Bn(n, "Token refresh failed"),
|
|
2921
2927
|
retry: s
|
|
2922
2928
|
}), _e(re("retry")), oe(t, n, e.sentAt);
|
|
2923
2929
|
}, z = (e, t) => {
|
|
@@ -2930,8 +2936,8 @@ function Un(e) {
|
|
|
2930
2936
|
fp: i.fp
|
|
2931
2937
|
})), r && N.deleteIfStillDead(r), R("strikes", t);
|
|
2932
2938
|
}, Oe = (e, t, n, r) => {
|
|
2933
|
-
l.release(), s.warn(`[passflow] The refresh token was already used, most likely by another tab; waiting for its successor: ${
|
|
2934
|
-
let i = d, a = T() +
|
|
2939
|
+
l.release(), s.warn(`[passflow] The refresh token was already used, most likely by another tab; waiting for its successor: ${Bn(n, "blocked")}`);
|
|
2940
|
+
let i = d, a = T() + Pt, c = {
|
|
2935
2941
|
kind: "blocked-wait",
|
|
2936
2942
|
pending: e,
|
|
2937
2943
|
deadline: a,
|
|
@@ -2944,9 +2950,9 @@ function Un(e) {
|
|
|
2944
2950
|
i === d && u === c && (ke() || (f ? (e.cookieRetried = !0, u = {
|
|
2945
2951
|
kind: "waiting",
|
|
2946
2952
|
pending: e
|
|
2947
|
-
}, l.request()) : T() >= a ? (s.warn("[passflow] No successor of the used refresh token appeared; ending the session in this tab only."), R("successor-timeout")) : c.cancel = o.setTimeout(p,
|
|
2953
|
+
}, l.request()) : T() >= a ? (s.warn("[passflow] No successor of the used refresh token appeared; ending the session in this tab only."), R("successor-timeout")) : c.cancel = o.setTimeout(p, Ft)));
|
|
2948
2954
|
};
|
|
2949
|
-
c.cancel = o.setTimeout(p, f ?
|
|
2955
|
+
c.cancel = o.setTimeout(p, f ? Lt : Ft);
|
|
2950
2956
|
}, ke = () => {
|
|
2951
2957
|
if (u.kind !== "blocked-wait") return !1;
|
|
2952
2958
|
let e = u;
|
|
@@ -2958,10 +2964,10 @@ function Un(e) {
|
|
|
2958
2964
|
r.setTokensCache(n.getTokens());
|
|
2959
2965
|
}
|
|
2960
2966
|
return u === e && (e.cancel(), L("adopted", "other-tab"), u = { kind: "idle" }, P(e.pending, void 0, !0), !0);
|
|
2961
|
-
},
|
|
2967
|
+
}, Ae = (e) => {
|
|
2962
2968
|
let t = k(), n = !e.sub || !t || e.sub === t;
|
|
2963
2969
|
return E() === "json" ? !!e.fp && e.fp === D() && n : !e.fp && n;
|
|
2964
|
-
},
|
|
2970
|
+
}, B = (e, t) => {
|
|
2965
2971
|
if (e !== "signed-out" || !t.sub) return !1;
|
|
2966
2972
|
let n = k();
|
|
2967
2973
|
return n !== void 0 && t.sub === n;
|
|
@@ -2990,12 +2996,12 @@ function Un(e) {
|
|
|
2990
2996
|
case "idle":
|
|
2991
2997
|
case "refreshing":
|
|
2992
2998
|
case "ended": return;
|
|
2993
|
-
default:
|
|
2999
|
+
default: Rn(u);
|
|
2994
3000
|
}
|
|
2995
3001
|
}, Ne = (e) => {
|
|
2996
3002
|
let t = {};
|
|
2997
3003
|
e.fp && (t.fp = e.fp), e.sub && (t.sub = e.sub), e.sid && (t.sid = e.sid), e.iat !== void 0 && (t.iat = e.iat);
|
|
2998
|
-
let n = u.kind !== "ended" && (
|
|
3004
|
+
let n = u.kind !== "ended" && (Ae(t) || B(e.type, t));
|
|
2999
3005
|
t.fp && N.endLineage({
|
|
3000
3006
|
...t,
|
|
3001
3007
|
fp: t.fp
|
|
@@ -3054,7 +3060,7 @@ function Un(e) {
|
|
|
3054
3060
|
return;
|
|
3055
3061
|
case "takeover":
|
|
3056
3062
|
case "rate-limited": return;
|
|
3057
|
-
default:
|
|
3063
|
+
default: Rn(e);
|
|
3058
3064
|
}
|
|
3059
3065
|
}, Fe = () => {
|
|
3060
3066
|
C && !l.holding && l.post({
|
|
@@ -3119,7 +3125,7 @@ function Un(e) {
|
|
|
3119
3125
|
case "refreshing":
|
|
3120
3126
|
case "backoff":
|
|
3121
3127
|
case "blocked-wait": return ae(u.pending, t);
|
|
3122
|
-
default: return
|
|
3128
|
+
default: return Rn(u);
|
|
3123
3129
|
}
|
|
3124
3130
|
}, Re = (e) => {
|
|
3125
3131
|
if (f) return Promise.reject(new q(K.disposed));
|
|
@@ -3159,7 +3165,7 @@ function Un(e) {
|
|
|
3159
3165
|
r(), n();
|
|
3160
3166
|
});
|
|
3161
3167
|
});
|
|
3162
|
-
},
|
|
3168
|
+
}, He = () => {
|
|
3163
3169
|
if (w = !1, !f && l.holding) {
|
|
3164
3170
|
if (u.kind === "waiting") be() || ye();
|
|
3165
3171
|
else if (u.kind === "backoff") {
|
|
@@ -3167,19 +3173,19 @@ function Un(e) {
|
|
|
3167
3173
|
u.cancel(), _e(e);
|
|
3168
3174
|
} else u.kind === "idle" && g && g.nextAt > T() && ge(g) ? (m = g.attempt, h = g.strikes, _e(re("retry"))) : u.kind === "idle" && l.release();
|
|
3169
3175
|
}
|
|
3170
|
-
},
|
|
3176
|
+
}, V = async (e, t) => {
|
|
3171
3177
|
if (f) throw new q(K.disposed);
|
|
3172
3178
|
ue();
|
|
3173
|
-
let n = T() +
|
|
3179
|
+
let n = T() + Rt;
|
|
3174
3180
|
if (await Ve(n - T()), (!l.holding || u.kind === "refreshing") && (u.kind === "refreshing" ? "timeout" : await Be("commit", n - T())) === "timeout") {
|
|
3175
|
-
let e = new
|
|
3181
|
+
let e = new En("lock-timeout");
|
|
3176
3182
|
throw F("upgrade.commit", "upgrade", e), e;
|
|
3177
3183
|
}
|
|
3178
3184
|
w = !0;
|
|
3179
3185
|
try {
|
|
3180
3186
|
return await Ue(e, t);
|
|
3181
3187
|
} finally {
|
|
3182
|
-
|
|
3188
|
+
He();
|
|
3183
3189
|
}
|
|
3184
3190
|
}, Ue = async (e, a) => {
|
|
3185
3191
|
let o, s;
|
|
@@ -3219,7 +3225,7 @@ function Un(e) {
|
|
|
3219
3225
|
if (!o) {
|
|
3220
3226
|
await i.applyOpaque(u), r.setTokensCache({
|
|
3221
3227
|
...n.getTokens() ?? {},
|
|
3222
|
-
...
|
|
3228
|
+
...Un(u, void 0)
|
|
3223
3229
|
}), We(c);
|
|
3224
3230
|
let e = k();
|
|
3225
3231
|
return l.post(e === void 0 ? {
|
|
@@ -3231,9 +3237,9 @@ function Un(e) {
|
|
|
3231
3237
|
sub: e
|
|
3232
3238
|
}), O();
|
|
3233
3239
|
}
|
|
3234
|
-
let d = N.commitSave(o,
|
|
3240
|
+
let d = N.commitSave(o, Un(u, s));
|
|
3235
3241
|
if (d.kind === "saved") return We(c), le(o.order, c), O();
|
|
3236
|
-
let f = new
|
|
3242
|
+
let f = new En("superseded");
|
|
3237
3243
|
throw F("upgrade.commit", "upgrade", f), d.kind === "superseded" && d.adopted && L("adopted", "other-tab"), f;
|
|
3238
3244
|
}, We = (e) => {
|
|
3239
3245
|
if (L("upgrade", "this-tab"), u.kind === "waiting" || u.kind === "backoff" || u.kind === "blocked-wait") {
|
|
@@ -3256,10 +3262,10 @@ function Un(e) {
|
|
|
3256
3262
|
return {
|
|
3257
3263
|
refresh: Re,
|
|
3258
3264
|
ensureFresh: ze,
|
|
3259
|
-
commitUpgrade:
|
|
3265
|
+
commitUpgrade: V,
|
|
3260
3266
|
signOut: async (e) => {
|
|
3261
3267
|
if (f) return e(n.getTokens()?.refresh_token);
|
|
3262
|
-
let t = T() +
|
|
3268
|
+
let t = T() + zt;
|
|
3263
3269
|
Ke(), await Ve(t - T()), Ke(), l.coordinated && !l.holding && await Be("logout", t - T());
|
|
3264
3270
|
try {
|
|
3265
3271
|
Ge(), await e(n.getTokens()?.refresh_token);
|
|
@@ -3303,8 +3309,8 @@ function Un(e) {
|
|
|
3303
3309
|
}
|
|
3304
3310
|
// lib/store.ts
|
|
3305
3311
|
var Z = /* @__PURE__ */ function(e) {
|
|
3306
|
-
return e.SignIn = "signin", e.SignInStart = "signin:start", e.Register = "register", e.RegisterStart = "register:start", e.SignOut = "signout", e.SessionRestored = "session:restored", e.SessionExpired = "session:expired", e.Error = "error", e.Refresh = "refresh", e.RefreshStart = "refresh:start", e.TokenCacheExpired = "token-cache-expired", e.TwoFactorRequired = "2fa:required", e.TwoFactorSetupStarted = "2fa:setup_started", e.TwoFactorEnabled = "2fa:enabled", e.TwoFactorDisabled = "2fa:disabled", e.TwoFactorVerified = "2fa:verified", e.TwoFactorRecoveryUsed = "2fa:recovery_used", e.TwoFactorRecoveryCodesLow = "2fa:recovery_low", e.TwoFactorRecoveryCodesExhausted = "2fa:recovery_exhausted", e.TwoFactorSetupMagicLinkValidated = "2fa:magic_link_validated", e.TwoFactorSetupMagicLinkFailed = "2fa:magic_link_failed", e.TwoFactorChallengeReceived = "two_factor_challenge_received", e.TwoFactorMethodSwitched = "two_factor_method_switched", e.TwoFactorDeviceTrusted = "two_factor_device_trusted", e.RefreshFailing = "refresh:failing", e.RefreshRecovered = "refresh:recovered", e;
|
|
3307
|
-
}({}),
|
|
3312
|
+
return e.SignIn = "signin", e.SignInStart = "signin:start", e.Register = "register", e.RegisterStart = "register:start", e.EmailVerificationRequired = "email-verification:required", e.SignOut = "signout", e.SessionRestored = "session:restored", e.SessionExpired = "session:expired", e.Error = "error", e.Refresh = "refresh", e.RefreshStart = "refresh:start", e.TokenCacheExpired = "token-cache-expired", e.TwoFactorRequired = "2fa:required", e.TwoFactorSetupStarted = "2fa:setup_started", e.TwoFactorEnabled = "2fa:enabled", e.TwoFactorDisabled = "2fa:disabled", e.TwoFactorVerified = "2fa:verified", e.TwoFactorRecoveryUsed = "2fa:recovery_used", e.TwoFactorRecoveryCodesLow = "2fa:recovery_low", e.TwoFactorRecoveryCodesExhausted = "2fa:recovery_exhausted", e.TwoFactorSetupMagicLinkValidated = "2fa:magic_link_validated", e.TwoFactorSetupMagicLinkFailed = "2fa:magic_link_failed", e.TwoFactorChallengeReceived = "two_factor_challenge_received", e.TwoFactorMethodSwitched = "two_factor_method_switched", e.TwoFactorDeviceTrusted = "two_factor_device_trusted", e.RefreshFailing = "refresh:failing", e.RefreshRecovered = "refresh:recovered", e;
|
|
3313
|
+
}({}), Gn = class {
|
|
3308
3314
|
constructor() {
|
|
3309
3315
|
this.subscribers = /* @__PURE__ */ new Map();
|
|
3310
3316
|
}
|
|
@@ -3323,7 +3329,7 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3323
3329
|
n && (t.forEach((e) => n.delete(e)), n.size === 0 && this.subscribers.delete(e));
|
|
3324
3330
|
}
|
|
3325
3331
|
notify(e, t) {
|
|
3326
|
-
e === "error" &&
|
|
3332
|
+
e === "error" && Et(this, t?.originalError), this.subscribers.forEach((n, r) => {
|
|
3327
3333
|
(!n || n.has(e)) && r.onAuthChange?.(e, t);
|
|
3328
3334
|
});
|
|
3329
3335
|
}
|
|
@@ -3344,18 +3350,18 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3344
3350
|
twoFactorNotEnabled: "error.2fa.not_enabled",
|
|
3345
3351
|
notImplemented: "error.not.implemented",
|
|
3346
3352
|
tokenInvalid: "error.api.request.token.invalid"
|
|
3347
|
-
},
|
|
3353
|
+
}, Kn = Object.freeze([
|
|
3348
3354
|
Q.twoFactorCodeInvalid,
|
|
3349
3355
|
Q.twoFactorNotEnabled,
|
|
3350
3356
|
Q.challengeInvalid,
|
|
3351
3357
|
Q.challengeSessionMismatch,
|
|
3352
3358
|
Q.challengeTooManyAttempts
|
|
3353
|
-
]),
|
|
3359
|
+
]), qn = Object.freeze([Q.tokenInvalid]), Jn = Object.freeze([
|
|
3354
3360
|
"wrong_code",
|
|
3355
3361
|
"challenge_spent",
|
|
3356
3362
|
"not_registered",
|
|
3357
3363
|
"prepare_not_required"
|
|
3358
|
-
]),
|
|
3364
|
+
]), Yn = (e) => Jn.includes(e), Xn = {
|
|
3359
3365
|
wrong_code: "That code was not accepted. Try again.",
|
|
3360
3366
|
challenge_spent: "That verification challenge is no longer valid. Start again.",
|
|
3361
3367
|
exhausted: "Too many attempts. Try again later.",
|
|
@@ -3369,16 +3375,16 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3369
3375
|
session_changed: "The session ended during verification."
|
|
3370
3376
|
}, $ = class extends Error {
|
|
3371
3377
|
constructor(e) {
|
|
3372
|
-
super(e.message ||
|
|
3378
|
+
super(e.message || Xn[e.kind]), this.name = "UpgradeTransportError", this.code = "upgrade_transport", this.kind = e.kind, this.status = e.status, this.errorId = e.errorId, this.retryable = Yn(e.kind), e.cause !== void 0 && (this.cause = e.cause);
|
|
3373
3379
|
}
|
|
3374
|
-
},
|
|
3380
|
+
}, Zn = Object.freeze([
|
|
3375
3381
|
"upgrade_transport",
|
|
3376
3382
|
"upgrade_insufficient",
|
|
3377
3383
|
"upgrade_unavailable",
|
|
3378
3384
|
"upgrade_session_changed",
|
|
3379
3385
|
"upgrade_cancelled",
|
|
3380
3386
|
"upgrade_unsatisfiable"
|
|
3381
|
-
]),
|
|
3387
|
+
]), Qn = (e) => typeof e == "object" && !!e && typeof e.code == "string" && Zn.includes(e.code), $n = (e) => e instanceof $ || typeof e == "object" && !!e && e.code === "upgrade_transport", er = (e) => {
|
|
3382
3388
|
if (typeof e != "object" || !e) return {
|
|
3383
3389
|
hasResponse: !1,
|
|
3384
3390
|
message: typeof e == "string" ? e : void 0
|
|
@@ -3390,7 +3396,7 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3390
3396
|
message: typeof t.message == "string" ? t.message : void 0,
|
|
3391
3397
|
hasResponse: n !== void 0 || typeof t.status == "number"
|
|
3392
3398
|
};
|
|
3393
|
-
},
|
|
3399
|
+
}, tr = (e, t) => {
|
|
3394
3400
|
switch (e) {
|
|
3395
3401
|
case Q.twoFactorCodeInvalid: return "wrong_code";
|
|
3396
3402
|
case Q.challengeInvalid:
|
|
@@ -3407,11 +3413,11 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3407
3413
|
case Q.tokenInvalid: return t === "refresh" ? "session_changed" : "fatal";
|
|
3408
3414
|
default: return;
|
|
3409
3415
|
}
|
|
3410
|
-
},
|
|
3416
|
+
}, nr = (e, t) => e === void 0 ? "network" : e === 501 ? "unavailable" : e === 400 ? "fatal" : e === 401 || e === 403 ? t === "start" ? "challenge_spent" : "session_changed" : e >= 500 ? "network" : "fatal", rr = (e, t) => {
|
|
3411
3417
|
if (e instanceof $) return e;
|
|
3412
|
-
let n =
|
|
3418
|
+
let n = er(e);
|
|
3413
3419
|
return n.hasResponse ? new $({
|
|
3414
|
-
kind:
|
|
3420
|
+
kind: tr(n.errorId, t) ?? nr(n.status, t),
|
|
3415
3421
|
message: n.message,
|
|
3416
3422
|
status: n.status,
|
|
3417
3423
|
errorId: n.errorId,
|
|
@@ -3421,62 +3427,74 @@ var Z = /* @__PURE__ */ function(e) {
|
|
|
3421
3427
|
message: n.message,
|
|
3422
3428
|
cause: e
|
|
3423
3429
|
});
|
|
3424
|
-
},
|
|
3430
|
+
}, ir = (e) => e.errorId !== void 0 && Kn.includes(e.errorId), ar = (e) => e.errorId !== void 0 && qn.includes(e.errorId), or = class extends Error {
|
|
3425
3431
|
constructor(e, t, n) {
|
|
3426
3432
|
super(n ?? "The session was elevated, but this action requires a higher assurance level"), this.name = "UpgradeInsufficientError", this.code = "upgrade_insufficient", this.obtained = e, this.required = t;
|
|
3427
3433
|
}
|
|
3428
|
-
},
|
|
3434
|
+
}, sr = class extends Error {
|
|
3429
3435
|
constructor(e = "Step-up verification is not available on this deployment") {
|
|
3430
3436
|
super(e), this.name = "UpgradeUnavailableError", this.code = "upgrade_unavailable";
|
|
3431
3437
|
}
|
|
3432
|
-
},
|
|
3438
|
+
}, cr = class extends Error {
|
|
3433
3439
|
constructor(e = "The session changed during verification") {
|
|
3434
3440
|
super(e), this.name = "UpgradeSessionChangedError", this.code = "upgrade_session_changed";
|
|
3435
3441
|
}
|
|
3436
|
-
},
|
|
3442
|
+
}, lr = (e) => {
|
|
3437
3443
|
if (e && typeof e.sub == "string" && e.sub !== "") return typeof e.sid == "string" && e.sid !== "" ? {
|
|
3438
3444
|
sub: e.sub,
|
|
3439
3445
|
sid: e.sid
|
|
3440
3446
|
} : { sub: e.sub };
|
|
3441
|
-
},
|
|
3447
|
+
}, ur = (e, t) => !t || t.sub !== e.sub ? !1 : e.sid !== void 0 && t.sid !== void 0 ? e.sid === t.sid : !0;
|
|
3442
3448
|
// lib/utils/validation.ts
|
|
3443
|
-
function
|
|
3449
|
+
function dr(e) {
|
|
3444
3450
|
if (!e || typeof e != "string") return !1;
|
|
3445
3451
|
let t = e.split(".");
|
|
3446
3452
|
if (t.length !== 3) return !1;
|
|
3447
3453
|
let n = /^[A-Za-z0-9_-]+$/;
|
|
3448
3454
|
return t.every((e) => n.test(e) && e.length > 0);
|
|
3449
3455
|
}
|
|
3450
|
-
function
|
|
3456
|
+
function fr(e) {
|
|
3451
3457
|
return e.replace(/<[^>]*>/g, "").substring(0, 200);
|
|
3452
3458
|
}
|
|
3453
|
-
function
|
|
3459
|
+
function pr(e) {
|
|
3454
3460
|
if (!e || typeof e != "string") return !1;
|
|
3455
3461
|
let t = e.trim();
|
|
3456
3462
|
return t.length !== 0 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);
|
|
3457
3463
|
}
|
|
3458
|
-
function
|
|
3464
|
+
function mr(e) {
|
|
3459
3465
|
if (!e || typeof e != "string") return !1;
|
|
3460
3466
|
let t = e.trim();
|
|
3461
3467
|
return /^\+[1-9]\d{1,14}$/.test(t);
|
|
3462
3468
|
}
|
|
3463
|
-
function
|
|
3469
|
+
function hr(e) {
|
|
3464
3470
|
if (!e || typeof e != "string") return !1;
|
|
3465
3471
|
let t = e.trim();
|
|
3466
3472
|
return t.length < 3 || t.length > 30 ? !1 : /^[a-zA-Z0-9_-]+$/.test(t);
|
|
3467
3473
|
}
|
|
3468
|
-
function
|
|
3474
|
+
function gr(e, t = 6) {
|
|
3469
3475
|
return !e || typeof e != "string" ? !1 : (t === 8 ? /^\d{8}$/ : /^\d{6}$/).test(e);
|
|
3470
3476
|
}
|
|
3471
|
-
function
|
|
3477
|
+
function _r(e) {
|
|
3472
3478
|
if (!e || typeof e != "string") return null;
|
|
3473
3479
|
let t = e.toUpperCase().replace(/\s+/g, "");
|
|
3474
3480
|
return /^[A-Z0-9-]{4,16}$/.test(t) ? t : null;
|
|
3475
3481
|
}
|
|
3476
3482
|
// lib/services/auth-service.ts
|
|
3477
|
-
var
|
|
3478
|
-
|
|
3479
|
-
|
|
3483
|
+
var vr = "passflow_2fa_pkce", yr = 3e5, br = 10, xr = "The sign-in answered with a PKCE code, but its verifier is gone", Sr = (e) => {
|
|
3484
|
+
if (!e) return;
|
|
3485
|
+
let t = new URLSearchParams(e.search).get("token");
|
|
3486
|
+
if (t) return t;
|
|
3487
|
+
let n = e.hash.indexOf("?");
|
|
3488
|
+
return n < 0 ? void 0 : new URLSearchParams(e.hash.slice(n + 1)).get("token") ?? void 0;
|
|
3489
|
+
}, Cr = (e) => {
|
|
3490
|
+
if (e) try {
|
|
3491
|
+
return A(e).email;
|
|
3492
|
+
} catch {
|
|
3493
|
+
return;
|
|
3494
|
+
}
|
|
3495
|
+
}, wr = class {
|
|
3496
|
+
constructor(e, t, n, r, i, a, o, s, c, l, u, d = P, f, p = { coordination: rn() }) {
|
|
3497
|
+
this.authApi = e, this.deviceService = t, this.storageManager = n, this.subscribeStore = r, this.tokenCacheService = i, this.scopes = a, this.createTenantForNewUser = o, this.url = s, this.sessionCallbacks = c, this.appId = l, this.platform = d, this.readPkceEnabled = f, this.emailChallenges = /* @__PURE__ */ new Map(), this.tokenExchangeConfig = u, this.tokenDeliveryManager = new ne(n), u?.enabled && this.tokenDeliveryManager.setMode(M.BFF), this.refresh = Wn({
|
|
3480
3498
|
emit: this.createRefreshEmit(),
|
|
3481
3499
|
storage: n,
|
|
3482
3500
|
cache: i,
|
|
@@ -3484,7 +3502,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3484
3502
|
coordination: p.coordination,
|
|
3485
3503
|
platform: d,
|
|
3486
3504
|
...p.strikes === void 0 ? {} : { strikes: p.strikes },
|
|
3487
|
-
logger:
|
|
3505
|
+
logger: pn()
|
|
3488
3506
|
}), this.initializeSession();
|
|
3489
3507
|
}
|
|
3490
3508
|
async initializeSession() {
|
|
@@ -3522,18 +3540,39 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3522
3540
|
tfaToken: e.tfa_token || ""
|
|
3523
3541
|
}), !0);
|
|
3524
3542
|
}
|
|
3543
|
+
handleEmailVerificationStep(e, t, n, r, i) {
|
|
3544
|
+
if (!Ae(e)) return !1;
|
|
3545
|
+
let a = e.challenge_id || void 0;
|
|
3546
|
+
return a && r ? this.rememberPkceSignIn(r.verifier, i) : this.forgetPkceSignIn(), a && this.rememberEmailChallenge(a, {
|
|
3547
|
+
operation: t,
|
|
3548
|
+
email: n,
|
|
3549
|
+
scopes: i,
|
|
3550
|
+
pkce: r !== void 0
|
|
3551
|
+
}), this.subscribeStore.notify(Z.EmailVerificationRequired, {
|
|
3552
|
+
email: n,
|
|
3553
|
+
challengeId: a,
|
|
3554
|
+
operation: t
|
|
3555
|
+
}), !0;
|
|
3556
|
+
}
|
|
3557
|
+
rememberEmailChallenge(e, t) {
|
|
3558
|
+
this.emailChallenges.delete(e), this.emailChallenges.set(e, t);
|
|
3559
|
+
for (let e of this.emailChallenges.keys()) {
|
|
3560
|
+
if (this.emailChallenges.size <= br) break;
|
|
3561
|
+
this.emailChallenges.delete(e);
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3525
3564
|
rememberPkceSignIn(e, t) {
|
|
3526
3565
|
if (this.pendingPkce = {
|
|
3527
3566
|
verifier: e,
|
|
3528
3567
|
scopes: t,
|
|
3529
|
-
expiresAt: Date.now() +
|
|
3568
|
+
expiresAt: Date.now() + yr
|
|
3530
3569
|
}, typeof sessionStorage < "u") try {
|
|
3531
|
-
sessionStorage.setItem(
|
|
3570
|
+
sessionStorage.setItem(vr, JSON.stringify(this.pendingPkce));
|
|
3532
3571
|
} catch {}
|
|
3533
3572
|
}
|
|
3534
3573
|
readPendingPkce() {
|
|
3535
3574
|
if (!this.pendingPkce && typeof sessionStorage < "u") try {
|
|
3536
|
-
let e = sessionStorage.getItem(
|
|
3575
|
+
let e = sessionStorage.getItem(vr);
|
|
3537
3576
|
this.pendingPkce = e ? JSON.parse(e) : void 0;
|
|
3538
3577
|
} catch {
|
|
3539
3578
|
this.pendingPkce = void 0;
|
|
@@ -3545,7 +3584,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3545
3584
|
}
|
|
3546
3585
|
forgetPkceSignIn() {
|
|
3547
3586
|
if (this.pendingPkce = void 0, typeof sessionStorage < "u") try {
|
|
3548
|
-
sessionStorage.removeItem(
|
|
3587
|
+
sessionStorage.removeItem(vr);
|
|
3549
3588
|
} catch {}
|
|
3550
3589
|
}
|
|
3551
3590
|
async startPkce() {
|
|
@@ -3553,17 +3592,17 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3553
3592
|
try {
|
|
3554
3593
|
e = await this.readPkceEnabled?.() ?? !1;
|
|
3555
3594
|
} catch (e) {
|
|
3556
|
-
|
|
3595
|
+
pn().warn("Passflow: could not read the app settings, so this sign-in sends no PKCE challenge", e);
|
|
3557
3596
|
return;
|
|
3558
3597
|
}
|
|
3559
|
-
return e ?
|
|
3598
|
+
return e ? dn() : void 0;
|
|
3560
3599
|
}
|
|
3561
3600
|
async exchangeCode(e, t) {
|
|
3562
3601
|
return !e.code || !t ? e : await this.authApi.pkceExchange(e.code, t.verifier);
|
|
3563
3602
|
}
|
|
3564
3603
|
async completePkceSignIn(e) {
|
|
3565
3604
|
let t = this.readPendingPkce();
|
|
3566
|
-
if (!t) throw Error(
|
|
3605
|
+
if (!t) throw Error(xr);
|
|
3567
3606
|
let n = await this.authApi.pkceExchange(e, t.verifier);
|
|
3568
3607
|
return await this.processAuthResponse(n, t.scopes ?? this.scopes), n;
|
|
3569
3608
|
}
|
|
@@ -3587,7 +3626,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3587
3626
|
if (!t.ok) throw Error(`BFF token storage failed: ${t.status}`);
|
|
3588
3627
|
}
|
|
3589
3628
|
async signIn(e) {
|
|
3590
|
-
if ("email" in e && e.email && !
|
|
3629
|
+
if ("email" in e && e.email && !pr(e.email)) {
|
|
3591
3630
|
let e = /* @__PURE__ */ Error("Invalid email format"), t = {
|
|
3592
3631
|
operation: "sign-in",
|
|
3593
3632
|
message: "Invalid email format",
|
|
@@ -3596,7 +3635,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3596
3635
|
};
|
|
3597
3636
|
throw U(this.subscribeStore, t), e;
|
|
3598
3637
|
}
|
|
3599
|
-
if ("username" in e && e.username && !
|
|
3638
|
+
if ("username" in e && e.username && !hr(e.username)) {
|
|
3600
3639
|
let e = /* @__PURE__ */ Error("Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"), t = {
|
|
3601
3640
|
operation: "sign-in",
|
|
3602
3641
|
message: "Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens",
|
|
@@ -3605,7 +3644,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3605
3644
|
};
|
|
3606
3645
|
throw U(this.subscribeStore, t), e;
|
|
3607
3646
|
}
|
|
3608
|
-
if ("phone" in e && e.phone && !
|
|
3647
|
+
if ("phone" in e && e.phone && !mr(e.phone)) {
|
|
3609
3648
|
let e = /* @__PURE__ */ Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), t = {
|
|
3610
3649
|
operation: "sign-in",
|
|
3611
3650
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
@@ -3615,14 +3654,14 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3615
3654
|
throw U(this.subscribeStore, t), e;
|
|
3616
3655
|
}
|
|
3617
3656
|
this.subscribeStore.notify(Z.SignInStart, { email: e.email });
|
|
3618
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
3657
|
+
let t = this.deviceService.getDeviceId(), n = Ne(this.platform.getDeviceType());
|
|
3619
3658
|
e.scopes = e.scopes ?? this.scopes;
|
|
3620
3659
|
try {
|
|
3621
3660
|
let r = await this.startPkce(), i = await this.authApi.signIn(r ? {
|
|
3622
3661
|
...e,
|
|
3623
3662
|
code_challenge: r.challenge
|
|
3624
3663
|
} : e, t, n);
|
|
3625
|
-
if (this.handlePendingSecondFactor(i, e.email, r, e.scopes)) return i;
|
|
3664
|
+
if (this.handleEmailVerificationStep(i, "sign-in", e.email, r, e.scopes) || this.handlePendingSecondFactor(i, e.email, r, e.scopes)) return i;
|
|
3626
3665
|
let a = await this.exchangeCode(i, r);
|
|
3627
3666
|
return this.handlePendingSecondFactor(a, e.email) || (await this.processAuthResponse(a, e.scopes), this.subscribeStore.notify(Z.SignIn, {
|
|
3628
3667
|
tokens: a,
|
|
@@ -3639,7 +3678,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3639
3678
|
}
|
|
3640
3679
|
}
|
|
3641
3680
|
async signUp(e) {
|
|
3642
|
-
if (e.user.email && !
|
|
3681
|
+
if (e.user.email && !pr(e.user.email)) {
|
|
3643
3682
|
let e = /* @__PURE__ */ Error("Invalid email format"), t = {
|
|
3644
3683
|
operation: "sign-up",
|
|
3645
3684
|
message: "Invalid email format",
|
|
@@ -3648,7 +3687,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3648
3687
|
};
|
|
3649
3688
|
throw U(this.subscribeStore, t), e;
|
|
3650
3689
|
}
|
|
3651
|
-
if (e.user.phone_number && !
|
|
3690
|
+
if (e.user.phone_number && !mr(e.user.phone_number)) {
|
|
3652
3691
|
let e = /* @__PURE__ */ Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), t = {
|
|
3653
3692
|
operation: "sign-up",
|
|
3654
3693
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
@@ -3663,7 +3702,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3663
3702
|
...e,
|
|
3664
3703
|
code_challenge: t.challenge
|
|
3665
3704
|
} : e);
|
|
3666
|
-
if (this.handlePendingSecondFactor(n, e.user.email, t, e.scopes)) return n;
|
|
3705
|
+
if (this.handleEmailVerificationStep(n, "sign-up", e.user.email, t, e.scopes) || this.handlePendingSecondFactor(n, e.user.email, t, e.scopes)) return n;
|
|
3667
3706
|
let r = await this.exchangeCode(n, t);
|
|
3668
3707
|
return this.handlePendingSecondFactor(r, e.user.email) || (await this.processAuthResponse(r, e.scopes), this.subscribeStore.notify(Z.Register, {
|
|
3669
3708
|
tokens: r,
|
|
@@ -3680,7 +3719,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3680
3719
|
}
|
|
3681
3720
|
}
|
|
3682
3721
|
async passwordlessSignIn(e) {
|
|
3683
|
-
if (e.email && !
|
|
3722
|
+
if (e.email && !pr(e.email)) {
|
|
3684
3723
|
let e = /* @__PURE__ */ Error("Invalid email format"), t = {
|
|
3685
3724
|
operation: "passwordless.start",
|
|
3686
3725
|
message: "Invalid email format",
|
|
@@ -3689,7 +3728,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3689
3728
|
};
|
|
3690
3729
|
throw U(this.subscribeStore, t), e;
|
|
3691
3730
|
}
|
|
3692
|
-
if (e.phone && !
|
|
3731
|
+
if (e.phone && !mr(e.phone)) {
|
|
3693
3732
|
let e = /* @__PURE__ */ Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), t = {
|
|
3694
3733
|
operation: "passwordless.start",
|
|
3695
3734
|
message: "Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)",
|
|
@@ -3699,7 +3738,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3699
3738
|
throw U(this.subscribeStore, t), e;
|
|
3700
3739
|
}
|
|
3701
3740
|
this.subscribeStore.notify(Z.SignInStart, { email: e.email }), e.scopes = e.scopes ?? this.scopes;
|
|
3702
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
3741
|
+
let t = this.deviceService.getDeviceId(), n = Ne(this.platform.getDeviceType());
|
|
3703
3742
|
try {
|
|
3704
3743
|
return await this.authApi.passwordlessSignIn(e, t, n);
|
|
3705
3744
|
} catch (e) {
|
|
@@ -3730,15 +3769,49 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3730
3769
|
throw U(this.subscribeStore, t), e;
|
|
3731
3770
|
}
|
|
3732
3771
|
}
|
|
3772
|
+
async verifyEmailCode(e) {
|
|
3773
|
+
let t = this.emailChallenges.get(e.challenge_id), n = t?.email;
|
|
3774
|
+
try {
|
|
3775
|
+
let r = t?.pkce === !1 ? void 0 : this.readPendingPkce();
|
|
3776
|
+
if (t?.pkce && !r) throw Error(xr);
|
|
3777
|
+
let i = await this.authApi.validateEmailCode(e);
|
|
3778
|
+
this.emailChallenges.delete(e.challenge_id);
|
|
3779
|
+
let a = r?.scopes ?? t?.scopes ?? this.scopes;
|
|
3780
|
+
if (this.handleEmailVerificationStep(i, t?.operation ?? "sign-in", n, r, a) || this.handlePendingSecondFactor(i, n, r, a)) return i;
|
|
3781
|
+
let o = i;
|
|
3782
|
+
if (i.code) {
|
|
3783
|
+
if (!r) throw Error(xr);
|
|
3784
|
+
if (o = await this.authApi.pkceExchange(i.code, r.verifier), this.handlePendingSecondFactor(o, n)) return o;
|
|
3785
|
+
}
|
|
3786
|
+
let s = i.redirect_url ? {
|
|
3787
|
+
...o,
|
|
3788
|
+
redirect_url: i.redirect_url
|
|
3789
|
+
} : o;
|
|
3790
|
+
return await this.processAuthResponse(s, a), this.forgetPkceSignIn(), this.subscribeStore.notify(t?.operation === "sign-up" ? Z.Register : Z.SignIn, {
|
|
3791
|
+
tokens: s,
|
|
3792
|
+
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
3793
|
+
}), await this.submitSessionCheck(), s;
|
|
3794
|
+
} catch (e) {
|
|
3795
|
+
let t = {
|
|
3796
|
+
operation: "email-verification.complete",
|
|
3797
|
+
message: e instanceof Error ? e.message : "Email verification failed",
|
|
3798
|
+
originalError: e,
|
|
3799
|
+
code: e instanceof B ? e.id : void 0
|
|
3800
|
+
};
|
|
3801
|
+
throw U(this.subscribeStore, t), e;
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3733
3804
|
async logOut() {
|
|
3734
3805
|
let e = this.refresh.identity();
|
|
3735
3806
|
return await this.refresh.signOut(async (e) => {
|
|
3736
|
-
await this.callLogoutApi(e), this.forgetPkceSignIn(), this.clearLocalSession();
|
|
3807
|
+
await this.callLogoutApi(e), this.forgetPkceSignIn(), this.emailChallenges.clear(), this.clearLocalSession();
|
|
3737
3808
|
}), e;
|
|
3738
3809
|
}
|
|
3739
3810
|
resetSession() {
|
|
3740
3811
|
let e = this.refresh.identity();
|
|
3741
|
-
return this.refresh.signOutNow(() =>
|
|
3812
|
+
return this.refresh.signOutNow(() => {
|
|
3813
|
+
this.emailChallenges.clear(), this.clearLocalSession();
|
|
3814
|
+
}), e;
|
|
3742
3815
|
}
|
|
3743
3816
|
async callLogoutApi(e) {
|
|
3744
3817
|
if (this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.logoutUrl) {
|
|
@@ -3761,13 +3834,13 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3761
3834
|
readSessionPin() {
|
|
3762
3835
|
try {
|
|
3763
3836
|
let e = this.storageManager.getToken(j.access_token);
|
|
3764
|
-
return e ?
|
|
3837
|
+
return e ? lr(A(e)) : void 0;
|
|
3765
3838
|
} catch {
|
|
3766
3839
|
return;
|
|
3767
3840
|
}
|
|
3768
3841
|
}
|
|
3769
3842
|
assertSessionPin(e) {
|
|
3770
|
-
if (e && !
|
|
3843
|
+
if (e && !ur(e, this.readSessionPin())) throw console.warn("[passflow] the session or user changed while a step-up upgrade was in flight; the elevated tokens were discarded and the live session was left untouched."), new cr("The session changed during verification, so the elevated tokens were discarded");
|
|
3771
3844
|
}
|
|
3772
3845
|
refreshMode() {
|
|
3773
3846
|
return this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.refreshUrl ? "bff" : this.tokenDeliveryManager.isCookieMode() ? "cookie" : "json";
|
|
@@ -3815,7 +3888,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3815
3888
|
case "signout":
|
|
3816
3889
|
n.notify(Z.SignOut, t);
|
|
3817
3890
|
return;
|
|
3818
|
-
default:
|
|
3891
|
+
default: pn().warn(`[passflow] Unknown refresh event: ${String(e)}`);
|
|
3819
3892
|
}
|
|
3820
3893
|
};
|
|
3821
3894
|
}
|
|
@@ -3899,19 +3972,19 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3899
3972
|
throw U(this.subscribeStore, t), e;
|
|
3900
3973
|
}
|
|
3901
3974
|
}
|
|
3902
|
-
async resetPassword(e, t) {
|
|
3975
|
+
async resetPassword(e, t, n) {
|
|
3903
3976
|
this.subscribeStore.notify(Z.SignInStart, {});
|
|
3904
|
-
let
|
|
3977
|
+
let r = n ?? Sr(this.platform.getCurrentUrl()), i = t ?? this.scopes;
|
|
3905
3978
|
try {
|
|
3906
|
-
let t = await this.startPkce(),
|
|
3907
|
-
if (this.handlePendingSecondFactor(
|
|
3908
|
-
let a = await this.exchangeCode(
|
|
3979
|
+
let t = await this.startPkce(), n = t ? await this.authApi.resetPassword(e, i, r, t.challenge) : await this.authApi.resetPassword(e, i, r);
|
|
3980
|
+
if (this.handleEmailVerificationStep(n, "reset-password", Cr(r), t, i) || this.handlePendingSecondFactor(n, void 0, t, i)) return n;
|
|
3981
|
+
let a = await this.exchangeCode(n, t);
|
|
3909
3982
|
if (this.handlePendingSecondFactor(a)) return a;
|
|
3910
|
-
let o =
|
|
3983
|
+
let o = n.redirect_url ? {
|
|
3911
3984
|
...a,
|
|
3912
|
-
redirect_url:
|
|
3985
|
+
redirect_url: n.redirect_url
|
|
3913
3986
|
} : a;
|
|
3914
|
-
return await this.processAuthResponse(o,
|
|
3987
|
+
return await this.processAuthResponse(o, i), this.subscribeStore.notify(Z.SignIn, {
|
|
3915
3988
|
tokens: o,
|
|
3916
3989
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
3917
3990
|
}), await this.submitSessionCheck(), o;
|
|
@@ -3928,7 +4001,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3928
4001
|
async passkeyRegister(e) {
|
|
3929
4002
|
if (!this.platform.passkeys) throw Error("Passkeys are not supported on this platform");
|
|
3930
4003
|
this.subscribeStore.notify(Z.RegisterStart, {});
|
|
3931
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
4004
|
+
let t = this.deviceService.getDeviceId(), n = Ne(this.platform.getDeviceType());
|
|
3932
4005
|
e.scopes = e.scopes ?? this.scopes, e.create_tenant = this.createTenantForNewUser;
|
|
3933
4006
|
try {
|
|
3934
4007
|
let r = await this.startPkce(), { challenge_id: i, publicKey: a } = await this.authApi.passkeyRegisterStart(r ? {
|
|
@@ -3958,7 +4031,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
3958
4031
|
async passkeyAuthenticate(e) {
|
|
3959
4032
|
if (!this.platform.passkeys) throw Error("Passkeys are not supported on this platform");
|
|
3960
4033
|
this.subscribeStore.notify(Z.SignInStart, {});
|
|
3961
|
-
let t = this.deviceService.getDeviceId(), n =
|
|
4034
|
+
let t = this.deviceService.getDeviceId(), n = Ne(this.platform.getDeviceType());
|
|
3962
4035
|
e.scopes = e.scopes ?? this.scopes;
|
|
3963
4036
|
try {
|
|
3964
4037
|
let r = await this.startPkce(), { challenge_id: i, publicKey: a } = await this.authApi.passkeyAuthenticateStart(r ? {
|
|
@@ -4126,7 +4199,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4126
4199
|
return;
|
|
4127
4200
|
}
|
|
4128
4201
|
}
|
|
4129
|
-
},
|
|
4202
|
+
}, Tr = class {
|
|
4130
4203
|
constructor(e) {
|
|
4131
4204
|
this.invitationApi = e;
|
|
4132
4205
|
}
|
|
@@ -4145,7 +4218,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4145
4218
|
getInvitationLink(e) {
|
|
4146
4219
|
return this.invitationApi.getInvitationLink(e);
|
|
4147
4220
|
}
|
|
4148
|
-
},
|
|
4221
|
+
}, Er = class {
|
|
4149
4222
|
constructor(e) {
|
|
4150
4223
|
this.data = this.normalize(e);
|
|
4151
4224
|
}
|
|
@@ -4202,9 +4275,9 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4202
4275
|
getData() {
|
|
4203
4276
|
return this.data;
|
|
4204
4277
|
}
|
|
4205
|
-
},
|
|
4278
|
+
}, Dr = class {
|
|
4206
4279
|
constructor(e, t, n) {
|
|
4207
|
-
this.tenantApi = e, this.scopes = t, this.logger = n ||
|
|
4280
|
+
this.tenantApi = e, this.scopes = t, this.logger = n || pn();
|
|
4208
4281
|
}
|
|
4209
4282
|
handlePassflowError(t, n) {
|
|
4210
4283
|
if (e.isAxiosError(t) && t.response?.data) {
|
|
@@ -4240,7 +4313,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4240
4313
|
}
|
|
4241
4314
|
async getTenantUserMembership(e) {
|
|
4242
4315
|
try {
|
|
4243
|
-
return new
|
|
4316
|
+
return new Er(await this.tenantApi.getTenantDetails(e));
|
|
4244
4317
|
} catch (t) {
|
|
4245
4318
|
this.handlePassflowError(t, `Get tenant user membership failed for tenant ID ${e}`);
|
|
4246
4319
|
}
|
|
@@ -4385,7 +4458,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4385
4458
|
this.handlePassflowError(r, `Invalidate invite by email failed for tenant ID ${e}, group ID ${t}, email ${n}`);
|
|
4386
4459
|
}
|
|
4387
4460
|
}
|
|
4388
|
-
},
|
|
4461
|
+
}, Or = class {
|
|
4389
4462
|
constructor(e, t, n, r = P) {
|
|
4390
4463
|
this.storageManager = e, this.subscribeStore = n, this.platform = r, this.checkInterval = null, this.CHECK_INTERVAL = 6e4, this.unsubscribeForeground = null, this.unsubscribeUnload = null, this.tokenExpiredFlag = !1, this.storageManager = e, this.setupLifecycleListeners();
|
|
4391
4464
|
}
|
|
@@ -4465,7 +4538,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4465
4538
|
isExpired() {
|
|
4466
4539
|
return this.tokensCache ? this.tokensCache.access_token ? k(A(this.tokensCache.access_token)) : !1 : !0;
|
|
4467
4540
|
}
|
|
4468
|
-
},
|
|
4541
|
+
}, kr = class {
|
|
4469
4542
|
constructor(e, t, n) {
|
|
4470
4543
|
this.twoFactorApi = e, this.subscribeStore = t, this.signInCompleter = n, this.PARTIAL_AUTH_TIMEOUT_MS = 3e5, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6, this.subscribeStore.subscribe({ onAuthChange: (e, t) => {
|
|
4471
4544
|
if (e === Z.TwoFactorRequired) {
|
|
@@ -4505,7 +4578,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4505
4578
|
}
|
|
4506
4579
|
}
|
|
4507
4580
|
async confirmSetup(e) {
|
|
4508
|
-
if (!
|
|
4581
|
+
if (!gr(e, this.totpDigits)) throw Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
4509
4582
|
try {
|
|
4510
4583
|
let t = await this.twoFactorApi.confirmSetup({ code: e });
|
|
4511
4584
|
return this.subscribeStore.notify(Z.TwoFactorEnabled, {
|
|
@@ -4519,7 +4592,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4519
4592
|
}
|
|
4520
4593
|
}
|
|
4521
4594
|
async verify(e, t) {
|
|
4522
|
-
if (!
|
|
4595
|
+
if (!gr(e, this.totpDigits)) throw Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
4523
4596
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired()) throw Error("2FA verification expired or not required. User must sign in first.");
|
|
4524
4597
|
if (!this.partialAuthState?.tfaToken) throw Error("No TFA token found. User must sign in first.");
|
|
4525
4598
|
try {
|
|
@@ -4535,7 +4608,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4535
4608
|
}
|
|
4536
4609
|
async useRecoveryCode(e, t) {
|
|
4537
4610
|
try {
|
|
4538
|
-
let n =
|
|
4611
|
+
let n = _r(e);
|
|
4539
4612
|
if (!n) throw Error("Invalid recovery code format. Expected format: XXXX-XXXX or XXXXXXXX (alphanumeric).");
|
|
4540
4613
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired()) throw Error("2FA verification expired or not required. User must sign in first.");
|
|
4541
4614
|
if (!this.partialAuthState?.tfaToken) throw Error("No TFA token found. User must sign in first.");
|
|
@@ -4556,7 +4629,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4556
4629
|
}
|
|
4557
4630
|
}
|
|
4558
4631
|
async disable(e) {
|
|
4559
|
-
if (!
|
|
4632
|
+
if (!gr(e, this.totpDigits)) throw Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
4560
4633
|
try {
|
|
4561
4634
|
let t = await this.twoFactorApi.disable({ code: e });
|
|
4562
4635
|
return this.subscribeStore.notify(Z.TwoFactorDisabled, {}), t;
|
|
@@ -4565,7 +4638,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4565
4638
|
}
|
|
4566
4639
|
}
|
|
4567
4640
|
async regenerateRecoveryCodes(e) {
|
|
4568
|
-
if (!
|
|
4641
|
+
if (!gr(e, this.totpDigits)) throw Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
4569
4642
|
try {
|
|
4570
4643
|
let t = await this.twoFactorApi.regenerateRecoveryCodes({ code: e }), n = [...t.recovery_codes];
|
|
4571
4644
|
return t.recovery_codes = [], t.recovery_codes = n, t;
|
|
@@ -4749,7 +4822,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4749
4822
|
this.emitErrorAndThrow(e, "2fa.trusted-devices.revoke", "Revoke trusted device");
|
|
4750
4823
|
}
|
|
4751
4824
|
}
|
|
4752
|
-
},
|
|
4825
|
+
}, Ar = class {
|
|
4753
4826
|
constructor(e, t, n = P) {
|
|
4754
4827
|
this.userAPI = e, this.deviceService = t, this.platform = n;
|
|
4755
4828
|
}
|
|
@@ -4764,7 +4837,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4764
4837
|
}
|
|
4765
4838
|
async addUserPasskey({ relyingPartyId: e, passkeyUsername: t, passkeyDisplayName: n } = {}) {
|
|
4766
4839
|
if (!this.platform.passkeys) throw Error("Passkeys are not supported on this platform");
|
|
4767
|
-
let r = this.deviceService.getDeviceId(), i =
|
|
4840
|
+
let r = this.deviceService.getDeviceId(), i = Ne(this.platform.getDeviceType()), { challenge_id: a, publicKey: o } = await this.userAPI.addUserPasskeyStart({
|
|
4768
4841
|
relyingPartyId: (e || this.platform.getCurrentUrl()?.hostname) ?? "",
|
|
4769
4842
|
deviceId: r,
|
|
4770
4843
|
os: i,
|
|
@@ -4776,69 +4849,69 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4776
4849
|
if (!s) throw Error("Passkey registration was not completed");
|
|
4777
4850
|
return await this.userAPI.addUserPasskeyComplete(s, r, a);
|
|
4778
4851
|
}
|
|
4779
|
-
},
|
|
4852
|
+
}, jr = class extends Error {
|
|
4780
4853
|
constructor(e, t, n = !1) {
|
|
4781
4854
|
super(t), this.name = "UpgradeFactorError", this.factor = e, this.cancelled = n;
|
|
4782
4855
|
}
|
|
4783
|
-
},
|
|
4856
|
+
}, Mr = (e, t) => {
|
|
4784
4857
|
let n = t?.trim();
|
|
4785
|
-
if (!n) throw new
|
|
4858
|
+
if (!n) throw new jr(e, "A verification code is required");
|
|
4786
4859
|
return n;
|
|
4787
|
-
},
|
|
4860
|
+
}, Nr = {
|
|
4788
4861
|
type: "totp",
|
|
4789
4862
|
requiresPrepare: !1,
|
|
4790
4863
|
input: "code",
|
|
4791
|
-
assert: async ({ code: e }) => ({ code:
|
|
4792
|
-
},
|
|
4864
|
+
assert: async ({ code: e }) => ({ code: Mr("totp", e) })
|
|
4865
|
+
}, Pr = {
|
|
4793
4866
|
type: "recovery_codes",
|
|
4794
4867
|
requiresPrepare: !1,
|
|
4795
4868
|
input: "code",
|
|
4796
|
-
assert: async ({ code: e }) => ({ code:
|
|
4797
|
-
},
|
|
4869
|
+
assert: async ({ code: e }) => ({ code: Mr("recovery_codes", e) })
|
|
4870
|
+
}, Fr = {
|
|
4798
4871
|
type: "passkey",
|
|
4799
4872
|
requiresPrepare: !0,
|
|
4800
4873
|
input: "none",
|
|
4801
4874
|
assert: async ({ prepared: e, platform: t }) => {
|
|
4802
|
-
if (!e?.webauthn) throw new
|
|
4875
|
+
if (!e?.webauthn) throw new jr("passkey", "The upgrade challenge carried no WebAuthn options");
|
|
4803
4876
|
let n = t.passkeys;
|
|
4804
|
-
if (!n) throw new
|
|
4877
|
+
if (!n) throw new jr("passkey", "This platform does not support passkeys");
|
|
4805
4878
|
let r;
|
|
4806
4879
|
try {
|
|
4807
4880
|
r = await n.startAuthentication(e.webauthn);
|
|
4808
4881
|
} catch (e) {
|
|
4809
|
-
throw new
|
|
4882
|
+
throw new jr("passkey", e?.message || "Passkey verification was cancelled", !0);
|
|
4810
4883
|
}
|
|
4811
|
-
if (!r) throw new
|
|
4884
|
+
if (!r) throw new jr("passkey", "Passkey verification was cancelled", !0);
|
|
4812
4885
|
return {
|
|
4813
4886
|
challenge_id: e.challengeId,
|
|
4814
4887
|
credential: r
|
|
4815
4888
|
};
|
|
4816
4889
|
}
|
|
4817
|
-
},
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
]),
|
|
4890
|
+
}, Ir = Object.freeze([
|
|
4891
|
+
Nr,
|
|
4892
|
+
Fr,
|
|
4893
|
+
Pr
|
|
4894
|
+
]), Lr = (e = Ir) => new Map(e.map((e) => [e.type, e])), Rr = 3, zr = {
|
|
4822
4895
|
passkey: 0,
|
|
4823
4896
|
totp: 1,
|
|
4824
4897
|
email_otp: 2,
|
|
4825
4898
|
sms_otp: 3,
|
|
4826
4899
|
recovery_codes: 9
|
|
4827
|
-
},
|
|
4828
|
-
let n =
|
|
4900
|
+
}, Br = (e) => e.requiredLevel ?? L(e.acrValues), Vr = (e, t) => {
|
|
4901
|
+
let n = zr[e.type] ?? 5, r = t !== void 0 && t >= Rr, i = e.type === "passkey";
|
|
4829
4902
|
return (r && !i ? 100 : 0) + n;
|
|
4830
|
-
},
|
|
4831
|
-
let n =
|
|
4832
|
-
return [...e].sort((e, t) =>
|
|
4833
|
-
},
|
|
4903
|
+
}, Hr = (e, t) => {
|
|
4904
|
+
let n = Br(t);
|
|
4905
|
+
return [...e].sort((e, t) => Vr(e, n) - Vr(t, n));
|
|
4906
|
+
}, Ur = class extends Error {
|
|
4834
4907
|
constructor(e) {
|
|
4835
4908
|
super("Upgrade authentication was cancelled"), this.code = "upgrade_cancelled", this.name = "UpgradeCancelledError", e !== void 0 && (this.cause = e);
|
|
4836
4909
|
}
|
|
4837
|
-
},
|
|
4910
|
+
}, Wr = class extends Error {
|
|
4838
4911
|
constructor(e = "No available authentication factor can satisfy this challenge") {
|
|
4839
4912
|
super(e), this.code = "upgrade_unsatisfiable", this.name = "UpgradeUnsatisfiableError";
|
|
4840
4913
|
}
|
|
4841
|
-
},
|
|
4914
|
+
}, Gr = 4, Kr = 3e4, qr = () => {
|
|
4842
4915
|
let e = () => void 0, t = () => void 0;
|
|
4843
4916
|
return {
|
|
4844
4917
|
promise: new Promise((n, r) => {
|
|
@@ -4847,11 +4920,11 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4847
4920
|
resolve: e,
|
|
4848
4921
|
reject: t
|
|
4849
4922
|
};
|
|
4850
|
-
},
|
|
4923
|
+
}, Jr = (e) => ({
|
|
4851
4924
|
acrValues: e.acrValues,
|
|
4852
4925
|
level: e.requiredLevel,
|
|
4853
4926
|
maxAge: e.maxAge
|
|
4854
|
-
}),
|
|
4927
|
+
}), Yr = (e, t) => t.level === void 0 || e.level !== void 0 && e.level >= t.level, Xr = (e, t) => {
|
|
4855
4928
|
let n = e.requiredLevel === void 0 ? t.requiredLevel : t.requiredLevel === void 0 ? e.requiredLevel : Math.max(e.requiredLevel, t.requiredLevel), r = n === void 0 ? e.acrValues ?? t.acrValues : n === e.requiredLevel ? e.acrValues : t.acrValues, i = e.maxAge === void 0 ? t.maxAge : t.maxAge === void 0 ? e.maxAge : Math.min(e.maxAge, t.maxAge), a = Array.from(/* @__PURE__ */ new Set([...e.channels ?? [], ...t.channels ?? []]));
|
|
4856
4929
|
return {
|
|
4857
4930
|
acrValues: r,
|
|
@@ -4860,12 +4933,12 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4860
4933
|
status: e.status,
|
|
4861
4934
|
...a.length > 0 ? { channels: a } : {}
|
|
4862
4935
|
};
|
|
4863
|
-
},
|
|
4936
|
+
}, Zr = (e, t) => {
|
|
4864
4937
|
let n = t.requiredLevel !== void 0 && (e.requiredLevel === void 0 || t.requiredLevel > e.requiredLevel), r = t.maxAge !== void 0 && (e.maxAge === void 0 || t.maxAge < e.maxAge);
|
|
4865
4938
|
return n || r;
|
|
4866
|
-
},
|
|
4939
|
+
}, Qr = class {
|
|
4867
4940
|
constructor(e) {
|
|
4868
|
-
this.state = "idle", this.inFlight = null, this.requirement = null, this.selected = null, this.rankedRequirement = null, this.registrations = [], this.proof = null, this.pruned = /* @__PURE__ */ new Set(), this.openPrompt = null, this.transport = e.transport, this.prompt = e.prompt, this.platform = e.platform, this.available = e.factors ??
|
|
4941
|
+
this.state = "idle", this.inFlight = null, this.requirement = null, this.selected = null, this.rankedRequirement = null, this.registrations = [], this.proof = null, this.pruned = /* @__PURE__ */ new Set(), this.openPrompt = null, this.transport = e.transport, this.prompt = e.prompt, this.platform = e.platform, this.available = e.factors ?? Ir, this.registry = Lr(this.available), this.maxAttempts = e.maxAttempts ?? Gr, this.readObtainedBar = e.readObtainedBar, this.onFlightSettled = e.onFlightSettled, this.settleTimeoutMs = e.replaySettleTimeoutMs ?? Kr;
|
|
4869
4942
|
}
|
|
4870
4943
|
get currentState() {
|
|
4871
4944
|
return this.state;
|
|
@@ -4885,9 +4958,9 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4885
4958
|
}
|
|
4886
4959
|
register(e, t) {
|
|
4887
4960
|
let n = t.kind === "imperative" && t.requested !== void 0, r = {
|
|
4888
|
-
demanded: t.kind === "imperative" && t.requested ? t.requested :
|
|
4961
|
+
demanded: t.kind === "imperative" && t.requested ? t.requested : Jr(e),
|
|
4889
4962
|
statedBar: n,
|
|
4890
|
-
settlement:
|
|
4963
|
+
settlement: qr(),
|
|
4891
4964
|
reported: !1,
|
|
4892
4965
|
entry: {
|
|
4893
4966
|
...t,
|
|
@@ -4903,15 +4976,15 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4903
4976
|
this.requirement = e;
|
|
4904
4977
|
return;
|
|
4905
4978
|
}
|
|
4906
|
-
let n =
|
|
4907
|
-
this.requirement =
|
|
4979
|
+
let n = Zr(t, e);
|
|
4980
|
+
this.requirement = Xr(t, e), n && this.state === "collecting" && this.selected === null && this.openPrompt?.onRequirementRaised?.({
|
|
4908
4981
|
challenge: this.requirement,
|
|
4909
4982
|
factors: this.offeredFactors()
|
|
4910
4983
|
});
|
|
4911
4984
|
}
|
|
4912
4985
|
offeredFactors() {
|
|
4913
4986
|
let e = this.available.filter((e) => !this.pruned.has(e.type)), t = this.requirement;
|
|
4914
|
-
return t ?
|
|
4987
|
+
return t ? Hr(e, t) : e;
|
|
4915
4988
|
}
|
|
4916
4989
|
receiveReport(e, t) {
|
|
4917
4990
|
e.reported || (e.reported = !0, e.entry.outcome = t.outcome, t.obtained && (e.entry.obtained = t.obtained), t.required && (e.entry.required = t.required), this.notifyReportsSettled());
|
|
@@ -4946,12 +5019,12 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
4946
5019
|
}
|
|
4947
5020
|
release(e, t) {
|
|
4948
5021
|
if (e.entry.kind === "imperative") {
|
|
4949
|
-
if (e.statedBar && !
|
|
5022
|
+
if (e.statedBar && !Yr(t, e.demanded)) {
|
|
4950
5023
|
this.receiveReport(e, {
|
|
4951
5024
|
outcome: "insufficient",
|
|
4952
5025
|
obtained: t,
|
|
4953
5026
|
required: e.demanded
|
|
4954
|
-
}), e.settlement.reject(new
|
|
5027
|
+
}), e.settlement.reject(new or(t, e.demanded));
|
|
4955
5028
|
return;
|
|
4956
5029
|
}
|
|
4957
5030
|
this.receiveReport(e, {
|
|
@@ -5024,7 +5097,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5024
5097
|
let t = this.offeredFactors();
|
|
5025
5098
|
if (t.length === 0) return {
|
|
5026
5099
|
status: "failed",
|
|
5027
|
-
reason: new
|
|
5100
|
+
reason: new Wr()
|
|
5028
5101
|
};
|
|
5029
5102
|
let n = this.requirement, r;
|
|
5030
5103
|
try {
|
|
@@ -5032,24 +5105,24 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5032
5105
|
} catch (e) {
|
|
5033
5106
|
return {
|
|
5034
5107
|
status: "failed",
|
|
5035
|
-
reason: new
|
|
5108
|
+
reason: new Ur(e)
|
|
5036
5109
|
};
|
|
5037
5110
|
}
|
|
5038
5111
|
if (r.type === "cancel") return {
|
|
5039
5112
|
status: "failed",
|
|
5040
|
-
reason: new
|
|
5113
|
+
reason: new Ur()
|
|
5041
5114
|
};
|
|
5042
5115
|
let i = this.registry.get(r.factor);
|
|
5043
|
-
if (!i) e = new
|
|
5116
|
+
if (!i) e = new Wr(`Unknown authentication factor: ${r.factor}`), this.state = "collecting", this.selected = null;
|
|
5044
5117
|
else try {
|
|
5045
5118
|
return await this.proveAndCommit(i, r.code), {
|
|
5046
5119
|
status: "proven",
|
|
5047
|
-
obtained: this.readObtainedBar?.() ??
|
|
5120
|
+
obtained: this.readObtainedBar?.() ?? Jr(this.rankedRequirement ?? n)
|
|
5048
5121
|
};
|
|
5049
5122
|
} catch (t) {
|
|
5050
|
-
if (t instanceof
|
|
5123
|
+
if (t instanceof jr && t.cancelled) return {
|
|
5051
5124
|
status: "failed",
|
|
5052
|
-
reason: new
|
|
5125
|
+
reason: new Ur()
|
|
5053
5126
|
};
|
|
5054
5127
|
let n = this.classifyProofFailure(t);
|
|
5055
5128
|
if (n) return {
|
|
@@ -5079,15 +5152,15 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5079
5152
|
return this.openPrompt = r, this.prompt(r);
|
|
5080
5153
|
}
|
|
5081
5154
|
classifyProofFailure(e) {
|
|
5082
|
-
if (e instanceof
|
|
5155
|
+
if (e instanceof or || e instanceof sr || e instanceof cr) return e;
|
|
5083
5156
|
if (e instanceof $) switch (e.kind) {
|
|
5084
|
-
case "unavailable": return new
|
|
5157
|
+
case "unavailable": return new sr(e.message);
|
|
5085
5158
|
case "exhausted":
|
|
5086
5159
|
case "attempts_exhausted":
|
|
5087
5160
|
case "fatal":
|
|
5088
5161
|
case "protocol":
|
|
5089
5162
|
case "network": return e;
|
|
5090
|
-
case "session_changed": return new
|
|
5163
|
+
case "session_changed": return new cr(e.message);
|
|
5091
5164
|
default: return;
|
|
5092
5165
|
}
|
|
5093
5166
|
}
|
|
@@ -5099,28 +5172,28 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5099
5172
|
});
|
|
5100
5173
|
await this.transport.commit(e.type, r);
|
|
5101
5174
|
}
|
|
5102
|
-
},
|
|
5175
|
+
}, $r = (e) => typeof e == "function" ? e() : e, ei = (e) => {
|
|
5103
5176
|
try {
|
|
5104
5177
|
return new URL(e);
|
|
5105
5178
|
} catch {
|
|
5106
5179
|
return;
|
|
5107
5180
|
}
|
|
5108
|
-
},
|
|
5181
|
+
}, ti = (e, t) => {
|
|
5109
5182
|
if (!t || t === "/") return !0;
|
|
5110
5183
|
let n = t.replace(/\/+$/, "");
|
|
5111
5184
|
return e === n || e.startsWith(`${n}/`);
|
|
5112
|
-
},
|
|
5185
|
+
}, ni = (e, t) => !t || e.origin === void 0 ? !1 : e.origin === t.origin && ti(e.pathname, t.pathPrefix), ri = (e, t) => {
|
|
5113
5186
|
for (let n of t) {
|
|
5114
5187
|
if (n === "") continue;
|
|
5115
5188
|
if (n.startsWith("/")) {
|
|
5116
|
-
if (e.relativeToBase &&
|
|
5189
|
+
if (e.relativeToBase && ti(e.pathname, n)) return !0;
|
|
5117
5190
|
continue;
|
|
5118
5191
|
}
|
|
5119
|
-
let t =
|
|
5120
|
-
if (t && e.origin !== void 0 && e.origin === t.origin &&
|
|
5192
|
+
let t = ei(n) ?? ei(`https://${n}`);
|
|
5193
|
+
if (t && e.origin !== void 0 && e.origin === t.origin && ti(e.pathname, t.pathname)) return !0;
|
|
5121
5194
|
}
|
|
5122
5195
|
return !1;
|
|
5123
|
-
},
|
|
5196
|
+
}, ii = (e, t, n) => ni(e, t.passflow) || ri(e, t.backend) ? !n || n(e.href) !== !1 : !1, ai = (e) => {
|
|
5124
5197
|
let t = e.detail, n = t?.message ?? `[passflow] upgrade challenge not actioned: ${e.reason}`;
|
|
5125
5198
|
console.warn(n, {
|
|
5126
5199
|
status: e.status,
|
|
@@ -5128,8 +5201,8 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5128
5201
|
reason: e.reason,
|
|
5129
5202
|
detail: t
|
|
5130
5203
|
});
|
|
5131
|
-
},
|
|
5132
|
-
let n = t.onUpgradeDiagnostic ??
|
|
5204
|
+
}, oi = (e, t) => {
|
|
5205
|
+
let n = t.onUpgradeDiagnostic ?? ai;
|
|
5133
5206
|
return (t, r) => {
|
|
5134
5207
|
n({
|
|
5135
5208
|
status: e.status,
|
|
@@ -5141,8 +5214,8 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5141
5214
|
}
|
|
5142
5215
|
});
|
|
5143
5216
|
};
|
|
5144
|
-
},
|
|
5145
|
-
let r = n.onUpgradeDiagnostic ??
|
|
5217
|
+
}, si = (e, t, n) => {
|
|
5218
|
+
let r = n.onUpgradeDiagnostic ?? ai;
|
|
5146
5219
|
for (let n of e) r({
|
|
5147
5220
|
...n,
|
|
5148
5221
|
url: t.request.href,
|
|
@@ -5151,8 +5224,8 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5151
5224
|
...n.detail ?? {}
|
|
5152
5225
|
}
|
|
5153
5226
|
});
|
|
5154
|
-
},
|
|
5155
|
-
let n = t.requireChallengeChannel === "header", r = e.getHeader("content-type") ?? "", i = !n &&
|
|
5227
|
+
}, ci = /\bjson\b/i, li = async (e, t) => {
|
|
5228
|
+
let n = t.requireChallengeChannel === "header", r = e.getHeader("content-type") ?? "", i = !n && ci.test(r), a;
|
|
5156
5229
|
if (i) try {
|
|
5157
5230
|
a = await e.readBody();
|
|
5158
5231
|
} catch {
|
|
@@ -5166,10 +5239,10 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5166
5239
|
status: e.status,
|
|
5167
5240
|
getHeader: (t) => e.getHeader(t) ?? void 0
|
|
5168
5241
|
}, { requireChallengeChannel: t.requireChallengeChannel });
|
|
5169
|
-
},
|
|
5242
|
+
}, ui = (e) => ve({
|
|
5170
5243
|
status: e.status,
|
|
5171
5244
|
getHeader: (t) => e.getHeader(t) ?? void 0
|
|
5172
|
-
}, { requireChallengeChannel: "header" }).challenge,
|
|
5245
|
+
}, { requireChallengeChannel: "header" }).challenge, di = (e, t) => t.passflow === null ? `[passflow] a 401/403 from ${e} carried an upgrade challenge, but no Passflow endpoint is configured — set \`url\` on the Passflow config.` : `[passflow] a 401/403 from ${e} carried an upgrade challenge, but that URL is not covered by the provider's \`backend\` prop — add it there to enable step-up for this API.`, fi = (e, t) => e instanceof Ur ? { kind: "cancelled" } : e instanceof Wr ? { kind: "unsatisfiable" } : e instanceof sr ? { kind: "unavailable" } : e instanceof cr ? { kind: "session-changed" } : e instanceof or ? {
|
|
5173
5246
|
kind: "insufficient",
|
|
5174
5247
|
obtained: e.obtained,
|
|
5175
5248
|
required: e.required
|
|
@@ -5185,17 +5258,17 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5185
5258
|
kind: "transport-failure",
|
|
5186
5259
|
retryable: !1,
|
|
5187
5260
|
error: e instanceof Error ? e : Error(String(e))
|
|
5188
|
-
},
|
|
5261
|
+
}, pi = async (e, t, n, r) => {
|
|
5189
5262
|
if (e.status !== 401 && e.status !== 403) return {
|
|
5190
5263
|
kind: "replayed",
|
|
5191
5264
|
response: e
|
|
5192
5265
|
};
|
|
5193
|
-
let { challenge: i, diagnostics: a } = await
|
|
5194
|
-
if (
|
|
5266
|
+
let { challenge: i, diagnostics: a } = await li(e, t);
|
|
5267
|
+
if (si(a, e, t), !i) return {
|
|
5195
5268
|
kind: "replayed",
|
|
5196
5269
|
response: e
|
|
5197
5270
|
};
|
|
5198
|
-
let o =
|
|
5271
|
+
let o = Jr(i);
|
|
5199
5272
|
return r("elevated-insufficient", {
|
|
5200
5273
|
obtained: n,
|
|
5201
5274
|
required: o
|
|
@@ -5205,7 +5278,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5205
5278
|
required: o,
|
|
5206
5279
|
response: e
|
|
5207
5280
|
};
|
|
5208
|
-
},
|
|
5281
|
+
}, mi = async (e, t) => {
|
|
5209
5282
|
if (!t) return {
|
|
5210
5283
|
aborted: !1,
|
|
5211
5284
|
value: await e
|
|
@@ -5232,14 +5305,14 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5232
5305
|
} finally {
|
|
5233
5306
|
n && t.removeEventListener?.("abort", n);
|
|
5234
5307
|
}
|
|
5235
|
-
},
|
|
5308
|
+
}, hi = async (e, t) => {
|
|
5236
5309
|
if (e.status !== 401 && e.status !== 403 || e.markers.upgradeTransaction) return { kind: "not-a-challenge" };
|
|
5237
|
-
let n =
|
|
5310
|
+
let n = oi(e, t);
|
|
5238
5311
|
if (e.markers.replayed) {
|
|
5239
|
-
if (
|
|
5240
|
-
let { challenge: r, diagnostics: i } = await
|
|
5241
|
-
if (
|
|
5242
|
-
let a = t.readObtainedBar?.() ?? {}, o =
|
|
5312
|
+
if (!ii(e.request, t.scope, t.shouldIntercept)) return { kind: "not-a-challenge" };
|
|
5313
|
+
let { challenge: r, diagnostics: i } = await li(e, t);
|
|
5314
|
+
if (si(i, e, t), !r) return { kind: "not-a-challenge" };
|
|
5315
|
+
let a = t.readObtainedBar?.() ?? {}, o = Jr(r);
|
|
5243
5316
|
return n("elevated-insufficient", {
|
|
5244
5317
|
obtained: a,
|
|
5245
5318
|
required: o
|
|
@@ -5250,12 +5323,12 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5250
5323
|
response: e
|
|
5251
5324
|
};
|
|
5252
5325
|
}
|
|
5253
|
-
if (
|
|
5326
|
+
if (!ii(e.request, t.scope, t.shouldIntercept)) return ui(e) ? (n("challenge-out-of-scope", {
|
|
5254
5327
|
header: e.getHeader("www-authenticate") ?? void 0,
|
|
5255
|
-
message:
|
|
5328
|
+
message: di(e.request.href, t.scope)
|
|
5256
5329
|
}), { kind: "out-of-scope" }) : { kind: "not-a-challenge" };
|
|
5257
|
-
let { challenge: r, diagnostics: i } = await
|
|
5258
|
-
if (
|
|
5330
|
+
let { challenge: r, diagnostics: i } = await li(e, t);
|
|
5331
|
+
if (si(i, e, t), !r) {
|
|
5259
5332
|
let r = e.getHeader("www-authenticate");
|
|
5260
5333
|
return t.requireChallengeChannel !== "header" && n("no-channel", {
|
|
5261
5334
|
...r ? { header: r } : {},
|
|
@@ -5269,9 +5342,9 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5269
5342
|
method: e.request.method
|
|
5270
5343
|
}, s, c;
|
|
5271
5344
|
try {
|
|
5272
|
-
s = Promise.resolve(t.elevate(r, o)), c = await
|
|
5345
|
+
s = Promise.resolve(t.elevate(r, o)), c = await mi(s, e.signal);
|
|
5273
5346
|
} catch (e) {
|
|
5274
|
-
return
|
|
5347
|
+
return fi(e, void 0);
|
|
5275
5348
|
}
|
|
5276
5349
|
if (c.aborted) return s?.then((e) => e?.waiter.report({ outcome: "failed" }), () => {}), {
|
|
5277
5350
|
kind: "aborted",
|
|
@@ -5282,7 +5355,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5282
5355
|
kind: "aborted",
|
|
5283
5356
|
reason: e.signal.reason
|
|
5284
5357
|
};
|
|
5285
|
-
let u = l?.obtained ?? t.readObtainedBar?.() ??
|
|
5358
|
+
let u = l?.obtained ?? t.readObtainedBar?.() ?? Jr(r), d = t.authorizationSwap?.(), f = d ? {
|
|
5286
5359
|
from: a?.from ?? d.from,
|
|
5287
5360
|
to: d.to
|
|
5288
5361
|
} : void 0;
|
|
@@ -5291,7 +5364,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5291
5364
|
try {
|
|
5292
5365
|
p = await e.replay(f ? { authorizationSwap: f } : void 0);
|
|
5293
5366
|
} catch (t) {
|
|
5294
|
-
if (t instanceof
|
|
5367
|
+
if (t instanceof or) return l?.waiter.report({
|
|
5295
5368
|
outcome: "insufficient",
|
|
5296
5369
|
obtained: t.obtained,
|
|
5297
5370
|
required: t.required
|
|
@@ -5309,7 +5382,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5309
5382
|
};
|
|
5310
5383
|
throw t;
|
|
5311
5384
|
}
|
|
5312
|
-
let m = await
|
|
5385
|
+
let m = await pi(p, t, u, n);
|
|
5313
5386
|
return m.kind === "insufficient" ? l?.waiter.report({
|
|
5314
5387
|
outcome: "insufficient",
|
|
5315
5388
|
obtained: m.obtained,
|
|
@@ -5318,18 +5391,18 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5318
5391
|
outcome: "replayed",
|
|
5319
5392
|
obtained: u
|
|
5320
5393
|
}), m;
|
|
5321
|
-
},
|
|
5394
|
+
}, gi = (e) => {
|
|
5322
5395
|
switch (e.kind) {
|
|
5323
|
-
case "cancelled": return new
|
|
5324
|
-
case "unsatisfiable": return new
|
|
5325
|
-
case "unavailable": return new
|
|
5326
|
-
case "session-changed": return new
|
|
5327
|
-
case "insufficient": return new
|
|
5396
|
+
case "cancelled": return new Ur();
|
|
5397
|
+
case "unsatisfiable": return new Wr();
|
|
5398
|
+
case "unavailable": return new sr();
|
|
5399
|
+
case "session-changed": return new cr();
|
|
5400
|
+
case "insufficient": return new or(e.obtained, e.required);
|
|
5328
5401
|
case "exhausted": return e.error;
|
|
5329
5402
|
case "transport-failure": return e.error;
|
|
5330
5403
|
default: return;
|
|
5331
5404
|
}
|
|
5332
|
-
},
|
|
5405
|
+
}, _i = (e, t, n) => {
|
|
5333
5406
|
switch (e.kind) {
|
|
5334
5407
|
case "replayed": return {
|
|
5335
5408
|
settle: "resolve",
|
|
@@ -5347,21 +5420,21 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5347
5420
|
};
|
|
5348
5421
|
case "cancelled": return n.onCancel === "reject" ? {
|
|
5349
5422
|
settle: "reject",
|
|
5350
|
-
error: new
|
|
5423
|
+
error: new Ur()
|
|
5351
5424
|
} : {
|
|
5352
5425
|
settle: "resolve",
|
|
5353
|
-
value:
|
|
5426
|
+
value: Ei(t, e)
|
|
5354
5427
|
};
|
|
5355
5428
|
case "insufficient": return {
|
|
5356
5429
|
settle: "resolve",
|
|
5357
|
-
value:
|
|
5430
|
+
value: Ei(e.response?.raw ?? t, e)
|
|
5358
5431
|
};
|
|
5359
5432
|
default: return {
|
|
5360
5433
|
settle: "resolve",
|
|
5361
|
-
value:
|
|
5434
|
+
value: Ei(t, e)
|
|
5362
5435
|
};
|
|
5363
5436
|
}
|
|
5364
|
-
},
|
|
5437
|
+
}, vi = (e, t) => {
|
|
5365
5438
|
switch (e.kind) {
|
|
5366
5439
|
case "replayed": return e.response.rejected ? {
|
|
5367
5440
|
settle: "reject",
|
|
@@ -5376,39 +5449,39 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5376
5449
|
};
|
|
5377
5450
|
default: return {
|
|
5378
5451
|
settle: "reject",
|
|
5379
|
-
error:
|
|
5452
|
+
error: gi(e) ?? t
|
|
5380
5453
|
};
|
|
5381
5454
|
}
|
|
5382
|
-
},
|
|
5455
|
+
}, yi = /* @__PURE__ */ new WeakSet(), bi = /* @__PURE__ */ new WeakSet(), xi = /* @__PURE__ */ new WeakSet(), Si = /* @__PURE__ */ new WeakSet(), Ci = /* @__PURE__ */ new WeakSet(), wi = /* @__PURE__ */ new WeakSet(), Ti = /* @__PURE__ */ new WeakSet(), Ei = (e, t) => {
|
|
5383
5456
|
switch (t.kind) {
|
|
5384
5457
|
case "cancelled":
|
|
5385
|
-
|
|
5458
|
+
yi.add(e);
|
|
5386
5459
|
break;
|
|
5387
5460
|
case "exhausted":
|
|
5388
|
-
|
|
5461
|
+
bi.add(e);
|
|
5389
5462
|
break;
|
|
5390
5463
|
case "insufficient":
|
|
5391
|
-
|
|
5464
|
+
xi.add(e);
|
|
5392
5465
|
break;
|
|
5393
5466
|
case "unsatisfiable":
|
|
5394
|
-
|
|
5467
|
+
Si.add(e);
|
|
5395
5468
|
break;
|
|
5396
5469
|
case "unavailable":
|
|
5397
|
-
|
|
5470
|
+
Ci.add(e);
|
|
5398
5471
|
break;
|
|
5399
5472
|
case "session-changed":
|
|
5400
|
-
|
|
5473
|
+
wi.add(e);
|
|
5401
5474
|
break;
|
|
5402
|
-
case "transport-failure":
|
|
5475
|
+
case "transport-failure": Ti.add(e);
|
|
5403
5476
|
}
|
|
5404
5477
|
return e;
|
|
5405
|
-
},
|
|
5478
|
+
}, Di = (e) => yi.has(e), Oi = (e) => bi.has(e), ki = (e) => xi.has(e), Ai = (e) => Si.has(e), ji = (e) => Ci.has(e), Mi = (e) => wi.has(e), Ni = (e) => Ti.has(e), Pi = "https://passflow-relative.invalid", Fi = () => {
|
|
5406
5479
|
let e = globalThis, t = e.document?.baseURI;
|
|
5407
5480
|
if (typeof t == "string" && t !== "") return t;
|
|
5408
5481
|
let n = e.location?.href;
|
|
5409
|
-
return typeof n == "string" && n !== "" && n !== "about:blank" ? n :
|
|
5410
|
-
},
|
|
5411
|
-
let n = t ===
|
|
5482
|
+
return typeof n == "string" && n !== "" && n !== "about:blank" ? n : Pi;
|
|
5483
|
+
}, Ii = (e, t = Fi()) => {
|
|
5484
|
+
let n = t === Pi, r;
|
|
5412
5485
|
try {
|
|
5413
5486
|
r = new URL(t).origin;
|
|
5414
5487
|
} catch {
|
|
@@ -5434,28 +5507,28 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5434
5507
|
relativeToBase: !1,
|
|
5435
5508
|
sentinelBase: n
|
|
5436
5509
|
};
|
|
5437
|
-
},
|
|
5510
|
+
}, Li = (e, t) => typeof t == "string" ? [e.toLowerCase(), t] : void 0, Ri = (e) => {
|
|
5438
5511
|
let t = [];
|
|
5439
5512
|
if (e == null) return Object.freeze(t);
|
|
5440
5513
|
let n = e;
|
|
5441
5514
|
if (typeof n.forEach == "function" && typeof n.entries == "function") return e.forEach((e, n) => {
|
|
5442
|
-
let r =
|
|
5515
|
+
let r = Li(n, e);
|
|
5443
5516
|
r && t.push(r);
|
|
5444
5517
|
}), Object.freeze(t);
|
|
5445
5518
|
if (Array.isArray(e)) {
|
|
5446
5519
|
for (let n of e) if (Array.isArray(n) && n.length >= 2) {
|
|
5447
|
-
let e =
|
|
5520
|
+
let e = Li(String(n[0]), n[1]);
|
|
5448
5521
|
e && t.push(e);
|
|
5449
5522
|
}
|
|
5450
5523
|
return Object.freeze(t);
|
|
5451
5524
|
}
|
|
5452
5525
|
if (typeof e == "object") for (let [n, r] of Object.entries(e)) {
|
|
5453
|
-
let e =
|
|
5526
|
+
let e = Li(n, Array.isArray(r) ? r.join(", ") : r);
|
|
5454
5527
|
e && t.push(e);
|
|
5455
5528
|
}
|
|
5456
5529
|
return Object.freeze(t);
|
|
5457
|
-
},
|
|
5458
|
-
let t = e.base === void 0 ?
|
|
5530
|
+
}, zi = (e) => {
|
|
5531
|
+
let t = e.base === void 0 ? Ii(e.url) : Ii(e.url, e.base), n = {
|
|
5459
5532
|
raw: e.url,
|
|
5460
5533
|
href: t.href,
|
|
5461
5534
|
dispatchUrl: t.sentinelBase || !t.resolved ? e.url : t.href,
|
|
@@ -5464,29 +5537,29 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5464
5537
|
resolved: t.resolved,
|
|
5465
5538
|
relativeToBase: t.relativeToBase,
|
|
5466
5539
|
method: (e.method ?? "GET").toUpperCase(),
|
|
5467
|
-
headers:
|
|
5540
|
+
headers: Ri(e.headers),
|
|
5468
5541
|
bodyKind: e.bodyKind,
|
|
5469
5542
|
..."body" in e ? { body: e.body } : {}
|
|
5470
5543
|
};
|
|
5471
5544
|
return Object.freeze(n);
|
|
5472
|
-
},
|
|
5545
|
+
}, Bi = (e, t) => {
|
|
5473
5546
|
if (!t || t.from === t.to) return e;
|
|
5474
5547
|
let n = !1, r = e.map(([e, r]) => e === "authorization" && r === t.from ? (n = !0, [e, t.to]) : [e, r]);
|
|
5475
5548
|
return n ? Object.freeze(r) : e;
|
|
5476
|
-
},
|
|
5549
|
+
}, Vi = (e) => {
|
|
5477
5550
|
let t = {};
|
|
5478
5551
|
for (let [n, r] of e) t[n] = r;
|
|
5479
5552
|
return t;
|
|
5480
|
-
},
|
|
5553
|
+
}, Hi = /* @__PURE__ */ new Set([
|
|
5481
5554
|
"GET",
|
|
5482
5555
|
"HEAD",
|
|
5483
5556
|
"OPTIONS"
|
|
5484
|
-
]),
|
|
5557
|
+
]), Ui = (e) => typeof e == "object" && !!e && typeof e.url == "string" && typeof e.clone == "function" && "method" in e, Wi = (e) => typeof e == "string" ? e : Ui(e) ? e.url : String(e), Gi = (e, t) => (t?.method ?? (Ui(e) ? e.method : void 0) ?? "GET").toUpperCase(), Ki = (e) => e == null ? "none" : typeof e == "string" ? "reusable" : typeof e.getReader == "function" ? "one-shot" : "reusable", qi = (e) => {
|
|
5485
5558
|
if (typeof e == "string") return e.length;
|
|
5486
5559
|
let t = e;
|
|
5487
5560
|
if (typeof t?.size == "number") return t.size;
|
|
5488
5561
|
if (typeof t?.byteLength == "number") return t.byteLength;
|
|
5489
|
-
},
|
|
5562
|
+
}, Ji = (e, t, n) => e === void 0 || e === "always" ? !0 : e === "idempotent-only" ? Hi.has(t.method) : typeof e == "function" ? e(t) : !(e.maxBodyBytes !== void 0 && n !== void 0 && n > e.maxBodyBytes), Yi = (e, t, n, r, i) => ({
|
|
5490
5563
|
replayable: !1,
|
|
5491
5564
|
bodyKind: e,
|
|
5492
5565
|
reason: t,
|
|
@@ -5494,11 +5567,11 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5494
5567
|
forwardInit: i,
|
|
5495
5568
|
snapshot: r,
|
|
5496
5569
|
replay: () => Promise.reject(/* @__PURE__ */ Error(`This request cannot be replayed: ${t}`))
|
|
5497
|
-
}),
|
|
5570
|
+
}), Xi = (e, t) => Vi(Bi(e.headers, t?.authorizationSwap)), Zi = (e) => {
|
|
5498
5571
|
if (!e || !("headers" in e)) return e;
|
|
5499
5572
|
let { headers: t, ...n } = e;
|
|
5500
5573
|
return n;
|
|
5501
|
-
},
|
|
5574
|
+
}, Qi = (e, t) => t && "headers" in t && t.headers !== void 0 ? t.headers : Ui(e) ? e.headers : void 0, $i = (e) => {
|
|
5502
5575
|
if (e === null || typeof e == "string") return e;
|
|
5503
5576
|
if (typeof FormData < "u" && e instanceof FormData) {
|
|
5504
5577
|
let t = new FormData();
|
|
@@ -5506,18 +5579,18 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5506
5579
|
return t;
|
|
5507
5580
|
}
|
|
5508
5581
|
return typeof URLSearchParams < "u" && e instanceof URLSearchParams ? new URLSearchParams(e) : e instanceof ArrayBuffer ? e.slice(0) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength).slice() : e;
|
|
5509
|
-
},
|
|
5510
|
-
let r =
|
|
5582
|
+
}, ea = (e, t, n) => new Request(e, { headers: Xi(t, n) }), ta = (e, t, n) => {
|
|
5583
|
+
let r = Wi(e), i = Gi(e, t), a = Qi(e, t), o = (e, t) => zi({
|
|
5511
5584
|
url: r,
|
|
5512
5585
|
method: i,
|
|
5513
5586
|
headers: a,
|
|
5514
5587
|
bodyKind: e,
|
|
5515
5588
|
...t === void 0 ? {} : { body: t }
|
|
5516
5589
|
});
|
|
5517
|
-
if (
|
|
5590
|
+
if (Ui(e)) {
|
|
5518
5591
|
if (e.body === null || e.body === void 0) {
|
|
5519
5592
|
let a = o("none");
|
|
5520
|
-
return
|
|
5593
|
+
return Ji(n, {
|
|
5521
5594
|
url: r,
|
|
5522
5595
|
method: i,
|
|
5523
5596
|
bodyKind: "none"
|
|
@@ -5527,20 +5600,20 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5527
5600
|
forwardInput: e,
|
|
5528
5601
|
forwardInit: t,
|
|
5529
5602
|
snapshot: a,
|
|
5530
|
-
replay: (n, r) => n(
|
|
5531
|
-
} :
|
|
5603
|
+
replay: (n, r) => n(ea(e, a, r), Zi(t))
|
|
5604
|
+
} : Yi("none", "the replay policy refused this request", e, a, t);
|
|
5532
5605
|
}
|
|
5533
5606
|
let a = o("request-clone");
|
|
5534
|
-
if (!
|
|
5607
|
+
if (!Ji(n, {
|
|
5535
5608
|
url: r,
|
|
5536
5609
|
method: i,
|
|
5537
5610
|
bodyKind: "request-clone"
|
|
5538
|
-
})) return
|
|
5611
|
+
})) return Yi("request-clone", "the replay policy refused this request", e, a, t);
|
|
5539
5612
|
let s;
|
|
5540
5613
|
try {
|
|
5541
5614
|
s = e.clone();
|
|
5542
5615
|
} catch {
|
|
5543
|
-
return
|
|
5616
|
+
return Yi("one-shot", "the Request body was already consumed and cannot be cloned", e, a, t);
|
|
5544
5617
|
}
|
|
5545
5618
|
return {
|
|
5546
5619
|
replayable: !0,
|
|
@@ -5548,17 +5621,17 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5548
5621
|
forwardInput: e,
|
|
5549
5622
|
forwardInit: t,
|
|
5550
5623
|
snapshot: a,
|
|
5551
|
-
replay: (e, n) => e(
|
|
5624
|
+
replay: (e, n) => e(ea(s, a, n), Zi(t))
|
|
5552
5625
|
};
|
|
5553
5626
|
}
|
|
5554
|
-
let s =
|
|
5555
|
-
if (s === "one-shot") return
|
|
5556
|
-
if (!
|
|
5627
|
+
let s = Ki(t?.body);
|
|
5628
|
+
if (s === "one-shot") return Yi("one-shot", "a streaming request body is consumed by the first send", e, o("one-shot"), t);
|
|
5629
|
+
if (!Ji(n, {
|
|
5557
5630
|
url: r,
|
|
5558
5631
|
method: i,
|
|
5559
5632
|
bodyKind: s
|
|
5560
|
-
},
|
|
5561
|
-
let c = t && "body" in t ?
|
|
5633
|
+
}, qi(t?.body))) return Yi(s, "the replay policy refused this request", e, o(s), t);
|
|
5634
|
+
let c = t && "body" in t ? $i(t.body ?? null) : void 0, l = o(s, c);
|
|
5562
5635
|
return {
|
|
5563
5636
|
replayable: !0,
|
|
5564
5637
|
bodyKind: s,
|
|
@@ -5566,21 +5639,21 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5566
5639
|
forwardInit: t,
|
|
5567
5640
|
snapshot: l,
|
|
5568
5641
|
replay: (e, n) => e(l.dispatchUrl, {
|
|
5569
|
-
...
|
|
5642
|
+
...Zi(t),
|
|
5570
5643
|
...c === void 0 ? {} : { body: c },
|
|
5571
|
-
headers:
|
|
5644
|
+
headers: Xi(l, n),
|
|
5572
5645
|
method: l.method
|
|
5573
5646
|
})
|
|
5574
5647
|
};
|
|
5575
|
-
},
|
|
5576
|
-
if (!
|
|
5648
|
+
}, na = (e) => typeof e == "object" && !!e, ra = (e) => (t) => {
|
|
5649
|
+
if (!na(e)) return;
|
|
5577
5650
|
let n = e[t] ?? e[t.toLowerCase()] ?? (typeof e.get == "function" ? e.get(t) : void 0);
|
|
5578
5651
|
return Array.isArray(n) ? n.join(", ") : typeof n == "string" ? n : void 0;
|
|
5579
|
-
},
|
|
5652
|
+
}, ia = (e) => {
|
|
5580
5653
|
let t = e?.url ?? "", n = e?.baseURL;
|
|
5581
5654
|
return !n || /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t) ? t : `${n.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
|
|
5582
|
-
},
|
|
5583
|
-
let r =
|
|
5655
|
+
}, aa = (e) => (e?.method ?? "GET").toUpperCase(), oa = (e) => e == null ? "none" : na(e) && (typeof e.pipe == "function" || typeof e.getReader == "function") ? "one-shot" : "reusable", sa = (e, t, n) => {
|
|
5656
|
+
let r = Vi(Bi(t.headers, n?.authorizationSwap)), i = t.dispatchUrl === t.href && t.resolved;
|
|
5584
5657
|
return {
|
|
5585
5658
|
...e,
|
|
5586
5659
|
...i ? { baseURL: void 0 } : {},
|
|
@@ -5589,10 +5662,10 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5589
5662
|
headers: r,
|
|
5590
5663
|
..."body" in t ? { data: t.body } : {}
|
|
5591
5664
|
};
|
|
5592
|
-
},
|
|
5593
|
-
let o = t ?? e?.config, s =
|
|
5594
|
-
url:
|
|
5595
|
-
method:
|
|
5665
|
+
}, ca = (e, t, n, r, i, a) => {
|
|
5666
|
+
let o = t ?? e?.config, s = oa(o?.data), c = a ?? zi({
|
|
5667
|
+
url: ia(o),
|
|
5668
|
+
method: aa(o),
|
|
5596
5669
|
headers: o?.headers,
|
|
5597
5670
|
bodyKind: s,
|
|
5598
5671
|
body: o?.data
|
|
@@ -5600,22 +5673,22 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5600
5673
|
url: c.href,
|
|
5601
5674
|
method: c.method,
|
|
5602
5675
|
bodyKind: s
|
|
5603
|
-
}, u = s !== "one-shot" &&
|
|
5676
|
+
}, u = s !== "one-shot" && Ji(i.replay, l);
|
|
5604
5677
|
return {
|
|
5605
5678
|
status: e?.status ?? 0,
|
|
5606
|
-
getHeader:
|
|
5679
|
+
getHeader: ra(e?.headers),
|
|
5607
5680
|
readBody: async () => e?.data,
|
|
5608
5681
|
request: c,
|
|
5609
5682
|
replay: async (e) => {
|
|
5610
|
-
let t = Te(
|
|
5683
|
+
let t = Te(sa(o ?? {}, c, e));
|
|
5611
5684
|
try {
|
|
5612
5685
|
let e = await r(t);
|
|
5613
|
-
return
|
|
5686
|
+
return ca(e, e?.config ?? t, e, r, i, c);
|
|
5614
5687
|
} catch (e) {
|
|
5615
|
-
let n =
|
|
5616
|
-
if (!n.response || typeof n.response.status != "number" ||
|
|
5688
|
+
let n = na(e) ? e : {};
|
|
5689
|
+
if (!n.response || typeof n.response.status != "number" || Qn(e)) throw e;
|
|
5617
5690
|
return {
|
|
5618
|
-
...
|
|
5691
|
+
...ca(n.response, n.config ?? t, e, r, i, c),
|
|
5619
5692
|
rejected: !0
|
|
5620
5693
|
};
|
|
5621
5694
|
}
|
|
@@ -5629,19 +5702,19 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5629
5702
|
replayUnsupportedReason: s === "one-shot" ? "a streaming request body is consumed by the first send" : "the replay policy refused this request",
|
|
5630
5703
|
signal: o?.signal
|
|
5631
5704
|
};
|
|
5632
|
-
},
|
|
5633
|
-
let r =
|
|
5705
|
+
}, la = (e, t) => async (n) => {
|
|
5706
|
+
let r = $r(e), i = na(n) ? n : {}, a = vi(await hi(ca(i.response, i.config, i.response, t, r), r), n);
|
|
5634
5707
|
if (a.settle === "reject") throw a.error;
|
|
5635
5708
|
return a.value;
|
|
5636
|
-
},
|
|
5637
|
-
let r = e.request, i = n ?? (typeof r == "function" ? (t) => r.call(e, t) : () => Promise.reject(/* @__PURE__ */ Error("Passflow: this client exposes no request() to replay through."))), a = e.interceptors.response.use(void 0,
|
|
5709
|
+
}, ua = (e, t, n) => {
|
|
5710
|
+
let r = e.request, i = n ?? (typeof r == "function" ? (t) => r.call(e, t) : () => Promise.reject(/* @__PURE__ */ Error("Passflow: this client exposes no request() to replay through."))), a = e.interceptors.response.use(void 0, la(t, i)), o = !1;
|
|
5638
5711
|
return () => {
|
|
5639
5712
|
o || (o = !0, e.interceptors.response.eject(a));
|
|
5640
5713
|
};
|
|
5641
|
-
},
|
|
5714
|
+
}, da = (t, n) => {
|
|
5642
5715
|
let r = e.create(t);
|
|
5643
5716
|
return n(r), r;
|
|
5644
|
-
},
|
|
5717
|
+
}, fa = 0, pa = (e, t) => {
|
|
5645
5718
|
let n = t?.signal ?? (typeof e == "object" && e ? e.signal : void 0) ?? void 0;
|
|
5646
5719
|
if (n) return {
|
|
5647
5720
|
get aborted() {
|
|
@@ -5655,34 +5728,34 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5655
5728
|
removeEventListener: (e, t) => n.removeEventListener(e, t)
|
|
5656
5729
|
} : {}
|
|
5657
5730
|
};
|
|
5658
|
-
},
|
|
5731
|
+
}, ma = (e) => (t) => e.headers?.get(t), ha = (e, t, n, r, i) => ({
|
|
5659
5732
|
status: e.status,
|
|
5660
|
-
getHeader:
|
|
5733
|
+
getHeader: ma(e),
|
|
5661
5734
|
readBody: () => e.clone().json(),
|
|
5662
5735
|
request: t.snapshot,
|
|
5663
|
-
replay: async (e) =>
|
|
5736
|
+
replay: async (e) => ha(await t.replay(n, e), t, n, r, i),
|
|
5664
5737
|
markers: r,
|
|
5665
5738
|
raw: e,
|
|
5666
5739
|
replayable: t.replayable,
|
|
5667
5740
|
replayUnsupportedReason: t.reason,
|
|
5668
5741
|
signal: i,
|
|
5669
5742
|
responseType: e.type
|
|
5670
|
-
}),
|
|
5743
|
+
}), ga = (e, t) => {
|
|
5671
5744
|
let n = (t, n) => {
|
|
5672
|
-
|
|
5745
|
+
fa += 1;
|
|
5673
5746
|
try {
|
|
5674
5747
|
return e(t, n);
|
|
5675
5748
|
} finally {
|
|
5676
|
-
--
|
|
5749
|
+
--fa;
|
|
5677
5750
|
}
|
|
5678
5751
|
};
|
|
5679
5752
|
return async (e, r) => {
|
|
5680
|
-
if (
|
|
5681
|
-
let i =
|
|
5753
|
+
if (fa > 0) return n(e, r);
|
|
5754
|
+
let i = $r(t), a = ta(e, r, i.replay), o = await n(a.forwardInput, a.forwardInit), s = _i(await hi(ha(o, a, n, {}, pa(e, r)), i), o, i);
|
|
5682
5755
|
if (s.settle === "reject") throw s.error;
|
|
5683
5756
|
return s.value;
|
|
5684
5757
|
};
|
|
5685
|
-
},
|
|
5758
|
+
}, _a = new Set(Ir.filter((e) => !e.requiresPrepare).map((e) => e.type)), va = (e) => {
|
|
5686
5759
|
if (!e || typeof e != "object" || !e.challenge_id || !e.expires_at) throw new $({
|
|
5687
5760
|
kind: "protocol",
|
|
5688
5761
|
message: "The upgrade start response is missing challenge_id or expires_at"
|
|
@@ -5694,17 +5767,17 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5694
5767
|
webauthn: e.webauthn,
|
|
5695
5768
|
codeSentTo: e.code_sent_to
|
|
5696
5769
|
};
|
|
5697
|
-
},
|
|
5770
|
+
}, ya = (e) => Qn(e) && !$n(e), ba = (e) => ({
|
|
5698
5771
|
async prepare(t) {
|
|
5699
|
-
if (!
|
|
5772
|
+
if (!_a.has(t)) try {
|
|
5700
5773
|
let n = e.relyingPartyId?.();
|
|
5701
|
-
return
|
|
5774
|
+
return va(await e.startUpgrade(n ? {
|
|
5702
5775
|
method: t,
|
|
5703
5776
|
relying_party_id: n
|
|
5704
5777
|
} : { method: t }));
|
|
5705
5778
|
} catch (e) {
|
|
5706
|
-
if (
|
|
5707
|
-
let t =
|
|
5779
|
+
if (ya(e)) throw e;
|
|
5780
|
+
let t = rr(e, "start");
|
|
5708
5781
|
if (t.kind === "prepare_not_required") return;
|
|
5709
5782
|
throw t;
|
|
5710
5783
|
}
|
|
@@ -5721,17 +5794,17 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5721
5794
|
assertion: n
|
|
5722
5795
|
});
|
|
5723
5796
|
} catch (t) {
|
|
5724
|
-
if (
|
|
5725
|
-
let n =
|
|
5726
|
-
throw n.status === 401 &&
|
|
5797
|
+
if (ya(t)) throw t;
|
|
5798
|
+
let n = rr(t, "refresh");
|
|
5799
|
+
throw n.status === 401 && ar(n) && e.markSessionInvalid?.(), n;
|
|
5727
5800
|
}
|
|
5728
5801
|
}
|
|
5729
|
-
}),
|
|
5802
|
+
}), xa = (e) => e === void 0 ? [] : (Array.isArray(e) ? e : [e]).filter((e) => e !== ""), Sa = (e) => {
|
|
5730
5803
|
let t, n = (e) => e !== void 0 && t === e, r = (r) => {
|
|
5731
5804
|
let i = () => {
|
|
5732
5805
|
if (!n(r())) throw new $({ kind: "session_changed" });
|
|
5733
5806
|
};
|
|
5734
|
-
return
|
|
5807
|
+
return ba({
|
|
5735
5808
|
...e,
|
|
5736
5809
|
relyingPartyId: () => t?.options.relyingPartyId ?? e.relyingPartyId?.(),
|
|
5737
5810
|
startUpgrade: (t) => (i(), e.startUpgrade(t)),
|
|
@@ -5742,7 +5815,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5742
5815
|
});
|
|
5743
5816
|
}, i = (t, n) => {
|
|
5744
5817
|
let i = {}, a = {
|
|
5745
|
-
controller: new
|
|
5818
|
+
controller: new Qr({
|
|
5746
5819
|
transport: r(() => i.current),
|
|
5747
5820
|
prompt: t.prompt,
|
|
5748
5821
|
platform: e.platform,
|
|
@@ -5754,17 +5827,17 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5754
5827
|
options: t,
|
|
5755
5828
|
scope: {
|
|
5756
5829
|
passflow: e.passflowDomain,
|
|
5757
|
-
backend:
|
|
5830
|
+
backend: xa(t.backend)
|
|
5758
5831
|
},
|
|
5759
5832
|
generation: n
|
|
5760
5833
|
};
|
|
5761
5834
|
return i.current = a, a;
|
|
5762
5835
|
}, a = async (r, i) => {
|
|
5763
5836
|
let a = t;
|
|
5764
|
-
if (!a) throw new
|
|
5837
|
+
if (!a) throw new sr("Step-up verification is not enabled on this Passflow instance");
|
|
5765
5838
|
a.controller.active || (a.pin = e.readSessionPin?.());
|
|
5766
5839
|
let o = await a.controller.elevate(r, i);
|
|
5767
|
-
if (!n(a)) throw new
|
|
5840
|
+
if (!n(a)) throw new cr();
|
|
5768
5841
|
return o;
|
|
5769
5842
|
}, o = () => {
|
|
5770
5843
|
let n = t, r = n?.scope ?? {
|
|
@@ -5808,9 +5881,9 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5808
5881
|
let r = [];
|
|
5809
5882
|
if (e.attachInternalSeam) {
|
|
5810
5883
|
let t = e.attachInternalSeam;
|
|
5811
|
-
t((e) =>
|
|
5884
|
+
t((e) => la(o, e)), r.push(() => t(void 0));
|
|
5812
5885
|
}
|
|
5813
|
-
n.interceptFetch && r.push(
|
|
5886
|
+
n.interceptFetch && r.push(mt((e, t, n) => ga(e, o)(t, n), {
|
|
5814
5887
|
priority: 20,
|
|
5815
5888
|
name: "passflow-upgrade"
|
|
5816
5889
|
})), e.onSessionChange && r.push(e.onSessionChange(() => {
|
|
@@ -5841,18 +5914,18 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5841
5914
|
withAuth: {
|
|
5842
5915
|
enumerable: !0,
|
|
5843
5916
|
value: (e) => {
|
|
5844
|
-
if (e) return
|
|
5917
|
+
if (e) return ga(e, o);
|
|
5845
5918
|
let t = typeof globalThis > "u" ? void 0 : globalThis;
|
|
5846
5919
|
if (!t || typeof t.fetch != "function") throw Error("Passflow: withAuth() needs a fetch to wrap — this runtime has none.");
|
|
5847
|
-
return
|
|
5920
|
+
return ga(t.fetch.bind(t), o);
|
|
5848
5921
|
}
|
|
5849
5922
|
},
|
|
5850
5923
|
attachAuth: {
|
|
5851
5924
|
enumerable: !0,
|
|
5852
|
-
value: (e) =>
|
|
5925
|
+
value: (e) => ua(e, o)
|
|
5853
5926
|
}
|
|
5854
5927
|
});
|
|
5855
|
-
},
|
|
5928
|
+
}, Ca, wa = class {
|
|
5856
5929
|
get origin() {
|
|
5857
5930
|
return this.platform.getCurrentUrl()?.origin ?? "";
|
|
5858
5931
|
}
|
|
@@ -5864,9 +5937,9 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5864
5937
|
this.url = t || "https://auth.passflow.cloud", this.appId = n, this.platform = e.platform ?? P, this.storageManager = new N({
|
|
5865
5938
|
prefix: e.keyStoragePrefix ?? "",
|
|
5866
5939
|
storage: this.platform.storage
|
|
5867
|
-
}), this.deviceService = new re(this.storageManager), this.authApi = new
|
|
5868
|
-
let i =
|
|
5869
|
-
this.authService = new
|
|
5940
|
+
}), this.deviceService = new re(this.storageManager), this.authApi = new Ge(e, this.storageManager, this.deviceService), this.appApi = new Ue(e, this.storageManager, this.deviceService), this.userApi = new et(e, this.storageManager, this.deviceService), this.settingApi = new Je(e, this.storageManager, this.deviceService), this.tenantApi = new Ye(e, this.storageManager, this.deviceService), this.invitationApi = new qe(e, this.storageManager, this.deviceService), this.twoFactorApi = new Qe(e, this.storageManager, this.deviceService), this.upgradeApi = new $e(e, this.storageManager, this.deviceService), this.upgradeDomain = ke(e.url), this.subscribeStore = new Gn(), this.tokenCacheService = new Or(this.storageManager, this.authApi, this.subscribeStore, this.platform), this.scopes = r ?? u, this.createTenantForNewUser = e.createTenantForNewUser ?? !1;
|
|
5941
|
+
let i = an(e.refreshCoordination, this.platform, e.keyStoragePrefix, { tokenKeys: () => this.storageManager.tokenKeys() });
|
|
5942
|
+
this.authService = new wr(this.authApi, this.deviceService, this.storageManager, this.subscribeStore, this.tokenCacheService, this.scopes, this.createTenantForNewUser, this.url, {
|
|
5870
5943
|
createSession: this.createSessionCallback,
|
|
5871
5944
|
expiredSession: this.expiredSessionCallback
|
|
5872
5945
|
}, this.appId ?? "", e.tokenExchange, this.platform, () => this.readPkceEnabled(), {
|
|
@@ -5874,7 +5947,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5874
5947
|
...e.refreshStrikes === void 0 ? {} : { strikes: e.refreshStrikes }
|
|
5875
5948
|
}), this.tokenCacheService.attachRefreshController(this.authService.refresh);
|
|
5876
5949
|
for (let e of this.axiosClients()) e.setRefreshHandler((e) => this.authService.refresh.ensureFresh(e));
|
|
5877
|
-
this.userService = new
|
|
5950
|
+
this.userService = new Ar(this.userApi, this.deviceService, this.platform), this.tenantService = new Dr(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new Tr(this.invitationApi), this.twoFactorService = new kr(this.twoFactorApi, this.subscribeStore, this.authService), this.twoFactor = this.twoFactorService, this.upgrade = Sa({
|
|
5878
5951
|
startUpgrade: (e) => this.upgradeApi.startUpgrade(e),
|
|
5879
5952
|
commitRefresh: async (e, t) => {
|
|
5880
5953
|
await this.authService.refreshToken(e, t);
|
|
@@ -5921,7 +5994,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
5921
5994
|
return this.upgrade.attachAuth(e);
|
|
5922
5995
|
}
|
|
5923
5996
|
createClient(e) {
|
|
5924
|
-
return
|
|
5997
|
+
return da(e, (e) => this.upgrade.attachAuth(e));
|
|
5925
5998
|
}
|
|
5926
5999
|
readAssuranceBar() {
|
|
5927
6000
|
let e = this.storageManager.getToken(j.access_token);
|
|
@@ -6001,7 +6074,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6001
6074
|
}
|
|
6002
6075
|
let r = t.get("access_token"), i = t.get("refresh_token"), a = t.get("id_token"), o = t.get("scopes")?.split(",") ?? this.scopes, s;
|
|
6003
6076
|
if (r) {
|
|
6004
|
-
if (!
|
|
6077
|
+
if (!dr(r)) {
|
|
6005
6078
|
U(this.subscribeStore, {
|
|
6006
6079
|
operation: "tokens.from-url",
|
|
6007
6080
|
message: "Invalid access token format received",
|
|
@@ -6009,7 +6082,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6009
6082
|
}), this.cleanupUrlParams(n, e);
|
|
6010
6083
|
return;
|
|
6011
6084
|
}
|
|
6012
|
-
if (i && !
|
|
6085
|
+
if (i && !dr(i)) {
|
|
6013
6086
|
U(this.subscribeStore, {
|
|
6014
6087
|
operation: "tokens.from-url",
|
|
6015
6088
|
message: "Invalid refresh token format received",
|
|
@@ -6017,7 +6090,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6017
6090
|
}), this.cleanupUrlParams(n, e);
|
|
6018
6091
|
return;
|
|
6019
6092
|
}
|
|
6020
|
-
if (a && !
|
|
6093
|
+
if (a && !dr(a)) {
|
|
6021
6094
|
U(this.subscribeStore, {
|
|
6022
6095
|
operation: "tokens.from-url",
|
|
6023
6096
|
message: "Invalid ID token format received",
|
|
@@ -6043,7 +6116,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6043
6116
|
if (!n) return !1;
|
|
6044
6117
|
t.delete("tfa_token");
|
|
6045
6118
|
let r = t.toString();
|
|
6046
|
-
return this.platform.replaceUrl(e.pathname + e.search + (r ? `#${r}` : "")),
|
|
6119
|
+
return this.platform.replaceUrl(e.pathname + e.search + (r ? `#${r}` : "")), dr(n) ? (this.subscribeStore.notify(Z.TwoFactorRequired, {
|
|
6047
6120
|
email: "",
|
|
6048
6121
|
challengeId: "",
|
|
6049
6122
|
tfaToken: n
|
|
@@ -6056,7 +6129,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6056
6129
|
checkErrorsFromURL() {
|
|
6057
6130
|
let e = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
|
|
6058
6131
|
if (e) {
|
|
6059
|
-
let t =
|
|
6132
|
+
let t = fr(e);
|
|
6060
6133
|
return Error(t);
|
|
6061
6134
|
}
|
|
6062
6135
|
}
|
|
@@ -6117,6 +6190,9 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6117
6190
|
async passwordlessSignInComplete(e) {
|
|
6118
6191
|
return await this.authService.passwordlessSignInComplete(e);
|
|
6119
6192
|
}
|
|
6193
|
+
async verifyEmailCode(e) {
|
|
6194
|
+
return await this.authService.verifyEmailCode(e);
|
|
6195
|
+
}
|
|
6120
6196
|
handleError(e, t, n) {
|
|
6121
6197
|
let r = {
|
|
6122
6198
|
operation: t,
|
|
@@ -6166,8 +6242,8 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6166
6242
|
sendPasswordResetEmail(e) {
|
|
6167
6243
|
return this.authService.sendPasswordResetEmail(e);
|
|
6168
6244
|
}
|
|
6169
|
-
async resetPassword(e, t) {
|
|
6170
|
-
return await this.authService.resetPassword(e, t);
|
|
6245
|
+
async resetPassword(e, t, n) {
|
|
6246
|
+
return await this.authService.resetPassword(e, t, n);
|
|
6171
6247
|
}
|
|
6172
6248
|
async getAppSettings() {
|
|
6173
6249
|
try {
|
|
@@ -6397,7 +6473,7 @@ var _r = "passflow_2fa_pkce", vr = 3e5, yr = class {
|
|
|
6397
6473
|
this.twoFactorService.clearMagicLinkSession();
|
|
6398
6474
|
}
|
|
6399
6475
|
};
|
|
6400
|
-
|
|
6401
|
-
export { i as APP_ID_HEADER_KEY, a as AUTHORIZATION_HEADER_KEY,
|
|
6476
|
+
Ca = wa, Ca.version = c;
|
|
6477
|
+
export { i as APP_ID_HEADER_KEY, a as AUTHORIZATION_HEADER_KEY, Ue as AppAPI, Ge as AuthAPI, wr as AuthService, Ke as CLIAuthAPI, f as DEFAULT_GROUP_NAME, u as DEFAULT_SCOPES, Ir as DEFAULT_UPGRADE_FACTORS, o as DEVICE_ID_HEADER_KEY, s as DEVICE_TYPE_HEADER_KEY, b as ERROR_MESSAGE_MAX_LENGTH, tt as FETCH_PRIORITY_OIDC, nt as FETCH_PRIORITY_UPGRADE, rt as FetchMiddlewareContractError, ce as INSUFFICIENT_USER_AUTHENTICATION, qe as InvitationAPI, Tr as InvitationService, Ct as M2MClient, vt as M2MConfigError, H as M2MError, yt as M2MErrorCodes, gt as M2MNetworkError, _t as M2MTokenParseError, bt as M2M_DEFAULTS, l as MINIMAL_DEFAULT_SCOPES, Me as OS, d as PASSFLOW_CLOUD_URL, m as POPUP_HEIGHT, h as POPUP_POLL_INTERVAL_MS, g as POPUP_TIMEOUT_MS, p as POPUP_WIDTH, wa as Passflow, Oe as PassflowAdminEndpointPaths, z as PassflowEndpointPaths, B as PassflowError, Z as PassflowEvent, q as PassflowRefreshError, ie as PopupClosedError, je as Providers, Kn as RECOVERABLE_COMMIT_ERROR_IDS, mn as REFRESH_AUTH_FAILURE_IDS, K as RefreshErrorId, De as RequestMethod, c as SDK_VERSION, qn as SESSION_INVALIDATING_COMMIT_ERROR_IDS, te as SessionState, Je as SettingAPI, _ as TOKEN_EXPIRY_BUFFER_SECONDS, Ye as TenantAPI, Dr as TenantService, Er as TenantUserMembership, Or as TokenCacheService, M as TokenDeliveryMode, j as TokenType, Qe as TwoFactorApiClient, Fe as TwoFactorPolicy, kr as TwoFactorService, le as UPGRADE_REQUIRED, y as USERNAME_MAX_LENGTH, v as USERNAME_MIN_LENGTH, $e as UpgradeAPI, Ur as UpgradeCancelledError, En as UpgradeCommitInterruptedError, Qr as UpgradeController, Q as UpgradeErrorIds, jr as UpgradeFactorError, or as UpgradeInsufficientError, cr as UpgradeSessionChangedError, $ as UpgradeTransportError, sr as UpgradeUnavailableError, Wr as UpgradeUnsatisfiableError, et as UserAPI, Ar as UserService, ae as WebAdapter, rr as classifyUpgradeError, Lr as factorRegistry, ht as fetchRegistryState, Ne as getOSFromDeviceType, ar as invalidatesSessionOnCommit, Ae as isEmailVerificationStep, ir as isRecoverableCommitFailure, Yn as isRetryableUpgradeKind, k as isTokenExpired, Di as isUpgradeCancelled, Oi as isUpgradeExhausted, ki as isUpgradeInsufficient, Mi as isUpgradeSessionChanged, $n as isUpgradeTransportError, Ni as isUpgradeTransportFailure, ji as isUpgradeUnavailable, Ai as isUpgradeUnsatisfiable, pr as isValidEmail, dr as isValidJWTFormat, mr as isValidPhoneNumber, hr as isValidUsername, he as parseChallengeBody, me as parseChallengeHeader, A as parseToken, ye as parseUpgradeChallenge, Fr as passkeyFactor, Pe as pathWithParams, Pr as recoveryCodesFactor, mt as registerFetchMiddleware, L as requiredAcrLevel, ke as resolveUpgradeDomain, fr as sanitizeErrorMessage, Hr as selectFactors, Nr as totpFactor, P as webAdapter };
|
|
6402
6478
|
|
|
6403
6479
|
//# sourceMappingURL=index.mjs.map
|