@skylabs-digital/react-identity-access 3.2.3 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/MagicLinkForm.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +1428 -1279
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/providers/AppProvider.d.ts.map +1 -1
- package/dist/providers/AuthProvider.d.ts +8 -1
- package/dist/providers/AuthProvider.d.ts.map +1 -1
- package/dist/services/SessionManager.d.ts +66 -2
- package/dist/services/SessionManager.d.ts.map +1 -1
- package/dist/types/api.d.ts +15 -0
- package/dist/types/api.d.ts.map +1 -1
- package/package.json +27 -1
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as s, Fragment as U, jsxs as f } from "react/jsx-runtime";
|
|
2
|
-
import me, { createContext as fe, useState as
|
|
3
|
-
import { useLocation as
|
|
2
|
+
import me, { createContext as fe, useState as C, useRef as be, useCallback as te, useMemo as O, useEffect as re, useContext as ne, useSyncExternalStore as Et } from "react";
|
|
3
|
+
import { useLocation as Re, Navigate as ve, useNavigate as xt, useSearchParams as Rt } from "react-router-dom";
|
|
4
4
|
class he {
|
|
5
5
|
constructor(e, t = 1e4) {
|
|
6
6
|
this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
|
|
@@ -11,25 +11,25 @@ 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, o = !1) {
|
|
15
|
+
const a = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, p = (i == null ? void 0 : i.timeout) || this.timeout;
|
|
16
|
+
let k = {
|
|
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
|
+
k = { ...k, Authorization: `Bearer ${c}` };
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const E = new AbortController(), S = setTimeout(() => E.abort(), p);
|
|
25
25
|
try {
|
|
26
|
-
const c = await fetch(
|
|
26
|
+
const c = await fetch(a, {
|
|
27
27
|
method: e,
|
|
28
|
-
headers:
|
|
28
|
+
headers: k,
|
|
29
29
|
body: n ? JSON.stringify(n) : void 0,
|
|
30
|
-
signal:
|
|
30
|
+
signal: E.signal
|
|
31
31
|
});
|
|
32
|
-
if (clearTimeout(
|
|
32
|
+
if (clearTimeout(S), c.status === 401 && !(i != null && i.skipAuth) && this.sessionManager && !o) {
|
|
33
33
|
try {
|
|
34
34
|
await c.text();
|
|
35
35
|
} catch {
|
|
@@ -41,7 +41,7 @@ class he {
|
|
|
41
41
|
const d = c.headers.get("content-type");
|
|
42
42
|
return !d || !d.includes("application/json") ? {} : await c.json();
|
|
43
43
|
} catch (c) {
|
|
44
|
-
throw clearTimeout(
|
|
44
|
+
throw clearTimeout(S), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${p}ms`) : c;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
async get(e, t) {
|
|
@@ -57,7 +57,7 @@ class he {
|
|
|
57
57
|
return this.executeRequest("DELETE", e, void 0, t);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function le(r) {
|
|
61
61
|
if (!r) return "";
|
|
62
62
|
const e = new URLSearchParams();
|
|
63
63
|
for (const [n, i] of Object.entries(r))
|
|
@@ -65,7 +65,7 @@ function ce(r) {
|
|
|
65
65
|
const t = e.toString();
|
|
66
66
|
return t ? `?${t}` : "";
|
|
67
67
|
}
|
|
68
|
-
class
|
|
68
|
+
class Ye {
|
|
69
69
|
constructor(e) {
|
|
70
70
|
this.httpService = e;
|
|
71
71
|
}
|
|
@@ -74,7 +74,7 @@ class Je {
|
|
|
74
74
|
}
|
|
75
75
|
async getApps(e) {
|
|
76
76
|
const t = await this.httpService.get(
|
|
77
|
-
`/apps/${
|
|
77
|
+
`/apps/${le(e)}`
|
|
78
78
|
);
|
|
79
79
|
return { apps: t.data, meta: t.meta };
|
|
80
80
|
}
|
|
@@ -105,92 +105,92 @@ class Je {
|
|
|
105
105
|
return (await this.httpService.get(`/apps/${e}/export-config`)).data;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
const
|
|
109
|
-
function
|
|
110
|
-
var
|
|
111
|
-
const { appId: t, baseUrl: n } = r, i = (((
|
|
108
|
+
const Be = fe(null), At = 300 * 1e3;
|
|
109
|
+
function Pr({ config: r, children: e }) {
|
|
110
|
+
var R, m, g;
|
|
111
|
+
const { appId: t, baseUrl: n } = r, i = (((R = r.cache) == null ? void 0 : R.enabled) ?? !0) && !!t, o = ((m = r.cache) == null ? void 0 : m.ttl) ?? At, a = ((g = r.cache) == null ? void 0 : g.storageKey) ?? (t ? `app_cache_${t}` : ""), [p, k] = C(() => {
|
|
112
112
|
if (!i) return null;
|
|
113
113
|
try {
|
|
114
|
-
const b = localStorage.getItem(
|
|
114
|
+
const b = localStorage.getItem(a);
|
|
115
115
|
if (!b) return null;
|
|
116
|
-
const
|
|
117
|
-
return Date.now() -
|
|
116
|
+
const w = JSON.parse(b);
|
|
117
|
+
return Date.now() - w.timestamp < o && w.appId === t ? w.data : (localStorage.removeItem(a), null);
|
|
118
118
|
} catch {
|
|
119
119
|
return null;
|
|
120
120
|
}
|
|
121
|
-
}), [
|
|
122
|
-
|
|
123
|
-
const
|
|
121
|
+
}), [E, S] = C(!!t && !p), [c, d] = C(null), x = be(p);
|
|
122
|
+
x.current = p;
|
|
123
|
+
const I = te(
|
|
124
124
|
async (b = !1) => {
|
|
125
|
-
if (t && !(!b && i &&
|
|
125
|
+
if (t && !(!b && i && x.current))
|
|
126
126
|
try {
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
127
|
+
S(!0), d(null);
|
|
128
|
+
const l = await new Ye(new he(n)).getPublicAppInfo(t);
|
|
129
|
+
if (k(l), i)
|
|
130
130
|
try {
|
|
131
|
-
const
|
|
132
|
-
data:
|
|
131
|
+
const h = {
|
|
132
|
+
data: l,
|
|
133
133
|
timestamp: Date.now(),
|
|
134
134
|
appId: t
|
|
135
135
|
};
|
|
136
|
-
localStorage.setItem(
|
|
137
|
-
} catch (
|
|
138
|
-
process.env.NODE_ENV === "development" && console.warn("[AppProvider] Failed to cache app info:",
|
|
136
|
+
localStorage.setItem(a, JSON.stringify(h));
|
|
137
|
+
} catch (h) {
|
|
138
|
+
process.env.NODE_ENV === "development" && console.warn("[AppProvider] Failed to cache app info:", h);
|
|
139
139
|
}
|
|
140
|
-
} catch (
|
|
141
|
-
const
|
|
142
|
-
d(
|
|
140
|
+
} catch (w) {
|
|
141
|
+
const l = w instanceof Error ? w : new Error("Failed to load app information");
|
|
142
|
+
d(l), k(null);
|
|
143
143
|
} finally {
|
|
144
|
-
|
|
144
|
+
S(!1);
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
|
-
[n, t, i,
|
|
148
|
-
),
|
|
149
|
-
if (!(!t || !i || !
|
|
147
|
+
[n, t, i, a]
|
|
148
|
+
), L = te(async () => {
|
|
149
|
+
if (!(!t || !i || !x.current))
|
|
150
150
|
try {
|
|
151
|
-
const b = localStorage.getItem(
|
|
151
|
+
const b = localStorage.getItem(a);
|
|
152
152
|
if (!b) return;
|
|
153
|
-
const
|
|
154
|
-
if (Date.now() -
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
data:
|
|
153
|
+
const w = JSON.parse(b);
|
|
154
|
+
if (Date.now() - w.timestamp <= o * 0.5) return;
|
|
155
|
+
const h = await new Ye(new he(n)).getPublicAppInfo(t);
|
|
156
|
+
k(h);
|
|
157
|
+
const A = {
|
|
158
|
+
data: h,
|
|
159
159
|
timestamp: Date.now(),
|
|
160
160
|
appId: t
|
|
161
161
|
};
|
|
162
|
-
localStorage.setItem(
|
|
162
|
+
localStorage.setItem(a, JSON.stringify(A));
|
|
163
163
|
} catch (b) {
|
|
164
164
|
process.env.NODE_ENV === "development" && console.warn("[AppProvider] Background app refresh failed:", b);
|
|
165
165
|
}
|
|
166
|
-
}, [n, t, i,
|
|
166
|
+
}, [n, t, i, o, a]), P = O(
|
|
167
167
|
() => ({
|
|
168
168
|
appId: t,
|
|
169
169
|
baseUrl: n,
|
|
170
|
-
appInfo:
|
|
171
|
-
isAppLoading:
|
|
170
|
+
appInfo: p,
|
|
171
|
+
isAppLoading: E,
|
|
172
172
|
appError: c,
|
|
173
173
|
retryApp: () => {
|
|
174
|
-
|
|
174
|
+
I(!0);
|
|
175
175
|
}
|
|
176
176
|
}),
|
|
177
|
-
[t, n,
|
|
177
|
+
[t, n, p, E, c, I]
|
|
178
178
|
);
|
|
179
179
|
return re(() => {
|
|
180
|
-
t && (
|
|
181
|
-
}, []), /* @__PURE__ */ s(
|
|
180
|
+
t && (x.current ? L() : I());
|
|
181
|
+
}, []), /* @__PURE__ */ s(Be.Provider, { value: P, children: e });
|
|
182
182
|
}
|
|
183
183
|
function Ae() {
|
|
184
|
-
const r = ne(
|
|
184
|
+
const r = ne(Be);
|
|
185
185
|
if (!r)
|
|
186
186
|
throw new Error("useApp must be used within an AppProvider");
|
|
187
187
|
return r;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
return ne(
|
|
189
|
+
function _e() {
|
|
190
|
+
return ne(Be);
|
|
191
191
|
}
|
|
192
|
-
const
|
|
193
|
-
class
|
|
192
|
+
const Ir = Ae;
|
|
193
|
+
class Q extends Error {
|
|
194
194
|
constructor(e, t) {
|
|
195
195
|
const n = {
|
|
196
196
|
token_expired: "Refresh token has expired",
|
|
@@ -200,24 +200,24 @@ class Z extends Error {
|
|
|
200
200
|
super(t || n[e]), this.name = "SessionExpiredError", this.reason = e;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
class
|
|
203
|
+
class Pt extends Error {
|
|
204
204
|
constructor(e) {
|
|
205
205
|
super(`Token refresh timed out after ${e}ms`), this.name = "TokenRefreshTimeoutError", this.timeoutMs = e;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
class
|
|
208
|
+
class It extends Error {
|
|
209
209
|
constructor(e, t) {
|
|
210
210
|
super(
|
|
211
211
|
`Token refresh failed after ${e} attempts: ${(t == null ? void 0 : t.message) || "Unknown error"}`
|
|
212
212
|
), this.name = "TokenRefreshError", this.attempts = e, this.lastError = t;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
class
|
|
215
|
+
class ie extends Error {
|
|
216
216
|
constructor(e, t, n) {
|
|
217
|
-
super(`Invalid configuration "${e}": ${n} (received: ${
|
|
217
|
+
super(`Invalid configuration "${e}": ${n} (received: ${Lt(t)})`), this.name = "ConfigurationError", this.field = e, this.received = t;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function Lt(r) {
|
|
221
221
|
if (r === void 0) return "undefined";
|
|
222
222
|
try {
|
|
223
223
|
const e = JSON.stringify(r);
|
|
@@ -226,85 +226,92 @@ function xt(r) {
|
|
|
226
226
|
return typeof r;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
function
|
|
229
|
+
function Xe(r) {
|
|
230
230
|
return JSON.parse(atob(r.replace(/-/g, "+").replace(/_/g, "/")));
|
|
231
231
|
}
|
|
232
|
-
function
|
|
232
|
+
function Pe(r) {
|
|
233
233
|
const e = r.split(".");
|
|
234
234
|
if (e.length !== 3) return null;
|
|
235
235
|
try {
|
|
236
|
-
return { header:
|
|
236
|
+
return { header: Xe(e[0]), payload: Xe(e[1]) };
|
|
237
237
|
} catch {
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function
|
|
242
|
-
const e =
|
|
241
|
+
function et(r) {
|
|
242
|
+
const e = Pe(r), t = e == null ? void 0 : e.payload.exp;
|
|
243
243
|
return typeof t == "number" ? t * 1e3 : void 0;
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function Ft(r, e) {
|
|
246
246
|
var n;
|
|
247
|
-
const t = (n =
|
|
247
|
+
const t = (n = Pe(r)) == null ? void 0 : n.payload[e];
|
|
248
248
|
return typeof t == "string" ? t : void 0;
|
|
249
249
|
}
|
|
250
|
-
const
|
|
251
|
-
function
|
|
250
|
+
const Nt = /^(javascript|data|vbscript|file):/i, Ct = /^https?:\/\//i;
|
|
251
|
+
function Dt(r, e = "baseUrl") {
|
|
252
252
|
if (!(r == null || r === "")) {
|
|
253
253
|
if (typeof r != "string")
|
|
254
|
-
throw new
|
|
255
|
-
if (
|
|
256
|
-
throw new
|
|
257
|
-
if (!
|
|
258
|
-
throw new
|
|
254
|
+
throw new ie(e, r, "must be a string");
|
|
255
|
+
if (Nt.test(r))
|
|
256
|
+
throw new ie(e, r, "dangerous URL scheme is not allowed");
|
|
257
|
+
if (!Ct.test(r))
|
|
258
|
+
throw new ie(e, r, "must start with http:// or https://");
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
function ge(r, e, t = {}) {
|
|
262
262
|
if (e === void 0) return;
|
|
263
263
|
if (typeof e != "number" || !Number.isFinite(e))
|
|
264
|
-
throw new
|
|
264
|
+
throw new ie(r, e, "must be a finite number");
|
|
265
265
|
const { min: n = 0, max: i = Number.MAX_SAFE_INTEGER } = t;
|
|
266
266
|
if (e < n)
|
|
267
|
-
throw new
|
|
267
|
+
throw new ie(r, e, `must be >= ${n}`);
|
|
268
268
|
if (e > i)
|
|
269
|
-
throw new
|
|
269
|
+
throw new ie(r, e, `must be <= ${i}`);
|
|
270
270
|
}
|
|
271
|
-
function
|
|
271
|
+
function tt(r, e) {
|
|
272
272
|
if (e !== void 0 && typeof e != "boolean")
|
|
273
|
-
throw new
|
|
273
|
+
throw new ie(r, e, "must be a boolean");
|
|
274
274
|
}
|
|
275
|
-
function
|
|
275
|
+
function Mt(r, e = "accessToken") {
|
|
276
276
|
if (typeof r != "string" || r.length === 0)
|
|
277
|
-
throw new
|
|
277
|
+
throw new ie(e, r, "must be a non-empty string");
|
|
278
278
|
if (!r.includes(".")) return;
|
|
279
279
|
const t = r.split(".");
|
|
280
280
|
if (t.length !== 3)
|
|
281
|
-
throw new
|
|
281
|
+
throw new ie(
|
|
282
282
|
e,
|
|
283
283
|
`<${t.length}-segment token>`,
|
|
284
284
|
"JWT must have exactly 3 segments (header.payload.signature)"
|
|
285
285
|
);
|
|
286
|
-
if (
|
|
287
|
-
throw new
|
|
286
|
+
if (Pe(r) === null)
|
|
287
|
+
throw new ie(
|
|
288
288
|
e,
|
|
289
289
|
"<malformed JWT>",
|
|
290
290
|
"JWT header or payload is not valid base64url-encoded JSON"
|
|
291
291
|
);
|
|
292
292
|
}
|
|
293
|
-
function
|
|
293
|
+
function $t(r) {
|
|
294
294
|
if (r !== void 0 && (typeof r != "number" || !Number.isFinite(r) || r <= 0))
|
|
295
|
-
throw new
|
|
295
|
+
throw new ie("expiresIn", r, "must be a finite positive number (seconds)");
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function Ut(r) {
|
|
298
298
|
if (r !== void 0 && (typeof r != "number" || !Number.isFinite(r) || r <= 0))
|
|
299
|
-
throw new
|
|
299
|
+
throw new ie(
|
|
300
300
|
"expiresAt",
|
|
301
301
|
r,
|
|
302
302
|
"must be a finite positive timestamp (ms since epoch)"
|
|
303
303
|
);
|
|
304
304
|
}
|
|
305
|
-
const
|
|
305
|
+
const rt = "__RIA_SESSION_INSTANCES_V1__", ye = (() => {
|
|
306
|
+
const r = globalThis, e = r[rt];
|
|
307
|
+
if (e instanceof Map) return e;
|
|
308
|
+
const t = /* @__PURE__ */ new Map();
|
|
309
|
+
return r[rt] = t, t;
|
|
310
|
+
})(), de = class de {
|
|
306
311
|
constructor(e = {}) {
|
|
307
|
-
this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, this.consecutiveBackgroundFailures = 0, this.memoryStore = null, this.visibilityListener = null,
|
|
312
|
+
this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, this.consecutiveBackgroundFailures = 0, this.state = "idle", this.isRefreshing = !1, this.lastExpiryReason = null, this.logoutInFlight = !1, this.listeners = /* @__PURE__ */ new Set(), this.notifyVersion = 0, this.memoryStore = null, this.visibilityListener = null, this.storageListener = null, de.validateConfig(e), this.storageKey = e.storageKey || "auth_tokens", this.autoRefresh = e.autoRefresh ?? !0, this.refreshThreshold = e.refreshThreshold || 3e5, this.onRefreshFailed = e.onRefreshFailed, this.onSessionExpired = e.onSessionExpired, this.baseUrl = e.baseUrl || "", this.enableCookieSession = e.enableCookieSession ?? !1, this.proactiveRefreshMargin = e.proactiveRefreshMargin ?? 6e4, this.refreshQueueTimeout = e.refreshQueueTimeout ?? 1e4, this.maxRefreshRetries = e.maxRefreshRetries ?? 3, this.retryBackoffBase = e.retryBackoffBase ?? 1e3, this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey);
|
|
313
|
+
const t = this.tokenStorage.get();
|
|
314
|
+
t != null && t.accessToken && (this.state = "restoring"), this.attachVisibilityListener(), this.attachStorageListener(), this.scheduleProactiveRefresh();
|
|
308
315
|
}
|
|
309
316
|
/**
|
|
310
317
|
* Get or create a SessionManager instance for the given config.
|
|
@@ -312,30 +319,30 @@ const ie = class ie {
|
|
|
312
319
|
* Mutable config (callbacks, baseUrl) is updated on the existing instance.
|
|
313
320
|
*/
|
|
314
321
|
static getInstance(e = {}) {
|
|
315
|
-
const t =
|
|
322
|
+
const t = de.resolveStorageKey(e), n = ye.get(t);
|
|
316
323
|
if (n)
|
|
317
324
|
return n.updateConfig(e), n;
|
|
318
|
-
const i = new
|
|
319
|
-
return
|
|
325
|
+
const i = new de(e);
|
|
326
|
+
return ye.set(t, i), i;
|
|
320
327
|
}
|
|
321
328
|
/** Reset all singleton instances. For testing only. */
|
|
322
329
|
static resetAllInstances() {
|
|
323
|
-
for (const e of
|
|
330
|
+
for (const e of ye.values())
|
|
324
331
|
e.destroy();
|
|
325
|
-
|
|
332
|
+
ye.clear();
|
|
326
333
|
}
|
|
327
334
|
static resolveStorageKey(e) {
|
|
328
335
|
return e.storageKey || "auth_tokens";
|
|
329
336
|
}
|
|
330
337
|
static validateConfig(e) {
|
|
331
|
-
|
|
338
|
+
Dt(e.baseUrl), tt("enableCookieSession", e.enableCookieSession), tt("autoRefresh", e.autoRefresh), ge("refreshThreshold", e.refreshThreshold, { min: 0 }), ge("proactiveRefreshMargin", e.proactiveRefreshMargin, { min: 0 }), ge("refreshQueueTimeout", e.refreshQueueTimeout, { min: 1 }), ge("maxRefreshRetries", e.maxRefreshRetries, { min: 0 }), ge("retryBackoffBase", e.retryBackoffBase, { min: 1 });
|
|
332
339
|
}
|
|
333
340
|
/** Update mutable config (callbacks, baseUrl) on an existing instance. */
|
|
334
341
|
updateConfig(e) {
|
|
335
342
|
e.onSessionExpired !== void 0 && (this.onSessionExpired = e.onSessionExpired), e.onRefreshFailed !== void 0 && (this.onRefreshFailed = e.onRefreshFailed), e.baseUrl && (this.baseUrl = e.baseUrl), e.enableCookieSession !== void 0 && (this.enableCookieSession = e.enableCookieSession);
|
|
336
343
|
}
|
|
337
344
|
createTokenStorage(e) {
|
|
338
|
-
return
|
|
345
|
+
return de.probeLocalStorage() || this.activateMemoryFallback(), {
|
|
339
346
|
get: () => {
|
|
340
347
|
const t = this.storageGet(e);
|
|
341
348
|
if (!t) return null;
|
|
@@ -397,26 +404,26 @@ const ie = class ie {
|
|
|
397
404
|
}
|
|
398
405
|
// --- Token CRUD ---
|
|
399
406
|
setTokens(e) {
|
|
400
|
-
if (
|
|
401
|
-
throw new
|
|
402
|
-
|
|
403
|
-
const t = e.expiresAt || (e.expiresIn ? Date.now() + e.expiresIn * 1e3 : void 0) ||
|
|
407
|
+
if (Mt(e.accessToken, "accessToken"), e.refreshToken !== void 0 && typeof e.refreshToken != "string")
|
|
408
|
+
throw new ie("refreshToken", e.refreshToken, "must be a string");
|
|
409
|
+
$t(e.expiresIn), Ut(e.expiresAt);
|
|
410
|
+
const t = e.expiresAt || (e.expiresIn ? Date.now() + e.expiresIn * 1e3 : void 0) || et(e.accessToken), n = {
|
|
404
411
|
...e,
|
|
405
412
|
expiresAt: t
|
|
406
413
|
}, i = this.tokenStorage.get() || {};
|
|
407
|
-
this.tokenStorage.set({ ...i, ...n }), this.scheduleProactiveRefresh();
|
|
414
|
+
this.tokenStorage.set({ ...i, ...n }), this.scheduleProactiveRefresh(), this.isTokenExpired(n) || this.transitionTo("authenticated"), this.notify();
|
|
408
415
|
}
|
|
409
416
|
getTokens() {
|
|
410
|
-
const { accessToken: e, refreshToken: t, expiresAt: n, expiresIn: i, tokenType:
|
|
417
|
+
const { accessToken: e, refreshToken: t, expiresAt: n, expiresIn: i, tokenType: o } = this.tokenStorage.get() || {};
|
|
411
418
|
if (!e)
|
|
412
419
|
return null;
|
|
413
|
-
const
|
|
420
|
+
const a = n || et(e);
|
|
414
421
|
return {
|
|
415
422
|
accessToken: e,
|
|
416
423
|
refreshToken: t,
|
|
417
|
-
expiresAt:
|
|
424
|
+
expiresAt: a,
|
|
418
425
|
expiresIn: i,
|
|
419
|
-
tokenType:
|
|
426
|
+
tokenType: o
|
|
420
427
|
};
|
|
421
428
|
}
|
|
422
429
|
clearTokens() {
|
|
@@ -471,6 +478,90 @@ const ie = class ie {
|
|
|
471
478
|
}
|
|
472
479
|
this.visibilityListener = null;
|
|
473
480
|
}
|
|
481
|
+
attachStorageListener() {
|
|
482
|
+
if (!this.storageListener && !(typeof window > "u" || typeof window.addEventListener != "function")) {
|
|
483
|
+
this.storageListener = (e) => {
|
|
484
|
+
if (e.key === this.storageKey && !(e.storageArea && e.storageArea !== localStorage) && !this.isDestroyed) {
|
|
485
|
+
if (e.newValue === null) {
|
|
486
|
+
this.sessionGeneration++, this.cancelProactiveTimer();
|
|
487
|
+
const t = new Q(
|
|
488
|
+
"token_invalid",
|
|
489
|
+
"Session cleared in another tab"
|
|
490
|
+
);
|
|
491
|
+
this.rejectQueue(t), this.transitionTo("idle");
|
|
492
|
+
} else {
|
|
493
|
+
this.scheduleProactiveRefresh();
|
|
494
|
+
const t = this.getTokens();
|
|
495
|
+
t != null && t.accessToken && !this.isTokenExpired(t) && this.transitionTo("authenticated");
|
|
496
|
+
}
|
|
497
|
+
this.notify();
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
try {
|
|
501
|
+
window.addEventListener("storage", this.storageListener);
|
|
502
|
+
} catch {
|
|
503
|
+
this.storageListener = null;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
detachStorageListener() {
|
|
508
|
+
if (this.storageListener && typeof window < "u")
|
|
509
|
+
try {
|
|
510
|
+
window.removeEventListener("storage", this.storageListener);
|
|
511
|
+
} catch {
|
|
512
|
+
}
|
|
513
|
+
this.storageListener = null;
|
|
514
|
+
}
|
|
515
|
+
// --- Reactivity (useSyncExternalStore-compatible) ---
|
|
516
|
+
/**
|
|
517
|
+
* Subscribe to session state changes. Returns an unsubscribe function.
|
|
518
|
+
* Fires on: setTokens, setUser, clearUser, clearSession, handleSessionExpired,
|
|
519
|
+
* refresh in-flight transitions, and cross-tab storage events.
|
|
520
|
+
*/
|
|
521
|
+
subscribe(e) {
|
|
522
|
+
return this.listeners.add(e), () => {
|
|
523
|
+
this.listeners.delete(e);
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Numeric snapshot for useSyncExternalStore. Strictly monotonic — every
|
|
528
|
+
* call to `notify()` bumps it so React will observe a fresh value even
|
|
529
|
+
* when the higher-level state ordinal and refreshing flag look identical.
|
|
530
|
+
*/
|
|
531
|
+
getSnapshot() {
|
|
532
|
+
return this.notifyVersion;
|
|
533
|
+
}
|
|
534
|
+
/** True iff a refresh network call is currently in flight or queued. */
|
|
535
|
+
getRefreshInFlight() {
|
|
536
|
+
return this.refreshPromise !== null;
|
|
537
|
+
}
|
|
538
|
+
/** Current state of the session machine. */
|
|
539
|
+
getState() {
|
|
540
|
+
return this.state;
|
|
541
|
+
}
|
|
542
|
+
/** Diagnostic snapshot — useful for tests and DevTools. */
|
|
543
|
+
getRefreshStats() {
|
|
544
|
+
return {
|
|
545
|
+
state: this.state,
|
|
546
|
+
isRefreshing: this.isRefreshing,
|
|
547
|
+
inFlight: this.refreshPromise !== null,
|
|
548
|
+
queued: this.refreshQueue.length,
|
|
549
|
+
sessionGeneration: this.sessionGeneration,
|
|
550
|
+
consecutiveBackgroundFailures: this.consecutiveBackgroundFailures,
|
|
551
|
+
lastExpiryReason: this.lastExpiryReason
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
notify() {
|
|
555
|
+
this.notifyVersion++;
|
|
556
|
+
for (const e of this.listeners)
|
|
557
|
+
try {
|
|
558
|
+
e();
|
|
559
|
+
} catch {
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
transitionTo(e) {
|
|
563
|
+
this.state !== e && (this.state = e);
|
|
564
|
+
}
|
|
474
565
|
backgroundRefresh() {
|
|
475
566
|
if (this.isDestroyed) return;
|
|
476
567
|
const e = this.getTokens();
|
|
@@ -479,13 +570,13 @@ const ie = class ie {
|
|
|
479
570
|
this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
|
|
480
571
|
this.consecutiveBackgroundFailures = 0;
|
|
481
572
|
}).catch((n) => {
|
|
482
|
-
if (!(n instanceof
|
|
573
|
+
if (!(n instanceof Q)) {
|
|
483
574
|
if (this.sessionGeneration === t) {
|
|
484
|
-
if (this.consecutiveBackgroundFailures++, this.consecutiveBackgroundFailures >=
|
|
575
|
+
if (this.consecutiveBackgroundFailures++, this.consecutiveBackgroundFailures >= de.MAX_BACKGROUND_FAILURES) {
|
|
485
576
|
process.env.NODE_ENV === "development" && console.error(
|
|
486
577
|
`[SessionManager] Background refresh failed ${this.consecutiveBackgroundFailures} consecutive times — expiring session`
|
|
487
578
|
), this.consecutiveBackgroundFailures = 0, this.handleSessionExpired(
|
|
488
|
-
new
|
|
579
|
+
new Q("token_invalid", "Background refresh failed repeatedly")
|
|
489
580
|
);
|
|
490
581
|
return;
|
|
491
582
|
}
|
|
@@ -552,13 +643,13 @@ const ie = class ie {
|
|
|
552
643
|
async getValidAccessToken() {
|
|
553
644
|
const e = this.getTokens();
|
|
554
645
|
if (!(e != null && e.accessToken)) {
|
|
555
|
-
const t = new
|
|
646
|
+
const t = new Q("token_invalid", "No tokens available");
|
|
556
647
|
throw this.handleSessionExpired(t), t;
|
|
557
648
|
}
|
|
558
649
|
if (!this.shouldRefreshToken(e) && !this.isTokenExpired(e))
|
|
559
650
|
return e.accessToken;
|
|
560
651
|
if (!e.refreshToken) {
|
|
561
|
-
const t = new
|
|
652
|
+
const t = new Q("token_invalid", "No refresh token available");
|
|
562
653
|
throw this.handleSessionExpired(t), t;
|
|
563
654
|
}
|
|
564
655
|
return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken);
|
|
@@ -577,15 +668,48 @@ const ie = class ie {
|
|
|
577
668
|
async forceRefresh() {
|
|
578
669
|
const e = this.getTokens();
|
|
579
670
|
if (!(e != null && e.accessToken)) {
|
|
580
|
-
const t = new
|
|
671
|
+
const t = new Q("token_invalid", "No tokens available");
|
|
581
672
|
throw this.handleSessionExpired(t), t;
|
|
582
673
|
}
|
|
583
674
|
if (!e.refreshToken) {
|
|
584
|
-
const t = new
|
|
675
|
+
const t = new Q("token_invalid", "No refresh token available");
|
|
585
676
|
throw this.handleSessionExpired(t), t;
|
|
586
677
|
}
|
|
587
678
|
return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken, !0);
|
|
588
679
|
}
|
|
680
|
+
/**
|
|
681
|
+
* Active bootstrap resolution: drive the session to a terminal state.
|
|
682
|
+
*
|
|
683
|
+
* Unlike `waitForPendingRefresh()` which only awaits a refresh someone else
|
|
684
|
+
* already started, this method actively triggers the refresh when needed.
|
|
685
|
+
* Use it from `AuthProvider` during initial mount so a page load with a
|
|
686
|
+
* stale access token but valid refresh token doesn't expose
|
|
687
|
+
* `isAuthenticated=false` before the refresh even runs.
|
|
688
|
+
*
|
|
689
|
+
* Resolves to:
|
|
690
|
+
* - `'authenticated'`: tokens exist and are valid (refreshed if necessary)
|
|
691
|
+
* - `'unauthenticated'`: no tokens at all (callers should treat as anon)
|
|
692
|
+
* - `'expired'`: tokens existed but refresh failed fatally; the
|
|
693
|
+
* `onSessionExpired` callback was already fired by `handleSessionExpired`.
|
|
694
|
+
*
|
|
695
|
+
* Never throws — all error paths collapse into `'expired'`.
|
|
696
|
+
*/
|
|
697
|
+
async ensureValidSession() {
|
|
698
|
+
const e = this.getTokens();
|
|
699
|
+
if (!(e != null && e.accessToken))
|
|
700
|
+
return this.transitionTo("idle"), this.notify(), "unauthenticated";
|
|
701
|
+
if (!this.isTokenExpired(e) && !this.shouldRefreshToken(e))
|
|
702
|
+
return this.transitionTo("authenticated"), this.notify(), "authenticated";
|
|
703
|
+
if (!e.refreshToken)
|
|
704
|
+
return this.handleSessionExpired(
|
|
705
|
+
new Q("token_invalid", "No refresh token available")
|
|
706
|
+
), "expired";
|
|
707
|
+
try {
|
|
708
|
+
return await this.getValidAccessToken(), this.transitionTo("authenticated"), this.notify(), "authenticated";
|
|
709
|
+
} catch {
|
|
710
|
+
return this.state !== "expired" && (this.transitionTo("expired"), this.notify()), "expired";
|
|
711
|
+
}
|
|
712
|
+
}
|
|
589
713
|
/**
|
|
590
714
|
* Backward-compatible getAuthHeaders — now delegates to getValidAccessToken.
|
|
591
715
|
*/
|
|
@@ -593,29 +717,30 @@ const ie = class ie {
|
|
|
593
717
|
try {
|
|
594
718
|
return { Authorization: `Bearer ${await this.getValidAccessToken()}` };
|
|
595
719
|
} catch (e) {
|
|
596
|
-
return e instanceof
|
|
720
|
+
return e instanceof Q && this.onRefreshFailed && this.onRefreshFailed(), {};
|
|
597
721
|
}
|
|
598
722
|
}
|
|
599
723
|
enqueueForToken() {
|
|
600
724
|
return new Promise((e, t) => {
|
|
601
725
|
const n = setTimeout(() => {
|
|
602
|
-
const i = this.refreshQueue.findIndex((
|
|
603
|
-
i !== -1 && this.refreshQueue.splice(i, 1), t(new
|
|
726
|
+
const i = this.refreshQueue.findIndex((o) => o.timeoutId === n);
|
|
727
|
+
i !== -1 && this.refreshQueue.splice(i, 1), t(new Pt(this.refreshQueueTimeout));
|
|
604
728
|
}, this.refreshQueueTimeout);
|
|
605
729
|
this.refreshQueue.push({ resolve: e, reject: t, timeoutId: n });
|
|
606
730
|
});
|
|
607
731
|
}
|
|
608
732
|
async startRefreshAndResolveQueue(e, t = !1) {
|
|
609
|
-
|
|
733
|
+
const n = this.sessionGeneration;
|
|
734
|
+
this.refreshPromise = this.executeRefreshWithRetry(e, t), this.isRefreshing = !0, this.notify();
|
|
610
735
|
try {
|
|
611
736
|
await this.refreshPromise;
|
|
612
|
-
const
|
|
613
|
-
return this.resolveQueue(
|
|
614
|
-
} catch (
|
|
615
|
-
const
|
|
616
|
-
throw
|
|
737
|
+
const i = this.getTokens(), o = (i == null ? void 0 : i.accessToken) || "";
|
|
738
|
+
return this.resolveQueue(o), o;
|
|
739
|
+
} catch (i) {
|
|
740
|
+
const o = i instanceof Error ? i : new Error("Token refresh failed");
|
|
741
|
+
throw o instanceof Q ? (this.rejectQueue(o), this.sessionGeneration === n && this.handleSessionExpired(o)) : this.rejectQueue(o), o;
|
|
617
742
|
} finally {
|
|
618
|
-
this.refreshPromise = null;
|
|
743
|
+
this.refreshPromise = null, this.isRefreshing = !1, this.notify();
|
|
619
744
|
}
|
|
620
745
|
}
|
|
621
746
|
resolveQueue(e) {
|
|
@@ -634,23 +759,23 @@ const ie = class ie {
|
|
|
634
759
|
async executeRefreshWithRetry(e, t = !1) {
|
|
635
760
|
let n;
|
|
636
761
|
const i = this.sessionGeneration;
|
|
637
|
-
for (let
|
|
762
|
+
for (let o = 0; o <= this.maxRefreshRetries; o++) {
|
|
638
763
|
if (this.sessionGeneration !== i)
|
|
639
|
-
throw new
|
|
764
|
+
throw new Q("token_invalid", "Session cleared during refresh");
|
|
640
765
|
try {
|
|
641
766
|
await this.performTokenRefresh(e, i, t);
|
|
642
767
|
return;
|
|
643
|
-
} catch (
|
|
644
|
-
const
|
|
645
|
-
if (
|
|
646
|
-
throw
|
|
647
|
-
if (n =
|
|
648
|
-
const
|
|
649
|
-
await this.sleep(
|
|
768
|
+
} catch (a) {
|
|
769
|
+
const p = a instanceof Error ? a : new Error(String(a));
|
|
770
|
+
if (p instanceof Q)
|
|
771
|
+
throw p;
|
|
772
|
+
if (n = p, o < this.maxRefreshRetries) {
|
|
773
|
+
const k = this.retryBackoffBase * Math.pow(2, o);
|
|
774
|
+
await this.sleep(k);
|
|
650
775
|
}
|
|
651
776
|
}
|
|
652
777
|
}
|
|
653
|
-
throw new
|
|
778
|
+
throw new It(this.maxRefreshRetries + 1, n);
|
|
654
779
|
}
|
|
655
780
|
/**
|
|
656
781
|
* Single refresh attempt with error classification.
|
|
@@ -669,46 +794,49 @@ const ie = class ie {
|
|
|
669
794
|
const i = this.getTokens();
|
|
670
795
|
if (!n && (i != null && i.accessToken) && !this.isTokenExpired(i) && !this.shouldRefreshToken(i))
|
|
671
796
|
return;
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
let
|
|
797
|
+
const o = (i == null ? void 0 : i.refreshToken) || e, a = `${this.baseUrl}/auth/refresh`, p = Ft(o, "deviceId"), k = { refreshToken: o };
|
|
798
|
+
p && (k.deviceId = p);
|
|
799
|
+
let E;
|
|
675
800
|
try {
|
|
676
|
-
|
|
801
|
+
E = await fetch(a, {
|
|
677
802
|
method: "POST",
|
|
678
803
|
headers: { "Content-Type": "application/json" },
|
|
679
|
-
body: JSON.stringify(
|
|
804
|
+
body: JSON.stringify(k),
|
|
680
805
|
...this.enableCookieSession && { credentials: "include" }
|
|
681
806
|
});
|
|
682
807
|
} catch (c) {
|
|
683
808
|
throw c instanceof Error ? c : new Error("Network error during token refresh");
|
|
684
809
|
}
|
|
685
|
-
if (!
|
|
810
|
+
if (!E.ok) {
|
|
686
811
|
let c = "";
|
|
687
812
|
try {
|
|
688
|
-
const d = await
|
|
813
|
+
const d = await E.json();
|
|
689
814
|
c = (d.message || d.error || "").toLowerCase();
|
|
690
815
|
} catch {
|
|
691
|
-
c =
|
|
816
|
+
c = E.statusText.toLowerCase();
|
|
692
817
|
}
|
|
693
|
-
throw
|
|
818
|
+
throw E.status === 401 ? c.includes("expired") ? new Q("token_expired") : c.includes("invalid") ? new Q("token_invalid") : new Q("token_invalid", `Unauthorized: ${c}`) : E.status === 400 ? c.includes("inactive") ? new Q("user_inactive") : c.includes("expired") || c.includes("invalid") ? new Q("token_invalid", c) : c.includes("reuse") || c.includes("revoked") ? new Q("token_invalid", c) : new Error(`Token refresh failed (400): ${c}`) : new Error(`Token refresh failed: ${E.status} ${c}`);
|
|
694
819
|
}
|
|
695
820
|
if (this.sessionGeneration !== t)
|
|
696
|
-
throw new
|
|
697
|
-
const
|
|
821
|
+
throw new Q("token_invalid", "Session cleared during refresh");
|
|
822
|
+
const S = await E.json();
|
|
698
823
|
this.setTokens({
|
|
699
|
-
accessToken:
|
|
700
|
-
refreshToken:
|
|
701
|
-
expiresIn:
|
|
824
|
+
accessToken: S.accessToken,
|
|
825
|
+
refreshToken: S.refreshToken || o,
|
|
826
|
+
expiresIn: S.expiresIn
|
|
702
827
|
});
|
|
703
828
|
}
|
|
704
829
|
// --- Session expiry handler ---
|
|
705
830
|
handleSessionExpired(e) {
|
|
706
|
-
|
|
831
|
+
const t = this.logoutInFlight;
|
|
832
|
+
this.lastExpiryReason = e.message, this.cancelProactiveTimer(), this.sessionGeneration++, this.clearTokens();
|
|
833
|
+
const n = new Q("token_invalid", "Session cleared");
|
|
834
|
+
this.rejectQueue(n), this.transitionTo(t ? "idle" : "expired"), this.notify(), !t && (this.onSessionExpired ? this.onSessionExpired(e) : this.onRefreshFailed && this.onRefreshFailed());
|
|
707
835
|
}
|
|
708
836
|
// --- User data ---
|
|
709
837
|
setUser(e) {
|
|
710
838
|
const t = this.tokenStorage.get() || {};
|
|
711
|
-
this.tokenStorage.set({ ...t, user: e });
|
|
839
|
+
this.tokenStorage.set({ ...t, user: e }), this.notify();
|
|
712
840
|
}
|
|
713
841
|
getUser() {
|
|
714
842
|
const e = this.tokenStorage.get();
|
|
@@ -716,28 +844,37 @@ const ie = class ie {
|
|
|
716
844
|
}
|
|
717
845
|
clearUser() {
|
|
718
846
|
const e = this.tokenStorage.get() || {};
|
|
719
|
-
delete e.user, this.tokenStorage.set(e);
|
|
847
|
+
delete e.user, this.tokenStorage.set(e), this.notify();
|
|
720
848
|
}
|
|
721
849
|
// --- Session lifecycle ---
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
850
|
+
/**
|
|
851
|
+
* Clear all session state.
|
|
852
|
+
*
|
|
853
|
+
* @param reason - 'logout' for intentional sign-out (suppresses any
|
|
854
|
+
* onSessionExpired callbacks fired by in-flight refreshes that race the
|
|
855
|
+
* logout); 'expired' for fatal-error paths. Defaults to 'expired' for
|
|
856
|
+
* backward compatibility.
|
|
857
|
+
*/
|
|
858
|
+
clearSession(e = "expired") {
|
|
859
|
+
const t = e === "logout";
|
|
860
|
+
t && (this.logoutInFlight = !0), this.sessionGeneration++, this.cancelProactiveTimer(), this.clearTokens();
|
|
861
|
+
const n = new Q("token_invalid", "Session cleared");
|
|
862
|
+
this.rejectQueue(n), this.transitionTo(t ? "idle" : "expired"), this.notify(), t && (this.logoutInFlight = !1);
|
|
726
863
|
}
|
|
727
864
|
/**
|
|
728
865
|
* Dispose of this SessionManager instance.
|
|
729
866
|
* Cancels all timers and rejects pending queue entries.
|
|
730
867
|
*/
|
|
731
868
|
destroy() {
|
|
732
|
-
this.isDestroyed = !0,
|
|
733
|
-
const e = new
|
|
869
|
+
this.isDestroyed = !0, ye.delete(this.storageKey), this.cancelProactiveTimer(), this.detachVisibilityListener(), this.detachStorageListener(), this.listeners.clear();
|
|
870
|
+
const e = new Q("token_invalid", "SessionManager destroyed");
|
|
734
871
|
this.rejectQueue(e);
|
|
735
872
|
}
|
|
736
873
|
// --- JWT helpers ---
|
|
737
874
|
getTokenPayload() {
|
|
738
875
|
var t, n;
|
|
739
876
|
const e = (t = this.getTokens()) == null ? void 0 : t.accessToken;
|
|
740
|
-
return e ? ((n =
|
|
877
|
+
return e ? ((n = Pe(e)) == null ? void 0 : n.payload) ?? null : null;
|
|
741
878
|
}
|
|
742
879
|
/**
|
|
743
880
|
* Get userId from token (source of truth) or fallback to stored user
|
|
@@ -757,9 +894,9 @@ const ie = class ie {
|
|
|
757
894
|
return new Promise((t) => setTimeout(t, e));
|
|
758
895
|
}
|
|
759
896
|
};
|
|
760
|
-
|
|
761
|
-
let
|
|
762
|
-
class
|
|
897
|
+
de.MAX_BACKGROUND_FAILURES = 3;
|
|
898
|
+
let Ue = de;
|
|
899
|
+
class Bt {
|
|
763
900
|
constructor(e) {
|
|
764
901
|
this.httpService = e, this.verificationCache = /* @__PURE__ */ new Map(), this.VERIFY_CACHE_TTL_MS = 6e4, this.pendingMagicLinks = /* @__PURE__ */ new Map();
|
|
765
902
|
}
|
|
@@ -816,10 +953,10 @@ class Ct {
|
|
|
816
953
|
"/auth/magic-link/verify",
|
|
817
954
|
e,
|
|
818
955
|
{ skipAuth: !0 }
|
|
819
|
-
),
|
|
820
|
-
return this.verificationCache.set(t,
|
|
956
|
+
), o = { promise: i };
|
|
957
|
+
return this.verificationCache.set(t, o), i.then(
|
|
821
958
|
() => {
|
|
822
|
-
|
|
959
|
+
o.timer = setTimeout(
|
|
823
960
|
() => this.verificationCache.delete(t),
|
|
824
961
|
this.VERIFY_CACHE_TTL_MS
|
|
825
962
|
);
|
|
@@ -836,7 +973,7 @@ class Ct {
|
|
|
836
973
|
await this.httpService.post("/auth/change-password", e);
|
|
837
974
|
}
|
|
838
975
|
}
|
|
839
|
-
class
|
|
976
|
+
class _t {
|
|
840
977
|
constructor(e) {
|
|
841
978
|
this.httpService = e;
|
|
842
979
|
}
|
|
@@ -854,7 +991,7 @@ class Dt {
|
|
|
854
991
|
}
|
|
855
992
|
async getRolesByApp(e, t) {
|
|
856
993
|
const n = await this.httpService.get(
|
|
857
|
-
`/roles/app/${e}${
|
|
994
|
+
`/roles/app/${e}${le(t)}`,
|
|
858
995
|
{ skipAuth: !0 }
|
|
859
996
|
);
|
|
860
997
|
return { roles: n.data, meta: n.meta };
|
|
@@ -867,12 +1004,12 @@ class Dt {
|
|
|
867
1004
|
}
|
|
868
1005
|
async getUserRoles(e, t) {
|
|
869
1006
|
const n = await this.httpService.get(
|
|
870
|
-
`/roles/user/${e}${
|
|
1007
|
+
`/roles/user/${e}${le(t)}`
|
|
871
1008
|
);
|
|
872
1009
|
return { roles: n.data, meta: n.meta };
|
|
873
1010
|
}
|
|
874
1011
|
}
|
|
875
|
-
class
|
|
1012
|
+
class Ot {
|
|
876
1013
|
constructor(e) {
|
|
877
1014
|
this.httpService = e;
|
|
878
1015
|
}
|
|
@@ -881,7 +1018,7 @@ class Mt {
|
|
|
881
1018
|
}
|
|
882
1019
|
async getUsers(e) {
|
|
883
1020
|
const t = await this.httpService.get(
|
|
884
|
-
`/users/${
|
|
1021
|
+
`/users/${le(e)}`
|
|
885
1022
|
);
|
|
886
1023
|
return { users: t.data, meta: t.meta };
|
|
887
1024
|
}
|
|
@@ -895,7 +1032,7 @@ class Mt {
|
|
|
895
1032
|
await this.httpService.delete(`/users/${e}`);
|
|
896
1033
|
}
|
|
897
1034
|
}
|
|
898
|
-
class
|
|
1035
|
+
class we {
|
|
899
1036
|
constructor(e, t) {
|
|
900
1037
|
this.httpService = e, this.appId = t;
|
|
901
1038
|
}
|
|
@@ -904,7 +1041,7 @@ class be {
|
|
|
904
1041
|
}
|
|
905
1042
|
async getTenants(e) {
|
|
906
1043
|
const t = await this.httpService.get(
|
|
907
|
-
`/tenants/${
|
|
1044
|
+
`/tenants/${le(e)}`
|
|
908
1045
|
);
|
|
909
1046
|
return { tenants: t.data, meta: t.meta };
|
|
910
1047
|
}
|
|
@@ -939,40 +1076,40 @@ class be {
|
|
|
939
1076
|
)).data;
|
|
940
1077
|
}
|
|
941
1078
|
}
|
|
942
|
-
function
|
|
1079
|
+
function Vt(r, e) {
|
|
943
1080
|
if (r === "localhost" || r.startsWith("127.") || r.startsWith("192.168."))
|
|
944
1081
|
return null;
|
|
945
1082
|
if (e) {
|
|
946
|
-
const i = e.toLowerCase(),
|
|
947
|
-
if (
|
|
1083
|
+
const i = e.toLowerCase(), o = r.toLowerCase();
|
|
1084
|
+
if (o === i || o === `www.${i}`)
|
|
948
1085
|
return null;
|
|
949
|
-
if (
|
|
950
|
-
const
|
|
951
|
-
return
|
|
1086
|
+
if (o.endsWith(`.${i}`)) {
|
|
1087
|
+
const a = o.slice(0, -(i.length + 1));
|
|
1088
|
+
return a === "www" ? null : a;
|
|
952
1089
|
}
|
|
953
1090
|
return null;
|
|
954
1091
|
}
|
|
955
1092
|
const n = r.split(".");
|
|
956
1093
|
return n.length >= 3 && n[0] !== "www" ? n[0] : null;
|
|
957
1094
|
}
|
|
958
|
-
function
|
|
1095
|
+
function qt(r, e = "tenant", t) {
|
|
959
1096
|
const i = new URLSearchParams(r).get(e);
|
|
960
1097
|
return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
|
|
961
1098
|
}
|
|
962
|
-
function
|
|
963
|
-
const { tenantMode: n, baseDomain: i, selectorParam:
|
|
964
|
-
return n === "fixed" ?
|
|
1099
|
+
function zt(r, e, t) {
|
|
1100
|
+
const { tenantMode: n, baseDomain: i, selectorParam: o, fixedTenantSlug: a } = r;
|
|
1101
|
+
return n === "fixed" ? a || null : n === "subdomain" ? Vt(e.hostname, i) : n === "selector" ? qt(e.search, o, t) : null;
|
|
965
1102
|
}
|
|
966
|
-
function
|
|
1103
|
+
function Gt(r, e, t) {
|
|
967
1104
|
if (t)
|
|
968
1105
|
return `${r}.${t}`;
|
|
969
1106
|
const n = e.split(".");
|
|
970
1107
|
return n.length === 2 ? `${r}.${e}` : n.length >= 3 ? (n[0] = r, n.join(".")) : null;
|
|
971
1108
|
}
|
|
972
|
-
const
|
|
973
|
-
function
|
|
974
|
-
var
|
|
975
|
-
const { baseUrl: t, appInfo: n, appId: i } = Ae(),
|
|
1109
|
+
const Oe = fe(null);
|
|
1110
|
+
function Lr({ config: r, children: e }) {
|
|
1111
|
+
var z, Z, K;
|
|
1112
|
+
const { baseUrl: t, appInfo: n, appId: i } = Ae(), o = te(() => typeof window > "u" ? null : zt(
|
|
976
1113
|
{
|
|
977
1114
|
tenantMode: r.tenantMode || "selector",
|
|
978
1115
|
baseDomain: r.baseDomain,
|
|
@@ -984,111 +1121,111 @@ function xr({ config: r, children: e }) {
|
|
|
984
1121
|
search: window.location.search
|
|
985
1122
|
},
|
|
986
1123
|
window.localStorage
|
|
987
|
-
), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [
|
|
988
|
-
() => ({ enabled:
|
|
989
|
-
[
|
|
990
|
-
), [d,
|
|
1124
|
+
), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [a, p] = C(() => o()), k = ((z = r.cache) == null ? void 0 : z.enabled) ?? !0, E = ((Z = r.cache) == null ? void 0 : Z.ttl) ?? 300 * 1e3, S = ((K = r.cache) == null ? void 0 : K.storageKey) ?? `tenant_cache_${a || "default"}`, c = O(
|
|
1125
|
+
() => ({ enabled: k, ttl: E, storageKey: S }),
|
|
1126
|
+
[k, E, S]
|
|
1127
|
+
), [d, x] = C(() => {
|
|
991
1128
|
if (r.initialTenant) return r.initialTenant;
|
|
992
|
-
if (!c.enabled || !
|
|
1129
|
+
if (!c.enabled || !a) return null;
|
|
993
1130
|
try {
|
|
994
|
-
const
|
|
995
|
-
if (!
|
|
996
|
-
const
|
|
997
|
-
return Date.now() -
|
|
1131
|
+
const D = localStorage.getItem(c.storageKey);
|
|
1132
|
+
if (!D) return null;
|
|
1133
|
+
const F = JSON.parse(D);
|
|
1134
|
+
return Date.now() - F.timestamp < c.ttl && F.tenantSlug === a ? F.data : (localStorage.removeItem(c.storageKey), null);
|
|
998
1135
|
} catch {
|
|
999
1136
|
return null;
|
|
1000
1137
|
}
|
|
1001
|
-
}), [
|
|
1138
|
+
}), [I, L] = C(!d && !r.initialTenant), [P, R] = C(null), [m, g] = C(null), [b, w] = C(!1), [l, h] = C(null);
|
|
1002
1139
|
re(() => {
|
|
1003
1140
|
if (r.tenantMode === "fixed") return;
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
}, [
|
|
1007
|
-
const
|
|
1008
|
-
async (
|
|
1009
|
-
if (!(!
|
|
1141
|
+
const D = o();
|
|
1142
|
+
p(D);
|
|
1143
|
+
}, [o, r.tenantMode]);
|
|
1144
|
+
const A = (n == null ? void 0 : n.settingsSchema) || null, y = te(
|
|
1145
|
+
async (D, F = !1) => {
|
|
1146
|
+
if (!(!F && c.enabled && d && d.subdomain === D))
|
|
1010
1147
|
try {
|
|
1011
|
-
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1148
|
+
L(!0), R(null);
|
|
1149
|
+
const _ = new he(t), G = await new we(_, i).getPublicTenantInfo(D);
|
|
1150
|
+
if (x(G), c.enabled)
|
|
1014
1151
|
try {
|
|
1015
1152
|
const Y = {
|
|
1016
|
-
data:
|
|
1153
|
+
data: G,
|
|
1017
1154
|
timestamp: Date.now(),
|
|
1018
|
-
tenantSlug:
|
|
1155
|
+
tenantSlug: D
|
|
1019
1156
|
};
|
|
1020
1157
|
localStorage.setItem(c.storageKey, JSON.stringify(Y));
|
|
1021
1158
|
} catch (Y) {
|
|
1022
1159
|
process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", Y);
|
|
1023
1160
|
}
|
|
1024
|
-
} catch (
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1161
|
+
} catch (_) {
|
|
1162
|
+
const B = _ instanceof Error ? _ : new Error("Failed to load tenant information");
|
|
1163
|
+
R(B), x(null);
|
|
1027
1164
|
} finally {
|
|
1028
|
-
|
|
1165
|
+
L(!1);
|
|
1029
1166
|
}
|
|
1030
1167
|
},
|
|
1031
1168
|
[t, i, c, d]
|
|
1032
1169
|
), u = te(async () => {
|
|
1033
|
-
if (!(!c.enabled || !d || !
|
|
1170
|
+
if (!(!c.enabled || !d || !a))
|
|
1034
1171
|
try {
|
|
1035
|
-
const
|
|
1036
|
-
if (!
|
|
1037
|
-
const
|
|
1038
|
-
if (Date.now() -
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1172
|
+
const D = localStorage.getItem(c.storageKey);
|
|
1173
|
+
if (!D) return;
|
|
1174
|
+
const F = JSON.parse(D);
|
|
1175
|
+
if (Date.now() - F.timestamp > c.ttl * 0.5) {
|
|
1176
|
+
const B = new he(t), Y = await new we(B, i).getPublicTenantInfo(a);
|
|
1177
|
+
x(Y);
|
|
1041
1178
|
const X = {
|
|
1042
1179
|
data: Y,
|
|
1043
1180
|
timestamp: Date.now(),
|
|
1044
|
-
tenantSlug:
|
|
1181
|
+
tenantSlug: a
|
|
1045
1182
|
};
|
|
1046
1183
|
localStorage.setItem(c.storageKey, JSON.stringify(X));
|
|
1047
1184
|
}
|
|
1048
|
-
} catch (
|
|
1049
|
-
process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:",
|
|
1185
|
+
} catch (D) {
|
|
1186
|
+
process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", D);
|
|
1050
1187
|
}
|
|
1051
|
-
}, [t, i, c, d,
|
|
1188
|
+
}, [t, i, c, d, a]), T = te(async () => {
|
|
1052
1189
|
if (d != null && d.id)
|
|
1053
1190
|
try {
|
|
1054
|
-
|
|
1055
|
-
const
|
|
1056
|
-
g(
|
|
1057
|
-
} catch (
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1191
|
+
w(!0), h(null);
|
|
1192
|
+
const D = new he(t), _ = await new we(D, d.appId).getTenantSettings(d.id);
|
|
1193
|
+
g(_);
|
|
1194
|
+
} catch (D) {
|
|
1195
|
+
const F = D instanceof Error ? D : new Error("Failed to load tenant settings");
|
|
1196
|
+
h(F), g(null);
|
|
1060
1197
|
} finally {
|
|
1061
|
-
|
|
1198
|
+
w(!1);
|
|
1062
1199
|
}
|
|
1063
|
-
}, [t, d]),
|
|
1064
|
-
|
|
1065
|
-
}, [
|
|
1066
|
-
(
|
|
1067
|
-
if (!
|
|
1200
|
+
}, [t, d]), M = te(() => {
|
|
1201
|
+
T();
|
|
1202
|
+
}, [T]), se = te(
|
|
1203
|
+
(D) => {
|
|
1204
|
+
if (!A)
|
|
1068
1205
|
return { isValid: !0, errors: [] };
|
|
1069
|
-
const
|
|
1206
|
+
const F = [];
|
|
1070
1207
|
try {
|
|
1071
|
-
return
|
|
1208
|
+
return A.properties && Object.entries(A.properties).forEach(([_, B]) => {
|
|
1072
1209
|
var Y;
|
|
1073
|
-
const
|
|
1074
|
-
if ((Y =
|
|
1075
|
-
|
|
1210
|
+
const G = D[_];
|
|
1211
|
+
if ((Y = A.required) != null && Y.includes(_) && G == null) {
|
|
1212
|
+
F.push(`Field '${_}' is required`);
|
|
1076
1213
|
return;
|
|
1077
1214
|
}
|
|
1078
|
-
if (
|
|
1079
|
-
if (
|
|
1080
|
-
const X =
|
|
1081
|
-
X === "string" &&
|
|
1215
|
+
if (G != null) {
|
|
1216
|
+
if (B.type) {
|
|
1217
|
+
const X = B.type, ae = typeof G;
|
|
1218
|
+
X === "string" && ae !== "string" ? F.push(`Field '${_}' must be a string`) : (X === "number" || X === "integer") && ae !== "number" ? F.push(`Field '${_}' must be a number`) : X === "boolean" && ae !== "boolean" ? F.push(`Field '${_}' must be a boolean`) : X === "array" && !Array.isArray(G) && F.push(`Field '${_}' must be an array`);
|
|
1082
1219
|
}
|
|
1083
|
-
|
|
1084
|
-
`Field '${
|
|
1085
|
-
),
|
|
1086
|
-
`Field '${
|
|
1087
|
-
),
|
|
1220
|
+
B.minLength !== void 0 && typeof G == "string" && G.length < B.minLength && F.push(
|
|
1221
|
+
`Field '${_}' must be at least ${B.minLength} characters long`
|
|
1222
|
+
), B.maxLength !== void 0 && typeof G == "string" && G.length > B.maxLength && F.push(
|
|
1223
|
+
`Field '${_}' must be no more than ${B.maxLength} characters long`
|
|
1224
|
+
), B.minimum !== void 0 && typeof G == "number" && G < B.minimum && F.push(`Field '${_}' must be at least ${B.minimum}`), B.maximum !== void 0 && typeof G == "number" && G > B.maximum && F.push(`Field '${_}' must be no more than ${B.maximum}`), B.pattern && typeof G == "string" && (new RegExp(B.pattern).test(G) || F.push(`Field '${_}' does not match the required pattern`)), B.enum && !B.enum.includes(G) && F.push(`Field '${_}' must be one of: ${B.enum.join(", ")}`);
|
|
1088
1225
|
}
|
|
1089
1226
|
}), {
|
|
1090
|
-
isValid:
|
|
1091
|
-
errors:
|
|
1227
|
+
isValid: F.length === 0,
|
|
1228
|
+
errors: F
|
|
1092
1229
|
};
|
|
1093
1230
|
} catch {
|
|
1094
1231
|
return {
|
|
@@ -1097,26 +1234,26 @@ function xr({ config: r, children: e }) {
|
|
|
1097
1234
|
};
|
|
1098
1235
|
}
|
|
1099
1236
|
},
|
|
1100
|
-
[
|
|
1237
|
+
[A]
|
|
1101
1238
|
);
|
|
1102
1239
|
re(() => {
|
|
1103
|
-
!r.initialTenant &&
|
|
1104
|
-
}, [r.initialTenant,
|
|
1105
|
-
d != null && d.id ?
|
|
1106
|
-
}, [d == null ? void 0 : d.id,
|
|
1107
|
-
const
|
|
1108
|
-
(
|
|
1109
|
-
const { mode:
|
|
1110
|
-
if (
|
|
1240
|
+
!r.initialTenant && a ? d ? u() : y(a) : !r.initialTenant && !a && (x(null), R(null), L(!1));
|
|
1241
|
+
}, [r.initialTenant, a, d, y, u]), re(() => {
|
|
1242
|
+
d != null && d.id ? T() : (g(null), h(null), w(!1));
|
|
1243
|
+
}, [d == null ? void 0 : d.id, T]);
|
|
1244
|
+
const N = te(
|
|
1245
|
+
(D, F) => {
|
|
1246
|
+
const { mode: _ = "reload", redirectPath: B } = F || {}, G = r.tenantMode || "selector";
|
|
1247
|
+
if (G === "fixed") {
|
|
1111
1248
|
process.env.NODE_ENV === "development" && console.warn(
|
|
1112
1249
|
"[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
|
|
1113
1250
|
r.fixedTenantSlug
|
|
1114
|
-
),
|
|
1251
|
+
), B && (window.location.href = B);
|
|
1115
1252
|
return;
|
|
1116
1253
|
}
|
|
1117
|
-
if (localStorage.setItem("tenant",
|
|
1118
|
-
const Y = window.location.hostname, X =
|
|
1119
|
-
|
|
1254
|
+
if (localStorage.setItem("tenant", D), G === "subdomain") {
|
|
1255
|
+
const Y = window.location.hostname, X = Gt(
|
|
1256
|
+
D,
|
|
1120
1257
|
Y,
|
|
1121
1258
|
r.baseDomain
|
|
1122
1259
|
);
|
|
@@ -1127,68 +1264,68 @@ function xr({ config: r, children: e }) {
|
|
|
1127
1264
|
);
|
|
1128
1265
|
return;
|
|
1129
1266
|
}
|
|
1130
|
-
const
|
|
1131
|
-
new URLSearchParams(window.location.search).forEach((
|
|
1132
|
-
|
|
1133
|
-
}), window.location.href =
|
|
1134
|
-
} else if (
|
|
1135
|
-
const Y =
|
|
1136
|
-
if (X.set(r.selectorParam || "tenant",
|
|
1137
|
-
const
|
|
1138
|
-
window.location.href =
|
|
1267
|
+
const ae = B || window.location.pathname, ke = new URL(`${window.location.protocol}//${X}${ae}`);
|
|
1268
|
+
new URLSearchParams(window.location.search).forEach((Ne, Ce) => {
|
|
1269
|
+
ke.searchParams.set(Ce, Ne);
|
|
1270
|
+
}), window.location.href = ke.toString();
|
|
1271
|
+
} else if (G === "selector") {
|
|
1272
|
+
const Y = B || window.location.pathname, X = new URLSearchParams(window.location.search);
|
|
1273
|
+
if (X.set(r.selectorParam || "tenant", D), _ === "reload") {
|
|
1274
|
+
const ae = `${Y}?${X.toString()}${window.location.hash}`;
|
|
1275
|
+
window.location.href = ae;
|
|
1139
1276
|
} else {
|
|
1140
|
-
const
|
|
1141
|
-
window.history.pushState({}, "",
|
|
1277
|
+
const ae = `${Y}?${X.toString()}${window.location.hash}`;
|
|
1278
|
+
window.history.pushState({}, "", ae), p(D), y(D);
|
|
1142
1279
|
}
|
|
1143
1280
|
}
|
|
1144
1281
|
},
|
|
1145
1282
|
[r.tenantMode, r.selectorParam, r.baseDomain, r.fixedTenantSlug, y]
|
|
1146
|
-
),
|
|
1283
|
+
), W = O(() => ({
|
|
1147
1284
|
// Tenant info
|
|
1148
1285
|
tenant: d,
|
|
1149
|
-
tenantSlug:
|
|
1150
|
-
isTenantLoading:
|
|
1151
|
-
tenantError:
|
|
1286
|
+
tenantSlug: a,
|
|
1287
|
+
isTenantLoading: I,
|
|
1288
|
+
tenantError: P,
|
|
1152
1289
|
retryTenant: () => {
|
|
1153
|
-
|
|
1290
|
+
a && y(a);
|
|
1154
1291
|
},
|
|
1155
1292
|
// Settings
|
|
1156
1293
|
settings: m,
|
|
1157
|
-
settingsSchema:
|
|
1294
|
+
settingsSchema: A,
|
|
1158
1295
|
isSettingsLoading: b,
|
|
1159
|
-
settingsError:
|
|
1296
|
+
settingsError: l,
|
|
1160
1297
|
// Actions
|
|
1161
|
-
refreshSettings:
|
|
1162
|
-
switchTenant:
|
|
1298
|
+
refreshSettings: M,
|
|
1299
|
+
switchTenant: N,
|
|
1163
1300
|
// Validation
|
|
1164
1301
|
validateSettings: se
|
|
1165
1302
|
}), [
|
|
1166
1303
|
d,
|
|
1167
|
-
|
|
1304
|
+
a,
|
|
1305
|
+
I,
|
|
1168
1306
|
P,
|
|
1169
|
-
R,
|
|
1170
1307
|
m,
|
|
1171
|
-
|
|
1308
|
+
A,
|
|
1172
1309
|
b,
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1310
|
+
l,
|
|
1311
|
+
M,
|
|
1312
|
+
N,
|
|
1176
1313
|
se
|
|
1177
1314
|
]);
|
|
1178
|
-
return /* @__PURE__ */ s(
|
|
1315
|
+
return /* @__PURE__ */ s(Oe.Provider, { value: W, children: e });
|
|
1179
1316
|
}
|
|
1180
|
-
function
|
|
1181
|
-
const r = ne(
|
|
1317
|
+
function Se() {
|
|
1318
|
+
const r = ne(Oe);
|
|
1182
1319
|
if (!r)
|
|
1183
1320
|
throw new Error("useTenant must be used within a TenantProvider");
|
|
1184
1321
|
return r;
|
|
1185
1322
|
}
|
|
1186
1323
|
function pe() {
|
|
1187
|
-
return ne(
|
|
1324
|
+
return ne(Oe);
|
|
1188
1325
|
}
|
|
1189
|
-
const
|
|
1190
|
-
function
|
|
1191
|
-
const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } =
|
|
1326
|
+
const Fr = Se;
|
|
1327
|
+
function Nr() {
|
|
1328
|
+
const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = Se();
|
|
1192
1329
|
return {
|
|
1193
1330
|
settings: r,
|
|
1194
1331
|
settingsSchema: e,
|
|
@@ -1197,8 +1334,8 @@ function Rr() {
|
|
|
1197
1334
|
validateSettings: i
|
|
1198
1335
|
};
|
|
1199
1336
|
}
|
|
1200
|
-
function
|
|
1201
|
-
const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } =
|
|
1337
|
+
function ct() {
|
|
1338
|
+
const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } = Se();
|
|
1202
1339
|
return {
|
|
1203
1340
|
tenant: r,
|
|
1204
1341
|
tenantSlug: e,
|
|
@@ -1207,380 +1344,392 @@ function ot() {
|
|
|
1207
1344
|
retry: i
|
|
1208
1345
|
};
|
|
1209
1346
|
}
|
|
1210
|
-
const
|
|
1211
|
-
function
|
|
1347
|
+
const Ve = "userTenants";
|
|
1348
|
+
function jt() {
|
|
1212
1349
|
try {
|
|
1213
|
-
const r = localStorage.getItem(
|
|
1350
|
+
const r = localStorage.getItem(Ve);
|
|
1214
1351
|
return r ? JSON.parse(r) : [];
|
|
1215
1352
|
} catch {
|
|
1216
1353
|
return [];
|
|
1217
1354
|
}
|
|
1218
1355
|
}
|
|
1219
|
-
function
|
|
1356
|
+
function nt(r) {
|
|
1220
1357
|
try {
|
|
1221
|
-
localStorage.setItem(
|
|
1358
|
+
localStorage.setItem(Ve, JSON.stringify(r));
|
|
1222
1359
|
} catch {
|
|
1223
1360
|
}
|
|
1224
1361
|
}
|
|
1225
|
-
function
|
|
1362
|
+
function De() {
|
|
1226
1363
|
try {
|
|
1227
|
-
localStorage.removeItem(
|
|
1364
|
+
localStorage.removeItem(Ve);
|
|
1228
1365
|
} catch {
|
|
1229
1366
|
}
|
|
1230
1367
|
}
|
|
1231
|
-
const
|
|
1232
|
-
function
|
|
1233
|
-
const t =
|
|
1368
|
+
const Ie = fe(null), Le = fe(null);
|
|
1369
|
+
function Cr({ config: r = {}, children: e }) {
|
|
1370
|
+
const t = _e(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? r.baseUrl ?? "", o = (t == null ? void 0 : t.appId) ?? r.appId, a = (n == null ? void 0 : n.tenant) ?? null, p = (n == null ? void 0 : n.tenantSlug) ?? null, k = (n == null ? void 0 : n.switchTenant) ?? (() => {
|
|
1234
1371
|
});
|
|
1235
1372
|
if (!i)
|
|
1236
1373
|
throw new Error(
|
|
1237
1374
|
"[AuthProvider] baseUrl is required. Provide it via AppProvider or AuthConfig.baseUrl."
|
|
1238
1375
|
);
|
|
1239
|
-
const [
|
|
1240
|
-
C.current.done || (C.current.done = !0);
|
|
1241
|
-
const o = V(() => Me.getInstance({
|
|
1376
|
+
const [E, S] = C(r.initialRoles || []), [c, d] = C(!r.initialRoles), [x, I] = C(null), [L, P] = C(!1), [R, m] = C(null), [g, b] = C(() => jt()), w = O(() => Ue.getInstance({
|
|
1242
1377
|
baseUrl: i,
|
|
1243
1378
|
enableCookieSession: r.enableCookieSession,
|
|
1244
1379
|
refreshQueueTimeout: r.refreshQueueTimeout,
|
|
1245
1380
|
proactiveRefreshMargin: r.proactiveRefreshMargin,
|
|
1246
|
-
onSessionExpired: (
|
|
1247
|
-
|
|
1381
|
+
onSessionExpired: (v) => {
|
|
1382
|
+
I(null), m(null), b([]), De(), r.onSessionExpired ? r.onSessionExpired(v) : r.onRefreshFailed && r.onRefreshFailed();
|
|
1248
1383
|
}
|
|
1249
1384
|
}), [
|
|
1250
1385
|
i,
|
|
1251
1386
|
r.enableCookieSession,
|
|
1252
1387
|
r.refreshQueueTimeout,
|
|
1253
1388
|
r.proactiveRefreshMargin
|
|
1254
|
-
]),
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1389
|
+
]), l = Et(
|
|
1390
|
+
(v) => w.subscribe(v),
|
|
1391
|
+
() => w.getSnapshot(),
|
|
1392
|
+
() => 0
|
|
1393
|
+
), [h, A] = C(!1), y = h, u = O(() => {
|
|
1394
|
+
const v = new he(i);
|
|
1395
|
+
return v.setSessionManager(w), v;
|
|
1396
|
+
}, [i, w]), T = O(
|
|
1397
|
+
() => new Bt(u),
|
|
1262
1398
|
[u]
|
|
1263
|
-
),
|
|
1264
|
-
() => new
|
|
1399
|
+
), M = O(
|
|
1400
|
+
() => new Ot(u),
|
|
1265
1401
|
[u]
|
|
1266
|
-
), se =
|
|
1267
|
-
() => new
|
|
1402
|
+
), se = O(
|
|
1403
|
+
() => new _t(u),
|
|
1268
1404
|
[u]
|
|
1269
|
-
),
|
|
1270
|
-
() =>
|
|
1271
|
-
[
|
|
1272
|
-
), K =
|
|
1405
|
+
), N = O(() => x != null && x.roleId && E.find((v) => v.id === x.roleId) || null, [x, E]), W = O(() => (N == null ? void 0 : N.permissions) || [], [N]), z = O(
|
|
1406
|
+
() => w.hasValidSession() && x !== null,
|
|
1407
|
+
[w, x, l]
|
|
1408
|
+
), Z = O(() => h ? w.getState() === "expired" ? "expired" : w.getRefreshInFlight() ? "refreshing" : w.hasValidSession() && x !== null ? "authenticated" : "unauthenticated" : "initializing", [w, h, x, l]), K = O(() => (x == null ? void 0 : x.tenantId) != null, [x]), D = be(null), F = be(/* @__PURE__ */ new Set()), _ = async (v = !1) => {
|
|
1273
1409
|
try {
|
|
1274
|
-
if (!
|
|
1275
|
-
const
|
|
1276
|
-
if (
|
|
1410
|
+
if (!w.hasValidSession() || !v && x) return;
|
|
1411
|
+
const $ = w.getUserId();
|
|
1412
|
+
if (!$) {
|
|
1277
1413
|
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] No userId available in token or storage");
|
|
1278
1414
|
return;
|
|
1279
1415
|
}
|
|
1280
|
-
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
} catch (
|
|
1284
|
-
const
|
|
1285
|
-
m(
|
|
1416
|
+
P(!0), m(null);
|
|
1417
|
+
const V = await M.getUserById($);
|
|
1418
|
+
I(V), w.setUser(V);
|
|
1419
|
+
} catch ($) {
|
|
1420
|
+
const V = $ instanceof Error ? $ : new Error("Failed to load user data");
|
|
1421
|
+
m(V), process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data:", V);
|
|
1286
1422
|
} finally {
|
|
1287
|
-
|
|
1423
|
+
P(!1);
|
|
1288
1424
|
}
|
|
1289
|
-
},
|
|
1290
|
-
var
|
|
1291
|
-
const { username:
|
|
1292
|
-
let ee =
|
|
1293
|
-
|
|
1294
|
-
const
|
|
1295
|
-
username:
|
|
1296
|
-
password:
|
|
1297
|
-
appId:
|
|
1425
|
+
}, B = async (v) => {
|
|
1426
|
+
var Ke;
|
|
1427
|
+
const { username: $, password: V, tenantSlug: q, redirectPath: J } = v;
|
|
1428
|
+
let ee = a == null ? void 0 : a.id, H = p;
|
|
1429
|
+
q && (ee = (await new we(u, o).getPublicTenantInfo(q)).id, H = q);
|
|
1430
|
+
const j = await T.login({
|
|
1431
|
+
username: $,
|
|
1432
|
+
password: V,
|
|
1433
|
+
appId: o,
|
|
1298
1434
|
tenantId: ee
|
|
1299
|
-
}),
|
|
1300
|
-
if (
|
|
1301
|
-
accessToken:
|
|
1302
|
-
refreshToken:
|
|
1303
|
-
expiresIn:
|
|
1304
|
-
}),
|
|
1305
|
-
|
|
1435
|
+
}), Ee = q && q !== p;
|
|
1436
|
+
if (w.setTokens({
|
|
1437
|
+
accessToken: j.accessToken,
|
|
1438
|
+
refreshToken: j.refreshToken,
|
|
1439
|
+
expiresIn: j.expiresIn
|
|
1440
|
+
}), j.user) {
|
|
1441
|
+
w.setUser(j.user), I(j.user);
|
|
1306
1442
|
try {
|
|
1307
|
-
await
|
|
1308
|
-
} catch (
|
|
1309
|
-
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:",
|
|
1443
|
+
await _();
|
|
1444
|
+
} catch (xe) {
|
|
1445
|
+
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", xe);
|
|
1310
1446
|
}
|
|
1311
1447
|
}
|
|
1312
|
-
|
|
1313
|
-
const
|
|
1314
|
-
if (
|
|
1315
|
-
return
|
|
1448
|
+
j.tenants && j.tenants.length > 0 && (b(j.tenants), nt(j.tenants));
|
|
1449
|
+
const Je = ((Ke = j.user) == null ? void 0 : Ke.tenantId) !== null;
|
|
1450
|
+
if (Ee && H)
|
|
1451
|
+
return k(H, { redirectPath: J }), j;
|
|
1316
1452
|
if (J && J !== window.location.pathname)
|
|
1317
|
-
return
|
|
1318
|
-
if (!
|
|
1319
|
-
const
|
|
1320
|
-
if (
|
|
1321
|
-
const
|
|
1322
|
-
return
|
|
1323
|
-
} else
|
|
1453
|
+
return k(H || p || "", { redirectPath: J }), j;
|
|
1454
|
+
if (!Je && j.tenants && j.tenants.length > 0) {
|
|
1455
|
+
const xe = v.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
|
|
1456
|
+
if (j.tenants.length === 1 && xe) {
|
|
1457
|
+
const Ze = j.tenants[0];
|
|
1458
|
+
return k(Ze.subdomain, { redirectPath: J }), j;
|
|
1459
|
+
} else j.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(j.tenants);
|
|
1324
1460
|
}
|
|
1325
|
-
return
|
|
1326
|
-
},
|
|
1327
|
-
const { email:
|
|
1328
|
-
if (
|
|
1461
|
+
return j;
|
|
1462
|
+
}, G = async (v) => {
|
|
1463
|
+
const { email: $, phoneNumber: V, name: q, password: J, lastName: ee, tenantId: H } = v;
|
|
1464
|
+
if (!$ && !V)
|
|
1329
1465
|
throw new Error("Either email or phoneNumber is required");
|
|
1330
|
-
if (!
|
|
1466
|
+
if (!q || !J)
|
|
1331
1467
|
throw new Error("Name and password are required");
|
|
1332
|
-
return
|
|
1333
|
-
email:
|
|
1334
|
-
phoneNumber:
|
|
1335
|
-
name:
|
|
1468
|
+
return T.signup({
|
|
1469
|
+
email: $,
|
|
1470
|
+
phoneNumber: V,
|
|
1471
|
+
name: q,
|
|
1336
1472
|
password: J,
|
|
1337
|
-
tenantId:
|
|
1473
|
+
tenantId: H ?? (a == null ? void 0 : a.id),
|
|
1338
1474
|
lastName: ee,
|
|
1339
|
-
appId:
|
|
1475
|
+
appId: o
|
|
1340
1476
|
});
|
|
1341
|
-
},
|
|
1342
|
-
const { email:
|
|
1343
|
-
if (
|
|
1477
|
+
}, Y = async (v) => {
|
|
1478
|
+
const { email: $, phoneNumber: V, name: q, password: J, tenantName: ee, lastName: H } = v;
|
|
1479
|
+
if (!$ && !V)
|
|
1344
1480
|
throw new Error("Either email or phoneNumber is required");
|
|
1345
|
-
if (!
|
|
1481
|
+
if (!q || !J || !ee)
|
|
1346
1482
|
throw new Error("Name, password, and tenantName are required");
|
|
1347
|
-
return
|
|
1348
|
-
email:
|
|
1349
|
-
phoneNumber:
|
|
1350
|
-
name:
|
|
1483
|
+
return T.signupTenantAdmin({
|
|
1484
|
+
email: $,
|
|
1485
|
+
phoneNumber: V,
|
|
1486
|
+
name: q,
|
|
1351
1487
|
password: J,
|
|
1352
1488
|
tenantName: ee,
|
|
1353
|
-
appId:
|
|
1354
|
-
lastName:
|
|
1489
|
+
appId: o,
|
|
1490
|
+
lastName: H
|
|
1355
1491
|
});
|
|
1356
|
-
},
|
|
1357
|
-
await
|
|
1358
|
-
},
|
|
1359
|
-
const { email:
|
|
1360
|
-
if (!
|
|
1492
|
+
}, X = async (v) => {
|
|
1493
|
+
await T.changePassword(v);
|
|
1494
|
+
}, ae = async (v) => {
|
|
1495
|
+
const { email: $, tenantId: V } = v, q = V ?? (a == null ? void 0 : a.id);
|
|
1496
|
+
if (!q)
|
|
1361
1497
|
throw new Error("tenantId is required for password reset");
|
|
1362
|
-
await
|
|
1363
|
-
},
|
|
1364
|
-
await
|
|
1365
|
-
},
|
|
1366
|
-
const { email:
|
|
1367
|
-
if (!
|
|
1498
|
+
await T.requestPasswordReset({ email: $, tenantId: q });
|
|
1499
|
+
}, ke = async (v) => {
|
|
1500
|
+
await T.confirmPasswordReset(v);
|
|
1501
|
+
}, He = async (v) => {
|
|
1502
|
+
const { email: $, frontendUrl: V, name: q, lastName: J, tenantId: ee } = v, H = ee ?? (a == null ? void 0 : a.id);
|
|
1503
|
+
if (!H)
|
|
1368
1504
|
throw new Error("tenantId is required for magic link authentication");
|
|
1369
|
-
return
|
|
1370
|
-
email:
|
|
1371
|
-
tenantId:
|
|
1372
|
-
frontendUrl:
|
|
1373
|
-
name:
|
|
1505
|
+
return T.sendMagicLink({
|
|
1506
|
+
email: $,
|
|
1507
|
+
tenantId: H,
|
|
1508
|
+
frontendUrl: V,
|
|
1509
|
+
name: q,
|
|
1374
1510
|
lastName: J,
|
|
1375
|
-
appId:
|
|
1511
|
+
appId: o
|
|
1376
1512
|
});
|
|
1377
|
-
},
|
|
1378
|
-
const { token:
|
|
1379
|
-
let J =
|
|
1380
|
-
|
|
1381
|
-
const
|
|
1382
|
-
token:
|
|
1383
|
-
email:
|
|
1384
|
-
appId:
|
|
1513
|
+
}, Ne = async (v) => {
|
|
1514
|
+
const { token: $, email: V, tenantSlug: q } = v;
|
|
1515
|
+
let J = a == null ? void 0 : a.id, ee = p;
|
|
1516
|
+
q && (J = (await new we(u, o).getPublicTenantInfo(q)).id, ee = q);
|
|
1517
|
+
const H = await T.verifyMagicLink({
|
|
1518
|
+
token: $,
|
|
1519
|
+
email: V,
|
|
1520
|
+
appId: o,
|
|
1385
1521
|
tenantId: J
|
|
1386
1522
|
});
|
|
1387
|
-
if (
|
|
1388
|
-
return
|
|
1389
|
-
|
|
1390
|
-
const
|
|
1391
|
-
if (
|
|
1392
|
-
accessToken:
|
|
1393
|
-
refreshToken:
|
|
1394
|
-
expiresIn:
|
|
1395
|
-
}),
|
|
1396
|
-
|
|
1523
|
+
if (F.current.has($))
|
|
1524
|
+
return H;
|
|
1525
|
+
F.current.add($);
|
|
1526
|
+
const j = q && q !== p;
|
|
1527
|
+
if (w.setTokens({
|
|
1528
|
+
accessToken: H.accessToken,
|
|
1529
|
+
refreshToken: H.refreshToken,
|
|
1530
|
+
expiresIn: H.expiresIn
|
|
1531
|
+
}), H.user) {
|
|
1532
|
+
w.setUser(H.user), I(H.user);
|
|
1397
1533
|
try {
|
|
1398
|
-
await
|
|
1399
|
-
} catch (
|
|
1400
|
-
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after magic link:",
|
|
1534
|
+
await _();
|
|
1535
|
+
} catch (Ee) {
|
|
1536
|
+
process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after magic link:", Ee);
|
|
1401
1537
|
}
|
|
1402
1538
|
}
|
|
1403
|
-
return
|
|
1404
|
-
},
|
|
1405
|
-
const
|
|
1406
|
-
if (!(
|
|
1539
|
+
return j && ee && ee !== p && k(ee), H;
|
|
1540
|
+
}, Ce = async () => {
|
|
1541
|
+
const v = w.getTokens();
|
|
1542
|
+
if (!(v != null && v.refreshToken))
|
|
1407
1543
|
throw new Error("No refresh token available");
|
|
1408
|
-
const
|
|
1409
|
-
refreshToken:
|
|
1544
|
+
const $ = await T.refreshToken({
|
|
1545
|
+
refreshToken: v.refreshToken
|
|
1410
1546
|
});
|
|
1411
|
-
|
|
1412
|
-
accessToken:
|
|
1413
|
-
refreshToken:
|
|
1414
|
-
expiresIn:
|
|
1547
|
+
w.setTokens({
|
|
1548
|
+
accessToken: $.accessToken,
|
|
1549
|
+
refreshToken: $.refreshToken || v.refreshToken,
|
|
1550
|
+
expiresIn: $.expiresIn
|
|
1415
1551
|
});
|
|
1416
|
-
},
|
|
1417
|
-
|
|
1418
|
-
},
|
|
1419
|
-
|
|
1420
|
-
},
|
|
1421
|
-
|
|
1422
|
-
},
|
|
1423
|
-
if (
|
|
1552
|
+
}, mt = () => {
|
|
1553
|
+
w.clearSession("logout"), I(null), m(null), b([]), De();
|
|
1554
|
+
}, gt = (v) => {
|
|
1555
|
+
w.setTokens(v);
|
|
1556
|
+
}, yt = () => w.hasValidSession(), bt = () => {
|
|
1557
|
+
w.clearSession(), I(null), m(null);
|
|
1558
|
+
}, wt = async () => {
|
|
1559
|
+
if (o)
|
|
1424
1560
|
try {
|
|
1425
1561
|
d(!0);
|
|
1426
|
-
const { roles:
|
|
1427
|
-
|
|
1428
|
-
} catch (
|
|
1429
|
-
process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:",
|
|
1562
|
+
const { roles: v } = await se.getRolesByApp(o);
|
|
1563
|
+
S(v);
|
|
1564
|
+
} catch (v) {
|
|
1565
|
+
process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", v);
|
|
1430
1566
|
} finally {
|
|
1431
1567
|
d(!1);
|
|
1432
1568
|
}
|
|
1433
|
-
},
|
|
1434
|
-
const { redirectPath:
|
|
1435
|
-
if (!(
|
|
1569
|
+
}, vt = async (v, $) => {
|
|
1570
|
+
const { redirectPath: V } = $ || {}, q = w.getTokens();
|
|
1571
|
+
if (!(q != null && q.refreshToken))
|
|
1436
1572
|
throw new Error("No refresh token available for tenant switch");
|
|
1437
|
-
const J = await
|
|
1438
|
-
refreshToken:
|
|
1439
|
-
tenantId:
|
|
1573
|
+
const J = await T.switchTenant({
|
|
1574
|
+
refreshToken: q.refreshToken,
|
|
1575
|
+
tenantId: v
|
|
1440
1576
|
});
|
|
1441
|
-
|
|
1577
|
+
w.setTokens({
|
|
1442
1578
|
accessToken: J.accessToken,
|
|
1443
|
-
refreshToken:
|
|
1579
|
+
refreshToken: q.refreshToken,
|
|
1444
1580
|
expiresIn: J.expiresIn
|
|
1445
|
-
}),
|
|
1446
|
-
const ee = g.find((
|
|
1447
|
-
ee &&
|
|
1448
|
-
},
|
|
1449
|
-
const
|
|
1450
|
-
return b(
|
|
1581
|
+
}), I(J.user), w.setUser(J.user);
|
|
1582
|
+
const ee = g.find((H) => H.id === v);
|
|
1583
|
+
ee && k(ee.subdomain, { redirectPath: V });
|
|
1584
|
+
}, Tt = async () => {
|
|
1585
|
+
const v = await T.getUserTenants();
|
|
1586
|
+
return b(v), nt(v), v;
|
|
1451
1587
|
};
|
|
1452
|
-
|
|
1453
|
-
login:
|
|
1454
|
-
signup:
|
|
1455
|
-
signupTenantAdmin:
|
|
1456
|
-
sendMagicLink:
|
|
1457
|
-
verifyMagicLink:
|
|
1458
|
-
changePassword:
|
|
1459
|
-
requestPasswordReset:
|
|
1460
|
-
confirmPasswordReset:
|
|
1461
|
-
refreshToken:
|
|
1462
|
-
logout:
|
|
1463
|
-
setTokens:
|
|
1464
|
-
hasValidSession:
|
|
1465
|
-
clearSession:
|
|
1466
|
-
loadUserData:
|
|
1467
|
-
refreshUser: () =>
|
|
1468
|
-
refreshRoles:
|
|
1469
|
-
switchToTenant:
|
|
1470
|
-
refreshUserTenants:
|
|
1588
|
+
D.current = {
|
|
1589
|
+
login: B,
|
|
1590
|
+
signup: G,
|
|
1591
|
+
signupTenantAdmin: Y,
|
|
1592
|
+
sendMagicLink: He,
|
|
1593
|
+
verifyMagicLink: Ne,
|
|
1594
|
+
changePassword: X,
|
|
1595
|
+
requestPasswordReset: ae,
|
|
1596
|
+
confirmPasswordReset: ke,
|
|
1597
|
+
refreshToken: Ce,
|
|
1598
|
+
logout: mt,
|
|
1599
|
+
setTokens: gt,
|
|
1600
|
+
hasValidSession: yt,
|
|
1601
|
+
clearSession: bt,
|
|
1602
|
+
loadUserData: _,
|
|
1603
|
+
refreshUser: () => _(),
|
|
1604
|
+
refreshRoles: wt,
|
|
1605
|
+
switchToTenant: vt,
|
|
1606
|
+
refreshUserTenants: Tt
|
|
1471
1607
|
};
|
|
1472
|
-
const
|
|
1608
|
+
const St = O(
|
|
1473
1609
|
() => ({
|
|
1474
|
-
login: (
|
|
1475
|
-
signup: (
|
|
1476
|
-
signupTenantAdmin: (
|
|
1477
|
-
sendMagicLink: (
|
|
1478
|
-
verifyMagicLink: (
|
|
1479
|
-
changePassword: (
|
|
1480
|
-
requestPasswordReset: (
|
|
1481
|
-
confirmPasswordReset: (
|
|
1482
|
-
refreshToken: () =>
|
|
1483
|
-
logout: () =>
|
|
1484
|
-
setTokens: (
|
|
1485
|
-
hasValidSession: () =>
|
|
1486
|
-
clearSession: () =>
|
|
1487
|
-
loadUserData: (
|
|
1488
|
-
refreshUser: () =>
|
|
1489
|
-
refreshRoles: () =>
|
|
1490
|
-
switchToTenant: (
|
|
1491
|
-
refreshUserTenants: () =>
|
|
1610
|
+
login: (v) => D.current.login(v),
|
|
1611
|
+
signup: (v) => D.current.signup(v),
|
|
1612
|
+
signupTenantAdmin: (v) => D.current.signupTenantAdmin(v),
|
|
1613
|
+
sendMagicLink: (v) => D.current.sendMagicLink(v),
|
|
1614
|
+
verifyMagicLink: (v) => D.current.verifyMagicLink(v),
|
|
1615
|
+
changePassword: (v) => D.current.changePassword(v),
|
|
1616
|
+
requestPasswordReset: (v) => D.current.requestPasswordReset(v),
|
|
1617
|
+
confirmPasswordReset: (v) => D.current.confirmPasswordReset(v),
|
|
1618
|
+
refreshToken: () => D.current.refreshToken(),
|
|
1619
|
+
logout: () => D.current.logout(),
|
|
1620
|
+
setTokens: (v) => D.current.setTokens(v),
|
|
1621
|
+
hasValidSession: () => D.current.hasValidSession(),
|
|
1622
|
+
clearSession: () => D.current.clearSession(),
|
|
1623
|
+
loadUserData: (v) => D.current.loadUserData(v),
|
|
1624
|
+
refreshUser: () => D.current.refreshUser(),
|
|
1625
|
+
refreshRoles: () => D.current.refreshRoles(),
|
|
1626
|
+
switchToTenant: (v, $) => D.current.switchToTenant(v, $),
|
|
1627
|
+
refreshUserTenants: () => D.current.refreshUserTenants()
|
|
1492
1628
|
}),
|
|
1493
1629
|
[]
|
|
1494
|
-
),
|
|
1495
|
-
const
|
|
1630
|
+
), kt = O(() => {
|
|
1631
|
+
const v = ($) => !W || W.length === 0 ? !1 : typeof $ == "string" ? W.includes($) : W.includes(`${$.resource}.${$.action}`);
|
|
1496
1632
|
return {
|
|
1497
|
-
isAuthenticated:
|
|
1633
|
+
isAuthenticated: z,
|
|
1498
1634
|
isAuthInitializing: !y,
|
|
1499
1635
|
isAuthReady: y,
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1636
|
+
sessionStatus: Z,
|
|
1637
|
+
currentUser: x,
|
|
1638
|
+
isUserLoading: L,
|
|
1639
|
+
userError: R,
|
|
1640
|
+
userRole: N,
|
|
1641
|
+
userPermissions: W,
|
|
1642
|
+
availableRoles: E,
|
|
1506
1643
|
rolesLoading: c,
|
|
1507
1644
|
userTenants: g,
|
|
1508
1645
|
hasTenantContext: K,
|
|
1509
|
-
sessionManager:
|
|
1646
|
+
sessionManager: w,
|
|
1510
1647
|
authenticatedHttpService: u,
|
|
1511
|
-
hasPermission:
|
|
1512
|
-
hasAnyPermission: (
|
|
1513
|
-
hasAllPermissions: (
|
|
1514
|
-
getUserPermissionStrings: () =>
|
|
1648
|
+
hasPermission: v,
|
|
1649
|
+
hasAnyPermission: ($) => $.some((V) => v(V)),
|
|
1650
|
+
hasAllPermissions: ($) => $.every((V) => v(V)),
|
|
1651
|
+
getUserPermissionStrings: () => W || []
|
|
1515
1652
|
};
|
|
1516
1653
|
}, [
|
|
1517
|
-
|
|
1654
|
+
z,
|
|
1518
1655
|
y,
|
|
1519
|
-
|
|
1520
|
-
|
|
1656
|
+
Z,
|
|
1657
|
+
x,
|
|
1658
|
+
L,
|
|
1659
|
+
R,
|
|
1660
|
+
N,
|
|
1661
|
+
W,
|
|
1521
1662
|
E,
|
|
1522
|
-
F,
|
|
1523
|
-
H,
|
|
1524
|
-
k,
|
|
1525
1663
|
c,
|
|
1526
1664
|
g,
|
|
1527
1665
|
K,
|
|
1528
|
-
|
|
1666
|
+
w,
|
|
1529
1667
|
u
|
|
1530
1668
|
]);
|
|
1531
|
-
|
|
1532
|
-
if (r.initialRoles || !
|
|
1533
|
-
let
|
|
1534
|
-
return d(!0), se.getRolesByApp(
|
|
1535
|
-
|
|
1536
|
-
}).catch((
|
|
1537
|
-
process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:",
|
|
1669
|
+
re(() => {
|
|
1670
|
+
if (r.initialRoles || !o) return;
|
|
1671
|
+
let v = !1;
|
|
1672
|
+
return d(!0), se.getRolesByApp(o).then(({ roles: $ }) => {
|
|
1673
|
+
v || S($);
|
|
1674
|
+
}).catch(($) => {
|
|
1675
|
+
process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", $);
|
|
1538
1676
|
}).finally(() => {
|
|
1539
|
-
|
|
1677
|
+
v || d(!1);
|
|
1540
1678
|
}), () => {
|
|
1541
|
-
|
|
1679
|
+
v = !0;
|
|
1542
1680
|
};
|
|
1543
|
-
}, [
|
|
1544
|
-
|
|
1681
|
+
}, [o, r.initialRoles, se]);
|
|
1682
|
+
const Qe = be({ completed: !1 });
|
|
1683
|
+
return re(() => {
|
|
1684
|
+
let v = !1;
|
|
1545
1685
|
return (async () => {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1686
|
+
try {
|
|
1687
|
+
if (Qe.current.completed || !w.getTokens() && r.enableCookieSession && (await w.attemptCookieSessionRestore(), v))
|
|
1688
|
+
return;
|
|
1689
|
+
const $ = await w.ensureValidSession();
|
|
1690
|
+
if (v) return;
|
|
1691
|
+
if ($ === "authenticated") {
|
|
1692
|
+
const V = w.getUser();
|
|
1693
|
+
V && I(V);
|
|
1694
|
+
try {
|
|
1695
|
+
await D.current.loadUserData(!V);
|
|
1696
|
+
} catch {
|
|
1697
|
+
}
|
|
1698
|
+
if (v) return;
|
|
1699
|
+
}
|
|
1700
|
+
} finally {
|
|
1701
|
+
v || (Qe.current.completed = !0, A(!0));
|
|
1702
|
+
}
|
|
1551
1703
|
})(), () => {
|
|
1552
|
-
|
|
1704
|
+
v = !0;
|
|
1553
1705
|
};
|
|
1554
|
-
}, [
|
|
1555
|
-
|
|
1556
|
-
|
|
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 }) });
|
|
1706
|
+
}, [w, r.enableCookieSession]), re(() => {
|
|
1707
|
+
h && !w.hasValidSession() && x !== null && (I(null), m(null), b([]), De());
|
|
1708
|
+
}, [l, h, x, w]), /* @__PURE__ */ s(Le.Provider, { value: St, children: /* @__PURE__ */ s(Ie.Provider, { value: kt, children: e }) });
|
|
1560
1709
|
}
|
|
1561
|
-
function
|
|
1562
|
-
const r = ne(
|
|
1710
|
+
function Dr() {
|
|
1711
|
+
const r = ne(Ie);
|
|
1563
1712
|
if (!r)
|
|
1564
1713
|
throw new Error("useAuthState must be used within an AuthProvider");
|
|
1565
1714
|
return r;
|
|
1566
1715
|
}
|
|
1567
|
-
function
|
|
1568
|
-
const r = ne(
|
|
1716
|
+
function Mr() {
|
|
1717
|
+
const r = ne(Le);
|
|
1569
1718
|
if (!r)
|
|
1570
1719
|
throw new Error("useAuthActions must be used within an AuthProvider");
|
|
1571
1720
|
return r;
|
|
1572
1721
|
}
|
|
1573
|
-
function
|
|
1574
|
-
const r = ne(
|
|
1722
|
+
function ue() {
|
|
1723
|
+
const r = ne(Ie), e = ne(Le);
|
|
1575
1724
|
if (!r || !e)
|
|
1576
1725
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
1577
|
-
return
|
|
1726
|
+
return O(() => ({ ...r, ...e }), [r, e]);
|
|
1578
1727
|
}
|
|
1579
|
-
function
|
|
1580
|
-
const r = ne(
|
|
1581
|
-
return
|
|
1728
|
+
function qe() {
|
|
1729
|
+
const r = ne(Ie), e = ne(Le);
|
|
1730
|
+
return O(() => !r || !e ? null : { ...r, ...e }, [r, e]);
|
|
1582
1731
|
}
|
|
1583
|
-
class
|
|
1732
|
+
class Wt {
|
|
1584
1733
|
constructor(e) {
|
|
1585
1734
|
this.httpService = e;
|
|
1586
1735
|
}
|
|
@@ -1592,7 +1741,7 @@ class Vt {
|
|
|
1592
1741
|
}
|
|
1593
1742
|
async getFeatureFlags(e) {
|
|
1594
1743
|
const t = await this.httpService.get(
|
|
1595
|
-
`/feature-flags/${
|
|
1744
|
+
`/feature-flags/${le(e)}`
|
|
1596
1745
|
);
|
|
1597
1746
|
return { featureFlags: t.data, meta: t.meta };
|
|
1598
1747
|
}
|
|
@@ -1611,7 +1760,7 @@ class Vt {
|
|
|
1611
1760
|
async getTenantFeatureFlags(e, t) {
|
|
1612
1761
|
if (!e || !t)
|
|
1613
1762
|
throw new Error("Tenant ID and App ID are required");
|
|
1614
|
-
const n =
|
|
1763
|
+
const n = le({ tenantId: e, appId: t });
|
|
1615
1764
|
return (await this.httpService.get(
|
|
1616
1765
|
`/tenant-feature-flags${n}`,
|
|
1617
1766
|
{ headers: { "X-Tenant-ID": e }, skipAuth: !0 }
|
|
@@ -1620,73 +1769,73 @@ class Vt {
|
|
|
1620
1769
|
async getTenantFeatureFlag(e, t, n) {
|
|
1621
1770
|
if (!e || !t || !n)
|
|
1622
1771
|
throw new Error("Flag Key, Tenant ID and App ID are required");
|
|
1623
|
-
const i =
|
|
1772
|
+
const i = le({ tenantId: t, appId: n });
|
|
1624
1773
|
return (await this.httpService.get(
|
|
1625
1774
|
`/tenant-feature-flags/${e}${i}`,
|
|
1626
1775
|
{ headers: { "X-Tenant-ID": t }, skipAuth: !0 }
|
|
1627
1776
|
)).data;
|
|
1628
1777
|
}
|
|
1629
1778
|
}
|
|
1630
|
-
const
|
|
1631
|
-
function
|
|
1632
|
-
const t =
|
|
1779
|
+
const ze = fe(null);
|
|
1780
|
+
function $r({ config: r = {}, children: e }) {
|
|
1781
|
+
const t = _e(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [p, k] = C([]), [E, S] = C(!1), [c, d] = C(null), [x, I] = C(!1), L = O(() => {
|
|
1633
1782
|
const m = new he(i);
|
|
1634
|
-
return new
|
|
1635
|
-
}, [i]),
|
|
1636
|
-
if (!(
|
|
1637
|
-
|
|
1783
|
+
return new Wt(m);
|
|
1784
|
+
}, [i]), P = async () => {
|
|
1785
|
+
if (!(a != null && a.id)) {
|
|
1786
|
+
k([]);
|
|
1638
1787
|
return;
|
|
1639
1788
|
}
|
|
1640
|
-
|
|
1789
|
+
S(!0), d(null);
|
|
1641
1790
|
try {
|
|
1642
|
-
const m = await
|
|
1643
|
-
|
|
1791
|
+
const m = await L.getTenantFeatureFlags(a.id, o);
|
|
1792
|
+
k(m);
|
|
1644
1793
|
} catch (m) {
|
|
1645
1794
|
const g = m instanceof Error ? m.message : "Failed to fetch feature flags";
|
|
1646
1795
|
d(g), r.onError && r.onError(m instanceof Error ? m : new Error(g));
|
|
1647
1796
|
} finally {
|
|
1648
|
-
|
|
1797
|
+
S(!1);
|
|
1649
1798
|
}
|
|
1650
1799
|
};
|
|
1651
1800
|
re(() => {
|
|
1652
|
-
if (!i || !
|
|
1653
|
-
|
|
1654
|
-
const m = r.refreshInterval ||
|
|
1801
|
+
if (!i || !o) return;
|
|
1802
|
+
P().finally(() => I(!0));
|
|
1803
|
+
const m = r.refreshInterval || 300 * 1e3, g = setInterval(P, m);
|
|
1655
1804
|
return () => clearInterval(g);
|
|
1656
|
-
}, [
|
|
1657
|
-
const
|
|
1658
|
-
const m = (
|
|
1659
|
-
const
|
|
1660
|
-
return (
|
|
1661
|
-
}, g = (
|
|
1662
|
-
const
|
|
1663
|
-
return
|
|
1664
|
-
},
|
|
1665
|
-
await
|
|
1666
|
-
},
|
|
1805
|
+
}, [a == null ? void 0 : a.id, i, o, r.refreshInterval]);
|
|
1806
|
+
const R = O(() => {
|
|
1807
|
+
const m = (h) => {
|
|
1808
|
+
const A = p.find((y) => y.key === h);
|
|
1809
|
+
return (A == null ? void 0 : A.value) === !0;
|
|
1810
|
+
}, g = (h) => p.find((A) => A.key === h), b = (h) => {
|
|
1811
|
+
const A = p.find((y) => y.key === h);
|
|
1812
|
+
return A ? A.value ? "enabled" : "disabled" : "not_found";
|
|
1813
|
+
}, w = async () => {
|
|
1814
|
+
await P();
|
|
1815
|
+
}, l = !!(i && o) && (x || !(a != null && a.id));
|
|
1667
1816
|
return {
|
|
1668
|
-
featureFlags:
|
|
1669
|
-
loading:
|
|
1817
|
+
featureFlags: p,
|
|
1818
|
+
loading: E,
|
|
1670
1819
|
error: c,
|
|
1671
|
-
isReady:
|
|
1820
|
+
isReady: l,
|
|
1672
1821
|
isEnabled: m,
|
|
1673
1822
|
getFlag: g,
|
|
1674
1823
|
getFlagState: b,
|
|
1675
|
-
refresh:
|
|
1824
|
+
refresh: w
|
|
1676
1825
|
};
|
|
1677
|
-
}, [
|
|
1678
|
-
return /* @__PURE__ */ s(
|
|
1826
|
+
}, [p, E, c, i, o, a == null ? void 0 : a.id, x]);
|
|
1827
|
+
return /* @__PURE__ */ s(ze.Provider, { value: R, children: e });
|
|
1679
1828
|
}
|
|
1680
|
-
function
|
|
1681
|
-
const r = ne(
|
|
1829
|
+
function Ht() {
|
|
1830
|
+
const r = ne(ze);
|
|
1682
1831
|
if (!r)
|
|
1683
1832
|
throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
|
|
1684
1833
|
return r;
|
|
1685
1834
|
}
|
|
1686
|
-
function
|
|
1687
|
-
return ne(
|
|
1835
|
+
function ut() {
|
|
1836
|
+
return ne(ze);
|
|
1688
1837
|
}
|
|
1689
|
-
class
|
|
1838
|
+
class Qt {
|
|
1690
1839
|
constructor(e) {
|
|
1691
1840
|
this.httpService = e;
|
|
1692
1841
|
}
|
|
@@ -1726,68 +1875,68 @@ class zt {
|
|
|
1726
1875
|
)).data;
|
|
1727
1876
|
}
|
|
1728
1877
|
}
|
|
1729
|
-
const
|
|
1730
|
-
function
|
|
1731
|
-
const t =
|
|
1732
|
-
const
|
|
1733
|
-
return new
|
|
1734
|
-
}, [i]),
|
|
1735
|
-
if (!(
|
|
1736
|
-
|
|
1878
|
+
const Ge = fe(void 0);
|
|
1879
|
+
function Ur({ config: r = {}, children: e }) {
|
|
1880
|
+
const t = _e(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (n == null ? void 0 : n.tenant) ?? null, [a, p] = C(null), [k, E] = C(!1), [S, c] = C(null), [d, x] = C(!1), I = O(() => {
|
|
1881
|
+
const R = new he(i);
|
|
1882
|
+
return new Qt(R);
|
|
1883
|
+
}, [i]), L = async () => {
|
|
1884
|
+
if (!(o != null && o.id)) {
|
|
1885
|
+
p(null);
|
|
1737
1886
|
return;
|
|
1738
1887
|
}
|
|
1739
|
-
|
|
1888
|
+
E(!0), c(null);
|
|
1740
1889
|
try {
|
|
1741
|
-
const
|
|
1742
|
-
|
|
1743
|
-
} catch (
|
|
1744
|
-
const m =
|
|
1745
|
-
c(m), r.onError && r.onError(
|
|
1890
|
+
const R = await I.getTenantSubscriptionFeatures(o.id);
|
|
1891
|
+
p(R);
|
|
1892
|
+
} catch (R) {
|
|
1893
|
+
const m = R instanceof Error ? R.message : "Failed to fetch subscription";
|
|
1894
|
+
c(m), r.onError && r.onError(R instanceof Error ? R : new Error(m));
|
|
1746
1895
|
} finally {
|
|
1747
|
-
|
|
1896
|
+
E(!1);
|
|
1748
1897
|
}
|
|
1749
1898
|
};
|
|
1750
1899
|
re(() => {
|
|
1751
|
-
if (!i || (
|
|
1752
|
-
const
|
|
1900
|
+
if (!i || (L().finally(() => x(!0)), !r.refreshInterval)) return;
|
|
1901
|
+
const R = r.refreshInterval || 600 * 1e3, m = setInterval(L, R);
|
|
1753
1902
|
return () => clearInterval(m);
|
|
1754
|
-
}, [
|
|
1755
|
-
const
|
|
1756
|
-
const
|
|
1757
|
-
const y =
|
|
1903
|
+
}, [o == null ? void 0 : o.id, i, r.refreshInterval]);
|
|
1904
|
+
const P = O(() => {
|
|
1905
|
+
const R = (a == null ? void 0 : a.features) || [], m = (A) => {
|
|
1906
|
+
const y = R.find((u) => u.key === A);
|
|
1758
1907
|
return y ? y.type === "BOOLEAN" || y.type === "boolean" ? y.value === !0 : !!y.value : !1;
|
|
1759
|
-
}, g = (
|
|
1760
|
-
const u =
|
|
1908
|
+
}, g = (A) => R.find((y) => y.key === A), b = (A, y) => {
|
|
1909
|
+
const u = R.find((T) => T.key === A);
|
|
1761
1910
|
return u ? u.value : y;
|
|
1762
|
-
},
|
|
1763
|
-
await
|
|
1764
|
-
},
|
|
1911
|
+
}, w = (A) => !a || !a.isActive ? !1 : A.includes(a.planId), l = async () => {
|
|
1912
|
+
await L();
|
|
1913
|
+
}, h = !!i && (d || !(o != null && o.id));
|
|
1765
1914
|
return {
|
|
1766
|
-
subscription:
|
|
1767
|
-
features:
|
|
1768
|
-
loading:
|
|
1769
|
-
error:
|
|
1770
|
-
isReady:
|
|
1915
|
+
subscription: a,
|
|
1916
|
+
features: R,
|
|
1917
|
+
loading: k,
|
|
1918
|
+
error: S,
|
|
1919
|
+
isReady: h,
|
|
1771
1920
|
isFeatureEnabled: m,
|
|
1772
1921
|
getFeature: g,
|
|
1773
1922
|
getFeatureValue: b,
|
|
1774
|
-
hasAllowedPlan:
|
|
1775
|
-
refresh:
|
|
1923
|
+
hasAllowedPlan: w,
|
|
1924
|
+
refresh: l
|
|
1776
1925
|
};
|
|
1777
|
-
}, [
|
|
1778
|
-
return /* @__PURE__ */ s(
|
|
1926
|
+
}, [a, k, S, i, o == null ? void 0 : o.id, d]);
|
|
1927
|
+
return /* @__PURE__ */ s(Ge.Provider, { value: P, children: e });
|
|
1779
1928
|
}
|
|
1780
|
-
function
|
|
1781
|
-
const r = ne(
|
|
1929
|
+
function Jt() {
|
|
1930
|
+
const r = ne(Ge);
|
|
1782
1931
|
if (r === void 0)
|
|
1783
1932
|
throw new Error("useSubscription must be used within a SubscriptionProvider");
|
|
1784
1933
|
return r;
|
|
1785
1934
|
}
|
|
1786
|
-
function
|
|
1787
|
-
return ne(
|
|
1935
|
+
function dt() {
|
|
1936
|
+
return ne(Ge) ?? null;
|
|
1788
1937
|
}
|
|
1789
|
-
var
|
|
1790
|
-
const
|
|
1938
|
+
var oe = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(oe || {});
|
|
1939
|
+
const je = {
|
|
1791
1940
|
publicGuest: "/",
|
|
1792
1941
|
publicUser: "/account",
|
|
1793
1942
|
publicAdmin: "/admin",
|
|
@@ -1795,7 +1944,7 @@ const ze = {
|
|
|
1795
1944
|
tenantUser: "/dashboard",
|
|
1796
1945
|
tenantAdmin: "/admin/dashboard",
|
|
1797
1946
|
default: "/"
|
|
1798
|
-
},
|
|
1947
|
+
}, ht = {
|
|
1799
1948
|
// Public/Landing zones
|
|
1800
1949
|
landing: { tenant: "forbidden", auth: "optional" },
|
|
1801
1950
|
publicOnly: { tenant: "forbidden", auth: "forbidden" },
|
|
@@ -1808,26 +1957,26 @@ const ze = {
|
|
|
1808
1957
|
tenantOpen: { tenant: "required", auth: "optional" },
|
|
1809
1958
|
tenantAuth: { tenant: "required", auth: "required" },
|
|
1810
1959
|
// User type zones
|
|
1811
|
-
user: { tenant: "required", auth: "required", userType:
|
|
1812
|
-
admin: { tenant: "required", auth: "required", userType:
|
|
1960
|
+
user: { tenant: "required", auth: "required", userType: oe.USER },
|
|
1961
|
+
admin: { tenant: "required", auth: "required", userType: oe.TENANT_ADMIN },
|
|
1813
1962
|
// Fully open
|
|
1814
1963
|
open: { tenant: "optional", auth: "optional" }
|
|
1815
|
-
},
|
|
1816
|
-
zoneRoots:
|
|
1817
|
-
presets:
|
|
1964
|
+
}, We = fe(null), Kt = {
|
|
1965
|
+
zoneRoots: je,
|
|
1966
|
+
presets: ht,
|
|
1818
1967
|
loadingFallback: null,
|
|
1819
1968
|
accessDeniedFallback: null,
|
|
1820
1969
|
onAccessDenied: void 0,
|
|
1821
1970
|
returnToParam: "returnTo",
|
|
1822
1971
|
returnToStorage: "url"
|
|
1823
1972
|
};
|
|
1824
|
-
function
|
|
1825
|
-
const t =
|
|
1973
|
+
function Br({ config: r = {}, children: e }) {
|
|
1974
|
+
const t = O(() => {
|
|
1826
1975
|
const n = {
|
|
1827
|
-
...
|
|
1976
|
+
...je,
|
|
1828
1977
|
...r.zoneRoots
|
|
1829
1978
|
}, i = {
|
|
1830
|
-
...
|
|
1979
|
+
...ht,
|
|
1831
1980
|
...r.presets
|
|
1832
1981
|
};
|
|
1833
1982
|
return {
|
|
@@ -1840,18 +1989,18 @@ function Cr({ config: r = {}, children: e }) {
|
|
|
1840
1989
|
returnToStorage: r.returnToStorage ?? "url"
|
|
1841
1990
|
};
|
|
1842
1991
|
}, [r]);
|
|
1843
|
-
return /* @__PURE__ */ s(
|
|
1992
|
+
return /* @__PURE__ */ s(We.Provider, { value: t, children: e });
|
|
1844
1993
|
}
|
|
1845
|
-
function
|
|
1846
|
-
const r = ne(
|
|
1994
|
+
function _r() {
|
|
1995
|
+
const r = ne(We);
|
|
1847
1996
|
if (!r)
|
|
1848
1997
|
throw new Error("useRouting must be used within a RoutingProvider");
|
|
1849
1998
|
return r;
|
|
1850
1999
|
}
|
|
1851
|
-
function
|
|
1852
|
-
return ne(
|
|
2000
|
+
function Zt() {
|
|
2001
|
+
return ne(We) ?? Kt;
|
|
1853
2002
|
}
|
|
1854
|
-
const
|
|
2003
|
+
const st = () => /* @__PURE__ */ f(
|
|
1855
2004
|
"div",
|
|
1856
2005
|
{
|
|
1857
2006
|
style: {
|
|
@@ -1888,7 +2037,7 @@ const tt = () => /* @__PURE__ */ f(
|
|
|
1888
2037
|
)
|
|
1889
2038
|
]
|
|
1890
2039
|
}
|
|
1891
|
-
),
|
|
2040
|
+
), it = ({
|
|
1892
2041
|
userType: r,
|
|
1893
2042
|
minUserType: e,
|
|
1894
2043
|
missingPermissions: t
|
|
@@ -1929,36 +2078,36 @@ const tt = () => /* @__PURE__ */ f(
|
|
|
1929
2078
|
] })
|
|
1930
2079
|
]
|
|
1931
2080
|
}
|
|
1932
|
-
),
|
|
2081
|
+
), Yt = (r, e) => {
|
|
1933
2082
|
const t = {
|
|
1934
|
-
[
|
|
1935
|
-
[
|
|
1936
|
-
[
|
|
2083
|
+
[oe.USER]: 1,
|
|
2084
|
+
[oe.TENANT_ADMIN]: 2,
|
|
2085
|
+
[oe.SUPERUSER]: 3
|
|
1937
2086
|
};
|
|
1938
2087
|
return t[r] >= t[e];
|
|
1939
2088
|
};
|
|
1940
|
-
function
|
|
2089
|
+
function Or({
|
|
1941
2090
|
children: r,
|
|
1942
2091
|
fallback: e,
|
|
1943
2092
|
minUserType: t,
|
|
1944
2093
|
requiredPermissions: n,
|
|
1945
2094
|
requireAllPermissions: i = !1
|
|
1946
2095
|
}) {
|
|
1947
|
-
const { hasValidSession:
|
|
1948
|
-
if (!
|
|
1949
|
-
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(
|
|
1950
|
-
const
|
|
1951
|
-
if (!
|
|
1952
|
-
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(
|
|
1953
|
-
if (t && !
|
|
1954
|
-
return /* @__PURE__ */ s(
|
|
1955
|
-
if (n && n.length > 0 && !(i ?
|
|
1956
|
-
const d = n.filter((
|
|
1957
|
-
return /* @__PURE__ */ s(
|
|
2096
|
+
const { hasValidSession: o, sessionManager: a, hasPermission: p, hasAnyPermission: k, hasAllPermissions: E } = ue();
|
|
2097
|
+
if (!o())
|
|
2098
|
+
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(st, {}) });
|
|
2099
|
+
const S = a.getUser();
|
|
2100
|
+
if (!S)
|
|
2101
|
+
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(st, {}) });
|
|
2102
|
+
if (t && !Yt(S.userType, t))
|
|
2103
|
+
return /* @__PURE__ */ s(it, { userType: S.userType, minUserType: t });
|
|
2104
|
+
if (n && n.length > 0 && !(i ? E(n) : k(n))) {
|
|
2105
|
+
const d = n.filter((x) => !p(x)).map((x) => typeof x == "string" ? x : x.name);
|
|
2106
|
+
return /* @__PURE__ */ s(it, { missingPermissions: d });
|
|
1958
2107
|
}
|
|
1959
2108
|
return /* @__PURE__ */ s(U, { children: r });
|
|
1960
2109
|
}
|
|
1961
|
-
const
|
|
2110
|
+
const Xt = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
1962
2111
|
"div",
|
|
1963
2112
|
{
|
|
1964
2113
|
style: {
|
|
@@ -1994,7 +2143,7 @@ const Qt = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
|
1994
2143
|
}
|
|
1995
2144
|
)
|
|
1996
2145
|
}
|
|
1997
|
-
),
|
|
2146
|
+
), ot = ({
|
|
1998
2147
|
userType: r,
|
|
1999
2148
|
requiredUserType: e,
|
|
2000
2149
|
missingPermissions: t
|
|
@@ -2045,43 +2194,43 @@ const Qt = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
|
2045
2194
|
}
|
|
2046
2195
|
)
|
|
2047
2196
|
}
|
|
2048
|
-
),
|
|
2049
|
-
function
|
|
2197
|
+
), er = (r, e) => r === e;
|
|
2198
|
+
function Vr({
|
|
2050
2199
|
children: r,
|
|
2051
2200
|
redirectTo: e = "/login",
|
|
2052
2201
|
requiredUserType: t,
|
|
2053
2202
|
requiredPermissions: n,
|
|
2054
2203
|
requireAllPermissions: i = !1,
|
|
2055
|
-
fallback:
|
|
2204
|
+
fallback: o
|
|
2056
2205
|
}) {
|
|
2057
|
-
const { hasValidSession:
|
|
2206
|
+
const { hasValidSession: a, sessionManager: p, hasPermission: k, hasAnyPermission: E, hasAllPermissions: S } = ue(), c = Re();
|
|
2058
2207
|
if (re(() => {
|
|
2059
2208
|
process.env.NODE_ENV === "development" && console.warn(
|
|
2060
2209
|
"[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
|
|
2061
2210
|
);
|
|
2062
|
-
}, []), !
|
|
2063
|
-
return
|
|
2064
|
-
/* @__PURE__ */ s(
|
|
2065
|
-
/* @__PURE__ */ s(
|
|
2211
|
+
}, []), !a())
|
|
2212
|
+
return o ? /* @__PURE__ */ s(U, { children: o }) : /* @__PURE__ */ f(U, { children: [
|
|
2213
|
+
/* @__PURE__ */ s(Xt, { redirectPath: e }),
|
|
2214
|
+
/* @__PURE__ */ s(ve, { to: e, state: { from: c.pathname }, replace: !0 })
|
|
2066
2215
|
] });
|
|
2067
|
-
const d =
|
|
2216
|
+
const d = p.getUser();
|
|
2068
2217
|
if (!d)
|
|
2069
|
-
return /* @__PURE__ */ s(
|
|
2070
|
-
if (t && !
|
|
2218
|
+
return /* @__PURE__ */ s(ve, { to: e, state: { from: c.pathname }, replace: !0 });
|
|
2219
|
+
if (t && !er(d.userType, t))
|
|
2071
2220
|
return /* @__PURE__ */ s(
|
|
2072
|
-
|
|
2221
|
+
ot,
|
|
2073
2222
|
{
|
|
2074
2223
|
userType: d.userType,
|
|
2075
2224
|
requiredUserType: t
|
|
2076
2225
|
}
|
|
2077
2226
|
);
|
|
2078
|
-
if (n && n.length > 0 && !(i ?
|
|
2079
|
-
const
|
|
2080
|
-
return /* @__PURE__ */ s(
|
|
2227
|
+
if (n && n.length > 0 && !(i ? S(n) : E(n))) {
|
|
2228
|
+
const I = n.filter((L) => !k(L)).map((L) => typeof L == "string" ? L : L.name);
|
|
2229
|
+
return /* @__PURE__ */ s(ot, { missingPermissions: I });
|
|
2081
2230
|
}
|
|
2082
2231
|
return /* @__PURE__ */ s(U, { children: r });
|
|
2083
2232
|
}
|
|
2084
|
-
const
|
|
2233
|
+
const tr = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
2085
2234
|
"div",
|
|
2086
2235
|
{
|
|
2087
2236
|
style: {
|
|
@@ -2118,18 +2267,18 @@ const Zt = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
|
2118
2267
|
)
|
|
2119
2268
|
}
|
|
2120
2269
|
);
|
|
2121
|
-
function
|
|
2122
|
-
const { tenant: n, isLoading: i, error:
|
|
2270
|
+
function qr({ children: r, redirectTo: e = "/", fallback: t }) {
|
|
2271
|
+
const { tenant: n, isLoading: i, error: o } = ct(), a = Re();
|
|
2123
2272
|
return re(() => {
|
|
2124
2273
|
process.env.NODE_ENV === "development" && console.warn(
|
|
2125
2274
|
"[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
|
|
2126
2275
|
);
|
|
2127
|
-
}, []), i ||
|
|
2128
|
-
/* @__PURE__ */ s(
|
|
2129
|
-
/* @__PURE__ */ s(
|
|
2276
|
+
}, []), i || o ? null : n ? /* @__PURE__ */ s(U, { children: r }) : t ? /* @__PURE__ */ s(U, { children: t }) : /* @__PURE__ */ f(U, { children: [
|
|
2277
|
+
/* @__PURE__ */ s(tr, { redirectPath: e }),
|
|
2278
|
+
/* @__PURE__ */ s(ve, { to: e, state: { from: a.pathname }, replace: !0 })
|
|
2130
2279
|
] });
|
|
2131
2280
|
}
|
|
2132
|
-
const
|
|
2281
|
+
const rr = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
2133
2282
|
"div",
|
|
2134
2283
|
{
|
|
2135
2284
|
style: {
|
|
@@ -2166,125 +2315,125 @@ const Kt = ({ redirectPath: r }) => /* @__PURE__ */ s(
|
|
|
2166
2315
|
)
|
|
2167
2316
|
}
|
|
2168
2317
|
);
|
|
2169
|
-
function
|
|
2170
|
-
const { tenant: n, isLoading: i, error:
|
|
2318
|
+
function zr({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
|
|
2319
|
+
const { tenant: n, isLoading: i, error: o } = ct(), a = Re();
|
|
2171
2320
|
return re(() => {
|
|
2172
2321
|
process.env.NODE_ENV === "development" && console.warn(
|
|
2173
2322
|
"[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
|
|
2174
2323
|
);
|
|
2175
|
-
}, []), i ||
|
|
2176
|
-
/* @__PURE__ */ s(
|
|
2177
|
-
/* @__PURE__ */ s(
|
|
2324
|
+
}, []), i || o ? null : n ? t ? /* @__PURE__ */ s(U, { children: t }) : /* @__PURE__ */ f(U, { children: [
|
|
2325
|
+
/* @__PURE__ */ s(rr, { redirectPath: e }),
|
|
2326
|
+
/* @__PURE__ */ s(ve, { to: e, state: { from: a.pathname }, replace: !0 })
|
|
2178
2327
|
] }) : /* @__PURE__ */ s(U, { children: r });
|
|
2179
2328
|
}
|
|
2180
|
-
function
|
|
2329
|
+
function nr(r, e) {
|
|
2181
2330
|
return e ? r ? Array.isArray(e) ? e.includes(r) : r === e : !1 : !0;
|
|
2182
2331
|
}
|
|
2183
|
-
function
|
|
2332
|
+
function at(r, e) {
|
|
2184
2333
|
return !r || r === "optional" ? "skip" : r === "required" ? e ? "pass" : "fail" : r === "forbidden" ? e ? "fail" : "pass" : "skip";
|
|
2185
2334
|
}
|
|
2186
|
-
function
|
|
2187
|
-
return
|
|
2335
|
+
function sr(r, e) {
|
|
2336
|
+
return at(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : at(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !nr(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(r.permissions) ? "missing_permissions" : null;
|
|
2188
2337
|
}
|
|
2189
|
-
function
|
|
2190
|
-
return r.hasTenant ? r.isAuthenticated ? r.userType ===
|
|
2338
|
+
function ir(r, e) {
|
|
2339
|
+
return r.hasTenant ? r.isAuthenticated ? r.userType === oe.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : r.isAuthenticated ? r.userType === oe.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
|
|
2191
2340
|
}
|
|
2192
|
-
function
|
|
2341
|
+
function or(r, e, t, n, i) {
|
|
2193
2342
|
if (!e || i !== "url")
|
|
2194
2343
|
return r;
|
|
2195
|
-
const
|
|
2196
|
-
return `${r}${
|
|
2344
|
+
const o = typeof e == "string" ? e : t, a = r.includes("?") ? "&" : "?";
|
|
2345
|
+
return `${r}${a}${n}=${encodeURIComponent(o)}`;
|
|
2197
2346
|
}
|
|
2198
|
-
function
|
|
2347
|
+
function ar(r, e, t) {
|
|
2199
2348
|
if (!r || t === "url") return;
|
|
2200
2349
|
const n = typeof r == "string" ? r : e, i = "zone_return_to";
|
|
2201
2350
|
t === "session" ? sessionStorage.setItem(i, n) : t === "local" && localStorage.setItem(i, n);
|
|
2202
2351
|
}
|
|
2203
|
-
const
|
|
2352
|
+
const ce = ({
|
|
2204
2353
|
children: r,
|
|
2205
2354
|
preset: e,
|
|
2206
2355
|
tenant: t,
|
|
2207
2356
|
auth: n,
|
|
2208
2357
|
userType: i,
|
|
2209
|
-
requiredPermissions:
|
|
2210
|
-
requireAllPermissions:
|
|
2211
|
-
returnTo:
|
|
2212
|
-
onAccessDenied:
|
|
2213
|
-
redirectTo:
|
|
2214
|
-
loadingFallback:
|
|
2358
|
+
requiredPermissions: o,
|
|
2359
|
+
requireAllPermissions: a = !0,
|
|
2360
|
+
returnTo: p,
|
|
2361
|
+
onAccessDenied: k,
|
|
2362
|
+
redirectTo: E,
|
|
2363
|
+
loadingFallback: S,
|
|
2215
2364
|
accessDeniedFallback: c
|
|
2216
2365
|
}) => {
|
|
2217
|
-
const d =
|
|
2366
|
+
const d = Re(), { isAuthenticated: x, isAuthInitializing: I, currentUser: L, userPermissions: P } = ue(), { tenant: R, isTenantLoading: m } = Se(), g = Zt(), b = O(() => {
|
|
2218
2367
|
if (e)
|
|
2219
2368
|
return g.presets[e];
|
|
2220
|
-
}, [e, g.presets]),
|
|
2369
|
+
}, [e, g.presets]), w = O(
|
|
2221
2370
|
() => ({
|
|
2222
2371
|
tenant: t ?? (b == null ? void 0 : b.tenant),
|
|
2223
2372
|
auth: n ?? (b == null ? void 0 : b.auth),
|
|
2224
2373
|
userType: i ?? (b == null ? void 0 : b.userType),
|
|
2225
|
-
permissions:
|
|
2226
|
-
requireAllPermissions:
|
|
2374
|
+
permissions: o ?? (b == null ? void 0 : b.requiredPermissions),
|
|
2375
|
+
requireAllPermissions: a
|
|
2227
2376
|
}),
|
|
2228
|
-
[t, n, i,
|
|
2229
|
-
),
|
|
2377
|
+
[t, n, i, o, b, a]
|
|
2378
|
+
), l = O(
|
|
2230
2379
|
() => ({
|
|
2231
|
-
hasTenant: !!
|
|
2232
|
-
isAuthenticated:
|
|
2233
|
-
userType:
|
|
2234
|
-
permissions:
|
|
2235
|
-
isLoading:
|
|
2380
|
+
hasTenant: !!R,
|
|
2381
|
+
isAuthenticated: x,
|
|
2382
|
+
userType: L == null ? void 0 : L.userType,
|
|
2383
|
+
permissions: P,
|
|
2384
|
+
isLoading: I || m
|
|
2236
2385
|
}),
|
|
2237
2386
|
[
|
|
2238
|
-
E,
|
|
2239
|
-
A,
|
|
2240
|
-
I == null ? void 0 : I.userType,
|
|
2241
2387
|
R,
|
|
2388
|
+
x,
|
|
2389
|
+
L == null ? void 0 : L.userType,
|
|
2242
2390
|
P,
|
|
2391
|
+
I,
|
|
2243
2392
|
m
|
|
2244
2393
|
]
|
|
2245
|
-
),
|
|
2246
|
-
type:
|
|
2394
|
+
), h = O(() => l.isLoading ? null : sr(w, l), [w, l]), A = O(() => h ? E || ir(l, g.zoneRoots) : null, [h, E, l, g.zoneRoots]), y = O(() => !h || !A ? null : {
|
|
2395
|
+
type: h,
|
|
2247
2396
|
required: {
|
|
2248
|
-
tenant:
|
|
2249
|
-
auth:
|
|
2250
|
-
userType:
|
|
2251
|
-
permissions:
|
|
2397
|
+
tenant: w.tenant,
|
|
2398
|
+
auth: w.auth,
|
|
2399
|
+
userType: w.userType,
|
|
2400
|
+
permissions: w.permissions
|
|
2252
2401
|
},
|
|
2253
2402
|
current: {
|
|
2254
|
-
hasTenant:
|
|
2255
|
-
isAuthenticated:
|
|
2256
|
-
userType:
|
|
2257
|
-
permissions:
|
|
2403
|
+
hasTenant: l.hasTenant,
|
|
2404
|
+
isAuthenticated: l.isAuthenticated,
|
|
2405
|
+
userType: l.userType,
|
|
2406
|
+
permissions: l.permissions
|
|
2258
2407
|
},
|
|
2259
|
-
redirectTo:
|
|
2260
|
-
}, [
|
|
2408
|
+
redirectTo: A
|
|
2409
|
+
}, [h, A, w, l]);
|
|
2261
2410
|
if (re(() => {
|
|
2262
|
-
y && (
|
|
2263
|
-
}, [y,
|
|
2264
|
-
y &&
|
|
2411
|
+
y && (k ? k(y) : g.onAccessDenied && g.onAccessDenied(y));
|
|
2412
|
+
}, [y, k, g]), re(() => {
|
|
2413
|
+
y && p && ar(p, d.pathname + d.search, g.returnToStorage);
|
|
2265
2414
|
}, [
|
|
2266
2415
|
y,
|
|
2267
|
-
|
|
2416
|
+
p,
|
|
2268
2417
|
d.pathname,
|
|
2269
2418
|
d.search,
|
|
2270
2419
|
g.returnToStorage
|
|
2271
|
-
]),
|
|
2272
|
-
return /* @__PURE__ */ s(U, { children:
|
|
2273
|
-
if (y &&
|
|
2420
|
+
]), l.isLoading)
|
|
2421
|
+
return /* @__PURE__ */ s(U, { children: S ?? g.loadingFallback ?? null });
|
|
2422
|
+
if (y && A) {
|
|
2274
2423
|
const u = c ?? g.accessDeniedFallback;
|
|
2275
2424
|
if (u)
|
|
2276
2425
|
return /* @__PURE__ */ s(U, { children: u });
|
|
2277
|
-
const
|
|
2278
|
-
|
|
2279
|
-
|
|
2426
|
+
const T = or(
|
|
2427
|
+
A,
|
|
2428
|
+
p,
|
|
2280
2429
|
d.pathname + d.search,
|
|
2281
2430
|
g.returnToParam,
|
|
2282
2431
|
g.returnToStorage
|
|
2283
2432
|
);
|
|
2284
|
-
return /* @__PURE__ */ s(
|
|
2433
|
+
return /* @__PURE__ */ s(ve, { to: T, replace: !0 });
|
|
2285
2434
|
}
|
|
2286
2435
|
return /* @__PURE__ */ s(U, { children: r });
|
|
2287
|
-
},
|
|
2436
|
+
}, Gr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", ...r }), jr = (r) => /* @__PURE__ */ s(ce, { tenant: "forbidden", ...r }), Wr = (r) => /* @__PURE__ */ s(ce, { auth: "required", ...r }), Hr = (r) => /* @__PURE__ */ s(ce, { auth: "forbidden", ...r }), Qr = (r) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.TENANT_ADMIN, ...r }), Jr = (r) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.USER, ...r }), Kr = (r) => /* @__PURE__ */ s(ce, { tenant: "optional", auth: "optional", ...r }), Zr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "required", ...r }), Yr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "optional", ...r }), Xr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "forbidden", ...r }), lr = () => /* @__PURE__ */ f(
|
|
2288
2437
|
"div",
|
|
2289
2438
|
{
|
|
2290
2439
|
style: {
|
|
@@ -2301,14 +2450,14 @@ const ue = ({
|
|
|
2301
2450
|
]
|
|
2302
2451
|
}
|
|
2303
2452
|
);
|
|
2304
|
-
function
|
|
2453
|
+
function en({
|
|
2305
2454
|
children: r,
|
|
2306
|
-
fallback: e = /* @__PURE__ */ s(
|
|
2455
|
+
fallback: e = /* @__PURE__ */ s(lr, {}),
|
|
2307
2456
|
allowedPlans: t,
|
|
2308
2457
|
requiredFeature: n
|
|
2309
2458
|
}) {
|
|
2310
|
-
const { subscription: i, hasAllowedPlan:
|
|
2311
|
-
return
|
|
2459
|
+
const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: p } = Jt();
|
|
2460
|
+
return p ? /* @__PURE__ */ s(
|
|
2312
2461
|
"div",
|
|
2313
2462
|
{
|
|
2314
2463
|
style: {
|
|
@@ -2318,9 +2467,9 @@ function Jr({
|
|
|
2318
2467
|
},
|
|
2319
2468
|
children: "Loading subscription..."
|
|
2320
2469
|
}
|
|
2321
|
-
) : i ? i.isActive ? t && t.length > 0 && !
|
|
2470
|
+
) : i ? i.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ s(U, { children: e }) : n && !a(n) ? /* @__PURE__ */ s(U, { children: e }) : /* @__PURE__ */ s(U, { children: r }) : /* @__PURE__ */ s(U, { children: e }) : /* @__PURE__ */ s(U, { children: e });
|
|
2322
2471
|
}
|
|
2323
|
-
const
|
|
2472
|
+
const cr = ({ flagName: r }) => /* @__PURE__ */ f(
|
|
2324
2473
|
"div",
|
|
2325
2474
|
{
|
|
2326
2475
|
style: {
|
|
@@ -2347,8 +2496,8 @@ const sr = ({ flagName: r }) => /* @__PURE__ */ f(
|
|
|
2347
2496
|
]
|
|
2348
2497
|
}
|
|
2349
2498
|
);
|
|
2350
|
-
function
|
|
2351
|
-
const { isEnabled: n, loading: i } =
|
|
2499
|
+
function tn({ name: r, children: e, fallback: t }) {
|
|
2500
|
+
const { isEnabled: n, loading: i } = Ht();
|
|
2352
2501
|
return i ? /* @__PURE__ */ s(
|
|
2353
2502
|
"div",
|
|
2354
2503
|
{
|
|
@@ -2362,49 +2511,49 @@ function Zr({ name: r, children: e, fallback: t }) {
|
|
|
2362
2511
|
},
|
|
2363
2512
|
children: "Loading feature flags..."
|
|
2364
2513
|
}
|
|
2365
|
-
) : n(r) ? /* @__PURE__ */ s(U, { children: e }) : /* @__PURE__ */ s(U, { children: t || /* @__PURE__ */ s(
|
|
2366
|
-
}
|
|
2367
|
-
function
|
|
2368
|
-
const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError:
|
|
2369
|
-
c((m) => ({ ...m, [
|
|
2370
|
-
}, []),
|
|
2371
|
-
c((
|
|
2372
|
-
if (!
|
|
2373
|
-
const m = { ...
|
|
2374
|
-
return delete m[
|
|
2514
|
+
) : n(r) ? /* @__PURE__ */ s(U, { children: e }) : /* @__PURE__ */ s(U, { children: t || /* @__PURE__ */ s(cr, { flagName: r }) });
|
|
2515
|
+
}
|
|
2516
|
+
function Te(r) {
|
|
2517
|
+
const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError: o } = r, [a, p] = C(!1), [k, E] = C(""), [S, c] = C({}), d = te((P, R) => {
|
|
2518
|
+
c((m) => ({ ...m, [P]: R }));
|
|
2519
|
+
}, []), x = te((P) => {
|
|
2520
|
+
c((R) => {
|
|
2521
|
+
if (!R[P]) return R;
|
|
2522
|
+
const m = { ...R };
|
|
2523
|
+
return delete m[P], m;
|
|
2375
2524
|
});
|
|
2376
|
-
}, []),
|
|
2377
|
-
|
|
2378
|
-
}, []),
|
|
2379
|
-
async (
|
|
2380
|
-
if (
|
|
2381
|
-
|
|
2525
|
+
}, []), I = te(() => {
|
|
2526
|
+
E(""), c({});
|
|
2527
|
+
}, []), L = te(
|
|
2528
|
+
async (P) => {
|
|
2529
|
+
if (P && P.preventDefault(), !(n && !n())) {
|
|
2530
|
+
p(!0), E("");
|
|
2382
2531
|
try {
|
|
2383
|
-
const
|
|
2384
|
-
return i == null || i(
|
|
2385
|
-
} catch (
|
|
2386
|
-
const m =
|
|
2387
|
-
|
|
2532
|
+
const R = await e();
|
|
2533
|
+
return i == null || i(R), R;
|
|
2534
|
+
} catch (R) {
|
|
2535
|
+
const m = R instanceof Error ? R.message : t;
|
|
2536
|
+
E(m), o == null || o(m);
|
|
2388
2537
|
return;
|
|
2389
2538
|
} finally {
|
|
2390
|
-
|
|
2539
|
+
p(!1);
|
|
2391
2540
|
}
|
|
2392
2541
|
}
|
|
2393
2542
|
},
|
|
2394
|
-
[e, n, t, i,
|
|
2543
|
+
[e, n, t, i, o]
|
|
2395
2544
|
);
|
|
2396
2545
|
return {
|
|
2397
|
-
loading:
|
|
2398
|
-
error:
|
|
2399
|
-
setError:
|
|
2400
|
-
fieldErrors:
|
|
2546
|
+
loading: a,
|
|
2547
|
+
error: k,
|
|
2548
|
+
setError: E,
|
|
2549
|
+
fieldErrors: S,
|
|
2401
2550
|
setFieldError: d,
|
|
2402
|
-
clearFieldError:
|
|
2403
|
-
resetErrors:
|
|
2404
|
-
handleSubmit:
|
|
2551
|
+
clearFieldError: x,
|
|
2552
|
+
resetErrors: I,
|
|
2553
|
+
handleSubmit: L
|
|
2405
2554
|
};
|
|
2406
2555
|
}
|
|
2407
|
-
const
|
|
2556
|
+
const lt = {
|
|
2408
2557
|
container: {
|
|
2409
2558
|
maxWidth: "400px",
|
|
2410
2559
|
width: "100%",
|
|
@@ -2568,18 +2717,18 @@ const it = {
|
|
|
2568
2717
|
color: "#6b7280"
|
|
2569
2718
|
}
|
|
2570
2719
|
};
|
|
2571
|
-
function
|
|
2720
|
+
function Fe(r, e) {
|
|
2572
2721
|
return {
|
|
2573
|
-
...
|
|
2722
|
+
...lt,
|
|
2574
2723
|
...e,
|
|
2575
2724
|
button: {
|
|
2576
|
-
...
|
|
2725
|
+
...lt.button,
|
|
2577
2726
|
backgroundColor: r,
|
|
2578
2727
|
...(e == null ? void 0 : e.button) || {}
|
|
2579
2728
|
}
|
|
2580
2729
|
};
|
|
2581
2730
|
}
|
|
2582
|
-
const
|
|
2731
|
+
const ur = () => me.createElement(
|
|
2583
2732
|
"svg",
|
|
2584
2733
|
{
|
|
2585
2734
|
width: "16",
|
|
@@ -2594,7 +2743,7 @@ const ir = () => me.createElement(
|
|
|
2594
2743
|
},
|
|
2595
2744
|
me.createElement("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
|
|
2596
2745
|
me.createElement("circle", { cx: "12", cy: "12", r: "3" })
|
|
2597
|
-
),
|
|
2746
|
+
), dr = () => me.createElement(
|
|
2598
2747
|
"svg",
|
|
2599
2748
|
{
|
|
2600
2749
|
width: "16",
|
|
@@ -2611,10 +2760,10 @@ const ir = () => me.createElement(
|
|
|
2611
2760
|
d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"
|
|
2612
2761
|
}),
|
|
2613
2762
|
me.createElement("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
|
|
2614
|
-
),
|
|
2615
|
-
showPassword: /* @__PURE__ */ s(
|
|
2616
|
-
hidePassword: /* @__PURE__ */ s(
|
|
2617
|
-
},
|
|
2763
|
+
), hr = {
|
|
2764
|
+
showPassword: /* @__PURE__ */ s(ur, {}),
|
|
2765
|
+
hidePassword: /* @__PURE__ */ s(dr, {})
|
|
2766
|
+
}, pr = {
|
|
2618
2767
|
title: "Sign In",
|
|
2619
2768
|
usernameLabel: "Email or Phone",
|
|
2620
2769
|
usernamePlaceholder: "Enter your email or phone number",
|
|
@@ -2633,40 +2782,40 @@ const ir = () => me.createElement(
|
|
|
2633
2782
|
showPasswordAriaLabel: "Show password",
|
|
2634
2783
|
hidePasswordAriaLabel: "Hide password"
|
|
2635
2784
|
};
|
|
2636
|
-
function
|
|
2785
|
+
function rn({
|
|
2637
2786
|
copy: r = {},
|
|
2638
2787
|
styles: e = {},
|
|
2639
2788
|
icons: t = {},
|
|
2640
2789
|
onSuccess: n,
|
|
2641
2790
|
onError: i,
|
|
2642
|
-
onForgotPassword:
|
|
2643
|
-
onSignupClick:
|
|
2644
|
-
onMagicLinkClick:
|
|
2645
|
-
showForgotPassword:
|
|
2646
|
-
showSignupLink:
|
|
2647
|
-
showMagicLinkOption:
|
|
2791
|
+
onForgotPassword: o,
|
|
2792
|
+
onSignupClick: a,
|
|
2793
|
+
onMagicLinkClick: p,
|
|
2794
|
+
showForgotPassword: k = !0,
|
|
2795
|
+
showSignupLink: E = !0,
|
|
2796
|
+
showMagicLinkOption: S = !0,
|
|
2648
2797
|
className: c
|
|
2649
2798
|
}) {
|
|
2650
|
-
const [d,
|
|
2799
|
+
const [d, x] = C(""), [I, L] = C(""), [P, R] = C(!1), { login: m } = ue(), g = { ...pr, ...r }, b = Fe("#3b82f6", e), w = { ...hr, ...t }, l = Te({
|
|
2651
2800
|
defaultErrorMessage: g.errorMessage,
|
|
2652
2801
|
validate: () => {
|
|
2653
2802
|
const u = [];
|
|
2654
|
-
return d.trim() || u.push("username"),
|
|
2803
|
+
return d.trim() || u.push("username"), I.trim() || u.push("password"), u.forEach((T) => l.setFieldError(T, !0)), u.length === 0;
|
|
2655
2804
|
},
|
|
2656
|
-
submit: () => m({ username: d, password:
|
|
2805
|
+
submit: () => m({ username: d, password: I }),
|
|
2657
2806
|
onSuccess: n,
|
|
2658
2807
|
onError: i
|
|
2659
|
-
}),
|
|
2808
|
+
}), h = (u) => ({
|
|
2660
2809
|
...b.input,
|
|
2661
|
-
...
|
|
2662
|
-
}),
|
|
2810
|
+
...l.fieldErrors[u] ? b.inputError : {}
|
|
2811
|
+
}), A = !d || !I || l.loading, y = {
|
|
2663
2812
|
...b.button,
|
|
2664
|
-
...
|
|
2665
|
-
...
|
|
2813
|
+
...l.loading ? b.buttonLoading : {},
|
|
2814
|
+
...A ? b.buttonDisabled : {}
|
|
2666
2815
|
};
|
|
2667
2816
|
return /* @__PURE__ */ f("div", { className: c, style: b.container, children: [
|
|
2668
2817
|
/* @__PURE__ */ s("h2", { style: b.title, children: g.title }),
|
|
2669
|
-
/* @__PURE__ */ f("form", { onSubmit:
|
|
2818
|
+
/* @__PURE__ */ f("form", { onSubmit: l.handleSubmit, style: b.form, children: [
|
|
2670
2819
|
/* @__PURE__ */ f("div", { style: b.fieldGroup, children: [
|
|
2671
2820
|
/* @__PURE__ */ s("label", { style: b.label, children: g.usernameLabel }),
|
|
2672
2821
|
/* @__PURE__ */ s(
|
|
@@ -2677,11 +2826,11 @@ function Kr({
|
|
|
2677
2826
|
type: "text",
|
|
2678
2827
|
value: d,
|
|
2679
2828
|
onChange: (u) => {
|
|
2680
|
-
|
|
2829
|
+
x(u.target.value), l.clearFieldError("username");
|
|
2681
2830
|
},
|
|
2682
2831
|
placeholder: g.usernamePlaceholder,
|
|
2683
|
-
style:
|
|
2684
|
-
disabled:
|
|
2832
|
+
style: h("username"),
|
|
2833
|
+
disabled: l.loading
|
|
2685
2834
|
}
|
|
2686
2835
|
)
|
|
2687
2836
|
] }),
|
|
@@ -2693,54 +2842,54 @@ function Kr({
|
|
|
2693
2842
|
{
|
|
2694
2843
|
id: "password",
|
|
2695
2844
|
name: "password",
|
|
2696
|
-
type:
|
|
2697
|
-
value:
|
|
2845
|
+
type: P ? "text" : "password",
|
|
2846
|
+
value: I,
|
|
2698
2847
|
onChange: (u) => {
|
|
2699
|
-
|
|
2848
|
+
L(u.target.value), l.clearFieldError("password");
|
|
2700
2849
|
},
|
|
2701
2850
|
placeholder: g.passwordPlaceholder,
|
|
2702
|
-
style: { ...
|
|
2703
|
-
disabled:
|
|
2851
|
+
style: { ...h("password"), ...b.inputWithIcon },
|
|
2852
|
+
disabled: l.loading
|
|
2704
2853
|
}
|
|
2705
2854
|
),
|
|
2706
2855
|
/* @__PURE__ */ s(
|
|
2707
2856
|
"button",
|
|
2708
2857
|
{
|
|
2709
2858
|
type: "button",
|
|
2710
|
-
onClick: () =>
|
|
2859
|
+
onClick: () => R(!P),
|
|
2711
2860
|
style: b.passwordToggle,
|
|
2712
|
-
disabled:
|
|
2713
|
-
"aria-label":
|
|
2714
|
-
children:
|
|
2861
|
+
disabled: l.loading,
|
|
2862
|
+
"aria-label": P ? g.hidePasswordAriaLabel : g.showPasswordAriaLabel,
|
|
2863
|
+
children: P ? w.hidePassword : w.showPassword
|
|
2715
2864
|
}
|
|
2716
2865
|
)
|
|
2717
2866
|
] })
|
|
2718
2867
|
] }),
|
|
2719
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled:
|
|
2720
|
-
|
|
2868
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: A, style: y, children: l.loading ? g.loadingText : g.submitButton }),
|
|
2869
|
+
l.error && /* @__PURE__ */ s("div", { style: b.errorText, children: l.error })
|
|
2721
2870
|
] }),
|
|
2722
|
-
(
|
|
2723
|
-
|
|
2871
|
+
(k || E || S) && /* @__PURE__ */ f("div", { style: b.linkContainer, children: [
|
|
2872
|
+
S && /* @__PURE__ */ f("div", { children: [
|
|
2724
2873
|
/* @__PURE__ */ f("span", { style: b.divider, children: [
|
|
2725
2874
|
g.magicLinkText,
|
|
2726
2875
|
" "
|
|
2727
2876
|
] }),
|
|
2728
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
2877
|
+
/* @__PURE__ */ s("a", { onClick: p, style: b.link, children: g.magicLinkLink })
|
|
2729
2878
|
] }),
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2879
|
+
S && (k || E) && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
|
|
2880
|
+
k && /* @__PURE__ */ s("a", { onClick: o, style: b.link, children: g.forgotPasswordLink }),
|
|
2881
|
+
k && E && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
|
|
2882
|
+
E && /* @__PURE__ */ f("div", { children: [
|
|
2734
2883
|
/* @__PURE__ */ f("span", { style: b.divider, children: [
|
|
2735
2884
|
g.signupText,
|
|
2736
2885
|
" "
|
|
2737
2886
|
] }),
|
|
2738
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
2887
|
+
/* @__PURE__ */ s("a", { onClick: a, style: b.link, children: g.signupLink })
|
|
2739
2888
|
] })
|
|
2740
2889
|
] })
|
|
2741
2890
|
] });
|
|
2742
2891
|
}
|
|
2743
|
-
const
|
|
2892
|
+
const fr = {
|
|
2744
2893
|
title: "Create Account",
|
|
2745
2894
|
nameLabel: "First Name",
|
|
2746
2895
|
namePlaceholder: "Enter your first name",
|
|
@@ -2770,75 +2919,75 @@ const cr = {
|
|
|
2770
2919
|
tenantNotFoundError: "Tenant not found",
|
|
2771
2920
|
dividerBullet: "•"
|
|
2772
2921
|
};
|
|
2773
|
-
function
|
|
2922
|
+
function nn({
|
|
2774
2923
|
copy: r = {},
|
|
2775
2924
|
styles: e = {},
|
|
2776
2925
|
signupType: t = "user",
|
|
2777
2926
|
onSuccess: n,
|
|
2778
2927
|
onError: i,
|
|
2779
|
-
onLoginClick:
|
|
2780
|
-
onMagicLinkClick:
|
|
2781
|
-
showLoginLink:
|
|
2782
|
-
showMagicLinkOption:
|
|
2783
|
-
className:
|
|
2928
|
+
onLoginClick: o,
|
|
2929
|
+
onMagicLinkClick: a,
|
|
2930
|
+
showLoginLink: p = !0,
|
|
2931
|
+
showMagicLinkOption: k = !0,
|
|
2932
|
+
className: E
|
|
2784
2933
|
}) {
|
|
2785
|
-
var
|
|
2786
|
-
const [
|
|
2787
|
-
defaultErrorMessage:
|
|
2934
|
+
var D;
|
|
2935
|
+
const [S, c] = C(""), [d, x] = C(""), [I, L] = C(""), [P, R] = C(""), [m, g] = C(""), [b, w] = C(""), [l, h] = C(""), { signup: A, signupTenantAdmin: y } = ue(), u = ((D = pe()) == null ? void 0 : D.tenant) ?? null, T = { ...fr, ...r }, M = Fe("#10b981", e), se = !!S && (!!I || !!P) && !!m && !!b && (t === "user" || !!l), N = Te({
|
|
2936
|
+
defaultErrorMessage: T.errorMessage,
|
|
2788
2937
|
validate: () => {
|
|
2789
|
-
const
|
|
2790
|
-
return
|
|
2938
|
+
const F = [];
|
|
2939
|
+
return S.trim() || F.push("name"), !I.trim() && !P.trim() && (F.push("email"), F.push("phoneNumber")), m.trim() || F.push("password"), b.trim() || F.push("confirmPassword"), t === "tenant" && !l.trim() && F.push("tenantName"), F.forEach((_) => N.setFieldError(_, !0)), F.length > 0 ? !1 : m !== b ? (N.setError(T.passwordMismatchError), N.setFieldError("confirmPassword", !0), !1) : t === "user" && !(u != null && u.id) ? (N.setError(T.tenantNotFoundError), !1) : !0;
|
|
2791
2940
|
},
|
|
2792
2941
|
submit: async () => t === "tenant" ? y({
|
|
2793
|
-
email:
|
|
2794
|
-
phoneNumber:
|
|
2795
|
-
name:
|
|
2942
|
+
email: I || void 0,
|
|
2943
|
+
phoneNumber: P || void 0,
|
|
2944
|
+
name: S,
|
|
2796
2945
|
password: m,
|
|
2797
|
-
tenantName:
|
|
2946
|
+
tenantName: l,
|
|
2798
2947
|
lastName: d || void 0
|
|
2799
|
-
}) :
|
|
2800
|
-
email:
|
|
2801
|
-
phoneNumber:
|
|
2802
|
-
name:
|
|
2948
|
+
}) : A({
|
|
2949
|
+
email: I || void 0,
|
|
2950
|
+
phoneNumber: P || void 0,
|
|
2951
|
+
name: S,
|
|
2803
2952
|
password: m,
|
|
2804
2953
|
tenantId: u.id,
|
|
2805
2954
|
lastName: d || void 0
|
|
2806
2955
|
}),
|
|
2807
2956
|
onSuccess: n,
|
|
2808
2957
|
onError: i
|
|
2809
|
-
}),
|
|
2810
|
-
...
|
|
2811
|
-
...
|
|
2812
|
-
}),
|
|
2813
|
-
...
|
|
2814
|
-
...
|
|
2815
|
-
...
|
|
2816
|
-
},
|
|
2817
|
-
|
|
2958
|
+
}), W = (F) => ({
|
|
2959
|
+
...M.input,
|
|
2960
|
+
...N.fieldErrors[F] ? M.inputError : {}
|
|
2961
|
+
}), z = !se || N.loading, Z = {
|
|
2962
|
+
...M.button,
|
|
2963
|
+
...N.loading ? M.buttonLoading : {},
|
|
2964
|
+
...z ? M.buttonDisabled : {}
|
|
2965
|
+
}, K = () => {
|
|
2966
|
+
N.clearFieldError("email"), N.clearFieldError("phoneNumber");
|
|
2818
2967
|
};
|
|
2819
|
-
return /* @__PURE__ */ f("div", { className:
|
|
2820
|
-
/* @__PURE__ */ s("h2", { style:
|
|
2821
|
-
/* @__PURE__ */ f("form", { onSubmit:
|
|
2822
|
-
/* @__PURE__ */ f("div", { style:
|
|
2823
|
-
/* @__PURE__ */ s("label", { style:
|
|
2968
|
+
return /* @__PURE__ */ f("div", { className: E, style: M.container, children: [
|
|
2969
|
+
/* @__PURE__ */ s("h2", { style: M.title, children: T.title }),
|
|
2970
|
+
/* @__PURE__ */ f("form", { onSubmit: N.handleSubmit, style: M.form, children: [
|
|
2971
|
+
/* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
2972
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.nameLabel }),
|
|
2824
2973
|
/* @__PURE__ */ s(
|
|
2825
2974
|
"input",
|
|
2826
2975
|
{
|
|
2827
2976
|
id: "name",
|
|
2828
2977
|
name: "name",
|
|
2829
2978
|
type: "text",
|
|
2830
|
-
value:
|
|
2831
|
-
onChange: (
|
|
2832
|
-
c(
|
|
2979
|
+
value: S,
|
|
2980
|
+
onChange: (F) => {
|
|
2981
|
+
c(F.target.value), N.clearFieldError("name");
|
|
2833
2982
|
},
|
|
2834
|
-
placeholder:
|
|
2835
|
-
style:
|
|
2836
|
-
disabled:
|
|
2983
|
+
placeholder: T.namePlaceholder,
|
|
2984
|
+
style: W("name"),
|
|
2985
|
+
disabled: N.loading
|
|
2837
2986
|
}
|
|
2838
2987
|
)
|
|
2839
2988
|
] }),
|
|
2840
|
-
/* @__PURE__ */ f("div", { style:
|
|
2841
|
-
/* @__PURE__ */ s("label", { style:
|
|
2989
|
+
/* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
2990
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.lastNameLabel }),
|
|
2842
2991
|
/* @__PURE__ */ s(
|
|
2843
2992
|
"input",
|
|
2844
2993
|
{
|
|
@@ -2846,52 +2995,52 @@ function Yr({
|
|
|
2846
2995
|
name: "lastName",
|
|
2847
2996
|
type: "text",
|
|
2848
2997
|
value: d,
|
|
2849
|
-
onChange: (
|
|
2850
|
-
placeholder:
|
|
2851
|
-
style:
|
|
2852
|
-
disabled:
|
|
2998
|
+
onChange: (F) => x(F.target.value),
|
|
2999
|
+
placeholder: T.lastNamePlaceholder,
|
|
3000
|
+
style: M.input,
|
|
3001
|
+
disabled: N.loading
|
|
2853
3002
|
}
|
|
2854
3003
|
)
|
|
2855
3004
|
] }),
|
|
2856
|
-
/* @__PURE__ */ f("div", { style:
|
|
2857
|
-
/* @__PURE__ */ s("label", { style:
|
|
3005
|
+
/* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
3006
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.emailLabel }),
|
|
2858
3007
|
/* @__PURE__ */ s(
|
|
2859
3008
|
"input",
|
|
2860
3009
|
{
|
|
2861
3010
|
id: "email",
|
|
2862
3011
|
name: "email",
|
|
2863
3012
|
type: "email",
|
|
2864
|
-
value:
|
|
2865
|
-
onChange: (
|
|
2866
|
-
|
|
3013
|
+
value: I,
|
|
3014
|
+
onChange: (F) => {
|
|
3015
|
+
L(F.target.value), K();
|
|
2867
3016
|
},
|
|
2868
|
-
placeholder:
|
|
2869
|
-
style:
|
|
2870
|
-
disabled:
|
|
3017
|
+
placeholder: T.emailPlaceholder,
|
|
3018
|
+
style: W("email"),
|
|
3019
|
+
disabled: N.loading
|
|
2871
3020
|
}
|
|
2872
3021
|
)
|
|
2873
3022
|
] }),
|
|
2874
|
-
/* @__PURE__ */ f("div", { style:
|
|
2875
|
-
/* @__PURE__ */ s("label", { style:
|
|
3023
|
+
/* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
3024
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.phoneNumberLabel }),
|
|
2876
3025
|
/* @__PURE__ */ s(
|
|
2877
3026
|
"input",
|
|
2878
3027
|
{
|
|
2879
3028
|
id: "phoneNumber",
|
|
2880
3029
|
name: "phoneNumber",
|
|
2881
3030
|
type: "tel",
|
|
2882
|
-
value:
|
|
2883
|
-
onChange: (
|
|
2884
|
-
|
|
3031
|
+
value: P,
|
|
3032
|
+
onChange: (F) => {
|
|
3033
|
+
R(F.target.value), K();
|
|
2885
3034
|
},
|
|
2886
|
-
placeholder:
|
|
2887
|
-
style:
|
|
2888
|
-
disabled:
|
|
3035
|
+
placeholder: T.phoneNumberPlaceholder,
|
|
3036
|
+
style: W("phoneNumber"),
|
|
3037
|
+
disabled: N.loading
|
|
2889
3038
|
}
|
|
2890
3039
|
)
|
|
2891
3040
|
] }),
|
|
2892
|
-
/* @__PURE__ */ s("div", { style:
|
|
2893
|
-
/* @__PURE__ */ f("div", { style:
|
|
2894
|
-
/* @__PURE__ */ s("label", { style:
|
|
3041
|
+
/* @__PURE__ */ s("div", { style: M.hintText, children: T.contactMethodHint }),
|
|
3042
|
+
/* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
3043
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.passwordLabel }),
|
|
2895
3044
|
/* @__PURE__ */ s(
|
|
2896
3045
|
"input",
|
|
2897
3046
|
{
|
|
@@ -2899,17 +3048,17 @@ function Yr({
|
|
|
2899
3048
|
name: "password",
|
|
2900
3049
|
type: "password",
|
|
2901
3050
|
value: m,
|
|
2902
|
-
onChange: (
|
|
2903
|
-
g(
|
|
3051
|
+
onChange: (F) => {
|
|
3052
|
+
g(F.target.value), N.clearFieldError("password");
|
|
2904
3053
|
},
|
|
2905
|
-
placeholder:
|
|
2906
|
-
style:
|
|
2907
|
-
disabled:
|
|
3054
|
+
placeholder: T.passwordPlaceholder,
|
|
3055
|
+
style: W("password"),
|
|
3056
|
+
disabled: N.loading
|
|
2908
3057
|
}
|
|
2909
3058
|
)
|
|
2910
3059
|
] }),
|
|
2911
|
-
/* @__PURE__ */ f("div", { style:
|
|
2912
|
-
/* @__PURE__ */ s("label", { style:
|
|
3060
|
+
/* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
3061
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.confirmPasswordLabel }),
|
|
2913
3062
|
/* @__PURE__ */ s(
|
|
2914
3063
|
"input",
|
|
2915
3064
|
{
|
|
@@ -2917,56 +3066,56 @@ function Yr({
|
|
|
2917
3066
|
name: "confirmPassword",
|
|
2918
3067
|
type: "password",
|
|
2919
3068
|
value: b,
|
|
2920
|
-
onChange: (
|
|
2921
|
-
|
|
3069
|
+
onChange: (F) => {
|
|
3070
|
+
w(F.target.value), N.clearFieldError("confirmPassword"), N.error === T.passwordMismatchError && N.setError("");
|
|
2922
3071
|
},
|
|
2923
|
-
placeholder:
|
|
2924
|
-
style:
|
|
2925
|
-
disabled:
|
|
3072
|
+
placeholder: T.confirmPasswordPlaceholder,
|
|
3073
|
+
style: W("confirmPassword"),
|
|
3074
|
+
disabled: N.loading
|
|
2926
3075
|
}
|
|
2927
3076
|
)
|
|
2928
3077
|
] }),
|
|
2929
|
-
t === "tenant" && /* @__PURE__ */ f("div", { style:
|
|
2930
|
-
/* @__PURE__ */ s("label", { style:
|
|
3078
|
+
t === "tenant" && /* @__PURE__ */ f("div", { style: M.fieldGroup, children: [
|
|
3079
|
+
/* @__PURE__ */ s("label", { style: M.label, children: T.tenantNameLabel }),
|
|
2931
3080
|
/* @__PURE__ */ s(
|
|
2932
3081
|
"input",
|
|
2933
3082
|
{
|
|
2934
3083
|
id: "tenantName",
|
|
2935
3084
|
name: "tenantName",
|
|
2936
3085
|
type: "text",
|
|
2937
|
-
value:
|
|
2938
|
-
onChange: (
|
|
2939
|
-
|
|
3086
|
+
value: l,
|
|
3087
|
+
onChange: (F) => {
|
|
3088
|
+
h(F.target.value), N.clearFieldError("tenantName");
|
|
2940
3089
|
},
|
|
2941
|
-
placeholder:
|
|
2942
|
-
style:
|
|
2943
|
-
disabled:
|
|
3090
|
+
placeholder: T.tenantNamePlaceholder,
|
|
3091
|
+
style: W("tenantName"),
|
|
3092
|
+
disabled: N.loading
|
|
2944
3093
|
}
|
|
2945
3094
|
)
|
|
2946
3095
|
] }),
|
|
2947
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled:
|
|
2948
|
-
|
|
3096
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: z, style: Z, children: N.loading ? T.loadingText : T.submitButton }),
|
|
3097
|
+
N.error && /* @__PURE__ */ s("div", { style: M.errorText, children: N.error })
|
|
2949
3098
|
] }),
|
|
2950
|
-
(
|
|
2951
|
-
|
|
2952
|
-
/* @__PURE__ */ f("span", { style:
|
|
2953
|
-
|
|
3099
|
+
(p || k) && /* @__PURE__ */ f("div", { style: M.linkContainer, children: [
|
|
3100
|
+
k && /* @__PURE__ */ f("div", { children: [
|
|
3101
|
+
/* @__PURE__ */ f("span", { style: M.divider, children: [
|
|
3102
|
+
T.magicLinkText,
|
|
2954
3103
|
" "
|
|
2955
3104
|
] }),
|
|
2956
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
3105
|
+
/* @__PURE__ */ s("a", { onClick: a, style: M.link, children: T.magicLinkLink })
|
|
2957
3106
|
] }),
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
/* @__PURE__ */ f("span", { style:
|
|
2961
|
-
|
|
3107
|
+
k && p && /* @__PURE__ */ s("div", { style: M.divider, children: T.dividerBullet }),
|
|
3108
|
+
p && /* @__PURE__ */ f("div", { children: [
|
|
3109
|
+
/* @__PURE__ */ f("span", { style: M.divider, children: [
|
|
3110
|
+
T.loginText,
|
|
2962
3111
|
" "
|
|
2963
3112
|
] }),
|
|
2964
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
3113
|
+
/* @__PURE__ */ s("a", { onClick: o, style: M.link, children: T.loginLink })
|
|
2965
3114
|
] })
|
|
2966
3115
|
] })
|
|
2967
3116
|
] });
|
|
2968
3117
|
}
|
|
2969
|
-
const
|
|
3118
|
+
const mr = {
|
|
2970
3119
|
title: "Sign In with Magic Link",
|
|
2971
3120
|
emailLabel: "Email",
|
|
2972
3121
|
emailPlaceholder: "Enter your email",
|
|
@@ -2991,73 +3140,73 @@ const ur = {
|
|
|
2991
3140
|
missingTenantOrEmailError: "Missing tenant or email",
|
|
2992
3141
|
dividerBullet: "•"
|
|
2993
3142
|
};
|
|
2994
|
-
function
|
|
3143
|
+
function sn({
|
|
2995
3144
|
copy: r = {},
|
|
2996
3145
|
styles: e = {},
|
|
2997
3146
|
onSuccess: t,
|
|
2998
3147
|
onError: n,
|
|
2999
3148
|
onLoginClick: i,
|
|
3000
|
-
onSignupClick:
|
|
3001
|
-
showTraditionalLinks:
|
|
3002
|
-
className:
|
|
3003
|
-
verifyToken:
|
|
3004
|
-
frontendUrl:
|
|
3149
|
+
onSignupClick: o,
|
|
3150
|
+
showTraditionalLinks: a = !0,
|
|
3151
|
+
className: p,
|
|
3152
|
+
verifyToken: k,
|
|
3153
|
+
frontendUrl: E
|
|
3005
3154
|
}) {
|
|
3006
|
-
var
|
|
3007
|
-
const [
|
|
3155
|
+
var W;
|
|
3156
|
+
const [S, c] = C(""), [d, x] = C(""), [I, L] = C(""), [P, R] = C(!1), [m, g] = C(""), [b, w] = C(!1), { sendMagicLink: l, verifyMagicLink: h } = ue(), A = ((W = pe()) == null ? void 0 : W.tenant) ?? null, y = { ...mr, ...r }, u = Fe("#3b82f6", e), T = Te({
|
|
3008
3157
|
defaultErrorMessage: y.errorMessage,
|
|
3009
3158
|
validate: () => {
|
|
3010
|
-
const
|
|
3011
|
-
return
|
|
3159
|
+
const z = [];
|
|
3160
|
+
return S.trim() || z.push("email"), b && !d.trim() && z.push("name"), z.forEach((Z) => T.setFieldError(Z, !0)), z.length > 0 ? !1 : A != null && A.id ? !0 : (T.setError(y.tenantNotFoundError), !1);
|
|
3012
3161
|
},
|
|
3013
3162
|
submit: async () => {
|
|
3014
3163
|
g("");
|
|
3015
|
-
const
|
|
3016
|
-
email:
|
|
3017
|
-
tenantId:
|
|
3018
|
-
frontendUrl:
|
|
3164
|
+
const z = E || (typeof window < "u" ? window.location.origin : ""), Z = await l({
|
|
3165
|
+
email: S,
|
|
3166
|
+
tenantId: A.id,
|
|
3167
|
+
frontendUrl: z,
|
|
3019
3168
|
name: b ? d : void 0,
|
|
3020
|
-
lastName: b ?
|
|
3169
|
+
lastName: b ? I : void 0
|
|
3021
3170
|
});
|
|
3022
|
-
return g(y.successMessage),
|
|
3171
|
+
return g(y.successMessage), Z;
|
|
3023
3172
|
},
|
|
3024
3173
|
onSuccess: t,
|
|
3025
3174
|
onError: n
|
|
3026
3175
|
});
|
|
3027
3176
|
re(() => {
|
|
3028
|
-
if (!
|
|
3177
|
+
if (!k) return;
|
|
3029
3178
|
(async () => {
|
|
3030
|
-
if (!
|
|
3031
|
-
|
|
3179
|
+
if (!A || !S) {
|
|
3180
|
+
T.setError(y.missingTenantOrEmailError);
|
|
3032
3181
|
return;
|
|
3033
3182
|
}
|
|
3034
|
-
|
|
3183
|
+
R(!0), T.setError("");
|
|
3035
3184
|
try {
|
|
3036
|
-
const
|
|
3037
|
-
t == null || t(
|
|
3038
|
-
} catch (
|
|
3039
|
-
const
|
|
3040
|
-
|
|
3185
|
+
const Z = await h({ token: k, email: S });
|
|
3186
|
+
t == null || t(Z);
|
|
3187
|
+
} catch (Z) {
|
|
3188
|
+
const K = Z instanceof Error ? Z.message : "Failed to verify magic link";
|
|
3189
|
+
T.setError(K), n == null || n(K);
|
|
3041
3190
|
} finally {
|
|
3042
|
-
|
|
3191
|
+
R(!1);
|
|
3043
3192
|
}
|
|
3044
3193
|
})();
|
|
3045
|
-
}, [
|
|
3046
|
-
const
|
|
3194
|
+
}, [k]);
|
|
3195
|
+
const M = (z) => ({
|
|
3047
3196
|
...u.input,
|
|
3048
|
-
...
|
|
3049
|
-
}), se = !
|
|
3197
|
+
...T.fieldErrors[z] ? u.inputError : {}
|
|
3198
|
+
}), se = !S || T.loading || P, N = {
|
|
3050
3199
|
...u.button,
|
|
3051
|
-
...
|
|
3200
|
+
...T.loading || P ? u.buttonLoading : {},
|
|
3052
3201
|
...se ? u.buttonDisabled : {}
|
|
3053
3202
|
};
|
|
3054
|
-
return
|
|
3203
|
+
return P ? /* @__PURE__ */ f("div", { className: p, style: u.container, children: [
|
|
3055
3204
|
/* @__PURE__ */ s("h2", { style: u.title, children: y.verifyingText }),
|
|
3056
3205
|
/* @__PURE__ */ s("div", { style: u.verifyingContainer, children: /* @__PURE__ */ s("div", { style: u.verifyingText, children: y.verifyingDescription }) })
|
|
3057
|
-
] }) : /* @__PURE__ */ f("div", { className:
|
|
3206
|
+
] }) : /* @__PURE__ */ f("div", { className: p, style: u.container, children: [
|
|
3058
3207
|
/* @__PURE__ */ s("h2", { style: u.title, children: y.title }),
|
|
3059
3208
|
/* @__PURE__ */ s("p", { style: u.description, children: y.description }),
|
|
3060
|
-
/* @__PURE__ */ f("form", { onSubmit:
|
|
3209
|
+
/* @__PURE__ */ f("form", { onSubmit: T.handleSubmit, style: u.form, children: [
|
|
3061
3210
|
/* @__PURE__ */ f("div", { style: u.fieldGroup, children: [
|
|
3062
3211
|
/* @__PURE__ */ s("label", { style: u.label, children: y.emailLabel }),
|
|
3063
3212
|
/* @__PURE__ */ s(
|
|
@@ -3066,13 +3215,13 @@ function Xr({
|
|
|
3066
3215
|
id: "email",
|
|
3067
3216
|
name: "email",
|
|
3068
3217
|
type: "email",
|
|
3069
|
-
value:
|
|
3070
|
-
onChange: (
|
|
3071
|
-
c(
|
|
3218
|
+
value: S,
|
|
3219
|
+
onChange: (z) => {
|
|
3220
|
+
c(z.target.value), T.clearFieldError("email");
|
|
3072
3221
|
},
|
|
3073
3222
|
placeholder: y.emailPlaceholder,
|
|
3074
|
-
style:
|
|
3075
|
-
disabled:
|
|
3223
|
+
style: M("email"),
|
|
3224
|
+
disabled: T.loading || P
|
|
3076
3225
|
}
|
|
3077
3226
|
)
|
|
3078
3227
|
] }),
|
|
@@ -3080,7 +3229,7 @@ function Xr({
|
|
|
3080
3229
|
"button",
|
|
3081
3230
|
{
|
|
3082
3231
|
type: "button",
|
|
3083
|
-
onClick: () =>
|
|
3232
|
+
onClick: () => w(!0),
|
|
3084
3233
|
style: u.toggleLink,
|
|
3085
3234
|
children: y.showNameToggle
|
|
3086
3235
|
}
|
|
@@ -3095,12 +3244,12 @@ function Xr({
|
|
|
3095
3244
|
name: "name",
|
|
3096
3245
|
type: "text",
|
|
3097
3246
|
value: d,
|
|
3098
|
-
onChange: (
|
|
3099
|
-
|
|
3247
|
+
onChange: (z) => {
|
|
3248
|
+
x(z.target.value), T.clearFieldError("name");
|
|
3100
3249
|
},
|
|
3101
3250
|
placeholder: y.namePlaceholder,
|
|
3102
|
-
style:
|
|
3103
|
-
disabled:
|
|
3251
|
+
style: M("name"),
|
|
3252
|
+
disabled: T.loading || P
|
|
3104
3253
|
}
|
|
3105
3254
|
)
|
|
3106
3255
|
] }),
|
|
@@ -3112,11 +3261,11 @@ function Xr({
|
|
|
3112
3261
|
id: "lastName",
|
|
3113
3262
|
name: "lastName",
|
|
3114
3263
|
type: "text",
|
|
3115
|
-
value:
|
|
3116
|
-
onChange: (
|
|
3264
|
+
value: I,
|
|
3265
|
+
onChange: (z) => L(z.target.value),
|
|
3117
3266
|
placeholder: y.lastNamePlaceholder,
|
|
3118
3267
|
style: u.input,
|
|
3119
|
-
disabled:
|
|
3268
|
+
disabled: T.loading || P
|
|
3120
3269
|
}
|
|
3121
3270
|
)
|
|
3122
3271
|
] }),
|
|
@@ -3125,18 +3274,18 @@ function Xr({
|
|
|
3125
3274
|
{
|
|
3126
3275
|
type: "button",
|
|
3127
3276
|
onClick: () => {
|
|
3128
|
-
|
|
3277
|
+
w(!1), x(""), L("");
|
|
3129
3278
|
},
|
|
3130
3279
|
style: u.toggleLink,
|
|
3131
3280
|
children: y.hideNameToggle
|
|
3132
3281
|
}
|
|
3133
3282
|
) })
|
|
3134
3283
|
] }),
|
|
3135
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled: se, style:
|
|
3136
|
-
|
|
3284
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: se, style: N, children: T.loading ? y.loadingText : y.submitButton }),
|
|
3285
|
+
T.error && /* @__PURE__ */ s("div", { style: u.errorText, children: T.error }),
|
|
3137
3286
|
m && /* @__PURE__ */ s("div", { style: u.successText, children: m })
|
|
3138
3287
|
] }),
|
|
3139
|
-
|
|
3288
|
+
a && /* @__PURE__ */ f("div", { style: u.linkContainer, children: [
|
|
3140
3289
|
/* @__PURE__ */ f("div", { children: [
|
|
3141
3290
|
/* @__PURE__ */ f("span", { style: u.divider, children: [
|
|
3142
3291
|
y.loginText,
|
|
@@ -3150,12 +3299,12 @@ function Xr({
|
|
|
3150
3299
|
y.signupText,
|
|
3151
3300
|
" "
|
|
3152
3301
|
] }),
|
|
3153
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
3302
|
+
/* @__PURE__ */ s("a", { onClick: o, style: u.link, children: y.signupLink })
|
|
3154
3303
|
] })
|
|
3155
3304
|
] })
|
|
3156
3305
|
] });
|
|
3157
3306
|
}
|
|
3158
|
-
const
|
|
3307
|
+
const gr = {
|
|
3159
3308
|
title: "Verifying Magic Link",
|
|
3160
3309
|
verifyingMessage: "Please wait while we verify your magic link...",
|
|
3161
3310
|
successMessage: "Magic link verified successfully! You are now logged in.",
|
|
@@ -3164,7 +3313,7 @@ const dr = {
|
|
|
3164
3313
|
retryButton: "Try Again",
|
|
3165
3314
|
backToLoginButton: "Back to Login",
|
|
3166
3315
|
missingParamsError: "Missing required parameters: token or email"
|
|
3167
|
-
},
|
|
3316
|
+
}, pt = {
|
|
3168
3317
|
container: {
|
|
3169
3318
|
maxWidth: "400px",
|
|
3170
3319
|
width: "100%",
|
|
@@ -3257,7 +3406,7 @@ const dr = {
|
|
|
3257
3406
|
backButtonHover: {
|
|
3258
3407
|
backgroundColor: "#e5e7eb"
|
|
3259
3408
|
}
|
|
3260
|
-
},
|
|
3409
|
+
}, yr = () => /* @__PURE__ */ s("div", { style: pt.spinner }), br = () => /* @__PURE__ */ f(
|
|
3261
3410
|
"svg",
|
|
3262
3411
|
{
|
|
3263
3412
|
width: "48",
|
|
@@ -3274,7 +3423,7 @@ const dr = {
|
|
|
3274
3423
|
/* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
|
|
3275
3424
|
]
|
|
3276
3425
|
}
|
|
3277
|
-
),
|
|
3426
|
+
), wr = () => /* @__PURE__ */ f(
|
|
3278
3427
|
"svg",
|
|
3279
3428
|
{
|
|
3280
3429
|
width: "48",
|
|
@@ -3292,63 +3441,63 @@ const dr = {
|
|
|
3292
3441
|
/* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
|
|
3293
3442
|
]
|
|
3294
3443
|
}
|
|
3295
|
-
),
|
|
3296
|
-
loading: /* @__PURE__ */ s(
|
|
3297
|
-
success: /* @__PURE__ */ s(
|
|
3298
|
-
error: /* @__PURE__ */ s(
|
|
3444
|
+
), vr = {
|
|
3445
|
+
loading: /* @__PURE__ */ s(yr, {}),
|
|
3446
|
+
success: /* @__PURE__ */ s(br, {}),
|
|
3447
|
+
error: /* @__PURE__ */ s(wr, {})
|
|
3299
3448
|
};
|
|
3300
|
-
function
|
|
3449
|
+
function on({
|
|
3301
3450
|
copy: r = {},
|
|
3302
3451
|
styles: e = {},
|
|
3303
3452
|
icons: t = {},
|
|
3304
3453
|
onSuccess: n,
|
|
3305
3454
|
onError: i,
|
|
3306
|
-
onRetry:
|
|
3307
|
-
onBackToLogin:
|
|
3308
|
-
className:
|
|
3309
|
-
token:
|
|
3310
|
-
email:
|
|
3311
|
-
appId:
|
|
3455
|
+
onRetry: o,
|
|
3456
|
+
onBackToLogin: a,
|
|
3457
|
+
className: p,
|
|
3458
|
+
token: k,
|
|
3459
|
+
email: E,
|
|
3460
|
+
appId: S,
|
|
3312
3461
|
tenantSlug: c,
|
|
3313
3462
|
autoRedirectDelay: d = 3e3
|
|
3314
3463
|
}) {
|
|
3315
|
-
const [
|
|
3464
|
+
const [x, I] = C("verifying"), [L, P] = C(""), { verifyMagicLink: R } = ue(), m = { ...gr, ...r }, g = { ...pt, ...e }, b = { ...vr, ...t }, w = () => {
|
|
3316
3465
|
if (typeof window > "u") return {};
|
|
3317
3466
|
const u = new URLSearchParams(window.location.search);
|
|
3318
3467
|
return {
|
|
3319
|
-
token:
|
|
3320
|
-
email:
|
|
3321
|
-
appId:
|
|
3468
|
+
token: k || u.get("token") || "",
|
|
3469
|
+
email: E || u.get("email") || "",
|
|
3470
|
+
appId: S || u.get("appId") || "",
|
|
3322
3471
|
tenantSlug: c || u.get("tenantSlug") || void 0
|
|
3323
3472
|
};
|
|
3324
|
-
},
|
|
3325
|
-
|
|
3473
|
+
}, l = async () => {
|
|
3474
|
+
I("verifying"), P("");
|
|
3326
3475
|
try {
|
|
3327
|
-
const u =
|
|
3476
|
+
const u = w();
|
|
3328
3477
|
if (!u.token || !u.email)
|
|
3329
3478
|
throw new Error(m.missingParamsError);
|
|
3330
|
-
const
|
|
3479
|
+
const T = await R({
|
|
3331
3480
|
token: u.token,
|
|
3332
3481
|
email: u.email,
|
|
3333
3482
|
tenantSlug: u.tenantSlug
|
|
3334
3483
|
});
|
|
3335
|
-
|
|
3336
|
-
|
|
3484
|
+
I("success"), n == null || n(T), d > 0 && setTimeout(() => {
|
|
3485
|
+
I("redirecting");
|
|
3337
3486
|
}, d);
|
|
3338
3487
|
} catch (u) {
|
|
3339
|
-
const
|
|
3340
|
-
|
|
3488
|
+
const T = u.message || m.errorMessage;
|
|
3489
|
+
P(T), I("error"), i == null || i(T);
|
|
3341
3490
|
}
|
|
3342
|
-
},
|
|
3343
|
-
|
|
3344
|
-
},
|
|
3345
|
-
|
|
3491
|
+
}, h = () => {
|
|
3492
|
+
o == null || o(), l();
|
|
3493
|
+
}, A = () => {
|
|
3494
|
+
a == null || a();
|
|
3346
3495
|
};
|
|
3347
3496
|
re(() => {
|
|
3348
|
-
|
|
3497
|
+
l();
|
|
3349
3498
|
}, []);
|
|
3350
3499
|
const y = () => {
|
|
3351
|
-
switch (
|
|
3500
|
+
switch (x) {
|
|
3352
3501
|
case "verifying":
|
|
3353
3502
|
return /* @__PURE__ */ f("div", { style: g.message, children: [
|
|
3354
3503
|
b.loading,
|
|
@@ -3367,20 +3516,20 @@ function en({
|
|
|
3367
3516
|
case "error":
|
|
3368
3517
|
return /* @__PURE__ */ f(U, { children: [
|
|
3369
3518
|
b.error,
|
|
3370
|
-
/* @__PURE__ */ s("div", { style: g.errorMessage, children:
|
|
3519
|
+
/* @__PURE__ */ s("div", { style: g.errorMessage, children: L || m.errorMessage }),
|
|
3371
3520
|
/* @__PURE__ */ f("div", { style: g.buttonContainer, children: [
|
|
3372
3521
|
/* @__PURE__ */ s(
|
|
3373
3522
|
"button",
|
|
3374
3523
|
{
|
|
3375
|
-
onClick:
|
|
3524
|
+
onClick: h,
|
|
3376
3525
|
style: g.retryButton,
|
|
3377
3526
|
onMouseOver: (u) => {
|
|
3378
3527
|
Object.assign(u.currentTarget.style, g.retryButtonHover);
|
|
3379
3528
|
},
|
|
3380
3529
|
onMouseOut: (u) => {
|
|
3381
|
-
const
|
|
3382
|
-
Object.keys(g.retryButtonHover || {}).forEach((
|
|
3383
|
-
u.currentTarget.style[
|
|
3530
|
+
const T = g.retryButton || {};
|
|
3531
|
+
Object.keys(g.retryButtonHover || {}).forEach((M) => {
|
|
3532
|
+
u.currentTarget.style[M] = T[M] ?? "";
|
|
3384
3533
|
});
|
|
3385
3534
|
},
|
|
3386
3535
|
children: m.retryButton
|
|
@@ -3389,15 +3538,15 @@ function en({
|
|
|
3389
3538
|
/* @__PURE__ */ s(
|
|
3390
3539
|
"button",
|
|
3391
3540
|
{
|
|
3392
|
-
onClick:
|
|
3541
|
+
onClick: A,
|
|
3393
3542
|
style: g.backButton,
|
|
3394
3543
|
onMouseOver: (u) => {
|
|
3395
3544
|
Object.assign(u.currentTarget.style, g.backButtonHover);
|
|
3396
3545
|
},
|
|
3397
3546
|
onMouseOut: (u) => {
|
|
3398
|
-
const
|
|
3399
|
-
Object.keys(g.backButtonHover || {}).forEach((
|
|
3400
|
-
u.currentTarget.style[
|
|
3547
|
+
const T = g.backButton || {};
|
|
3548
|
+
Object.keys(g.backButtonHover || {}).forEach((M) => {
|
|
3549
|
+
u.currentTarget.style[M] = T[M] ?? "";
|
|
3401
3550
|
});
|
|
3402
3551
|
},
|
|
3403
3552
|
children: m.backToLoginButton
|
|
@@ -3409,7 +3558,7 @@ function en({
|
|
|
3409
3558
|
return null;
|
|
3410
3559
|
}
|
|
3411
3560
|
};
|
|
3412
|
-
return /* @__PURE__ */ f("div", { style: g.container, className:
|
|
3561
|
+
return /* @__PURE__ */ f("div", { style: g.container, className: p, children: [
|
|
3413
3562
|
/* @__PURE__ */ s("style", { children: `
|
|
3414
3563
|
@keyframes spin {
|
|
3415
3564
|
0% { transform: rotate(0deg); }
|
|
@@ -3420,7 +3569,7 @@ function en({
|
|
|
3420
3569
|
y()
|
|
3421
3570
|
] });
|
|
3422
3571
|
}
|
|
3423
|
-
const
|
|
3572
|
+
const Tr = {
|
|
3424
3573
|
title: "Reset Password",
|
|
3425
3574
|
subtitle: "Enter your email address and we'll send you a link to reset your password.",
|
|
3426
3575
|
emailLabel: "Email",
|
|
@@ -3447,154 +3596,154 @@ const gr = {
|
|
|
3447
3596
|
tenantNotFoundError: "Tenant not found",
|
|
3448
3597
|
dividerBullet: "•"
|
|
3449
3598
|
};
|
|
3450
|
-
function
|
|
3599
|
+
function an({
|
|
3451
3600
|
copy: r = {},
|
|
3452
3601
|
styles: e = {},
|
|
3453
3602
|
mode: t = "request",
|
|
3454
3603
|
token: n = "",
|
|
3455
3604
|
onSuccess: i,
|
|
3456
|
-
onError:
|
|
3457
|
-
onBackToLogin:
|
|
3458
|
-
onModeChange:
|
|
3459
|
-
className:
|
|
3605
|
+
onError: o,
|
|
3606
|
+
onBackToLogin: a,
|
|
3607
|
+
onModeChange: p,
|
|
3608
|
+
className: k
|
|
3460
3609
|
}) {
|
|
3461
3610
|
var se;
|
|
3462
|
-
const [
|
|
3463
|
-
defaultErrorMessage:
|
|
3464
|
-
validate: () =>
|
|
3611
|
+
const [E, S] = C(""), [c, d] = C(n), [x, I] = C(""), [L, P] = C(""), [R, m] = C(""), { requestPasswordReset: g, confirmPasswordReset: b } = ue(), w = ((se = pe()) == null ? void 0 : se.tenant) ?? null, l = { ...Tr, ...r }, h = Fe("#f59e0b", e), A = Te({
|
|
3612
|
+
defaultErrorMessage: l.errorMessage,
|
|
3613
|
+
validate: () => E.trim() ? w != null && w.id ? !0 : (A.setError(l.tenantNotFoundError), !1) : (A.setFieldError("email", !0), !1),
|
|
3465
3614
|
submit: async () => {
|
|
3466
|
-
m(""), await g({ email:
|
|
3615
|
+
m(""), await g({ email: E, tenantId: w.id }), m(l.successMessage);
|
|
3467
3616
|
},
|
|
3468
3617
|
onSuccess: () => i == null ? void 0 : i(),
|
|
3469
|
-
onError:
|
|
3470
|
-
}), y =
|
|
3471
|
-
defaultErrorMessage:
|
|
3618
|
+
onError: o
|
|
3619
|
+
}), y = Te({
|
|
3620
|
+
defaultErrorMessage: l.errorMessage,
|
|
3472
3621
|
validate: () => {
|
|
3473
|
-
const
|
|
3474
|
-
return c.trim() ||
|
|
3622
|
+
const N = [];
|
|
3623
|
+
return c.trim() || N.push("token"), x.trim() || N.push("newPassword"), L.trim() || N.push("confirmPassword"), N.forEach((W) => y.setFieldError(W, !0)), N.length > 0 ? !1 : x !== L ? (y.setError(l.passwordMismatchError), y.setFieldError("confirmPassword", !0), !1) : !0;
|
|
3475
3624
|
},
|
|
3476
3625
|
submit: async () => {
|
|
3477
|
-
m(""), await b({ token: c, newPassword:
|
|
3626
|
+
m(""), await b({ token: c, newPassword: x }), m(l.resetSuccessMessage);
|
|
3478
3627
|
},
|
|
3479
3628
|
onSuccess: () => i == null ? void 0 : i(),
|
|
3480
|
-
onError:
|
|
3629
|
+
onError: o
|
|
3481
3630
|
});
|
|
3482
3631
|
if (t === "reset") {
|
|
3483
|
-
const
|
|
3484
|
-
...
|
|
3485
|
-
...y.fieldErrors[
|
|
3486
|
-
}),
|
|
3487
|
-
...
|
|
3488
|
-
...y.loading ?
|
|
3489
|
-
...
|
|
3632
|
+
const N = (K) => ({
|
|
3633
|
+
...h.input,
|
|
3634
|
+
...y.fieldErrors[K] ? h.inputError : {}
|
|
3635
|
+
}), z = !(!!c && !!x && !!L) || y.loading, Z = {
|
|
3636
|
+
...h.button,
|
|
3637
|
+
...y.loading ? h.buttonLoading : {},
|
|
3638
|
+
...z ? h.buttonDisabled : {}
|
|
3490
3639
|
};
|
|
3491
|
-
return /* @__PURE__ */ f("div", { className:
|
|
3492
|
-
/* @__PURE__ */ s("h2", { style:
|
|
3493
|
-
/* @__PURE__ */ s("p", { style:
|
|
3494
|
-
/* @__PURE__ */ f("form", { onSubmit: y.handleSubmit, style:
|
|
3495
|
-
/* @__PURE__ */ f("div", { style:
|
|
3496
|
-
/* @__PURE__ */ s("label", { style:
|
|
3640
|
+
return /* @__PURE__ */ f("div", { className: k, style: h.container, children: [
|
|
3641
|
+
/* @__PURE__ */ s("h2", { style: h.title, children: l.resetTitle }),
|
|
3642
|
+
/* @__PURE__ */ s("p", { style: h.subtitle, children: l.resetSubtitle }),
|
|
3643
|
+
/* @__PURE__ */ f("form", { onSubmit: y.handleSubmit, style: h.form, children: [
|
|
3644
|
+
/* @__PURE__ */ f("div", { style: h.fieldGroup, children: [
|
|
3645
|
+
/* @__PURE__ */ s("label", { style: h.label, children: l.tokenLabel }),
|
|
3497
3646
|
/* @__PURE__ */ s(
|
|
3498
3647
|
"input",
|
|
3499
3648
|
{
|
|
3500
3649
|
type: "text",
|
|
3501
3650
|
value: c,
|
|
3502
|
-
onChange: (
|
|
3503
|
-
d(
|
|
3651
|
+
onChange: (K) => {
|
|
3652
|
+
d(K.target.value), y.clearFieldError("token");
|
|
3504
3653
|
},
|
|
3505
|
-
placeholder:
|
|
3506
|
-
style:
|
|
3654
|
+
placeholder: l.tokenPlaceholder,
|
|
3655
|
+
style: N("token"),
|
|
3507
3656
|
disabled: y.loading
|
|
3508
3657
|
}
|
|
3509
3658
|
)
|
|
3510
3659
|
] }),
|
|
3511
|
-
/* @__PURE__ */ f("div", { style:
|
|
3512
|
-
/* @__PURE__ */ s("label", { style:
|
|
3660
|
+
/* @__PURE__ */ f("div", { style: h.fieldGroup, children: [
|
|
3661
|
+
/* @__PURE__ */ s("label", { style: h.label, children: l.newPasswordLabel }),
|
|
3513
3662
|
/* @__PURE__ */ s(
|
|
3514
3663
|
"input",
|
|
3515
3664
|
{
|
|
3516
3665
|
type: "password",
|
|
3517
|
-
value:
|
|
3518
|
-
onChange: (
|
|
3519
|
-
|
|
3666
|
+
value: x,
|
|
3667
|
+
onChange: (K) => {
|
|
3668
|
+
I(K.target.value), y.clearFieldError("newPassword");
|
|
3520
3669
|
},
|
|
3521
|
-
placeholder:
|
|
3522
|
-
style:
|
|
3670
|
+
placeholder: l.newPasswordPlaceholder,
|
|
3671
|
+
style: N("newPassword"),
|
|
3523
3672
|
disabled: y.loading
|
|
3524
3673
|
}
|
|
3525
3674
|
)
|
|
3526
3675
|
] }),
|
|
3527
|
-
/* @__PURE__ */ f("div", { style:
|
|
3528
|
-
/* @__PURE__ */ s("label", { style:
|
|
3676
|
+
/* @__PURE__ */ f("div", { style: h.fieldGroup, children: [
|
|
3677
|
+
/* @__PURE__ */ s("label", { style: h.label, children: l.confirmPasswordLabel }),
|
|
3529
3678
|
/* @__PURE__ */ s(
|
|
3530
3679
|
"input",
|
|
3531
3680
|
{
|
|
3532
3681
|
type: "password",
|
|
3533
|
-
value:
|
|
3534
|
-
onChange: (
|
|
3535
|
-
|
|
3682
|
+
value: L,
|
|
3683
|
+
onChange: (K) => {
|
|
3684
|
+
P(K.target.value), y.clearFieldError("confirmPassword"), y.error === l.passwordMismatchError && y.setError("");
|
|
3536
3685
|
},
|
|
3537
|
-
placeholder:
|
|
3538
|
-
style:
|
|
3686
|
+
placeholder: l.confirmPasswordPlaceholder,
|
|
3687
|
+
style: N("confirmPassword"),
|
|
3539
3688
|
disabled: y.loading
|
|
3540
3689
|
}
|
|
3541
3690
|
)
|
|
3542
3691
|
] }),
|
|
3543
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled:
|
|
3544
|
-
y.error && /* @__PURE__ */ s("div", { style:
|
|
3545
|
-
|
|
3692
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: z, style: Z, children: y.loading ? l.resetLoadingText : l.resetSubmitButton }),
|
|
3693
|
+
y.error && /* @__PURE__ */ s("div", { style: h.errorText, children: y.error }),
|
|
3694
|
+
R && /* @__PURE__ */ s("div", { style: h.successText, children: R })
|
|
3546
3695
|
] }),
|
|
3547
|
-
/* @__PURE__ */ f("div", { style:
|
|
3548
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
3549
|
-
|
|
3550
|
-
/* @__PURE__ */ s("span", { style:
|
|
3551
|
-
/* @__PURE__ */ s("a", { onClick: () =>
|
|
3696
|
+
/* @__PURE__ */ f("div", { style: h.linkContainer, children: [
|
|
3697
|
+
/* @__PURE__ */ s("a", { onClick: a, style: h.link, children: l.backToLoginLink }),
|
|
3698
|
+
p && /* @__PURE__ */ f(U, { children: [
|
|
3699
|
+
/* @__PURE__ */ s("span", { style: h.modeSwitchDivider, children: l.dividerBullet }),
|
|
3700
|
+
/* @__PURE__ */ s("a", { onClick: () => p("request"), style: h.link, children: l.requestNewLinkLink })
|
|
3552
3701
|
] })
|
|
3553
3702
|
] })
|
|
3554
3703
|
] });
|
|
3555
3704
|
}
|
|
3556
|
-
const u = (
|
|
3557
|
-
...
|
|
3558
|
-
...
|
|
3559
|
-
}),
|
|
3560
|
-
...
|
|
3561
|
-
...
|
|
3562
|
-
...
|
|
3705
|
+
const u = (N) => ({
|
|
3706
|
+
...h.input,
|
|
3707
|
+
...A.fieldErrors[N] ? h.inputError : {}
|
|
3708
|
+
}), T = !E || A.loading, M = {
|
|
3709
|
+
...h.button,
|
|
3710
|
+
...A.loading ? h.buttonLoading : {},
|
|
3711
|
+
...T ? h.buttonDisabled : {}
|
|
3563
3712
|
};
|
|
3564
|
-
return /* @__PURE__ */ f("div", { className:
|
|
3565
|
-
/* @__PURE__ */ s("h2", { style:
|
|
3566
|
-
/* @__PURE__ */ s("p", { style:
|
|
3567
|
-
/* @__PURE__ */ f("form", { onSubmit:
|
|
3568
|
-
/* @__PURE__ */ f("div", { style:
|
|
3569
|
-
/* @__PURE__ */ s("label", { style:
|
|
3713
|
+
return /* @__PURE__ */ f("div", { className: k, style: h.container, children: [
|
|
3714
|
+
/* @__PURE__ */ s("h2", { style: h.title, children: l.title }),
|
|
3715
|
+
/* @__PURE__ */ s("p", { style: h.subtitle, children: l.subtitle }),
|
|
3716
|
+
/* @__PURE__ */ f("form", { onSubmit: A.handleSubmit, style: h.form, children: [
|
|
3717
|
+
/* @__PURE__ */ f("div", { style: h.fieldGroup, children: [
|
|
3718
|
+
/* @__PURE__ */ s("label", { style: h.label, children: l.emailLabel }),
|
|
3570
3719
|
/* @__PURE__ */ s(
|
|
3571
3720
|
"input",
|
|
3572
3721
|
{
|
|
3573
3722
|
type: "email",
|
|
3574
|
-
value:
|
|
3575
|
-
onChange: (
|
|
3576
|
-
|
|
3723
|
+
value: E,
|
|
3724
|
+
onChange: (N) => {
|
|
3725
|
+
S(N.target.value), A.clearFieldError("email");
|
|
3577
3726
|
},
|
|
3578
|
-
placeholder:
|
|
3727
|
+
placeholder: l.emailPlaceholder,
|
|
3579
3728
|
style: u("email"),
|
|
3580
|
-
disabled:
|
|
3729
|
+
disabled: A.loading
|
|
3581
3730
|
}
|
|
3582
3731
|
)
|
|
3583
3732
|
] }),
|
|
3584
|
-
/* @__PURE__ */ s("button", { type: "submit", disabled:
|
|
3585
|
-
|
|
3586
|
-
|
|
3733
|
+
/* @__PURE__ */ s("button", { type: "submit", disabled: T, style: M, children: A.loading ? l.loadingText : l.submitButton }),
|
|
3734
|
+
A.error && /* @__PURE__ */ s("div", { style: h.errorText, children: A.error }),
|
|
3735
|
+
R && /* @__PURE__ */ s("div", { style: h.successText, children: R })
|
|
3587
3736
|
] }),
|
|
3588
|
-
/* @__PURE__ */ f("div", { style:
|
|
3589
|
-
/* @__PURE__ */ s("a", { onClick:
|
|
3590
|
-
|
|
3591
|
-
/* @__PURE__ */ s("span", { style:
|
|
3592
|
-
/* @__PURE__ */ s("a", { onClick: () =>
|
|
3737
|
+
/* @__PURE__ */ f("div", { style: h.linkContainer, children: [
|
|
3738
|
+
/* @__PURE__ */ s("a", { onClick: a, style: h.link, children: l.backToLoginLink }),
|
|
3739
|
+
p && /* @__PURE__ */ f(U, { children: [
|
|
3740
|
+
/* @__PURE__ */ s("span", { style: h.modeSwitchDivider, children: l.dividerBullet }),
|
|
3741
|
+
/* @__PURE__ */ s("a", { onClick: () => p("reset"), style: h.link, children: l.haveTokenLink })
|
|
3593
3742
|
] })
|
|
3594
3743
|
] })
|
|
3595
3744
|
] });
|
|
3596
3745
|
}
|
|
3597
|
-
const
|
|
3746
|
+
const Sr = () => /* @__PURE__ */ s(
|
|
3598
3747
|
"div",
|
|
3599
3748
|
{
|
|
3600
3749
|
style: {
|
|
@@ -3606,7 +3755,7 @@ const yr = () => /* @__PURE__ */ s(
|
|
|
3606
3755
|
},
|
|
3607
3756
|
children: /* @__PURE__ */ s("div", { children: "Loading..." })
|
|
3608
3757
|
}
|
|
3609
|
-
),
|
|
3758
|
+
), kr = ({ error: r, retry: e }) => /* @__PURE__ */ f(
|
|
3610
3759
|
"div",
|
|
3611
3760
|
{
|
|
3612
3761
|
style: {
|
|
@@ -3640,43 +3789,43 @@ const yr = () => /* @__PURE__ */ s(
|
|
|
3640
3789
|
]
|
|
3641
3790
|
}
|
|
3642
3791
|
);
|
|
3643
|
-
function
|
|
3792
|
+
function ln({
|
|
3644
3793
|
children: r,
|
|
3645
3794
|
loadingFallback: e,
|
|
3646
3795
|
errorFallback: t,
|
|
3647
3796
|
requireTenant: n = !0
|
|
3648
3797
|
}) {
|
|
3649
|
-
const { isAppLoading: i, appError:
|
|
3650
|
-
}),
|
|
3651
|
-
|
|
3798
|
+
const { isAppLoading: i, appError: o, retryApp: a } = Ae(), p = pe(), k = qe(), E = ut(), S = dt(), c = (p == null ? void 0 : p.isTenantLoading) ?? !1, d = (p == null ? void 0 : p.tenantError) ?? null, x = (p == null ? void 0 : p.tenantSlug) ?? null, I = (p == null ? void 0 : p.retryTenant) ?? (() => {
|
|
3799
|
+
}), L = (k == null ? void 0 : k.isAuthReady) ?? !0, P = (E == null ? void 0 : E.isReady) ?? !0, R = (S == null ? void 0 : S.isReady) ?? !0, m = n && p && x, l = i || m && c || k && !L || E && !P || S && !R, h = o || (m ? d : null), A = () => {
|
|
3800
|
+
o && a(), d && p && I();
|
|
3652
3801
|
};
|
|
3653
|
-
if (
|
|
3654
|
-
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(
|
|
3655
|
-
if (
|
|
3656
|
-
const y = typeof t == "function" ? t(
|
|
3802
|
+
if (l)
|
|
3803
|
+
return /* @__PURE__ */ s(U, { children: e || /* @__PURE__ */ s(Sr, {}) });
|
|
3804
|
+
if (h) {
|
|
3805
|
+
const y = typeof t == "function" ? t(h, A) : t || /* @__PURE__ */ s(kr, { error: h, retry: A });
|
|
3657
3806
|
return /* @__PURE__ */ s(U, { children: y });
|
|
3658
3807
|
}
|
|
3659
3808
|
return /* @__PURE__ */ s(U, { children: r });
|
|
3660
3809
|
}
|
|
3661
|
-
function
|
|
3662
|
-
const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = Ae(),
|
|
3663
|
-
}),
|
|
3810
|
+
function cn(r = !0) {
|
|
3811
|
+
const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = Ae(), o = pe(), a = qe(), p = ut(), k = dt(), E = (o == null ? void 0 : o.isTenantLoading) ?? !1, S = (o == null ? void 0 : o.tenantError) ?? null, c = (o == null ? void 0 : o.tenant) ?? null, d = (o == null ? void 0 : o.tenantSlug) ?? null, x = (o == null ? void 0 : o.retryTenant) ?? (() => {
|
|
3812
|
+
}), I = (a == null ? void 0 : a.isAuthReady) ?? !0, L = (p == null ? void 0 : p.isReady) ?? !0, P = (k == null ? void 0 : k.isReady) ?? !0, R = r && o && d, w = e || R && E || a && !I || p && !L || k && !P, l = t || (R ? S : null);
|
|
3664
3813
|
return {
|
|
3665
|
-
isLoading:
|
|
3666
|
-
error:
|
|
3667
|
-
isReady: !
|
|
3814
|
+
isLoading: w,
|
|
3815
|
+
error: l,
|
|
3816
|
+
isReady: !w && !l && i !== null && (!R || c !== null),
|
|
3668
3817
|
retry: () => {
|
|
3669
|
-
t && n(),
|
|
3818
|
+
t && n(), S && o && x();
|
|
3670
3819
|
},
|
|
3671
3820
|
// Individual states
|
|
3672
3821
|
app: { isLoading: e, error: t, data: i },
|
|
3673
|
-
tenant:
|
|
3674
|
-
auth:
|
|
3675
|
-
featureFlags:
|
|
3676
|
-
subscription:
|
|
3822
|
+
tenant: o ? { isLoading: E, error: S, data: c } : null,
|
|
3823
|
+
auth: a ? { isReady: I } : null,
|
|
3824
|
+
featureFlags: p ? { isReady: L } : null,
|
|
3825
|
+
subscription: k ? { isReady: P } : null
|
|
3677
3826
|
};
|
|
3678
3827
|
}
|
|
3679
|
-
const
|
|
3828
|
+
const Er = {
|
|
3680
3829
|
wrapper: {
|
|
3681
3830
|
position: "relative"
|
|
3682
3831
|
},
|
|
@@ -3720,89 +3869,89 @@ const wr = {
|
|
|
3720
3869
|
marginLeft: 8
|
|
3721
3870
|
}
|
|
3722
3871
|
};
|
|
3723
|
-
function
|
|
3872
|
+
function un({
|
|
3724
3873
|
tenants: r,
|
|
3725
3874
|
currentTenantId: e,
|
|
3726
3875
|
onSelect: t,
|
|
3727
3876
|
styles: n = {},
|
|
3728
3877
|
className: i = "",
|
|
3729
|
-
dropdownClassName:
|
|
3730
|
-
itemClassName:
|
|
3731
|
-
renderItem:
|
|
3732
|
-
placeholder:
|
|
3733
|
-
disabled:
|
|
3734
|
-
showCurrentTenant:
|
|
3878
|
+
dropdownClassName: o = "",
|
|
3879
|
+
itemClassName: a = "",
|
|
3880
|
+
renderItem: p,
|
|
3881
|
+
placeholder: k = "Select tenant",
|
|
3882
|
+
disabled: E = !1,
|
|
3883
|
+
showCurrentTenant: S = !0
|
|
3735
3884
|
}) {
|
|
3736
|
-
var
|
|
3737
|
-
const c = { ...
|
|
3738
|
-
|
|
3885
|
+
var w;
|
|
3886
|
+
const c = { ...Er, ...n }, d = qe(), [x, I] = C(!1), L = be(null), P = r ?? (d == null ? void 0 : d.userTenants) ?? [], R = e ?? ((w = d == null ? void 0 : d.currentUser) == null ? void 0 : w.tenantId) ?? null, m = async (l) => {
|
|
3887
|
+
I(!1), t ? t(l) : d != null && d.switchToTenant && await d.switchToTenant(l);
|
|
3739
3888
|
};
|
|
3740
3889
|
re(() => {
|
|
3741
|
-
const
|
|
3742
|
-
|
|
3890
|
+
const l = (h) => {
|
|
3891
|
+
L.current && !L.current.contains(h.target) && I(!1);
|
|
3743
3892
|
};
|
|
3744
|
-
return document.addEventListener("mousedown",
|
|
3893
|
+
return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
|
|
3745
3894
|
}, []);
|
|
3746
|
-
const g =
|
|
3747
|
-
if (
|
|
3895
|
+
const g = P.find((l) => l.id === R);
|
|
3896
|
+
if (P.length === 0)
|
|
3748
3897
|
return null;
|
|
3749
|
-
if (
|
|
3750
|
-
return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children:
|
|
3751
|
-
const b = (
|
|
3752
|
-
|
|
3753
|
-
|
|
3898
|
+
if (P.length === 1 && S)
|
|
3899
|
+
return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: P[0].name }) });
|
|
3900
|
+
const b = (l, h) => /* @__PURE__ */ f("span", { style: { fontWeight: h ? "bold" : "normal" }, children: [
|
|
3901
|
+
l.name,
|
|
3902
|
+
l.role && /* @__PURE__ */ f("span", { style: c.itemRole, children: [
|
|
3754
3903
|
"(",
|
|
3755
|
-
|
|
3904
|
+
l.role,
|
|
3756
3905
|
")"
|
|
3757
3906
|
] })
|
|
3758
3907
|
] });
|
|
3759
|
-
return /* @__PURE__ */ f("div", { ref:
|
|
3908
|
+
return /* @__PURE__ */ f("div", { ref: L, className: i, style: c.wrapper, children: [
|
|
3760
3909
|
/* @__PURE__ */ f(
|
|
3761
3910
|
"button",
|
|
3762
3911
|
{
|
|
3763
3912
|
type: "button",
|
|
3764
|
-
onClick: () => !
|
|
3765
|
-
disabled:
|
|
3913
|
+
onClick: () => !E && I(!x),
|
|
3914
|
+
disabled: E,
|
|
3766
3915
|
style: {
|
|
3767
3916
|
...c.button,
|
|
3768
|
-
...
|
|
3917
|
+
...E ? c.buttonDisabled : {}
|
|
3769
3918
|
},
|
|
3770
3919
|
children: [
|
|
3771
|
-
g ? g.name :
|
|
3772
|
-
/* @__PURE__ */ s("span", { style: c.arrow, children:
|
|
3920
|
+
g ? g.name : k,
|
|
3921
|
+
/* @__PURE__ */ s("span", { style: c.arrow, children: x ? "▲" : "▼" })
|
|
3773
3922
|
]
|
|
3774
3923
|
}
|
|
3775
3924
|
),
|
|
3776
|
-
|
|
3777
|
-
const
|
|
3925
|
+
x && /* @__PURE__ */ s("div", { className: o, style: c.dropdown, children: P.map((l) => {
|
|
3926
|
+
const h = l.id === R;
|
|
3778
3927
|
return /* @__PURE__ */ s(
|
|
3779
3928
|
"div",
|
|
3780
3929
|
{
|
|
3781
|
-
className:
|
|
3782
|
-
onClick: () => m(
|
|
3930
|
+
className: a,
|
|
3931
|
+
onClick: () => m(l.id),
|
|
3783
3932
|
style: {
|
|
3784
3933
|
...c.item,
|
|
3785
|
-
...
|
|
3934
|
+
...h ? c.itemSelected : {}
|
|
3786
3935
|
},
|
|
3787
|
-
onMouseEnter: (
|
|
3788
|
-
|
|
3936
|
+
onMouseEnter: (A) => {
|
|
3937
|
+
h || Object.assign(A.currentTarget.style, c.itemHover);
|
|
3789
3938
|
},
|
|
3790
|
-
onMouseLeave: (
|
|
3791
|
-
if (!
|
|
3939
|
+
onMouseLeave: (A) => {
|
|
3940
|
+
if (!h) {
|
|
3792
3941
|
const y = c.item || {};
|
|
3793
3942
|
Object.keys(c.itemHover || {}).forEach((u) => {
|
|
3794
|
-
|
|
3943
|
+
A.currentTarget.style[u] = y[u] ?? "";
|
|
3795
3944
|
});
|
|
3796
3945
|
}
|
|
3797
3946
|
},
|
|
3798
|
-
children:
|
|
3947
|
+
children: p ? p(l, h) : b(l, h)
|
|
3799
3948
|
},
|
|
3800
|
-
|
|
3949
|
+
l.id
|
|
3801
3950
|
);
|
|
3802
3951
|
}) })
|
|
3803
3952
|
] });
|
|
3804
3953
|
}
|
|
3805
|
-
class
|
|
3954
|
+
class dn {
|
|
3806
3955
|
constructor(e) {
|
|
3807
3956
|
this.httpService = e;
|
|
3808
3957
|
}
|
|
@@ -3811,7 +3960,7 @@ class on {
|
|
|
3811
3960
|
}
|
|
3812
3961
|
async getPermissions(e) {
|
|
3813
3962
|
const t = await this.httpService.get(
|
|
3814
|
-
`/permissions/${
|
|
3963
|
+
`/permissions/${le(e)}`
|
|
3815
3964
|
);
|
|
3816
3965
|
return { permissions: t.data, meta: t.meta };
|
|
3817
3966
|
}
|
|
@@ -3829,13 +3978,13 @@ class on {
|
|
|
3829
3978
|
}
|
|
3830
3979
|
async getAppPermissions(e, t) {
|
|
3831
3980
|
const n = await this.httpService.get(
|
|
3832
|
-
`/permissions/apps/${e}${
|
|
3981
|
+
`/permissions/apps/${e}${le(t)}`,
|
|
3833
3982
|
{ skipAuth: !0 }
|
|
3834
3983
|
);
|
|
3835
3984
|
return { permissions: n.data, meta: n.meta };
|
|
3836
3985
|
}
|
|
3837
3986
|
}
|
|
3838
|
-
class
|
|
3987
|
+
class hn {
|
|
3839
3988
|
constructor(e) {
|
|
3840
3989
|
this.httpService = e;
|
|
3841
3990
|
}
|
|
@@ -3847,7 +3996,7 @@ class an {
|
|
|
3847
3996
|
}
|
|
3848
3997
|
async getSubscriptionPlans(e) {
|
|
3849
3998
|
const t = await this.httpService.get(
|
|
3850
|
-
`/subscription-plans/${
|
|
3999
|
+
`/subscription-plans/${le(e)}`
|
|
3851
4000
|
);
|
|
3852
4001
|
return { plans: t.data, meta: t.meta };
|
|
3853
4002
|
}
|
|
@@ -3866,7 +4015,7 @@ class an {
|
|
|
3866
4015
|
await this.httpService.delete(`/subscription-plans/${e}`);
|
|
3867
4016
|
}
|
|
3868
4017
|
}
|
|
3869
|
-
class
|
|
4018
|
+
class pn {
|
|
3870
4019
|
constructor(e) {
|
|
3871
4020
|
this.httpService = e;
|
|
3872
4021
|
}
|
|
@@ -3875,142 +4024,142 @@ class ln {
|
|
|
3875
4024
|
return await this.httpService.get("/health");
|
|
3876
4025
|
}
|
|
3877
4026
|
}
|
|
3878
|
-
const
|
|
3879
|
-
function
|
|
4027
|
+
const ft = "returnTo", Me = "zone_return_to", $e = "zone_return_to";
|
|
4028
|
+
function fn(r = {}) {
|
|
3880
4029
|
const {
|
|
3881
4030
|
zoneRoots: e = {},
|
|
3882
|
-
returnToParam: t =
|
|
4031
|
+
returnToParam: t = ft,
|
|
3883
4032
|
returnToStorage: n = "url"
|
|
3884
|
-
} = r, i =
|
|
4033
|
+
} = r, i = xt(), [o, a] = Rt(), { isAuthenticated: p, currentUser: k } = ue(), { tenant: E } = Se(), S = O(() => ({ ...je, ...e }), [e]), c = !!E, d = k == null ? void 0 : k.userType, x = O(() => {
|
|
3885
4034
|
switch (n) {
|
|
3886
4035
|
case "url":
|
|
3887
|
-
return
|
|
4036
|
+
return o.get(t);
|
|
3888
4037
|
case "session":
|
|
3889
|
-
return sessionStorage.getItem(
|
|
4038
|
+
return sessionStorage.getItem(Me);
|
|
3890
4039
|
case "local":
|
|
3891
|
-
return localStorage.getItem(
|
|
4040
|
+
return localStorage.getItem($e);
|
|
3892
4041
|
default:
|
|
3893
4042
|
return null;
|
|
3894
4043
|
}
|
|
3895
|
-
}, [n,
|
|
4044
|
+
}, [n, o, t]), I = te(() => {
|
|
3896
4045
|
switch (n) {
|
|
3897
4046
|
case "url": {
|
|
3898
|
-
const m = new URLSearchParams(
|
|
3899
|
-
m.delete(t),
|
|
4047
|
+
const m = new URLSearchParams(o);
|
|
4048
|
+
m.delete(t), a(m, { replace: !0 });
|
|
3900
4049
|
break;
|
|
3901
4050
|
}
|
|
3902
4051
|
case "session":
|
|
3903
|
-
sessionStorage.removeItem(
|
|
4052
|
+
sessionStorage.removeItem(Me);
|
|
3904
4053
|
break;
|
|
3905
4054
|
case "local":
|
|
3906
|
-
localStorage.removeItem(
|
|
4055
|
+
localStorage.removeItem($e);
|
|
3907
4056
|
break;
|
|
3908
4057
|
}
|
|
3909
|
-
}, [n,
|
|
4058
|
+
}, [n, o, t, a]), L = te(
|
|
3910
4059
|
(m) => {
|
|
3911
4060
|
switch (n) {
|
|
3912
4061
|
case "url": {
|
|
3913
|
-
const g = new URLSearchParams(
|
|
3914
|
-
g.set(t, m),
|
|
4062
|
+
const g = new URLSearchParams(o);
|
|
4063
|
+
g.set(t, m), a(g, { replace: !0 });
|
|
3915
4064
|
break;
|
|
3916
4065
|
}
|
|
3917
4066
|
case "session":
|
|
3918
|
-
sessionStorage.setItem(
|
|
4067
|
+
sessionStorage.setItem(Me, m);
|
|
3919
4068
|
break;
|
|
3920
4069
|
case "local":
|
|
3921
|
-
localStorage.setItem(
|
|
4070
|
+
localStorage.setItem($e, m);
|
|
3922
4071
|
break;
|
|
3923
4072
|
}
|
|
3924
4073
|
},
|
|
3925
|
-
[n,
|
|
3926
|
-
),
|
|
4074
|
+
[n, o, t, a]
|
|
4075
|
+
), P = te(
|
|
3927
4076
|
(m) => {
|
|
3928
|
-
const g =
|
|
4077
|
+
const g = S[m] || S.default;
|
|
3929
4078
|
i(g);
|
|
3930
4079
|
},
|
|
3931
|
-
[i,
|
|
3932
|
-
),
|
|
4080
|
+
[i, S]
|
|
4081
|
+
), R = te(() => c ? p ? d === oe.TENANT_ADMIN ? S.tenantAdmin : S.tenantUser : S.tenantGuest : p ? d === oe.TENANT_ADMIN ? S.publicAdmin : S.publicUser : S.publicGuest, [c, p, d, S]);
|
|
3933
4082
|
return {
|
|
3934
|
-
returnToUrl:
|
|
3935
|
-
clearReturnTo:
|
|
3936
|
-
setReturnTo:
|
|
3937
|
-
navigateToZone:
|
|
3938
|
-
getSmartRedirect:
|
|
4083
|
+
returnToUrl: x,
|
|
4084
|
+
clearReturnTo: I,
|
|
4085
|
+
setReturnTo: L,
|
|
4086
|
+
navigateToZone: P,
|
|
4087
|
+
getSmartRedirect: R
|
|
3939
4088
|
};
|
|
3940
4089
|
}
|
|
3941
|
-
function
|
|
4090
|
+
function mn(r, e, t = ft, n = "url") {
|
|
3942
4091
|
if (!e || n !== "url")
|
|
3943
4092
|
return r;
|
|
3944
4093
|
const i = new URL(r, window.location.origin);
|
|
3945
4094
|
return i.searchParams.set(t, e), i.pathname + i.search;
|
|
3946
4095
|
}
|
|
3947
4096
|
export {
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
4097
|
+
Qr as AdminZone,
|
|
4098
|
+
Ye as AppApiService,
|
|
4099
|
+
ln as AppLoader,
|
|
4100
|
+
Pr as AppProvider,
|
|
4101
|
+
Bt as AuthApiService,
|
|
4102
|
+
Cr as AuthProvider,
|
|
4103
|
+
Wr as AuthenticatedZone,
|
|
4104
|
+
ie as ConfigurationError,
|
|
4105
|
+
ht as DEFAULT_ZONE_PRESETS,
|
|
4106
|
+
je as DEFAULT_ZONE_ROOTS,
|
|
4107
|
+
tn as FeatureFlag,
|
|
4108
|
+
Wt as FeatureFlagApiService,
|
|
4109
|
+
$r as FeatureFlagProvider,
|
|
4110
|
+
Hr as GuestZone,
|
|
4111
|
+
pn as HealthApiService,
|
|
3963
4112
|
he as HttpService,
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
4113
|
+
zr as LandingRoute,
|
|
4114
|
+
rn as LoginForm,
|
|
4115
|
+
sn as MagicLinkForm,
|
|
4116
|
+
on as MagicLinkVerify,
|
|
4117
|
+
Kr as OpenZone,
|
|
4118
|
+
an as PasswordRecoveryForm,
|
|
4119
|
+
dn as PermissionApiService,
|
|
4120
|
+
Or as Protected,
|
|
4121
|
+
Vr as ProtectedRoute,
|
|
4122
|
+
jr as PublicZone,
|
|
4123
|
+
_t as RoleApiService,
|
|
4124
|
+
Br as RoutingProvider,
|
|
4125
|
+
Q as SessionExpiredError,
|
|
4126
|
+
Ue as SessionManager,
|
|
4127
|
+
nn as SignupForm,
|
|
4128
|
+
Qt as SubscriptionApiService,
|
|
4129
|
+
en as SubscriptionGuard,
|
|
4130
|
+
hn as SubscriptionPlanApiService,
|
|
4131
|
+
Ur as SubscriptionProvider,
|
|
4132
|
+
we as TenantApiService,
|
|
4133
|
+
Zr as TenantAuthenticatedZone,
|
|
4134
|
+
Xr as TenantGuestZone,
|
|
4135
|
+
Yr as TenantOpenZone,
|
|
4136
|
+
Lr as TenantProvider,
|
|
4137
|
+
qr as TenantRoute,
|
|
4138
|
+
un as TenantSelector,
|
|
4139
|
+
Gr as TenantZone,
|
|
4140
|
+
It as TokenRefreshError,
|
|
4141
|
+
Pt as TokenRefreshTimeoutError,
|
|
4142
|
+
Ot as UserApiService,
|
|
4143
|
+
oe as UserType,
|
|
4144
|
+
Jr as UserZone,
|
|
4145
|
+
ce as ZoneRoute,
|
|
4146
|
+
mn as buildRedirectUrl,
|
|
4147
|
+
Ir as useApi,
|
|
3999
4148
|
Ae as useApp,
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4149
|
+
cn as useAppLoaderState,
|
|
4150
|
+
ue as useAuth,
|
|
4151
|
+
Mr as useAuthActions,
|
|
4152
|
+
qe as useAuthOptional,
|
|
4153
|
+
Dr as useAuthState,
|
|
4154
|
+
Ht as useFeatureFlags,
|
|
4155
|
+
_r as useRouting,
|
|
4156
|
+
Zt as useRoutingOptional,
|
|
4157
|
+
Nr as useSettings,
|
|
4158
|
+
Jt as useSubscription,
|
|
4159
|
+
Se as useTenant,
|
|
4160
|
+
ct as useTenantInfo,
|
|
4012
4161
|
pe as useTenantOptional,
|
|
4013
|
-
|
|
4014
|
-
|
|
4162
|
+
Fr as useTenantSettings,
|
|
4163
|
+
fn as useZoneNavigation
|
|
4015
4164
|
};
|
|
4016
4165
|
//# sourceMappingURL=index.es.js.map
|