@skylabs-digital/react-identity-access 2.0.1 → 2.2.0

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