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