@skylabs-digital/react-identity-access 2.26.0 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as s, Fragment as _, jsxs as d } from "react/jsx-runtime";
2
- import { createContext as fe, useMemo as K, useState as k, useCallback as se, useEffect as re, useContext as ae, useRef as Me } from "react";
3
- import { useLocation as ke, Navigate as ve, useNavigate as pt, useSearchParams as ft } from "react-router-dom";
4
- class le {
1
+ import { jsx as s, Fragment as _, jsxs as u } from "react/jsx-runtime";
2
+ import { createContext as ye, useMemo as Z, useState as x, useCallback as oe, useEffect as ne, useContext as le, useRef as Ne } from "react";
3
+ import { useLocation as xe, Navigate as Se, useNavigate as mt, useSearchParams as yt } from "react-router-dom";
4
+ class de {
5
5
  constructor(e, t = 1e4) {
6
6
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
7
7
  }
@@ -13,26 +13,26 @@ class le {
13
13
  }
14
14
  async executeRequest(e, t, r, i) {
15
15
  const o = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, a = (i == null ? void 0 : i.timeout) || this.timeout;
16
- let p = {
16
+ let c = {
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 f = await this.sessionManager.getValidAccessToken();
22
- p = { ...p, Authorization: `Bearer ${f}` };
22
+ c = { ...c, Authorization: `Bearer ${f}` };
23
23
  }
24
- const w = new AbortController(), y = setTimeout(() => w.abort(), a);
24
+ const m = new AbortController(), y = setTimeout(() => m.abort(), a);
25
25
  try {
26
26
  const f = await fetch(o, {
27
27
  method: e,
28
- headers: p,
28
+ headers: c,
29
29
  body: r ? JSON.stringify(r) : void 0,
30
- signal: w.signal
30
+ signal: m.signal
31
31
  });
32
32
  if (clearTimeout(y), !f.ok)
33
33
  throw new Error(`HTTP ${f.status}: ${f.statusText}`);
34
- const x = f.headers.get("content-type");
35
- return !x || !x.includes("application/json") ? {} : await f.json();
34
+ const F = f.headers.get("content-type");
35
+ return !F || !F.includes("application/json") ? {} : await f.json();
36
36
  } catch (f) {
37
37
  throw clearTimeout(y), f instanceof Error && f.name === "AbortError" ? new Error(`Request timeout after ${a}ms`) : f;
38
38
  }
@@ -50,7 +50,7 @@ class le {
50
50
  return this.executeRequest("DELETE", e, void 0, t);
51
51
  }
52
52
  }
53
- class qe {
53
+ class Ve {
54
54
  constructor(e, t) {
55
55
  this.httpService = e, this.sessionManager = t;
56
56
  }
@@ -109,31 +109,31 @@ class qe {
109
109
  })).data;
110
110
  }
111
111
  }
112
- const Le = fe(null);
113
- function mr({ config: n, children: e }) {
114
- const t = K(
112
+ const Fe = ye(null);
113
+ function br({ config: n, children: e }) {
114
+ const t = Z(
115
115
  () => {
116
- var h, R, N;
116
+ var g, T, A;
117
117
  return {
118
- enabled: ((h = n.cache) == null ? void 0 : h.enabled) ?? !0,
119
- ttl: ((R = n.cache) == null ? void 0 : R.ttl) ?? 3e5,
118
+ enabled: ((g = n.cache) == null ? void 0 : g.enabled) ?? !0,
119
+ ttl: ((T = n.cache) == null ? void 0 : T.ttl) ?? 3e5,
120
120
  // 5 minutes default
121
- storageKey: ((N = n.cache) == null ? void 0 : N.storageKey) ?? `app_cache_${n.appId}`
121
+ storageKey: ((A = n.cache) == null ? void 0 : A.storageKey) ?? `app_cache_${n.appId}`
122
122
  };
123
123
  },
124
124
  [n.cache, n.appId]
125
- ), [r, i] = k(() => {
125
+ ), [r, i] = x(() => {
126
126
  if (!t.enabled) return null;
127
127
  try {
128
- const h = localStorage.getItem(t.storageKey);
129
- if (!h) return null;
130
- const R = JSON.parse(h);
131
- return Date.now() - R.timestamp < t.ttl && R.appId === n.appId ? R.data : (localStorage.removeItem(t.storageKey), null);
128
+ const g = localStorage.getItem(t.storageKey);
129
+ if (!g) return null;
130
+ const T = JSON.parse(g);
131
+ return Date.now() - T.timestamp < t.ttl && T.appId === n.appId ? T.data : (localStorage.removeItem(t.storageKey), null);
132
132
  } catch {
133
133
  return null;
134
134
  }
135
- }), [o, a] = k(!r), [p, w] = k(null), y = K(() => {
136
- const h = () => {
135
+ }), [o, a] = x(!r), [c, m] = x(null), y = Z(() => {
136
+ const g = () => {
137
137
  f();
138
138
  };
139
139
  return {
@@ -142,69 +142,69 @@ function mr({ config: n, children: e }) {
142
142
  // App info
143
143
  appInfo: r,
144
144
  isAppLoading: o,
145
- appError: p,
146
- retryApp: h
145
+ appError: c,
146
+ retryApp: g
147
147
  };
148
- }, [n, r, o, p]), f = se(
149
- async (h = !1) => {
150
- if (!(!h && t.enabled && r))
148
+ }, [n, r, o, c]), f = oe(
149
+ async (g = !1) => {
150
+ if (!(!g && t.enabled && r))
151
151
  try {
152
- a(!0), w(null);
153
- const R = new le(n.baseUrl), D = await new qe(R, {}).getPublicAppInfo(n.appId);
154
- if (i(D), t.enabled)
152
+ a(!0), m(null);
153
+ const T = new de(n.baseUrl), L = await new Ve(T, {}).getPublicAppInfo(n.appId);
154
+ if (i(L), t.enabled)
155
155
  try {
156
- const E = {
157
- data: D,
156
+ const M = {
157
+ data: L,
158
158
  timestamp: Date.now(),
159
159
  appId: n.appId
160
160
  };
161
- localStorage.setItem(t.storageKey, JSON.stringify(E));
162
- } catch (E) {
163
- process.env.NODE_ENV === "development" && console.warn("[AppProvider] Failed to cache app info:", E);
161
+ localStorage.setItem(t.storageKey, JSON.stringify(M));
162
+ } catch (M) {
163
+ process.env.NODE_ENV === "development" && console.warn("[AppProvider] Failed to cache app info:", M);
164
164
  }
165
- } catch (R) {
166
- const N = R instanceof Error ? R : new Error("Failed to load app information");
167
- w(N), i(null);
165
+ } catch (T) {
166
+ const A = T instanceof Error ? T : new Error("Failed to load app information");
167
+ m(A), i(null);
168
168
  } finally {
169
169
  a(!1);
170
170
  }
171
171
  },
172
172
  [n.baseUrl, n.appId, t, r]
173
- ), x = se(async () => {
173
+ ), F = oe(async () => {
174
174
  if (!(!t.enabled || !r))
175
175
  try {
176
- const h = localStorage.getItem(t.storageKey);
177
- if (!h) return;
178
- const R = JSON.parse(h);
179
- if (Date.now() - R.timestamp > t.ttl * 0.5) {
180
- const D = new le(n.baseUrl), P = await new qe(D, {}).getPublicAppInfo(n.appId);
176
+ const g = localStorage.getItem(t.storageKey);
177
+ if (!g) return;
178
+ const T = JSON.parse(g);
179
+ if (Date.now() - T.timestamp > t.ttl * 0.5) {
180
+ const L = new de(n.baseUrl), P = await new Ve(L, {}).getPublicAppInfo(n.appId);
181
181
  i(P);
182
- const u = {
182
+ const d = {
183
183
  data: P,
184
184
  timestamp: Date.now(),
185
185
  appId: n.appId
186
186
  };
187
- localStorage.setItem(t.storageKey, JSON.stringify(u));
187
+ localStorage.setItem(t.storageKey, JSON.stringify(d));
188
188
  }
189
- } catch (h) {
190
- process.env.NODE_ENV === "development" && console.warn("[AppProvider] Background app refresh failed:", h);
189
+ } catch (g) {
190
+ process.env.NODE_ENV === "development" && console.warn("[AppProvider] Background app refresh failed:", g);
191
191
  }
192
192
  }, [n, t, r]);
193
- return re(() => {
194
- r ? x() : f();
195
- }, []), /* @__PURE__ */ s(Le.Provider, { value: y, children: e });
193
+ return ne(() => {
194
+ r ? F() : f();
195
+ }, []), /* @__PURE__ */ s(Fe.Provider, { value: y, children: e });
196
196
  }
197
- function Se() {
198
- const n = ae(Le);
197
+ function Ae() {
198
+ const n = le(Fe);
199
199
  if (!n)
200
200
  throw new Error("useApp must be used within an AppProvider");
201
201
  return n;
202
202
  }
203
- function Qe() {
204
- return ae(Le);
203
+ function De() {
204
+ return le(Fe);
205
205
  }
206
- const yr = Se;
207
- class ne extends Error {
206
+ const vr = Ae;
207
+ class se extends Error {
208
208
  constructor(e, t) {
209
209
  const r = {
210
210
  token_expired: "Refresh token has expired",
@@ -214,12 +214,12 @@ class ne extends Error {
214
214
  super(t || r[e]), this.name = "SessionExpiredError", this.reason = e;
215
215
  }
216
216
  }
217
- class gt extends Error {
217
+ class wt extends Error {
218
218
  constructor(e) {
219
219
  super(`Token refresh timed out after ${e}ms`), this.name = "TokenRefreshTimeoutError", this.timeoutMs = e;
220
220
  }
221
221
  }
222
- class mt extends Error {
222
+ class bt extends Error {
223
223
  constructor(e, t) {
224
224
  super(
225
225
  `Token refresh failed after ${e} attempts: ${(t == null ? void 0 : t.message) || "Unknown error"}`
@@ -228,7 +228,7 @@ class mt extends Error {
228
228
  }
229
229
  const ie = class ie {
230
230
  constructor(e = {}) {
231
- this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : 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.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), this.scheduleProactiveRefresh();
231
+ this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, this.consecutiveBackgroundFailures = 0, e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : 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.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), this.scheduleProactiveRefresh();
232
232
  }
233
233
  /**
234
234
  * Get or create a SessionManager instance for the given config.
@@ -353,13 +353,26 @@ const ie = class ie {
353
353
  if (!(e != null && e.refreshToken) || this.refreshPromise) return;
354
354
  const t = this.sessionGeneration;
355
355
  this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
356
+ this.consecutiveBackgroundFailures = 0;
356
357
  }).catch((r) => {
357
- r instanceof ne || this.sessionGeneration === t && (process.env.NODE_ENV === "development" && console.warn(
358
- "[SessionManager] Background refresh failed, retrying in 30s:",
359
- r.message
360
- ), this.backgroundRetryTimerId = setTimeout(() => {
361
- this.backgroundRefresh();
362
- }, 3e4));
358
+ if (!(r instanceof se)) {
359
+ if (this.sessionGeneration === t) {
360
+ if (this.consecutiveBackgroundFailures++, this.consecutiveBackgroundFailures >= ie.MAX_BACKGROUND_FAILURES) {
361
+ process.env.NODE_ENV === "development" && console.error(
362
+ `[SessionManager] Background refresh failed ${this.consecutiveBackgroundFailures} consecutive times — expiring session`
363
+ ), this.consecutiveBackgroundFailures = 0, this.handleSessionExpired(
364
+ new se("token_invalid", "Background refresh failed repeatedly")
365
+ );
366
+ return;
367
+ }
368
+ process.env.NODE_ENV === "development" && console.warn(
369
+ "[SessionManager] Background refresh failed, retrying in 30s:",
370
+ r.message
371
+ ), this.backgroundRetryTimerId = setTimeout(() => {
372
+ this.backgroundRefresh();
373
+ }, 3e4);
374
+ }
375
+ }
363
376
  });
364
377
  }
365
378
  /**
@@ -386,13 +399,13 @@ const ie = class ie {
386
399
  async getValidAccessToken() {
387
400
  const e = this.getTokens();
388
401
  if (!(e != null && e.accessToken)) {
389
- const t = new ne("token_invalid", "No tokens available");
402
+ const t = new se("token_invalid", "No tokens available");
390
403
  throw this.handleSessionExpired(t), t;
391
404
  }
392
405
  if (!this.shouldRefreshToken(e) && !this.isTokenExpired(e))
393
406
  return e.accessToken;
394
407
  if (!e.refreshToken) {
395
- const t = new ne("token_invalid", "No refresh token available");
408
+ const t = new se("token_invalid", "No refresh token available");
396
409
  throw this.handleSessionExpired(t), t;
397
410
  }
398
411
  return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken);
@@ -404,14 +417,14 @@ const ie = class ie {
404
417
  try {
405
418
  return { Authorization: `Bearer ${await this.getValidAccessToken()}` };
406
419
  } catch (e) {
407
- return e instanceof ne && this.onRefreshFailed && this.onRefreshFailed(), {};
420
+ return e instanceof se && this.onRefreshFailed && this.onRefreshFailed(), {};
408
421
  }
409
422
  }
410
423
  enqueueForToken() {
411
424
  return new Promise((e, t) => {
412
425
  const r = setTimeout(() => {
413
426
  const i = this.refreshQueue.findIndex((o) => o.timeoutId === r);
414
- i !== -1 && this.refreshQueue.splice(i, 1), t(new gt(this.refreshQueueTimeout));
427
+ i !== -1 && this.refreshQueue.splice(i, 1), t(new wt(this.refreshQueueTimeout));
415
428
  }, this.refreshQueueTimeout);
416
429
  this.refreshQueue.push({ resolve: e, reject: t, timeoutId: r });
417
430
  });
@@ -424,7 +437,7 @@ const ie = class ie {
424
437
  return this.resolveQueue(r), r;
425
438
  } catch (t) {
426
439
  const r = t instanceof Error ? t : new Error("Token refresh failed");
427
- throw r instanceof ne ? (this.rejectQueue(r), this.handleSessionExpired(r)) : this.rejectQueue(r), r;
440
+ throw r instanceof se ? (this.rejectQueue(r), this.handleSessionExpired(r)) : this.rejectQueue(r), r;
428
441
  } finally {
429
442
  this.refreshPromise = null;
430
443
  }
@@ -447,21 +460,21 @@ const ie = class ie {
447
460
  const r = this.sessionGeneration;
448
461
  for (let i = 0; i <= this.maxRefreshRetries; i++) {
449
462
  if (this.sessionGeneration !== r)
450
- throw new ne("token_invalid", "Session cleared during refresh");
463
+ throw new se("token_invalid", "Session cleared during refresh");
451
464
  try {
452
465
  await this.performTokenRefresh(e, r);
453
466
  return;
454
467
  } catch (o) {
455
468
  const a = o instanceof Error ? o : new Error(String(o));
456
- if (a instanceof ne)
469
+ if (a instanceof se)
457
470
  throw a;
458
471
  if (t = a, i < this.maxRefreshRetries) {
459
- const p = this.retryBackoffBase * Math.pow(2, i);
460
- await this.sleep(p);
472
+ const c = this.retryBackoffBase * Math.pow(2, i);
473
+ await this.sleep(c);
461
474
  }
462
475
  }
463
476
  }
464
- throw new mt(this.maxRefreshRetries + 1, t);
477
+ throw new bt(this.maxRefreshRetries + 1, t);
465
478
  }
466
479
  /**
467
480
  * Single refresh attempt with error classification.
@@ -485,15 +498,15 @@ const ie = class ie {
485
498
  if (!i.ok) {
486
499
  let a = "";
487
500
  try {
488
- const p = await i.json();
489
- a = (p.message || p.error || "").toLowerCase();
501
+ const c = await i.json();
502
+ a = (c.message || c.error || "").toLowerCase();
490
503
  } catch {
491
504
  a = i.statusText.toLowerCase();
492
505
  }
493
- throw i.status === 401 ? a.includes("expired") ? new ne("token_expired") : a.includes("invalid") ? new ne("token_invalid") : new ne("token_invalid", `Unauthorized: ${a}`) : i.status === 400 ? a.includes("inactive") ? new ne("user_inactive") : a.includes("expired") || a.includes("invalid") ? new ne("token_invalid", a) : new Error(`Token refresh failed (400): ${a}`) : new Error(`Token refresh failed: ${i.status} ${a}`);
506
+ throw i.status === 401 ? a.includes("expired") ? new se("token_expired") : a.includes("invalid") ? new se("token_invalid") : new se("token_invalid", `Unauthorized: ${a}`) : i.status === 400 ? a.includes("inactive") ? new se("user_inactive") : a.includes("expired") || a.includes("invalid") ? new se("token_invalid", a) : a.includes("reuse") || a.includes("revoked") ? new se("token_invalid", a) : new Error(`Token refresh failed (400): ${a}`) : new Error(`Token refresh failed: ${i.status} ${a}`);
494
507
  }
495
508
  if (this.sessionGeneration !== t)
496
- throw new ne("token_invalid", "Session cleared during refresh");
509
+ throw new se("token_invalid", "Session cleared during refresh");
497
510
  const o = await i.json();
498
511
  this.setTokens({
499
512
  accessToken: o.accessToken,
@@ -521,7 +534,7 @@ const ie = class ie {
521
534
  // --- Session lifecycle ---
522
535
  clearSession() {
523
536
  this.sessionGeneration++, this.cancelProactiveTimer(), this.clearTokens();
524
- const e = new ne("token_invalid", "Session cleared");
537
+ const e = new se("token_invalid", "Session cleared");
525
538
  this.rejectQueue(e);
526
539
  }
527
540
  /**
@@ -530,7 +543,7 @@ const ie = class ie {
530
543
  */
531
544
  destroy() {
532
545
  this.isDestroyed = !0, ie.instances.delete(this.storageKey), this.cancelProactiveTimer();
533
- const e = new ne("token_invalid", "SessionManager destroyed");
546
+ const e = new se("token_invalid", "SessionManager destroyed");
534
547
  this.rejectQueue(e);
535
548
  }
536
549
  // --- JWT helpers ---
@@ -568,9 +581,10 @@ const ie = class ie {
568
581
  return new Promise((t) => setTimeout(t, e));
569
582
  }
570
583
  };
571
- ie.instances = /* @__PURE__ */ new Map();
572
- let we = ie;
573
- class yt {
584
+ ie.instances = /* @__PURE__ */ new Map(), ie.MAX_BACKGROUND_FAILURES = 3;
585
+ let be = ie;
586
+ const Ie = /* @__PURE__ */ new Map();
587
+ class vt {
574
588
  constructor(e) {
575
589
  this.httpService = e;
576
590
  }
@@ -611,10 +625,12 @@ class yt {
611
625
  );
612
626
  }
613
627
  async verifyMagicLink(e) {
614
- return await this.httpService.post(
615
- "/auth/magic-link/verify",
616
- e
617
- );
628
+ const t = e.token, r = Ie.get(t);
629
+ if (r) return r;
630
+ const i = this.httpService.post("/auth/magic-link/verify", e).finally(() => {
631
+ Ie.delete(t);
632
+ });
633
+ return Ie.set(t, i), i;
618
634
  }
619
635
  async confirmPasswordReset(e) {
620
636
  await this.httpService.post("/auth/password-reset/confirm", e);
@@ -626,7 +642,7 @@ class yt {
626
642
  });
627
643
  }
628
644
  }
629
- class ze {
645
+ class We {
630
646
  constructor(e, t) {
631
647
  this.httpService = e, this.sessionManager = t;
632
648
  }
@@ -702,7 +718,7 @@ class ze {
702
718
  };
703
719
  }
704
720
  }
705
- class wt {
721
+ class St {
706
722
  constructor(e, t) {
707
723
  this.httpService = e, this.sessionManager = t;
708
724
  }
@@ -742,7 +758,7 @@ class wt {
742
758
  });
743
759
  }
744
760
  }
745
- class be {
761
+ class ve {
746
762
  constructor(e, t, r) {
747
763
  this.httpService = e, this.appId = t, this.sessionManager = r;
748
764
  }
@@ -820,7 +836,7 @@ class be {
820
836
  )).data;
821
837
  }
822
838
  }
823
- function bt(n, e) {
839
+ function Tt(n, e) {
824
840
  if (n === "localhost" || n.startsWith("127.") || n.startsWith("192.168."))
825
841
  return null;
826
842
  if (e) {
@@ -836,26 +852,26 @@ function bt(n, e) {
836
852
  const r = n.split(".");
837
853
  return r.length >= 3 && r[0] !== "www" ? r[0] : null;
838
854
  }
839
- function vt(n, e = "tenant", t) {
855
+ function kt(n, e = "tenant", t) {
840
856
  const i = new URLSearchParams(n).get(e);
841
857
  return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
842
858
  }
843
- function St(n, e, t) {
859
+ function xt(n, e, t) {
844
860
  const { tenantMode: r, baseDomain: i, selectorParam: o, fixedTenantSlug: a } = n;
845
- return r === "fixed" ? a || null : r === "subdomain" ? bt(e.hostname, i) : r === "selector" ? vt(e.search, o, t) : null;
861
+ return r === "fixed" ? a || null : r === "subdomain" ? Tt(e.hostname, i) : r === "selector" ? kt(e.search, o, t) : null;
846
862
  }
847
- function Tt(n, e, t) {
863
+ function At(n, e, t) {
848
864
  if (t)
849
865
  return `${n}.${t}`;
850
866
  const r = e.split(".");
851
867
  return r.length === 2 ? `${n}.${e}` : r.length >= 3 ? (r[0] = n, r.join(".")) : null;
852
868
  }
853
- const pe = "_auth";
854
- function _e(n) {
869
+ const me = "_auth";
870
+ function je(n) {
855
871
  const e = JSON.stringify(n);
856
872
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
857
873
  }
858
- function kt(n) {
874
+ function Pt(n) {
859
875
  try {
860
876
  let e = n.replace(/-/g, "+").replace(/_/g, "/");
861
877
  for (; e.length % 4; )
@@ -866,20 +882,20 @@ function kt(n) {
866
882
  return null;
867
883
  }
868
884
  }
869
- function xt() {
885
+ function Rt() {
870
886
  if (typeof window > "u")
871
887
  return null;
872
- const e = new URLSearchParams(window.location.search).get(pe);
873
- return e ? kt(e) : null;
888
+ const e = new URLSearchParams(window.location.search).get(me);
889
+ return e ? Pt(e) : null;
874
890
  }
875
- function At() {
891
+ function Et() {
876
892
  if (typeof window > "u") return;
877
893
  const n = new URL(window.location.href);
878
- n.searchParams.delete(pe), window.history.replaceState({}, "", n.toString());
894
+ n.searchParams.delete(me), window.history.replaceState({}, "", n.toString());
879
895
  }
880
- const Ne = fe(null);
881
- function wr({ config: n, children: e }) {
882
- const { baseUrl: t, appInfo: r, appId: i } = Se(), o = se(() => typeof window > "u" ? null : St(
896
+ const Ue = ye(null);
897
+ function Sr({ config: n, children: e }) {
898
+ const { baseUrl: t, appInfo: r, appId: i } = Ae(), o = oe(() => typeof window > "u" ? null : xt(
883
899
  {
884
900
  tenantMode: n.tenantMode || "selector",
885
901
  baseDomain: n.baseDomain,
@@ -891,119 +907,119 @@ function wr({ config: n, children: e }) {
891
907
  search: window.location.search
892
908
  },
893
909
  window.localStorage
894
- ), [n.tenantMode, n.baseDomain, n.selectorParam, n.fixedTenantSlug]), [a, p] = k(() => o()), w = K(
910
+ ), [n.tenantMode, n.baseDomain, n.selectorParam, n.fixedTenantSlug]), [a, c] = x(() => o()), m = Z(
895
911
  () => {
896
- var c, H, I;
912
+ var p, U, b;
897
913
  return {
898
- enabled: ((c = n.cache) == null ? void 0 : c.enabled) ?? !0,
899
- ttl: ((H = n.cache) == null ? void 0 : H.ttl) ?? 5 * 60 * 1e3,
914
+ enabled: ((p = n.cache) == null ? void 0 : p.enabled) ?? !0,
915
+ ttl: ((U = n.cache) == null ? void 0 : U.ttl) ?? 5 * 60 * 1e3,
900
916
  // 5 minutes default
901
- storageKey: ((I = n.cache) == null ? void 0 : I.storageKey) ?? `tenant_cache_${a || "default"}`
917
+ storageKey: ((b = n.cache) == null ? void 0 : b.storageKey) ?? `tenant_cache_${a || "default"}`
902
918
  };
903
919
  },
904
920
  [n.cache, a]
905
- ), [y, f] = k(() => {
921
+ ), [y, f] = x(() => {
906
922
  if (n.initialTenant) return n.initialTenant;
907
- if (!w.enabled || !a) return null;
923
+ if (!m.enabled || !a) return null;
908
924
  try {
909
- const c = localStorage.getItem(w.storageKey);
910
- if (!c) return null;
911
- const H = JSON.parse(c);
912
- return Date.now() - H.timestamp < w.ttl && H.tenantSlug === a ? H.data : (localStorage.removeItem(w.storageKey), null);
925
+ const p = localStorage.getItem(m.storageKey);
926
+ if (!p) return null;
927
+ const U = JSON.parse(p);
928
+ return Date.now() - U.timestamp < m.ttl && U.tenantSlug === a ? U.data : (localStorage.removeItem(m.storageKey), null);
913
929
  } catch {
914
930
  return null;
915
931
  }
916
- }), [x, h] = k(!y && !n.initialTenant), [R, N] = k(null), [D, E] = k(null), [P, u] = k(!1), [S, C] = k(null);
917
- re(() => {
932
+ }), [F, g] = x(!y && !n.initialTenant), [T, A] = x(null), [L, M] = x(null), [P, d] = x(!1), [v, N] = x(null);
933
+ ne(() => {
918
934
  if (n.tenantMode === "fixed") return;
919
- const c = o();
920
- p(c);
935
+ const p = o();
936
+ c(p);
921
937
  }, [o, n.tenantMode]);
922
- const M = (r == null ? void 0 : r.settingsSchema) || null, T = se(
923
- async (c, H = !1) => {
924
- if (!(!H && w.enabled && y && y.domain === c))
938
+ const B = (r == null ? void 0 : r.settingsSchema) || null, w = oe(
939
+ async (p, U = !1) => {
940
+ if (!(!U && m.enabled && y && y.domain === p))
925
941
  try {
926
- h(!0), N(null);
927
- const I = new le(t), m = await new be(I, i).getPublicTenantInfo(c);
928
- if (f(m), w.enabled)
942
+ g(!0), A(null);
943
+ const b = new de(t), S = await new ve(b, i).getPublicTenantInfo(p);
944
+ if (f(S), m.enabled)
929
945
  try {
930
- const v = {
931
- data: m,
946
+ const E = {
947
+ data: S,
932
948
  timestamp: Date.now(),
933
- tenantSlug: c
949
+ tenantSlug: p
934
950
  };
935
- localStorage.setItem(w.storageKey, JSON.stringify(v));
936
- } catch (v) {
937
- process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", v);
951
+ localStorage.setItem(m.storageKey, JSON.stringify(E));
952
+ } catch (E) {
953
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", E);
938
954
  }
939
- } catch (I) {
940
- const g = I instanceof Error ? I : new Error("Failed to load tenant information");
941
- N(g), f(null);
955
+ } catch (b) {
956
+ const h = b instanceof Error ? b : new Error("Failed to load tenant information");
957
+ A(h), f(null);
942
958
  } finally {
943
- h(!1);
959
+ g(!1);
944
960
  }
945
961
  },
946
- [t, i, w, y]
947
- ), $ = se(async () => {
948
- if (!(!w.enabled || !y || !a))
962
+ [t, i, m, y]
963
+ ), R = oe(async () => {
964
+ if (!(!m.enabled || !y || !a))
949
965
  try {
950
- const c = localStorage.getItem(w.storageKey);
951
- if (!c) return;
952
- const H = JSON.parse(c);
953
- if (Date.now() - H.timestamp > w.ttl * 0.5) {
954
- const g = new le(t), v = await new be(g, i).getPublicTenantInfo(a);
955
- f(v);
956
- const Q = {
957
- data: v,
966
+ const p = localStorage.getItem(m.storageKey);
967
+ if (!p) return;
968
+ const U = JSON.parse(p);
969
+ if (Date.now() - U.timestamp > m.ttl * 0.5) {
970
+ const h = new de(t), E = await new ve(h, i).getPublicTenantInfo(a);
971
+ f(E);
972
+ const K = {
973
+ data: E,
958
974
  timestamp: Date.now(),
959
975
  tenantSlug: a
960
976
  };
961
- localStorage.setItem(w.storageKey, JSON.stringify(Q));
977
+ localStorage.setItem(m.storageKey, JSON.stringify(K));
962
978
  }
963
- } catch (c) {
964
- process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", c);
979
+ } catch (p) {
980
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", p);
965
981
  }
966
- }, [t, i, w, y, a]), l = se(async () => {
982
+ }, [t, i, m, y, a]), k = oe(async () => {
967
983
  if (y != null && y.id)
968
984
  try {
969
- u(!0), C(null);
970
- const c = new le(t), I = await new be(c, y.appId).getTenantSettings(y.id);
971
- E(I);
972
- } catch (c) {
973
- const H = c instanceof Error ? c : new Error("Failed to load tenant settings");
974
- C(H), E(null);
985
+ d(!0), N(null);
986
+ const p = new de(t), b = await new ve(p, y.appId).getTenantSettings(y.id);
987
+ M(b);
988
+ } catch (p) {
989
+ const U = p instanceof Error ? p : new Error("Failed to load tenant settings");
990
+ N(U), M(null);
975
991
  } finally {
976
- u(!1);
992
+ d(!1);
977
993
  }
978
- }, [t, y]), U = se(() => {
979
- l();
980
- }, [l]), b = se(
981
- (c) => {
982
- if (!M)
994
+ }, [t, y]), I = oe(() => {
995
+ k();
996
+ }, [k]), l = oe(
997
+ (p) => {
998
+ if (!B)
983
999
  return { isValid: !0, errors: [] };
984
- const H = [];
1000
+ const U = [];
985
1001
  try {
986
- return M.properties && Object.entries(M.properties).forEach(([I, g]) => {
987
- var v;
988
- const m = c[I];
989
- if ((v = M.required) != null && v.includes(I) && m == null) {
990
- H.push(`Field '${I}' is required`);
1002
+ return B.properties && Object.entries(B.properties).forEach(([b, h]) => {
1003
+ var E;
1004
+ const S = p[b];
1005
+ if ((E = B.required) != null && E.includes(b) && S == null) {
1006
+ U.push(`Field '${b}' is required`);
991
1007
  return;
992
1008
  }
993
- if (m != null) {
994
- if (g.type) {
995
- const Q = g.type, J = typeof m;
996
- Q === "string" && J !== "string" ? H.push(`Field '${I}' must be a string`) : (Q === "number" || Q === "integer") && J !== "number" ? H.push(`Field '${I}' must be a number`) : Q === "boolean" && J !== "boolean" ? H.push(`Field '${I}' must be a boolean`) : Q === "array" && !Array.isArray(m) && H.push(`Field '${I}' must be an array`);
1009
+ if (S != null) {
1010
+ if (h.type) {
1011
+ const K = h.type, G = typeof S;
1012
+ K === "string" && G !== "string" ? U.push(`Field '${b}' must be a string`) : (K === "number" || K === "integer") && G !== "number" ? U.push(`Field '${b}' must be a number`) : K === "boolean" && G !== "boolean" ? U.push(`Field '${b}' must be a boolean`) : K === "array" && !Array.isArray(S) && U.push(`Field '${b}' must be an array`);
997
1013
  }
998
- g.minLength !== void 0 && typeof m == "string" && m.length < g.minLength && H.push(
999
- `Field '${I}' must be at least ${g.minLength} characters long`
1000
- ), g.maxLength !== void 0 && typeof m == "string" && m.length > g.maxLength && H.push(
1001
- `Field '${I}' must be no more than ${g.maxLength} characters long`
1002
- ), g.minimum !== void 0 && typeof m == "number" && m < g.minimum && H.push(`Field '${I}' must be at least ${g.minimum}`), g.maximum !== void 0 && typeof m == "number" && m > g.maximum && H.push(`Field '${I}' must be no more than ${g.maximum}`), g.pattern && typeof m == "string" && (new RegExp(g.pattern).test(m) || H.push(`Field '${I}' does not match the required pattern`)), g.enum && !g.enum.includes(m) && H.push(`Field '${I}' must be one of: ${g.enum.join(", ")}`);
1014
+ h.minLength !== void 0 && typeof S == "string" && S.length < h.minLength && U.push(
1015
+ `Field '${b}' must be at least ${h.minLength} characters long`
1016
+ ), h.maxLength !== void 0 && typeof S == "string" && S.length > h.maxLength && U.push(
1017
+ `Field '${b}' must be no more than ${h.maxLength} characters long`
1018
+ ), h.minimum !== void 0 && typeof S == "number" && S < h.minimum && U.push(`Field '${b}' must be at least ${h.minimum}`), h.maximum !== void 0 && typeof S == "number" && S > h.maximum && U.push(`Field '${b}' must be no more than ${h.maximum}`), h.pattern && typeof S == "string" && (new RegExp(h.pattern).test(S) || U.push(`Field '${b}' does not match the required pattern`)), h.enum && !h.enum.includes(S) && U.push(`Field '${b}' must be one of: ${h.enum.join(", ")}`);
1003
1019
  }
1004
1020
  }), {
1005
- isValid: H.length === 0,
1006
- errors: H
1021
+ isValid: U.length === 0,
1022
+ errors: U
1007
1023
  };
1008
1024
  } catch {
1009
1025
  return {
@@ -1012,98 +1028,98 @@ function wr({ config: n, children: e }) {
1012
1028
  };
1013
1029
  }
1014
1030
  },
1015
- [M]
1031
+ [B]
1016
1032
  );
1017
- re(() => {
1018
- !n.initialTenant && a ? y ? $() : T(a) : !n.initialTenant && !a && (f(null), N(null), h(!1));
1019
- }, [n.initialTenant, a, y, T, $]), re(() => {
1020
- y != null && y.id ? l() : (E(null), C(null), u(!1));
1021
- }, [y == null ? void 0 : y.id, l]);
1022
- const L = se(
1023
- (c, H) => {
1024
- const { mode: I = "reload", tokens: g, redirectPath: m } = H || {}, v = n.tenantMode || "selector";
1025
- if (v === "fixed") {
1033
+ ne(() => {
1034
+ !n.initialTenant && a ? y ? R() : w(a) : !n.initialTenant && !a && (f(null), A(null), g(!1));
1035
+ }, [n.initialTenant, a, y, w, R]), ne(() => {
1036
+ y != null && y.id ? k() : (M(null), N(null), d(!1));
1037
+ }, [y == null ? void 0 : y.id, k]);
1038
+ const z = oe(
1039
+ (p, U) => {
1040
+ const { mode: b = "reload", tokens: h, redirectPath: S } = U || {}, E = n.tenantMode || "selector";
1041
+ if (E === "fixed") {
1026
1042
  process.env.NODE_ENV === "development" && console.warn(
1027
1043
  "[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
1028
1044
  n.fixedTenantSlug
1029
- ), m && (window.location.href = m);
1045
+ ), S && (window.location.href = S);
1030
1046
  return;
1031
1047
  }
1032
- if (localStorage.setItem("tenant", c), v === "subdomain") {
1033
- const Q = window.location.hostname, J = Tt(
1034
- c,
1035
- Q,
1048
+ if (localStorage.setItem("tenant", p), E === "subdomain") {
1049
+ const K = window.location.hostname, G = At(
1050
+ p,
1051
+ K,
1036
1052
  n.baseDomain
1037
1053
  );
1038
- if (!J) {
1054
+ if (!G) {
1039
1055
  process.env.NODE_ENV === "development" && console.warn(
1040
1056
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
1041
- Q
1057
+ K
1042
1058
  );
1043
1059
  return;
1044
1060
  }
1045
- const O = m || window.location.pathname, q = new URL(`${window.location.protocol}//${J}${O}`);
1046
- new URLSearchParams(window.location.search).forEach((A, V) => {
1047
- V !== pe && q.searchParams.set(V, A);
1048
- }), g && q.searchParams.set(pe, _e(g)), window.location.href = q.toString();
1049
- } else if (v === "selector") {
1050
- const Q = m || window.location.pathname, J = new URLSearchParams(window.location.search);
1051
- if (J.set(n.selectorParam || "tenant", c), J.delete(pe), g && J.set(pe, _e(g)), I === "reload") {
1052
- const O = `${Q}?${J.toString()}${window.location.hash}`;
1053
- window.location.href = O;
1061
+ const X = S || window.location.pathname, W = new URL(`${window.location.protocol}//${G}${X}`);
1062
+ new URLSearchParams(window.location.search).forEach((V, H) => {
1063
+ H !== me && W.searchParams.set(H, V);
1064
+ }), h && W.searchParams.set(me, je(h)), window.location.href = W.toString();
1065
+ } else if (E === "selector") {
1066
+ const K = S || window.location.pathname, G = new URLSearchParams(window.location.search);
1067
+ if (G.set(n.selectorParam || "tenant", p), G.delete(me), h && G.set(me, je(h)), b === "reload") {
1068
+ const X = `${K}?${G.toString()}${window.location.hash}`;
1069
+ window.location.href = X;
1054
1070
  } else {
1055
- const O = `${Q}?${J.toString()}${window.location.hash}`;
1056
- window.history.pushState({}, "", O), p(c), T(c);
1071
+ const X = `${K}?${G.toString()}${window.location.hash}`;
1072
+ window.history.pushState({}, "", X), c(p), w(p);
1057
1073
  }
1058
1074
  }
1059
1075
  },
1060
- [n.tenantMode, n.selectorParam, n.baseDomain, T]
1061
- ), F = K(() => ({
1076
+ [n.tenantMode, n.selectorParam, n.baseDomain, w]
1077
+ ), D = Z(() => ({
1062
1078
  // Tenant info
1063
1079
  tenant: y,
1064
1080
  tenantSlug: a,
1065
- isTenantLoading: x,
1066
- tenantError: R,
1081
+ isTenantLoading: F,
1082
+ tenantError: T,
1067
1083
  retryTenant: () => {
1068
- a && T(a);
1084
+ a && w(a);
1069
1085
  },
1070
1086
  // Settings
1071
- settings: D,
1072
- settingsSchema: M,
1087
+ settings: L,
1088
+ settingsSchema: B,
1073
1089
  isSettingsLoading: P,
1074
- settingsError: S,
1090
+ settingsError: v,
1075
1091
  // Actions
1076
- refreshSettings: U,
1077
- switchTenant: L,
1092
+ refreshSettings: I,
1093
+ switchTenant: z,
1078
1094
  // Validation
1079
- validateSettings: b
1095
+ validateSettings: l
1080
1096
  }), [
1081
1097
  y,
1082
1098
  a,
1083
- x,
1084
- R,
1085
- D,
1086
- M,
1087
- P,
1088
- S,
1089
- U,
1099
+ F,
1100
+ T,
1090
1101
  L,
1091
- b
1102
+ B,
1103
+ P,
1104
+ v,
1105
+ I,
1106
+ z,
1107
+ l
1092
1108
  ]);
1093
- return /* @__PURE__ */ s(Ne.Provider, { value: F, children: e });
1109
+ return /* @__PURE__ */ s(Ue.Provider, { value: D, children: e });
1094
1110
  }
1095
- function ge() {
1096
- const n = ae(Ne);
1111
+ function Te() {
1112
+ const n = le(Ue);
1097
1113
  if (!n)
1098
1114
  throw new Error("useTenant must be used within a TenantProvider");
1099
1115
  return n;
1100
1116
  }
1101
- function xe() {
1102
- return ae(Ne);
1117
+ function pe() {
1118
+ return le(Ue);
1103
1119
  }
1104
- const br = ge;
1105
- function vr() {
1106
- const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = ge();
1120
+ const Tr = Te;
1121
+ function kr() {
1122
+ const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = Te();
1107
1123
  return {
1108
1124
  settings: n,
1109
1125
  settingsSchema: e,
@@ -1112,8 +1128,8 @@ function vr() {
1112
1128
  validateSettings: i
1113
1129
  };
1114
1130
  }
1115
- function me() {
1116
- const { tenant: n, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: i } = ge();
1131
+ function Je() {
1132
+ const { tenant: n, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: i } = Te();
1117
1133
  return {
1118
1134
  tenant: n,
1119
1135
  tenantSlug: e,
@@ -1122,389 +1138,395 @@ function me() {
1122
1138
  retry: i
1123
1139
  };
1124
1140
  }
1125
- const De = fe(null);
1126
- function Sr({ config: n = {}, children: e }) {
1127
- const { appId: t, baseUrl: r } = Se(), { tenant: i, tenantSlug: o, switchTenant: a } = ge(), [p, w] = k(n.initialRoles || []), [y, f] = k(!n.initialRoles), [x, h] = k(null), [R, N] = k(!1), [D, E] = k(null), [P, u] = k(() => {
1141
+ const Be = ye(null);
1142
+ function xr({ config: n = {}, children: e }) {
1143
+ const t = De(), r = pe(), i = (t == null ? void 0 : t.baseUrl) ?? n.baseUrl ?? "", o = (t == null ? void 0 : t.appId) ?? n.appId, a = (r == null ? void 0 : r.tenant) ?? null, c = (r == null ? void 0 : r.tenantSlug) ?? null, m = (r == null ? void 0 : r.switchTenant) ?? (() => {
1144
+ });
1145
+ if (!i)
1146
+ throw new Error(
1147
+ "[AuthProvider] baseUrl is required. Provide it via AppProvider or AuthConfig.baseUrl."
1148
+ );
1149
+ const [y, f] = x(n.initialRoles || []), [F, g] = x(!n.initialRoles), [T, A] = x(null), [L, M] = x(!1), [P, d] = x(null), [v, N] = x(() => {
1128
1150
  try {
1129
- const A = localStorage.getItem("userTenants");
1130
- return A ? JSON.parse(A) : [];
1151
+ const $ = localStorage.getItem("userTenants");
1152
+ return $ ? JSON.parse($) : [];
1131
1153
  } catch {
1132
1154
  return [];
1133
1155
  }
1134
- }), [S, C] = k(!1), M = Me({ done: !1, urlTokens: null });
1135
- M.current.done || (M.current.done = !0, M.current.urlTokens = xt());
1136
- const [T, $] = k(() => M.current.urlTokens !== null), l = K(() => {
1137
- const A = we.getInstance({
1138
- tenantSlug: o,
1139
- baseUrl: r,
1156
+ }), [B, w] = x(!1), R = Ne({ done: !1, urlTokens: null });
1157
+ R.current.done || (R.current.done = !0, R.current.urlTokens = Rt());
1158
+ const [k, I] = x(() => R.current.urlTokens !== null), l = Z(() => {
1159
+ const $ = be.getInstance({
1160
+ tenantSlug: c,
1161
+ baseUrl: i,
1140
1162
  refreshQueueTimeout: n.refreshQueueTimeout,
1141
1163
  proactiveRefreshMargin: n.proactiveRefreshMargin,
1142
- onSessionExpired: (V) => {
1143
- h(null), E(null), u([]), C(!1);
1164
+ onSessionExpired: (ce) => {
1165
+ A(null), d(null), N([]), w(!1);
1144
1166
  try {
1145
1167
  localStorage.removeItem("userTenants");
1146
1168
  } catch {
1147
1169
  }
1148
- n.onSessionExpired ? n.onSessionExpired(V) : n.onRefreshFailed && n.onRefreshFailed();
1170
+ n.onSessionExpired ? n.onSessionExpired(ce) : n.onRefreshFailed && n.onRefreshFailed();
1149
1171
  }
1150
1172
  });
1151
- return M.current.urlTokens && A.setTokens({
1152
- accessToken: M.current.urlTokens.accessToken,
1153
- refreshToken: M.current.urlTokens.refreshToken,
1154
- expiresIn: M.current.urlTokens.expiresIn
1155
- }), A;
1156
- }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [U, b] = k(() => {
1157
- if (M.current.urlTokens) return !1;
1158
- const A = l.getTokens();
1159
- return A ? l.hasValidSession() || !!A.refreshToken : !1;
1160
- }), L = M.current.done && !T && !U, F = K(() => {
1161
- const A = new le(r);
1162
- return A.setSessionManager(l), A;
1163
- }, [r, l]), c = K(() => new yt(new le(r)), [r]), H = K(() => new wt(F, l), [F, l]), I = K(() => new ze(new le(r)), [r]), g = K(() => x || l.getUser(), [x, l]), m = K(() => g != null && g.roleId && p.find((A) => A.id === g.roleId) || null, [g, p]), v = K(() => (m == null ? void 0 : m.permissions) || [], [m]), Q = K(() => l.hasValidSession() && x !== null, [l, x]), J = Me(async () => {
1164
- }), O = K(() => {
1165
- const A = async (B = !1) => {
1173
+ return R.current.urlTokens && $.setTokens({
1174
+ accessToken: R.current.urlTokens.accessToken,
1175
+ refreshToken: R.current.urlTokens.refreshToken,
1176
+ expiresIn: R.current.urlTokens.expiresIn
1177
+ }), $;
1178
+ }, [c, i, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [z, D] = x(() => {
1179
+ if (R.current.urlTokens) return !1;
1180
+ const $ = l.getTokens();
1181
+ return $ ? l.hasValidSession() || !!$.refreshToken : !1;
1182
+ }), p = R.current.done && !k && !z, U = Z(() => {
1183
+ const $ = new de(i);
1184
+ return $.setSessionManager(l), $;
1185
+ }, [i, l]), b = Z(() => new vt(new de(i)), [i]), h = Z(() => new St(U, l), [U, l]), S = Z(() => new We(new de(i)), [i]), E = Z(() => T || l.getUser(), [T, l]), K = Z(() => E != null && E.roleId && y.find(($) => $.id === E.roleId) || null, [E, y]), G = Z(() => (K == null ? void 0 : K.permissions) || [], [K]), X = Z(() => l.hasValidSession() && T !== null, [l, T]), W = Ne(async () => {
1186
+ }), q = Z(() => {
1187
+ const $ = async (C = !1) => {
1166
1188
  try {
1167
- if (!l.hasValidSession() || !B && x)
1189
+ if (!l.hasValidSession() || !C && T)
1168
1190
  return;
1169
- const z = l.getUserId();
1170
- if (!z) {
1191
+ const O = l.getUserId();
1192
+ if (!O) {
1171
1193
  process.env.NODE_ENV === "development" && console.warn("[AuthProvider] No userId available in token or storage");
1172
1194
  return;
1173
1195
  }
1174
- N(!0), E(null);
1175
- const Z = await H.getUserById(z);
1176
- h(Z), l.setUser(Z);
1177
- } catch (z) {
1178
- const Z = z instanceof Error ? z : new Error("Failed to load user data");
1179
- E(Z), process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data:", Z);
1196
+ M(!0), d(null);
1197
+ const J = await h.getUserById(O);
1198
+ A(J), l.setUser(J);
1199
+ } catch (O) {
1200
+ const J = O instanceof Error ? O : new Error("Failed to load user data");
1201
+ d(J), process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data:", J);
1180
1202
  } finally {
1181
- N(!1);
1203
+ M(!1);
1182
1204
  }
1183
- }, V = async () => {
1184
- await A();
1185
- }, de = async (B) => {
1186
- var Be;
1187
- const { username: z, password: Z, tenantSlug: W, redirectPath: Y } = B;
1188
- let X = i == null ? void 0 : i.id, ee = o, te = l;
1189
- W && (X = (await new be(F, t).getPublicTenantInfo(W)).id, ee = W);
1190
- const G = await c.login({
1191
- username: z,
1192
- password: Z,
1193
- appId: t,
1194
- tenantId: X
1195
- }), ye = W && W !== o;
1196
- if (ye && (te = new we({
1197
- tenantSlug: ee,
1198
- baseUrl: r
1199
- })), te.setTokens({
1200
- accessToken: G.accessToken,
1201
- refreshToken: G.refreshToken,
1202
- expiresIn: G.expiresIn
1203
- }), G.user) {
1204
- te.setUser(G.user), h(G.user);
1205
+ }, ce = async () => {
1206
+ await $();
1207
+ }, fe = async (C) => {
1208
+ var _e;
1209
+ const { username: O, password: J, tenantSlug: j, redirectPath: Y } = C;
1210
+ let ee = a == null ? void 0 : a.id, te = c, re = l;
1211
+ j && (ee = (await new ve(U, o).getPublicTenantInfo(j)).id, te = j);
1212
+ const Q = await b.login({
1213
+ username: O,
1214
+ password: J,
1215
+ appId: o,
1216
+ tenantId: ee
1217
+ }), we = j && j !== c;
1218
+ if (we && (re = new be({
1219
+ tenantSlug: te,
1220
+ baseUrl: i
1221
+ })), re.setTokens({
1222
+ accessToken: Q.accessToken,
1223
+ refreshToken: Q.refreshToken,
1224
+ expiresIn: Q.expiresIn
1225
+ }), Q.user) {
1226
+ re.setUser(Q.user), A(Q.user);
1205
1227
  try {
1206
- await A();
1207
- } catch (Te) {
1208
- process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", Te);
1228
+ await $();
1229
+ } catch (ke) {
1230
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", ke);
1209
1231
  }
1210
1232
  }
1211
- if (G.tenants && G.tenants.length > 0) {
1212
- u(G.tenants);
1233
+ if (Q.tenants && Q.tenants.length > 0) {
1234
+ N(Q.tenants);
1213
1235
  try {
1214
- localStorage.setItem("userTenants", JSON.stringify(G.tenants));
1236
+ localStorage.setItem("userTenants", JSON.stringify(Q.tenants));
1215
1237
  } catch {
1216
1238
  }
1217
1239
  }
1218
- const Pe = ((Be = G.user) == null ? void 0 : Be.tenantId) !== null;
1219
- C(Pe);
1220
- const Re = {
1221
- accessToken: G.accessToken,
1222
- refreshToken: G.refreshToken,
1223
- expiresIn: G.expiresIn
1240
+ const Re = ((_e = Q.user) == null ? void 0 : _e.tenantId) !== null;
1241
+ w(Re);
1242
+ const Ee = {
1243
+ accessToken: Q.accessToken,
1244
+ refreshToken: Q.refreshToken,
1245
+ expiresIn: Q.expiresIn
1224
1246
  };
1225
- if (ye && ee)
1226
- return a(ee, { tokens: Re, redirectPath: Y }), G;
1247
+ if (we && te)
1248
+ return m(te, { tokens: Ee, redirectPath: Y }), Q;
1227
1249
  if (Y && Y !== window.location.pathname)
1228
- return a(ee || o || "", { tokens: Re, redirectPath: Y }), G;
1229
- if (!Pe && G.tenants && G.tenants.length > 0) {
1230
- const Te = B.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1231
- if (G.tenants.length === 1 && Te) {
1232
- const Oe = G.tenants[0];
1233
- return a(Oe.subdomain, { tokens: Re, redirectPath: Y }), G;
1234
- } else G.tenants.length > 1 && n.onTenantSelectionRequired && n.onTenantSelectionRequired(G.tenants);
1250
+ return m(te || c || "", { tokens: Ee, redirectPath: Y }), Q;
1251
+ if (!Re && Q.tenants && Q.tenants.length > 0) {
1252
+ const ke = C.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1253
+ if (Q.tenants.length === 1 && ke) {
1254
+ const ze = Q.tenants[0];
1255
+ return m(ze.subdomain, { tokens: Ee, redirectPath: Y }), Q;
1256
+ } else Q.tenants.length > 1 && n.onTenantSelectionRequired && n.onTenantSelectionRequired(Q.tenants);
1235
1257
  }
1236
- return G;
1237
- }, he = async (B) => {
1238
- const { email: z, phoneNumber: Z, name: W, password: Y, lastName: X, tenantId: ee } = B;
1239
- if (!z && !Z)
1258
+ return Q;
1259
+ }, ge = async (C) => {
1260
+ const { email: O, phoneNumber: J, name: j, password: Y, lastName: ee, tenantId: te } = C;
1261
+ if (!O && !J)
1240
1262
  throw new Error("Either email or phoneNumber is required");
1241
- if (!W || !Y)
1263
+ if (!j || !Y)
1242
1264
  throw new Error("Name and password are required");
1243
- const te = ee ?? (i == null ? void 0 : i.id);
1244
- return await c.signup({
1245
- email: z,
1246
- phoneNumber: Z,
1247
- name: W,
1265
+ const re = te ?? (a == null ? void 0 : a.id);
1266
+ return await b.signup({
1267
+ email: O,
1268
+ phoneNumber: J,
1269
+ name: j,
1248
1270
  password: Y,
1249
- tenantId: te,
1250
- lastName: X,
1251
- appId: t
1271
+ tenantId: re,
1272
+ lastName: ee,
1273
+ appId: o
1252
1274
  });
1253
- }, et = async (B) => {
1254
- const { email: z, phoneNumber: Z, name: W, password: Y, tenantName: X, lastName: ee } = B;
1255
- if (!z && !Z)
1275
+ }, nt = async (C) => {
1276
+ const { email: O, phoneNumber: J, name: j, password: Y, tenantName: ee, lastName: te } = C;
1277
+ if (!O && !J)
1256
1278
  throw new Error("Either email or phoneNumber is required");
1257
- if (!W || !Y || !X)
1279
+ if (!j || !Y || !ee)
1258
1280
  throw new Error("Name, password, and tenantName are required");
1259
- return await c.signupTenantAdmin({
1260
- email: z,
1261
- phoneNumber: Z,
1262
- name: W,
1281
+ return await b.signupTenantAdmin({
1282
+ email: O,
1283
+ phoneNumber: J,
1284
+ name: j,
1263
1285
  password: Y,
1264
- tenantName: X,
1265
- appId: t,
1266
- lastName: ee
1286
+ tenantName: ee,
1287
+ appId: o,
1288
+ lastName: te
1267
1289
  });
1268
- }, tt = async (B) => {
1269
- const { currentPassword: z, newPassword: Z } = B, W = await l.getAuthHeaders();
1270
- await c.changePassword({ currentPassword: z, newPassword: Z }, W);
1271
- }, rt = async (B) => {
1272
- const { email: z, tenantId: Z } = B, W = Z ?? (i == null ? void 0 : i.id);
1273
- if (!W)
1290
+ }, st = async (C) => {
1291
+ const { currentPassword: O, newPassword: J } = C, j = await l.getAuthHeaders();
1292
+ await b.changePassword({ currentPassword: O, newPassword: J }, j);
1293
+ }, it = async (C) => {
1294
+ const { email: O, tenantId: J } = C, j = J ?? (a == null ? void 0 : a.id);
1295
+ if (!j)
1274
1296
  throw new Error("tenantId is required for password reset");
1275
- await c.requestPasswordReset({ email: z, tenantId: W });
1276
- }, nt = async (B) => {
1277
- const { token: z, newPassword: Z } = B;
1278
- await c.confirmPasswordReset({ token: z, newPassword: Z });
1279
- }, st = async (B) => {
1280
- const { email: z, frontendUrl: Z, name: W, lastName: Y, tenantId: X } = B, ee = X ?? (i == null ? void 0 : i.id);
1281
- if (!ee)
1297
+ await b.requestPasswordReset({ email: O, tenantId: j });
1298
+ }, ot = async (C) => {
1299
+ const { token: O, newPassword: J } = C;
1300
+ await b.confirmPasswordReset({ token: O, newPassword: J });
1301
+ }, at = async (C) => {
1302
+ const { email: O, frontendUrl: J, name: j, lastName: Y, tenantId: ee } = C, te = ee ?? (a == null ? void 0 : a.id);
1303
+ if (!te)
1282
1304
  throw new Error("tenantId is required for magic link authentication");
1283
- return await c.sendMagicLink({
1284
- email: z,
1285
- tenantId: ee,
1286
- frontendUrl: Z,
1287
- name: W,
1305
+ return await b.sendMagicLink({
1306
+ email: O,
1307
+ tenantId: te,
1308
+ frontendUrl: J,
1309
+ name: j,
1288
1310
  lastName: Y,
1289
- appId: t
1311
+ appId: o
1290
1312
  });
1291
- }, it = async (B) => {
1292
- const { token: z, email: Z, tenantSlug: W } = B;
1293
- let Y = i == null ? void 0 : i.id, X = o, ee = l;
1294
- W && (Y = (await new be(F, t).getPublicTenantInfo(W)).id, X = W);
1295
- const te = await c.verifyMagicLink({
1296
- token: z,
1297
- email: Z,
1298
- appId: t,
1313
+ }, lt = async (C) => {
1314
+ const { token: O, email: J, tenantSlug: j } = C;
1315
+ let Y = a == null ? void 0 : a.id, ee = c, te = l;
1316
+ j && (Y = (await new ve(U, o).getPublicTenantInfo(j)).id, ee = j);
1317
+ const re = await b.verifyMagicLink({
1318
+ token: O,
1319
+ email: J,
1320
+ appId: o,
1299
1321
  tenantId: Y
1300
- }), G = W && W !== o;
1301
- if (G && (ee = new we({
1302
- tenantSlug: X,
1303
- baseUrl: r
1304
- })), ee.setTokens({
1305
- accessToken: te.accessToken,
1306
- refreshToken: te.refreshToken,
1307
- expiresIn: te.expiresIn
1308
- }), te.user) {
1309
- ee.setUser(te.user), h(te.user);
1322
+ }), Q = j && j !== c;
1323
+ if (Q && (te = new be({
1324
+ tenantSlug: ee,
1325
+ baseUrl: i
1326
+ })), te.setTokens({
1327
+ accessToken: re.accessToken,
1328
+ refreshToken: re.refreshToken,
1329
+ expiresIn: re.expiresIn
1330
+ }), re.user) {
1331
+ te.setUser(re.user), A(re.user);
1310
1332
  try {
1311
- await A();
1312
- } catch (ye) {
1333
+ await $();
1334
+ } catch (we) {
1313
1335
  process.env.NODE_ENV === "development" && console.warn(
1314
1336
  "[AuthProvider] Failed to load complete user data after magic link:",
1315
- ye
1337
+ we
1316
1338
  );
1317
1339
  }
1318
1340
  }
1319
- return G && X && X !== o && a(X, {
1341
+ return Q && ee && ee !== c && m(ee, {
1320
1342
  tokens: {
1321
- accessToken: te.accessToken,
1322
- refreshToken: te.refreshToken,
1323
- expiresIn: te.expiresIn
1343
+ accessToken: re.accessToken,
1344
+ refreshToken: re.refreshToken,
1345
+ expiresIn: re.expiresIn
1324
1346
  }
1325
- }), te;
1326
- }, ot = async () => {
1327
- const B = l.getTokens();
1328
- if (!(B != null && B.refreshToken))
1347
+ }), re;
1348
+ }, ct = async () => {
1349
+ const C = l.getTokens();
1350
+ if (!(C != null && C.refreshToken))
1329
1351
  throw new Error("No refresh token available");
1330
- const z = await c.refreshToken({
1331
- refreshToken: B.refreshToken
1352
+ const O = await b.refreshToken({
1353
+ refreshToken: C.refreshToken
1332
1354
  });
1333
1355
  l.setTokens({
1334
- accessToken: z.accessToken,
1335
- refreshToken: z.refreshToken || B.refreshToken,
1336
- expiresIn: z.expiresIn
1356
+ accessToken: O.accessToken,
1357
+ refreshToken: O.refreshToken || C.refreshToken,
1358
+ expiresIn: O.expiresIn
1337
1359
  });
1338
- }, at = () => {
1339
- l.clearSession(), h(null), E(null), u([]), C(!1);
1360
+ }, dt = () => {
1361
+ l.clearSession(), A(null), d(null), N([]), w(!1);
1340
1362
  try {
1341
1363
  localStorage.removeItem("userTenants");
1342
1364
  } catch {
1343
1365
  }
1344
- }, lt = (B) => {
1345
- l.setTokens(B);
1346
- }, ct = () => l.hasValidSession(), dt = () => {
1347
- l.clearSession(), h(null), E(null);
1348
- }, ut = async () => {
1349
- if (t)
1366
+ }, ut = (C) => {
1367
+ l.setTokens(C);
1368
+ }, ht = () => l.hasValidSession(), pt = () => {
1369
+ l.clearSession(), A(null), d(null);
1370
+ }, ft = async () => {
1371
+ if (o)
1350
1372
  try {
1351
- f(!0);
1352
- const { roles: B } = await I.getRolesByApp(t);
1353
- w(B);
1354
- } catch (B) {
1355
- process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", B);
1373
+ g(!0);
1374
+ const { roles: C } = await S.getRolesByApp(o);
1375
+ f(C);
1376
+ } catch (C) {
1377
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", C);
1356
1378
  } finally {
1357
- f(!1);
1379
+ g(!1);
1358
1380
  }
1359
- }, ht = async () => {
1360
- await ut();
1361
- }, Ae = (B) => {
1362
- if (!v || v.length === 0)
1381
+ }, gt = async () => {
1382
+ await ft();
1383
+ }, Pe = (C) => {
1384
+ if (!G || G.length === 0)
1363
1385
  return !1;
1364
- if (typeof B == "string")
1365
- return v.includes(B);
1366
- const z = `${B.resource}.${B.action}`;
1367
- return v.includes(z);
1386
+ if (typeof C == "string")
1387
+ return G.includes(C);
1388
+ const O = `${C.resource}.${C.action}`;
1389
+ return G.includes(O);
1368
1390
  };
1369
1391
  return {
1370
1392
  // RFC-003: Authentication state
1371
- isAuthenticated: Q,
1393
+ isAuthenticated: X,
1372
1394
  sessionManager: l,
1373
- authenticatedHttpService: F,
1374
- login: de,
1375
- signup: he,
1376
- signupTenantAdmin: et,
1377
- sendMagicLink: st,
1378
- verifyMagicLink: it,
1379
- changePassword: tt,
1380
- requestPasswordReset: rt,
1381
- confirmPasswordReset: nt,
1382
- refreshToken: ot,
1383
- logout: at,
1384
- setTokens: lt,
1385
- hasValidSession: ct,
1386
- clearSession: dt,
1387
- currentUser: x,
1388
- isUserLoading: R,
1389
- userError: D,
1390
- loadUserData: A,
1391
- refreshUser: V,
1392
- isAuthInitializing: !L,
1393
- isAuthReady: L,
1394
- userRole: m,
1395
- userPermissions: v,
1396
- availableRoles: p,
1397
- rolesLoading: y,
1398
- hasPermission: Ae,
1399
- hasAnyPermission: (B) => B.some((z) => Ae(z)),
1400
- hasAllPermissions: (B) => B.every((z) => Ae(z)),
1401
- getUserPermissionStrings: () => v || [],
1402
- refreshRoles: ht,
1395
+ authenticatedHttpService: U,
1396
+ login: fe,
1397
+ signup: ge,
1398
+ signupTenantAdmin: nt,
1399
+ sendMagicLink: at,
1400
+ verifyMagicLink: lt,
1401
+ changePassword: st,
1402
+ requestPasswordReset: it,
1403
+ confirmPasswordReset: ot,
1404
+ refreshToken: ct,
1405
+ logout: dt,
1406
+ setTokens: ut,
1407
+ hasValidSession: ht,
1408
+ clearSession: pt,
1409
+ currentUser: T,
1410
+ isUserLoading: L,
1411
+ userError: P,
1412
+ loadUserData: $,
1413
+ refreshUser: ce,
1414
+ isAuthInitializing: !p,
1415
+ isAuthReady: p,
1416
+ userRole: K,
1417
+ userPermissions: G,
1418
+ availableRoles: y,
1419
+ rolesLoading: F,
1420
+ hasPermission: Pe,
1421
+ hasAnyPermission: (C) => C.some((O) => Pe(O)),
1422
+ hasAllPermissions: (C) => C.every((O) => Pe(O)),
1423
+ getUserPermissionStrings: () => G || [],
1424
+ refreshRoles: gt,
1403
1425
  // RFC-004: Multi-tenant user membership
1404
- userTenants: P,
1405
- hasTenantContext: S,
1406
- switchToTenant: async (B, z) => {
1407
- const { redirectPath: Z } = z || {}, W = l.getTokens();
1408
- if (!(W != null && W.refreshToken))
1426
+ userTenants: v,
1427
+ hasTenantContext: B,
1428
+ switchToTenant: async (C, O) => {
1429
+ const { redirectPath: J } = O || {}, j = l.getTokens();
1430
+ if (!(j != null && j.refreshToken))
1409
1431
  throw new Error("No refresh token available for tenant switch");
1410
- const Y = await c.switchTenant({
1411
- refreshToken: W.refreshToken,
1412
- tenantId: B
1432
+ const Y = await b.switchTenant({
1433
+ refreshToken: j.refreshToken,
1434
+ tenantId: C
1413
1435
  });
1414
1436
  l.setTokens({
1415
1437
  accessToken: Y.accessToken,
1416
- refreshToken: W.refreshToken,
1438
+ refreshToken: j.refreshToken,
1417
1439
  // Keep the same refresh token
1418
1440
  expiresIn: Y.expiresIn
1419
- }), h(Y.user), l.setUser(Y.user), C(!0);
1420
- const X = P.find((ee) => ee.id === B);
1421
- X && a(X.subdomain, {
1441
+ }), A(Y.user), l.setUser(Y.user), w(!0);
1442
+ const ee = v.find((te) => te.id === C);
1443
+ ee && m(ee.subdomain, {
1422
1444
  tokens: {
1423
1445
  accessToken: Y.accessToken,
1424
- refreshToken: W.refreshToken,
1446
+ refreshToken: j.refreshToken,
1425
1447
  expiresIn: Y.expiresIn
1426
1448
  },
1427
- redirectPath: Z
1449
+ redirectPath: J
1428
1450
  });
1429
1451
  },
1430
1452
  refreshUserTenants: async () => {
1431
- const B = await l.getAuthHeaders(), z = await c.getUserTenants(B);
1432
- u(z);
1453
+ const C = await l.getAuthHeaders(), O = await b.getUserTenants(C);
1454
+ N(O);
1433
1455
  try {
1434
- localStorage.setItem("userTenants", JSON.stringify(z));
1456
+ localStorage.setItem("userTenants", JSON.stringify(O));
1435
1457
  } catch {
1436
1458
  }
1437
- return z;
1459
+ return O;
1438
1460
  }
1439
1461
  };
1440
1462
  }, [
1441
- Q,
1463
+ X,
1442
1464
  l,
1443
- F,
1444
- c,
1445
- H,
1446
- I,
1447
- t,
1448
- i,
1465
+ U,
1466
+ b,
1467
+ h,
1468
+ S,
1449
1469
  o,
1450
1470
  a,
1451
- p,
1452
- x,
1453
- R,
1454
- D,
1455
- P,
1456
- S,
1457
- L,
1471
+ c,
1458
1472
  m,
1459
- v
1473
+ y,
1474
+ T,
1475
+ L,
1476
+ P,
1477
+ v,
1478
+ B,
1479
+ p,
1480
+ K,
1481
+ G
1460
1482
  ]);
1461
- J.current = O.loadUserData, re(() => {
1462
- !n.initialRoles && t && (async () => {
1483
+ W.current = q.loadUserData, ne(() => {
1484
+ !n.initialRoles && o && (async () => {
1463
1485
  try {
1464
- f(!0);
1465
- const V = new le(r), de = new ze(V), { roles: he } = await de.getRolesByApp(t);
1466
- w(he);
1467
- } catch (V) {
1468
- process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", V);
1486
+ g(!0);
1487
+ const ce = new de(i), fe = new We(ce), { roles: ge } = await fe.getRolesByApp(o);
1488
+ f(ge);
1489
+ } catch (ce) {
1490
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", ce);
1469
1491
  } finally {
1470
- f(!1);
1492
+ g(!1);
1471
1493
  }
1472
1494
  })();
1473
- }, [t, r, n.initialRoles]);
1474
- const [q, j] = k(!1);
1475
- return re(() => {
1476
- q || (j(!0), M.current.urlTokens && (At(), $(!0), O.loadUserData().catch((A) => {
1477
- process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data after URL tokens:", A);
1495
+ }, [o, i, n.initialRoles]);
1496
+ const [V, H] = x(!1);
1497
+ return ne(() => {
1498
+ V || (H(!0), R.current.urlTokens && (Et(), I(!0), q.loadUserData().catch(($) => {
1499
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data after URL tokens:", $);
1478
1500
  }).finally(() => {
1479
- $(!1);
1501
+ I(!1);
1480
1502
  })));
1481
- }, [O, q]), re(() => {
1482
- let A = !1;
1503
+ }, [q, V]), ne(() => {
1504
+ let $ = !1;
1483
1505
  return (async () => {
1484
- var he;
1485
- if (!l.hasValidSession() && ((he = l.getTokens()) != null && he.refreshToken) && await l.waitForPendingRefresh(), A) return;
1486
- const de = l.getUser();
1487
- de && l.hasValidSession() && h(de), b(!1);
1506
+ var ge;
1507
+ if (!l.hasValidSession() && ((ge = l.getTokens()) != null && ge.refreshToken) && await l.waitForPendingRefresh(), $) return;
1508
+ const fe = l.getUser();
1509
+ fe && l.hasValidSession() && A(fe), D(!1);
1488
1510
  })(), () => {
1489
- A = !0;
1511
+ $ = !0;
1490
1512
  };
1491
- }, [l]), re(() => {
1492
- q && (M.current.urlTokens || (!x && !R && !D && l.hasValidSession() ? J.current().catch(() => {
1513
+ }, [l]), ne(() => {
1514
+ V && (R.current.urlTokens || (!T && !L && !P && l.hasValidSession() ? W.current().catch(() => {
1493
1515
  }).finally(() => {
1494
- b(!1);
1495
- }) : b(!1)));
1496
- }, [x, R, D, l, q]), /* @__PURE__ */ s(De.Provider, { value: O, children: e });
1516
+ D(!1);
1517
+ }) : D(!1)));
1518
+ }, [T, L, P, l, V]), /* @__PURE__ */ s(Be.Provider, { value: q, children: e });
1497
1519
  }
1498
- function ue() {
1499
- const n = ae(De);
1520
+ function he() {
1521
+ const n = le(Be);
1500
1522
  if (!n)
1501
1523
  throw new Error("useAuth must be used within an AuthProvider");
1502
1524
  return n;
1503
1525
  }
1504
- function Fe() {
1505
- return ae(De);
1526
+ function $e() {
1527
+ return le(Be);
1506
1528
  }
1507
- class Pt {
1529
+ class It {
1508
1530
  constructor(e, t) {
1509
1531
  this.httpService = e, this.sessionManager = t;
1510
1532
  }
@@ -1584,66 +1606,66 @@ class Pt {
1584
1606
  })).data;
1585
1607
  }
1586
1608
  }
1587
- const Ce = fe(null);
1588
- function Tr({ config: n = {}, children: e }) {
1589
- const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [p, w] = k([]), [y, f] = k(!1), [x, h] = k(null), [R, N] = k(!1), D = K(() => {
1590
- const u = new le(i);
1591
- return new Pt(u);
1592
- }, [i]), E = async () => {
1609
+ const Ce = ye(null);
1610
+ function Ar({ config: n = {}, children: e }) {
1611
+ const t = De(), r = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [c, m] = x([]), [y, f] = x(!1), [F, g] = x(null), [T, A] = x(!1), L = Z(() => {
1612
+ const d = new de(i);
1613
+ return new It(d);
1614
+ }, [i]), M = async () => {
1593
1615
  if (!(a != null && a.id)) {
1594
- w([]);
1616
+ m([]);
1595
1617
  return;
1596
1618
  }
1597
- f(!0), h(null);
1619
+ f(!0), g(null);
1598
1620
  try {
1599
- const u = await D.getTenantFeatureFlags(a.id, o);
1600
- w(u);
1601
- } catch (u) {
1602
- const S = u instanceof Error ? u.message : "Failed to fetch feature flags";
1603
- h(S), n.onError && n.onError(u instanceof Error ? u : new Error(S));
1621
+ const d = await L.getTenantFeatureFlags(a.id, o);
1622
+ m(d);
1623
+ } catch (d) {
1624
+ const v = d instanceof Error ? d.message : "Failed to fetch feature flags";
1625
+ g(v), n.onError && n.onError(d instanceof Error ? d : new Error(v));
1604
1626
  } finally {
1605
1627
  f(!1);
1606
1628
  }
1607
1629
  };
1608
- re(() => {
1630
+ ne(() => {
1609
1631
  if (!i || !o) return;
1610
- E().finally(() => N(!0));
1611
- const u = n.refreshInterval || 5 * 60 * 1e3, S = setInterval(E, u);
1612
- return () => clearInterval(S);
1632
+ M().finally(() => A(!0));
1633
+ const d = n.refreshInterval || 5 * 60 * 1e3, v = setInterval(M, d);
1634
+ return () => clearInterval(v);
1613
1635
  }, [a == null ? void 0 : a.id, i, o, n.refreshInterval]);
1614
- const P = K(() => {
1615
- const u = ($) => {
1616
- const l = p.find((U) => U.key === $);
1617
- return (l == null ? void 0 : l.value) === !0;
1618
- }, S = ($) => p.find((l) => l.key === $), C = ($) => {
1619
- const l = p.find((U) => U.key === $);
1620
- return l ? l.value ? "enabled" : "disabled" : "not_found";
1621
- }, M = async () => {
1622
- await E();
1623
- }, T = !!(i && o) && (R || !(a != null && a.id));
1636
+ const P = Z(() => {
1637
+ const d = (R) => {
1638
+ const k = c.find((I) => I.key === R);
1639
+ return (k == null ? void 0 : k.value) === !0;
1640
+ }, v = (R) => c.find((k) => k.key === R), N = (R) => {
1641
+ const k = c.find((I) => I.key === R);
1642
+ return k ? k.value ? "enabled" : "disabled" : "not_found";
1643
+ }, B = async () => {
1644
+ await M();
1645
+ }, w = !!(i && o) && (T || !(a != null && a.id));
1624
1646
  return {
1625
- featureFlags: p,
1647
+ featureFlags: c,
1626
1648
  loading: y,
1627
- error: x,
1628
- isReady: T,
1629
- isEnabled: u,
1630
- getFlag: S,
1631
- getFlagState: C,
1632
- refresh: M
1649
+ error: F,
1650
+ isReady: w,
1651
+ isEnabled: d,
1652
+ getFlag: v,
1653
+ getFlagState: N,
1654
+ refresh: B
1633
1655
  };
1634
- }, [p, y, x, i, o, a == null ? void 0 : a.id, R]);
1656
+ }, [c, y, F, i, o, a == null ? void 0 : a.id, T]);
1635
1657
  return /* @__PURE__ */ s(Ce.Provider, { value: P, children: e });
1636
1658
  }
1637
- function Rt() {
1638
- const n = ae(Ce);
1659
+ function Mt() {
1660
+ const n = le(Ce);
1639
1661
  if (!n)
1640
1662
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1641
1663
  return n;
1642
1664
  }
1643
- function Ke() {
1644
- return ae(Ce);
1665
+ function Ye() {
1666
+ return le(Ce);
1645
1667
  }
1646
- class Et {
1668
+ class Lt {
1647
1669
  constructor(e, t) {
1648
1670
  this.httpService = e, this.sessionManager = t;
1649
1671
  }
@@ -1709,68 +1731,68 @@ class Et {
1709
1731
  )).data;
1710
1732
  }
1711
1733
  }
1712
- const $e = fe(void 0);
1713
- function kr({ config: n = {}, children: e }) {
1714
- const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, p] = k(null), [w, y] = k(!1), [f, x] = k(null), [h, R] = k(!1), N = K(() => {
1715
- const P = new le(i);
1716
- return new Et(P);
1717
- }, [i]), D = async () => {
1734
+ const He = ye(void 0);
1735
+ function Pr({ config: n = {}, children: e }) {
1736
+ const t = De(), r = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, c] = x(null), [m, y] = x(!1), [f, F] = x(null), [g, T] = x(!1), A = Z(() => {
1737
+ const P = new de(i);
1738
+ return new Lt(P);
1739
+ }, [i]), L = async () => {
1718
1740
  if (!(o != null && o.id)) {
1719
- p(null);
1741
+ c(null);
1720
1742
  return;
1721
1743
  }
1722
- y(!0), x(null);
1744
+ y(!0), F(null);
1723
1745
  try {
1724
- const P = await N.getTenantSubscriptionFeatures(o.id);
1725
- p(P);
1746
+ const P = await A.getTenantSubscriptionFeatures(o.id);
1747
+ c(P);
1726
1748
  } catch (P) {
1727
- const u = P instanceof Error ? P.message : "Failed to fetch subscription";
1728
- x(u), n.onError && n.onError(P instanceof Error ? P : new Error(u));
1749
+ const d = P instanceof Error ? P.message : "Failed to fetch subscription";
1750
+ F(d), n.onError && n.onError(P instanceof Error ? P : new Error(d));
1729
1751
  } finally {
1730
1752
  y(!1);
1731
1753
  }
1732
1754
  };
1733
- re(() => {
1734
- if (!i || (D().finally(() => R(!0)), !n.refreshInterval)) return;
1735
- const P = n.refreshInterval || 10 * 60 * 1e3, u = setInterval(D, P);
1736
- return () => clearInterval(u);
1755
+ ne(() => {
1756
+ if (!i || (L().finally(() => T(!0)), !n.refreshInterval)) return;
1757
+ const P = n.refreshInterval || 10 * 60 * 1e3, d = setInterval(L, P);
1758
+ return () => clearInterval(d);
1737
1759
  }, [o == null ? void 0 : o.id, i, n.refreshInterval]);
1738
- const E = K(() => {
1739
- const P = (a == null ? void 0 : a.features) || [], u = (l) => {
1740
- const U = P.find((b) => b.key === l);
1741
- return U ? U.type === "BOOLEAN" || U.type === "boolean" ? U.value === !0 : !!U.value : !1;
1742
- }, S = (l) => P.find((U) => U.key === l), C = (l, U) => {
1743
- const b = P.find((L) => L.key === l);
1744
- return b ? b.value : U;
1745
- }, M = (l) => !a || !a.isActive ? !1 : l.includes(a.planId), T = async () => {
1746
- await D();
1747
- }, $ = !!i && (h || !(o != null && o.id));
1760
+ const M = Z(() => {
1761
+ const P = (a == null ? void 0 : a.features) || [], d = (k) => {
1762
+ const I = P.find((l) => l.key === k);
1763
+ return I ? I.type === "BOOLEAN" || I.type === "boolean" ? I.value === !0 : !!I.value : !1;
1764
+ }, v = (k) => P.find((I) => I.key === k), N = (k, I) => {
1765
+ const l = P.find((z) => z.key === k);
1766
+ return l ? l.value : I;
1767
+ }, B = (k) => !a || !a.isActive ? !1 : k.includes(a.planId), w = async () => {
1768
+ await L();
1769
+ }, R = !!i && (g || !(o != null && o.id));
1748
1770
  return {
1749
1771
  subscription: a,
1750
1772
  features: P,
1751
- loading: w,
1773
+ loading: m,
1752
1774
  error: f,
1753
- isReady: $,
1754
- isFeatureEnabled: u,
1755
- getFeature: S,
1756
- getFeatureValue: C,
1757
- hasAllowedPlan: M,
1758
- refresh: T
1775
+ isReady: R,
1776
+ isFeatureEnabled: d,
1777
+ getFeature: v,
1778
+ getFeatureValue: N,
1779
+ hasAllowedPlan: B,
1780
+ refresh: w
1759
1781
  };
1760
- }, [a, w, f, i, o == null ? void 0 : o.id, h]);
1761
- return /* @__PURE__ */ s($e.Provider, { value: E, children: e });
1782
+ }, [a, m, f, i, o == null ? void 0 : o.id, g]);
1783
+ return /* @__PURE__ */ s(He.Provider, { value: M, children: e });
1762
1784
  }
1763
- function It() {
1764
- const n = ae($e);
1785
+ function Nt() {
1786
+ const n = le(He);
1765
1787
  if (n === void 0)
1766
1788
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1767
1789
  return n;
1768
1790
  }
1769
- function Ze() {
1770
- return ae($e) ?? null;
1791
+ function Xe() {
1792
+ return le(He) ?? null;
1771
1793
  }
1772
- var oe = /* @__PURE__ */ ((n) => (n.SUPERUSER = "SUPERUSER", n.TENANT_ADMIN = "TENANT_ADMIN", n.USER = "USER", n))(oe || {});
1773
- const Ue = {
1794
+ var ae = /* @__PURE__ */ ((n) => (n.SUPERUSER = "SUPERUSER", n.TENANT_ADMIN = "TENANT_ADMIN", n.USER = "USER", n))(ae || {});
1795
+ const Oe = {
1774
1796
  publicGuest: "/",
1775
1797
  publicUser: "/account",
1776
1798
  publicAdmin: "/admin",
@@ -1778,7 +1800,7 @@ const Ue = {
1778
1800
  tenantUser: "/dashboard",
1779
1801
  tenantAdmin: "/admin/dashboard",
1780
1802
  default: "/"
1781
- }, Je = {
1803
+ }, et = {
1782
1804
  // Public/Landing zones
1783
1805
  landing: { tenant: "forbidden", auth: "optional" },
1784
1806
  publicOnly: { tenant: "forbidden", auth: "forbidden" },
@@ -1791,18 +1813,18 @@ const Ue = {
1791
1813
  tenantOpen: { tenant: "required", auth: "optional" },
1792
1814
  tenantAuth: { tenant: "required", auth: "required" },
1793
1815
  // User type zones
1794
- user: { tenant: "required", auth: "required", userType: oe.USER },
1795
- admin: { tenant: "required", auth: "required", userType: oe.TENANT_ADMIN },
1816
+ user: { tenant: "required", auth: "required", userType: ae.USER },
1817
+ admin: { tenant: "required", auth: "required", userType: ae.TENANT_ADMIN },
1796
1818
  // Fully open
1797
1819
  open: { tenant: "optional", auth: "optional" }
1798
- }, He = fe(null);
1799
- function xr({ config: n = {}, children: e }) {
1800
- const t = K(() => {
1820
+ }, qe = ye(null);
1821
+ function Rr({ config: n = {}, children: e }) {
1822
+ const t = Z(() => {
1801
1823
  const r = {
1802
- ...Ue,
1824
+ ...Oe,
1803
1825
  ...n.zoneRoots
1804
1826
  }, i = {
1805
- ...Je,
1827
+ ...et,
1806
1828
  ...n.presets
1807
1829
  };
1808
1830
  return {
@@ -1815,19 +1837,19 @@ function xr({ config: n = {}, children: e }) {
1815
1837
  returnToStorage: n.returnToStorage ?? "url"
1816
1838
  };
1817
1839
  }, [n]);
1818
- return /* @__PURE__ */ s(He.Provider, { value: t, children: e });
1840
+ return /* @__PURE__ */ s(qe.Provider, { value: t, children: e });
1819
1841
  }
1820
- function Ar() {
1821
- const n = ae(He);
1842
+ function Er() {
1843
+ const n = le(qe);
1822
1844
  if (!n)
1823
1845
  throw new Error("useRouting must be used within a RoutingProvider");
1824
1846
  return n;
1825
1847
  }
1826
- function Mt() {
1827
- const n = ae(He);
1848
+ function Ft() {
1849
+ const n = le(qe);
1828
1850
  return n || {
1829
- zoneRoots: Ue,
1830
- presets: Je,
1851
+ zoneRoots: Oe,
1852
+ presets: et,
1831
1853
  loadingFallback: null,
1832
1854
  accessDeniedFallback: null,
1833
1855
  onAccessDenied: void 0,
@@ -1835,7 +1857,7 @@ function Mt() {
1835
1857
  returnToStorage: "url"
1836
1858
  };
1837
1859
  }
1838
- const We = () => /* @__PURE__ */ d(
1860
+ const Ge = () => /* @__PURE__ */ u(
1839
1861
  "div",
1840
1862
  {
1841
1863
  style: {
@@ -1872,11 +1894,11 @@ const We = () => /* @__PURE__ */ d(
1872
1894
  )
1873
1895
  ]
1874
1896
  }
1875
- ), Ve = ({
1897
+ ), Ke = ({
1876
1898
  userType: n,
1877
1899
  minUserType: e,
1878
1900
  missingPermissions: t
1879
- }) => /* @__PURE__ */ d(
1901
+ }) => /* @__PURE__ */ u(
1880
1902
  "div",
1881
1903
  {
1882
1904
  style: {
@@ -1894,55 +1916,55 @@ const We = () => /* @__PURE__ */ d(
1894
1916
  children: [
1895
1917
  /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1896
1918
  /* @__PURE__ */ s("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1897
- e && n ? /* @__PURE__ */ d(_, { children: [
1898
- /* @__PURE__ */ d("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1919
+ e && n ? /* @__PURE__ */ u(_, { children: [
1920
+ /* @__PURE__ */ u("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1899
1921
  "This content requires ",
1900
1922
  /* @__PURE__ */ s("strong", { children: e }),
1901
1923
  " access level or higher."
1902
1924
  ] }),
1903
- /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1925
+ /* @__PURE__ */ u("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1904
1926
  "Your current access level: ",
1905
1927
  /* @__PURE__ */ s("strong", { children: n })
1906
1928
  ] })
1907
- ] }) : /* @__PURE__ */ d(_, { children: [
1929
+ ] }) : /* @__PURE__ */ u(_, { children: [
1908
1930
  /* @__PURE__ */ s("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1909
- t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1931
+ t && t.length > 0 && /* @__PURE__ */ u("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1910
1932
  "Required permissions: ",
1911
1933
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
1912
1934
  ] })
1913
1935
  ] })
1914
1936
  ]
1915
1937
  }
1916
- ), Lt = (n, e) => {
1938
+ ), Dt = (n, e) => {
1917
1939
  const t = {
1918
- [oe.USER]: 1,
1919
- [oe.TENANT_ADMIN]: 2,
1920
- [oe.SUPERUSER]: 3
1940
+ [ae.USER]: 1,
1941
+ [ae.TENANT_ADMIN]: 2,
1942
+ [ae.SUPERUSER]: 3
1921
1943
  };
1922
1944
  return t[n] >= t[e];
1923
1945
  };
1924
- function Pr({
1946
+ function Ir({
1925
1947
  children: n,
1926
1948
  fallback: e,
1927
1949
  minUserType: t,
1928
1950
  requiredPermissions: r,
1929
1951
  requireAllPermissions: i = !1
1930
1952
  }) {
1931
- const { hasValidSession: o, sessionManager: a, hasPermission: p, hasAnyPermission: w, hasAllPermissions: y } = ue();
1953
+ const { hasValidSession: o, sessionManager: a, hasPermission: c, hasAnyPermission: m, hasAllPermissions: y } = he();
1932
1954
  if (!o())
1933
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(We, {}) });
1955
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Ge, {}) });
1934
1956
  const f = a.getUser();
1935
1957
  if (!f)
1936
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(We, {}) });
1937
- if (t && !Lt(f.userType, t))
1938
- return /* @__PURE__ */ s(Ve, { userType: f.userType, minUserType: t });
1939
- if (r && r.length > 0 && !(i ? y(r) : w(r))) {
1940
- const h = r.filter((R) => !p(R)).map((R) => typeof R == "string" ? R : R.name);
1941
- return /* @__PURE__ */ s(Ve, { missingPermissions: h });
1958
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Ge, {}) });
1959
+ if (t && !Dt(f.userType, t))
1960
+ return /* @__PURE__ */ s(Ke, { userType: f.userType, minUserType: t });
1961
+ if (r && r.length > 0 && !(i ? y(r) : m(r))) {
1962
+ const g = r.filter((T) => !c(T)).map((T) => typeof T == "string" ? T : T.name);
1963
+ return /* @__PURE__ */ s(Ke, { missingPermissions: g });
1942
1964
  }
1943
1965
  return /* @__PURE__ */ s(_, { children: n });
1944
1966
  }
1945
- const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1967
+ const Ut = ({ redirectPath: n }) => /* @__PURE__ */ s(
1946
1968
  "div",
1947
1969
  {
1948
1970
  style: {
@@ -1955,7 +1977,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1955
1977
  backgroundColor: "#f9fafb",
1956
1978
  textAlign: "center"
1957
1979
  },
1958
- children: /* @__PURE__ */ d(
1980
+ children: /* @__PURE__ */ u(
1959
1981
  "div",
1960
1982
  {
1961
1983
  style: {
@@ -1969,7 +1991,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1969
1991
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1970
1992
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1971
1993
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1972
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1994
+ /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1973
1995
  "Redirecting to ",
1974
1996
  n,
1975
1997
  "..."
@@ -1978,7 +2000,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1978
2000
  }
1979
2001
  )
1980
2002
  }
1981
- ), je = ({
2003
+ ), Qe = ({
1982
2004
  userType: n,
1983
2005
  requiredUserType: e,
1984
2006
  missingPermissions: t
@@ -1995,7 +2017,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1995
2017
  backgroundColor: "#f9fafb",
1996
2018
  textAlign: "center"
1997
2019
  },
1998
- children: /* @__PURE__ */ d(
2020
+ children: /* @__PURE__ */ u(
1999
2021
  "div",
2000
2022
  {
2001
2023
  style: {
@@ -2008,19 +2030,19 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2008
2030
  children: [
2009
2031
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
2010
2032
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
2011
- e && n ? /* @__PURE__ */ d(_, { children: [
2012
- /* @__PURE__ */ d("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
2033
+ e && n ? /* @__PURE__ */ u(_, { children: [
2034
+ /* @__PURE__ */ u("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
2013
2035
  "This page requires ",
2014
2036
  /* @__PURE__ */ s("strong", { children: e }),
2015
2037
  " access."
2016
2038
  ] }),
2017
- /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2039
+ /* @__PURE__ */ u("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2018
2040
  "Your current user type: ",
2019
2041
  /* @__PURE__ */ s("strong", { children: n })
2020
2042
  ] })
2021
- ] }) : /* @__PURE__ */ d(_, { children: [
2043
+ ] }) : /* @__PURE__ */ u(_, { children: [
2022
2044
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
2023
- t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2045
+ t && t.length > 0 && /* @__PURE__ */ u("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2024
2046
  "Required permissions: ",
2025
2047
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
2026
2048
  ] })
@@ -2029,8 +2051,8 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2029
2051
  }
2030
2052
  )
2031
2053
  }
2032
- ), Dt = (n, e) => n === e;
2033
- function Rr({
2054
+ ), Bt = (n, e) => n === e;
2055
+ function Mr({
2034
2056
  children: n,
2035
2057
  redirectTo: e = "/login",
2036
2058
  requiredUserType: t,
@@ -2038,34 +2060,34 @@ function Rr({
2038
2060
  requireAllPermissions: i = !1,
2039
2061
  fallback: o
2040
2062
  }) {
2041
- const { hasValidSession: a, sessionManager: p, hasPermission: w, hasAnyPermission: y, hasAllPermissions: f } = ue(), x = ke();
2042
- if (re(() => {
2063
+ const { hasValidSession: a, sessionManager: c, hasPermission: m, hasAnyPermission: y, hasAllPermissions: f } = he(), F = xe();
2064
+ if (ne(() => {
2043
2065
  process.env.NODE_ENV === "development" && console.warn(
2044
2066
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
2045
2067
  );
2046
2068
  }, []), !a())
2047
- return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ d(_, { children: [
2048
- /* @__PURE__ */ s(Nt, { redirectPath: e }),
2049
- /* @__PURE__ */ s(ve, { to: e, state: { from: x.pathname }, replace: !0 })
2069
+ return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ u(_, { children: [
2070
+ /* @__PURE__ */ s(Ut, { redirectPath: e }),
2071
+ /* @__PURE__ */ s(Se, { to: e, state: { from: F.pathname }, replace: !0 })
2050
2072
  ] });
2051
- const h = p.getUser();
2052
- if (!h)
2053
- return /* @__PURE__ */ s(ve, { to: e, state: { from: x.pathname }, replace: !0 });
2054
- if (t && !Dt(h.userType, t))
2073
+ const g = c.getUser();
2074
+ if (!g)
2075
+ return /* @__PURE__ */ s(Se, { to: e, state: { from: F.pathname }, replace: !0 });
2076
+ if (t && !Bt(g.userType, t))
2055
2077
  return /* @__PURE__ */ s(
2056
- je,
2078
+ Qe,
2057
2079
  {
2058
- userType: h.userType,
2080
+ userType: g.userType,
2059
2081
  requiredUserType: t
2060
2082
  }
2061
2083
  );
2062
2084
  if (r && r.length > 0 && !(i ? f(r) : y(r))) {
2063
- const N = r.filter((D) => !w(D)).map((D) => typeof D == "string" ? D : D.name);
2064
- return /* @__PURE__ */ s(je, { missingPermissions: N });
2085
+ const A = r.filter((L) => !m(L)).map((L) => typeof L == "string" ? L : L.name);
2086
+ return /* @__PURE__ */ s(Qe, { missingPermissions: A });
2065
2087
  }
2066
2088
  return /* @__PURE__ */ s(_, { children: n });
2067
2089
  }
2068
- const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2090
+ const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
2069
2091
  "div",
2070
2092
  {
2071
2093
  style: {
@@ -2078,7 +2100,7 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2078
2100
  backgroundColor: "#f9fafb",
2079
2101
  textAlign: "center"
2080
2102
  },
2081
- children: /* @__PURE__ */ d(
2103
+ children: /* @__PURE__ */ u(
2082
2104
  "div",
2083
2105
  {
2084
2106
  style: {
@@ -2092,7 +2114,7 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2092
2114
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
2093
2115
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
2094
2116
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
2095
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2117
+ /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2096
2118
  "Redirecting to ",
2097
2119
  n,
2098
2120
  "..."
@@ -2102,15 +2124,15 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2102
2124
  )
2103
2125
  }
2104
2126
  );
2105
- function Er({ children: n, redirectTo: e = "/", fallback: t }) {
2106
- const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2107
- return re(() => {
2127
+ function Lr({ children: n, redirectTo: e = "/", fallback: t }) {
2128
+ const { tenant: r, isLoading: i, error: o } = Je(), a = xe();
2129
+ return ne(() => {
2108
2130
  process.env.NODE_ENV === "development" && console.warn(
2109
2131
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
2110
2132
  );
2111
- }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2112
- /* @__PURE__ */ s(Ft, { redirectPath: e }),
2113
- /* @__PURE__ */ s(ve, { to: e, state: { from: a.pathname }, replace: !0 })
2133
+ }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ u(_, { children: [
2134
+ /* @__PURE__ */ s($t, { redirectPath: e }),
2135
+ /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2114
2136
  ] });
2115
2137
  }
2116
2138
  const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
@@ -2126,7 +2148,7 @@ const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
2126
2148
  backgroundColor: "#f9fafb",
2127
2149
  textAlign: "center"
2128
2150
  },
2129
- children: /* @__PURE__ */ d(
2151
+ children: /* @__PURE__ */ u(
2130
2152
  "div",
2131
2153
  {
2132
2154
  style: {
@@ -2140,7 +2162,7 @@ const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
2140
2162
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
2141
2163
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
2142
2164
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
2143
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2165
+ /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2144
2166
  "Redirecting to ",
2145
2167
  n,
2146
2168
  "..."
@@ -2150,41 +2172,41 @@ const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
2150
2172
  )
2151
2173
  }
2152
2174
  );
2153
- function Ir({ children: n, redirectTo: e = "/dashboard", fallback: t }) {
2154
- const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2155
- return re(() => {
2175
+ function Nr({ children: n, redirectTo: e = "/dashboard", fallback: t }) {
2176
+ const { tenant: r, isLoading: i, error: o } = Je(), a = xe();
2177
+ return ne(() => {
2156
2178
  process.env.NODE_ENV === "development" && console.warn(
2157
2179
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
2158
2180
  );
2159
- }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2181
+ }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ u(_, { children: [
2160
2182
  /* @__PURE__ */ s(Ct, { redirectPath: e }),
2161
- /* @__PURE__ */ s(ve, { to: e, state: { from: a.pathname }, replace: !0 })
2183
+ /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2162
2184
  ] }) : /* @__PURE__ */ s(_, { children: n });
2163
2185
  }
2164
- function $t(n, e) {
2186
+ function Ht(n, e) {
2165
2187
  return e ? n ? Array.isArray(e) ? e.includes(n) : n === e : !1 : !0;
2166
2188
  }
2167
- function Ge(n, e) {
2189
+ function Ze(n, e) {
2168
2190
  return !n || n === "optional" ? "skip" : n === "required" ? e ? "pass" : "fail" : n === "forbidden" ? e ? "fail" : "pass" : "skip";
2169
2191
  }
2170
- function Ut(n, e) {
2171
- return Ge(n.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Ge(n.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : n.userType && e.isAuthenticated && !$t(e.userType, n.userType) ? "wrong_user_type" : n.permissions && n.permissions.length > 0 && !(n.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(n.permissions) ? "missing_permissions" : null;
2192
+ function Ot(n, e) {
2193
+ return Ze(n.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Ze(n.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : n.userType && e.isAuthenticated && !Ht(e.userType, n.userType) ? "wrong_user_type" : n.permissions && n.permissions.length > 0 && !(n.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(n.permissions) ? "missing_permissions" : null;
2172
2194
  }
2173
- function Ht(n, e) {
2174
- return n.hasTenant ? n.isAuthenticated ? n.userType === oe.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : n.isAuthenticated ? n.userType === oe.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
2195
+ function qt(n, e) {
2196
+ return n.hasTenant ? n.isAuthenticated ? n.userType === ae.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : n.isAuthenticated ? n.userType === ae.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
2175
2197
  }
2176
- function Bt(n, e, t, r, i) {
2198
+ function _t(n, e, t, r, i) {
2177
2199
  if (!e || i !== "url")
2178
2200
  return n;
2179
2201
  const o = typeof e == "string" ? e : t, a = n.includes("?") ? "&" : "?";
2180
2202
  return `${n}${a}${r}=${encodeURIComponent(o)}`;
2181
2203
  }
2182
- function Ot(n, e, t) {
2204
+ function zt(n, e, t) {
2183
2205
  if (!n || t === "url") return;
2184
2206
  const r = typeof n == "string" ? n : e, i = "zone_return_to";
2185
2207
  t === "session" ? sessionStorage.setItem(i, r) : t === "local" && localStorage.setItem(i, r);
2186
2208
  }
2187
- const ce = ({
2209
+ const ue = ({
2188
2210
  children: n,
2189
2211
  preset: e,
2190
2212
  tenant: t,
@@ -2192,83 +2214,83 @@ const ce = ({
2192
2214
  userType: i,
2193
2215
  requiredPermissions: o,
2194
2216
  requireAllPermissions: a = !0,
2195
- returnTo: p,
2196
- onAccessDenied: w,
2217
+ returnTo: c,
2218
+ onAccessDenied: m,
2197
2219
  redirectTo: y,
2198
2220
  loadingFallback: f,
2199
- accessDeniedFallback: x
2221
+ accessDeniedFallback: F
2200
2222
  }) => {
2201
- const h = ke(), { isAuthenticated: R, isAuthInitializing: N, currentUser: D, userPermissions: E } = ue(), { tenant: P, isTenantLoading: u } = ge(), S = Mt(), C = K(() => {
2223
+ const g = xe(), { isAuthenticated: T, isAuthInitializing: A, currentUser: L, userPermissions: M } = he(), { tenant: P, isTenantLoading: d } = Te(), v = Ft(), N = Z(() => {
2202
2224
  if (e)
2203
- return S.presets[e];
2204
- }, [e, S.presets]), M = K(
2225
+ return v.presets[e];
2226
+ }, [e, v.presets]), B = Z(
2205
2227
  () => ({
2206
- tenant: t ?? (C == null ? void 0 : C.tenant),
2207
- auth: r ?? (C == null ? void 0 : C.auth),
2208
- userType: i ?? (C == null ? void 0 : C.userType),
2209
- permissions: o ?? (C == null ? void 0 : C.requiredPermissions),
2228
+ tenant: t ?? (N == null ? void 0 : N.tenant),
2229
+ auth: r ?? (N == null ? void 0 : N.auth),
2230
+ userType: i ?? (N == null ? void 0 : N.userType),
2231
+ permissions: o ?? (N == null ? void 0 : N.requiredPermissions),
2210
2232
  requireAllPermissions: a
2211
2233
  }),
2212
- [t, r, i, o, C, a]
2213
- ), T = K(
2234
+ [t, r, i, o, N, a]
2235
+ ), w = Z(
2214
2236
  () => ({
2215
2237
  hasTenant: !!P,
2216
- isAuthenticated: R,
2217
- userType: D == null ? void 0 : D.userType,
2218
- permissions: E,
2219
- isLoading: N || u
2238
+ isAuthenticated: T,
2239
+ userType: L == null ? void 0 : L.userType,
2240
+ permissions: M,
2241
+ isLoading: A || d
2220
2242
  }),
2221
2243
  [
2222
2244
  P,
2223
- R,
2224
- D == null ? void 0 : D.userType,
2225
- E,
2226
- N,
2227
- u
2245
+ T,
2246
+ L == null ? void 0 : L.userType,
2247
+ M,
2248
+ A,
2249
+ d
2228
2250
  ]
2229
- ), $ = K(() => T.isLoading ? null : Ut(M, T), [M, T]), l = K(() => $ ? y || Ht(T, S.zoneRoots) : null, [$, y, T, S.zoneRoots]), U = K(() => !$ || !l ? null : {
2230
- type: $,
2251
+ ), R = Z(() => w.isLoading ? null : Ot(B, w), [B, w]), k = Z(() => R ? y || qt(w, v.zoneRoots) : null, [R, y, w, v.zoneRoots]), I = Z(() => !R || !k ? null : {
2252
+ type: R,
2231
2253
  required: {
2232
- tenant: M.tenant,
2233
- auth: M.auth,
2234
- userType: M.userType,
2235
- permissions: M.permissions
2254
+ tenant: B.tenant,
2255
+ auth: B.auth,
2256
+ userType: B.userType,
2257
+ permissions: B.permissions
2236
2258
  },
2237
2259
  current: {
2238
- hasTenant: T.hasTenant,
2239
- isAuthenticated: T.isAuthenticated,
2240
- userType: T.userType,
2241
- permissions: T.permissions
2260
+ hasTenant: w.hasTenant,
2261
+ isAuthenticated: w.isAuthenticated,
2262
+ userType: w.userType,
2263
+ permissions: w.permissions
2242
2264
  },
2243
- redirectTo: l
2244
- }, [$, l, M, T]);
2245
- if (re(() => {
2246
- U && (w ? w(U) : S.onAccessDenied && S.onAccessDenied(U));
2247
- }, [U, w, S]), re(() => {
2248
- U && p && Ot(p, h.pathname + h.search, S.returnToStorage);
2265
+ redirectTo: k
2266
+ }, [R, k, B, w]);
2267
+ if (ne(() => {
2268
+ I && (m ? m(I) : v.onAccessDenied && v.onAccessDenied(I));
2269
+ }, [I, m, v]), ne(() => {
2270
+ I && c && zt(c, g.pathname + g.search, v.returnToStorage);
2249
2271
  }, [
2250
- U,
2251
- p,
2252
- h.pathname,
2253
- h.search,
2254
- S.returnToStorage
2255
- ]), T.isLoading)
2256
- return /* @__PURE__ */ s(_, { children: f ?? S.loadingFallback ?? null });
2257
- if (U && l) {
2258
- const b = x ?? S.accessDeniedFallback;
2259
- if (b)
2260
- return /* @__PURE__ */ s(_, { children: b });
2261
- const L = Bt(
2262
- l,
2263
- p,
2264
- h.pathname + h.search,
2265
- S.returnToParam,
2266
- S.returnToStorage
2272
+ I,
2273
+ c,
2274
+ g.pathname,
2275
+ g.search,
2276
+ v.returnToStorage
2277
+ ]), w.isLoading)
2278
+ return /* @__PURE__ */ s(_, { children: f ?? v.loadingFallback ?? null });
2279
+ if (I && k) {
2280
+ const l = F ?? v.accessDeniedFallback;
2281
+ if (l)
2282
+ return /* @__PURE__ */ s(_, { children: l });
2283
+ const z = _t(
2284
+ k,
2285
+ c,
2286
+ g.pathname + g.search,
2287
+ v.returnToParam,
2288
+ v.returnToStorage
2267
2289
  );
2268
- return /* @__PURE__ */ s(ve, { to: L, replace: !0 });
2290
+ return /* @__PURE__ */ s(Se, { to: z, replace: !0 });
2269
2291
  }
2270
2292
  return /* @__PURE__ */ s(_, { children: n });
2271
- }, Mr = (n) => /* @__PURE__ */ s(ce, { tenant: "required", ...n }), Lr = (n) => /* @__PURE__ */ s(ce, { tenant: "forbidden", ...n }), Nr = (n) => /* @__PURE__ */ s(ce, { auth: "required", ...n }), Dr = (n) => /* @__PURE__ */ s(ce, { auth: "forbidden", ...n }), Fr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.TENANT_ADMIN, ...n }), Cr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.USER, ...n }), $r = (n) => /* @__PURE__ */ s(ce, { tenant: "optional", auth: "optional", ...n }), Ur = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "required", ...n }), Hr = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "optional", ...n }), Br = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "forbidden", ...n }), qt = () => /* @__PURE__ */ d(
2293
+ }, Fr = (n) => /* @__PURE__ */ s(ue, { tenant: "required", ...n }), Dr = (n) => /* @__PURE__ */ s(ue, { tenant: "forbidden", ...n }), Ur = (n) => /* @__PURE__ */ s(ue, { auth: "required", ...n }), Br = (n) => /* @__PURE__ */ s(ue, { auth: "forbidden", ...n }), $r = (n) => /* @__PURE__ */ s(ue, { auth: "required", userType: ae.TENANT_ADMIN, ...n }), Cr = (n) => /* @__PURE__ */ s(ue, { auth: "required", userType: ae.USER, ...n }), Hr = (n) => /* @__PURE__ */ s(ue, { tenant: "optional", auth: "optional", ...n }), Or = (n) => /* @__PURE__ */ s(ue, { tenant: "required", auth: "required", ...n }), qr = (n) => /* @__PURE__ */ s(ue, { tenant: "required", auth: "optional", ...n }), _r = (n) => /* @__PURE__ */ s(ue, { tenant: "required", auth: "forbidden", ...n }), Vt = () => /* @__PURE__ */ u(
2272
2294
  "div",
2273
2295
  {
2274
2296
  style: {
@@ -2285,14 +2307,14 @@ const ce = ({
2285
2307
  ]
2286
2308
  }
2287
2309
  );
2288
- function Or({
2310
+ function zr({
2289
2311
  children: n,
2290
- fallback: e = /* @__PURE__ */ s(qt, {}),
2312
+ fallback: e = /* @__PURE__ */ s(Vt, {}),
2291
2313
  allowedPlans: t,
2292
2314
  requiredFeature: r
2293
2315
  }) {
2294
- const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: p } = It();
2295
- return p ? /* @__PURE__ */ s(
2316
+ const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: c } = Nt();
2317
+ return c ? /* @__PURE__ */ s(
2296
2318
  "div",
2297
2319
  {
2298
2320
  style: {
@@ -2304,7 +2326,7 @@ function Or({
2304
2326
  }
2305
2327
  ) : i ? i.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ s(_, { children: e }) : r && !a(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: n }) : /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: e });
2306
2328
  }
2307
- const zt = ({ flagName: n }) => /* @__PURE__ */ d(
2329
+ const Wt = ({ flagName: n }) => /* @__PURE__ */ u(
2308
2330
  "div",
2309
2331
  {
2310
2332
  style: {
@@ -2323,7 +2345,7 @@ const zt = ({ flagName: n }) => /* @__PURE__ */ d(
2323
2345
  children: [
2324
2346
  /* @__PURE__ */ s("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
2325
2347
  /* @__PURE__ */ s("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
2326
- /* @__PURE__ */ d("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2348
+ /* @__PURE__ */ u("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2327
2349
  'Feature flag "',
2328
2350
  n,
2329
2351
  '" is disabled'
@@ -2331,8 +2353,8 @@ const zt = ({ flagName: n }) => /* @__PURE__ */ d(
2331
2353
  ]
2332
2354
  }
2333
2355
  );
2334
- function qr({ name: n, children: e, fallback: t }) {
2335
- const { isEnabled: r, loading: i } = Rt();
2356
+ function Vr({ name: n, children: e, fallback: t }) {
2357
+ const { isEnabled: r, loading: i } = Mt();
2336
2358
  return i ? /* @__PURE__ */ s(
2337
2359
  "div",
2338
2360
  {
@@ -2346,9 +2368,9 @@ function qr({ name: n, children: e, fallback: t }) {
2346
2368
  },
2347
2369
  children: "Loading feature flags..."
2348
2370
  }
2349
- ) : r(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(zt, { flagName: n }) });
2371
+ ) : r(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(Wt, { flagName: n }) });
2350
2372
  }
2351
- const _t = () => /* @__PURE__ */ d(
2373
+ const jt = () => /* @__PURE__ */ u(
2352
2374
  "svg",
2353
2375
  {
2354
2376
  width: "16",
@@ -2365,7 +2387,7 @@ const _t = () => /* @__PURE__ */ d(
2365
2387
  /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "3" })
2366
2388
  ]
2367
2389
  }
2368
- ), Wt = () => /* @__PURE__ */ d(
2390
+ ), Gt = () => /* @__PURE__ */ u(
2369
2391
  "svg",
2370
2392
  {
2371
2393
  width: "16",
@@ -2382,10 +2404,10 @@ const _t = () => /* @__PURE__ */ d(
2382
2404
  /* @__PURE__ */ s("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2383
2405
  ]
2384
2406
  }
2385
- ), Vt = {
2386
- showPassword: /* @__PURE__ */ s(_t, {}),
2387
- hidePassword: /* @__PURE__ */ s(Wt, {})
2388
- }, jt = {
2407
+ ), Kt = {
2408
+ showPassword: /* @__PURE__ */ s(jt, {}),
2409
+ hidePassword: /* @__PURE__ */ s(Gt, {})
2410
+ }, Qt = {
2389
2411
  title: "Sign In",
2390
2412
  usernameLabel: "Email or Phone",
2391
2413
  usernamePlaceholder: "Enter your email or phone number",
@@ -2403,7 +2425,7 @@ const _t = () => /* @__PURE__ */ d(
2403
2425
  dividerBullet: "•",
2404
2426
  showPasswordAriaLabel: "Show password",
2405
2427
  hidePasswordAriaLabel: "Hide password"
2406
- }, Gt = {
2428
+ }, Zt = {
2407
2429
  container: {
2408
2430
  maxWidth: "400px",
2409
2431
  width: "100%",
@@ -2513,7 +2535,7 @@ const _t = () => /* @__PURE__ */ d(
2513
2535
  paddingRight: "2.5rem"
2514
2536
  }
2515
2537
  };
2516
- function zr({
2538
+ function Wr({
2517
2539
  copy: n = {},
2518
2540
  styles: e = {},
2519
2541
  icons: t = {},
@@ -2521,124 +2543,120 @@ function zr({
2521
2543
  onError: i,
2522
2544
  onForgotPassword: o,
2523
2545
  onSignupClick: a,
2524
- onMagicLinkClick: p,
2525
- showForgotPassword: w = !0,
2546
+ onMagicLinkClick: c,
2547
+ showForgotPassword: m = !0,
2526
2548
  showSignupLink: y = !0,
2527
2549
  showMagicLinkOption: f = !0,
2528
- className: x
2550
+ className: F
2529
2551
  }) {
2530
- const [h, R] = k(""), [N, D] = k(""), [E, P] = k(!1), [u, S] = k(!1), [C, M] = k(""), [T, $] = k({}), { login: l } = ue(), { tenant: U } = me(), b = { ...jt, ...n }, L = { ...Gt, ...e }, F = { ...Vt, ...t }, c = () => {
2531
- const m = {};
2532
- return h.trim() || (m.username = !0), N.trim() || (m.password = !0), $(m), Object.keys(m).length === 0;
2533
- }, H = async (m) => {
2534
- if (m.preventDefault(), !!c()) {
2535
- if (!(U != null && U.id)) {
2536
- M(b.tenantNotFoundError);
2537
- return;
2538
- }
2539
- S(!0), M("");
2552
+ const [g, T] = x(""), [A, L] = x(""), [M, P] = x(!1), [d, v] = x(!1), [N, B] = x(""), [w, R] = x({}), { login: k } = he(), I = { ...Qt, ...n }, l = { ...Zt, ...e }, z = { ...Kt, ...t }, D = () => {
2553
+ const h = {};
2554
+ return g.trim() || (h.username = !0), A.trim() || (h.password = !0), R(h), Object.keys(h).length === 0;
2555
+ }, p = async (h) => {
2556
+ if (h.preventDefault(), !!D()) {
2557
+ v(!0), B("");
2540
2558
  try {
2541
- const v = await l({
2542
- username: h,
2543
- password: N
2559
+ const S = await k({
2560
+ username: g,
2561
+ password: A
2544
2562
  // tenantId inferred from context automatically
2545
2563
  });
2546
- r == null || r(v);
2547
- } catch (v) {
2548
- const Q = v.message || b.errorMessage;
2549
- M(Q), i == null || i(Q);
2564
+ r == null || r(S);
2565
+ } catch (S) {
2566
+ const E = S.message || I.errorMessage;
2567
+ B(E), i == null || i(E);
2550
2568
  } finally {
2551
- S(!1);
2569
+ v(!1);
2552
2570
  }
2553
2571
  }
2554
- }, I = (m) => ({
2555
- ...L.input,
2556
- ...T[m] ? L.inputError : {}
2557
- }), g = () => ({
2558
- ...L.button,
2559
- ...u ? L.buttonLoading : {},
2560
- ...!h || !N || u ? L.buttonDisabled : {}
2572
+ }, U = (h) => ({
2573
+ ...l.input,
2574
+ ...w[h] ? l.inputError : {}
2575
+ }), b = () => ({
2576
+ ...l.button,
2577
+ ...d ? l.buttonLoading : {},
2578
+ ...!g || !A || d ? l.buttonDisabled : {}
2561
2579
  });
2562
- return /* @__PURE__ */ d("div", { className: x, style: L.container, children: [
2563
- /* @__PURE__ */ s("h2", { style: L.title, children: b.title }),
2564
- /* @__PURE__ */ d("form", { onSubmit: H, style: L.form, children: [
2565
- /* @__PURE__ */ d("div", { style: L.fieldGroup, children: [
2566
- /* @__PURE__ */ s("label", { style: L.label, children: b.usernameLabel }),
2580
+ return /* @__PURE__ */ u("div", { className: F, style: l.container, children: [
2581
+ /* @__PURE__ */ s("h2", { style: l.title, children: I.title }),
2582
+ /* @__PURE__ */ u("form", { onSubmit: p, style: l.form, children: [
2583
+ /* @__PURE__ */ u("div", { style: l.fieldGroup, children: [
2584
+ /* @__PURE__ */ s("label", { style: l.label, children: I.usernameLabel }),
2567
2585
  /* @__PURE__ */ s(
2568
2586
  "input",
2569
2587
  {
2570
2588
  id: "username",
2571
2589
  name: "username",
2572
2590
  type: "text",
2573
- value: h,
2574
- onChange: (m) => {
2575
- R(m.target.value), T.username && $((v) => ({ ...v, username: !1 }));
2591
+ value: g,
2592
+ onChange: (h) => {
2593
+ T(h.target.value), w.username && R((S) => ({ ...S, username: !1 }));
2576
2594
  },
2577
- placeholder: b.usernamePlaceholder,
2578
- style: I("username"),
2579
- disabled: u
2595
+ placeholder: I.usernamePlaceholder,
2596
+ style: U("username"),
2597
+ disabled: d
2580
2598
  }
2581
2599
  )
2582
2600
  ] }),
2583
- /* @__PURE__ */ d("div", { style: L.fieldGroup, children: [
2584
- /* @__PURE__ */ s("label", { style: L.label, children: b.passwordLabel }),
2585
- /* @__PURE__ */ d("div", { style: L.inputContainer, children: [
2601
+ /* @__PURE__ */ u("div", { style: l.fieldGroup, children: [
2602
+ /* @__PURE__ */ s("label", { style: l.label, children: I.passwordLabel }),
2603
+ /* @__PURE__ */ u("div", { style: l.inputContainer, children: [
2586
2604
  /* @__PURE__ */ s(
2587
2605
  "input",
2588
2606
  {
2589
2607
  id: "password",
2590
2608
  name: "password",
2591
- type: E ? "text" : "password",
2592
- value: N,
2593
- onChange: (m) => {
2594
- D(m.target.value), T.password && $((v) => ({ ...v, password: !1 }));
2609
+ type: M ? "text" : "password",
2610
+ value: A,
2611
+ onChange: (h) => {
2612
+ L(h.target.value), w.password && R((S) => ({ ...S, password: !1 }));
2595
2613
  },
2596
- placeholder: b.passwordPlaceholder,
2614
+ placeholder: I.passwordPlaceholder,
2597
2615
  style: {
2598
- ...I("password"),
2599
- ...L.inputWithIcon
2616
+ ...U("password"),
2617
+ ...l.inputWithIcon
2600
2618
  },
2601
- disabled: u
2619
+ disabled: d
2602
2620
  }
2603
2621
  ),
2604
2622
  /* @__PURE__ */ s(
2605
2623
  "button",
2606
2624
  {
2607
2625
  type: "button",
2608
- onClick: () => P(!E),
2609
- style: L.passwordToggle,
2610
- disabled: u,
2611
- "aria-label": E ? b.hidePasswordAriaLabel : b.showPasswordAriaLabel,
2612
- children: E ? F.hidePassword : F.showPassword
2626
+ onClick: () => P(!M),
2627
+ style: l.passwordToggle,
2628
+ disabled: d,
2629
+ "aria-label": M ? I.hidePasswordAriaLabel : I.showPasswordAriaLabel,
2630
+ children: M ? z.hidePassword : z.showPassword
2613
2631
  }
2614
2632
  )
2615
2633
  ] })
2616
2634
  ] }),
2617
- /* @__PURE__ */ s("button", { type: "submit", disabled: !h || !N || u, style: g(), children: u ? b.loadingText : b.submitButton }),
2618
- C && /* @__PURE__ */ s("div", { style: L.errorText, children: C })
2635
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !g || !A || d, style: b(), children: d ? I.loadingText : I.submitButton }),
2636
+ N && /* @__PURE__ */ s("div", { style: l.errorText, children: N })
2619
2637
  ] }),
2620
- (w || y || f) && /* @__PURE__ */ d("div", { style: L.linkContainer, children: [
2621
- f && /* @__PURE__ */ d("div", { children: [
2622
- /* @__PURE__ */ d("span", { style: L.divider, children: [
2623
- b.magicLinkText,
2638
+ (m || y || f) && /* @__PURE__ */ u("div", { style: l.linkContainer, children: [
2639
+ f && /* @__PURE__ */ u("div", { children: [
2640
+ /* @__PURE__ */ u("span", { style: l.divider, children: [
2641
+ I.magicLinkText,
2624
2642
  " "
2625
2643
  ] }),
2626
- /* @__PURE__ */ s("a", { onClick: p, style: L.link, children: b.magicLinkLink })
2644
+ /* @__PURE__ */ s("a", { onClick: c, style: l.link, children: I.magicLinkLink })
2627
2645
  ] }),
2628
- f && (w || y) && /* @__PURE__ */ s("div", { style: L.divider, children: b.dividerBullet }),
2629
- w && /* @__PURE__ */ s("a", { onClick: o, style: L.link, children: b.forgotPasswordLink }),
2630
- w && y && /* @__PURE__ */ s("div", { style: L.divider, children: b.dividerBullet }),
2631
- y && /* @__PURE__ */ d("div", { children: [
2632
- /* @__PURE__ */ d("span", { style: L.divider, children: [
2633
- b.signupText,
2646
+ f && (m || y) && /* @__PURE__ */ s("div", { style: l.divider, children: I.dividerBullet }),
2647
+ m && /* @__PURE__ */ s("a", { onClick: o, style: l.link, children: I.forgotPasswordLink }),
2648
+ m && y && /* @__PURE__ */ s("div", { style: l.divider, children: I.dividerBullet }),
2649
+ y && /* @__PURE__ */ u("div", { children: [
2650
+ /* @__PURE__ */ u("span", { style: l.divider, children: [
2651
+ I.signupText,
2634
2652
  " "
2635
2653
  ] }),
2636
- /* @__PURE__ */ s("a", { onClick: a, style: L.link, children: b.signupLink })
2654
+ /* @__PURE__ */ s("a", { onClick: a, style: l.link, children: I.signupLink })
2637
2655
  ] })
2638
2656
  ] })
2639
2657
  ] });
2640
2658
  }
2641
- const Qt = {
2659
+ const Jt = {
2642
2660
  title: "Create Account",
2643
2661
  nameLabel: "First Name",
2644
2662
  namePlaceholder: "Enter your first name",
@@ -2667,7 +2685,7 @@ const Qt = {
2667
2685
  contactMethodHint: "At least one contact method (email or phone) is required",
2668
2686
  tenantNotFoundError: "Tenant not found",
2669
2687
  dividerBullet: "•"
2670
- }, Kt = {
2688
+ }, Yt = {
2671
2689
  container: {
2672
2690
  maxWidth: "400px",
2673
2691
  width: "100%",
@@ -2772,7 +2790,7 @@ const Qt = {
2772
2790
  margin: "0.5rem 0"
2773
2791
  }
2774
2792
  };
2775
- function _r({
2793
+ function jr({
2776
2794
  copy: n = {},
2777
2795
  styles: e = {},
2778
2796
  signupType: t = "user",
@@ -2780,61 +2798,62 @@ function _r({
2780
2798
  onError: i,
2781
2799
  onLoginClick: o,
2782
2800
  onMagicLinkClick: a,
2783
- showLoginLink: p = !0,
2784
- showMagicLinkOption: w = !0,
2801
+ showLoginLink: c = !0,
2802
+ showMagicLinkOption: m = !0,
2785
2803
  className: y
2786
2804
  }) {
2787
- const [f, x] = k(""), [h, R] = k(""), [N, D] = k(""), [E, P] = k(""), [u, S] = k(""), [C, M] = k(""), [T, $] = k(""), [l, U] = k(!1), [b, L] = k(""), [F, c] = k({}), { signup: H, signupTenantAdmin: I } = ue(), { tenant: g } = me(), m = { ...Qt, ...n }, v = { ...Kt, ...e }, Q = () => {
2788
- const A = {};
2789
- return f.trim() || (A.name = !0), !N.trim() && !E.trim() && (A.email = !0, A.phoneNumber = !0), u.trim() || (A.password = !0), C.trim() || (A.confirmPassword = !0), t === "tenant" && !T.trim() && (A.tenantName = !0), c(A), Object.keys(A).length === 0;
2790
- }, J = async (A) => {
2791
- if (A.preventDefault(), !!Q()) {
2792
- if (u !== C) {
2793
- L(m.passwordMismatchError), c({ confirmPassword: !0 });
2805
+ var V;
2806
+ const [f, F] = x(""), [g, T] = x(""), [A, L] = x(""), [M, P] = x(""), [d, v] = x(""), [N, B] = x(""), [w, R] = x(""), [k, I] = x(!1), [l, z] = x(""), [D, p] = x({}), { signup: U, signupTenantAdmin: b } = he(), h = ((V = pe()) == null ? void 0 : V.tenant) ?? null, S = { ...Jt, ...n }, E = { ...Yt, ...e }, K = () => {
2807
+ const H = {};
2808
+ return f.trim() || (H.name = !0), !A.trim() && !M.trim() && (H.email = !0, H.phoneNumber = !0), d.trim() || (H.password = !0), N.trim() || (H.confirmPassword = !0), t === "tenant" && !w.trim() && (H.tenantName = !0), p(H), Object.keys(H).length === 0;
2809
+ }, G = async (H) => {
2810
+ if (H.preventDefault(), !!K()) {
2811
+ if (d !== N) {
2812
+ z(S.passwordMismatchError), p({ confirmPassword: !0 });
2794
2813
  return;
2795
2814
  }
2796
- if (t === "user" && !(g != null && g.id)) {
2797
- L(m.tenantNotFoundError);
2815
+ if (t === "user" && !(h != null && h.id)) {
2816
+ z(S.tenantNotFoundError);
2798
2817
  return;
2799
2818
  }
2800
- U(!0), L("");
2819
+ I(!0), z("");
2801
2820
  try {
2802
- let V;
2803
- t === "tenant" ? V = await I({
2804
- email: N || void 0,
2805
- phoneNumber: E || void 0,
2821
+ let $;
2822
+ t === "tenant" ? $ = await b({
2823
+ email: A || void 0,
2824
+ phoneNumber: M || void 0,
2806
2825
  name: f,
2807
- password: u,
2808
- tenantName: T,
2809
- lastName: h || void 0
2810
- }) : V = await H({
2811
- email: N || void 0,
2812
- phoneNumber: E || void 0,
2826
+ password: d,
2827
+ tenantName: w,
2828
+ lastName: g || void 0
2829
+ }) : $ = await U({
2830
+ email: A || void 0,
2831
+ phoneNumber: M || void 0,
2813
2832
  name: f,
2814
- password: u,
2815
- tenantId: g.id,
2816
- lastName: h || void 0
2817
- }), r == null || r(V);
2818
- } catch (V) {
2819
- const de = V.message || m.errorMessage;
2820
- L(de), i == null || i(de);
2833
+ password: d,
2834
+ tenantId: h.id,
2835
+ lastName: g || void 0
2836
+ }), r == null || r($);
2837
+ } catch ($) {
2838
+ const ce = $.message || S.errorMessage;
2839
+ z(ce), i == null || i(ce);
2821
2840
  } finally {
2822
- U(!1);
2841
+ I(!1);
2823
2842
  }
2824
2843
  }
2825
- }, O = (A) => ({
2826
- ...v.input,
2827
- ...F[A] ? v.inputError : {}
2828
- }), q = () => ({
2829
- ...v.button,
2830
- ...l ? v.buttonLoading : {},
2831
- ...!f || !N && !E || !u || !C || l || t === "tenant" && !T ? v.buttonDisabled : {}
2832
- }), j = f && (N || E) && u && C && (t === "user" || T);
2833
- return /* @__PURE__ */ d("div", { className: y, style: v.container, children: [
2834
- /* @__PURE__ */ s("h2", { style: v.title, children: m.title }),
2835
- /* @__PURE__ */ d("form", { onSubmit: J, style: v.form, children: [
2836
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2837
- /* @__PURE__ */ s("label", { style: v.label, children: m.nameLabel }),
2844
+ }, X = (H) => ({
2845
+ ...E.input,
2846
+ ...D[H] ? E.inputError : {}
2847
+ }), W = () => ({
2848
+ ...E.button,
2849
+ ...k ? E.buttonLoading : {},
2850
+ ...!f || !A && !M || !d || !N || k || t === "tenant" && !w ? E.buttonDisabled : {}
2851
+ }), q = f && (A || M) && d && N && (t === "user" || w);
2852
+ return /* @__PURE__ */ u("div", { className: y, style: E.container, children: [
2853
+ /* @__PURE__ */ s("h2", { style: E.title, children: S.title }),
2854
+ /* @__PURE__ */ u("form", { onSubmit: G, style: E.form, children: [
2855
+ /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2856
+ /* @__PURE__ */ s("label", { style: E.label, children: S.nameLabel }),
2838
2857
  /* @__PURE__ */ s(
2839
2858
  "input",
2840
2859
  {
@@ -2842,145 +2861,145 @@ function _r({
2842
2861
  name: "name",
2843
2862
  type: "text",
2844
2863
  value: f,
2845
- onChange: (A) => {
2846
- x(A.target.value), F.name && c((V) => ({ ...V, name: !1 }));
2864
+ onChange: (H) => {
2865
+ F(H.target.value), D.name && p(($) => ({ ...$, name: !1 }));
2847
2866
  },
2848
- placeholder: m.namePlaceholder,
2849
- style: O("name"),
2850
- disabled: l
2867
+ placeholder: S.namePlaceholder,
2868
+ style: X("name"),
2869
+ disabled: k
2851
2870
  }
2852
2871
  )
2853
2872
  ] }),
2854
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2855
- /* @__PURE__ */ s("label", { style: v.label, children: m.lastNameLabel }),
2873
+ /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2874
+ /* @__PURE__ */ s("label", { style: E.label, children: S.lastNameLabel }),
2856
2875
  /* @__PURE__ */ s(
2857
2876
  "input",
2858
2877
  {
2859
2878
  id: "lastName",
2860
2879
  name: "lastName",
2861
2880
  type: "text",
2862
- value: h,
2863
- onChange: (A) => R(A.target.value),
2864
- placeholder: m.lastNamePlaceholder,
2865
- style: v.input,
2866
- disabled: l
2881
+ value: g,
2882
+ onChange: (H) => T(H.target.value),
2883
+ placeholder: S.lastNamePlaceholder,
2884
+ style: E.input,
2885
+ disabled: k
2867
2886
  }
2868
2887
  )
2869
2888
  ] }),
2870
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2871
- /* @__PURE__ */ s("label", { style: v.label, children: m.emailLabel }),
2889
+ /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2890
+ /* @__PURE__ */ s("label", { style: E.label, children: S.emailLabel }),
2872
2891
  /* @__PURE__ */ s(
2873
2892
  "input",
2874
2893
  {
2875
2894
  id: "email",
2876
2895
  name: "email",
2877
2896
  type: "email",
2878
- value: N,
2879
- onChange: (A) => {
2880
- D(A.target.value), F.email && c((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2897
+ value: A,
2898
+ onChange: (H) => {
2899
+ L(H.target.value), D.email && p(($) => ({ ...$, email: !1, phoneNumber: !1 }));
2881
2900
  },
2882
- placeholder: m.emailPlaceholder,
2883
- style: O("email"),
2884
- disabled: l
2901
+ placeholder: S.emailPlaceholder,
2902
+ style: X("email"),
2903
+ disabled: k
2885
2904
  }
2886
2905
  )
2887
2906
  ] }),
2888
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2889
- /* @__PURE__ */ s("label", { style: v.label, children: m.phoneNumberLabel }),
2907
+ /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2908
+ /* @__PURE__ */ s("label", { style: E.label, children: S.phoneNumberLabel }),
2890
2909
  /* @__PURE__ */ s(
2891
2910
  "input",
2892
2911
  {
2893
2912
  id: "phoneNumber",
2894
2913
  name: "phoneNumber",
2895
2914
  type: "tel",
2896
- value: E,
2897
- onChange: (A) => {
2898
- P(A.target.value), F.phoneNumber && c((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2915
+ value: M,
2916
+ onChange: (H) => {
2917
+ P(H.target.value), D.phoneNumber && p(($) => ({ ...$, email: !1, phoneNumber: !1 }));
2899
2918
  },
2900
- placeholder: m.phoneNumberPlaceholder,
2901
- style: O("phoneNumber"),
2902
- disabled: l
2919
+ placeholder: S.phoneNumberPlaceholder,
2920
+ style: X("phoneNumber"),
2921
+ disabled: k
2903
2922
  }
2904
2923
  )
2905
2924
  ] }),
2906
- /* @__PURE__ */ s("div", { style: v.hintText, children: m.contactMethodHint }),
2907
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2908
- /* @__PURE__ */ s("label", { style: v.label, children: m.passwordLabel }),
2925
+ /* @__PURE__ */ s("div", { style: E.hintText, children: S.contactMethodHint }),
2926
+ /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2927
+ /* @__PURE__ */ s("label", { style: E.label, children: S.passwordLabel }),
2909
2928
  /* @__PURE__ */ s(
2910
2929
  "input",
2911
2930
  {
2912
2931
  id: "password",
2913
2932
  name: "password",
2914
2933
  type: "password",
2915
- value: u,
2916
- onChange: (A) => {
2917
- S(A.target.value), F.password && c((V) => ({ ...V, password: !1 }));
2934
+ value: d,
2935
+ onChange: (H) => {
2936
+ v(H.target.value), D.password && p(($) => ({ ...$, password: !1 }));
2918
2937
  },
2919
- placeholder: m.passwordPlaceholder,
2920
- style: O("password"),
2921
- disabled: l
2938
+ placeholder: S.passwordPlaceholder,
2939
+ style: X("password"),
2940
+ disabled: k
2922
2941
  }
2923
2942
  )
2924
2943
  ] }),
2925
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2926
- /* @__PURE__ */ s("label", { style: v.label, children: m.confirmPasswordLabel }),
2944
+ /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2945
+ /* @__PURE__ */ s("label", { style: E.label, children: S.confirmPasswordLabel }),
2927
2946
  /* @__PURE__ */ s(
2928
2947
  "input",
2929
2948
  {
2930
2949
  id: "confirmPassword",
2931
2950
  name: "confirmPassword",
2932
2951
  type: "password",
2933
- value: C,
2934
- onChange: (A) => {
2935
- M(A.target.value), F.confirmPassword && c((V) => ({ ...V, confirmPassword: !1 })), b === m.passwordMismatchError && L("");
2952
+ value: N,
2953
+ onChange: (H) => {
2954
+ B(H.target.value), D.confirmPassword && p(($) => ({ ...$, confirmPassword: !1 })), l === S.passwordMismatchError && z("");
2936
2955
  },
2937
- placeholder: m.confirmPasswordPlaceholder,
2938
- style: O("confirmPassword"),
2939
- disabled: l
2956
+ placeholder: S.confirmPasswordPlaceholder,
2957
+ style: X("confirmPassword"),
2958
+ disabled: k
2940
2959
  }
2941
2960
  )
2942
2961
  ] }),
2943
- t === "tenant" && /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2944
- /* @__PURE__ */ s("label", { style: v.label, children: m.tenantNameLabel }),
2962
+ t === "tenant" && /* @__PURE__ */ u("div", { style: E.fieldGroup, children: [
2963
+ /* @__PURE__ */ s("label", { style: E.label, children: S.tenantNameLabel }),
2945
2964
  /* @__PURE__ */ s(
2946
2965
  "input",
2947
2966
  {
2948
2967
  id: "tenantName",
2949
2968
  name: "tenantName",
2950
2969
  type: "text",
2951
- value: T,
2952
- onChange: (A) => {
2953
- $(A.target.value), F.tenantName && c((V) => ({ ...V, tenantName: !1 }));
2970
+ value: w,
2971
+ onChange: (H) => {
2972
+ R(H.target.value), D.tenantName && p(($) => ({ ...$, tenantName: !1 }));
2954
2973
  },
2955
- placeholder: m.tenantNamePlaceholder,
2956
- style: O("tenantName"),
2957
- disabled: l
2974
+ placeholder: S.tenantNamePlaceholder,
2975
+ style: X("tenantName"),
2976
+ disabled: k
2958
2977
  }
2959
2978
  )
2960
2979
  ] }),
2961
- /* @__PURE__ */ s("button", { type: "submit", disabled: !j || l, style: q(), children: l ? m.loadingText : m.submitButton }),
2962
- b && /* @__PURE__ */ s("div", { style: v.errorText, children: b })
2980
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !q || k, style: W(), children: k ? S.loadingText : S.submitButton }),
2981
+ l && /* @__PURE__ */ s("div", { style: E.errorText, children: l })
2963
2982
  ] }),
2964
- (p || w) && /* @__PURE__ */ d("div", { style: v.linkContainer, children: [
2965
- w && /* @__PURE__ */ d("div", { children: [
2966
- /* @__PURE__ */ d("span", { style: v.divider, children: [
2967
- m.magicLinkText,
2983
+ (c || m) && /* @__PURE__ */ u("div", { style: E.linkContainer, children: [
2984
+ m && /* @__PURE__ */ u("div", { children: [
2985
+ /* @__PURE__ */ u("span", { style: E.divider, children: [
2986
+ S.magicLinkText,
2968
2987
  " "
2969
2988
  ] }),
2970
- /* @__PURE__ */ s("a", { onClick: a, style: v.link, children: m.magicLinkLink })
2989
+ /* @__PURE__ */ s("a", { onClick: a, style: E.link, children: S.magicLinkLink })
2971
2990
  ] }),
2972
- w && p && /* @__PURE__ */ s("div", { style: v.divider, children: m.dividerBullet }),
2973
- p && /* @__PURE__ */ d("div", { children: [
2974
- /* @__PURE__ */ d("span", { style: v.divider, children: [
2975
- m.loginText,
2991
+ m && c && /* @__PURE__ */ s("div", { style: E.divider, children: S.dividerBullet }),
2992
+ c && /* @__PURE__ */ u("div", { children: [
2993
+ /* @__PURE__ */ u("span", { style: E.divider, children: [
2994
+ S.loginText,
2976
2995
  " "
2977
2996
  ] }),
2978
- /* @__PURE__ */ s("a", { onClick: o, style: v.link, children: m.loginLink })
2997
+ /* @__PURE__ */ s("a", { onClick: o, style: E.link, children: S.loginLink })
2979
2998
  ] })
2980
2999
  ] })
2981
3000
  ] });
2982
3001
  }
2983
- const Zt = {
3002
+ const Xt = {
2984
3003
  title: "Sign In with Magic Link",
2985
3004
  emailLabel: "Email",
2986
3005
  emailPlaceholder: "Enter your email",
@@ -3004,7 +3023,7 @@ const Zt = {
3004
3023
  tenantNotFoundError: "Tenant not found",
3005
3024
  missingTenantOrEmailError: "Missing tenant or email",
3006
3025
  dividerBullet: "•"
3007
- }, Jt = {
3026
+ }, er = {
3008
3027
  container: {
3009
3028
  maxWidth: "400px",
3010
3029
  width: "100%",
@@ -3127,7 +3146,7 @@ const Zt = {
3127
3146
  textDecoration: "underline"
3128
3147
  }
3129
3148
  };
3130
- function Wr({
3149
+ function Gr({
3131
3150
  copy: n = {},
3132
3151
  styles: e = {},
3133
3152
  onSuccess: t,
@@ -3135,76 +3154,77 @@ function Wr({
3135
3154
  onLoginClick: i,
3136
3155
  onSignupClick: o,
3137
3156
  showTraditionalLinks: a = !0,
3138
- className: p,
3139
- verifyToken: w,
3157
+ className: c,
3158
+ verifyToken: m,
3140
3159
  frontendUrl: y
3141
3160
  }) {
3142
- const [f, x] = k(""), [h, R] = k(""), [N, D] = k(""), [E, P] = k(!1), [u, S] = k(!1), [C, M] = k(""), [T, $] = k(""), [l, U] = k({}), [b, L] = k(!1), { sendMagicLink: F, verifyMagicLink: c } = ue(), { tenant: H } = me(), I = { ...Zt, ...n }, g = { ...Jt, ...e };
3143
- re(() => {
3144
- w && m(w);
3145
- }, [w]);
3146
- const m = async (q) => {
3147
- if (!H || !f) {
3148
- M(I.missingTenantOrEmailError);
3161
+ var W;
3162
+ const [f, F] = x(""), [g, T] = x(""), [A, L] = x(""), [M, P] = x(!1), [d, v] = x(!1), [N, B] = x(""), [w, R] = x(""), [k, I] = x({}), [l, z] = x(!1), { sendMagicLink: D, verifyMagicLink: p } = he(), U = ((W = pe()) == null ? void 0 : W.tenant) ?? null, b = { ...Xt, ...n }, h = { ...er, ...e };
3163
+ ne(() => {
3164
+ m && S(m);
3165
+ }, [m]);
3166
+ const S = async (q) => {
3167
+ if (!U || !f) {
3168
+ B(b.missingTenantOrEmailError);
3149
3169
  return;
3150
3170
  }
3151
- S(!0), M("");
3171
+ v(!0), B("");
3152
3172
  try {
3153
- const j = await c({
3173
+ const V = await p({
3154
3174
  token: q,
3155
3175
  email: f
3156
3176
  // tenantId inferred from context automatically
3157
3177
  });
3158
- t == null || t(j);
3159
- } catch (j) {
3160
- const A = j.message || "Failed to verify magic link";
3161
- M(A), r == null || r(A);
3178
+ t == null || t(V);
3179
+ } catch (V) {
3180
+ const H = V.message || "Failed to verify magic link";
3181
+ B(H), r == null || r(H);
3162
3182
  } finally {
3163
- S(!1);
3183
+ v(!1);
3164
3184
  }
3165
- }, v = () => {
3185
+ }, E = () => {
3166
3186
  const q = {};
3167
- return f.trim() || (q.email = !0), b && !h.trim() && (q.name = !0), U(q), Object.keys(q).length === 0;
3168
- }, Q = async (q) => {
3169
- if (q.preventDefault(), !!v()) {
3170
- if (!(H != null && H.id)) {
3171
- M(I.tenantNotFoundError);
3187
+ return f.trim() || (q.email = !0), l && !g.trim() && (q.name = !0), I(q), Object.keys(q).length === 0;
3188
+ }, K = async (q) => {
3189
+ if (q.preventDefault(), !!E()) {
3190
+ if (!(U != null && U.id)) {
3191
+ B(b.tenantNotFoundError);
3172
3192
  return;
3173
3193
  }
3174
- P(!0), M(""), $("");
3194
+ P(!0), B(""), R("");
3175
3195
  try {
3176
- const j = y || (typeof window < "u" ? window.location.origin : ""), A = await F({
3196
+ const V = y || (typeof window < "u" ? window.location.origin : ""), H = await D({
3177
3197
  email: f,
3178
- tenantId: H.id,
3179
- frontendUrl: j,
3180
- name: b ? h : void 0,
3181
- lastName: b ? N : void 0
3198
+ tenantId: U.id,
3199
+ frontendUrl: V,
3200
+ name: l ? g : void 0,
3201
+ lastName: l ? A : void 0
3182
3202
  });
3183
- $(I.successMessage), t == null || t(A);
3184
- } catch (j) {
3185
- const A = j.message || I.errorMessage;
3186
- M(A), r == null || r(A);
3203
+ R(b.successMessage), t == null || t(H);
3204
+ } catch (V) {
3205
+ const H = V.message || b.errorMessage;
3206
+ B(H), r == null || r(H);
3187
3207
  } finally {
3188
3208
  P(!1);
3189
3209
  }
3190
3210
  }
3191
- }, J = (q) => ({
3192
- ...g.input,
3193
- ...l[q] ? g.inputError : {}
3194
- }), O = () => ({
3195
- ...g.button,
3196
- ...E || u ? g.buttonLoading : {},
3197
- ...!f || E || u ? g.buttonDisabled : {}
3211
+ }, G = (q) => ({
3212
+ ...h.input,
3213
+ ...k[q] ? h.inputError : {}
3214
+ }), X = () => ({
3215
+ ...h.button,
3216
+ ...M || d ? h.buttonLoading : {},
3217
+ ...!f || M || d ? h.buttonDisabled : {}
3198
3218
  });
3199
- return u ? /* @__PURE__ */ d("div", { className: p, style: g.container, children: [
3200
- /* @__PURE__ */ s("h2", { style: g.title, children: I.verifyingText }),
3201
- /* @__PURE__ */ s("div", { style: g.verifyingContainer, children: /* @__PURE__ */ s("div", { style: g.verifyingText, children: I.verifyingDescription }) })
3202
- ] }) : /* @__PURE__ */ d("div", { className: p, style: g.container, children: [
3203
- /* @__PURE__ */ s("h2", { style: g.title, children: I.title }),
3204
- /* @__PURE__ */ s("p", { style: g.description, children: I.description }),
3205
- /* @__PURE__ */ d("form", { onSubmit: Q, style: g.form, children: [
3206
- /* @__PURE__ */ d("div", { style: g.fieldGroup, children: [
3207
- /* @__PURE__ */ s("label", { style: g.label, children: I.emailLabel }),
3219
+ return d ? /* @__PURE__ */ u("div", { className: c, style: h.container, children: [
3220
+ /* @__PURE__ */ s("h2", { style: h.title, children: b.verifyingText }),
3221
+ /* @__PURE__ */ s("div", { style: h.verifyingContainer, children: /* @__PURE__ */ s("div", { style: h.verifyingText, children: b.verifyingDescription }) })
3222
+ ] }) : /* @__PURE__ */ u("div", { className: c, style: h.container, children: [
3223
+ /* @__PURE__ */ s("h2", { style: h.title, children: b.title }),
3224
+ /* @__PURE__ */ s("p", { style: h.description, children: b.description }),
3225
+ /* @__PURE__ */ u("form", { onSubmit: K, style: h.form, children: [
3226
+ /* @__PURE__ */ u("div", { style: h.fieldGroup, children: [
3227
+ /* @__PURE__ */ s("label", { style: h.label, children: b.emailLabel }),
3208
3228
  /* @__PURE__ */ s(
3209
3229
  "input",
3210
3230
  {
@@ -3213,94 +3233,94 @@ function Wr({
3213
3233
  type: "email",
3214
3234
  value: f,
3215
3235
  onChange: (q) => {
3216
- x(q.target.value), l.email && U((j) => ({ ...j, email: !1 }));
3236
+ F(q.target.value), k.email && I((V) => ({ ...V, email: !1 }));
3217
3237
  },
3218
- placeholder: I.emailPlaceholder,
3219
- style: J("email"),
3220
- disabled: E || u
3238
+ placeholder: b.emailPlaceholder,
3239
+ style: G("email"),
3240
+ disabled: M || d
3221
3241
  }
3222
3242
  )
3223
3243
  ] }),
3224
- !b && /* @__PURE__ */ s("div", { style: g.toggleContainer, children: /* @__PURE__ */ s(
3244
+ !l && /* @__PURE__ */ s("div", { style: h.toggleContainer, children: /* @__PURE__ */ s(
3225
3245
  "button",
3226
3246
  {
3227
3247
  type: "button",
3228
- onClick: () => L(!0),
3229
- style: g.toggleLink,
3230
- children: I.showNameToggle
3248
+ onClick: () => z(!0),
3249
+ style: h.toggleLink,
3250
+ children: b.showNameToggle
3231
3251
  }
3232
3252
  ) }),
3233
- b && /* @__PURE__ */ d(_, { children: [
3234
- /* @__PURE__ */ d("div", { style: g.fieldGroup, children: [
3235
- /* @__PURE__ */ s("label", { style: g.label, children: I.nameLabel }),
3253
+ l && /* @__PURE__ */ u(_, { children: [
3254
+ /* @__PURE__ */ u("div", { style: h.fieldGroup, children: [
3255
+ /* @__PURE__ */ s("label", { style: h.label, children: b.nameLabel }),
3236
3256
  /* @__PURE__ */ s(
3237
3257
  "input",
3238
3258
  {
3239
3259
  id: "name",
3240
3260
  name: "name",
3241
3261
  type: "text",
3242
- value: h,
3262
+ value: g,
3243
3263
  onChange: (q) => {
3244
- R(q.target.value), l.name && U((j) => ({ ...j, name: !1 }));
3264
+ T(q.target.value), k.name && I((V) => ({ ...V, name: !1 }));
3245
3265
  },
3246
- placeholder: I.namePlaceholder,
3247
- style: J("name"),
3248
- disabled: E || u
3266
+ placeholder: b.namePlaceholder,
3267
+ style: G("name"),
3268
+ disabled: M || d
3249
3269
  }
3250
3270
  )
3251
3271
  ] }),
3252
- /* @__PURE__ */ d("div", { style: g.fieldGroup, children: [
3253
- /* @__PURE__ */ s("label", { style: g.label, children: I.lastNameLabel }),
3272
+ /* @__PURE__ */ u("div", { style: h.fieldGroup, children: [
3273
+ /* @__PURE__ */ s("label", { style: h.label, children: b.lastNameLabel }),
3254
3274
  /* @__PURE__ */ s(
3255
3275
  "input",
3256
3276
  {
3257
3277
  id: "lastName",
3258
3278
  name: "lastName",
3259
3279
  type: "text",
3260
- value: N,
3261
- onChange: (q) => D(q.target.value),
3262
- placeholder: I.lastNamePlaceholder,
3263
- style: g.input,
3264
- disabled: E || u
3280
+ value: A,
3281
+ onChange: (q) => L(q.target.value),
3282
+ placeholder: b.lastNamePlaceholder,
3283
+ style: h.input,
3284
+ disabled: M || d
3265
3285
  }
3266
3286
  )
3267
3287
  ] }),
3268
- /* @__PURE__ */ s("div", { style: g.toggleContainer, children: /* @__PURE__ */ s(
3288
+ /* @__PURE__ */ s("div", { style: h.toggleContainer, children: /* @__PURE__ */ s(
3269
3289
  "button",
3270
3290
  {
3271
3291
  type: "button",
3272
3292
  onClick: () => {
3273
- L(!1), R(""), D("");
3293
+ z(!1), T(""), L("");
3274
3294
  },
3275
- style: g.toggleLink,
3276
- children: I.hideNameToggle
3295
+ style: h.toggleLink,
3296
+ children: b.hideNameToggle
3277
3297
  }
3278
3298
  ) })
3279
3299
  ] }),
3280
- /* @__PURE__ */ s("button", { type: "submit", disabled: !f || E || u, style: O(), children: E ? I.loadingText : I.submitButton }),
3281
- C && /* @__PURE__ */ s("div", { style: g.errorText, children: C }),
3282
- T && /* @__PURE__ */ s("div", { style: g.successText, children: T })
3300
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !f || M || d, style: X(), children: M ? b.loadingText : b.submitButton }),
3301
+ N && /* @__PURE__ */ s("div", { style: h.errorText, children: N }),
3302
+ w && /* @__PURE__ */ s("div", { style: h.successText, children: w })
3283
3303
  ] }),
3284
- a && /* @__PURE__ */ d("div", { style: g.linkContainer, children: [
3285
- /* @__PURE__ */ d("div", { children: [
3286
- /* @__PURE__ */ d("span", { style: g.divider, children: [
3287
- I.loginText,
3304
+ a && /* @__PURE__ */ u("div", { style: h.linkContainer, children: [
3305
+ /* @__PURE__ */ u("div", { children: [
3306
+ /* @__PURE__ */ u("span", { style: h.divider, children: [
3307
+ b.loginText,
3288
3308
  " "
3289
3309
  ] }),
3290
- /* @__PURE__ */ s("a", { onClick: i, style: g.link, children: I.loginLink })
3310
+ /* @__PURE__ */ s("a", { onClick: i, style: h.link, children: b.loginLink })
3291
3311
  ] }),
3292
- /* @__PURE__ */ s("div", { style: g.divider, children: I.dividerBullet }),
3293
- /* @__PURE__ */ d("div", { children: [
3294
- /* @__PURE__ */ d("span", { style: g.divider, children: [
3295
- I.signupText,
3312
+ /* @__PURE__ */ s("div", { style: h.divider, children: b.dividerBullet }),
3313
+ /* @__PURE__ */ u("div", { children: [
3314
+ /* @__PURE__ */ u("span", { style: h.divider, children: [
3315
+ b.signupText,
3296
3316
  " "
3297
3317
  ] }),
3298
- /* @__PURE__ */ s("a", { onClick: o, style: g.link, children: I.signupLink })
3318
+ /* @__PURE__ */ s("a", { onClick: o, style: h.link, children: b.signupLink })
3299
3319
  ] })
3300
3320
  ] })
3301
3321
  ] });
3302
3322
  }
3303
- const Yt = {
3323
+ const tr = {
3304
3324
  title: "Verifying Magic Link",
3305
3325
  verifyingMessage: "Please wait while we verify your magic link...",
3306
3326
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -3309,7 +3329,7 @@ const Yt = {
3309
3329
  retryButton: "Try Again",
3310
3330
  backToLoginButton: "Back to Login",
3311
3331
  missingParamsError: "Missing required parameters: token or email"
3312
- }, Ye = {
3332
+ }, tt = {
3313
3333
  container: {
3314
3334
  maxWidth: "400px",
3315
3335
  width: "100%",
@@ -3402,7 +3422,7 @@ const Yt = {
3402
3422
  backButtonHover: {
3403
3423
  backgroundColor: "#e5e7eb"
3404
3424
  }
3405
- }, Xt = () => /* @__PURE__ */ s("div", { style: Ye.spinner }), er = () => /* @__PURE__ */ d(
3425
+ }, rr = () => /* @__PURE__ */ s("div", { style: tt.spinner }), nr = () => /* @__PURE__ */ u(
3406
3426
  "svg",
3407
3427
  {
3408
3428
  width: "48",
@@ -3419,7 +3439,7 @@ const Yt = {
3419
3439
  /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3420
3440
  ]
3421
3441
  }
3422
- ), tr = () => /* @__PURE__ */ d(
3442
+ ), sr = () => /* @__PURE__ */ u(
3423
3443
  "svg",
3424
3444
  {
3425
3445
  width: "48",
@@ -3437,12 +3457,12 @@ const Yt = {
3437
3457
  /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3438
3458
  ]
3439
3459
  }
3440
- ), rr = {
3441
- loading: /* @__PURE__ */ s(Xt, {}),
3442
- success: /* @__PURE__ */ s(er, {}),
3443
- error: /* @__PURE__ */ s(tr, {})
3460
+ ), ir = {
3461
+ loading: /* @__PURE__ */ s(rr, {}),
3462
+ success: /* @__PURE__ */ s(nr, {}),
3463
+ error: /* @__PURE__ */ s(sr, {})
3444
3464
  };
3445
- function Vr({
3465
+ function Kr({
3446
3466
  copy: n = {},
3447
3467
  styles: e = {},
3448
3468
  icons: t = {},
@@ -3450,102 +3470,102 @@ function Vr({
3450
3470
  onError: i,
3451
3471
  onRetry: o,
3452
3472
  onBackToLogin: a,
3453
- className: p,
3454
- token: w,
3473
+ className: c,
3474
+ token: m,
3455
3475
  email: y,
3456
3476
  appId: f,
3457
- tenantSlug: x,
3458
- autoRedirectDelay: h = 3e3
3477
+ tenantSlug: F,
3478
+ autoRedirectDelay: g = 3e3
3459
3479
  }) {
3460
- const [R, N] = k("verifying"), [D, E] = k(""), { verifyMagicLink: P } = ue(), u = { ...Yt, ...n }, S = { ...Ye, ...e }, C = { ...rr, ...t }, M = () => {
3480
+ const [T, A] = x("verifying"), [L, M] = x(""), { verifyMagicLink: P } = he(), d = { ...tr, ...n }, v = { ...tt, ...e }, N = { ...ir, ...t }, B = () => {
3461
3481
  if (typeof window > "u") return {};
3462
- const b = new URLSearchParams(window.location.search);
3482
+ const l = new URLSearchParams(window.location.search);
3463
3483
  return {
3464
- token: w || b.get("token") || "",
3465
- email: y || b.get("email") || "",
3466
- appId: f || b.get("appId") || "",
3467
- tenantSlug: x || b.get("tenantSlug") || void 0
3484
+ token: m || l.get("token") || "",
3485
+ email: y || l.get("email") || "",
3486
+ appId: f || l.get("appId") || "",
3487
+ tenantSlug: F || l.get("tenantSlug") || void 0
3468
3488
  };
3469
- }, T = async () => {
3470
- N("verifying"), E("");
3489
+ }, w = async () => {
3490
+ A("verifying"), M("");
3471
3491
  try {
3472
- const b = M();
3473
- if (!b.token || !b.email)
3474
- throw new Error(u.missingParamsError);
3475
- const L = await P({
3476
- token: b.token,
3477
- email: b.email,
3478
- tenantSlug: b.tenantSlug
3492
+ const l = B();
3493
+ if (!l.token || !l.email)
3494
+ throw new Error(d.missingParamsError);
3495
+ const z = await P({
3496
+ token: l.token,
3497
+ email: l.email,
3498
+ tenantSlug: l.tenantSlug
3479
3499
  });
3480
- N("success"), r == null || r(L), h > 0 && setTimeout(() => {
3481
- N("redirecting");
3482
- }, h);
3483
- } catch (b) {
3484
- const L = b.message || u.errorMessage;
3485
- E(L), N("error"), i == null || i(L);
3500
+ A("success"), r == null || r(z), g > 0 && setTimeout(() => {
3501
+ A("redirecting");
3502
+ }, g);
3503
+ } catch (l) {
3504
+ const z = l.message || d.errorMessage;
3505
+ M(z), A("error"), i == null || i(z);
3486
3506
  }
3487
- }, $ = () => {
3488
- o == null || o(), T();
3489
- }, l = () => {
3507
+ }, R = () => {
3508
+ o == null || o(), w();
3509
+ }, k = () => {
3490
3510
  a == null || a();
3491
3511
  };
3492
- re(() => {
3493
- T();
3512
+ ne(() => {
3513
+ w();
3494
3514
  }, []);
3495
- const U = () => {
3496
- switch (R) {
3515
+ const I = () => {
3516
+ switch (T) {
3497
3517
  case "verifying":
3498
- return /* @__PURE__ */ d("div", { style: S.message, children: [
3499
- C.loading,
3500
- u.verifyingMessage
3518
+ return /* @__PURE__ */ u("div", { style: v.message, children: [
3519
+ N.loading,
3520
+ d.verifyingMessage
3501
3521
  ] });
3502
3522
  case "success":
3503
- return /* @__PURE__ */ d(_, { children: [
3504
- C.success,
3505
- /* @__PURE__ */ s("div", { style: S.successMessage, children: u.successMessage })
3523
+ return /* @__PURE__ */ u(_, { children: [
3524
+ N.success,
3525
+ /* @__PURE__ */ s("div", { style: v.successMessage, children: d.successMessage })
3506
3526
  ] });
3507
3527
  case "redirecting":
3508
- return /* @__PURE__ */ d(_, { children: [
3509
- C.loading,
3510
- /* @__PURE__ */ s("div", { style: S.message, children: u.redirectingMessage })
3528
+ return /* @__PURE__ */ u(_, { children: [
3529
+ N.loading,
3530
+ /* @__PURE__ */ s("div", { style: v.message, children: d.redirectingMessage })
3511
3531
  ] });
3512
3532
  case "error":
3513
- return /* @__PURE__ */ d(_, { children: [
3514
- C.error,
3515
- /* @__PURE__ */ s("div", { style: S.errorMessage, children: D || u.errorMessage }),
3516
- /* @__PURE__ */ d("div", { style: S.buttonContainer, children: [
3533
+ return /* @__PURE__ */ u(_, { children: [
3534
+ N.error,
3535
+ /* @__PURE__ */ s("div", { style: v.errorMessage, children: L || d.errorMessage }),
3536
+ /* @__PURE__ */ u("div", { style: v.buttonContainer, children: [
3517
3537
  /* @__PURE__ */ s(
3518
3538
  "button",
3519
3539
  {
3520
- onClick: $,
3521
- style: S.retryButton,
3522
- onMouseOver: (b) => {
3523
- Object.assign(b.currentTarget.style, S.retryButtonHover);
3540
+ onClick: R,
3541
+ style: v.retryButton,
3542
+ onMouseOver: (l) => {
3543
+ Object.assign(l.currentTarget.style, v.retryButtonHover);
3524
3544
  },
3525
- onMouseOut: (b) => {
3526
- const L = S.retryButton || {};
3527
- Object.keys(S.retryButtonHover || {}).forEach((F) => {
3528
- b.currentTarget.style[F] = L[F] ?? "";
3545
+ onMouseOut: (l) => {
3546
+ const z = v.retryButton || {};
3547
+ Object.keys(v.retryButtonHover || {}).forEach((D) => {
3548
+ l.currentTarget.style[D] = z[D] ?? "";
3529
3549
  });
3530
3550
  },
3531
- children: u.retryButton
3551
+ children: d.retryButton
3532
3552
  }
3533
3553
  ),
3534
3554
  /* @__PURE__ */ s(
3535
3555
  "button",
3536
3556
  {
3537
- onClick: l,
3538
- style: S.backButton,
3539
- onMouseOver: (b) => {
3540
- Object.assign(b.currentTarget.style, S.backButtonHover);
3557
+ onClick: k,
3558
+ style: v.backButton,
3559
+ onMouseOver: (l) => {
3560
+ Object.assign(l.currentTarget.style, v.backButtonHover);
3541
3561
  },
3542
- onMouseOut: (b) => {
3543
- const L = S.backButton || {};
3544
- Object.keys(S.backButtonHover || {}).forEach((F) => {
3545
- b.currentTarget.style[F] = L[F] ?? "";
3562
+ onMouseOut: (l) => {
3563
+ const z = v.backButton || {};
3564
+ Object.keys(v.backButtonHover || {}).forEach((D) => {
3565
+ l.currentTarget.style[D] = z[D] ?? "";
3546
3566
  });
3547
3567
  },
3548
- children: u.backToLoginButton
3568
+ children: d.backToLoginButton
3549
3569
  }
3550
3570
  )
3551
3571
  ] })
@@ -3554,18 +3574,18 @@ function Vr({
3554
3574
  return null;
3555
3575
  }
3556
3576
  };
3557
- return /* @__PURE__ */ d("div", { style: S.container, className: p, children: [
3577
+ return /* @__PURE__ */ u("div", { style: v.container, className: c, children: [
3558
3578
  /* @__PURE__ */ s("style", { children: `
3559
3579
  @keyframes spin {
3560
3580
  0% { transform: rotate(0deg); }
3561
3581
  100% { transform: rotate(360deg); }
3562
3582
  }
3563
3583
  ` }),
3564
- /* @__PURE__ */ s("h1", { style: S.title, children: u.title }),
3565
- U()
3584
+ /* @__PURE__ */ s("h1", { style: v.title, children: d.title }),
3585
+ I()
3566
3586
  ] });
3567
3587
  }
3568
- const nr = {
3588
+ const or = {
3569
3589
  title: "Reset Password",
3570
3590
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3571
3591
  emailLabel: "Email",
@@ -3591,7 +3611,7 @@ const nr = {
3591
3611
  haveTokenLink: "I have a token",
3592
3612
  tenantNotFoundError: "Tenant not found",
3593
3613
  dividerBullet: "•"
3594
- }, sr = {
3614
+ }, ar = {
3595
3615
  container: {
3596
3616
  maxWidth: "400px",
3597
3617
  margin: "0 auto",
@@ -3687,7 +3707,7 @@ const nr = {
3687
3707
  color: "#6b7280"
3688
3708
  }
3689
3709
  };
3690
- function jr({
3710
+ function Qr({
3691
3711
  copy: n = {},
3692
3712
  styles: e = {},
3693
3713
  mode: t = "request",
@@ -3695,104 +3715,105 @@ function jr({
3695
3715
  onSuccess: i,
3696
3716
  onError: o,
3697
3717
  onBackToLogin: a,
3698
- onModeChange: p,
3699
- className: w
3718
+ onModeChange: c,
3719
+ className: m
3700
3720
  }) {
3701
- const [y, f] = k(""), [x, h] = k(r), [R, N] = k(""), [D, E] = k(""), [P, u] = k(!1), [S, C] = k(""), [M, T] = k(""), [$, l] = k({}), { requestPasswordReset: U, confirmPasswordReset: b } = ue(), { tenant: L } = me(), F = { ...nr, ...n }, c = { ...sr, ...e }, H = () => {
3702
- const O = {};
3703
- return y.trim() || (O.email = !0), l(O), Object.keys(O).length === 0;
3704
- }, I = () => {
3705
- const O = {};
3706
- return x.trim() || (O.token = !0), R.trim() || (O.newPassword = !0), D.trim() || (O.confirmPassword = !0), l(O), Object.keys(O).length === 0;
3707
- }, g = async (O) => {
3708
- if (O.preventDefault(), !!H()) {
3709
- if (!(L != null && L.id)) {
3710
- C(F.tenantNotFoundError);
3721
+ var X;
3722
+ const [y, f] = x(""), [F, g] = x(r), [T, A] = x(""), [L, M] = x(""), [P, d] = x(!1), [v, N] = x(""), [B, w] = x(""), [R, k] = x({}), { requestPasswordReset: I, confirmPasswordReset: l } = he(), z = ((X = pe()) == null ? void 0 : X.tenant) ?? null, D = { ...or, ...n }, p = { ...ar, ...e }, U = () => {
3723
+ const W = {};
3724
+ return y.trim() || (W.email = !0), k(W), Object.keys(W).length === 0;
3725
+ }, b = () => {
3726
+ const W = {};
3727
+ return F.trim() || (W.token = !0), T.trim() || (W.newPassword = !0), L.trim() || (W.confirmPassword = !0), k(W), Object.keys(W).length === 0;
3728
+ }, h = async (W) => {
3729
+ if (W.preventDefault(), !!U()) {
3730
+ if (!(z != null && z.id)) {
3731
+ N(D.tenantNotFoundError);
3711
3732
  return;
3712
3733
  }
3713
- u(!0), C(""), T("");
3734
+ d(!0), N(""), w("");
3714
3735
  try {
3715
- await U({ email: y, tenantId: L.id }), T(F.successMessage), i == null || i();
3736
+ await I({ email: y, tenantId: z.id }), w(D.successMessage), i == null || i();
3716
3737
  } catch (q) {
3717
- const j = q.message || F.errorMessage;
3718
- C(j), o == null || o(j);
3738
+ const V = q.message || D.errorMessage;
3739
+ N(V), o == null || o(V);
3719
3740
  } finally {
3720
- u(!1);
3741
+ d(!1);
3721
3742
  }
3722
3743
  }
3723
- }, m = async (O) => {
3724
- if (O.preventDefault(), !!I()) {
3725
- if (R !== D) {
3726
- C(F.passwordMismatchError), l({ confirmPassword: !0 });
3744
+ }, S = async (W) => {
3745
+ if (W.preventDefault(), !!b()) {
3746
+ if (T !== L) {
3747
+ N(D.passwordMismatchError), k({ confirmPassword: !0 });
3727
3748
  return;
3728
3749
  }
3729
- u(!0), C(""), T("");
3750
+ d(!0), N(""), w("");
3730
3751
  try {
3731
- await b({ token: x, newPassword: R }), T(F.resetSuccessMessage), i == null || i();
3752
+ await l({ token: F, newPassword: T }), w(D.resetSuccessMessage), i == null || i();
3732
3753
  } catch (q) {
3733
- const j = q.message || F.errorMessage;
3734
- C(j), o == null || o(j);
3754
+ const V = q.message || D.errorMessage;
3755
+ N(V), o == null || o(V);
3735
3756
  } finally {
3736
- u(!1);
3757
+ d(!1);
3737
3758
  }
3738
3759
  }
3739
- }, v = (O) => ({
3740
- ...c.input,
3741
- ...$[O] ? c.inputError : {}
3742
- }), Q = () => ({
3743
- ...c.button,
3744
- ...P ? c.buttonLoading : {}
3760
+ }, E = (W) => ({
3761
+ ...p.input,
3762
+ ...R[W] ? p.inputError : {}
3763
+ }), K = () => ({
3764
+ ...p.button,
3765
+ ...P ? p.buttonLoading : {}
3745
3766
  });
3746
3767
  if (t === "reset") {
3747
- const O = x && R && D;
3748
- return /* @__PURE__ */ d("div", { className: w, style: c.container, children: [
3749
- /* @__PURE__ */ s("h2", { style: c.title, children: F.resetTitle }),
3750
- /* @__PURE__ */ s("p", { style: c.subtitle, children: F.resetSubtitle }),
3751
- /* @__PURE__ */ d("form", { onSubmit: m, style: c.form, children: [
3752
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3753
- /* @__PURE__ */ s("label", { style: c.label, children: F.tokenLabel }),
3768
+ const W = F && T && L;
3769
+ return /* @__PURE__ */ u("div", { className: m, style: p.container, children: [
3770
+ /* @__PURE__ */ s("h2", { style: p.title, children: D.resetTitle }),
3771
+ /* @__PURE__ */ s("p", { style: p.subtitle, children: D.resetSubtitle }),
3772
+ /* @__PURE__ */ u("form", { onSubmit: S, style: p.form, children: [
3773
+ /* @__PURE__ */ u("div", { style: p.fieldGroup, children: [
3774
+ /* @__PURE__ */ s("label", { style: p.label, children: D.tokenLabel }),
3754
3775
  /* @__PURE__ */ s(
3755
3776
  "input",
3756
3777
  {
3757
3778
  type: "text",
3758
- value: x,
3779
+ value: F,
3759
3780
  onChange: (q) => {
3760
- h(q.target.value), $.token && l((j) => ({ ...j, token: !1 }));
3781
+ g(q.target.value), R.token && k((V) => ({ ...V, token: !1 }));
3761
3782
  },
3762
- placeholder: F.tokenPlaceholder,
3763
- style: v("token"),
3783
+ placeholder: D.tokenPlaceholder,
3784
+ style: E("token"),
3764
3785
  disabled: P
3765
3786
  }
3766
3787
  )
3767
3788
  ] }),
3768
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3769
- /* @__PURE__ */ s("label", { style: c.label, children: F.newPasswordLabel }),
3789
+ /* @__PURE__ */ u("div", { style: p.fieldGroup, children: [
3790
+ /* @__PURE__ */ s("label", { style: p.label, children: D.newPasswordLabel }),
3770
3791
  /* @__PURE__ */ s(
3771
3792
  "input",
3772
3793
  {
3773
3794
  type: "password",
3774
- value: R,
3795
+ value: T,
3775
3796
  onChange: (q) => {
3776
- N(q.target.value), $.newPassword && l((j) => ({ ...j, newPassword: !1 }));
3797
+ A(q.target.value), R.newPassword && k((V) => ({ ...V, newPassword: !1 }));
3777
3798
  },
3778
- placeholder: F.newPasswordPlaceholder,
3779
- style: v("newPassword"),
3799
+ placeholder: D.newPasswordPlaceholder,
3800
+ style: E("newPassword"),
3780
3801
  disabled: P
3781
3802
  }
3782
3803
  )
3783
3804
  ] }),
3784
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3785
- /* @__PURE__ */ s("label", { style: c.label, children: F.confirmPasswordLabel }),
3805
+ /* @__PURE__ */ u("div", { style: p.fieldGroup, children: [
3806
+ /* @__PURE__ */ s("label", { style: p.label, children: D.confirmPasswordLabel }),
3786
3807
  /* @__PURE__ */ s(
3787
3808
  "input",
3788
3809
  {
3789
3810
  type: "password",
3790
- value: D,
3811
+ value: L,
3791
3812
  onChange: (q) => {
3792
- E(q.target.value), $.confirmPassword && l((j) => ({ ...j, confirmPassword: !1 })), S === F.passwordMismatchError && C("");
3813
+ M(q.target.value), R.confirmPassword && k((V) => ({ ...V, confirmPassword: !1 })), v === D.passwordMismatchError && N("");
3793
3814
  },
3794
- placeholder: F.confirmPasswordPlaceholder,
3795
- style: v("confirmPassword"),
3815
+ placeholder: D.confirmPasswordPlaceholder,
3816
+ style: E("confirmPassword"),
3796
3817
  disabled: P
3797
3818
  }
3798
3819
  )
@@ -3801,43 +3822,43 @@ function jr({
3801
3822
  "button",
3802
3823
  {
3803
3824
  type: "submit",
3804
- disabled: !O || P,
3825
+ disabled: !W || P,
3805
3826
  style: {
3806
- ...Q(),
3807
- ...!O || P ? c.buttonDisabled : {}
3827
+ ...K(),
3828
+ ...!W || P ? p.buttonDisabled : {}
3808
3829
  },
3809
- children: P ? F.resetLoadingText : F.resetSubmitButton
3830
+ children: P ? D.resetLoadingText : D.resetSubmitButton
3810
3831
  }
3811
3832
  ),
3812
- S && /* @__PURE__ */ s("div", { style: c.errorText, children: S }),
3813
- M && /* @__PURE__ */ s("div", { style: c.successText, children: M })
3833
+ v && /* @__PURE__ */ s("div", { style: p.errorText, children: v }),
3834
+ B && /* @__PURE__ */ s("div", { style: p.successText, children: B })
3814
3835
  ] }),
3815
- /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3816
- /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: F.backToLoginLink }),
3817
- p && /* @__PURE__ */ d(_, { children: [
3818
- /* @__PURE__ */ s("span", { style: c.modeSwitchDivider, children: F.dividerBullet }),
3819
- /* @__PURE__ */ s("a", { onClick: () => p("request"), style: c.link, children: F.requestNewLinkLink })
3836
+ /* @__PURE__ */ u("div", { style: p.linkContainer, children: [
3837
+ /* @__PURE__ */ s("a", { onClick: a, style: p.link, children: D.backToLoginLink }),
3838
+ c && /* @__PURE__ */ u(_, { children: [
3839
+ /* @__PURE__ */ s("span", { style: p.modeSwitchDivider, children: D.dividerBullet }),
3840
+ /* @__PURE__ */ s("a", { onClick: () => c("request"), style: p.link, children: D.requestNewLinkLink })
3820
3841
  ] })
3821
3842
  ] })
3822
3843
  ] });
3823
3844
  }
3824
- const J = y;
3825
- return /* @__PURE__ */ d("div", { className: w, style: c.container, children: [
3826
- /* @__PURE__ */ s("h2", { style: c.title, children: F.title }),
3827
- /* @__PURE__ */ s("p", { style: c.subtitle, children: F.subtitle }),
3828
- /* @__PURE__ */ d("form", { onSubmit: g, style: c.form, children: [
3829
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3830
- /* @__PURE__ */ s("label", { style: c.label, children: F.emailLabel }),
3845
+ const G = y;
3846
+ return /* @__PURE__ */ u("div", { className: m, style: p.container, children: [
3847
+ /* @__PURE__ */ s("h2", { style: p.title, children: D.title }),
3848
+ /* @__PURE__ */ s("p", { style: p.subtitle, children: D.subtitle }),
3849
+ /* @__PURE__ */ u("form", { onSubmit: h, style: p.form, children: [
3850
+ /* @__PURE__ */ u("div", { style: p.fieldGroup, children: [
3851
+ /* @__PURE__ */ s("label", { style: p.label, children: D.emailLabel }),
3831
3852
  /* @__PURE__ */ s(
3832
3853
  "input",
3833
3854
  {
3834
3855
  type: "email",
3835
3856
  value: y,
3836
- onChange: (O) => {
3837
- f(O.target.value), $.email && l((q) => ({ ...q, email: !1 }));
3857
+ onChange: (W) => {
3858
+ f(W.target.value), R.email && k((q) => ({ ...q, email: !1 }));
3838
3859
  },
3839
- placeholder: F.emailPlaceholder,
3840
- style: v("email"),
3860
+ placeholder: D.emailPlaceholder,
3861
+ style: E("email"),
3841
3862
  disabled: P
3842
3863
  }
3843
3864
  )
@@ -3846,27 +3867,27 @@ function jr({
3846
3867
  "button",
3847
3868
  {
3848
3869
  type: "submit",
3849
- disabled: !J || P,
3870
+ disabled: !G || P,
3850
3871
  style: {
3851
- ...Q(),
3852
- ...!J || P ? c.buttonDisabled : {}
3872
+ ...K(),
3873
+ ...!G || P ? p.buttonDisabled : {}
3853
3874
  },
3854
- children: P ? F.loadingText : F.submitButton
3875
+ children: P ? D.loadingText : D.submitButton
3855
3876
  }
3856
3877
  ),
3857
- S && /* @__PURE__ */ s("div", { style: c.errorText, children: S }),
3858
- M && /* @__PURE__ */ s("div", { style: c.successText, children: M })
3878
+ v && /* @__PURE__ */ s("div", { style: p.errorText, children: v }),
3879
+ B && /* @__PURE__ */ s("div", { style: p.successText, children: B })
3859
3880
  ] }),
3860
- /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3861
- /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: F.backToLoginLink }),
3862
- p && /* @__PURE__ */ d(_, { children: [
3863
- /* @__PURE__ */ s("span", { style: c.modeSwitchDivider, children: F.dividerBullet }),
3864
- /* @__PURE__ */ s("a", { onClick: () => p("reset"), style: c.link, children: F.haveTokenLink })
3881
+ /* @__PURE__ */ u("div", { style: p.linkContainer, children: [
3882
+ /* @__PURE__ */ s("a", { onClick: a, style: p.link, children: D.backToLoginLink }),
3883
+ c && /* @__PURE__ */ u(_, { children: [
3884
+ /* @__PURE__ */ s("span", { style: p.modeSwitchDivider, children: D.dividerBullet }),
3885
+ /* @__PURE__ */ s("a", { onClick: () => c("reset"), style: p.link, children: D.haveTokenLink })
3865
3886
  ] })
3866
3887
  ] })
3867
3888
  ] });
3868
3889
  }
3869
- const ir = () => /* @__PURE__ */ s(
3890
+ const lr = () => /* @__PURE__ */ s(
3870
3891
  "div",
3871
3892
  {
3872
3893
  style: {
@@ -3878,7 +3899,7 @@ const ir = () => /* @__PURE__ */ s(
3878
3899
  },
3879
3900
  children: /* @__PURE__ */ s("div", { children: "Loading..." })
3880
3901
  }
3881
- ), or = ({ error: n, retry: e }) => /* @__PURE__ */ d(
3902
+ ), cr = ({ error: n, retry: e }) => /* @__PURE__ */ u(
3882
3903
  "div",
3883
3904
  {
3884
3905
  style: {
@@ -3912,43 +3933,43 @@ const ir = () => /* @__PURE__ */ s(
3912
3933
  ]
3913
3934
  }
3914
3935
  );
3915
- function Gr({
3936
+ function Zr({
3916
3937
  children: n,
3917
3938
  loadingFallback: e,
3918
3939
  errorFallback: t,
3919
3940
  requireTenant: r = !0
3920
3941
  }) {
3921
- const { isAppLoading: i, appError: o, retryApp: a } = Se(), p = xe(), w = Fe(), y = Ke(), f = Ze(), x = (p == null ? void 0 : p.isTenantLoading) ?? !1, h = (p == null ? void 0 : p.tenantError) ?? null, R = (p == null ? void 0 : p.tenantSlug) ?? null, N = (p == null ? void 0 : p.retryTenant) ?? (() => {
3922
- }), D = (w == null ? void 0 : w.isAuthReady) ?? !0, E = (y == null ? void 0 : y.isReady) ?? !0, P = (f == null ? void 0 : f.isReady) ?? !0, u = r && p && R, T = i || u && x || w && !D || y && !E || f && !P, $ = o || (u ? h : null), l = () => {
3923
- o && a(), h && p && N();
3942
+ const { isAppLoading: i, appError: o, retryApp: a } = Ae(), c = pe(), m = $e(), y = Ye(), f = Xe(), F = (c == null ? void 0 : c.isTenantLoading) ?? !1, g = (c == null ? void 0 : c.tenantError) ?? null, T = (c == null ? void 0 : c.tenantSlug) ?? null, A = (c == null ? void 0 : c.retryTenant) ?? (() => {
3943
+ }), L = (m == null ? void 0 : m.isAuthReady) ?? !0, M = (y == null ? void 0 : y.isReady) ?? !0, P = (f == null ? void 0 : f.isReady) ?? !0, d = r && c && T, w = i || d && F || m && !L || y && !M || f && !P, R = o || (d ? g : null), k = () => {
3944
+ o && a(), g && c && A();
3924
3945
  };
3925
- if (T)
3926
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(ir, {}) });
3927
- if ($) {
3928
- const U = typeof t == "function" ? t($, l) : t || /* @__PURE__ */ s(or, { error: $, retry: l });
3929
- return /* @__PURE__ */ s(_, { children: U });
3946
+ if (w)
3947
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(lr, {}) });
3948
+ if (R) {
3949
+ const I = typeof t == "function" ? t(R, k) : t || /* @__PURE__ */ s(cr, { error: R, retry: k });
3950
+ return /* @__PURE__ */ s(_, { children: I });
3930
3951
  }
3931
3952
  return /* @__PURE__ */ s(_, { children: n });
3932
3953
  }
3933
- function Qr(n = !0) {
3934
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = Se(), o = xe(), a = Fe(), p = Ke(), w = Ze(), y = (o == null ? void 0 : o.isTenantLoading) ?? !1, f = (o == null ? void 0 : o.tenantError) ?? null, x = (o == null ? void 0 : o.tenant) ?? null, h = (o == null ? void 0 : o.tenantSlug) ?? null, R = (o == null ? void 0 : o.retryTenant) ?? (() => {
3935
- }), N = (a == null ? void 0 : a.isAuthReady) ?? !0, D = (p == null ? void 0 : p.isReady) ?? !0, E = (w == null ? void 0 : w.isReady) ?? !0, P = n && o && h, M = e || P && y || a && !N || p && !D || w && !E, T = t || (P ? f : null);
3954
+ function Jr(n = !0) {
3955
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = Ae(), o = pe(), a = $e(), c = Ye(), m = Xe(), y = (o == null ? void 0 : o.isTenantLoading) ?? !1, f = (o == null ? void 0 : o.tenantError) ?? null, F = (o == null ? void 0 : o.tenant) ?? null, g = (o == null ? void 0 : o.tenantSlug) ?? null, T = (o == null ? void 0 : o.retryTenant) ?? (() => {
3956
+ }), A = (a == null ? void 0 : a.isAuthReady) ?? !0, L = (c == null ? void 0 : c.isReady) ?? !0, M = (m == null ? void 0 : m.isReady) ?? !0, P = n && o && g, B = e || P && y || a && !A || c && !L || m && !M, w = t || (P ? f : null);
3936
3957
  return {
3937
- isLoading: M,
3938
- error: T,
3939
- isReady: !M && !T && i !== null && (!P || x !== null),
3958
+ isLoading: B,
3959
+ error: w,
3960
+ isReady: !B && !w && i !== null && (!P || F !== null),
3940
3961
  retry: () => {
3941
- t && r(), f && o && R();
3962
+ t && r(), f && o && T();
3942
3963
  },
3943
3964
  // Individual states
3944
3965
  app: { isLoading: e, error: t, data: i },
3945
- tenant: o ? { isLoading: y, error: f, data: x } : null,
3946
- auth: a ? { isReady: N } : null,
3947
- featureFlags: p ? { isReady: D } : null,
3948
- subscription: w ? { isReady: E } : null
3966
+ tenant: o ? { isLoading: y, error: f, data: F } : null,
3967
+ auth: a ? { isReady: A } : null,
3968
+ featureFlags: c ? { isReady: L } : null,
3969
+ subscription: m ? { isReady: M } : null
3949
3970
  };
3950
3971
  }
3951
- const ar = {
3972
+ const dr = {
3952
3973
  wrapper: {
3953
3974
  position: "relative"
3954
3975
  },
@@ -3992,7 +4013,7 @@ const ar = {
3992
4013
  marginLeft: 8
3993
4014
  }
3994
4015
  };
3995
- function Kr({
4016
+ function Yr({
3996
4017
  tenants: n,
3997
4018
  currentTenantId: e,
3998
4019
  onSelect: t,
@@ -4000,81 +4021,81 @@ function Kr({
4000
4021
  className: i = "",
4001
4022
  dropdownClassName: o = "",
4002
4023
  itemClassName: a = "",
4003
- renderItem: p,
4004
- placeholder: w = "Select tenant",
4024
+ renderItem: c,
4025
+ placeholder: m = "Select tenant",
4005
4026
  disabled: y = !1,
4006
4027
  showCurrentTenant: f = !0
4007
4028
  }) {
4008
- var M;
4009
- const x = { ...ar, ...r }, h = Fe(), [R, N] = k(!1), D = Me(null), E = n ?? (h == null ? void 0 : h.userTenants) ?? [], P = e ?? ((M = h == null ? void 0 : h.currentUser) == null ? void 0 : M.tenantId) ?? null, u = async (T) => {
4010
- N(!1), t ? t(T) : h != null && h.switchToTenant && await h.switchToTenant(T);
4029
+ var B;
4030
+ const F = { ...dr, ...r }, g = $e(), [T, A] = x(!1), L = Ne(null), M = n ?? (g == null ? void 0 : g.userTenants) ?? [], P = e ?? ((B = g == null ? void 0 : g.currentUser) == null ? void 0 : B.tenantId) ?? null, d = async (w) => {
4031
+ A(!1), t ? t(w) : g != null && g.switchToTenant && await g.switchToTenant(w);
4011
4032
  };
4012
- re(() => {
4013
- const T = ($) => {
4014
- D.current && !D.current.contains($.target) && N(!1);
4033
+ ne(() => {
4034
+ const w = (R) => {
4035
+ L.current && !L.current.contains(R.target) && A(!1);
4015
4036
  };
4016
- return document.addEventListener("mousedown", T), () => document.removeEventListener("mousedown", T);
4037
+ return document.addEventListener("mousedown", w), () => document.removeEventListener("mousedown", w);
4017
4038
  }, []);
4018
- const S = E.find((T) => T.id === P);
4019
- if (E.length === 0)
4039
+ const v = M.find((w) => w.id === P);
4040
+ if (M.length === 0)
4020
4041
  return null;
4021
- if (E.length === 1 && f)
4022
- return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: E[0].name }) });
4023
- const C = (T, $) => /* @__PURE__ */ d("span", { style: { fontWeight: $ ? "bold" : "normal" }, children: [
4024
- T.name,
4025
- T.role && /* @__PURE__ */ d("span", { style: x.itemRole, children: [
4042
+ if (M.length === 1 && f)
4043
+ return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: M[0].name }) });
4044
+ const N = (w, R) => /* @__PURE__ */ u("span", { style: { fontWeight: R ? "bold" : "normal" }, children: [
4045
+ w.name,
4046
+ w.role && /* @__PURE__ */ u("span", { style: F.itemRole, children: [
4026
4047
  "(",
4027
- T.role,
4048
+ w.role,
4028
4049
  ")"
4029
4050
  ] })
4030
4051
  ] });
4031
- return /* @__PURE__ */ d("div", { ref: D, className: i, style: x.wrapper, children: [
4032
- /* @__PURE__ */ d(
4052
+ return /* @__PURE__ */ u("div", { ref: L, className: i, style: F.wrapper, children: [
4053
+ /* @__PURE__ */ u(
4033
4054
  "button",
4034
4055
  {
4035
4056
  type: "button",
4036
- onClick: () => !y && N(!R),
4057
+ onClick: () => !y && A(!T),
4037
4058
  disabled: y,
4038
4059
  style: {
4039
- ...x.button,
4040
- ...y ? x.buttonDisabled : {}
4060
+ ...F.button,
4061
+ ...y ? F.buttonDisabled : {}
4041
4062
  },
4042
4063
  children: [
4043
- S ? S.name : w,
4044
- /* @__PURE__ */ s("span", { style: x.arrow, children: R ? "▲" : "▼" })
4064
+ v ? v.name : m,
4065
+ /* @__PURE__ */ s("span", { style: F.arrow, children: T ? "▲" : "▼" })
4045
4066
  ]
4046
4067
  }
4047
4068
  ),
4048
- R && /* @__PURE__ */ s("div", { className: o, style: x.dropdown, children: E.map((T) => {
4049
- const $ = T.id === P;
4069
+ T && /* @__PURE__ */ s("div", { className: o, style: F.dropdown, children: M.map((w) => {
4070
+ const R = w.id === P;
4050
4071
  return /* @__PURE__ */ s(
4051
4072
  "div",
4052
4073
  {
4053
4074
  className: a,
4054
- onClick: () => u(T.id),
4075
+ onClick: () => d(w.id),
4055
4076
  style: {
4056
- ...x.item,
4057
- ...$ ? x.itemSelected : {}
4077
+ ...F.item,
4078
+ ...R ? F.itemSelected : {}
4058
4079
  },
4059
- onMouseEnter: (l) => {
4060
- $ || Object.assign(l.currentTarget.style, x.itemHover);
4080
+ onMouseEnter: (k) => {
4081
+ R || Object.assign(k.currentTarget.style, F.itemHover);
4061
4082
  },
4062
- onMouseLeave: (l) => {
4063
- if (!$) {
4064
- const U = x.item || {};
4065
- Object.keys(x.itemHover || {}).forEach((b) => {
4066
- l.currentTarget.style[b] = U[b] ?? "";
4083
+ onMouseLeave: (k) => {
4084
+ if (!R) {
4085
+ const I = F.item || {};
4086
+ Object.keys(F.itemHover || {}).forEach((l) => {
4087
+ k.currentTarget.style[l] = I[l] ?? "";
4067
4088
  });
4068
4089
  }
4069
4090
  },
4070
- children: p ? p(T, $) : C(T, $)
4091
+ children: c ? c(w, R) : N(w, R)
4071
4092
  },
4072
- T.id
4093
+ w.id
4073
4094
  );
4074
4095
  }) })
4075
4096
  ] });
4076
4097
  }
4077
- class Zr {
4098
+ class Xr {
4078
4099
  constructor(e, t) {
4079
4100
  this.httpService = e, this.sessionManager = t;
4080
4101
  }
@@ -4142,7 +4163,7 @@ class Zr {
4142
4163
  };
4143
4164
  }
4144
4165
  }
4145
- class Jr {
4166
+ class en {
4146
4167
  constructor(e, t) {
4147
4168
  this.httpService = e, this.sessionManager = t;
4148
4169
  }
@@ -4193,7 +4214,7 @@ class Jr {
4193
4214
  });
4194
4215
  }
4195
4216
  }
4196
- class Yr {
4217
+ class tn {
4197
4218
  constructor(e) {
4198
4219
  this.httpService = e;
4199
4220
  }
@@ -4202,7 +4223,7 @@ class Yr {
4202
4223
  return await this.httpService.get("/health");
4203
4224
  }
4204
4225
  }
4205
- class Xr {
4226
+ class rn {
4206
4227
  // Date string to Date object
4207
4228
  static toDate(e) {
4208
4229
  return new Date(e);
@@ -4324,139 +4345,139 @@ class Xr {
4324
4345
  }), t;
4325
4346
  }
4326
4347
  }
4327
- const Xe = "returnTo", Ee = "zone_return_to", Ie = "zone_return_to";
4328
- function en(n = {}) {
4348
+ const rt = "returnTo", Me = "zone_return_to", Le = "zone_return_to";
4349
+ function nn(n = {}) {
4329
4350
  const {
4330
4351
  zoneRoots: e = {},
4331
- returnToParam: t = Xe,
4352
+ returnToParam: t = rt,
4332
4353
  returnToStorage: r = "url"
4333
- } = n, i = pt(), [o, a] = ft(), { isAuthenticated: p, currentUser: w } = ue(), { tenant: y } = ge(), f = K(() => ({ ...Ue, ...e }), [e]), x = !!y, h = w == null ? void 0 : w.userType, R = K(() => {
4354
+ } = n, i = mt(), [o, a] = yt(), { isAuthenticated: c, currentUser: m } = he(), { tenant: y } = Te(), f = Z(() => ({ ...Oe, ...e }), [e]), F = !!y, g = m == null ? void 0 : m.userType, T = Z(() => {
4334
4355
  switch (r) {
4335
4356
  case "url":
4336
4357
  return o.get(t);
4337
4358
  case "session":
4338
- return sessionStorage.getItem(Ee);
4359
+ return sessionStorage.getItem(Me);
4339
4360
  case "local":
4340
- return localStorage.getItem(Ie);
4361
+ return localStorage.getItem(Le);
4341
4362
  default:
4342
4363
  return null;
4343
4364
  }
4344
- }, [r, o, t]), N = se(() => {
4365
+ }, [r, o, t]), A = oe(() => {
4345
4366
  switch (r) {
4346
4367
  case "url": {
4347
- const u = new URLSearchParams(o);
4348
- u.delete(t), a(u, { replace: !0 });
4368
+ const d = new URLSearchParams(o);
4369
+ d.delete(t), a(d, { replace: !0 });
4349
4370
  break;
4350
4371
  }
4351
4372
  case "session":
4352
- sessionStorage.removeItem(Ee);
4373
+ sessionStorage.removeItem(Me);
4353
4374
  break;
4354
4375
  case "local":
4355
- localStorage.removeItem(Ie);
4376
+ localStorage.removeItem(Le);
4356
4377
  break;
4357
4378
  }
4358
- }, [r, o, t, a]), D = se(
4359
- (u) => {
4379
+ }, [r, o, t, a]), L = oe(
4380
+ (d) => {
4360
4381
  switch (r) {
4361
4382
  case "url": {
4362
- const S = new URLSearchParams(o);
4363
- S.set(t, u), a(S, { replace: !0 });
4383
+ const v = new URLSearchParams(o);
4384
+ v.set(t, d), a(v, { replace: !0 });
4364
4385
  break;
4365
4386
  }
4366
4387
  case "session":
4367
- sessionStorage.setItem(Ee, u);
4388
+ sessionStorage.setItem(Me, d);
4368
4389
  break;
4369
4390
  case "local":
4370
- localStorage.setItem(Ie, u);
4391
+ localStorage.setItem(Le, d);
4371
4392
  break;
4372
4393
  }
4373
4394
  },
4374
4395
  [r, o, t, a]
4375
- ), E = se(
4376
- (u) => {
4377
- const S = f[u] || f.default;
4378
- i(S);
4396
+ ), M = oe(
4397
+ (d) => {
4398
+ const v = f[d] || f.default;
4399
+ i(v);
4379
4400
  },
4380
4401
  [i, f]
4381
- ), P = se(() => x ? p ? h === oe.TENANT_ADMIN ? f.tenantAdmin : f.tenantUser : f.tenantGuest : p ? h === oe.TENANT_ADMIN ? f.publicAdmin : f.publicUser : f.publicGuest, [x, p, h, f]);
4402
+ ), P = oe(() => F ? c ? g === ae.TENANT_ADMIN ? f.tenantAdmin : f.tenantUser : f.tenantGuest : c ? g === ae.TENANT_ADMIN ? f.publicAdmin : f.publicUser : f.publicGuest, [F, c, g, f]);
4382
4403
  return {
4383
- returnToUrl: R,
4384
- clearReturnTo: N,
4385
- setReturnTo: D,
4386
- navigateToZone: E,
4404
+ returnToUrl: T,
4405
+ clearReturnTo: A,
4406
+ setReturnTo: L,
4407
+ navigateToZone: M,
4387
4408
  getSmartRedirect: P
4388
4409
  };
4389
4410
  }
4390
- function tn(n, e, t = Xe, r = "url") {
4411
+ function sn(n, e, t = rt, r = "url") {
4391
4412
  if (!e || r !== "url")
4392
4413
  return n;
4393
4414
  const i = new URL(n, window.location.origin);
4394
4415
  return i.searchParams.set(t, e), i.pathname + i.search;
4395
4416
  }
4396
4417
  export {
4397
- Fr as AdminZone,
4398
- Xr as ApiMappers,
4399
- qe as AppApiService,
4400
- Gr as AppLoader,
4401
- mr as AppProvider,
4402
- yt as AuthApiService,
4403
- Sr as AuthProvider,
4404
- Nr as AuthenticatedZone,
4405
- Je as DEFAULT_ZONE_PRESETS,
4406
- Ue as DEFAULT_ZONE_ROOTS,
4407
- qr as FeatureFlag,
4408
- Pt as FeatureFlagApiService,
4409
- Tr as FeatureFlagProvider,
4410
- Dr as GuestZone,
4411
- Yr as HealthApiService,
4412
- le as HttpService,
4413
- Ir as LandingRoute,
4414
- zr as LoginForm,
4415
- Wr as MagicLinkForm,
4416
- Vr as MagicLinkVerify,
4417
- $r as OpenZone,
4418
- jr as PasswordRecoveryForm,
4419
- Zr as PermissionApiService,
4420
- Pr as Protected,
4421
- Rr as ProtectedRoute,
4422
- Lr as PublicZone,
4423
- ze as RoleApiService,
4424
- xr as RoutingProvider,
4425
- ne as SessionExpiredError,
4426
- we as SessionManager,
4427
- _r as SignupForm,
4428
- Et as SubscriptionApiService,
4429
- Or as SubscriptionGuard,
4430
- Jr as SubscriptionPlanApiService,
4431
- kr as SubscriptionProvider,
4432
- be as TenantApiService,
4433
- Ur as TenantAuthenticatedZone,
4434
- Br as TenantGuestZone,
4435
- Hr as TenantOpenZone,
4436
- wr as TenantProvider,
4437
- Er as TenantRoute,
4438
- Kr as TenantSelector,
4439
- Mr as TenantZone,
4440
- mt as TokenRefreshError,
4441
- gt as TokenRefreshTimeoutError,
4442
- wt as UserApiService,
4443
- oe as UserType,
4418
+ $r as AdminZone,
4419
+ rn as ApiMappers,
4420
+ Ve as AppApiService,
4421
+ Zr as AppLoader,
4422
+ br as AppProvider,
4423
+ vt as AuthApiService,
4424
+ xr as AuthProvider,
4425
+ Ur as AuthenticatedZone,
4426
+ et as DEFAULT_ZONE_PRESETS,
4427
+ Oe as DEFAULT_ZONE_ROOTS,
4428
+ Vr as FeatureFlag,
4429
+ It as FeatureFlagApiService,
4430
+ Ar as FeatureFlagProvider,
4431
+ Br as GuestZone,
4432
+ tn as HealthApiService,
4433
+ de as HttpService,
4434
+ Nr as LandingRoute,
4435
+ Wr as LoginForm,
4436
+ Gr as MagicLinkForm,
4437
+ Kr as MagicLinkVerify,
4438
+ Hr as OpenZone,
4439
+ Qr as PasswordRecoveryForm,
4440
+ Xr as PermissionApiService,
4441
+ Ir as Protected,
4442
+ Mr as ProtectedRoute,
4443
+ Dr as PublicZone,
4444
+ We as RoleApiService,
4445
+ Rr as RoutingProvider,
4446
+ se as SessionExpiredError,
4447
+ be as SessionManager,
4448
+ jr as SignupForm,
4449
+ Lt as SubscriptionApiService,
4450
+ zr as SubscriptionGuard,
4451
+ en as SubscriptionPlanApiService,
4452
+ Pr as SubscriptionProvider,
4453
+ ve as TenantApiService,
4454
+ Or as TenantAuthenticatedZone,
4455
+ _r as TenantGuestZone,
4456
+ qr as TenantOpenZone,
4457
+ Sr as TenantProvider,
4458
+ Lr as TenantRoute,
4459
+ Yr as TenantSelector,
4460
+ Fr as TenantZone,
4461
+ bt as TokenRefreshError,
4462
+ wt as TokenRefreshTimeoutError,
4463
+ St as UserApiService,
4464
+ ae as UserType,
4444
4465
  Cr as UserZone,
4445
- ce as ZoneRoute,
4446
- tn as buildRedirectUrl,
4447
- yr as useApi,
4448
- Se as useApp,
4449
- Qr as useAppLoaderState,
4450
- ue as useAuth,
4451
- Rt as useFeatureFlags,
4452
- Ar as useRouting,
4453
- Mt as useRoutingOptional,
4454
- vr as useSettings,
4455
- It as useSubscription,
4456
- ge as useTenant,
4457
- me as useTenantInfo,
4458
- xe as useTenantOptional,
4459
- br as useTenantSettings,
4460
- en as useZoneNavigation
4466
+ ue as ZoneRoute,
4467
+ sn as buildRedirectUrl,
4468
+ vr as useApi,
4469
+ Ae as useApp,
4470
+ Jr as useAppLoaderState,
4471
+ he as useAuth,
4472
+ Mt as useFeatureFlags,
4473
+ Er as useRouting,
4474
+ Ft as useRoutingOptional,
4475
+ kr as useSettings,
4476
+ Nt as useSubscription,
4477
+ Te as useTenant,
4478
+ Je as useTenantInfo,
4479
+ pe as useTenantOptional,
4480
+ Tr as useTenantSettings,
4481
+ nn as useZoneNavigation
4461
4482
  };
4462
4483
  //# sourceMappingURL=index.es.js.map