@passflow/core 0.13.1 → 0.13.3
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 +739 -522
- 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.3", 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,77 +2713,72 @@ 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 {
|
|
2513
2722
|
const e = this.storageManager.getTokens();
|
|
2514
|
-
if (!e)
|
|
2515
|
-
this.startTokenCheck();
|
|
2723
|
+
if (!e)
|
|
2516
2724
|
return;
|
|
2517
|
-
}
|
|
2518
2725
|
if (!e.access_token) {
|
|
2519
2726
|
this.setTokensCache(e), this.startTokenCheck();
|
|
2520
2727
|
return;
|
|
2521
2728
|
}
|
|
2522
|
-
const t =
|
|
2523
|
-
S(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(
|
|
2729
|
+
const t = m(e.access_token);
|
|
2730
|
+
S(t) ? (this.tokenExpiredFlag = !0, this.stopTokenCheck(), this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 })) : (this.setTokensCache(e), this.startTokenCheck());
|
|
2524
2731
|
} catch (e) {
|
|
2525
2732
|
const t = {
|
|
2526
2733
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
2527
2734
|
originalError: e
|
|
2528
2735
|
};
|
|
2529
|
-
this.subscribeStore.notify(
|
|
2736
|
+
this.subscribeStore.notify(a.Error, t), this.setTokensCache(void 0);
|
|
2530
2737
|
}
|
|
2531
2738
|
}
|
|
2532
2739
|
async refreshTokensCache(e) {
|
|
2533
2740
|
if (!this.isRefreshing)
|
|
2534
2741
|
try {
|
|
2535
|
-
this.isRefreshing = !0, this.subscribeStore.notify(
|
|
2742
|
+
this.isRefreshing = !0, this.subscribeStore.notify(a.RefreshStart, {});
|
|
2536
2743
|
const t = await this.authApi.refreshToken(e?.refresh_token ?? "", e.scopes ?? [], e.access_token);
|
|
2537
|
-
this.setTokensCache(t), this.subscribeStore.notify(
|
|
2744
|
+
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
2745
|
} catch (t) {
|
|
2539
2746
|
const r = {
|
|
2540
2747
|
message: t instanceof Error ? t.message : "Failed to get tokens",
|
|
2541
2748
|
originalError: t
|
|
2542
2749
|
};
|
|
2543
|
-
this.subscribeStore.notify(
|
|
2750
|
+
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
2751
|
} finally {
|
|
2545
2752
|
this.isRefreshing = !1;
|
|
2546
2753
|
}
|
|
2547
2754
|
}
|
|
2548
2755
|
startTokenCheck() {
|
|
2549
|
-
this.checkInterval && clearInterval(this.checkInterval), !this.tokenExpiredFlag && (this.
|
|
2550
|
-
|
|
2756
|
+
this.checkInterval && clearInterval(this.checkInterval), !this.tokenExpiredFlag && (this.setupLifecycleListeners(), this.checkInterval = setInterval(() => {
|
|
2757
|
+
this.platform.isInForeground() && (this.isRefreshing || this.tokenExpiredFlag || this.isExpired() && !this.tokenExpiredFlag && (this.tokenExpiredFlag = !0, this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 }), this.stopTokenCheck()));
|
|
2551
2758
|
}, this.CHECK_INTERVAL));
|
|
2552
2759
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
},
|
|
2557
|
-
}
|
|
2558
|
-
setupPageUnloadHandler() {
|
|
2559
|
-
typeof window > "u" || window.addEventListener("beforeunload", () => {
|
|
2760
|
+
setupLifecycleListeners() {
|
|
2761
|
+
this.unsubscribeForeground && (this.unsubscribeForeground(), this.unsubscribeForeground = null), this.unsubscribeForeground = this.platform.onForeground(() => {
|
|
2762
|
+
this.checkInterval && !this.isRefreshing && !this.tokenExpiredFlag && this.isExpired() && (this.tokenExpiredFlag = !0, this.subscribeStore.notify(a.TokenCacheExpired, { isExpired: !0 }), this.stopTokenCheck());
|
|
2763
|
+
}), this.unsubscribeUnload || (this.unsubscribeUnload = this.platform.onBeforeUnload(() => {
|
|
2560
2764
|
this.destroy();
|
|
2561
|
-
});
|
|
2765
|
+
}));
|
|
2562
2766
|
}
|
|
2563
2767
|
stopTokenCheck() {
|
|
2564
|
-
this.checkInterval && (clearInterval(this.checkInterval), this.checkInterval = null), this.
|
|
2768
|
+
this.checkInterval && (clearInterval(this.checkInterval), this.checkInterval = null), this.unsubscribeForeground && (this.unsubscribeForeground(), this.unsubscribeForeground = null);
|
|
2565
2769
|
}
|
|
2566
2770
|
/**
|
|
2567
2771
|
* Cleanup method to stop all intervals and remove event listeners.
|
|
2568
2772
|
* Should be called when the service is no longer needed.
|
|
2569
2773
|
*/
|
|
2570
2774
|
destroy() {
|
|
2571
|
-
this.stopTokenCheck();
|
|
2775
|
+
this.stopTokenCheck(), this.unsubscribeUnload && (this.unsubscribeUnload(), this.unsubscribeUnload = null);
|
|
2572
2776
|
}
|
|
2573
2777
|
setTokensCache(e) {
|
|
2574
2778
|
this.tokensCache = e, e ? this.parsedTokensCache = {
|
|
2575
|
-
access_token: e.access_token ?
|
|
2576
|
-
id_token: e.id_token ?
|
|
2577
|
-
refresh_token: e.refresh_token ?
|
|
2779
|
+
access_token: e.access_token ? m(e.access_token) : void 0,
|
|
2780
|
+
id_token: e.id_token ? m(e.id_token) : void 0,
|
|
2781
|
+
refresh_token: e.refresh_token ? m(e.refresh_token) : void 0,
|
|
2578
2782
|
scopes: e.scopes
|
|
2579
2783
|
} : this.parsedTokensCache = void 0;
|
|
2580
2784
|
}
|
|
@@ -2586,14 +2790,14 @@ class Fe {
|
|
|
2586
2790
|
if (!this.tokensCache) return this.tokensCache;
|
|
2587
2791
|
if (!this.tokensCache.access_token)
|
|
2588
2792
|
return this.tokensCache;
|
|
2589
|
-
const e =
|
|
2793
|
+
const e = m(this.tokensCache.access_token);
|
|
2590
2794
|
return S(e) && !this.tokenExpiredFlag ? (await this.refreshTokensCache(this.tokensCache), this.tokensCache) : this.tokensCache;
|
|
2591
2795
|
} catch (e) {
|
|
2592
2796
|
const t = {
|
|
2593
2797
|
message: e instanceof Error ? e.message : "Failed to get tokens",
|
|
2594
2798
|
originalError: e
|
|
2595
2799
|
};
|
|
2596
|
-
this.subscribeStore.notify(
|
|
2800
|
+
this.subscribeStore.notify(a.Error, t);
|
|
2597
2801
|
return;
|
|
2598
2802
|
}
|
|
2599
2803
|
}
|
|
@@ -2604,22 +2808,22 @@ class Fe {
|
|
|
2604
2808
|
if (!this.tokensCache) return !0;
|
|
2605
2809
|
if (!this.tokensCache.access_token)
|
|
2606
2810
|
return !1;
|
|
2607
|
-
const e =
|
|
2811
|
+
const e = m(this.tokensCache.access_token);
|
|
2608
2812
|
return S(e);
|
|
2609
2813
|
}
|
|
2610
2814
|
}
|
|
2611
|
-
class
|
|
2815
|
+
class $e {
|
|
2612
2816
|
constructor(e, t) {
|
|
2613
2817
|
this.twoFactorApi = e, this.subscribeStore = t, this.PARTIAL_AUTH_TIMEOUT_MS = 300 * 1e3, this.SESSION_STORAGE_KEY = "passflow_2fa_challenge", this.totpDigits = 6;
|
|
2614
2818
|
const r = {
|
|
2615
2819
|
onAuthChange: (s, o) => {
|
|
2616
|
-
if (s ===
|
|
2617
|
-
const
|
|
2618
|
-
this.setPartialAuthState(
|
|
2820
|
+
if (s === a.TwoFactorRequired) {
|
|
2821
|
+
const n = o;
|
|
2822
|
+
this.setPartialAuthState(n.email, n.challengeId, n.tfaToken);
|
|
2619
2823
|
}
|
|
2620
2824
|
}
|
|
2621
2825
|
};
|
|
2622
|
-
this.subscribeStore.subscribe(r, [
|
|
2826
|
+
this.subscribeStore.subscribe(r, [a.TwoFactorRequired]);
|
|
2623
2827
|
}
|
|
2624
2828
|
/**
|
|
2625
2829
|
* Emit error event and throw the error
|
|
@@ -2631,7 +2835,7 @@ class De {
|
|
|
2631
2835
|
originalError: e,
|
|
2632
2836
|
code: r?.id || void 0
|
|
2633
2837
|
};
|
|
2634
|
-
throw this.subscribeStore.notify(
|
|
2838
|
+
throw this.subscribeStore.notify(a.Error, s), e;
|
|
2635
2839
|
}
|
|
2636
2840
|
/**
|
|
2637
2841
|
* Get 2FA enrollment status for current user
|
|
@@ -2651,7 +2855,7 @@ class De {
|
|
|
2651
2855
|
async beginSetup() {
|
|
2652
2856
|
try {
|
|
2653
2857
|
const e = await this.twoFactorApi.beginSetup();
|
|
2654
|
-
return e.totp_digits && (this.totpDigits = e.totp_digits), this.subscribeStore.notify(
|
|
2858
|
+
return e.totp_digits && (this.totpDigits = e.totp_digits), this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: e.secret }), e;
|
|
2655
2859
|
} catch (e) {
|
|
2656
2860
|
this.emitErrorAndThrow(e, "Begin 2FA setup");
|
|
2657
2861
|
}
|
|
@@ -2661,11 +2865,11 @@ class De {
|
|
|
2661
2865
|
* Returns recovery codes that MUST be displayed to user
|
|
2662
2866
|
*/
|
|
2663
2867
|
async confirmSetup(e) {
|
|
2664
|
-
if (!
|
|
2868
|
+
if (!C(e, this.totpDigits))
|
|
2665
2869
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2666
2870
|
try {
|
|
2667
2871
|
const t = await this.twoFactorApi.confirmSetup({ code: e });
|
|
2668
|
-
return this.subscribeStore.notify(
|
|
2872
|
+
return this.subscribeStore.notify(a.TwoFactorEnabled, {
|
|
2669
2873
|
recoveryCodes: t.recovery_codes,
|
|
2670
2874
|
clearRecoveryCodes: () => {
|
|
2671
2875
|
t.recovery_codes.length = 0;
|
|
@@ -2680,7 +2884,7 @@ class De {
|
|
|
2680
2884
|
* Completes authentication if successful
|
|
2681
2885
|
*/
|
|
2682
2886
|
async verify(e) {
|
|
2683
|
-
if (!
|
|
2887
|
+
if (!C(e, this.totpDigits))
|
|
2684
2888
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2685
2889
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired())
|
|
2686
2890
|
throw new Error("2FA verification expired or not required. User must sign in first.");
|
|
@@ -2691,7 +2895,7 @@ class De {
|
|
|
2691
2895
|
code: e,
|
|
2692
2896
|
tfa_token: this.partialAuthState.tfaToken
|
|
2693
2897
|
});
|
|
2694
|
-
return this.clearPartialAuthState(), this.subscribeStore.notify(
|
|
2898
|
+
return this.clearPartialAuthState(), this.subscribeStore.notify(a.TwoFactorVerified, { tokens: t }), t;
|
|
2695
2899
|
} catch (t) {
|
|
2696
2900
|
this.emitErrorAndThrow(t, "Verify 2FA code");
|
|
2697
2901
|
}
|
|
@@ -2702,7 +2906,7 @@ class De {
|
|
|
2702
2906
|
*/
|
|
2703
2907
|
async useRecoveryCode(e) {
|
|
2704
2908
|
try {
|
|
2705
|
-
const t =
|
|
2909
|
+
const t = Ce(e);
|
|
2706
2910
|
if (!t)
|
|
2707
2911
|
throw new Error("Invalid recovery code format. Expected format: XXXX-XXXX or XXXXXXXX (alphanumeric).");
|
|
2708
2912
|
if (this.recoverPartialAuthState(), !this.isVerificationRequired())
|
|
@@ -2713,13 +2917,13 @@ class De {
|
|
|
2713
2917
|
recovery_code: t,
|
|
2714
2918
|
tfa_token: this.partialAuthState.tfaToken
|
|
2715
2919
|
});
|
|
2716
|
-
return this.clearPartialAuthState(), r.remaining_recovery_codes === 0 ? this.subscribeStore.notify(
|
|
2920
|
+
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
2921
|
tokens: r,
|
|
2718
2922
|
remainingCodes: r.remaining_recovery_codes
|
|
2719
|
-
}), this.subscribeStore.notify(
|
|
2923
|
+
}), this.subscribeStore.notify(a.TwoFactorRecoveryUsed, {
|
|
2720
2924
|
tokens: r,
|
|
2721
2925
|
remainingCodes: r.remaining_recovery_codes
|
|
2722
|
-
}), this.subscribeStore.notify(
|
|
2926
|
+
}), this.subscribeStore.notify(a.TwoFactorVerified, { tokens: r }), r;
|
|
2723
2927
|
} catch (t) {
|
|
2724
2928
|
this.emitErrorAndThrow(t, "Use recovery code");
|
|
2725
2929
|
}
|
|
@@ -2728,11 +2932,11 @@ class De {
|
|
|
2728
2932
|
* Disable 2FA (requires TOTP verification)
|
|
2729
2933
|
*/
|
|
2730
2934
|
async disable(e) {
|
|
2731
|
-
if (!
|
|
2935
|
+
if (!C(e, this.totpDigits))
|
|
2732
2936
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2733
2937
|
try {
|
|
2734
2938
|
const t = await this.twoFactorApi.disable({ code: e });
|
|
2735
|
-
return this.subscribeStore.notify(
|
|
2939
|
+
return this.subscribeStore.notify(a.TwoFactorDisabled, {}), t;
|
|
2736
2940
|
} catch (t) {
|
|
2737
2941
|
this.emitErrorAndThrow(t, "Disable 2FA");
|
|
2738
2942
|
}
|
|
@@ -2741,7 +2945,7 @@ class De {
|
|
|
2741
2945
|
* Regenerate recovery codes
|
|
2742
2946
|
*/
|
|
2743
2947
|
async regenerateRecoveryCodes(e) {
|
|
2744
|
-
if (!
|
|
2948
|
+
if (!C(e, this.totpDigits))
|
|
2745
2949
|
throw new Error(`Invalid TOTP code format. Code must be exactly ${this.totpDigits} digits.`);
|
|
2746
2950
|
try {
|
|
2747
2951
|
const t = await this.twoFactorApi.regenerateRecoveryCodes({ code: e }), r = [...t.recovery_codes];
|
|
@@ -2832,12 +3036,12 @@ class De {
|
|
|
2832
3036
|
scope: "2fa_setup",
|
|
2833
3037
|
timestamp: Date.now(),
|
|
2834
3038
|
expiresAt: Date.now() + (t.expiresIn || 3600) * 1e3
|
|
2835
|
-
}, this.subscribeStore.notify(
|
|
3039
|
+
}, this.subscribeStore.notify(a.TwoFactorSetupMagicLinkValidated, {
|
|
2836
3040
|
userId: t.userId,
|
|
2837
3041
|
appId: t.appId,
|
|
2838
3042
|
expiresIn: t.expiresIn || 3600,
|
|
2839
3043
|
sessionToken: t.sessionToken
|
|
2840
|
-
})) : t.error && this.subscribeStore.notify(
|
|
3044
|
+
})) : t.error && this.subscribeStore.notify(a.TwoFactorSetupMagicLinkFailed, {
|
|
2841
3045
|
error: t.error
|
|
2842
3046
|
}), t;
|
|
2843
3047
|
}
|
|
@@ -2908,7 +3112,7 @@ class De {
|
|
|
2908
3112
|
async beginMethodSetup(e) {
|
|
2909
3113
|
try {
|
|
2910
3114
|
const t = await this.twoFactorApi.beginMethodSetup(e);
|
|
2911
|
-
return this.subscribeStore.notify(
|
|
3115
|
+
return this.subscribeStore.notify(a.TwoFactorSetupStarted, { secret: "", method: e }), t;
|
|
2912
3116
|
} catch (t) {
|
|
2913
3117
|
this.emitErrorAndThrow(t, "Begin 2FA method setup");
|
|
2914
3118
|
}
|
|
@@ -2919,7 +3123,7 @@ class De {
|
|
|
2919
3123
|
async confirmMethodSetup(e, t) {
|
|
2920
3124
|
try {
|
|
2921
3125
|
const r = await this.twoFactorApi.confirmMethodSetup(e, t);
|
|
2922
|
-
return this.subscribeStore.notify(
|
|
3126
|
+
return this.subscribeStore.notify(a.TwoFactorEnabled, {
|
|
2923
3127
|
recoveryCodes: [],
|
|
2924
3128
|
clearRecoveryCodes: () => {
|
|
2925
3129
|
}
|
|
@@ -2944,7 +3148,7 @@ class De {
|
|
|
2944
3148
|
async requestChallenge(e) {
|
|
2945
3149
|
try {
|
|
2946
3150
|
const t = await this.twoFactorApi.requestChallenge(e);
|
|
2947
|
-
return this.subscribeStore.notify(
|
|
3151
|
+
return this.subscribeStore.notify(a.TwoFactorChallengeReceived, {
|
|
2948
3152
|
challengeId: t.challenge_id,
|
|
2949
3153
|
method: t.method,
|
|
2950
3154
|
alternativeMethods: t.alternative_methods
|
|
@@ -2959,12 +3163,12 @@ class De {
|
|
|
2959
3163
|
async verifyV2(e) {
|
|
2960
3164
|
try {
|
|
2961
3165
|
const t = await this.twoFactorApi.verifyV2(e);
|
|
2962
|
-
return t.success && (this.subscribeStore.notify(
|
|
3166
|
+
return t.success && (this.subscribeStore.notify(a.TwoFactorVerified, {
|
|
2963
3167
|
tokens: {
|
|
2964
3168
|
access_token: t.access_token,
|
|
2965
3169
|
refresh_token: t.refresh_token
|
|
2966
3170
|
}
|
|
2967
|
-
}), t.device_trusted && this.subscribeStore.notify(
|
|
3171
|
+
}), t.device_trusted && this.subscribeStore.notify(a.TwoFactorDeviceTrusted, {})), t;
|
|
2968
3172
|
} catch (t) {
|
|
2969
3173
|
this.emitErrorAndThrow(t, "Verify 2FA challenge");
|
|
2970
3174
|
}
|
|
@@ -2975,7 +3179,7 @@ class De {
|
|
|
2975
3179
|
async switchToAlternative(e) {
|
|
2976
3180
|
try {
|
|
2977
3181
|
const t = await this.twoFactorApi.switchToAlternative(e);
|
|
2978
|
-
return this.subscribeStore.notify(
|
|
3182
|
+
return this.subscribeStore.notify(a.TwoFactorMethodSwitched, {
|
|
2979
3183
|
challengeId: t.challenge_id,
|
|
2980
3184
|
method: t.method,
|
|
2981
3185
|
alternativeMethods: t.alternative_methods
|
|
@@ -3005,9 +3209,9 @@ class De {
|
|
|
3005
3209
|
}
|
|
3006
3210
|
}
|
|
3007
3211
|
}
|
|
3008
|
-
class
|
|
3009
|
-
constructor(e, t) {
|
|
3010
|
-
this.userAPI = e, this.deviceService = t;
|
|
3212
|
+
class Oe {
|
|
3213
|
+
constructor(e, t, r = A) {
|
|
3214
|
+
this.userAPI = e, this.deviceService = t, this.platform = r;
|
|
3011
3215
|
}
|
|
3012
3216
|
/**
|
|
3013
3217
|
* Get user's registered passkeys
|
|
@@ -3043,31 +3247,34 @@ class Pe {
|
|
|
3043
3247
|
passkeyUsername: t,
|
|
3044
3248
|
passkeyDisplayName: r
|
|
3045
3249
|
} = {}) {
|
|
3046
|
-
|
|
3047
|
-
|
|
3250
|
+
if (!this.platform.passkeys) throw new Error("Passkeys are not supported on this platform");
|
|
3251
|
+
const s = this.deviceService.getDeviceId(), o = this.platform.getDeviceType(), { challenge_id: n, publicKey: h } = await this.userAPI.addUserPasskeyStart({
|
|
3252
|
+
relyingPartyId: (e || this.platform.getCurrentUrl()?.hostname) ?? "",
|
|
3048
3253
|
deviceId: s,
|
|
3049
3254
|
os: o,
|
|
3050
3255
|
passkeyDisplayName: r,
|
|
3051
3256
|
passkeyUsername: t
|
|
3052
3257
|
});
|
|
3053
|
-
|
|
3054
|
-
const
|
|
3055
|
-
|
|
3258
|
+
h.user.id = this.platform.btoa(h.user.id);
|
|
3259
|
+
const d = await this.platform.passkeys.startRegistration(h);
|
|
3260
|
+
if (!d) throw new Error("Passkey registration was not completed");
|
|
3261
|
+
return await this.userAPI.addUserPasskeyComplete(d, s, n);
|
|
3056
3262
|
}
|
|
3057
3263
|
}
|
|
3058
3264
|
const O = class O {
|
|
3059
3265
|
constructor(e) {
|
|
3060
|
-
this.doRefreshTokens = !1, this.
|
|
3266
|
+
this.doRefreshTokens = !1, this.session = async ({
|
|
3061
3267
|
createSession: o,
|
|
3062
|
-
expiredSession:
|
|
3063
|
-
doRefresh:
|
|
3268
|
+
expiredSession: n,
|
|
3269
|
+
doRefresh: h = !1
|
|
3064
3270
|
}) => {
|
|
3065
|
-
this.createSessionCallback = o, this.expiredSessionCallback =
|
|
3271
|
+
this.createSessionCallback = o, this.expiredSessionCallback = n, this.doRefreshTokens = h, await this.submitSessionCheck();
|
|
3066
3272
|
};
|
|
3067
3273
|
const { url: t, appId: r, scopes: s } = e;
|
|
3068
|
-
this.url = t ||
|
|
3069
|
-
prefix: e.keyStoragePrefix ?? ""
|
|
3070
|
-
|
|
3274
|
+
this.url = t || K, this.appId = r, this.platform = e.platform ?? A, this.storageManager = new $({
|
|
3275
|
+
prefix: e.keyStoragePrefix ?? "",
|
|
3276
|
+
storage: this.platform.storage
|
|
3277
|
+
}), 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
3278
|
this.authApi,
|
|
3072
3279
|
this.deviceService,
|
|
3073
3280
|
this.storageManager,
|
|
@@ -3075,15 +3282,18 @@ const O = class O {
|
|
|
3075
3282
|
this.tokenCacheService,
|
|
3076
3283
|
this.scopes,
|
|
3077
3284
|
this.createTenantForNewUser,
|
|
3078
|
-
this.origin,
|
|
3079
3285
|
this.url,
|
|
3080
3286
|
{
|
|
3081
3287
|
createSession: this.createSessionCallback,
|
|
3082
3288
|
expiredSession: this.expiredSessionCallback
|
|
3083
3289
|
},
|
|
3084
3290
|
this.appId ?? "",
|
|
3085
|
-
e.tokenExchange
|
|
3086
|
-
|
|
3291
|
+
e.tokenExchange,
|
|
3292
|
+
this.platform
|
|
3293
|
+
), 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();
|
|
3294
|
+
}
|
|
3295
|
+
get origin() {
|
|
3296
|
+
return this.platform.getCurrentUrl()?.origin ?? "";
|
|
3087
3297
|
}
|
|
3088
3298
|
/**
|
|
3089
3299
|
* Update the appId and propagate it to all API clients.
|
|
@@ -3106,10 +3316,10 @@ const O = class O {
|
|
|
3106
3316
|
e = await this.authService.getTokens(this.doRefreshTokens), t = this.tokenCacheService.getParsedTokens();
|
|
3107
3317
|
} catch (r) {
|
|
3108
3318
|
const s = {
|
|
3109
|
-
message: r instanceof Error || r instanceof
|
|
3319
|
+
message: r instanceof Error || r instanceof l ? r.message : "Session check failed",
|
|
3110
3320
|
originalError: r
|
|
3111
3321
|
};
|
|
3112
|
-
this.subscribeStore.notify(
|
|
3322
|
+
this.subscribeStore.notify(a.Error, s), e = void 0;
|
|
3113
3323
|
}
|
|
3114
3324
|
e && this.createSessionCallback && await this.createSessionCallback({ tokens: e, parsedTokens: t }), !e && this.expiredSessionCallback && await this.expiredSessionCallback();
|
|
3115
3325
|
}
|
|
@@ -3182,61 +3392,64 @@ const O = class O {
|
|
|
3182
3392
|
return this.checkAndSetTokens();
|
|
3183
3393
|
}
|
|
3184
3394
|
checkAndSetTokens() {
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3395
|
+
const e = this.platform.getCurrentUrl();
|
|
3396
|
+
let t = new URLSearchParams(e?.search ?? ""), r = !1;
|
|
3397
|
+
if (!t.get("access_token") && e?.hash) {
|
|
3398
|
+
const u = new URLSearchParams(e.hash.substring(1));
|
|
3399
|
+
u.get("access_token") && (t = u, r = !0);
|
|
3189
3400
|
}
|
|
3190
|
-
const
|
|
3401
|
+
const s = t.get("access_token"), o = t.get("refresh_token"), n = t.get("id_token"), h = t.get("scopes")?.split(",") ?? this.scopes;
|
|
3191
3402
|
let d;
|
|
3192
|
-
if (
|
|
3193
|
-
if (!D(
|
|
3194
|
-
const
|
|
3403
|
+
if (s) {
|
|
3404
|
+
if (!D(s)) {
|
|
3405
|
+
const u = {
|
|
3195
3406
|
message: "Invalid access token format received",
|
|
3196
3407
|
code: "INVALID_TOKEN_FORMAT"
|
|
3197
3408
|
};
|
|
3198
|
-
this.subscribeStore.notify(
|
|
3409
|
+
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3199
3410
|
return;
|
|
3200
3411
|
}
|
|
3201
|
-
if (
|
|
3202
|
-
const
|
|
3412
|
+
if (o && !D(o)) {
|
|
3413
|
+
const u = {
|
|
3203
3414
|
message: "Invalid refresh token format received",
|
|
3204
3415
|
code: "INVALID_TOKEN_FORMAT"
|
|
3205
3416
|
};
|
|
3206
|
-
this.subscribeStore.notify(
|
|
3417
|
+
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3207
3418
|
return;
|
|
3208
3419
|
}
|
|
3209
|
-
if (
|
|
3210
|
-
const
|
|
3420
|
+
if (n && !D(n)) {
|
|
3421
|
+
const u = {
|
|
3211
3422
|
message: "Invalid ID token format received",
|
|
3212
3423
|
code: "INVALID_TOKEN_FORMAT"
|
|
3213
3424
|
};
|
|
3214
|
-
this.subscribeStore.notify(
|
|
3425
|
+
this.subscribeStore.notify(a.Error, u), this.cleanupUrlParams(r, e);
|
|
3215
3426
|
return;
|
|
3216
3427
|
}
|
|
3217
3428
|
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(
|
|
3429
|
+
access_token: s,
|
|
3430
|
+
refresh_token: o ?? void 0,
|
|
3431
|
+
id_token: n ?? void 0,
|
|
3432
|
+
scopes: h
|
|
3433
|
+
}, 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
3434
|
} else
|
|
3224
3435
|
this.error = this.checkErrorsFromURL();
|
|
3225
3436
|
}
|
|
3226
3437
|
checkErrorsFromURL() {
|
|
3227
|
-
const t = new URLSearchParams(
|
|
3438
|
+
const t = new URLSearchParams(this.platform.getCurrentUrl()?.search ?? "").get("error");
|
|
3228
3439
|
if (t) {
|
|
3229
|
-
const r =
|
|
3440
|
+
const r = be(t);
|
|
3230
3441
|
return new Error(r);
|
|
3231
3442
|
}
|
|
3232
3443
|
}
|
|
3233
|
-
cleanupUrlParams(e = !1) {
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3444
|
+
cleanupUrlParams(e = !1, t = null) {
|
|
3445
|
+
const r = t ?? this.platform.getCurrentUrl();
|
|
3446
|
+
if (r)
|
|
3447
|
+
if (e)
|
|
3448
|
+
this.platform.replaceUrl(r.pathname + r.search);
|
|
3449
|
+
else {
|
|
3450
|
+
const s = new URLSearchParams(r.search);
|
|
3451
|
+
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);
|
|
3452
|
+
}
|
|
3240
3453
|
}
|
|
3241
3454
|
setTokensToCacheFromLocalStorage() {
|
|
3242
3455
|
let e = this.storageManager.getTokens();
|
|
@@ -3452,9 +3665,9 @@ const O = class O {
|
|
|
3452
3665
|
const r = {
|
|
3453
3666
|
message: e instanceof Error ? e.message : `${t} failed`,
|
|
3454
3667
|
originalError: e,
|
|
3455
|
-
code: e instanceof
|
|
3668
|
+
code: e instanceof l ? e.id : void 0
|
|
3456
3669
|
};
|
|
3457
|
-
throw this.subscribeStore.notify(
|
|
3670
|
+
throw this.subscribeStore.notify(a.Error, r), e;
|
|
3458
3671
|
}
|
|
3459
3672
|
/**
|
|
3460
3673
|
* Sign out the current user and clear all tokens.
|
|
@@ -3475,7 +3688,7 @@ const O = class O {
|
|
|
3475
3688
|
*/
|
|
3476
3689
|
async logOut() {
|
|
3477
3690
|
try {
|
|
3478
|
-
await this.authService.logOut(), this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.twoFactorService.clearPartialAuthState(), await this.submitSessionCheck(), this.subscribeStore.notify(
|
|
3691
|
+
await this.authService.logOut(), this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.twoFactorService.clearPartialAuthState(), await this.submitSessionCheck(), this.subscribeStore.notify(a.SignOut, {});
|
|
3479
3692
|
} catch (e) {
|
|
3480
3693
|
this.handleError(e, "Log out");
|
|
3481
3694
|
}
|
|
@@ -3545,13 +3758,13 @@ const O = class O {
|
|
|
3545
3758
|
* ```
|
|
3546
3759
|
*/
|
|
3547
3760
|
reset(e) {
|
|
3548
|
-
if (this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.subscribeStore.notify(
|
|
3761
|
+
if (this.storageManager.deleteTokens(), this.tokenCacheService.setTokensCache(void 0), this.subscribeStore.notify(a.SignOut, {}), e) {
|
|
3549
3762
|
this.error = new Error(e);
|
|
3550
3763
|
const t = {
|
|
3551
3764
|
message: e,
|
|
3552
3765
|
code: "RESET_ERROR"
|
|
3553
3766
|
};
|
|
3554
|
-
throw this.subscribeStore.notify(
|
|
3767
|
+
throw this.subscribeStore.notify(a.Error, t), this.error;
|
|
3555
3768
|
}
|
|
3556
3769
|
}
|
|
3557
3770
|
/**
|
|
@@ -3578,7 +3791,7 @@ const O = class O {
|
|
|
3578
3791
|
try {
|
|
3579
3792
|
return await this.authService.refreshToken();
|
|
3580
3793
|
} catch (e) {
|
|
3581
|
-
throw e instanceof
|
|
3794
|
+
throw e instanceof l || this.subscribeStore.notify(a.Error, {
|
|
3582
3795
|
message: "Failed to refresh token",
|
|
3583
3796
|
originalError: e
|
|
3584
3797
|
}), e;
|
|
@@ -3783,7 +3996,7 @@ const O = class O {
|
|
|
3783
3996
|
* ```
|
|
3784
3997
|
*/
|
|
3785
3998
|
setTokens(e) {
|
|
3786
|
-
this.storageManager.saveTokens(e), this.tokenCacheService.setTokensCache(e), this.subscribeStore.notify(
|
|
3999
|
+
this.storageManager.saveTokens(e), this.tokenCacheService.setTokensCache(e), this.subscribeStore.notify(a.SignIn, {
|
|
3787
4000
|
tokens: e,
|
|
3788
4001
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
3789
4002
|
});
|
|
@@ -4219,7 +4432,7 @@ const O = class O {
|
|
|
4219
4432
|
async verifyTwoFactor(e) {
|
|
4220
4433
|
try {
|
|
4221
4434
|
const t = await this.twoFactorService.verify(e);
|
|
4222
|
-
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(
|
|
4435
|
+
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(a.SignIn, {
|
|
4223
4436
|
tokens: t,
|
|
4224
4437
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4225
4438
|
}), await this.submitSessionCheck(), t;
|
|
@@ -4246,7 +4459,7 @@ const O = class O {
|
|
|
4246
4459
|
async useTwoFactorRecoveryCode(e) {
|
|
4247
4460
|
try {
|
|
4248
4461
|
const t = await this.twoFactorService.useRecoveryCode(e);
|
|
4249
|
-
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(
|
|
4462
|
+
return this.storageManager.saveTokens(t), this.tokenCacheService.setTokensCache(t), this.subscribeStore.notify(a.SignIn, {
|
|
4250
4463
|
tokens: t,
|
|
4251
4464
|
parsedTokens: this.tokenCacheService.getParsedTokens()
|
|
4252
4465
|
}), await this.submitSessionCheck(), t;
|
|
@@ -4408,20 +4621,20 @@ const O = class O {
|
|
|
4408
4621
|
this.twoFactorService.clearMagicLinkSession();
|
|
4409
4622
|
}
|
|
4410
4623
|
};
|
|
4411
|
-
O.version =
|
|
4624
|
+
O.version = ee;
|
|
4412
4625
|
let L = O;
|
|
4413
|
-
class
|
|
4626
|
+
class p extends Error {
|
|
4414
4627
|
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,
|
|
4628
|
+
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
4629
|
}
|
|
4417
4630
|
/**
|
|
4418
4631
|
* Create an M2MError from an OAuth 2.0 error response
|
|
4419
4632
|
*/
|
|
4420
4633
|
static fromOAuthError(e, t, r) {
|
|
4421
|
-
const s = r ?
|
|
4422
|
-
return new
|
|
4634
|
+
const s = r ? p.parseRateLimitHeaders(r) : void 0;
|
|
4635
|
+
return new p({
|
|
4423
4636
|
code: e.error,
|
|
4424
|
-
message: e.error_description ??
|
|
4637
|
+
message: e.error_description ?? p.getDefaultMessage(e.error),
|
|
4425
4638
|
status: t,
|
|
4426
4639
|
errorUri: e.error_uri,
|
|
4427
4640
|
rateLimitInfo: s,
|
|
@@ -4432,7 +4645,7 @@ class l extends Error {
|
|
|
4432
4645
|
* Create an M2MError from a network or other error
|
|
4433
4646
|
*/
|
|
4434
4647
|
static fromError(e, t = "server_error") {
|
|
4435
|
-
return new
|
|
4648
|
+
return new p({
|
|
4436
4649
|
code: t,
|
|
4437
4650
|
message: e.message || "An unexpected error occurred",
|
|
4438
4651
|
status: 500,
|
|
@@ -4505,7 +4718,7 @@ class l extends Error {
|
|
|
4505
4718
|
return this.status && (e += ` (HTTP ${this.status})`), e;
|
|
4506
4719
|
}
|
|
4507
4720
|
}
|
|
4508
|
-
class N extends
|
|
4721
|
+
class N extends p {
|
|
4509
4722
|
constructor(e, t) {
|
|
4510
4723
|
super({
|
|
4511
4724
|
code: "temporarily_unavailable",
|
|
@@ -4515,7 +4728,7 @@ class N extends l {
|
|
|
4515
4728
|
}), this.name = "M2MNetworkError";
|
|
4516
4729
|
}
|
|
4517
4730
|
}
|
|
4518
|
-
class
|
|
4731
|
+
class R extends p {
|
|
4519
4732
|
constructor(e, t) {
|
|
4520
4733
|
super({
|
|
4521
4734
|
code: "invalid_request",
|
|
@@ -4525,7 +4738,7 @@ class M extends l {
|
|
|
4525
4738
|
}), this.name = "M2MTokenParseError";
|
|
4526
4739
|
}
|
|
4527
4740
|
}
|
|
4528
|
-
class U extends
|
|
4741
|
+
class U extends p {
|
|
4529
4742
|
constructor(e) {
|
|
4530
4743
|
super({
|
|
4531
4744
|
code: "invalid_request",
|
|
@@ -4534,7 +4747,7 @@ class U extends l {
|
|
|
4534
4747
|
}), this.name = "M2MConfigError";
|
|
4535
4748
|
}
|
|
4536
4749
|
}
|
|
4537
|
-
const
|
|
4750
|
+
const He = {
|
|
4538
4751
|
InvalidRequest: "invalid_request",
|
|
4539
4752
|
InvalidClient: "invalid_client",
|
|
4540
4753
|
InvalidGrant: "invalid_grant",
|
|
@@ -4558,7 +4771,7 @@ const Ge = {
|
|
|
4558
4771
|
/** Content-Type for token requests */
|
|
4559
4772
|
CONTENT_TYPE: "application/x-www-form-urlencoded"
|
|
4560
4773
|
};
|
|
4561
|
-
class
|
|
4774
|
+
class Le {
|
|
4562
4775
|
constructor() {
|
|
4563
4776
|
this.cache = /* @__PURE__ */ new Map();
|
|
4564
4777
|
}
|
|
@@ -4576,7 +4789,7 @@ class xe {
|
|
|
4576
4789
|
return this.cache.delete(e), Promise.resolve();
|
|
4577
4790
|
}
|
|
4578
4791
|
}
|
|
4579
|
-
const
|
|
4792
|
+
const Ne = {
|
|
4580
4793
|
shouldRetry(i, e) {
|
|
4581
4794
|
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
4795
|
},
|
|
@@ -4584,7 +4797,7 @@ const Ue = {
|
|
|
4584
4797
|
return Math.pow(2, i - 1) * 1e3;
|
|
4585
4798
|
}
|
|
4586
4799
|
};
|
|
4587
|
-
class
|
|
4800
|
+
class ze {
|
|
4588
4801
|
/**
|
|
4589
4802
|
* Create a new M2M client
|
|
4590
4803
|
*
|
|
@@ -4624,7 +4837,7 @@ class qe {
|
|
|
4624
4837
|
onTokenRequest: e.onTokenRequest,
|
|
4625
4838
|
onTokenResponse: e.onTokenResponse,
|
|
4626
4839
|
onError: e.onError
|
|
4627
|
-
}, this.cache = e.cache ?? new
|
|
4840
|
+
}, this.cache = e.cache ?? new Le(), this.retryStrategy = e.retryStrategy ?? Ne, this.tokenEndpoint = `${t}${T.TOKEN_ENDPOINT}`;
|
|
4628
4841
|
}
|
|
4629
4842
|
/**
|
|
4630
4843
|
* Get the cache key for this client
|
|
@@ -4722,29 +4935,29 @@ class qe {
|
|
|
4722
4935
|
signal: r.signal
|
|
4723
4936
|
});
|
|
4724
4937
|
clearTimeout(s);
|
|
4725
|
-
const
|
|
4726
|
-
o.headers.forEach((
|
|
4727
|
-
|
|
4938
|
+
const n = {};
|
|
4939
|
+
o.headers.forEach((d, u) => {
|
|
4940
|
+
n[u.toLowerCase()] = d;
|
|
4728
4941
|
});
|
|
4729
|
-
const
|
|
4942
|
+
const h = await o.json();
|
|
4730
4943
|
if (!o.ok) {
|
|
4731
|
-
const
|
|
4944
|
+
const d = p.fromOAuthError(
|
|
4732
4945
|
{
|
|
4733
|
-
error:
|
|
4734
|
-
error_description:
|
|
4735
|
-
error_uri:
|
|
4946
|
+
error: h.error || "server_error",
|
|
4947
|
+
error_description: h.error_description || h.message,
|
|
4948
|
+
error_uri: h.error_uri
|
|
4736
4949
|
},
|
|
4737
4950
|
o.status,
|
|
4738
|
-
|
|
4951
|
+
n
|
|
4739
4952
|
);
|
|
4740
4953
|
throw this.config.onError && this.config.onError({
|
|
4741
|
-
error:
|
|
4742
|
-
error_description:
|
|
4743
|
-
}),
|
|
4954
|
+
error: d.code,
|
|
4955
|
+
error_description: d.message
|
|
4956
|
+
}), d;
|
|
4744
4957
|
}
|
|
4745
|
-
return
|
|
4958
|
+
return h;
|
|
4746
4959
|
} 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
|
|
4960
|
+
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
4961
|
}
|
|
4749
4962
|
}
|
|
4750
4963
|
/**
|
|
@@ -4756,7 +4969,7 @@ class qe {
|
|
|
4756
4969
|
try {
|
|
4757
4970
|
return await e();
|
|
4758
4971
|
} catch (s) {
|
|
4759
|
-
if (!(s instanceof
|
|
4972
|
+
if (!(s instanceof p))
|
|
4760
4973
|
throw s;
|
|
4761
4974
|
if (t = s, r < this.config.retries && this.retryStrategy.shouldRetry({ code: s.code, status: s.status }, r)) {
|
|
4762
4975
|
const o = this.retryStrategy.getDelay(r);
|
|
@@ -4765,7 +4978,7 @@ class qe {
|
|
|
4765
4978
|
}
|
|
4766
4979
|
throw s;
|
|
4767
4980
|
}
|
|
4768
|
-
throw t ?? new
|
|
4981
|
+
throw t ?? new p({ code: "server_error", message: "Request failed after retries" });
|
|
4769
4982
|
}
|
|
4770
4983
|
/**
|
|
4771
4984
|
* Sleep for a given duration
|
|
@@ -4839,14 +5052,14 @@ class qe {
|
|
|
4839
5052
|
try {
|
|
4840
5053
|
const t = e.split(".");
|
|
4841
5054
|
if (t.length !== 3)
|
|
4842
|
-
throw new
|
|
5055
|
+
throw new R("Invalid JWT format: expected 3 parts");
|
|
4843
5056
|
const r = t[1];
|
|
4844
5057
|
if (!r)
|
|
4845
|
-
throw new
|
|
5058
|
+
throw new R("Invalid JWT format: missing payload");
|
|
4846
5059
|
const s = atob(r.replace(/-/g, "+").replace(/_/g, "/")), o = JSON.parse(s);
|
|
4847
5060
|
return o.scopes && typeof o.scopes == "string" ? o.scopes = o.scopes.split(" ") : o.scopes || (o.scopes = []), o;
|
|
4848
5061
|
} catch (t) {
|
|
4849
|
-
throw t instanceof
|
|
5062
|
+
throw t instanceof R ? t : new R(`Failed to parse token: ${t instanceof Error ? t.message : "Unknown error"}`);
|
|
4850
5063
|
}
|
|
4851
5064
|
}
|
|
4852
5065
|
/**
|
|
@@ -4893,7 +5106,7 @@ class qe {
|
|
|
4893
5106
|
});
|
|
4894
5107
|
if (!s.ok && s.status !== 200) {
|
|
4895
5108
|
const o = await s.json().catch(() => ({}));
|
|
4896
|
-
throw
|
|
5109
|
+
throw p.fromOAuthError(
|
|
4897
5110
|
{
|
|
4898
5111
|
error: o.error || "server_error",
|
|
4899
5112
|
error_description: o.error_description || "Token revocation failed"
|
|
@@ -4903,7 +5116,7 @@ class qe {
|
|
|
4903
5116
|
}
|
|
4904
5117
|
this.clearCache();
|
|
4905
5118
|
} catch (s) {
|
|
4906
|
-
throw s instanceof
|
|
5119
|
+
throw s instanceof p ? s : p.fromError(s instanceof Error ? s : new Error(String(s)));
|
|
4907
5120
|
}
|
|
4908
5121
|
}
|
|
4909
5122
|
/**
|
|
@@ -4932,64 +5145,68 @@ class qe {
|
|
|
4932
5145
|
}
|
|
4933
5146
|
}
|
|
4934
5147
|
export {
|
|
4935
|
-
|
|
5148
|
+
b as APP_ID_HEADER_KEY,
|
|
4936
5149
|
I as AUTHORIZATION_HEADER_KEY,
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
5150
|
+
ve as AppAPI,
|
|
5151
|
+
ye as AuthAPI,
|
|
5152
|
+
Re as AuthService,
|
|
5153
|
+
je as CLIAuthAPI,
|
|
5154
|
+
Be as DEFAULT_GROUP_NAME,
|
|
5155
|
+
te as DEFAULT_SCOPES,
|
|
5156
|
+
Z as DEVICE_ID_HEADER_KEY,
|
|
5157
|
+
Q as DEVICE_TYPE_HEADER_KEY,
|
|
5158
|
+
ce as ERROR_MESSAGE_MAX_LENGTH,
|
|
5159
|
+
Se as InvitationAPI,
|
|
5160
|
+
Fe as InvitationService,
|
|
5161
|
+
ze as M2MClient,
|
|
4949
5162
|
U as M2MConfigError,
|
|
4950
|
-
|
|
4951
|
-
|
|
5163
|
+
p as M2MError,
|
|
5164
|
+
He as M2MErrorCodes,
|
|
4952
5165
|
N as M2MNetworkError,
|
|
4953
|
-
|
|
5166
|
+
R as M2MTokenParseError,
|
|
4954
5167
|
T as M2M_DEFAULTS,
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
5168
|
+
qe as MINIMAL_DEFAULT_SCOPES,
|
|
5169
|
+
ge as OS,
|
|
5170
|
+
K as PASSFLOW_CLOUD_URL,
|
|
5171
|
+
se as POPUP_HEIGHT,
|
|
5172
|
+
ie as POPUP_POLL_INTERVAL_MS,
|
|
5173
|
+
oe as POPUP_TIMEOUT_MS,
|
|
5174
|
+
re as POPUP_WIDTH,
|
|
4962
5175
|
L as Passflow,
|
|
4963
|
-
|
|
5176
|
+
E as PassflowAdminEndpointPaths,
|
|
4964
5177
|
c as PassflowEndpointPaths,
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
5178
|
+
l as PassflowError,
|
|
5179
|
+
a as PassflowEvent,
|
|
5180
|
+
Y as PopupClosedError,
|
|
5181
|
+
pe as Providers,
|
|
5182
|
+
_ as RequestMethod,
|
|
5183
|
+
ee as SDK_VERSION,
|
|
5184
|
+
V as SessionState,
|
|
5185
|
+
we as SettingAPI,
|
|
4972
5186
|
G as TOKEN_EXPIRY_BUFFER_SECONDS,
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
5187
|
+
Te as TenantAPI,
|
|
5188
|
+
xe as TenantService,
|
|
5189
|
+
Pe as TenantUserMembership,
|
|
5190
|
+
Ue as TokenCacheService,
|
|
5191
|
+
y as TokenDeliveryMode,
|
|
5192
|
+
k as TokenType,
|
|
5193
|
+
Ee as TwoFactorApiClient,
|
|
5194
|
+
fe as TwoFactorPolicy,
|
|
5195
|
+
$e as TwoFactorService,
|
|
5196
|
+
ae as USERNAME_MAX_LENGTH,
|
|
5197
|
+
ne as USERNAME_MIN_LENGTH,
|
|
5198
|
+
_e as UserAPI,
|
|
5199
|
+
Oe as UserService,
|
|
5200
|
+
le as WebAdapter,
|
|
5201
|
+
Ye as getOSFromDeviceType,
|
|
4986
5202
|
S as isTokenExpired,
|
|
4987
5203
|
P as isValidEmail,
|
|
4988
5204
|
D as isValidJWTFormat,
|
|
4989
5205
|
x as isValidPhoneNumber,
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
5206
|
+
Ae as isValidUsername,
|
|
5207
|
+
m as parseToken,
|
|
5208
|
+
v as pathWithParams,
|
|
5209
|
+
be as sanitizeErrorMessage,
|
|
5210
|
+
A as webAdapter
|
|
4994
5211
|
};
|
|
4995
5212
|
//# sourceMappingURL=index.mjs.map
|