@skylabs-digital/react-identity-access 3.2.2 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +487 -457
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/services/HttpService.d.ts.map +1 -1
- package/dist/services/SessionManager.d.ts +12 -0
- package/dist/services/SessionManager.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -11,30 +11,37 @@ class he {
|
|
|
11
11
|
getBaseUrl() {
|
|
12
12
|
return this.baseUrl;
|
|
13
13
|
}
|
|
14
|
-
async executeRequest(e, t, n, i) {
|
|
15
|
-
const
|
|
16
|
-
let
|
|
14
|
+
async executeRequest(e, t, n, i, a = !1) {
|
|
15
|
+
const l = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, h = (i == null ? void 0 : i.timeout) || this.timeout;
|
|
16
|
+
let S = {
|
|
17
17
|
"Content-Type": "application/json",
|
|
18
18
|
...i == null ? void 0 : i.headers
|
|
19
19
|
};
|
|
20
20
|
if (!(i != null && i.skipAuth) && this.sessionManager) {
|
|
21
21
|
const c = await this.sessionManager.getValidAccessToken();
|
|
22
|
-
|
|
22
|
+
S = { ...S, Authorization: `Bearer ${c}` };
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const k = new AbortController(), T = setTimeout(() => k.abort(), h);
|
|
25
25
|
try {
|
|
26
|
-
const c = await fetch(
|
|
26
|
+
const c = await fetch(l, {
|
|
27
27
|
method: e,
|
|
28
|
-
headers:
|
|
28
|
+
headers: S,
|
|
29
29
|
body: n ? JSON.stringify(n) : void 0,
|
|
30
|
-
signal:
|
|
30
|
+
signal: k.signal
|
|
31
31
|
});
|
|
32
|
-
if (clearTimeout(
|
|
32
|
+
if (clearTimeout(T), c.status === 401 && !(i != null && i.skipAuth) && this.sessionManager && !a) {
|
|
33
|
+
try {
|
|
34
|
+
await c.text();
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
return await this.sessionManager.forceRefresh(), this.executeRequest(e, t, n, i, !0);
|
|
38
|
+
}
|
|
39
|
+
if (!c.ok)
|
|
33
40
|
throw new Error(`HTTP ${c.status}: ${c.statusText}`);
|
|
34
|
-
const
|
|
35
|
-
return !
|
|
41
|
+
const d = c.headers.get("content-type");
|
|
42
|
+
return !d || !d.includes("application/json") ? {} : await c.json();
|
|
36
43
|
} catch (c) {
|
|
37
|
-
throw clearTimeout(
|
|
44
|
+
throw clearTimeout(T), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${h}ms`) : c;
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
async get(e, t) {
|
|
@@ -100,8 +107,8 @@ class Je {
|
|
|
100
107
|
}
|
|
101
108
|
const $e = fe(null), St = 5 * 60 * 1e3;
|
|
102
109
|
function kr({ config: r, children: e }) {
|
|
103
|
-
var
|
|
104
|
-
const { appId: t, baseUrl: n } = r, i = (((
|
|
110
|
+
var E, m, g;
|
|
111
|
+
const { appId: t, baseUrl: n } = r, i = (((E = r.cache) == null ? void 0 : E.enabled) ?? !0) && !!t, a = ((m = r.cache) == null ? void 0 : m.ttl) ?? St, l = ((g = r.cache) == null ? void 0 : g.storageKey) ?? (t ? `app_cache_${t}` : ""), [h, S] = N(() => {
|
|
105
112
|
if (!i) return null;
|
|
106
113
|
try {
|
|
107
114
|
const b = localStorage.getItem(l);
|
|
@@ -111,15 +118,15 @@ function kr({ config: r, children: e }) {
|
|
|
111
118
|
} catch {
|
|
112
119
|
return null;
|
|
113
120
|
}
|
|
114
|
-
}), [
|
|
115
|
-
|
|
121
|
+
}), [k, T] = N(!!t && !h), [c, d] = N(null), A = ye(h);
|
|
122
|
+
A.current = h;
|
|
116
123
|
const P = te(
|
|
117
124
|
async (b = !1) => {
|
|
118
|
-
if (t && !(!b && i &&
|
|
125
|
+
if (t && !(!b && i && A.current))
|
|
119
126
|
try {
|
|
120
|
-
|
|
127
|
+
T(!0), d(null);
|
|
121
128
|
const o = await new Je(new he(n)).getPublicAppInfo(t);
|
|
122
|
-
if (
|
|
129
|
+
if (S(o), i)
|
|
123
130
|
try {
|
|
124
131
|
const p = {
|
|
125
132
|
data: o,
|
|
@@ -132,27 +139,27 @@ function kr({ config: r, children: e }) {
|
|
|
132
139
|
}
|
|
133
140
|
} catch (C) {
|
|
134
141
|
const o = C instanceof Error ? C : new Error("Failed to load app information");
|
|
135
|
-
|
|
142
|
+
d(o), S(null);
|
|
136
143
|
} finally {
|
|
137
|
-
|
|
144
|
+
T(!1);
|
|
138
145
|
}
|
|
139
146
|
},
|
|
140
147
|
[n, t, i, l]
|
|
141
148
|
), I = te(async () => {
|
|
142
|
-
if (!(!t || !i || !
|
|
149
|
+
if (!(!t || !i || !A.current))
|
|
143
150
|
try {
|
|
144
151
|
const b = localStorage.getItem(l);
|
|
145
152
|
if (!b) return;
|
|
146
153
|
const C = JSON.parse(b);
|
|
147
154
|
if (Date.now() - C.timestamp <= a * 0.5) return;
|
|
148
155
|
const p = await new Je(new he(n)).getPublicAppInfo(t);
|
|
149
|
-
|
|
150
|
-
const
|
|
156
|
+
S(p);
|
|
157
|
+
const x = {
|
|
151
158
|
data: p,
|
|
152
159
|
timestamp: Date.now(),
|
|
153
160
|
appId: t
|
|
154
161
|
};
|
|
155
|
-
localStorage.setItem(l, JSON.stringify(
|
|
162
|
+
localStorage.setItem(l, JSON.stringify(x));
|
|
156
163
|
} catch (b) {
|
|
157
164
|
process.env.NODE_ENV === "development" && console.warn("[AppProvider] Background app refresh failed:", b);
|
|
158
165
|
}
|
|
@@ -160,17 +167,17 @@ function kr({ config: r, children: e }) {
|
|
|
160
167
|
() => ({
|
|
161
168
|
appId: t,
|
|
162
169
|
baseUrl: n,
|
|
163
|
-
appInfo:
|
|
164
|
-
isAppLoading:
|
|
165
|
-
appError:
|
|
170
|
+
appInfo: h,
|
|
171
|
+
isAppLoading: k,
|
|
172
|
+
appError: c,
|
|
166
173
|
retryApp: () => {
|
|
167
174
|
P(!0);
|
|
168
175
|
}
|
|
169
176
|
}),
|
|
170
|
-
[t, n,
|
|
177
|
+
[t, n, h, k, c, P]
|
|
171
178
|
);
|
|
172
179
|
return re(() => {
|
|
173
|
-
t && (
|
|
180
|
+
t && (A.current ? I() : P());
|
|
174
181
|
}, []), /* @__PURE__ */ s($e.Provider, { value: R, children: e });
|
|
175
182
|
}
|
|
176
183
|
function Ae() {
|
|
@@ -183,7 +190,7 @@ function Ue() {
|
|
|
183
190
|
return ne($e);
|
|
184
191
|
}
|
|
185
192
|
const Er = Ae;
|
|
186
|
-
class
|
|
193
|
+
class Z extends Error {
|
|
187
194
|
constructor(e, t) {
|
|
188
195
|
const n = {
|
|
189
196
|
token_expired: "Refresh token has expired",
|
|
@@ -472,13 +479,13 @@ const ie = class ie {
|
|
|
472
479
|
this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
|
|
473
480
|
this.consecutiveBackgroundFailures = 0;
|
|
474
481
|
}).catch((n) => {
|
|
475
|
-
if (!(n instanceof
|
|
482
|
+
if (!(n instanceof Z)) {
|
|
476
483
|
if (this.sessionGeneration === t) {
|
|
477
484
|
if (this.consecutiveBackgroundFailures++, this.consecutiveBackgroundFailures >= ie.MAX_BACKGROUND_FAILURES) {
|
|
478
485
|
process.env.NODE_ENV === "development" && console.error(
|
|
479
486
|
`[SessionManager] Background refresh failed ${this.consecutiveBackgroundFailures} consecutive times — expiring session`
|
|
480
487
|
), this.consecutiveBackgroundFailures = 0, this.handleSessionExpired(
|
|
481
|
-
new
|
|
488
|
+
new Z("token_invalid", "Background refresh failed repeatedly")
|
|
482
489
|
);
|
|
483
490
|
return;
|
|
484
491
|
}
|
|
@@ -545,17 +552,40 @@ const ie = class ie {
|
|
|
545
552
|
async getValidAccessToken() {
|
|
546
553
|
const e = this.getTokens();
|
|
547
554
|
if (!(e != null && e.accessToken)) {
|
|
548
|
-
const t = new
|
|
555
|
+
const t = new Z("token_invalid", "No tokens available");
|
|
549
556
|
throw this.handleSessionExpired(t), t;
|
|
550
557
|
}
|
|
551
558
|
if (!this.shouldRefreshToken(e) && !this.isTokenExpired(e))
|
|
552
559
|
return e.accessToken;
|
|
553
560
|
if (!e.refreshToken) {
|
|
554
|
-
const t = new
|
|
561
|
+
const t = new Z("token_invalid", "No refresh token available");
|
|
555
562
|
throw this.handleSessionExpired(t), t;
|
|
556
563
|
}
|
|
557
564
|
return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken);
|
|
558
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Force a refresh ignoring local expiry heuristics. Callers (e.g. HttpService
|
|
568
|
+
* retrying a 401) use this when the backend rejected the current access token
|
|
569
|
+
* as invalid even though `expiresAt` claims it's still valid. Shares the same
|
|
570
|
+
* refreshPromise/queue as getValidAccessToken, so concurrent forceRefresh
|
|
571
|
+
* calls deduplicate to a single refresh network call.
|
|
572
|
+
*
|
|
573
|
+
* @throws {SessionExpiredError} if no refresh token → caller should logout
|
|
574
|
+
* @throws {TokenRefreshTimeoutError} if queue wait exceeds timeout
|
|
575
|
+
* @throws {TokenRefreshError} if refresh fails after all retries
|
|
576
|
+
*/
|
|
577
|
+
async forceRefresh() {
|
|
578
|
+
const e = this.getTokens();
|
|
579
|
+
if (!(e != null && e.accessToken)) {
|
|
580
|
+
const t = new Z("token_invalid", "No tokens available");
|
|
581
|
+
throw this.handleSessionExpired(t), t;
|
|
582
|
+
}
|
|
583
|
+
if (!e.refreshToken) {
|
|
584
|
+
const t = new Z("token_invalid", "No refresh token available");
|
|
585
|
+
throw this.handleSessionExpired(t), t;
|
|
586
|
+
}
|
|
587
|
+
return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken, !0);
|
|
588
|
+
}
|
|
559
589
|
/**
|
|
560
590
|
* Backward-compatible getAuthHeaders — now delegates to getValidAccessToken.
|
|
561
591
|
*/
|
|
@@ -563,7 +593,7 @@ const ie = class ie {
|
|
|
563
593
|
try {
|
|
564
594
|
return { Authorization: `Bearer ${await this.getValidAccessToken()}` };
|
|
565
595
|
} catch (e) {
|
|
566
|
-
return e instanceof
|
|
596
|
+
return e instanceof Z && this.onRefreshFailed && this.onRefreshFailed(), {};
|
|
567
597
|
}
|
|
568
598
|
}
|
|
569
599
|
enqueueForToken() {
|
|
@@ -575,15 +605,15 @@ const ie = class ie {
|
|
|
575
605
|
this.refreshQueue.push({ resolve: e, reject: t, timeoutId: n });
|
|
576
606
|
});
|
|
577
607
|
}
|
|
578
|
-
async startRefreshAndResolveQueue(e) {
|
|
579
|
-
this.refreshPromise = this.executeRefreshWithRetry(e);
|
|
608
|
+
async startRefreshAndResolveQueue(e, t = !1) {
|
|
609
|
+
this.refreshPromise = this.executeRefreshWithRetry(e, t);
|
|
580
610
|
try {
|
|
581
611
|
await this.refreshPromise;
|
|
582
|
-
const
|
|
583
|
-
return this.resolveQueue(
|
|
584
|
-
} catch (
|
|
585
|
-
const
|
|
586
|
-
throw
|
|
612
|
+
const n = this.getTokens(), i = (n == null ? void 0 : n.accessToken) || "";
|
|
613
|
+
return this.resolveQueue(i), i;
|
|
614
|
+
} catch (n) {
|
|
615
|
+
const i = n instanceof Error ? n : new Error("Token refresh failed");
|
|
616
|
+
throw i instanceof Z ? (this.rejectQueue(i), this.handleSessionExpired(i)) : this.rejectQueue(i), i;
|
|
587
617
|
} finally {
|
|
588
618
|
this.refreshPromise = null;
|
|
589
619
|
}
|
|
@@ -601,74 +631,74 @@ const ie = class ie {
|
|
|
601
631
|
clearTimeout(n.timeoutId), n.reject(e);
|
|
602
632
|
}
|
|
603
633
|
// --- Refresh with retry + error classification ---
|
|
604
|
-
async executeRefreshWithRetry(e) {
|
|
605
|
-
let
|
|
606
|
-
const
|
|
607
|
-
for (let
|
|
608
|
-
if (this.sessionGeneration !==
|
|
609
|
-
throw new
|
|
634
|
+
async executeRefreshWithRetry(e, t = !1) {
|
|
635
|
+
let n;
|
|
636
|
+
const i = this.sessionGeneration;
|
|
637
|
+
for (let a = 0; a <= this.maxRefreshRetries; a++) {
|
|
638
|
+
if (this.sessionGeneration !== i)
|
|
639
|
+
throw new Z("token_invalid", "Session cleared during refresh");
|
|
610
640
|
try {
|
|
611
|
-
await this.performTokenRefresh(e,
|
|
641
|
+
await this.performTokenRefresh(e, i, t);
|
|
612
642
|
return;
|
|
613
|
-
} catch (
|
|
614
|
-
const
|
|
615
|
-
if (
|
|
616
|
-
throw
|
|
617
|
-
if (
|
|
618
|
-
const
|
|
619
|
-
await this.sleep(
|
|
643
|
+
} catch (l) {
|
|
644
|
+
const h = l instanceof Error ? l : new Error(String(l));
|
|
645
|
+
if (h instanceof Z)
|
|
646
|
+
throw h;
|
|
647
|
+
if (n = h, a < this.maxRefreshRetries) {
|
|
648
|
+
const S = this.retryBackoffBase * Math.pow(2, a);
|
|
649
|
+
await this.sleep(S);
|
|
620
650
|
}
|
|
621
651
|
}
|
|
622
652
|
}
|
|
623
|
-
throw new Et(this.maxRefreshRetries + 1,
|
|
653
|
+
throw new Et(this.maxRefreshRetries + 1, n);
|
|
624
654
|
}
|
|
625
655
|
/**
|
|
626
656
|
* Single refresh attempt with error classification.
|
|
627
657
|
* Throws SessionExpiredError for fatal errors (no retry).
|
|
628
658
|
* Throws generic Error for transient errors (will be retried).
|
|
629
659
|
*/
|
|
630
|
-
async performTokenRefresh(e, t) {
|
|
660
|
+
async performTokenRefresh(e, t, n = !1) {
|
|
631
661
|
return typeof navigator < "u" && navigator.locks ? navigator.locks.request(
|
|
632
662
|
`session-refresh:${this.storageKey}`,
|
|
633
|
-
() => this.performTokenRefreshInner(e, t)
|
|
634
|
-
) : this.performTokenRefreshInner(e, t);
|
|
663
|
+
() => this.performTokenRefreshInner(e, t, n)
|
|
664
|
+
) : this.performTokenRefreshInner(e, t, n);
|
|
635
665
|
}
|
|
636
|
-
async performTokenRefreshInner(e, t) {
|
|
666
|
+
async performTokenRefreshInner(e, t, n = !1) {
|
|
637
667
|
if (!this.baseUrl)
|
|
638
668
|
throw new Error("Base URL not configured for token refresh");
|
|
639
|
-
const
|
|
640
|
-
if (n != null &&
|
|
669
|
+
const i = this.getTokens();
|
|
670
|
+
if (!n && (i != null && i.accessToken) && !this.isTokenExpired(i) && !this.shouldRefreshToken(i))
|
|
641
671
|
return;
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
let
|
|
672
|
+
const a = (i == null ? void 0 : i.refreshToken) || e, l = `${this.baseUrl}/auth/refresh`, h = At(a, "deviceId"), S = { refreshToken: a };
|
|
673
|
+
h && (S.deviceId = h);
|
|
674
|
+
let k;
|
|
645
675
|
try {
|
|
646
|
-
|
|
676
|
+
k = await fetch(l, {
|
|
647
677
|
method: "POST",
|
|
648
678
|
headers: { "Content-Type": "application/json" },
|
|
649
|
-
body: JSON.stringify(
|
|
679
|
+
body: JSON.stringify(S),
|
|
650
680
|
...this.enableCookieSession && { credentials: "include" }
|
|
651
681
|
});
|
|
652
682
|
} catch (c) {
|
|
653
683
|
throw c instanceof Error ? c : new Error("Network error during token refresh");
|
|
654
684
|
}
|
|
655
|
-
if (!
|
|
685
|
+
if (!k.ok) {
|
|
656
686
|
let c = "";
|
|
657
687
|
try {
|
|
658
|
-
const
|
|
659
|
-
c = (
|
|
688
|
+
const d = await k.json();
|
|
689
|
+
c = (d.message || d.error || "").toLowerCase();
|
|
660
690
|
} catch {
|
|
661
|
-
c =
|
|
691
|
+
c = k.statusText.toLowerCase();
|
|
662
692
|
}
|
|
663
|
-
throw
|
|
693
|
+
throw k.status === 401 ? c.includes("expired") ? new Z("token_expired") : c.includes("invalid") ? new Z("token_invalid") : new Z("token_invalid", `Unauthorized: ${c}`) : k.status === 400 ? c.includes("inactive") ? new Z("user_inactive") : c.includes("expired") || c.includes("invalid") ? new Z("token_invalid", c) : c.includes("reuse") || c.includes("revoked") ? new Z("token_invalid", c) : new Error(`Token refresh failed (400): ${c}`) : new Error(`Token refresh failed: ${k.status} ${c}`);
|
|
664
694
|
}
|
|
665
695
|
if (this.sessionGeneration !== t)
|
|
666
|
-
throw new
|
|
667
|
-
const
|
|
696
|
+
throw new Z("token_invalid", "Session cleared during refresh");
|
|
697
|
+
const T = await k.json();
|
|
668
698
|
this.setTokens({
|
|
669
|
-
accessToken:
|
|
670
|
-
refreshToken:
|
|
671
|
-
expiresIn:
|
|
699
|
+
accessToken: T.accessToken,
|
|
700
|
+
refreshToken: T.refreshToken || a,
|
|
701
|
+
expiresIn: T.expiresIn
|
|
672
702
|
});
|
|
673
703
|
}
|
|
674
704
|
// --- Session expiry handler ---
|
|
@@ -691,7 +721,7 @@ const ie = class ie {
|
|
|
691
721
|
// --- Session lifecycle ---
|
|
692
722
|
clearSession() {
|
|
693
723
|
this.sessionGeneration++, this.cancelProactiveTimer(), this.clearTokens();
|
|
694
|
-
const e = new
|
|
724
|
+
const e = new Z("token_invalid", "Session cleared");
|
|
695
725
|
this.rejectQueue(e);
|
|
696
726
|
}
|
|
697
727
|
/**
|
|
@@ -700,7 +730,7 @@ const ie = class ie {
|
|
|
700
730
|
*/
|
|
701
731
|
destroy() {
|
|
702
732
|
this.isDestroyed = !0, ie.instances.delete(this.storageKey), this.cancelProactiveTimer(), this.detachVisibilityListener();
|
|
703
|
-
const e = new
|
|
733
|
+
const e = new Z("token_invalid", "SessionManager destroyed");
|
|
704
734
|
this.rejectQueue(e);
|
|
705
735
|
}
|
|
706
736
|
// --- JWT helpers ---
|
|
@@ -941,7 +971,7 @@ function _t(r, e, t) {
|
|
|
941
971
|
}
|
|
942
972
|
const Be = fe(null);
|
|
943
973
|
function xr({ config: r, children: e }) {
|
|
944
|
-
var j,
|
|
974
|
+
var j, K, $;
|
|
945
975
|
const { baseUrl: t, appInfo: n, appId: i } = Ae(), a = te(() => typeof window > "u" ? null : Bt(
|
|
946
976
|
{
|
|
947
977
|
tenantMode: r.tenantMode || "selector",
|
|
@@ -954,75 +984,75 @@ function xr({ config: r, children: e }) {
|
|
|
954
984
|
search: window.location.search
|
|
955
985
|
},
|
|
956
986
|
window.localStorage
|
|
957
|
-
), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [l,
|
|
958
|
-
() => ({ enabled:
|
|
959
|
-
[
|
|
960
|
-
), [
|
|
987
|
+
), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [l, h] = N(() => a()), S = ((j = r.cache) == null ? void 0 : j.enabled) ?? !0, k = ((K = r.cache) == null ? void 0 : K.ttl) ?? 5 * 60 * 1e3, T = (($ = r.cache) == null ? void 0 : $.storageKey) ?? `tenant_cache_${l || "default"}`, c = V(
|
|
988
|
+
() => ({ enabled: S, ttl: k, storageKey: T }),
|
|
989
|
+
[S, k, T]
|
|
990
|
+
), [d, A] = N(() => {
|
|
961
991
|
if (r.initialTenant) return r.initialTenant;
|
|
962
|
-
if (!
|
|
992
|
+
if (!c.enabled || !l) return null;
|
|
963
993
|
try {
|
|
964
|
-
const B = localStorage.getItem(
|
|
994
|
+
const B = localStorage.getItem(c.storageKey);
|
|
965
995
|
if (!B) return null;
|
|
966
996
|
const L = JSON.parse(B);
|
|
967
|
-
return Date.now() - L.timestamp <
|
|
997
|
+
return Date.now() - L.timestamp < c.ttl && L.tenantSlug === l ? L.data : (localStorage.removeItem(c.storageKey), null);
|
|
968
998
|
} catch {
|
|
969
999
|
return null;
|
|
970
1000
|
}
|
|
971
|
-
}), [P, I] = N(!
|
|
1001
|
+
}), [P, I] = N(!d && !r.initialTenant), [R, E] = N(null), [m, g] = N(null), [b, C] = N(!1), [o, p] = N(null);
|
|
972
1002
|
re(() => {
|
|
973
1003
|
if (r.tenantMode === "fixed") return;
|
|
974
1004
|
const B = a();
|
|
975
|
-
|
|
1005
|
+
h(B);
|
|
976
1006
|
}, [a, r.tenantMode]);
|
|
977
|
-
const
|
|
1007
|
+
const x = (n == null ? void 0 : n.settingsSchema) || null, y = te(
|
|
978
1008
|
async (B, L = !1) => {
|
|
979
|
-
if (!(!L &&
|
|
1009
|
+
if (!(!L && c.enabled && d && d.subdomain === B))
|
|
980
1010
|
try {
|
|
981
|
-
I(!0),
|
|
1011
|
+
I(!0), E(null);
|
|
982
1012
|
const q = new he(t), W = await new be(q, i).getPublicTenantInfo(B);
|
|
983
|
-
if (
|
|
1013
|
+
if (A(W), c.enabled)
|
|
984
1014
|
try {
|
|
985
|
-
const
|
|
1015
|
+
const Y = {
|
|
986
1016
|
data: W,
|
|
987
1017
|
timestamp: Date.now(),
|
|
988
1018
|
tenantSlug: B
|
|
989
1019
|
};
|
|
990
|
-
localStorage.setItem(
|
|
991
|
-
} catch (
|
|
992
|
-
process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:",
|
|
1020
|
+
localStorage.setItem(c.storageKey, JSON.stringify(Y));
|
|
1021
|
+
} catch (Y) {
|
|
1022
|
+
process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", Y);
|
|
993
1023
|
}
|
|
994
1024
|
} catch (q) {
|
|
995
1025
|
const _ = q instanceof Error ? q : new Error("Failed to load tenant information");
|
|
996
|
-
|
|
1026
|
+
E(_), A(null);
|
|
997
1027
|
} finally {
|
|
998
1028
|
I(!1);
|
|
999
1029
|
}
|
|
1000
1030
|
},
|
|
1001
|
-
[t, i,
|
|
1031
|
+
[t, i, c, d]
|
|
1002
1032
|
), u = te(async () => {
|
|
1003
|
-
if (!(!
|
|
1033
|
+
if (!(!c.enabled || !d || !l))
|
|
1004
1034
|
try {
|
|
1005
|
-
const B = localStorage.getItem(
|
|
1035
|
+
const B = localStorage.getItem(c.storageKey);
|
|
1006
1036
|
if (!B) return;
|
|
1007
1037
|
const L = JSON.parse(B);
|
|
1008
|
-
if (Date.now() - L.timestamp >
|
|
1009
|
-
const _ = new he(t),
|
|
1010
|
-
|
|
1011
|
-
const
|
|
1012
|
-
data:
|
|
1038
|
+
if (Date.now() - L.timestamp > c.ttl * 0.5) {
|
|
1039
|
+
const _ = new he(t), Y = await new be(_, i).getPublicTenantInfo(l);
|
|
1040
|
+
A(Y);
|
|
1041
|
+
const X = {
|
|
1042
|
+
data: Y,
|
|
1013
1043
|
timestamp: Date.now(),
|
|
1014
1044
|
tenantSlug: l
|
|
1015
1045
|
};
|
|
1016
|
-
localStorage.setItem(
|
|
1046
|
+
localStorage.setItem(c.storageKey, JSON.stringify(X));
|
|
1017
1047
|
}
|
|
1018
1048
|
} catch (B) {
|
|
1019
1049
|
process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", B);
|
|
1020
1050
|
}
|
|
1021
|
-
}, [t, i,
|
|
1022
|
-
if (
|
|
1051
|
+
}, [t, i, c, d, l]), v = te(async () => {
|
|
1052
|
+
if (d != null && d.id)
|
|
1023
1053
|
try {
|
|
1024
1054
|
C(!0), p(null);
|
|
1025
|
-
const B = new he(t), q = await new be(B,
|
|
1055
|
+
const B = new he(t), q = await new be(B, d.appId).getTenantSettings(d.id);
|
|
1026
1056
|
g(q);
|
|
1027
1057
|
} catch (B) {
|
|
1028
1058
|
const L = B instanceof Error ? B : new Error("Failed to load tenant settings");
|
|
@@ -1030,25 +1060,25 @@ function xr({ config: r, children: e }) {
|
|
|
1030
1060
|
} finally {
|
|
1031
1061
|
C(!1);
|
|
1032
1062
|
}
|
|
1033
|
-
}, [t,
|
|
1063
|
+
}, [t, d]), D = te(() => {
|
|
1034
1064
|
v();
|
|
1035
1065
|
}, [v]), se = te(
|
|
1036
1066
|
(B) => {
|
|
1037
|
-
if (!
|
|
1067
|
+
if (!x)
|
|
1038
1068
|
return { isValid: !0, errors: [] };
|
|
1039
1069
|
const L = [];
|
|
1040
1070
|
try {
|
|
1041
|
-
return
|
|
1042
|
-
var
|
|
1071
|
+
return x.properties && Object.entries(x.properties).forEach(([q, _]) => {
|
|
1072
|
+
var Y;
|
|
1043
1073
|
const W = B[q];
|
|
1044
|
-
if ((
|
|
1074
|
+
if ((Y = x.required) != null && Y.includes(q) && W == null) {
|
|
1045
1075
|
L.push(`Field '${q}' is required`);
|
|
1046
1076
|
return;
|
|
1047
1077
|
}
|
|
1048
1078
|
if (W != null) {
|
|
1049
1079
|
if (_.type) {
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1080
|
+
const X = _.type, le = typeof W;
|
|
1081
|
+
X === "string" && le !== "string" ? L.push(`Field '${q}' must be a string`) : (X === "number" || X === "integer") && le !== "number" ? L.push(`Field '${q}' must be a number`) : X === "boolean" && le !== "boolean" ? L.push(`Field '${q}' must be a boolean`) : X === "array" && !Array.isArray(W) && L.push(`Field '${q}' must be an array`);
|
|
1052
1082
|
}
|
|
1053
1083
|
_.minLength !== void 0 && typeof W == "string" && W.length < _.minLength && L.push(
|
|
1054
1084
|
`Field '${q}' must be at least ${_.minLength} characters long`
|
|
@@ -1067,13 +1097,13 @@ function xr({ config: r, children: e }) {
|
|
|
1067
1097
|
};
|
|
1068
1098
|
}
|
|
1069
1099
|
},
|
|
1070
|
-
[
|
|
1100
|
+
[x]
|
|
1071
1101
|
);
|
|
1072
1102
|
re(() => {
|
|
1073
|
-
!r.initialTenant && l ?
|
|
1074
|
-
}, [r.initialTenant, l,
|
|
1075
|
-
|
|
1076
|
-
}, [
|
|
1103
|
+
!r.initialTenant && l ? d ? u() : y(l) : !r.initialTenant && !l && (A(null), E(null), I(!1));
|
|
1104
|
+
}, [r.initialTenant, l, d, y, u]), re(() => {
|
|
1105
|
+
d != null && d.id ? v() : (g(null), p(null), C(!1));
|
|
1106
|
+
}, [d == null ? void 0 : d.id, v]);
|
|
1077
1107
|
const F = te(
|
|
1078
1108
|
(B, L) => {
|
|
1079
1109
|
const { mode: q = "reload", redirectPath: _ } = L || {}, W = r.tenantMode || "selector";
|
|
@@ -1085,37 +1115,37 @@ function xr({ config: r, children: e }) {
|
|
|
1085
1115
|
return;
|
|
1086
1116
|
}
|
|
1087
1117
|
if (localStorage.setItem("tenant", B), W === "subdomain") {
|
|
1088
|
-
const
|
|
1118
|
+
const Y = window.location.hostname, X = _t(
|
|
1089
1119
|
B,
|
|
1090
|
-
|
|
1120
|
+
Y,
|
|
1091
1121
|
r.baseDomain
|
|
1092
1122
|
);
|
|
1093
|
-
if (!
|
|
1123
|
+
if (!X) {
|
|
1094
1124
|
process.env.NODE_ENV === "development" && console.warn(
|
|
1095
1125
|
"[TenantProvider] Cannot switch subdomain, invalid hostname:",
|
|
1096
|
-
|
|
1126
|
+
Y
|
|
1097
1127
|
);
|
|
1098
1128
|
return;
|
|
1099
1129
|
}
|
|
1100
|
-
const le = _ || window.location.pathname, Se = new URL(`${window.location.protocol}//${
|
|
1130
|
+
const le = _ || window.location.pathname, Se = new URL(`${window.location.protocol}//${X}${le}`);
|
|
1101
1131
|
new URLSearchParams(window.location.search).forEach((Fe, Ne) => {
|
|
1102
1132
|
Se.searchParams.set(Ne, Fe);
|
|
1103
1133
|
}), window.location.href = Se.toString();
|
|
1104
1134
|
} else if (W === "selector") {
|
|
1105
|
-
const
|
|
1106
|
-
if (
|
|
1107
|
-
const le = `${
|
|
1135
|
+
const Y = _ || window.location.pathname, X = new URLSearchParams(window.location.search);
|
|
1136
|
+
if (X.set(r.selectorParam || "tenant", B), q === "reload") {
|
|
1137
|
+
const le = `${Y}?${X.toString()}${window.location.hash}`;
|
|
1108
1138
|
window.location.href = le;
|
|
1109
1139
|
} else {
|
|
1110
|
-
const le = `${
|
|
1111
|
-
window.history.pushState({}, "", le),
|
|
1140
|
+
const le = `${Y}?${X.toString()}${window.location.hash}`;
|
|
1141
|
+
window.history.pushState({}, "", le), h(B), y(B);
|
|
1112
1142
|
}
|
|
1113
1143
|
}
|
|
1114
1144
|
},
|
|
1115
1145
|
[r.tenantMode, r.selectorParam, r.baseDomain, r.fixedTenantSlug, y]
|
|
1116
1146
|
), H = V(() => ({
|
|
1117
1147
|
// Tenant info
|
|
1118
|
-
tenant:
|
|
1148
|
+
tenant: d,
|
|
1119
1149
|
tenantSlug: l,
|
|
1120
1150
|
isTenantLoading: P,
|
|
1121
1151
|
tenantError: R,
|
|
@@ -1124,7 +1154,7 @@ function xr({ config: r, children: e }) {
|
|
|
1124
1154
|
},
|
|
1125
1155
|
// Settings
|
|
1126
1156
|
settings: m,
|
|
1127
|
-
settingsSchema:
|
|
1157
|
+
settingsSchema: x,
|
|
1128
1158
|
isSettingsLoading: b,
|
|
1129
1159
|
settingsError: o,
|
|
1130
1160
|
// Actions
|
|
@@ -1133,12 +1163,12 @@ function xr({ config: r, children: e }) {
|
|
|
1133
1163
|
// Validation
|
|
1134
1164
|
validateSettings: se
|
|
1135
1165
|
}), [
|
|
1136
|
-
|
|
1166
|
+
d,
|
|
1137
1167
|
l,
|
|
1138
1168
|
P,
|
|
1139
1169
|
R,
|
|
1140
1170
|
m,
|
|
1141
|
-
|
|
1171
|
+
x,
|
|
1142
1172
|
b,
|
|
1143
1173
|
o,
|
|
1144
1174
|
D,
|
|
@@ -1200,13 +1230,13 @@ function et() {
|
|
|
1200
1230
|
}
|
|
1201
1231
|
const Pe = fe(null), Ie = fe(null);
|
|
1202
1232
|
function Pr({ config: r = {}, children: e }) {
|
|
1203
|
-
const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? r.baseUrl ?? "", a = (t == null ? void 0 : t.appId) ?? r.appId, l = (n == null ? void 0 : n.tenant) ?? null,
|
|
1233
|
+
const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? r.baseUrl ?? "", a = (t == null ? void 0 : t.appId) ?? r.appId, l = (n == null ? void 0 : n.tenant) ?? null, h = (n == null ? void 0 : n.tenantSlug) ?? null, S = (n == null ? void 0 : n.switchTenant) ?? (() => {
|
|
1204
1234
|
});
|
|
1205
1235
|
if (!i)
|
|
1206
1236
|
throw new Error(
|
|
1207
1237
|
"[AuthProvider] baseUrl is required. Provide it via AppProvider or AuthConfig.baseUrl."
|
|
1208
1238
|
);
|
|
1209
|
-
const [
|
|
1239
|
+
const [k, T] = N(r.initialRoles || []), [c, d] = N(!r.initialRoles), [A, P] = N(null), [I, R] = N(!1), [E, m] = N(null), [g, b] = N(() => Ot()), C = ye({ done: !1 });
|
|
1210
1240
|
C.current.done || (C.current.done = !0);
|
|
1211
1241
|
const o = V(() => Me.getInstance({
|
|
1212
1242
|
baseUrl: i,
|
|
@@ -1221,7 +1251,7 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1221
1251
|
r.enableCookieSession,
|
|
1222
1252
|
r.refreshQueueTimeout,
|
|
1223
1253
|
r.proactiveRefreshMargin
|
|
1224
|
-
]), [p,
|
|
1254
|
+
]), [p, x] = N(() => {
|
|
1225
1255
|
const w = o.getTokens();
|
|
1226
1256
|
return w ? o.hasValidSession() || !!w.refreshToken : !!r.enableCookieSession;
|
|
1227
1257
|
}), y = C.current.done && !p, u = V(() => {
|
|
@@ -1236,12 +1266,12 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1236
1266
|
), se = V(
|
|
1237
1267
|
() => new Dt(u),
|
|
1238
1268
|
[u]
|
|
1239
|
-
), F = V(() =>
|
|
1240
|
-
() => o.hasValidSession() &&
|
|
1241
|
-
[o,
|
|
1242
|
-
),
|
|
1269
|
+
), F = V(() => A != null && A.roleId && k.find((w) => w.id === A.roleId) || null, [A, k]), H = V(() => (F == null ? void 0 : F.permissions) || [], [F]), j = V(
|
|
1270
|
+
() => o.hasValidSession() && A !== null,
|
|
1271
|
+
[o, A]
|
|
1272
|
+
), K = V(() => (A == null ? void 0 : A.tenantId) != null, [A]), $ = ye(null), B = ye(/* @__PURE__ */ new Set()), L = async (w = !1) => {
|
|
1243
1273
|
try {
|
|
1244
|
-
if (!o.hasValidSession() || !w &&
|
|
1274
|
+
if (!o.hasValidSession() || !w && A) return;
|
|
1245
1275
|
const M = o.getUserId();
|
|
1246
1276
|
if (!M) {
|
|
1247
1277
|
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] No userId available in token or storage");
|
|
@@ -1259,14 +1289,14 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1259
1289
|
}, q = async (w) => {
|
|
1260
1290
|
var He;
|
|
1261
1291
|
const { username: M, password: z, tenantSlug: O, redirectPath: J } = w;
|
|
1262
|
-
let
|
|
1263
|
-
O && (
|
|
1292
|
+
let ee = l == null ? void 0 : l.id, Q = h;
|
|
1293
|
+
O && (ee = (await new be(u, a).getPublicTenantInfo(O)).id, Q = O);
|
|
1264
1294
|
const G = await v.login({
|
|
1265
1295
|
username: M,
|
|
1266
1296
|
password: z,
|
|
1267
1297
|
appId: a,
|
|
1268
|
-
tenantId:
|
|
1269
|
-
}), ke = O && O !==
|
|
1298
|
+
tenantId: ee
|
|
1299
|
+
}), ke = O && O !== h;
|
|
1270
1300
|
if (o.setTokens({
|
|
1271
1301
|
accessToken: G.accessToken,
|
|
1272
1302
|
refreshToken: G.refreshToken,
|
|
@@ -1282,19 +1312,19 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1282
1312
|
G.tenants && G.tenants.length > 0 && (b(G.tenants), Xe(G.tenants));
|
|
1283
1313
|
const Ge = ((He = G.user) == null ? void 0 : He.tenantId) !== null;
|
|
1284
1314
|
if (ke && Q)
|
|
1285
|
-
return
|
|
1315
|
+
return S(Q, { redirectPath: J }), G;
|
|
1286
1316
|
if (J && J !== window.location.pathname)
|
|
1287
|
-
return
|
|
1317
|
+
return S(Q || h || "", { redirectPath: J }), G;
|
|
1288
1318
|
if (!Ge && G.tenants && G.tenants.length > 0) {
|
|
1289
1319
|
const Ee = w.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
|
|
1290
1320
|
if (G.tenants.length === 1 && Ee) {
|
|
1291
1321
|
const Qe = G.tenants[0];
|
|
1292
|
-
return
|
|
1322
|
+
return S(Qe.subdomain, { redirectPath: J }), G;
|
|
1293
1323
|
} else G.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(G.tenants);
|
|
1294
1324
|
}
|
|
1295
1325
|
return G;
|
|
1296
1326
|
}, _ = async (w) => {
|
|
1297
|
-
const { email: M, phoneNumber: z, name: O, password: J, lastName:
|
|
1327
|
+
const { email: M, phoneNumber: z, name: O, password: J, lastName: ee, tenantId: Q } = w;
|
|
1298
1328
|
if (!M && !z)
|
|
1299
1329
|
throw new Error("Either email or phoneNumber is required");
|
|
1300
1330
|
if (!O || !J)
|
|
@@ -1305,27 +1335,27 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1305
1335
|
name: O,
|
|
1306
1336
|
password: J,
|
|
1307
1337
|
tenantId: Q ?? (l == null ? void 0 : l.id),
|
|
1308
|
-
lastName:
|
|
1338
|
+
lastName: ee,
|
|
1309
1339
|
appId: a
|
|
1310
1340
|
});
|
|
1311
1341
|
}, W = async (w) => {
|
|
1312
|
-
const { email: M, phoneNumber: z, name: O, password: J, tenantName:
|
|
1342
|
+
const { email: M, phoneNumber: z, name: O, password: J, tenantName: ee, lastName: Q } = w;
|
|
1313
1343
|
if (!M && !z)
|
|
1314
1344
|
throw new Error("Either email or phoneNumber is required");
|
|
1315
|
-
if (!O || !J || !
|
|
1345
|
+
if (!O || !J || !ee)
|
|
1316
1346
|
throw new Error("Name, password, and tenantName are required");
|
|
1317
1347
|
return v.signupTenantAdmin({
|
|
1318
1348
|
email: M,
|
|
1319
1349
|
phoneNumber: z,
|
|
1320
1350
|
name: O,
|
|
1321
1351
|
password: J,
|
|
1322
|
-
tenantName:
|
|
1352
|
+
tenantName: ee,
|
|
1323
1353
|
appId: a,
|
|
1324
1354
|
lastName: Q
|
|
1325
1355
|
});
|
|
1326
|
-
}, K = async (w) => {
|
|
1327
|
-
await v.changePassword(w);
|
|
1328
1356
|
}, Y = async (w) => {
|
|
1357
|
+
await v.changePassword(w);
|
|
1358
|
+
}, X = async (w) => {
|
|
1329
1359
|
const { email: M, tenantId: z } = w, O = z ?? (l == null ? void 0 : l.id);
|
|
1330
1360
|
if (!O)
|
|
1331
1361
|
throw new Error("tenantId is required for password reset");
|
|
@@ -1333,7 +1363,7 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1333
1363
|
}, le = async (w) => {
|
|
1334
1364
|
await v.confirmPasswordReset(w);
|
|
1335
1365
|
}, Se = async (w) => {
|
|
1336
|
-
const { email: M, frontendUrl: z, name: O, lastName: J, tenantId:
|
|
1366
|
+
const { email: M, frontendUrl: z, name: O, lastName: J, tenantId: ee } = w, Q = ee ?? (l == null ? void 0 : l.id);
|
|
1337
1367
|
if (!Q)
|
|
1338
1368
|
throw new Error("tenantId is required for magic link authentication");
|
|
1339
1369
|
return v.sendMagicLink({
|
|
@@ -1346,8 +1376,8 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1346
1376
|
});
|
|
1347
1377
|
}, We = async (w) => {
|
|
1348
1378
|
const { token: M, email: z, tenantSlug: O } = w;
|
|
1349
|
-
let J = l == null ? void 0 : l.id,
|
|
1350
|
-
O && (J = (await new be(u, a).getPublicTenantInfo(O)).id,
|
|
1379
|
+
let J = l == null ? void 0 : l.id, ee = h;
|
|
1380
|
+
O && (J = (await new be(u, a).getPublicTenantInfo(O)).id, ee = O);
|
|
1351
1381
|
const Q = await v.verifyMagicLink({
|
|
1352
1382
|
token: M,
|
|
1353
1383
|
email: z,
|
|
@@ -1357,7 +1387,7 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1357
1387
|
if (B.current.has(M))
|
|
1358
1388
|
return Q;
|
|
1359
1389
|
B.current.add(M);
|
|
1360
|
-
const G = O && O !==
|
|
1390
|
+
const G = O && O !== h;
|
|
1361
1391
|
if (o.setTokens({
|
|
1362
1392
|
accessToken: Q.accessToken,
|
|
1363
1393
|
refreshToken: Q.refreshToken,
|
|
@@ -1370,7 +1400,7 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1370
1400
|
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after magic link:", ke);
|
|
1371
1401
|
}
|
|
1372
1402
|
}
|
|
1373
|
-
return G &&
|
|
1403
|
+
return G && ee && ee !== h && S(ee), Q;
|
|
1374
1404
|
}, Fe = async () => {
|
|
1375
1405
|
const w = o.getTokens();
|
|
1376
1406
|
if (!(w != null && w.refreshToken))
|
|
@@ -1392,13 +1422,13 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1392
1422
|
}, mt = async () => {
|
|
1393
1423
|
if (a)
|
|
1394
1424
|
try {
|
|
1395
|
-
|
|
1425
|
+
d(!0);
|
|
1396
1426
|
const { roles: w } = await se.getRolesByApp(a);
|
|
1397
|
-
|
|
1427
|
+
T(w);
|
|
1398
1428
|
} catch (w) {
|
|
1399
1429
|
process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", w);
|
|
1400
1430
|
} finally {
|
|
1401
|
-
|
|
1431
|
+
d(!1);
|
|
1402
1432
|
}
|
|
1403
1433
|
}, gt = async (w, M) => {
|
|
1404
1434
|
const { redirectPath: z } = M || {}, O = o.getTokens();
|
|
@@ -1413,8 +1443,8 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1413
1443
|
refreshToken: O.refreshToken,
|
|
1414
1444
|
expiresIn: J.expiresIn
|
|
1415
1445
|
}), P(J.user), o.setUser(J.user);
|
|
1416
|
-
const
|
|
1417
|
-
|
|
1446
|
+
const ee = g.find((Q) => Q.id === w);
|
|
1447
|
+
ee && S(ee.subdomain, { redirectPath: z });
|
|
1418
1448
|
}, yt = async () => {
|
|
1419
1449
|
const w = await v.getUserTenants();
|
|
1420
1450
|
return b(w), Xe(w), w;
|
|
@@ -1425,8 +1455,8 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1425
1455
|
signupTenantAdmin: W,
|
|
1426
1456
|
sendMagicLink: Se,
|
|
1427
1457
|
verifyMagicLink: We,
|
|
1428
|
-
changePassword:
|
|
1429
|
-
requestPasswordReset:
|
|
1458
|
+
changePassword: Y,
|
|
1459
|
+
requestPasswordReset: X,
|
|
1430
1460
|
confirmPasswordReset: le,
|
|
1431
1461
|
refreshToken: Fe,
|
|
1432
1462
|
logout: Ne,
|
|
@@ -1467,15 +1497,15 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1467
1497
|
isAuthenticated: j,
|
|
1468
1498
|
isAuthInitializing: !y,
|
|
1469
1499
|
isAuthReady: y,
|
|
1470
|
-
currentUser:
|
|
1500
|
+
currentUser: A,
|
|
1471
1501
|
isUserLoading: I,
|
|
1472
|
-
userError:
|
|
1502
|
+
userError: E,
|
|
1473
1503
|
userRole: F,
|
|
1474
1504
|
userPermissions: H,
|
|
1475
|
-
availableRoles:
|
|
1476
|
-
rolesLoading:
|
|
1505
|
+
availableRoles: k,
|
|
1506
|
+
rolesLoading: c,
|
|
1477
1507
|
userTenants: g,
|
|
1478
|
-
hasTenantContext:
|
|
1508
|
+
hasTenantContext: K,
|
|
1479
1509
|
sessionManager: o,
|
|
1480
1510
|
authenticatedHttpService: u,
|
|
1481
1511
|
hasPermission: w,
|
|
@@ -1486,27 +1516,27 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1486
1516
|
}, [
|
|
1487
1517
|
j,
|
|
1488
1518
|
y,
|
|
1489
|
-
|
|
1519
|
+
A,
|
|
1490
1520
|
I,
|
|
1491
|
-
|
|
1521
|
+
E,
|
|
1492
1522
|
F,
|
|
1493
1523
|
H,
|
|
1494
|
-
|
|
1495
|
-
|
|
1524
|
+
k,
|
|
1525
|
+
c,
|
|
1496
1526
|
g,
|
|
1497
|
-
|
|
1527
|
+
K,
|
|
1498
1528
|
o,
|
|
1499
1529
|
u
|
|
1500
1530
|
]);
|
|
1501
1531
|
return re(() => {
|
|
1502
1532
|
if (r.initialRoles || !a) return;
|
|
1503
1533
|
let w = !1;
|
|
1504
|
-
return
|
|
1505
|
-
w ||
|
|
1534
|
+
return d(!0), se.getRolesByApp(a).then(({ roles: M }) => {
|
|
1535
|
+
w || T(M);
|
|
1506
1536
|
}).catch((M) => {
|
|
1507
1537
|
process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", M);
|
|
1508
1538
|
}).finally(() => {
|
|
1509
|
-
w ||
|
|
1539
|
+
w || d(!1);
|
|
1510
1540
|
}), () => {
|
|
1511
1541
|
w = !0;
|
|
1512
1542
|
};
|
|
@@ -1517,16 +1547,16 @@ function Pr({ config: r = {}, children: e }) {
|
|
|
1517
1547
|
if (!o.hasValidSession() && ((O = o.getTokens()) != null && O.refreshToken) && await o.waitForPendingRefresh(), w || !o.hasValidSession() && !o.getTokens() && r.enableCookieSession && (await o.attemptCookieSessionRestore(), w))
|
|
1518
1548
|
return;
|
|
1519
1549
|
const z = o.getUser();
|
|
1520
|
-
z && o.hasValidSession() && P(z),
|
|
1550
|
+
z && o.hasValidSession() && P(z), x(!1);
|
|
1521
1551
|
})(), () => {
|
|
1522
1552
|
w = !0;
|
|
1523
1553
|
};
|
|
1524
1554
|
}, [o, r.enableCookieSession]), re(() => {
|
|
1525
|
-
!
|
|
1555
|
+
!A && !I && !E && o.hasValidSession() ? $.current.loadUserData().catch(() => {
|
|
1526
1556
|
}).finally(() => {
|
|
1527
|
-
|
|
1528
|
-
}) :
|
|
1529
|
-
}, [
|
|
1557
|
+
x(!1);
|
|
1558
|
+
}) : x(!1);
|
|
1559
|
+
}, [A, I, E, o]), /* @__PURE__ */ s(Ie.Provider, { value: bt, children: /* @__PURE__ */ s(Pe.Provider, { value: wt, children: e }) });
|
|
1530
1560
|
}
|
|
1531
1561
|
function Ir() {
|
|
1532
1562
|
const r = ne(Pe);
|
|
@@ -1599,23 +1629,23 @@ class Vt {
|
|
|
1599
1629
|
}
|
|
1600
1630
|
const Ve = fe(null);
|
|
1601
1631
|
function Fr({ config: r = {}, children: e }) {
|
|
1602
|
-
const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (t == null ? void 0 : t.appId) ?? "", l = (n == null ? void 0 : n.tenant) ?? null, [
|
|
1632
|
+
const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (t == null ? void 0 : t.appId) ?? "", l = (n == null ? void 0 : n.tenant) ?? null, [h, S] = N([]), [k, T] = N(!1), [c, d] = N(null), [A, P] = N(!1), I = V(() => {
|
|
1603
1633
|
const m = new he(i);
|
|
1604
1634
|
return new Vt(m);
|
|
1605
1635
|
}, [i]), R = async () => {
|
|
1606
1636
|
if (!(l != null && l.id)) {
|
|
1607
|
-
|
|
1637
|
+
S([]);
|
|
1608
1638
|
return;
|
|
1609
1639
|
}
|
|
1610
|
-
|
|
1640
|
+
T(!0), d(null);
|
|
1611
1641
|
try {
|
|
1612
1642
|
const m = await I.getTenantFeatureFlags(l.id, a);
|
|
1613
|
-
|
|
1643
|
+
S(m);
|
|
1614
1644
|
} catch (m) {
|
|
1615
1645
|
const g = m instanceof Error ? m.message : "Failed to fetch feature flags";
|
|
1616
|
-
|
|
1646
|
+
d(g), r.onError && r.onError(m instanceof Error ? m : new Error(g));
|
|
1617
1647
|
} finally {
|
|
1618
|
-
|
|
1648
|
+
T(!1);
|
|
1619
1649
|
}
|
|
1620
1650
|
};
|
|
1621
1651
|
re(() => {
|
|
@@ -1624,28 +1654,28 @@ function Fr({ config: r = {}, children: e }) {
|
|
|
1624
1654
|
const m = r.refreshInterval || 5 * 60 * 1e3, g = setInterval(R, m);
|
|
1625
1655
|
return () => clearInterval(g);
|
|
1626
1656
|
}, [l == null ? void 0 : l.id, i, a, r.refreshInterval]);
|
|
1627
|
-
const
|
|
1657
|
+
const E = V(() => {
|
|
1628
1658
|
const m = (p) => {
|
|
1629
|
-
const
|
|
1630
|
-
return (
|
|
1631
|
-
}, g = (p) =>
|
|
1632
|
-
const
|
|
1633
|
-
return
|
|
1659
|
+
const x = h.find((y) => y.key === p);
|
|
1660
|
+
return (x == null ? void 0 : x.value) === !0;
|
|
1661
|
+
}, g = (p) => h.find((x) => x.key === p), b = (p) => {
|
|
1662
|
+
const x = h.find((y) => y.key === p);
|
|
1663
|
+
return x ? x.value ? "enabled" : "disabled" : "not_found";
|
|
1634
1664
|
}, C = async () => {
|
|
1635
1665
|
await R();
|
|
1636
|
-
}, o = !!(i && a) && (
|
|
1666
|
+
}, o = !!(i && a) && (A || !(l != null && l.id));
|
|
1637
1667
|
return {
|
|
1638
|
-
featureFlags:
|
|
1639
|
-
loading:
|
|
1640
|
-
error:
|
|
1668
|
+
featureFlags: h,
|
|
1669
|
+
loading: k,
|
|
1670
|
+
error: c,
|
|
1641
1671
|
isReady: o,
|
|
1642
1672
|
isEnabled: m,
|
|
1643
1673
|
getFlag: g,
|
|
1644
1674
|
getFlagState: b,
|
|
1645
1675
|
refresh: C
|
|
1646
1676
|
};
|
|
1647
|
-
}, [
|
|
1648
|
-
return /* @__PURE__ */ s(Ve.Provider, { value:
|
|
1677
|
+
}, [h, k, c, i, a, l == null ? void 0 : l.id, A]);
|
|
1678
|
+
return /* @__PURE__ */ s(Ve.Provider, { value: E, children: e });
|
|
1649
1679
|
}
|
|
1650
1680
|
function qt() {
|
|
1651
1681
|
const r = ne(Ve);
|
|
@@ -1698,45 +1728,45 @@ class zt {
|
|
|
1698
1728
|
}
|
|
1699
1729
|
const qe = fe(void 0);
|
|
1700
1730
|
function Nr({ config: r = {}, children: e }) {
|
|
1701
|
-
const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [l,
|
|
1702
|
-
const
|
|
1703
|
-
return new zt(
|
|
1731
|
+
const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [l, h] = N(null), [S, k] = N(!1), [T, c] = N(null), [d, A] = N(!1), P = V(() => {
|
|
1732
|
+
const E = new he(i);
|
|
1733
|
+
return new zt(E);
|
|
1704
1734
|
}, [i]), I = async () => {
|
|
1705
1735
|
if (!(a != null && a.id)) {
|
|
1706
|
-
|
|
1736
|
+
h(null);
|
|
1707
1737
|
return;
|
|
1708
1738
|
}
|
|
1709
|
-
|
|
1739
|
+
k(!0), c(null);
|
|
1710
1740
|
try {
|
|
1711
|
-
const
|
|
1712
|
-
|
|
1713
|
-
} catch (
|
|
1714
|
-
const m =
|
|
1715
|
-
|
|
1741
|
+
const E = await P.getTenantSubscriptionFeatures(a.id);
|
|
1742
|
+
h(E);
|
|
1743
|
+
} catch (E) {
|
|
1744
|
+
const m = E instanceof Error ? E.message : "Failed to fetch subscription";
|
|
1745
|
+
c(m), r.onError && r.onError(E instanceof Error ? E : new Error(m));
|
|
1716
1746
|
} finally {
|
|
1717
|
-
|
|
1747
|
+
k(!1);
|
|
1718
1748
|
}
|
|
1719
1749
|
};
|
|
1720
1750
|
re(() => {
|
|
1721
|
-
if (!i || (I().finally(() =>
|
|
1722
|
-
const
|
|
1751
|
+
if (!i || (I().finally(() => A(!0)), !r.refreshInterval)) return;
|
|
1752
|
+
const E = r.refreshInterval || 10 * 60 * 1e3, m = setInterval(I, E);
|
|
1723
1753
|
return () => clearInterval(m);
|
|
1724
1754
|
}, [a == null ? void 0 : a.id, i, r.refreshInterval]);
|
|
1725
1755
|
const R = V(() => {
|
|
1726
|
-
const
|
|
1727
|
-
const y =
|
|
1756
|
+
const E = (l == null ? void 0 : l.features) || [], m = (x) => {
|
|
1757
|
+
const y = E.find((u) => u.key === x);
|
|
1728
1758
|
return y ? y.type === "BOOLEAN" || y.type === "boolean" ? y.value === !0 : !!y.value : !1;
|
|
1729
|
-
}, g = (
|
|
1730
|
-
const u =
|
|
1759
|
+
}, g = (x) => E.find((y) => y.key === x), b = (x, y) => {
|
|
1760
|
+
const u = E.find((v) => v.key === x);
|
|
1731
1761
|
return u ? u.value : y;
|
|
1732
|
-
}, C = (
|
|
1762
|
+
}, C = (x) => !l || !l.isActive ? !1 : x.includes(l.planId), o = async () => {
|
|
1733
1763
|
await I();
|
|
1734
|
-
}, p = !!i && (
|
|
1764
|
+
}, p = !!i && (d || !(a != null && a.id));
|
|
1735
1765
|
return {
|
|
1736
1766
|
subscription: l,
|
|
1737
|
-
features:
|
|
1738
|
-
loading:
|
|
1739
|
-
error:
|
|
1767
|
+
features: E,
|
|
1768
|
+
loading: S,
|
|
1769
|
+
error: T,
|
|
1740
1770
|
isReady: p,
|
|
1741
1771
|
isFeatureEnabled: m,
|
|
1742
1772
|
getFeature: g,
|
|
@@ -1744,7 +1774,7 @@ function Nr({ config: r = {}, children: e }) {
|
|
|
1744
1774
|
hasAllowedPlan: C,
|
|
1745
1775
|
refresh: o
|
|
1746
1776
|
};
|
|
1747
|
-
}, [l,
|
|
1777
|
+
}, [l, S, T, i, a == null ? void 0 : a.id, d]);
|
|
1748
1778
|
return /* @__PURE__ */ s(qe.Provider, { value: R, children: e });
|
|
1749
1779
|
}
|
|
1750
1780
|
function jt() {
|
|
@@ -1914,17 +1944,17 @@ function Mr({
|
|
|
1914
1944
|
requiredPermissions: n,
|
|
1915
1945
|
requireAllPermissions: i = !1
|
|
1916
1946
|
}) {
|
|
1917
|
-
const { hasValidSession: a, sessionManager: l, hasPermission:
|
|
1947
|
+
const { hasValidSession: a, sessionManager: l, hasPermission: h, hasAnyPermission: S, hasAllPermissions: k } = de();
|
|
1918
1948
|
if (!a())
|
|
1919
1949
|
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(tt, {}) });
|
|
1920
|
-
const
|
|
1921
|
-
if (!
|
|
1950
|
+
const T = l.getUser();
|
|
1951
|
+
if (!T)
|
|
1922
1952
|
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(tt, {}) });
|
|
1923
|
-
if (t && !Ht(
|
|
1924
|
-
return /* @__PURE__ */ s(rt, { userType:
|
|
1925
|
-
if (n && n.length > 0 && !(i ?
|
|
1926
|
-
const
|
|
1927
|
-
return /* @__PURE__ */ s(rt, { missingPermissions:
|
|
1953
|
+
if (t && !Ht(T.userType, t))
|
|
1954
|
+
return /* @__PURE__ */ s(rt, { userType: T.userType, minUserType: t });
|
|
1955
|
+
if (n && n.length > 0 && !(i ? k(n) : S(n))) {
|
|
1956
|
+
const d = n.filter((A) => !h(A)).map((A) => typeof A == "string" ? A : A.name);
|
|
1957
|
+
return /* @__PURE__ */ s(rt, { missingPermissions: d });
|
|
1928
1958
|
}
|
|
1929
1959
|
return /* @__PURE__ */ s(U, { children: r });
|
|
1930
1960
|
}
|
|
@@ -2024,7 +2054,7 @@ function $r({
|
|
|
2024
2054
|
requireAllPermissions: i = !1,
|
|
2025
2055
|
fallback: a
|
|
2026
2056
|
}) {
|
|
2027
|
-
const { hasValidSession: l, sessionManager:
|
|
2057
|
+
const { hasValidSession: l, sessionManager: h, hasPermission: S, hasAnyPermission: k, hasAllPermissions: T } = de(), c = xe();
|
|
2028
2058
|
if (re(() => {
|
|
2029
2059
|
process.env.NODE_ENV === "development" && console.warn(
|
|
2030
2060
|
"[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
|
|
@@ -2032,21 +2062,21 @@ function $r({
|
|
|
2032
2062
|
}, []), !l())
|
|
2033
2063
|
return a ? /* @__PURE__ */ s(U, { children: a }) : /* @__PURE__ */ f(U, { children: [
|
|
2034
2064
|
/* @__PURE__ */ s(Qt, { redirectPath: e }),
|
|
2035
|
-
/* @__PURE__ */ s(we, { to: e, state: { from:
|
|
2065
|
+
/* @__PURE__ */ s(we, { to: e, state: { from: c.pathname }, replace: !0 })
|
|
2036
2066
|
] });
|
|
2037
|
-
const
|
|
2038
|
-
if (!
|
|
2039
|
-
return /* @__PURE__ */ s(we, { to: e, state: { from:
|
|
2040
|
-
if (t && !Jt(
|
|
2067
|
+
const d = h.getUser();
|
|
2068
|
+
if (!d)
|
|
2069
|
+
return /* @__PURE__ */ s(we, { to: e, state: { from: c.pathname }, replace: !0 });
|
|
2070
|
+
if (t && !Jt(d.userType, t))
|
|
2041
2071
|
return /* @__PURE__ */ s(
|
|
2042
2072
|
nt,
|
|
2043
2073
|
{
|
|
2044
|
-
userType:
|
|
2074
|
+
userType: d.userType,
|
|
2045
2075
|
requiredUserType: t
|
|
2046
2076
|
}
|
|
2047
2077
|
);
|
|
2048
|
-
if (n && n.length > 0 && !(i ?
|
|
2049
|
-
const P = n.filter((I) => !
|
|
2078
|
+
if (n && n.length > 0 && !(i ? T(n) : k(n))) {
|
|
2079
|
+
const P = n.filter((I) => !S(I)).map((I) => typeof I == "string" ? I : I.name);
|
|
2050
2080
|
return /* @__PURE__ */ s(nt, { missingPermissions: P });
|
|
2051
2081
|
}
|
|
2052
2082
|
return /* @__PURE__ */ s(U, { children: r });
|
|
@@ -2178,13 +2208,13 @@ const ue = ({
|
|
|
2178
2208
|
userType: i,
|
|
2179
2209
|
requiredPermissions: a,
|
|
2180
2210
|
requireAllPermissions: l = !0,
|
|
2181
|
-
returnTo:
|
|
2182
|
-
onAccessDenied:
|
|
2183
|
-
redirectTo:
|
|
2184
|
-
loadingFallback:
|
|
2185
|
-
accessDeniedFallback:
|
|
2211
|
+
returnTo: h,
|
|
2212
|
+
onAccessDenied: S,
|
|
2213
|
+
redirectTo: k,
|
|
2214
|
+
loadingFallback: T,
|
|
2215
|
+
accessDeniedFallback: c
|
|
2186
2216
|
}) => {
|
|
2187
|
-
const
|
|
2217
|
+
const d = xe(), { isAuthenticated: A, isAuthInitializing: P, currentUser: I, userPermissions: R } = de(), { tenant: E, isTenantLoading: m } = Te(), g = Gt(), b = V(() => {
|
|
2188
2218
|
if (e)
|
|
2189
2219
|
return g.presets[e];
|
|
2190
2220
|
}, [e, g.presets]), C = V(
|
|
@@ -2198,21 +2228,21 @@ const ue = ({
|
|
|
2198
2228
|
[t, n, i, a, b, l]
|
|
2199
2229
|
), o = V(
|
|
2200
2230
|
() => ({
|
|
2201
|
-
hasTenant: !!
|
|
2202
|
-
isAuthenticated:
|
|
2231
|
+
hasTenant: !!E,
|
|
2232
|
+
isAuthenticated: A,
|
|
2203
2233
|
userType: I == null ? void 0 : I.userType,
|
|
2204
2234
|
permissions: R,
|
|
2205
2235
|
isLoading: P || m
|
|
2206
2236
|
}),
|
|
2207
2237
|
[
|
|
2208
|
-
|
|
2209
|
-
|
|
2238
|
+
E,
|
|
2239
|
+
A,
|
|
2210
2240
|
I == null ? void 0 : I.userType,
|
|
2211
2241
|
R,
|
|
2212
2242
|
P,
|
|
2213
2243
|
m
|
|
2214
2244
|
]
|
|
2215
|
-
), p = V(() => o.isLoading ? null : Xt(C, o), [C, o]),
|
|
2245
|
+
), p = V(() => o.isLoading ? null : Xt(C, o), [C, o]), x = V(() => p ? k || er(o, g.zoneRoots) : null, [p, k, o, g.zoneRoots]), y = V(() => !p || !x ? null : {
|
|
2216
2246
|
type: p,
|
|
2217
2247
|
required: {
|
|
2218
2248
|
tenant: C.tenant,
|
|
@@ -2226,28 +2256,28 @@ const ue = ({
|
|
|
2226
2256
|
userType: o.userType,
|
|
2227
2257
|
permissions: o.permissions
|
|
2228
2258
|
},
|
|
2229
|
-
redirectTo:
|
|
2230
|
-
}, [p,
|
|
2259
|
+
redirectTo: x
|
|
2260
|
+
}, [p, x, C, o]);
|
|
2231
2261
|
if (re(() => {
|
|
2232
|
-
y && (
|
|
2233
|
-
}, [y,
|
|
2234
|
-
y &&
|
|
2262
|
+
y && (S ? S(y) : g.onAccessDenied && g.onAccessDenied(y));
|
|
2263
|
+
}, [y, S, g]), re(() => {
|
|
2264
|
+
y && h && rr(h, d.pathname + d.search, g.returnToStorage);
|
|
2235
2265
|
}, [
|
|
2236
2266
|
y,
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2267
|
+
h,
|
|
2268
|
+
d.pathname,
|
|
2269
|
+
d.search,
|
|
2240
2270
|
g.returnToStorage
|
|
2241
2271
|
]), o.isLoading)
|
|
2242
|
-
return /* @__PURE__ */ s(U, { children:
|
|
2243
|
-
if (y &&
|
|
2244
|
-
const u =
|
|
2272
|
+
return /* @__PURE__ */ s(U, { children: T ?? g.loadingFallback ?? null });
|
|
2273
|
+
if (y && x) {
|
|
2274
|
+
const u = c ?? g.accessDeniedFallback;
|
|
2245
2275
|
if (u)
|
|
2246
2276
|
return /* @__PURE__ */ s(U, { children: u });
|
|
2247
2277
|
const v = tr(
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2278
|
+
x,
|
|
2279
|
+
h,
|
|
2280
|
+
d.pathname + d.search,
|
|
2251
2281
|
g.returnToParam,
|
|
2252
2282
|
g.returnToStorage
|
|
2253
2283
|
);
|
|
@@ -2277,8 +2307,8 @@ function Jr({
|
|
|
2277
2307
|
allowedPlans: t,
|
|
2278
2308
|
requiredFeature: n
|
|
2279
2309
|
}) {
|
|
2280
|
-
const { subscription: i, hasAllowedPlan: a, isFeatureEnabled: l, loading:
|
|
2281
|
-
return
|
|
2310
|
+
const { subscription: i, hasAllowedPlan: a, isFeatureEnabled: l, loading: h } = jt();
|
|
2311
|
+
return h ? /* @__PURE__ */ s(
|
|
2282
2312
|
"div",
|
|
2283
2313
|
{
|
|
2284
2314
|
style: {
|
|
@@ -2335,29 +2365,29 @@ function Zr({ name: r, children: e, fallback: t }) {
|
|
|
2335
2365
|
) : n(r) ? /* @__PURE__ */ s(U, { children: e }) : /* @__PURE__ */ s(U, { children: t || /* @__PURE__ */ s(sr, { flagName: r }) });
|
|
2336
2366
|
}
|
|
2337
2367
|
function ve(r) {
|
|
2338
|
-
const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError: a } = r, [l,
|
|
2339
|
-
|
|
2340
|
-
}, []),
|
|
2341
|
-
|
|
2342
|
-
if (!
|
|
2343
|
-
const m = { ...
|
|
2368
|
+
const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError: a } = r, [l, h] = N(!1), [S, k] = N(""), [T, c] = N({}), d = te((R, E) => {
|
|
2369
|
+
c((m) => ({ ...m, [R]: E }));
|
|
2370
|
+
}, []), A = te((R) => {
|
|
2371
|
+
c((E) => {
|
|
2372
|
+
if (!E[R]) return E;
|
|
2373
|
+
const m = { ...E };
|
|
2344
2374
|
return delete m[R], m;
|
|
2345
2375
|
});
|
|
2346
2376
|
}, []), P = te(() => {
|
|
2347
|
-
|
|
2377
|
+
k(""), c({});
|
|
2348
2378
|
}, []), I = te(
|
|
2349
2379
|
async (R) => {
|
|
2350
2380
|
if (R && R.preventDefault(), !(n && !n())) {
|
|
2351
|
-
|
|
2381
|
+
h(!0), k("");
|
|
2352
2382
|
try {
|
|
2353
|
-
const
|
|
2354
|
-
return i == null || i(
|
|
2355
|
-
} catch (
|
|
2356
|
-
const m =
|
|
2357
|
-
|
|
2383
|
+
const E = await e();
|
|
2384
|
+
return i == null || i(E), E;
|
|
2385
|
+
} catch (E) {
|
|
2386
|
+
const m = E instanceof Error ? E.message : t;
|
|
2387
|
+
k(m), a == null || a(m);
|
|
2358
2388
|
return;
|
|
2359
2389
|
} finally {
|
|
2360
|
-
|
|
2390
|
+
h(!1);
|
|
2361
2391
|
}
|
|
2362
2392
|
}
|
|
2363
2393
|
},
|
|
@@ -2365,11 +2395,11 @@ function ve(r) {
|
|
|
2365
2395
|
);
|
|
2366
2396
|
return {
|
|
2367
2397
|
loading: l,
|
|
2368
|
-
error:
|
|
2369
|
-
setError:
|
|
2370
|
-
fieldErrors:
|
|
2371
|
-
setFieldError:
|
|
2372
|
-
clearFieldError:
|
|
2398
|
+
error: S,
|
|
2399
|
+
setError: k,
|
|
2400
|
+
fieldErrors: T,
|
|
2401
|
+
setFieldError: d,
|
|
2402
|
+
clearFieldError: A,
|
|
2373
2403
|
resetErrors: P,
|
|
2374
2404
|
handleSubmit: I
|
|
2375
2405
|
};
|
|
@@ -2611,30 +2641,30 @@ function Kr({
|
|
|
2611
2641
|
onError: i,
|
|
2612
2642
|
onForgotPassword: a,
|
|
2613
2643
|
onSignupClick: l,
|
|
2614
|
-
onMagicLinkClick:
|
|
2615
|
-
showForgotPassword:
|
|
2616
|
-
showSignupLink:
|
|
2617
|
-
showMagicLinkOption:
|
|
2618
|
-
className:
|
|
2644
|
+
onMagicLinkClick: h,
|
|
2645
|
+
showForgotPassword: S = !0,
|
|
2646
|
+
showSignupLink: k = !0,
|
|
2647
|
+
showMagicLinkOption: T = !0,
|
|
2648
|
+
className: c
|
|
2619
2649
|
}) {
|
|
2620
|
-
const [
|
|
2650
|
+
const [d, A] = N(""), [P, I] = N(""), [R, E] = N(!1), { login: m } = de(), g = { ...lr, ...r }, b = Le("#3b82f6", e), C = { ...ar, ...t }, o = ve({
|
|
2621
2651
|
defaultErrorMessage: g.errorMessage,
|
|
2622
2652
|
validate: () => {
|
|
2623
2653
|
const u = [];
|
|
2624
|
-
return
|
|
2654
|
+
return d.trim() || u.push("username"), P.trim() || u.push("password"), u.forEach((v) => o.setFieldError(v, !0)), u.length === 0;
|
|
2625
2655
|
},
|
|
2626
|
-
submit: () => m({ username:
|
|
2656
|
+
submit: () => m({ username: d, password: P }),
|
|
2627
2657
|
onSuccess: n,
|
|
2628
2658
|
onError: i
|
|
2629
2659
|
}), p = (u) => ({
|
|
2630
2660
|
...b.input,
|
|
2631
2661
|
...o.fieldErrors[u] ? b.inputError : {}
|
|
2632
|
-
}),
|
|
2662
|
+
}), x = !d || !P || o.loading, y = {
|
|
2633
2663
|
...b.button,
|
|
2634
2664
|
...o.loading ? b.buttonLoading : {},
|
|
2635
|
-
...
|
|
2665
|
+
...x ? b.buttonDisabled : {}
|
|
2636
2666
|
};
|
|
2637
|
-
return /* @__PURE__ */ f("div", { className:
|
|
2667
|
+
return /* @__PURE__ */ f("div", { className: c, style: b.container, children: [
|
|
2638
2668
|
/* @__PURE__ */ s("h2", { style: b.title, children: g.title }),
|
|
2639
2669
|
/* @__PURE__ */ f("form", { onSubmit: o.handleSubmit, style: b.form, children: [
|
|
2640
2670
|
/* @__PURE__ */ f("div", { style: b.fieldGroup, children: [
|
|
@@ -2645,9 +2675,9 @@ function Kr({
|
|
|
2645
2675
|
id: "username",
|
|
2646
2676
|
name: "username",
|
|
2647
2677
|
type: "text",
|
|
2648
|
-
value:
|
|
2678
|
+
value: d,
|
|
2649
2679
|
onChange: (u) => {
|
|
2650
|
-
|
|
2680
|
+
A(u.target.value), o.clearFieldError("username");
|
|
2651
2681
|
},
|
|
2652
2682
|
placeholder: g.usernamePlaceholder,
|
|
2653
2683
|
style: p("username"),
|
|
@@ -2677,7 +2707,7 @@ function Kr({
|
|
|
2677
2707
|
"button",
|
|
2678
2708
|
{
|
|
2679
2709
|
type: "button",
|
|
2680
|
-
onClick: () =>
|
|
2710
|
+
onClick: () => E(!R),
|
|
2681
2711
|
style: b.passwordToggle,
|
|
2682
2712
|
disabled: o.loading,
|
|
2683
2713
|
"aria-label": R ? g.hidePasswordAriaLabel : g.showPasswordAriaLabel,
|
|
@@ -2686,21 +2716,21 @@ function Kr({
|
|
|
2686
2716
|
)
|
|
2687
2717
|
] })
|
|
2688
2718
|
] }),
|
|
2689
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled:
|
|
2719
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: x, style: y, children: o.loading ? g.loadingText : g.submitButton }),
|
|
2690
2720
|
o.error && /* @__PURE__ */ s("div", { style: b.errorText, children: o.error })
|
|
2691
2721
|
] }),
|
|
2692
|
-
(
|
|
2693
|
-
|
|
2722
|
+
(S || k || T) && /* @__PURE__ */ f("div", { style: b.linkContainer, children: [
|
|
2723
|
+
T && /* @__PURE__ */ f("div", { children: [
|
|
2694
2724
|
/* @__PURE__ */ f("span", { style: b.divider, children: [
|
|
2695
2725
|
g.magicLinkText,
|
|
2696
2726
|
" "
|
|
2697
2727
|
] }),
|
|
2698
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
2728
|
+
/* @__PURE__ */ s("a", { onClick: h, style: b.link, children: g.magicLinkLink })
|
|
2699
2729
|
] }),
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2730
|
+
T && (S || k) && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
|
|
2731
|
+
S && /* @__PURE__ */ s("a", { onClick: a, style: b.link, children: g.forgotPasswordLink }),
|
|
2732
|
+
S && k && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
|
|
2733
|
+
k && /* @__PURE__ */ f("div", { children: [
|
|
2704
2734
|
/* @__PURE__ */ f("span", { style: b.divider, children: [
|
|
2705
2735
|
g.signupText,
|
|
2706
2736
|
" "
|
|
@@ -2748,45 +2778,45 @@ function Yr({
|
|
|
2748
2778
|
onError: i,
|
|
2749
2779
|
onLoginClick: a,
|
|
2750
2780
|
onMagicLinkClick: l,
|
|
2751
|
-
showLoginLink:
|
|
2752
|
-
showMagicLinkOption:
|
|
2753
|
-
className:
|
|
2781
|
+
showLoginLink: h = !0,
|
|
2782
|
+
showMagicLinkOption: S = !0,
|
|
2783
|
+
className: k
|
|
2754
2784
|
}) {
|
|
2755
2785
|
var B;
|
|
2756
|
-
const [
|
|
2786
|
+
const [T, c] = N(""), [d, A] = N(""), [P, I] = N(""), [R, E] = N(""), [m, g] = N(""), [b, C] = N(""), [o, p] = N(""), { signup: x, signupTenantAdmin: y } = de(), u = ((B = pe()) == null ? void 0 : B.tenant) ?? null, v = { ...cr, ...r }, D = Le("#10b981", e), se = !!T && (!!P || !!R) && !!m && !!b && (t === "user" || !!o), F = ve({
|
|
2757
2787
|
defaultErrorMessage: v.errorMessage,
|
|
2758
2788
|
validate: () => {
|
|
2759
2789
|
const L = [];
|
|
2760
|
-
return
|
|
2790
|
+
return T.trim() || L.push("name"), !P.trim() && !R.trim() && (L.push("email"), L.push("phoneNumber")), m.trim() || L.push("password"), b.trim() || L.push("confirmPassword"), t === "tenant" && !o.trim() && L.push("tenantName"), L.forEach((q) => F.setFieldError(q, !0)), L.length > 0 ? !1 : m !== b ? (F.setError(v.passwordMismatchError), F.setFieldError("confirmPassword", !0), !1) : t === "user" && !(u != null && u.id) ? (F.setError(v.tenantNotFoundError), !1) : !0;
|
|
2761
2791
|
},
|
|
2762
2792
|
submit: async () => t === "tenant" ? y({
|
|
2763
2793
|
email: P || void 0,
|
|
2764
2794
|
phoneNumber: R || void 0,
|
|
2765
|
-
name:
|
|
2795
|
+
name: T,
|
|
2766
2796
|
password: m,
|
|
2767
2797
|
tenantName: o,
|
|
2768
|
-
lastName:
|
|
2769
|
-
}) :
|
|
2798
|
+
lastName: d || void 0
|
|
2799
|
+
}) : x({
|
|
2770
2800
|
email: P || void 0,
|
|
2771
2801
|
phoneNumber: R || void 0,
|
|
2772
|
-
name:
|
|
2802
|
+
name: T,
|
|
2773
2803
|
password: m,
|
|
2774
2804
|
tenantId: u.id,
|
|
2775
|
-
lastName:
|
|
2805
|
+
lastName: d || void 0
|
|
2776
2806
|
}),
|
|
2777
2807
|
onSuccess: n,
|
|
2778
2808
|
onError: i
|
|
2779
2809
|
}), H = (L) => ({
|
|
2780
2810
|
...D.input,
|
|
2781
2811
|
...F.fieldErrors[L] ? D.inputError : {}
|
|
2782
|
-
}), j = !se || F.loading,
|
|
2812
|
+
}), j = !se || F.loading, K = {
|
|
2783
2813
|
...D.button,
|
|
2784
2814
|
...F.loading ? D.buttonLoading : {},
|
|
2785
2815
|
...j ? D.buttonDisabled : {}
|
|
2786
2816
|
}, $ = () => {
|
|
2787
2817
|
F.clearFieldError("email"), F.clearFieldError("phoneNumber");
|
|
2788
2818
|
};
|
|
2789
|
-
return /* @__PURE__ */ f("div", { className:
|
|
2819
|
+
return /* @__PURE__ */ f("div", { className: k, style: D.container, children: [
|
|
2790
2820
|
/* @__PURE__ */ s("h2", { style: D.title, children: v.title }),
|
|
2791
2821
|
/* @__PURE__ */ f("form", { onSubmit: F.handleSubmit, style: D.form, children: [
|
|
2792
2822
|
/* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
|
|
@@ -2797,9 +2827,9 @@ function Yr({
|
|
|
2797
2827
|
id: "name",
|
|
2798
2828
|
name: "name",
|
|
2799
2829
|
type: "text",
|
|
2800
|
-
value:
|
|
2830
|
+
value: T,
|
|
2801
2831
|
onChange: (L) => {
|
|
2802
|
-
|
|
2832
|
+
c(L.target.value), F.clearFieldError("name");
|
|
2803
2833
|
},
|
|
2804
2834
|
placeholder: v.namePlaceholder,
|
|
2805
2835
|
style: H("name"),
|
|
@@ -2815,8 +2845,8 @@ function Yr({
|
|
|
2815
2845
|
id: "lastName",
|
|
2816
2846
|
name: "lastName",
|
|
2817
2847
|
type: "text",
|
|
2818
|
-
value:
|
|
2819
|
-
onChange: (L) =>
|
|
2848
|
+
value: d,
|
|
2849
|
+
onChange: (L) => A(L.target.value),
|
|
2820
2850
|
placeholder: v.lastNamePlaceholder,
|
|
2821
2851
|
style: D.input,
|
|
2822
2852
|
disabled: F.loading
|
|
@@ -2851,7 +2881,7 @@ function Yr({
|
|
|
2851
2881
|
type: "tel",
|
|
2852
2882
|
value: R,
|
|
2853
2883
|
onChange: (L) => {
|
|
2854
|
-
|
|
2884
|
+
E(L.target.value), $();
|
|
2855
2885
|
},
|
|
2856
2886
|
placeholder: v.phoneNumberPlaceholder,
|
|
2857
2887
|
style: H("phoneNumber"),
|
|
@@ -2914,19 +2944,19 @@ function Yr({
|
|
|
2914
2944
|
}
|
|
2915
2945
|
)
|
|
2916
2946
|
] }),
|
|
2917
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled: j, style:
|
|
2947
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: j, style: K, children: F.loading ? v.loadingText : v.submitButton }),
|
|
2918
2948
|
F.error && /* @__PURE__ */ s("div", { style: D.errorText, children: F.error })
|
|
2919
2949
|
] }),
|
|
2920
|
-
(
|
|
2921
|
-
|
|
2950
|
+
(h || S) && /* @__PURE__ */ f("div", { style: D.linkContainer, children: [
|
|
2951
|
+
S && /* @__PURE__ */ f("div", { children: [
|
|
2922
2952
|
/* @__PURE__ */ f("span", { style: D.divider, children: [
|
|
2923
2953
|
v.magicLinkText,
|
|
2924
2954
|
" "
|
|
2925
2955
|
] }),
|
|
2926
2956
|
/* @__PURE__ */ s("a", { onClick: l, style: D.link, children: v.magicLinkLink })
|
|
2927
2957
|
] }),
|
|
2928
|
-
|
|
2929
|
-
|
|
2958
|
+
S && h && /* @__PURE__ */ s("div", { style: D.divider, children: v.dividerBullet }),
|
|
2959
|
+
h && /* @__PURE__ */ f("div", { children: [
|
|
2930
2960
|
/* @__PURE__ */ f("span", { style: D.divider, children: [
|
|
2931
2961
|
v.loginText,
|
|
2932
2962
|
" "
|
|
@@ -2969,62 +2999,62 @@ function Xr({
|
|
|
2969
2999
|
onLoginClick: i,
|
|
2970
3000
|
onSignupClick: a,
|
|
2971
3001
|
showTraditionalLinks: l = !0,
|
|
2972
|
-
className:
|
|
2973
|
-
verifyToken:
|
|
2974
|
-
frontendUrl:
|
|
3002
|
+
className: h,
|
|
3003
|
+
verifyToken: S,
|
|
3004
|
+
frontendUrl: k
|
|
2975
3005
|
}) {
|
|
2976
3006
|
var H;
|
|
2977
|
-
const [
|
|
3007
|
+
const [T, c] = N(""), [d, A] = N(""), [P, I] = N(""), [R, E] = N(!1), [m, g] = N(""), [b, C] = N(!1), { sendMagicLink: o, verifyMagicLink: p } = de(), x = ((H = pe()) == null ? void 0 : H.tenant) ?? null, y = { ...ur, ...r }, u = Le("#3b82f6", e), v = ve({
|
|
2978
3008
|
defaultErrorMessage: y.errorMessage,
|
|
2979
3009
|
validate: () => {
|
|
2980
3010
|
const j = [];
|
|
2981
|
-
return
|
|
3011
|
+
return T.trim() || j.push("email"), b && !d.trim() && j.push("name"), j.forEach((K) => v.setFieldError(K, !0)), j.length > 0 ? !1 : x != null && x.id ? !0 : (v.setError(y.tenantNotFoundError), !1);
|
|
2982
3012
|
},
|
|
2983
3013
|
submit: async () => {
|
|
2984
3014
|
g("");
|
|
2985
|
-
const j =
|
|
2986
|
-
email:
|
|
2987
|
-
tenantId:
|
|
3015
|
+
const j = k || (typeof window < "u" ? window.location.origin : ""), K = await o({
|
|
3016
|
+
email: T,
|
|
3017
|
+
tenantId: x.id,
|
|
2988
3018
|
frontendUrl: j,
|
|
2989
|
-
name: b ?
|
|
3019
|
+
name: b ? d : void 0,
|
|
2990
3020
|
lastName: b ? P : void 0
|
|
2991
3021
|
});
|
|
2992
|
-
return g(y.successMessage),
|
|
3022
|
+
return g(y.successMessage), K;
|
|
2993
3023
|
},
|
|
2994
3024
|
onSuccess: t,
|
|
2995
3025
|
onError: n
|
|
2996
3026
|
});
|
|
2997
3027
|
re(() => {
|
|
2998
|
-
if (!
|
|
3028
|
+
if (!S) return;
|
|
2999
3029
|
(async () => {
|
|
3000
|
-
if (!
|
|
3030
|
+
if (!x || !T) {
|
|
3001
3031
|
v.setError(y.missingTenantOrEmailError);
|
|
3002
3032
|
return;
|
|
3003
3033
|
}
|
|
3004
|
-
|
|
3034
|
+
E(!0), v.setError("");
|
|
3005
3035
|
try {
|
|
3006
|
-
const
|
|
3007
|
-
t == null || t(
|
|
3008
|
-
} catch (
|
|
3009
|
-
const $ =
|
|
3036
|
+
const K = await p({ token: S, email: T });
|
|
3037
|
+
t == null || t(K);
|
|
3038
|
+
} catch (K) {
|
|
3039
|
+
const $ = K instanceof Error ? K.message : "Failed to verify magic link";
|
|
3010
3040
|
v.setError($), n == null || n($);
|
|
3011
3041
|
} finally {
|
|
3012
|
-
|
|
3042
|
+
E(!1);
|
|
3013
3043
|
}
|
|
3014
3044
|
})();
|
|
3015
|
-
}, [
|
|
3045
|
+
}, [S]);
|
|
3016
3046
|
const D = (j) => ({
|
|
3017
3047
|
...u.input,
|
|
3018
3048
|
...v.fieldErrors[j] ? u.inputError : {}
|
|
3019
|
-
}), se = !
|
|
3049
|
+
}), se = !T || v.loading || R, F = {
|
|
3020
3050
|
...u.button,
|
|
3021
3051
|
...v.loading || R ? u.buttonLoading : {},
|
|
3022
3052
|
...se ? u.buttonDisabled : {}
|
|
3023
3053
|
};
|
|
3024
|
-
return R ? /* @__PURE__ */ f("div", { className:
|
|
3054
|
+
return R ? /* @__PURE__ */ f("div", { className: h, style: u.container, children: [
|
|
3025
3055
|
/* @__PURE__ */ s("h2", { style: u.title, children: y.verifyingText }),
|
|
3026
3056
|
/* @__PURE__ */ s("div", { style: u.verifyingContainer, children: /* @__PURE__ */ s("div", { style: u.verifyingText, children: y.verifyingDescription }) })
|
|
3027
|
-
] }) : /* @__PURE__ */ f("div", { className:
|
|
3057
|
+
] }) : /* @__PURE__ */ f("div", { className: h, style: u.container, children: [
|
|
3028
3058
|
/* @__PURE__ */ s("h2", { style: u.title, children: y.title }),
|
|
3029
3059
|
/* @__PURE__ */ s("p", { style: u.description, children: y.description }),
|
|
3030
3060
|
/* @__PURE__ */ f("form", { onSubmit: v.handleSubmit, style: u.form, children: [
|
|
@@ -3036,9 +3066,9 @@ function Xr({
|
|
|
3036
3066
|
id: "email",
|
|
3037
3067
|
name: "email",
|
|
3038
3068
|
type: "email",
|
|
3039
|
-
value:
|
|
3069
|
+
value: T,
|
|
3040
3070
|
onChange: (j) => {
|
|
3041
|
-
|
|
3071
|
+
c(j.target.value), v.clearFieldError("email");
|
|
3042
3072
|
},
|
|
3043
3073
|
placeholder: y.emailPlaceholder,
|
|
3044
3074
|
style: D("email"),
|
|
@@ -3064,9 +3094,9 @@ function Xr({
|
|
|
3064
3094
|
id: "name",
|
|
3065
3095
|
name: "name",
|
|
3066
3096
|
type: "text",
|
|
3067
|
-
value:
|
|
3097
|
+
value: d,
|
|
3068
3098
|
onChange: (j) => {
|
|
3069
|
-
|
|
3099
|
+
A(j.target.value), v.clearFieldError("name");
|
|
3070
3100
|
},
|
|
3071
3101
|
placeholder: y.namePlaceholder,
|
|
3072
3102
|
style: D("name"),
|
|
@@ -3095,7 +3125,7 @@ function Xr({
|
|
|
3095
3125
|
{
|
|
3096
3126
|
type: "button",
|
|
3097
3127
|
onClick: () => {
|
|
3098
|
-
C(!1),
|
|
3128
|
+
C(!1), A(""), I("");
|
|
3099
3129
|
},
|
|
3100
3130
|
style: u.toggleLink,
|
|
3101
3131
|
children: y.hideNameToggle
|
|
@@ -3275,21 +3305,21 @@ function en({
|
|
|
3275
3305
|
onError: i,
|
|
3276
3306
|
onRetry: a,
|
|
3277
3307
|
onBackToLogin: l,
|
|
3278
|
-
className:
|
|
3279
|
-
token:
|
|
3280
|
-
email:
|
|
3281
|
-
appId:
|
|
3282
|
-
tenantSlug:
|
|
3283
|
-
autoRedirectDelay:
|
|
3308
|
+
className: h,
|
|
3309
|
+
token: S,
|
|
3310
|
+
email: k,
|
|
3311
|
+
appId: T,
|
|
3312
|
+
tenantSlug: c,
|
|
3313
|
+
autoRedirectDelay: d = 3e3
|
|
3284
3314
|
}) {
|
|
3285
|
-
const [
|
|
3315
|
+
const [A, P] = N("verifying"), [I, R] = N(""), { verifyMagicLink: E } = de(), m = { ...dr, ...r }, g = { ...ut, ...e }, b = { ...mr, ...t }, C = () => {
|
|
3286
3316
|
if (typeof window > "u") return {};
|
|
3287
3317
|
const u = new URLSearchParams(window.location.search);
|
|
3288
3318
|
return {
|
|
3289
|
-
token:
|
|
3290
|
-
email:
|
|
3291
|
-
appId:
|
|
3292
|
-
tenantSlug:
|
|
3319
|
+
token: S || u.get("token") || "",
|
|
3320
|
+
email: k || u.get("email") || "",
|
|
3321
|
+
appId: T || u.get("appId") || "",
|
|
3322
|
+
tenantSlug: c || u.get("tenantSlug") || void 0
|
|
3293
3323
|
};
|
|
3294
3324
|
}, o = async () => {
|
|
3295
3325
|
P("verifying"), R("");
|
|
@@ -3297,28 +3327,28 @@ function en({
|
|
|
3297
3327
|
const u = C();
|
|
3298
3328
|
if (!u.token || !u.email)
|
|
3299
3329
|
throw new Error(m.missingParamsError);
|
|
3300
|
-
const v = await
|
|
3330
|
+
const v = await E({
|
|
3301
3331
|
token: u.token,
|
|
3302
3332
|
email: u.email,
|
|
3303
3333
|
tenantSlug: u.tenantSlug
|
|
3304
3334
|
});
|
|
3305
|
-
P("success"), n == null || n(v),
|
|
3335
|
+
P("success"), n == null || n(v), d > 0 && setTimeout(() => {
|
|
3306
3336
|
P("redirecting");
|
|
3307
|
-
},
|
|
3337
|
+
}, d);
|
|
3308
3338
|
} catch (u) {
|
|
3309
3339
|
const v = u.message || m.errorMessage;
|
|
3310
3340
|
R(v), P("error"), i == null || i(v);
|
|
3311
3341
|
}
|
|
3312
3342
|
}, p = () => {
|
|
3313
3343
|
a == null || a(), o();
|
|
3314
|
-
},
|
|
3344
|
+
}, x = () => {
|
|
3315
3345
|
l == null || l();
|
|
3316
3346
|
};
|
|
3317
3347
|
re(() => {
|
|
3318
3348
|
o();
|
|
3319
3349
|
}, []);
|
|
3320
3350
|
const y = () => {
|
|
3321
|
-
switch (
|
|
3351
|
+
switch (A) {
|
|
3322
3352
|
case "verifying":
|
|
3323
3353
|
return /* @__PURE__ */ f("div", { style: g.message, children: [
|
|
3324
3354
|
b.loading,
|
|
@@ -3359,7 +3389,7 @@ function en({
|
|
|
3359
3389
|
/* @__PURE__ */ s(
|
|
3360
3390
|
"button",
|
|
3361
3391
|
{
|
|
3362
|
-
onClick:
|
|
3392
|
+
onClick: x,
|
|
3363
3393
|
style: g.backButton,
|
|
3364
3394
|
onMouseOver: (u) => {
|
|
3365
3395
|
Object.assign(u.currentTarget.style, g.backButtonHover);
|
|
@@ -3379,7 +3409,7 @@ function en({
|
|
|
3379
3409
|
return null;
|
|
3380
3410
|
}
|
|
3381
3411
|
};
|
|
3382
|
-
return /* @__PURE__ */ f("div", { style: g.container, className:
|
|
3412
|
+
return /* @__PURE__ */ f("div", { style: g.container, className: h, children: [
|
|
3383
3413
|
/* @__PURE__ */ s("style", { children: `
|
|
3384
3414
|
@keyframes spin {
|
|
3385
3415
|
0% { transform: rotate(0deg); }
|
|
@@ -3425,15 +3455,15 @@ function tn({
|
|
|
3425
3455
|
onSuccess: i,
|
|
3426
3456
|
onError: a,
|
|
3427
3457
|
onBackToLogin: l,
|
|
3428
|
-
onModeChange:
|
|
3429
|
-
className:
|
|
3458
|
+
onModeChange: h,
|
|
3459
|
+
className: S
|
|
3430
3460
|
}) {
|
|
3431
3461
|
var se;
|
|
3432
|
-
const [
|
|
3462
|
+
const [k, T] = N(""), [c, d] = N(n), [A, P] = N(""), [I, R] = N(""), [E, m] = N(""), { requestPasswordReset: g, confirmPasswordReset: b } = de(), C = ((se = pe()) == null ? void 0 : se.tenant) ?? null, o = { ...gr, ...r }, p = Le("#f59e0b", e), x = ve({
|
|
3433
3463
|
defaultErrorMessage: o.errorMessage,
|
|
3434
|
-
validate: () =>
|
|
3464
|
+
validate: () => k.trim() ? C != null && C.id ? !0 : (x.setError(o.tenantNotFoundError), !1) : (x.setFieldError("email", !0), !1),
|
|
3435
3465
|
submit: async () => {
|
|
3436
|
-
m(""), await g({ email:
|
|
3466
|
+
m(""), await g({ email: k, tenantId: C.id }), m(o.successMessage);
|
|
3437
3467
|
},
|
|
3438
3468
|
onSuccess: () => i == null ? void 0 : i(),
|
|
3439
3469
|
onError: a
|
|
@@ -3441,10 +3471,10 @@ function tn({
|
|
|
3441
3471
|
defaultErrorMessage: o.errorMessage,
|
|
3442
3472
|
validate: () => {
|
|
3443
3473
|
const F = [];
|
|
3444
|
-
return
|
|
3474
|
+
return c.trim() || F.push("token"), A.trim() || F.push("newPassword"), I.trim() || F.push("confirmPassword"), F.forEach((H) => y.setFieldError(H, !0)), F.length > 0 ? !1 : A !== I ? (y.setError(o.passwordMismatchError), y.setFieldError("confirmPassword", !0), !1) : !0;
|
|
3445
3475
|
},
|
|
3446
3476
|
submit: async () => {
|
|
3447
|
-
m(""), await b({ token:
|
|
3477
|
+
m(""), await b({ token: c, newPassword: A }), m(o.resetSuccessMessage);
|
|
3448
3478
|
},
|
|
3449
3479
|
onSuccess: () => i == null ? void 0 : i(),
|
|
3450
3480
|
onError: a
|
|
@@ -3453,12 +3483,12 @@ function tn({
|
|
|
3453
3483
|
const F = ($) => ({
|
|
3454
3484
|
...p.input,
|
|
3455
3485
|
...y.fieldErrors[$] ? p.inputError : {}
|
|
3456
|
-
}), j = !(!!
|
|
3486
|
+
}), j = !(!!c && !!A && !!I) || y.loading, K = {
|
|
3457
3487
|
...p.button,
|
|
3458
3488
|
...y.loading ? p.buttonLoading : {},
|
|
3459
3489
|
...j ? p.buttonDisabled : {}
|
|
3460
3490
|
};
|
|
3461
|
-
return /* @__PURE__ */ f("div", { className:
|
|
3491
|
+
return /* @__PURE__ */ f("div", { className: S, style: p.container, children: [
|
|
3462
3492
|
/* @__PURE__ */ s("h2", { style: p.title, children: o.resetTitle }),
|
|
3463
3493
|
/* @__PURE__ */ s("p", { style: p.subtitle, children: o.resetSubtitle }),
|
|
3464
3494
|
/* @__PURE__ */ f("form", { onSubmit: y.handleSubmit, style: p.form, children: [
|
|
@@ -3468,9 +3498,9 @@ function tn({
|
|
|
3468
3498
|
"input",
|
|
3469
3499
|
{
|
|
3470
3500
|
type: "text",
|
|
3471
|
-
value:
|
|
3501
|
+
value: c,
|
|
3472
3502
|
onChange: ($) => {
|
|
3473
|
-
|
|
3503
|
+
d($.target.value), y.clearFieldError("token");
|
|
3474
3504
|
},
|
|
3475
3505
|
placeholder: o.tokenPlaceholder,
|
|
3476
3506
|
style: F("token"),
|
|
@@ -3484,7 +3514,7 @@ function tn({
|
|
|
3484
3514
|
"input",
|
|
3485
3515
|
{
|
|
3486
3516
|
type: "password",
|
|
3487
|
-
value:
|
|
3517
|
+
value: A,
|
|
3488
3518
|
onChange: ($) => {
|
|
3489
3519
|
P($.target.value), y.clearFieldError("newPassword");
|
|
3490
3520
|
},
|
|
@@ -3510,56 +3540,56 @@ function tn({
|
|
|
3510
3540
|
}
|
|
3511
3541
|
)
|
|
3512
3542
|
] }),
|
|
3513
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled: j, style:
|
|
3543
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: j, style: K, children: y.loading ? o.resetLoadingText : o.resetSubmitButton }),
|
|
3514
3544
|
y.error && /* @__PURE__ */ s("div", { style: p.errorText, children: y.error }),
|
|
3515
|
-
|
|
3545
|
+
E && /* @__PURE__ */ s("div", { style: p.successText, children: E })
|
|
3516
3546
|
] }),
|
|
3517
3547
|
/* @__PURE__ */ f("div", { style: p.linkContainer, children: [
|
|
3518
3548
|
/* @__PURE__ */ s("a", { onClick: l, style: p.link, children: o.backToLoginLink }),
|
|
3519
|
-
|
|
3549
|
+
h && /* @__PURE__ */ f(U, { children: [
|
|
3520
3550
|
/* @__PURE__ */ s("span", { style: p.modeSwitchDivider, children: o.dividerBullet }),
|
|
3521
|
-
/* @__PURE__ */ s("a", { onClick: () =>
|
|
3551
|
+
/* @__PURE__ */ s("a", { onClick: () => h("request"), style: p.link, children: o.requestNewLinkLink })
|
|
3522
3552
|
] })
|
|
3523
3553
|
] })
|
|
3524
3554
|
] });
|
|
3525
3555
|
}
|
|
3526
3556
|
const u = (F) => ({
|
|
3527
3557
|
...p.input,
|
|
3528
|
-
...
|
|
3529
|
-
}), v = !
|
|
3558
|
+
...x.fieldErrors[F] ? p.inputError : {}
|
|
3559
|
+
}), v = !k || x.loading, D = {
|
|
3530
3560
|
...p.button,
|
|
3531
|
-
...
|
|
3561
|
+
...x.loading ? p.buttonLoading : {},
|
|
3532
3562
|
...v ? p.buttonDisabled : {}
|
|
3533
3563
|
};
|
|
3534
|
-
return /* @__PURE__ */ f("div", { className:
|
|
3564
|
+
return /* @__PURE__ */ f("div", { className: S, style: p.container, children: [
|
|
3535
3565
|
/* @__PURE__ */ s("h2", { style: p.title, children: o.title }),
|
|
3536
3566
|
/* @__PURE__ */ s("p", { style: p.subtitle, children: o.subtitle }),
|
|
3537
|
-
/* @__PURE__ */ f("form", { onSubmit:
|
|
3567
|
+
/* @__PURE__ */ f("form", { onSubmit: x.handleSubmit, style: p.form, children: [
|
|
3538
3568
|
/* @__PURE__ */ f("div", { style: p.fieldGroup, children: [
|
|
3539
3569
|
/* @__PURE__ */ s("label", { style: p.label, children: o.emailLabel }),
|
|
3540
3570
|
/* @__PURE__ */ s(
|
|
3541
3571
|
"input",
|
|
3542
3572
|
{
|
|
3543
3573
|
type: "email",
|
|
3544
|
-
value:
|
|
3574
|
+
value: k,
|
|
3545
3575
|
onChange: (F) => {
|
|
3546
|
-
|
|
3576
|
+
T(F.target.value), x.clearFieldError("email");
|
|
3547
3577
|
},
|
|
3548
3578
|
placeholder: o.emailPlaceholder,
|
|
3549
3579
|
style: u("email"),
|
|
3550
|
-
disabled:
|
|
3580
|
+
disabled: x.loading
|
|
3551
3581
|
}
|
|
3552
3582
|
)
|
|
3553
3583
|
] }),
|
|
3554
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled: v, style: D, children:
|
|
3555
|
-
|
|
3556
|
-
|
|
3584
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: v, style: D, children: x.loading ? o.loadingText : o.submitButton }),
|
|
3585
|
+
x.error && /* @__PURE__ */ s("div", { style: p.errorText, children: x.error }),
|
|
3586
|
+
E && /* @__PURE__ */ s("div", { style: p.successText, children: E })
|
|
3557
3587
|
] }),
|
|
3558
3588
|
/* @__PURE__ */ f("div", { style: p.linkContainer, children: [
|
|
3559
3589
|
/* @__PURE__ */ s("a", { onClick: l, style: p.link, children: o.backToLoginLink }),
|
|
3560
|
-
|
|
3590
|
+
h && /* @__PURE__ */ f(U, { children: [
|
|
3561
3591
|
/* @__PURE__ */ s("span", { style: p.modeSwitchDivider, children: o.dividerBullet }),
|
|
3562
|
-
/* @__PURE__ */ s("a", { onClick: () =>
|
|
3592
|
+
/* @__PURE__ */ s("a", { onClick: () => h("reset"), style: p.link, children: o.haveTokenLink })
|
|
3563
3593
|
] })
|
|
3564
3594
|
] })
|
|
3565
3595
|
] });
|
|
@@ -3616,34 +3646,34 @@ function rn({
|
|
|
3616
3646
|
errorFallback: t,
|
|
3617
3647
|
requireTenant: n = !0
|
|
3618
3648
|
}) {
|
|
3619
|
-
const { isAppLoading: i, appError: a, retryApp: l } = Ae(),
|
|
3620
|
-
}), I = (
|
|
3621
|
-
a && l(),
|
|
3649
|
+
const { isAppLoading: i, appError: a, retryApp: l } = Ae(), h = pe(), S = Oe(), k = at(), T = lt(), c = (h == null ? void 0 : h.isTenantLoading) ?? !1, d = (h == null ? void 0 : h.tenantError) ?? null, A = (h == null ? void 0 : h.tenantSlug) ?? null, P = (h == null ? void 0 : h.retryTenant) ?? (() => {
|
|
3650
|
+
}), I = (S == null ? void 0 : S.isAuthReady) ?? !0, R = (k == null ? void 0 : k.isReady) ?? !0, E = (T == null ? void 0 : T.isReady) ?? !0, m = n && h && A, o = i || m && c || S && !I || k && !R || T && !E, p = a || (m ? d : null), x = () => {
|
|
3651
|
+
a && l(), d && h && P();
|
|
3622
3652
|
};
|
|
3623
3653
|
if (o)
|
|
3624
3654
|
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(yr, {}) });
|
|
3625
3655
|
if (p) {
|
|
3626
|
-
const y = typeof t == "function" ? t(p,
|
|
3656
|
+
const y = typeof t == "function" ? t(p, x) : t || /* @__PURE__ */ s(br, { error: p, retry: x });
|
|
3627
3657
|
return /* @__PURE__ */ s(U, { children: y });
|
|
3628
3658
|
}
|
|
3629
3659
|
return /* @__PURE__ */ s(U, { children: r });
|
|
3630
3660
|
}
|
|
3631
3661
|
function nn(r = !0) {
|
|
3632
|
-
const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = Ae(), a = pe(), l = Oe(),
|
|
3633
|
-
}), P = (l == null ? void 0 : l.isAuthReady) ?? !0, I = (
|
|
3662
|
+
const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = Ae(), a = pe(), l = Oe(), h = at(), S = lt(), k = (a == null ? void 0 : a.isTenantLoading) ?? !1, T = (a == null ? void 0 : a.tenantError) ?? null, c = (a == null ? void 0 : a.tenant) ?? null, d = (a == null ? void 0 : a.tenantSlug) ?? null, A = (a == null ? void 0 : a.retryTenant) ?? (() => {
|
|
3663
|
+
}), P = (l == null ? void 0 : l.isAuthReady) ?? !0, I = (h == null ? void 0 : h.isReady) ?? !0, R = (S == null ? void 0 : S.isReady) ?? !0, E = r && a && d, C = e || E && k || l && !P || h && !I || S && !R, o = t || (E ? T : null);
|
|
3634
3664
|
return {
|
|
3635
3665
|
isLoading: C,
|
|
3636
3666
|
error: o,
|
|
3637
|
-
isReady: !C && !o && i !== null && (!
|
|
3667
|
+
isReady: !C && !o && i !== null && (!E || c !== null),
|
|
3638
3668
|
retry: () => {
|
|
3639
|
-
t && n(),
|
|
3669
|
+
t && n(), T && a && A();
|
|
3640
3670
|
},
|
|
3641
3671
|
// Individual states
|
|
3642
3672
|
app: { isLoading: e, error: t, data: i },
|
|
3643
|
-
tenant: a ? { isLoading:
|
|
3673
|
+
tenant: a ? { isLoading: k, error: T, data: c } : null,
|
|
3644
3674
|
auth: l ? { isReady: P } : null,
|
|
3645
|
-
featureFlags:
|
|
3646
|
-
subscription:
|
|
3675
|
+
featureFlags: h ? { isReady: I } : null,
|
|
3676
|
+
subscription: S ? { isReady: R } : null
|
|
3647
3677
|
};
|
|
3648
3678
|
}
|
|
3649
3679
|
const wr = {
|
|
@@ -3698,14 +3728,14 @@ function sn({
|
|
|
3698
3728
|
className: i = "",
|
|
3699
3729
|
dropdownClassName: a = "",
|
|
3700
3730
|
itemClassName: l = "",
|
|
3701
|
-
renderItem:
|
|
3702
|
-
placeholder:
|
|
3703
|
-
disabled:
|
|
3704
|
-
showCurrentTenant:
|
|
3731
|
+
renderItem: h,
|
|
3732
|
+
placeholder: S = "Select tenant",
|
|
3733
|
+
disabled: k = !1,
|
|
3734
|
+
showCurrentTenant: T = !0
|
|
3705
3735
|
}) {
|
|
3706
3736
|
var C;
|
|
3707
|
-
const
|
|
3708
|
-
P(!1), t ? t(o) :
|
|
3737
|
+
const c = { ...wr, ...n }, d = Oe(), [A, P] = N(!1), I = ye(null), R = r ?? (d == null ? void 0 : d.userTenants) ?? [], E = e ?? ((C = d == null ? void 0 : d.currentUser) == null ? void 0 : C.tenantId) ?? null, m = async (o) => {
|
|
3738
|
+
P(!1), t ? t(o) : d != null && d.switchToTenant && await d.switchToTenant(o);
|
|
3709
3739
|
};
|
|
3710
3740
|
re(() => {
|
|
3711
3741
|
const o = (p) => {
|
|
@@ -3713,59 +3743,59 @@ function sn({
|
|
|
3713
3743
|
};
|
|
3714
3744
|
return document.addEventListener("mousedown", o), () => document.removeEventListener("mousedown", o);
|
|
3715
3745
|
}, []);
|
|
3716
|
-
const g = R.find((o) => o.id ===
|
|
3746
|
+
const g = R.find((o) => o.id === E);
|
|
3717
3747
|
if (R.length === 0)
|
|
3718
3748
|
return null;
|
|
3719
|
-
if (R.length === 1 &&
|
|
3749
|
+
if (R.length === 1 && T)
|
|
3720
3750
|
return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: R[0].name }) });
|
|
3721
3751
|
const b = (o, p) => /* @__PURE__ */ f("span", { style: { fontWeight: p ? "bold" : "normal" }, children: [
|
|
3722
3752
|
o.name,
|
|
3723
|
-
o.role && /* @__PURE__ */ f("span", { style:
|
|
3753
|
+
o.role && /* @__PURE__ */ f("span", { style: c.itemRole, children: [
|
|
3724
3754
|
"(",
|
|
3725
3755
|
o.role,
|
|
3726
3756
|
")"
|
|
3727
3757
|
] })
|
|
3728
3758
|
] });
|
|
3729
|
-
return /* @__PURE__ */ f("div", { ref: I, className: i, style:
|
|
3759
|
+
return /* @__PURE__ */ f("div", { ref: I, className: i, style: c.wrapper, children: [
|
|
3730
3760
|
/* @__PURE__ */ f(
|
|
3731
3761
|
"button",
|
|
3732
3762
|
{
|
|
3733
3763
|
type: "button",
|
|
3734
|
-
onClick: () => !
|
|
3735
|
-
disabled:
|
|
3764
|
+
onClick: () => !k && P(!A),
|
|
3765
|
+
disabled: k,
|
|
3736
3766
|
style: {
|
|
3737
|
-
...
|
|
3738
|
-
...
|
|
3767
|
+
...c.button,
|
|
3768
|
+
...k ? c.buttonDisabled : {}
|
|
3739
3769
|
},
|
|
3740
3770
|
children: [
|
|
3741
|
-
g ? g.name :
|
|
3742
|
-
/* @__PURE__ */ s("span", { style:
|
|
3771
|
+
g ? g.name : S,
|
|
3772
|
+
/* @__PURE__ */ s("span", { style: c.arrow, children: A ? "▲" : "▼" })
|
|
3743
3773
|
]
|
|
3744
3774
|
}
|
|
3745
3775
|
),
|
|
3746
|
-
|
|
3747
|
-
const p = o.id ===
|
|
3776
|
+
A && /* @__PURE__ */ s("div", { className: a, style: c.dropdown, children: R.map((o) => {
|
|
3777
|
+
const p = o.id === E;
|
|
3748
3778
|
return /* @__PURE__ */ s(
|
|
3749
3779
|
"div",
|
|
3750
3780
|
{
|
|
3751
3781
|
className: l,
|
|
3752
3782
|
onClick: () => m(o.id),
|
|
3753
3783
|
style: {
|
|
3754
|
-
...
|
|
3755
|
-
...p ?
|
|
3784
|
+
...c.item,
|
|
3785
|
+
...p ? c.itemSelected : {}
|
|
3756
3786
|
},
|
|
3757
|
-
onMouseEnter: (
|
|
3758
|
-
p || Object.assign(
|
|
3787
|
+
onMouseEnter: (x) => {
|
|
3788
|
+
p || Object.assign(x.currentTarget.style, c.itemHover);
|
|
3759
3789
|
},
|
|
3760
|
-
onMouseLeave: (
|
|
3790
|
+
onMouseLeave: (x) => {
|
|
3761
3791
|
if (!p) {
|
|
3762
|
-
const y =
|
|
3763
|
-
Object.keys(
|
|
3764
|
-
|
|
3792
|
+
const y = c.item || {};
|
|
3793
|
+
Object.keys(c.itemHover || {}).forEach((u) => {
|
|
3794
|
+
x.currentTarget.style[u] = y[u] ?? "";
|
|
3765
3795
|
});
|
|
3766
3796
|
}
|
|
3767
3797
|
},
|
|
3768
|
-
children:
|
|
3798
|
+
children: h ? h(o, p) : b(o, p)
|
|
3769
3799
|
},
|
|
3770
3800
|
o.id
|
|
3771
3801
|
);
|
|
@@ -3851,7 +3881,7 @@ function cn(r = {}) {
|
|
|
3851
3881
|
zoneRoots: e = {},
|
|
3852
3882
|
returnToParam: t = dt,
|
|
3853
3883
|
returnToStorage: n = "url"
|
|
3854
|
-
} = r, i = vt(), [a, l] = Tt(), { isAuthenticated:
|
|
3884
|
+
} = r, i = vt(), [a, l] = Tt(), { isAuthenticated: h, currentUser: S } = de(), { tenant: k } = Te(), T = V(() => ({ ...ze, ...e }), [e]), c = !!k, d = S == null ? void 0 : S.userType, A = V(() => {
|
|
3855
3885
|
switch (n) {
|
|
3856
3886
|
case "url":
|
|
3857
3887
|
return a.get(t);
|
|
@@ -3895,17 +3925,17 @@ function cn(r = {}) {
|
|
|
3895
3925
|
[n, a, t, l]
|
|
3896
3926
|
), R = te(
|
|
3897
3927
|
(m) => {
|
|
3898
|
-
const g =
|
|
3928
|
+
const g = T[m] || T.default;
|
|
3899
3929
|
i(g);
|
|
3900
3930
|
},
|
|
3901
|
-
[i,
|
|
3902
|
-
),
|
|
3931
|
+
[i, T]
|
|
3932
|
+
), E = te(() => c ? h ? d === ae.TENANT_ADMIN ? T.tenantAdmin : T.tenantUser : T.tenantGuest : h ? d === ae.TENANT_ADMIN ? T.publicAdmin : T.publicUser : T.publicGuest, [c, h, d, T]);
|
|
3903
3933
|
return {
|
|
3904
|
-
returnToUrl:
|
|
3934
|
+
returnToUrl: A,
|
|
3905
3935
|
clearReturnTo: P,
|
|
3906
3936
|
setReturnTo: I,
|
|
3907
3937
|
navigateToZone: R,
|
|
3908
|
-
getSmartRedirect:
|
|
3938
|
+
getSmartRedirect: E
|
|
3909
3939
|
};
|
|
3910
3940
|
}
|
|
3911
3941
|
function un(r, e, t = dt, n = "url") {
|
|
@@ -3943,7 +3973,7 @@ export {
|
|
|
3943
3973
|
Or as PublicZone,
|
|
3944
3974
|
Dt as RoleApiService,
|
|
3945
3975
|
Cr as RoutingProvider,
|
|
3946
|
-
|
|
3976
|
+
Z as SessionExpiredError,
|
|
3947
3977
|
Me as SessionManager,
|
|
3948
3978
|
Yr as SignupForm,
|
|
3949
3979
|
zt as SubscriptionApiService,
|