@skylabs-digital/react-identity-access 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js 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 U, jsxs as l } from "react/jsx-runtime";
2
+ import { createContext as he, useMemo as X, useState as x, useCallback as ne, useEffect as te, useContext as ce, useRef as Be } from "react";
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 p = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, b = (s == null ? void 0 : s.timeout) || this.timeout;
20
+ let k = {
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
+ k = { ...k, ...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 S = new AbortController(), T = setTimeout(() => S.abort(), b);
32
32
  try {
33
- const f = await fetch(g, {
33
+ const m = await fetch(p, {
34
34
  method: e,
35
- headers: A,
35
+ headers: k,
36
36
  body: r ? JSON.stringify(r) : void 0,
37
- signal: w.signal
37
+ signal: S.signal
38
38
  });
39
- if (clearTimeout(T), f.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
39
+ if (clearTimeout(T), 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(T), m instanceof Error && m.name === "AbortError" ? new Error(`Request timeout after ${b}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,31 +124,31 @@ class Se {
124
124
  })).data;
125
125
  }
126
126
  }
127
- const Te = he(null);
128
- function xt({ config: i, children: e }) {
129
- const t = Q(
127
+ const Pe = he(null);
128
+ function Et({ 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] = x(() => {
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 = () => {
150
+ }), [o, p] = x(!r), [b, k] = x(null), S = X(() => {
151
+ const f = () => {
152
152
  T();
153
153
  };
154
154
  return {
@@ -157,15 +157,15 @@ function xt({ config: i, children: e }) {
157
157
  // App info
158
158
  appInfo: r,
159
159
  isAppLoading: o,
160
- appError: y,
161
- retryApp: p
160
+ appError: b,
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, b]), T = 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);
167
+ p(!0), k(null);
168
+ const u = new re(i.baseUrl), R = await new ve(u, {}).getPublicAppInfo(i.appId);
169
169
  if (s(R), t.enabled)
170
170
  try {
171
171
  const C = {
@@ -177,46 +177,46 @@ function xt({ 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
+ k(y), s(null);
183
183
  } finally {
184
- g(!1);
184
+ p(!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 R = new re(i.baseUrl), q = await new ve(R, {}).getPublicAppInfo(i.appId);
196
+ s(q);
197
+ const A = {
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(A));
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() : T();
210
+ }, []), /* @__PURE__ */ n(Pe.Provider, { value: S, 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 kt = oe;
219
- class ye {
218
+ const Rt = 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 Ue {
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
  }
@@ -481,16 +481,16 @@ class ve {
481
481
  throw new Error("SessionManager is required for private endpoints");
482
482
  const r = await this.sessionManager.getAuthHeaders(), s = new URLSearchParams();
483
483
  t != null && t.page && s.append("page", t.page.toString()), t != null && t.limit && s.append("limit", t.limit.toString()), t != null && t.sortBy && s.append("sortBy", t.sortBy), t != null && t.sortOrder && s.append("sortOrder", t.sortOrder);
484
- const o = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, g = await this.httpService.get(o, {
484
+ const o = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, p = await this.httpService.get(o, {
485
485
  headers: r
486
486
  });
487
487
  return {
488
- roles: g.data,
489
- meta: g.meta
488
+ roles: p.data,
489
+ meta: p.meta
490
490
  };
491
491
  }
492
492
  }
493
- class Ne {
493
+ class qe {
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 ze(i, e) {
612
612
  if (i === "localhost" || i.startsWith("127.") || i.startsWith("192.168."))
613
613
  return null;
614
614
  if (e) {
@@ -616,25 +616,57 @@ function Be(i, e) {
616
616
  if (o === s || o === `www.${s}`)
617
617
  return null;
618
618
  if (o.endsWith(`.${s}`)) {
619
- const g = o.slice(0, -(s.length + 1));
620
- return g === "www" ? null : g;
619
+ const p = o.slice(0, -(s.length + 1));
620
+ return p === "www" ? null : p;
621
621
  }
622
622
  return null;
623
623
  }
624
624
  const r = i.split(".");
625
625
  return r.length >= 3 && r[0] !== "www" ? r[0] : null;
626
626
  }
627
- function Ue(i, e = "tenant", t) {
627
+ function Oe(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 We(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" ? ze(e.hostname, s) : r === "selector" ? Oe(e.search, o, t) : null;
634
+ }
635
+ function je(i, e, t) {
636
+ if (t)
637
+ return `${i}.${t}`;
638
+ const r = e.split(".");
639
+ return r.length === 2 ? `${i}.${e}` : r.length >= 3 ? (r[0] = i, r.join(".")) : null;
634
640
  }
635
- const be = he(null);
636
- function At({ config: i, children: e }) {
637
- const { baseUrl: t, appInfo: r, appId: s } = oe(), o = ne(() => typeof window > "u" ? null : qe(
641
+ const fe = "_auth";
642
+ function Ve(i) {
643
+ const e = JSON.stringify(i);
644
+ return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
645
+ }
646
+ function _e(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 Ge() {
658
+ if (typeof window > "u") return null;
659
+ const e = new URLSearchParams(window.location.search).get(fe);
660
+ return e ? _e(e) : null;
661
+ }
662
+ function Ke() {
663
+ if (typeof window > "u") return;
664
+ const i = new URL(window.location.href);
665
+ i.searchParams.delete(fe), window.history.replaceState({}, "", i.toString());
666
+ }
667
+ const Se = he(null);
668
+ function Ct({ config: i, children: e }) {
669
+ const { baseUrl: t, appInfo: r, appId: s } = oe(), o = ne(() => typeof window > "u" ? null : We(
638
670
  {
639
671
  tenantMode: i.tenantMode || "selector",
640
672
  baseDomain: i.baseDomain,
@@ -645,118 +677,118 @@ function At({ config: i, children: e }) {
645
677
  search: window.location.search
646
678
  },
647
679
  window.localStorage
648
- ), [i.tenantMode, i.baseDomain, i.selectorParam]), [g, y] = k(() => o()), A = Q(
680
+ ), [i.tenantMode, i.baseDomain, i.selectorParam]), [p, b] = x(() => o()), k = X(
649
681
  () => {
650
- var l, x, b;
682
+ var a, L, c;
651
683
  return {
652
- enabled: ((l = i.cache) == null ? void 0 : l.enabled) ?? !0,
653
- ttl: ((x = i.cache) == null ? void 0 : x.ttl) ?? 5 * 60 * 1e3,
684
+ enabled: ((a = i.cache) == null ? void 0 : a.enabled) ?? !0,
685
+ ttl: ((L = i.cache) == null ? void 0 : L.ttl) ?? 5 * 60 * 1e3,
654
686
  // 5 minutes default
655
- storageKey: ((b = i.cache) == null ? void 0 : b.storageKey) ?? `tenant_cache_${g || "default"}`
687
+ storageKey: ((c = i.cache) == null ? void 0 : c.storageKey) ?? `tenant_cache_${p || "default"}`
656
688
  };
657
689
  },
658
- [i.cache, g]
659
- ), [w, T] = k(() => {
690
+ [i.cache, p]
691
+ ), [S, T] = x(() => {
660
692
  if (i.initialTenant) return i.initialTenant;
661
- if (!A.enabled || !g) return null;
693
+ if (!k.enabled || !p) return null;
662
694
  try {
663
- const l = localStorage.getItem(A.storageKey);
664
- if (!l) return null;
665
- const x = JSON.parse(l);
666
- return Date.now() - x.timestamp < A.ttl && x.tenantSlug === g ? x.data : (localStorage.removeItem(A.storageKey), null);
695
+ const a = localStorage.getItem(k.storageKey);
696
+ if (!a) return null;
697
+ const L = JSON.parse(a);
698
+ return Date.now() - L.timestamp < k.ttl && L.tenantSlug === p ? L.data : (localStorage.removeItem(k.storageKey), null);
667
699
  } catch {
668
700
  return null;
669
701
  }
670
- }), [f, p] = k(!w && !i.initialTenant), [h, m] = k(null), [R, C] = k(null), [U, P] = k(!1), [u, M] = k(null);
702
+ }), [m, f] = x(!S && !i.initialTenant), [u, y] = x(null), [R, C] = x(null), [q, A] = x(!1), [d, P] = x(null);
671
703
  te(() => {
672
- const l = o();
673
- y(l);
704
+ const a = o();
705
+ b(a);
674
706
  }, [o]);
675
- const E = (r == null ? void 0 : r.settingsSchema) || null, q = ne(
676
- async (l, x = !1) => {
677
- if (!(!x && A.enabled && w && w.domain === l))
707
+ const E = (r == null ? void 0 : r.settingsSchema) || null, z = ne(
708
+ async (a, L = !1) => {
709
+ if (!(!L && k.enabled && S && S.domain === a))
678
710
  try {
679
- p(!0), m(null);
680
- const b = new re(t), c = await new ue(b, s).getPublicTenantInfo(l);
681
- if (T(c), A.enabled)
711
+ f(!0), y(null);
712
+ const c = new re(t), g = await new ue(c, s).getPublicTenantInfo(a);
713
+ if (T(g), k.enabled)
682
714
  try {
683
- const S = {
684
- data: c,
715
+ const w = {
716
+ data: g,
685
717
  timestamp: Date.now(),
686
- tenantSlug: l
718
+ tenantSlug: a
687
719
  };
688
- localStorage.setItem(A.storageKey, JSON.stringify(S));
689
- } catch (S) {
690
- console.warn("Failed to cache tenant info:", S);
720
+ localStorage.setItem(k.storageKey, JSON.stringify(w));
721
+ } catch (w) {
722
+ console.warn("Failed to cache tenant info:", w);
691
723
  }
692
- } catch (b) {
693
- const d = b instanceof Error ? b : new Error("Failed to load tenant information");
694
- m(d), T(null);
724
+ } catch (c) {
725
+ const h = c instanceof Error ? c : new Error("Failed to load tenant information");
726
+ y(h), T(null);
695
727
  } finally {
696
- p(!1);
728
+ f(!1);
697
729
  }
698
730
  },
699
- [t, s, A, w]
700
- ), V = ne(async () => {
701
- if (!(!A.enabled || !w || !g))
731
+ [t, s, k, S]
732
+ ), G = ne(async () => {
733
+ if (!(!k.enabled || !S || !p))
702
734
  try {
703
- const l = localStorage.getItem(A.storageKey);
704
- if (!l) return;
705
- const x = JSON.parse(l);
706
- if (Date.now() - x.timestamp > A.ttl * 0.5) {
707
- const d = new re(t), S = await new ue(d, s).getPublicTenantInfo(g);
708
- T(S);
709
- const G = {
710
- data: S,
735
+ const a = localStorage.getItem(k.storageKey);
736
+ if (!a) return;
737
+ const L = JSON.parse(a);
738
+ if (Date.now() - L.timestamp > k.ttl * 0.5) {
739
+ const h = new re(t), w = await new ue(h, s).getPublicTenantInfo(p);
740
+ T(w);
741
+ const j = {
742
+ data: w,
711
743
  timestamp: Date.now(),
712
- tenantSlug: g
744
+ tenantSlug: p
713
745
  };
714
- localStorage.setItem(A.storageKey, JSON.stringify(G));
746
+ localStorage.setItem(k.storageKey, JSON.stringify(j));
715
747
  }
716
- } catch (l) {
717
- console.warn("Background tenant refresh failed:", l);
748
+ } catch (a) {
749
+ console.warn("Background tenant refresh failed:", a);
718
750
  }
719
- }, [t, s, A, w, g]), $ = ne(async () => {
720
- if (w != null && w.id)
751
+ }, [t, s, k, S, p]), $ = ne(async () => {
752
+ if (S != null && S.id)
721
753
  try {
722
- P(!0), M(null);
723
- const l = new re(t), b = await new ue(l, w.appId).getTenantSettings(w.id);
724
- C(b);
725
- } catch (l) {
726
- const x = l instanceof Error ? l : new Error("Failed to load tenant settings");
727
- M(x), C(null);
754
+ A(!0), P(null);
755
+ const a = new re(t), c = await new ue(a, S.appId).getTenantSettings(S.id);
756
+ C(c);
757
+ } catch (a) {
758
+ const L = a instanceof Error ? a : new Error("Failed to load tenant settings");
759
+ P(L), C(null);
728
760
  } finally {
729
- P(!1);
761
+ A(!1);
730
762
  }
731
- }, [t, w]), j = ne(() => {
763
+ }, [t, S]), _ = ne(() => {
732
764
  $();
733
765
  }, [$]), v = ne(
734
- (l) => {
766
+ (a) => {
735
767
  if (!E)
736
768
  return { isValid: !0, errors: [] };
737
- const x = [];
769
+ const L = [];
738
770
  try {
739
- return E.properties && Object.entries(E.properties).forEach(([b, d]) => {
740
- var S;
741
- const c = l[b];
742
- if ((S = E.required) != null && S.includes(b) && c == null) {
743
- x.push(`Field '${b}' is required`);
771
+ return E.properties && Object.entries(E.properties).forEach(([c, h]) => {
772
+ var w;
773
+ const g = a[c];
774
+ if ((w = E.required) != null && w.includes(c) && g == null) {
775
+ L.push(`Field '${c}' is required`);
744
776
  return;
745
777
  }
746
- if (c != null) {
747
- if (d.type) {
748
- const G = d.type, ee = typeof c;
749
- G === "string" && ee !== "string" ? x.push(`Field '${b}' must be a string`) : (G === "number" || G === "integer") && ee !== "number" ? x.push(`Field '${b}' must be a number`) : G === "boolean" && ee !== "boolean" ? x.push(`Field '${b}' must be a boolean`) : G === "array" && !Array.isArray(c) && x.push(`Field '${b}' must be an array`);
778
+ if (g != null) {
779
+ if (h.type) {
780
+ const j = h.type, Y = typeof g;
781
+ j === "string" && Y !== "string" ? L.push(`Field '${c}' must be a string`) : (j === "number" || j === "integer") && Y !== "number" ? L.push(`Field '${c}' must be a number`) : j === "boolean" && Y !== "boolean" ? L.push(`Field '${c}' must be a boolean`) : j === "array" && !Array.isArray(g) && L.push(`Field '${c}' must be an array`);
750
782
  }
751
- d.minLength !== void 0 && typeof c == "string" && c.length < d.minLength && x.push(
752
- `Field '${b}' must be at least ${d.minLength} characters long`
753
- ), d.maxLength !== void 0 && typeof c == "string" && c.length > d.maxLength && x.push(
754
- `Field '${b}' must be no more than ${d.maxLength} characters long`
755
- ), 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(", ")}`);
783
+ h.minLength !== void 0 && typeof g == "string" && g.length < h.minLength && L.push(
784
+ `Field '${c}' must be at least ${h.minLength} characters long`
785
+ ), h.maxLength !== void 0 && typeof g == "string" && g.length > h.maxLength && L.push(
786
+ `Field '${c}' must be no more than ${h.maxLength} characters long`
787
+ ), h.minimum !== void 0 && typeof g == "number" && g < h.minimum && L.push(`Field '${c}' must be at least ${h.minimum}`), h.maximum !== void 0 && typeof g == "number" && g > h.maximum && L.push(`Field '${c}' must be no more than ${h.maximum}`), h.pattern && typeof g == "string" && (new RegExp(h.pattern).test(g) || L.push(`Field '${c}' does not match the required pattern`)), h.enum && !h.enum.includes(g) && L.push(`Field '${c}' must be one of: ${h.enum.join(", ")}`);
756
788
  }
757
789
  }), {
758
- isValid: x.length === 0,
759
- errors: x
790
+ isValid: L.length === 0,
791
+ errors: L
760
792
  };
761
793
  } catch {
762
794
  return {
@@ -768,82 +800,88 @@ function At({ config: i, children: e }) {
768
800
  [E]
769
801
  );
770
802
  te(() => {
771
- !i.initialTenant && g ? w ? V() : q(g) : !i.initialTenant && !g && (T(null), m(null), p(!1));
772
- }, [i.initialTenant, g, w, q, V]), te(() => {
773
- w != null && w.id ? $() : (C(null), M(null), P(!1));
774
- }, [w == null ? void 0 : w.id, $]);
775
- const I = ne(
776
- (l, x = "reload") => {
777
- const b = i.tenantMode || "selector";
778
- if (localStorage.setItem("tenant", l), b === "subdomain") {
779
- const d = window.location.hostname, c = d.split(".");
780
- if (c.length >= 2) {
781
- c[0] = l;
782
- const S = c.join("."), G = `${window.location.protocol}//${S}${window.location.pathname}${window.location.search}`;
783
- window.location.href = G;
784
- } else
803
+ !i.initialTenant && p ? S ? G() : z(p) : !i.initialTenant && !p && (T(null), y(null), f(!1));
804
+ }, [i.initialTenant, p, S, z, G]), te(() => {
805
+ S != null && S.id ? $() : (C(null), P(null), A(!1));
806
+ }, [S == null ? void 0 : S.id, $]);
807
+ const M = ne(
808
+ (a, L) => {
809
+ const { mode: c = "reload", tokens: h, redirectPath: g } = L || {}, w = i.tenantMode || "selector";
810
+ if (localStorage.setItem("tenant", a), w === "subdomain") {
811
+ const j = window.location.hostname, Y = je(
812
+ a,
813
+ j,
814
+ i.baseDomain
815
+ );
816
+ if (!Y) {
785
817
  console.warn(
786
818
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
787
- d
819
+ j
788
820
  );
789
- } else if (b === "selector") {
790
- const d = new URLSearchParams(window.location.search);
791
- if (d.set(i.selectorParam || "tenant", l), x === "reload") {
792
- const c = `${window.location.pathname}?${d.toString()}${window.location.hash}`;
793
- window.location.href = c;
821
+ return;
822
+ }
823
+ const H = g || window.location.pathname, N = new URL(`${window.location.protocol}//${Y}${H}`);
824
+ new URLSearchParams(window.location.search).forEach((F, K) => {
825
+ K !== fe && N.searchParams.set(K, F);
826
+ }), h && N.searchParams.set(fe, Ve(h)), window.location.href = N.toString();
827
+ } else if (w === "selector") {
828
+ const j = g || window.location.pathname, Y = new URLSearchParams(window.location.search);
829
+ if (Y.set(i.selectorParam || "tenant", a), c === "reload") {
830
+ const H = `${j}?${Y.toString()}${window.location.hash}`;
831
+ window.location.href = H;
794
832
  } else {
795
- const c = `${window.location.pathname}?${d.toString()}${window.location.hash}`;
796
- window.history.pushState({}, "", c), y(l), q(l);
833
+ const H = `${j}?${Y.toString()}${window.location.hash}`;
834
+ window.history.pushState({}, "", H), b(a), z(a);
797
835
  }
798
836
  }
799
837
  },
800
- [i.tenantMode, i.selectorParam, q, g]
801
- ), L = Q(() => ({
838
+ [i.tenantMode, i.selectorParam, i.baseDomain, z]
839
+ ), I = X(() => ({
802
840
  // Tenant info
803
- tenant: w,
804
- tenantSlug: g,
805
- isTenantLoading: f,
806
- tenantError: h,
841
+ tenant: S,
842
+ tenantSlug: p,
843
+ isTenantLoading: m,
844
+ tenantError: u,
807
845
  retryTenant: () => {
808
- g && q(g);
846
+ p && z(p);
809
847
  },
810
848
  // Settings
811
849
  settings: R,
812
850
  settingsSchema: E,
813
- isSettingsLoading: U,
814
- settingsError: u,
851
+ isSettingsLoading: q,
852
+ settingsError: d,
815
853
  // Actions
816
- refreshSettings: j,
817
- switchTenant: I,
854
+ refreshSettings: _,
855
+ switchTenant: M,
818
856
  // Validation
819
857
  validateSettings: v
820
858
  }), [
821
- w,
822
- g,
823
- f,
824
- h,
859
+ S,
860
+ p,
861
+ m,
862
+ u,
825
863
  R,
826
864
  E,
827
- U,
828
- u,
829
- j,
830
- I,
865
+ q,
866
+ d,
867
+ _,
868
+ M,
831
869
  v
832
870
  ]);
833
- return /* @__PURE__ */ n(be.Provider, { value: L, children: e });
871
+ return /* @__PURE__ */ n(Se.Provider, { value: I, children: e });
834
872
  }
835
- function fe() {
836
- const i = ce(be);
873
+ function me() {
874
+ const i = ce(Se);
837
875
  if (!i)
838
876
  throw new Error("useTenant must be used within a TenantProvider");
839
877
  return i;
840
878
  }
841
- function Pe() {
842
- return ce(be);
879
+ function Me() {
880
+ return ce(Se);
843
881
  }
844
- const Tt = fe;
845
- function Pt() {
846
- const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = fe();
882
+ const $t = me;
883
+ function Ft() {
884
+ const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = me();
847
885
  return {
848
886
  settings: i,
849
887
  settingsSchema: e,
@@ -853,7 +891,7 @@ function Pt() {
853
891
  };
854
892
  }
855
893
  function se() {
856
- const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = fe();
894
+ const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = me();
857
895
  return {
858
896
  tenant: i,
859
897
  tenantSlug: e,
@@ -862,273 +900,296 @@ function se() {
862
900
  retry: s
863
901
  };
864
902
  }
865
- const Me = he(null);
866
- function Mt({ config: i = {}, children: e }) {
867
- 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({
903
+ const Ie = he(null);
904
+ function Dt({ config: i = {}, children: e }) {
905
+ const { appId: t, baseUrl: r } = oe(), { tenant: s, tenantSlug: o, switchTenant: p } = me(), [b, k] = x(i.initialRoles || []), [S, T] = x(!i.initialRoles), [m, f] = x(null), [u, y] = x(!1), [R, C] = x(null), [q, A] = x(0), d = X(() => new we({
868
906
  tenantSlug: o,
869
907
  // SessionManager will generate storageKey internally
870
908
  onRefreshFailed: i.onRefreshFailed,
871
909
  baseUrl: r
872
- }), [o, r, i.onRefreshFailed]), M = Q(() => {
873
- const x = new re(r);
874
- return x.setSessionManager(u), x;
875
- }, [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(() => {
876
- const x = async (F = !1) => {
910
+ }), [o, r, i.onRefreshFailed]), P = X(() => {
911
+ const c = new re(r);
912
+ return c.setSessionManager(d), c;
913
+ }, [r, d]), E = X(() => new Ue(new re(r)), [r]), z = X(() => new qe(P, d), [P, d]), G = X(() => new xe(new re(r)), [r]), $ = X(() => m || d.getUser(), [m, d]), _ = X(() => $ != null && $.roleId && b.find((c) => c.id === $.roleId) || null, [$, b]), v = X(() => (_ == null ? void 0 : _.permissions) || [], [_]), M = X(() => d.hasValidSession() && m !== null, [d, m]), I = 5 * 60 * 1e3, a = X(() => {
914
+ const c = async (D = !1) => {
877
915
  try {
878
- if (!u.hasValidSession())
916
+ if (!d.hasValidSession())
879
917
  return;
880
- const N = Date.now();
881
- if (!F && N - U < L && f)
918
+ const B = Date.now();
919
+ if (!D && B - q < I && m)
882
920
  return;
883
- const W = u.getUserId();
921
+ const W = d.getUserId();
884
922
  if (!W) {
885
923
  console.warn("[AuthProvider] No userId available in token or storage");
886
924
  return;
887
925
  }
888
- m(!0), C(null);
889
- const X = await q.getUserById(W);
890
- p(X), u.setUser(X), P(Date.now());
891
- } catch (N) {
892
- const _ = N instanceof Error ? N : new Error("Failed to load user data");
893
- C(_), console.error("[AuthProvider] Failed to load user data:", _);
926
+ y(!0), C(null);
927
+ const Z = await z.getUserById(W);
928
+ f(Z), d.setUser(Z), A(Date.now());
929
+ } catch (B) {
930
+ const J = B instanceof Error ? B : new Error("Failed to load user data");
931
+ C(J), console.error("[AuthProvider] Failed to load user data:", J);
894
932
  } finally {
895
- m(!1);
933
+ y(!1);
896
934
  }
897
- }, b = async () => {
898
- await x();
899
- }, d = async (F) => {
900
- const { username: N, password: _, tenantSlug: W } = F;
901
- let X = s == null ? void 0 : s.id, Y = o, Z = u;
902
- W && (X = (await new ue(M, t).getPublicTenantInfo(W)).id, Y = W);
903
- const J = await E.login({
904
- username: N,
905
- password: _,
935
+ }, h = async () => {
936
+ await c();
937
+ }, g = async (D) => {
938
+ const { username: B, password: J, tenantSlug: W } = D;
939
+ let Z = s == null ? void 0 : s.id, Q = o, ee = d;
940
+ W && (Z = (await new ue(P, t).getPublicTenantInfo(W)).id, Q = W);
941
+ const V = await E.login({
942
+ username: B,
943
+ password: J,
906
944
  appId: t,
907
- tenantId: X
945
+ tenantId: Z
908
946
  }), le = W && W !== o;
909
- if (le && (Z = new ye({
910
- tenantSlug: Y,
947
+ if (le && (ee = new we({
948
+ tenantSlug: Q,
911
949
  baseUrl: r
912
- })), Z.setTokens({
913
- accessToken: J.accessToken,
914
- refreshToken: J.refreshToken,
915
- expiresIn: J.expiresIn
916
- }), J.user) {
917
- Z.setUser(J.user), p(J.user);
950
+ })), ee.setTokens({
951
+ accessToken: V.accessToken,
952
+ refreshToken: V.refreshToken,
953
+ expiresIn: V.expiresIn
954
+ }), V.user) {
955
+ ee.setUser(V.user), f(V.user);
918
956
  try {
919
- await x();
957
+ await c();
920
958
  } catch (de) {
921
959
  console.warn("Failed to load complete user data after login:", de);
922
960
  }
923
961
  }
924
- return le && Y && Y !== o && g(Y), J;
925
- }, c = async (F) => {
926
- const { email: N, phoneNumber: _, name: W, password: X, lastName: Y, tenantId: Z } = F;
927
- if (!N && !_)
962
+ return le && Q && Q !== o && p(Q, {
963
+ tokens: {
964
+ accessToken: V.accessToken,
965
+ refreshToken: V.refreshToken,
966
+ expiresIn: V.expiresIn
967
+ }
968
+ }), V;
969
+ }, w = async (D) => {
970
+ const { email: B, phoneNumber: J, name: W, password: Z, lastName: Q, tenantId: ee } = D;
971
+ if (!B && !J)
928
972
  throw new Error("Either email or phoneNumber is required");
929
- if (!W || !X)
973
+ if (!W || !Z)
930
974
  throw new Error("Name and password are required");
931
- const J = Z ?? (s == null ? void 0 : s.id);
975
+ const V = ee ?? (s == null ? void 0 : s.id);
932
976
  return await E.signup({
933
- email: N,
934
- phoneNumber: _,
977
+ email: B,
978
+ phoneNumber: J,
935
979
  name: W,
936
- password: X,
937
- tenantId: J,
938
- lastName: Y,
980
+ password: Z,
981
+ tenantId: V,
982
+ lastName: Q,
939
983
  appId: t
940
984
  });
941
- }, S = async (F) => {
942
- const { email: N, phoneNumber: _, name: W, password: X, tenantName: Y, lastName: Z } = F;
943
- if (!N && !_)
985
+ }, j = async (D) => {
986
+ const { email: B, phoneNumber: J, name: W, password: Z, tenantName: Q, lastName: ee } = D;
987
+ if (!B && !J)
944
988
  throw new Error("Either email or phoneNumber is required");
945
- if (!W || !X || !Y)
989
+ if (!W || !Z || !Q)
946
990
  throw new Error("Name, password, and tenantName are required");
947
991
  return await E.signupTenantAdmin({
948
- email: N,
949
- phoneNumber: _,
992
+ email: B,
993
+ phoneNumber: J,
950
994
  name: W,
951
- password: X,
952
- tenantName: Y,
995
+ password: Z,
996
+ tenantName: Q,
953
997
  appId: t,
954
- lastName: Z
998
+ lastName: ee
955
999
  });
956
- }, G = async (F) => {
957
- const { currentPassword: N, newPassword: _ } = F, W = await u.getAuthHeaders();
958
- await E.changePassword({ currentPassword: N, newPassword: _ }, W);
959
- }, ee = async (F) => {
960
- const { email: N, tenantId: _ } = F, W = _ ?? (s == null ? void 0 : s.id);
1000
+ }, Y = async (D) => {
1001
+ const { currentPassword: B, newPassword: J } = D, W = await d.getAuthHeaders();
1002
+ await E.changePassword({ currentPassword: B, newPassword: J }, W);
1003
+ }, H = async (D) => {
1004
+ const { email: B, tenantId: J } = D, W = J ?? (s == null ? void 0 : s.id);
961
1005
  if (!W)
962
1006
  throw new Error("tenantId is required for password reset");
963
- await E.requestPasswordReset({ email: N, tenantId: W });
964
- }, z = async (F) => {
965
- const { token: N, newPassword: _ } = F;
966
- await E.confirmPasswordReset({ token: N, newPassword: _ });
967
- }, H = async (F) => {
968
- const { email: N, frontendUrl: _, name: W, lastName: X, tenantId: Y } = F, Z = Y ?? (s == null ? void 0 : s.id);
969
- if (!Z)
1007
+ await E.requestPasswordReset({ email: B, tenantId: W });
1008
+ }, N = async (D) => {
1009
+ const { token: B, newPassword: J } = D;
1010
+ await E.confirmPasswordReset({ token: B, newPassword: J });
1011
+ }, O = async (D) => {
1012
+ const { email: B, frontendUrl: J, name: W, lastName: Z, tenantId: Q } = D, ee = Q ?? (s == null ? void 0 : s.id);
1013
+ if (!ee)
970
1014
  throw new Error("tenantId is required for magic link authentication");
971
1015
  return await E.sendMagicLink({
972
- email: N,
973
- tenantId: Z,
974
- frontendUrl: _,
1016
+ email: B,
1017
+ tenantId: ee,
1018
+ frontendUrl: J,
975
1019
  name: W,
976
- lastName: X,
1020
+ lastName: Z,
977
1021
  appId: t
978
1022
  });
979
- }, O = async (F) => {
980
- const { token: N, email: _, tenantSlug: W } = F;
981
- let X = s == null ? void 0 : s.id, Y = o, Z = u;
982
- W && (X = (await new ue(M, t).getPublicTenantInfo(W)).id, Y = W);
983
- const J = await E.verifyMagicLink({
984
- token: N,
985
- email: _,
1023
+ }, F = async (D) => {
1024
+ const { token: B, email: J, tenantSlug: W } = D;
1025
+ let Z = s == null ? void 0 : s.id, Q = o, ee = d;
1026
+ W && (Z = (await new ue(P, t).getPublicTenantInfo(W)).id, Q = W);
1027
+ const V = await E.verifyMagicLink({
1028
+ token: B,
1029
+ email: J,
986
1030
  appId: t,
987
- tenantId: X
1031
+ tenantId: Z
988
1032
  }), le = W && W !== o;
989
- if (le && (Z = new ye({
990
- tenantSlug: Y,
1033
+ if (le && (ee = new we({
1034
+ tenantSlug: Q,
991
1035
  baseUrl: r
992
- })), Z.setTokens({
993
- accessToken: J.accessToken,
994
- refreshToken: J.refreshToken,
995
- expiresIn: J.expiresIn
996
- }), J.user) {
997
- Z.setUser(J.user), p(J.user);
1036
+ })), ee.setTokens({
1037
+ accessToken: V.accessToken,
1038
+ refreshToken: V.refreshToken,
1039
+ expiresIn: V.expiresIn
1040
+ }), V.user) {
1041
+ ee.setUser(V.user), f(V.user);
998
1042
  try {
999
- await x();
1043
+ await c();
1000
1044
  } catch (de) {
1001
1045
  console.warn("Failed to load complete user data after magic link login:", de);
1002
1046
  }
1003
1047
  }
1004
- return le && Y && Y !== o && g(Y), J;
1005
- }, D = async () => {
1006
- const F = u.getTokens();
1007
- if (!(F != null && F.refreshToken))
1048
+ return le && Q && Q !== o && p(Q, {
1049
+ tokens: {
1050
+ accessToken: V.accessToken,
1051
+ refreshToken: V.refreshToken,
1052
+ expiresIn: V.expiresIn
1053
+ }
1054
+ }), V;
1055
+ }, K = async () => {
1056
+ const D = d.getTokens();
1057
+ if (!(D != null && D.refreshToken))
1008
1058
  throw new Error("No refresh token available");
1009
- const N = await E.refreshToken({
1010
- refreshToken: F.refreshToken
1059
+ const B = await E.refreshToken({
1060
+ refreshToken: D.refreshToken
1011
1061
  });
1012
- u.setTokens({
1013
- accessToken: N.accessToken,
1014
- refreshToken: N.refreshToken || F.refreshToken,
1015
- expiresIn: N.expiresIn
1062
+ d.setTokens({
1063
+ accessToken: B.accessToken,
1064
+ refreshToken: B.refreshToken || D.refreshToken,
1065
+ expiresIn: B.expiresIn
1016
1066
  });
1017
- }, K = () => {
1018
- u.clearSession(), p(null), C(null);
1019
- }, ge = (F) => {
1020
- u.setTokens(F);
1021
- }, Re = () => u.hasValidSession(), Ce = () => {
1022
- u.clearSession(), p(null), C(null);
1023
- }, $e = async () => {
1067
+ }, ge = () => {
1068
+ d.clearSession(), f(null), C(null);
1069
+ }, Ce = (D) => {
1070
+ d.setTokens(D);
1071
+ }, $e = () => d.hasValidSession(), Fe = () => {
1072
+ d.clearSession(), f(null), C(null);
1073
+ }, De = async () => {
1024
1074
  if (t)
1025
1075
  try {
1026
1076
  T(!0);
1027
- const { roles: F } = await V.getRolesByApp(t);
1028
- A(F);
1029
- } catch (F) {
1030
- console.error("Failed to fetch roles:", F);
1077
+ const { roles: D } = await G.getRolesByApp(t);
1078
+ k(D);
1079
+ } catch (D) {
1080
+ console.error("Failed to fetch roles:", D);
1031
1081
  } finally {
1032
1082
  T(!1);
1033
1083
  }
1034
- }, Fe = async () => {
1035
- await $e();
1036
- }, me = (F) => {
1084
+ }, He = async () => {
1085
+ await De();
1086
+ }, ye = (D) => {
1037
1087
  if (!v || v.length === 0)
1038
1088
  return !1;
1039
- if (typeof F == "string")
1040
- return v.includes(F);
1041
- const N = `${F.resource}.${F.action}`;
1042
- return v.includes(N);
1089
+ if (typeof D == "string")
1090
+ return v.includes(D);
1091
+ const B = `${D.resource}.${D.action}`;
1092
+ return v.includes(B);
1043
1093
  };
1044
1094
  return {
1045
1095
  // RFC-003: Authentication state
1046
- isAuthenticated: I,
1047
- sessionManager: u,
1048
- authenticatedHttpService: M,
1049
- login: d,
1050
- signup: c,
1051
- signupTenantAdmin: S,
1052
- sendMagicLink: H,
1053
- verifyMagicLink: O,
1054
- changePassword: G,
1055
- requestPasswordReset: ee,
1056
- confirmPasswordReset: z,
1057
- refreshToken: D,
1058
- logout: K,
1059
- setTokens: ge,
1060
- hasValidSession: Re,
1061
- clearSession: Ce,
1062
- currentUser: f,
1063
- isUserLoading: h,
1096
+ isAuthenticated: M,
1097
+ sessionManager: d,
1098
+ authenticatedHttpService: P,
1099
+ login: g,
1100
+ signup: w,
1101
+ signupTenantAdmin: j,
1102
+ sendMagicLink: O,
1103
+ verifyMagicLink: F,
1104
+ changePassword: Y,
1105
+ requestPasswordReset: H,
1106
+ confirmPasswordReset: N,
1107
+ refreshToken: K,
1108
+ logout: ge,
1109
+ setTokens: Ce,
1110
+ hasValidSession: $e,
1111
+ clearSession: Fe,
1112
+ currentUser: m,
1113
+ isUserLoading: u,
1064
1114
  userError: R,
1065
- loadUserData: x,
1066
- refreshUser: b,
1067
- userRole: j,
1115
+ loadUserData: c,
1116
+ refreshUser: h,
1117
+ userRole: _,
1068
1118
  userPermissions: v,
1069
- availableRoles: y,
1070
- rolesLoading: w,
1071
- hasPermission: me,
1072
- hasAnyPermission: (F) => F.some((N) => me(N)),
1073
- hasAllPermissions: (F) => F.every((N) => me(N)),
1119
+ availableRoles: b,
1120
+ rolesLoading: S,
1121
+ hasPermission: ye,
1122
+ hasAnyPermission: (D) => D.some((B) => ye(B)),
1123
+ hasAllPermissions: (D) => D.every((B) => ye(B)),
1074
1124
  getUserPermissionStrings: () => v || [],
1075
- refreshRoles: Fe
1125
+ refreshRoles: He
1076
1126
  };
1077
1127
  }, [
1078
- I,
1079
- u,
1080
1128
  M,
1129
+ d,
1130
+ P,
1081
1131
  E,
1082
- q,
1083
- V,
1132
+ z,
1133
+ G,
1084
1134
  t,
1085
1135
  s,
1086
1136
  o,
1087
- g,
1088
- y,
1089
- f,
1090
- h,
1137
+ p,
1138
+ b,
1139
+ m,
1140
+ u,
1091
1141
  R,
1092
- j,
1142
+ _,
1093
1143
  v,
1094
- U,
1095
- L
1144
+ q,
1145
+ I
1096
1146
  ]);
1097
- return te(() => {
1147
+ te(() => {
1098
1148
  !i.initialRoles && t && (async () => {
1099
1149
  try {
1100
1150
  T(!0);
1101
- const b = new re(r), d = new ve(b), { roles: c } = await d.getRolesByApp(t);
1102
- A(c);
1103
- } catch (b) {
1104
- console.error("Failed to fetch roles:", b);
1151
+ const h = new re(r), g = new xe(h), { roles: w } = await g.getRolesByApp(t);
1152
+ k(w);
1153
+ } catch (h) {
1154
+ console.error("Failed to fetch roles:", h);
1105
1155
  } finally {
1106
1156
  T(!1);
1107
1157
  }
1108
1158
  })();
1109
- }, [t, r, i.initialRoles]), te(() => {
1110
- const x = u.getUser();
1111
- x && u.hasValidSession() && p(x);
1112
- }, [u]), te(() => {
1113
- !f && !h && l.loadUserData().catch(() => {
1159
+ }, [t, r, i.initialRoles]);
1160
+ const L = Be(!1);
1161
+ return te(() => {
1162
+ if (L.current) return;
1163
+ const c = Ge();
1164
+ c && (L.current = !0, d.setTokens({
1165
+ accessToken: c.accessToken,
1166
+ refreshToken: c.refreshToken,
1167
+ expiresIn: c.expiresIn
1168
+ }), Ke(), a.loadUserData().catch(() => {
1169
+ }));
1170
+ }, [d, a]), te(() => {
1171
+ const c = d.getUser();
1172
+ c && d.hasValidSession() && f(c);
1173
+ }, [d]), te(() => {
1174
+ !m && !u && a.loadUserData().catch(() => {
1114
1175
  });
1115
- }, [f, h, l]), te(() => {
1116
- if (!u.hasValidSession() || !f)
1176
+ }, [m, u, a]), te(() => {
1177
+ if (!d.hasValidSession() || !m)
1117
1178
  return;
1118
- const x = setInterval(() => {
1119
- l.loadUserData().catch(() => {
1179
+ const c = setInterval(() => {
1180
+ a.loadUserData().catch(() => {
1120
1181
  });
1121
- }, L);
1122
- return () => clearInterval(x);
1123
- }, [u, f, l, L]), /* @__PURE__ */ n(Me.Provider, { value: l, children: e });
1182
+ }, I);
1183
+ return () => clearInterval(c);
1184
+ }, [d, m, a, I]), /* @__PURE__ */ n(Ie.Provider, { value: a, children: e });
1124
1185
  }
1125
1186
  function ae() {
1126
- const i = ce(Me);
1187
+ const i = ce(Ie);
1127
1188
  if (!i)
1128
1189
  throw new Error("useAuth must be used within an AuthProvider");
1129
1190
  return i;
1130
1191
  }
1131
- class ze {
1192
+ class Je {
1132
1193
  constructor(e, t) {
1133
1194
  this.httpService = e, this.sessionManager = t;
1134
1195
  }
@@ -1208,58 +1269,58 @@ class ze {
1208
1269
  })).data;
1209
1270
  }
1210
1271
  }
1211
- const Ie = he(null);
1212
- function It({ config: i = {}, children: e }) {
1213
- const { baseUrl: t, appId: r } = oe(), { tenant: s } = se(), [o, g] = k([]), [y, A] = k(!1), [w, T] = k(null), f = Q(() => {
1214
- const m = new re(t);
1215
- return new ze(m);
1216
- }, [t]), p = async () => {
1272
+ const Le = he(null);
1273
+ function Ht({ config: i = {}, children: e }) {
1274
+ const { baseUrl: t, appId: r } = oe(), { tenant: s } = se(), [o, p] = x([]), [b, k] = x(!1), [S, T] = x(null), m = X(() => {
1275
+ const y = new re(t);
1276
+ return new Je(y);
1277
+ }, [t]), f = async () => {
1217
1278
  if (!(s != null && s.id)) {
1218
- g([]);
1279
+ p([]);
1219
1280
  return;
1220
1281
  }
1221
- A(!0), T(null);
1282
+ k(!0), T(null);
1222
1283
  try {
1223
- const m = await f.getTenantFeatureFlags(s.id, r);
1224
- g(m);
1225
- } catch (m) {
1226
- const R = m instanceof Error ? m.message : "Failed to fetch feature flags";
1227
- T(R), i.onError && i.onError(m instanceof Error ? m : new Error(R));
1284
+ const y = await m.getTenantFeatureFlags(s.id, r);
1285
+ p(y);
1286
+ } catch (y) {
1287
+ const R = y instanceof Error ? y.message : "Failed to fetch feature flags";
1288
+ T(R), i.onError && i.onError(y instanceof Error ? y : new Error(R));
1228
1289
  } finally {
1229
- A(!1);
1290
+ k(!1);
1230
1291
  }
1231
1292
  };
1232
1293
  te(() => {
1233
- p();
1234
- const m = i.refreshInterval || 5 * 60 * 1e3, R = setInterval(p, m);
1294
+ f();
1295
+ const y = i.refreshInterval || 5 * 60 * 1e3, R = setInterval(f, y);
1235
1296
  return () => clearInterval(R);
1236
1297
  }, [s == null ? void 0 : s.id, i.refreshInterval]);
1237
- const h = Q(() => ({
1298
+ const u = X(() => ({
1238
1299
  featureFlags: o,
1239
- loading: y,
1240
- error: w,
1241
- isEnabled: (P) => {
1242
- const u = o.find((M) => M.key === P);
1243
- return (u == null ? void 0 : u.value) === !0;
1300
+ loading: b,
1301
+ error: S,
1302
+ isEnabled: (A) => {
1303
+ const d = o.find((P) => P.key === A);
1304
+ return (d == null ? void 0 : d.value) === !0;
1244
1305
  },
1245
- getFlag: (P) => o.find((u) => u.key === P),
1246
- getFlagState: (P) => {
1247
- const u = o.find((M) => M.key === P);
1248
- return u ? u.value ? "enabled" : "disabled" : "not_found";
1306
+ getFlag: (A) => o.find((d) => d.key === A),
1307
+ getFlagState: (A) => {
1308
+ const d = o.find((P) => P.key === A);
1309
+ return d ? d.value ? "enabled" : "disabled" : "not_found";
1249
1310
  },
1250
1311
  refresh: async () => {
1251
- await p();
1312
+ await f();
1252
1313
  }
1253
- }), [o, y, w]);
1254
- return /* @__PURE__ */ n(Ie.Provider, { value: h, children: e });
1314
+ }), [o, b, S]);
1315
+ return /* @__PURE__ */ n(Le.Provider, { value: u, children: e });
1255
1316
  }
1256
- function Oe() {
1257
- const i = ce(Ie);
1317
+ function Ye() {
1318
+ const i = ce(Le);
1258
1319
  if (!i)
1259
1320
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1260
1321
  return i;
1261
1322
  }
1262
- class We {
1323
+ class Qe {
1263
1324
  constructor(e, t) {
1264
1325
  this.httpService = e, this.sessionManager = t;
1265
1326
  }
@@ -1325,64 +1386,64 @@ class We {
1325
1386
  )).data;
1326
1387
  }
1327
1388
  }
1328
- const Le = he(void 0);
1329
- function Lt({ config: i = {}, children: e }) {
1330
- const { baseUrl: t } = oe(), { tenant: r } = se(), [s, o] = k(null), [g, y] = k(!1), [A, w] = k(null), T = Q(() => {
1331
- const h = new re(t);
1332
- return new We(h);
1333
- }, [t]), f = async () => {
1389
+ const Ee = he(void 0);
1390
+ function Nt({ config: i = {}, children: e }) {
1391
+ const { baseUrl: t } = oe(), { tenant: r } = se(), [s, o] = x(null), [p, b] = x(!1), [k, S] = x(null), T = X(() => {
1392
+ const u = new re(t);
1393
+ return new Qe(u);
1394
+ }, [t]), m = async () => {
1334
1395
  if (!(r != null && r.id)) {
1335
1396
  o(null);
1336
1397
  return;
1337
1398
  }
1338
- y(!0), w(null);
1399
+ b(!0), S(null);
1339
1400
  try {
1340
- const h = await T.getTenantSubscriptionFeatures(r.id);
1341
- o(h);
1342
- } catch (h) {
1343
- const m = h instanceof Error ? h.message : "Failed to fetch subscription";
1344
- w(m), i.onError && i.onError(h instanceof Error ? h : new Error(m));
1401
+ const u = await T.getTenantSubscriptionFeatures(r.id);
1402
+ o(u);
1403
+ } catch (u) {
1404
+ const y = u instanceof Error ? u.message : "Failed to fetch subscription";
1405
+ S(y), i.onError && i.onError(u instanceof Error ? u : new Error(y));
1345
1406
  } finally {
1346
- y(!1);
1407
+ b(!1);
1347
1408
  }
1348
1409
  };
1349
1410
  te(() => {
1350
- if (f(), !i.refreshInterval) return;
1351
- const h = i.refreshInterval || 10 * 60 * 1e3, m = setInterval(f, h);
1352
- return () => clearInterval(m);
1411
+ if (m(), !i.refreshInterval) return;
1412
+ const u = i.refreshInterval || 10 * 60 * 1e3, y = setInterval(m, u);
1413
+ return () => clearInterval(y);
1353
1414
  }, [r == null ? void 0 : r.id, i.refreshInterval]);
1354
- const p = Q(() => {
1355
- const h = (s == null ? void 0 : s.features) || [];
1415
+ const f = X(() => {
1416
+ const u = (s == null ? void 0 : s.features) || [];
1356
1417
  return {
1357
1418
  subscription: s,
1358
- features: h,
1359
- loading: g,
1360
- error: A,
1361
- isFeatureEnabled: (u) => {
1362
- const M = h.find((E) => E.key === u);
1363
- return M ? M.type === "BOOLEAN" || M.type === "boolean" ? M.value === !0 : !!M.value : !1;
1419
+ features: u,
1420
+ loading: p,
1421
+ error: k,
1422
+ isFeatureEnabled: (d) => {
1423
+ const P = u.find((E) => E.key === d);
1424
+ return P ? P.type === "BOOLEAN" || P.type === "boolean" ? P.value === !0 : !!P.value : !1;
1364
1425
  },
1365
- getFeature: (u) => h.find((M) => M.key === u),
1366
- getFeatureValue: (u, M) => {
1367
- const E = h.find((q) => q.key === u);
1368
- return E ? E.value : M;
1426
+ getFeature: (d) => u.find((P) => P.key === d),
1427
+ getFeatureValue: (d, P) => {
1428
+ const E = u.find((z) => z.key === d);
1429
+ return E ? E.value : P;
1369
1430
  },
1370
- hasAllowedPlan: (u) => !s || !s.isActive ? !1 : u.includes(s.planId),
1431
+ hasAllowedPlan: (d) => !s || !s.isActive ? !1 : d.includes(s.planId),
1371
1432
  refresh: async () => {
1372
- await f();
1433
+ await m();
1373
1434
  }
1374
1435
  };
1375
- }, [s, g, A]);
1376
- return /* @__PURE__ */ n(Le.Provider, { value: p, children: e });
1436
+ }, [s, p, k]);
1437
+ return /* @__PURE__ */ n(Ee.Provider, { value: f, children: e });
1377
1438
  }
1378
- function je() {
1379
- const i = ce(Le);
1439
+ function Xe() {
1440
+ const i = ce(Ee);
1380
1441
  if (i === void 0)
1381
1442
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1382
1443
  return i;
1383
1444
  }
1384
1445
  var ie = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(ie || {});
1385
- const xe = () => /* @__PURE__ */ a(
1446
+ const ke = () => /* @__PURE__ */ l(
1386
1447
  "div",
1387
1448
  {
1388
1449
  style: {
@@ -1419,11 +1480,11 @@ const xe = () => /* @__PURE__ */ a(
1419
1480
  )
1420
1481
  ]
1421
1482
  }
1422
- ), ke = ({
1483
+ ), Te = ({
1423
1484
  userType: i,
1424
1485
  minUserType: e,
1425
1486
  missingPermissions: t
1426
- }) => /* @__PURE__ */ a(
1487
+ }) => /* @__PURE__ */ l(
1427
1488
  "div",
1428
1489
  {
1429
1490
  style: {
@@ -1441,26 +1502,26 @@ const xe = () => /* @__PURE__ */ a(
1441
1502
  children: [
1442
1503
  /* @__PURE__ */ n("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1443
1504
  /* @__PURE__ */ n("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1444
- e && i ? /* @__PURE__ */ a(B, { children: [
1445
- /* @__PURE__ */ a("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1505
+ e && i ? /* @__PURE__ */ l(U, { children: [
1506
+ /* @__PURE__ */ l("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1446
1507
  "This content requires ",
1447
1508
  /* @__PURE__ */ n("strong", { children: e }),
1448
1509
  " access level or higher."
1449
1510
  ] }),
1450
- /* @__PURE__ */ a("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1511
+ /* @__PURE__ */ l("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1451
1512
  "Your current access level: ",
1452
1513
  /* @__PURE__ */ n("strong", { children: i })
1453
1514
  ] })
1454
- ] }) : /* @__PURE__ */ a(B, { children: [
1515
+ ] }) : /* @__PURE__ */ l(U, { children: [
1455
1516
  /* @__PURE__ */ n("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1456
- t && t.length > 0 && /* @__PURE__ */ a("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1517
+ t && t.length > 0 && /* @__PURE__ */ l("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1457
1518
  "Required permissions: ",
1458
1519
  /* @__PURE__ */ n("strong", { children: t.join(", ") })
1459
1520
  ] })
1460
1521
  ] })
1461
1522
  ]
1462
1523
  }
1463
- ), Ve = (i, e) => {
1524
+ ), Ze = (i, e) => {
1464
1525
  const t = {
1465
1526
  [ie.USER]: 1,
1466
1527
  [ie.TENANT_ADMIN]: 2,
@@ -1468,28 +1529,28 @@ const xe = () => /* @__PURE__ */ a(
1468
1529
  };
1469
1530
  return t[i] >= t[e];
1470
1531
  };
1471
- function Et({
1532
+ function Bt({
1472
1533
  children: i,
1473
1534
  fallback: e,
1474
1535
  minUserType: t,
1475
1536
  requiredPermissions: r,
1476
1537
  requireAllPermissions: s = !1
1477
1538
  }) {
1478
- const { hasValidSession: o, sessionManager: g, hasPermission: y, hasAnyPermission: A, hasAllPermissions: w } = ae();
1539
+ const { hasValidSession: o, sessionManager: p, hasPermission: b, hasAnyPermission: k, hasAllPermissions: S } = ae();
1479
1540
  if (!o())
1480
- return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(xe, {}) });
1481
- const T = g.getUser();
1541
+ return /* @__PURE__ */ n(U, { children: e || /* @__PURE__ */ n(ke, {}) });
1542
+ const T = p.getUser();
1482
1543
  if (!T)
1483
- return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(xe, {}) });
1484
- if (t && !Ve(T.userType, t))
1485
- return /* @__PURE__ */ n(ke, { userType: T.userType, minUserType: t });
1486
- if (r && r.length > 0 && !(s ? w(r) : A(r))) {
1487
- const p = r.filter((h) => !y(h)).map((h) => typeof h == "string" ? h : h.name);
1488
- return /* @__PURE__ */ n(ke, { missingPermissions: p });
1489
- }
1490
- return /* @__PURE__ */ n(B, { children: i });
1544
+ return /* @__PURE__ */ n(U, { children: e || /* @__PURE__ */ n(ke, {}) });
1545
+ if (t && !Ze(T.userType, t))
1546
+ return /* @__PURE__ */ n(Te, { userType: T.userType, minUserType: t });
1547
+ if (r && r.length > 0 && !(s ? S(r) : k(r))) {
1548
+ const f = r.filter((u) => !b(u)).map((u) => typeof u == "string" ? u : u.name);
1549
+ return /* @__PURE__ */ n(Te, { missingPermissions: f });
1550
+ }
1551
+ return /* @__PURE__ */ n(U, { children: i });
1491
1552
  }
1492
- const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1553
+ const et = ({ redirectPath: i }) => /* @__PURE__ */ n(
1493
1554
  "div",
1494
1555
  {
1495
1556
  style: {
@@ -1502,7 +1563,7 @@ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1502
1563
  backgroundColor: "#f9fafb",
1503
1564
  textAlign: "center"
1504
1565
  },
1505
- children: /* @__PURE__ */ a(
1566
+ children: /* @__PURE__ */ l(
1506
1567
  "div",
1507
1568
  {
1508
1569
  style: {
@@ -1516,7 +1577,7 @@ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1516
1577
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1517
1578
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1518
1579
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1519
- /* @__PURE__ */ a("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1580
+ /* @__PURE__ */ l("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1520
1581
  "Redirecting to ",
1521
1582
  i,
1522
1583
  "..."
@@ -1542,7 +1603,7 @@ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1542
1603
  backgroundColor: "#f9fafb",
1543
1604
  textAlign: "center"
1544
1605
  },
1545
- children: /* @__PURE__ */ a(
1606
+ children: /* @__PURE__ */ l(
1546
1607
  "div",
1547
1608
  {
1548
1609
  style: {
@@ -1555,19 +1616,19 @@ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1555
1616
  children: [
1556
1617
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1557
1618
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1558
- e && i ? /* @__PURE__ */ a(B, { children: [
1559
- /* @__PURE__ */ a("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1619
+ e && i ? /* @__PURE__ */ l(U, { children: [
1620
+ /* @__PURE__ */ l("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1560
1621
  "This page requires ",
1561
1622
  /* @__PURE__ */ n("strong", { children: e }),
1562
1623
  " access level or higher."
1563
1624
  ] }),
1564
- /* @__PURE__ */ a("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1625
+ /* @__PURE__ */ l("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1565
1626
  "Your current access level: ",
1566
1627
  /* @__PURE__ */ n("strong", { children: i })
1567
1628
  ] })
1568
- ] }) : /* @__PURE__ */ a(B, { children: [
1629
+ ] }) : /* @__PURE__ */ l(U, { children: [
1569
1630
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1570
- t && t.length > 0 && /* @__PURE__ */ a("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1631
+ t && t.length > 0 && /* @__PURE__ */ l("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1571
1632
  "Required permissions: ",
1572
1633
  /* @__PURE__ */ n("strong", { children: t.join(", ") })
1573
1634
  ] })
@@ -1576,7 +1637,7 @@ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1576
1637
  }
1577
1638
  )
1578
1639
  }
1579
- ), _e = (i, e) => {
1640
+ ), tt = (i, e) => {
1580
1641
  const t = {
1581
1642
  [ie.USER]: 1,
1582
1643
  [ie.TENANT_ADMIN]: 2,
@@ -1584,7 +1645,7 @@ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1584
1645
  };
1585
1646
  return t[i] >= t[e];
1586
1647
  };
1587
- function Rt({
1648
+ function Ut({
1588
1649
  children: i,
1589
1650
  redirectTo: e = "/login",
1590
1651
  minUserType: t,
@@ -1592,24 +1653,24 @@ function Rt({
1592
1653
  requireAllPermissions: s = !1,
1593
1654
  fallback: o
1594
1655
  }) {
1595
- const { hasValidSession: g, sessionManager: y, hasPermission: A, hasAnyPermission: w, hasAllPermissions: T } = ae(), f = we();
1596
- if (!g())
1597
- return o ? /* @__PURE__ */ n(B, { children: o }) : /* @__PURE__ */ a(B, { children: [
1598
- /* @__PURE__ */ n(Ge, { redirectPath: e }),
1599
- /* @__PURE__ */ n(pe, { to: e, state: { from: f.pathname }, replace: !0 })
1656
+ const { hasValidSession: p, sessionManager: b, hasPermission: k, hasAnyPermission: S, hasAllPermissions: T } = ae(), m = be();
1657
+ if (!p())
1658
+ return o ? /* @__PURE__ */ n(U, { children: o }) : /* @__PURE__ */ l(U, { children: [
1659
+ /* @__PURE__ */ n(et, { redirectPath: e }),
1660
+ /* @__PURE__ */ n(pe, { to: e, state: { from: m.pathname }, replace: !0 })
1600
1661
  ] });
1601
- const p = y.getUser();
1602
- if (!p)
1603
- return /* @__PURE__ */ n(pe, { to: e, state: { from: f.pathname }, replace: !0 });
1604
- if (t && !_e(p.userType, t))
1605
- return /* @__PURE__ */ n(Ae, { userType: p.userType, minUserType: t });
1606
- if (r && r.length > 0 && !(s ? T(r) : w(r))) {
1607
- const m = r.filter((R) => !A(R)).map((R) => typeof R == "string" ? R : R.name);
1608
- return /* @__PURE__ */ n(Ae, { missingPermissions: m });
1609
- }
1610
- return /* @__PURE__ */ n(B, { children: i });
1662
+ const f = b.getUser();
1663
+ if (!f)
1664
+ return /* @__PURE__ */ n(pe, { to: e, state: { from: m.pathname }, replace: !0 });
1665
+ if (t && !tt(f.userType, t))
1666
+ return /* @__PURE__ */ n(Ae, { userType: f.userType, minUserType: t });
1667
+ if (r && r.length > 0 && !(s ? T(r) : S(r))) {
1668
+ const y = r.filter((R) => !k(R)).map((R) => typeof R == "string" ? R : R.name);
1669
+ return /* @__PURE__ */ n(Ae, { missingPermissions: y });
1670
+ }
1671
+ return /* @__PURE__ */ n(U, { children: i });
1611
1672
  }
1612
- const Ke = ({ redirectPath: i }) => /* @__PURE__ */ n(
1673
+ const rt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1613
1674
  "div",
1614
1675
  {
1615
1676
  style: {
@@ -1622,7 +1683,7 @@ const Ke = ({ redirectPath: i }) => /* @__PURE__ */ n(
1622
1683
  backgroundColor: "#f9fafb",
1623
1684
  textAlign: "center"
1624
1685
  },
1625
- children: /* @__PURE__ */ a(
1686
+ children: /* @__PURE__ */ l(
1626
1687
  "div",
1627
1688
  {
1628
1689
  style: {
@@ -1636,7 +1697,7 @@ const Ke = ({ redirectPath: i }) => /* @__PURE__ */ n(
1636
1697
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
1637
1698
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
1638
1699
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
1639
- /* @__PURE__ */ a("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1700
+ /* @__PURE__ */ l("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1640
1701
  "Redirecting to ",
1641
1702
  i,
1642
1703
  "..."
@@ -1646,14 +1707,14 @@ const Ke = ({ redirectPath: i }) => /* @__PURE__ */ n(
1646
1707
  )
1647
1708
  }
1648
1709
  );
1649
- function Ct({ children: i, redirectTo: e = "/", fallback: t }) {
1650
- const { tenant: r, isLoading: s, error: o } = se(), g = we();
1651
- return s || o ? null : r ? /* @__PURE__ */ n(B, { children: i }) : t ? /* @__PURE__ */ n(B, { children: t }) : /* @__PURE__ */ a(B, { children: [
1652
- /* @__PURE__ */ n(Ke, { redirectPath: e }),
1653
- /* @__PURE__ */ n(pe, { to: e, state: { from: g.pathname }, replace: !0 })
1710
+ function qt({ children: i, redirectTo: e = "/", fallback: t }) {
1711
+ const { tenant: r, isLoading: s, error: o } = se(), p = be();
1712
+ return s || o ? null : r ? /* @__PURE__ */ n(U, { children: i }) : t ? /* @__PURE__ */ n(U, { children: t }) : /* @__PURE__ */ l(U, { children: [
1713
+ /* @__PURE__ */ n(rt, { redirectPath: e }),
1714
+ /* @__PURE__ */ n(pe, { to: e, state: { from: p.pathname }, replace: !0 })
1654
1715
  ] });
1655
1716
  }
1656
- const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1717
+ const nt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1657
1718
  "div",
1658
1719
  {
1659
1720
  style: {
@@ -1666,7 +1727,7 @@ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1666
1727
  backgroundColor: "#f9fafb",
1667
1728
  textAlign: "center"
1668
1729
  },
1669
- children: /* @__PURE__ */ a(
1730
+ children: /* @__PURE__ */ l(
1670
1731
  "div",
1671
1732
  {
1672
1733
  style: {
@@ -1680,7 +1741,7 @@ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1680
1741
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
1681
1742
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
1682
1743
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
1683
- /* @__PURE__ */ a("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1744
+ /* @__PURE__ */ l("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1684
1745
  "Redirecting to ",
1685
1746
  i,
1686
1747
  "..."
@@ -1690,14 +1751,14 @@ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1690
1751
  )
1691
1752
  }
1692
1753
  );
1693
- function $t({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1694
- const { tenant: r, isLoading: s, error: o } = se(), g = we();
1695
- return s || o ? null : r ? t ? /* @__PURE__ */ n(B, { children: t }) : /* @__PURE__ */ a(B, { children: [
1696
- /* @__PURE__ */ n(Je, { redirectPath: e }),
1697
- /* @__PURE__ */ n(pe, { to: e, state: { from: g.pathname }, replace: !0 })
1698
- ] }) : /* @__PURE__ */ n(B, { children: i });
1754
+ function zt({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1755
+ const { tenant: r, isLoading: s, error: o } = se(), p = be();
1756
+ return s || o ? null : r ? t ? /* @__PURE__ */ n(U, { children: t }) : /* @__PURE__ */ l(U, { children: [
1757
+ /* @__PURE__ */ n(nt, { redirectPath: e }),
1758
+ /* @__PURE__ */ n(pe, { to: e, state: { from: p.pathname }, replace: !0 })
1759
+ ] }) : /* @__PURE__ */ n(U, { children: i });
1699
1760
  }
1700
- const Ye = () => /* @__PURE__ */ a(
1761
+ const st = () => /* @__PURE__ */ l(
1701
1762
  "div",
1702
1763
  {
1703
1764
  style: {
@@ -1714,14 +1775,14 @@ const Ye = () => /* @__PURE__ */ a(
1714
1775
  ]
1715
1776
  }
1716
1777
  );
1717
- function Ft({
1778
+ function Ot({
1718
1779
  children: i,
1719
- fallback: e = /* @__PURE__ */ n(Ye, {}),
1780
+ fallback: e = /* @__PURE__ */ n(st, {}),
1720
1781
  allowedPlans: t,
1721
1782
  requiredFeature: r
1722
1783
  }) {
1723
- const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: g, loading: y } = je();
1724
- return y ? /* @__PURE__ */ n(
1784
+ const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: p, loading: b } = Xe();
1785
+ return b ? /* @__PURE__ */ n(
1725
1786
  "div",
1726
1787
  {
1727
1788
  style: {
@@ -1731,9 +1792,9 @@ function Ft({
1731
1792
  },
1732
1793
  children: "Loading subscription..."
1733
1794
  }
1734
- ) : 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 });
1795
+ ) : s ? s.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ n(U, { children: e }) : r && !p(r) ? /* @__PURE__ */ n(U, { children: e }) : /* @__PURE__ */ n(U, { children: i }) : /* @__PURE__ */ n(U, { children: e }) : /* @__PURE__ */ n(U, { children: e });
1735
1796
  }
1736
- const Qe = ({ flagName: i }) => /* @__PURE__ */ a(
1797
+ const it = ({ flagName: i }) => /* @__PURE__ */ l(
1737
1798
  "div",
1738
1799
  {
1739
1800
  style: {
@@ -1752,7 +1813,7 @@ const Qe = ({ flagName: i }) => /* @__PURE__ */ a(
1752
1813
  children: [
1753
1814
  /* @__PURE__ */ n("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
1754
1815
  /* @__PURE__ */ n("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
1755
- /* @__PURE__ */ a("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
1816
+ /* @__PURE__ */ l("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
1756
1817
  'Feature flag "',
1757
1818
  i,
1758
1819
  '" is disabled'
@@ -1760,8 +1821,8 @@ const Qe = ({ flagName: i }) => /* @__PURE__ */ a(
1760
1821
  ]
1761
1822
  }
1762
1823
  );
1763
- function Dt({ name: i, children: e, fallback: t }) {
1764
- const { isEnabled: r, loading: s } = Oe();
1824
+ function Wt({ name: i, children: e, fallback: t }) {
1825
+ const { isEnabled: r, loading: s } = Ye();
1765
1826
  return s ? /* @__PURE__ */ n(
1766
1827
  "div",
1767
1828
  {
@@ -1775,9 +1836,9 @@ function Dt({ name: i, children: e, fallback: t }) {
1775
1836
  },
1776
1837
  children: "Loading feature flags..."
1777
1838
  }
1778
- ) : r(i) ? /* @__PURE__ */ n(B, { children: e }) : /* @__PURE__ */ n(B, { children: t || /* @__PURE__ */ n(Qe, { flagName: i }) });
1839
+ ) : r(i) ? /* @__PURE__ */ n(U, { children: e }) : /* @__PURE__ */ n(U, { children: t || /* @__PURE__ */ n(it, { flagName: i }) });
1779
1840
  }
1780
- const Xe = () => /* @__PURE__ */ a(
1841
+ const ot = () => /* @__PURE__ */ l(
1781
1842
  "svg",
1782
1843
  {
1783
1844
  width: "16",
@@ -1794,7 +1855,7 @@ const Xe = () => /* @__PURE__ */ a(
1794
1855
  /* @__PURE__ */ n("circle", { cx: "12", cy: "12", r: "3" })
1795
1856
  ]
1796
1857
  }
1797
- ), Ze = () => /* @__PURE__ */ a(
1858
+ ), at = () => /* @__PURE__ */ l(
1798
1859
  "svg",
1799
1860
  {
1800
1861
  width: "16",
@@ -1811,10 +1872,10 @@ const Xe = () => /* @__PURE__ */ a(
1811
1872
  /* @__PURE__ */ n("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
1812
1873
  ]
1813
1874
  }
1814
- ), et = {
1815
- showPassword: /* @__PURE__ */ n(Xe, {}),
1816
- hidePassword: /* @__PURE__ */ n(Ze, {})
1817
- }, tt = {
1875
+ ), lt = {
1876
+ showPassword: /* @__PURE__ */ n(ot, {}),
1877
+ hidePassword: /* @__PURE__ */ n(at, {})
1878
+ }, ct = {
1818
1879
  title: "Sign In",
1819
1880
  usernameLabel: "Email or Phone",
1820
1881
  usernamePlaceholder: "Enter your email or phone number",
@@ -1828,7 +1889,7 @@ const Xe = () => /* @__PURE__ */ a(
1828
1889
  magicLinkLink: "Use Magic Link",
1829
1890
  errorMessage: "Invalid credentials",
1830
1891
  loadingText: "Signing in..."
1831
- }, rt = {
1892
+ }, dt = {
1832
1893
  container: {
1833
1894
  maxWidth: "400px",
1834
1895
  width: "100%",
@@ -1935,133 +1996,133 @@ const Xe = () => /* @__PURE__ */ a(
1935
1996
  fontSize: "0.875rem"
1936
1997
  }
1937
1998
  };
1938
- function Ht({
1999
+ function jt({
1939
2000
  copy: i = {},
1940
2001
  styles: e = {},
1941
2002
  icons: t = {},
1942
2003
  onSuccess: r,
1943
2004
  onError: s,
1944
2005
  onForgotPassword: o,
1945
- onSignupClick: g,
1946
- onMagicLinkClick: y,
1947
- showForgotPassword: A = !0,
1948
- showSignupLink: w = !0,
2006
+ onSignupClick: p,
2007
+ onMagicLinkClick: b,
2008
+ showForgotPassword: k = !0,
2009
+ showSignupLink: S = !0,
1949
2010
  showMagicLinkOption: T = !0,
1950
- className: f
2011
+ className: m
1951
2012
  }) {
1952
- 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 = { ...tt, ...i }, I = { ...rt, ...e }, L = { ...et, ...t }, l = () => {
1953
- const c = {};
1954
- return p.trim() || (c.username = !0), m.trim() || (c.password = !0), V(c), Object.keys(c).length === 0;
1955
- }, x = async (c) => {
1956
- if (c.preventDefault(), !!l()) {
1957
- if (!(j != null && j.id)) {
2013
+ const [f, u] = x(""), [y, R] = x(""), [C, q] = x(!1), [A, d] = x(!1), [P, E] = x(""), [z, G] = x({}), { login: $ } = ae(), { tenant: _ } = se(), v = { ...ct, ...i }, M = { ...dt, ...e }, I = { ...lt, ...t }, a = () => {
2014
+ const g = {};
2015
+ return f.trim() || (g.username = !0), y.trim() || (g.password = !0), G(g), Object.keys(g).length === 0;
2016
+ }, L = async (g) => {
2017
+ if (g.preventDefault(), !!a()) {
2018
+ if (!(_ != null && _.id)) {
1958
2019
  E("Tenant not found");
1959
2020
  return;
1960
2021
  }
1961
- u(!0), E("");
2022
+ d(!0), E("");
1962
2023
  try {
1963
- const S = await $({
1964
- username: p,
1965
- password: m
2024
+ const w = await $({
2025
+ username: f,
2026
+ password: y
1966
2027
  // tenantId inferred from context automatically
1967
2028
  });
1968
- r == null || r(S);
1969
- } catch (S) {
1970
- const G = S.message || v.errorMessage;
1971
- E(G), s == null || s(G);
2029
+ r == null || r(w);
2030
+ } catch (w) {
2031
+ const j = w.message || v.errorMessage;
2032
+ E(j), s == null || s(j);
1972
2033
  } finally {
1973
- u(!1);
2034
+ d(!1);
1974
2035
  }
1975
2036
  }
1976
- }, b = (c) => ({
1977
- ...I.input,
1978
- ...q[c] ? I.inputError : {}
1979
- }), d = () => ({
1980
- ...I.button,
1981
- ...P ? I.buttonLoading : {},
1982
- ...!p || !m || P ? I.buttonDisabled : {}
2037
+ }, c = (g) => ({
2038
+ ...M.input,
2039
+ ...z[g] ? M.inputError : {}
2040
+ }), h = () => ({
2041
+ ...M.button,
2042
+ ...A ? M.buttonLoading : {},
2043
+ ...!f || !y || A ? M.buttonDisabled : {}
1983
2044
  });
1984
- return /* @__PURE__ */ a("div", { className: f, style: I.container, children: [
1985
- /* @__PURE__ */ n("h2", { style: I.title, children: v.title }),
1986
- /* @__PURE__ */ a("form", { onSubmit: x, style: I.form, children: [
1987
- /* @__PURE__ */ a("div", { style: I.fieldGroup, children: [
1988
- /* @__PURE__ */ n("label", { style: I.label, children: v.usernameLabel }),
2045
+ return /* @__PURE__ */ l("div", { className: m, style: M.container, children: [
2046
+ /* @__PURE__ */ n("h2", { style: M.title, children: v.title }),
2047
+ /* @__PURE__ */ l("form", { onSubmit: L, style: M.form, children: [
2048
+ /* @__PURE__ */ l("div", { style: M.fieldGroup, children: [
2049
+ /* @__PURE__ */ n("label", { style: M.label, children: v.usernameLabel }),
1989
2050
  /* @__PURE__ */ n(
1990
2051
  "input",
1991
2052
  {
1992
2053
  id: "username",
1993
2054
  name: "username",
1994
2055
  type: "text",
1995
- value: p,
1996
- onChange: (c) => {
1997
- h(c.target.value), q.username && V((S) => ({ ...S, username: !1 }));
2056
+ value: f,
2057
+ onChange: (g) => {
2058
+ u(g.target.value), z.username && G((w) => ({ ...w, username: !1 }));
1998
2059
  },
1999
2060
  placeholder: v.usernamePlaceholder,
2000
- style: b("username"),
2001
- disabled: P
2061
+ style: c("username"),
2062
+ disabled: A
2002
2063
  }
2003
2064
  )
2004
2065
  ] }),
2005
- /* @__PURE__ */ a("div", { style: I.fieldGroup, children: [
2006
- /* @__PURE__ */ n("label", { style: I.label, children: v.passwordLabel }),
2007
- /* @__PURE__ */ a("div", { style: I.inputContainer, children: [
2066
+ /* @__PURE__ */ l("div", { style: M.fieldGroup, children: [
2067
+ /* @__PURE__ */ n("label", { style: M.label, children: v.passwordLabel }),
2068
+ /* @__PURE__ */ l("div", { style: M.inputContainer, children: [
2008
2069
  /* @__PURE__ */ n(
2009
2070
  "input",
2010
2071
  {
2011
2072
  id: "password",
2012
2073
  name: "password",
2013
2074
  type: C ? "text" : "password",
2014
- value: m,
2015
- onChange: (c) => {
2016
- R(c.target.value), q.password && V((S) => ({ ...S, password: !1 }));
2075
+ value: y,
2076
+ onChange: (g) => {
2077
+ R(g.target.value), z.password && G((w) => ({ ...w, password: !1 }));
2017
2078
  },
2018
2079
  placeholder: v.passwordPlaceholder,
2019
2080
  style: {
2020
- ...b("password"),
2081
+ ...c("password"),
2021
2082
  paddingRight: "2.5rem"
2022
2083
  // Make room for the icon
2023
2084
  },
2024
- disabled: P
2085
+ disabled: A
2025
2086
  }
2026
2087
  ),
2027
2088
  /* @__PURE__ */ n(
2028
2089
  "button",
2029
2090
  {
2030
2091
  type: "button",
2031
- onClick: () => U(!C),
2032
- style: I.passwordToggle,
2033
- disabled: P,
2092
+ onClick: () => q(!C),
2093
+ style: M.passwordToggle,
2094
+ disabled: A,
2034
2095
  "aria-label": C ? "Hide password" : "Show password",
2035
- children: C ? L.hidePassword : L.showPassword
2096
+ children: C ? I.hidePassword : I.showPassword
2036
2097
  }
2037
2098
  )
2038
2099
  ] })
2039
2100
  ] }),
2040
- /* @__PURE__ */ n("button", { type: "submit", disabled: !p || !m || P, style: d(), children: P ? v.loadingText : v.submitButton }),
2041
- M && /* @__PURE__ */ n("div", { style: I.errorText, children: M })
2101
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !f || !y || A, style: h(), children: A ? v.loadingText : v.submitButton }),
2102
+ P && /* @__PURE__ */ n("div", { style: M.errorText, children: P })
2042
2103
  ] }),
2043
- (A || w || T) && /* @__PURE__ */ a("div", { style: I.linkContainer, children: [
2044
- T && /* @__PURE__ */ a("div", { children: [
2045
- /* @__PURE__ */ a("span", { style: I.divider, children: [
2104
+ (k || S || T) && /* @__PURE__ */ l("div", { style: M.linkContainer, children: [
2105
+ T && /* @__PURE__ */ l("div", { children: [
2106
+ /* @__PURE__ */ l("span", { style: M.divider, children: [
2046
2107
  v.magicLinkText,
2047
2108
  " "
2048
2109
  ] }),
2049
- /* @__PURE__ */ n("a", { onClick: y, style: I.link, children: v.magicLinkLink })
2110
+ /* @__PURE__ */ n("a", { onClick: b, style: M.link, children: v.magicLinkLink })
2050
2111
  ] }),
2051
- T && (A || w) && /* @__PURE__ */ n("div", { style: I.divider, children: "•" }),
2052
- A && /* @__PURE__ */ n("a", { onClick: o, style: I.link, children: v.forgotPasswordLink }),
2053
- A && w && /* @__PURE__ */ n("div", { style: I.divider, children: "•" }),
2054
- w && /* @__PURE__ */ a("div", { children: [
2055
- /* @__PURE__ */ a("span", { style: I.divider, children: [
2112
+ T && (k || S) && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2113
+ k && /* @__PURE__ */ n("a", { onClick: o, style: M.link, children: v.forgotPasswordLink }),
2114
+ k && S && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2115
+ S && /* @__PURE__ */ l("div", { children: [
2116
+ /* @__PURE__ */ l("span", { style: M.divider, children: [
2056
2117
  v.signupText,
2057
2118
  " "
2058
2119
  ] }),
2059
- /* @__PURE__ */ n("a", { onClick: g, style: I.link, children: v.signupLink })
2120
+ /* @__PURE__ */ n("a", { onClick: p, style: M.link, children: v.signupLink })
2060
2121
  ] })
2061
2122
  ] })
2062
2123
  ] });
2063
2124
  }
2064
- const nt = {
2125
+ const ut = {
2065
2126
  title: "Create Account",
2066
2127
  nameLabel: "First Name",
2067
2128
  namePlaceholder: "Enter your first name",
@@ -2087,7 +2148,7 @@ const nt = {
2087
2148
  passwordMismatchError: "Passwords do not match",
2088
2149
  isAdminLabel: "Create new organization",
2089
2150
  isAdminDescription: "Check this if you want to create a new organization"
2090
- }, st = {
2151
+ }, ht = {
2091
2152
  container: {
2092
2153
  maxWidth: "400px",
2093
2154
  width: "100%",
@@ -2186,69 +2247,69 @@ const nt = {
2186
2247
  fontSize: "0.875rem"
2187
2248
  }
2188
2249
  };
2189
- function Nt({
2250
+ function Vt({
2190
2251
  copy: i = {},
2191
2252
  styles: e = {},
2192
2253
  signupType: t = "user",
2193
2254
  onSuccess: r,
2194
2255
  onError: s,
2195
2256
  onLoginClick: o,
2196
- onMagicLinkClick: g,
2197
- showLoginLink: y = !0,
2198
- showMagicLinkOption: A = !0,
2199
- className: w
2257
+ onMagicLinkClick: p,
2258
+ showLoginLink: b = !0,
2259
+ showMagicLinkOption: k = !0,
2260
+ className: S
2200
2261
  }) {
2201
- 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 = { ...nt, ...i }, S = { ...st, ...e }, G = () => {
2202
- const D = {};
2203
- 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;
2204
- }, ee = async (D) => {
2205
- if (D.preventDefault(), !!G()) {
2206
- if (P !== M) {
2207
- I(c.passwordMismatchError), l({ confirmPassword: !0 });
2262
+ const [T, m] = x(""), [f, u] = x(""), [y, R] = x(""), [C, q] = x(""), [A, d] = x(""), [P, E] = x(""), [z, G] = x(""), [$, _] = x(!1), [v, M] = x(""), [I, a] = x({}), { signup: L, signupTenantAdmin: c } = ae(), { tenant: h } = se(), g = { ...ut, ...i }, w = { ...ht, ...e }, j = () => {
2263
+ const F = {};
2264
+ return T.trim() || (F.name = !0), !y.trim() && !C.trim() && (F.email = !0, F.phoneNumber = !0), A.trim() || (F.password = !0), P.trim() || (F.confirmPassword = !0), t === "tenant" && !z.trim() && (F.tenantName = !0), a(F), Object.keys(F).length === 0;
2265
+ }, Y = async (F) => {
2266
+ if (F.preventDefault(), !!j()) {
2267
+ if (A !== P) {
2268
+ M(g.passwordMismatchError), a({ confirmPassword: !0 });
2208
2269
  return;
2209
2270
  }
2210
- if (t === "user" && !(d != null && d.id)) {
2211
- I("Tenant not found");
2271
+ if (t === "user" && !(h != null && h.id)) {
2272
+ M("Tenant not found");
2212
2273
  return;
2213
2274
  }
2214
- j(!0), I("");
2275
+ _(!0), M("");
2215
2276
  try {
2216
2277
  let K;
2217
- t === "tenant" ? K = await b({
2218
- email: m || void 0,
2278
+ t === "tenant" ? K = await c({
2279
+ email: y || void 0,
2219
2280
  phoneNumber: C || void 0,
2220
2281
  name: T,
2221
- password: P,
2222
- tenantName: q,
2223
- lastName: p || void 0
2224
- }) : K = await x({
2225
- email: m || void 0,
2282
+ password: A,
2283
+ tenantName: z,
2284
+ lastName: f || void 0
2285
+ }) : K = await L({
2286
+ email: y || void 0,
2226
2287
  phoneNumber: C || void 0,
2227
2288
  name: T,
2228
- password: P,
2229
- tenantId: d.id,
2230
- lastName: p || void 0
2289
+ password: A,
2290
+ tenantId: h.id,
2291
+ lastName: f || void 0
2231
2292
  }), r == null || r(K);
2232
2293
  } catch (K) {
2233
- const ge = K.message || c.errorMessage;
2234
- I(ge), s == null || s(ge);
2294
+ const ge = K.message || g.errorMessage;
2295
+ M(ge), s == null || s(ge);
2235
2296
  } finally {
2236
- j(!1);
2297
+ _(!1);
2237
2298
  }
2238
2299
  }
2239
- }, z = (D) => ({
2240
- ...S.input,
2241
- ...L[D] ? S.inputError : {}
2242
- }), H = () => ({
2243
- ...S.button,
2244
- ...$ ? S.buttonLoading : {},
2245
- ...!T || !m && !C || !P || !M || $ || t === "tenant" && !q ? S.buttonDisabled : {}
2246
- }), O = T && (m || C) && P && M && (t === "user" || q);
2247
- return /* @__PURE__ */ a("div", { className: w, style: S.container, children: [
2248
- /* @__PURE__ */ n("h2", { style: S.title, children: c.title }),
2249
- /* @__PURE__ */ a("form", { onSubmit: ee, style: S.form, children: [
2250
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2251
- /* @__PURE__ */ n("label", { style: S.label, children: c.nameLabel }),
2300
+ }, H = (F) => ({
2301
+ ...w.input,
2302
+ ...I[F] ? w.inputError : {}
2303
+ }), N = () => ({
2304
+ ...w.button,
2305
+ ...$ ? w.buttonLoading : {},
2306
+ ...!T || !y && !C || !A || !P || $ || t === "tenant" && !z ? w.buttonDisabled : {}
2307
+ }), O = T && (y || C) && A && P && (t === "user" || z);
2308
+ return /* @__PURE__ */ l("div", { className: S, style: w.container, children: [
2309
+ /* @__PURE__ */ n("h2", { style: w.title, children: g.title }),
2310
+ /* @__PURE__ */ l("form", { onSubmit: Y, style: w.form, children: [
2311
+ /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2312
+ /* @__PURE__ */ n("label", { style: w.label, children: g.nameLabel }),
2252
2313
  /* @__PURE__ */ n(
2253
2314
  "input",
2254
2315
  {
@@ -2256,51 +2317,51 @@ function Nt({
2256
2317
  name: "name",
2257
2318
  type: "text",
2258
2319
  value: T,
2259
- onChange: (D) => {
2260
- f(D.target.value), L.name && l((K) => ({ ...K, name: !1 }));
2320
+ onChange: (F) => {
2321
+ m(F.target.value), I.name && a((K) => ({ ...K, name: !1 }));
2261
2322
  },
2262
- placeholder: c.namePlaceholder,
2263
- style: z("name"),
2323
+ placeholder: g.namePlaceholder,
2324
+ style: H("name"),
2264
2325
  disabled: $
2265
2326
  }
2266
2327
  )
2267
2328
  ] }),
2268
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2269
- /* @__PURE__ */ n("label", { style: S.label, children: c.lastNameLabel }),
2329
+ /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2330
+ /* @__PURE__ */ n("label", { style: w.label, children: g.lastNameLabel }),
2270
2331
  /* @__PURE__ */ n(
2271
2332
  "input",
2272
2333
  {
2273
2334
  id: "lastName",
2274
2335
  name: "lastName",
2275
2336
  type: "text",
2276
- value: p,
2277
- onChange: (D) => h(D.target.value),
2278
- placeholder: c.lastNamePlaceholder,
2279
- style: S.input,
2337
+ value: f,
2338
+ onChange: (F) => u(F.target.value),
2339
+ placeholder: g.lastNamePlaceholder,
2340
+ style: w.input,
2280
2341
  disabled: $
2281
2342
  }
2282
2343
  )
2283
2344
  ] }),
2284
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2285
- /* @__PURE__ */ n("label", { style: S.label, children: c.emailLabel }),
2345
+ /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2346
+ /* @__PURE__ */ n("label", { style: w.label, children: g.emailLabel }),
2286
2347
  /* @__PURE__ */ n(
2287
2348
  "input",
2288
2349
  {
2289
2350
  id: "email",
2290
2351
  name: "email",
2291
2352
  type: "email",
2292
- value: m,
2293
- onChange: (D) => {
2294
- R(D.target.value), L.email && l((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2353
+ value: y,
2354
+ onChange: (F) => {
2355
+ R(F.target.value), I.email && a((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2295
2356
  },
2296
- placeholder: c.emailPlaceholder,
2297
- style: z("email"),
2357
+ placeholder: g.emailPlaceholder,
2358
+ style: H("email"),
2298
2359
  disabled: $
2299
2360
  }
2300
2361
  )
2301
2362
  ] }),
2302
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2303
- /* @__PURE__ */ n("label", { style: S.label, children: c.phoneNumberLabel }),
2363
+ /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2364
+ /* @__PURE__ */ n("label", { style: w.label, children: g.phoneNumberLabel }),
2304
2365
  /* @__PURE__ */ n(
2305
2366
  "input",
2306
2367
  {
@@ -2308,11 +2369,11 @@ function Nt({
2308
2369
  name: "phoneNumber",
2309
2370
  type: "tel",
2310
2371
  value: C,
2311
- onChange: (D) => {
2312
- U(D.target.value), L.phoneNumber && l((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2372
+ onChange: (F) => {
2373
+ q(F.target.value), I.phoneNumber && a((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2313
2374
  },
2314
- placeholder: c.phoneNumberPlaceholder,
2315
- style: z("phoneNumber"),
2375
+ placeholder: g.phoneNumberPlaceholder,
2376
+ style: H("phoneNumber"),
2316
2377
  disabled: $
2317
2378
  }
2318
2379
  )
@@ -2329,83 +2390,83 @@ function Nt({
2329
2390
  children: "At least one contact method (email or phone) is required"
2330
2391
  }
2331
2392
  ),
2332
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2333
- /* @__PURE__ */ n("label", { style: S.label, children: c.passwordLabel }),
2393
+ /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2394
+ /* @__PURE__ */ n("label", { style: w.label, children: g.passwordLabel }),
2334
2395
  /* @__PURE__ */ n(
2335
2396
  "input",
2336
2397
  {
2337
2398
  id: "password",
2338
2399
  name: "password",
2339
2400
  type: "password",
2340
- value: P,
2341
- onChange: (D) => {
2342
- u(D.target.value), L.password && l((K) => ({ ...K, password: !1 }));
2401
+ value: A,
2402
+ onChange: (F) => {
2403
+ d(F.target.value), I.password && a((K) => ({ ...K, password: !1 }));
2343
2404
  },
2344
- placeholder: c.passwordPlaceholder,
2345
- style: z("password"),
2405
+ placeholder: g.passwordPlaceholder,
2406
+ style: H("password"),
2346
2407
  disabled: $
2347
2408
  }
2348
2409
  )
2349
2410
  ] }),
2350
- /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2351
- /* @__PURE__ */ n("label", { style: S.label, children: c.confirmPasswordLabel }),
2411
+ /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2412
+ /* @__PURE__ */ n("label", { style: w.label, children: g.confirmPasswordLabel }),
2352
2413
  /* @__PURE__ */ n(
2353
2414
  "input",
2354
2415
  {
2355
2416
  id: "confirmPassword",
2356
2417
  name: "confirmPassword",
2357
2418
  type: "password",
2358
- value: M,
2359
- onChange: (D) => {
2360
- E(D.target.value), L.confirmPassword && l((K) => ({ ...K, confirmPassword: !1 })), v === c.passwordMismatchError && I("");
2419
+ value: P,
2420
+ onChange: (F) => {
2421
+ E(F.target.value), I.confirmPassword && a((K) => ({ ...K, confirmPassword: !1 })), v === g.passwordMismatchError && M("");
2361
2422
  },
2362
- placeholder: c.confirmPasswordPlaceholder,
2363
- style: z("confirmPassword"),
2423
+ placeholder: g.confirmPasswordPlaceholder,
2424
+ style: H("confirmPassword"),
2364
2425
  disabled: $
2365
2426
  }
2366
2427
  )
2367
2428
  ] }),
2368
- t === "tenant" && /* @__PURE__ */ a("div", { style: S.fieldGroup, children: [
2369
- /* @__PURE__ */ n("label", { style: S.label, children: c.tenantNameLabel }),
2429
+ t === "tenant" && /* @__PURE__ */ l("div", { style: w.fieldGroup, children: [
2430
+ /* @__PURE__ */ n("label", { style: w.label, children: g.tenantNameLabel }),
2370
2431
  /* @__PURE__ */ n(
2371
2432
  "input",
2372
2433
  {
2373
2434
  id: "tenantName",
2374
2435
  name: "tenantName",
2375
2436
  type: "text",
2376
- value: q,
2377
- onChange: (D) => {
2378
- V(D.target.value), L.tenantName && l((K) => ({ ...K, tenantName: !1 }));
2437
+ value: z,
2438
+ onChange: (F) => {
2439
+ G(F.target.value), I.tenantName && a((K) => ({ ...K, tenantName: !1 }));
2379
2440
  },
2380
- placeholder: c.tenantNamePlaceholder,
2381
- style: z("tenantName"),
2441
+ placeholder: g.tenantNamePlaceholder,
2442
+ style: H("tenantName"),
2382
2443
  disabled: $
2383
2444
  }
2384
2445
  )
2385
2446
  ] }),
2386
- /* @__PURE__ */ n("button", { type: "submit", disabled: !O || $, style: H(), children: $ ? c.loadingText : c.submitButton }),
2387
- v && /* @__PURE__ */ n("div", { style: S.errorText, children: v })
2447
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !O || $, style: N(), children: $ ? g.loadingText : g.submitButton }),
2448
+ v && /* @__PURE__ */ n("div", { style: w.errorText, children: v })
2388
2449
  ] }),
2389
- (y || A) && /* @__PURE__ */ a("div", { style: S.linkContainer, children: [
2390
- A && /* @__PURE__ */ a("div", { children: [
2391
- /* @__PURE__ */ a("span", { style: S.divider, children: [
2392
- c.magicLinkText,
2450
+ (b || k) && /* @__PURE__ */ l("div", { style: w.linkContainer, children: [
2451
+ k && /* @__PURE__ */ l("div", { children: [
2452
+ /* @__PURE__ */ l("span", { style: w.divider, children: [
2453
+ g.magicLinkText,
2393
2454
  " "
2394
2455
  ] }),
2395
- /* @__PURE__ */ n("a", { onClick: g, style: S.link, children: c.magicLinkLink })
2456
+ /* @__PURE__ */ n("a", { onClick: p, style: w.link, children: g.magicLinkLink })
2396
2457
  ] }),
2397
- A && y && /* @__PURE__ */ n("div", { style: S.divider, children: "•" }),
2398
- y && /* @__PURE__ */ a("div", { children: [
2399
- /* @__PURE__ */ a("span", { style: S.divider, children: [
2400
- c.loginText,
2458
+ k && b && /* @__PURE__ */ n("div", { style: w.divider, children: "•" }),
2459
+ b && /* @__PURE__ */ l("div", { children: [
2460
+ /* @__PURE__ */ l("span", { style: w.divider, children: [
2461
+ g.loginText,
2401
2462
  " "
2402
2463
  ] }),
2403
- /* @__PURE__ */ n("a", { onClick: o, style: S.link, children: c.loginLink })
2464
+ /* @__PURE__ */ n("a", { onClick: o, style: w.link, children: g.loginLink })
2404
2465
  ] })
2405
2466
  ] })
2406
2467
  ] });
2407
2468
  }
2408
- const it = {
2469
+ const gt = {
2409
2470
  title: "Sign In with Magic Link",
2410
2471
  emailLabel: "Email",
2411
2472
  emailPlaceholder: "Enter your email",
@@ -2423,7 +2484,7 @@ const it = {
2423
2484
  loadingText: "Sending magic link...",
2424
2485
  verifyingText: "Verifying magic link...",
2425
2486
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2426
- }, ot = {
2487
+ }, pt = {
2427
2488
  container: {
2428
2489
  maxWidth: "400px",
2429
2490
  width: "100%",
@@ -2526,84 +2587,84 @@ const it = {
2526
2587
  fontSize: "0.875rem"
2527
2588
  }
2528
2589
  };
2529
- function Bt({
2590
+ function _t({
2530
2591
  copy: i = {},
2531
2592
  styles: e = {},
2532
2593
  onSuccess: t,
2533
2594
  onError: r,
2534
2595
  onLoginClick: s,
2535
2596
  onSignupClick: o,
2536
- showTraditionalLinks: g = !0,
2537
- className: y,
2538
- verifyToken: A,
2539
- frontendUrl: w
2597
+ showTraditionalLinks: p = !0,
2598
+ className: b,
2599
+ verifyToken: k,
2600
+ frontendUrl: S
2540
2601
  }) {
2541
- 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 = { ...it, ...i }, d = { ...ot, ...e };
2602
+ const [T, m] = x(""), [f, u] = x(""), [y, R] = x(""), [C, q] = x(!1), [A, d] = x(!1), [P, E] = x(""), [z, G] = x(""), [$, _] = x({}), [v, M] = x(!1), { sendMagicLink: I, verifyMagicLink: a } = ae(), { tenant: L } = se(), c = { ...gt, ...i }, h = { ...pt, ...e };
2542
2603
  te(() => {
2543
- A && c(A);
2544
- }, [A]);
2545
- const c = async (H) => {
2546
- if (!x || !T) {
2604
+ k && g(k);
2605
+ }, [k]);
2606
+ const g = async (N) => {
2607
+ if (!L || !T) {
2547
2608
  E("Missing tenant or email");
2548
2609
  return;
2549
2610
  }
2550
- u(!0), E("");
2611
+ d(!0), E("");
2551
2612
  try {
2552
- const O = await l({
2553
- token: H,
2613
+ const O = await a({
2614
+ token: N,
2554
2615
  email: T
2555
2616
  // tenantId inferred from context automatically
2556
2617
  });
2557
2618
  t == null || t(O);
2558
2619
  } catch (O) {
2559
- const D = O.message || "Failed to verify magic link";
2560
- E(D), r == null || r(D);
2620
+ const F = O.message || "Failed to verify magic link";
2621
+ E(F), r == null || r(F);
2561
2622
  } finally {
2562
- u(!1);
2623
+ d(!1);
2563
2624
  }
2564
- }, S = () => {
2565
- const H = {};
2566
- return T.trim() || (H.email = !0), v && !p.trim() && (H.name = !0), j(H), Object.keys(H).length === 0;
2567
- }, G = async (H) => {
2568
- if (H.preventDefault(), !!S()) {
2569
- if (!(x != null && x.id)) {
2625
+ }, w = () => {
2626
+ const N = {};
2627
+ return T.trim() || (N.email = !0), v && !f.trim() && (N.name = !0), _(N), Object.keys(N).length === 0;
2628
+ }, j = async (N) => {
2629
+ if (N.preventDefault(), !!w()) {
2630
+ if (!(L != null && L.id)) {
2570
2631
  E("Tenant not found");
2571
2632
  return;
2572
2633
  }
2573
- U(!0), E(""), V("");
2634
+ q(!0), E(""), G("");
2574
2635
  try {
2575
- const O = w || (typeof window < "u" ? window.location.origin : ""), D = await L({
2636
+ const O = S || (typeof window < "u" ? window.location.origin : ""), F = await I({
2576
2637
  email: T,
2577
- tenantId: x.id,
2638
+ tenantId: L.id,
2578
2639
  frontendUrl: O,
2579
- name: v ? p : void 0,
2580
- lastName: v ? m : void 0
2640
+ name: v ? f : void 0,
2641
+ lastName: v ? y : void 0
2581
2642
  });
2582
- V(b.successMessage), t == null || t(D);
2643
+ G(c.successMessage), t == null || t(F);
2583
2644
  } catch (O) {
2584
- const D = O.message || b.errorMessage;
2585
- E(D), r == null || r(D);
2645
+ const F = O.message || c.errorMessage;
2646
+ E(F), r == null || r(F);
2586
2647
  } finally {
2587
- U(!1);
2648
+ q(!1);
2588
2649
  }
2589
2650
  }
2590
- }, ee = (H) => ({
2591
- ...d.input,
2592
- ...$[H] ? d.inputError : {}
2593
- }), z = () => ({
2594
- ...d.button,
2595
- ...C || P ? d.buttonLoading : {},
2596
- ...!T || C || P ? d.buttonDisabled : {}
2651
+ }, Y = (N) => ({
2652
+ ...h.input,
2653
+ ...$[N] ? h.inputError : {}
2654
+ }), H = () => ({
2655
+ ...h.button,
2656
+ ...C || A ? h.buttonLoading : {},
2657
+ ...!T || C || A ? h.buttonDisabled : {}
2597
2658
  });
2598
- return P ? /* @__PURE__ */ a("div", { className: y, style: d.container, children: [
2599
- /* @__PURE__ */ n("h2", { style: d.title, children: b.verifyingText }),
2659
+ return A ? /* @__PURE__ */ l("div", { className: b, style: h.container, children: [
2660
+ /* @__PURE__ */ n("h2", { style: h.title, children: c.verifyingText }),
2600
2661
  /* @__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..." }) })
2601
- ] }) : /* @__PURE__ */ a("div", { className: y, style: d.container, children: [
2602
- /* @__PURE__ */ n("h2", { style: d.title, children: b.title }),
2603
- /* @__PURE__ */ n("p", { style: d.description, children: b.description }),
2604
- /* @__PURE__ */ a("form", { onSubmit: G, style: d.form, children: [
2605
- /* @__PURE__ */ a("div", { style: d.fieldGroup, children: [
2606
- /* @__PURE__ */ n("label", { style: d.label, children: b.emailLabel }),
2662
+ ] }) : /* @__PURE__ */ l("div", { className: b, style: h.container, children: [
2663
+ /* @__PURE__ */ n("h2", { style: h.title, children: c.title }),
2664
+ /* @__PURE__ */ n("p", { style: h.description, children: c.description }),
2665
+ /* @__PURE__ */ l("form", { onSubmit: j, style: h.form, children: [
2666
+ /* @__PURE__ */ l("div", { style: h.fieldGroup, children: [
2667
+ /* @__PURE__ */ n("label", { style: h.label, children: c.emailLabel }),
2607
2668
  /* @__PURE__ */ n(
2608
2669
  "input",
2609
2670
  {
@@ -2611,12 +2672,12 @@ function Bt({
2611
2672
  name: "email",
2612
2673
  type: "email",
2613
2674
  value: T,
2614
- onChange: (H) => {
2615
- f(H.target.value), $.email && j((O) => ({ ...O, email: !1 }));
2675
+ onChange: (N) => {
2676
+ m(N.target.value), $.email && _((O) => ({ ...O, email: !1 }));
2616
2677
  },
2617
- placeholder: b.emailPlaceholder,
2618
- style: ee("email"),
2619
- disabled: C || P
2678
+ placeholder: c.emailPlaceholder,
2679
+ style: Y("email"),
2680
+ disabled: C || A
2620
2681
  }
2621
2682
  )
2622
2683
  ] }),
@@ -2624,7 +2685,7 @@ function Bt({
2624
2685
  "button",
2625
2686
  {
2626
2687
  type: "button",
2627
- onClick: () => I(!0),
2688
+ onClick: () => M(!0),
2628
2689
  style: {
2629
2690
  background: "none",
2630
2691
  border: "none",
@@ -2636,38 +2697,38 @@ function Bt({
2636
2697
  children: "New user? Add your name"
2637
2698
  }
2638
2699
  ) }),
2639
- v && /* @__PURE__ */ a(B, { children: [
2640
- /* @__PURE__ */ a("div", { style: d.fieldGroup, children: [
2641
- /* @__PURE__ */ n("label", { style: d.label, children: b.nameLabel }),
2700
+ v && /* @__PURE__ */ l(U, { children: [
2701
+ /* @__PURE__ */ l("div", { style: h.fieldGroup, children: [
2702
+ /* @__PURE__ */ n("label", { style: h.label, children: c.nameLabel }),
2642
2703
  /* @__PURE__ */ n(
2643
2704
  "input",
2644
2705
  {
2645
2706
  id: "name",
2646
2707
  name: "name",
2647
2708
  type: "text",
2648
- value: p,
2649
- onChange: (H) => {
2650
- h(H.target.value), $.name && j((O) => ({ ...O, name: !1 }));
2709
+ value: f,
2710
+ onChange: (N) => {
2711
+ u(N.target.value), $.name && _((O) => ({ ...O, name: !1 }));
2651
2712
  },
2652
- placeholder: b.namePlaceholder,
2653
- style: ee("name"),
2654
- disabled: C || P
2713
+ placeholder: c.namePlaceholder,
2714
+ style: Y("name"),
2715
+ disabled: C || A
2655
2716
  }
2656
2717
  )
2657
2718
  ] }),
2658
- /* @__PURE__ */ a("div", { style: d.fieldGroup, children: [
2659
- /* @__PURE__ */ n("label", { style: d.label, children: b.lastNameLabel }),
2719
+ /* @__PURE__ */ l("div", { style: h.fieldGroup, children: [
2720
+ /* @__PURE__ */ n("label", { style: h.label, children: c.lastNameLabel }),
2660
2721
  /* @__PURE__ */ n(
2661
2722
  "input",
2662
2723
  {
2663
2724
  id: "lastName",
2664
2725
  name: "lastName",
2665
2726
  type: "text",
2666
- value: m,
2667
- onChange: (H) => R(H.target.value),
2668
- placeholder: b.lastNamePlaceholder,
2669
- style: d.input,
2670
- disabled: C || P
2727
+ value: y,
2728
+ onChange: (N) => R(N.target.value),
2729
+ placeholder: c.lastNamePlaceholder,
2730
+ style: h.input,
2731
+ disabled: C || A
2671
2732
  }
2672
2733
  )
2673
2734
  ] }),
@@ -2676,7 +2737,7 @@ function Bt({
2676
2737
  {
2677
2738
  type: "button",
2678
2739
  onClick: () => {
2679
- I(!1), h(""), R("");
2740
+ M(!1), u(""), R("");
2680
2741
  },
2681
2742
  style: {
2682
2743
  background: "none",
@@ -2690,30 +2751,30 @@ function Bt({
2690
2751
  }
2691
2752
  ) })
2692
2753
  ] }),
2693
- /* @__PURE__ */ n("button", { type: "submit", disabled: !T || C || P, style: z(), children: C ? b.loadingText : b.submitButton }),
2694
- M && /* @__PURE__ */ n("div", { style: d.errorText, children: M }),
2695
- q && /* @__PURE__ */ n("div", { style: d.successText, children: q })
2754
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !T || C || A, style: H(), children: C ? c.loadingText : c.submitButton }),
2755
+ P && /* @__PURE__ */ n("div", { style: h.errorText, children: P }),
2756
+ z && /* @__PURE__ */ n("div", { style: h.successText, children: z })
2696
2757
  ] }),
2697
- g && /* @__PURE__ */ a("div", { style: d.linkContainer, children: [
2698
- /* @__PURE__ */ a("div", { children: [
2699
- /* @__PURE__ */ a("span", { style: d.divider, children: [
2700
- b.loginText,
2758
+ p && /* @__PURE__ */ l("div", { style: h.linkContainer, children: [
2759
+ /* @__PURE__ */ l("div", { children: [
2760
+ /* @__PURE__ */ l("span", { style: h.divider, children: [
2761
+ c.loginText,
2701
2762
  " "
2702
2763
  ] }),
2703
- /* @__PURE__ */ n("a", { onClick: s, style: d.link, children: b.loginLink })
2764
+ /* @__PURE__ */ n("a", { onClick: s, style: h.link, children: c.loginLink })
2704
2765
  ] }),
2705
- /* @__PURE__ */ n("div", { style: d.divider, children: "•" }),
2706
- /* @__PURE__ */ a("div", { children: [
2707
- /* @__PURE__ */ a("span", { style: d.divider, children: [
2708
- b.signupText,
2766
+ /* @__PURE__ */ n("div", { style: h.divider, children: "•" }),
2767
+ /* @__PURE__ */ l("div", { children: [
2768
+ /* @__PURE__ */ l("span", { style: h.divider, children: [
2769
+ c.signupText,
2709
2770
  " "
2710
2771
  ] }),
2711
- /* @__PURE__ */ n("a", { onClick: o, style: d.link, children: b.signupLink })
2772
+ /* @__PURE__ */ n("a", { onClick: o, style: h.link, children: c.signupLink })
2712
2773
  ] })
2713
2774
  ] })
2714
2775
  ] });
2715
2776
  }
2716
- const at = {
2777
+ const ft = {
2717
2778
  title: "Verifying Magic Link",
2718
2779
  verifyingMessage: "Please wait while we verify your magic link...",
2719
2780
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2721,7 +2782,7 @@ const at = {
2721
2782
  redirectingMessage: "Redirecting you to the dashboard...",
2722
2783
  retryButton: "Try Again",
2723
2784
  backToLoginButton: "Back to Login"
2724
- }, Ee = {
2785
+ }, Re = {
2725
2786
  container: {
2726
2787
  maxWidth: "400px",
2727
2788
  width: "100%",
@@ -2808,7 +2869,7 @@ const at = {
2808
2869
  cursor: "pointer",
2809
2870
  transition: "all 0.15s ease-in-out"
2810
2871
  }
2811
- }, lt = () => /* @__PURE__ */ n("div", { style: Ee.spinner }), ct = () => /* @__PURE__ */ a(
2872
+ }, mt = () => /* @__PURE__ */ n("div", { style: Re.spinner }), yt = () => /* @__PURE__ */ l(
2812
2873
  "svg",
2813
2874
  {
2814
2875
  width: "48",
@@ -2825,7 +2886,7 @@ const at = {
2825
2886
  /* @__PURE__ */ n("polyline", { points: "22,4 12,14.01 9,11.01" })
2826
2887
  ]
2827
2888
  }
2828
- ), dt = () => /* @__PURE__ */ a(
2889
+ ), wt = () => /* @__PURE__ */ l(
2829
2890
  "svg",
2830
2891
  {
2831
2892
  width: "48",
@@ -2843,109 +2904,109 @@ const at = {
2843
2904
  /* @__PURE__ */ n("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
2844
2905
  ]
2845
2906
  }
2846
- ), ut = {
2847
- loading: /* @__PURE__ */ n(lt, {}),
2848
- success: /* @__PURE__ */ n(ct, {}),
2849
- error: /* @__PURE__ */ n(dt, {})
2907
+ ), bt = {
2908
+ loading: /* @__PURE__ */ n(mt, {}),
2909
+ success: /* @__PURE__ */ n(yt, {}),
2910
+ error: /* @__PURE__ */ n(wt, {})
2850
2911
  };
2851
- function Ut({
2912
+ function Gt({
2852
2913
  copy: i = {},
2853
2914
  styles: e = {},
2854
2915
  icons: t = {},
2855
2916
  onSuccess: r,
2856
2917
  onError: s,
2857
2918
  onRetry: o,
2858
- onBackToLogin: g,
2859
- className: y,
2860
- token: A,
2861
- email: w,
2919
+ onBackToLogin: p,
2920
+ className: b,
2921
+ token: k,
2922
+ email: S,
2862
2923
  appId: T,
2863
- tenantSlug: f,
2864
- autoRedirectDelay: p = 3e3
2924
+ tenantSlug: m,
2925
+ autoRedirectDelay: f = 3e3
2865
2926
  }) {
2866
- const [h, m] = k("verifying"), [R, C] = k(""), { verifyMagicLink: U } = ae(), P = { ...at, ...i }, u = { ...Ee, ...e }, M = { ...ut, ...t }, E = () => {
2927
+ const [u, y] = x("verifying"), [R, C] = x(""), { verifyMagicLink: q } = ae(), A = { ...ft, ...i }, d = { ...Re, ...e }, P = { ...bt, ...t }, E = () => {
2867
2928
  if (typeof window > "u") return {};
2868
2929
  const v = new URLSearchParams(window.location.search);
2869
2930
  return {
2870
- token: A || v.get("token") || "",
2871
- email: w || v.get("email") || "",
2931
+ token: k || v.get("token") || "",
2932
+ email: S || v.get("email") || "",
2872
2933
  appId: T || v.get("appId") || "",
2873
- tenantSlug: f || v.get("tenantSlug") || void 0
2934
+ tenantSlug: m || v.get("tenantSlug") || void 0
2874
2935
  };
2875
- }, q = async () => {
2876
- m("verifying"), C("");
2936
+ }, z = async () => {
2937
+ y("verifying"), C("");
2877
2938
  try {
2878
2939
  const v = E();
2879
2940
  if (!v.token || !v.email)
2880
2941
  throw new Error("Missing required parameters: token or email");
2881
- const I = await U({
2942
+ const M = await q({
2882
2943
  token: v.token,
2883
2944
  email: v.email,
2884
2945
  tenantSlug: v.tenantSlug
2885
2946
  });
2886
- m("success"), r == null || r(I), p > 0 && setTimeout(() => {
2887
- m("redirecting");
2888
- }, p);
2947
+ y("success"), r == null || r(M), f > 0 && setTimeout(() => {
2948
+ y("redirecting");
2949
+ }, f);
2889
2950
  } catch (v) {
2890
- const I = v.message || P.errorMessage;
2891
- C(I), m("error"), s == null || s(I);
2951
+ const M = v.message || A.errorMessage;
2952
+ C(M), y("error"), s == null || s(M);
2892
2953
  }
2893
- }, V = () => {
2894
- o == null || o(), q();
2954
+ }, G = () => {
2955
+ o == null || o(), z();
2895
2956
  }, $ = () => {
2896
- g == null || g();
2957
+ p == null || p();
2897
2958
  };
2898
2959
  te(() => {
2899
- q();
2960
+ z();
2900
2961
  }, []);
2901
- const j = () => {
2902
- switch (h) {
2962
+ const _ = () => {
2963
+ switch (u) {
2903
2964
  case "verifying":
2904
- return /* @__PURE__ */ a("div", { style: u.message, children: [
2905
- M.loading,
2906
- P.verifyingMessage
2965
+ return /* @__PURE__ */ l("div", { style: d.message, children: [
2966
+ P.loading,
2967
+ A.verifyingMessage
2907
2968
  ] });
2908
2969
  case "success":
2909
- return /* @__PURE__ */ a(B, { children: [
2910
- M.success,
2911
- /* @__PURE__ */ n("div", { style: u.successMessage, children: P.successMessage })
2970
+ return /* @__PURE__ */ l(U, { children: [
2971
+ P.success,
2972
+ /* @__PURE__ */ n("div", { style: d.successMessage, children: A.successMessage })
2912
2973
  ] });
2913
2974
  case "redirecting":
2914
- return /* @__PURE__ */ a(B, { children: [
2915
- M.loading,
2916
- /* @__PURE__ */ n("div", { style: u.message, children: P.redirectingMessage })
2975
+ return /* @__PURE__ */ l(U, { children: [
2976
+ P.loading,
2977
+ /* @__PURE__ */ n("div", { style: d.message, children: A.redirectingMessage })
2917
2978
  ] });
2918
2979
  case "error":
2919
- return /* @__PURE__ */ a(B, { children: [
2920
- M.error,
2921
- /* @__PURE__ */ n("div", { style: u.errorMessage, children: R || P.errorMessage }),
2922
- /* @__PURE__ */ a("div", { style: u.buttonContainer, children: [
2980
+ return /* @__PURE__ */ l(U, { children: [
2981
+ P.error,
2982
+ /* @__PURE__ */ n("div", { style: d.errorMessage, children: R || A.errorMessage }),
2983
+ /* @__PURE__ */ l("div", { style: d.buttonContainer, children: [
2923
2984
  /* @__PURE__ */ n(
2924
2985
  "button",
2925
2986
  {
2926
- onClick: V,
2927
- style: u.retryButton,
2987
+ onClick: G,
2988
+ style: d.retryButton,
2928
2989
  onMouseOver: (v) => {
2929
2990
  v.currentTarget.style.backgroundColor = "#2563eb";
2930
2991
  },
2931
2992
  onMouseOut: (v) => {
2932
2993
  v.currentTarget.style.backgroundColor = "#3b82f6";
2933
2994
  },
2934
- children: P.retryButton
2995
+ children: A.retryButton
2935
2996
  }
2936
2997
  ),
2937
2998
  /* @__PURE__ */ n(
2938
2999
  "button",
2939
3000
  {
2940
3001
  onClick: $,
2941
- style: u.backButton,
3002
+ style: d.backButton,
2942
3003
  onMouseOver: (v) => {
2943
3004
  v.currentTarget.style.backgroundColor = "#e5e7eb";
2944
3005
  },
2945
3006
  onMouseOut: (v) => {
2946
3007
  v.currentTarget.style.backgroundColor = "#f3f4f6";
2947
3008
  },
2948
- children: P.backToLoginButton
3009
+ children: A.backToLoginButton
2949
3010
  }
2950
3011
  )
2951
3012
  ] })
@@ -2954,18 +3015,18 @@ function Ut({
2954
3015
  return null;
2955
3016
  }
2956
3017
  };
2957
- return /* @__PURE__ */ a("div", { style: u.container, className: y, children: [
3018
+ return /* @__PURE__ */ l("div", { style: d.container, className: b, children: [
2958
3019
  /* @__PURE__ */ n("style", { children: `
2959
3020
  @keyframes spin {
2960
3021
  0% { transform: rotate(0deg); }
2961
3022
  100% { transform: rotate(360deg); }
2962
3023
  }
2963
3024
  ` }),
2964
- /* @__PURE__ */ n("h1", { style: u.title, children: P.title }),
2965
- j()
3025
+ /* @__PURE__ */ n("h1", { style: d.title, children: A.title }),
3026
+ _()
2966
3027
  ] });
2967
3028
  }
2968
- const ht = {
3029
+ const St = {
2969
3030
  title: "Reset Password",
2970
3031
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
2971
3032
  emailLabel: "Email",
@@ -2987,7 +3048,7 @@ const ht = {
2987
3048
  resetLoadingText: "Resetting...",
2988
3049
  resetSuccessMessage: "Password reset successfully!",
2989
3050
  passwordMismatchError: "Passwords do not match"
2990
- }, gt = {
3051
+ }, vt = {
2991
3052
  container: {
2992
3053
  maxWidth: "400px",
2993
3054
  margin: "0 auto",
@@ -3079,113 +3140,113 @@ const ht = {
3079
3140
  cursor: "pointer"
3080
3141
  }
3081
3142
  };
3082
- function qt({
3143
+ function Kt({
3083
3144
  copy: i = {},
3084
3145
  styles: e = {},
3085
3146
  mode: t = "request",
3086
3147
  token: r = "",
3087
3148
  onSuccess: s,
3088
3149
  onError: o,
3089
- onBackToLogin: g,
3090
- onModeChange: y,
3091
- className: A
3150
+ onBackToLogin: p,
3151
+ onModeChange: b,
3152
+ className: k
3092
3153
  }) {
3093
- 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 = { ...ht, ...i }, l = { ...gt, ...e }, x = () => {
3094
- const z = {};
3095
- return w.trim() || (z.email = !0), $(z), Object.keys(z).length === 0;
3096
- }, b = () => {
3097
- const z = {};
3098
- return f.trim() || (z.token = !0), h.trim() || (z.newPassword = !0), R.trim() || (z.confirmPassword = !0), $(z), Object.keys(z).length === 0;
3099
- }, d = async (z) => {
3100
- if (z.preventDefault(), !!x()) {
3101
- if (!(I != null && I.id)) {
3102
- M("Tenant not found");
3154
+ const [S, T] = x(""), [m, f] = x(r), [u, y] = x(""), [R, C] = x(""), [q, A] = x(!1), [d, P] = x(""), [E, z] = x(""), [G, $] = x({}), { requestPasswordReset: _, confirmPasswordReset: v } = ae(), { tenant: M } = se(), I = { ...St, ...i }, a = { ...vt, ...e }, L = () => {
3155
+ const H = {};
3156
+ return S.trim() || (H.email = !0), $(H), Object.keys(H).length === 0;
3157
+ }, c = () => {
3158
+ const H = {};
3159
+ return m.trim() || (H.token = !0), u.trim() || (H.newPassword = !0), R.trim() || (H.confirmPassword = !0), $(H), Object.keys(H).length === 0;
3160
+ }, h = async (H) => {
3161
+ if (H.preventDefault(), !!L()) {
3162
+ if (!(M != null && M.id)) {
3163
+ P("Tenant not found");
3103
3164
  return;
3104
3165
  }
3105
- P(!0), M(""), q("");
3166
+ A(!0), P(""), z("");
3106
3167
  try {
3107
- await j({ email: w, tenantId: I.id }), q(L.successMessage), s == null || s();
3108
- } catch (H) {
3109
- const O = H.message || L.errorMessage;
3110
- M(O), o == null || o(O);
3168
+ await _({ email: S, tenantId: M.id }), z(I.successMessage), s == null || s();
3169
+ } catch (N) {
3170
+ const O = N.message || I.errorMessage;
3171
+ P(O), o == null || o(O);
3111
3172
  } finally {
3112
- P(!1);
3173
+ A(!1);
3113
3174
  }
3114
3175
  }
3115
- }, c = async (z) => {
3116
- if (z.preventDefault(), !!b()) {
3117
- if (h !== R) {
3118
- M(L.passwordMismatchError), $({ confirmPassword: !0 });
3176
+ }, g = async (H) => {
3177
+ if (H.preventDefault(), !!c()) {
3178
+ if (u !== R) {
3179
+ P(I.passwordMismatchError), $({ confirmPassword: !0 });
3119
3180
  return;
3120
3181
  }
3121
- P(!0), M(""), q("");
3182
+ A(!0), P(""), z("");
3122
3183
  try {
3123
- await v({ token: f, newPassword: h }), q(L.resetSuccessMessage), s == null || s();
3124
- } catch (H) {
3125
- const O = H.message || L.errorMessage;
3126
- M(O), o == null || o(O);
3184
+ await v({ token: m, newPassword: u }), z(I.resetSuccessMessage), s == null || s();
3185
+ } catch (N) {
3186
+ const O = N.message || I.errorMessage;
3187
+ P(O), o == null || o(O);
3127
3188
  } finally {
3128
- P(!1);
3189
+ A(!1);
3129
3190
  }
3130
3191
  }
3131
- }, S = (z) => ({
3132
- ...l.input,
3133
- ...V[z] ? l.inputError : {}
3134
- }), G = () => ({
3135
- ...l.button,
3136
- ...U ? l.buttonLoading : {}
3192
+ }, w = (H) => ({
3193
+ ...a.input,
3194
+ ...G[H] ? a.inputError : {}
3195
+ }), j = () => ({
3196
+ ...a.button,
3197
+ ...q ? a.buttonLoading : {}
3137
3198
  });
3138
3199
  if (t === "reset") {
3139
- const z = f && h && R;
3140
- return /* @__PURE__ */ a("div", { className: A, style: l.container, children: [
3141
- /* @__PURE__ */ n("h2", { style: l.title, children: L.resetTitle }),
3142
- /* @__PURE__ */ n("p", { style: l.subtitle, children: L.resetSubtitle }),
3143
- /* @__PURE__ */ a("form", { onSubmit: c, style: l.form, children: [
3144
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3145
- /* @__PURE__ */ n("label", { style: l.label, children: L.tokenLabel }),
3200
+ const H = m && u && R;
3201
+ return /* @__PURE__ */ l("div", { className: k, style: a.container, children: [
3202
+ /* @__PURE__ */ n("h2", { style: a.title, children: I.resetTitle }),
3203
+ /* @__PURE__ */ n("p", { style: a.subtitle, children: I.resetSubtitle }),
3204
+ /* @__PURE__ */ l("form", { onSubmit: g, style: a.form, children: [
3205
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3206
+ /* @__PURE__ */ n("label", { style: a.label, children: I.tokenLabel }),
3146
3207
  /* @__PURE__ */ n(
3147
3208
  "input",
3148
3209
  {
3149
3210
  type: "text",
3150
- value: f,
3151
- onChange: (H) => {
3152
- p(H.target.value), V.token && $((O) => ({ ...O, token: !1 }));
3211
+ value: m,
3212
+ onChange: (N) => {
3213
+ f(N.target.value), G.token && $((O) => ({ ...O, token: !1 }));
3153
3214
  },
3154
- placeholder: L.tokenPlaceholder,
3155
- style: S("token"),
3156
- disabled: U
3215
+ placeholder: I.tokenPlaceholder,
3216
+ style: w("token"),
3217
+ disabled: q
3157
3218
  }
3158
3219
  )
3159
3220
  ] }),
3160
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3161
- /* @__PURE__ */ n("label", { style: l.label, children: L.newPasswordLabel }),
3221
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3222
+ /* @__PURE__ */ n("label", { style: a.label, children: I.newPasswordLabel }),
3162
3223
  /* @__PURE__ */ n(
3163
3224
  "input",
3164
3225
  {
3165
3226
  type: "password",
3166
- value: h,
3167
- onChange: (H) => {
3168
- m(H.target.value), V.newPassword && $((O) => ({ ...O, newPassword: !1 }));
3227
+ value: u,
3228
+ onChange: (N) => {
3229
+ y(N.target.value), G.newPassword && $((O) => ({ ...O, newPassword: !1 }));
3169
3230
  },
3170
- placeholder: L.newPasswordPlaceholder,
3171
- style: S("newPassword"),
3172
- disabled: U
3231
+ placeholder: I.newPasswordPlaceholder,
3232
+ style: w("newPassword"),
3233
+ disabled: q
3173
3234
  }
3174
3235
  )
3175
3236
  ] }),
3176
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3177
- /* @__PURE__ */ n("label", { style: l.label, children: L.confirmPasswordLabel }),
3237
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3238
+ /* @__PURE__ */ n("label", { style: a.label, children: I.confirmPasswordLabel }),
3178
3239
  /* @__PURE__ */ n(
3179
3240
  "input",
3180
3241
  {
3181
3242
  type: "password",
3182
3243
  value: R,
3183
- onChange: (H) => {
3184
- C(H.target.value), V.confirmPassword && $((O) => ({ ...O, confirmPassword: !1 })), u === L.passwordMismatchError && M("");
3244
+ onChange: (N) => {
3245
+ C(N.target.value), G.confirmPassword && $((O) => ({ ...O, confirmPassword: !1 })), d === I.passwordMismatchError && P("");
3185
3246
  },
3186
- placeholder: L.confirmPasswordPlaceholder,
3187
- style: S("confirmPassword"),
3188
- disabled: U
3247
+ placeholder: I.confirmPasswordPlaceholder,
3248
+ style: w("confirmPassword"),
3249
+ disabled: q
3189
3250
  }
3190
3251
  )
3191
3252
  ] }),
@@ -3193,44 +3254,44 @@ function qt({
3193
3254
  "button",
3194
3255
  {
3195
3256
  type: "submit",
3196
- disabled: !z || U,
3257
+ disabled: !H || q,
3197
3258
  style: {
3198
- ...G(),
3199
- ...!z || U ? l.buttonDisabled : {}
3259
+ ...j(),
3260
+ ...!H || q ? a.buttonDisabled : {}
3200
3261
  },
3201
- children: U ? L.resetLoadingText : L.resetSubmitButton
3262
+ children: q ? I.resetLoadingText : I.resetSubmitButton
3202
3263
  }
3203
3264
  ),
3204
- u && /* @__PURE__ */ n("div", { style: l.errorText, children: u }),
3205
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3265
+ d && /* @__PURE__ */ n("div", { style: a.errorText, children: d }),
3266
+ E && /* @__PURE__ */ n("div", { style: a.successText, children: E })
3206
3267
  ] }),
3207
- /* @__PURE__ */ a("div", { style: l.linkContainer, children: [
3208
- /* @__PURE__ */ n("a", { onClick: g, style: l.link, children: L.backToLoginLink }),
3209
- y && /* @__PURE__ */ a(B, { children: [
3268
+ /* @__PURE__ */ l("div", { style: a.linkContainer, children: [
3269
+ /* @__PURE__ */ n("a", { onClick: p, style: a.link, children: I.backToLoginLink }),
3270
+ b && /* @__PURE__ */ l(U, { children: [
3210
3271
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3211
- /* @__PURE__ */ n("a", { onClick: () => y("request"), style: l.link, children: "Request New Link" })
3272
+ /* @__PURE__ */ n("a", { onClick: () => b("request"), style: a.link, children: "Request New Link" })
3212
3273
  ] })
3213
3274
  ] })
3214
3275
  ] });
3215
3276
  }
3216
- const ee = w;
3217
- return /* @__PURE__ */ a("div", { className: A, style: l.container, children: [
3218
- /* @__PURE__ */ n("h2", { style: l.title, children: L.title }),
3219
- /* @__PURE__ */ n("p", { style: l.subtitle, children: L.subtitle }),
3220
- /* @__PURE__ */ a("form", { onSubmit: d, style: l.form, children: [
3221
- /* @__PURE__ */ a("div", { style: l.fieldGroup, children: [
3222
- /* @__PURE__ */ n("label", { style: l.label, children: L.emailLabel }),
3277
+ const Y = S;
3278
+ return /* @__PURE__ */ l("div", { className: k, style: a.container, children: [
3279
+ /* @__PURE__ */ n("h2", { style: a.title, children: I.title }),
3280
+ /* @__PURE__ */ n("p", { style: a.subtitle, children: I.subtitle }),
3281
+ /* @__PURE__ */ l("form", { onSubmit: h, style: a.form, children: [
3282
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3283
+ /* @__PURE__ */ n("label", { style: a.label, children: I.emailLabel }),
3223
3284
  /* @__PURE__ */ n(
3224
3285
  "input",
3225
3286
  {
3226
3287
  type: "email",
3227
- value: w,
3228
- onChange: (z) => {
3229
- T(z.target.value), V.email && $((H) => ({ ...H, email: !1 }));
3288
+ value: S,
3289
+ onChange: (H) => {
3290
+ T(H.target.value), G.email && $((N) => ({ ...N, email: !1 }));
3230
3291
  },
3231
- placeholder: L.emailPlaceholder,
3232
- style: S("email"),
3233
- disabled: U
3292
+ placeholder: I.emailPlaceholder,
3293
+ style: w("email"),
3294
+ disabled: q
3234
3295
  }
3235
3296
  )
3236
3297
  ] }),
@@ -3238,27 +3299,27 @@ function qt({
3238
3299
  "button",
3239
3300
  {
3240
3301
  type: "submit",
3241
- disabled: !ee || U,
3302
+ disabled: !Y || q,
3242
3303
  style: {
3243
- ...G(),
3244
- ...!ee || U ? l.buttonDisabled : {}
3304
+ ...j(),
3305
+ ...!Y || q ? a.buttonDisabled : {}
3245
3306
  },
3246
- children: U ? L.loadingText : L.submitButton
3307
+ children: q ? I.loadingText : I.submitButton
3247
3308
  }
3248
3309
  ),
3249
- u && /* @__PURE__ */ n("div", { style: l.errorText, children: u }),
3250
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3310
+ d && /* @__PURE__ */ n("div", { style: a.errorText, children: d }),
3311
+ E && /* @__PURE__ */ n("div", { style: a.successText, children: E })
3251
3312
  ] }),
3252
- /* @__PURE__ */ a("div", { style: l.linkContainer, children: [
3253
- /* @__PURE__ */ n("a", { onClick: g, style: l.link, children: L.backToLoginLink }),
3254
- y && /* @__PURE__ */ a(B, { children: [
3313
+ /* @__PURE__ */ l("div", { style: a.linkContainer, children: [
3314
+ /* @__PURE__ */ n("a", { onClick: p, style: a.link, children: I.backToLoginLink }),
3315
+ b && /* @__PURE__ */ l(U, { children: [
3255
3316
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3256
- /* @__PURE__ */ n("a", { onClick: () => y("reset"), style: l.link, children: "I have a token" })
3317
+ /* @__PURE__ */ n("a", { onClick: () => b("reset"), style: a.link, children: "I have a token" })
3257
3318
  ] })
3258
3319
  ] })
3259
3320
  ] });
3260
3321
  }
3261
- const pt = () => /* @__PURE__ */ n(
3322
+ const xt = () => /* @__PURE__ */ n(
3262
3323
  "div",
3263
3324
  {
3264
3325
  style: {
@@ -3270,7 +3331,7 @@ const pt = () => /* @__PURE__ */ n(
3270
3331
  },
3271
3332
  children: /* @__PURE__ */ n("div", { children: "Loading..." })
3272
3333
  }
3273
- ), ft = ({ error: i, retry: e }) => /* @__PURE__ */ a(
3334
+ ), kt = ({ error: i, retry: e }) => /* @__PURE__ */ l(
3274
3335
  "div",
3275
3336
  {
3276
3337
  style: {
@@ -3304,40 +3365,40 @@ const pt = () => /* @__PURE__ */ n(
3304
3365
  ]
3305
3366
  }
3306
3367
  );
3307
- function zt({
3368
+ function Jt({
3308
3369
  children: i,
3309
3370
  loadingFallback: e,
3310
3371
  errorFallback: t,
3311
3372
  requireTenant: r = !0
3312
3373
  }) {
3313
- 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) ?? (() => {
3314
- }), p = r && y && T, h = s || p && A, m = o || (p ? w : null), R = () => {
3315
- o && g(), w && y && f();
3374
+ const { isAppLoading: s, appError: o, retryApp: p } = oe(), b = Me(), k = (b == null ? void 0 : b.isTenantLoading) ?? !1, S = (b == null ? void 0 : b.tenantError) ?? null, T = (b == null ? void 0 : b.tenantSlug) ?? null, m = (b == null ? void 0 : b.retryTenant) ?? (() => {
3375
+ }), f = r && b && T, u = s || f && k, y = o || (f ? S : null), R = () => {
3376
+ o && p(), S && b && m();
3316
3377
  };
3317
- if (h)
3318
- return /* @__PURE__ */ n(B, { children: e || /* @__PURE__ */ n(pt, {}) });
3319
- if (m) {
3320
- const C = typeof t == "function" ? t(m, R) : t || /* @__PURE__ */ n(ft, { error: m, retry: R });
3321
- return /* @__PURE__ */ n(B, { children: C });
3378
+ if (u)
3379
+ return /* @__PURE__ */ n(U, { children: e || /* @__PURE__ */ n(xt, {}) });
3380
+ if (y) {
3381
+ const C = typeof t == "function" ? t(y, R) : t || /* @__PURE__ */ n(kt, { error: y, retry: R });
3382
+ return /* @__PURE__ */ n(U, { children: C });
3322
3383
  }
3323
- return /* @__PURE__ */ n(B, { children: i });
3384
+ return /* @__PURE__ */ n(U, { children: i });
3324
3385
  }
3325
- function Ot(i = !0) {
3326
- 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) ?? (() => {
3327
- }), f = i && o && w, p = e || f && g, h = t || (f ? y : null);
3386
+ function Yt(i = !0) {
3387
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: s } = oe(), o = Me(), p = (o == null ? void 0 : o.isTenantLoading) ?? !1, b = (o == null ? void 0 : o.tenantError) ?? null, k = (o == null ? void 0 : o.tenant) ?? null, S = (o == null ? void 0 : o.tenantSlug) ?? null, T = (o == null ? void 0 : o.retryTenant) ?? (() => {
3388
+ }), m = i && o && S, f = e || m && p, u = t || (m ? b : null);
3328
3389
  return {
3329
- isLoading: p,
3330
- error: h,
3331
- isReady: !p && !h && s !== null && (!f || A !== null),
3390
+ isLoading: f,
3391
+ error: u,
3392
+ isReady: !f && !u && s !== null && (!m || k !== null),
3332
3393
  retry: () => {
3333
- t && r(), y && o && T();
3394
+ t && r(), b && o && T();
3334
3395
  },
3335
3396
  // Individual states
3336
3397
  app: { isLoading: e, error: t, data: s },
3337
- tenant: o ? { isLoading: g, error: y, data: A } : null
3398
+ tenant: o ? { isLoading: p, error: b, data: k } : null
3338
3399
  };
3339
3400
  }
3340
- class Wt {
3401
+ class Qt {
3341
3402
  constructor(e, t) {
3342
3403
  this.httpService = e, this.sessionManager = t;
3343
3404
  }
@@ -3405,7 +3466,7 @@ class Wt {
3405
3466
  };
3406
3467
  }
3407
3468
  }
3408
- class jt {
3469
+ class Xt {
3409
3470
  constructor(e, t) {
3410
3471
  this.httpService = e, this.sessionManager = t;
3411
3472
  }
@@ -3456,7 +3517,7 @@ class jt {
3456
3517
  });
3457
3518
  }
3458
3519
  }
3459
- class Vt {
3520
+ class Zt {
3460
3521
  constructor(e) {
3461
3522
  this.httpService = e;
3462
3523
  }
@@ -3465,7 +3526,7 @@ class Vt {
3465
3526
  return await this.httpService.get("/health");
3466
3527
  }
3467
3528
  }
3468
- class Gt {
3529
+ class er {
3469
3530
  // Date string to Date object
3470
3531
  static toDate(e) {
3471
3532
  return new Date(e);
@@ -3588,47 +3649,47 @@ class Gt {
3588
3649
  }
3589
3650
  }
3590
3651
  export {
3591
- Gt as ApiMappers,
3592
- Se as AppApiService,
3593
- zt as AppLoader,
3594
- xt as AppProvider,
3595
- He as AuthApiService,
3596
- Mt as AuthProvider,
3597
- Dt as FeatureFlag,
3598
- ze as FeatureFlagApiService,
3599
- It as FeatureFlagProvider,
3600
- Vt as HealthApiService,
3652
+ er as ApiMappers,
3653
+ ve as AppApiService,
3654
+ Jt as AppLoader,
3655
+ Et as AppProvider,
3656
+ Ue as AuthApiService,
3657
+ Dt as AuthProvider,
3658
+ Wt as FeatureFlag,
3659
+ Je as FeatureFlagApiService,
3660
+ Ht as FeatureFlagProvider,
3661
+ Zt as HealthApiService,
3601
3662
  re as HttpService,
3602
- $t as LandingRoute,
3603
- Ht as LoginForm,
3604
- Bt as MagicLinkForm,
3605
- Ut as MagicLinkVerify,
3606
- qt as PasswordRecoveryForm,
3607
- Wt as PermissionApiService,
3608
- Et as Protected,
3609
- Rt as ProtectedRoute,
3610
- ve as RoleApiService,
3611
- ye as SessionManager,
3612
- Nt as SignupForm,
3613
- We as SubscriptionApiService,
3614
- Ft as SubscriptionGuard,
3615
- jt as SubscriptionPlanApiService,
3616
- Lt as SubscriptionProvider,
3663
+ zt as LandingRoute,
3664
+ jt as LoginForm,
3665
+ _t as MagicLinkForm,
3666
+ Gt as MagicLinkVerify,
3667
+ Kt as PasswordRecoveryForm,
3668
+ Qt as PermissionApiService,
3669
+ Bt as Protected,
3670
+ Ut as ProtectedRoute,
3671
+ xe as RoleApiService,
3672
+ we as SessionManager,
3673
+ Vt as SignupForm,
3674
+ Qe as SubscriptionApiService,
3675
+ Ot as SubscriptionGuard,
3676
+ Xt as SubscriptionPlanApiService,
3677
+ Nt as SubscriptionProvider,
3617
3678
  ue as TenantApiService,
3618
- At as TenantProvider,
3619
- Ct as TenantRoute,
3620
- Ne as UserApiService,
3679
+ Ct as TenantProvider,
3680
+ qt as TenantRoute,
3681
+ qe as UserApiService,
3621
3682
  ie as UserType,
3622
- kt as useApi,
3683
+ Rt as useApi,
3623
3684
  oe as useApp,
3624
- Ot as useAppLoaderState,
3685
+ Yt as useAppLoaderState,
3625
3686
  ae as useAuth,
3626
- Oe as useFeatureFlags,
3627
- Pt as useSettings,
3628
- je as useSubscription,
3629
- fe as useTenant,
3687
+ Ye as useFeatureFlags,
3688
+ Ft as useSettings,
3689
+ Xe as useSubscription,
3690
+ me as useTenant,
3630
3691
  se as useTenantInfo,
3631
- Pe as useTenantOptional,
3632
- Tt as useTenantSettings
3692
+ Me as useTenantOptional,
3693
+ $t as useTenantSettings
3633
3694
  };
3634
3695
  //# sourceMappingURL=index.es.js.map