@skylabs-digital/react-identity-access 2.2.0 → 2.4.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,6 +1,6 @@
1
- import { jsx as n, Fragment as B, jsxs as a } from "react/jsx-runtime";
2
- import { createContext as he, useMemo as Q, useState as k, useCallback as ne, useEffect as te, useContext as ce } from "react";
3
- import { useLocation as we, Navigate as pe } from "react-router-dom";
1
+ import { jsx as n, Fragment as B, jsxs as c } 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
+ import { useLocation as be, Navigate as pe } from "react-router-dom";
4
4
  class re {
5
5
  // SessionManager instance
6
6
  constructor(e, t = 1e4) {
@@ -16,40 +16,40 @@ 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 g = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, y = (s == null ? void 0 : s.timeout) || this.timeout;
20
- let A = {
19
+ const g = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, w = (s == null ? void 0 : s.timeout) || this.timeout;
20
+ let x = {
21
21
  "Content-Type": "application/json",
22
22
  ...s == null ? void 0 : s.headers
23
23
  };
24
24
  if (!(s != null && s.skipAuth) && this.sessionManager)
25
25
  try {
26
- const f = await this.sessionManager.getAuthHeaders();
27
- A = { ...A, ...f };
28
- } catch (f) {
29
- console.warn("Failed to inject auth headers:", f);
26
+ const m = await this.sessionManager.getAuthHeaders();
27
+ x = { ...x, ...m };
28
+ } catch (m) {
29
+ console.warn("Failed to inject auth headers:", m);
30
30
  }
31
- const w = new AbortController(), T = setTimeout(() => w.abort(), y);
31
+ const b = new AbortController(), A = setTimeout(() => b.abort(), w);
32
32
  try {
33
- const f = await fetch(g, {
33
+ const m = await fetch(g, {
34
34
  method: e,
35
- headers: A,
35
+ headers: x,
36
36
  body: r ? JSON.stringify(r) : void 0,
37
- signal: w.signal
37
+ signal: b.signal
38
38
  });
39
- if (clearTimeout(T), f.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
39
+ if (clearTimeout(A), m.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
40
40
  try {
41
- const h = this.sessionManager.getTokens();
42
- if (h != null && h.refreshToken)
41
+ const u = this.sessionManager.getTokens();
42
+ if (u != null && u.refreshToken)
43
43
  return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, r, s, !0);
44
44
  } catch {
45
- throw new Error(`HTTP ${f.status}: ${f.statusText}`);
45
+ throw new Error(`HTTP ${m.status}: ${m.statusText}`);
46
46
  }
47
- if (!f.ok)
48
- throw new Error(`HTTP ${f.status}: ${f.statusText}`);
49
- const p = f.headers.get("content-type");
50
- return !p || !p.includes("application/json") ? {} : await f.json();
51
- } catch (f) {
52
- throw clearTimeout(T), f instanceof Error && f.name === "AbortError" ? new Error(`Request timeout after ${y}ms`) : f;
47
+ if (!m.ok)
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();
51
+ } catch (m) {
52
+ throw clearTimeout(A), m instanceof Error && m.name === "AbortError" ? new Error(`Request timeout after ${w}ms`) : m;
53
53
  }
54
54
  }
55
55
  async get(e, t) {
@@ -65,7 +65,7 @@ class re {
65
65
  return this.request("DELETE", e, void 0, t);
66
66
  }
67
67
  }
68
- class Se {
68
+ class ve {
69
69
  constructor(e, t) {
70
70
  this.httpService = e, this.sessionManager = t;
71
71
  }
@@ -124,32 +124,32 @@ class Se {
124
124
  })).data;
125
125
  }
126
126
  }
127
- const Te = he(null);
128
- function kt({ config: i, children: e }) {
129
- const t = Q(
127
+ const Pe = he(null);
128
+ function Ct({ config: i, children: e }) {
129
+ const t = X(
130
130
  () => {
131
- var p, h, m;
131
+ var f, u, y;
132
132
  return {
133
- enabled: ((p = i.cache) == null ? void 0 : p.enabled) ?? !0,
134
- ttl: ((h = i.cache) == null ? void 0 : h.ttl) ?? 3e5,
133
+ enabled: ((f = i.cache) == null ? void 0 : f.enabled) ?? !0,
134
+ ttl: ((u = i.cache) == null ? void 0 : u.ttl) ?? 3e5,
135
135
  // 5 minutes default
136
- storageKey: ((m = i.cache) == null ? void 0 : m.storageKey) ?? `app_cache_${i.appId}`
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] = k(() => {
140
+ ), [r, s] = v(() => {
141
141
  if (!t.enabled) return null;
142
142
  try {
143
- const p = localStorage.getItem(t.storageKey);
144
- if (!p) return null;
145
- const h = JSON.parse(p);
146
- return Date.now() - h.timestamp < t.ttl && h.appId === i.appId ? h.data : (localStorage.removeItem(t.storageKey), null);
143
+ const f = localStorage.getItem(t.storageKey);
144
+ if (!f) return null;
145
+ const u = JSON.parse(f);
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, g] = k(!r), [y, A] = k(null), w = Q(() => {
151
- const p = () => {
152
- T();
150
+ }), [o, g] = v(!r), [w, x] = v(null), b = X(() => {
151
+ const f = () => {
152
+ A();
153
153
  };
154
154
  return {
155
155
  appId: i.appId,
@@ -157,19 +157,19 @@ function kt({ config: i, children: e }) {
157
157
  // App info
158
158
  appInfo: r,
159
159
  isAppLoading: o,
160
- appError: y,
161
- retryApp: p
160
+ appError: w,
161
+ retryApp: f
162
162
  };
163
- }, [i, r, o, y]), T = ne(
164
- async (p = !1) => {
165
- if (!(!p && t.enabled && r))
163
+ }, [i, r, o, w]), A = ne(
164
+ async (f = !1) => {
165
+ if (!(!f && t.enabled && r))
166
166
  try {
167
- g(!0), A(null);
168
- const h = new re(i.baseUrl), R = await new Se(h, {}).getPublicAppInfo(i.appId);
169
- if (s(R), t.enabled)
167
+ g(!0), x(null);
168
+ const u = new re(i.baseUrl), E = await new ve(u, {}).getPublicAppInfo(i.appId);
169
+ if (s(E), t.enabled)
170
170
  try {
171
171
  const C = {
172
- data: R,
172
+ data: E,
173
173
  timestamp: Date.now(),
174
174
  appId: i.appId
175
175
  };
@@ -177,46 +177,46 @@ function kt({ config: i, children: e }) {
177
177
  } catch (C) {
178
178
  console.warn("Failed to cache app info:", C);
179
179
  }
180
- } catch (h) {
181
- const m = h instanceof Error ? h : new Error("Failed to load app information");
182
- A(m), s(null);
180
+ } catch (u) {
181
+ const y = u instanceof Error ? u : new Error("Failed to load app information");
182
+ x(y), s(null);
183
183
  } finally {
184
184
  g(!1);
185
185
  }
186
186
  },
187
187
  [i.baseUrl, i.appId, t, r]
188
- ), f = ne(async () => {
188
+ ), m = ne(async () => {
189
189
  if (!(!t.enabled || !r))
190
190
  try {
191
- const p = localStorage.getItem(t.storageKey);
192
- if (!p) return;
193
- const h = JSON.parse(p);
194
- if (Date.now() - h.timestamp > t.ttl * 0.5) {
195
- const R = new re(i.baseUrl), U = await new Se(R, {}).getPublicAppInfo(i.appId);
196
- s(U);
197
- const P = {
198
- data: U,
191
+ const f = localStorage.getItem(t.storageKey);
192
+ if (!f) return;
193
+ const u = JSON.parse(f);
194
+ if (Date.now() - u.timestamp > t.ttl * 0.5) {
195
+ const E = new re(i.baseUrl), q = await new ve(E, {}).getPublicAppInfo(i.appId);
196
+ s(q);
197
+ const T = {
198
+ data: q,
199
199
  timestamp: Date.now(),
200
200
  appId: i.appId
201
201
  };
202
- localStorage.setItem(t.storageKey, JSON.stringify(P));
202
+ localStorage.setItem(t.storageKey, JSON.stringify(T));
203
203
  }
204
- } catch (p) {
205
- console.warn("Background app refresh failed:", p);
204
+ } catch (f) {
205
+ console.warn("Background app refresh failed:", f);
206
206
  }
207
207
  }, [i, t, r]);
208
208
  return te(() => {
209
- r ? f() : T();
210
- }, []), /* @__PURE__ */ n(Te.Provider, { value: w, children: e });
209
+ r ? m() : A();
210
+ }, []), /* @__PURE__ */ n(Pe.Provider, { value: b, children: e });
211
211
  }
212
212
  function oe() {
213
- const i = ce(Te);
213
+ const i = ce(Pe);
214
214
  if (!i)
215
215
  throw new Error("useApp must be used within an AppProvider");
216
216
  return i;
217
217
  }
218
- const At = oe;
219
- class ye {
218
+ const $t = oe;
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);
222
222
  }
@@ -369,7 +369,7 @@ class ye {
369
369
  return e !== null && !this.isTokenExpired(e);
370
370
  }
371
371
  }
372
- class He {
372
+ class ze {
373
373
  constructor(e) {
374
374
  this.httpService = e;
375
375
  }
@@ -414,7 +414,7 @@ class He {
414
414
  });
415
415
  }
416
416
  }
417
- class ve {
417
+ class xe {
418
418
  constructor(e, t) {
419
419
  this.httpService = e, this.sessionManager = t;
420
420
  }
@@ -490,7 +490,7 @@ class ve {
490
490
  };
491
491
  }
492
492
  }
493
- class Ne {
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 Be(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) {
@@ -624,23 +624,64 @@ function Be(i, e) {
624
624
  const r = i.split(".");
625
625
  return r.length >= 3 && r[0] !== "www" ? r[0] : null;
626
626
  }
627
- function Ue(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 qe(i, e, t) {
631
+ function je(i, e, t) {
632
632
  const { tenantMode: r, baseDomain: s, selectorParam: o } = i;
633
- return r === "subdomain" ? Be(e.hostname, s) : r === "selector" ? Ue(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 ze(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
- const be = he(null);
642
- function Tt({ config: i, children: e }) {
643
- const { baseUrl: t, appInfo: r, appId: s } = oe(), o = ne(() => typeof window > "u" ? null : qe(
641
+ const fe = "_auth";
642
+ function Ge(i) {
643
+ const e = JSON.stringify(i);
644
+ return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
645
+ }
646
+ function Ke(i) {
647
+ try {
648
+ let e = i.replace(/-/g, "+").replace(/_/g, "/");
649
+ for (; e.length % 4; )
650
+ e += "=";
651
+ const t = atob(e), r = JSON.parse(t);
652
+ return typeof r.accessToken == "string" && typeof r.refreshToken == "string" && typeof r.expiresIn == "number" ? r : null;
653
+ } catch {
654
+ return null;
655
+ }
656
+ }
657
+ function Je() {
658
+ if (typeof window > "u")
659
+ return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
660
+ const e = new URLSearchParams(window.location.search).get(fe);
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;
673
+ }
674
+ function Ye() {
675
+ if (typeof window > "u") return;
676
+ const i = new URL(window.location.href);
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());
681
+ }
682
+ const Se = he(null);
683
+ function Dt({ config: i, children: e }) {
684
+ const { baseUrl: t, appInfo: r, appId: s } = oe(), o = ne(() => typeof window > "u" ? null : je(
644
685
  {
645
686
  tenantMode: i.tenantMode || "selector",
646
687
  baseDomain: i.baseDomain,
@@ -651,118 +692,118 @@ function Tt({ config: i, children: e }) {
651
692
  search: window.location.search
652
693
  },
653
694
  window.localStorage
654
- ), [i.tenantMode, i.baseDomain, i.selectorParam]), [g, y] = k(() => o()), A = Q(
695
+ ), [i.tenantMode, i.baseDomain, i.selectorParam]), [g, w] = v(() => o()), x = X(
655
696
  () => {
656
- var l, x, b;
697
+ var l, I, k;
657
698
  return {
658
699
  enabled: ((l = i.cache) == null ? void 0 : l.enabled) ?? !0,
659
- ttl: ((x = i.cache) == null ? void 0 : x.ttl) ?? 5 * 60 * 1e3,
700
+ ttl: ((I = i.cache) == null ? void 0 : I.ttl) ?? 5 * 60 * 1e3,
660
701
  // 5 minutes default
661
- storageKey: ((b = i.cache) == null ? void 0 : b.storageKey) ?? `tenant_cache_${g || "default"}`
702
+ storageKey: ((k = i.cache) == null ? void 0 : k.storageKey) ?? `tenant_cache_${g || "default"}`
662
703
  };
663
704
  },
664
705
  [i.cache, g]
665
- ), [w, T] = k(() => {
706
+ ), [b, A] = v(() => {
666
707
  if (i.initialTenant) return i.initialTenant;
667
- if (!A.enabled || !g) return null;
708
+ if (!x.enabled || !g) return null;
668
709
  try {
669
- const l = localStorage.getItem(A.storageKey);
710
+ const l = localStorage.getItem(x.storageKey);
670
711
  if (!l) return null;
671
- const x = JSON.parse(l);
672
- return Date.now() - x.timestamp < A.ttl && x.tenantSlug === g ? x.data : (localStorage.removeItem(A.storageKey), null);
712
+ const I = JSON.parse(l);
713
+ return Date.now() - I.timestamp < x.ttl && I.tenantSlug === g ? I.data : (localStorage.removeItem(x.storageKey), null);
673
714
  } catch {
674
715
  return null;
675
716
  }
676
- }), [f, p] = k(!w && !i.initialTenant), [h, m] = k(null), [R, C] = k(null), [U, P] = k(!1), [u, M] = k(null);
717
+ }), [m, f] = v(!b && !i.initialTenant), [u, y] = v(null), [E, C] = v(null), [q, T] = v(!1), [d, P] = v(null);
677
718
  te(() => {
678
719
  const l = o();
679
- y(l);
720
+ w(l);
680
721
  }, [o]);
681
- const E = (r == null ? void 0 : r.settingsSchema) || null, q = ne(
682
- async (l, x = !1) => {
683
- if (!(!x && A.enabled && w && w.domain === l))
722
+ const R = (r == null ? void 0 : r.settingsSchema) || null, z = ne(
723
+ async (l, I = !1) => {
724
+ if (!(!I && x.enabled && b && b.domain === l))
684
725
  try {
685
- p(!0), m(null);
686
- const b = new re(t), c = await new ue(b, s).getPublicTenantInfo(l);
687
- if (T(c), A.enabled)
726
+ f(!0), y(null);
727
+ const k = new re(t), a = await new ue(k, s).getPublicTenantInfo(l);
728
+ if (A(a), x.enabled)
688
729
  try {
689
- const S = {
690
- data: c,
730
+ const p = {
731
+ data: a,
691
732
  timestamp: Date.now(),
692
733
  tenantSlug: l
693
734
  };
694
- localStorage.setItem(A.storageKey, JSON.stringify(S));
695
- } catch (S) {
696
- console.warn("Failed to cache tenant info:", S);
735
+ localStorage.setItem(x.storageKey, JSON.stringify(p));
736
+ } catch (p) {
737
+ console.warn("Failed to cache tenant info:", p);
697
738
  }
698
- } catch (b) {
699
- const d = b instanceof Error ? b : new Error("Failed to load tenant information");
700
- m(d), T(null);
739
+ } catch (k) {
740
+ const h = k instanceof Error ? k : new Error("Failed to load tenant information");
741
+ y(h), A(null);
701
742
  } finally {
702
- p(!1);
743
+ f(!1);
703
744
  }
704
745
  },
705
- [t, s, A, w]
706
- ), V = ne(async () => {
707
- if (!(!A.enabled || !w || !g))
746
+ [t, s, x, b]
747
+ ), G = ne(async () => {
748
+ if (!(!x.enabled || !b || !g))
708
749
  try {
709
- const l = localStorage.getItem(A.storageKey);
750
+ const l = localStorage.getItem(x.storageKey);
710
751
  if (!l) return;
711
- const x = JSON.parse(l);
712
- if (Date.now() - x.timestamp > A.ttl * 0.5) {
713
- const d = new re(t), S = await new ue(d, s).getPublicTenantInfo(g);
714
- T(S);
715
- const _ = {
716
- data: S,
752
+ const I = JSON.parse(l);
753
+ if (Date.now() - I.timestamp > x.ttl * 0.5) {
754
+ const h = new re(t), p = await new ue(h, s).getPublicTenantInfo(g);
755
+ A(p);
756
+ const O = {
757
+ data: p,
717
758
  timestamp: Date.now(),
718
759
  tenantSlug: g
719
760
  };
720
- localStorage.setItem(A.storageKey, JSON.stringify(_));
761
+ localStorage.setItem(x.storageKey, JSON.stringify(O));
721
762
  }
722
763
  } catch (l) {
723
764
  console.warn("Background tenant refresh failed:", l);
724
765
  }
725
- }, [t, s, A, w, g]), $ = ne(async () => {
726
- if (w != null && w.id)
766
+ }, [t, s, x, b, g]), $ = ne(async () => {
767
+ if (b != null && b.id)
727
768
  try {
728
- P(!0), M(null);
729
- const l = new re(t), b = await new ue(l, w.appId).getTenantSettings(w.id);
730
- C(b);
769
+ T(!0), P(null);
770
+ const l = new re(t), k = await new ue(l, b.appId).getTenantSettings(b.id);
771
+ C(k);
731
772
  } catch (l) {
732
- const x = l instanceof Error ? l : new Error("Failed to load tenant settings");
733
- M(x), C(null);
773
+ const I = l instanceof Error ? l : new Error("Failed to load tenant settings");
774
+ P(I), C(null);
734
775
  } finally {
735
- P(!1);
776
+ T(!1);
736
777
  }
737
- }, [t, w]), j = ne(() => {
778
+ }, [t, b]), _ = ne(() => {
738
779
  $();
739
- }, [$]), v = ne(
780
+ }, [$]), S = ne(
740
781
  (l) => {
741
- if (!E)
782
+ if (!R)
742
783
  return { isValid: !0, errors: [] };
743
- const x = [];
784
+ const I = [];
744
785
  try {
745
- return E.properties && Object.entries(E.properties).forEach(([b, d]) => {
746
- var S;
747
- const c = l[b];
748
- if ((S = E.required) != null && S.includes(b) && c == null) {
749
- x.push(`Field '${b}' is required`);
786
+ return R.properties && Object.entries(R.properties).forEach(([k, h]) => {
787
+ var p;
788
+ const a = l[k];
789
+ if ((p = R.required) != null && p.includes(k) && a == null) {
790
+ I.push(`Field '${k}' is required`);
750
791
  return;
751
792
  }
752
- if (c != null) {
753
- if (d.type) {
754
- const _ = d.type, ee = typeof c;
755
- _ === "string" && ee !== "string" ? x.push(`Field '${b}' must be a string`) : (_ === "number" || _ === "integer") && ee !== "number" ? x.push(`Field '${b}' must be a number`) : _ === "boolean" && ee !== "boolean" ? x.push(`Field '${b}' must be a boolean`) : _ === "array" && !Array.isArray(c) && x.push(`Field '${b}' must be an array`);
793
+ if (a != null) {
794
+ if (h.type) {
795
+ const O = h.type, K = typeof a;
796
+ O === "string" && K !== "string" ? I.push(`Field '${k}' must be a string`) : (O === "number" || O === "integer") && K !== "number" ? I.push(`Field '${k}' must be a number`) : O === "boolean" && K !== "boolean" ? I.push(`Field '${k}' must be a boolean`) : O === "array" && !Array.isArray(a) && I.push(`Field '${k}' must be an array`);
756
797
  }
757
- d.minLength !== void 0 && typeof c == "string" && c.length < d.minLength && x.push(
758
- `Field '${b}' must be at least ${d.minLength} characters long`
759
- ), d.maxLength !== void 0 && typeof c == "string" && c.length > d.maxLength && x.push(
760
- `Field '${b}' must be no more than ${d.maxLength} characters long`
761
- ), d.minimum !== void 0 && typeof c == "number" && c < d.minimum && x.push(`Field '${b}' must be at least ${d.minimum}`), d.maximum !== void 0 && typeof c == "number" && c > d.maximum && x.push(`Field '${b}' must be no more than ${d.maximum}`), d.pattern && typeof c == "string" && (new RegExp(d.pattern).test(c) || x.push(`Field '${b}' does not match the required pattern`)), d.enum && !d.enum.includes(c) && x.push(`Field '${b}' must be one of: ${d.enum.join(", ")}`);
798
+ h.minLength !== void 0 && typeof a == "string" && a.length < h.minLength && I.push(
799
+ `Field '${k}' must be at least ${h.minLength} characters long`
800
+ ), h.maxLength !== void 0 && typeof a == "string" && a.length > h.maxLength && I.push(
801
+ `Field '${k}' must be no more than ${h.maxLength} characters long`
802
+ ), h.minimum !== void 0 && typeof a == "number" && a < h.minimum && I.push(`Field '${k}' must be at least ${h.minimum}`), h.maximum !== void 0 && typeof a == "number" && a > h.maximum && I.push(`Field '${k}' must be no more than ${h.maximum}`), h.pattern && typeof a == "string" && (new RegExp(h.pattern).test(a) || I.push(`Field '${k}' does not match the required pattern`)), h.enum && !h.enum.includes(a) && I.push(`Field '${k}' must be one of: ${h.enum.join(", ")}`);
762
803
  }
763
804
  }), {
764
- isValid: x.length === 0,
765
- errors: x
805
+ isValid: I.length === 0,
806
+ errors: I
766
807
  };
767
808
  } catch {
768
809
  return {
@@ -771,89 +812,91 @@ function Tt({ config: i, children: e }) {
771
812
  };
772
813
  }
773
814
  },
774
- [E]
815
+ [R]
775
816
  );
776
817
  te(() => {
777
- !i.initialTenant && g ? w ? V() : q(g) : !i.initialTenant && !g && (T(null), m(null), p(!1));
778
- }, [i.initialTenant, g, w, q, V]), te(() => {
779
- w != null && w.id ? $() : (C(null), M(null), P(!1));
780
- }, [w == null ? void 0 : w.id, $]);
781
- const I = ne(
782
- (l, x = "reload") => {
783
- const b = i.tenantMode || "selector";
784
- if (localStorage.setItem("tenant", l), b === "subdomain") {
785
- const d = window.location.hostname, c = ze(
818
+ !i.initialTenant && g ? b ? G() : z(g) : !i.initialTenant && !g && (A(null), y(null), f(!1));
819
+ }, [i.initialTenant, g, b, z, G]), te(() => {
820
+ b != null && b.id ? $() : (C(null), P(null), T(!1));
821
+ }, [b == null ? void 0 : b.id, $]);
822
+ const M = ne(
823
+ (l, I) => {
824
+ const { mode: k = "reload", tokens: h, redirectPath: a } = I || {}, p = i.tenantMode || "selector";
825
+ if (localStorage.setItem("tenant", l), p === "subdomain") {
826
+ const O = window.location.hostname, K = _e(
786
827
  l,
787
- d,
828
+ O,
788
829
  i.baseDomain
789
830
  );
790
- if (!c) {
831
+ if (!K) {
791
832
  console.warn(
792
833
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
793
- d
834
+ O
794
835
  );
795
836
  return;
796
837
  }
797
- const S = `${window.location.protocol}//${c}${window.location.pathname}${window.location.search}`;
798
- window.location.href = S;
799
- } else if (b === "selector") {
800
- const d = new URLSearchParams(window.location.search);
801
- if (d.set(i.selectorParam || "tenant", l), x === "reload") {
802
- const c = `${window.location.pathname}?${d.toString()}${window.location.hash}`;
803
- window.location.href = c;
838
+ const H = a || window.location.pathname, N = new URL(`${window.location.protocol}//${K}${H}`);
839
+ new URLSearchParams(window.location.search).forEach((D, J) => {
840
+ J !== fe && N.searchParams.set(J, D);
841
+ }), h && N.searchParams.set(fe, Ge(h)), window.location.href = N.toString();
842
+ } else if (p === "selector") {
843
+ const O = a || window.location.pathname, K = new URLSearchParams(window.location.search);
844
+ if (K.set(i.selectorParam || "tenant", l), k === "reload") {
845
+ const H = `${O}?${K.toString()}${window.location.hash}`;
846
+ window.location.href = H;
804
847
  } else {
805
- const c = `${window.location.pathname}?${d.toString()}${window.location.hash}`;
806
- window.history.pushState({}, "", c), y(l), q(l);
848
+ const H = `${O}?${K.toString()}${window.location.hash}`;
849
+ window.history.pushState({}, "", H), w(l), z(l);
807
850
  }
808
851
  }
809
852
  },
810
- [i.tenantMode, i.selectorParam, q, g]
811
- ), L = Q(() => ({
853
+ [i.tenantMode, i.selectorParam, i.baseDomain, z]
854
+ ), L = X(() => ({
812
855
  // Tenant info
813
- tenant: w,
856
+ tenant: b,
814
857
  tenantSlug: g,
815
- isTenantLoading: f,
816
- tenantError: h,
858
+ isTenantLoading: m,
859
+ tenantError: u,
817
860
  retryTenant: () => {
818
- g && q(g);
861
+ g && z(g);
819
862
  },
820
863
  // Settings
821
- settings: R,
822
- settingsSchema: E,
823
- isSettingsLoading: U,
824
- settingsError: u,
864
+ settings: E,
865
+ settingsSchema: R,
866
+ isSettingsLoading: q,
867
+ settingsError: d,
825
868
  // Actions
826
- refreshSettings: j,
827
- switchTenant: I,
869
+ refreshSettings: _,
870
+ switchTenant: M,
828
871
  // Validation
829
- validateSettings: v
872
+ validateSettings: S
830
873
  }), [
831
- w,
874
+ b,
832
875
  g,
833
- f,
834
- h,
835
- R,
836
- E,
837
- U,
876
+ m,
838
877
  u,
839
- j,
840
- I,
841
- v
878
+ E,
879
+ R,
880
+ q,
881
+ d,
882
+ _,
883
+ M,
884
+ S
842
885
  ]);
843
- return /* @__PURE__ */ n(be.Provider, { value: L, children: e });
886
+ return /* @__PURE__ */ n(Se.Provider, { value: L, children: e });
844
887
  }
845
- function fe() {
846
- const i = ce(be);
888
+ function me() {
889
+ const i = ce(Se);
847
890
  if (!i)
848
891
  throw new Error("useTenant must be used within a TenantProvider");
849
892
  return i;
850
893
  }
851
- function Pe() {
852
- return ce(be);
894
+ function Me() {
895
+ return ce(Se);
853
896
  }
854
- const Pt = fe;
855
- function Mt() {
856
- const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = fe();
897
+ const Ft = me;
898
+ function Ht() {
899
+ const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = me();
857
900
  return {
858
901
  settings: i,
859
902
  settingsSchema: e,
@@ -863,7 +906,7 @@ function Mt() {
863
906
  };
864
907
  }
865
908
  function se() {
866
- const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = fe();
909
+ const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = me();
867
910
  return {
868
911
  tenant: i,
869
912
  tenantSlug: e,
@@ -872,273 +915,323 @@ function se() {
872
915
  retry: s
873
916
  };
874
917
  }
875
- const Me = he(null);
876
- function It({ config: i = {}, children: e }) {
877
- const { appId: t, baseUrl: r } = oe(), { tenant: s, tenantSlug: o, switchTenant: g } = fe(), [y, A] = k(i.initialRoles || []), [w, T] = k(!i.initialRoles), [f, p] = k(null), [h, m] = k(!1), [R, C] = k(null), [U, P] = k(0), u = Q(() => new ye({
918
+ const Ie = he(null);
919
+ function Nt({ config: i = {}, children: e }) {
920
+ const { appId: t, baseUrl: r } = oe(), { tenant: s, tenantSlug: o, switchTenant: g } = me(), [w, x] = v(i.initialRoles || []), [b, A] = v(!i.initialRoles), [m, f] = v(null), [u, y] = v(!1), [E, C] = v(null), [q, T] = v(0), d = X(() => new we({
878
921
  tenantSlug: o,
879
922
  // SessionManager will generate storageKey internally
880
923
  onRefreshFailed: i.onRefreshFailed,
881
924
  baseUrl: r
882
- }), [o, r, i.onRefreshFailed]), M = Q(() => {
883
- const x = new re(r);
884
- return x.setSessionManager(u), x;
885
- }, [r, u]), E = Q(() => new He(new re(r)), [r]), q = Q(() => new Ne(M, u), [M, u]), V = Q(() => new ve(new re(r)), [r]), $ = Q(() => f || u.getUser(), [f, u]), j = Q(() => $ != null && $.roleId && y.find((x) => x.id === $.roleId) || null, [$, y]), v = Q(() => (j == null ? void 0 : j.permissions) || [], [j]), I = Q(() => u.hasValidSession() && f !== null, [u, f]), L = 5 * 60 * 1e3, l = Q(() => {
886
- const x = async (F = !1) => {
925
+ }), [o, r, i.onRefreshFailed]), P = X(() => {
926
+ const a = new re(r);
927
+ return a.setSessionManager(d), a;
928
+ }, [r, d]), R = X(() => new ze(new re(r)), [r]), z = X(() => new Oe(P, d), [P, d]), G = X(() => new xe(new re(r)), [r]), $ = X(() => m || d.getUser(), [m, d]), _ = X(() => $ != null && $.roleId && w.find((a) => a.id === $.roleId) || null, [$, w]), S = X(() => (_ == null ? void 0 : _.permissions) || [], [_]), M = X(() => d.hasValidSession() && m !== null, [d, m]), L = 5 * 60 * 1e3, l = X(() => {
929
+ const a = async (F = !1) => {
887
930
  try {
888
- if (!u.hasValidSession())
931
+ if (!d.hasValidSession())
889
932
  return;
890
- const N = Date.now();
891
- if (!F && N - U < L && f)
933
+ const U = Date.now();
934
+ if (!F && U - q < L && m)
892
935
  return;
893
- const W = u.getUserId();
894
- if (!W) {
936
+ const V = d.getUserId();
937
+ if (!V) {
895
938
  console.warn("[AuthProvider] No userId available in token or storage");
896
939
  return;
897
940
  }
898
- m(!0), C(null);
899
- const X = await q.getUserById(W);
900
- p(X), u.setUser(X), P(Date.now());
901
- } catch (N) {
902
- const G = N instanceof Error ? N : new Error("Failed to load user data");
903
- C(G), console.error("[AuthProvider] Failed to load user data:", G);
941
+ y(!0), C(null);
942
+ const Z = await z.getUserById(V);
943
+ f(Z), d.setUser(Z), T(Date.now());
944
+ } catch (U) {
945
+ const Y = U instanceof Error ? U : new Error("Failed to load user data");
946
+ C(Y), console.error("[AuthProvider] Failed to load user data:", Y);
904
947
  } finally {
905
- m(!1);
948
+ y(!1);
906
949
  }
907
- }, b = async () => {
908
- await x();
909
- }, d = async (F) => {
910
- const { username: N, password: G, tenantSlug: W } = F;
911
- let X = s == null ? void 0 : s.id, Y = o, Z = u;
912
- W && (X = (await new ue(M, t).getPublicTenantInfo(W)).id, Y = W);
913
- const J = await E.login({
914
- username: N,
915
- password: G,
950
+ }, p = async () => {
951
+ await a();
952
+ }, O = async (F) => {
953
+ const { username: U, password: Y, tenantSlug: V } = F;
954
+ let Z = s == null ? void 0 : s.id, Q = o, ee = d;
955
+ V && (Z = (await new ue(P, t).getPublicTenantInfo(V)).id, Q = V);
956
+ const j = await R.login({
957
+ username: U,
958
+ password: Y,
916
959
  appId: t,
917
- tenantId: X
918
- }), le = W && W !== o;
919
- if (le && (Z = new ye({
920
- tenantSlug: Y,
960
+ tenantId: Z
961
+ }), le = V && V !== o;
962
+ if (le && (ee = new we({
963
+ tenantSlug: Q,
921
964
  baseUrl: r
922
- })), Z.setTokens({
923
- accessToken: J.accessToken,
924
- refreshToken: J.refreshToken,
925
- expiresIn: J.expiresIn
926
- }), J.user) {
927
- Z.setUser(J.user), p(J.user);
965
+ })), ee.setTokens({
966
+ accessToken: j.accessToken,
967
+ refreshToken: j.refreshToken,
968
+ expiresIn: j.expiresIn
969
+ }), j.user) {
970
+ ee.setUser(j.user), f(j.user);
928
971
  try {
929
- await x();
972
+ await a();
930
973
  } catch (de) {
931
974
  console.warn("Failed to load complete user data after login:", de);
932
975
  }
933
976
  }
934
- return le && Y && Y !== o && g(Y), J;
935
- }, c = async (F) => {
936
- const { email: N, phoneNumber: G, name: W, password: X, lastName: Y, tenantId: Z } = F;
937
- if (!N && !G)
977
+ return le && Q && Q !== o && g(Q, {
978
+ tokens: {
979
+ accessToken: j.accessToken,
980
+ refreshToken: j.refreshToken,
981
+ expiresIn: j.expiresIn
982
+ }
983
+ }), j;
984
+ }, K = async (F) => {
985
+ const { email: U, phoneNumber: Y, name: V, password: Z, lastName: Q, tenantId: ee } = F;
986
+ if (!U && !Y)
938
987
  throw new Error("Either email or phoneNumber is required");
939
- if (!W || !X)
988
+ if (!V || !Z)
940
989
  throw new Error("Name and password are required");
941
- const J = Z ?? (s == null ? void 0 : s.id);
942
- return await E.signup({
943
- email: N,
944
- phoneNumber: G,
945
- name: W,
946
- password: X,
947
- tenantId: J,
948
- lastName: Y,
990
+ const j = ee ?? (s == null ? void 0 : s.id);
991
+ return await R.signup({
992
+ email: U,
993
+ phoneNumber: Y,
994
+ name: V,
995
+ password: Z,
996
+ tenantId: j,
997
+ lastName: Q,
949
998
  appId: t
950
999
  });
951
- }, S = async (F) => {
952
- const { email: N, phoneNumber: G, name: W, password: X, tenantName: Y, lastName: Z } = F;
953
- if (!N && !G)
1000
+ }, H = async (F) => {
1001
+ const { email: U, phoneNumber: Y, name: V, password: Z, tenantName: Q, lastName: ee } = F;
1002
+ if (!U && !Y)
954
1003
  throw new Error("Either email or phoneNumber is required");
955
- if (!W || !X || !Y)
1004
+ if (!V || !Z || !Q)
956
1005
  throw new Error("Name, password, and tenantName are required");
957
- return await E.signupTenantAdmin({
958
- email: N,
959
- phoneNumber: G,
960
- name: W,
961
- password: X,
962
- tenantName: Y,
1006
+ return await R.signupTenantAdmin({
1007
+ email: U,
1008
+ phoneNumber: Y,
1009
+ name: V,
1010
+ password: Z,
1011
+ tenantName: Q,
963
1012
  appId: t,
964
- lastName: Z
1013
+ lastName: ee
965
1014
  });
966
- }, _ = async (F) => {
967
- const { currentPassword: N, newPassword: G } = F, W = await u.getAuthHeaders();
968
- await E.changePassword({ currentPassword: N, newPassword: G }, W);
969
- }, ee = async (F) => {
970
- const { email: N, tenantId: G } = F, W = G ?? (s == null ? void 0 : s.id);
971
- if (!W)
1015
+ }, N = async (F) => {
1016
+ const { currentPassword: U, newPassword: Y } = F, V = await d.getAuthHeaders();
1017
+ await R.changePassword({ currentPassword: U, newPassword: Y }, V);
1018
+ }, W = async (F) => {
1019
+ const { email: U, tenantId: Y } = F, V = Y ?? (s == null ? void 0 : s.id);
1020
+ if (!V)
972
1021
  throw new Error("tenantId is required for password reset");
973
- await E.requestPasswordReset({ email: N, tenantId: W });
974
- }, z = async (F) => {
975
- const { token: N, newPassword: G } = F;
976
- await E.confirmPasswordReset({ token: N, newPassword: G });
977
- }, H = async (F) => {
978
- const { email: N, frontendUrl: G, name: W, lastName: X, tenantId: Y } = F, Z = Y ?? (s == null ? void 0 : s.id);
979
- if (!Z)
1022
+ await R.requestPasswordReset({ email: U, tenantId: V });
1023
+ }, D = async (F) => {
1024
+ const { token: U, newPassword: Y } = F;
1025
+ await R.confirmPasswordReset({ token: U, newPassword: Y });
1026
+ }, J = async (F) => {
1027
+ const { email: U, frontendUrl: Y, name: V, lastName: Z, tenantId: Q } = F, ee = Q ?? (s == null ? void 0 : s.id);
1028
+ if (!ee)
980
1029
  throw new Error("tenantId is required for magic link authentication");
981
- return await E.sendMagicLink({
982
- email: N,
983
- tenantId: Z,
984
- frontendUrl: G,
985
- name: W,
986
- lastName: X,
1030
+ return await R.sendMagicLink({
1031
+ email: U,
1032
+ tenantId: ee,
1033
+ frontendUrl: Y,
1034
+ name: V,
1035
+ lastName: Z,
987
1036
  appId: t
988
1037
  });
989
- }, O = async (F) => {
990
- const { token: N, email: G, tenantSlug: W } = F;
991
- let X = s == null ? void 0 : s.id, Y = o, Z = u;
992
- W && (X = (await new ue(M, t).getPublicTenantInfo(W)).id, Y = W);
993
- const J = await E.verifyMagicLink({
994
- token: N,
995
- email: G,
1038
+ }, ge = async (F) => {
1039
+ const { token: U, email: Y, tenantSlug: V } = F;
1040
+ let Z = s == null ? void 0 : s.id, Q = o, ee = d;
1041
+ V && (Z = (await new ue(P, t).getPublicTenantInfo(V)).id, Q = V);
1042
+ const j = await R.verifyMagicLink({
1043
+ token: U,
1044
+ email: Y,
996
1045
  appId: t,
997
- tenantId: X
998
- }), le = W && W !== o;
999
- if (le && (Z = new ye({
1000
- tenantSlug: Y,
1046
+ tenantId: Z
1047
+ }), le = V && V !== o;
1048
+ if (le && (ee = new we({
1049
+ tenantSlug: Q,
1001
1050
  baseUrl: r
1002
- })), Z.setTokens({
1003
- accessToken: J.accessToken,
1004
- refreshToken: J.refreshToken,
1005
- expiresIn: J.expiresIn
1006
- }), J.user) {
1007
- Z.setUser(J.user), p(J.user);
1051
+ })), ee.setTokens({
1052
+ accessToken: j.accessToken,
1053
+ refreshToken: j.refreshToken,
1054
+ expiresIn: j.expiresIn
1055
+ }), j.user) {
1056
+ ee.setUser(j.user), f(j.user);
1008
1057
  try {
1009
- await x();
1058
+ await a();
1010
1059
  } catch (de) {
1011
1060
  console.warn("Failed to load complete user data after magic link login:", de);
1012
1061
  }
1013
1062
  }
1014
- return le && Y && Y !== o && g(Y), J;
1015
- }, D = async () => {
1016
- const F = u.getTokens();
1063
+ return le && Q && Q !== o && g(Q, {
1064
+ tokens: {
1065
+ accessToken: j.accessToken,
1066
+ refreshToken: j.refreshToken,
1067
+ expiresIn: j.expiresIn
1068
+ }
1069
+ }), j;
1070
+ }, Ce = async () => {
1071
+ const F = d.getTokens();
1017
1072
  if (!(F != null && F.refreshToken))
1018
1073
  throw new Error("No refresh token available");
1019
- const N = await E.refreshToken({
1074
+ const U = await R.refreshToken({
1020
1075
  refreshToken: F.refreshToken
1021
1076
  });
1022
- u.setTokens({
1023
- accessToken: N.accessToken,
1024
- refreshToken: N.refreshToken || F.refreshToken,
1025
- expiresIn: N.expiresIn
1077
+ d.setTokens({
1078
+ accessToken: U.accessToken,
1079
+ refreshToken: U.refreshToken || F.refreshToken,
1080
+ expiresIn: U.expiresIn
1026
1081
  });
1027
- }, K = () => {
1028
- u.clearSession(), p(null), C(null);
1029
- }, ge = (F) => {
1030
- u.setTokens(F);
1031
- }, Re = () => u.hasValidSession(), Ce = () => {
1032
- u.clearSession(), p(null), C(null);
1033
- }, $e = async () => {
1082
+ }, $e = () => {
1083
+ d.clearSession(), f(null), C(null);
1084
+ }, De = (F) => {
1085
+ d.setTokens(F);
1086
+ }, Fe = () => d.hasValidSession(), He = () => {
1087
+ d.clearSession(), f(null), C(null);
1088
+ }, Ne = async () => {
1034
1089
  if (t)
1035
1090
  try {
1036
- T(!0);
1037
- const { roles: F } = await V.getRolesByApp(t);
1038
- A(F);
1091
+ A(!0);
1092
+ const { roles: F } = await G.getRolesByApp(t);
1093
+ x(F);
1039
1094
  } catch (F) {
1040
1095
  console.error("Failed to fetch roles:", F);
1041
1096
  } finally {
1042
- T(!1);
1097
+ A(!1);
1043
1098
  }
1044
- }, Fe = async () => {
1045
- await $e();
1046
- }, me = (F) => {
1047
- if (!v || v.length === 0)
1099
+ }, Ue = async () => {
1100
+ await Ne();
1101
+ }, ye = (F) => {
1102
+ if (!S || S.length === 0)
1048
1103
  return !1;
1049
1104
  if (typeof F == "string")
1050
- return v.includes(F);
1051
- const N = `${F.resource}.${F.action}`;
1052
- return v.includes(N);
1105
+ return S.includes(F);
1106
+ const U = `${F.resource}.${F.action}`;
1107
+ return S.includes(U);
1053
1108
  };
1054
1109
  return {
1055
1110
  // RFC-003: Authentication state
1056
- isAuthenticated: I,
1057
- sessionManager: u,
1058
- authenticatedHttpService: M,
1059
- login: d,
1060
- signup: c,
1061
- signupTenantAdmin: S,
1062
- sendMagicLink: H,
1063
- verifyMagicLink: O,
1064
- changePassword: _,
1065
- requestPasswordReset: ee,
1066
- confirmPasswordReset: z,
1067
- refreshToken: D,
1068
- logout: K,
1069
- setTokens: ge,
1070
- hasValidSession: Re,
1071
- clearSession: Ce,
1072
- currentUser: f,
1073
- isUserLoading: h,
1074
- userError: R,
1075
- loadUserData: x,
1076
- refreshUser: b,
1077
- userRole: j,
1078
- userPermissions: v,
1079
- availableRoles: y,
1080
- rolesLoading: w,
1081
- hasPermission: me,
1082
- hasAnyPermission: (F) => F.some((N) => me(N)),
1083
- hasAllPermissions: (F) => F.every((N) => me(N)),
1084
- getUserPermissionStrings: () => v || [],
1085
- refreshRoles: Fe
1111
+ isAuthenticated: M,
1112
+ sessionManager: d,
1113
+ authenticatedHttpService: P,
1114
+ login: O,
1115
+ signup: K,
1116
+ signupTenantAdmin: H,
1117
+ sendMagicLink: J,
1118
+ verifyMagicLink: ge,
1119
+ changePassword: N,
1120
+ requestPasswordReset: W,
1121
+ confirmPasswordReset: D,
1122
+ refreshToken: Ce,
1123
+ logout: $e,
1124
+ setTokens: De,
1125
+ hasValidSession: Fe,
1126
+ clearSession: He,
1127
+ currentUser: m,
1128
+ isUserLoading: u,
1129
+ userError: E,
1130
+ loadUserData: a,
1131
+ refreshUser: p,
1132
+ userRole: _,
1133
+ userPermissions: S,
1134
+ availableRoles: w,
1135
+ rolesLoading: b,
1136
+ hasPermission: ye,
1137
+ hasAnyPermission: (F) => F.some((U) => ye(U)),
1138
+ hasAllPermissions: (F) => F.every((U) => ye(U)),
1139
+ getUserPermissionStrings: () => S || [],
1140
+ refreshRoles: Ue
1086
1141
  };
1087
1142
  }, [
1088
- I,
1089
- u,
1090
1143
  M,
1091
- E,
1092
- q,
1093
- V,
1144
+ d,
1145
+ P,
1146
+ R,
1147
+ z,
1148
+ G,
1094
1149
  t,
1095
1150
  s,
1096
1151
  o,
1097
1152
  g,
1098
- y,
1099
- f,
1100
- h,
1101
- R,
1102
- j,
1103
- v,
1104
- U,
1153
+ w,
1154
+ m,
1155
+ u,
1156
+ E,
1157
+ _,
1158
+ S,
1159
+ q,
1105
1160
  L
1106
1161
  ]);
1107
- return te(() => {
1162
+ te(() => {
1108
1163
  !i.initialRoles && t && (async () => {
1109
1164
  try {
1110
- T(!0);
1111
- const b = new re(r), d = new ve(b), { roles: c } = await d.getRolesByApp(t);
1112
- A(c);
1113
- } catch (b) {
1114
- console.error("Failed to fetch roles:", b);
1165
+ A(!0);
1166
+ const p = new re(r), O = new xe(p), { roles: K } = await O.getRolesByApp(t);
1167
+ x(K);
1168
+ } catch (p) {
1169
+ console.error("Failed to fetch roles:", p);
1115
1170
  } finally {
1116
- T(!1);
1171
+ A(!1);
1117
1172
  }
1118
1173
  })();
1119
- }, [t, r, i.initialRoles]), te(() => {
1120
- const x = u.getUser();
1121
- x && u.hasValidSession() && p(x);
1122
- }, [u]), te(() => {
1123
- !f && !h && l.loadUserData().catch(() => {
1124
- });
1125
- }, [f, h, l]), te(() => {
1126
- if (!u.hasValidSession() || !f)
1174
+ }, [t, r, i.initialRoles]);
1175
+ const [I, k] = v(!1), h = qe(!1);
1176
+ return te(() => {
1177
+ if (console.log("[AuthProvider] Cross-subdomain auth effect running", {
1178
+ alreadyChecked: I,
1179
+ alreadyProcessed: h.current,
1180
+ currentUrl: typeof window < "u" ? window.location.href : "SSR"
1181
+ }), I) {
1182
+ console.log("[AuthProvider] URL tokens already checked, skipping");
1183
+ return;
1184
+ }
1185
+ k(!0);
1186
+ const a = Je();
1187
+ console.log("[AuthProvider] URL tokens extraction result:", {
1188
+ found: !!a,
1189
+ hasAccessToken: !!(a != null && a.accessToken)
1190
+ }), a && (h.current = !0, console.log("[AuthProvider] Saving URL tokens to session..."), d.setTokens({
1191
+ accessToken: a.accessToken,
1192
+ refreshToken: a.refreshToken,
1193
+ expiresIn: a.expiresIn
1194
+ }), console.log("[AuthProvider] Tokens saved, verifying session validity:", {
1195
+ hasValidSession: d.hasValidSession()
1196
+ }), Ye(), console.log("[AuthProvider] Loading user data after URL token consumption..."), l.loadUserData().catch((p) => {
1197
+ console.error(
1198
+ "[AuthProvider] Failed to load user data after URL token consumption:",
1199
+ p
1200
+ );
1201
+ }));
1202
+ }, [d, l, I]), te(() => {
1203
+ const a = d.getUser();
1204
+ a && d.hasValidSession() && f(a);
1205
+ }, [d]), te(() => {
1206
+ if (console.log("[AuthProvider] Auto-load effect running", {
1207
+ hasCurrentUser: !!m,
1208
+ isUserLoading: u,
1209
+ hasValidSession: d.hasValidSession(),
1210
+ urlTokensChecked: I,
1211
+ urlTokensProcessed: h.current
1212
+ }), !I) {
1213
+ console.log("[AuthProvider] Waiting for URL tokens check before auto-load");
1214
+ return;
1215
+ }
1216
+ !m && !u && (console.log("[AuthProvider] Auto-loading user data..."), l.loadUserData().catch(() => {
1217
+ }));
1218
+ }, [m, u, l, d, I]), te(() => {
1219
+ if (!d.hasValidSession() || !m)
1127
1220
  return;
1128
- const x = setInterval(() => {
1221
+ const a = setInterval(() => {
1129
1222
  l.loadUserData().catch(() => {
1130
1223
  });
1131
1224
  }, L);
1132
- return () => clearInterval(x);
1133
- }, [u, f, l, L]), /* @__PURE__ */ n(Me.Provider, { value: l, children: e });
1225
+ return () => clearInterval(a);
1226
+ }, [d, m, l, L]), /* @__PURE__ */ n(Ie.Provider, { value: l, children: e });
1134
1227
  }
1135
1228
  function ae() {
1136
- const i = ce(Me);
1229
+ const i = ce(Ie);
1137
1230
  if (!i)
1138
1231
  throw new Error("useAuth must be used within an AuthProvider");
1139
1232
  return i;
1140
1233
  }
1141
- class Oe {
1234
+ class Qe {
1142
1235
  constructor(e, t) {
1143
1236
  this.httpService = e, this.sessionManager = t;
1144
1237
  }
@@ -1218,58 +1311,58 @@ class Oe {
1218
1311
  })).data;
1219
1312
  }
1220
1313
  }
1221
- const Ie = he(null);
1222
- function Lt({ config: i = {}, children: e }) {
1223
- const { baseUrl: t, appId: r } = oe(), { tenant: s } = se(), [o, g] = k([]), [y, A] = k(!1), [w, T] = k(null), f = Q(() => {
1224
- const m = new re(t);
1225
- return new Oe(m);
1226
- }, [t]), p = async () => {
1314
+ const Le = he(null);
1315
+ function Ut({ config: i = {}, children: e }) {
1316
+ const { baseUrl: t, appId: r } = oe(), { tenant: s } = se(), [o, g] = v([]), [w, x] = v(!1), [b, A] = v(null), m = X(() => {
1317
+ const y = new re(t);
1318
+ return new Qe(y);
1319
+ }, [t]), f = async () => {
1227
1320
  if (!(s != null && s.id)) {
1228
1321
  g([]);
1229
1322
  return;
1230
1323
  }
1231
- A(!0), T(null);
1324
+ x(!0), A(null);
1232
1325
  try {
1233
- const m = await f.getTenantFeatureFlags(s.id, r);
1234
- g(m);
1235
- } catch (m) {
1236
- const R = m instanceof Error ? m.message : "Failed to fetch feature flags";
1237
- T(R), i.onError && i.onError(m instanceof Error ? m : new Error(R));
1326
+ const y = await m.getTenantFeatureFlags(s.id, r);
1327
+ g(y);
1328
+ } catch (y) {
1329
+ const E = y instanceof Error ? y.message : "Failed to fetch feature flags";
1330
+ A(E), i.onError && i.onError(y instanceof Error ? y : new Error(E));
1238
1331
  } finally {
1239
- A(!1);
1332
+ x(!1);
1240
1333
  }
1241
1334
  };
1242
1335
  te(() => {
1243
- p();
1244
- const m = i.refreshInterval || 5 * 60 * 1e3, R = setInterval(p, m);
1245
- return () => clearInterval(R);
1336
+ f();
1337
+ const y = i.refreshInterval || 5 * 60 * 1e3, E = setInterval(f, y);
1338
+ return () => clearInterval(E);
1246
1339
  }, [s == null ? void 0 : s.id, i.refreshInterval]);
1247
- const h = Q(() => ({
1340
+ const u = X(() => ({
1248
1341
  featureFlags: o,
1249
- loading: y,
1250
- error: w,
1251
- isEnabled: (P) => {
1252
- const u = o.find((M) => M.key === P);
1253
- return (u == null ? void 0 : u.value) === !0;
1342
+ loading: w,
1343
+ error: b,
1344
+ isEnabled: (T) => {
1345
+ const d = o.find((P) => P.key === T);
1346
+ return (d == null ? void 0 : d.value) === !0;
1254
1347
  },
1255
- getFlag: (P) => o.find((u) => u.key === P),
1256
- getFlagState: (P) => {
1257
- const u = o.find((M) => M.key === P);
1258
- return u ? u.value ? "enabled" : "disabled" : "not_found";
1348
+ getFlag: (T) => o.find((d) => d.key === T),
1349
+ getFlagState: (T) => {
1350
+ const d = o.find((P) => P.key === T);
1351
+ return d ? d.value ? "enabled" : "disabled" : "not_found";
1259
1352
  },
1260
1353
  refresh: async () => {
1261
- await p();
1354
+ await f();
1262
1355
  }
1263
- }), [o, y, w]);
1264
- return /* @__PURE__ */ n(Ie.Provider, { value: h, children: e });
1356
+ }), [o, w, b]);
1357
+ return /* @__PURE__ */ n(Le.Provider, { value: u, children: e });
1265
1358
  }
1266
- function We() {
1267
- const i = ce(Ie);
1359
+ function Xe() {
1360
+ const i = ce(Le);
1268
1361
  if (!i)
1269
1362
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1270
1363
  return i;
1271
1364
  }
1272
- class je {
1365
+ class Ze {
1273
1366
  constructor(e, t) {
1274
1367
  this.httpService = e, this.sessionManager = t;
1275
1368
  }
@@ -1335,64 +1428,64 @@ class je {
1335
1428
  )).data;
1336
1429
  }
1337
1430
  }
1338
- const Le = he(void 0);
1339
- function Et({ config: i = {}, children: e }) {
1340
- const { baseUrl: t } = oe(), { tenant: r } = se(), [s, o] = k(null), [g, y] = k(!1), [A, w] = k(null), T = Q(() => {
1341
- const h = new re(t);
1342
- return new je(h);
1343
- }, [t]), f = async () => {
1431
+ const Re = he(void 0);
1432
+ function Bt({ config: i = {}, children: e }) {
1433
+ const { baseUrl: t } = oe(), { tenant: r } = se(), [s, o] = v(null), [g, w] = v(!1), [x, b] = v(null), A = X(() => {
1434
+ const u = new re(t);
1435
+ return new Ze(u);
1436
+ }, [t]), m = async () => {
1344
1437
  if (!(r != null && r.id)) {
1345
1438
  o(null);
1346
1439
  return;
1347
1440
  }
1348
- y(!0), w(null);
1441
+ w(!0), b(null);
1349
1442
  try {
1350
- const h = await T.getTenantSubscriptionFeatures(r.id);
1351
- o(h);
1352
- } catch (h) {
1353
- const m = h instanceof Error ? h.message : "Failed to fetch subscription";
1354
- w(m), i.onError && i.onError(h instanceof Error ? h : new Error(m));
1443
+ const u = await A.getTenantSubscriptionFeatures(r.id);
1444
+ o(u);
1445
+ } catch (u) {
1446
+ const y = u instanceof Error ? u.message : "Failed to fetch subscription";
1447
+ b(y), i.onError && i.onError(u instanceof Error ? u : new Error(y));
1355
1448
  } finally {
1356
- y(!1);
1449
+ w(!1);
1357
1450
  }
1358
1451
  };
1359
1452
  te(() => {
1360
- if (f(), !i.refreshInterval) return;
1361
- const h = i.refreshInterval || 10 * 60 * 1e3, m = setInterval(f, h);
1362
- return () => clearInterval(m);
1453
+ if (m(), !i.refreshInterval) return;
1454
+ const u = i.refreshInterval || 10 * 60 * 1e3, y = setInterval(m, u);
1455
+ return () => clearInterval(y);
1363
1456
  }, [r == null ? void 0 : r.id, i.refreshInterval]);
1364
- const p = Q(() => {
1365
- const h = (s == null ? void 0 : s.features) || [];
1457
+ const f = X(() => {
1458
+ const u = (s == null ? void 0 : s.features) || [];
1366
1459
  return {
1367
1460
  subscription: s,
1368
- features: h,
1461
+ features: u,
1369
1462
  loading: g,
1370
- error: A,
1371
- isFeatureEnabled: (u) => {
1372
- const M = h.find((E) => E.key === u);
1373
- return M ? M.type === "BOOLEAN" || M.type === "boolean" ? M.value === !0 : !!M.value : !1;
1463
+ error: x,
1464
+ isFeatureEnabled: (d) => {
1465
+ const P = u.find((R) => R.key === d);
1466
+ return P ? P.type === "BOOLEAN" || P.type === "boolean" ? P.value === !0 : !!P.value : !1;
1374
1467
  },
1375
- getFeature: (u) => h.find((M) => M.key === u),
1376
- getFeatureValue: (u, M) => {
1377
- const E = h.find((q) => q.key === u);
1378
- return E ? E.value : M;
1468
+ getFeature: (d) => u.find((P) => P.key === d),
1469
+ getFeatureValue: (d, P) => {
1470
+ const R = u.find((z) => z.key === d);
1471
+ return R ? R.value : P;
1379
1472
  },
1380
- hasAllowedPlan: (u) => !s || !s.isActive ? !1 : u.includes(s.planId),
1473
+ hasAllowedPlan: (d) => !s || !s.isActive ? !1 : d.includes(s.planId),
1381
1474
  refresh: async () => {
1382
- await f();
1475
+ await m();
1383
1476
  }
1384
1477
  };
1385
- }, [s, g, A]);
1386
- return /* @__PURE__ */ n(Le.Provider, { value: p, children: e });
1478
+ }, [s, g, x]);
1479
+ return /* @__PURE__ */ n(Re.Provider, { value: f, children: e });
1387
1480
  }
1388
- function Ve() {
1389
- const i = ce(Le);
1481
+ function et() {
1482
+ const i = ce(Re);
1390
1483
  if (i === void 0)
1391
1484
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1392
1485
  return i;
1393
1486
  }
1394
1487
  var ie = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(ie || {});
1395
- const xe = () => /* @__PURE__ */ a(
1488
+ const ke = () => /* @__PURE__ */ c(
1396
1489
  "div",
1397
1490
  {
1398
1491
  style: {
@@ -1429,11 +1522,11 @@ const xe = () => /* @__PURE__ */ a(
1429
1522
  )
1430
1523
  ]
1431
1524
  }
1432
- ), ke = ({
1525
+ ), Ae = ({
1433
1526
  userType: i,
1434
1527
  minUserType: e,
1435
1528
  missingPermissions: t
1436
- }) => /* @__PURE__ */ a(
1529
+ }) => /* @__PURE__ */ c(
1437
1530
  "div",
1438
1531
  {
1439
1532
  style: {
@@ -1451,26 +1544,26 @@ const xe = () => /* @__PURE__ */ a(
1451
1544
  children: [
1452
1545
  /* @__PURE__ */ n("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1453
1546
  /* @__PURE__ */ n("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1454
- e && i ? /* @__PURE__ */ a(B, { children: [
1455
- /* @__PURE__ */ a("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1547
+ e && i ? /* @__PURE__ */ c(B, { children: [
1548
+ /* @__PURE__ */ c("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1456
1549
  "This content requires ",
1457
1550
  /* @__PURE__ */ n("strong", { children: e }),
1458
1551
  " access level or higher."
1459
1552
  ] }),
1460
- /* @__PURE__ */ a("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1553
+ /* @__PURE__ */ c("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1461
1554
  "Your current access level: ",
1462
1555
  /* @__PURE__ */ n("strong", { children: i })
1463
1556
  ] })
1464
- ] }) : /* @__PURE__ */ a(B, { children: [
1557
+ ] }) : /* @__PURE__ */ c(B, { children: [
1465
1558
  /* @__PURE__ */ n("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1466
- t && t.length > 0 && /* @__PURE__ */ a("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1559
+ t && t.length > 0 && /* @__PURE__ */ c("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1467
1560
  "Required permissions: ",
1468
1561
  /* @__PURE__ */ n("strong", { children: t.join(", ") })
1469
1562
  ] })
1470
1563
  ] })
1471
1564
  ]
1472
1565
  }
1473
- ), Ge = (i, e) => {
1566
+ ), tt = (i, e) => {
1474
1567
  const t = {
1475
1568
  [ie.USER]: 1,
1476
1569
  [ie.TENANT_ADMIN]: 2,
@@ -1478,28 +1571,28 @@ const xe = () => /* @__PURE__ */ a(
1478
1571
  };
1479
1572
  return t[i] >= t[e];
1480
1573
  };
1481
- function Rt({
1574
+ function qt({
1482
1575
  children: i,
1483
1576
  fallback: e,
1484
1577
  minUserType: t,
1485
1578
  requiredPermissions: r,
1486
1579
  requireAllPermissions: s = !1
1487
1580
  }) {
1488
- const { hasValidSession: o, sessionManager: g, hasPermission: y, hasAnyPermission: A, hasAllPermissions: w } = ae();
1581
+ const { hasValidSession: o, sessionManager: g, hasPermission: w, hasAnyPermission: x, hasAllPermissions: b } = ae();
1489
1582
  if (!o())
1490
- return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(xe, {}) });
1491
- const T = g.getUser();
1492
- if (!T)
1493
- return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(xe, {}) });
1494
- if (t && !Ge(T.userType, t))
1495
- return /* @__PURE__ */ n(ke, { userType: T.userType, minUserType: t });
1496
- if (r && r.length > 0 && !(s ? w(r) : A(r))) {
1497
- const p = r.filter((h) => !y(h)).map((h) => typeof h == "string" ? h : h.name);
1498
- return /* @__PURE__ */ n(ke, { missingPermissions: p });
1583
+ return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(ke, {}) });
1584
+ const A = g.getUser();
1585
+ if (!A)
1586
+ return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(ke, {}) });
1587
+ if (t && !tt(A.userType, t))
1588
+ return /* @__PURE__ */ n(Ae, { userType: A.userType, minUserType: t });
1589
+ if (r && r.length > 0 && !(s ? b(r) : x(r))) {
1590
+ const f = r.filter((u) => !w(u)).map((u) => typeof u == "string" ? u : u.name);
1591
+ return /* @__PURE__ */ n(Ae, { missingPermissions: f });
1499
1592
  }
1500
1593
  return /* @__PURE__ */ n(B, { children: i });
1501
1594
  }
1502
- const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1595
+ const rt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1503
1596
  "div",
1504
1597
  {
1505
1598
  style: {
@@ -1512,7 +1605,7 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1512
1605
  backgroundColor: "#f9fafb",
1513
1606
  textAlign: "center"
1514
1607
  },
1515
- children: /* @__PURE__ */ a(
1608
+ children: /* @__PURE__ */ c(
1516
1609
  "div",
1517
1610
  {
1518
1611
  style: {
@@ -1526,7 +1619,7 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1526
1619
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1527
1620
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1528
1621
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1529
- /* @__PURE__ */ a("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1622
+ /* @__PURE__ */ c("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1530
1623
  "Redirecting to ",
1531
1624
  i,
1532
1625
  "..."
@@ -1535,7 +1628,7 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1535
1628
  }
1536
1629
  )
1537
1630
  }
1538
- ), Ae = ({
1631
+ ), Te = ({
1539
1632
  userType: i,
1540
1633
  minUserType: e,
1541
1634
  missingPermissions: t
@@ -1552,7 +1645,7 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1552
1645
  backgroundColor: "#f9fafb",
1553
1646
  textAlign: "center"
1554
1647
  },
1555
- children: /* @__PURE__ */ a(
1648
+ children: /* @__PURE__ */ c(
1556
1649
  "div",
1557
1650
  {
1558
1651
  style: {
@@ -1565,19 +1658,19 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1565
1658
  children: [
1566
1659
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1567
1660
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1568
- e && i ? /* @__PURE__ */ a(B, { children: [
1569
- /* @__PURE__ */ a("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1661
+ e && i ? /* @__PURE__ */ c(B, { children: [
1662
+ /* @__PURE__ */ c("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1570
1663
  "This page requires ",
1571
1664
  /* @__PURE__ */ n("strong", { children: e }),
1572
1665
  " access level or higher."
1573
1666
  ] }),
1574
- /* @__PURE__ */ a("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1667
+ /* @__PURE__ */ c("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1575
1668
  "Your current access level: ",
1576
1669
  /* @__PURE__ */ n("strong", { children: i })
1577
1670
  ] })
1578
- ] }) : /* @__PURE__ */ a(B, { children: [
1671
+ ] }) : /* @__PURE__ */ c(B, { children: [
1579
1672
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1580
- t && t.length > 0 && /* @__PURE__ */ a("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1673
+ t && t.length > 0 && /* @__PURE__ */ c("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1581
1674
  "Required permissions: ",
1582
1675
  /* @__PURE__ */ n("strong", { children: t.join(", ") })
1583
1676
  ] })
@@ -1586,7 +1679,7 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1586
1679
  }
1587
1680
  )
1588
1681
  }
1589
- ), Ke = (i, e) => {
1682
+ ), nt = (i, e) => {
1590
1683
  const t = {
1591
1684
  [ie.USER]: 1,
1592
1685
  [ie.TENANT_ADMIN]: 2,
@@ -1594,7 +1687,7 @@ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1594
1687
  };
1595
1688
  return t[i] >= t[e];
1596
1689
  };
1597
- function Ct({
1690
+ function zt({
1598
1691
  children: i,
1599
1692
  redirectTo: e = "/login",
1600
1693
  minUserType: t,
@@ -1602,24 +1695,24 @@ function Ct({
1602
1695
  requireAllPermissions: s = !1,
1603
1696
  fallback: o
1604
1697
  }) {
1605
- const { hasValidSession: g, sessionManager: y, hasPermission: A, hasAnyPermission: w, hasAllPermissions: T } = ae(), f = we();
1698
+ const { hasValidSession: g, sessionManager: w, hasPermission: x, hasAnyPermission: b, hasAllPermissions: A } = ae(), m = be();
1606
1699
  if (!g())
1607
- return o ? /* @__PURE__ */ n(B, { children: o }) : /* @__PURE__ */ a(B, { children: [
1608
- /* @__PURE__ */ n(_e, { redirectPath: e }),
1609
- /* @__PURE__ */ n(pe, { to: e, state: { from: f.pathname }, replace: !0 })
1700
+ return o ? /* @__PURE__ */ n(B, { children: o }) : /* @__PURE__ */ c(B, { children: [
1701
+ /* @__PURE__ */ n(rt, { redirectPath: e }),
1702
+ /* @__PURE__ */ n(pe, { to: e, state: { from: m.pathname }, replace: !0 })
1610
1703
  ] });
1611
- const p = y.getUser();
1612
- if (!p)
1613
- return /* @__PURE__ */ n(pe, { to: e, state: { from: f.pathname }, replace: !0 });
1614
- if (t && !Ke(p.userType, t))
1615
- return /* @__PURE__ */ n(Ae, { userType: p.userType, minUserType: t });
1616
- if (r && r.length > 0 && !(s ? T(r) : w(r))) {
1617
- const m = r.filter((R) => !A(R)).map((R) => typeof R == "string" ? R : R.name);
1618
- return /* @__PURE__ */ n(Ae, { missingPermissions: m });
1704
+ const f = w.getUser();
1705
+ if (!f)
1706
+ return /* @__PURE__ */ n(pe, { to: e, state: { from: m.pathname }, replace: !0 });
1707
+ if (t && !nt(f.userType, t))
1708
+ return /* @__PURE__ */ n(Te, { userType: f.userType, minUserType: t });
1709
+ if (r && r.length > 0 && !(s ? A(r) : b(r))) {
1710
+ const y = r.filter((E) => !x(E)).map((E) => typeof E == "string" ? E : E.name);
1711
+ return /* @__PURE__ */ n(Te, { missingPermissions: y });
1619
1712
  }
1620
1713
  return /* @__PURE__ */ n(B, { children: i });
1621
1714
  }
1622
- const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1715
+ const st = ({ redirectPath: i }) => /* @__PURE__ */ n(
1623
1716
  "div",
1624
1717
  {
1625
1718
  style: {
@@ -1632,7 +1725,7 @@ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1632
1725
  backgroundColor: "#f9fafb",
1633
1726
  textAlign: "center"
1634
1727
  },
1635
- children: /* @__PURE__ */ a(
1728
+ children: /* @__PURE__ */ c(
1636
1729
  "div",
1637
1730
  {
1638
1731
  style: {
@@ -1646,7 +1739,7 @@ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1646
1739
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
1647
1740
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
1648
1741
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
1649
- /* @__PURE__ */ a("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1742
+ /* @__PURE__ */ c("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1650
1743
  "Redirecting to ",
1651
1744
  i,
1652
1745
  "..."
@@ -1656,14 +1749,14 @@ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1656
1749
  )
1657
1750
  }
1658
1751
  );
1659
- function $t({ children: i, redirectTo: e = "/", fallback: t }) {
1660
- const { tenant: r, isLoading: s, error: o } = se(), g = we();
1661
- return s || o ? null : r ? /* @__PURE__ */ n(B, { children: i }) : t ? /* @__PURE__ */ n(B, { children: t }) : /* @__PURE__ */ a(B, { children: [
1662
- /* @__PURE__ */ n(Je, { redirectPath: e }),
1752
+ function Ot({ children: i, redirectTo: e = "/", fallback: t }) {
1753
+ const { tenant: r, isLoading: s, error: o } = se(), g = be();
1754
+ return s || o ? null : r ? /* @__PURE__ */ n(B, { children: i }) : t ? /* @__PURE__ */ n(B, { children: t }) : /* @__PURE__ */ c(B, { children: [
1755
+ /* @__PURE__ */ n(st, { redirectPath: e }),
1663
1756
  /* @__PURE__ */ n(pe, { to: e, state: { from: g.pathname }, replace: !0 })
1664
1757
  ] });
1665
1758
  }
1666
- const Ye = ({ redirectPath: i }) => /* @__PURE__ */ n(
1759
+ const it = ({ redirectPath: i }) => /* @__PURE__ */ n(
1667
1760
  "div",
1668
1761
  {
1669
1762
  style: {
@@ -1676,7 +1769,7 @@ const Ye = ({ redirectPath: i }) => /* @__PURE__ */ n(
1676
1769
  backgroundColor: "#f9fafb",
1677
1770
  textAlign: "center"
1678
1771
  },
1679
- children: /* @__PURE__ */ a(
1772
+ children: /* @__PURE__ */ c(
1680
1773
  "div",
1681
1774
  {
1682
1775
  style: {
@@ -1690,7 +1783,7 @@ const Ye = ({ redirectPath: i }) => /* @__PURE__ */ n(
1690
1783
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
1691
1784
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
1692
1785
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
1693
- /* @__PURE__ */ a("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1786
+ /* @__PURE__ */ c("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1694
1787
  "Redirecting to ",
1695
1788
  i,
1696
1789
  "..."
@@ -1700,14 +1793,14 @@ const Ye = ({ redirectPath: i }) => /* @__PURE__ */ n(
1700
1793
  )
1701
1794
  }
1702
1795
  );
1703
- function Ft({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1704
- const { tenant: r, isLoading: s, error: o } = se(), g = we();
1705
- return s || o ? null : r ? t ? /* @__PURE__ */ n(B, { children: t }) : /* @__PURE__ */ a(B, { children: [
1706
- /* @__PURE__ */ n(Ye, { redirectPath: e }),
1796
+ function Wt({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1797
+ const { tenant: r, isLoading: s, error: o } = se(), g = be();
1798
+ return s || o ? null : r ? t ? /* @__PURE__ */ n(B, { children: t }) : /* @__PURE__ */ c(B, { children: [
1799
+ /* @__PURE__ */ n(it, { redirectPath: e }),
1707
1800
  /* @__PURE__ */ n(pe, { to: e, state: { from: g.pathname }, replace: !0 })
1708
1801
  ] }) : /* @__PURE__ */ n(B, { children: i });
1709
1802
  }
1710
- const Qe = () => /* @__PURE__ */ a(
1803
+ const ot = () => /* @__PURE__ */ c(
1711
1804
  "div",
1712
1805
  {
1713
1806
  style: {
@@ -1724,14 +1817,14 @@ const Qe = () => /* @__PURE__ */ a(
1724
1817
  ]
1725
1818
  }
1726
1819
  );
1727
- function Dt({
1820
+ function Vt({
1728
1821
  children: i,
1729
- fallback: e = /* @__PURE__ */ n(Qe, {}),
1822
+ fallback: e = /* @__PURE__ */ n(ot, {}),
1730
1823
  allowedPlans: t,
1731
1824
  requiredFeature: r
1732
1825
  }) {
1733
- const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: g, loading: y } = Ve();
1734
- return y ? /* @__PURE__ */ n(
1826
+ const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: g, loading: w } = et();
1827
+ return w ? /* @__PURE__ */ n(
1735
1828
  "div",
1736
1829
  {
1737
1830
  style: {
@@ -1743,7 +1836,7 @@ function Dt({
1743
1836
  }
1744
1837
  ) : s ? s.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ n(B, { children: e }) : r && !g(r) ? /* @__PURE__ */ n(B, { children: e }) : /* @__PURE__ */ n(B, { children: i }) : /* @__PURE__ */ n(B, { children: e }) : /* @__PURE__ */ n(B, { children: e });
1745
1838
  }
1746
- const Xe = ({ flagName: i }) => /* @__PURE__ */ a(
1839
+ const at = ({ flagName: i }) => /* @__PURE__ */ c(
1747
1840
  "div",
1748
1841
  {
1749
1842
  style: {
@@ -1762,7 +1855,7 @@ const Xe = ({ flagName: i }) => /* @__PURE__ */ a(
1762
1855
  children: [
1763
1856
  /* @__PURE__ */ n("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
1764
1857
  /* @__PURE__ */ n("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
1765
- /* @__PURE__ */ a("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
1858
+ /* @__PURE__ */ c("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
1766
1859
  'Feature flag "',
1767
1860
  i,
1768
1861
  '" is disabled'
@@ -1770,8 +1863,8 @@ const Xe = ({ flagName: i }) => /* @__PURE__ */ a(
1770
1863
  ]
1771
1864
  }
1772
1865
  );
1773
- function Ht({ name: i, children: e, fallback: t }) {
1774
- const { isEnabled: r, loading: s } = We();
1866
+ function jt({ name: i, children: e, fallback: t }) {
1867
+ const { isEnabled: r, loading: s } = Xe();
1775
1868
  return s ? /* @__PURE__ */ n(
1776
1869
  "div",
1777
1870
  {
@@ -1785,9 +1878,9 @@ function Ht({ name: i, children: e, fallback: t }) {
1785
1878
  },
1786
1879
  children: "Loading feature flags..."
1787
1880
  }
1788
- ) : r(i) ? /* @__PURE__ */ n(B, { children: e }) : /* @__PURE__ */ n(B, { children: t || /* @__PURE__ */ n(Xe, { flagName: i }) });
1881
+ ) : r(i) ? /* @__PURE__ */ n(B, { children: e }) : /* @__PURE__ */ n(B, { children: t || /* @__PURE__ */ n(at, { flagName: i }) });
1789
1882
  }
1790
- const Ze = () => /* @__PURE__ */ a(
1883
+ const lt = () => /* @__PURE__ */ c(
1791
1884
  "svg",
1792
1885
  {
1793
1886
  width: "16",
@@ -1804,7 +1897,7 @@ const Ze = () => /* @__PURE__ */ a(
1804
1897
  /* @__PURE__ */ n("circle", { cx: "12", cy: "12", r: "3" })
1805
1898
  ]
1806
1899
  }
1807
- ), et = () => /* @__PURE__ */ a(
1900
+ ), ct = () => /* @__PURE__ */ c(
1808
1901
  "svg",
1809
1902
  {
1810
1903
  width: "16",
@@ -1821,10 +1914,10 @@ const Ze = () => /* @__PURE__ */ a(
1821
1914
  /* @__PURE__ */ n("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
1822
1915
  ]
1823
1916
  }
1824
- ), tt = {
1825
- showPassword: /* @__PURE__ */ n(Ze, {}),
1826
- hidePassword: /* @__PURE__ */ n(et, {})
1827
- }, rt = {
1917
+ ), dt = {
1918
+ showPassword: /* @__PURE__ */ n(lt, {}),
1919
+ hidePassword: /* @__PURE__ */ n(ct, {})
1920
+ }, ut = {
1828
1921
  title: "Sign In",
1829
1922
  usernameLabel: "Email or Phone",
1830
1923
  usernamePlaceholder: "Enter your email or phone number",
@@ -1838,7 +1931,7 @@ const Ze = () => /* @__PURE__ */ a(
1838
1931
  magicLinkLink: "Use Magic Link",
1839
1932
  errorMessage: "Invalid credentials",
1840
1933
  loadingText: "Signing in..."
1841
- }, nt = {
1934
+ }, ht = {
1842
1935
  container: {
1843
1936
  maxWidth: "400px",
1844
1937
  width: "100%",
@@ -1945,7 +2038,7 @@ const Ze = () => /* @__PURE__ */ a(
1945
2038
  fontSize: "0.875rem"
1946
2039
  }
1947
2040
  };
1948
- function Nt({
2041
+ function _t({
1949
2042
  copy: i = {},
1950
2043
  styles: e = {},
1951
2044
  icons: t = {},
@@ -1953,125 +2046,125 @@ function Nt({
1953
2046
  onError: s,
1954
2047
  onForgotPassword: o,
1955
2048
  onSignupClick: g,
1956
- onMagicLinkClick: y,
1957
- showForgotPassword: A = !0,
1958
- showSignupLink: w = !0,
1959
- showMagicLinkOption: T = !0,
1960
- className: f
2049
+ onMagicLinkClick: w,
2050
+ showForgotPassword: x = !0,
2051
+ showSignupLink: b = !0,
2052
+ showMagicLinkOption: A = !0,
2053
+ className: m
1961
2054
  }) {
1962
- const [p, h] = k(""), [m, R] = k(""), [C, U] = k(!1), [P, u] = k(!1), [M, E] = k(""), [q, V] = k({}), { login: $ } = ae(), { tenant: j } = se(), v = { ...rt, ...i }, I = { ...nt, ...e }, L = { ...tt, ...t }, l = () => {
1963
- const c = {};
1964
- return p.trim() || (c.username = !0), m.trim() || (c.password = !0), V(c), Object.keys(c).length === 0;
1965
- }, x = async (c) => {
1966
- if (c.preventDefault(), !!l()) {
1967
- if (!(j != null && j.id)) {
1968
- E("Tenant not found");
2055
+ const [f, u] = v(""), [y, E] = v(""), [C, q] = v(!1), [T, d] = v(!1), [P, R] = v(""), [z, G] = v({}), { login: $ } = ae(), { tenant: _ } = se(), S = { ...ut, ...i }, M = { ...ht, ...e }, L = { ...dt, ...t }, l = () => {
2056
+ const a = {};
2057
+ return f.trim() || (a.username = !0), y.trim() || (a.password = !0), G(a), Object.keys(a).length === 0;
2058
+ }, I = async (a) => {
2059
+ if (a.preventDefault(), !!l()) {
2060
+ if (!(_ != null && _.id)) {
2061
+ R("Tenant not found");
1969
2062
  return;
1970
2063
  }
1971
- u(!0), E("");
2064
+ d(!0), R("");
1972
2065
  try {
1973
- const S = await $({
1974
- username: p,
1975
- password: m
2066
+ const p = await $({
2067
+ username: f,
2068
+ password: y
1976
2069
  // tenantId inferred from context automatically
1977
2070
  });
1978
- r == null || r(S);
1979
- } catch (S) {
1980
- const _ = S.message || v.errorMessage;
1981
- E(_), s == null || s(_);
2071
+ r == null || r(p);
2072
+ } catch (p) {
2073
+ const O = p.message || S.errorMessage;
2074
+ R(O), s == null || s(O);
1982
2075
  } finally {
1983
- u(!1);
2076
+ d(!1);
1984
2077
  }
1985
2078
  }
1986
- }, b = (c) => ({
1987
- ...I.input,
1988
- ...q[c] ? I.inputError : {}
1989
- }), d = () => ({
1990
- ...I.button,
1991
- ...P ? I.buttonLoading : {},
1992
- ...!p || !m || P ? I.buttonDisabled : {}
2079
+ }, k = (a) => ({
2080
+ ...M.input,
2081
+ ...z[a] ? M.inputError : {}
2082
+ }), h = () => ({
2083
+ ...M.button,
2084
+ ...T ? M.buttonLoading : {},
2085
+ ...!f || !y || T ? M.buttonDisabled : {}
1993
2086
  });
1994
- return /* @__PURE__ */ a("div", { className: f, style: I.container, children: [
1995
- /* @__PURE__ */ n("h2", { style: I.title, children: v.title }),
1996
- /* @__PURE__ */ a("form", { onSubmit: x, style: I.form, children: [
1997
- /* @__PURE__ */ a("div", { style: I.fieldGroup, children: [
1998
- /* @__PURE__ */ n("label", { style: I.label, children: v.usernameLabel }),
2087
+ return /* @__PURE__ */ c("div", { className: m, style: M.container, children: [
2088
+ /* @__PURE__ */ n("h2", { style: M.title, children: S.title }),
2089
+ /* @__PURE__ */ c("form", { onSubmit: I, style: M.form, children: [
2090
+ /* @__PURE__ */ c("div", { style: M.fieldGroup, children: [
2091
+ /* @__PURE__ */ n("label", { style: M.label, children: S.usernameLabel }),
1999
2092
  /* @__PURE__ */ n(
2000
2093
  "input",
2001
2094
  {
2002
2095
  id: "username",
2003
2096
  name: "username",
2004
2097
  type: "text",
2005
- value: p,
2006
- onChange: (c) => {
2007
- h(c.target.value), q.username && V((S) => ({ ...S, username: !1 }));
2098
+ value: f,
2099
+ onChange: (a) => {
2100
+ u(a.target.value), z.username && G((p) => ({ ...p, username: !1 }));
2008
2101
  },
2009
- placeholder: v.usernamePlaceholder,
2010
- style: b("username"),
2011
- disabled: P
2102
+ placeholder: S.usernamePlaceholder,
2103
+ style: k("username"),
2104
+ disabled: T
2012
2105
  }
2013
2106
  )
2014
2107
  ] }),
2015
- /* @__PURE__ */ a("div", { style: I.fieldGroup, children: [
2016
- /* @__PURE__ */ n("label", { style: I.label, children: v.passwordLabel }),
2017
- /* @__PURE__ */ a("div", { style: I.inputContainer, children: [
2108
+ /* @__PURE__ */ c("div", { style: M.fieldGroup, children: [
2109
+ /* @__PURE__ */ n("label", { style: M.label, children: S.passwordLabel }),
2110
+ /* @__PURE__ */ c("div", { style: M.inputContainer, children: [
2018
2111
  /* @__PURE__ */ n(
2019
2112
  "input",
2020
2113
  {
2021
2114
  id: "password",
2022
2115
  name: "password",
2023
2116
  type: C ? "text" : "password",
2024
- value: m,
2025
- onChange: (c) => {
2026
- R(c.target.value), q.password && V((S) => ({ ...S, password: !1 }));
2117
+ value: y,
2118
+ onChange: (a) => {
2119
+ E(a.target.value), z.password && G((p) => ({ ...p, password: !1 }));
2027
2120
  },
2028
- placeholder: v.passwordPlaceholder,
2121
+ placeholder: S.passwordPlaceholder,
2029
2122
  style: {
2030
- ...b("password"),
2123
+ ...k("password"),
2031
2124
  paddingRight: "2.5rem"
2032
2125
  // Make room for the icon
2033
2126
  },
2034
- disabled: P
2127
+ disabled: T
2035
2128
  }
2036
2129
  ),
2037
2130
  /* @__PURE__ */ n(
2038
2131
  "button",
2039
2132
  {
2040
2133
  type: "button",
2041
- onClick: () => U(!C),
2042
- style: I.passwordToggle,
2043
- disabled: P,
2134
+ onClick: () => q(!C),
2135
+ style: M.passwordToggle,
2136
+ disabled: T,
2044
2137
  "aria-label": C ? "Hide password" : "Show password",
2045
2138
  children: C ? L.hidePassword : L.showPassword
2046
2139
  }
2047
2140
  )
2048
2141
  ] })
2049
2142
  ] }),
2050
- /* @__PURE__ */ n("button", { type: "submit", disabled: !p || !m || P, style: d(), children: P ? v.loadingText : v.submitButton }),
2051
- M && /* @__PURE__ */ n("div", { style: I.errorText, children: M })
2143
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !f || !y || T, style: h(), children: T ? S.loadingText : S.submitButton }),
2144
+ P && /* @__PURE__ */ n("div", { style: M.errorText, children: P })
2052
2145
  ] }),
2053
- (A || w || T) && /* @__PURE__ */ a("div", { style: I.linkContainer, children: [
2054
- T && /* @__PURE__ */ a("div", { children: [
2055
- /* @__PURE__ */ a("span", { style: I.divider, children: [
2056
- v.magicLinkText,
2146
+ (x || b || A) && /* @__PURE__ */ c("div", { style: M.linkContainer, children: [
2147
+ A && /* @__PURE__ */ c("div", { children: [
2148
+ /* @__PURE__ */ c("span", { style: M.divider, children: [
2149
+ S.magicLinkText,
2057
2150
  " "
2058
2151
  ] }),
2059
- /* @__PURE__ */ n("a", { onClick: y, style: I.link, children: v.magicLinkLink })
2152
+ /* @__PURE__ */ n("a", { onClick: w, style: M.link, children: S.magicLinkLink })
2060
2153
  ] }),
2061
- T && (A || w) && /* @__PURE__ */ n("div", { style: I.divider, children: "•" }),
2062
- A && /* @__PURE__ */ n("a", { onClick: o, style: I.link, children: v.forgotPasswordLink }),
2063
- A && w && /* @__PURE__ */ n("div", { style: I.divider, children: "•" }),
2064
- w && /* @__PURE__ */ a("div", { children: [
2065
- /* @__PURE__ */ a("span", { style: I.divider, children: [
2066
- v.signupText,
2154
+ A && (x || b) && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2155
+ x && /* @__PURE__ */ n("a", { onClick: o, style: M.link, children: S.forgotPasswordLink }),
2156
+ x && b && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2157
+ b && /* @__PURE__ */ c("div", { children: [
2158
+ /* @__PURE__ */ c("span", { style: M.divider, children: [
2159
+ S.signupText,
2067
2160
  " "
2068
2161
  ] }),
2069
- /* @__PURE__ */ n("a", { onClick: g, style: I.link, children: v.signupLink })
2162
+ /* @__PURE__ */ n("a", { onClick: g, style: M.link, children: S.signupLink })
2070
2163
  ] })
2071
2164
  ] })
2072
2165
  ] });
2073
2166
  }
2074
- const st = {
2167
+ const gt = {
2075
2168
  title: "Create Account",
2076
2169
  nameLabel: "First Name",
2077
2170
  namePlaceholder: "Enter your first name",
@@ -2097,7 +2190,7 @@ const st = {
2097
2190
  passwordMismatchError: "Passwords do not match",
2098
2191
  isAdminLabel: "Create new organization",
2099
2192
  isAdminDescription: "Check this if you want to create a new organization"
2100
- }, it = {
2193
+ }, pt = {
2101
2194
  container: {
2102
2195
  maxWidth: "400px",
2103
2196
  width: "100%",
@@ -2196,7 +2289,7 @@ const st = {
2196
2289
  fontSize: "0.875rem"
2197
2290
  }
2198
2291
  };
2199
- function Bt({
2292
+ function Gt({
2200
2293
  copy: i = {},
2201
2294
  styles: e = {},
2202
2295
  signupType: t = "user",
@@ -2204,113 +2297,113 @@ function Bt({
2204
2297
  onError: s,
2205
2298
  onLoginClick: o,
2206
2299
  onMagicLinkClick: g,
2207
- showLoginLink: y = !0,
2208
- showMagicLinkOption: A = !0,
2209
- className: w
2300
+ showLoginLink: w = !0,
2301
+ showMagicLinkOption: x = !0,
2302
+ className: b
2210
2303
  }) {
2211
- const [T, f] = k(""), [p, h] = k(""), [m, R] = k(""), [C, U] = k(""), [P, u] = k(""), [M, E] = k(""), [q, V] = k(""), [$, j] = k(!1), [v, I] = k(""), [L, l] = k({}), { signup: x, signupTenantAdmin: b } = ae(), { tenant: d } = se(), c = { ...st, ...i }, S = { ...it, ...e }, _ = () => {
2304
+ const [A, m] = v(""), [f, u] = v(""), [y, E] = v(""), [C, q] = v(""), [T, d] = v(""), [P, R] = v(""), [z, G] = v(""), [$, _] = v(!1), [S, M] = v(""), [L, l] = v({}), { signup: I, signupTenantAdmin: k } = ae(), { tenant: h } = se(), a = { ...gt, ...i }, p = { ...pt, ...e }, O = () => {
2212
2305
  const D = {};
2213
- return T.trim() || (D.name = !0), !m.trim() && !C.trim() && (D.email = !0, D.phoneNumber = !0), P.trim() || (D.password = !0), M.trim() || (D.confirmPassword = !0), t === "tenant" && !q.trim() && (D.tenantName = !0), l(D), Object.keys(D).length === 0;
2214
- }, ee = async (D) => {
2215
- if (D.preventDefault(), !!_()) {
2216
- if (P !== M) {
2217
- I(c.passwordMismatchError), l({ confirmPassword: !0 });
2306
+ return A.trim() || (D.name = !0), !y.trim() && !C.trim() && (D.email = !0, D.phoneNumber = !0), T.trim() || (D.password = !0), P.trim() || (D.confirmPassword = !0), t === "tenant" && !z.trim() && (D.tenantName = !0), l(D), Object.keys(D).length === 0;
2307
+ }, K = async (D) => {
2308
+ if (D.preventDefault(), !!O()) {
2309
+ if (T !== P) {
2310
+ M(a.passwordMismatchError), l({ confirmPassword: !0 });
2218
2311
  return;
2219
2312
  }
2220
- if (t === "user" && !(d != null && d.id)) {
2221
- I("Tenant not found");
2313
+ if (t === "user" && !(h != null && h.id)) {
2314
+ M("Tenant not found");
2222
2315
  return;
2223
2316
  }
2224
- j(!0), I("");
2317
+ _(!0), M("");
2225
2318
  try {
2226
- let K;
2227
- t === "tenant" ? K = await b({
2228
- email: m || void 0,
2319
+ let J;
2320
+ t === "tenant" ? J = await k({
2321
+ email: y || void 0,
2229
2322
  phoneNumber: C || void 0,
2230
- name: T,
2231
- password: P,
2232
- tenantName: q,
2233
- lastName: p || void 0
2234
- }) : K = await x({
2235
- email: m || void 0,
2323
+ name: A,
2324
+ password: T,
2325
+ tenantName: z,
2326
+ lastName: f || void 0
2327
+ }) : J = await I({
2328
+ email: y || void 0,
2236
2329
  phoneNumber: C || void 0,
2237
- name: T,
2238
- password: P,
2239
- tenantId: d.id,
2240
- lastName: p || void 0
2241
- }), r == null || r(K);
2242
- } catch (K) {
2243
- const ge = K.message || c.errorMessage;
2244
- I(ge), s == null || s(ge);
2330
+ name: A,
2331
+ password: T,
2332
+ tenantId: h.id,
2333
+ lastName: f || void 0
2334
+ }), r == null || r(J);
2335
+ } catch (J) {
2336
+ const ge = J.message || a.errorMessage;
2337
+ M(ge), s == null || s(ge);
2245
2338
  } finally {
2246
- j(!1);
2339
+ _(!1);
2247
2340
  }
2248
2341
  }
2249
- }, z = (D) => ({
2250
- ...S.input,
2251
- ...L[D] ? S.inputError : {}
2252
- }), H = () => ({
2253
- ...S.button,
2254
- ...$ ? S.buttonLoading : {},
2255
- ...!T || !m && !C || !P || !M || $ || t === "tenant" && !q ? S.buttonDisabled : {}
2256
- }), O = T && (m || C) && P && M && (t === "user" || q);
2257
- return /* @__PURE__ */ a("div", { className: w, style: S.container, children: [
2258
- /* @__PURE__ */ n("h2", { style: S.title, children: c.title }),
2259
- /* @__PURE__ */ a("form", { onSubmit: ee, style: S.form, children: [
2260
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2261
- /* @__PURE__ */ n("label", { style: S.label, children: c.nameLabel }),
2342
+ }, H = (D) => ({
2343
+ ...p.input,
2344
+ ...L[D] ? p.inputError : {}
2345
+ }), N = () => ({
2346
+ ...p.button,
2347
+ ...$ ? p.buttonLoading : {},
2348
+ ...!A || !y && !C || !T || !P || $ || t === "tenant" && !z ? p.buttonDisabled : {}
2349
+ }), W = A && (y || C) && T && P && (t === "user" || z);
2350
+ return /* @__PURE__ */ c("div", { className: b, style: p.container, children: [
2351
+ /* @__PURE__ */ n("h2", { style: p.title, children: a.title }),
2352
+ /* @__PURE__ */ c("form", { onSubmit: K, style: p.form, children: [
2353
+ /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2354
+ /* @__PURE__ */ n("label", { style: p.label, children: a.nameLabel }),
2262
2355
  /* @__PURE__ */ n(
2263
2356
  "input",
2264
2357
  {
2265
2358
  id: "name",
2266
2359
  name: "name",
2267
2360
  type: "text",
2268
- value: T,
2361
+ value: A,
2269
2362
  onChange: (D) => {
2270
- f(D.target.value), L.name && l((K) => ({ ...K, name: !1 }));
2363
+ m(D.target.value), L.name && l((J) => ({ ...J, name: !1 }));
2271
2364
  },
2272
- placeholder: c.namePlaceholder,
2273
- style: z("name"),
2365
+ placeholder: a.namePlaceholder,
2366
+ style: H("name"),
2274
2367
  disabled: $
2275
2368
  }
2276
2369
  )
2277
2370
  ] }),
2278
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2279
- /* @__PURE__ */ n("label", { style: S.label, children: c.lastNameLabel }),
2371
+ /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2372
+ /* @__PURE__ */ n("label", { style: p.label, children: a.lastNameLabel }),
2280
2373
  /* @__PURE__ */ n(
2281
2374
  "input",
2282
2375
  {
2283
2376
  id: "lastName",
2284
2377
  name: "lastName",
2285
2378
  type: "text",
2286
- value: p,
2287
- onChange: (D) => h(D.target.value),
2288
- placeholder: c.lastNamePlaceholder,
2289
- style: S.input,
2379
+ value: f,
2380
+ onChange: (D) => u(D.target.value),
2381
+ placeholder: a.lastNamePlaceholder,
2382
+ style: p.input,
2290
2383
  disabled: $
2291
2384
  }
2292
2385
  )
2293
2386
  ] }),
2294
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2295
- /* @__PURE__ */ n("label", { style: S.label, children: c.emailLabel }),
2387
+ /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2388
+ /* @__PURE__ */ n("label", { style: p.label, children: a.emailLabel }),
2296
2389
  /* @__PURE__ */ n(
2297
2390
  "input",
2298
2391
  {
2299
2392
  id: "email",
2300
2393
  name: "email",
2301
2394
  type: "email",
2302
- value: m,
2395
+ value: y,
2303
2396
  onChange: (D) => {
2304
- R(D.target.value), L.email && l((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2397
+ E(D.target.value), L.email && l((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2305
2398
  },
2306
- placeholder: c.emailPlaceholder,
2307
- style: z("email"),
2399
+ placeholder: a.emailPlaceholder,
2400
+ style: H("email"),
2308
2401
  disabled: $
2309
2402
  }
2310
2403
  )
2311
2404
  ] }),
2312
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2313
- /* @__PURE__ */ n("label", { style: S.label, children: c.phoneNumberLabel }),
2405
+ /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2406
+ /* @__PURE__ */ n("label", { style: p.label, children: a.phoneNumberLabel }),
2314
2407
  /* @__PURE__ */ n(
2315
2408
  "input",
2316
2409
  {
@@ -2319,10 +2412,10 @@ function Bt({
2319
2412
  type: "tel",
2320
2413
  value: C,
2321
2414
  onChange: (D) => {
2322
- U(D.target.value), L.phoneNumber && l((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2415
+ q(D.target.value), L.phoneNumber && l((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2323
2416
  },
2324
- placeholder: c.phoneNumberPlaceholder,
2325
- style: z("phoneNumber"),
2417
+ placeholder: a.phoneNumberPlaceholder,
2418
+ style: H("phoneNumber"),
2326
2419
  disabled: $
2327
2420
  }
2328
2421
  )
@@ -2339,83 +2432,83 @@ function Bt({
2339
2432
  children: "At least one contact method (email or phone) is required"
2340
2433
  }
2341
2434
  ),
2342
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2343
- /* @__PURE__ */ n("label", { style: S.label, children: c.passwordLabel }),
2435
+ /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2436
+ /* @__PURE__ */ n("label", { style: p.label, children: a.passwordLabel }),
2344
2437
  /* @__PURE__ */ n(
2345
2438
  "input",
2346
2439
  {
2347
2440
  id: "password",
2348
2441
  name: "password",
2349
2442
  type: "password",
2350
- value: P,
2443
+ value: T,
2351
2444
  onChange: (D) => {
2352
- u(D.target.value), L.password && l((K) => ({ ...K, password: !1 }));
2445
+ d(D.target.value), L.password && l((J) => ({ ...J, password: !1 }));
2353
2446
  },
2354
- placeholder: c.passwordPlaceholder,
2355
- style: z("password"),
2447
+ placeholder: a.passwordPlaceholder,
2448
+ style: H("password"),
2356
2449
  disabled: $
2357
2450
  }
2358
2451
  )
2359
2452
  ] }),
2360
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2361
- /* @__PURE__ */ n("label", { style: S.label, children: c.confirmPasswordLabel }),
2453
+ /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2454
+ /* @__PURE__ */ n("label", { style: p.label, children: a.confirmPasswordLabel }),
2362
2455
  /* @__PURE__ */ n(
2363
2456
  "input",
2364
2457
  {
2365
2458
  id: "confirmPassword",
2366
2459
  name: "confirmPassword",
2367
2460
  type: "password",
2368
- value: M,
2461
+ value: P,
2369
2462
  onChange: (D) => {
2370
- E(D.target.value), L.confirmPassword && l((K) => ({ ...K, confirmPassword: !1 })), v === c.passwordMismatchError && I("");
2463
+ R(D.target.value), L.confirmPassword && l((J) => ({ ...J, confirmPassword: !1 })), S === a.passwordMismatchError && M("");
2371
2464
  },
2372
- placeholder: c.confirmPasswordPlaceholder,
2373
- style: z("confirmPassword"),
2465
+ placeholder: a.confirmPasswordPlaceholder,
2466
+ style: H("confirmPassword"),
2374
2467
  disabled: $
2375
2468
  }
2376
2469
  )
2377
2470
  ] }),
2378
- t === "tenant" && /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2379
- /* @__PURE__ */ n("label", { style: S.label, children: c.tenantNameLabel }),
2471
+ t === "tenant" && /* @__PURE__ */ c("div", { style: p.fieldGroup, children: [
2472
+ /* @__PURE__ */ n("label", { style: p.label, children: a.tenantNameLabel }),
2380
2473
  /* @__PURE__ */ n(
2381
2474
  "input",
2382
2475
  {
2383
2476
  id: "tenantName",
2384
2477
  name: "tenantName",
2385
2478
  type: "text",
2386
- value: q,
2479
+ value: z,
2387
2480
  onChange: (D) => {
2388
- V(D.target.value), L.tenantName && l((K) => ({ ...K, tenantName: !1 }));
2481
+ G(D.target.value), L.tenantName && l((J) => ({ ...J, tenantName: !1 }));
2389
2482
  },
2390
- placeholder: c.tenantNamePlaceholder,
2391
- style: z("tenantName"),
2483
+ placeholder: a.tenantNamePlaceholder,
2484
+ style: H("tenantName"),
2392
2485
  disabled: $
2393
2486
  }
2394
2487
  )
2395
2488
  ] }),
2396
- /* @__PURE__ */ n("button", { type: "submit", disabled: !O || $, style: H(), children: $ ? c.loadingText : c.submitButton }),
2397
- v && /* @__PURE__ */ n("div", { style: S.errorText, children: v })
2489
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !W || $, style: N(), children: $ ? a.loadingText : a.submitButton }),
2490
+ S && /* @__PURE__ */ n("div", { style: p.errorText, children: S })
2398
2491
  ] }),
2399
- (y || A) && /* @__PURE__ */ a("div", { style: S.linkContainer, children: [
2400
- A && /* @__PURE__ */ a("div", { children: [
2401
- /* @__PURE__ */ a("span", { style: S.divider, children: [
2402
- c.magicLinkText,
2492
+ (w || x) && /* @__PURE__ */ c("div", { style: p.linkContainer, children: [
2493
+ x && /* @__PURE__ */ c("div", { children: [
2494
+ /* @__PURE__ */ c("span", { style: p.divider, children: [
2495
+ a.magicLinkText,
2403
2496
  " "
2404
2497
  ] }),
2405
- /* @__PURE__ */ n("a", { onClick: g, style: S.link, children: c.magicLinkLink })
2498
+ /* @__PURE__ */ n("a", { onClick: g, style: p.link, children: a.magicLinkLink })
2406
2499
  ] }),
2407
- A && y && /* @__PURE__ */ n("div", { style: S.divider, children: "•" }),
2408
- y && /* @__PURE__ */ a("div", { children: [
2409
- /* @__PURE__ */ a("span", { style: S.divider, children: [
2410
- c.loginText,
2500
+ x && w && /* @__PURE__ */ n("div", { style: p.divider, children: "•" }),
2501
+ w && /* @__PURE__ */ c("div", { children: [
2502
+ /* @__PURE__ */ c("span", { style: p.divider, children: [
2503
+ a.loginText,
2411
2504
  " "
2412
2505
  ] }),
2413
- /* @__PURE__ */ n("a", { onClick: o, style: S.link, children: c.loginLink })
2506
+ /* @__PURE__ */ n("a", { onClick: o, style: p.link, children: a.loginLink })
2414
2507
  ] })
2415
2508
  ] })
2416
2509
  ] });
2417
2510
  }
2418
- const ot = {
2511
+ const ft = {
2419
2512
  title: "Sign In with Magic Link",
2420
2513
  emailLabel: "Email",
2421
2514
  emailPlaceholder: "Enter your email",
@@ -2433,7 +2526,7 @@ const ot = {
2433
2526
  loadingText: "Sending magic link...",
2434
2527
  verifyingText: "Verifying magic link...",
2435
2528
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2436
- }, at = {
2529
+ }, mt = {
2437
2530
  container: {
2438
2531
  maxWidth: "400px",
2439
2532
  width: "100%",
@@ -2536,7 +2629,7 @@ const ot = {
2536
2629
  fontSize: "0.875rem"
2537
2630
  }
2538
2631
  };
2539
- function Ut({
2632
+ function Kt({
2540
2633
  copy: i = {},
2541
2634
  styles: e = {},
2542
2635
  onSuccess: t,
@@ -2544,97 +2637,97 @@ function Ut({
2544
2637
  onLoginClick: s,
2545
2638
  onSignupClick: o,
2546
2639
  showTraditionalLinks: g = !0,
2547
- className: y,
2548
- verifyToken: A,
2549
- frontendUrl: w
2640
+ className: w,
2641
+ verifyToken: x,
2642
+ frontendUrl: b
2550
2643
  }) {
2551
- const [T, f] = k(""), [p, h] = k(""), [m, R] = k(""), [C, U] = k(!1), [P, u] = k(!1), [M, E] = k(""), [q, V] = k(""), [$, j] = k({}), [v, I] = k(!1), { sendMagicLink: L, verifyMagicLink: l } = ae(), { tenant: x } = se(), b = { ...ot, ...i }, d = { ...at, ...e };
2644
+ const [A, m] = v(""), [f, u] = v(""), [y, E] = v(""), [C, q] = v(!1), [T, d] = v(!1), [P, R] = v(""), [z, G] = v(""), [$, _] = v({}), [S, M] = v(!1), { sendMagicLink: L, verifyMagicLink: l } = ae(), { tenant: I } = se(), k = { ...ft, ...i }, h = { ...mt, ...e };
2552
2645
  te(() => {
2553
- A && c(A);
2554
- }, [A]);
2555
- const c = async (H) => {
2556
- if (!x || !T) {
2557
- E("Missing tenant or email");
2646
+ x && a(x);
2647
+ }, [x]);
2648
+ const a = async (N) => {
2649
+ if (!I || !A) {
2650
+ R("Missing tenant or email");
2558
2651
  return;
2559
2652
  }
2560
- u(!0), E("");
2653
+ d(!0), R("");
2561
2654
  try {
2562
- const O = await l({
2563
- token: H,
2564
- email: T
2655
+ const W = await l({
2656
+ token: N,
2657
+ email: A
2565
2658
  // tenantId inferred from context automatically
2566
2659
  });
2567
- t == null || t(O);
2568
- } catch (O) {
2569
- const D = O.message || "Failed to verify magic link";
2570
- E(D), r == null || r(D);
2660
+ t == null || t(W);
2661
+ } catch (W) {
2662
+ const D = W.message || "Failed to verify magic link";
2663
+ R(D), r == null || r(D);
2571
2664
  } finally {
2572
- u(!1);
2665
+ d(!1);
2573
2666
  }
2574
- }, S = () => {
2575
- const H = {};
2576
- return T.trim() || (H.email = !0), v && !p.trim() && (H.name = !0), j(H), Object.keys(H).length === 0;
2577
- }, _ = async (H) => {
2578
- if (H.preventDefault(), !!S()) {
2579
- if (!(x != null && x.id)) {
2580
- E("Tenant not found");
2667
+ }, p = () => {
2668
+ const N = {};
2669
+ return A.trim() || (N.email = !0), S && !f.trim() && (N.name = !0), _(N), Object.keys(N).length === 0;
2670
+ }, O = async (N) => {
2671
+ if (N.preventDefault(), !!p()) {
2672
+ if (!(I != null && I.id)) {
2673
+ R("Tenant not found");
2581
2674
  return;
2582
2675
  }
2583
- U(!0), E(""), V("");
2676
+ q(!0), R(""), G("");
2584
2677
  try {
2585
- const O = w || (typeof window < "u" ? window.location.origin : ""), D = await L({
2586
- email: T,
2587
- tenantId: x.id,
2588
- frontendUrl: O,
2589
- name: v ? p : void 0,
2590
- lastName: v ? m : void 0
2678
+ const W = b || (typeof window < "u" ? window.location.origin : ""), D = await L({
2679
+ email: A,
2680
+ tenantId: I.id,
2681
+ frontendUrl: W,
2682
+ name: S ? f : void 0,
2683
+ lastName: S ? y : void 0
2591
2684
  });
2592
- V(b.successMessage), t == null || t(D);
2593
- } catch (O) {
2594
- const D = O.message || b.errorMessage;
2595
- E(D), r == null || r(D);
2685
+ G(k.successMessage), t == null || t(D);
2686
+ } catch (W) {
2687
+ const D = W.message || k.errorMessage;
2688
+ R(D), r == null || r(D);
2596
2689
  } finally {
2597
- U(!1);
2690
+ q(!1);
2598
2691
  }
2599
2692
  }
2600
- }, ee = (H) => ({
2601
- ...d.input,
2602
- ...$[H] ? d.inputError : {}
2603
- }), z = () => ({
2604
- ...d.button,
2605
- ...C || P ? d.buttonLoading : {},
2606
- ...!T || C || P ? d.buttonDisabled : {}
2693
+ }, K = (N) => ({
2694
+ ...h.input,
2695
+ ...$[N] ? h.inputError : {}
2696
+ }), H = () => ({
2697
+ ...h.button,
2698
+ ...C || T ? h.buttonLoading : {},
2699
+ ...!A || C || T ? h.buttonDisabled : {}
2607
2700
  });
2608
- return P ? /* @__PURE__ */ a("div", { className: y, style: d.container, children: [
2609
- /* @__PURE__ */ n("h2", { style: d.title, children: b.verifyingText }),
2701
+ return T ? /* @__PURE__ */ c("div", { className: w, style: h.container, children: [
2702
+ /* @__PURE__ */ n("h2", { style: h.title, children: k.verifyingText }),
2610
2703
  /* @__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..." }) })
2611
- ] }) : /* @__PURE__ */ a("div", { className: y, style: d.container, children: [
2612
- /* @__PURE__ */ n("h2", { style: d.title, children: b.title }),
2613
- /* @__PURE__ */ n("p", { style: d.description, children: b.description }),
2614
- /* @__PURE__ */ a("form", { onSubmit: _, style: d.form, children: [
2615
- /* @__PURE__ */ a("div", { style: d.fieldGroup, children: [
2616
- /* @__PURE__ */ n("label", { style: d.label, children: b.emailLabel }),
2704
+ ] }) : /* @__PURE__ */ c("div", { className: w, style: h.container, children: [
2705
+ /* @__PURE__ */ n("h2", { style: h.title, children: k.title }),
2706
+ /* @__PURE__ */ n("p", { style: h.description, children: k.description }),
2707
+ /* @__PURE__ */ c("form", { onSubmit: O, style: h.form, children: [
2708
+ /* @__PURE__ */ c("div", { style: h.fieldGroup, children: [
2709
+ /* @__PURE__ */ n("label", { style: h.label, children: k.emailLabel }),
2617
2710
  /* @__PURE__ */ n(
2618
2711
  "input",
2619
2712
  {
2620
2713
  id: "email",
2621
2714
  name: "email",
2622
2715
  type: "email",
2623
- value: T,
2624
- onChange: (H) => {
2625
- f(H.target.value), $.email && j((O) => ({ ...O, email: !1 }));
2716
+ value: A,
2717
+ onChange: (N) => {
2718
+ m(N.target.value), $.email && _((W) => ({ ...W, email: !1 }));
2626
2719
  },
2627
- placeholder: b.emailPlaceholder,
2628
- style: ee("email"),
2629
- disabled: C || P
2720
+ placeholder: k.emailPlaceholder,
2721
+ style: K("email"),
2722
+ disabled: C || T
2630
2723
  }
2631
2724
  )
2632
2725
  ] }),
2633
- !v && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2726
+ !S && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2634
2727
  "button",
2635
2728
  {
2636
2729
  type: "button",
2637
- onClick: () => I(!0),
2730
+ onClick: () => M(!0),
2638
2731
  style: {
2639
2732
  background: "none",
2640
2733
  border: "none",
@@ -2646,38 +2739,38 @@ function Ut({
2646
2739
  children: "New user? Add your name"
2647
2740
  }
2648
2741
  ) }),
2649
- v && /* @__PURE__ */ a(B, { children: [
2650
- /* @__PURE__ */ a("div", { style: d.fieldGroup, children: [
2651
- /* @__PURE__ */ n("label", { style: d.label, children: b.nameLabel }),
2742
+ S && /* @__PURE__ */ c(B, { children: [
2743
+ /* @__PURE__ */ c("div", { style: h.fieldGroup, children: [
2744
+ /* @__PURE__ */ n("label", { style: h.label, children: k.nameLabel }),
2652
2745
  /* @__PURE__ */ n(
2653
2746
  "input",
2654
2747
  {
2655
2748
  id: "name",
2656
2749
  name: "name",
2657
2750
  type: "text",
2658
- value: p,
2659
- onChange: (H) => {
2660
- h(H.target.value), $.name && j((O) => ({ ...O, name: !1 }));
2751
+ value: f,
2752
+ onChange: (N) => {
2753
+ u(N.target.value), $.name && _((W) => ({ ...W, name: !1 }));
2661
2754
  },
2662
- placeholder: b.namePlaceholder,
2663
- style: ee("name"),
2664
- disabled: C || P
2755
+ placeholder: k.namePlaceholder,
2756
+ style: K("name"),
2757
+ disabled: C || T
2665
2758
  }
2666
2759
  )
2667
2760
  ] }),
2668
- /* @__PURE__ */ a("div", { style: d.fieldGroup, children: [
2669
- /* @__PURE__ */ n("label", { style: d.label, children: b.lastNameLabel }),
2761
+ /* @__PURE__ */ c("div", { style: h.fieldGroup, children: [
2762
+ /* @__PURE__ */ n("label", { style: h.label, children: k.lastNameLabel }),
2670
2763
  /* @__PURE__ */ n(
2671
2764
  "input",
2672
2765
  {
2673
2766
  id: "lastName",
2674
2767
  name: "lastName",
2675
2768
  type: "text",
2676
- value: m,
2677
- onChange: (H) => R(H.target.value),
2678
- placeholder: b.lastNamePlaceholder,
2679
- style: d.input,
2680
- disabled: C || P
2769
+ value: y,
2770
+ onChange: (N) => E(N.target.value),
2771
+ placeholder: k.lastNamePlaceholder,
2772
+ style: h.input,
2773
+ disabled: C || T
2681
2774
  }
2682
2775
  )
2683
2776
  ] }),
@@ -2686,7 +2779,7 @@ function Ut({
2686
2779
  {
2687
2780
  type: "button",
2688
2781
  onClick: () => {
2689
- I(!1), h(""), R("");
2782
+ M(!1), u(""), E("");
2690
2783
  },
2691
2784
  style: {
2692
2785
  background: "none",
@@ -2700,30 +2793,30 @@ function Ut({
2700
2793
  }
2701
2794
  ) })
2702
2795
  ] }),
2703
- /* @__PURE__ */ n("button", { type: "submit", disabled: !T || C || P, style: z(), children: C ? b.loadingText : b.submitButton }),
2704
- M && /* @__PURE__ */ n("div", { style: d.errorText, children: M }),
2705
- q && /* @__PURE__ */ n("div", { style: d.successText, children: q })
2796
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !A || C || T, style: H(), children: C ? k.loadingText : k.submitButton }),
2797
+ P && /* @__PURE__ */ n("div", { style: h.errorText, children: P }),
2798
+ z && /* @__PURE__ */ n("div", { style: h.successText, children: z })
2706
2799
  ] }),
2707
- g && /* @__PURE__ */ a("div", { style: d.linkContainer, children: [
2708
- /* @__PURE__ */ a("div", { children: [
2709
- /* @__PURE__ */ a("span", { style: d.divider, children: [
2710
- b.loginText,
2800
+ g && /* @__PURE__ */ c("div", { style: h.linkContainer, children: [
2801
+ /* @__PURE__ */ c("div", { children: [
2802
+ /* @__PURE__ */ c("span", { style: h.divider, children: [
2803
+ k.loginText,
2711
2804
  " "
2712
2805
  ] }),
2713
- /* @__PURE__ */ n("a", { onClick: s, style: d.link, children: b.loginLink })
2806
+ /* @__PURE__ */ n("a", { onClick: s, style: h.link, children: k.loginLink })
2714
2807
  ] }),
2715
- /* @__PURE__ */ n("div", { style: d.divider, children: "•" }),
2716
- /* @__PURE__ */ a("div", { children: [
2717
- /* @__PURE__ */ a("span", { style: d.divider, children: [
2718
- b.signupText,
2808
+ /* @__PURE__ */ n("div", { style: h.divider, children: "•" }),
2809
+ /* @__PURE__ */ c("div", { children: [
2810
+ /* @__PURE__ */ c("span", { style: h.divider, children: [
2811
+ k.signupText,
2719
2812
  " "
2720
2813
  ] }),
2721
- /* @__PURE__ */ n("a", { onClick: o, style: d.link, children: b.signupLink })
2814
+ /* @__PURE__ */ n("a", { onClick: o, style: h.link, children: k.signupLink })
2722
2815
  ] })
2723
2816
  ] })
2724
2817
  ] });
2725
2818
  }
2726
- const lt = {
2819
+ const yt = {
2727
2820
  title: "Verifying Magic Link",
2728
2821
  verifyingMessage: "Please wait while we verify your magic link...",
2729
2822
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2818,7 +2911,7 @@ const lt = {
2818
2911
  cursor: "pointer",
2819
2912
  transition: "all 0.15s ease-in-out"
2820
2913
  }
2821
- }, ct = () => /* @__PURE__ */ n("div", { style: Ee.spinner }), dt = () => /* @__PURE__ */ a(
2914
+ }, wt = () => /* @__PURE__ */ n("div", { style: Ee.spinner }), bt = () => /* @__PURE__ */ c(
2822
2915
  "svg",
2823
2916
  {
2824
2917
  width: "48",
@@ -2835,7 +2928,7 @@ const lt = {
2835
2928
  /* @__PURE__ */ n("polyline", { points: "22,4 12,14.01 9,11.01" })
2836
2929
  ]
2837
2930
  }
2838
- ), ut = () => /* @__PURE__ */ a(
2931
+ ), St = () => /* @__PURE__ */ c(
2839
2932
  "svg",
2840
2933
  {
2841
2934
  width: "48",
@@ -2853,12 +2946,12 @@ const lt = {
2853
2946
  /* @__PURE__ */ n("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
2854
2947
  ]
2855
2948
  }
2856
- ), ht = {
2857
- loading: /* @__PURE__ */ n(ct, {}),
2858
- success: /* @__PURE__ */ n(dt, {}),
2859
- error: /* @__PURE__ */ n(ut, {})
2949
+ ), vt = {
2950
+ loading: /* @__PURE__ */ n(wt, {}),
2951
+ success: /* @__PURE__ */ n(bt, {}),
2952
+ error: /* @__PURE__ */ n(St, {})
2860
2953
  };
2861
- function qt({
2954
+ function Jt({
2862
2955
  copy: i = {},
2863
2956
  styles: e = {},
2864
2957
  icons: t = {},
@@ -2866,96 +2959,96 @@ function qt({
2866
2959
  onError: s,
2867
2960
  onRetry: o,
2868
2961
  onBackToLogin: g,
2869
- className: y,
2870
- token: A,
2871
- email: w,
2872
- appId: T,
2873
- tenantSlug: f,
2874
- autoRedirectDelay: p = 3e3
2962
+ className: w,
2963
+ token: x,
2964
+ email: b,
2965
+ appId: A,
2966
+ tenantSlug: m,
2967
+ autoRedirectDelay: f = 3e3
2875
2968
  }) {
2876
- const [h, m] = k("verifying"), [R, C] = k(""), { verifyMagicLink: U } = ae(), P = { ...lt, ...i }, u = { ...Ee, ...e }, M = { ...ht, ...t }, E = () => {
2969
+ const [u, y] = v("verifying"), [E, C] = v(""), { verifyMagicLink: q } = ae(), T = { ...yt, ...i }, d = { ...Ee, ...e }, P = { ...vt, ...t }, R = () => {
2877
2970
  if (typeof window > "u") return {};
2878
- const v = new URLSearchParams(window.location.search);
2971
+ const S = new URLSearchParams(window.location.search);
2879
2972
  return {
2880
- token: A || v.get("token") || "",
2881
- email: w || v.get("email") || "",
2882
- appId: T || v.get("appId") || "",
2883
- tenantSlug: f || v.get("tenantSlug") || void 0
2973
+ token: x || S.get("token") || "",
2974
+ email: b || S.get("email") || "",
2975
+ appId: A || S.get("appId") || "",
2976
+ tenantSlug: m || S.get("tenantSlug") || void 0
2884
2977
  };
2885
- }, q = async () => {
2886
- m("verifying"), C("");
2978
+ }, z = async () => {
2979
+ y("verifying"), C("");
2887
2980
  try {
2888
- const v = E();
2889
- if (!v.token || !v.email)
2981
+ const S = R();
2982
+ if (!S.token || !S.email)
2890
2983
  throw new Error("Missing required parameters: token or email");
2891
- const I = await U({
2892
- token: v.token,
2893
- email: v.email,
2894
- tenantSlug: v.tenantSlug
2984
+ const M = await q({
2985
+ token: S.token,
2986
+ email: S.email,
2987
+ tenantSlug: S.tenantSlug
2895
2988
  });
2896
- m("success"), r == null || r(I), p > 0 && setTimeout(() => {
2897
- m("redirecting");
2898
- }, p);
2899
- } catch (v) {
2900
- const I = v.message || P.errorMessage;
2901
- C(I), m("error"), s == null || s(I);
2989
+ y("success"), r == null || r(M), f > 0 && setTimeout(() => {
2990
+ y("redirecting");
2991
+ }, f);
2992
+ } catch (S) {
2993
+ const M = S.message || T.errorMessage;
2994
+ C(M), y("error"), s == null || s(M);
2902
2995
  }
2903
- }, V = () => {
2904
- o == null || o(), q();
2996
+ }, G = () => {
2997
+ o == null || o(), z();
2905
2998
  }, $ = () => {
2906
2999
  g == null || g();
2907
3000
  };
2908
3001
  te(() => {
2909
- q();
3002
+ z();
2910
3003
  }, []);
2911
- const j = () => {
2912
- switch (h) {
3004
+ const _ = () => {
3005
+ switch (u) {
2913
3006
  case "verifying":
2914
- return /* @__PURE__ */ a("div", { style: u.message, children: [
2915
- M.loading,
2916
- P.verifyingMessage
3007
+ return /* @__PURE__ */ c("div", { style: d.message, children: [
3008
+ P.loading,
3009
+ T.verifyingMessage
2917
3010
  ] });
2918
3011
  case "success":
2919
- return /* @__PURE__ */ a(B, { children: [
2920
- M.success,
2921
- /* @__PURE__ */ n("div", { style: u.successMessage, children: P.successMessage })
3012
+ return /* @__PURE__ */ c(B, { children: [
3013
+ P.success,
3014
+ /* @__PURE__ */ n("div", { style: d.successMessage, children: T.successMessage })
2922
3015
  ] });
2923
3016
  case "redirecting":
2924
- return /* @__PURE__ */ a(B, { children: [
2925
- M.loading,
2926
- /* @__PURE__ */ n("div", { style: u.message, children: P.redirectingMessage })
3017
+ return /* @__PURE__ */ c(B, { children: [
3018
+ P.loading,
3019
+ /* @__PURE__ */ n("div", { style: d.message, children: T.redirectingMessage })
2927
3020
  ] });
2928
3021
  case "error":
2929
- return /* @__PURE__ */ a(B, { children: [
2930
- M.error,
2931
- /* @__PURE__ */ n("div", { style: u.errorMessage, children: R || P.errorMessage }),
2932
- /* @__PURE__ */ a("div", { style: u.buttonContainer, children: [
3022
+ return /* @__PURE__ */ c(B, { children: [
3023
+ P.error,
3024
+ /* @__PURE__ */ n("div", { style: d.errorMessage, children: E || T.errorMessage }),
3025
+ /* @__PURE__ */ c("div", { style: d.buttonContainer, children: [
2933
3026
  /* @__PURE__ */ n(
2934
3027
  "button",
2935
3028
  {
2936
- onClick: V,
2937
- style: u.retryButton,
2938
- onMouseOver: (v) => {
2939
- v.currentTarget.style.backgroundColor = "#2563eb";
3029
+ onClick: G,
3030
+ style: d.retryButton,
3031
+ onMouseOver: (S) => {
3032
+ S.currentTarget.style.backgroundColor = "#2563eb";
2940
3033
  },
2941
- onMouseOut: (v) => {
2942
- v.currentTarget.style.backgroundColor = "#3b82f6";
3034
+ onMouseOut: (S) => {
3035
+ S.currentTarget.style.backgroundColor = "#3b82f6";
2943
3036
  },
2944
- children: P.retryButton
3037
+ children: T.retryButton
2945
3038
  }
2946
3039
  ),
2947
3040
  /* @__PURE__ */ n(
2948
3041
  "button",
2949
3042
  {
2950
3043
  onClick: $,
2951
- style: u.backButton,
2952
- onMouseOver: (v) => {
2953
- v.currentTarget.style.backgroundColor = "#e5e7eb";
3044
+ style: d.backButton,
3045
+ onMouseOver: (S) => {
3046
+ S.currentTarget.style.backgroundColor = "#e5e7eb";
2954
3047
  },
2955
- onMouseOut: (v) => {
2956
- v.currentTarget.style.backgroundColor = "#f3f4f6";
3048
+ onMouseOut: (S) => {
3049
+ S.currentTarget.style.backgroundColor = "#f3f4f6";
2957
3050
  },
2958
- children: P.backToLoginButton
3051
+ children: T.backToLoginButton
2959
3052
  }
2960
3053
  )
2961
3054
  ] })
@@ -2964,18 +3057,18 @@ function qt({
2964
3057
  return null;
2965
3058
  }
2966
3059
  };
2967
- return /* @__PURE__ */ a("div", { style: u.container, className: y, children: [
3060
+ return /* @__PURE__ */ c("div", { style: d.container, className: w, children: [
2968
3061
  /* @__PURE__ */ n("style", { children: `
2969
3062
  @keyframes spin {
2970
3063
  0% { transform: rotate(0deg); }
2971
3064
  100% { transform: rotate(360deg); }
2972
3065
  }
2973
3066
  ` }),
2974
- /* @__PURE__ */ n("h1", { style: u.title, children: P.title }),
2975
- j()
3067
+ /* @__PURE__ */ n("h1", { style: d.title, children: T.title }),
3068
+ _()
2976
3069
  ] });
2977
3070
  }
2978
- const gt = {
3071
+ const xt = {
2979
3072
  title: "Reset Password",
2980
3073
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
2981
3074
  emailLabel: "Email",
@@ -2997,7 +3090,7 @@ const gt = {
2997
3090
  resetLoadingText: "Resetting...",
2998
3091
  resetSuccessMessage: "Password reset successfully!",
2999
3092
  passwordMismatchError: "Passwords do not match"
3000
- }, pt = {
3093
+ }, kt = {
3001
3094
  container: {
3002
3095
  maxWidth: "400px",
3003
3096
  margin: "0 auto",
@@ -3089,7 +3182,7 @@ const gt = {
3089
3182
  cursor: "pointer"
3090
3183
  }
3091
3184
  };
3092
- function zt({
3185
+ function Yt({
3093
3186
  copy: i = {},
3094
3187
  styles: e = {},
3095
3188
  mode: t = "request",
@@ -3097,105 +3190,105 @@ function zt({
3097
3190
  onSuccess: s,
3098
3191
  onError: o,
3099
3192
  onBackToLogin: g,
3100
- onModeChange: y,
3101
- className: A
3193
+ onModeChange: w,
3194
+ className: x
3102
3195
  }) {
3103
- const [w, T] = k(""), [f, p] = k(r), [h, m] = k(""), [R, C] = k(""), [U, P] = k(!1), [u, M] = k(""), [E, q] = k(""), [V, $] = k({}), { requestPasswordReset: j, confirmPasswordReset: v } = ae(), { tenant: I } = se(), L = { ...gt, ...i }, l = { ...pt, ...e }, x = () => {
3104
- const z = {};
3105
- return w.trim() || (z.email = !0), $(z), Object.keys(z).length === 0;
3106
- }, b = () => {
3107
- const z = {};
3108
- return f.trim() || (z.token = !0), h.trim() || (z.newPassword = !0), R.trim() || (z.confirmPassword = !0), $(z), Object.keys(z).length === 0;
3109
- }, d = async (z) => {
3110
- if (z.preventDefault(), !!x()) {
3111
- if (!(I != null && I.id)) {
3112
- M("Tenant not found");
3196
+ const [b, A] = v(""), [m, f] = v(r), [u, y] = v(""), [E, C] = v(""), [q, T] = v(!1), [d, P] = v(""), [R, z] = v(""), [G, $] = v({}), { requestPasswordReset: _, confirmPasswordReset: S } = ae(), { tenant: M } = se(), L = { ...xt, ...i }, l = { ...kt, ...e }, I = () => {
3197
+ const H = {};
3198
+ return b.trim() || (H.email = !0), $(H), Object.keys(H).length === 0;
3199
+ }, k = () => {
3200
+ const H = {};
3201
+ return m.trim() || (H.token = !0), u.trim() || (H.newPassword = !0), E.trim() || (H.confirmPassword = !0), $(H), Object.keys(H).length === 0;
3202
+ }, h = async (H) => {
3203
+ if (H.preventDefault(), !!I()) {
3204
+ if (!(M != null && M.id)) {
3205
+ P("Tenant not found");
3113
3206
  return;
3114
3207
  }
3115
- P(!0), M(""), q("");
3208
+ T(!0), P(""), z("");
3116
3209
  try {
3117
- await j({ email: w, tenantId: I.id }), q(L.successMessage), s == null || s();
3118
- } catch (H) {
3119
- const O = H.message || L.errorMessage;
3120
- M(O), o == null || o(O);
3210
+ await _({ email: b, tenantId: M.id }), z(L.successMessage), s == null || s();
3211
+ } catch (N) {
3212
+ const W = N.message || L.errorMessage;
3213
+ P(W), o == null || o(W);
3121
3214
  } finally {
3122
- P(!1);
3215
+ T(!1);
3123
3216
  }
3124
3217
  }
3125
- }, c = async (z) => {
3126
- if (z.preventDefault(), !!b()) {
3127
- if (h !== R) {
3128
- M(L.passwordMismatchError), $({ confirmPassword: !0 });
3218
+ }, a = async (H) => {
3219
+ if (H.preventDefault(), !!k()) {
3220
+ if (u !== E) {
3221
+ P(L.passwordMismatchError), $({ confirmPassword: !0 });
3129
3222
  return;
3130
3223
  }
3131
- P(!0), M(""), q("");
3224
+ T(!0), P(""), z("");
3132
3225
  try {
3133
- await v({ token: f, newPassword: h }), q(L.resetSuccessMessage), s == null || s();
3134
- } catch (H) {
3135
- const O = H.message || L.errorMessage;
3136
- M(O), o == null || o(O);
3226
+ await S({ token: m, newPassword: u }), z(L.resetSuccessMessage), s == null || s();
3227
+ } catch (N) {
3228
+ const W = N.message || L.errorMessage;
3229
+ P(W), o == null || o(W);
3137
3230
  } finally {
3138
- P(!1);
3231
+ T(!1);
3139
3232
  }
3140
3233
  }
3141
- }, S = (z) => ({
3234
+ }, p = (H) => ({
3142
3235
  ...l.input,
3143
- ...V[z] ? l.inputError : {}
3144
- }), _ = () => ({
3236
+ ...G[H] ? l.inputError : {}
3237
+ }), O = () => ({
3145
3238
  ...l.button,
3146
- ...U ? l.buttonLoading : {}
3239
+ ...q ? l.buttonLoading : {}
3147
3240
  });
3148
3241
  if (t === "reset") {
3149
- const z = f && h && R;
3150
- return /* @__PURE__ */ a("div", { className: A, style: l.container, children: [
3242
+ const H = m && u && E;
3243
+ return /* @__PURE__ */ c("div", { className: x, style: l.container, children: [
3151
3244
  /* @__PURE__ */ n("h2", { style: l.title, children: L.resetTitle }),
3152
3245
  /* @__PURE__ */ n("p", { style: l.subtitle, children: L.resetSubtitle }),
3153
- /* @__PURE__ */ a("form", { onSubmit: c, style: l.form, children: [
3154
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3246
+ /* @__PURE__ */ c("form", { onSubmit: a, style: l.form, children: [
3247
+ /* @__PURE__ */ c("div", { style: l.fieldGroup, children: [
3155
3248
  /* @__PURE__ */ n("label", { style: l.label, children: L.tokenLabel }),
3156
3249
  /* @__PURE__ */ n(
3157
3250
  "input",
3158
3251
  {
3159
3252
  type: "text",
3160
- value: f,
3161
- onChange: (H) => {
3162
- p(H.target.value), V.token && $((O) => ({ ...O, token: !1 }));
3253
+ value: m,
3254
+ onChange: (N) => {
3255
+ f(N.target.value), G.token && $((W) => ({ ...W, token: !1 }));
3163
3256
  },
3164
3257
  placeholder: L.tokenPlaceholder,
3165
- style: S("token"),
3166
- disabled: U
3258
+ style: p("token"),
3259
+ disabled: q
3167
3260
  }
3168
3261
  )
3169
3262
  ] }),
3170
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3263
+ /* @__PURE__ */ c("div", { style: l.fieldGroup, children: [
3171
3264
  /* @__PURE__ */ n("label", { style: l.label, children: L.newPasswordLabel }),
3172
3265
  /* @__PURE__ */ n(
3173
3266
  "input",
3174
3267
  {
3175
3268
  type: "password",
3176
- value: h,
3177
- onChange: (H) => {
3178
- m(H.target.value), V.newPassword && $((O) => ({ ...O, newPassword: !1 }));
3269
+ value: u,
3270
+ onChange: (N) => {
3271
+ y(N.target.value), G.newPassword && $((W) => ({ ...W, newPassword: !1 }));
3179
3272
  },
3180
3273
  placeholder: L.newPasswordPlaceholder,
3181
- style: S("newPassword"),
3182
- disabled: U
3274
+ style: p("newPassword"),
3275
+ disabled: q
3183
3276
  }
3184
3277
  )
3185
3278
  ] }),
3186
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3279
+ /* @__PURE__ */ c("div", { style: l.fieldGroup, children: [
3187
3280
  /* @__PURE__ */ n("label", { style: l.label, children: L.confirmPasswordLabel }),
3188
3281
  /* @__PURE__ */ n(
3189
3282
  "input",
3190
3283
  {
3191
3284
  type: "password",
3192
- value: R,
3193
- onChange: (H) => {
3194
- C(H.target.value), V.confirmPassword && $((O) => ({ ...O, confirmPassword: !1 })), u === L.passwordMismatchError && M("");
3285
+ value: E,
3286
+ onChange: (N) => {
3287
+ C(N.target.value), G.confirmPassword && $((W) => ({ ...W, confirmPassword: !1 })), d === L.passwordMismatchError && P("");
3195
3288
  },
3196
3289
  placeholder: L.confirmPasswordPlaceholder,
3197
- style: S("confirmPassword"),
3198
- disabled: U
3290
+ style: p("confirmPassword"),
3291
+ disabled: q
3199
3292
  }
3200
3293
  )
3201
3294
  ] }),
@@ -3203,44 +3296,44 @@ function zt({
3203
3296
  "button",
3204
3297
  {
3205
3298
  type: "submit",
3206
- disabled: !z || U,
3299
+ disabled: !H || q,
3207
3300
  style: {
3208
- ..._(),
3209
- ...!z || U ? l.buttonDisabled : {}
3301
+ ...O(),
3302
+ ...!H || q ? l.buttonDisabled : {}
3210
3303
  },
3211
- children: U ? L.resetLoadingText : L.resetSubmitButton
3304
+ children: q ? L.resetLoadingText : L.resetSubmitButton
3212
3305
  }
3213
3306
  ),
3214
- u && /* @__PURE__ */ n("div", { style: l.errorText, children: u }),
3215
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3307
+ d && /* @__PURE__ */ n("div", { style: l.errorText, children: d }),
3308
+ R && /* @__PURE__ */ n("div", { style: l.successText, children: R })
3216
3309
  ] }),
3217
- /* @__PURE__ */ a("div", { style: l.linkContainer, children: [
3310
+ /* @__PURE__ */ c("div", { style: l.linkContainer, children: [
3218
3311
  /* @__PURE__ */ n("a", { onClick: g, style: l.link, children: L.backToLoginLink }),
3219
- y && /* @__PURE__ */ a(B, { children: [
3312
+ w && /* @__PURE__ */ c(B, { children: [
3220
3313
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3221
- /* @__PURE__ */ n("a", { onClick: () => y("request"), style: l.link, children: "Request New Link" })
3314
+ /* @__PURE__ */ n("a", { onClick: () => w("request"), style: l.link, children: "Request New Link" })
3222
3315
  ] })
3223
3316
  ] })
3224
3317
  ] });
3225
3318
  }
3226
- const ee = w;
3227
- return /* @__PURE__ */ a("div", { className: A, style: l.container, children: [
3319
+ const K = b;
3320
+ return /* @__PURE__ */ c("div", { className: x, style: l.container, children: [
3228
3321
  /* @__PURE__ */ n("h2", { style: l.title, children: L.title }),
3229
3322
  /* @__PURE__ */ n("p", { style: l.subtitle, children: L.subtitle }),
3230
- /* @__PURE__ */ a("form", { onSubmit: d, style: l.form, children: [
3231
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3323
+ /* @__PURE__ */ c("form", { onSubmit: h, style: l.form, children: [
3324
+ /* @__PURE__ */ c("div", { style: l.fieldGroup, children: [
3232
3325
  /* @__PURE__ */ n("label", { style: l.label, children: L.emailLabel }),
3233
3326
  /* @__PURE__ */ n(
3234
3327
  "input",
3235
3328
  {
3236
3329
  type: "email",
3237
- value: w,
3238
- onChange: (z) => {
3239
- T(z.target.value), V.email && $((H) => ({ ...H, email: !1 }));
3330
+ value: b,
3331
+ onChange: (H) => {
3332
+ A(H.target.value), G.email && $((N) => ({ ...N, email: !1 }));
3240
3333
  },
3241
3334
  placeholder: L.emailPlaceholder,
3242
- style: S("email"),
3243
- disabled: U
3335
+ style: p("email"),
3336
+ disabled: q
3244
3337
  }
3245
3338
  )
3246
3339
  ] }),
@@ -3248,27 +3341,27 @@ function zt({
3248
3341
  "button",
3249
3342
  {
3250
3343
  type: "submit",
3251
- disabled: !ee || U,
3344
+ disabled: !K || q,
3252
3345
  style: {
3253
- ..._(),
3254
- ...!ee || U ? l.buttonDisabled : {}
3346
+ ...O(),
3347
+ ...!K || q ? l.buttonDisabled : {}
3255
3348
  },
3256
- children: U ? L.loadingText : L.submitButton
3349
+ children: q ? L.loadingText : L.submitButton
3257
3350
  }
3258
3351
  ),
3259
- u && /* @__PURE__ */ n("div", { style: l.errorText, children: u }),
3260
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3352
+ d && /* @__PURE__ */ n("div", { style: l.errorText, children: d }),
3353
+ R && /* @__PURE__ */ n("div", { style: l.successText, children: R })
3261
3354
  ] }),
3262
- /* @__PURE__ */ a("div", { style: l.linkContainer, children: [
3355
+ /* @__PURE__ */ c("div", { style: l.linkContainer, children: [
3263
3356
  /* @__PURE__ */ n("a", { onClick: g, style: l.link, children: L.backToLoginLink }),
3264
- y && /* @__PURE__ */ a(B, { children: [
3357
+ w && /* @__PURE__ */ c(B, { children: [
3265
3358
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3266
- /* @__PURE__ */ n("a", { onClick: () => y("reset"), style: l.link, children: "I have a token" })
3359
+ /* @__PURE__ */ n("a", { onClick: () => w("reset"), style: l.link, children: "I have a token" })
3267
3360
  ] })
3268
3361
  ] })
3269
3362
  ] });
3270
3363
  }
3271
- const ft = () => /* @__PURE__ */ n(
3364
+ const At = () => /* @__PURE__ */ n(
3272
3365
  "div",
3273
3366
  {
3274
3367
  style: {
@@ -3280,7 +3373,7 @@ const ft = () => /* @__PURE__ */ n(
3280
3373
  },
3281
3374
  children: /* @__PURE__ */ n("div", { children: "Loading..." })
3282
3375
  }
3283
- ), mt = ({ error: i, retry: e }) => /* @__PURE__ */ a(
3376
+ ), Tt = ({ error: i, retry: e }) => /* @__PURE__ */ c(
3284
3377
  "div",
3285
3378
  {
3286
3379
  style: {
@@ -3314,40 +3407,40 @@ const ft = () => /* @__PURE__ */ n(
3314
3407
  ]
3315
3408
  }
3316
3409
  );
3317
- function Ot({
3410
+ function Qt({
3318
3411
  children: i,
3319
3412
  loadingFallback: e,
3320
3413
  errorFallback: t,
3321
3414
  requireTenant: r = !0
3322
3415
  }) {
3323
- const { isAppLoading: s, appError: o, retryApp: g } = oe(), y = Pe(), A = (y == null ? void 0 : y.isTenantLoading) ?? !1, w = (y == null ? void 0 : y.tenantError) ?? null, T = (y == null ? void 0 : y.tenantSlug) ?? null, f = (y == null ? void 0 : y.retryTenant) ?? (() => {
3324
- }), p = r && y && T, h = s || p && A, m = o || (p ? w : null), R = () => {
3325
- o && g(), w && y && f();
3416
+ const { isAppLoading: s, appError: o, retryApp: g } = oe(), w = Me(), x = (w == null ? void 0 : w.isTenantLoading) ?? !1, b = (w == null ? void 0 : w.tenantError) ?? null, A = (w == null ? void 0 : w.tenantSlug) ?? null, m = (w == null ? void 0 : w.retryTenant) ?? (() => {
3417
+ }), f = r && w && A, u = s || f && x, y = o || (f ? b : null), E = () => {
3418
+ o && g(), b && w && m();
3326
3419
  };
3327
- if (h)
3328
- return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(ft, {}) });
3329
- if (m) {
3330
- const C = typeof t == "function" ? t(m, R) : t || /* @__PURE__ */ n(mt, { error: m, retry: R });
3420
+ if (u)
3421
+ return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(At, {}) });
3422
+ if (y) {
3423
+ const C = typeof t == "function" ? t(y, E) : t || /* @__PURE__ */ n(Tt, { error: y, retry: E });
3331
3424
  return /* @__PURE__ */ n(B, { children: C });
3332
3425
  }
3333
3426
  return /* @__PURE__ */ n(B, { children: i });
3334
3427
  }
3335
- function Wt(i = !0) {
3336
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: s } = oe(), o = Pe(), g = (o == null ? void 0 : o.isTenantLoading) ?? !1, y = (o == null ? void 0 : o.tenantError) ?? null, A = (o == null ? void 0 : o.tenant) ?? null, w = (o == null ? void 0 : o.tenantSlug) ?? null, T = (o == null ? void 0 : o.retryTenant) ?? (() => {
3337
- }), f = i && o && w, p = e || f && g, h = t || (f ? y : null);
3428
+ function Xt(i = !0) {
3429
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: s } = oe(), o = Me(), g = (o == null ? void 0 : o.isTenantLoading) ?? !1, w = (o == null ? void 0 : o.tenantError) ?? null, x = (o == null ? void 0 : o.tenant) ?? null, b = (o == null ? void 0 : o.tenantSlug) ?? null, A = (o == null ? void 0 : o.retryTenant) ?? (() => {
3430
+ }), m = i && o && b, f = e || m && g, u = t || (m ? w : null);
3338
3431
  return {
3339
- isLoading: p,
3340
- error: h,
3341
- isReady: !p && !h && s !== null && (!f || A !== null),
3432
+ isLoading: f,
3433
+ error: u,
3434
+ isReady: !f && !u && s !== null && (!m || x !== null),
3342
3435
  retry: () => {
3343
- t && r(), y && o && T();
3436
+ t && r(), w && o && A();
3344
3437
  },
3345
3438
  // Individual states
3346
3439
  app: { isLoading: e, error: t, data: s },
3347
- tenant: o ? { isLoading: g, error: y, data: A } : null
3440
+ tenant: o ? { isLoading: g, error: w, data: x } : null
3348
3441
  };
3349
3442
  }
3350
- class jt {
3443
+ class Zt {
3351
3444
  constructor(e, t) {
3352
3445
  this.httpService = e, this.sessionManager = t;
3353
3446
  }
@@ -3415,7 +3508,7 @@ class jt {
3415
3508
  };
3416
3509
  }
3417
3510
  }
3418
- class Vt {
3511
+ class er {
3419
3512
  constructor(e, t) {
3420
3513
  this.httpService = e, this.sessionManager = t;
3421
3514
  }
@@ -3466,7 +3559,7 @@ class Vt {
3466
3559
  });
3467
3560
  }
3468
3561
  }
3469
- class Gt {
3562
+ class tr {
3470
3563
  constructor(e) {
3471
3564
  this.httpService = e;
3472
3565
  }
@@ -3475,7 +3568,7 @@ class Gt {
3475
3568
  return await this.httpService.get("/health");
3476
3569
  }
3477
3570
  }
3478
- class _t {
3571
+ class rr {
3479
3572
  // Date string to Date object
3480
3573
  static toDate(e) {
3481
3574
  return new Date(e);
@@ -3598,47 +3691,47 @@ class _t {
3598
3691
  }
3599
3692
  }
3600
3693
  export {
3601
- _t as ApiMappers,
3602
- Se as AppApiService,
3603
- Ot as AppLoader,
3604
- kt as AppProvider,
3605
- He as AuthApiService,
3606
- It as AuthProvider,
3607
- Ht as FeatureFlag,
3608
- Oe as FeatureFlagApiService,
3609
- Lt as FeatureFlagProvider,
3610
- Gt as HealthApiService,
3694
+ rr as ApiMappers,
3695
+ ve as AppApiService,
3696
+ Qt as AppLoader,
3697
+ Ct as AppProvider,
3698
+ ze as AuthApiService,
3699
+ Nt as AuthProvider,
3700
+ jt as FeatureFlag,
3701
+ Qe as FeatureFlagApiService,
3702
+ Ut as FeatureFlagProvider,
3703
+ tr as HealthApiService,
3611
3704
  re as HttpService,
3612
- Ft as LandingRoute,
3613
- Nt as LoginForm,
3614
- Ut as MagicLinkForm,
3615
- qt as MagicLinkVerify,
3616
- zt as PasswordRecoveryForm,
3617
- jt as PermissionApiService,
3618
- Rt as Protected,
3619
- Ct as ProtectedRoute,
3620
- ve as RoleApiService,
3621
- ye as SessionManager,
3622
- Bt as SignupForm,
3623
- je as SubscriptionApiService,
3624
- Dt as SubscriptionGuard,
3625
- Vt as SubscriptionPlanApiService,
3626
- Et as SubscriptionProvider,
3705
+ Wt as LandingRoute,
3706
+ _t as LoginForm,
3707
+ Kt as MagicLinkForm,
3708
+ Jt as MagicLinkVerify,
3709
+ Yt as PasswordRecoveryForm,
3710
+ Zt as PermissionApiService,
3711
+ qt as Protected,
3712
+ zt as ProtectedRoute,
3713
+ xe as RoleApiService,
3714
+ we as SessionManager,
3715
+ Gt as SignupForm,
3716
+ Ze as SubscriptionApiService,
3717
+ Vt as SubscriptionGuard,
3718
+ er as SubscriptionPlanApiService,
3719
+ Bt as SubscriptionProvider,
3627
3720
  ue as TenantApiService,
3628
- Tt as TenantProvider,
3629
- $t as TenantRoute,
3630
- Ne as UserApiService,
3721
+ Dt as TenantProvider,
3722
+ Ot as TenantRoute,
3723
+ Oe as UserApiService,
3631
3724
  ie as UserType,
3632
- At as useApi,
3725
+ $t as useApi,
3633
3726
  oe as useApp,
3634
- Wt as useAppLoaderState,
3727
+ Xt as useAppLoaderState,
3635
3728
  ae as useAuth,
3636
- We as useFeatureFlags,
3637
- Mt as useSettings,
3638
- Ve as useSubscription,
3639
- fe as useTenant,
3729
+ Xe as useFeatureFlags,
3730
+ Ht as useSettings,
3731
+ et as useSubscription,
3732
+ me as useTenant,
3640
3733
  se as useTenantInfo,
3641
- Pe as useTenantOptional,
3642
- Pt as useTenantSettings
3734
+ Me as useTenantOptional,
3735
+ Ft as useTenantSettings
3643
3736
  };
3644
3737
  //# sourceMappingURL=index.es.js.map