@passflow/core 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +738 -519
- package/dist/index.mjs.map +1 -1
- package/dist/lib/api/axios-client.d.ts +9 -3
- package/dist/lib/api/axios-client.d.ts.map +1 -1
- package/dist/lib/api/model.d.ts +16 -1
- package/dist/lib/api/model.d.ts.map +1 -1
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/passflow.d.ts +2 -1
- package/dist/lib/passflow.d.ts.map +1 -1
- package/dist/lib/platform/index.d.ts +4 -0
- package/dist/lib/platform/index.d.ts.map +1 -0
- package/dist/lib/platform/types.d.ts +206 -0
- package/dist/lib/platform/types.d.ts.map +1 -0
- package/dist/lib/platform/web-adapter.d.ts +104 -0
- package/dist/lib/platform/web-adapter.d.ts.map +1 -0
- package/dist/lib/services/auth-service.d.ts +5 -4
- package/dist/lib/services/auth-service.d.ts.map +1 -1
- package/dist/lib/services/token-cache-service.d.ts +6 -4
- package/dist/lib/services/token-cache-service.d.ts.map +1 -1
- package/dist/lib/services/user-service.d.ts +3 -1
- package/dist/lib/services/user-service.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -4
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import F from "axios";
|
|
2
2
|
import { v4 as H } from "uuid";
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
version:
|
|
6
|
-
},
|
|
3
|
+
import { startAuthentication as z, startRegistration as X } from "@simplewebauthn/browser";
|
|
4
|
+
const W = "0.13.2", J = {
|
|
5
|
+
version: W
|
|
6
|
+
}, b = "X-Passflow-Clientid", I = "Authorization", Z = "X-Passflow-DeviceId", Q = "X-Passflow-DeviceType", ee = J.version, qe = ["id", "offline", "openid"], te = ["id", "offline", "tenant", "email", "oidc", "openid", "access:tenant:all"], K = "https://auth.passflow.cloud", Be = "default", re = 500, se = 600, ie = 100, oe = 6e4, G = 30, ne = 3, ae = 30, ce = 200, he = (i) => {
|
|
7
7
|
const e = [];
|
|
8
8
|
let t;
|
|
9
9
|
for (t in i) {
|
|
@@ -12,20 +12,20 @@ const z = "0.13.1", X = {
|
|
|
12
12
|
continue;
|
|
13
13
|
const s = { tenant: { id: r.tenant_id, name: r.tenant_name } };
|
|
14
14
|
s.groups = r.groups ? Object.keys(r.groups).map((o) => {
|
|
15
|
-
const
|
|
16
|
-
return { group: { id: o, name: r.group_names?.[o] ?? "unknown" }, roles:
|
|
15
|
+
const n = r.groups[o] || [];
|
|
16
|
+
return { group: { id: o, name: r.group_names?.[o] ?? "unknown" }, roles: n };
|
|
17
17
|
}) : [], s.tenantRoles = s.groups?.find((o) => o.group.id === r.root_group_id), e.push(s);
|
|
18
18
|
}
|
|
19
19
|
return { raw: i, tenants: e };
|
|
20
20
|
};
|
|
21
|
-
function
|
|
21
|
+
function de(i) {
|
|
22
22
|
if (typeof window < "u" && typeof window.atob == "function")
|
|
23
23
|
return window.atob(i);
|
|
24
24
|
if (typeof Buffer < "u")
|
|
25
25
|
return Buffer.from(i, "base64").toString("utf-8");
|
|
26
26
|
throw new Error("No Base64 decoding method available in this environment");
|
|
27
27
|
}
|
|
28
|
-
class
|
|
28
|
+
class ue {
|
|
29
29
|
constructor(e) {
|
|
30
30
|
this.storageManager = e;
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ class he {
|
|
|
38
38
|
isTokenTypeExpired(e) {
|
|
39
39
|
const t = this.storageManager.getToken(e);
|
|
40
40
|
if (!t) return !0;
|
|
41
|
-
const r =
|
|
41
|
+
const r = m(t);
|
|
42
42
|
return r ? S(r) : !0;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -51,22 +51,22 @@ class he {
|
|
|
51
51
|
parseTokenType(e) {
|
|
52
52
|
const t = this.storageManager.getToken(e);
|
|
53
53
|
if (t)
|
|
54
|
-
return
|
|
54
|
+
return m(t);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
function S(i, e = G) {
|
|
58
58
|
return Math.floor(Date.now() / 1e3) + e > i.exp;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function m(i) {
|
|
61
61
|
const e = i.split(".")[1];
|
|
62
62
|
if (!e) throw new Error("Invalid token string");
|
|
63
|
-
const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = t + "=".repeat((4 - t.length % 4) % 4), s =
|
|
64
|
-
s.split("").map((
|
|
65
|
-
),
|
|
66
|
-
return
|
|
63
|
+
const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = t + "=".repeat((4 - t.length % 4) % 4), s = de(r), o = decodeURIComponent(
|
|
64
|
+
s.split("").map((h) => "%" + ("00" + h.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
65
|
+
), n = JSON.parse(o);
|
|
66
|
+
return n.membership = n.passflow_tm && n.type !== "invite" ? he(n.passflow_tm) : void 0, n;
|
|
67
67
|
}
|
|
68
|
-
var
|
|
69
|
-
class
|
|
68
|
+
var k = /* @__PURE__ */ ((i) => (i.id_token = "id_token", i.access_token = "access", i.refresh_token = "refresh", i.invite_token = "invite", i.reset_token = "reset", i.web_cookie = "web-cookie", i.management = "management", i.signin = "signin", i.actor = "actor", i.two_factor = "2fa", i))(k || {}), y = /* @__PURE__ */ ((i) => (i.JsonBody = "json_body", i.Cookie = "cookie", i.Mobile = "mobile", i.BFF = "bff", i))(y || {}), V = /* @__PURE__ */ ((i) => (i.Unknown = "unknown", i.Valid = "valid", i.Invalid = "invalid", i))(V || {});
|
|
69
|
+
class q {
|
|
70
70
|
constructor(e) {
|
|
71
71
|
this.storageManager = e, this.mode = "json_body", this.sessionState = "unknown", this.isInitializedFlag = !1, this.STORAGE_PREFIX = "passflow_", this.DELIVERY_MODE_KEY = `${this.STORAGE_PREFIX}delivery_mode`, this.SESSION_STATE_KEY = `${this.STORAGE_PREFIX}session_state`, this.loadPersistedMode(), this.loadPersistedSessionState();
|
|
72
72
|
}
|
|
@@ -166,7 +166,7 @@ class Y {
|
|
|
166
166
|
loadPersistedMode() {
|
|
167
167
|
try {
|
|
168
168
|
const e = this.storageManager.storage.getItem(this.DELIVERY_MODE_KEY);
|
|
169
|
-
e && Object.values(
|
|
169
|
+
e && Object.values(y).includes(e) && (this.mode = e, this.isInitializedFlag = !0);
|
|
170
170
|
} catch {
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -176,7 +176,7 @@ class Y {
|
|
|
176
176
|
loadPersistedSessionState() {
|
|
177
177
|
try {
|
|
178
178
|
const e = this.storageManager.storage.getItem(this.SESSION_STATE_KEY);
|
|
179
|
-
e && Object.values(
|
|
179
|
+
e && Object.values(V).includes(e) && (this.sessionState = e);
|
|
180
180
|
} catch {
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -227,8 +227,8 @@ class $ {
|
|
|
227
227
|
* In JSON mode: save all tokens (existing behavior)
|
|
228
228
|
*/
|
|
229
229
|
saveTokens(e, t) {
|
|
230
|
-
const { id_token: r, access_token: s, refresh_token: o, scopes:
|
|
231
|
-
t ===
|
|
230
|
+
const { id_token: r, access_token: s, refresh_token: o, scopes: n } = e;
|
|
231
|
+
t === y.Cookie || t === y.BFF ? r && this.storage.setItem(this.ID_TOKEN_KEY, r) : (r && this.storage.setItem(this.getKeyForTokenType(k.id_token), r), s && this.storage.setItem(this.getKeyForTokenType(k.access_token), s), o && this.storage.setItem(this.getKeyForTokenType(k.refresh_token), o), n && this.storage.setItem(this.scopes, n.join(",")));
|
|
232
232
|
}
|
|
233
233
|
getToken(e) {
|
|
234
234
|
const t = this.getKeyForTokenType(e);
|
|
@@ -241,19 +241,19 @@ class $ {
|
|
|
241
241
|
*/
|
|
242
242
|
getTokens() {
|
|
243
243
|
const e = this.getDeliveryMode();
|
|
244
|
-
if (e ===
|
|
244
|
+
if (e === y.Cookie || e === y.BFF) {
|
|
245
245
|
const r = this.storage.getItem(this.ID_TOKEN_KEY);
|
|
246
246
|
return r ? {
|
|
247
247
|
id_token: r
|
|
248
248
|
// access_token and refresh_token are in HttpOnly cookies, not localStorage
|
|
249
249
|
} : void 0;
|
|
250
250
|
}
|
|
251
|
-
const t = this.storage.getItem(this.getKeyForTokenType(
|
|
251
|
+
const t = this.storage.getItem(this.getKeyForTokenType(k.access_token));
|
|
252
252
|
if (t)
|
|
253
253
|
return {
|
|
254
254
|
access_token: t,
|
|
255
|
-
id_token: this.storage.getItem(this.getKeyForTokenType(
|
|
256
|
-
refresh_token: this.storage.getItem(this.getKeyForTokenType(
|
|
255
|
+
id_token: this.storage.getItem(this.getKeyForTokenType(k.id_token)) ?? void 0,
|
|
256
|
+
refresh_token: this.storage.getItem(this.getKeyForTokenType(k.refresh_token)) ?? void 0,
|
|
257
257
|
scopes: this.storage.getItem(this.scopes)?.split(",") ?? void 0
|
|
258
258
|
};
|
|
259
259
|
}
|
|
@@ -265,7 +265,7 @@ class $ {
|
|
|
265
265
|
* Used to detect stale state where delivery_mode is set but JSON tokens exist
|
|
266
266
|
*/
|
|
267
267
|
hasJsonModeTokens() {
|
|
268
|
-
return !!this.storage.getItem(this.getKeyForTokenType(
|
|
268
|
+
return !!this.storage.getItem(this.getKeyForTokenType(k.access_token));
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
271
271
|
* Check if cookie mode ID token exists in storage
|
|
@@ -279,7 +279,7 @@ class $ {
|
|
|
279
279
|
this.storage.removeItem(t);
|
|
280
280
|
}
|
|
281
281
|
deleteTokens() {
|
|
282
|
-
this.storage.removeItem(this.getKeyForTokenType(
|
|
282
|
+
this.storage.removeItem(this.getKeyForTokenType(k.id_token)), this.storage.removeItem(this.getKeyForTokenType(k.access_token)), this.storage.removeItem(this.getKeyForTokenType(k.refresh_token)), this.storage.removeItem(this.scopes), this.clearIdToken(), this.clearDeliveryMode(), this.clearCsrfToken();
|
|
283
283
|
}
|
|
284
284
|
getDeviceId() {
|
|
285
285
|
return this.storage.getItem(this.deviceId) ?? void 0;
|
|
@@ -324,7 +324,7 @@ class $ {
|
|
|
324
324
|
getDeliveryMode() {
|
|
325
325
|
try {
|
|
326
326
|
const e = this.storage.getItem(this.DELIVERY_MODE_KEY);
|
|
327
|
-
if (e && Object.values(
|
|
327
|
+
if (e && Object.values(y).includes(e))
|
|
328
328
|
return e;
|
|
329
329
|
} catch {
|
|
330
330
|
}
|
|
@@ -416,84 +416,308 @@ class B {
|
|
|
416
416
|
return H();
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
|
|
420
|
-
|
|
419
|
+
class Y extends Error {
|
|
420
|
+
constructor(e = "Authentication popup was closed") {
|
|
421
|
+
super(e), this.name = "PopupClosedError";
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
class le {
|
|
425
|
+
constructor() {
|
|
426
|
+
this.passkeys = {
|
|
427
|
+
startRegistration: (e) => X({ optionsJSON: e }),
|
|
428
|
+
startAuthentication: (e) => z({ optionsJSON: e })
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
// ----------------------------------------------------------------
|
|
432
|
+
// Storage
|
|
433
|
+
// Replaces: StorageManager constructor default `storage ?? localStorage`
|
|
434
|
+
// File: lib/storage/index.ts line 41
|
|
435
|
+
// ----------------------------------------------------------------
|
|
436
|
+
get storage() {
|
|
437
|
+
return typeof localStorage > "u" ? {
|
|
438
|
+
getItem: () => null,
|
|
439
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op for SSR
|
|
440
|
+
setItem: () => {
|
|
441
|
+
},
|
|
442
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op for SSR
|
|
443
|
+
removeItem: () => {
|
|
444
|
+
}
|
|
445
|
+
} : localStorage;
|
|
446
|
+
}
|
|
447
|
+
// ----------------------------------------------------------------
|
|
448
|
+
// Navigation
|
|
449
|
+
// ----------------------------------------------------------------
|
|
450
|
+
/**
|
|
451
|
+
* Replaces:
|
|
452
|
+
* window.location.origin (passflow.ts:95, axios-client.ts:49)
|
|
453
|
+
* window.location.search (passflow.ts:338,416, auth-service.ts:610,826)
|
|
454
|
+
* window.location.hash (passflow.ts:342)
|
|
455
|
+
* window.location.href (auth-service.ts:826)
|
|
456
|
+
* window.location.pathname (passflow.ts:429,441,443)
|
|
457
|
+
* window?.location?.hostname (user-service.ts:57)
|
|
458
|
+
*/
|
|
459
|
+
getCurrentUrl() {
|
|
460
|
+
return typeof window > "u" ? null : {
|
|
461
|
+
href: window.location.href,
|
|
462
|
+
origin: window.location.origin,
|
|
463
|
+
pathname: window.location.pathname,
|
|
464
|
+
search: window.location.search,
|
|
465
|
+
hash: window.location.hash,
|
|
466
|
+
hostname: window.location.hostname
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Replaces:
|
|
471
|
+
* window.history.replaceState({}, document.title, ...)
|
|
472
|
+
* (passflow.ts:429, 441, 443)
|
|
473
|
+
*/
|
|
474
|
+
replaceUrl(e) {
|
|
475
|
+
typeof window > "u" || window.history.replaceState({}, document.title, e);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Replaces:
|
|
479
|
+
* window.location.href = url
|
|
480
|
+
* (auth-service.ts:795, 813, 845, passflow.ts indirectly)
|
|
481
|
+
*/
|
|
482
|
+
navigateTo(e) {
|
|
483
|
+
typeof window > "u" || (window.location.href = e);
|
|
484
|
+
}
|
|
485
|
+
// ----------------------------------------------------------------
|
|
486
|
+
// Lifecycle
|
|
487
|
+
// ----------------------------------------------------------------
|
|
488
|
+
/**
|
|
489
|
+
* Replaces:
|
|
490
|
+
* document.addEventListener('visibilitychange', handler) where !document.hidden
|
|
491
|
+
* (token-cache-service.ts:134-145)
|
|
492
|
+
*/
|
|
493
|
+
onForeground(e) {
|
|
494
|
+
if (typeof document > "u")
|
|
495
|
+
return () => {
|
|
496
|
+
};
|
|
497
|
+
const t = () => {
|
|
498
|
+
document.hidden || e();
|
|
499
|
+
};
|
|
500
|
+
return document.addEventListener("visibilitychange", t), () => document.removeEventListener("visibilitychange", t);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Replaces:
|
|
504
|
+
* document.addEventListener('visibilitychange', handler) where document.hidden
|
|
505
|
+
* (token-cache-service.ts:134-145, complementary to onForeground)
|
|
506
|
+
*
|
|
507
|
+
* NOTE: Not currently called by the SDK. Included in the interface for
|
|
508
|
+
* React Native adapter compatibility (future use).
|
|
509
|
+
*/
|
|
510
|
+
onBackground(e) {
|
|
511
|
+
if (typeof document > "u")
|
|
512
|
+
return () => {
|
|
513
|
+
};
|
|
514
|
+
const t = () => {
|
|
515
|
+
document.hidden && e();
|
|
516
|
+
};
|
|
517
|
+
return document.addEventListener("visibilitychange", t), () => document.removeEventListener("visibilitychange", t);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Replaces:
|
|
521
|
+
* window.addEventListener('beforeunload', ...)
|
|
522
|
+
* (token-cache-service.ts:151)
|
|
523
|
+
*/
|
|
524
|
+
onBeforeUnload(e) {
|
|
525
|
+
return typeof window > "u" ? () => {
|
|
526
|
+
} : (window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e));
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Replaces:
|
|
530
|
+
* typeof document !== 'undefined' && document.hidden
|
|
531
|
+
* (token-cache-service.ts:112)
|
|
532
|
+
*/
|
|
533
|
+
isInForeground() {
|
|
534
|
+
return typeof document > "u" ? !0 : !document.hidden;
|
|
535
|
+
}
|
|
536
|
+
// ----------------------------------------------------------------
|
|
537
|
+
// Auth UI
|
|
538
|
+
// ----------------------------------------------------------------
|
|
539
|
+
/**
|
|
540
|
+
* Replaces:
|
|
541
|
+
* window.open(passflowURL, '_blank', `width=...,height=...`)
|
|
542
|
+
* + polling loop with popupWindow.location.href/search
|
|
543
|
+
* + window.location.href = origin (post-auth redirect)
|
|
544
|
+
* (auth-service.ts:741-805)
|
|
545
|
+
*
|
|
546
|
+
* window.location.href = passflowURL (redirect mode)
|
|
547
|
+
* (auth-service.ts:813)
|
|
548
|
+
*/
|
|
549
|
+
openAuthUrl(e, t = {}) {
|
|
550
|
+
const r = t.mode ?? "popup";
|
|
551
|
+
if (r === "redirect")
|
|
552
|
+
return window.location.href = e, new Promise(() => {
|
|
553
|
+
});
|
|
554
|
+
if (r === "deeplink")
|
|
555
|
+
return Promise.reject(
|
|
556
|
+
new Error(
|
|
557
|
+
'openAuthUrl: "deeplink" mode is not supported on web. Use "popup" or "redirect" instead, or provide a native platform adapter.'
|
|
558
|
+
)
|
|
559
|
+
);
|
|
560
|
+
const s = t.width ?? re, o = t.height ?? se, n = t.expectedReturnOrigin ?? window.location.origin, h = window.open(e, "_blank", `width=${s},height=${o}`);
|
|
561
|
+
return h ? new Promise((d, u) => {
|
|
562
|
+
const g = Date.now(), f = setInterval(() => {
|
|
563
|
+
if (h.closed) {
|
|
564
|
+
clearInterval(f), u(new Y());
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (Date.now() - g > oe) {
|
|
568
|
+
clearInterval(f), h.close(), u(new Error("Authentication popup timed out"));
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
if (h.location.href.startsWith(n)) {
|
|
573
|
+
const M = h.location.search, j = h.location.hash;
|
|
574
|
+
clearInterval(f), h.close(), d({ callbackSearch: M, callbackHash: j });
|
|
575
|
+
}
|
|
576
|
+
} catch {
|
|
577
|
+
}
|
|
578
|
+
}, ie);
|
|
579
|
+
}) : (window.location.href = e, new Promise(() => {
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
// ----------------------------------------------------------------
|
|
583
|
+
// Base64
|
|
584
|
+
// ----------------------------------------------------------------
|
|
585
|
+
/**
|
|
586
|
+
* Replaces:
|
|
587
|
+
* btoa(publicKey.user.id)
|
|
588
|
+
* (auth-service.ts:644, user-service.ts:64)
|
|
589
|
+
*/
|
|
590
|
+
btoa(e) {
|
|
591
|
+
return btoa(e);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Replaces:
|
|
595
|
+
* window.atob(base64) / Buffer.from(base64, 'base64').toString('utf-8')
|
|
596
|
+
* (token/service.ts:26-27)
|
|
597
|
+
*/
|
|
598
|
+
atob(e) {
|
|
599
|
+
if (typeof window < "u" && typeof window.atob == "function")
|
|
600
|
+
return window.atob(e);
|
|
601
|
+
if (typeof Buffer < "u")
|
|
602
|
+
return Buffer.from(e, "base64").toString("utf-8");
|
|
603
|
+
throw new Error("No Base64 decoding method available in this environment");
|
|
604
|
+
}
|
|
605
|
+
// ----------------------------------------------------------------
|
|
606
|
+
// Cookies
|
|
607
|
+
// ----------------------------------------------------------------
|
|
608
|
+
/**
|
|
609
|
+
* Replaces:
|
|
610
|
+
* document.cookie write/read test
|
|
611
|
+
* (axios-client.ts:221-223)
|
|
612
|
+
*/
|
|
613
|
+
cookiesSupported() {
|
|
614
|
+
if (typeof document > "u") return !1;
|
|
615
|
+
try {
|
|
616
|
+
document.cookie = "passflow_test=1; SameSite=Lax";
|
|
617
|
+
const e = document.cookie.indexOf("passflow_test=1") !== -1;
|
|
618
|
+
return document.cookie = "passflow_test=; expires=Thu, 01 Jan 1970 00:00:00 UTC", e;
|
|
619
|
+
} catch {
|
|
620
|
+
return !1;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
// ----------------------------------------------------------------
|
|
624
|
+
// Device
|
|
625
|
+
// ----------------------------------------------------------------
|
|
626
|
+
/**
|
|
627
|
+
* Replaces:
|
|
628
|
+
* Hardcoded 'web' string in DEVICE_TYPE_HEADER_KEY header
|
|
629
|
+
* (axios-client.ts:91)
|
|
630
|
+
* OS.web enum value (auth-service.ts:244, 358, 637, 676, user-service.ts:55)
|
|
631
|
+
*/
|
|
632
|
+
getDeviceType() {
|
|
633
|
+
return "web";
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
const A = new le();
|
|
637
|
+
var _ = /* @__PURE__ */ ((i) => (i.GET = "get", i.POST = "post", i.PUT = "put", i.PATCH = "patch", i.DELETE = "delete", i))(_ || {}), c = /* @__PURE__ */ ((i) => (i.signin = "/auth/login", i.signup = "/auth/register", i.signInWithProvider = "/auth/federated/start/", i.passwordless = "/auth/passwordless/start", i.passwordlessComplete = "/auth/passwordless/complete", i.logout = "/user/logout", i.refresh = "/auth/refresh", i.validateSession = "/user/me", i.sendPasswordResetEmail = "/auth/password/reset", i.resetPassword = "/auth/password/change", i.appSettings = "/app/settings", i.passkeyRegisterStart = "/auth/passkey/register/start", i.passkeyRegisterComplete = "/auth/passkey/register/complete", i.passkeyAuthenticateStart = "/auth/passkey/authenticate/start", i.passkeyAuthenticateComplete = "/auth/passkey/authenticate/complete", i.passkeyValidate = "/auth/validate", i.settingsAll = "/settings", i.settingsPasswordPolicy = "/settings/password", i.settingsPasskey = "/settings/passkey", i.userPasskey = "/user/passkey", i.addUserPasskey = "/user/passkey/add/start", i.completeAddUserPasskey = "/user/passkey/add/complete", i.joinInvitation = "/user/tenant/join", i.tenantPath = "/user/tenant", i.invitationsPath = "/user/tenant/:tenantID/invitations", i.requestInvitation = "/user/invite", i.invitationDelete = "/user/invite/:invitationID", i.invitationResend = "/user/invite/:invitationID/resend", i.invitationGetLink = "/user/invite/:invitationID/link", i.twoFactor = "/user/2fa", i.twoFactorStatus = "/user/2fa/status", i.twoFactorSetupBegin = "/user/2fa/setup/begin", i.twoFactorSetupConfirm = "/user/2fa/setup/confirm", i.twoFactorVerify = "/auth/2fa/verify", i.twoFactorRecovery = "/auth/2fa/recovery", i.twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate", i.twoFactorSetupMagicLink = "/auth/2fa-setup", i.TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available", i.TwoFactorMethodsRegistered = "/v2/user/2fa/methods", i.TwoFactorMethodSetupBegin = "/v2/user/2fa/methods/:method/setup/begin", i.TwoFactorMethodSetupConfirm = "/v2/user/2fa/methods/:method/setup/confirm", i.TwoFactorMethodRemove = "/v2/user/2fa/methods/:id", i.TwoFactorChallenge = "/v2/auth/2fa/challenge", i.TwoFactorVerifyV2 = "/v2/auth/2fa/verify", i.TwoFactorAlternative = "/v2/auth/2fa/alternative", i.TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices", i.TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id", i.cliAuthStatus = "/cli/auth/status/:sessionId", i.cliAuthComplete = "/cli/auth/complete", i))(c || {}), E = /* @__PURE__ */ ((i) => (i.passkeyRegisterStart = "/admin/auth/passkey/register/start", i.passkeyRegisterComplete = "/admin/auth/passkey/register/complete", i.passkeyAuthenticateStart = "/admin/auth/passkey/authenticate/start", i.passkeyAuthenticateComplete = "/admin/auth/passkey/authenticate/complete", i.passkeyValidate = "/admin/auth/validate", i.logout = "/admin/auth/logout", i))(E || {});
|
|
638
|
+
class l extends Error {
|
|
421
639
|
constructor(e) {
|
|
422
640
|
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();
|
|
423
641
|
}
|
|
424
642
|
}
|
|
425
|
-
var
|
|
426
|
-
function
|
|
643
|
+
var pe = /* @__PURE__ */ ((i) => (i.google = "google", i.facebook = "facebook", i))(pe || {}), ge = /* @__PURE__ */ ((i) => (i.web = "web", i.ios = "ios", i.android = "android", i))(ge || {});
|
|
644
|
+
function Ye(i) {
|
|
645
|
+
return i;
|
|
646
|
+
}
|
|
647
|
+
function v(i, e) {
|
|
427
648
|
let t = i;
|
|
428
649
|
return Object.entries(e).forEach(([r, s]) => {
|
|
429
650
|
t = t.replace(`:${r}`, s);
|
|
430
651
|
}), t;
|
|
431
652
|
}
|
|
432
|
-
var
|
|
433
|
-
const
|
|
653
|
+
var fe = /* @__PURE__ */ ((i) => (i.Disabled = "disabled", i.Optional = "optional", i.Required = "required", i))(fe || {});
|
|
654
|
+
const ke = 3, me = 1e3;
|
|
434
655
|
class w {
|
|
435
656
|
constructor(e, t, r) {
|
|
436
|
-
this.refreshPromise = null, this.isRefreshing = !1, this.
|
|
657
|
+
this.refreshPromise = null, this.isRefreshing = !1, this.defaultHeaders = {
|
|
437
658
|
Accept: "application/json",
|
|
438
659
|
"Content-Type": "application/json"
|
|
439
660
|
}, this.nonAccessTokenEndpoints = ["/auth/", "/settings", "/settings/"], this.protectedEndpoints = ["logout", "refresh"];
|
|
440
|
-
const { url: s, appId: o, keyStoragePrefix:
|
|
441
|
-
this.url = s ||
|
|
442
|
-
prefix:
|
|
443
|
-
}), this.deviceService = r ?? new B(this.storageManager), this.tokenService = new
|
|
661
|
+
const { url: s, appId: o, keyStoragePrefix: n } = e;
|
|
662
|
+
this._platform = e.platform ?? A, this.url = s || K, this.storageManager = t ?? new $({
|
|
663
|
+
prefix: n ?? ""
|
|
664
|
+
}), this.deviceService = r ?? new B(this.storageManager), this.tokenService = new ue(this.storageManager), this.tokenDeliveryManager = new q(this.storageManager), o && (this.appId = o, this.defaultHeaders = {
|
|
444
665
|
...this.defaultHeaders,
|
|
445
|
-
[
|
|
666
|
+
[b]: o
|
|
446
667
|
});
|
|
447
|
-
const
|
|
668
|
+
const h = this.deviceService.getDeviceId();
|
|
448
669
|
this.defaultHeaders = {
|
|
449
670
|
...this.defaultHeaders,
|
|
450
|
-
[
|
|
451
|
-
[
|
|
671
|
+
[Z]: h,
|
|
672
|
+
[Q]: this._platform.getDeviceType()
|
|
452
673
|
}, this.detectCookieSupport(), this.instance = F.create({
|
|
453
674
|
baseURL: this.url,
|
|
454
675
|
headers: { ...this.defaultHeaders }
|
|
455
|
-
}), this.instance.interceptors.request.use(async (
|
|
456
|
-
if (this.isNonAuthEndpoint(
|
|
457
|
-
return
|
|
676
|
+
}), this.instance.interceptors.request.use(async (d) => {
|
|
677
|
+
if (this.isNonAuthEndpoint(d.url))
|
|
678
|
+
return d;
|
|
458
679
|
if (this.tokenDeliveryManager.isCookieMode()) {
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
return
|
|
680
|
+
d.withCredentials = !0;
|
|
681
|
+
const g = this.storageManager.getCsrfToken();
|
|
682
|
+
return g && (d.headers["X-CSRF-Token"] = g), d;
|
|
462
683
|
}
|
|
463
|
-
if (
|
|
684
|
+
if (d.url?.includes("refresh")) {
|
|
464
685
|
if (this.isRefreshing) {
|
|
465
|
-
const
|
|
466
|
-
return
|
|
686
|
+
const g = new AbortController();
|
|
687
|
+
return g.abort(), d.signal = g.signal, d;
|
|
467
688
|
}
|
|
468
|
-
return
|
|
689
|
+
return d;
|
|
469
690
|
}
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
472
|
-
const
|
|
473
|
-
if (S(
|
|
691
|
+
const u = this.storageManager.getTokens();
|
|
692
|
+
if (u?.access_token) {
|
|
693
|
+
const g = m(u.access_token);
|
|
694
|
+
if (S(g, G) && u.refresh_token)
|
|
474
695
|
try {
|
|
475
696
|
if (this.refreshPromise) {
|
|
476
|
-
const
|
|
477
|
-
return
|
|
697
|
+
const f = await this.refreshPromise;
|
|
698
|
+
return f?.data?.access_token && (d.headers[I] = `Bearer ${f.data.access_token}`), d;
|
|
478
699
|
}
|
|
479
700
|
this.refreshPromise = this.refreshTokens();
|
|
480
701
|
try {
|
|
481
|
-
const
|
|
482
|
-
return
|
|
702
|
+
const f = await this.refreshPromise;
|
|
703
|
+
return f?.data?.access_token && (d.headers[I] = `Bearer ${f.data.access_token}`), d;
|
|
483
704
|
} finally {
|
|
484
705
|
this.refreshPromise = null;
|
|
485
706
|
}
|
|
486
|
-
} catch (
|
|
487
|
-
return this.refreshPromise = null, this.isRefreshing = !1, this.storageManager.deleteTokens(), Promise.reject(
|
|
707
|
+
} catch (f) {
|
|
708
|
+
return this.refreshPromise = null, this.isRefreshing = !1, this.storageManager.deleteTokens(), Promise.reject(f);
|
|
488
709
|
}
|
|
489
|
-
return
|
|
710
|
+
return d.headers[I] = `Bearer ${u.access_token}`, d;
|
|
490
711
|
}
|
|
491
|
-
return
|
|
712
|
+
return d;
|
|
492
713
|
}), this.instance.interceptors.response.use(
|
|
493
|
-
(
|
|
494
|
-
async (
|
|
714
|
+
(d) => d,
|
|
715
|
+
async (d) => (d.response?.status === 401 && this.tokenDeliveryManager.setSessionInvalid(), d.response?.status === 429 ? await this.handleRateLimitError(d) : this.handleAxiosError(d))
|
|
495
716
|
);
|
|
496
717
|
}
|
|
718
|
+
get origin() {
|
|
719
|
+
return this._platform.getCurrentUrl()?.origin ?? "";
|
|
720
|
+
}
|
|
497
721
|
isProtectedEndpoint(e) {
|
|
498
722
|
return this.protectedEndpoints.some((t) => e?.includes(t));
|
|
499
723
|
}
|
|
@@ -501,17 +725,19 @@ class w {
|
|
|
501
725
|
return this.nonAccessTokenEndpoints.some((t) => e?.includes(t)) && !this.isProtectedEndpoint(e);
|
|
502
726
|
}
|
|
503
727
|
/**
|
|
504
|
-
* Detect if cookies are supported/enabled in the browser
|
|
505
|
-
*
|
|
728
|
+
* Detect if cookies are supported/enabled in the browser.
|
|
729
|
+
* If cookie mode is already active (restored from storage) and cookies are not
|
|
730
|
+
* supported, throws immediately to prevent silent misconfiguration.
|
|
731
|
+
*
|
|
732
|
+
* Note: If cookie mode is set later (e.g., server responds with token_delivery=cookie
|
|
733
|
+
* on a non-cookie platform), this check will not catch it. The server should not
|
|
734
|
+
* configure cookie mode for platforms where cookiesSupported() returns false.
|
|
506
735
|
*/
|
|
507
736
|
detectCookieSupport() {
|
|
508
|
-
if (!(
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
document.cookie = "passflow_test=; expires=Thu, 01 Jan 1970 00:00:00 UTC", !e && this.tokenDeliveryManager.isCookieMode();
|
|
513
|
-
} catch {
|
|
514
|
-
}
|
|
737
|
+
if (!this._platform.cookiesSupported() && this.tokenDeliveryManager.isCookieMode())
|
|
738
|
+
throw new Error(
|
|
739
|
+
"Passflow SDK: Cookie delivery mode is configured but cookies are not supported in this environment. Use a platform adapter that supports cookies or configure the server to use JSON token delivery."
|
|
740
|
+
);
|
|
515
741
|
}
|
|
516
742
|
/**
|
|
517
743
|
* Refresh tokens using single-flight pattern to prevent race conditions
|
|
@@ -550,20 +776,20 @@ class w {
|
|
|
550
776
|
if (!["GET", "HEAD", "OPTIONS"].includes(r || ""))
|
|
551
777
|
return Promise.reject(e);
|
|
552
778
|
const o = t._retryCount || 0;
|
|
553
|
-
if (o >=
|
|
779
|
+
if (o >= ke)
|
|
554
780
|
return Promise.reject(e);
|
|
555
|
-
let
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
558
|
-
const
|
|
559
|
-
if (!Number.isNaN(
|
|
560
|
-
|
|
781
|
+
let n = me * Math.pow(2, o);
|
|
782
|
+
const h = e.response?.headers?.["retry-after"];
|
|
783
|
+
if (h) {
|
|
784
|
+
const d = Number.parseInt(h, 10);
|
|
785
|
+
if (!Number.isNaN(d))
|
|
786
|
+
n = d * 1e3;
|
|
561
787
|
else {
|
|
562
|
-
const
|
|
563
|
-
Number.isNaN(
|
|
788
|
+
const u = new Date(h);
|
|
789
|
+
Number.isNaN(u.getTime()) || (n = Math.max(0, u.getTime() - Date.now()));
|
|
564
790
|
}
|
|
565
791
|
}
|
|
566
|
-
return await new Promise((
|
|
792
|
+
return await new Promise((d) => setTimeout(d, n)), t._retryCount = o + 1, this.instance.request(t);
|
|
567
793
|
}
|
|
568
794
|
// eslint-disable-next-line complexity
|
|
569
795
|
// biome-ignore lint/suspicious/useAwait: <explanation>
|
|
@@ -573,10 +799,10 @@ class w {
|
|
|
573
799
|
const t = e.response.status, r = e.response.data;
|
|
574
800
|
if ("error" in r && typeof r.error == "object" && r.error !== null) {
|
|
575
801
|
const { error: s } = r;
|
|
576
|
-
return Promise.reject(new
|
|
802
|
+
return Promise.reject(new l(s));
|
|
577
803
|
}
|
|
578
804
|
return Promise.reject(
|
|
579
|
-
new
|
|
805
|
+
new l({
|
|
580
806
|
id: `error.http.${t}`,
|
|
581
807
|
message: e.message || "An error occurred",
|
|
582
808
|
status: t,
|
|
@@ -593,19 +819,19 @@ class w {
|
|
|
593
819
|
})).data;
|
|
594
820
|
}
|
|
595
821
|
get(e, t) {
|
|
596
|
-
return this.send(
|
|
822
|
+
return this.send(_.GET, e, t);
|
|
597
823
|
}
|
|
598
824
|
post(e, t, r) {
|
|
599
|
-
return this.send(
|
|
825
|
+
return this.send(_.POST, e, { data: t, ...r });
|
|
600
826
|
}
|
|
601
827
|
put(e, t, r) {
|
|
602
|
-
return this.send(
|
|
828
|
+
return this.send(_.PUT, e, { data: t, ...r });
|
|
603
829
|
}
|
|
604
830
|
patch(e, t, r) {
|
|
605
|
-
return this.send(
|
|
831
|
+
return this.send(_.PATCH, e, { data: t, ...r });
|
|
606
832
|
}
|
|
607
833
|
delete(e, t) {
|
|
608
|
-
return this.send(
|
|
834
|
+
return this.send(_.DELETE, e, t);
|
|
609
835
|
}
|
|
610
836
|
/**
|
|
611
837
|
* Update the appId and propagate it to axios headers.
|
|
@@ -616,11 +842,11 @@ class w {
|
|
|
616
842
|
setAppId(e) {
|
|
617
843
|
this.appId = e, this.defaultHeaders = {
|
|
618
844
|
...this.defaultHeaders,
|
|
619
|
-
[
|
|
620
|
-
}, this.instance.defaults.headers.common[
|
|
845
|
+
[b]: e
|
|
846
|
+
}, this.instance.defaults.headers.common[b] = e;
|
|
621
847
|
}
|
|
622
848
|
}
|
|
623
|
-
class
|
|
849
|
+
class ve {
|
|
624
850
|
constructor(e, t, r) {
|
|
625
851
|
this.axiosClient = new w(e, t, r);
|
|
626
852
|
}
|
|
@@ -631,7 +857,7 @@ class pe {
|
|
|
631
857
|
return this.axiosClient.get(c.appSettings);
|
|
632
858
|
}
|
|
633
859
|
}
|
|
634
|
-
class
|
|
860
|
+
class ye {
|
|
635
861
|
constructor(e, t, r) {
|
|
636
862
|
this.axiosClient = new w(e, t, r);
|
|
637
863
|
}
|
|
@@ -690,7 +916,7 @@ class fe {
|
|
|
690
916
|
);
|
|
691
917
|
}
|
|
692
918
|
logOut(e, t, r = !1) {
|
|
693
|
-
const s = r ? void 0 : { refresh_token: t, device: e }, o = r ?
|
|
919
|
+
const s = r ? void 0 : { refresh_token: t, device: e }, o = r ? E.logout : c.logout;
|
|
694
920
|
return this.axiosClient.post(o, s);
|
|
695
921
|
}
|
|
696
922
|
validateSession() {
|
|
@@ -710,26 +936,26 @@ class fe {
|
|
|
710
936
|
return this.axiosClient.post(c.resetPassword, s, {
|
|
711
937
|
headers: {
|
|
712
938
|
[I]: `Bearer ${r}`,
|
|
713
|
-
[
|
|
939
|
+
[b]: void 0
|
|
714
940
|
}
|
|
715
941
|
});
|
|
716
942
|
}
|
|
717
943
|
passkeyRegisterStart(e, t, r, s = !1) {
|
|
718
|
-
const { create_tenant: o } = e,
|
|
944
|
+
const { create_tenant: o } = e, n = {
|
|
719
945
|
...e,
|
|
720
946
|
create_tenant: o ?? !1,
|
|
721
947
|
device: t,
|
|
722
948
|
os: r
|
|
723
|
-
},
|
|
724
|
-
return this.axiosClient.post(
|
|
949
|
+
}, h = s ? E.passkeyRegisterStart : c.passkeyRegisterStart;
|
|
950
|
+
return this.axiosClient.post(h, n);
|
|
725
951
|
}
|
|
726
952
|
passkeyRegisterComplete(e, t, r, s = !1) {
|
|
727
953
|
const o = {
|
|
728
954
|
challenge_id: r,
|
|
729
955
|
device: t,
|
|
730
956
|
passkey_data: e
|
|
731
|
-
},
|
|
732
|
-
return this.axiosClient.post(
|
|
957
|
+
}, n = s ? E.passkeyRegisterComplete : c.passkeyRegisterComplete;
|
|
958
|
+
return this.axiosClient.post(n, o);
|
|
733
959
|
}
|
|
734
960
|
passkeyAuthenticateStart(e, t, r, s = !1) {
|
|
735
961
|
const o = {
|
|
@@ -737,9 +963,9 @@ class fe {
|
|
|
737
963
|
user_id: e.user_id ?? "",
|
|
738
964
|
device: t,
|
|
739
965
|
os: r
|
|
740
|
-
},
|
|
966
|
+
}, n = s ? E.passkeyAuthenticateStart : c.passkeyAuthenticateStart;
|
|
741
967
|
return this.axiosClient.post(
|
|
742
|
-
|
|
968
|
+
n,
|
|
743
969
|
o
|
|
744
970
|
);
|
|
745
971
|
}
|
|
@@ -748,22 +974,22 @@ class fe {
|
|
|
748
974
|
challenge_id: r,
|
|
749
975
|
device: t,
|
|
750
976
|
passkey_data: e
|
|
751
|
-
},
|
|
752
|
-
return this.axiosClient.post(
|
|
977
|
+
}, n = s ? E.passkeyAuthenticateComplete : c.passkeyAuthenticateComplete;
|
|
978
|
+
return this.axiosClient.post(n, o);
|
|
753
979
|
}
|
|
754
980
|
passkeyValidate(e, t, r, s = !1, o) {
|
|
755
|
-
const
|
|
981
|
+
const n = {
|
|
756
982
|
otp: e,
|
|
757
983
|
device: t,
|
|
758
984
|
challenge_id: r
|
|
759
985
|
};
|
|
760
|
-
let
|
|
761
|
-
!o && s && (
|
|
762
|
-
const
|
|
763
|
-
return this.axiosClient.post(
|
|
986
|
+
let h = c.passkeyValidate;
|
|
987
|
+
!o && s && (h = E.passkeyValidate);
|
|
988
|
+
const d = o ? { [b]: o } : {};
|
|
989
|
+
return this.axiosClient.post(h, n, { headers: d });
|
|
764
990
|
}
|
|
765
991
|
}
|
|
766
|
-
class
|
|
992
|
+
class je {
|
|
767
993
|
constructor(e, t, r) {
|
|
768
994
|
this.axiosClient = new w(e, t, r);
|
|
769
995
|
}
|
|
@@ -771,14 +997,14 @@ class Ve {
|
|
|
771
997
|
this.axiosClient.setAppId(e);
|
|
772
998
|
}
|
|
773
999
|
getCLIAuthStatus(e) {
|
|
774
|
-
const t =
|
|
1000
|
+
const t = v(c.cliAuthStatus, { sessionId: e });
|
|
775
1001
|
return this.axiosClient.get(t);
|
|
776
1002
|
}
|
|
777
1003
|
completeCLIAuth(e) {
|
|
778
1004
|
return this.axiosClient.post(c.cliAuthComplete, e);
|
|
779
1005
|
}
|
|
780
1006
|
}
|
|
781
|
-
class
|
|
1007
|
+
class Se {
|
|
782
1008
|
constructor(e, t, r) {
|
|
783
1009
|
this.axiosClient = new w(e, t, r);
|
|
784
1010
|
}
|
|
@@ -804,7 +1030,7 @@ class ke {
|
|
|
804
1030
|
getInvitations(e) {
|
|
805
1031
|
const t = {};
|
|
806
1032
|
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());
|
|
807
|
-
const r =
|
|
1033
|
+
const r = v(c.invitationsPath, {
|
|
808
1034
|
tenantID: e.tenantID
|
|
809
1035
|
});
|
|
810
1036
|
return this.axiosClient.get(r, { params: t }).then((s) => ({
|
|
@@ -818,7 +1044,7 @@ class ke {
|
|
|
818
1044
|
* @returns Promise with success response
|
|
819
1045
|
*/
|
|
820
1046
|
deleteInvitation(e) {
|
|
821
|
-
const t =
|
|
1047
|
+
const t = v(c.invitationDelete, {
|
|
822
1048
|
invitationID: e
|
|
823
1049
|
});
|
|
824
1050
|
return this.axiosClient.delete(t);
|
|
@@ -829,7 +1055,7 @@ class ke {
|
|
|
829
1055
|
* @returns Promise with success response
|
|
830
1056
|
*/
|
|
831
1057
|
resendInvitation(e) {
|
|
832
|
-
const t =
|
|
1058
|
+
const t = v(c.invitationResend, {
|
|
833
1059
|
invitationID: e
|
|
834
1060
|
});
|
|
835
1061
|
return this.axiosClient.post(t, {});
|
|
@@ -840,13 +1066,13 @@ class ke {
|
|
|
840
1066
|
* @returns Promise with the link
|
|
841
1067
|
*/
|
|
842
1068
|
getInvitationLink(e) {
|
|
843
|
-
const t =
|
|
1069
|
+
const t = v(c.invitationGetLink, {
|
|
844
1070
|
invitationID: e
|
|
845
1071
|
});
|
|
846
1072
|
return this.axiosClient.get(t);
|
|
847
1073
|
}
|
|
848
1074
|
}
|
|
849
|
-
class
|
|
1075
|
+
class we {
|
|
850
1076
|
constructor(e, t, r) {
|
|
851
1077
|
this.axiosClient = new w(e, t, r);
|
|
852
1078
|
}
|
|
@@ -863,7 +1089,7 @@ class ve {
|
|
|
863
1089
|
return this.axiosClient.get(c.settingsPasskey);
|
|
864
1090
|
}
|
|
865
1091
|
}
|
|
866
|
-
class
|
|
1092
|
+
class Te {
|
|
867
1093
|
constructor(e, t, r) {
|
|
868
1094
|
this.axiosClient = new w(e, t, r);
|
|
869
1095
|
}
|
|
@@ -967,8 +1193,8 @@ class ye {
|
|
|
967
1193
|
* @param role Role to assign
|
|
968
1194
|
*/
|
|
969
1195
|
addUserToGroup(e, t, r, s) {
|
|
970
|
-
const o = `${c.tenantPath}/${e}/group/${t}/add`,
|
|
971
|
-
return this.axiosClient.post(o,
|
|
1196
|
+
const o = `${c.tenantPath}/${e}/group/${t}/add`, n = { user_id: r, role: s };
|
|
1197
|
+
return this.axiosClient.post(o, n);
|
|
972
1198
|
}
|
|
973
1199
|
/**
|
|
974
1200
|
* Remove user roles from a group
|
|
@@ -978,8 +1204,8 @@ class ye {
|
|
|
978
1204
|
* @param roles Roles to remove
|
|
979
1205
|
*/
|
|
980
1206
|
removeUserRolesFromGroup(e, t, r, s) {
|
|
981
|
-
const o = `${c.tenantPath}/${e}/group/${t}/remove_roles`,
|
|
982
|
-
return this.axiosClient.post(o,
|
|
1207
|
+
const o = `${c.tenantPath}/${e}/group/${t}/remove_roles`, n = { user_id: r, roles: s };
|
|
1208
|
+
return this.axiosClient.post(o, n);
|
|
983
1209
|
}
|
|
984
1210
|
/**
|
|
985
1211
|
* Change user roles in a group
|
|
@@ -989,8 +1215,8 @@ class ye {
|
|
|
989
1215
|
* @param roles New roles to assign
|
|
990
1216
|
*/
|
|
991
1217
|
changeUserRoles(e, t, r, s) {
|
|
992
|
-
const o = `${c.tenantPath}/${e}/group/${t}/change`,
|
|
993
|
-
return this.axiosClient.post(o,
|
|
1218
|
+
const o = `${c.tenantPath}/${e}/group/${t}/change`, n = { user_id: r, roles: s };
|
|
1219
|
+
return this.axiosClient.post(o, n);
|
|
994
1220
|
}
|
|
995
1221
|
/**
|
|
996
1222
|
* Delete a user from a group
|
|
@@ -1096,7 +1322,7 @@ class ye {
|
|
|
1096
1322
|
return this.axiosClient.delete(s);
|
|
1097
1323
|
}
|
|
1098
1324
|
}
|
|
1099
|
-
class
|
|
1325
|
+
class Ee {
|
|
1100
1326
|
constructor(e, t, r) {
|
|
1101
1327
|
this.axiosClient = new w(e, t, r);
|
|
1102
1328
|
}
|
|
@@ -1212,13 +1438,13 @@ class me {
|
|
|
1212
1438
|
};
|
|
1213
1439
|
}).catch((r) => {
|
|
1214
1440
|
if (r.response) {
|
|
1215
|
-
const s = r.response.status, o = r.response.data || {},
|
|
1441
|
+
const s = r.response.status, o = r.response.data || {}, n = r.response.headers?.["retry-after"] ? parseInt(r.response.headers["retry-after"], 10) : void 0;
|
|
1216
1442
|
return {
|
|
1217
1443
|
success: !1,
|
|
1218
1444
|
error: {
|
|
1219
1445
|
code: o.error || this.mapStatusToErrorCode(s),
|
|
1220
1446
|
message: o.message || this.getDefaultErrorMessage(s),
|
|
1221
|
-
retryAfter:
|
|
1447
|
+
retryAfter: n
|
|
1222
1448
|
}
|
|
1223
1449
|
};
|
|
1224
1450
|
}
|
|
@@ -1287,7 +1513,7 @@ class me {
|
|
|
1287
1513
|
* POST /v2/user/2fa/methods/:method/setup/begin
|
|
1288
1514
|
*/
|
|
1289
1515
|
beginMethodSetup(e) {
|
|
1290
|
-
const t =
|
|
1516
|
+
const t = v(c.TwoFactorMethodSetupBegin, { method: e });
|
|
1291
1517
|
return this.axiosClient.post(t, {});
|
|
1292
1518
|
}
|
|
1293
1519
|
/**
|
|
@@ -1295,7 +1521,7 @@ class me {
|
|
|
1295
1521
|
* POST /v2/user/2fa/methods/:method/setup/confirm
|
|
1296
1522
|
*/
|
|
1297
1523
|
confirmMethodSetup(e, t) {
|
|
1298
|
-
const r =
|
|
1524
|
+
const r = v(c.TwoFactorMethodSetupConfirm, { method: e });
|
|
1299
1525
|
return this.axiosClient.post(r, t);
|
|
1300
1526
|
}
|
|
1301
1527
|
/**
|
|
@@ -1303,7 +1529,7 @@ class me {
|
|
|
1303
1529
|
* DELETE /v2/user/2fa/methods/:id
|
|
1304
1530
|
*/
|
|
1305
1531
|
removeMethod(e) {
|
|
1306
|
-
const t =
|
|
1532
|
+
const t = v(c.TwoFactorMethodRemove, { id: e });
|
|
1307
1533
|
return this.axiosClient.delete(t);
|
|
1308
1534
|
}
|
|
1309
1535
|
/**
|
|
@@ -1348,11 +1574,11 @@ class me {
|
|
|
1348
1574
|
* DELETE /v2/user/2fa/trusted-devices/:id
|
|
1349
1575
|
*/
|
|
1350
1576
|
revokeTrustedDevice(e) {
|
|
1351
|
-
const t =
|
|
1577
|
+
const t = v(c.TwoFactorTrustedDeviceRevoke, { id: e });
|
|
1352
1578
|
return this.axiosClient.delete(t);
|
|
1353
1579
|
}
|
|
1354
1580
|
}
|
|
1355
|
-
class
|
|
1581
|
+
class _e {
|
|
1356
1582
|
constructor(e, t, r) {
|
|
1357
1583
|
this.axiosClient = new w(e, t, r);
|
|
1358
1584
|
}
|
|
@@ -1380,14 +1606,14 @@ class Se {
|
|
|
1380
1606
|
passkeyDisplayName: s,
|
|
1381
1607
|
passkeyUsername: o
|
|
1382
1608
|
}) {
|
|
1383
|
-
const
|
|
1609
|
+
const n = {
|
|
1384
1610
|
passkey_display_name: s,
|
|
1385
1611
|
passkey_username: o,
|
|
1386
1612
|
relying_party_id: e,
|
|
1387
1613
|
deviceId: t,
|
|
1388
1614
|
os: r
|
|
1389
1615
|
};
|
|
1390
|
-
return this.axiosClient.post(c.addUserPasskey,
|
|
1616
|
+
return this.axiosClient.post(c.addUserPasskey, n);
|
|
1391
1617
|
}
|
|
1392
1618
|
addUserPasskeyComplete(e, t, r) {
|
|
1393
1619
|
return this.axiosClient.post(c.completeAddUserPasskey, {
|
|
@@ -1397,8 +1623,8 @@ class Se {
|
|
|
1397
1623
|
});
|
|
1398
1624
|
}
|
|
1399
1625
|
}
|
|
1400
|
-
var
|
|
1401
|
-
class
|
|
1626
|
+
var a = /* @__PURE__ */ ((i) => (i.SignIn = "signin", i.SignInStart = "signin:start", i.Register = "register", i.RegisterStart = "register:start", i.SignOut = "signout", i.SessionRestored = "session:restored", i.SessionExpired = "session:expired", i.Error = "error", i.Refresh = "refresh", i.RefreshStart = "refresh:start", i.TokenCacheExpired = "token-cache-expired", i.TwoFactorRequired = "2fa:required", i.TwoFactorSetupStarted = "2fa:setup_started", i.TwoFactorEnabled = "2fa:enabled", i.TwoFactorDisabled = "2fa:disabled", i.TwoFactorVerified = "2fa:verified", i.TwoFactorRecoveryUsed = "2fa:recovery_used", i.TwoFactorRecoveryCodesLow = "2fa:recovery_low", i.TwoFactorRecoveryCodesExhausted = "2fa:recovery_exhausted", i.TwoFactorSetupMagicLinkValidated = "2fa:magic_link_validated", i.TwoFactorSetupMagicLinkFailed = "2fa:magic_link_failed", i.TwoFactorChallengeReceived = "two_factor_challenge_received", i.TwoFactorMethodSwitched = "two_factor_method_switched", i.TwoFactorDeviceTrusted = "two_factor_device_trusted", i))(a || {});
|
|
1627
|
+
class Ie {
|
|
1402
1628
|
constructor() {
|
|
1403
1629
|
this.subscribers = /* @__PURE__ */ new Map();
|
|
1404
1630
|
}
|
|
@@ -1445,8 +1671,8 @@ function D(i) {
|
|
|
1445
1671
|
const t = /^[A-Za-z0-9_-]+$/;
|
|
1446
1672
|
return e.every((r) => t.test(r) && r.length > 0);
|
|
1447
1673
|
}
|
|
1448
|
-
function
|
|
1449
|
-
return i.replace(/<[^>]*>/g, "").substring(0,
|
|
1674
|
+
function be(i) {
|
|
1675
|
+
return i.replace(/<[^>]*>/g, "").substring(0, ce);
|
|
1450
1676
|
}
|
|
1451
1677
|
function P(i) {
|
|
1452
1678
|
if (!i || typeof i != "string") return !1;
|
|
@@ -1458,22 +1684,22 @@ function x(i) {
|
|
|
1458
1684
|
const e = i.trim();
|
|
1459
1685
|
return /^\+[1-9]\d{1,14}$/.test(e);
|
|
1460
1686
|
}
|
|
1461
|
-
function
|
|
1687
|
+
function Ae(i) {
|
|
1462
1688
|
if (!i || typeof i != "string") return !1;
|
|
1463
1689
|
const e = i.trim();
|
|
1464
|
-
return e.length <
|
|
1690
|
+
return e.length < ne || e.length > ae ? !1 : /^[a-zA-Z0-9_-]+$/.test(e);
|
|
1465
1691
|
}
|
|
1466
|
-
function
|
|
1692
|
+
function C(i, e = 6) {
|
|
1467
1693
|
return !i || typeof i != "string" ? !1 : (e === 8 ? /^\d{8}$/ : /^\d{6}$/).test(i);
|
|
1468
1694
|
}
|
|
1469
|
-
function
|
|
1695
|
+
function Ce(i) {
|
|
1470
1696
|
if (!i || typeof i != "string") return null;
|
|
1471
1697
|
const e = i.toUpperCase().replace(/\s+/g, "");
|
|
1472
1698
|
return /^[A-Z0-9-]{4,16}$/.test(e) ? e : null;
|
|
1473
1699
|
}
|
|
1474
|
-
class
|
|
1475
|
-
constructor(e, t, r, s, o,
|
|
1476
|
-
this.authApi = e, this.deviceService = t, this.storageManager = r, this.subscribeStore = s, this.tokenCacheService = o, this.scopes =
|
|
1700
|
+
class Re {
|
|
1701
|
+
constructor(e, t, r, s, o, n, h, d, u, g, f, M = A) {
|
|
1702
|
+
this.authApi = e, this.deviceService = t, this.storageManager = r, this.subscribeStore = s, this.tokenCacheService = o, this.scopes = n, this.createTenantForNewUser = h, this.url = d, this.sessionCallbacks = u, this.appId = g, this.platform = M, this.tokenExchangeConfig = f, this.tokenDeliveryManager = new q(r), f?.enabled && this.tokenDeliveryManager.setMode(y.BFF), this.initializeSession();
|
|
1477
1703
|
}
|
|
1478
1704
|
/**
|
|
1479
1705
|
* Initialize session state on page load for cookie/BFF mode
|
|
@@ -1502,7 +1728,7 @@ class Ie {
|
|
|
1502
1728
|
return !1;
|
|
1503
1729
|
try {
|
|
1504
1730
|
const e = await this.authApi.validateSession();
|
|
1505
|
-
return e.valid ? (this.tokenDeliveryManager.setSessionValid(), e.user && this.subscribeStore.notify(
|
|
1731
|
+
return e.valid ? (this.tokenDeliveryManager.setSessionValid(), e.user && this.subscribeStore.notify(a.SessionRestored, e.user), !0) : (this.tokenDeliveryManager.setSessionInvalid(), !1);
|
|
1506
1732
|
} catch {
|
|
1507
1733
|
return this.tokenDeliveryManager.setSessionInvalid(), !1;
|
|
1508
1734
|
}
|
|
@@ -1546,9 +1772,9 @@ class Ie {
|
|
|
1546
1772
|
originalError: s,
|
|
1547
1773
|
code: "VALIDATION_ERROR"
|
|
1548
1774
|
};
|
|
1549
|
-
throw this.subscribeStore.notify(
|
|
1775
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1550
1776
|
}
|
|
1551
|
-
if ("username" in e && e.username && !
|
|
1777
|
+
if ("username" in e && e.username && !Ae(e.username)) {
|
|
1552
1778
|
const s = new Error(
|
|
1553
1779
|
"Invalid username format. Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"
|
|
1554
1780
|
), o = {
|
|
@@ -1556,7 +1782,7 @@ class Ie {
|
|
|
1556
1782
|
originalError: s,
|
|
1557
1783
|
code: "VALIDATION_ERROR"
|
|
1558
1784
|
};
|
|
1559
|
-
throw this.subscribeStore.notify(
|
|
1785
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1560
1786
|
}
|
|
1561
1787
|
if ("phone" in e && e.phone && !x(e.phone)) {
|
|
1562
1788
|
const s = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), o = {
|
|
@@ -1564,18 +1790,18 @@ class Ie {
|
|
|
1564
1790
|
originalError: s,
|
|
1565
1791
|
code: "VALIDATION_ERROR"
|
|
1566
1792
|
};
|
|
1567
|
-
throw this.subscribeStore.notify(
|
|
1793
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1568
1794
|
}
|
|
1569
|
-
this.subscribeStore.notify(
|
|
1570
|
-
const t = this.deviceService.getDeviceId(), r =
|
|
1795
|
+
this.subscribeStore.notify(a.SignInStart, { email: e.email });
|
|
1796
|
+
const t = this.deviceService.getDeviceId(), r = this.platform.getDeviceType();
|
|
1571
1797
|
e.scopes = e.scopes ?? this.scopes;
|
|
1572
1798
|
try {
|
|
1573
1799
|
const s = await this.authApi.signIn(e, t, r);
|
|
1574
|
-
return "requires_2fa" in s && s.requires_2fa === !0 || "tfa_token" in s && s.tfa_token ? (this.subscribeStore.notify(
|
|
1800
|
+
return "requires_2fa" in s && s.requires_2fa === !0 || "tfa_token" in s && s.tfa_token ? (this.subscribeStore.notify(a.TwoFactorRequired, {
|
|
1575
1801
|
email: e.email || "",
|
|
1576
1802
|
challengeId: s.challenge_id || "",
|
|
1577
1803
|
tfaToken: s.tfa_token || ""
|
|
1578
|
-
}), s) : (await this.processAuthResponse(s, e.scopes), this.subscribeStore.notify(
|
|
1804
|
+
}), s) : (await this.processAuthResponse(s, e.scopes), this.subscribeStore.notify(a.SignIn, {
|
|
1579
1805
|
tokens: s,
|
|
1580
1806
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1581
1807
|
}), await this.submitSessionCheck(), s);
|
|
@@ -1583,9 +1809,9 @@ class Ie {
|
|
|
1583
1809
|
const o = {
|
|
1584
1810
|
message: s instanceof Error ? s.message : "Sign in failed",
|
|
1585
1811
|
originalError: s,
|
|
1586
|
-
code: s instanceof
|
|
1812
|
+
code: s instanceof l ? s.id : void 0
|
|
1587
1813
|
};
|
|
1588
|
-
throw this.subscribeStore.notify(
|
|
1814
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1589
1815
|
}
|
|
1590
1816
|
}
|
|
1591
1817
|
async signUp(e) {
|
|
@@ -1595,7 +1821,7 @@ class Ie {
|
|
|
1595
1821
|
originalError: t,
|
|
1596
1822
|
code: "VALIDATION_ERROR"
|
|
1597
1823
|
};
|
|
1598
|
-
throw this.subscribeStore.notify(
|
|
1824
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1599
1825
|
}
|
|
1600
1826
|
if (e.user.phone_number && !x(e.user.phone_number)) {
|
|
1601
1827
|
const t = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), r = {
|
|
@@ -1603,12 +1829,12 @@ class Ie {
|
|
|
1603
1829
|
originalError: t,
|
|
1604
1830
|
code: "VALIDATION_ERROR"
|
|
1605
1831
|
};
|
|
1606
|
-
throw this.subscribeStore.notify(
|
|
1832
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1607
1833
|
}
|
|
1608
|
-
this.subscribeStore.notify(
|
|
1834
|
+
this.subscribeStore.notify(a.RegisterStart, { email: e.user.email }), e.scopes = e.scopes ?? this.scopes, e.create_tenant = this.createTenantForNewUser;
|
|
1609
1835
|
try {
|
|
1610
1836
|
const t = await this.authApi.signUp(e);
|
|
1611
|
-
return await this.processAuthResponse(t, e.scopes), this.subscribeStore.notify(
|
|
1837
|
+
return await this.processAuthResponse(t, e.scopes), this.subscribeStore.notify(a.Register, {
|
|
1612
1838
|
tokens: t,
|
|
1613
1839
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1614
1840
|
}), await this.submitSessionCheck(), t;
|
|
@@ -1616,9 +1842,9 @@ class Ie {
|
|
|
1616
1842
|
const r = {
|
|
1617
1843
|
message: t instanceof Error ? t.message : "Sign up failed",
|
|
1618
1844
|
originalError: t,
|
|
1619
|
-
code: t instanceof
|
|
1845
|
+
code: t instanceof l ? t.id : void 0
|
|
1620
1846
|
};
|
|
1621
|
-
throw this.subscribeStore.notify(
|
|
1847
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1622
1848
|
}
|
|
1623
1849
|
}
|
|
1624
1850
|
async passwordlessSignIn(e) {
|
|
@@ -1628,7 +1854,7 @@ class Ie {
|
|
|
1628
1854
|
originalError: s,
|
|
1629
1855
|
code: "VALIDATION_ERROR"
|
|
1630
1856
|
};
|
|
1631
|
-
throw this.subscribeStore.notify(
|
|
1857
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1632
1858
|
}
|
|
1633
1859
|
if (e.phone && !x(e.phone)) {
|
|
1634
1860
|
const s = new Error("Invalid phone number format. Phone must be in E.164 format (e.g., +12345678901)"), o = {
|
|
@@ -1636,26 +1862,26 @@ class Ie {
|
|
|
1636
1862
|
originalError: s,
|
|
1637
1863
|
code: "VALIDATION_ERROR"
|
|
1638
1864
|
};
|
|
1639
|
-
throw this.subscribeStore.notify(
|
|
1865
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1640
1866
|
}
|
|
1641
|
-
this.subscribeStore.notify(
|
|
1642
|
-
const t = this.deviceService.getDeviceId(), r =
|
|
1867
|
+
this.subscribeStore.notify(a.SignInStart, { email: e.email }), e.scopes = e.scopes ?? this.scopes;
|
|
1868
|
+
const t = this.deviceService.getDeviceId(), r = this.platform.getDeviceType();
|
|
1643
1869
|
try {
|
|
1644
1870
|
return await this.authApi.passwordlessSignIn(e, t, r);
|
|
1645
1871
|
} catch (s) {
|
|
1646
1872
|
const o = {
|
|
1647
1873
|
message: s instanceof Error ? s.message : "Failed to send passwordless sign-in link",
|
|
1648
1874
|
originalError: s,
|
|
1649
|
-
code: s instanceof
|
|
1875
|
+
code: s instanceof l ? s.id : void 0
|
|
1650
1876
|
};
|
|
1651
|
-
throw this.subscribeStore.notify(
|
|
1877
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1652
1878
|
}
|
|
1653
1879
|
}
|
|
1654
1880
|
async passwordlessSignInComplete(e) {
|
|
1655
|
-
this.subscribeStore.notify(
|
|
1881
|
+
this.subscribeStore.notify(a.SignInStart, {}), e.scopes = e.scopes ?? this.scopes, e.device = this.deviceService.getDeviceId();
|
|
1656
1882
|
try {
|
|
1657
1883
|
const t = await this.authApi.passwordlessSignInComplete(e);
|
|
1658
|
-
return await this.processAuthResponse(t, e.scopes), this.subscribeStore.notify(
|
|
1884
|
+
return await this.processAuthResponse(t, e.scopes), this.subscribeStore.notify(a.SignIn, {
|
|
1659
1885
|
tokens: t,
|
|
1660
1886
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1661
1887
|
}), await this.submitSessionCheck(), t;
|
|
@@ -1663,9 +1889,9 @@ class Ie {
|
|
|
1663
1889
|
const r = {
|
|
1664
1890
|
message: t instanceof Error ? t.message : "Passwordless sign in failed",
|
|
1665
1891
|
originalError: t,
|
|
1666
|
-
code: t instanceof
|
|
1892
|
+
code: t instanceof l ? t.id : void 0
|
|
1667
1893
|
};
|
|
1668
|
-
throw this.subscribeStore.notify(
|
|
1894
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1669
1895
|
}
|
|
1670
1896
|
}
|
|
1671
1897
|
async logOut() {
|
|
@@ -1679,17 +1905,17 @@ class Ie {
|
|
|
1679
1905
|
} catch {
|
|
1680
1906
|
}
|
|
1681
1907
|
else {
|
|
1682
|
-
const e = this.storageManager.getToken(
|
|
1908
|
+
const e = this.storageManager.getToken(k.refresh_token), t = this.storageManager.getDeviceId();
|
|
1683
1909
|
try {
|
|
1684
1910
|
if ((await this.authApi.logOut(t, e, !this.appId)).status !== "ok")
|
|
1685
1911
|
throw new Error("Logout failed");
|
|
1686
1912
|
} catch {
|
|
1687
1913
|
}
|
|
1688
1914
|
}
|
|
1689
|
-
this.storageManager.deleteTokens(), this.storageManager.clearIdToken(), this.storageManager.clearCsrfToken(), this.tokenDeliveryManager.reset(), this.subscribeStore.notify(
|
|
1915
|
+
this.storageManager.deleteTokens(), this.storageManager.clearIdToken(), this.storageManager.clearCsrfToken(), this.tokenDeliveryManager.reset(), this.subscribeStore.notify(a.SignOut, {});
|
|
1690
1916
|
}
|
|
1691
1917
|
async refreshToken() {
|
|
1692
|
-
if (this.subscribeStore.notify(
|
|
1918
|
+
if (this.subscribeStore.notify(a.RefreshStart, {}), this.tokenDeliveryManager.isBFFMode() && this.tokenExchangeConfig?.refreshUrl)
|
|
1693
1919
|
try {
|
|
1694
1920
|
const r = await fetch(this.tokenExchangeConfig.refreshUrl, {
|
|
1695
1921
|
method: "POST",
|
|
@@ -1699,33 +1925,33 @@ class Ie {
|
|
|
1699
1925
|
if (!r.ok)
|
|
1700
1926
|
throw this.tokenDeliveryManager.setSessionInvalid(), new Error("BFF token refresh failed");
|
|
1701
1927
|
const s = await r.json();
|
|
1702
|
-
return this.tokenDeliveryManager.setSessionValid(), s.id_token && this.storageManager.setIdToken(s.id_token), this.subscribeStore.notify(
|
|
1928
|
+
return this.tokenDeliveryManager.setSessionValid(), s.id_token && this.storageManager.setIdToken(s.id_token), this.subscribeStore.notify(a.Refresh, {
|
|
1703
1929
|
tokens: s,
|
|
1704
1930
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1705
|
-
}), this.subscribeStore.notify(
|
|
1931
|
+
}), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !1 }), this.tokenCacheService.isRefreshing = !1, this.tokenCacheService.tokenExpiredFlag = !1, s;
|
|
1706
1932
|
} catch (r) {
|
|
1707
1933
|
this.tokenDeliveryManager.setSessionInvalid();
|
|
1708
1934
|
const s = {
|
|
1709
1935
|
message: r instanceof Error ? r.message : "Token refresh failed",
|
|
1710
1936
|
originalError: r
|
|
1711
1937
|
};
|
|
1712
|
-
throw this.subscribeStore.notify(
|
|
1938
|
+
throw this.subscribeStore.notify(a.Error, s), r;
|
|
1713
1939
|
}
|
|
1714
1940
|
if (this.tokenDeliveryManager.isCookieMode())
|
|
1715
1941
|
try {
|
|
1716
1942
|
const r = await this.authApi.refreshToken("", this.scopes);
|
|
1717
|
-
return this.tokenDeliveryManager.setSessionValid(), await this.processAuthResponse(r, this.scopes), this.subscribeStore.notify(
|
|
1943
|
+
return this.tokenDeliveryManager.setSessionValid(), await this.processAuthResponse(r, this.scopes), this.subscribeStore.notify(a.Refresh, {
|
|
1718
1944
|
tokens: r,
|
|
1719
1945
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1720
|
-
}), this.subscribeStore.notify(
|
|
1946
|
+
}), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !1 }), this.tokenCacheService.isRefreshing = !1, this.tokenCacheService.tokenExpiredFlag = !1, r;
|
|
1721
1947
|
} catch (r) {
|
|
1722
1948
|
this.tokenDeliveryManager.setSessionInvalid();
|
|
1723
1949
|
const s = {
|
|
1724
1950
|
message: r instanceof Error ? r.message : "Token refresh failed",
|
|
1725
1951
|
originalError: r,
|
|
1726
|
-
code: r instanceof
|
|
1952
|
+
code: r instanceof l ? r.id : void 0
|
|
1727
1953
|
};
|
|
1728
|
-
throw this.subscribeStore.notify(
|
|
1954
|
+
throw this.subscribeStore.notify(a.Error, s), r;
|
|
1729
1955
|
}
|
|
1730
1956
|
const e = this.storageManager.getTokens();
|
|
1731
1957
|
if (e) {
|
|
@@ -1734,35 +1960,35 @@ class Ie {
|
|
|
1734
1960
|
message: "No refresh token found",
|
|
1735
1961
|
originalError: r
|
|
1736
1962
|
};
|
|
1737
|
-
throw this.subscribeStore.notify(
|
|
1963
|
+
throw this.subscribeStore.notify(a.Error, s), r;
|
|
1738
1964
|
}
|
|
1739
1965
|
} else {
|
|
1740
1966
|
const r = new Error("No tokens found"), s = {
|
|
1741
1967
|
message: "No tokens found",
|
|
1742
1968
|
originalError: r
|
|
1743
1969
|
};
|
|
1744
|
-
throw this.subscribeStore.notify(
|
|
1970
|
+
throw this.subscribeStore.notify(a.Error, s), r;
|
|
1745
1971
|
}
|
|
1746
1972
|
const t = e?.scopes ?? this.scopes;
|
|
1747
1973
|
try {
|
|
1748
1974
|
const r = await this.authApi.refreshToken(e?.refresh_token ?? "", t, e?.access_token);
|
|
1749
|
-
return r.scopes = t, this.storageManager.saveTokens(r), this.tokenCacheService.setTokensCache(r), this.subscribeStore.notify(
|
|
1975
|
+
return r.scopes = t, this.storageManager.saveTokens(r), this.tokenCacheService.setTokensCache(r), this.subscribeStore.notify(a.Refresh, {
|
|
1750
1976
|
tokens: r,
|
|
1751
1977
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1752
|
-
}), this.subscribeStore.notify(
|
|
1978
|
+
}), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !1 }), this.tokenCacheService.isRefreshing = !1, this.tokenCacheService.tokenExpiredFlag = !1, this.tokenCacheService.startTokenCheck(), r;
|
|
1753
1979
|
} catch (r) {
|
|
1754
1980
|
const s = {
|
|
1755
1981
|
message: r instanceof Error ? r.message : "Token refresh failed",
|
|
1756
1982
|
originalError: r,
|
|
1757
|
-
code: r instanceof
|
|
1983
|
+
code: r instanceof l ? r.id : void 0,
|
|
1758
1984
|
details: F.isAxiosError(r) && r.response ? {
|
|
1759
1985
|
status: r.response.status,
|
|
1760
1986
|
data: r.response.data
|
|
1761
1987
|
} : void 0
|
|
1762
1988
|
};
|
|
1763
|
-
this.subscribeStore.notify(
|
|
1989
|
+
this.subscribeStore.notify(a.Error, s);
|
|
1764
1990
|
const o = F.isAxiosError(r) && r.response?.status && r.response.status >= 400 && r.response.status < 500;
|
|
1765
|
-
throw o && (this.tokenCacheService.tokenExpiredFlag = !0, this.tokenCacheService.setTokensCache(void 0), this.storageManager.deleteTokens(), this.subscribeStore.notify(
|
|
1991
|
+
throw o && (this.tokenCacheService.tokenExpiredFlag = !0, this.tokenCacheService.setTokensCache(void 0), this.storageManager.deleteTokens(), this.subscribeStore.notify(a.SessionExpired, { reason: "refresh_failed" })), r instanceof l ? r : o ? new Error(`Getting unknown error message from server with code:${r.response?.status}`) : r;
|
|
1766
1992
|
}
|
|
1767
1993
|
}
|
|
1768
1994
|
async sendPasswordResetEmail(e) {
|
|
@@ -1772,81 +1998,83 @@ class Ie {
|
|
|
1772
1998
|
const r = {
|
|
1773
1999
|
message: t instanceof Error ? t.message : "Failed to send password reset email",
|
|
1774
2000
|
originalError: t,
|
|
1775
|
-
code: t instanceof
|
|
2001
|
+
code: t instanceof l ? t.id : void 0
|
|
1776
2002
|
};
|
|
1777
|
-
throw this.subscribeStore.notify(
|
|
2003
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1778
2004
|
}
|
|
1779
2005
|
}
|
|
1780
2006
|
async resetPassword(e, t) {
|
|
1781
|
-
this.subscribeStore.notify(
|
|
1782
|
-
const s = new URLSearchParams(
|
|
2007
|
+
this.subscribeStore.notify(a.SignInStart, {});
|
|
2008
|
+
const s = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("token") ?? void 0, o = t ?? this.scopes;
|
|
1783
2009
|
try {
|
|
1784
|
-
const
|
|
1785
|
-
return await this.processAuthResponse(
|
|
1786
|
-
tokens:
|
|
2010
|
+
const n = await this.authApi.resetPassword(e, o, s);
|
|
2011
|
+
return await this.processAuthResponse(n, o), this.subscribeStore.notify(a.SignIn, {
|
|
2012
|
+
tokens: n,
|
|
1787
2013
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1788
|
-
}), await this.submitSessionCheck(),
|
|
1789
|
-
} catch (
|
|
1790
|
-
const
|
|
1791
|
-
message:
|
|
1792
|
-
originalError:
|
|
1793
|
-
code:
|
|
2014
|
+
}), await this.submitSessionCheck(), n;
|
|
2015
|
+
} catch (n) {
|
|
2016
|
+
const h = {
|
|
2017
|
+
message: n instanceof Error ? n.message : "Password reset failed",
|
|
2018
|
+
originalError: n,
|
|
2019
|
+
code: n instanceof l ? n.id : void 0
|
|
1794
2020
|
};
|
|
1795
|
-
throw this.subscribeStore.notify(
|
|
2021
|
+
throw this.subscribeStore.notify(a.Error, h), n;
|
|
1796
2022
|
}
|
|
1797
2023
|
}
|
|
1798
2024
|
async passkeyRegister(e) {
|
|
1799
|
-
this.
|
|
1800
|
-
|
|
2025
|
+
if (!this.platform.passkeys) throw new Error("Passkeys are not supported on this platform");
|
|
2026
|
+
this.subscribeStore.notify(a.RegisterStart, {});
|
|
2027
|
+
const t = this.deviceService.getDeviceId(), r = this.platform.getDeviceType();
|
|
1801
2028
|
e.scopes = e.scopes ?? this.scopes, e.create_tenant = this.createTenantForNewUser;
|
|
1802
2029
|
try {
|
|
1803
2030
|
const { challenge_id: s, publicKey: o } = await this.authApi.passkeyRegisterStart(e, t, r, !this.appId);
|
|
1804
|
-
o.user.id = btoa(o.user.id);
|
|
1805
|
-
const
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
2031
|
+
o.user.id = this.platform.btoa(o.user.id);
|
|
2032
|
+
const n = await this.platform.passkeys.startRegistration(o);
|
|
2033
|
+
if (!n) throw new Error("Passkey registration was not completed");
|
|
2034
|
+
const h = await this.authApi.passkeyRegisterComplete(
|
|
2035
|
+
n,
|
|
1809
2036
|
t,
|
|
1810
2037
|
s,
|
|
1811
2038
|
!this.appId
|
|
1812
2039
|
);
|
|
1813
|
-
return await this.processAuthResponse(
|
|
1814
|
-
tokens:
|
|
2040
|
+
return await this.processAuthResponse(h, e.scopes), this.subscribeStore.notify(a.Register, {
|
|
2041
|
+
tokens: h,
|
|
1815
2042
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1816
|
-
}), await this.submitSessionCheck(),
|
|
2043
|
+
}), await this.submitSessionCheck(), h;
|
|
1817
2044
|
} catch (s) {
|
|
1818
2045
|
const o = {
|
|
1819
2046
|
message: s instanceof Error ? s.message : "Passkey registration failed",
|
|
1820
2047
|
originalError: s,
|
|
1821
|
-
code: s instanceof
|
|
2048
|
+
code: s instanceof l ? s.id : void 0
|
|
1822
2049
|
};
|
|
1823
|
-
throw this.subscribeStore.notify(
|
|
2050
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1824
2051
|
}
|
|
1825
2052
|
}
|
|
1826
2053
|
async passkeyAuthenticate(e) {
|
|
1827
|
-
this.
|
|
1828
|
-
|
|
2054
|
+
if (!this.platform.passkeys) throw new Error("Passkeys are not supported on this platform");
|
|
2055
|
+
this.subscribeStore.notify(a.SignInStart, {});
|
|
2056
|
+
const t = this.deviceService.getDeviceId(), r = this.platform.getDeviceType();
|
|
1829
2057
|
e.scopes = e.scopes ?? this.scopes;
|
|
1830
2058
|
try {
|
|
1831
|
-
const { challenge_id: s, publicKey: o } = await this.authApi.passkeyAuthenticateStart(e, t, r, !this.appId),
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
2059
|
+
const { challenge_id: s, publicKey: o } = await this.authApi.passkeyAuthenticateStart(e, t, r, !this.appId), n = await this.platform.passkeys.startAuthentication(o);
|
|
2060
|
+
if (!n) throw new Error("Passkey authentication was not completed");
|
|
2061
|
+
const h = await this.authApi.passkeyAuthenticateComplete(
|
|
2062
|
+
n,
|
|
1835
2063
|
t,
|
|
1836
2064
|
s,
|
|
1837
2065
|
!this.appId
|
|
1838
2066
|
);
|
|
1839
|
-
return "access_token" in
|
|
1840
|
-
tokens:
|
|
2067
|
+
return "access_token" in h && (await this.processAuthResponse(h, e.scopes), this.subscribeStore.notify(a.SignIn, {
|
|
2068
|
+
tokens: h,
|
|
1841
2069
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1842
|
-
}), await this.submitSessionCheck()),
|
|
2070
|
+
}), await this.submitSessionCheck()), h;
|
|
1843
2071
|
} catch (s) {
|
|
1844
2072
|
const o = {
|
|
1845
2073
|
message: s instanceof Error ? s.message : "Passkey authentication failed",
|
|
1846
2074
|
originalError: s,
|
|
1847
|
-
code: s instanceof
|
|
2075
|
+
code: s instanceof l ? s.id : void 0
|
|
1848
2076
|
};
|
|
1849
|
-
throw this.subscribeStore.notify(
|
|
2077
|
+
throw this.subscribeStore.notify(a.Error, o), s;
|
|
1850
2078
|
}
|
|
1851
2079
|
}
|
|
1852
2080
|
createFederatedAuthUrl(e) {
|
|
@@ -1854,92 +2082,73 @@ class Ie {
|
|
|
1854
2082
|
if (!this.appId) throw new Error("AppId is required for federated auth");
|
|
1855
2083
|
const s = {
|
|
1856
2084
|
scopes: (e.scopes ?? this.scopes).join(" "),
|
|
1857
|
-
redirect_url: e.redirect_url ?? this.origin,
|
|
2085
|
+
redirect_url: e.redirect_url ?? this.platform.getCurrentUrl()?.origin ?? "",
|
|
1858
2086
|
appId: this.appId,
|
|
1859
2087
|
...e.invite_token ? { invite_token: e.invite_token } : {},
|
|
1860
2088
|
...e.create_tenant ? { create_tenant: e.create_tenant.toString() } : {},
|
|
1861
2089
|
...e.device ? { device: e.device } : {}
|
|
1862
|
-
}, o = new URL(t, this.url),
|
|
1863
|
-
return o.search =
|
|
2090
|
+
}, o = new URL(t, this.url), n = new URLSearchParams(s);
|
|
2091
|
+
return o.search = n.toString(), o.toString();
|
|
1864
2092
|
}
|
|
1865
|
-
federatedAuthWithPopup(e) {
|
|
1866
|
-
this.subscribeStore.notify(
|
|
1867
|
-
const t = e.scopes ?? this.scopes, r = this.deviceService.getDeviceId(), s = this.createFederatedAuthUrl({ ...e, scopes: t, device: r })
|
|
1868
|
-
|
|
1869
|
-
this.
|
|
1870
|
-
|
|
2093
|
+
async federatedAuthWithPopup(e) {
|
|
2094
|
+
this.subscribeStore.notify(a.SignInStart, { provider: e.provider });
|
|
2095
|
+
const t = e.scopes ?? this.scopes, r = this.deviceService.getDeviceId(), s = this.createFederatedAuthUrl({ ...e, scopes: t, device: r });
|
|
2096
|
+
try {
|
|
2097
|
+
const o = await this.platform.openAuthUrl(s, {
|
|
2098
|
+
mode: "popup",
|
|
2099
|
+
expectedReturnOrigin: this.platform.getCurrentUrl()?.origin ?? ""
|
|
2100
|
+
}), n = new URLSearchParams(o.callbackSearch), h = n.get("access_token") || "", d = n.get("refresh_token") || "", u = n.get("id_token") || "", g = {
|
|
2101
|
+
access_token: h,
|
|
2102
|
+
refresh_token: d || void 0,
|
|
2103
|
+
id_token: u || void 0,
|
|
2104
|
+
scopes: t
|
|
2105
|
+
};
|
|
2106
|
+
await this.processAuthResponse(g, t), this.subscribeStore.notify(a.SignIn, {
|
|
2107
|
+
tokens: g,
|
|
2108
|
+
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
2109
|
+
}), this.platform.navigateTo(this.platform.getCurrentUrl()?.origin ?? "");
|
|
2110
|
+
} catch (o) {
|
|
2111
|
+
const n = {
|
|
2112
|
+
message: o instanceof Error ? o.message : "Authentication failed",
|
|
2113
|
+
code: o instanceof Y ? "POPUP_CLOSED" : "AUTH_FAILED",
|
|
2114
|
+
originalError: o
|
|
2115
|
+
};
|
|
2116
|
+
this.subscribeStore.notify(a.Error, n);
|
|
1871
2117
|
}
|
|
1872
|
-
const a = Date.now(), d = setInterval(() => {
|
|
1873
|
-
if (o.closed) {
|
|
1874
|
-
clearInterval(d);
|
|
1875
|
-
const h = {
|
|
1876
|
-
message: "Authentication popup was closed",
|
|
1877
|
-
code: "POPUP_CLOSED"
|
|
1878
|
-
};
|
|
1879
|
-
this.subscribeStore.notify(n.Error, h);
|
|
1880
|
-
return;
|
|
1881
|
-
}
|
|
1882
|
-
if (Date.now() - a > se) {
|
|
1883
|
-
clearInterval(d), o.close();
|
|
1884
|
-
const h = {
|
|
1885
|
-
message: "Authentication popup timed out",
|
|
1886
|
-
code: "POPUP_TIMEOUT"
|
|
1887
|
-
};
|
|
1888
|
-
this.subscribeStore.notify(n.Error, h);
|
|
1889
|
-
return;
|
|
1890
|
-
}
|
|
1891
|
-
try {
|
|
1892
|
-
if (o.location.href.startsWith(this.origin)) {
|
|
1893
|
-
const h = new URLSearchParams(o.location.search), g = h.get("access_token") || "", f = h.get("refresh_token") || "", k = h.get("id_token") || "", A = {
|
|
1894
|
-
access_token: g,
|
|
1895
|
-
refresh_token: f || void 0,
|
|
1896
|
-
id_token: k || void 0,
|
|
1897
|
-
scopes: t
|
|
1898
|
-
};
|
|
1899
|
-
this.processAuthResponse(A, t).then(() => {
|
|
1900
|
-
this.subscribeStore.notify(n.SignIn, {
|
|
1901
|
-
tokens: A,
|
|
1902
|
-
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
1903
|
-
}), window.location.href = `${this.origin}`;
|
|
1904
|
-
}), clearInterval(d), o.close();
|
|
1905
|
-
}
|
|
1906
|
-
} catch {
|
|
1907
|
-
}
|
|
1908
|
-
}, re);
|
|
1909
2118
|
}
|
|
1910
2119
|
federatedAuthWithRedirect(e) {
|
|
1911
|
-
this.subscribeStore.notify(
|
|
2120
|
+
this.subscribeStore.notify(a.SignInStart, { provider: e.provider });
|
|
1912
2121
|
const t = e.scopes ?? this.scopes, r = this.deviceService.getDeviceId(), s = this.createFederatedAuthUrl({ ...e, scopes: t, device: r });
|
|
1913
|
-
|
|
2122
|
+
this.platform.navigateTo(s);
|
|
1914
2123
|
}
|
|
1915
2124
|
// Helper methods for authentication UI redirect
|
|
1916
2125
|
authRedirectUrl(e = {}) {
|
|
1917
2126
|
try {
|
|
1918
|
-
const { url: t, redirectUrl: r, scopes: s, appId: o } = e ?? {},
|
|
1919
|
-
|
|
1920
|
-
const
|
|
2127
|
+
const { url: t, redirectUrl: r, scopes: s, appId: o } = e ?? {}, n = new URL(t ?? this.url);
|
|
2128
|
+
n.pathname = (n.pathname.endsWith("/") ? n.pathname : n.pathname + "/") + "web";
|
|
2129
|
+
const h = s ?? this.scopes, d = {
|
|
1921
2130
|
appId: o ?? this.appId ?? "",
|
|
1922
|
-
redirectto: r ??
|
|
1923
|
-
scopes:
|
|
1924
|
-
},
|
|
1925
|
-
return
|
|
2131
|
+
redirectto: r ?? this.platform.getCurrentUrl()?.href ?? "",
|
|
2132
|
+
scopes: h.join(",")
|
|
2133
|
+
}, u = new URLSearchParams(d);
|
|
2134
|
+
return n.search = u.toString(), n.toString();
|
|
1926
2135
|
} catch (t) {
|
|
1927
2136
|
const r = {
|
|
1928
2137
|
message: t instanceof Error ? t.message : "Failed to create auth redirect URL",
|
|
1929
2138
|
originalError: t
|
|
1930
2139
|
};
|
|
1931
|
-
throw this.subscribeStore.notify(
|
|
2140
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1932
2141
|
}
|
|
1933
2142
|
}
|
|
1934
2143
|
authRedirect(e = {}) {
|
|
1935
2144
|
try {
|
|
1936
|
-
|
|
2145
|
+
this.platform.navigateTo(this.authRedirectUrl(e));
|
|
1937
2146
|
} catch (t) {
|
|
1938
2147
|
const r = {
|
|
1939
2148
|
message: t instanceof Error ? t.message : "Failed to redirect to auth page",
|
|
1940
2149
|
originalError: t
|
|
1941
2150
|
};
|
|
1942
|
-
throw this.subscribeStore.notify(
|
|
2151
|
+
throw this.subscribeStore.notify(a.Error, r), t;
|
|
1943
2152
|
}
|
|
1944
2153
|
}
|
|
1945
2154
|
/**
|
|
@@ -1958,7 +2167,7 @@ class Ie {
|
|
|
1958
2167
|
message: t instanceof Error ? t.message : "Failed to check authentication status",
|
|
1959
2168
|
originalError: t
|
|
1960
2169
|
};
|
|
1961
|
-
return this.subscribeStore.notify(
|
|
2170
|
+
return this.subscribeStore.notify(a.Error, r), !1;
|
|
1962
2171
|
}
|
|
1963
2172
|
}
|
|
1964
2173
|
/**
|
|
@@ -1970,10 +2179,10 @@ class Ie {
|
|
|
1970
2179
|
t = await this.getTokens(e), r = this.tokenCacheService.getParsedTokens();
|
|
1971
2180
|
} catch (s) {
|
|
1972
2181
|
const o = {
|
|
1973
|
-
message: s instanceof Error || s instanceof
|
|
2182
|
+
message: s instanceof Error || s instanceof l ? s.message : "Session check failed",
|
|
1974
2183
|
originalError: s
|
|
1975
2184
|
};
|
|
1976
|
-
this.subscribeStore.notify(
|
|
2185
|
+
this.subscribeStore.notify(a.Error, o), t = void 0;
|
|
1977
2186
|
}
|
|
1978
2187
|
return t && this.sessionCallbacks.createSession && await this.sessionCallbacks.createSession({ tokens: t, parsedTokens: r }), !t && this.sessionCallbacks.expiredSession && await this.sessionCallbacks.expiredSession(), t;
|
|
1979
2188
|
}
|
|
@@ -1990,19 +2199,19 @@ class Ie {
|
|
|
1990
2199
|
}
|
|
1991
2200
|
const t = this.storageManager.getTokens();
|
|
1992
2201
|
if (!t || !t.access_token) return;
|
|
1993
|
-
const r =
|
|
2202
|
+
const r = m(t.access_token);
|
|
1994
2203
|
return S(r) ? e ? await this.refreshToken() : void 0 : t;
|
|
1995
2204
|
} catch (t) {
|
|
1996
2205
|
const r = {
|
|
1997
2206
|
message: t instanceof Error ? t.message : "Failed to get tokens",
|
|
1998
2207
|
originalError: t
|
|
1999
2208
|
};
|
|
2000
|
-
this.subscribeStore.notify(
|
|
2209
|
+
this.subscribeStore.notify(a.Error, r);
|
|
2001
2210
|
return;
|
|
2002
2211
|
}
|
|
2003
2212
|
}
|
|
2004
2213
|
}
|
|
2005
|
-
class
|
|
2214
|
+
class Fe {
|
|
2006
2215
|
constructor(e) {
|
|
2007
2216
|
this.invitationApi = e;
|
|
2008
2217
|
}
|
|
@@ -2047,7 +2256,7 @@ class be {
|
|
|
2047
2256
|
return this.invitationApi.getInvitationLink(e);
|
|
2048
2257
|
}
|
|
2049
2258
|
}
|
|
2050
|
-
class
|
|
2259
|
+
class Me {
|
|
2051
2260
|
error(e, ...t) {
|
|
2052
2261
|
console.error(e, ...t);
|
|
2053
2262
|
}
|
|
@@ -2061,40 +2270,40 @@ class Ae {
|
|
|
2061
2270
|
console.debug(e, ...t);
|
|
2062
2271
|
}
|
|
2063
2272
|
}
|
|
2064
|
-
function
|
|
2065
|
-
return new
|
|
2273
|
+
function De() {
|
|
2274
|
+
return new Me();
|
|
2066
2275
|
}
|
|
2067
|
-
class
|
|
2276
|
+
class Pe {
|
|
2068
2277
|
constructor(e) {
|
|
2069
2278
|
this.data = this.normalize(e);
|
|
2070
2279
|
}
|
|
2071
2280
|
normalize(e) {
|
|
2072
2281
|
const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), o = [];
|
|
2073
|
-
return e.groups?.forEach((
|
|
2074
|
-
r.set(
|
|
2075
|
-
id:
|
|
2076
|
-
name:
|
|
2077
|
-
default:
|
|
2078
|
-
updated_at:
|
|
2079
|
-
created_at:
|
|
2282
|
+
return e.groups?.forEach((n) => {
|
|
2283
|
+
r.set(n.id, {
|
|
2284
|
+
id: n.id,
|
|
2285
|
+
name: n.name,
|
|
2286
|
+
default: n.default ?? !1,
|
|
2287
|
+
updated_at: n.updated_at,
|
|
2288
|
+
created_at: n.created_at
|
|
2080
2289
|
});
|
|
2081
|
-
}), e.roles?.forEach((
|
|
2082
|
-
s.set(
|
|
2083
|
-
id:
|
|
2084
|
-
tenant_id:
|
|
2085
|
-
name:
|
|
2290
|
+
}), e.roles?.forEach((n) => {
|
|
2291
|
+
s.set(n.id, {
|
|
2292
|
+
id: n.id,
|
|
2293
|
+
tenant_id: n.tenant_id,
|
|
2294
|
+
name: n.name
|
|
2086
2295
|
});
|
|
2087
|
-
}), e.users_in_groups?.forEach((
|
|
2088
|
-
const
|
|
2089
|
-
|
|
2090
|
-
id:
|
|
2091
|
-
name:
|
|
2092
|
-
email:
|
|
2093
|
-
phone:
|
|
2094
|
-
}),
|
|
2095
|
-
userId:
|
|
2096
|
-
groupId:
|
|
2097
|
-
roleIds:
|
|
2296
|
+
}), e.users_in_groups?.forEach((n) => {
|
|
2297
|
+
const h = n.user;
|
|
2298
|
+
h && !t.has(h.id) && t.set(h.id, {
|
|
2299
|
+
id: h.id,
|
|
2300
|
+
name: h.name ?? null,
|
|
2301
|
+
email: h.email ?? null,
|
|
2302
|
+
phone: h.phone ?? null
|
|
2303
|
+
}), h && n.group_id && r.has(n.group_id) && o.push({
|
|
2304
|
+
userId: h.id,
|
|
2305
|
+
groupId: n.group_id,
|
|
2306
|
+
roleIds: n.roles?.map((d) => d.id) ?? []
|
|
2098
2307
|
});
|
|
2099
2308
|
}), {
|
|
2100
2309
|
tenant_id: e.tenant_id,
|
|
@@ -2134,9 +2343,9 @@ class Re {
|
|
|
2134
2343
|
return this.data;
|
|
2135
2344
|
}
|
|
2136
2345
|
}
|
|
2137
|
-
class
|
|
2346
|
+
class xe {
|
|
2138
2347
|
constructor(e, t, r) {
|
|
2139
|
-
this.tenantApi = e, this.scopes = t, this.logger = r ||
|
|
2348
|
+
this.tenantApi = e, this.scopes = t, this.logger = r || De();
|
|
2140
2349
|
}
|
|
2141
2350
|
/**
|
|
2142
2351
|
* Handle Passflow API errors
|
|
@@ -2206,7 +2415,7 @@ class Me {
|
|
|
2206
2415
|
async getTenantUserMembership(e) {
|
|
2207
2416
|
try {
|
|
2208
2417
|
const t = await this.tenantApi.getTenantDetails(e);
|
|
2209
|
-
return new
|
|
2418
|
+
return new Pe(t);
|
|
2210
2419
|
} catch (t) {
|
|
2211
2420
|
this.handlePassflowError(t, `Get tenant user membership failed for tenant ID ${e}`);
|
|
2212
2421
|
}
|
|
@@ -2504,9 +2713,9 @@ class Me {
|
|
|
2504
2713
|
}
|
|
2505
2714
|
}
|
|
2506
2715
|
}
|
|
2507
|
-
class
|
|
2508
|
-
constructor(e, t, r) {
|
|
2509
|
-
this.storageManager = e, this.authApi = t, this.subscribeStore = r, this.checkInterval = null, this.CHECK_INTERVAL = 6e4, this.
|
|
2716
|
+
class Ue {
|
|
2717
|
+
constructor(e, t, r, s = A) {
|
|
2718
|
+
this.storageManager = e, this.authApi = t, this.subscribeStore = r, this.platform = s, this.checkInterval = null, this.CHECK_INTERVAL = 6e4, this.unsubscribeForeground = null, this.unsubscribeUnload = null, this.isRefreshing = !1, this.tokenExpiredFlag = !1, this.storageManager = e, this.authApi = t, this.setupLifecycleListeners();
|
|
2510
2719
|
}
|
|
2511
2720
|
initialize() {
|
|
2512
2721
|
try {
|
|
@@ -2519,62 +2728,59 @@ class Fe {
|
|
|
2519
2728
|
this.setTokensCache(e), this.startTokenCheck();
|
|
2520
2729
|
return;
|
|
2521
2730
|
}
|
|
2522
|
-
const t =
|
|
2523
|
-
S(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(
|
|
2731
|
+
const t = m(e.access_token);
|
|
2732
|
+
S(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 })) : (this.setTokensCache(e), this.startTokenCheck());
|
|
2524
2733
|
} catch (e) {
|
|
2525
2734
|
const t = {
|
|
2526
2735
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
2527
2736
|
originalError: e
|
|
2528
2737
|
};
|
|
2529
|
-
this.subscribeStore.notify(
|
|
2738
|
+
this.subscribeStore.notify(a.Error, t), this.setTokensCache(void 0);
|
|
2530
2739
|
}
|
|
2531
2740
|
}
|
|
2532
2741
|
async refreshTokensCache(e) {
|
|
2533
2742
|
if (!this.isRefreshing)
|
|
2534
2743
|
try {
|
|
2535
|
-
this.isRefreshing = !0, this.subscribeStore.notify(
|
|
2744
|
+
this.isRefreshing = !0, this.subscribeStore.notify(a.RefreshStart, {});
|
|
2536
2745
|
const t = await this.authApi.refreshToken(e?.refresh_token ?? "", e.scopes ?? [], e.access_token);
|
|
2537
|
-
this.setTokensCache(t), this.subscribeStore.notify(
|
|
2746
|
+
this.setTokensCache(t), this.subscribeStore.notify(a.Refresh, { tokens: t, parsedTokens: this.getParsedTokens() }), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !1 }), this.tokenExpiredFlag = !1, this.startTokenCheck();
|
|
2538
2747
|
} catch (t) {
|
|
2539
2748
|
const r = {
|
|
2540
2749
|
message: t instanceof Error ? t.message : "Failed to get tokens",
|
|
2541
2750
|
originalError: t
|
|
2542
2751
|
};
|
|
2543
|
-
this.subscribeStore.notify(
|
|
2752
|
+
this.subscribeStore.notify(a.Error, r), this.tokenExpiredFlag = !0, this.setTokensCache(void 0), this.stopTokenCheck(), this.storageManager.deleteTokens(), this.subscribeStore.notify(a.SessionExpired, { reason: "refresh_failed" });
|
|
2544
2753
|
} finally {
|
|
2545
2754
|
this.isRefreshing = !1;
|
|
2546
2755
|
}
|
|
2547
2756
|
}
|
|
2548
2757
|
startTokenCheck() {
|
|
2549
|
-
this.checkInterval && clearInterval(this.checkInterval), !this.tokenExpiredFlag && (this.
|
|
2550
|
-
|
|
2758
|
+
this.checkInterval && clearInterval(this.checkInterval), !this.tokenExpiredFlag && (this.setupLifecycleListeners(), this.checkInterval = setInterval(() => {
|
|
2759
|
+
this.platform.isInForeground() && (this.isRefreshing || this.tokenExpiredFlag || this.isExpired() && !this.tokenExpiredFlag && (this.tokenExpiredFlag = !0, this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 }), this.stopTokenCheck()));
|
|
2551
2760
|
}, this.CHECK_INTERVAL));
|
|
2552
2761
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
},
|
|
2557
|
-
}
|
|
2558
|
-
setupPageUnloadHandler() {
|
|
2559
|
-
typeof window > "u" || window.addEventListener("beforeunload", () => {
|
|
2762
|
+
setupLifecycleListeners() {
|
|
2763
|
+
this.unsubscribeForeground && (this.unsubscribeForeground(), this.unsubscribeForeground = null), this.unsubscribeForeground = this.platform.onForeground(() => {
|
|
2764
|
+
this.checkInterval && !this.isRefreshing && !this.tokenExpiredFlag && this.isExpired() && (this.tokenExpiredFlag = !0, this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 }), this.stopTokenCheck());
|
|
2765
|
+
}), this.unsubscribeUnload || (this.unsubscribeUnload = this.platform.onBeforeUnload(() => {
|
|
2560
2766
|
this.destroy();
|
|
2561
|
-
});
|
|
2767
|
+
}));
|
|
2562
2768
|
}
|
|
2563
2769
|
stopTokenCheck() {
|
|
2564
|
-
this.checkInterval && (clearInterval(this.checkInterval), this.checkInterval = null), this.
|
|
2770
|
+
this.checkInterval && (clearInterval(this.checkInterval), this.checkInterval = null), this.unsubscribeForeground && (this.unsubscribeForeground(), this.unsubscribeForeground = null);
|
|
2565
2771
|
}
|
|
2566
2772
|
/**
|
|
2567
2773
|
* Cleanup method to stop all intervals and remove event listeners.
|
|
2568
2774
|
* Should be called when the service is no longer needed.
|
|
2569
2775
|
*/
|
|
2570
2776
|
destroy() {
|
|
2571
|
-
this.stopTokenCheck();
|
|
2777
|
+
this.stopTokenCheck(), this.unsubscribeUnload && (this.unsubscribeUnload(), this.unsubscribeUnload = null);
|
|
2572
2778
|
}
|
|
2573
2779
|
setTokensCache(e) {
|
|
2574
2780
|
this.tokensCache = e, e ? this.parsedTokensCache = {
|
|
2575
|
-
access_token: e.access_token ?
|
|
2576
|
-
id_token: e.id_token ?
|
|
2577
|
-
refresh_token: e.refresh_token ?
|
|
2781
|
+
access_token: e.access_token ? m(e.access_token) : void 0,
|
|
2782
|
+
id_token: e.id_token ? m(e.id_token) : void 0,
|
|
2783
|
+
refresh_token: e.refresh_token ? m(e.refresh_token) : void 0,
|
|
2578
2784
|
scopes: e.scopes
|
|
2579
2785
|
} : this.parsedTokensCache = void 0;
|
|
2580
2786
|
}
|
|
@@ -2586,14 +2792,14 @@ class Fe {
|
|
|
2586
2792
|
if (!this.tokensCache) return this.tokensCache;
|
|
2587
2793
|
if (!this.tokensCache.access_token)
|
|
2588
2794
|
return this.tokensCache;
|
|
2589
|
-
const e =
|
|
2795
|
+
const e = m(this.tokensCache.access_token);
|
|
2590
2796
|
return S(e) && !this.tokenExpiredFlag ? (await this.refreshTokensCache(this.tokensCache), this.tokensCache) : this.tokensCache;
|
|
2591
2797
|
} catch (e) {
|
|
2592
2798
|
const t = {
|
|
2593
2799
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
2594
2800
|
originalError: e
|
|
2595
2801
|
};
|
|
2596
|
-
this.subscribeStore.notify(
|
|
2802
|
+
this.subscribeStore.notify(a.Error, t);
|
|
2597
2803
|
return;
|
|
2598
2804
|
}
|
|
2599
2805
|
}
|
|
@@ -2604,22 +2810,22 @@ class Fe {
|
|
|
2604
2810
|
if (!this.tokensCache) return !0;
|
|
2605
2811
|
if (!this.tokensCache.access_token)
|
|
2606
2812
|
return !1;
|
|
2607
|
-
const e =
|
|
2813
|
+
const e = m(this.tokensCache.access_token);
|
|
2608
2814
|
return S(e);
|
|
2609
2815
|
}
|
|
2610
2816
|
}
|
|
2611
|
-
class
|
|
2817
|
+
class $e {
|
|
2612
2818
|
constructor(e, t) {
|
|
2613
2819
|
this.twoFactorApi = e, this.subscribeStore = t, this.PARTIAL_AUTH_TIMEOUT_MS = 300 * 1e3, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6;
|
|
2614
2820
|
const r = {
|
|
2615
2821
|
onAuthChange: (s, o) => {
|
|
2616
|
-
if (s ===
|
|
2617
|
-
const
|
|
2618
|
-
this.setPartialAuthState(
|
|
2822
|
+
if (s === a.TwoFactorRequired) {
|
|
2823
|
+
const n = o;
|
|
2824
|
+
this.setPartialAuthState(n.email, n.challengeId, n.tfaToken);
|
|
2619
2825
|
}
|
|
2620
2826
|
}
|
|
2621
2827
|
};
|
|
2622
|
-
this.subscribeStore.subscribe(r, [
|
|
2828
|
+
this.subscribeStore.subscribe(r, [a.TwoFactorRequired]);
|
|
2623
2829
|
}
|
|
2624
2830
|
/**
|
|
2625
2831
|
* Emit error event and throw the error
|
|
@@ -2631,7 +2837,7 @@ class De {
|
|
|
2631
2837
|
originalError: e,
|
|
2632
2838
|
code: r?.id || void 0
|
|
2633
2839
|
};
|
|
2634
|
-
throw this.subscribeStore.notify(
|
|
2840
|
+
throw this.subscribeStore.notify(a.Error, s), e;
|
|
2635
2841
|
}
|
|
2636
2842
|
/**
|
|
2637
2843
|
* Get 2FA enrollment status for current user
|
|
@@ -2651,7 +2857,7 @@ class De {
|
|
|
2651
2857
|
async beginSetup() {
|
|
2652
2858
|
try {
|
|
2653
2859
|
const e = await this.twoFactorApi.beginSetup();
|
|
2654
|
-
return e.totp_digits && (this.totpDigits = e.totp_digits), this.subscribeStore.notify(
|
|
2860
|
+
return e.totp_digits && (this.totpDigits = e.totp_digits), this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: e.secret }), e;
|
|
2655
2861
|
} catch (e) {
|
|
2656
2862
|
this.emitErrorAndThrow(e, "Begin 2FA setup");
|
|
2657
2863
|
}
|
|
@@ -2661,11 +2867,11 @@ class De {
|
|
|
2661
2867
|
* Returns recovery codes that MUST be displayed to user
|
|
2662
2868
|
*/
|
|
2663
2869
|
async confirmSetup(e) {
|
|
2664
|
-
if (!
|
|
2870
|
+
if (!C(e, this.totpDigits))
|
|
2665
2871
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2666
2872
|
try {
|
|
2667
2873
|
const t = await this.twoFactorApi.confirmSetup({ code: e });
|
|
2668
|
-
return this.subscribeStore.notify(
|
|
2874
|
+
return this.subscribeStore.notify(a.TwoFactorEnabled, {
|
|
2669
2875
|
recoveryCodes: t.recovery_codes,
|
|
2670
2876
|
clearRecoveryCodes: () => {
|
|
2671
2877
|
t.recovery_codes.length = 0;
|
|
@@ -2680,7 +2886,7 @@ class De {
|
|
|
2680
2886
|
* Completes authentication if successful
|
|
2681
2887
|
*/
|
|
2682
2888
|
async verify(e) {
|
|
2683
|
-
if (!
|
|
2889
|
+
if (!C(e, this.totpDigits))
|
|
2684
2890
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2685
2891
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired())
|
|
2686
2892
|
throw new Error("2FA verification expired or not required. User must sign in first.");
|
|
@@ -2691,7 +2897,7 @@ class De {
|
|
|
2691
2897
|
code: e,
|
|
2692
2898
|
tfa_token: this.partialAuthState.tfaToken
|
|
2693
2899
|
});
|
|
2694
|
-
return this.clearPartialAuthState(), this.subscribeStore.notify(
|
|
2900
|
+
return this.clearPartialAuthState(), this.subscribeStore.notify(a.TwoFactorVerified, { tokens: t }), t;
|
|
2695
2901
|
} catch (t) {
|
|
2696
2902
|
this.emitErrorAndThrow(t, "Verify 2FA code");
|
|
2697
2903
|
}
|
|
@@ -2702,7 +2908,7 @@ class De {
|
|
|
2702
2908
|
*/
|
|
2703
2909
|
async useRecoveryCode(e) {
|
|
2704
2910
|
try {
|
|
2705
|
-
const t =
|
|
2911
|
+
const t = Ce(e);
|
|
2706
2912
|
if (!t)
|
|
2707
2913
|
throw new Error("Invalid recovery code format. Expected format: XXXX-XXXX or XXXXXXXX (alphanumeric).");
|
|
2708
2914
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired())
|
|
@@ -2713,13 +2919,13 @@ class De {
|
|
|
2713
2919
|
recovery_code: t,
|
|
2714
2920
|
tfa_token: this.partialAuthState.tfaToken
|
|
2715
2921
|
});
|
|
2716
|
-
return this.clearPartialAuthState(), r.remaining_recovery_codes === 0 ? this.subscribeStore.notify(
|
|
2922
|
+
return this.clearPartialAuthState(), r.remaining_recovery_codes === 0 ? this.subscribeStore.notify(a.TwoFactorRecoveryCodesExhausted, { tokens: r }) : r.remaining_recovery_codes <= 2 && this.subscribeStore.notify(a.TwoFactorRecoveryCodesLow, {
|
|
2717
2923
|
tokens: r,
|
|
2718
2924
|
remainingCodes: r.remaining_recovery_codes
|
|
2719
|
-
}), this.subscribeStore.notify(
|
|
2925
|
+
}), this.subscribeStore.notify(a.TwoFactorRecoveryUsed, {
|
|
2720
2926
|
tokens: r,
|
|
2721
2927
|
remainingCodes: r.remaining_recovery_codes
|
|
2722
|
-
}), this.subscribeStore.notify(
|
|
2928
|
+
}), this.subscribeStore.notify(a.TwoFactorVerified, { tokens: r }), r;
|
|
2723
2929
|
} catch (t) {
|
|
2724
2930
|
this.emitErrorAndThrow(t, "Use recovery code");
|
|
2725
2931
|
}
|
|
@@ -2728,11 +2934,11 @@ class De {
|
|
|
2728
2934
|
* Disable 2FA (requires TOTP verification)
|
|
2729
2935
|
*/
|
|
2730
2936
|
async disable(e) {
|
|
2731
|
-
if (!
|
|
2937
|
+
if (!C(e, this.totpDigits))
|
|
2732
2938
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2733
2939
|
try {
|
|
2734
2940
|
const t = await this.twoFactorApi.disable({ code: e });
|
|
2735
|
-
return this.subscribeStore.notify(
|
|
2941
|
+
return this.subscribeStore.notify(a.TwoFactorDisabled, {}), t;
|
|
2736
2942
|
} catch (t) {
|
|
2737
2943
|
this.emitErrorAndThrow(t, "Disable 2FA");
|
|
2738
2944
|
}
|
|
@@ -2741,7 +2947,7 @@ class De {
|
|
|
2741
2947
|
* Regenerate recovery codes
|
|
2742
2948
|
*/
|
|
2743
2949
|
async regenerateRecoveryCodes(e) {
|
|
2744
|
-
if (!
|
|
2950
|
+
if (!C(e, this.totpDigits))
|
|
2745
2951
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2746
2952
|
try {
|
|
2747
2953
|
const t = await this.twoFactorApi.regenerateRecoveryCodes({ code: e }), r = [...t.recovery_codes];
|
|
@@ -2832,12 +3038,12 @@ class De {
|
|
|
2832
3038
|
scope: "2fa_setup",
|
|
2833
3039
|
timestamp: Date.now(),
|
|
2834
3040
|
expiresAt: Date.now() + (t.expiresIn || 3600) * 1e3
|
|
2835
|
-
}, this.subscribeStore.notify(
|
|
3041
|
+
}, this.subscribeStore.notify(a.TwoFactorSetupMagicLinkValidated, {
|
|
2836
3042
|
userId: t.userId,
|
|
2837
3043
|
appId: t.appId,
|
|
2838
3044
|
expiresIn: t.expiresIn || 3600,
|
|
2839
3045
|
sessionToken: t.sessionToken
|
|
2840
|
-
})) : t.error && this.subscribeStore.notify(
|
|
3046
|
+
})) : t.error && this.subscribeStore.notify(a.TwoFactorSetupMagicLinkFailed, {
|
|
2841
3047
|
error: t.error
|
|
2842
3048
|
}), t;
|
|
2843
3049
|
}
|
|
@@ -2908,7 +3114,7 @@ class De {
|
|
|
2908
3114
|
async beginMethodSetup(e) {
|
|
2909
3115
|
try {
|
|
2910
3116
|
const t = await this.twoFactorApi.beginMethodSetup(e);
|
|
2911
|
-
return this.subscribeStore.notify(
|
|
3117
|
+
return this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: "", method: e }), t;
|
|
2912
3118
|
} catch (t) {
|
|
2913
3119
|
this.emitErrorAndThrow(t, "Begin 2FA method setup");
|
|
2914
3120
|
}
|
|
@@ -2919,7 +3125,7 @@ class De {
|
|
|
2919
3125
|
async confirmMethodSetup(e, t) {
|
|
2920
3126
|
try {
|
|
2921
3127
|
const r = await this.twoFactorApi.confirmMethodSetup(e, t);
|
|
2922
|
-
return this.subscribeStore.notify(
|
|
3128
|
+
return this.subscribeStore.notify(a.TwoFactorEnabled, {
|
|
2923
3129
|
recoveryCodes: [],
|
|
2924
3130
|
clearRecoveryCodes: () => {
|
|
2925
3131
|
}
|
|
@@ -2944,7 +3150,7 @@ class De {
|
|
|
2944
3150
|
async requestChallenge(e) {
|
|
2945
3151
|
try {
|
|
2946
3152
|
const t = await this.twoFactorApi.requestChallenge(e);
|
|
2947
|
-
return this.subscribeStore.notify(
|
|
3153
|
+
return this.subscribeStore.notify(a.TwoFactorChallengeReceived, {
|
|
2948
3154
|
challengeId: t.challenge_id,
|
|
2949
3155
|
method: t.method,
|
|
2950
3156
|
alternativeMethods: t.alternative_methods
|
|
@@ -2959,12 +3165,12 @@ class De {
|
|
|
2959
3165
|
async verifyV2(e) {
|
|
2960
3166
|
try {
|
|
2961
3167
|
const t = await this.twoFactorApi.verifyV2(e);
|
|
2962
|
-
return t.success && (this.subscribeStore.notify(
|
|
3168
|
+
return t.success && (this.subscribeStore.notify(a.TwoFactorVerified, {
|
|
2963
3169
|
tokens: {
|
|
2964
3170
|
access_token: t.access_token,
|
|
2965
3171
|
refresh_token: t.refresh_token
|
|
2966
3172
|
}
|
|
2967
|
-
}), t.device_trusted && this.subscribeStore.notify(
|
|
3173
|
+
}), t.device_trusted && this.subscribeStore.notify(a.TwoFactorDeviceTrusted, {})), t;
|
|
2968
3174
|
} catch (t) {
|
|
2969
3175
|
this.emitErrorAndThrow(t, "Verify 2FA challenge");
|
|
2970
3176
|
}
|
|
@@ -2975,7 +3181,7 @@ class De {
|
|
|
2975
3181
|
async switchToAlternative(e) {
|
|
2976
3182
|
try {
|
|
2977
3183
|
const t = await this.twoFactorApi.switchToAlternative(e);
|
|
2978
|
-
return this.subscribeStore.notify(
|
|
3184
|
+
return this.subscribeStore.notify(a.TwoFactorMethodSwitched, {
|
|
2979
3185
|
challengeId: t.challenge_id,
|
|
2980
3186
|
method: t.method,
|
|
2981
3187
|
alternativeMethods: t.alternative_methods
|
|
@@ -3005,9 +3211,9 @@ class De {
|
|
|
3005
3211
|
}
|
|
3006
3212
|
}
|
|
3007
3213
|
}
|
|
3008
|
-
class
|
|
3009
|
-
constructor(e, t) {
|
|
3010
|
-
this.userAPI = e, this.deviceService = t;
|
|
3214
|
+
class Oe {
|
|
3215
|
+
constructor(e, t, r = A) {
|
|
3216
|
+
this.userAPI = e, this.deviceService = t, this.platform = r;
|
|
3011
3217
|
}
|
|
3012
3218
|
/**
|
|
3013
3219
|
* Get user's registered passkeys
|
|
@@ -3043,31 +3249,34 @@ class Pe {
|
|
|
3043
3249
|
passkeyUsername: t,
|
|
3044
3250
|
passkeyDisplayName: r
|
|
3045
3251
|
} = {}) {
|
|
3046
|
-
|
|
3047
|
-
|
|
3252
|
+
if (!this.platform.passkeys) throw new Error("Passkeys are not supported on this platform");
|
|
3253
|
+
const s = this.deviceService.getDeviceId(), o = this.platform.getDeviceType(), { challenge_id: n, publicKey: h } = await this.userAPI.addUserPasskeyStart({
|
|
3254
|
+
relyingPartyId: (e || this.platform.getCurrentUrl()?.hostname) ?? "",
|
|
3048
3255
|
deviceId: s,
|
|
3049
3256
|
os: o,
|
|
3050
3257
|
passkeyDisplayName: r,
|
|
3051
3258
|
passkeyUsername: t
|
|
3052
3259
|
});
|
|
3053
|
-
|
|
3054
|
-
const
|
|
3055
|
-
|
|
3260
|
+
h.user.id = this.platform.btoa(h.user.id);
|
|
3261
|
+
const d = await this.platform.passkeys.startRegistration(h);
|
|
3262
|
+
if (!d) throw new Error("Passkey registration was not completed");
|
|
3263
|
+
return await this.userAPI.addUserPasskeyComplete(d, s, n);
|
|
3056
3264
|
}
|
|
3057
3265
|
}
|
|
3058
3266
|
const O = class O {
|
|
3059
3267
|
constructor(e) {
|
|
3060
|
-
this.doRefreshTokens = !1, this.
|
|
3268
|
+
this.doRefreshTokens = !1, this.session = async ({
|
|
3061
3269
|
createSession: o,
|
|
3062
|
-
expiredSession:
|
|
3063
|
-
doRefresh:
|
|
3270
|
+
expiredSession: n,
|
|
3271
|
+
doRefresh: h = !1
|
|
3064
3272
|
}) => {
|
|
3065
|
-
this.createSessionCallback = o, this.expiredSessionCallback =
|
|
3273
|
+
this.createSessionCallback = o, this.expiredSessionCallback = n, this.doRefreshTokens = h, await this.submitSessionCheck();
|
|
3066
3274
|
};
|
|
3067
3275
|
const { url: t, appId: r, scopes: s } = e;
|
|
3068
|
-
this.url = t ||
|
|
3069
|
-
prefix: e.keyStoragePrefix ?? ""
|
|
3070
|
-
|
|
3276
|
+
this.url = t || K, this.appId = r, this.platform = e.platform ?? A, this.storageManager = new $({
|
|
3277
|
+
prefix: e.keyStoragePrefix ?? "",
|
|
3278
|
+
storage: this.platform.storage
|
|
3279
|
+
}), this.deviceService = new B(this.storageManager), this.authApi = new ye(e, this.storageManager, this.deviceService), this.appApi = new ve(e, this.storageManager, this.deviceService), this.userApi = new _e(e, this.storageManager, this.deviceService), this.settingApi = new we(e, this.storageManager, this.deviceService), this.tenantApi = new Te(e, this.storageManager, this.deviceService), this.invitationApi = new Se(e, this.storageManager, this.deviceService), this.twoFactorApi = new Ee(e, this.storageManager, this.deviceService), this.subscribeStore = new Ie(), this.tokenCacheService = new Ue(this.storageManager, this.authApi, this.subscribeStore, this.platform), this.scopes = s ?? te, this.createTenantForNewUser = e.createTenantForNewUser ?? !1, this.authService = new Re(
|
|
3071
3280
|
this.authApi,
|
|
3072
3281
|
this.deviceService,
|
|
3073
3282
|
this.storageManager,
|
|
@@ -3075,15 +3284,18 @@ const O = class O {
|
|
|
3075
3284
|
this.tokenCacheService,
|
|
3076
3285
|
this.scopes,
|
|
3077
3286
|
this.createTenantForNewUser,
|
|
3078
|
-
this.origin,
|
|
3079
3287
|
this.url,
|
|
3080
3288
|
{
|
|
3081
3289
|
createSession: this.createSessionCallback,
|
|
3082
3290
|
expiredSession: this.expiredSessionCallback
|
|
3083
3291
|
},
|
|
3084
3292
|
this.appId ?? "",
|
|
3085
|
-
e.tokenExchange
|
|
3086
|
-
|
|
3293
|
+
e.tokenExchange,
|
|
3294
|
+
this.platform
|
|
3295
|
+
), this.userService = new Oe(this.userApi, this.deviceService, this.platform), this.tenantService = new xe(this.tenantApi, this.scopes), this.tenant = this.tenantService, this.invitationService = new Fe(this.invitationApi), this.twoFactorService = new $e(this.twoFactorApi, this.subscribeStore), this.twoFactor = this.twoFactorService, e.parseQueryParams && this.checkAndSetTokens(), this.setTokensToCacheFromLocalStorage();
|
|
3296
|
+
}
|
|
3297
|
+
get origin() {
|
|
3298
|
+
return this.platform.getCurrentUrl()?.origin ?? "";
|
|
3087
3299
|
}
|
|
3088
3300
|
/**
|
|
3089
3301
|
* Update the appId and propagate it to all API clients.
|
|
@@ -3106,10 +3318,10 @@ const O = class O {
|
|
|
3106
3318
|
e = await this.authService.getTokens(this.doRefreshTokens), t = this.tokenCacheService.getParsedTokens();
|
|
3107
3319
|
} catch (r) {
|
|
3108
3320
|
const s = {
|
|
3109
|
-
message: r instanceof Error || r instanceof
|
|
3321
|
+
message: r instanceof Error || r instanceof l ? r.message : "Session check failed",
|
|
3110
3322
|
originalError: r
|
|
3111
3323
|
};
|
|
3112
|
-
this.subscribeStore.notify(
|
|
3324
|
+
this.subscribeStore.notify(a.Error, s), e = void 0;
|
|
3113
3325
|
}
|
|
3114
3326
|
e && this.createSessionCallback && await this.createSessionCallback({ tokens: e, parsedTokens: t }), !e && this.expiredSessionCallback && await this.expiredSessionCallback();
|
|
3115
3327
|
}
|
|
@@ -3182,61 +3394,64 @@ const O = class O {
|
|
|
3182
3394
|
return this.checkAndSetTokens();
|
|
3183
3395
|
}
|
|
3184
3396
|
checkAndSetTokens() {
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3397
|
+
const e = this.platform.getCurrentUrl();
|
|
3398
|
+
let t = new URLSearchParams(e?.search ?? ""), r = !1;
|
|
3399
|
+
if (!t.get("access_token") && e?.hash) {
|
|
3400
|
+
const u = new URLSearchParams(e.hash.substring(1));
|
|
3401
|
+
u.get("access_token") && (t = u, r = !0);
|
|
3189
3402
|
}
|
|
3190
|
-
const
|
|
3403
|
+
const s = t.get("access_token"), o = t.get("refresh_token"), n = t.get("id_token"), h = t.get("scopes")?.split(",") ?? this.scopes;
|
|
3191
3404
|
let d;
|
|
3192
|
-
if (
|
|
3193
|
-
if (!D(
|
|
3194
|
-
const
|
|
3405
|
+
if (s) {
|
|
3406
|
+
if (!D(s)) {
|
|
3407
|
+
const u = {
|
|
3195
3408
|
message: "Invalid access token format received",
|
|
3196
3409
|
code: "INVALID_TOKEN_FORMAT"
|
|
3197
3410
|
};
|
|
3198
|
-
this.subscribeStore.notify(
|
|
3411
|
+
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3199
3412
|
return;
|
|
3200
3413
|
}
|
|
3201
|
-
if (
|
|
3202
|
-
const
|
|
3414
|
+
if (o && !D(o)) {
|
|
3415
|
+
const u = {
|
|
3203
3416
|
message: "Invalid refresh token format received",
|
|
3204
3417
|
code: "INVALID_TOKEN_FORMAT"
|
|
3205
3418
|
};
|
|
3206
|
-
this.subscribeStore.notify(
|
|
3419
|
+
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3207
3420
|
return;
|
|
3208
3421
|
}
|
|
3209
|
-
if (
|
|
3210
|
-
const
|
|
3422
|
+
if (n && !D(n)) {
|
|
3423
|
+
const u = {
|
|
3211
3424
|
message: "Invalid ID token format received",
|
|
3212
3425
|
code: "INVALID_TOKEN_FORMAT"
|
|
3213
3426
|
};
|
|
3214
|
-
this.subscribeStore.notify(
|
|
3427
|
+
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3215
3428
|
return;
|
|
3216
3429
|
}
|
|
3217
3430
|
return d = {
|
|
3218
|
-
access_token:
|
|
3219
|
-
refresh_token:
|
|
3220
|
-
id_token:
|
|
3221
|
-
scopes:
|
|
3222
|
-
}, this.storageManager.clearDeliveryMode(), this.storageManager.saveTokens(d), this.tokenCacheService.setTokensCache(d), this.subscribeStore.notify(
|
|
3431
|
+
access_token: s,
|
|
3432
|
+
refresh_token: o ?? void 0,
|
|
3433
|
+
id_token: n ?? void 0,
|
|
3434
|
+
scopes: h
|
|
3435
|
+
}, this.storageManager.clearDeliveryMode(), this.storageManager.saveTokens(d), this.tokenCacheService.setTokensCache(d), this.subscribeStore.notify(a.SignIn, { tokens: d, parsedTokens: this.getParsedTokens() }), this.submitSessionCheck(), this.cleanupUrlParams(r, e), this.error = void 0, d;
|
|
3223
3436
|
} else
|
|
3224
3437
|
this.error = this.checkErrorsFromURL();
|
|
3225
3438
|
}
|
|
3226
3439
|
checkErrorsFromURL() {
|
|
3227
|
-
const t = new URLSearchParams(
|
|
3440
|
+
const t = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
|
|
3228
3441
|
if (t) {
|
|
3229
|
-
const r =
|
|
3442
|
+
const r = be(t);
|
|
3230
3443
|
return new Error(r);
|
|
3231
3444
|
}
|
|
3232
3445
|
}
|
|
3233
|
-
cleanupUrlParams(e = !1) {
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3446
|
+
cleanupUrlParams(e = !1, t = null) {
|
|
3447
|
+
const r = t ?? this.platform.getCurrentUrl();
|
|
3448
|
+
if (r)
|
|
3449
|
+
if (e)
|
|
3450
|
+
this.platform.replaceUrl(r.pathname + r.search);
|
|
3451
|
+
else {
|
|
3452
|
+
const s = new URLSearchParams(r.search);
|
|
3453
|
+
s.delete("access_token"), s.delete("refresh_token"), s.delete("id_token"), s.delete("client_challenge"), s.size > 0 ? this.platform.replaceUrl(`${r.pathname}?${s.toString()}`) : this.platform.replaceUrl(r.pathname);
|
|
3454
|
+
}
|
|
3240
3455
|
}
|
|
3241
3456
|
setTokensToCacheFromLocalStorage() {
|
|
3242
3457
|
let e = this.storageManager.getTokens();
|
|
@@ -3452,9 +3667,9 @@ const O = class O {
|
|
|
3452
3667
|
const r = {
|
|
3453
3668
|
message: e instanceof Error ? e.message : `${t} failed`,
|
|
3454
3669
|
originalError: e,
|
|
3455
|
-
code: e instanceof
|
|
3670
|
+
code: e instanceof l ? e.id : void 0
|
|
3456
3671
|
};
|
|
3457
|
-
throw this.subscribeStore.notify(
|
|
3672
|
+
throw this.subscribeStore.notify(a.Error, r), e;
|
|
3458
3673
|
}
|
|
3459
3674
|
/**
|
|
3460
3675
|
* Sign out the current user and clear all tokens.
|
|
@@ -3475,7 +3690,7 @@ const O = class O {
|
|
|
3475
3690
|
*/
|
|
3476
3691
|
async logOut() {
|
|
3477
3692
|
try {
|
|
3478
|
-
await this.authService.logOut(), this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.twoFactorService.clearPartialAuthState(), await this.submitSessionCheck(), this.subscribeStore.notify(
|
|
3693
|
+
await this.authService.logOut(), this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.twoFactorService.clearPartialAuthState(), await this.submitSessionCheck(), this.subscribeStore.notify(a.SignOut, {});
|
|
3479
3694
|
} catch (e) {
|
|
3480
3695
|
this.handleError(e, "Log out");
|
|
3481
3696
|
}
|
|
@@ -3545,13 +3760,13 @@ const O = class O {
|
|
|
3545
3760
|
* ```
|
|
3546
3761
|
*/
|
|
3547
3762
|
reset(e) {
|
|
3548
|
-
if (this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.subscribeStore.notify(
|
|
3763
|
+
if (this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.subscribeStore.notify(a.SignOut, {}), e) {
|
|
3549
3764
|
this.error = new Error(e);
|
|
3550
3765
|
const t = {
|
|
3551
3766
|
message: e,
|
|
3552
3767
|
code: "RESET_ERROR"
|
|
3553
3768
|
};
|
|
3554
|
-
throw this.subscribeStore.notify(
|
|
3769
|
+
throw this.subscribeStore.notify(a.Error, t), this.error;
|
|
3555
3770
|
}
|
|
3556
3771
|
}
|
|
3557
3772
|
/**
|
|
@@ -3578,7 +3793,7 @@ const O = class O {
|
|
|
3578
3793
|
try {
|
|
3579
3794
|
return await this.authService.refreshToken();
|
|
3580
3795
|
} catch (e) {
|
|
3581
|
-
throw e instanceof
|
|
3796
|
+
throw e instanceof l || this.subscribeStore.notify(a.Error, {
|
|
3582
3797
|
message: "Failed to refresh token",
|
|
3583
3798
|
originalError: e
|
|
3584
3799
|
}), e;
|
|
@@ -3783,7 +3998,7 @@ const O = class O {
|
|
|
3783
3998
|
* ```
|
|
3784
3999
|
*/
|
|
3785
4000
|
setTokens(e) {
|
|
3786
|
-
this.storageManager.saveTokens(e), this.tokenCacheService.setTokensCache(e), this.subscribeStore.notify(
|
|
4001
|
+
this.storageManager.saveTokens(e), this.tokenCacheService.setTokensCache(e), this.subscribeStore.notify(a.SignIn, {
|
|
3787
4002
|
tokens: e,
|
|
3788
4003
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
3789
4004
|
});
|
|
@@ -4219,7 +4434,7 @@ const O = class O {
|
|
|
4219
4434
|
async verifyTwoFactor(e) {
|
|
4220
4435
|
try {
|
|
4221
4436
|
const t = await this.twoFactorService.verify(e);
|
|
4222
|
-
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(
|
|
4437
|
+
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(a.SignIn, {
|
|
4223
4438
|
tokens: t,
|
|
4224
4439
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4225
4440
|
}), await this.submitSessionCheck(), t;
|
|
@@ -4246,7 +4461,7 @@ const O = class O {
|
|
|
4246
4461
|
async useTwoFactorRecoveryCode(e) {
|
|
4247
4462
|
try {
|
|
4248
4463
|
const t = await this.twoFactorService.useRecoveryCode(e);
|
|
4249
|
-
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(
|
|
4464
|
+
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(a.SignIn, {
|
|
4250
4465
|
tokens: t,
|
|
4251
4466
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4252
4467
|
}), await this.submitSessionCheck(), t;
|
|
@@ -4408,20 +4623,20 @@ const O = class O {
|
|
|
4408
4623
|
this.twoFactorService.clearMagicLinkSession();
|
|
4409
4624
|
}
|
|
4410
4625
|
};
|
|
4411
|
-
O.version =
|
|
4626
|
+
O.version = ee;
|
|
4412
4627
|
let L = O;
|
|
4413
|
-
class
|
|
4628
|
+
class p extends Error {
|
|
4414
4629
|
constructor(e) {
|
|
4415
|
-
super(e.message), this.name = "M2MError", this.code = e.code, this.status = e.status ?? 400, this.errorUri = e.errorUri, this.rateLimitInfo = e.rateLimitInfo, this.headers = e.headers, this.cause = e.cause, this.timestamp = (/* @__PURE__ */ new Date()).toISOString(), Error.captureStackTrace && Error.captureStackTrace(this,
|
|
4630
|
+
super(e.message), this.name = "M2MError", this.code = e.code, this.status = e.status ?? 400, this.errorUri = e.errorUri, this.rateLimitInfo = e.rateLimitInfo, this.headers = e.headers, this.cause = e.cause, this.timestamp = (/* @__PURE__ */ new Date()).toISOString(), Error.captureStackTrace && Error.captureStackTrace(this, p);
|
|
4416
4631
|
}
|
|
4417
4632
|
/**
|
|
4418
4633
|
* Create an M2MError from an OAuth 2.0 error response
|
|
4419
4634
|
*/
|
|
4420
4635
|
static fromOAuthError(e, t, r) {
|
|
4421
|
-
const s = r ?
|
|
4422
|
-
return new
|
|
4636
|
+
const s = r ? p.parseRateLimitHeaders(r) : void 0;
|
|
4637
|
+
return new p({
|
|
4423
4638
|
code: e.error,
|
|
4424
|
-
message: e.error_description ??
|
|
4639
|
+
message: e.error_description ?? p.getDefaultMessage(e.error),
|
|
4425
4640
|
status: t,
|
|
4426
4641
|
errorUri: e.error_uri,
|
|
4427
4642
|
rateLimitInfo: s,
|
|
@@ -4432,7 +4647,7 @@ class l extends Error {
|
|
|
4432
4647
|
* Create an M2MError from a network or other error
|
|
4433
4648
|
*/
|
|
4434
4649
|
static fromError(e, t = "server_error") {
|
|
4435
|
-
return new
|
|
4650
|
+
return new p({
|
|
4436
4651
|
code: t,
|
|
4437
4652
|
message: e.message || "An unexpected error occurred",
|
|
4438
4653
|
status: 500,
|
|
@@ -4505,7 +4720,7 @@ class l extends Error {
|
|
|
4505
4720
|
return this.status && (e += ` (HTTP ${this.status})`), e;
|
|
4506
4721
|
}
|
|
4507
4722
|
}
|
|
4508
|
-
class N extends
|
|
4723
|
+
class N extends p {
|
|
4509
4724
|
constructor(e, t) {
|
|
4510
4725
|
super({
|
|
4511
4726
|
code: "temporarily_unavailable",
|
|
@@ -4515,7 +4730,7 @@ class N extends l {
|
|
|
4515
4730
|
}), this.name = "M2MNetworkError";
|
|
4516
4731
|
}
|
|
4517
4732
|
}
|
|
4518
|
-
class
|
|
4733
|
+
class R extends p {
|
|
4519
4734
|
constructor(e, t) {
|
|
4520
4735
|
super({
|
|
4521
4736
|
code: "invalid_request",
|
|
@@ -4525,7 +4740,7 @@ class M extends l {
|
|
|
4525
4740
|
}), this.name = "M2MTokenParseError";
|
|
4526
4741
|
}
|
|
4527
4742
|
}
|
|
4528
|
-
class U extends
|
|
4743
|
+
class U extends p {
|
|
4529
4744
|
constructor(e) {
|
|
4530
4745
|
super({
|
|
4531
4746
|
code: "invalid_request",
|
|
@@ -4534,7 +4749,7 @@ class U extends l {
|
|
|
4534
4749
|
}), this.name = "M2MConfigError";
|
|
4535
4750
|
}
|
|
4536
4751
|
}
|
|
4537
|
-
const
|
|
4752
|
+
const He = {
|
|
4538
4753
|
InvalidRequest: "invalid_request",
|
|
4539
4754
|
InvalidClient: "invalid_client",
|
|
4540
4755
|
InvalidGrant: "invalid_grant",
|
|
@@ -4558,7 +4773,7 @@ const Ge = {
|
|
|
4558
4773
|
/** Content-Type for token requests */
|
|
4559
4774
|
CONTENT_TYPE: "application/x-www-form-urlencoded"
|
|
4560
4775
|
};
|
|
4561
|
-
class
|
|
4776
|
+
class Le {
|
|
4562
4777
|
constructor() {
|
|
4563
4778
|
this.cache = /* @__PURE__ */ new Map();
|
|
4564
4779
|
}
|
|
@@ -4576,7 +4791,7 @@ class xe {
|
|
|
4576
4791
|
return this.cache.delete(e), Promise.resolve();
|
|
4577
4792
|
}
|
|
4578
4793
|
}
|
|
4579
|
-
const
|
|
4794
|
+
const Ne = {
|
|
4580
4795
|
shouldRetry(i, e) {
|
|
4581
4796
|
return e >= 3 ? !1 : i.code === "server_error" || i.code === "temporarily_unavailable" || i.code === "rate_limit_exceeded" || i.status !== void 0 && i.status >= 500;
|
|
4582
4797
|
},
|
|
@@ -4584,7 +4799,7 @@ const Ue = {
|
|
|
4584
4799
|
return Math.pow(2, i - 1) * 1e3;
|
|
4585
4800
|
}
|
|
4586
4801
|
};
|
|
4587
|
-
class
|
|
4802
|
+
class ze {
|
|
4588
4803
|
/**
|
|
4589
4804
|
* Create a new M2M client
|
|
4590
4805
|
*
|
|
@@ -4624,7 +4839,7 @@ class qe {
|
|
|
4624
4839
|
onTokenRequest: e.onTokenRequest,
|
|
4625
4840
|
onTokenResponse: e.onTokenResponse,
|
|
4626
4841
|
onError: e.onError
|
|
4627
|
-
}, this.cache = e.cache ?? new
|
|
4842
|
+
}, this.cache = e.cache ?? new Le(), this.retryStrategy = e.retryStrategy ?? Ne, this.tokenEndpoint = `${t}${T.TOKEN_ENDPOINT}`;
|
|
4628
4843
|
}
|
|
4629
4844
|
/**
|
|
4630
4845
|
* Get the cache key for this client
|
|
@@ -4722,29 +4937,29 @@ class qe {
|
|
|
4722
4937
|
signal: r.signal
|
|
4723
4938
|
});
|
|
4724
4939
|
clearTimeout(s);
|
|
4725
|
-
const
|
|
4726
|
-
o.headers.forEach((
|
|
4727
|
-
|
|
4940
|
+
const n = {};
|
|
4941
|
+
o.headers.forEach((d, u) => {
|
|
4942
|
+
n[u.toLowerCase()] = d;
|
|
4728
4943
|
});
|
|
4729
|
-
const
|
|
4944
|
+
const h = await o.json();
|
|
4730
4945
|
if (!o.ok) {
|
|
4731
|
-
const
|
|
4946
|
+
const d = p.fromOAuthError(
|
|
4732
4947
|
{
|
|
4733
|
-
error:
|
|
4734
|
-
error_description:
|
|
4735
|
-
error_uri:
|
|
4948
|
+
error: h.error || "server_error",
|
|
4949
|
+
error_description: h.error_description || h.message,
|
|
4950
|
+
error_uri: h.error_uri
|
|
4736
4951
|
},
|
|
4737
4952
|
o.status,
|
|
4738
|
-
|
|
4953
|
+
n
|
|
4739
4954
|
);
|
|
4740
4955
|
throw this.config.onError && this.config.onError({
|
|
4741
|
-
error:
|
|
4742
|
-
error_description:
|
|
4743
|
-
}),
|
|
4956
|
+
error: d.code,
|
|
4957
|
+
error_description: d.message
|
|
4958
|
+
}), d;
|
|
4744
4959
|
}
|
|
4745
|
-
return
|
|
4960
|
+
return h;
|
|
4746
4961
|
} catch (o) {
|
|
4747
|
-
throw clearTimeout(s), o instanceof Error && o.name === "AbortError" ? new N(`Request timed out after ${this.config.timeout}ms`) : o instanceof TypeError && o.message.includes("fetch") ? new N(`Network error: ${o.message}`, o) : o instanceof
|
|
4962
|
+
throw clearTimeout(s), o instanceof Error && o.name === "AbortError" ? new N(`Request timed out after ${this.config.timeout}ms`) : o instanceof TypeError && o.message.includes("fetch") ? new N(`Network error: ${o.message}`, o) : o instanceof p ? o : p.fromError(o instanceof Error ? o : new Error(String(o)));
|
|
4748
4963
|
}
|
|
4749
4964
|
}
|
|
4750
4965
|
/**
|
|
@@ -4756,7 +4971,7 @@ class qe {
|
|
|
4756
4971
|
try {
|
|
4757
4972
|
return await e();
|
|
4758
4973
|
} catch (s) {
|
|
4759
|
-
if (!(s instanceof
|
|
4974
|
+
if (!(s instanceof p))
|
|
4760
4975
|
throw s;
|
|
4761
4976
|
if (t = s, r < this.config.retries && this.retryStrategy.shouldRetry({ code: s.code, status: s.status }, r)) {
|
|
4762
4977
|
const o = this.retryStrategy.getDelay(r);
|
|
@@ -4765,7 +4980,7 @@ class qe {
|
|
|
4765
4980
|
}
|
|
4766
4981
|
throw s;
|
|
4767
4982
|
}
|
|
4768
|
-
throw t ?? new
|
|
4983
|
+
throw t ?? new p({ code: "server_error", message: "Request failed after retries" });
|
|
4769
4984
|
}
|
|
4770
4985
|
/**
|
|
4771
4986
|
* Sleep for a given duration
|
|
@@ -4839,14 +5054,14 @@ class qe {
|
|
|
4839
5054
|
try {
|
|
4840
5055
|
const t = e.split(".");
|
|
4841
5056
|
if (t.length !== 3)
|
|
4842
|
-
throw new
|
|
5057
|
+
throw new R("Invalid JWT format: expected 3 parts");
|
|
4843
5058
|
const r = t[1];
|
|
4844
5059
|
if (!r)
|
|
4845
|
-
throw new
|
|
5060
|
+
throw new R("Invalid JWT format: missing payload");
|
|
4846
5061
|
const s = atob(r.replace(/-/g, "+").replace(/_/g, "/")), o = JSON.parse(s);
|
|
4847
5062
|
return o.scopes && typeof o.scopes == "string" ? o.scopes = o.scopes.split(" ") : o.scopes || (o.scopes = []), o;
|
|
4848
5063
|
} catch (t) {
|
|
4849
|
-
throw t instanceof
|
|
5064
|
+
throw t instanceof R ? t : new R(`Failed to parse token: ${t instanceof Error ? t.message : "Unknown error"}`);
|
|
4850
5065
|
}
|
|
4851
5066
|
}
|
|
4852
5067
|
/**
|
|
@@ -4893,7 +5108,7 @@ class qe {
|
|
|
4893
5108
|
});
|
|
4894
5109
|
if (!s.ok && s.status !== 200) {
|
|
4895
5110
|
const o = await s.json().catch(() => ({}));
|
|
4896
|
-
throw
|
|
5111
|
+
throw p.fromOAuthError(
|
|
4897
5112
|
{
|
|
4898
5113
|
error: o.error || "server_error",
|
|
4899
5114
|
error_description: o.error_description || "Token revocation failed"
|
|
@@ -4903,7 +5118,7 @@ class qe {
|
|
|
4903
5118
|
}
|
|
4904
5119
|
this.clearCache();
|
|
4905
5120
|
} catch (s) {
|
|
4906
|
-
throw s instanceof
|
|
5121
|
+
throw s instanceof p ? s : p.fromError(s instanceof Error ? s : new Error(String(s)));
|
|
4907
5122
|
}
|
|
4908
5123
|
}
|
|
4909
5124
|
/**
|
|
@@ -4932,64 +5147,68 @@ class qe {
|
|
|
4932
5147
|
}
|
|
4933
5148
|
}
|
|
4934
5149
|
export {
|
|
4935
|
-
|
|
5150
|
+
b as APP_ID_HEADER_KEY,
|
|
4936
5151
|
I as AUTHORIZATION_HEADER_KEY,
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
5152
|
+
ve as AppAPI,
|
|
5153
|
+
ye as AuthAPI,
|
|
5154
|
+
Re as AuthService,
|
|
5155
|
+
je as CLIAuthAPI,
|
|
5156
|
+
Be as DEFAULT_GROUP_NAME,
|
|
5157
|
+
te as DEFAULT_SCOPES,
|
|
5158
|
+
Z as DEVICE_ID_HEADER_KEY,
|
|
5159
|
+
Q as DEVICE_TYPE_HEADER_KEY,
|
|
5160
|
+
ce as ERROR_MESSAGE_MAX_LENGTH,
|
|
5161
|
+
Se as InvitationAPI,
|
|
5162
|
+
Fe as InvitationService,
|
|
5163
|
+
ze as M2MClient,
|
|
4949
5164
|
U as M2MConfigError,
|
|
4950
|
-
|
|
4951
|
-
|
|
5165
|
+
p as M2MError,
|
|
5166
|
+
He as M2MErrorCodes,
|
|
4952
5167
|
N as M2MNetworkError,
|
|
4953
|
-
|
|
5168
|
+
R as M2MTokenParseError,
|
|
4954
5169
|
T as M2M_DEFAULTS,
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
5170
|
+
qe as MINIMAL_DEFAULT_SCOPES,
|
|
5171
|
+
ge as OS,
|
|
5172
|
+
K as PASSFLOW_CLOUD_URL,
|
|
5173
|
+
se as POPUP_HEIGHT,
|
|
5174
|
+
ie as POPUP_POLL_INTERVAL_MS,
|
|
5175
|
+
oe as POPUP_TIMEOUT_MS,
|
|
5176
|
+
re as POPUP_WIDTH,
|
|
4962
5177
|
L as Passflow,
|
|
4963
|
-
|
|
5178
|
+
E as PassflowAdminEndpointPaths,
|
|
4964
5179
|
c as PassflowEndpointPaths,
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
5180
|
+
l as PassflowError,
|
|
5181
|
+
a as PassflowEvent,
|
|
5182
|
+
Y as PopupClosedError,
|
|
5183
|
+
pe as Providers,
|
|
5184
|
+
_ as RequestMethod,
|
|
5185
|
+
ee as SDK_VERSION,
|
|
5186
|
+
V as SessionState,
|
|
5187
|
+
we as SettingAPI,
|
|
4972
5188
|
G as TOKEN_EXPIRY_BUFFER_SECONDS,
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
5189
|
+
Te as TenantAPI,
|
|
5190
|
+
xe as TenantService,
|
|
5191
|
+
Pe as TenantUserMembership,
|
|
5192
|
+
Ue as TokenCacheService,
|
|
5193
|
+
y as TokenDeliveryMode,
|
|
5194
|
+
k as TokenType,
|
|
5195
|
+
Ee as TwoFactorApiClient,
|
|
5196
|
+
fe as TwoFactorPolicy,
|
|
5197
|
+
$e as TwoFactorService,
|
|
5198
|
+
ae as USERNAME_MAX_LENGTH,
|
|
5199
|
+
ne as USERNAME_MIN_LENGTH,
|
|
5200
|
+
_e as UserAPI,
|
|
5201
|
+
Oe as UserService,
|
|
5202
|
+
le as WebAdapter,
|
|
5203
|
+
Ye as getOSFromDeviceType,
|
|
4986
5204
|
S as isTokenExpired,
|
|
4987
5205
|
P as isValidEmail,
|
|
4988
5206
|
D as isValidJWTFormat,
|
|
4989
5207
|
x as isValidPhoneNumber,
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
5208
|
+
Ae as isValidUsername,
|
|
5209
|
+
m as parseToken,
|
|
5210
|
+
v as pathWithParams,
|
|
5211
|
+
be as sanitizeErrorMessage,
|
|
5212
|
+
A as webAdapter
|
|
4994
5213
|
};
|
|
4995
5214
|
//# sourceMappingURL=index.mjs.map
|