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