@skylabs-digital/react-identity-access 2.3.0 → 2.5.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,5 +1,5 @@
1
- import { jsx as n, Fragment as U, jsxs as l } from "react/jsx-runtime";
2
- import { createContext as he, useMemo as X, useState as x, useCallback as ne, useEffect as te, useContext as ce, useRef as Be } from "react";
1
+ import { jsx as n, Fragment as q, jsxs as l } from "react/jsx-runtime";
2
+ import { createContext as he, useMemo as X, useState as v, useCallback as ne, useEffect as te, useContext as ce, useRef as qe } from "react";
3
3
  import { useLocation as be, Navigate as pe } from "react-router-dom";
4
4
  class re {
5
5
  // SessionManager instance
@@ -16,7 +16,7 @@ class re {
16
16
  return this.executeRequest(e, t, r, s, !1);
17
17
  }
18
18
  async executeRequest(e, t, r, s, o = !1) {
19
- const p = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, b = (s == null ? void 0 : s.timeout) || this.timeout;
19
+ const h = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, w = (s == null ? void 0 : s.timeout) || this.timeout;
20
20
  let k = {
21
21
  "Content-Type": "application/json",
22
22
  ...s == null ? void 0 : s.headers
@@ -28,15 +28,15 @@ class re {
28
28
  } catch (m) {
29
29
  console.warn("Failed to inject auth headers:", m);
30
30
  }
31
- const S = new AbortController(), T = setTimeout(() => S.abort(), b);
31
+ const b = new AbortController(), P = setTimeout(() => b.abort(), w);
32
32
  try {
33
- const m = await fetch(p, {
33
+ const m = await fetch(h, {
34
34
  method: e,
35
35
  headers: k,
36
36
  body: r ? JSON.stringify(r) : void 0,
37
- signal: S.signal
37
+ signal: b.signal
38
38
  });
39
- if (clearTimeout(T), m.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
39
+ if (clearTimeout(P), m.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
40
40
  try {
41
41
  const u = this.sessionManager.getTokens();
42
42
  if (u != null && u.refreshToken)
@@ -46,10 +46,10 @@ class re {
46
46
  }
47
47
  if (!m.ok)
48
48
  throw new Error(`HTTP ${m.status}: ${m.statusText}`);
49
- const f = m.headers.get("content-type");
50
- return !f || !f.includes("application/json") ? {} : await m.json();
49
+ const p = m.headers.get("content-type");
50
+ return !p || !p.includes("application/json") ? {} : await m.json();
51
51
  } catch (m) {
52
- throw clearTimeout(T), m instanceof Error && m.name === "AbortError" ? new Error(`Request timeout after ${b}ms`) : m;
52
+ throw clearTimeout(P), m instanceof Error && m.name === "AbortError" ? new Error(`Request timeout after ${w}ms`) : m;
53
53
  }
54
54
  }
55
55
  async get(e, t) {
@@ -125,31 +125,31 @@ class ve {
125
125
  }
126
126
  }
127
127
  const Pe = he(null);
128
- function Et({ config: i, children: e }) {
128
+ function Ct({ config: i, children: e }) {
129
129
  const t = X(
130
130
  () => {
131
- var f, u, y;
131
+ var p, u, y;
132
132
  return {
133
- enabled: ((f = i.cache) == null ? void 0 : f.enabled) ?? !0,
133
+ enabled: ((p = i.cache) == null ? void 0 : p.enabled) ?? !0,
134
134
  ttl: ((u = i.cache) == null ? void 0 : u.ttl) ?? 3e5,
135
135
  // 5 minutes default
136
136
  storageKey: ((y = i.cache) == null ? void 0 : y.storageKey) ?? `app_cache_${i.appId}`
137
137
  };
138
138
  },
139
139
  [i.cache, i.appId]
140
- ), [r, s] = x(() => {
140
+ ), [r, s] = v(() => {
141
141
  if (!t.enabled) return null;
142
142
  try {
143
- const f = localStorage.getItem(t.storageKey);
144
- if (!f) return null;
145
- const u = JSON.parse(f);
143
+ const p = localStorage.getItem(t.storageKey);
144
+ if (!p) return null;
145
+ const u = JSON.parse(p);
146
146
  return Date.now() - u.timestamp < t.ttl && u.appId === i.appId ? u.data : (localStorage.removeItem(t.storageKey), null);
147
147
  } catch {
148
148
  return null;
149
149
  }
150
- }), [o, p] = x(!r), [b, k] = x(null), S = X(() => {
151
- const f = () => {
152
- T();
150
+ }), [o, h] = v(!r), [w, k] = v(null), b = X(() => {
151
+ const p = () => {
152
+ P();
153
153
  };
154
154
  return {
155
155
  appId: i.appId,
@@ -157,57 +157,57 @@ function Et({ config: i, children: e }) {
157
157
  // App info
158
158
  appInfo: r,
159
159
  isAppLoading: o,
160
- appError: b,
161
- retryApp: f
160
+ appError: w,
161
+ retryApp: p
162
162
  };
163
- }, [i, r, o, b]), T = ne(
164
- async (f = !1) => {
165
- if (!(!f && t.enabled && r))
163
+ }, [i, r, o, w]), P = ne(
164
+ async (p = !1) => {
165
+ if (!(!p && t.enabled && r))
166
166
  try {
167
- p(!0), k(null);
168
- const u = new re(i.baseUrl), R = await new ve(u, {}).getPublicAppInfo(i.appId);
169
- if (s(R), t.enabled)
167
+ h(!0), k(null);
168
+ const u = new re(i.baseUrl), L = await new ve(u, {}).getPublicAppInfo(i.appId);
169
+ if (s(L), t.enabled)
170
170
  try {
171
- const C = {
172
- data: R,
171
+ const R = {
172
+ data: L,
173
173
  timestamp: Date.now(),
174
174
  appId: i.appId
175
175
  };
176
- localStorage.setItem(t.storageKey, JSON.stringify(C));
177
- } catch (C) {
178
- console.warn("Failed to cache app info:", C);
176
+ localStorage.setItem(t.storageKey, JSON.stringify(R));
177
+ } catch (R) {
178
+ console.warn("Failed to cache app info:", R);
179
179
  }
180
180
  } catch (u) {
181
181
  const y = u instanceof Error ? u : new Error("Failed to load app information");
182
182
  k(y), s(null);
183
183
  } finally {
184
- p(!1);
184
+ h(!1);
185
185
  }
186
186
  },
187
187
  [i.baseUrl, i.appId, t, r]
188
188
  ), m = ne(async () => {
189
189
  if (!(!t.enabled || !r))
190
190
  try {
191
- const f = localStorage.getItem(t.storageKey);
192
- if (!f) return;
193
- const u = JSON.parse(f);
191
+ const p = localStorage.getItem(t.storageKey);
192
+ if (!p) return;
193
+ const u = JSON.parse(p);
194
194
  if (Date.now() - u.timestamp > t.ttl * 0.5) {
195
- const R = new re(i.baseUrl), q = await new ve(R, {}).getPublicAppInfo(i.appId);
196
- s(q);
197
- const A = {
198
- data: q,
195
+ const L = new re(i.baseUrl), z = await new ve(L, {}).getPublicAppInfo(i.appId);
196
+ s(z);
197
+ const M = {
198
+ data: z,
199
199
  timestamp: Date.now(),
200
200
  appId: i.appId
201
201
  };
202
- localStorage.setItem(t.storageKey, JSON.stringify(A));
202
+ localStorage.setItem(t.storageKey, JSON.stringify(M));
203
203
  }
204
- } catch (f) {
205
- console.warn("Background app refresh failed:", f);
204
+ } catch (p) {
205
+ console.warn("Background app refresh failed:", p);
206
206
  }
207
207
  }, [i, t, r]);
208
208
  return te(() => {
209
- r ? m() : T();
210
- }, []), /* @__PURE__ */ n(Pe.Provider, { value: S, children: e });
209
+ r ? m() : P();
210
+ }, []), /* @__PURE__ */ n(Pe.Provider, { value: b, children: e });
211
211
  }
212
212
  function oe() {
213
213
  const i = ce(Pe);
@@ -215,7 +215,7 @@ function oe() {
215
215
  throw new Error("useApp must be used within an AppProvider");
216
216
  return i;
217
217
  }
218
- const Rt = oe;
218
+ const Ft = oe;
219
219
  class we {
220
220
  constructor(e = {}) {
221
221
  this.refreshPromise = null, this.refreshQueue = [], 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.baseUrl = e.baseUrl || "", this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey);
@@ -369,7 +369,7 @@ class we {
369
369
  return e !== null && !this.isTokenExpired(e);
370
370
  }
371
371
  }
372
- class Ue {
372
+ class ze {
373
373
  constructor(e) {
374
374
  this.httpService = e;
375
375
  }
@@ -414,7 +414,7 @@ class Ue {
414
414
  });
415
415
  }
416
416
  }
417
- class xe {
417
+ class ke {
418
418
  constructor(e, t) {
419
419
  this.httpService = e, this.sessionManager = t;
420
420
  }
@@ -481,16 +481,16 @@ class xe {
481
481
  throw new Error("SessionManager is required for private endpoints");
482
482
  const r = await this.sessionManager.getAuthHeaders(), s = new URLSearchParams();
483
483
  t != null && t.page && s.append("page", t.page.toString()), t != null && t.limit && s.append("limit", t.limit.toString()), t != null && t.sortBy && s.append("sortBy", t.sortBy), t != null && t.sortOrder && s.append("sortOrder", t.sortOrder);
484
- const o = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, p = await this.httpService.get(o, {
484
+ const o = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, h = await this.httpService.get(o, {
485
485
  headers: r
486
486
  });
487
487
  return {
488
- roles: p.data,
489
- meta: p.meta
488
+ roles: h.data,
489
+ meta: h.meta
490
490
  };
491
491
  }
492
492
  }
493
- class qe {
493
+ class Oe {
494
494
  constructor(e, t) {
495
495
  this.httpService = e, this.sessionManager = t;
496
496
  }
@@ -608,7 +608,7 @@ class ue {
608
608
  )).data;
609
609
  }
610
610
  }
611
- function ze(i, e) {
611
+ function We(i, e) {
612
612
  if (i === "localhost" || i.startsWith("127.") || i.startsWith("192.168."))
613
613
  return null;
614
614
  if (e) {
@@ -616,34 +616,34 @@ function ze(i, e) {
616
616
  if (o === s || o === `www.${s}`)
617
617
  return null;
618
618
  if (o.endsWith(`.${s}`)) {
619
- const p = o.slice(0, -(s.length + 1));
620
- return p === "www" ? null : p;
619
+ const h = o.slice(0, -(s.length + 1));
620
+ return h === "www" ? null : h;
621
621
  }
622
622
  return null;
623
623
  }
624
624
  const r = i.split(".");
625
625
  return r.length >= 3 && r[0] !== "www" ? r[0] : null;
626
626
  }
627
- function Oe(i, e = "tenant", t) {
627
+ function Ve(i, e = "tenant", t) {
628
628
  const s = new URLSearchParams(i).get(e);
629
629
  return s ? (t && t.setItem("tenant", s), s) : t ? t.getItem("tenant") : null;
630
630
  }
631
- function We(i, e, t) {
631
+ function je(i, e, t) {
632
632
  const { tenantMode: r, baseDomain: s, selectorParam: o } = i;
633
- return r === "subdomain" ? ze(e.hostname, s) : r === "selector" ? Oe(e.search, o, t) : null;
633
+ return r === "subdomain" ? We(e.hostname, s) : r === "selector" ? Ve(e.search, o, t) : null;
634
634
  }
635
- function je(i, e, t) {
635
+ function _e(i, e, t) {
636
636
  if (t)
637
637
  return `${i}.${t}`;
638
638
  const r = e.split(".");
639
639
  return r.length === 2 ? `${i}.${e}` : r.length >= 3 ? (r[0] = i, r.join(".")) : null;
640
640
  }
641
641
  const fe = "_auth";
642
- function Ve(i) {
642
+ function Ge(i) {
643
643
  const e = JSON.stringify(i);
644
644
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
645
645
  }
646
- function _e(i) {
646
+ function Ke(i) {
647
647
  try {
648
648
  let e = i.replace(/-/g, "+").replace(/_/g, "/");
649
649
  for (; e.length % 4; )
@@ -654,19 +654,34 @@ function _e(i) {
654
654
  return null;
655
655
  }
656
656
  }
657
- function Ge() {
658
- if (typeof window > "u") return null;
657
+ function Je() {
658
+ if (typeof window > "u")
659
+ return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
659
660
  const e = new URLSearchParams(window.location.search).get(fe);
660
- return e ? _e(e) : null;
661
+ if (console.log("[CrossDomainAuth] extractAuthTokensFromUrl called", {
662
+ hasAuthParam: !!e,
663
+ searchParams: window.location.search,
664
+ encodedLength: e == null ? void 0 : e.length
665
+ }), !e) return null;
666
+ const t = Ke(e);
667
+ return console.log("[CrossDomainAuth] Token decode result:", {
668
+ success: !!t,
669
+ hasAccessToken: !!(t != null && t.accessToken),
670
+ hasRefreshToken: !!(t != null && t.refreshToken),
671
+ expiresIn: t == null ? void 0 : t.expiresIn
672
+ }), t;
661
673
  }
662
- function Ke() {
674
+ function Ye() {
663
675
  if (typeof window > "u") return;
664
676
  const i = new URL(window.location.href);
665
- i.searchParams.delete(fe), window.history.replaceState({}, "", i.toString());
677
+ i.searchParams.delete(fe), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
678
+ oldUrl: window.location.href,
679
+ newUrl: i.toString()
680
+ }), window.history.replaceState({}, "", i.toString());
666
681
  }
667
682
  const Se = he(null);
668
- function Ct({ config: i, children: e }) {
669
- const { baseUrl: t, appInfo: r, appId: s } = oe(), o = ne(() => typeof window > "u" ? null : We(
683
+ function $t({ config: i, children: e }) {
684
+ const { baseUrl: t, appInfo: r, appId: s } = oe(), o = ne(() => typeof window > "u" ? null : je(
670
685
  {
671
686
  tenantMode: i.tenantMode || "selector",
672
687
  baseDomain: i.baseDomain,
@@ -677,118 +692,118 @@ function Ct({ config: i, children: e }) {
677
692
  search: window.location.search
678
693
  },
679
694
  window.localStorage
680
- ), [i.tenantMode, i.baseDomain, i.selectorParam]), [p, b] = x(() => o()), k = X(
695
+ ), [i.tenantMode, i.baseDomain, i.selectorParam]), [h, w] = v(() => o()), k = X(
681
696
  () => {
682
- var a, L, c;
697
+ var c, I, S;
683
698
  return {
684
- enabled: ((a = i.cache) == null ? void 0 : a.enabled) ?? !0,
685
- ttl: ((L = i.cache) == null ? void 0 : L.ttl) ?? 5 * 60 * 1e3,
699
+ enabled: ((c = i.cache) == null ? void 0 : c.enabled) ?? !0,
700
+ ttl: ((I = i.cache) == null ? void 0 : I.ttl) ?? 5 * 60 * 1e3,
686
701
  // 5 minutes default
687
- storageKey: ((c = i.cache) == null ? void 0 : c.storageKey) ?? `tenant_cache_${p || "default"}`
702
+ storageKey: ((S = i.cache) == null ? void 0 : S.storageKey) ?? `tenant_cache_${h || "default"}`
688
703
  };
689
704
  },
690
- [i.cache, p]
691
- ), [S, T] = x(() => {
705
+ [i.cache, h]
706
+ ), [b, P] = v(() => {
692
707
  if (i.initialTenant) return i.initialTenant;
693
- if (!k.enabled || !p) return null;
708
+ if (!k.enabled || !h) return null;
694
709
  try {
695
- const a = localStorage.getItem(k.storageKey);
696
- if (!a) return null;
697
- const L = JSON.parse(a);
698
- return Date.now() - L.timestamp < k.ttl && L.tenantSlug === p ? L.data : (localStorage.removeItem(k.storageKey), null);
710
+ const c = localStorage.getItem(k.storageKey);
711
+ if (!c) return null;
712
+ const I = JSON.parse(c);
713
+ return Date.now() - I.timestamp < k.ttl && I.tenantSlug === h ? I.data : (localStorage.removeItem(k.storageKey), null);
699
714
  } catch {
700
715
  return null;
701
716
  }
702
- }), [m, f] = x(!S && !i.initialTenant), [u, y] = x(null), [R, C] = x(null), [q, A] = x(!1), [d, P] = x(null);
717
+ }), [m, p] = v(!b && !i.initialTenant), [u, y] = v(null), [L, R] = v(null), [z, M] = v(!1), [A, d] = v(null);
703
718
  te(() => {
704
- const a = o();
705
- b(a);
719
+ const c = o();
720
+ w(c);
706
721
  }, [o]);
707
- const E = (r == null ? void 0 : r.settingsSchema) || null, z = ne(
708
- async (a, L = !1) => {
709
- if (!(!L && k.enabled && S && S.domain === a))
722
+ const C = (r == null ? void 0 : r.settingsSchema) || null, F = ne(
723
+ async (c, I = !1) => {
724
+ if (!(!I && k.enabled && b && b.domain === c))
710
725
  try {
711
- f(!0), y(null);
712
- const c = new re(t), g = await new ue(c, s).getPublicTenantInfo(a);
713
- if (T(g), k.enabled)
726
+ p(!0), y(null);
727
+ const S = new re(t), a = await new ue(S, s).getPublicTenantInfo(c);
728
+ if (P(a), k.enabled)
714
729
  try {
715
- const w = {
716
- data: g,
730
+ const f = {
731
+ data: a,
717
732
  timestamp: Date.now(),
718
- tenantSlug: a
733
+ tenantSlug: c
719
734
  };
720
- localStorage.setItem(k.storageKey, JSON.stringify(w));
721
- } catch (w) {
722
- console.warn("Failed to cache tenant info:", w);
735
+ localStorage.setItem(k.storageKey, JSON.stringify(f));
736
+ } catch (f) {
737
+ console.warn("Failed to cache tenant info:", f);
723
738
  }
724
- } catch (c) {
725
- const h = c instanceof Error ? c : new Error("Failed to load tenant information");
726
- y(h), T(null);
739
+ } catch (S) {
740
+ const g = S instanceof Error ? S : new Error("Failed to load tenant information");
741
+ y(g), P(null);
727
742
  } finally {
728
- f(!1);
743
+ p(!1);
729
744
  }
730
745
  },
731
- [t, s, k, S]
746
+ [t, s, k, b]
732
747
  ), G = ne(async () => {
733
- if (!(!k.enabled || !S || !p))
748
+ if (!(!k.enabled || !b || !h))
734
749
  try {
735
- const a = localStorage.getItem(k.storageKey);
736
- if (!a) return;
737
- const L = JSON.parse(a);
738
- if (Date.now() - L.timestamp > k.ttl * 0.5) {
739
- const h = new re(t), w = await new ue(h, s).getPublicTenantInfo(p);
740
- T(w);
741
- const j = {
742
- data: w,
750
+ const c = localStorage.getItem(k.storageKey);
751
+ if (!c) return;
752
+ const I = JSON.parse(c);
753
+ if (Date.now() - I.timestamp > k.ttl * 0.5) {
754
+ const g = new re(t), f = await new ue(g, s).getPublicTenantInfo(h);
755
+ P(f);
756
+ const O = {
757
+ data: f,
743
758
  timestamp: Date.now(),
744
- tenantSlug: p
759
+ tenantSlug: h
745
760
  };
746
- localStorage.setItem(k.storageKey, JSON.stringify(j));
761
+ localStorage.setItem(k.storageKey, JSON.stringify(O));
747
762
  }
748
- } catch (a) {
749
- console.warn("Background tenant refresh failed:", a);
763
+ } catch (c) {
764
+ console.warn("Background tenant refresh failed:", c);
750
765
  }
751
- }, [t, s, k, S, p]), $ = ne(async () => {
752
- if (S != null && S.id)
766
+ }, [t, s, k, b, h]), U = ne(async () => {
767
+ if (b != null && b.id)
753
768
  try {
754
- A(!0), P(null);
755
- const a = new re(t), c = await new ue(a, S.appId).getTenantSettings(S.id);
756
- C(c);
757
- } catch (a) {
758
- const L = a instanceof Error ? a : new Error("Failed to load tenant settings");
759
- P(L), C(null);
769
+ M(!0), d(null);
770
+ const c = new re(t), S = await new ue(c, b.appId).getTenantSettings(b.id);
771
+ R(S);
772
+ } catch (c) {
773
+ const I = c instanceof Error ? c : new Error("Failed to load tenant settings");
774
+ d(I), R(null);
760
775
  } finally {
761
- A(!1);
776
+ M(!1);
762
777
  }
763
- }, [t, S]), _ = ne(() => {
764
- $();
765
- }, [$]), v = ne(
766
- (a) => {
767
- if (!E)
778
+ }, [t, b]), _ = ne(() => {
779
+ U();
780
+ }, [U]), x = ne(
781
+ (c) => {
782
+ if (!C)
768
783
  return { isValid: !0, errors: [] };
769
- const L = [];
784
+ const I = [];
770
785
  try {
771
- return E.properties && Object.entries(E.properties).forEach(([c, h]) => {
772
- var w;
773
- const g = a[c];
774
- if ((w = E.required) != null && w.includes(c) && g == null) {
775
- L.push(`Field '${c}' is required`);
786
+ return C.properties && Object.entries(C.properties).forEach(([S, g]) => {
787
+ var f;
788
+ const a = c[S];
789
+ if ((f = C.required) != null && f.includes(S) && a == null) {
790
+ I.push(`Field '${S}' is required`);
776
791
  return;
777
792
  }
778
- if (g != null) {
779
- if (h.type) {
780
- const j = h.type, Y = typeof g;
781
- j === "string" && Y !== "string" ? L.push(`Field '${c}' must be a string`) : (j === "number" || j === "integer") && Y !== "number" ? L.push(`Field '${c}' must be a number`) : j === "boolean" && Y !== "boolean" ? L.push(`Field '${c}' must be a boolean`) : j === "array" && !Array.isArray(g) && L.push(`Field '${c}' must be an array`);
793
+ if (a != null) {
794
+ if (g.type) {
795
+ const O = g.type, K = typeof a;
796
+ O === "string" && K !== "string" ? I.push(`Field '${S}' must be a string`) : (O === "number" || O === "integer") && K !== "number" ? I.push(`Field '${S}' must be a number`) : O === "boolean" && K !== "boolean" ? I.push(`Field '${S}' must be a boolean`) : O === "array" && !Array.isArray(a) && I.push(`Field '${S}' must be an array`);
782
797
  }
783
- h.minLength !== void 0 && typeof g == "string" && g.length < h.minLength && L.push(
784
- `Field '${c}' must be at least ${h.minLength} characters long`
785
- ), h.maxLength !== void 0 && typeof g == "string" && g.length > h.maxLength && L.push(
786
- `Field '${c}' must be no more than ${h.maxLength} characters long`
787
- ), h.minimum !== void 0 && typeof g == "number" && g < h.minimum && L.push(`Field '${c}' must be at least ${h.minimum}`), h.maximum !== void 0 && typeof g == "number" && g > h.maximum && L.push(`Field '${c}' must be no more than ${h.maximum}`), h.pattern && typeof g == "string" && (new RegExp(h.pattern).test(g) || L.push(`Field '${c}' does not match the required pattern`)), h.enum && !h.enum.includes(g) && L.push(`Field '${c}' must be one of: ${h.enum.join(", ")}`);
798
+ g.minLength !== void 0 && typeof a == "string" && a.length < g.minLength && I.push(
799
+ `Field '${S}' must be at least ${g.minLength} characters long`
800
+ ), g.maxLength !== void 0 && typeof a == "string" && a.length > g.maxLength && I.push(
801
+ `Field '${S}' must be no more than ${g.maxLength} characters long`
802
+ ), g.minimum !== void 0 && typeof a == "number" && a < g.minimum && I.push(`Field '${S}' must be at least ${g.minimum}`), g.maximum !== void 0 && typeof a == "number" && a > g.maximum && I.push(`Field '${S}' must be no more than ${g.maximum}`), g.pattern && typeof a == "string" && (new RegExp(g.pattern).test(a) || I.push(`Field '${S}' does not match the required pattern`)), g.enum && !g.enum.includes(a) && I.push(`Field '${S}' must be one of: ${g.enum.join(", ")}`);
788
803
  }
789
804
  }), {
790
- isValid: L.length === 0,
791
- errors: L
805
+ isValid: I.length === 0,
806
+ errors: I
792
807
  };
793
808
  } catch {
794
809
  return {
@@ -797,78 +812,78 @@ function Ct({ config: i, children: e }) {
797
812
  };
798
813
  }
799
814
  },
800
- [E]
815
+ [C]
801
816
  );
802
817
  te(() => {
803
- !i.initialTenant && p ? S ? G() : z(p) : !i.initialTenant && !p && (T(null), y(null), f(!1));
804
- }, [i.initialTenant, p, S, z, G]), te(() => {
805
- S != null && S.id ? $() : (C(null), P(null), A(!1));
806
- }, [S == null ? void 0 : S.id, $]);
807
- const M = ne(
808
- (a, L) => {
809
- const { mode: c = "reload", tokens: h, redirectPath: g } = L || {}, w = i.tenantMode || "selector";
810
- if (localStorage.setItem("tenant", a), w === "subdomain") {
811
- const j = window.location.hostname, Y = je(
812
- a,
813
- j,
818
+ !i.initialTenant && h ? b ? G() : F(h) : !i.initialTenant && !h && (P(null), y(null), p(!1));
819
+ }, [i.initialTenant, h, b, F, G]), te(() => {
820
+ b != null && b.id ? U() : (R(null), d(null), M(!1));
821
+ }, [b == null ? void 0 : b.id, U]);
822
+ const T = ne(
823
+ (c, I) => {
824
+ const { mode: S = "reload", tokens: g, redirectPath: a } = I || {}, f = i.tenantMode || "selector";
825
+ if (localStorage.setItem("tenant", c), f === "subdomain") {
826
+ const O = window.location.hostname, K = _e(
827
+ c,
828
+ O,
814
829
  i.baseDomain
815
830
  );
816
- if (!Y) {
831
+ if (!K) {
817
832
  console.warn(
818
833
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
819
- j
834
+ O
820
835
  );
821
836
  return;
822
837
  }
823
- const H = g || window.location.pathname, N = new URL(`${window.location.protocol}//${Y}${H}`);
824
- new URLSearchParams(window.location.search).forEach((F, K) => {
825
- K !== fe && N.searchParams.set(K, F);
826
- }), h && N.searchParams.set(fe, Ve(h)), window.location.href = N.toString();
827
- } else if (w === "selector") {
828
- const j = g || window.location.pathname, Y = new URLSearchParams(window.location.search);
829
- if (Y.set(i.selectorParam || "tenant", a), c === "reload") {
830
- const H = `${j}?${Y.toString()}${window.location.hash}`;
838
+ const H = a || window.location.pathname, N = new URL(`${window.location.protocol}//${K}${H}`);
839
+ new URLSearchParams(window.location.search).forEach(($, J) => {
840
+ J !== fe && N.searchParams.set(J, $);
841
+ }), g && N.searchParams.set(fe, Ge(g)), window.location.href = N.toString();
842
+ } else if (f === "selector") {
843
+ const O = a || window.location.pathname, K = new URLSearchParams(window.location.search);
844
+ if (K.set(i.selectorParam || "tenant", c), S === "reload") {
845
+ const H = `${O}?${K.toString()}${window.location.hash}`;
831
846
  window.location.href = H;
832
847
  } else {
833
- const H = `${j}?${Y.toString()}${window.location.hash}`;
834
- window.history.pushState({}, "", H), b(a), z(a);
848
+ const H = `${O}?${K.toString()}${window.location.hash}`;
849
+ window.history.pushState({}, "", H), w(c), F(c);
835
850
  }
836
851
  }
837
852
  },
838
- [i.tenantMode, i.selectorParam, i.baseDomain, z]
839
- ), I = X(() => ({
853
+ [i.tenantMode, i.selectorParam, i.baseDomain, F]
854
+ ), E = X(() => ({
840
855
  // Tenant info
841
- tenant: S,
842
- tenantSlug: p,
856
+ tenant: b,
857
+ tenantSlug: h,
843
858
  isTenantLoading: m,
844
859
  tenantError: u,
845
860
  retryTenant: () => {
846
- p && z(p);
861
+ h && F(h);
847
862
  },
848
863
  // Settings
849
- settings: R,
850
- settingsSchema: E,
851
- isSettingsLoading: q,
852
- settingsError: d,
864
+ settings: L,
865
+ settingsSchema: C,
866
+ isSettingsLoading: z,
867
+ settingsError: A,
853
868
  // Actions
854
869
  refreshSettings: _,
855
- switchTenant: M,
870
+ switchTenant: T,
856
871
  // Validation
857
- validateSettings: v
872
+ validateSettings: x
858
873
  }), [
859
- S,
860
- p,
874
+ b,
875
+ h,
861
876
  m,
862
877
  u,
863
- R,
864
- E,
865
- q,
866
- d,
878
+ L,
879
+ C,
880
+ z,
881
+ A,
867
882
  _,
868
- M,
869
- v
883
+ T,
884
+ x
870
885
  ]);
871
- return /* @__PURE__ */ n(Se.Provider, { value: I, children: e });
886
+ return /* @__PURE__ */ n(Se.Provider, { value: E, children: e });
872
887
  }
873
888
  function me() {
874
889
  const i = ce(Se);
@@ -879,8 +894,8 @@ function me() {
879
894
  function Me() {
880
895
  return ce(Se);
881
896
  }
882
- const $t = me;
883
- function Ft() {
897
+ const Dt = me;
898
+ function Ht() {
884
899
  const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = me();
885
900
  return {
886
901
  settings: i,
@@ -901,162 +916,180 @@ function se() {
901
916
  };
902
917
  }
903
918
  const Ie = he(null);
904
- function Dt({ config: i = {}, children: e }) {
905
- const { appId: t, baseUrl: r } = oe(), { tenant: s, tenantSlug: o, switchTenant: p } = me(), [b, k] = x(i.initialRoles || []), [S, T] = x(!i.initialRoles), [m, f] = x(null), [u, y] = x(!1), [R, C] = x(null), [q, A] = x(0), d = X(() => new we({
906
- tenantSlug: o,
907
- // SessionManager will generate storageKey internally
908
- onRefreshFailed: i.onRefreshFailed,
909
- baseUrl: r
910
- }), [o, r, i.onRefreshFailed]), P = X(() => {
911
- const c = new re(r);
912
- return c.setSessionManager(d), c;
913
- }, [r, d]), E = X(() => new Ue(new re(r)), [r]), z = X(() => new qe(P, d), [P, d]), G = X(() => new xe(new re(r)), [r]), $ = X(() => m || d.getUser(), [m, d]), _ = X(() => $ != null && $.roleId && b.find((c) => c.id === $.roleId) || null, [$, b]), v = X(() => (_ == null ? void 0 : _.permissions) || [], [_]), M = X(() => d.hasValidSession() && m !== null, [d, m]), I = 5 * 60 * 1e3, a = X(() => {
914
- const c = async (D = !1) => {
919
+ function Nt({ config: i = {}, children: e }) {
920
+ const { appId: t, baseUrl: r } = oe(), { tenant: s, tenantSlug: o, switchTenant: h } = me(), [w, k] = v(i.initialRoles || []), [b, P] = v(!i.initialRoles), [m, p] = v(null), [u, y] = v(!1), [L, R] = v(null), [z, M] = v(0), A = qe({
921
+ processed: !1,
922
+ tokens: null
923
+ });
924
+ A.current.processed || (A.current.processed = !0, A.current.tokens = Je(), console.log("[AuthProvider] SYNC: URL tokens extracted on init", {
925
+ found: !!A.current.tokens,
926
+ url: typeof window < "u" ? window.location.href : "SSR"
927
+ }));
928
+ const d = X(() => {
929
+ const a = new we({
930
+ tenantSlug: o,
931
+ // SessionManager will generate storageKey internally
932
+ onRefreshFailed: i.onRefreshFailed,
933
+ baseUrl: r
934
+ });
935
+ return A.current.tokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), a.setTokens({
936
+ accessToken: A.current.tokens.accessToken,
937
+ refreshToken: A.current.tokens.refreshToken,
938
+ expiresIn: A.current.tokens.expiresIn
939
+ }), console.log(
940
+ "[AuthProvider] SYNC: Session valid after saving tokens:",
941
+ a.hasValidSession()
942
+ )), a;
943
+ }, [o, r, i.onRefreshFailed]), C = X(() => {
944
+ const a = new re(r);
945
+ return a.setSessionManager(d), a;
946
+ }, [r, d]), F = X(() => new ze(new re(r)), [r]), G = X(() => new Oe(C, d), [C, d]), U = X(() => new ke(new re(r)), [r]), _ = X(() => m || d.getUser(), [m, d]), x = X(() => _ != null && _.roleId && w.find((a) => a.id === _.roleId) || null, [_, w]), T = X(() => (x == null ? void 0 : x.permissions) || [], [x]), E = X(() => d.hasValidSession() && m !== null, [d, m]), c = 5 * 60 * 1e3, I = X(() => {
947
+ const a = async (D = !1) => {
915
948
  try {
916
949
  if (!d.hasValidSession())
917
950
  return;
918
951
  const B = Date.now();
919
- if (!D && B - q < I && m)
952
+ if (!D && B - z < c && m)
920
953
  return;
921
- const W = d.getUserId();
922
- if (!W) {
954
+ const V = d.getUserId();
955
+ if (!V) {
923
956
  console.warn("[AuthProvider] No userId available in token or storage");
924
957
  return;
925
958
  }
926
- y(!0), C(null);
927
- const Z = await z.getUserById(W);
928
- f(Z), d.setUser(Z), A(Date.now());
959
+ y(!0), R(null);
960
+ const Z = await G.getUserById(V);
961
+ p(Z), d.setUser(Z), M(Date.now());
929
962
  } catch (B) {
930
- const J = B instanceof Error ? B : new Error("Failed to load user data");
931
- C(J), console.error("[AuthProvider] Failed to load user data:", J);
963
+ const Y = B instanceof Error ? B : new Error("Failed to load user data");
964
+ R(Y), console.error("[AuthProvider] Failed to load user data:", Y);
932
965
  } finally {
933
966
  y(!1);
934
967
  }
935
- }, h = async () => {
936
- await c();
937
- }, g = async (D) => {
938
- const { username: B, password: J, tenantSlug: W } = D;
968
+ }, f = async () => {
969
+ await a();
970
+ }, O = async (D) => {
971
+ const { username: B, password: Y, tenantSlug: V } = D;
939
972
  let Z = s == null ? void 0 : s.id, Q = o, ee = d;
940
- W && (Z = (await new ue(P, t).getPublicTenantInfo(W)).id, Q = W);
941
- const V = await E.login({
973
+ V && (Z = (await new ue(C, t).getPublicTenantInfo(V)).id, Q = V);
974
+ const j = await F.login({
942
975
  username: B,
943
- password: J,
976
+ password: Y,
944
977
  appId: t,
945
978
  tenantId: Z
946
- }), le = W && W !== o;
979
+ }), le = V && V !== o;
947
980
  if (le && (ee = new we({
948
981
  tenantSlug: Q,
949
982
  baseUrl: r
950
983
  })), ee.setTokens({
951
- accessToken: V.accessToken,
952
- refreshToken: V.refreshToken,
953
- expiresIn: V.expiresIn
954
- }), V.user) {
955
- ee.setUser(V.user), f(V.user);
984
+ accessToken: j.accessToken,
985
+ refreshToken: j.refreshToken,
986
+ expiresIn: j.expiresIn
987
+ }), j.user) {
988
+ ee.setUser(j.user), p(j.user);
956
989
  try {
957
- await c();
990
+ await a();
958
991
  } catch (de) {
959
992
  console.warn("Failed to load complete user data after login:", de);
960
993
  }
961
994
  }
962
- return le && Q && Q !== o && p(Q, {
995
+ return le && Q && Q !== o && h(Q, {
963
996
  tokens: {
964
- accessToken: V.accessToken,
965
- refreshToken: V.refreshToken,
966
- expiresIn: V.expiresIn
997
+ accessToken: j.accessToken,
998
+ refreshToken: j.refreshToken,
999
+ expiresIn: j.expiresIn
967
1000
  }
968
- }), V;
969
- }, w = async (D) => {
970
- const { email: B, phoneNumber: J, name: W, password: Z, lastName: Q, tenantId: ee } = D;
971
- if (!B && !J)
1001
+ }), j;
1002
+ }, K = async (D) => {
1003
+ const { email: B, phoneNumber: Y, name: V, password: Z, lastName: Q, tenantId: ee } = D;
1004
+ if (!B && !Y)
972
1005
  throw new Error("Either email or phoneNumber is required");
973
- if (!W || !Z)
1006
+ if (!V || !Z)
974
1007
  throw new Error("Name and password are required");
975
- const V = ee ?? (s == null ? void 0 : s.id);
976
- return await E.signup({
1008
+ const j = ee ?? (s == null ? void 0 : s.id);
1009
+ return await F.signup({
977
1010
  email: B,
978
- phoneNumber: J,
979
- name: W,
1011
+ phoneNumber: Y,
1012
+ name: V,
980
1013
  password: Z,
981
- tenantId: V,
1014
+ tenantId: j,
982
1015
  lastName: Q,
983
1016
  appId: t
984
1017
  });
985
- }, j = async (D) => {
986
- const { email: B, phoneNumber: J, name: W, password: Z, tenantName: Q, lastName: ee } = D;
987
- if (!B && !J)
1018
+ }, H = async (D) => {
1019
+ const { email: B, phoneNumber: Y, name: V, password: Z, tenantName: Q, lastName: ee } = D;
1020
+ if (!B && !Y)
988
1021
  throw new Error("Either email or phoneNumber is required");
989
- if (!W || !Z || !Q)
1022
+ if (!V || !Z || !Q)
990
1023
  throw new Error("Name, password, and tenantName are required");
991
- return await E.signupTenantAdmin({
1024
+ return await F.signupTenantAdmin({
992
1025
  email: B,
993
- phoneNumber: J,
994
- name: W,
1026
+ phoneNumber: Y,
1027
+ name: V,
995
1028
  password: Z,
996
1029
  tenantName: Q,
997
1030
  appId: t,
998
1031
  lastName: ee
999
1032
  });
1000
- }, Y = async (D) => {
1001
- const { currentPassword: B, newPassword: J } = D, W = await d.getAuthHeaders();
1002
- await E.changePassword({ currentPassword: B, newPassword: J }, W);
1003
- }, H = async (D) => {
1004
- const { email: B, tenantId: J } = D, W = J ?? (s == null ? void 0 : s.id);
1005
- if (!W)
1006
- throw new Error("tenantId is required for password reset");
1007
- await E.requestPasswordReset({ email: B, tenantId: W });
1008
1033
  }, N = async (D) => {
1009
- const { token: B, newPassword: J } = D;
1010
- await E.confirmPasswordReset({ token: B, newPassword: J });
1011
- }, O = async (D) => {
1012
- const { email: B, frontendUrl: J, name: W, lastName: Z, tenantId: Q } = D, ee = Q ?? (s == null ? void 0 : s.id);
1034
+ const { currentPassword: B, newPassword: Y } = D, V = await d.getAuthHeaders();
1035
+ await F.changePassword({ currentPassword: B, newPassword: Y }, V);
1036
+ }, W = async (D) => {
1037
+ const { email: B, tenantId: Y } = D, V = Y ?? (s == null ? void 0 : s.id);
1038
+ if (!V)
1039
+ throw new Error("tenantId is required for password reset");
1040
+ await F.requestPasswordReset({ email: B, tenantId: V });
1041
+ }, $ = async (D) => {
1042
+ const { token: B, newPassword: Y } = D;
1043
+ await F.confirmPasswordReset({ token: B, newPassword: Y });
1044
+ }, J = async (D) => {
1045
+ const { email: B, frontendUrl: Y, name: V, lastName: Z, tenantId: Q } = D, ee = Q ?? (s == null ? void 0 : s.id);
1013
1046
  if (!ee)
1014
1047
  throw new Error("tenantId is required for magic link authentication");
1015
- return await E.sendMagicLink({
1048
+ return await F.sendMagicLink({
1016
1049
  email: B,
1017
1050
  tenantId: ee,
1018
- frontendUrl: J,
1019
- name: W,
1051
+ frontendUrl: Y,
1052
+ name: V,
1020
1053
  lastName: Z,
1021
1054
  appId: t
1022
1055
  });
1023
- }, F = async (D) => {
1024
- const { token: B, email: J, tenantSlug: W } = D;
1056
+ }, ge = async (D) => {
1057
+ const { token: B, email: Y, tenantSlug: V } = D;
1025
1058
  let Z = s == null ? void 0 : s.id, Q = o, ee = d;
1026
- W && (Z = (await new ue(P, t).getPublicTenantInfo(W)).id, Q = W);
1027
- const V = await E.verifyMagicLink({
1059
+ V && (Z = (await new ue(C, t).getPublicTenantInfo(V)).id, Q = V);
1060
+ const j = await F.verifyMagicLink({
1028
1061
  token: B,
1029
- email: J,
1062
+ email: Y,
1030
1063
  appId: t,
1031
1064
  tenantId: Z
1032
- }), le = W && W !== o;
1065
+ }), le = V && V !== o;
1033
1066
  if (le && (ee = new we({
1034
1067
  tenantSlug: Q,
1035
1068
  baseUrl: r
1036
1069
  })), ee.setTokens({
1037
- accessToken: V.accessToken,
1038
- refreshToken: V.refreshToken,
1039
- expiresIn: V.expiresIn
1040
- }), V.user) {
1041
- ee.setUser(V.user), f(V.user);
1070
+ accessToken: j.accessToken,
1071
+ refreshToken: j.refreshToken,
1072
+ expiresIn: j.expiresIn
1073
+ }), j.user) {
1074
+ ee.setUser(j.user), p(j.user);
1042
1075
  try {
1043
- await c();
1076
+ await a();
1044
1077
  } catch (de) {
1045
1078
  console.warn("Failed to load complete user data after magic link login:", de);
1046
1079
  }
1047
1080
  }
1048
- return le && Q && Q !== o && p(Q, {
1081
+ return le && Q && Q !== o && h(Q, {
1049
1082
  tokens: {
1050
- accessToken: V.accessToken,
1051
- refreshToken: V.refreshToken,
1052
- expiresIn: V.expiresIn
1083
+ accessToken: j.accessToken,
1084
+ refreshToken: j.refreshToken,
1085
+ expiresIn: j.expiresIn
1053
1086
  }
1054
- }), V;
1055
- }, K = async () => {
1087
+ }), j;
1088
+ }, Ce = async () => {
1056
1089
  const D = d.getTokens();
1057
1090
  if (!(D != null && D.refreshToken))
1058
1091
  throw new Error("No refresh token available");
1059
- const B = await E.refreshToken({
1092
+ const B = await F.refreshToken({
1060
1093
  refreshToken: D.refreshToken
1061
1094
  });
1062
1095
  d.setTokens({
@@ -1064,124 +1097,136 @@ function Dt({ config: i = {}, children: e }) {
1064
1097
  refreshToken: B.refreshToken || D.refreshToken,
1065
1098
  expiresIn: B.expiresIn
1066
1099
  });
1067
- }, ge = () => {
1068
- d.clearSession(), f(null), C(null);
1069
- }, Ce = (D) => {
1100
+ }, Fe = () => {
1101
+ d.clearSession(), p(null), R(null);
1102
+ }, $e = (D) => {
1070
1103
  d.setTokens(D);
1071
- }, $e = () => d.hasValidSession(), Fe = () => {
1072
- d.clearSession(), f(null), C(null);
1073
- }, De = async () => {
1104
+ }, De = () => d.hasValidSession(), He = () => {
1105
+ d.clearSession(), p(null), R(null);
1106
+ }, Ne = async () => {
1074
1107
  if (t)
1075
1108
  try {
1076
- T(!0);
1077
- const { roles: D } = await G.getRolesByApp(t);
1109
+ P(!0);
1110
+ const { roles: D } = await U.getRolesByApp(t);
1078
1111
  k(D);
1079
1112
  } catch (D) {
1080
1113
  console.error("Failed to fetch roles:", D);
1081
1114
  } finally {
1082
- T(!1);
1115
+ P(!1);
1083
1116
  }
1084
- }, He = async () => {
1085
- await De();
1117
+ }, Ue = async () => {
1118
+ await Ne();
1086
1119
  }, ye = (D) => {
1087
- if (!v || v.length === 0)
1120
+ if (!T || T.length === 0)
1088
1121
  return !1;
1089
1122
  if (typeof D == "string")
1090
- return v.includes(D);
1123
+ return T.includes(D);
1091
1124
  const B = `${D.resource}.${D.action}`;
1092
- return v.includes(B);
1125
+ return T.includes(B);
1093
1126
  };
1094
1127
  return {
1095
1128
  // RFC-003: Authentication state
1096
- isAuthenticated: M,
1129
+ isAuthenticated: E,
1097
1130
  sessionManager: d,
1098
- authenticatedHttpService: P,
1099
- login: g,
1100
- signup: w,
1101
- signupTenantAdmin: j,
1102
- sendMagicLink: O,
1103
- verifyMagicLink: F,
1104
- changePassword: Y,
1105
- requestPasswordReset: H,
1106
- confirmPasswordReset: N,
1107
- refreshToken: K,
1108
- logout: ge,
1109
- setTokens: Ce,
1110
- hasValidSession: $e,
1111
- clearSession: Fe,
1131
+ authenticatedHttpService: C,
1132
+ login: O,
1133
+ signup: K,
1134
+ signupTenantAdmin: H,
1135
+ sendMagicLink: J,
1136
+ verifyMagicLink: ge,
1137
+ changePassword: N,
1138
+ requestPasswordReset: W,
1139
+ confirmPasswordReset: $,
1140
+ refreshToken: Ce,
1141
+ logout: Fe,
1142
+ setTokens: $e,
1143
+ hasValidSession: De,
1144
+ clearSession: He,
1112
1145
  currentUser: m,
1113
1146
  isUserLoading: u,
1114
- userError: R,
1115
- loadUserData: c,
1116
- refreshUser: h,
1117
- userRole: _,
1118
- userPermissions: v,
1119
- availableRoles: b,
1120
- rolesLoading: S,
1147
+ userError: L,
1148
+ loadUserData: a,
1149
+ refreshUser: f,
1150
+ userRole: x,
1151
+ userPermissions: T,
1152
+ availableRoles: w,
1153
+ rolesLoading: b,
1121
1154
  hasPermission: ye,
1122
1155
  hasAnyPermission: (D) => D.some((B) => ye(B)),
1123
1156
  hasAllPermissions: (D) => D.every((B) => ye(B)),
1124
- getUserPermissionStrings: () => v || [],
1125
- refreshRoles: He
1157
+ getUserPermissionStrings: () => T || [],
1158
+ refreshRoles: Ue
1126
1159
  };
1127
1160
  }, [
1128
- M,
1129
- d,
1130
- P,
1131
1161
  E,
1132
- z,
1162
+ d,
1163
+ C,
1164
+ F,
1133
1165
  G,
1166
+ U,
1134
1167
  t,
1135
1168
  s,
1136
1169
  o,
1137
- p,
1138
- b,
1170
+ h,
1171
+ w,
1139
1172
  m,
1140
1173
  u,
1141
- R,
1142
- _,
1143
- v,
1144
- q,
1145
- I
1174
+ L,
1175
+ x,
1176
+ T,
1177
+ z,
1178
+ c
1146
1179
  ]);
1147
1180
  te(() => {
1148
1181
  !i.initialRoles && t && (async () => {
1149
1182
  try {
1150
- T(!0);
1151
- const h = new re(r), g = new xe(h), { roles: w } = await g.getRolesByApp(t);
1152
- k(w);
1153
- } catch (h) {
1154
- console.error("Failed to fetch roles:", h);
1183
+ P(!0);
1184
+ const f = new re(r), O = new ke(f), { roles: K } = await O.getRolesByApp(t);
1185
+ k(K);
1186
+ } catch (f) {
1187
+ console.error("Failed to fetch roles:", f);
1155
1188
  } finally {
1156
- T(!1);
1189
+ P(!1);
1157
1190
  }
1158
1191
  })();
1159
1192
  }, [t, r, i.initialRoles]);
1160
- const L = Be(!1);
1193
+ const [S, g] = v(!1);
1161
1194
  return te(() => {
1162
- if (L.current) return;
1163
- const c = Ge();
1164
- c && (L.current = !0, d.setTokens({
1165
- accessToken: c.accessToken,
1166
- refreshToken: c.refreshToken,
1167
- expiresIn: c.expiresIn
1168
- }), Ke(), a.loadUserData().catch(() => {
1169
- }));
1170
- }, [d, a]), te(() => {
1171
- const c = d.getUser();
1172
- c && d.hasValidSession() && f(c);
1195
+ S || (g(!0), A.current.tokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), Ye(), console.log("[AuthProvider] EFFECT: Loading user data after URL token consumption..."), I.loadUserData().catch((a) => {
1196
+ console.error(
1197
+ "[AuthProvider] Failed to load user data after URL token consumption:",
1198
+ a
1199
+ );
1200
+ })));
1201
+ }, [I, S]), te(() => {
1202
+ const a = d.getUser();
1203
+ a && d.hasValidSession() && p(a);
1173
1204
  }, [d]), te(() => {
1174
- !m && !u && a.loadUserData().catch(() => {
1175
- });
1176
- }, [m, u, a]), te(() => {
1205
+ if (console.log("[AuthProvider] Auto-load effect running", {
1206
+ hasCurrentUser: !!m,
1207
+ isUserLoading: u,
1208
+ hasValidSession: d.hasValidSession(),
1209
+ urlTokensCleanedUp: S,
1210
+ hadUrlTokens: !!A.current.tokens
1211
+ }), !S) {
1212
+ console.log("[AuthProvider] Waiting for URL tokens cleanup before auto-load");
1213
+ return;
1214
+ }
1215
+ if (A.current.tokens) {
1216
+ console.log("[AuthProvider] URL tokens present, skipping auto-load (already handled)");
1217
+ return;
1218
+ }
1219
+ !m && !u && (console.log("[AuthProvider] Auto-loading user data..."), I.loadUserData().catch(() => {
1220
+ }));
1221
+ }, [m, u, I, d, S]), te(() => {
1177
1222
  if (!d.hasValidSession() || !m)
1178
1223
  return;
1179
- const c = setInterval(() => {
1180
- a.loadUserData().catch(() => {
1224
+ const a = setInterval(() => {
1225
+ I.loadUserData().catch(() => {
1181
1226
  });
1182
- }, I);
1183
- return () => clearInterval(c);
1184
- }, [d, m, a, I]), /* @__PURE__ */ n(Ie.Provider, { value: a, children: e });
1227
+ }, c);
1228
+ return () => clearInterval(a);
1229
+ }, [d, m, I, c]), /* @__PURE__ */ n(Ie.Provider, { value: I, children: e });
1185
1230
  }
1186
1231
  function ae() {
1187
1232
  const i = ce(Ie);
@@ -1189,7 +1234,7 @@ function ae() {
1189
1234
  throw new Error("useAuth must be used within an AuthProvider");
1190
1235
  return i;
1191
1236
  }
1192
- class Je {
1237
+ class Qe {
1193
1238
  constructor(e, t) {
1194
1239
  this.httpService = e, this.sessionManager = t;
1195
1240
  }
@@ -1270,57 +1315,57 @@ class Je {
1270
1315
  }
1271
1316
  }
1272
1317
  const Le = he(null);
1273
- function Ht({ config: i = {}, children: e }) {
1274
- const { baseUrl: t, appId: r } = oe(), { tenant: s } = se(), [o, p] = x([]), [b, k] = x(!1), [S, T] = x(null), m = X(() => {
1318
+ function Ut({ config: i = {}, children: e }) {
1319
+ const { baseUrl: t, appId: r } = oe(), { tenant: s } = se(), [o, h] = v([]), [w, k] = v(!1), [b, P] = v(null), m = X(() => {
1275
1320
  const y = new re(t);
1276
- return new Je(y);
1277
- }, [t]), f = async () => {
1321
+ return new Qe(y);
1322
+ }, [t]), p = async () => {
1278
1323
  if (!(s != null && s.id)) {
1279
- p([]);
1324
+ h([]);
1280
1325
  return;
1281
1326
  }
1282
- k(!0), T(null);
1327
+ k(!0), P(null);
1283
1328
  try {
1284
1329
  const y = await m.getTenantFeatureFlags(s.id, r);
1285
- p(y);
1330
+ h(y);
1286
1331
  } catch (y) {
1287
- const R = y instanceof Error ? y.message : "Failed to fetch feature flags";
1288
- T(R), i.onError && i.onError(y instanceof Error ? y : new Error(R));
1332
+ const L = y instanceof Error ? y.message : "Failed to fetch feature flags";
1333
+ P(L), i.onError && i.onError(y instanceof Error ? y : new Error(L));
1289
1334
  } finally {
1290
1335
  k(!1);
1291
1336
  }
1292
1337
  };
1293
1338
  te(() => {
1294
- f();
1295
- const y = i.refreshInterval || 5 * 60 * 1e3, R = setInterval(f, y);
1296
- return () => clearInterval(R);
1339
+ p();
1340
+ const y = i.refreshInterval || 5 * 60 * 1e3, L = setInterval(p, y);
1341
+ return () => clearInterval(L);
1297
1342
  }, [s == null ? void 0 : s.id, i.refreshInterval]);
1298
1343
  const u = X(() => ({
1299
1344
  featureFlags: o,
1300
- loading: b,
1301
- error: S,
1302
- isEnabled: (A) => {
1303
- const d = o.find((P) => P.key === A);
1304
- return (d == null ? void 0 : d.value) === !0;
1345
+ loading: w,
1346
+ error: b,
1347
+ isEnabled: (M) => {
1348
+ const A = o.find((d) => d.key === M);
1349
+ return (A == null ? void 0 : A.value) === !0;
1305
1350
  },
1306
- getFlag: (A) => o.find((d) => d.key === A),
1307
- getFlagState: (A) => {
1308
- const d = o.find((P) => P.key === A);
1309
- return d ? d.value ? "enabled" : "disabled" : "not_found";
1351
+ getFlag: (M) => o.find((A) => A.key === M),
1352
+ getFlagState: (M) => {
1353
+ const A = o.find((d) => d.key === M);
1354
+ return A ? A.value ? "enabled" : "disabled" : "not_found";
1310
1355
  },
1311
1356
  refresh: async () => {
1312
- await f();
1357
+ await p();
1313
1358
  }
1314
- }), [o, b, S]);
1359
+ }), [o, w, b]);
1315
1360
  return /* @__PURE__ */ n(Le.Provider, { value: u, children: e });
1316
1361
  }
1317
- function Ye() {
1362
+ function Xe() {
1318
1363
  const i = ce(Le);
1319
1364
  if (!i)
1320
1365
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1321
1366
  return i;
1322
1367
  }
1323
- class Qe {
1368
+ class Ze {
1324
1369
  constructor(e, t) {
1325
1370
  this.httpService = e, this.sessionManager = t;
1326
1371
  }
@@ -1386,25 +1431,25 @@ class Qe {
1386
1431
  )).data;
1387
1432
  }
1388
1433
  }
1389
- const Ee = he(void 0);
1390
- function Nt({ config: i = {}, children: e }) {
1391
- const { baseUrl: t } = oe(), { tenant: r } = se(), [s, o] = x(null), [p, b] = x(!1), [k, S] = x(null), T = X(() => {
1434
+ const Re = he(void 0);
1435
+ function Bt({ config: i = {}, children: e }) {
1436
+ const { baseUrl: t } = oe(), { tenant: r } = se(), [s, o] = v(null), [h, w] = v(!1), [k, b] = v(null), P = X(() => {
1392
1437
  const u = new re(t);
1393
- return new Qe(u);
1438
+ return new Ze(u);
1394
1439
  }, [t]), m = async () => {
1395
1440
  if (!(r != null && r.id)) {
1396
1441
  o(null);
1397
1442
  return;
1398
1443
  }
1399
- b(!0), S(null);
1444
+ w(!0), b(null);
1400
1445
  try {
1401
- const u = await T.getTenantSubscriptionFeatures(r.id);
1446
+ const u = await P.getTenantSubscriptionFeatures(r.id);
1402
1447
  o(u);
1403
1448
  } catch (u) {
1404
1449
  const y = u instanceof Error ? u.message : "Failed to fetch subscription";
1405
- S(y), i.onError && i.onError(u instanceof Error ? u : new Error(y));
1450
+ b(y), i.onError && i.onError(u instanceof Error ? u : new Error(y));
1406
1451
  } finally {
1407
- b(!1);
1452
+ w(!1);
1408
1453
  }
1409
1454
  };
1410
1455
  te(() => {
@@ -1412,38 +1457,38 @@ function Nt({ config: i = {}, children: e }) {
1412
1457
  const u = i.refreshInterval || 10 * 60 * 1e3, y = setInterval(m, u);
1413
1458
  return () => clearInterval(y);
1414
1459
  }, [r == null ? void 0 : r.id, i.refreshInterval]);
1415
- const f = X(() => {
1460
+ const p = X(() => {
1416
1461
  const u = (s == null ? void 0 : s.features) || [];
1417
1462
  return {
1418
1463
  subscription: s,
1419
1464
  features: u,
1420
- loading: p,
1465
+ loading: h,
1421
1466
  error: k,
1422
- isFeatureEnabled: (d) => {
1423
- const P = u.find((E) => E.key === d);
1424
- return P ? P.type === "BOOLEAN" || P.type === "boolean" ? P.value === !0 : !!P.value : !1;
1467
+ isFeatureEnabled: (A) => {
1468
+ const d = u.find((C) => C.key === A);
1469
+ return d ? d.type === "BOOLEAN" || d.type === "boolean" ? d.value === !0 : !!d.value : !1;
1425
1470
  },
1426
- getFeature: (d) => u.find((P) => P.key === d),
1427
- getFeatureValue: (d, P) => {
1428
- const E = u.find((z) => z.key === d);
1429
- return E ? E.value : P;
1471
+ getFeature: (A) => u.find((d) => d.key === A),
1472
+ getFeatureValue: (A, d) => {
1473
+ const C = u.find((F) => F.key === A);
1474
+ return C ? C.value : d;
1430
1475
  },
1431
- hasAllowedPlan: (d) => !s || !s.isActive ? !1 : d.includes(s.planId),
1476
+ hasAllowedPlan: (A) => !s || !s.isActive ? !1 : A.includes(s.planId),
1432
1477
  refresh: async () => {
1433
1478
  await m();
1434
1479
  }
1435
1480
  };
1436
- }, [s, p, k]);
1437
- return /* @__PURE__ */ n(Ee.Provider, { value: f, children: e });
1481
+ }, [s, h, k]);
1482
+ return /* @__PURE__ */ n(Re.Provider, { value: p, children: e });
1438
1483
  }
1439
- function Xe() {
1440
- const i = ce(Ee);
1484
+ function et() {
1485
+ const i = ce(Re);
1441
1486
  if (i === void 0)
1442
1487
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1443
1488
  return i;
1444
1489
  }
1445
1490
  var ie = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(ie || {});
1446
- const ke = () => /* @__PURE__ */ l(
1491
+ const xe = () => /* @__PURE__ */ l(
1447
1492
  "div",
1448
1493
  {
1449
1494
  style: {
@@ -1480,7 +1525,7 @@ const ke = () => /* @__PURE__ */ l(
1480
1525
  )
1481
1526
  ]
1482
1527
  }
1483
- ), Te = ({
1528
+ ), Ae = ({
1484
1529
  userType: i,
1485
1530
  minUserType: e,
1486
1531
  missingPermissions: t
@@ -1502,7 +1547,7 @@ const ke = () => /* @__PURE__ */ l(
1502
1547
  children: [
1503
1548
  /* @__PURE__ */ n("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1504
1549
  /* @__PURE__ */ n("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1505
- e && i ? /* @__PURE__ */ l(U, { children: [
1550
+ e && i ? /* @__PURE__ */ l(q, { children: [
1506
1551
  /* @__PURE__ */ l("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1507
1552
  "This content requires ",
1508
1553
  /* @__PURE__ */ n("strong", { children: e }),
@@ -1512,7 +1557,7 @@ const ke = () => /* @__PURE__ */ l(
1512
1557
  "Your current access level: ",
1513
1558
  /* @__PURE__ */ n("strong", { children: i })
1514
1559
  ] })
1515
- ] }) : /* @__PURE__ */ l(U, { children: [
1560
+ ] }) : /* @__PURE__ */ l(q, { children: [
1516
1561
  /* @__PURE__ */ n("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1517
1562
  t && t.length > 0 && /* @__PURE__ */ l("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1518
1563
  "Required permissions: ",
@@ -1521,7 +1566,7 @@ const ke = () => /* @__PURE__ */ l(
1521
1566
  ] })
1522
1567
  ]
1523
1568
  }
1524
- ), Ze = (i, e) => {
1569
+ ), tt = (i, e) => {
1525
1570
  const t = {
1526
1571
  [ie.USER]: 1,
1527
1572
  [ie.TENANT_ADMIN]: 2,
@@ -1529,28 +1574,28 @@ const ke = () => /* @__PURE__ */ l(
1529
1574
  };
1530
1575
  return t[i] >= t[e];
1531
1576
  };
1532
- function Bt({
1577
+ function qt({
1533
1578
  children: i,
1534
1579
  fallback: e,
1535
1580
  minUserType: t,
1536
1581
  requiredPermissions: r,
1537
1582
  requireAllPermissions: s = !1
1538
1583
  }) {
1539
- const { hasValidSession: o, sessionManager: p, hasPermission: b, hasAnyPermission: k, hasAllPermissions: S } = ae();
1584
+ const { hasValidSession: o, sessionManager: h, hasPermission: w, hasAnyPermission: k, hasAllPermissions: b } = ae();
1540
1585
  if (!o())
1541
- return /* @__PURE__ */ n(U, { children: e || /* @__PURE__ */ n(ke, {}) });
1542
- const T = p.getUser();
1543
- if (!T)
1544
- return /* @__PURE__ */ n(U, { children: e || /* @__PURE__ */ n(ke, {}) });
1545
- if (t && !Ze(T.userType, t))
1546
- return /* @__PURE__ */ n(Te, { userType: T.userType, minUserType: t });
1547
- if (r && r.length > 0 && !(s ? S(r) : k(r))) {
1548
- const f = r.filter((u) => !b(u)).map((u) => typeof u == "string" ? u : u.name);
1549
- return /* @__PURE__ */ n(Te, { missingPermissions: f });
1550
- }
1551
- return /* @__PURE__ */ n(U, { children: i });
1586
+ return /* @__PURE__ */ n(q, { children: e || /* @__PURE__ */ n(xe, {}) });
1587
+ const P = h.getUser();
1588
+ if (!P)
1589
+ return /* @__PURE__ */ n(q, { children: e || /* @__PURE__ */ n(xe, {}) });
1590
+ if (t && !tt(P.userType, t))
1591
+ return /* @__PURE__ */ n(Ae, { userType: P.userType, minUserType: t });
1592
+ if (r && r.length > 0 && !(s ? b(r) : k(r))) {
1593
+ const p = r.filter((u) => !w(u)).map((u) => typeof u == "string" ? u : u.name);
1594
+ return /* @__PURE__ */ n(Ae, { missingPermissions: p });
1595
+ }
1596
+ return /* @__PURE__ */ n(q, { children: i });
1552
1597
  }
1553
- const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1598
+ const rt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1554
1599
  "div",
1555
1600
  {
1556
1601
  style: {
@@ -1586,7 +1631,7 @@ const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1586
1631
  }
1587
1632
  )
1588
1633
  }
1589
- ), Ae = ({
1634
+ ), Te = ({
1590
1635
  userType: i,
1591
1636
  minUserType: e,
1592
1637
  missingPermissions: t
@@ -1616,7 +1661,7 @@ const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1616
1661
  children: [
1617
1662
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1618
1663
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1619
- e && i ? /* @__PURE__ */ l(U, { children: [
1664
+ e && i ? /* @__PURE__ */ l(q, { children: [
1620
1665
  /* @__PURE__ */ l("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1621
1666
  "This page requires ",
1622
1667
  /* @__PURE__ */ n("strong", { children: e }),
@@ -1626,7 +1671,7 @@ const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1626
1671
  "Your current access level: ",
1627
1672
  /* @__PURE__ */ n("strong", { children: i })
1628
1673
  ] })
1629
- ] }) : /* @__PURE__ */ l(U, { children: [
1674
+ ] }) : /* @__PURE__ */ l(q, { children: [
1630
1675
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1631
1676
  t && t.length > 0 && /* @__PURE__ */ l("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1632
1677
  "Required permissions: ",
@@ -1637,7 +1682,7 @@ const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1637
1682
  }
1638
1683
  )
1639
1684
  }
1640
- ), tt = (i, e) => {
1685
+ ), nt = (i, e) => {
1641
1686
  const t = {
1642
1687
  [ie.USER]: 1,
1643
1688
  [ie.TENANT_ADMIN]: 2,
@@ -1645,7 +1690,7 @@ const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1645
1690
  };
1646
1691
  return t[i] >= t[e];
1647
1692
  };
1648
- function Ut({
1693
+ function zt({
1649
1694
  children: i,
1650
1695
  redirectTo: e = "/login",
1651
1696
  minUserType: t,
@@ -1653,24 +1698,24 @@ function Ut({
1653
1698
  requireAllPermissions: s = !1,
1654
1699
  fallback: o
1655
1700
  }) {
1656
- const { hasValidSession: p, sessionManager: b, hasPermission: k, hasAnyPermission: S, hasAllPermissions: T } = ae(), m = be();
1657
- if (!p())
1658
- return o ? /* @__PURE__ */ n(U, { children: o }) : /* @__PURE__ */ l(U, { children: [
1659
- /* @__PURE__ */ n(et, { redirectPath: e }),
1701
+ const { hasValidSession: h, sessionManager: w, hasPermission: k, hasAnyPermission: b, hasAllPermissions: P } = ae(), m = be();
1702
+ if (!h())
1703
+ return o ? /* @__PURE__ */ n(q, { children: o }) : /* @__PURE__ */ l(q, { children: [
1704
+ /* @__PURE__ */ n(rt, { redirectPath: e }),
1660
1705
  /* @__PURE__ */ n(pe, { to: e, state: { from: m.pathname }, replace: !0 })
1661
1706
  ] });
1662
- const f = b.getUser();
1663
- if (!f)
1707
+ const p = w.getUser();
1708
+ if (!p)
1664
1709
  return /* @__PURE__ */ n(pe, { to: e, state: { from: m.pathname }, replace: !0 });
1665
- if (t && !tt(f.userType, t))
1666
- return /* @__PURE__ */ n(Ae, { userType: f.userType, minUserType: t });
1667
- if (r && r.length > 0 && !(s ? T(r) : S(r))) {
1668
- const y = r.filter((R) => !k(R)).map((R) => typeof R == "string" ? R : R.name);
1669
- return /* @__PURE__ */ n(Ae, { missingPermissions: y });
1710
+ if (t && !nt(p.userType, t))
1711
+ return /* @__PURE__ */ n(Te, { userType: p.userType, minUserType: t });
1712
+ if (r && r.length > 0 && !(s ? P(r) : b(r))) {
1713
+ const y = r.filter((L) => !k(L)).map((L) => typeof L == "string" ? L : L.name);
1714
+ return /* @__PURE__ */ n(Te, { missingPermissions: y });
1670
1715
  }
1671
- return /* @__PURE__ */ n(U, { children: i });
1716
+ return /* @__PURE__ */ n(q, { children: i });
1672
1717
  }
1673
- const rt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1718
+ const st = ({ redirectPath: i }) => /* @__PURE__ */ n(
1674
1719
  "div",
1675
1720
  {
1676
1721
  style: {
@@ -1707,14 +1752,14 @@ const rt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1707
1752
  )
1708
1753
  }
1709
1754
  );
1710
- function qt({ children: i, redirectTo: e = "/", fallback: t }) {
1711
- const { tenant: r, isLoading: s, error: o } = se(), p = be();
1712
- return s || o ? null : r ? /* @__PURE__ */ n(U, { children: i }) : t ? /* @__PURE__ */ n(U, { children: t }) : /* @__PURE__ */ l(U, { children: [
1713
- /* @__PURE__ */ n(rt, { redirectPath: e }),
1714
- /* @__PURE__ */ n(pe, { to: e, state: { from: p.pathname }, replace: !0 })
1755
+ function Ot({ children: i, redirectTo: e = "/", fallback: t }) {
1756
+ const { tenant: r, isLoading: s, error: o } = se(), h = be();
1757
+ return s || o ? null : r ? /* @__PURE__ */ n(q, { children: i }) : t ? /* @__PURE__ */ n(q, { children: t }) : /* @__PURE__ */ l(q, { children: [
1758
+ /* @__PURE__ */ n(st, { redirectPath: e }),
1759
+ /* @__PURE__ */ n(pe, { to: e, state: { from: h.pathname }, replace: !0 })
1715
1760
  ] });
1716
1761
  }
1717
- const nt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1762
+ const it = ({ redirectPath: i }) => /* @__PURE__ */ n(
1718
1763
  "div",
1719
1764
  {
1720
1765
  style: {
@@ -1751,14 +1796,14 @@ const nt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1751
1796
  )
1752
1797
  }
1753
1798
  );
1754
- function zt({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1755
- const { tenant: r, isLoading: s, error: o } = se(), p = be();
1756
- return s || o ? null : r ? t ? /* @__PURE__ */ n(U, { children: t }) : /* @__PURE__ */ l(U, { children: [
1757
- /* @__PURE__ */ n(nt, { redirectPath: e }),
1758
- /* @__PURE__ */ n(pe, { to: e, state: { from: p.pathname }, replace: !0 })
1759
- ] }) : /* @__PURE__ */ n(U, { children: i });
1799
+ function Wt({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1800
+ const { tenant: r, isLoading: s, error: o } = se(), h = be();
1801
+ return s || o ? null : r ? t ? /* @__PURE__ */ n(q, { children: t }) : /* @__PURE__ */ l(q, { children: [
1802
+ /* @__PURE__ */ n(it, { redirectPath: e }),
1803
+ /* @__PURE__ */ n(pe, { to: e, state: { from: h.pathname }, replace: !0 })
1804
+ ] }) : /* @__PURE__ */ n(q, { children: i });
1760
1805
  }
1761
- const st = () => /* @__PURE__ */ l(
1806
+ const ot = () => /* @__PURE__ */ l(
1762
1807
  "div",
1763
1808
  {
1764
1809
  style: {
@@ -1775,14 +1820,14 @@ const st = () => /* @__PURE__ */ l(
1775
1820
  ]
1776
1821
  }
1777
1822
  );
1778
- function Ot({
1823
+ function Vt({
1779
1824
  children: i,
1780
- fallback: e = /* @__PURE__ */ n(st, {}),
1825
+ fallback: e = /* @__PURE__ */ n(ot, {}),
1781
1826
  allowedPlans: t,
1782
1827
  requiredFeature: r
1783
1828
  }) {
1784
- const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: p, loading: b } = Xe();
1785
- return b ? /* @__PURE__ */ n(
1829
+ const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: h, loading: w } = et();
1830
+ return w ? /* @__PURE__ */ n(
1786
1831
  "div",
1787
1832
  {
1788
1833
  style: {
@@ -1792,9 +1837,9 @@ function Ot({
1792
1837
  },
1793
1838
  children: "Loading subscription..."
1794
1839
  }
1795
- ) : s ? s.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ n(U, { children: e }) : r && !p(r) ? /* @__PURE__ */ n(U, { children: e }) : /* @__PURE__ */ n(U, { children: i }) : /* @__PURE__ */ n(U, { children: e }) : /* @__PURE__ */ n(U, { children: e });
1840
+ ) : s ? s.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ n(q, { children: e }) : r && !h(r) ? /* @__PURE__ */ n(q, { children: e }) : /* @__PURE__ */ n(q, { children: i }) : /* @__PURE__ */ n(q, { children: e }) : /* @__PURE__ */ n(q, { children: e });
1796
1841
  }
1797
- const it = ({ flagName: i }) => /* @__PURE__ */ l(
1842
+ const at = ({ flagName: i }) => /* @__PURE__ */ l(
1798
1843
  "div",
1799
1844
  {
1800
1845
  style: {
@@ -1821,8 +1866,8 @@ const it = ({ flagName: i }) => /* @__PURE__ */ l(
1821
1866
  ]
1822
1867
  }
1823
1868
  );
1824
- function Wt({ name: i, children: e, fallback: t }) {
1825
- const { isEnabled: r, loading: s } = Ye();
1869
+ function jt({ name: i, children: e, fallback: t }) {
1870
+ const { isEnabled: r, loading: s } = Xe();
1826
1871
  return s ? /* @__PURE__ */ n(
1827
1872
  "div",
1828
1873
  {
@@ -1836,9 +1881,9 @@ function Wt({ name: i, children: e, fallback: t }) {
1836
1881
  },
1837
1882
  children: "Loading feature flags..."
1838
1883
  }
1839
- ) : r(i) ? /* @__PURE__ */ n(U, { children: e }) : /* @__PURE__ */ n(U, { children: t || /* @__PURE__ */ n(it, { flagName: i }) });
1884
+ ) : r(i) ? /* @__PURE__ */ n(q, { children: e }) : /* @__PURE__ */ n(q, { children: t || /* @__PURE__ */ n(at, { flagName: i }) });
1840
1885
  }
1841
- const ot = () => /* @__PURE__ */ l(
1886
+ const lt = () => /* @__PURE__ */ l(
1842
1887
  "svg",
1843
1888
  {
1844
1889
  width: "16",
@@ -1855,7 +1900,7 @@ const ot = () => /* @__PURE__ */ l(
1855
1900
  /* @__PURE__ */ n("circle", { cx: "12", cy: "12", r: "3" })
1856
1901
  ]
1857
1902
  }
1858
- ), at = () => /* @__PURE__ */ l(
1903
+ ), ct = () => /* @__PURE__ */ l(
1859
1904
  "svg",
1860
1905
  {
1861
1906
  width: "16",
@@ -1872,10 +1917,10 @@ const ot = () => /* @__PURE__ */ l(
1872
1917
  /* @__PURE__ */ n("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
1873
1918
  ]
1874
1919
  }
1875
- ), lt = {
1876
- showPassword: /* @__PURE__ */ n(ot, {}),
1877
- hidePassword: /* @__PURE__ */ n(at, {})
1878
- }, ct = {
1920
+ ), dt = {
1921
+ showPassword: /* @__PURE__ */ n(lt, {}),
1922
+ hidePassword: /* @__PURE__ */ n(ct, {})
1923
+ }, ut = {
1879
1924
  title: "Sign In",
1880
1925
  usernameLabel: "Email or Phone",
1881
1926
  usernamePlaceholder: "Enter your email or phone number",
@@ -1889,7 +1934,7 @@ const ot = () => /* @__PURE__ */ l(
1889
1934
  magicLinkLink: "Use Magic Link",
1890
1935
  errorMessage: "Invalid credentials",
1891
1936
  loadingText: "Signing in..."
1892
- }, dt = {
1937
+ }, ht = {
1893
1938
  container: {
1894
1939
  maxWidth: "400px",
1895
1940
  width: "100%",
@@ -1996,133 +2041,133 @@ const ot = () => /* @__PURE__ */ l(
1996
2041
  fontSize: "0.875rem"
1997
2042
  }
1998
2043
  };
1999
- function jt({
2044
+ function _t({
2000
2045
  copy: i = {},
2001
2046
  styles: e = {},
2002
2047
  icons: t = {},
2003
2048
  onSuccess: r,
2004
2049
  onError: s,
2005
2050
  onForgotPassword: o,
2006
- onSignupClick: p,
2007
- onMagicLinkClick: b,
2051
+ onSignupClick: h,
2052
+ onMagicLinkClick: w,
2008
2053
  showForgotPassword: k = !0,
2009
- showSignupLink: S = !0,
2010
- showMagicLinkOption: T = !0,
2054
+ showSignupLink: b = !0,
2055
+ showMagicLinkOption: P = !0,
2011
2056
  className: m
2012
2057
  }) {
2013
- const [f, u] = x(""), [y, R] = x(""), [C, q] = x(!1), [A, d] = x(!1), [P, E] = x(""), [z, G] = x({}), { login: $ } = ae(), { tenant: _ } = se(), v = { ...ct, ...i }, M = { ...dt, ...e }, I = { ...lt, ...t }, a = () => {
2014
- const g = {};
2015
- return f.trim() || (g.username = !0), y.trim() || (g.password = !0), G(g), Object.keys(g).length === 0;
2016
- }, L = async (g) => {
2017
- if (g.preventDefault(), !!a()) {
2058
+ const [p, u] = v(""), [y, L] = v(""), [R, z] = v(!1), [M, A] = v(!1), [d, C] = v(""), [F, G] = v({}), { login: U } = ae(), { tenant: _ } = se(), x = { ...ut, ...i }, T = { ...ht, ...e }, E = { ...dt, ...t }, c = () => {
2059
+ const a = {};
2060
+ return p.trim() || (a.username = !0), y.trim() || (a.password = !0), G(a), Object.keys(a).length === 0;
2061
+ }, I = async (a) => {
2062
+ if (a.preventDefault(), !!c()) {
2018
2063
  if (!(_ != null && _.id)) {
2019
- E("Tenant not found");
2064
+ C("Tenant not found");
2020
2065
  return;
2021
2066
  }
2022
- d(!0), E("");
2067
+ A(!0), C("");
2023
2068
  try {
2024
- const w = await $({
2025
- username: f,
2069
+ const f = await U({
2070
+ username: p,
2026
2071
  password: y
2027
2072
  // tenantId inferred from context automatically
2028
2073
  });
2029
- r == null || r(w);
2030
- } catch (w) {
2031
- const j = w.message || v.errorMessage;
2032
- E(j), s == null || s(j);
2074
+ r == null || r(f);
2075
+ } catch (f) {
2076
+ const O = f.message || x.errorMessage;
2077
+ C(O), s == null || s(O);
2033
2078
  } finally {
2034
- d(!1);
2079
+ A(!1);
2035
2080
  }
2036
2081
  }
2037
- }, c = (g) => ({
2038
- ...M.input,
2039
- ...z[g] ? M.inputError : {}
2040
- }), h = () => ({
2041
- ...M.button,
2042
- ...A ? M.buttonLoading : {},
2043
- ...!f || !y || A ? M.buttonDisabled : {}
2082
+ }, S = (a) => ({
2083
+ ...T.input,
2084
+ ...F[a] ? T.inputError : {}
2085
+ }), g = () => ({
2086
+ ...T.button,
2087
+ ...M ? T.buttonLoading : {},
2088
+ ...!p || !y || M ? T.buttonDisabled : {}
2044
2089
  });
2045
- return /* @__PURE__ */ l("div", { className: m, style: M.container, children: [
2046
- /* @__PURE__ */ n("h2", { style: M.title, children: v.title }),
2047
- /* @__PURE__ */ l("form", { onSubmit: L, style: M.form, children: [
2048
- /* @__PURE__ */ l("div", { style: M.fieldGroup, children: [
2049
- /* @__PURE__ */ n("label", { style: M.label, children: v.usernameLabel }),
2090
+ return /* @__PURE__ */ l("div", { className: m, style: T.container, children: [
2091
+ /* @__PURE__ */ n("h2", { style: T.title, children: x.title }),
2092
+ /* @__PURE__ */ l("form", { onSubmit: I, style: T.form, children: [
2093
+ /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2094
+ /* @__PURE__ */ n("label", { style: T.label, children: x.usernameLabel }),
2050
2095
  /* @__PURE__ */ n(
2051
2096
  "input",
2052
2097
  {
2053
2098
  id: "username",
2054
2099
  name: "username",
2055
2100
  type: "text",
2056
- value: f,
2057
- onChange: (g) => {
2058
- u(g.target.value), z.username && G((w) => ({ ...w, username: !1 }));
2101
+ value: p,
2102
+ onChange: (a) => {
2103
+ u(a.target.value), F.username && G((f) => ({ ...f, username: !1 }));
2059
2104
  },
2060
- placeholder: v.usernamePlaceholder,
2061
- style: c("username"),
2062
- disabled: A
2105
+ placeholder: x.usernamePlaceholder,
2106
+ style: S("username"),
2107
+ disabled: M
2063
2108
  }
2064
2109
  )
2065
2110
  ] }),
2066
- /* @__PURE__ */ l("div", { style: M.fieldGroup, children: [
2067
- /* @__PURE__ */ n("label", { style: M.label, children: v.passwordLabel }),
2068
- /* @__PURE__ */ l("div", { style: M.inputContainer, children: [
2111
+ /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2112
+ /* @__PURE__ */ n("label", { style: T.label, children: x.passwordLabel }),
2113
+ /* @__PURE__ */ l("div", { style: T.inputContainer, children: [
2069
2114
  /* @__PURE__ */ n(
2070
2115
  "input",
2071
2116
  {
2072
2117
  id: "password",
2073
2118
  name: "password",
2074
- type: C ? "text" : "password",
2119
+ type: R ? "text" : "password",
2075
2120
  value: y,
2076
- onChange: (g) => {
2077
- R(g.target.value), z.password && G((w) => ({ ...w, password: !1 }));
2121
+ onChange: (a) => {
2122
+ L(a.target.value), F.password && G((f) => ({ ...f, password: !1 }));
2078
2123
  },
2079
- placeholder: v.passwordPlaceholder,
2124
+ placeholder: x.passwordPlaceholder,
2080
2125
  style: {
2081
- ...c("password"),
2126
+ ...S("password"),
2082
2127
  paddingRight: "2.5rem"
2083
2128
  // Make room for the icon
2084
2129
  },
2085
- disabled: A
2130
+ disabled: M
2086
2131
  }
2087
2132
  ),
2088
2133
  /* @__PURE__ */ n(
2089
2134
  "button",
2090
2135
  {
2091
2136
  type: "button",
2092
- onClick: () => q(!C),
2093
- style: M.passwordToggle,
2094
- disabled: A,
2095
- "aria-label": C ? "Hide password" : "Show password",
2096
- children: C ? I.hidePassword : I.showPassword
2137
+ onClick: () => z(!R),
2138
+ style: T.passwordToggle,
2139
+ disabled: M,
2140
+ "aria-label": R ? "Hide password" : "Show password",
2141
+ children: R ? E.hidePassword : E.showPassword
2097
2142
  }
2098
2143
  )
2099
2144
  ] })
2100
2145
  ] }),
2101
- /* @__PURE__ */ n("button", { type: "submit", disabled: !f || !y || A, style: h(), children: A ? v.loadingText : v.submitButton }),
2102
- P && /* @__PURE__ */ n("div", { style: M.errorText, children: P })
2146
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !p || !y || M, style: g(), children: M ? x.loadingText : x.submitButton }),
2147
+ d && /* @__PURE__ */ n("div", { style: T.errorText, children: d })
2103
2148
  ] }),
2104
- (k || S || T) && /* @__PURE__ */ l("div", { style: M.linkContainer, children: [
2105
- T && /* @__PURE__ */ l("div", { children: [
2106
- /* @__PURE__ */ l("span", { style: M.divider, children: [
2107
- v.magicLinkText,
2149
+ (k || b || P) && /* @__PURE__ */ l("div", { style: T.linkContainer, children: [
2150
+ P && /* @__PURE__ */ l("div", { children: [
2151
+ /* @__PURE__ */ l("span", { style: T.divider, children: [
2152
+ x.magicLinkText,
2108
2153
  " "
2109
2154
  ] }),
2110
- /* @__PURE__ */ n("a", { onClick: b, style: M.link, children: v.magicLinkLink })
2155
+ /* @__PURE__ */ n("a", { onClick: w, style: T.link, children: x.magicLinkLink })
2111
2156
  ] }),
2112
- T && (k || S) && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2113
- k && /* @__PURE__ */ n("a", { onClick: o, style: M.link, children: v.forgotPasswordLink }),
2114
- k && S && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2115
- S && /* @__PURE__ */ l("div", { children: [
2116
- /* @__PURE__ */ l("span", { style: M.divider, children: [
2117
- v.signupText,
2157
+ P && (k || b) && /* @__PURE__ */ n("div", { style: T.divider, children: "•" }),
2158
+ k && /* @__PURE__ */ n("a", { onClick: o, style: T.link, children: x.forgotPasswordLink }),
2159
+ k && b && /* @__PURE__ */ n("div", { style: T.divider, children: "•" }),
2160
+ b && /* @__PURE__ */ l("div", { children: [
2161
+ /* @__PURE__ */ l("span", { style: T.divider, children: [
2162
+ x.signupText,
2118
2163
  " "
2119
2164
  ] }),
2120
- /* @__PURE__ */ n("a", { onClick: p, style: M.link, children: v.signupLink })
2165
+ /* @__PURE__ */ n("a", { onClick: h, style: T.link, children: x.signupLink })
2121
2166
  ] })
2122
2167
  ] })
2123
2168
  ] });
2124
2169
  }
2125
- const ut = {
2170
+ const gt = {
2126
2171
  title: "Create Account",
2127
2172
  nameLabel: "First Name",
2128
2173
  namePlaceholder: "Enter your first name",
@@ -2148,7 +2193,7 @@ const ut = {
2148
2193
  passwordMismatchError: "Passwords do not match",
2149
2194
  isAdminLabel: "Create new organization",
2150
2195
  isAdminDescription: "Check this if you want to create a new organization"
2151
- }, ht = {
2196
+ }, pt = {
2152
2197
  container: {
2153
2198
  maxWidth: "400px",
2154
2199
  width: "100%",
@@ -2247,103 +2292,103 @@ const ut = {
2247
2292
  fontSize: "0.875rem"
2248
2293
  }
2249
2294
  };
2250
- function Vt({
2295
+ function Gt({
2251
2296
  copy: i = {},
2252
2297
  styles: e = {},
2253
2298
  signupType: t = "user",
2254
2299
  onSuccess: r,
2255
2300
  onError: s,
2256
2301
  onLoginClick: o,
2257
- onMagicLinkClick: p,
2258
- showLoginLink: b = !0,
2302
+ onMagicLinkClick: h,
2303
+ showLoginLink: w = !0,
2259
2304
  showMagicLinkOption: k = !0,
2260
- className: S
2305
+ className: b
2261
2306
  }) {
2262
- const [T, m] = x(""), [f, u] = x(""), [y, R] = x(""), [C, q] = x(""), [A, d] = x(""), [P, E] = x(""), [z, G] = x(""), [$, _] = x(!1), [v, M] = x(""), [I, a] = x({}), { signup: L, signupTenantAdmin: c } = ae(), { tenant: h } = se(), g = { ...ut, ...i }, w = { ...ht, ...e }, j = () => {
2263
- const F = {};
2264
- return T.trim() || (F.name = !0), !y.trim() && !C.trim() && (F.email = !0, F.phoneNumber = !0), A.trim() || (F.password = !0), P.trim() || (F.confirmPassword = !0), t === "tenant" && !z.trim() && (F.tenantName = !0), a(F), Object.keys(F).length === 0;
2265
- }, Y = async (F) => {
2266
- if (F.preventDefault(), !!j()) {
2267
- if (A !== P) {
2268
- M(g.passwordMismatchError), a({ confirmPassword: !0 });
2307
+ const [P, m] = v(""), [p, u] = v(""), [y, L] = v(""), [R, z] = v(""), [M, A] = v(""), [d, C] = v(""), [F, G] = v(""), [U, _] = v(!1), [x, T] = v(""), [E, c] = v({}), { signup: I, signupTenantAdmin: S } = ae(), { tenant: g } = se(), a = { ...gt, ...i }, f = { ...pt, ...e }, O = () => {
2308
+ const $ = {};
2309
+ return P.trim() || ($.name = !0), !y.trim() && !R.trim() && ($.email = !0, $.phoneNumber = !0), M.trim() || ($.password = !0), d.trim() || ($.confirmPassword = !0), t === "tenant" && !F.trim() && ($.tenantName = !0), c($), Object.keys($).length === 0;
2310
+ }, K = async ($) => {
2311
+ if ($.preventDefault(), !!O()) {
2312
+ if (M !== d) {
2313
+ T(a.passwordMismatchError), c({ confirmPassword: !0 });
2269
2314
  return;
2270
2315
  }
2271
- if (t === "user" && !(h != null && h.id)) {
2272
- M("Tenant not found");
2316
+ if (t === "user" && !(g != null && g.id)) {
2317
+ T("Tenant not found");
2273
2318
  return;
2274
2319
  }
2275
- _(!0), M("");
2320
+ _(!0), T("");
2276
2321
  try {
2277
- let K;
2278
- t === "tenant" ? K = await c({
2322
+ let J;
2323
+ t === "tenant" ? J = await S({
2279
2324
  email: y || void 0,
2280
- phoneNumber: C || void 0,
2281
- name: T,
2282
- password: A,
2283
- tenantName: z,
2284
- lastName: f || void 0
2285
- }) : K = await L({
2325
+ phoneNumber: R || void 0,
2326
+ name: P,
2327
+ password: M,
2328
+ tenantName: F,
2329
+ lastName: p || void 0
2330
+ }) : J = await I({
2286
2331
  email: y || void 0,
2287
- phoneNumber: C || void 0,
2288
- name: T,
2289
- password: A,
2290
- tenantId: h.id,
2291
- lastName: f || void 0
2292
- }), r == null || r(K);
2293
- } catch (K) {
2294
- const ge = K.message || g.errorMessage;
2295
- M(ge), s == null || s(ge);
2332
+ phoneNumber: R || void 0,
2333
+ name: P,
2334
+ password: M,
2335
+ tenantId: g.id,
2336
+ lastName: p || void 0
2337
+ }), r == null || r(J);
2338
+ } catch (J) {
2339
+ const ge = J.message || a.errorMessage;
2340
+ T(ge), s == null || s(ge);
2296
2341
  } finally {
2297
2342
  _(!1);
2298
2343
  }
2299
2344
  }
2300
- }, H = (F) => ({
2301
- ...w.input,
2302
- ...I[F] ? w.inputError : {}
2345
+ }, H = ($) => ({
2346
+ ...f.input,
2347
+ ...E[$] ? f.inputError : {}
2303
2348
  }), N = () => ({
2304
- ...w.button,
2305
- ...$ ? w.buttonLoading : {},
2306
- ...!T || !y && !C || !A || !P || $ || t === "tenant" && !z ? w.buttonDisabled : {}
2307
- }), O = T && (y || C) && A && P && (t === "user" || z);
2308
- return /* @__PURE__ */ l("div", { className: S, style: w.container, children: [
2309
- /* @__PURE__ */ n("h2", { style: w.title, children: g.title }),
2310
- /* @__PURE__ */ l("form", { onSubmit: Y, style: w.form, children: [
2311
- /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2312
- /* @__PURE__ */ n("label", { style: w.label, children: g.nameLabel }),
2349
+ ...f.button,
2350
+ ...U ? f.buttonLoading : {},
2351
+ ...!P || !y && !R || !M || !d || U || t === "tenant" && !F ? f.buttonDisabled : {}
2352
+ }), W = P && (y || R) && M && d && (t === "user" || F);
2353
+ return /* @__PURE__ */ l("div", { className: b, style: f.container, children: [
2354
+ /* @__PURE__ */ n("h2", { style: f.title, children: a.title }),
2355
+ /* @__PURE__ */ l("form", { onSubmit: K, style: f.form, children: [
2356
+ /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2357
+ /* @__PURE__ */ n("label", { style: f.label, children: a.nameLabel }),
2313
2358
  /* @__PURE__ */ n(
2314
2359
  "input",
2315
2360
  {
2316
2361
  id: "name",
2317
2362
  name: "name",
2318
2363
  type: "text",
2319
- value: T,
2320
- onChange: (F) => {
2321
- m(F.target.value), I.name && a((K) => ({ ...K, name: !1 }));
2364
+ value: P,
2365
+ onChange: ($) => {
2366
+ m($.target.value), E.name && c((J) => ({ ...J, name: !1 }));
2322
2367
  },
2323
- placeholder: g.namePlaceholder,
2368
+ placeholder: a.namePlaceholder,
2324
2369
  style: H("name"),
2325
- disabled: $
2370
+ disabled: U
2326
2371
  }
2327
2372
  )
2328
2373
  ] }),
2329
- /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2330
- /* @__PURE__ */ n("label", { style: w.label, children: g.lastNameLabel }),
2374
+ /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2375
+ /* @__PURE__ */ n("label", { style: f.label, children: a.lastNameLabel }),
2331
2376
  /* @__PURE__ */ n(
2332
2377
  "input",
2333
2378
  {
2334
2379
  id: "lastName",
2335
2380
  name: "lastName",
2336
2381
  type: "text",
2337
- value: f,
2338
- onChange: (F) => u(F.target.value),
2339
- placeholder: g.lastNamePlaceholder,
2340
- style: w.input,
2341
- disabled: $
2382
+ value: p,
2383
+ onChange: ($) => u($.target.value),
2384
+ placeholder: a.lastNamePlaceholder,
2385
+ style: f.input,
2386
+ disabled: U
2342
2387
  }
2343
2388
  )
2344
2389
  ] }),
2345
- /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2346
- /* @__PURE__ */ n("label", { style: w.label, children: g.emailLabel }),
2390
+ /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2391
+ /* @__PURE__ */ n("label", { style: f.label, children: a.emailLabel }),
2347
2392
  /* @__PURE__ */ n(
2348
2393
  "input",
2349
2394
  {
@@ -2351,30 +2396,30 @@ function Vt({
2351
2396
  name: "email",
2352
2397
  type: "email",
2353
2398
  value: y,
2354
- onChange: (F) => {
2355
- R(F.target.value), I.email && a((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2399
+ onChange: ($) => {
2400
+ L($.target.value), E.email && c((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2356
2401
  },
2357
- placeholder: g.emailPlaceholder,
2402
+ placeholder: a.emailPlaceholder,
2358
2403
  style: H("email"),
2359
- disabled: $
2404
+ disabled: U
2360
2405
  }
2361
2406
  )
2362
2407
  ] }),
2363
- /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2364
- /* @__PURE__ */ n("label", { style: w.label, children: g.phoneNumberLabel }),
2408
+ /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2409
+ /* @__PURE__ */ n("label", { style: f.label, children: a.phoneNumberLabel }),
2365
2410
  /* @__PURE__ */ n(
2366
2411
  "input",
2367
2412
  {
2368
2413
  id: "phoneNumber",
2369
2414
  name: "phoneNumber",
2370
2415
  type: "tel",
2371
- value: C,
2372
- onChange: (F) => {
2373
- q(F.target.value), I.phoneNumber && a((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2416
+ value: R,
2417
+ onChange: ($) => {
2418
+ z($.target.value), E.phoneNumber && c((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2374
2419
  },
2375
- placeholder: g.phoneNumberPlaceholder,
2420
+ placeholder: a.phoneNumberPlaceholder,
2376
2421
  style: H("phoneNumber"),
2377
- disabled: $
2422
+ disabled: U
2378
2423
  }
2379
2424
  )
2380
2425
  ] }),
@@ -2390,83 +2435,83 @@ function Vt({
2390
2435
  children: "At least one contact method (email or phone) is required"
2391
2436
  }
2392
2437
  ),
2393
- /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2394
- /* @__PURE__ */ n("label", { style: w.label, children: g.passwordLabel }),
2438
+ /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2439
+ /* @__PURE__ */ n("label", { style: f.label, children: a.passwordLabel }),
2395
2440
  /* @__PURE__ */ n(
2396
2441
  "input",
2397
2442
  {
2398
2443
  id: "password",
2399
2444
  name: "password",
2400
2445
  type: "password",
2401
- value: A,
2402
- onChange: (F) => {
2403
- d(F.target.value), I.password && a((K) => ({ ...K, password: !1 }));
2446
+ value: M,
2447
+ onChange: ($) => {
2448
+ A($.target.value), E.password && c((J) => ({ ...J, password: !1 }));
2404
2449
  },
2405
- placeholder: g.passwordPlaceholder,
2450
+ placeholder: a.passwordPlaceholder,
2406
2451
  style: H("password"),
2407
- disabled: $
2452
+ disabled: U
2408
2453
  }
2409
2454
  )
2410
2455
  ] }),
2411
- /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2412
- /* @__PURE__ */ n("label", { style: w.label, children: g.confirmPasswordLabel }),
2456
+ /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2457
+ /* @__PURE__ */ n("label", { style: f.label, children: a.confirmPasswordLabel }),
2413
2458
  /* @__PURE__ */ n(
2414
2459
  "input",
2415
2460
  {
2416
2461
  id: "confirmPassword",
2417
2462
  name: "confirmPassword",
2418
2463
  type: "password",
2419
- value: P,
2420
- onChange: (F) => {
2421
- E(F.target.value), I.confirmPassword && a((K) => ({ ...K, confirmPassword: !1 })), v === g.passwordMismatchError && M("");
2464
+ value: d,
2465
+ onChange: ($) => {
2466
+ C($.target.value), E.confirmPassword && c((J) => ({ ...J, confirmPassword: !1 })), x === a.passwordMismatchError && T("");
2422
2467
  },
2423
- placeholder: g.confirmPasswordPlaceholder,
2468
+ placeholder: a.confirmPasswordPlaceholder,
2424
2469
  style: H("confirmPassword"),
2425
- disabled: $
2470
+ disabled: U
2426
2471
  }
2427
2472
  )
2428
2473
  ] }),
2429
- t === "tenant" && /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2430
- /* @__PURE__ */ n("label", { style: w.label, children: g.tenantNameLabel }),
2474
+ t === "tenant" && /* @__PURE__ */ l("div", { style: f.fieldGroup, children: [
2475
+ /* @__PURE__ */ n("label", { style: f.label, children: a.tenantNameLabel }),
2431
2476
  /* @__PURE__ */ n(
2432
2477
  "input",
2433
2478
  {
2434
2479
  id: "tenantName",
2435
2480
  name: "tenantName",
2436
2481
  type: "text",
2437
- value: z,
2438
- onChange: (F) => {
2439
- G(F.target.value), I.tenantName && a((K) => ({ ...K, tenantName: !1 }));
2482
+ value: F,
2483
+ onChange: ($) => {
2484
+ G($.target.value), E.tenantName && c((J) => ({ ...J, tenantName: !1 }));
2440
2485
  },
2441
- placeholder: g.tenantNamePlaceholder,
2486
+ placeholder: a.tenantNamePlaceholder,
2442
2487
  style: H("tenantName"),
2443
- disabled: $
2488
+ disabled: U
2444
2489
  }
2445
2490
  )
2446
2491
  ] }),
2447
- /* @__PURE__ */ n("button", { type: "submit", disabled: !O || $, style: N(), children: $ ? g.loadingText : g.submitButton }),
2448
- v && /* @__PURE__ */ n("div", { style: w.errorText, children: v })
2492
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !W || U, style: N(), children: U ? a.loadingText : a.submitButton }),
2493
+ x && /* @__PURE__ */ n("div", { style: f.errorText, children: x })
2449
2494
  ] }),
2450
- (b || k) && /* @__PURE__ */ l("div", { style: w.linkContainer, children: [
2495
+ (w || k) && /* @__PURE__ */ l("div", { style: f.linkContainer, children: [
2451
2496
  k && /* @__PURE__ */ l("div", { children: [
2452
- /* @__PURE__ */ l("span", { style: w.divider, children: [
2453
- g.magicLinkText,
2497
+ /* @__PURE__ */ l("span", { style: f.divider, children: [
2498
+ a.magicLinkText,
2454
2499
  " "
2455
2500
  ] }),
2456
- /* @__PURE__ */ n("a", { onClick: p, style: w.link, children: g.magicLinkLink })
2501
+ /* @__PURE__ */ n("a", { onClick: h, style: f.link, children: a.magicLinkLink })
2457
2502
  ] }),
2458
- k && b && /* @__PURE__ */ n("div", { style: w.divider, children: "•" }),
2459
- b && /* @__PURE__ */ l("div", { children: [
2460
- /* @__PURE__ */ l("span", { style: w.divider, children: [
2461
- g.loginText,
2503
+ k && w && /* @__PURE__ */ n("div", { style: f.divider, children: "•" }),
2504
+ w && /* @__PURE__ */ l("div", { children: [
2505
+ /* @__PURE__ */ l("span", { style: f.divider, children: [
2506
+ a.loginText,
2462
2507
  " "
2463
2508
  ] }),
2464
- /* @__PURE__ */ n("a", { onClick: o, style: w.link, children: g.loginLink })
2509
+ /* @__PURE__ */ n("a", { onClick: o, style: f.link, children: a.loginLink })
2465
2510
  ] })
2466
2511
  ] })
2467
2512
  ] });
2468
2513
  }
2469
- const gt = {
2514
+ const ft = {
2470
2515
  title: "Sign In with Magic Link",
2471
2516
  emailLabel: "Email",
2472
2517
  emailPlaceholder: "Enter your email",
@@ -2484,7 +2529,7 @@ const gt = {
2484
2529
  loadingText: "Sending magic link...",
2485
2530
  verifyingText: "Verifying magic link...",
2486
2531
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2487
- }, pt = {
2532
+ }, mt = {
2488
2533
  container: {
2489
2534
  maxWidth: "400px",
2490
2535
  width: "100%",
@@ -2587,105 +2632,105 @@ const gt = {
2587
2632
  fontSize: "0.875rem"
2588
2633
  }
2589
2634
  };
2590
- function _t({
2635
+ function Kt({
2591
2636
  copy: i = {},
2592
2637
  styles: e = {},
2593
2638
  onSuccess: t,
2594
2639
  onError: r,
2595
2640
  onLoginClick: s,
2596
2641
  onSignupClick: o,
2597
- showTraditionalLinks: p = !0,
2598
- className: b,
2642
+ showTraditionalLinks: h = !0,
2643
+ className: w,
2599
2644
  verifyToken: k,
2600
- frontendUrl: S
2645
+ frontendUrl: b
2601
2646
  }) {
2602
- const [T, m] = x(""), [f, u] = x(""), [y, R] = x(""), [C, q] = x(!1), [A, d] = x(!1), [P, E] = x(""), [z, G] = x(""), [$, _] = x({}), [v, M] = x(!1), { sendMagicLink: I, verifyMagicLink: a } = ae(), { tenant: L } = se(), c = { ...gt, ...i }, h = { ...pt, ...e };
2647
+ const [P, m] = v(""), [p, u] = v(""), [y, L] = v(""), [R, z] = v(!1), [M, A] = v(!1), [d, C] = v(""), [F, G] = v(""), [U, _] = v({}), [x, T] = v(!1), { sendMagicLink: E, verifyMagicLink: c } = ae(), { tenant: I } = se(), S = { ...ft, ...i }, g = { ...mt, ...e };
2603
2648
  te(() => {
2604
- k && g(k);
2649
+ k && a(k);
2605
2650
  }, [k]);
2606
- const g = async (N) => {
2607
- if (!L || !T) {
2608
- E("Missing tenant or email");
2651
+ const a = async (N) => {
2652
+ if (!I || !P) {
2653
+ C("Missing tenant or email");
2609
2654
  return;
2610
2655
  }
2611
- d(!0), E("");
2656
+ A(!0), C("");
2612
2657
  try {
2613
- const O = await a({
2658
+ const W = await c({
2614
2659
  token: N,
2615
- email: T
2660
+ email: P
2616
2661
  // tenantId inferred from context automatically
2617
2662
  });
2618
- t == null || t(O);
2619
- } catch (O) {
2620
- const F = O.message || "Failed to verify magic link";
2621
- E(F), r == null || r(F);
2663
+ t == null || t(W);
2664
+ } catch (W) {
2665
+ const $ = W.message || "Failed to verify magic link";
2666
+ C($), r == null || r($);
2622
2667
  } finally {
2623
- d(!1);
2668
+ A(!1);
2624
2669
  }
2625
- }, w = () => {
2670
+ }, f = () => {
2626
2671
  const N = {};
2627
- return T.trim() || (N.email = !0), v && !f.trim() && (N.name = !0), _(N), Object.keys(N).length === 0;
2628
- }, j = async (N) => {
2629
- if (N.preventDefault(), !!w()) {
2630
- if (!(L != null && L.id)) {
2631
- E("Tenant not found");
2672
+ return P.trim() || (N.email = !0), x && !p.trim() && (N.name = !0), _(N), Object.keys(N).length === 0;
2673
+ }, O = async (N) => {
2674
+ if (N.preventDefault(), !!f()) {
2675
+ if (!(I != null && I.id)) {
2676
+ C("Tenant not found");
2632
2677
  return;
2633
2678
  }
2634
- q(!0), E(""), G("");
2679
+ z(!0), C(""), G("");
2635
2680
  try {
2636
- const O = S || (typeof window < "u" ? window.location.origin : ""), F = await I({
2637
- email: T,
2638
- tenantId: L.id,
2639
- frontendUrl: O,
2640
- name: v ? f : void 0,
2641
- lastName: v ? y : void 0
2681
+ const W = b || (typeof window < "u" ? window.location.origin : ""), $ = await E({
2682
+ email: P,
2683
+ tenantId: I.id,
2684
+ frontendUrl: W,
2685
+ name: x ? p : void 0,
2686
+ lastName: x ? y : void 0
2642
2687
  });
2643
- G(c.successMessage), t == null || t(F);
2644
- } catch (O) {
2645
- const F = O.message || c.errorMessage;
2646
- E(F), r == null || r(F);
2688
+ G(S.successMessage), t == null || t($);
2689
+ } catch (W) {
2690
+ const $ = W.message || S.errorMessage;
2691
+ C($), r == null || r($);
2647
2692
  } finally {
2648
- q(!1);
2693
+ z(!1);
2649
2694
  }
2650
2695
  }
2651
- }, Y = (N) => ({
2652
- ...h.input,
2653
- ...$[N] ? h.inputError : {}
2696
+ }, K = (N) => ({
2697
+ ...g.input,
2698
+ ...U[N] ? g.inputError : {}
2654
2699
  }), H = () => ({
2655
- ...h.button,
2656
- ...C || A ? h.buttonLoading : {},
2657
- ...!T || C || A ? h.buttonDisabled : {}
2700
+ ...g.button,
2701
+ ...R || M ? g.buttonLoading : {},
2702
+ ...!P || R || M ? g.buttonDisabled : {}
2658
2703
  });
2659
- return A ? /* @__PURE__ */ l("div", { className: b, style: h.container, children: [
2660
- /* @__PURE__ */ n("h2", { style: h.title, children: c.verifyingText }),
2704
+ return M ? /* @__PURE__ */ l("div", { className: w, style: g.container, children: [
2705
+ /* @__PURE__ */ n("h2", { style: g.title, children: S.verifyingText }),
2661
2706
  /* @__PURE__ */ n("div", { style: { textAlign: "center", padding: "2rem" }, children: /* @__PURE__ */ n("div", { style: { fontSize: "1rem", color: "#6b7280" }, children: "Please wait while we verify your magic link..." }) })
2662
- ] }) : /* @__PURE__ */ l("div", { className: b, style: h.container, children: [
2663
- /* @__PURE__ */ n("h2", { style: h.title, children: c.title }),
2664
- /* @__PURE__ */ n("p", { style: h.description, children: c.description }),
2665
- /* @__PURE__ */ l("form", { onSubmit: j, style: h.form, children: [
2666
- /* @__PURE__ */ l("div", { style: h.fieldGroup, children: [
2667
- /* @__PURE__ */ n("label", { style: h.label, children: c.emailLabel }),
2707
+ ] }) : /* @__PURE__ */ l("div", { className: w, style: g.container, children: [
2708
+ /* @__PURE__ */ n("h2", { style: g.title, children: S.title }),
2709
+ /* @__PURE__ */ n("p", { style: g.description, children: S.description }),
2710
+ /* @__PURE__ */ l("form", { onSubmit: O, style: g.form, children: [
2711
+ /* @__PURE__ */ l("div", { style: g.fieldGroup, children: [
2712
+ /* @__PURE__ */ n("label", { style: g.label, children: S.emailLabel }),
2668
2713
  /* @__PURE__ */ n(
2669
2714
  "input",
2670
2715
  {
2671
2716
  id: "email",
2672
2717
  name: "email",
2673
2718
  type: "email",
2674
- value: T,
2719
+ value: P,
2675
2720
  onChange: (N) => {
2676
- m(N.target.value), $.email && _((O) => ({ ...O, email: !1 }));
2721
+ m(N.target.value), U.email && _((W) => ({ ...W, email: !1 }));
2677
2722
  },
2678
- placeholder: c.emailPlaceholder,
2679
- style: Y("email"),
2680
- disabled: C || A
2723
+ placeholder: S.emailPlaceholder,
2724
+ style: K("email"),
2725
+ disabled: R || M
2681
2726
  }
2682
2727
  )
2683
2728
  ] }),
2684
- !v && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2729
+ !x && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2685
2730
  "button",
2686
2731
  {
2687
2732
  type: "button",
2688
- onClick: () => M(!0),
2733
+ onClick: () => T(!0),
2689
2734
  style: {
2690
2735
  background: "none",
2691
2736
  border: "none",
@@ -2697,27 +2742,27 @@ function _t({
2697
2742
  children: "New user? Add your name"
2698
2743
  }
2699
2744
  ) }),
2700
- v && /* @__PURE__ */ l(U, { children: [
2701
- /* @__PURE__ */ l("div", { style: h.fieldGroup, children: [
2702
- /* @__PURE__ */ n("label", { style: h.label, children: c.nameLabel }),
2745
+ x && /* @__PURE__ */ l(q, { children: [
2746
+ /* @__PURE__ */ l("div", { style: g.fieldGroup, children: [
2747
+ /* @__PURE__ */ n("label", { style: g.label, children: S.nameLabel }),
2703
2748
  /* @__PURE__ */ n(
2704
2749
  "input",
2705
2750
  {
2706
2751
  id: "name",
2707
2752
  name: "name",
2708
2753
  type: "text",
2709
- value: f,
2754
+ value: p,
2710
2755
  onChange: (N) => {
2711
- u(N.target.value), $.name && _((O) => ({ ...O, name: !1 }));
2756
+ u(N.target.value), U.name && _((W) => ({ ...W, name: !1 }));
2712
2757
  },
2713
- placeholder: c.namePlaceholder,
2714
- style: Y("name"),
2715
- disabled: C || A
2758
+ placeholder: S.namePlaceholder,
2759
+ style: K("name"),
2760
+ disabled: R || M
2716
2761
  }
2717
2762
  )
2718
2763
  ] }),
2719
- /* @__PURE__ */ l("div", { style: h.fieldGroup, children: [
2720
- /* @__PURE__ */ n("label", { style: h.label, children: c.lastNameLabel }),
2764
+ /* @__PURE__ */ l("div", { style: g.fieldGroup, children: [
2765
+ /* @__PURE__ */ n("label", { style: g.label, children: S.lastNameLabel }),
2721
2766
  /* @__PURE__ */ n(
2722
2767
  "input",
2723
2768
  {
@@ -2725,10 +2770,10 @@ function _t({
2725
2770
  name: "lastName",
2726
2771
  type: "text",
2727
2772
  value: y,
2728
- onChange: (N) => R(N.target.value),
2729
- placeholder: c.lastNamePlaceholder,
2730
- style: h.input,
2731
- disabled: C || A
2773
+ onChange: (N) => L(N.target.value),
2774
+ placeholder: S.lastNamePlaceholder,
2775
+ style: g.input,
2776
+ disabled: R || M
2732
2777
  }
2733
2778
  )
2734
2779
  ] }),
@@ -2737,7 +2782,7 @@ function _t({
2737
2782
  {
2738
2783
  type: "button",
2739
2784
  onClick: () => {
2740
- M(!1), u(""), R("");
2785
+ T(!1), u(""), L("");
2741
2786
  },
2742
2787
  style: {
2743
2788
  background: "none",
@@ -2751,30 +2796,30 @@ function _t({
2751
2796
  }
2752
2797
  ) })
2753
2798
  ] }),
2754
- /* @__PURE__ */ n("button", { type: "submit", disabled: !T || C || A, style: H(), children: C ? c.loadingText : c.submitButton }),
2755
- P && /* @__PURE__ */ n("div", { style: h.errorText, children: P }),
2756
- z && /* @__PURE__ */ n("div", { style: h.successText, children: z })
2799
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !P || R || M, style: H(), children: R ? S.loadingText : S.submitButton }),
2800
+ d && /* @__PURE__ */ n("div", { style: g.errorText, children: d }),
2801
+ F && /* @__PURE__ */ n("div", { style: g.successText, children: F })
2757
2802
  ] }),
2758
- p && /* @__PURE__ */ l("div", { style: h.linkContainer, children: [
2803
+ h && /* @__PURE__ */ l("div", { style: g.linkContainer, children: [
2759
2804
  /* @__PURE__ */ l("div", { children: [
2760
- /* @__PURE__ */ l("span", { style: h.divider, children: [
2761
- c.loginText,
2805
+ /* @__PURE__ */ l("span", { style: g.divider, children: [
2806
+ S.loginText,
2762
2807
  " "
2763
2808
  ] }),
2764
- /* @__PURE__ */ n("a", { onClick: s, style: h.link, children: c.loginLink })
2809
+ /* @__PURE__ */ n("a", { onClick: s, style: g.link, children: S.loginLink })
2765
2810
  ] }),
2766
- /* @__PURE__ */ n("div", { style: h.divider, children: "•" }),
2811
+ /* @__PURE__ */ n("div", { style: g.divider, children: "•" }),
2767
2812
  /* @__PURE__ */ l("div", { children: [
2768
- /* @__PURE__ */ l("span", { style: h.divider, children: [
2769
- c.signupText,
2813
+ /* @__PURE__ */ l("span", { style: g.divider, children: [
2814
+ S.signupText,
2770
2815
  " "
2771
2816
  ] }),
2772
- /* @__PURE__ */ n("a", { onClick: o, style: h.link, children: c.signupLink })
2817
+ /* @__PURE__ */ n("a", { onClick: o, style: g.link, children: S.signupLink })
2773
2818
  ] })
2774
2819
  ] })
2775
2820
  ] });
2776
2821
  }
2777
- const ft = {
2822
+ const yt = {
2778
2823
  title: "Verifying Magic Link",
2779
2824
  verifyingMessage: "Please wait while we verify your magic link...",
2780
2825
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2782,7 +2827,7 @@ const ft = {
2782
2827
  redirectingMessage: "Redirecting you to the dashboard...",
2783
2828
  retryButton: "Try Again",
2784
2829
  backToLoginButton: "Back to Login"
2785
- }, Re = {
2830
+ }, Ee = {
2786
2831
  container: {
2787
2832
  maxWidth: "400px",
2788
2833
  width: "100%",
@@ -2869,7 +2914,7 @@ const ft = {
2869
2914
  cursor: "pointer",
2870
2915
  transition: "all 0.15s ease-in-out"
2871
2916
  }
2872
- }, mt = () => /* @__PURE__ */ n("div", { style: Re.spinner }), yt = () => /* @__PURE__ */ l(
2917
+ }, wt = () => /* @__PURE__ */ n("div", { style: Ee.spinner }), bt = () => /* @__PURE__ */ l(
2873
2918
  "svg",
2874
2919
  {
2875
2920
  width: "48",
@@ -2886,7 +2931,7 @@ const ft = {
2886
2931
  /* @__PURE__ */ n("polyline", { points: "22,4 12,14.01 9,11.01" })
2887
2932
  ]
2888
2933
  }
2889
- ), wt = () => /* @__PURE__ */ l(
2934
+ ), St = () => /* @__PURE__ */ l(
2890
2935
  "svg",
2891
2936
  {
2892
2937
  width: "48",
@@ -2904,109 +2949,109 @@ const ft = {
2904
2949
  /* @__PURE__ */ n("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
2905
2950
  ]
2906
2951
  }
2907
- ), bt = {
2908
- loading: /* @__PURE__ */ n(mt, {}),
2909
- success: /* @__PURE__ */ n(yt, {}),
2910
- error: /* @__PURE__ */ n(wt, {})
2952
+ ), vt = {
2953
+ loading: /* @__PURE__ */ n(wt, {}),
2954
+ success: /* @__PURE__ */ n(bt, {}),
2955
+ error: /* @__PURE__ */ n(St, {})
2911
2956
  };
2912
- function Gt({
2957
+ function Jt({
2913
2958
  copy: i = {},
2914
2959
  styles: e = {},
2915
2960
  icons: t = {},
2916
2961
  onSuccess: r,
2917
2962
  onError: s,
2918
2963
  onRetry: o,
2919
- onBackToLogin: p,
2920
- className: b,
2964
+ onBackToLogin: h,
2965
+ className: w,
2921
2966
  token: k,
2922
- email: S,
2923
- appId: T,
2967
+ email: b,
2968
+ appId: P,
2924
2969
  tenantSlug: m,
2925
- autoRedirectDelay: f = 3e3
2970
+ autoRedirectDelay: p = 3e3
2926
2971
  }) {
2927
- const [u, y] = x("verifying"), [R, C] = x(""), { verifyMagicLink: q } = ae(), A = { ...ft, ...i }, d = { ...Re, ...e }, P = { ...bt, ...t }, E = () => {
2972
+ const [u, y] = v("verifying"), [L, R] = v(""), { verifyMagicLink: z } = ae(), M = { ...yt, ...i }, A = { ...Ee, ...e }, d = { ...vt, ...t }, C = () => {
2928
2973
  if (typeof window > "u") return {};
2929
- const v = new URLSearchParams(window.location.search);
2974
+ const x = new URLSearchParams(window.location.search);
2930
2975
  return {
2931
- token: k || v.get("token") || "",
2932
- email: S || v.get("email") || "",
2933
- appId: T || v.get("appId") || "",
2934
- tenantSlug: m || v.get("tenantSlug") || void 0
2976
+ token: k || x.get("token") || "",
2977
+ email: b || x.get("email") || "",
2978
+ appId: P || x.get("appId") || "",
2979
+ tenantSlug: m || x.get("tenantSlug") || void 0
2935
2980
  };
2936
- }, z = async () => {
2937
- y("verifying"), C("");
2981
+ }, F = async () => {
2982
+ y("verifying"), R("");
2938
2983
  try {
2939
- const v = E();
2940
- if (!v.token || !v.email)
2984
+ const x = C();
2985
+ if (!x.token || !x.email)
2941
2986
  throw new Error("Missing required parameters: token or email");
2942
- const M = await q({
2943
- token: v.token,
2944
- email: v.email,
2945
- tenantSlug: v.tenantSlug
2987
+ const T = await z({
2988
+ token: x.token,
2989
+ email: x.email,
2990
+ tenantSlug: x.tenantSlug
2946
2991
  });
2947
- y("success"), r == null || r(M), f > 0 && setTimeout(() => {
2992
+ y("success"), r == null || r(T), p > 0 && setTimeout(() => {
2948
2993
  y("redirecting");
2949
- }, f);
2950
- } catch (v) {
2951
- const M = v.message || A.errorMessage;
2952
- C(M), y("error"), s == null || s(M);
2994
+ }, p);
2995
+ } catch (x) {
2996
+ const T = x.message || M.errorMessage;
2997
+ R(T), y("error"), s == null || s(T);
2953
2998
  }
2954
2999
  }, G = () => {
2955
- o == null || o(), z();
2956
- }, $ = () => {
2957
- p == null || p();
3000
+ o == null || o(), F();
3001
+ }, U = () => {
3002
+ h == null || h();
2958
3003
  };
2959
3004
  te(() => {
2960
- z();
3005
+ F();
2961
3006
  }, []);
2962
3007
  const _ = () => {
2963
3008
  switch (u) {
2964
3009
  case "verifying":
2965
- return /* @__PURE__ */ l("div", { style: d.message, children: [
2966
- P.loading,
2967
- A.verifyingMessage
3010
+ return /* @__PURE__ */ l("div", { style: A.message, children: [
3011
+ d.loading,
3012
+ M.verifyingMessage
2968
3013
  ] });
2969
3014
  case "success":
2970
- return /* @__PURE__ */ l(U, { children: [
2971
- P.success,
2972
- /* @__PURE__ */ n("div", { style: d.successMessage, children: A.successMessage })
3015
+ return /* @__PURE__ */ l(q, { children: [
3016
+ d.success,
3017
+ /* @__PURE__ */ n("div", { style: A.successMessage, children: M.successMessage })
2973
3018
  ] });
2974
3019
  case "redirecting":
2975
- return /* @__PURE__ */ l(U, { children: [
2976
- P.loading,
2977
- /* @__PURE__ */ n("div", { style: d.message, children: A.redirectingMessage })
3020
+ return /* @__PURE__ */ l(q, { children: [
3021
+ d.loading,
3022
+ /* @__PURE__ */ n("div", { style: A.message, children: M.redirectingMessage })
2978
3023
  ] });
2979
3024
  case "error":
2980
- return /* @__PURE__ */ l(U, { children: [
2981
- P.error,
2982
- /* @__PURE__ */ n("div", { style: d.errorMessage, children: R || A.errorMessage }),
2983
- /* @__PURE__ */ l("div", { style: d.buttonContainer, children: [
3025
+ return /* @__PURE__ */ l(q, { children: [
3026
+ d.error,
3027
+ /* @__PURE__ */ n("div", { style: A.errorMessage, children: L || M.errorMessage }),
3028
+ /* @__PURE__ */ l("div", { style: A.buttonContainer, children: [
2984
3029
  /* @__PURE__ */ n(
2985
3030
  "button",
2986
3031
  {
2987
3032
  onClick: G,
2988
- style: d.retryButton,
2989
- onMouseOver: (v) => {
2990
- v.currentTarget.style.backgroundColor = "#2563eb";
3033
+ style: A.retryButton,
3034
+ onMouseOver: (x) => {
3035
+ x.currentTarget.style.backgroundColor = "#2563eb";
2991
3036
  },
2992
- onMouseOut: (v) => {
2993
- v.currentTarget.style.backgroundColor = "#3b82f6";
3037
+ onMouseOut: (x) => {
3038
+ x.currentTarget.style.backgroundColor = "#3b82f6";
2994
3039
  },
2995
- children: A.retryButton
3040
+ children: M.retryButton
2996
3041
  }
2997
3042
  ),
2998
3043
  /* @__PURE__ */ n(
2999
3044
  "button",
3000
3045
  {
3001
- onClick: $,
3002
- style: d.backButton,
3003
- onMouseOver: (v) => {
3004
- v.currentTarget.style.backgroundColor = "#e5e7eb";
3046
+ onClick: U,
3047
+ style: A.backButton,
3048
+ onMouseOver: (x) => {
3049
+ x.currentTarget.style.backgroundColor = "#e5e7eb";
3005
3050
  },
3006
- onMouseOut: (v) => {
3007
- v.currentTarget.style.backgroundColor = "#f3f4f6";
3051
+ onMouseOut: (x) => {
3052
+ x.currentTarget.style.backgroundColor = "#f3f4f6";
3008
3053
  },
3009
- children: A.backToLoginButton
3054
+ children: M.backToLoginButton
3010
3055
  }
3011
3056
  )
3012
3057
  ] })
@@ -3015,18 +3060,18 @@ function Gt({
3015
3060
  return null;
3016
3061
  }
3017
3062
  };
3018
- return /* @__PURE__ */ l("div", { style: d.container, className: b, children: [
3063
+ return /* @__PURE__ */ l("div", { style: A.container, className: w, children: [
3019
3064
  /* @__PURE__ */ n("style", { children: `
3020
3065
  @keyframes spin {
3021
3066
  0% { transform: rotate(0deg); }
3022
3067
  100% { transform: rotate(360deg); }
3023
3068
  }
3024
3069
  ` }),
3025
- /* @__PURE__ */ n("h1", { style: d.title, children: A.title }),
3070
+ /* @__PURE__ */ n("h1", { style: A.title, children: M.title }),
3026
3071
  _()
3027
3072
  ] });
3028
3073
  }
3029
- const St = {
3074
+ const kt = {
3030
3075
  title: "Reset Password",
3031
3076
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3032
3077
  emailLabel: "Email",
@@ -3048,7 +3093,7 @@ const St = {
3048
3093
  resetLoadingText: "Resetting...",
3049
3094
  resetSuccessMessage: "Password reset successfully!",
3050
3095
  passwordMismatchError: "Passwords do not match"
3051
- }, vt = {
3096
+ }, xt = {
3052
3097
  container: {
3053
3098
  maxWidth: "400px",
3054
3099
  margin: "0 auto",
@@ -3140,113 +3185,113 @@ const St = {
3140
3185
  cursor: "pointer"
3141
3186
  }
3142
3187
  };
3143
- function Kt({
3188
+ function Yt({
3144
3189
  copy: i = {},
3145
3190
  styles: e = {},
3146
3191
  mode: t = "request",
3147
3192
  token: r = "",
3148
3193
  onSuccess: s,
3149
3194
  onError: o,
3150
- onBackToLogin: p,
3151
- onModeChange: b,
3195
+ onBackToLogin: h,
3196
+ onModeChange: w,
3152
3197
  className: k
3153
3198
  }) {
3154
- const [S, T] = x(""), [m, f] = x(r), [u, y] = x(""), [R, C] = x(""), [q, A] = x(!1), [d, P] = x(""), [E, z] = x(""), [G, $] = x({}), { requestPasswordReset: _, confirmPasswordReset: v } = ae(), { tenant: M } = se(), I = { ...St, ...i }, a = { ...vt, ...e }, L = () => {
3199
+ const [b, P] = v(""), [m, p] = v(r), [u, y] = v(""), [L, R] = v(""), [z, M] = v(!1), [A, d] = v(""), [C, F] = v(""), [G, U] = v({}), { requestPasswordReset: _, confirmPasswordReset: x } = ae(), { tenant: T } = se(), E = { ...kt, ...i }, c = { ...xt, ...e }, I = () => {
3155
3200
  const H = {};
3156
- return S.trim() || (H.email = !0), $(H), Object.keys(H).length === 0;
3157
- }, c = () => {
3201
+ return b.trim() || (H.email = !0), U(H), Object.keys(H).length === 0;
3202
+ }, S = () => {
3158
3203
  const H = {};
3159
- return m.trim() || (H.token = !0), u.trim() || (H.newPassword = !0), R.trim() || (H.confirmPassword = !0), $(H), Object.keys(H).length === 0;
3160
- }, h = async (H) => {
3161
- if (H.preventDefault(), !!L()) {
3162
- if (!(M != null && M.id)) {
3163
- P("Tenant not found");
3204
+ return m.trim() || (H.token = !0), u.trim() || (H.newPassword = !0), L.trim() || (H.confirmPassword = !0), U(H), Object.keys(H).length === 0;
3205
+ }, g = async (H) => {
3206
+ if (H.preventDefault(), !!I()) {
3207
+ if (!(T != null && T.id)) {
3208
+ d("Tenant not found");
3164
3209
  return;
3165
3210
  }
3166
- A(!0), P(""), z("");
3211
+ M(!0), d(""), F("");
3167
3212
  try {
3168
- await _({ email: S, tenantId: M.id }), z(I.successMessage), s == null || s();
3213
+ await _({ email: b, tenantId: T.id }), F(E.successMessage), s == null || s();
3169
3214
  } catch (N) {
3170
- const O = N.message || I.errorMessage;
3171
- P(O), o == null || o(O);
3215
+ const W = N.message || E.errorMessage;
3216
+ d(W), o == null || o(W);
3172
3217
  } finally {
3173
- A(!1);
3218
+ M(!1);
3174
3219
  }
3175
3220
  }
3176
- }, g = async (H) => {
3177
- if (H.preventDefault(), !!c()) {
3178
- if (u !== R) {
3179
- P(I.passwordMismatchError), $({ confirmPassword: !0 });
3221
+ }, a = async (H) => {
3222
+ if (H.preventDefault(), !!S()) {
3223
+ if (u !== L) {
3224
+ d(E.passwordMismatchError), U({ confirmPassword: !0 });
3180
3225
  return;
3181
3226
  }
3182
- A(!0), P(""), z("");
3227
+ M(!0), d(""), F("");
3183
3228
  try {
3184
- await v({ token: m, newPassword: u }), z(I.resetSuccessMessage), s == null || s();
3229
+ await x({ token: m, newPassword: u }), F(E.resetSuccessMessage), s == null || s();
3185
3230
  } catch (N) {
3186
- const O = N.message || I.errorMessage;
3187
- P(O), o == null || o(O);
3231
+ const W = N.message || E.errorMessage;
3232
+ d(W), o == null || o(W);
3188
3233
  } finally {
3189
- A(!1);
3234
+ M(!1);
3190
3235
  }
3191
3236
  }
3192
- }, w = (H) => ({
3193
- ...a.input,
3194
- ...G[H] ? a.inputError : {}
3195
- }), j = () => ({
3196
- ...a.button,
3197
- ...q ? a.buttonLoading : {}
3237
+ }, f = (H) => ({
3238
+ ...c.input,
3239
+ ...G[H] ? c.inputError : {}
3240
+ }), O = () => ({
3241
+ ...c.button,
3242
+ ...z ? c.buttonLoading : {}
3198
3243
  });
3199
3244
  if (t === "reset") {
3200
- const H = m && u && R;
3201
- return /* @__PURE__ */ l("div", { className: k, style: a.container, children: [
3202
- /* @__PURE__ */ n("h2", { style: a.title, children: I.resetTitle }),
3203
- /* @__PURE__ */ n("p", { style: a.subtitle, children: I.resetSubtitle }),
3204
- /* @__PURE__ */ l("form", { onSubmit: g, style: a.form, children: [
3205
- /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3206
- /* @__PURE__ */ n("label", { style: a.label, children: I.tokenLabel }),
3245
+ const H = m && u && L;
3246
+ return /* @__PURE__ */ l("div", { className: k, style: c.container, children: [
3247
+ /* @__PURE__ */ n("h2", { style: c.title, children: E.resetTitle }),
3248
+ /* @__PURE__ */ n("p", { style: c.subtitle, children: E.resetSubtitle }),
3249
+ /* @__PURE__ */ l("form", { onSubmit: a, style: c.form, children: [
3250
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
3251
+ /* @__PURE__ */ n("label", { style: c.label, children: E.tokenLabel }),
3207
3252
  /* @__PURE__ */ n(
3208
3253
  "input",
3209
3254
  {
3210
3255
  type: "text",
3211
3256
  value: m,
3212
3257
  onChange: (N) => {
3213
- f(N.target.value), G.token && $((O) => ({ ...O, token: !1 }));
3258
+ p(N.target.value), G.token && U((W) => ({ ...W, token: !1 }));
3214
3259
  },
3215
- placeholder: I.tokenPlaceholder,
3216
- style: w("token"),
3217
- disabled: q
3260
+ placeholder: E.tokenPlaceholder,
3261
+ style: f("token"),
3262
+ disabled: z
3218
3263
  }
3219
3264
  )
3220
3265
  ] }),
3221
- /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3222
- /* @__PURE__ */ n("label", { style: a.label, children: I.newPasswordLabel }),
3266
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
3267
+ /* @__PURE__ */ n("label", { style: c.label, children: E.newPasswordLabel }),
3223
3268
  /* @__PURE__ */ n(
3224
3269
  "input",
3225
3270
  {
3226
3271
  type: "password",
3227
3272
  value: u,
3228
3273
  onChange: (N) => {
3229
- y(N.target.value), G.newPassword && $((O) => ({ ...O, newPassword: !1 }));
3274
+ y(N.target.value), G.newPassword && U((W) => ({ ...W, newPassword: !1 }));
3230
3275
  },
3231
- placeholder: I.newPasswordPlaceholder,
3232
- style: w("newPassword"),
3233
- disabled: q
3276
+ placeholder: E.newPasswordPlaceholder,
3277
+ style: f("newPassword"),
3278
+ disabled: z
3234
3279
  }
3235
3280
  )
3236
3281
  ] }),
3237
- /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3238
- /* @__PURE__ */ n("label", { style: a.label, children: I.confirmPasswordLabel }),
3282
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
3283
+ /* @__PURE__ */ n("label", { style: c.label, children: E.confirmPasswordLabel }),
3239
3284
  /* @__PURE__ */ n(
3240
3285
  "input",
3241
3286
  {
3242
3287
  type: "password",
3243
- value: R,
3288
+ value: L,
3244
3289
  onChange: (N) => {
3245
- C(N.target.value), G.confirmPassword && $((O) => ({ ...O, confirmPassword: !1 })), d === I.passwordMismatchError && P("");
3290
+ R(N.target.value), G.confirmPassword && U((W) => ({ ...W, confirmPassword: !1 })), A === E.passwordMismatchError && d("");
3246
3291
  },
3247
- placeholder: I.confirmPasswordPlaceholder,
3248
- style: w("confirmPassword"),
3249
- disabled: q
3292
+ placeholder: E.confirmPasswordPlaceholder,
3293
+ style: f("confirmPassword"),
3294
+ disabled: z
3250
3295
  }
3251
3296
  )
3252
3297
  ] }),
@@ -3254,44 +3299,44 @@ function Kt({
3254
3299
  "button",
3255
3300
  {
3256
3301
  type: "submit",
3257
- disabled: !H || q,
3302
+ disabled: !H || z,
3258
3303
  style: {
3259
- ...j(),
3260
- ...!H || q ? a.buttonDisabled : {}
3304
+ ...O(),
3305
+ ...!H || z ? c.buttonDisabled : {}
3261
3306
  },
3262
- children: q ? I.resetLoadingText : I.resetSubmitButton
3307
+ children: z ? E.resetLoadingText : E.resetSubmitButton
3263
3308
  }
3264
3309
  ),
3265
- d && /* @__PURE__ */ n("div", { style: a.errorText, children: d }),
3266
- E && /* @__PURE__ */ n("div", { style: a.successText, children: E })
3310
+ A && /* @__PURE__ */ n("div", { style: c.errorText, children: A }),
3311
+ C && /* @__PURE__ */ n("div", { style: c.successText, children: C })
3267
3312
  ] }),
3268
- /* @__PURE__ */ l("div", { style: a.linkContainer, children: [
3269
- /* @__PURE__ */ n("a", { onClick: p, style: a.link, children: I.backToLoginLink }),
3270
- b && /* @__PURE__ */ l(U, { children: [
3313
+ /* @__PURE__ */ l("div", { style: c.linkContainer, children: [
3314
+ /* @__PURE__ */ n("a", { onClick: h, style: c.link, children: E.backToLoginLink }),
3315
+ w && /* @__PURE__ */ l(q, { children: [
3271
3316
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3272
- /* @__PURE__ */ n("a", { onClick: () => b("request"), style: a.link, children: "Request New Link" })
3317
+ /* @__PURE__ */ n("a", { onClick: () => w("request"), style: c.link, children: "Request New Link" })
3273
3318
  ] })
3274
3319
  ] })
3275
3320
  ] });
3276
3321
  }
3277
- const Y = S;
3278
- return /* @__PURE__ */ l("div", { className: k, style: a.container, children: [
3279
- /* @__PURE__ */ n("h2", { style: a.title, children: I.title }),
3280
- /* @__PURE__ */ n("p", { style: a.subtitle, children: I.subtitle }),
3281
- /* @__PURE__ */ l("form", { onSubmit: h, style: a.form, children: [
3282
- /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3283
- /* @__PURE__ */ n("label", { style: a.label, children: I.emailLabel }),
3322
+ const K = b;
3323
+ return /* @__PURE__ */ l("div", { className: k, style: c.container, children: [
3324
+ /* @__PURE__ */ n("h2", { style: c.title, children: E.title }),
3325
+ /* @__PURE__ */ n("p", { style: c.subtitle, children: E.subtitle }),
3326
+ /* @__PURE__ */ l("form", { onSubmit: g, style: c.form, children: [
3327
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
3328
+ /* @__PURE__ */ n("label", { style: c.label, children: E.emailLabel }),
3284
3329
  /* @__PURE__ */ n(
3285
3330
  "input",
3286
3331
  {
3287
3332
  type: "email",
3288
- value: S,
3333
+ value: b,
3289
3334
  onChange: (H) => {
3290
- T(H.target.value), G.email && $((N) => ({ ...N, email: !1 }));
3335
+ P(H.target.value), G.email && U((N) => ({ ...N, email: !1 }));
3291
3336
  },
3292
- placeholder: I.emailPlaceholder,
3293
- style: w("email"),
3294
- disabled: q
3337
+ placeholder: E.emailPlaceholder,
3338
+ style: f("email"),
3339
+ disabled: z
3295
3340
  }
3296
3341
  )
3297
3342
  ] }),
@@ -3299,27 +3344,27 @@ function Kt({
3299
3344
  "button",
3300
3345
  {
3301
3346
  type: "submit",
3302
- disabled: !Y || q,
3347
+ disabled: !K || z,
3303
3348
  style: {
3304
- ...j(),
3305
- ...!Y || q ? a.buttonDisabled : {}
3349
+ ...O(),
3350
+ ...!K || z ? c.buttonDisabled : {}
3306
3351
  },
3307
- children: q ? I.loadingText : I.submitButton
3352
+ children: z ? E.loadingText : E.submitButton
3308
3353
  }
3309
3354
  ),
3310
- d && /* @__PURE__ */ n("div", { style: a.errorText, children: d }),
3311
- E && /* @__PURE__ */ n("div", { style: a.successText, children: E })
3355
+ A && /* @__PURE__ */ n("div", { style: c.errorText, children: A }),
3356
+ C && /* @__PURE__ */ n("div", { style: c.successText, children: C })
3312
3357
  ] }),
3313
- /* @__PURE__ */ l("div", { style: a.linkContainer, children: [
3314
- /* @__PURE__ */ n("a", { onClick: p, style: a.link, children: I.backToLoginLink }),
3315
- b && /* @__PURE__ */ l(U, { children: [
3358
+ /* @__PURE__ */ l("div", { style: c.linkContainer, children: [
3359
+ /* @__PURE__ */ n("a", { onClick: h, style: c.link, children: E.backToLoginLink }),
3360
+ w && /* @__PURE__ */ l(q, { children: [
3316
3361
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3317
- /* @__PURE__ */ n("a", { onClick: () => b("reset"), style: a.link, children: "I have a token" })
3362
+ /* @__PURE__ */ n("a", { onClick: () => w("reset"), style: c.link, children: "I have a token" })
3318
3363
  ] })
3319
3364
  ] })
3320
3365
  ] });
3321
3366
  }
3322
- const xt = () => /* @__PURE__ */ n(
3367
+ const At = () => /* @__PURE__ */ n(
3323
3368
  "div",
3324
3369
  {
3325
3370
  style: {
@@ -3331,7 +3376,7 @@ const xt = () => /* @__PURE__ */ n(
3331
3376
  },
3332
3377
  children: /* @__PURE__ */ n("div", { children: "Loading..." })
3333
3378
  }
3334
- ), kt = ({ error: i, retry: e }) => /* @__PURE__ */ l(
3379
+ ), Tt = ({ error: i, retry: e }) => /* @__PURE__ */ l(
3335
3380
  "div",
3336
3381
  {
3337
3382
  style: {
@@ -3365,40 +3410,40 @@ const xt = () => /* @__PURE__ */ n(
3365
3410
  ]
3366
3411
  }
3367
3412
  );
3368
- function Jt({
3413
+ function Qt({
3369
3414
  children: i,
3370
3415
  loadingFallback: e,
3371
3416
  errorFallback: t,
3372
3417
  requireTenant: r = !0
3373
3418
  }) {
3374
- const { isAppLoading: s, appError: o, retryApp: p } = oe(), b = Me(), k = (b == null ? void 0 : b.isTenantLoading) ?? !1, S = (b == null ? void 0 : b.tenantError) ?? null, T = (b == null ? void 0 : b.tenantSlug) ?? null, m = (b == null ? void 0 : b.retryTenant) ?? (() => {
3375
- }), f = r && b && T, u = s || f && k, y = o || (f ? S : null), R = () => {
3376
- o && p(), S && b && m();
3419
+ const { isAppLoading: s, appError: o, retryApp: h } = oe(), w = Me(), k = (w == null ? void 0 : w.isTenantLoading) ?? !1, b = (w == null ? void 0 : w.tenantError) ?? null, P = (w == null ? void 0 : w.tenantSlug) ?? null, m = (w == null ? void 0 : w.retryTenant) ?? (() => {
3420
+ }), p = r && w && P, u = s || p && k, y = o || (p ? b : null), L = () => {
3421
+ o && h(), b && w && m();
3377
3422
  };
3378
3423
  if (u)
3379
- return /* @__PURE__ */ n(U, { children: e || /* @__PURE__ */ n(xt, {}) });
3424
+ return /* @__PURE__ */ n(q, { children: e || /* @__PURE__ */ n(At, {}) });
3380
3425
  if (y) {
3381
- const C = typeof t == "function" ? t(y, R) : t || /* @__PURE__ */ n(kt, { error: y, retry: R });
3382
- return /* @__PURE__ */ n(U, { children: C });
3426
+ const R = typeof t == "function" ? t(y, L) : t || /* @__PURE__ */ n(Tt, { error: y, retry: L });
3427
+ return /* @__PURE__ */ n(q, { children: R });
3383
3428
  }
3384
- return /* @__PURE__ */ n(U, { children: i });
3429
+ return /* @__PURE__ */ n(q, { children: i });
3385
3430
  }
3386
- function Yt(i = !0) {
3387
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: s } = oe(), o = Me(), p = (o == null ? void 0 : o.isTenantLoading) ?? !1, b = (o == null ? void 0 : o.tenantError) ?? null, k = (o == null ? void 0 : o.tenant) ?? null, S = (o == null ? void 0 : o.tenantSlug) ?? null, T = (o == null ? void 0 : o.retryTenant) ?? (() => {
3388
- }), m = i && o && S, f = e || m && p, u = t || (m ? b : null);
3431
+ function Xt(i = !0) {
3432
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: s } = oe(), o = Me(), h = (o == null ? void 0 : o.isTenantLoading) ?? !1, w = (o == null ? void 0 : o.tenantError) ?? null, k = (o == null ? void 0 : o.tenant) ?? null, b = (o == null ? void 0 : o.tenantSlug) ?? null, P = (o == null ? void 0 : o.retryTenant) ?? (() => {
3433
+ }), m = i && o && b, p = e || m && h, u = t || (m ? w : null);
3389
3434
  return {
3390
- isLoading: f,
3435
+ isLoading: p,
3391
3436
  error: u,
3392
- isReady: !f && !u && s !== null && (!m || k !== null),
3437
+ isReady: !p && !u && s !== null && (!m || k !== null),
3393
3438
  retry: () => {
3394
- t && r(), b && o && T();
3439
+ t && r(), w && o && P();
3395
3440
  },
3396
3441
  // Individual states
3397
3442
  app: { isLoading: e, error: t, data: s },
3398
- tenant: o ? { isLoading: p, error: b, data: k } : null
3443
+ tenant: o ? { isLoading: h, error: w, data: k } : null
3399
3444
  };
3400
3445
  }
3401
- class Qt {
3446
+ class Zt {
3402
3447
  constructor(e, t) {
3403
3448
  this.httpService = e, this.sessionManager = t;
3404
3449
  }
@@ -3466,7 +3511,7 @@ class Qt {
3466
3511
  };
3467
3512
  }
3468
3513
  }
3469
- class Xt {
3514
+ class er {
3470
3515
  constructor(e, t) {
3471
3516
  this.httpService = e, this.sessionManager = t;
3472
3517
  }
@@ -3517,7 +3562,7 @@ class Xt {
3517
3562
  });
3518
3563
  }
3519
3564
  }
3520
- class Zt {
3565
+ class tr {
3521
3566
  constructor(e) {
3522
3567
  this.httpService = e;
3523
3568
  }
@@ -3526,7 +3571,7 @@ class Zt {
3526
3571
  return await this.httpService.get("/health");
3527
3572
  }
3528
3573
  }
3529
- class er {
3574
+ class rr {
3530
3575
  // Date string to Date object
3531
3576
  static toDate(e) {
3532
3577
  return new Date(e);
@@ -3649,47 +3694,47 @@ class er {
3649
3694
  }
3650
3695
  }
3651
3696
  export {
3652
- er as ApiMappers,
3697
+ rr as ApiMappers,
3653
3698
  ve as AppApiService,
3654
- Jt as AppLoader,
3655
- Et as AppProvider,
3656
- Ue as AuthApiService,
3657
- Dt as AuthProvider,
3658
- Wt as FeatureFlag,
3659
- Je as FeatureFlagApiService,
3660
- Ht as FeatureFlagProvider,
3661
- Zt as HealthApiService,
3699
+ Qt as AppLoader,
3700
+ Ct as AppProvider,
3701
+ ze as AuthApiService,
3702
+ Nt as AuthProvider,
3703
+ jt as FeatureFlag,
3704
+ Qe as FeatureFlagApiService,
3705
+ Ut as FeatureFlagProvider,
3706
+ tr as HealthApiService,
3662
3707
  re as HttpService,
3663
- zt as LandingRoute,
3664
- jt as LoginForm,
3665
- _t as MagicLinkForm,
3666
- Gt as MagicLinkVerify,
3667
- Kt as PasswordRecoveryForm,
3668
- Qt as PermissionApiService,
3669
- Bt as Protected,
3670
- Ut as ProtectedRoute,
3671
- xe as RoleApiService,
3708
+ Wt as LandingRoute,
3709
+ _t as LoginForm,
3710
+ Kt as MagicLinkForm,
3711
+ Jt as MagicLinkVerify,
3712
+ Yt as PasswordRecoveryForm,
3713
+ Zt as PermissionApiService,
3714
+ qt as Protected,
3715
+ zt as ProtectedRoute,
3716
+ ke as RoleApiService,
3672
3717
  we as SessionManager,
3673
- Vt as SignupForm,
3674
- Qe as SubscriptionApiService,
3675
- Ot as SubscriptionGuard,
3676
- Xt as SubscriptionPlanApiService,
3677
- Nt as SubscriptionProvider,
3718
+ Gt as SignupForm,
3719
+ Ze as SubscriptionApiService,
3720
+ Vt as SubscriptionGuard,
3721
+ er as SubscriptionPlanApiService,
3722
+ Bt as SubscriptionProvider,
3678
3723
  ue as TenantApiService,
3679
- Ct as TenantProvider,
3680
- qt as TenantRoute,
3681
- qe as UserApiService,
3724
+ $t as TenantProvider,
3725
+ Ot as TenantRoute,
3726
+ Oe as UserApiService,
3682
3727
  ie as UserType,
3683
- Rt as useApi,
3728
+ Ft as useApi,
3684
3729
  oe as useApp,
3685
- Yt as useAppLoaderState,
3730
+ Xt as useAppLoaderState,
3686
3731
  ae as useAuth,
3687
- Ye as useFeatureFlags,
3688
- Ft as useSettings,
3689
- Xe as useSubscription,
3732
+ Xe as useFeatureFlags,
3733
+ Ht as useSettings,
3734
+ et as useSubscription,
3690
3735
  me as useTenant,
3691
3736
  se as useTenantInfo,
3692
3737
  Me as useTenantOptional,
3693
- $t as useTenantSettings
3738
+ Dt as useTenantSettings
3694
3739
  };
3695
3740
  //# sourceMappingURL=index.es.js.map