@skylabs-digital/react-identity-access 2.15.0 → 2.17.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,7 +1,7 @@
1
- import { jsx as s, Fragment as _, jsxs as d } from "react/jsx-runtime";
2
- import { createContext as ue, useMemo as Z, useState as A, useCallback as re, useEffect as X, useContext as ie, useRef as Ve } from "react";
3
- import { useLocation as be, Navigate as me, useNavigate as ut, useSearchParams as ht } from "react-router-dom";
4
- class oe {
1
+ import { jsx as s, Fragment as _, jsxs as c } from "react/jsx-runtime";
2
+ import { createContext as ue, useMemo as J, useState as x, useCallback as se, useEffect as ee, useContext as oe, useRef as Ge } from "react";
3
+ import { useLocation as Se, Navigate as ye, useNavigate as gt, useSearchParams as pt } from "react-router-dom";
4
+ class ae {
5
5
  // SessionManager instance
6
6
  constructor(e, t = 1e4) {
7
7
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
@@ -23,33 +23,33 @@ class oe {
23
23
  };
24
24
  if (!(i != null && i.skipAuth) && this.sessionManager)
25
25
  try {
26
- const b = await this.sessionManager.getAuthHeaders();
27
- f = { ...f, ...b };
28
- } catch (b) {
29
- console.warn("Failed to inject auth headers:", b);
26
+ const m = await this.sessionManager.getAuthHeaders();
27
+ f = { ...f, ...m };
28
+ } catch (m) {
29
+ console.warn("Failed to inject auth headers:", m);
30
30
  }
31
- const w = new AbortController(), u = setTimeout(() => w.abort(), p);
31
+ const w = new AbortController(), d = setTimeout(() => w.abort(), p);
32
32
  try {
33
- const b = await fetch(a, {
33
+ const m = await fetch(a, {
34
34
  method: e,
35
35
  headers: f,
36
36
  body: n ? JSON.stringify(n) : void 0,
37
37
  signal: w.signal
38
38
  });
39
- if (clearTimeout(u), b.status === 401 && !(i != null && i.skipRetry) && !o && this.sessionManager)
39
+ if (clearTimeout(d), m.status === 401 && !(i != null && i.skipRetry) && !o && this.sessionManager)
40
40
  try {
41
- const T = this.sessionManager.getTokens();
42
- if (T != null && T.refreshToken)
41
+ const v = this.sessionManager.getTokens();
42
+ if (v != null && v.refreshToken)
43
43
  return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, n, i, !0);
44
44
  } catch {
45
- throw new Error(`HTTP ${b.status}: ${b.statusText}`);
45
+ throw new Error(`HTTP ${m.status}: ${m.statusText}`);
46
46
  }
47
- if (!b.ok)
48
- throw new Error(`HTTP ${b.status}: ${b.statusText}`);
49
- const g = b.headers.get("content-type");
50
- return !g || !g.includes("application/json") ? {} : await b.json();
51
- } catch (b) {
52
- throw clearTimeout(u), b instanceof Error && b.name === "AbortError" ? new Error(`Request timeout after ${p}ms`) : b;
47
+ if (!m.ok)
48
+ throw new Error(`HTTP ${m.status}: ${m.statusText}`);
49
+ const h = m.headers.get("content-type");
50
+ return !h || !h.includes("application/json") ? {} : await m.json();
51
+ } catch (m) {
52
+ throw clearTimeout(d), m instanceof Error && m.name === "AbortError" ? new Error(`Request timeout after ${p}ms`) : m;
53
53
  }
54
54
  }
55
55
  async get(e, t) {
@@ -65,7 +65,7 @@ class oe {
65
65
  return this.request("DELETE", e, void 0, t);
66
66
  }
67
67
  }
68
- class He {
68
+ class qe {
69
69
  constructor(e, t) {
70
70
  this.httpService = e, this.sessionManager = t;
71
71
  }
@@ -124,32 +124,32 @@ class He {
124
124
  })).data;
125
125
  }
126
126
  }
127
- const Ie = ue(null);
128
- function hn({ config: r, children: e }) {
129
- const t = Z(
127
+ const Le = ue(null);
128
+ function pn({ config: r, children: e }) {
129
+ const t = J(
130
130
  () => {
131
- var g, T, I;
131
+ var h, v, I;
132
132
  return {
133
- enabled: ((g = r.cache) == null ? void 0 : g.enabled) ?? !0,
134
- ttl: ((T = r.cache) == null ? void 0 : T.ttl) ?? 3e5,
133
+ enabled: ((h = r.cache) == null ? void 0 : h.enabled) ?? !0,
134
+ ttl: ((v = r.cache) == null ? void 0 : v.ttl) ?? 3e5,
135
135
  // 5 minutes default
136
136
  storageKey: ((I = r.cache) == null ? void 0 : I.storageKey) ?? `app_cache_${r.appId}`
137
137
  };
138
138
  },
139
139
  [r.cache, r.appId]
140
- ), [n, i] = A(() => {
140
+ ), [n, i] = x(() => {
141
141
  if (!t.enabled) return null;
142
142
  try {
143
- const g = localStorage.getItem(t.storageKey);
144
- if (!g) return null;
145
- const T = JSON.parse(g);
146
- return Date.now() - T.timestamp < t.ttl && T.appId === r.appId ? T.data : (localStorage.removeItem(t.storageKey), null);
143
+ const h = localStorage.getItem(t.storageKey);
144
+ if (!h) return null;
145
+ const v = JSON.parse(h);
146
+ return Date.now() - v.timestamp < t.ttl && v.appId === r.appId ? v.data : (localStorage.removeItem(t.storageKey), null);
147
147
  } catch {
148
148
  return null;
149
149
  }
150
- }), [o, a] = A(!n), [p, f] = A(null), w = Z(() => {
151
- const g = () => {
152
- u();
150
+ }), [o, a] = x(!n), [p, f] = x(null), w = J(() => {
151
+ const h = () => {
152
+ d();
153
153
  };
154
154
  return {
155
155
  appId: r.appId,
@@ -158,18 +158,18 @@ function hn({ config: r, children: e }) {
158
158
  appInfo: n,
159
159
  isAppLoading: o,
160
160
  appError: p,
161
- retryApp: g
161
+ retryApp: h
162
162
  };
163
- }, [r, n, o, p]), u = re(
164
- async (g = !1) => {
165
- if (!(!g && t.enabled && n))
163
+ }, [r, n, o, p]), d = se(
164
+ async (h = !1) => {
165
+ if (!(!h && t.enabled && n))
166
166
  try {
167
167
  a(!0), f(null);
168
- const T = new oe(r.baseUrl), N = await new He(T, {}).getPublicAppInfo(r.appId);
169
- if (i(N), t.enabled)
168
+ const v = new ae(r.baseUrl), F = await new qe(v, {}).getPublicAppInfo(r.appId);
169
+ if (i(F), t.enabled)
170
170
  try {
171
171
  const M = {
172
- data: N,
172
+ data: F,
173
173
  timestamp: Date.now(),
174
174
  appId: r.appId
175
175
  };
@@ -177,49 +177,49 @@ function hn({ config: r, children: e }) {
177
177
  } catch (M) {
178
178
  console.warn("Failed to cache app info:", M);
179
179
  }
180
- } catch (T) {
181
- const I = T instanceof Error ? T : new Error("Failed to load app information");
180
+ } catch (v) {
181
+ const I = v instanceof Error ? v : new Error("Failed to load app information");
182
182
  f(I), i(null);
183
183
  } finally {
184
184
  a(!1);
185
185
  }
186
186
  },
187
187
  [r.baseUrl, r.appId, t, n]
188
- ), b = re(async () => {
188
+ ), m = se(async () => {
189
189
  if (!(!t.enabled || !n))
190
190
  try {
191
- const g = localStorage.getItem(t.storageKey);
192
- if (!g) return;
193
- const T = JSON.parse(g);
194
- if (Date.now() - T.timestamp > t.ttl * 0.5) {
195
- const N = new oe(r.baseUrl), P = await new He(N, {}).getPublicAppInfo(r.appId);
191
+ const h = localStorage.getItem(t.storageKey);
192
+ if (!h) return;
193
+ const v = JSON.parse(h);
194
+ if (Date.now() - v.timestamp > t.ttl * 0.5) {
195
+ const F = new ae(r.baseUrl), P = await new qe(F, {}).getPublicAppInfo(r.appId);
196
196
  i(P);
197
- const h = {
197
+ const u = {
198
198
  data: P,
199
199
  timestamp: Date.now(),
200
200
  appId: r.appId
201
201
  };
202
- localStorage.setItem(t.storageKey, JSON.stringify(h));
202
+ localStorage.setItem(t.storageKey, JSON.stringify(u));
203
203
  }
204
- } catch (g) {
205
- console.warn("Background app refresh failed:", g);
204
+ } catch (h) {
205
+ console.warn("Background app refresh failed:", h);
206
206
  }
207
207
  }, [r, t, n]);
208
- return X(() => {
209
- n ? b() : u();
210
- }, []), /* @__PURE__ */ s(Ie.Provider, { value: w, children: e });
208
+ return ee(() => {
209
+ n ? m() : d();
210
+ }, []), /* @__PURE__ */ s(Le.Provider, { value: w, children: e });
211
211
  }
212
- function ye() {
213
- const r = ie(Ie);
212
+ function we() {
213
+ const r = oe(Le);
214
214
  if (!r)
215
215
  throw new Error("useApp must be used within an AppProvider");
216
216
  return r;
217
217
  }
218
- function je() {
219
- return ie(Ie);
218
+ function Ze() {
219
+ return oe(Le);
220
220
  }
221
- const gn = ye;
222
- class xe {
221
+ const fn = we;
222
+ class Re {
223
223
  constructor(e = {}) {
224
224
  this.refreshPromise = null, this.refreshQueue = [], e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : this.storageKey = e.storageKey || "auth_tokens", this.autoRefresh = e.autoRefresh ?? !0, this.refreshThreshold = e.refreshThreshold || 3e5, this.onRefreshFailed = e.onRefreshFailed, this.baseUrl = e.baseUrl || "", this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey);
225
225
  }
@@ -372,7 +372,7 @@ class xe {
372
372
  return e !== null && !this.isTokenExpired(e);
373
373
  }
374
374
  }
375
- class gt {
375
+ class ft {
376
376
  constructor(e) {
377
377
  this.httpService = e;
378
378
  }
@@ -428,7 +428,7 @@ class gt {
428
428
  });
429
429
  }
430
430
  }
431
- class Be {
431
+ class Oe {
432
432
  constructor(e, t) {
433
433
  this.httpService = e, this.sessionManager = t;
434
434
  }
@@ -504,7 +504,7 @@ class Be {
504
504
  };
505
505
  }
506
506
  }
507
- class pt {
507
+ class mt {
508
508
  constructor(e, t) {
509
509
  this.httpService = e, this.sessionManager = t;
510
510
  }
@@ -544,7 +544,7 @@ class pt {
544
544
  });
545
545
  }
546
546
  }
547
- class fe {
547
+ class me {
548
548
  constructor(e, t, n) {
549
549
  this.httpService = e, this.appId = t, this.sessionManager = n;
550
550
  }
@@ -622,7 +622,7 @@ class fe {
622
622
  )).data;
623
623
  }
624
624
  }
625
- function ft(r, e) {
625
+ function yt(r, e) {
626
626
  if (r === "localhost" || r.startsWith("127.") || r.startsWith("192.168."))
627
627
  return null;
628
628
  if (e) {
@@ -638,26 +638,26 @@ function ft(r, e) {
638
638
  const n = r.split(".");
639
639
  return n.length >= 3 && n[0] !== "www" ? n[0] : null;
640
640
  }
641
- function mt(r, e = "tenant", t) {
641
+ function wt(r, e = "tenant", t) {
642
642
  const i = new URLSearchParams(r).get(e);
643
643
  return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
644
644
  }
645
- function yt(r, e, t) {
646
- const { tenantMode: n, baseDomain: i, selectorParam: o } = r;
647
- return n === "subdomain" ? ft(e.hostname, i) : n === "selector" ? mt(e.search, o, t) : null;
645
+ function bt(r, e, t) {
646
+ const { tenantMode: n, baseDomain: i, selectorParam: o, fixedTenantSlug: a } = r;
647
+ return n === "fixed" ? a || null : n === "subdomain" ? yt(e.hostname, i) : n === "selector" ? wt(e.search, o, t) : null;
648
648
  }
649
- function wt(r, e, t) {
649
+ function St(r, e, t) {
650
650
  if (t)
651
651
  return `${r}.${t}`;
652
652
  const n = e.split(".");
653
653
  return n.length === 2 ? `${r}.${e}` : n.length >= 3 ? (n[0] = r, n.join(".")) : null;
654
654
  }
655
655
  const de = "_auth";
656
- function qe(r) {
656
+ function ze(r) {
657
657
  const e = JSON.stringify(r);
658
658
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
659
659
  }
660
- function bt(r) {
660
+ function vt(r) {
661
661
  try {
662
662
  let e = r.replace(/-/g, "+").replace(/_/g, "/");
663
663
  for (; e.length % 4; )
@@ -668,7 +668,7 @@ function bt(r) {
668
668
  return null;
669
669
  }
670
670
  }
671
- function St() {
671
+ function Tt() {
672
672
  if (typeof window > "u")
673
673
  return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
674
674
  const e = new URLSearchParams(window.location.search).get(de);
@@ -677,7 +677,7 @@ function St() {
677
677
  searchParams: window.location.search,
678
678
  encodedLength: e == null ? void 0 : e.length
679
679
  }), !e) return null;
680
- const t = bt(e);
680
+ const t = vt(e);
681
681
  return console.log("[CrossDomainAuth] Token decode result:", {
682
682
  success: !!t,
683
683
  hasAccessToken: !!(t != null && t.accessToken),
@@ -685,7 +685,7 @@ function St() {
685
685
  expiresIn: t == null ? void 0 : t.expiresIn
686
686
  }), t;
687
687
  }
688
- function vt() {
688
+ function kt() {
689
689
  if (typeof window > "u") return;
690
690
  const r = new URL(window.location.href);
691
691
  r.searchParams.delete(de), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
@@ -693,131 +693,133 @@ function vt() {
693
693
  newUrl: r.toString()
694
694
  }), window.history.replaceState({}, "", r.toString());
695
695
  }
696
- const Me = ue(null);
697
- function pn({ config: r, children: e }) {
698
- const { baseUrl: t, appInfo: n, appId: i } = ye(), o = re(() => typeof window > "u" ? null : yt(
696
+ const Ee = ue(null);
697
+ function mn({ config: r, children: e }) {
698
+ const { baseUrl: t, appInfo: n, appId: i } = we(), o = se(() => typeof window > "u" ? null : bt(
699
699
  {
700
700
  tenantMode: r.tenantMode || "selector",
701
701
  baseDomain: r.baseDomain,
702
- selectorParam: r.selectorParam
702
+ selectorParam: r.selectorParam,
703
+ fixedTenantSlug: r.fixedTenantSlug
703
704
  },
704
705
  {
705
706
  hostname: window.location.hostname,
706
707
  search: window.location.search
707
708
  },
708
709
  window.localStorage
709
- ), [r.tenantMode, r.baseDomain, r.selectorParam]), [a, p] = A(() => o()), f = Z(
710
+ ), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [a, p] = x(() => o()), f = J(
710
711
  () => {
711
- var c, H, F;
712
+ var g, C, T;
712
713
  return {
713
- enabled: ((c = r.cache) == null ? void 0 : c.enabled) ?? !0,
714
- ttl: ((H = r.cache) == null ? void 0 : H.ttl) ?? 5 * 60 * 1e3,
714
+ enabled: ((g = r.cache) == null ? void 0 : g.enabled) ?? !0,
715
+ ttl: ((C = r.cache) == null ? void 0 : C.ttl) ?? 5 * 60 * 1e3,
715
716
  // 5 minutes default
716
- storageKey: ((F = r.cache) == null ? void 0 : F.storageKey) ?? `tenant_cache_${a || "default"}`
717
+ storageKey: ((T = r.cache) == null ? void 0 : T.storageKey) ?? `tenant_cache_${a || "default"}`
717
718
  };
718
719
  },
719
720
  [r.cache, a]
720
- ), [w, u] = A(() => {
721
+ ), [w, d] = x(() => {
721
722
  if (r.initialTenant) return r.initialTenant;
722
723
  if (!f.enabled || !a) return null;
723
724
  try {
724
- const c = localStorage.getItem(f.storageKey);
725
- if (!c) return null;
726
- const H = JSON.parse(c);
727
- return Date.now() - H.timestamp < f.ttl && H.tenantSlug === a ? H.data : (localStorage.removeItem(f.storageKey), null);
725
+ const g = localStorage.getItem(f.storageKey);
726
+ if (!g) return null;
727
+ const C = JSON.parse(g);
728
+ return Date.now() - C.timestamp < f.ttl && C.tenantSlug === a ? C.data : (localStorage.removeItem(f.storageKey), null);
728
729
  } catch {
729
730
  return null;
730
731
  }
731
- }), [b, g] = A(!w && !r.initialTenant), [T, I] = A(null), [N, M] = A(null), [P, h] = A(!1), [x, S] = A(null);
732
- X(() => {
733
- const c = o();
734
- p(c);
735
- }, [o]);
736
- const L = (n == null ? void 0 : n.settingsSchema) || null, E = re(
737
- async (c, H = !1) => {
738
- if (!(!H && f.enabled && w && w.domain === c))
732
+ }), [m, h] = x(!w && !r.initialTenant), [v, I] = x(null), [F, M] = x(null), [P, u] = x(!1), [A, b] = x(null);
733
+ ee(() => {
734
+ if (r.tenantMode === "fixed") return;
735
+ const g = o();
736
+ p(g);
737
+ }, [o, r.tenantMode]);
738
+ const L = (n == null ? void 0 : n.settingsSchema) || null, E = se(
739
+ async (g, C = !1) => {
740
+ if (!(!C && f.enabled && w && w.domain === g))
739
741
  try {
740
- g(!0), I(null);
741
- const F = new oe(t), m = await new fe(F, i).getPublicTenantInfo(c);
742
- if (u(m), f.enabled)
742
+ h(!0), I(null);
743
+ const T = new ae(t), y = await new me(T, i).getPublicTenantInfo(g);
744
+ if (d(y), f.enabled)
743
745
  try {
744
- const v = {
745
- data: m,
746
+ const k = {
747
+ data: y,
746
748
  timestamp: Date.now(),
747
- tenantSlug: c
749
+ tenantSlug: g
748
750
  };
749
- localStorage.setItem(f.storageKey, JSON.stringify(v));
750
- } catch (v) {
751
- console.warn("Failed to cache tenant info:", v);
751
+ localStorage.setItem(f.storageKey, JSON.stringify(k));
752
+ } catch (k) {
753
+ console.warn("Failed to cache tenant info:", k);
752
754
  }
753
- } catch (F) {
754
- const y = F instanceof Error ? F : new Error("Failed to load tenant information");
755
- I(y), u(null);
755
+ } catch (T) {
756
+ const S = T instanceof Error ? T : new Error("Failed to load tenant information");
757
+ I(S), d(null);
756
758
  } finally {
757
- g(!1);
759
+ h(!1);
758
760
  }
759
761
  },
760
762
  [t, i, f, w]
761
- ), C = re(async () => {
763
+ ), N = se(async () => {
762
764
  if (!(!f.enabled || !w || !a))
763
765
  try {
764
- const c = localStorage.getItem(f.storageKey);
765
- if (!c) return;
766
- const H = JSON.parse(c);
767
- if (Date.now() - H.timestamp > f.ttl * 0.5) {
768
- const y = new oe(t), v = await new fe(y, i).getPublicTenantInfo(a);
769
- u(v);
770
- const G = {
771
- data: v,
766
+ const g = localStorage.getItem(f.storageKey);
767
+ if (!g) return;
768
+ const C = JSON.parse(g);
769
+ if (Date.now() - C.timestamp > f.ttl * 0.5) {
770
+ const S = new ae(t), k = await new me(S, i).getPublicTenantInfo(a);
771
+ d(k);
772
+ const j = {
773
+ data: k,
772
774
  timestamp: Date.now(),
773
775
  tenantSlug: a
774
776
  };
775
- localStorage.setItem(f.storageKey, JSON.stringify(G));
777
+ localStorage.setItem(f.storageKey, JSON.stringify(j));
776
778
  }
777
- } catch (c) {
778
- console.warn("Background tenant refresh failed:", c);
779
+ } catch (g) {
780
+ console.warn("Background tenant refresh failed:", g);
779
781
  }
780
- }, [t, i, f, w, a]), R = re(async () => {
782
+ }, [t, i, f, w, a]), R = se(async () => {
781
783
  if (w != null && w.id)
782
784
  try {
783
- h(!0), S(null);
784
- const c = new oe(t), F = await new fe(c, w.appId).getTenantSettings(w.id);
785
- M(F);
786
- } catch (c) {
787
- const H = c instanceof Error ? c : new Error("Failed to load tenant settings");
788
- S(H), M(null);
785
+ u(!0), b(null);
786
+ const g = new ae(t), T = await new me(g, w.appId).getTenantSettings(w.id);
787
+ M(T);
788
+ } catch (g) {
789
+ const C = g instanceof Error ? g : new Error("Failed to load tenant settings");
790
+ b(C), M(null);
789
791
  } finally {
790
- h(!1);
792
+ u(!1);
791
793
  }
792
- }, [t, w]), $ = re(() => {
794
+ }, [t, w]), U = se(() => {
793
795
  R();
794
- }, [R]), l = re(
795
- (c) => {
796
+ }, [R]), l = se(
797
+ (g) => {
796
798
  if (!L)
797
799
  return { isValid: !0, errors: [] };
798
- const H = [];
800
+ const C = [];
799
801
  try {
800
- return L.properties && Object.entries(L.properties).forEach(([F, y]) => {
801
- var v;
802
- const m = c[F];
803
- if ((v = L.required) != null && v.includes(F) && m == null) {
804
- H.push(`Field '${F}' is required`);
802
+ return L.properties && Object.entries(L.properties).forEach(([T, S]) => {
803
+ var k;
804
+ const y = g[T];
805
+ if ((k = L.required) != null && k.includes(T) && y == null) {
806
+ C.push(`Field '${T}' is required`);
805
807
  return;
806
808
  }
807
- if (m != null) {
808
- if (y.type) {
809
- const G = y.type, Y = typeof m;
810
- G === "string" && Y !== "string" ? H.push(`Field '${F}' must be a string`) : (G === "number" || G === "integer") && Y !== "number" ? H.push(`Field '${F}' must be a number`) : G === "boolean" && Y !== "boolean" ? H.push(`Field '${F}' must be a boolean`) : G === "array" && !Array.isArray(m) && H.push(`Field '${F}' must be an array`);
809
+ if (y != null) {
810
+ if (S.type) {
811
+ const j = S.type, Z = typeof y;
812
+ j === "string" && Z !== "string" ? C.push(`Field '${T}' must be a string`) : (j === "number" || j === "integer") && Z !== "number" ? C.push(`Field '${T}' must be a number`) : j === "boolean" && Z !== "boolean" ? C.push(`Field '${T}' must be a boolean`) : j === "array" && !Array.isArray(y) && C.push(`Field '${T}' must be an array`);
811
813
  }
812
- y.minLength !== void 0 && typeof m == "string" && m.length < y.minLength && H.push(
813
- `Field '${F}' must be at least ${y.minLength} characters long`
814
- ), y.maxLength !== void 0 && typeof m == "string" && m.length > y.maxLength && H.push(
815
- `Field '${F}' must be no more than ${y.maxLength} characters long`
816
- ), y.minimum !== void 0 && typeof m == "number" && m < y.minimum && H.push(`Field '${F}' must be at least ${y.minimum}`), y.maximum !== void 0 && typeof m == "number" && m > y.maximum && H.push(`Field '${F}' must be no more than ${y.maximum}`), y.pattern && typeof m == "string" && (new RegExp(y.pattern).test(m) || H.push(`Field '${F}' does not match the required pattern`)), y.enum && !y.enum.includes(m) && H.push(`Field '${F}' must be one of: ${y.enum.join(", ")}`);
814
+ S.minLength !== void 0 && typeof y == "string" && y.length < S.minLength && C.push(
815
+ `Field '${T}' must be at least ${S.minLength} characters long`
816
+ ), S.maxLength !== void 0 && typeof y == "string" && y.length > S.maxLength && C.push(
817
+ `Field '${T}' must be no more than ${S.maxLength} characters long`
818
+ ), S.minimum !== void 0 && typeof y == "number" && y < S.minimum && C.push(`Field '${T}' must be at least ${S.minimum}`), S.maximum !== void 0 && typeof y == "number" && y > S.maximum && C.push(`Field '${T}' must be no more than ${S.maximum}`), S.pattern && typeof y == "string" && (new RegExp(S.pattern).test(y) || C.push(`Field '${T}' does not match the required pattern`)), S.enum && !S.enum.includes(y) && C.push(`Field '${T}' must be one of: ${S.enum.join(", ")}`);
817
819
  }
818
820
  }), {
819
- isValid: H.length === 0,
820
- errors: H
821
+ isValid: C.length === 0,
822
+ errors: C
821
823
  };
822
824
  } catch {
823
825
  return {
@@ -828,88 +830,95 @@ function pn({ config: r, children: e }) {
828
830
  },
829
831
  [L]
830
832
  );
831
- X(() => {
832
- !r.initialTenant && a ? w ? C() : E(a) : !r.initialTenant && !a && (u(null), I(null), g(!1));
833
- }, [r.initialTenant, a, w, E, C]), X(() => {
834
- w != null && w.id ? R() : (M(null), S(null), h(!1));
833
+ ee(() => {
834
+ !r.initialTenant && a ? w ? N() : E(a) : !r.initialTenant && !a && (d(null), I(null), h(!1));
835
+ }, [r.initialTenant, a, w, E, N]), ee(() => {
836
+ w != null && w.id ? R() : (M(null), b(null), u(!1));
835
837
  }, [w == null ? void 0 : w.id, R]);
836
- const D = re(
837
- (c, H) => {
838
- const { mode: F = "reload", tokens: y, redirectPath: m } = H || {}, v = r.tenantMode || "selector";
839
- if (localStorage.setItem("tenant", c), v === "subdomain") {
840
- const G = window.location.hostname, Y = wt(
841
- c,
842
- G,
838
+ const D = se(
839
+ (g, C) => {
840
+ const { mode: T = "reload", tokens: S, redirectPath: y } = C || {}, k = r.tenantMode || "selector";
841
+ if (k === "fixed") {
842
+ console.warn(
843
+ "[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
844
+ r.fixedTenantSlug
845
+ ), y && (window.location.href = y);
846
+ return;
847
+ }
848
+ if (localStorage.setItem("tenant", g), k === "subdomain") {
849
+ const j = window.location.hostname, Z = St(
850
+ g,
851
+ j,
843
852
  r.baseDomain
844
853
  );
845
- if (!Y) {
854
+ if (!Z) {
846
855
  console.warn(
847
856
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
848
- G
857
+ j
849
858
  );
850
859
  return;
851
860
  }
852
- const q = m || window.location.pathname, O = new URL(`${window.location.protocol}//${Y}${q}`);
853
- new URLSearchParams(window.location.search).forEach((k, K) => {
854
- K !== de && O.searchParams.set(K, k);
855
- }), y && O.searchParams.set(de, qe(y)), window.location.href = O.toString();
856
- } else if (v === "selector") {
857
- const G = m || window.location.pathname, Y = new URLSearchParams(window.location.search);
858
- if (Y.set(r.selectorParam || "tenant", c), Y.delete(de), y && Y.set(de, qe(y)), F === "reload") {
859
- const q = `${G}?${Y.toString()}${window.location.hash}`;
860
- window.location.href = q;
861
+ const O = y || window.location.pathname, q = new URL(`${window.location.protocol}//${Z}${O}`);
862
+ new URLSearchParams(window.location.search).forEach((B, X) => {
863
+ X !== de && q.searchParams.set(X, B);
864
+ }), S && q.searchParams.set(de, ze(S)), window.location.href = q.toString();
865
+ } else if (k === "selector") {
866
+ const j = y || window.location.pathname, Z = new URLSearchParams(window.location.search);
867
+ if (Z.set(r.selectorParam || "tenant", g), Z.delete(de), S && Z.set(de, ze(S)), T === "reload") {
868
+ const O = `${j}?${Z.toString()}${window.location.hash}`;
869
+ window.location.href = O;
861
870
  } else {
862
- const q = `${G}?${Y.toString()}${window.location.hash}`;
863
- window.history.pushState({}, "", q), p(c), E(c);
871
+ const O = `${j}?${Z.toString()}${window.location.hash}`;
872
+ window.history.pushState({}, "", O), p(g), E(g);
864
873
  }
865
874
  }
866
875
  },
867
876
  [r.tenantMode, r.selectorParam, r.baseDomain, E]
868
- ), U = Z(() => ({
877
+ ), $ = J(() => ({
869
878
  // Tenant info
870
879
  tenant: w,
871
880
  tenantSlug: a,
872
- isTenantLoading: b,
873
- tenantError: T,
881
+ isTenantLoading: m,
882
+ tenantError: v,
874
883
  retryTenant: () => {
875
884
  a && E(a);
876
885
  },
877
886
  // Settings
878
- settings: N,
887
+ settings: F,
879
888
  settingsSchema: L,
880
889
  isSettingsLoading: P,
881
- settingsError: x,
890
+ settingsError: A,
882
891
  // Actions
883
- refreshSettings: $,
892
+ refreshSettings: U,
884
893
  switchTenant: D,
885
894
  // Validation
886
895
  validateSettings: l
887
896
  }), [
888
897
  w,
889
898
  a,
890
- b,
891
- T,
892
- N,
899
+ m,
900
+ v,
901
+ F,
893
902
  L,
894
903
  P,
895
- x,
896
- $,
904
+ A,
905
+ U,
897
906
  D,
898
907
  l
899
908
  ]);
900
- return /* @__PURE__ */ s(Me.Provider, { value: U, children: e });
909
+ return /* @__PURE__ */ s(Ee.Provider, { value: $, children: e });
901
910
  }
902
911
  function he() {
903
- const r = ie(Me);
912
+ const r = oe(Ee);
904
913
  if (!r)
905
914
  throw new Error("useTenant must be used within a TenantProvider");
906
915
  return r;
907
916
  }
908
- function Se() {
909
- return ie(Me);
917
+ function ve() {
918
+ return oe(Ee);
910
919
  }
911
- const fn = he;
912
- function mn() {
920
+ const yn = he;
921
+ function wn() {
913
922
  const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = he();
914
923
  return {
915
924
  settings: r,
@@ -929,305 +938,305 @@ function ge() {
929
938
  retry: i
930
939
  };
931
940
  }
932
- const Le = ue(null);
933
- function yn({ config: r = {}, children: e }) {
934
- const { appId: t, baseUrl: n } = ye(), { tenant: i, tenantSlug: o, switchTenant: a } = he(), [p, f] = A(r.initialRoles || []), [w, u] = A(!r.initialRoles), [b, g] = A(null), [T, I] = A(!1), [N, M] = A(null), [P, h] = A(0), [x, S] = A(() => {
941
+ const Fe = ue(null);
942
+ function bn({ config: r = {}, children: e }) {
943
+ const { appId: t, baseUrl: n } = we(), { tenant: i, tenantSlug: o, switchTenant: a } = he(), [p, f] = x(r.initialRoles || []), [w, d] = x(!r.initialRoles), [m, h] = x(null), [v, I] = x(!1), [F, M] = x(null), [P, u] = x(0), [A, b] = x(() => {
935
944
  try {
936
- const k = localStorage.getItem("userTenants");
937
- return k ? JSON.parse(k) : [];
945
+ const G = localStorage.getItem("userTenants");
946
+ return G ? JSON.parse(G) : [];
938
947
  } catch {
939
948
  return [];
940
949
  }
941
- }), [L, E] = A(!1), C = Ve({ done: !1, urlTokens: null });
942
- C.current.done || (C.current.done = !0, C.current.urlTokens = St(), C.current.urlTokens && console.log(
950
+ }), [L, E] = x(!1), N = Ge({ done: !1, urlTokens: null });
951
+ N.current.done || (N.current.done = !0, N.current.urlTokens = Tt(), N.current.urlTokens && console.log(
943
952
  "[AuthProvider] SYNC: URL tokens found, will block isAuthReady until user loaded"
944
953
  ));
945
- const [R, $] = A(() => {
946
- const k = C.current.urlTokens !== null;
947
- return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", k), k;
948
- }), l = Z(() => {
949
- const k = new xe({
954
+ const [R, U] = x(() => {
955
+ const G = N.current.urlTokens !== null;
956
+ return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", G), G;
957
+ }), l = J(() => {
958
+ const G = new Re({
950
959
  tenantSlug: o,
951
960
  onRefreshFailed: r.onRefreshFailed,
952
961
  baseUrl: n
953
962
  });
954
- return C.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), k.setTokens({
955
- accessToken: C.current.urlTokens.accessToken,
956
- refreshToken: C.current.urlTokens.refreshToken,
957
- expiresIn: C.current.urlTokens.expiresIn
958
- }), console.log("[AuthProvider] SYNC: Session valid:", k.hasValidSession())), k;
959
- }, [o, n, r.onRefreshFailed]), D = C.current.done && !R, U = Z(() => {
960
- const k = new oe(n);
961
- return k.setSessionManager(l), k;
962
- }, [n, l]), c = Z(() => new gt(new oe(n)), [n]), H = Z(() => new pt(U, l), [U, l]), F = Z(() => new Be(new oe(n)), [n]), y = Z(() => b || l.getUser(), [b, l]), m = Z(() => y != null && y.roleId && p.find((k) => k.id === y.roleId) || null, [y, p]), v = Z(() => (m == null ? void 0 : m.permissions) || [], [m]), G = Z(() => l.hasValidSession() && b !== null, [l, b]), Y = 5 * 60 * 1e3, q = Z(() => {
963
- const k = async (B = !1) => {
963
+ return N.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), G.setTokens({
964
+ accessToken: N.current.urlTokens.accessToken,
965
+ refreshToken: N.current.urlTokens.refreshToken,
966
+ expiresIn: N.current.urlTokens.expiresIn
967
+ }), console.log("[AuthProvider] SYNC: Session valid:", G.hasValidSession())), G;
968
+ }, [o, n, r.onRefreshFailed]), [D, $] = x(() => N.current.urlTokens ? !1 : l.hasValidSession()), g = N.current.done && !R && !D, C = J(() => {
969
+ const G = new ae(n);
970
+ return G.setSessionManager(l), G;
971
+ }, [n, l]), T = J(() => new ft(new ae(n)), [n]), S = J(() => new mt(C, l), [C, l]), y = J(() => new Oe(new ae(n)), [n]), k = J(() => m || l.getUser(), [m, l]), j = J(() => k != null && k.roleId && p.find((G) => G.id === k.roleId) || null, [k, p]), Z = J(() => (j == null ? void 0 : j.permissions) || [], [j]), O = J(() => l.hasValidSession() && m !== null, [l, m]), q = 5 * 60 * 1e3, W = J(() => {
972
+ const G = async (H = !1) => {
964
973
  try {
965
974
  if (!l.hasValidSession())
966
975
  return;
967
976
  const z = Date.now();
968
- if (!B && z - P < Y && b)
977
+ if (!H && z - P < q && m)
969
978
  return;
970
- const W = l.getUserId();
971
- if (!W) {
979
+ const V = l.getUserId();
980
+ if (!V) {
972
981
  console.warn("[AuthProvider] No userId available in token or storage");
973
982
  return;
974
983
  }
975
984
  I(!0), M(null);
976
- const J = await H.getUserById(W);
977
- g(J), l.setUser(J), h(Date.now());
985
+ const Y = await S.getUserById(V);
986
+ h(Y), l.setUser(Y), u(Date.now());
978
987
  } catch (z) {
979
988
  const Q = z instanceof Error ? z : new Error("Failed to load user data");
980
989
  M(Q), console.error("[AuthProvider] Failed to load user data:", Q);
981
990
  } finally {
982
991
  I(!1);
983
992
  }
984
- }, K = async () => {
985
- await k();
986
- }, ce = async (B) => {
987
- var Ue;
988
- const { username: z, password: Q, tenantSlug: W, redirectPath: J } = B;
989
- let ee = i == null ? void 0 : i.id, te = o, ne = l;
990
- W && (ee = (await new fe(U, t).getPublicTenantInfo(W)).id, te = W);
991
- const j = await c.login({
993
+ }, pe = async () => {
994
+ await G();
995
+ }, Te = async (H) => {
996
+ var He;
997
+ const { username: z, password: Q, tenantSlug: V, redirectPath: Y } = H;
998
+ let te = i == null ? void 0 : i.id, ne = o, re = l;
999
+ V && (te = (await new me(C, t).getPublicTenantInfo(V)).id, ne = V);
1000
+ const K = await T.login({
992
1001
  username: z,
993
1002
  password: Q,
994
1003
  appId: t,
995
- tenantId: ee
996
- }), pe = W && W !== o;
997
- if (pe && (ne = new xe({
998
- tenantSlug: te,
1004
+ tenantId: te
1005
+ }), fe = V && V !== o;
1006
+ if (fe && (re = new Re({
1007
+ tenantSlug: ne,
999
1008
  baseUrl: n
1000
- })), ne.setTokens({
1001
- accessToken: j.accessToken,
1002
- refreshToken: j.refreshToken,
1003
- expiresIn: j.expiresIn
1004
- }), j.user) {
1005
- ne.setUser(j.user), g(j.user);
1009
+ })), re.setTokens({
1010
+ accessToken: K.accessToken,
1011
+ refreshToken: K.refreshToken,
1012
+ expiresIn: K.expiresIn
1013
+ }), K.user) {
1014
+ re.setUser(K.user), h(K.user);
1006
1015
  try {
1007
- await k();
1008
- } catch (we) {
1009
- console.warn("Failed to load complete user data after login:", we);
1016
+ await G();
1017
+ } catch (be) {
1018
+ console.warn("Failed to load complete user data after login:", be);
1010
1019
  }
1011
1020
  }
1012
- if (j.tenants && j.tenants.length > 0) {
1013
- S(j.tenants);
1021
+ if (K.tenants && K.tenants.length > 0) {
1022
+ b(K.tenants);
1014
1023
  try {
1015
- localStorage.setItem("userTenants", JSON.stringify(j.tenants));
1024
+ localStorage.setItem("userTenants", JSON.stringify(K.tenants));
1016
1025
  } catch {
1017
1026
  }
1018
1027
  }
1019
- const ke = ((Ue = j.user) == null ? void 0 : Ue.tenantId) !== null;
1020
- E(ke);
1021
- const Ae = {
1022
- accessToken: j.accessToken,
1023
- refreshToken: j.refreshToken,
1024
- expiresIn: j.expiresIn
1028
+ const Ae = ((He = K.user) == null ? void 0 : He.tenantId) !== null;
1029
+ E(Ae);
1030
+ const Pe = {
1031
+ accessToken: K.accessToken,
1032
+ refreshToken: K.refreshToken,
1033
+ expiresIn: K.expiresIn
1025
1034
  };
1026
- if (pe && te)
1027
- return a(te, { tokens: Ae, redirectPath: J }), j;
1028
- if (J && J !== window.location.pathname)
1029
- return a(te || o || "", { tokens: Ae, redirectPath: J }), j;
1030
- if (!ke && j.tenants && j.tenants.length > 0) {
1031
- const we = B.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
1032
- if (j.tenants.length === 1 && we) {
1033
- const $e = j.tenants[0];
1034
- return a($e.subdomain, { tokens: Ae, redirectPath: J }), j;
1035
- } else j.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(j.tenants);
1035
+ if (fe && ne)
1036
+ return a(ne, { tokens: Pe, redirectPath: Y }), K;
1037
+ if (Y && Y !== window.location.pathname)
1038
+ return a(ne || o || "", { tokens: Pe, redirectPath: Y }), K;
1039
+ if (!Ae && K.tenants && K.tenants.length > 0) {
1040
+ const be = H.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
1041
+ if (K.tenants.length === 1 && be) {
1042
+ const Be = K.tenants[0];
1043
+ return a(Be.subdomain, { tokens: Pe, redirectPath: Y }), K;
1044
+ } else K.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(K.tenants);
1036
1045
  }
1037
- return j;
1038
- }, ve = async (B) => {
1039
- const { email: z, phoneNumber: Q, name: W, password: J, lastName: ee, tenantId: te } = B;
1046
+ return K;
1047
+ }, ke = async (H) => {
1048
+ const { email: z, phoneNumber: Q, name: V, password: Y, lastName: te, tenantId: ne } = H;
1040
1049
  if (!z && !Q)
1041
1050
  throw new Error("Either email or phoneNumber is required");
1042
- if (!W || !J)
1051
+ if (!V || !Y)
1043
1052
  throw new Error("Name and password are required");
1044
- const ne = te ?? (i == null ? void 0 : i.id);
1045
- return await c.signup({
1053
+ const re = ne ?? (i == null ? void 0 : i.id);
1054
+ return await T.signup({
1046
1055
  email: z,
1047
1056
  phoneNumber: Q,
1048
- name: W,
1049
- password: J,
1050
- tenantId: ne,
1051
- lastName: ee,
1057
+ name: V,
1058
+ password: Y,
1059
+ tenantId: re,
1060
+ lastName: te,
1052
1061
  appId: t
1053
1062
  });
1054
- }, Qe = async (B) => {
1055
- const { email: z, phoneNumber: Q, name: W, password: J, tenantName: ee, lastName: te } = B;
1063
+ }, et = async (H) => {
1064
+ const { email: z, phoneNumber: Q, name: V, password: Y, tenantName: te, lastName: ne } = H;
1056
1065
  if (!z && !Q)
1057
1066
  throw new Error("Either email or phoneNumber is required");
1058
- if (!W || !J || !ee)
1067
+ if (!V || !Y || !te)
1059
1068
  throw new Error("Name, password, and tenantName are required");
1060
- return await c.signupTenantAdmin({
1069
+ return await T.signupTenantAdmin({
1061
1070
  email: z,
1062
1071
  phoneNumber: Q,
1063
- name: W,
1064
- password: J,
1065
- tenantName: ee,
1072
+ name: V,
1073
+ password: Y,
1074
+ tenantName: te,
1066
1075
  appId: t,
1067
- lastName: te
1076
+ lastName: ne
1068
1077
  });
1069
- }, Xe = async (B) => {
1070
- const { currentPassword: z, newPassword: Q } = B, W = await l.getAuthHeaders();
1071
- await c.changePassword({ currentPassword: z, newPassword: Q }, W);
1072
- }, et = async (B) => {
1073
- const { email: z, tenantId: Q } = B, W = Q ?? (i == null ? void 0 : i.id);
1074
- if (!W)
1078
+ }, tt = async (H) => {
1079
+ const { currentPassword: z, newPassword: Q } = H, V = await l.getAuthHeaders();
1080
+ await T.changePassword({ currentPassword: z, newPassword: Q }, V);
1081
+ }, nt = async (H) => {
1082
+ const { email: z, tenantId: Q } = H, V = Q ?? (i == null ? void 0 : i.id);
1083
+ if (!V)
1075
1084
  throw new Error("tenantId is required for password reset");
1076
- await c.requestPasswordReset({ email: z, tenantId: W });
1077
- }, tt = async (B) => {
1078
- const { token: z, newPassword: Q } = B;
1079
- await c.confirmPasswordReset({ token: z, newPassword: Q });
1080
- }, nt = async (B) => {
1081
- const { email: z, frontendUrl: Q, name: W, lastName: J, tenantId: ee } = B, te = ee ?? (i == null ? void 0 : i.id);
1082
- if (!te)
1085
+ await T.requestPasswordReset({ email: z, tenantId: V });
1086
+ }, rt = async (H) => {
1087
+ const { token: z, newPassword: Q } = H;
1088
+ await T.confirmPasswordReset({ token: z, newPassword: Q });
1089
+ }, st = async (H) => {
1090
+ const { email: z, frontendUrl: Q, name: V, lastName: Y, tenantId: te } = H, ne = te ?? (i == null ? void 0 : i.id);
1091
+ if (!ne)
1083
1092
  throw new Error("tenantId is required for magic link authentication");
1084
- return await c.sendMagicLink({
1093
+ return await T.sendMagicLink({
1085
1094
  email: z,
1086
- tenantId: te,
1095
+ tenantId: ne,
1087
1096
  frontendUrl: Q,
1088
- name: W,
1089
- lastName: J,
1097
+ name: V,
1098
+ lastName: Y,
1090
1099
  appId: t
1091
1100
  });
1092
- }, rt = async (B) => {
1093
- const { token: z, email: Q, tenantSlug: W } = B;
1094
- let J = i == null ? void 0 : i.id, ee = o, te = l;
1095
- W && (J = (await new fe(U, t).getPublicTenantInfo(W)).id, ee = W);
1096
- const ne = await c.verifyMagicLink({
1101
+ }, it = async (H) => {
1102
+ const { token: z, email: Q, tenantSlug: V } = H;
1103
+ let Y = i == null ? void 0 : i.id, te = o, ne = l;
1104
+ V && (Y = (await new me(C, t).getPublicTenantInfo(V)).id, te = V);
1105
+ const re = await T.verifyMagicLink({
1097
1106
  token: z,
1098
1107
  email: Q,
1099
1108
  appId: t,
1100
- tenantId: J
1101
- }), j = W && W !== o;
1102
- if (j && (te = new xe({
1103
- tenantSlug: ee,
1109
+ tenantId: Y
1110
+ }), K = V && V !== o;
1111
+ if (K && (ne = new Re({
1112
+ tenantSlug: te,
1104
1113
  baseUrl: n
1105
- })), te.setTokens({
1106
- accessToken: ne.accessToken,
1107
- refreshToken: ne.refreshToken,
1108
- expiresIn: ne.expiresIn
1109
- }), ne.user) {
1110
- te.setUser(ne.user), g(ne.user);
1114
+ })), ne.setTokens({
1115
+ accessToken: re.accessToken,
1116
+ refreshToken: re.refreshToken,
1117
+ expiresIn: re.expiresIn
1118
+ }), re.user) {
1119
+ ne.setUser(re.user), h(re.user);
1111
1120
  try {
1112
- await k();
1113
- } catch (pe) {
1114
- console.warn("Failed to load complete user data after magic link login:", pe);
1121
+ await G();
1122
+ } catch (fe) {
1123
+ console.warn("Failed to load complete user data after magic link login:", fe);
1115
1124
  }
1116
1125
  }
1117
- return j && ee && ee !== o && a(ee, {
1126
+ return K && te && te !== o && a(te, {
1118
1127
  tokens: {
1119
- accessToken: ne.accessToken,
1120
- refreshToken: ne.refreshToken,
1121
- expiresIn: ne.expiresIn
1128
+ accessToken: re.accessToken,
1129
+ refreshToken: re.refreshToken,
1130
+ expiresIn: re.expiresIn
1122
1131
  }
1123
- }), ne;
1124
- }, st = async () => {
1125
- const B = l.getTokens();
1126
- if (!(B != null && B.refreshToken))
1132
+ }), re;
1133
+ }, ot = async () => {
1134
+ const H = l.getTokens();
1135
+ if (!(H != null && H.refreshToken))
1127
1136
  throw new Error("No refresh token available");
1128
- const z = await c.refreshToken({
1129
- refreshToken: B.refreshToken
1137
+ const z = await T.refreshToken({
1138
+ refreshToken: H.refreshToken
1130
1139
  });
1131
1140
  l.setTokens({
1132
1141
  accessToken: z.accessToken,
1133
- refreshToken: z.refreshToken || B.refreshToken,
1142
+ refreshToken: z.refreshToken || H.refreshToken,
1134
1143
  expiresIn: z.expiresIn
1135
1144
  });
1136
- }, it = () => {
1137
- l.clearSession(), g(null), M(null), S([]), E(!1);
1145
+ }, at = () => {
1146
+ l.clearSession(), h(null), M(null), b([]), E(!1);
1138
1147
  try {
1139
1148
  localStorage.removeItem("userTenants");
1140
1149
  } catch {
1141
1150
  }
1142
- }, ot = (B) => {
1143
- l.setTokens(B);
1144
- }, at = () => l.hasValidSession(), lt = () => {
1145
- l.clearSession(), g(null), M(null);
1146
- }, ct = async () => {
1151
+ }, lt = (H) => {
1152
+ l.setTokens(H);
1153
+ }, ct = () => l.hasValidSession(), dt = () => {
1154
+ l.clearSession(), h(null), M(null);
1155
+ }, ut = async () => {
1147
1156
  if (t)
1148
1157
  try {
1149
- u(!0);
1150
- const { roles: B } = await F.getRolesByApp(t);
1151
- f(B);
1152
- } catch (B) {
1153
- console.error("Failed to fetch roles:", B);
1158
+ d(!0);
1159
+ const { roles: H } = await y.getRolesByApp(t);
1160
+ f(H);
1161
+ } catch (H) {
1162
+ console.error("Failed to fetch roles:", H);
1154
1163
  } finally {
1155
- u(!1);
1164
+ d(!1);
1156
1165
  }
1157
- }, dt = async () => {
1158
- await ct();
1159
- }, Te = (B) => {
1160
- if (!v || v.length === 0)
1166
+ }, ht = async () => {
1167
+ await ut();
1168
+ }, xe = (H) => {
1169
+ if (!Z || Z.length === 0)
1161
1170
  return !1;
1162
- if (typeof B == "string")
1163
- return v.includes(B);
1164
- const z = `${B.resource}.${B.action}`;
1165
- return v.includes(z);
1171
+ if (typeof H == "string")
1172
+ return Z.includes(H);
1173
+ const z = `${H.resource}.${H.action}`;
1174
+ return Z.includes(z);
1166
1175
  };
1167
1176
  return {
1168
1177
  // RFC-003: Authentication state
1169
- isAuthenticated: G,
1178
+ isAuthenticated: O,
1170
1179
  sessionManager: l,
1171
- authenticatedHttpService: U,
1172
- login: ce,
1173
- signup: ve,
1174
- signupTenantAdmin: Qe,
1175
- sendMagicLink: nt,
1176
- verifyMagicLink: rt,
1177
- changePassword: Xe,
1178
- requestPasswordReset: et,
1179
- confirmPasswordReset: tt,
1180
- refreshToken: st,
1181
- logout: it,
1182
- setTokens: ot,
1183
- hasValidSession: at,
1184
- clearSession: lt,
1185
- currentUser: b,
1186
- isUserLoading: T,
1187
- userError: N,
1188
- loadUserData: k,
1189
- refreshUser: K,
1190
- isAuthInitializing: !D,
1191
- isAuthReady: D,
1192
- userRole: m,
1193
- userPermissions: v,
1180
+ authenticatedHttpService: C,
1181
+ login: Te,
1182
+ signup: ke,
1183
+ signupTenantAdmin: et,
1184
+ sendMagicLink: st,
1185
+ verifyMagicLink: it,
1186
+ changePassword: tt,
1187
+ requestPasswordReset: nt,
1188
+ confirmPasswordReset: rt,
1189
+ refreshToken: ot,
1190
+ logout: at,
1191
+ setTokens: lt,
1192
+ hasValidSession: ct,
1193
+ clearSession: dt,
1194
+ currentUser: m,
1195
+ isUserLoading: v,
1196
+ userError: F,
1197
+ loadUserData: G,
1198
+ refreshUser: pe,
1199
+ isAuthInitializing: !g,
1200
+ isAuthReady: g,
1201
+ userRole: j,
1202
+ userPermissions: Z,
1194
1203
  availableRoles: p,
1195
1204
  rolesLoading: w,
1196
- hasPermission: Te,
1197
- hasAnyPermission: (B) => B.some((z) => Te(z)),
1198
- hasAllPermissions: (B) => B.every((z) => Te(z)),
1199
- getUserPermissionStrings: () => v || [],
1200
- refreshRoles: dt,
1205
+ hasPermission: xe,
1206
+ hasAnyPermission: (H) => H.some((z) => xe(z)),
1207
+ hasAllPermissions: (H) => H.every((z) => xe(z)),
1208
+ getUserPermissionStrings: () => Z || [],
1209
+ refreshRoles: ht,
1201
1210
  // RFC-004: Multi-tenant user membership
1202
- userTenants: x,
1211
+ userTenants: A,
1203
1212
  hasTenantContext: L,
1204
- switchToTenant: async (B, z) => {
1205
- const { redirectPath: Q } = z || {}, W = l.getTokens();
1206
- if (!(W != null && W.refreshToken))
1213
+ switchToTenant: async (H, z) => {
1214
+ const { redirectPath: Q } = z || {}, V = l.getTokens();
1215
+ if (!(V != null && V.refreshToken))
1207
1216
  throw new Error("No refresh token available for tenant switch");
1208
- const J = await c.switchTenant({
1209
- refreshToken: W.refreshToken,
1210
- tenantId: B
1217
+ const Y = await T.switchTenant({
1218
+ refreshToken: V.refreshToken,
1219
+ tenantId: H
1211
1220
  });
1212
1221
  l.setTokens({
1213
- accessToken: J.accessToken,
1214
- refreshToken: W.refreshToken,
1222
+ accessToken: Y.accessToken,
1223
+ refreshToken: V.refreshToken,
1215
1224
  // Keep the same refresh token
1216
- expiresIn: J.expiresIn
1217
- }), g(J.user), l.setUser(J.user), E(!0);
1218
- const ee = x.find((te) => te.id === B);
1219
- ee && a(ee.subdomain, {
1225
+ expiresIn: Y.expiresIn
1226
+ }), h(Y.user), l.setUser(Y.user), E(!0);
1227
+ const te = A.find((ne) => ne.id === H);
1228
+ te && a(te.subdomain, {
1220
1229
  tokens: {
1221
- accessToken: J.accessToken,
1222
- refreshToken: W.refreshToken,
1223
- expiresIn: J.expiresIn
1230
+ accessToken: Y.accessToken,
1231
+ refreshToken: V.refreshToken,
1232
+ expiresIn: Y.expiresIn
1224
1233
  },
1225
1234
  redirectPath: Q
1226
1235
  });
1227
1236
  },
1228
1237
  refreshUserTenants: async () => {
1229
- const B = await l.getAuthHeaders(), z = await c.getUserTenants(B);
1230
- S(z);
1238
+ const H = await l.getAuthHeaders(), z = await T.getUserTenants(H);
1239
+ b(z);
1231
1240
  try {
1232
1241
  localStorage.setItem("userTenants", JSON.stringify(z));
1233
1242
  } catch {
@@ -1236,74 +1245,76 @@ function yn({ config: r = {}, children: e }) {
1236
1245
  }
1237
1246
  };
1238
1247
  }, [
1239
- G,
1248
+ O,
1240
1249
  l,
1241
- U,
1242
- c,
1243
- H,
1244
- F,
1250
+ C,
1251
+ T,
1252
+ S,
1253
+ y,
1245
1254
  t,
1246
1255
  i,
1247
1256
  o,
1248
1257
  a,
1249
1258
  p,
1250
- b,
1251
- T,
1252
- N,
1253
- x,
1254
- L,
1255
- D,
1256
1259
  m,
1257
1260
  v,
1261
+ F,
1262
+ A,
1263
+ L,
1264
+ g,
1265
+ j,
1266
+ Z,
1258
1267
  P,
1259
- Y
1268
+ q
1260
1269
  ]);
1261
- X(() => {
1270
+ ee(() => {
1262
1271
  !r.initialRoles && t && (async () => {
1263
1272
  try {
1264
- u(!0);
1265
- const K = new oe(n), ce = new Be(K), { roles: ve } = await ce.getRolesByApp(t);
1266
- f(ve);
1267
- } catch (K) {
1268
- console.error("Failed to fetch roles:", K);
1273
+ d(!0);
1274
+ const pe = new ae(n), Te = new Oe(pe), { roles: ke } = await Te.getRolesByApp(t);
1275
+ f(ke);
1276
+ } catch (pe) {
1277
+ console.error("Failed to fetch roles:", pe);
1269
1278
  } finally {
1270
- u(!1);
1279
+ d(!1);
1271
1280
  }
1272
1281
  })();
1273
1282
  }, [t, n, r.initialRoles]);
1274
- const [O, V] = A(!1);
1275
- return X(() => {
1276
- O || (V(!0), C.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), vt(), $(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), q.loadUserData().catch((k) => {
1277
- console.error("[AuthProvider] Failed to load user data:", k);
1283
+ const [B, X] = x(!1);
1284
+ return ee(() => {
1285
+ B || (X(!0), N.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), kt(), U(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), W.loadUserData().catch((G) => {
1286
+ console.error("[AuthProvider] Failed to load user data:", G);
1278
1287
  }).finally(() => {
1279
- console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), $(!1);
1288
+ console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), U(!1);
1280
1289
  })));
1281
- }, [q, O]), X(() => {
1282
- const k = l.getUser();
1283
- k && l.hasValidSession() && g(k);
1284
- }, [l]), X(() => {
1285
- O && (C.current.urlTokens || !b && !T && l.hasValidSession() && (console.log("[AuthProvider] Auto-loading user data..."), q.loadUserData().catch(() => {
1286
- })));
1287
- }, [b, T, q, l, O]), X(() => {
1288
- if (!l.hasValidSession() || !b)
1290
+ }, [W, B]), ee(() => {
1291
+ const G = l.getUser();
1292
+ G && l.hasValidSession() ? (h(G), $(!1)) : l.hasValidSession() || $(!1);
1293
+ }, [l]), ee(() => {
1294
+ B && (N.current.urlTokens || (!m && !v && l.hasValidSession() ? (console.log("[AuthProvider] Auto-loading user data..."), W.loadUserData().catch(() => {
1295
+ }).finally(() => {
1296
+ $(!1);
1297
+ })) : m && $(!1)));
1298
+ }, [m, v, W, l, B]), ee(() => {
1299
+ if (!l.hasValidSession() || !m)
1289
1300
  return;
1290
- const k = setInterval(() => {
1291
- q.loadUserData().catch(() => {
1301
+ const G = setInterval(() => {
1302
+ W.loadUserData().catch(() => {
1292
1303
  });
1293
- }, Y);
1294
- return () => clearInterval(k);
1295
- }, [l, b, q, Y]), /* @__PURE__ */ s(Le.Provider, { value: q, children: e });
1304
+ }, q);
1305
+ return () => clearInterval(G);
1306
+ }, [l, m, W, q]), /* @__PURE__ */ s(Fe.Provider, { value: W, children: e });
1296
1307
  }
1297
- function le() {
1298
- const r = ie(Le);
1308
+ function ce() {
1309
+ const r = oe(Fe);
1299
1310
  if (!r)
1300
1311
  throw new Error("useAuth must be used within an AuthProvider");
1301
1312
  return r;
1302
1313
  }
1303
- function Ee() {
1304
- return ie(Le);
1314
+ function Ne() {
1315
+ return oe(Fe);
1305
1316
  }
1306
- class Tt {
1317
+ class xt {
1307
1318
  constructor(e, t) {
1308
1319
  this.httpService = e, this.sessionManager = t;
1309
1320
  }
@@ -1383,66 +1394,66 @@ class Tt {
1383
1394
  })).data;
1384
1395
  }
1385
1396
  }
1386
- const Fe = ue(null);
1387
- function wn({ config: r = {}, children: e }) {
1388
- const t = je(), n = Se(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [p, f] = A([]), [w, u] = A(!1), [b, g] = A(null), [T, I] = A(!1), N = Z(() => {
1389
- const h = new oe(i);
1390
- return new Tt(h);
1397
+ const De = ue(null);
1398
+ function Sn({ config: r = {}, children: e }) {
1399
+ const t = Ze(), n = ve(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [p, f] = x([]), [w, d] = x(!1), [m, h] = x(null), [v, I] = x(!1), F = J(() => {
1400
+ const u = new ae(i);
1401
+ return new xt(u);
1391
1402
  }, [i]), M = async () => {
1392
1403
  if (!(a != null && a.id)) {
1393
1404
  f([]);
1394
1405
  return;
1395
1406
  }
1396
- u(!0), g(null);
1407
+ d(!0), h(null);
1397
1408
  try {
1398
- const h = await N.getTenantFeatureFlags(a.id, o);
1399
- f(h);
1400
- } catch (h) {
1401
- const x = h instanceof Error ? h.message : "Failed to fetch feature flags";
1402
- g(x), r.onError && r.onError(h instanceof Error ? h : new Error(x));
1409
+ const u = await F.getTenantFeatureFlags(a.id, o);
1410
+ f(u);
1411
+ } catch (u) {
1412
+ const A = u instanceof Error ? u.message : "Failed to fetch feature flags";
1413
+ h(A), r.onError && r.onError(u instanceof Error ? u : new Error(A));
1403
1414
  } finally {
1404
- u(!1);
1415
+ d(!1);
1405
1416
  }
1406
1417
  };
1407
- X(() => {
1418
+ ee(() => {
1408
1419
  if (!i || !o) return;
1409
1420
  M().finally(() => I(!0));
1410
- const h = r.refreshInterval || 5 * 60 * 1e3, x = setInterval(M, h);
1411
- return () => clearInterval(x);
1421
+ const u = r.refreshInterval || 5 * 60 * 1e3, A = setInterval(M, u);
1422
+ return () => clearInterval(A);
1412
1423
  }, [a == null ? void 0 : a.id, i, o, r.refreshInterval]);
1413
- const P = Z(() => {
1414
- const h = (C) => {
1415
- const R = p.find(($) => $.key === C);
1424
+ const P = J(() => {
1425
+ const u = (N) => {
1426
+ const R = p.find((U) => U.key === N);
1416
1427
  return (R == null ? void 0 : R.value) === !0;
1417
- }, x = (C) => p.find((R) => R.key === C), S = (C) => {
1418
- const R = p.find(($) => $.key === C);
1428
+ }, A = (N) => p.find((R) => R.key === N), b = (N) => {
1429
+ const R = p.find((U) => U.key === N);
1419
1430
  return R ? R.value ? "enabled" : "disabled" : "not_found";
1420
1431
  }, L = async () => {
1421
1432
  await M();
1422
- }, E = !!(i && o) && (T || !(a != null && a.id));
1433
+ }, E = !!(i && o) && (v || !(a != null && a.id));
1423
1434
  return {
1424
1435
  featureFlags: p,
1425
1436
  loading: w,
1426
- error: b,
1437
+ error: m,
1427
1438
  isReady: E,
1428
- isEnabled: h,
1429
- getFlag: x,
1430
- getFlagState: S,
1439
+ isEnabled: u,
1440
+ getFlag: A,
1441
+ getFlagState: b,
1431
1442
  refresh: L
1432
1443
  };
1433
- }, [p, w, b, i, o, a == null ? void 0 : a.id, T]);
1434
- return /* @__PURE__ */ s(Fe.Provider, { value: P, children: e });
1444
+ }, [p, w, m, i, o, a == null ? void 0 : a.id, v]);
1445
+ return /* @__PURE__ */ s(De.Provider, { value: P, children: e });
1435
1446
  }
1436
- function kt() {
1437
- const r = ie(Fe);
1447
+ function At() {
1448
+ const r = oe(De);
1438
1449
  if (!r)
1439
1450
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1440
1451
  return r;
1441
1452
  }
1442
- function Ge() {
1443
- return ie(Fe);
1453
+ function Ke() {
1454
+ return oe(De);
1444
1455
  }
1445
- class At {
1456
+ class Pt {
1446
1457
  constructor(e, t) {
1447
1458
  this.httpService = e, this.sessionManager = t;
1448
1459
  }
@@ -1508,68 +1519,68 @@ class At {
1508
1519
  )).data;
1509
1520
  }
1510
1521
  }
1511
- const Ne = ue(void 0);
1512
- function bn({ config: r = {}, children: e }) {
1513
- const t = je(), n = Se(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (n == null ? void 0 : n.tenant) ?? null, [a, p] = A(null), [f, w] = A(!1), [u, b] = A(null), [g, T] = A(!1), I = Z(() => {
1514
- const P = new oe(i);
1515
- return new At(P);
1516
- }, [i]), N = async () => {
1522
+ const Ce = ue(void 0);
1523
+ function vn({ config: r = {}, children: e }) {
1524
+ const t = Ze(), n = ve(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (n == null ? void 0 : n.tenant) ?? null, [a, p] = x(null), [f, w] = x(!1), [d, m] = x(null), [h, v] = x(!1), I = J(() => {
1525
+ const P = new ae(i);
1526
+ return new Pt(P);
1527
+ }, [i]), F = async () => {
1517
1528
  if (!(o != null && o.id)) {
1518
1529
  p(null);
1519
1530
  return;
1520
1531
  }
1521
- w(!0), b(null);
1532
+ w(!0), m(null);
1522
1533
  try {
1523
1534
  const P = await I.getTenantSubscriptionFeatures(o.id);
1524
1535
  p(P);
1525
1536
  } catch (P) {
1526
- const h = P instanceof Error ? P.message : "Failed to fetch subscription";
1527
- b(h), r.onError && r.onError(P instanceof Error ? P : new Error(h));
1537
+ const u = P instanceof Error ? P.message : "Failed to fetch subscription";
1538
+ m(u), r.onError && r.onError(P instanceof Error ? P : new Error(u));
1528
1539
  } finally {
1529
1540
  w(!1);
1530
1541
  }
1531
1542
  };
1532
- X(() => {
1533
- if (!i || (N().finally(() => T(!0)), !r.refreshInterval)) return;
1534
- const P = r.refreshInterval || 10 * 60 * 1e3, h = setInterval(N, P);
1535
- return () => clearInterval(h);
1543
+ ee(() => {
1544
+ if (!i || (F().finally(() => v(!0)), !r.refreshInterval)) return;
1545
+ const P = r.refreshInterval || 10 * 60 * 1e3, u = setInterval(F, P);
1546
+ return () => clearInterval(u);
1536
1547
  }, [o == null ? void 0 : o.id, i, r.refreshInterval]);
1537
- const M = Z(() => {
1538
- const P = (a == null ? void 0 : a.features) || [], h = (R) => {
1539
- const $ = P.find((l) => l.key === R);
1540
- return $ ? $.type === "BOOLEAN" || $.type === "boolean" ? $.value === !0 : !!$.value : !1;
1541
- }, x = (R) => P.find(($) => $.key === R), S = (R, $) => {
1548
+ const M = J(() => {
1549
+ const P = (a == null ? void 0 : a.features) || [], u = (R) => {
1550
+ const U = P.find((l) => l.key === R);
1551
+ return U ? U.type === "BOOLEAN" || U.type === "boolean" ? U.value === !0 : !!U.value : !1;
1552
+ }, A = (R) => P.find((U) => U.key === R), b = (R, U) => {
1542
1553
  const l = P.find((D) => D.key === R);
1543
- return l ? l.value : $;
1554
+ return l ? l.value : U;
1544
1555
  }, L = (R) => !a || !a.isActive ? !1 : R.includes(a.planId), E = async () => {
1545
- await N();
1546
- }, C = !!i && (g || !(o != null && o.id));
1556
+ await F();
1557
+ }, N = !!i && (h || !(o != null && o.id));
1547
1558
  return {
1548
1559
  subscription: a,
1549
1560
  features: P,
1550
1561
  loading: f,
1551
- error: u,
1552
- isReady: C,
1553
- isFeatureEnabled: h,
1554
- getFeature: x,
1555
- getFeatureValue: S,
1562
+ error: d,
1563
+ isReady: N,
1564
+ isFeatureEnabled: u,
1565
+ getFeature: A,
1566
+ getFeatureValue: b,
1556
1567
  hasAllowedPlan: L,
1557
1568
  refresh: E
1558
1569
  };
1559
- }, [a, f, u, i, o == null ? void 0 : o.id, g]);
1560
- return /* @__PURE__ */ s(Ne.Provider, { value: M, children: e });
1570
+ }, [a, f, d, i, o == null ? void 0 : o.id, h]);
1571
+ return /* @__PURE__ */ s(Ce.Provider, { value: M, children: e });
1561
1572
  }
1562
- function xt() {
1563
- const r = ie(Ne);
1573
+ function Rt() {
1574
+ const r = oe(Ce);
1564
1575
  if (r === void 0)
1565
1576
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1566
1577
  return r;
1567
1578
  }
1568
- function Ze() {
1569
- return ie(Ne) ?? null;
1579
+ function Je() {
1580
+ return oe(Ce) ?? null;
1570
1581
  }
1571
- var se = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(se || {});
1572
- const De = {
1582
+ var ie = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(ie || {});
1583
+ const Ue = {
1573
1584
  publicGuest: "/",
1574
1585
  publicUser: "/account",
1575
1586
  publicAdmin: "/admin",
@@ -1577,7 +1588,7 @@ const De = {
1577
1588
  tenantUser: "/dashboard",
1578
1589
  tenantAdmin: "/admin/dashboard",
1579
1590
  default: "/"
1580
- }, Ke = {
1591
+ }, Ye = {
1581
1592
  // Public/Landing zones
1582
1593
  landing: { tenant: "forbidden", auth: "optional" },
1583
1594
  publicOnly: { tenant: "forbidden", auth: "forbidden" },
@@ -1590,18 +1601,18 @@ const De = {
1590
1601
  tenantOpen: { tenant: "required", auth: "optional" },
1591
1602
  tenantAuth: { tenant: "required", auth: "required" },
1592
1603
  // User type zones
1593
- user: { tenant: "required", auth: "required", userType: se.USER },
1594
- admin: { tenant: "required", auth: "required", userType: se.TENANT_ADMIN },
1604
+ user: { tenant: "required", auth: "required", userType: ie.USER },
1605
+ admin: { tenant: "required", auth: "required", userType: ie.TENANT_ADMIN },
1595
1606
  // Fully open
1596
1607
  open: { tenant: "optional", auth: "optional" }
1597
- }, Ce = ue(null);
1598
- function Sn({ config: r = {}, children: e }) {
1599
- const t = Z(() => {
1608
+ }, $e = ue(null);
1609
+ function Tn({ config: r = {}, children: e }) {
1610
+ const t = J(() => {
1600
1611
  const n = {
1601
- ...De,
1612
+ ...Ue,
1602
1613
  ...r.zoneRoots
1603
1614
  }, i = {
1604
- ...Ke,
1615
+ ...Ye,
1605
1616
  ...r.presets
1606
1617
  };
1607
1618
  return {
@@ -1614,19 +1625,19 @@ function Sn({ config: r = {}, children: e }) {
1614
1625
  returnToStorage: r.returnToStorage ?? "url"
1615
1626
  };
1616
1627
  }, [r]);
1617
- return /* @__PURE__ */ s(Ce.Provider, { value: t, children: e });
1628
+ return /* @__PURE__ */ s($e.Provider, { value: t, children: e });
1618
1629
  }
1619
- function vn() {
1620
- const r = ie(Ce);
1630
+ function kn() {
1631
+ const r = oe($e);
1621
1632
  if (!r)
1622
1633
  throw new Error("useRouting must be used within a RoutingProvider");
1623
1634
  return r;
1624
1635
  }
1625
- function Pt() {
1626
- const r = ie(Ce);
1636
+ function It() {
1637
+ const r = oe($e);
1627
1638
  return r || {
1628
- zoneRoots: De,
1629
- presets: Ke,
1639
+ zoneRoots: Ue,
1640
+ presets: Ye,
1630
1641
  loadingFallback: null,
1631
1642
  accessDeniedFallback: null,
1632
1643
  onAccessDenied: void 0,
@@ -1634,7 +1645,7 @@ function Pt() {
1634
1645
  returnToStorage: "url"
1635
1646
  };
1636
1647
  }
1637
- const Oe = () => /* @__PURE__ */ d(
1648
+ const _e = () => /* @__PURE__ */ c(
1638
1649
  "div",
1639
1650
  {
1640
1651
  style: {
@@ -1671,11 +1682,11 @@ const Oe = () => /* @__PURE__ */ d(
1671
1682
  )
1672
1683
  ]
1673
1684
  }
1674
- ), ze = ({
1685
+ ), We = ({
1675
1686
  userType: r,
1676
1687
  minUserType: e,
1677
1688
  missingPermissions: t
1678
- }) => /* @__PURE__ */ d(
1689
+ }) => /* @__PURE__ */ c(
1679
1690
  "div",
1680
1691
  {
1681
1692
  style: {
@@ -1693,55 +1704,55 @@ const Oe = () => /* @__PURE__ */ d(
1693
1704
  children: [
1694
1705
  /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1695
1706
  /* @__PURE__ */ s("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1696
- e && r ? /* @__PURE__ */ d(_, { children: [
1697
- /* @__PURE__ */ d("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1707
+ e && r ? /* @__PURE__ */ c(_, { children: [
1708
+ /* @__PURE__ */ c("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1698
1709
  "This content requires ",
1699
1710
  /* @__PURE__ */ s("strong", { children: e }),
1700
1711
  " access level or higher."
1701
1712
  ] }),
1702
- /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1713
+ /* @__PURE__ */ c("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1703
1714
  "Your current access level: ",
1704
1715
  /* @__PURE__ */ s("strong", { children: r })
1705
1716
  ] })
1706
- ] }) : /* @__PURE__ */ d(_, { children: [
1717
+ ] }) : /* @__PURE__ */ c(_, { children: [
1707
1718
  /* @__PURE__ */ s("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1708
- t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1719
+ t && t.length > 0 && /* @__PURE__ */ c("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1709
1720
  "Required permissions: ",
1710
1721
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
1711
1722
  ] })
1712
1723
  ] })
1713
1724
  ]
1714
1725
  }
1715
- ), Rt = (r, e) => {
1726
+ ), Mt = (r, e) => {
1716
1727
  const t = {
1717
- [se.USER]: 1,
1718
- [se.TENANT_ADMIN]: 2,
1719
- [se.SUPERUSER]: 3
1728
+ [ie.USER]: 1,
1729
+ [ie.TENANT_ADMIN]: 2,
1730
+ [ie.SUPERUSER]: 3
1720
1731
  };
1721
1732
  return t[r] >= t[e];
1722
1733
  };
1723
- function Tn({
1734
+ function xn({
1724
1735
  children: r,
1725
1736
  fallback: e,
1726
1737
  minUserType: t,
1727
1738
  requiredPermissions: n,
1728
1739
  requireAllPermissions: i = !1
1729
1740
  }) {
1730
- const { hasValidSession: o, sessionManager: a, hasPermission: p, hasAnyPermission: f, hasAllPermissions: w } = le();
1741
+ const { hasValidSession: o, sessionManager: a, hasPermission: p, hasAnyPermission: f, hasAllPermissions: w } = ce();
1731
1742
  if (!o())
1732
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Oe, {}) });
1733
- const u = a.getUser();
1734
- if (!u)
1735
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Oe, {}) });
1736
- if (t && !Rt(u.userType, t))
1737
- return /* @__PURE__ */ s(ze, { userType: u.userType, minUserType: t });
1743
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(_e, {}) });
1744
+ const d = a.getUser();
1745
+ if (!d)
1746
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(_e, {}) });
1747
+ if (t && !Mt(d.userType, t))
1748
+ return /* @__PURE__ */ s(We, { userType: d.userType, minUserType: t });
1738
1749
  if (n && n.length > 0 && !(i ? w(n) : f(n))) {
1739
- const g = n.filter((T) => !p(T)).map((T) => typeof T == "string" ? T : T.name);
1740
- return /* @__PURE__ */ s(ze, { missingPermissions: g });
1750
+ const h = n.filter((v) => !p(v)).map((v) => typeof v == "string" ? v : v.name);
1751
+ return /* @__PURE__ */ s(We, { missingPermissions: h });
1741
1752
  }
1742
1753
  return /* @__PURE__ */ s(_, { children: r });
1743
1754
  }
1744
- const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1755
+ const Lt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1745
1756
  "div",
1746
1757
  {
1747
1758
  style: {
@@ -1754,7 +1765,7 @@ const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1754
1765
  backgroundColor: "#f9fafb",
1755
1766
  textAlign: "center"
1756
1767
  },
1757
- children: /* @__PURE__ */ d(
1768
+ children: /* @__PURE__ */ c(
1758
1769
  "div",
1759
1770
  {
1760
1771
  style: {
@@ -1768,7 +1779,7 @@ const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1768
1779
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1769
1780
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1770
1781
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1771
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1782
+ /* @__PURE__ */ c("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1772
1783
  "Redirecting to ",
1773
1784
  r,
1774
1785
  "..."
@@ -1777,7 +1788,7 @@ const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1777
1788
  }
1778
1789
  )
1779
1790
  }
1780
- ), _e = ({
1791
+ ), Ve = ({
1781
1792
  userType: r,
1782
1793
  requiredUserType: e,
1783
1794
  missingPermissions: t
@@ -1794,7 +1805,7 @@ const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1794
1805
  backgroundColor: "#f9fafb",
1795
1806
  textAlign: "center"
1796
1807
  },
1797
- children: /* @__PURE__ */ d(
1808
+ children: /* @__PURE__ */ c(
1798
1809
  "div",
1799
1810
  {
1800
1811
  style: {
@@ -1807,19 +1818,19 @@ const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1807
1818
  children: [
1808
1819
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1809
1820
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1810
- e && r ? /* @__PURE__ */ d(_, { children: [
1811
- /* @__PURE__ */ d("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1821
+ e && r ? /* @__PURE__ */ c(_, { children: [
1822
+ /* @__PURE__ */ c("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1812
1823
  "This page requires ",
1813
1824
  /* @__PURE__ */ s("strong", { children: e }),
1814
1825
  " access."
1815
1826
  ] }),
1816
- /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1827
+ /* @__PURE__ */ c("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1817
1828
  "Your current user type: ",
1818
1829
  /* @__PURE__ */ s("strong", { children: r })
1819
1830
  ] })
1820
- ] }) : /* @__PURE__ */ d(_, { children: [
1831
+ ] }) : /* @__PURE__ */ c(_, { children: [
1821
1832
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1822
- t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1833
+ t && t.length > 0 && /* @__PURE__ */ c("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1823
1834
  "Required permissions: ",
1824
1835
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
1825
1836
  ] })
@@ -1828,8 +1839,8 @@ const It = ({ redirectPath: r }) => /* @__PURE__ */ s(
1828
1839
  }
1829
1840
  )
1830
1841
  }
1831
- ), Mt = (r, e) => r === e;
1832
- function kn({
1842
+ ), Et = (r, e) => r === e;
1843
+ function An({
1833
1844
  children: r,
1834
1845
  redirectTo: e = "/login",
1835
1846
  requiredUserType: t,
@@ -1837,34 +1848,34 @@ function kn({
1837
1848
  requireAllPermissions: i = !1,
1838
1849
  fallback: o
1839
1850
  }) {
1840
- const { hasValidSession: a, sessionManager: p, hasPermission: f, hasAnyPermission: w, hasAllPermissions: u } = le(), b = be();
1841
- if (X(() => {
1851
+ const { hasValidSession: a, sessionManager: p, hasPermission: f, hasAnyPermission: w, hasAllPermissions: d } = ce(), m = Se();
1852
+ if (ee(() => {
1842
1853
  process.env.NODE_ENV === "development" && console.warn(
1843
1854
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
1844
1855
  );
1845
1856
  }, []), !a())
1846
- return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ d(_, { children: [
1847
- /* @__PURE__ */ s(It, { redirectPath: e }),
1848
- /* @__PURE__ */ s(me, { to: e, state: { from: b.pathname }, replace: !0 })
1857
+ return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ c(_, { children: [
1858
+ /* @__PURE__ */ s(Lt, { redirectPath: e }),
1859
+ /* @__PURE__ */ s(ye, { to: e, state: { from: m.pathname }, replace: !0 })
1849
1860
  ] });
1850
- const g = p.getUser();
1851
- if (!g)
1852
- return /* @__PURE__ */ s(me, { to: e, state: { from: b.pathname }, replace: !0 });
1853
- if (t && !Mt(g.userType, t))
1861
+ const h = p.getUser();
1862
+ if (!h)
1863
+ return /* @__PURE__ */ s(ye, { to: e, state: { from: m.pathname }, replace: !0 });
1864
+ if (t && !Et(h.userType, t))
1854
1865
  return /* @__PURE__ */ s(
1855
- _e,
1866
+ Ve,
1856
1867
  {
1857
- userType: g.userType,
1868
+ userType: h.userType,
1858
1869
  requiredUserType: t
1859
1870
  }
1860
1871
  );
1861
- if (n && n.length > 0 && !(i ? u(n) : w(n))) {
1862
- const I = n.filter((N) => !f(N)).map((N) => typeof N == "string" ? N : N.name);
1863
- return /* @__PURE__ */ s(_e, { missingPermissions: I });
1872
+ if (n && n.length > 0 && !(i ? d(n) : w(n))) {
1873
+ const I = n.filter((F) => !f(F)).map((F) => typeof F == "string" ? F : F.name);
1874
+ return /* @__PURE__ */ s(Ve, { missingPermissions: I });
1864
1875
  }
1865
1876
  return /* @__PURE__ */ s(_, { children: r });
1866
1877
  }
1867
- const Lt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1878
+ const Ft = ({ redirectPath: r }) => /* @__PURE__ */ s(
1868
1879
  "div",
1869
1880
  {
1870
1881
  style: {
@@ -1877,7 +1888,7 @@ const Lt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1877
1888
  backgroundColor: "#f9fafb",
1878
1889
  textAlign: "center"
1879
1890
  },
1880
- children: /* @__PURE__ */ d(
1891
+ children: /* @__PURE__ */ c(
1881
1892
  "div",
1882
1893
  {
1883
1894
  style: {
@@ -1891,7 +1902,7 @@ const Lt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1891
1902
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
1892
1903
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
1893
1904
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
1894
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1905
+ /* @__PURE__ */ c("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1895
1906
  "Redirecting to ",
1896
1907
  r,
1897
1908
  "..."
@@ -1901,18 +1912,18 @@ const Lt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1901
1912
  )
1902
1913
  }
1903
1914
  );
1904
- function An({ children: r, redirectTo: e = "/", fallback: t }) {
1905
- const { tenant: n, isLoading: i, error: o } = ge(), a = be();
1906
- return X(() => {
1915
+ function Pn({ children: r, redirectTo: e = "/", fallback: t }) {
1916
+ const { tenant: n, isLoading: i, error: o } = ge(), a = Se();
1917
+ return ee(() => {
1907
1918
  process.env.NODE_ENV === "development" && console.warn(
1908
1919
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
1909
1920
  );
1910
- }, []), i || o ? null : n ? /* @__PURE__ */ s(_, { children: r }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
1911
- /* @__PURE__ */ s(Lt, { redirectPath: e }),
1912
- /* @__PURE__ */ s(me, { to: e, state: { from: a.pathname }, replace: !0 })
1921
+ }, []), i || o ? null : n ? /* @__PURE__ */ s(_, { children: r }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ c(_, { children: [
1922
+ /* @__PURE__ */ s(Ft, { redirectPath: e }),
1923
+ /* @__PURE__ */ s(ye, { to: e, state: { from: a.pathname }, replace: !0 })
1913
1924
  ] });
1914
1925
  }
1915
- const Et = ({ redirectPath: r }) => /* @__PURE__ */ s(
1926
+ const Nt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1916
1927
  "div",
1917
1928
  {
1918
1929
  style: {
@@ -1925,7 +1936,7 @@ const Et = ({ redirectPath: r }) => /* @__PURE__ */ s(
1925
1936
  backgroundColor: "#f9fafb",
1926
1937
  textAlign: "center"
1927
1938
  },
1928
- children: /* @__PURE__ */ d(
1939
+ children: /* @__PURE__ */ c(
1929
1940
  "div",
1930
1941
  {
1931
1942
  style: {
@@ -1939,7 +1950,7 @@ const Et = ({ redirectPath: r }) => /* @__PURE__ */ s(
1939
1950
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
1940
1951
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
1941
1952
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
1942
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1953
+ /* @__PURE__ */ c("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1943
1954
  "Redirecting to ",
1944
1955
  r,
1945
1956
  "..."
@@ -1949,41 +1960,41 @@ const Et = ({ redirectPath: r }) => /* @__PURE__ */ s(
1949
1960
  )
1950
1961
  }
1951
1962
  );
1952
- function xn({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
1953
- const { tenant: n, isLoading: i, error: o } = ge(), a = be();
1954
- return X(() => {
1963
+ function Rn({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
1964
+ const { tenant: n, isLoading: i, error: o } = ge(), a = Se();
1965
+ return ee(() => {
1955
1966
  process.env.NODE_ENV === "development" && console.warn(
1956
1967
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
1957
1968
  );
1958
- }, []), i || o ? null : n ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
1959
- /* @__PURE__ */ s(Et, { redirectPath: e }),
1960
- /* @__PURE__ */ s(me, { to: e, state: { from: a.pathname }, replace: !0 })
1969
+ }, []), i || o ? null : n ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ c(_, { children: [
1970
+ /* @__PURE__ */ s(Nt, { redirectPath: e }),
1971
+ /* @__PURE__ */ s(ye, { to: e, state: { from: a.pathname }, replace: !0 })
1961
1972
  ] }) : /* @__PURE__ */ s(_, { children: r });
1962
1973
  }
1963
- function Ft(r, e) {
1974
+ function Dt(r, e) {
1964
1975
  return e ? r ? Array.isArray(e) ? e.includes(r) : r === e : !1 : !0;
1965
1976
  }
1966
- function We(r, e) {
1977
+ function je(r, e) {
1967
1978
  return !r || r === "optional" ? "skip" : r === "required" ? e ? "pass" : "fail" : r === "forbidden" ? e ? "fail" : "pass" : "skip";
1968
1979
  }
1969
- function Nt(r, e) {
1970
- return We(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : We(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !Ft(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(r.permissions) ? "missing_permissions" : null;
1980
+ function Ct(r, e) {
1981
+ return je(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : je(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !Dt(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(r.permissions) ? "missing_permissions" : null;
1971
1982
  }
1972
- function Dt(r, e) {
1973
- return r.hasTenant ? r.isAuthenticated ? r.userType === se.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : r.isAuthenticated ? r.userType === se.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
1983
+ function Ut(r, e) {
1984
+ return r.hasTenant ? r.isAuthenticated ? r.userType === ie.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : r.isAuthenticated ? r.userType === ie.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
1974
1985
  }
1975
- function Ct(r, e, t, n, i) {
1986
+ function $t(r, e, t, n, i) {
1976
1987
  if (!e || i !== "url")
1977
1988
  return r;
1978
1989
  const o = typeof e == "string" ? e : t, a = r.includes("?") ? "&" : "?";
1979
1990
  return `${r}${a}${n}=${encodeURIComponent(o)}`;
1980
1991
  }
1981
- function Ut(r, e, t) {
1992
+ function Ht(r, e, t) {
1982
1993
  if (!r || t === "url") return;
1983
1994
  const n = typeof r == "string" ? r : e, i = "zone_return_to";
1984
1995
  t === "session" ? sessionStorage.setItem(i, n) : t === "local" && localStorage.setItem(i, n);
1985
1996
  }
1986
- const ae = ({
1997
+ const le = ({
1987
1998
  children: r,
1988
1999
  preset: e,
1989
2000
  tenant: t,
@@ -1994,39 +2005,39 @@ const ae = ({
1994
2005
  returnTo: p,
1995
2006
  onAccessDenied: f,
1996
2007
  redirectTo: w,
1997
- loadingFallback: u,
1998
- accessDeniedFallback: b
2008
+ loadingFallback: d,
2009
+ accessDeniedFallback: m
1999
2010
  }) => {
2000
- const g = be(), { isAuthenticated: T, isAuthInitializing: I, currentUser: N, userPermissions: M } = le(), { tenant: P, isTenantLoading: h } = he(), x = Pt(), S = Z(() => {
2011
+ const h = Se(), { isAuthenticated: v, isAuthInitializing: I, currentUser: F, userPermissions: M } = ce(), { tenant: P, isTenantLoading: u } = he(), A = It(), b = J(() => {
2001
2012
  if (e)
2002
- return x.presets[e];
2003
- }, [e, x.presets]), L = Z(
2013
+ return A.presets[e];
2014
+ }, [e, A.presets]), L = J(
2004
2015
  () => ({
2005
- tenant: t ?? (S == null ? void 0 : S.tenant),
2006
- auth: n ?? (S == null ? void 0 : S.auth),
2007
- userType: i ?? (S == null ? void 0 : S.userType),
2008
- permissions: o ?? (S == null ? void 0 : S.requiredPermissions),
2016
+ tenant: t ?? (b == null ? void 0 : b.tenant),
2017
+ auth: n ?? (b == null ? void 0 : b.auth),
2018
+ userType: i ?? (b == null ? void 0 : b.userType),
2019
+ permissions: o ?? (b == null ? void 0 : b.requiredPermissions),
2009
2020
  requireAllPermissions: a
2010
2021
  }),
2011
- [t, n, i, o, S, a]
2012
- ), E = Z(
2022
+ [t, n, i, o, b, a]
2023
+ ), E = J(
2013
2024
  () => ({
2014
2025
  hasTenant: !!P,
2015
- isAuthenticated: T,
2016
- userType: N == null ? void 0 : N.userType,
2026
+ isAuthenticated: v,
2027
+ userType: F == null ? void 0 : F.userType,
2017
2028
  permissions: M,
2018
- isLoading: I || h
2029
+ isLoading: I || u
2019
2030
  }),
2020
2031
  [
2021
2032
  P,
2022
- T,
2023
- N == null ? void 0 : N.userType,
2033
+ v,
2034
+ F == null ? void 0 : F.userType,
2024
2035
  M,
2025
2036
  I,
2026
- h
2037
+ u
2027
2038
  ]
2028
- ), C = Z(() => E.isLoading ? null : Nt(L, E), [L, E]), R = Z(() => C ? w || Dt(E, x.zoneRoots) : null, [C, w, E, x.zoneRoots]), $ = Z(() => !C || !R ? null : {
2029
- type: C,
2039
+ ), N = J(() => E.isLoading ? null : Ct(L, E), [L, E]), R = J(() => N ? w || Ut(E, A.zoneRoots) : null, [N, w, E, A.zoneRoots]), U = J(() => !N || !R ? null : {
2040
+ type: N,
2030
2041
  required: {
2031
2042
  tenant: L.tenant,
2032
2043
  auth: L.auth,
@@ -2040,34 +2051,34 @@ const ae = ({
2040
2051
  permissions: E.permissions
2041
2052
  },
2042
2053
  redirectTo: R
2043
- }, [C, R, L, E]);
2044
- if (X(() => {
2045
- $ && (f ? f($) : x.onAccessDenied && x.onAccessDenied($));
2046
- }, [$, f, x]), X(() => {
2047
- $ && p && Ut(p, g.pathname + g.search, x.returnToStorage);
2054
+ }, [N, R, L, E]);
2055
+ if (ee(() => {
2056
+ U && (f ? f(U) : A.onAccessDenied && A.onAccessDenied(U));
2057
+ }, [U, f, A]), ee(() => {
2058
+ U && p && Ht(p, h.pathname + h.search, A.returnToStorage);
2048
2059
  }, [
2049
- $,
2060
+ U,
2050
2061
  p,
2051
- g.pathname,
2052
- g.search,
2053
- x.returnToStorage
2062
+ h.pathname,
2063
+ h.search,
2064
+ A.returnToStorage
2054
2065
  ]), E.isLoading)
2055
- return /* @__PURE__ */ s(_, { children: u ?? x.loadingFallback ?? null });
2056
- if ($ && R) {
2057
- const l = b ?? x.accessDeniedFallback;
2066
+ return /* @__PURE__ */ s(_, { children: d ?? A.loadingFallback ?? null });
2067
+ if (U && R) {
2068
+ const l = m ?? A.accessDeniedFallback;
2058
2069
  if (l)
2059
2070
  return /* @__PURE__ */ s(_, { children: l });
2060
- const D = Ct(
2071
+ const D = $t(
2061
2072
  R,
2062
2073
  p,
2063
- g.pathname + g.search,
2064
- x.returnToParam,
2065
- x.returnToStorage
2074
+ h.pathname + h.search,
2075
+ A.returnToParam,
2076
+ A.returnToStorage
2066
2077
  );
2067
- return /* @__PURE__ */ s(me, { to: D, replace: !0 });
2078
+ return /* @__PURE__ */ s(ye, { to: D, replace: !0 });
2068
2079
  }
2069
2080
  return /* @__PURE__ */ s(_, { children: r });
2070
- }, Pn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", ...r }), Rn = (r) => /* @__PURE__ */ s(ae, { tenant: "forbidden", ...r }), In = (r) => /* @__PURE__ */ s(ae, { auth: "required", ...r }), Mn = (r) => /* @__PURE__ */ s(ae, { auth: "forbidden", ...r }), Ln = (r) => /* @__PURE__ */ s(ae, { auth: "required", userType: se.TENANT_ADMIN, ...r }), En = (r) => /* @__PURE__ */ s(ae, { auth: "required", userType: se.USER, ...r }), Fn = (r) => /* @__PURE__ */ s(ae, { tenant: "optional", auth: "optional", ...r }), Nn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "required", ...r }), Dn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "optional", ...r }), Cn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "forbidden", ...r }), $t = () => /* @__PURE__ */ d(
2081
+ }, In = (r) => /* @__PURE__ */ s(le, { tenant: "required", ...r }), Mn = (r) => /* @__PURE__ */ s(le, { tenant: "forbidden", ...r }), Ln = (r) => /* @__PURE__ */ s(le, { auth: "required", ...r }), En = (r) => /* @__PURE__ */ s(le, { auth: "forbidden", ...r }), Fn = (r) => /* @__PURE__ */ s(le, { auth: "required", userType: ie.TENANT_ADMIN, ...r }), Nn = (r) => /* @__PURE__ */ s(le, { auth: "required", userType: ie.USER, ...r }), Dn = (r) => /* @__PURE__ */ s(le, { tenant: "optional", auth: "optional", ...r }), Cn = (r) => /* @__PURE__ */ s(le, { tenant: "required", auth: "required", ...r }), Un = (r) => /* @__PURE__ */ s(le, { tenant: "required", auth: "optional", ...r }), $n = (r) => /* @__PURE__ */ s(le, { tenant: "required", auth: "forbidden", ...r }), Bt = () => /* @__PURE__ */ c(
2071
2082
  "div",
2072
2083
  {
2073
2084
  style: {
@@ -2084,13 +2095,13 @@ const ae = ({
2084
2095
  ]
2085
2096
  }
2086
2097
  );
2087
- function Un({
2098
+ function Hn({
2088
2099
  children: r,
2089
- fallback: e = /* @__PURE__ */ s($t, {}),
2100
+ fallback: e = /* @__PURE__ */ s(Bt, {}),
2090
2101
  allowedPlans: t,
2091
2102
  requiredFeature: n
2092
2103
  }) {
2093
- const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: p } = xt();
2104
+ const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: p } = Rt();
2094
2105
  return p ? /* @__PURE__ */ s(
2095
2106
  "div",
2096
2107
  {
@@ -2103,7 +2114,7 @@ function Un({
2103
2114
  }
2104
2115
  ) : i ? i.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ s(_, { children: e }) : n && !a(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: r }) : /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: e });
2105
2116
  }
2106
- const Ht = ({ flagName: r }) => /* @__PURE__ */ d(
2117
+ const qt = ({ flagName: r }) => /* @__PURE__ */ c(
2107
2118
  "div",
2108
2119
  {
2109
2120
  style: {
@@ -2122,7 +2133,7 @@ const Ht = ({ flagName: r }) => /* @__PURE__ */ d(
2122
2133
  children: [
2123
2134
  /* @__PURE__ */ s("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
2124
2135
  /* @__PURE__ */ s("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
2125
- /* @__PURE__ */ d("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2136
+ /* @__PURE__ */ c("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2126
2137
  'Feature flag "',
2127
2138
  r,
2128
2139
  '" is disabled'
@@ -2130,8 +2141,8 @@ const Ht = ({ flagName: r }) => /* @__PURE__ */ d(
2130
2141
  ]
2131
2142
  }
2132
2143
  );
2133
- function $n({ name: r, children: e, fallback: t }) {
2134
- const { isEnabled: n, loading: i } = kt();
2144
+ function Bn({ name: r, children: e, fallback: t }) {
2145
+ const { isEnabled: n, loading: i } = At();
2135
2146
  return i ? /* @__PURE__ */ s(
2136
2147
  "div",
2137
2148
  {
@@ -2145,9 +2156,9 @@ function $n({ name: r, children: e, fallback: t }) {
2145
2156
  },
2146
2157
  children: "Loading feature flags..."
2147
2158
  }
2148
- ) : n(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(Ht, { flagName: r }) });
2159
+ ) : n(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(qt, { flagName: r }) });
2149
2160
  }
2150
- const Bt = () => /* @__PURE__ */ d(
2161
+ const Ot = () => /* @__PURE__ */ c(
2151
2162
  "svg",
2152
2163
  {
2153
2164
  width: "16",
@@ -2164,7 +2175,7 @@ const Bt = () => /* @__PURE__ */ d(
2164
2175
  /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "3" })
2165
2176
  ]
2166
2177
  }
2167
- ), qt = () => /* @__PURE__ */ d(
2178
+ ), zt = () => /* @__PURE__ */ c(
2168
2179
  "svg",
2169
2180
  {
2170
2181
  width: "16",
@@ -2181,10 +2192,10 @@ const Bt = () => /* @__PURE__ */ d(
2181
2192
  /* @__PURE__ */ s("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2182
2193
  ]
2183
2194
  }
2184
- ), Ot = {
2185
- showPassword: /* @__PURE__ */ s(Bt, {}),
2186
- hidePassword: /* @__PURE__ */ s(qt, {})
2187
- }, zt = {
2195
+ ), _t = {
2196
+ showPassword: /* @__PURE__ */ s(Ot, {}),
2197
+ hidePassword: /* @__PURE__ */ s(zt, {})
2198
+ }, Wt = {
2188
2199
  title: "Sign In",
2189
2200
  usernameLabel: "Email or Phone",
2190
2201
  usernamePlaceholder: "Enter your email or phone number",
@@ -2198,7 +2209,7 @@ const Bt = () => /* @__PURE__ */ d(
2198
2209
  magicLinkLink: "Use Magic Link",
2199
2210
  errorMessage: "Invalid credentials",
2200
2211
  loadingText: "Signing in..."
2201
- }, _t = {
2212
+ }, Vt = {
2202
2213
  container: {
2203
2214
  maxWidth: "400px",
2204
2215
  width: "100%",
@@ -2305,7 +2316,7 @@ const Bt = () => /* @__PURE__ */ d(
2305
2316
  fontSize: "0.875rem"
2306
2317
  }
2307
2318
  };
2308
- function Hn({
2319
+ function qn({
2309
2320
  copy: r = {},
2310
2321
  styles: e = {},
2311
2322
  icons: t = {},
@@ -2316,45 +2327,45 @@ function Hn({
2316
2327
  onMagicLinkClick: p,
2317
2328
  showForgotPassword: f = !0,
2318
2329
  showSignupLink: w = !0,
2319
- showMagicLinkOption: u = !0,
2320
- className: b
2330
+ showMagicLinkOption: d = !0,
2331
+ className: m
2321
2332
  }) {
2322
- const [g, T] = A(""), [I, N] = A(""), [M, P] = A(!1), [h, x] = A(!1), [S, L] = A(""), [E, C] = A({}), { login: R } = le(), { tenant: $ } = ge(), l = { ...zt, ...r }, D = { ..._t, ...e }, U = { ...Ot, ...t }, c = () => {
2323
- const m = {};
2324
- return g.trim() || (m.username = !0), I.trim() || (m.password = !0), C(m), Object.keys(m).length === 0;
2325
- }, H = async (m) => {
2326
- if (m.preventDefault(), !!c()) {
2327
- if (!($ != null && $.id)) {
2333
+ const [h, v] = x(""), [I, F] = x(""), [M, P] = x(!1), [u, A] = x(!1), [b, L] = x(""), [E, N] = x({}), { login: R } = ce(), { tenant: U } = ge(), l = { ...Wt, ...r }, D = { ...Vt, ...e }, $ = { ..._t, ...t }, g = () => {
2334
+ const y = {};
2335
+ return h.trim() || (y.username = !0), I.trim() || (y.password = !0), N(y), Object.keys(y).length === 0;
2336
+ }, C = async (y) => {
2337
+ if (y.preventDefault(), !!g()) {
2338
+ if (!(U != null && U.id)) {
2328
2339
  L("Tenant not found");
2329
2340
  return;
2330
2341
  }
2331
- x(!0), L("");
2342
+ A(!0), L("");
2332
2343
  try {
2333
- const v = await R({
2334
- username: g,
2344
+ const k = await R({
2345
+ username: h,
2335
2346
  password: I
2336
2347
  // tenantId inferred from context automatically
2337
2348
  });
2338
- n == null || n(v);
2339
- } catch (v) {
2340
- const G = v.message || l.errorMessage;
2341
- L(G), i == null || i(G);
2349
+ n == null || n(k);
2350
+ } catch (k) {
2351
+ const j = k.message || l.errorMessage;
2352
+ L(j), i == null || i(j);
2342
2353
  } finally {
2343
- x(!1);
2354
+ A(!1);
2344
2355
  }
2345
2356
  }
2346
- }, F = (m) => ({
2357
+ }, T = (y) => ({
2347
2358
  ...D.input,
2348
- ...E[m] ? D.inputError : {}
2349
- }), y = () => ({
2359
+ ...E[y] ? D.inputError : {}
2360
+ }), S = () => ({
2350
2361
  ...D.button,
2351
- ...h ? D.buttonLoading : {},
2352
- ...!g || !I || h ? D.buttonDisabled : {}
2362
+ ...u ? D.buttonLoading : {},
2363
+ ...!h || !I || u ? D.buttonDisabled : {}
2353
2364
  });
2354
- return /* @__PURE__ */ d("div", { className: b, style: D.container, children: [
2365
+ return /* @__PURE__ */ c("div", { className: m, style: D.container, children: [
2355
2366
  /* @__PURE__ */ s("h2", { style: D.title, children: l.title }),
2356
- /* @__PURE__ */ d("form", { onSubmit: H, style: D.form, children: [
2357
- /* @__PURE__ */ d("div", { style: D.fieldGroup, children: [
2367
+ /* @__PURE__ */ c("form", { onSubmit: C, style: D.form, children: [
2368
+ /* @__PURE__ */ c("div", { style: D.fieldGroup, children: [
2358
2369
  /* @__PURE__ */ s("label", { style: D.label, children: l.usernameLabel }),
2359
2370
  /* @__PURE__ */ s(
2360
2371
  "input",
@@ -2362,19 +2373,19 @@ function Hn({
2362
2373
  id: "username",
2363
2374
  name: "username",
2364
2375
  type: "text",
2365
- value: g,
2366
- onChange: (m) => {
2367
- T(m.target.value), E.username && C((v) => ({ ...v, username: !1 }));
2376
+ value: h,
2377
+ onChange: (y) => {
2378
+ v(y.target.value), E.username && N((k) => ({ ...k, username: !1 }));
2368
2379
  },
2369
2380
  placeholder: l.usernamePlaceholder,
2370
- style: F("username"),
2371
- disabled: h
2381
+ style: T("username"),
2382
+ disabled: u
2372
2383
  }
2373
2384
  )
2374
2385
  ] }),
2375
- /* @__PURE__ */ d("div", { style: D.fieldGroup, children: [
2386
+ /* @__PURE__ */ c("div", { style: D.fieldGroup, children: [
2376
2387
  /* @__PURE__ */ s("label", { style: D.label, children: l.passwordLabel }),
2377
- /* @__PURE__ */ d("div", { style: D.inputContainer, children: [
2388
+ /* @__PURE__ */ c("div", { style: D.inputContainer, children: [
2378
2389
  /* @__PURE__ */ s(
2379
2390
  "input",
2380
2391
  {
@@ -2382,16 +2393,16 @@ function Hn({
2382
2393
  name: "password",
2383
2394
  type: M ? "text" : "password",
2384
2395
  value: I,
2385
- onChange: (m) => {
2386
- N(m.target.value), E.password && C((v) => ({ ...v, password: !1 }));
2396
+ onChange: (y) => {
2397
+ F(y.target.value), E.password && N((k) => ({ ...k, password: !1 }));
2387
2398
  },
2388
2399
  placeholder: l.passwordPlaceholder,
2389
2400
  style: {
2390
- ...F("password"),
2401
+ ...T("password"),
2391
2402
  paddingRight: "2.5rem"
2392
2403
  // Make room for the icon
2393
2404
  },
2394
- disabled: h
2405
+ disabled: u
2395
2406
  }
2396
2407
  ),
2397
2408
  /* @__PURE__ */ s(
@@ -2400,29 +2411,29 @@ function Hn({
2400
2411
  type: "button",
2401
2412
  onClick: () => P(!M),
2402
2413
  style: D.passwordToggle,
2403
- disabled: h,
2414
+ disabled: u,
2404
2415
  "aria-label": M ? "Hide password" : "Show password",
2405
- children: M ? U.hidePassword : U.showPassword
2416
+ children: M ? $.hidePassword : $.showPassword
2406
2417
  }
2407
2418
  )
2408
2419
  ] })
2409
2420
  ] }),
2410
- /* @__PURE__ */ s("button", { type: "submit", disabled: !g || !I || h, style: y(), children: h ? l.loadingText : l.submitButton }),
2411
- S && /* @__PURE__ */ s("div", { style: D.errorText, children: S })
2421
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !h || !I || u, style: S(), children: u ? l.loadingText : l.submitButton }),
2422
+ b && /* @__PURE__ */ s("div", { style: D.errorText, children: b })
2412
2423
  ] }),
2413
- (f || w || u) && /* @__PURE__ */ d("div", { style: D.linkContainer, children: [
2414
- u && /* @__PURE__ */ d("div", { children: [
2415
- /* @__PURE__ */ d("span", { style: D.divider, children: [
2424
+ (f || w || d) && /* @__PURE__ */ c("div", { style: D.linkContainer, children: [
2425
+ d && /* @__PURE__ */ c("div", { children: [
2426
+ /* @__PURE__ */ c("span", { style: D.divider, children: [
2416
2427
  l.magicLinkText,
2417
2428
  " "
2418
2429
  ] }),
2419
2430
  /* @__PURE__ */ s("a", { onClick: p, style: D.link, children: l.magicLinkLink })
2420
2431
  ] }),
2421
- u && (f || w) && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2432
+ d && (f || w) && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2422
2433
  f && /* @__PURE__ */ s("a", { onClick: o, style: D.link, children: l.forgotPasswordLink }),
2423
2434
  f && w && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2424
- w && /* @__PURE__ */ d("div", { children: [
2425
- /* @__PURE__ */ d("span", { style: D.divider, children: [
2435
+ w && /* @__PURE__ */ c("div", { children: [
2436
+ /* @__PURE__ */ c("span", { style: D.divider, children: [
2426
2437
  l.signupText,
2427
2438
  " "
2428
2439
  ] }),
@@ -2431,7 +2442,7 @@ function Hn({
2431
2442
  ] })
2432
2443
  ] });
2433
2444
  }
2434
- const Wt = {
2445
+ const jt = {
2435
2446
  title: "Create Account",
2436
2447
  nameLabel: "First Name",
2437
2448
  namePlaceholder: "Enter your first name",
@@ -2457,7 +2468,7 @@ const Wt = {
2457
2468
  passwordMismatchError: "Passwords do not match",
2458
2469
  isAdminLabel: "Create new organization",
2459
2470
  isAdminDescription: "Check this if you want to create a new organization"
2460
- }, Vt = {
2471
+ }, Gt = {
2461
2472
  container: {
2462
2473
  maxWidth: "400px",
2463
2474
  width: "100%",
@@ -2556,7 +2567,7 @@ const Wt = {
2556
2567
  fontSize: "0.875rem"
2557
2568
  }
2558
2569
  };
2559
- function Bn({
2570
+ function On({
2560
2571
  copy: r = {},
2561
2572
  styles: e = {},
2562
2573
  signupType: t = "user",
@@ -2568,91 +2579,91 @@ function Bn({
2568
2579
  showMagicLinkOption: f = !0,
2569
2580
  className: w
2570
2581
  }) {
2571
- const [u, b] = A(""), [g, T] = A(""), [I, N] = A(""), [M, P] = A(""), [h, x] = A(""), [S, L] = A(""), [E, C] = A(""), [R, $] = A(!1), [l, D] = A(""), [U, c] = A({}), { signup: H, signupTenantAdmin: F } = le(), { tenant: y } = ge(), m = { ...Wt, ...r }, v = { ...Vt, ...e }, G = () => {
2572
- const k = {};
2573
- return u.trim() || (k.name = !0), !I.trim() && !M.trim() && (k.email = !0, k.phoneNumber = !0), h.trim() || (k.password = !0), S.trim() || (k.confirmPassword = !0), t === "tenant" && !E.trim() && (k.tenantName = !0), c(k), Object.keys(k).length === 0;
2574
- }, Y = async (k) => {
2575
- if (k.preventDefault(), !!G()) {
2576
- if (h !== S) {
2577
- D(m.passwordMismatchError), c({ confirmPassword: !0 });
2582
+ const [d, m] = x(""), [h, v] = x(""), [I, F] = x(""), [M, P] = x(""), [u, A] = x(""), [b, L] = x(""), [E, N] = x(""), [R, U] = x(!1), [l, D] = x(""), [$, g] = x({}), { signup: C, signupTenantAdmin: T } = ce(), { tenant: S } = ge(), y = { ...jt, ...r }, k = { ...Gt, ...e }, j = () => {
2583
+ const B = {};
2584
+ return d.trim() || (B.name = !0), !I.trim() && !M.trim() && (B.email = !0, B.phoneNumber = !0), u.trim() || (B.password = !0), b.trim() || (B.confirmPassword = !0), t === "tenant" && !E.trim() && (B.tenantName = !0), g(B), Object.keys(B).length === 0;
2585
+ }, Z = async (B) => {
2586
+ if (B.preventDefault(), !!j()) {
2587
+ if (u !== b) {
2588
+ D(y.passwordMismatchError), g({ confirmPassword: !0 });
2578
2589
  return;
2579
2590
  }
2580
- if (t === "user" && !(y != null && y.id)) {
2591
+ if (t === "user" && !(S != null && S.id)) {
2581
2592
  D("Tenant not found");
2582
2593
  return;
2583
2594
  }
2584
- $(!0), D("");
2595
+ U(!0), D("");
2585
2596
  try {
2586
- let K;
2587
- t === "tenant" ? K = await F({
2597
+ let X;
2598
+ t === "tenant" ? X = await T({
2588
2599
  email: I || void 0,
2589
2600
  phoneNumber: M || void 0,
2590
- name: u,
2591
- password: h,
2601
+ name: d,
2602
+ password: u,
2592
2603
  tenantName: E,
2593
- lastName: g || void 0
2594
- }) : K = await H({
2604
+ lastName: h || void 0
2605
+ }) : X = await C({
2595
2606
  email: I || void 0,
2596
2607
  phoneNumber: M || void 0,
2597
- name: u,
2598
- password: h,
2599
- tenantId: y.id,
2600
- lastName: g || void 0
2601
- }), n == null || n(K);
2602
- } catch (K) {
2603
- const ce = K.message || m.errorMessage;
2604
- D(ce), i == null || i(ce);
2608
+ name: d,
2609
+ password: u,
2610
+ tenantId: S.id,
2611
+ lastName: h || void 0
2612
+ }), n == null || n(X);
2613
+ } catch (X) {
2614
+ const G = X.message || y.errorMessage;
2615
+ D(G), i == null || i(G);
2605
2616
  } finally {
2606
- $(!1);
2617
+ U(!1);
2607
2618
  }
2608
2619
  }
2609
- }, q = (k) => ({
2610
- ...v.input,
2611
- ...U[k] ? v.inputError : {}
2612
- }), O = () => ({
2613
- ...v.button,
2614
- ...R ? v.buttonLoading : {},
2615
- ...!u || !I && !M || !h || !S || R || t === "tenant" && !E ? v.buttonDisabled : {}
2616
- }), V = u && (I || M) && h && S && (t === "user" || E);
2617
- return /* @__PURE__ */ d("div", { className: w, style: v.container, children: [
2618
- /* @__PURE__ */ s("h2", { style: v.title, children: m.title }),
2619
- /* @__PURE__ */ d("form", { onSubmit: Y, style: v.form, children: [
2620
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2621
- /* @__PURE__ */ s("label", { style: v.label, children: m.nameLabel }),
2620
+ }, O = (B) => ({
2621
+ ...k.input,
2622
+ ...$[B] ? k.inputError : {}
2623
+ }), q = () => ({
2624
+ ...k.button,
2625
+ ...R ? k.buttonLoading : {},
2626
+ ...!d || !I && !M || !u || !b || R || t === "tenant" && !E ? k.buttonDisabled : {}
2627
+ }), W = d && (I || M) && u && b && (t === "user" || E);
2628
+ return /* @__PURE__ */ c("div", { className: w, style: k.container, children: [
2629
+ /* @__PURE__ */ s("h2", { style: k.title, children: y.title }),
2630
+ /* @__PURE__ */ c("form", { onSubmit: Z, style: k.form, children: [
2631
+ /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2632
+ /* @__PURE__ */ s("label", { style: k.label, children: y.nameLabel }),
2622
2633
  /* @__PURE__ */ s(
2623
2634
  "input",
2624
2635
  {
2625
2636
  id: "name",
2626
2637
  name: "name",
2627
2638
  type: "text",
2628
- value: u,
2629
- onChange: (k) => {
2630
- b(k.target.value), U.name && c((K) => ({ ...K, name: !1 }));
2639
+ value: d,
2640
+ onChange: (B) => {
2641
+ m(B.target.value), $.name && g((X) => ({ ...X, name: !1 }));
2631
2642
  },
2632
- placeholder: m.namePlaceholder,
2633
- style: q("name"),
2643
+ placeholder: y.namePlaceholder,
2644
+ style: O("name"),
2634
2645
  disabled: R
2635
2646
  }
2636
2647
  )
2637
2648
  ] }),
2638
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2639
- /* @__PURE__ */ s("label", { style: v.label, children: m.lastNameLabel }),
2649
+ /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2650
+ /* @__PURE__ */ s("label", { style: k.label, children: y.lastNameLabel }),
2640
2651
  /* @__PURE__ */ s(
2641
2652
  "input",
2642
2653
  {
2643
2654
  id: "lastName",
2644
2655
  name: "lastName",
2645
2656
  type: "text",
2646
- value: g,
2647
- onChange: (k) => T(k.target.value),
2648
- placeholder: m.lastNamePlaceholder,
2649
- style: v.input,
2657
+ value: h,
2658
+ onChange: (B) => v(B.target.value),
2659
+ placeholder: y.lastNamePlaceholder,
2660
+ style: k.input,
2650
2661
  disabled: R
2651
2662
  }
2652
2663
  )
2653
2664
  ] }),
2654
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2655
- /* @__PURE__ */ s("label", { style: v.label, children: m.emailLabel }),
2665
+ /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2666
+ /* @__PURE__ */ s("label", { style: k.label, children: y.emailLabel }),
2656
2667
  /* @__PURE__ */ s(
2657
2668
  "input",
2658
2669
  {
@@ -2660,17 +2671,17 @@ function Bn({
2660
2671
  name: "email",
2661
2672
  type: "email",
2662
2673
  value: I,
2663
- onChange: (k) => {
2664
- N(k.target.value), U.email && c((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2674
+ onChange: (B) => {
2675
+ F(B.target.value), $.email && g((X) => ({ ...X, email: !1, phoneNumber: !1 }));
2665
2676
  },
2666
- placeholder: m.emailPlaceholder,
2667
- style: q("email"),
2677
+ placeholder: y.emailPlaceholder,
2678
+ style: O("email"),
2668
2679
  disabled: R
2669
2680
  }
2670
2681
  )
2671
2682
  ] }),
2672
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2673
- /* @__PURE__ */ s("label", { style: v.label, children: m.phoneNumberLabel }),
2683
+ /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2684
+ /* @__PURE__ */ s("label", { style: k.label, children: y.phoneNumberLabel }),
2674
2685
  /* @__PURE__ */ s(
2675
2686
  "input",
2676
2687
  {
@@ -2678,11 +2689,11 @@ function Bn({
2678
2689
  name: "phoneNumber",
2679
2690
  type: "tel",
2680
2691
  value: M,
2681
- onChange: (k) => {
2682
- P(k.target.value), U.phoneNumber && c((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2692
+ onChange: (B) => {
2693
+ P(B.target.value), $.phoneNumber && g((X) => ({ ...X, email: !1, phoneNumber: !1 }));
2683
2694
  },
2684
- placeholder: m.phoneNumberPlaceholder,
2685
- style: q("phoneNumber"),
2695
+ placeholder: y.phoneNumberPlaceholder,
2696
+ style: O("phoneNumber"),
2686
2697
  disabled: R
2687
2698
  }
2688
2699
  )
@@ -2699,44 +2710,44 @@ function Bn({
2699
2710
  children: "At least one contact method (email or phone) is required"
2700
2711
  }
2701
2712
  ),
2702
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2703
- /* @__PURE__ */ s("label", { style: v.label, children: m.passwordLabel }),
2713
+ /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2714
+ /* @__PURE__ */ s("label", { style: k.label, children: y.passwordLabel }),
2704
2715
  /* @__PURE__ */ s(
2705
2716
  "input",
2706
2717
  {
2707
2718
  id: "password",
2708
2719
  name: "password",
2709
2720
  type: "password",
2710
- value: h,
2711
- onChange: (k) => {
2712
- x(k.target.value), U.password && c((K) => ({ ...K, password: !1 }));
2721
+ value: u,
2722
+ onChange: (B) => {
2723
+ A(B.target.value), $.password && g((X) => ({ ...X, password: !1 }));
2713
2724
  },
2714
- placeholder: m.passwordPlaceholder,
2715
- style: q("password"),
2725
+ placeholder: y.passwordPlaceholder,
2726
+ style: O("password"),
2716
2727
  disabled: R
2717
2728
  }
2718
2729
  )
2719
2730
  ] }),
2720
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2721
- /* @__PURE__ */ s("label", { style: v.label, children: m.confirmPasswordLabel }),
2731
+ /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2732
+ /* @__PURE__ */ s("label", { style: k.label, children: y.confirmPasswordLabel }),
2722
2733
  /* @__PURE__ */ s(
2723
2734
  "input",
2724
2735
  {
2725
2736
  id: "confirmPassword",
2726
2737
  name: "confirmPassword",
2727
2738
  type: "password",
2728
- value: S,
2729
- onChange: (k) => {
2730
- L(k.target.value), U.confirmPassword && c((K) => ({ ...K, confirmPassword: !1 })), l === m.passwordMismatchError && D("");
2739
+ value: b,
2740
+ onChange: (B) => {
2741
+ L(B.target.value), $.confirmPassword && g((X) => ({ ...X, confirmPassword: !1 })), l === y.passwordMismatchError && D("");
2731
2742
  },
2732
- placeholder: m.confirmPasswordPlaceholder,
2733
- style: q("confirmPassword"),
2743
+ placeholder: y.confirmPasswordPlaceholder,
2744
+ style: O("confirmPassword"),
2734
2745
  disabled: R
2735
2746
  }
2736
2747
  )
2737
2748
  ] }),
2738
- t === "tenant" && /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2739
- /* @__PURE__ */ s("label", { style: v.label, children: m.tenantNameLabel }),
2749
+ t === "tenant" && /* @__PURE__ */ c("div", { style: k.fieldGroup, children: [
2750
+ /* @__PURE__ */ s("label", { style: k.label, children: y.tenantNameLabel }),
2740
2751
  /* @__PURE__ */ s(
2741
2752
  "input",
2742
2753
  {
@@ -2744,38 +2755,38 @@ function Bn({
2744
2755
  name: "tenantName",
2745
2756
  type: "text",
2746
2757
  value: E,
2747
- onChange: (k) => {
2748
- C(k.target.value), U.tenantName && c((K) => ({ ...K, tenantName: !1 }));
2758
+ onChange: (B) => {
2759
+ N(B.target.value), $.tenantName && g((X) => ({ ...X, tenantName: !1 }));
2749
2760
  },
2750
- placeholder: m.tenantNamePlaceholder,
2751
- style: q("tenantName"),
2761
+ placeholder: y.tenantNamePlaceholder,
2762
+ style: O("tenantName"),
2752
2763
  disabled: R
2753
2764
  }
2754
2765
  )
2755
2766
  ] }),
2756
- /* @__PURE__ */ s("button", { type: "submit", disabled: !V || R, style: O(), children: R ? m.loadingText : m.submitButton }),
2757
- l && /* @__PURE__ */ s("div", { style: v.errorText, children: l })
2767
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !W || R, style: q(), children: R ? y.loadingText : y.submitButton }),
2768
+ l && /* @__PURE__ */ s("div", { style: k.errorText, children: l })
2758
2769
  ] }),
2759
- (p || f) && /* @__PURE__ */ d("div", { style: v.linkContainer, children: [
2760
- f && /* @__PURE__ */ d("div", { children: [
2761
- /* @__PURE__ */ d("span", { style: v.divider, children: [
2762
- m.magicLinkText,
2770
+ (p || f) && /* @__PURE__ */ c("div", { style: k.linkContainer, children: [
2771
+ f && /* @__PURE__ */ c("div", { children: [
2772
+ /* @__PURE__ */ c("span", { style: k.divider, children: [
2773
+ y.magicLinkText,
2763
2774
  " "
2764
2775
  ] }),
2765
- /* @__PURE__ */ s("a", { onClick: a, style: v.link, children: m.magicLinkLink })
2776
+ /* @__PURE__ */ s("a", { onClick: a, style: k.link, children: y.magicLinkLink })
2766
2777
  ] }),
2767
- f && p && /* @__PURE__ */ s("div", { style: v.divider, children: "•" }),
2768
- p && /* @__PURE__ */ d("div", { children: [
2769
- /* @__PURE__ */ d("span", { style: v.divider, children: [
2770
- m.loginText,
2778
+ f && p && /* @__PURE__ */ s("div", { style: k.divider, children: "•" }),
2779
+ p && /* @__PURE__ */ c("div", { children: [
2780
+ /* @__PURE__ */ c("span", { style: k.divider, children: [
2781
+ y.loginText,
2771
2782
  " "
2772
2783
  ] }),
2773
- /* @__PURE__ */ s("a", { onClick: o, style: v.link, children: m.loginLink })
2784
+ /* @__PURE__ */ s("a", { onClick: o, style: k.link, children: y.loginLink })
2774
2785
  ] })
2775
2786
  ] })
2776
2787
  ] });
2777
2788
  }
2778
- const jt = {
2789
+ const Zt = {
2779
2790
  title: "Sign In with Magic Link",
2780
2791
  emailLabel: "Email",
2781
2792
  emailPlaceholder: "Enter your email",
@@ -2793,7 +2804,7 @@ const jt = {
2793
2804
  loadingText: "Sending magic link...",
2794
2805
  verifyingText: "Verifying magic link...",
2795
2806
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2796
- }, Gt = {
2807
+ }, Kt = {
2797
2808
  container: {
2798
2809
  maxWidth: "400px",
2799
2810
  width: "100%",
@@ -2896,7 +2907,7 @@ const jt = {
2896
2907
  fontSize: "0.875rem"
2897
2908
  }
2898
2909
  };
2899
- function qn({
2910
+ function zn({
2900
2911
  copy: r = {},
2901
2912
  styles: e = {},
2902
2913
  onSuccess: t,
@@ -2908,85 +2919,85 @@ function qn({
2908
2919
  verifyToken: f,
2909
2920
  frontendUrl: w
2910
2921
  }) {
2911
- const [u, b] = A(""), [g, T] = A(""), [I, N] = A(""), [M, P] = A(!1), [h, x] = A(!1), [S, L] = A(""), [E, C] = A(""), [R, $] = A({}), [l, D] = A(!1), { sendMagicLink: U, verifyMagicLink: c } = le(), { tenant: H } = ge(), F = { ...jt, ...r }, y = { ...Gt, ...e };
2912
- X(() => {
2913
- f && m(f);
2922
+ const [d, m] = x(""), [h, v] = x(""), [I, F] = x(""), [M, P] = x(!1), [u, A] = x(!1), [b, L] = x(""), [E, N] = x(""), [R, U] = x({}), [l, D] = x(!1), { sendMagicLink: $, verifyMagicLink: g } = ce(), { tenant: C } = ge(), T = { ...Zt, ...r }, S = { ...Kt, ...e };
2923
+ ee(() => {
2924
+ f && y(f);
2914
2925
  }, [f]);
2915
- const m = async (O) => {
2916
- if (!H || !u) {
2926
+ const y = async (q) => {
2927
+ if (!C || !d) {
2917
2928
  L("Missing tenant or email");
2918
2929
  return;
2919
2930
  }
2920
- x(!0), L("");
2931
+ A(!0), L("");
2921
2932
  try {
2922
- const V = await c({
2923
- token: O,
2924
- email: u
2933
+ const W = await g({
2934
+ token: q,
2935
+ email: d
2925
2936
  // tenantId inferred from context automatically
2926
2937
  });
2927
- t == null || t(V);
2928
- } catch (V) {
2929
- const k = V.message || "Failed to verify magic link";
2930
- L(k), n == null || n(k);
2938
+ t == null || t(W);
2939
+ } catch (W) {
2940
+ const B = W.message || "Failed to verify magic link";
2941
+ L(B), n == null || n(B);
2931
2942
  } finally {
2932
- x(!1);
2943
+ A(!1);
2933
2944
  }
2934
- }, v = () => {
2935
- const O = {};
2936
- return u.trim() || (O.email = !0), l && !g.trim() && (O.name = !0), $(O), Object.keys(O).length === 0;
2937
- }, G = async (O) => {
2938
- if (O.preventDefault(), !!v()) {
2939
- if (!(H != null && H.id)) {
2945
+ }, k = () => {
2946
+ const q = {};
2947
+ return d.trim() || (q.email = !0), l && !h.trim() && (q.name = !0), U(q), Object.keys(q).length === 0;
2948
+ }, j = async (q) => {
2949
+ if (q.preventDefault(), !!k()) {
2950
+ if (!(C != null && C.id)) {
2940
2951
  L("Tenant not found");
2941
2952
  return;
2942
2953
  }
2943
- P(!0), L(""), C("");
2954
+ P(!0), L(""), N("");
2944
2955
  try {
2945
- const V = w || (typeof window < "u" ? window.location.origin : ""), k = await U({
2946
- email: u,
2947
- tenantId: H.id,
2948
- frontendUrl: V,
2949
- name: l ? g : void 0,
2956
+ const W = w || (typeof window < "u" ? window.location.origin : ""), B = await $({
2957
+ email: d,
2958
+ tenantId: C.id,
2959
+ frontendUrl: W,
2960
+ name: l ? h : void 0,
2950
2961
  lastName: l ? I : void 0
2951
2962
  });
2952
- C(F.successMessage), t == null || t(k);
2953
- } catch (V) {
2954
- const k = V.message || F.errorMessage;
2955
- L(k), n == null || n(k);
2963
+ N(T.successMessage), t == null || t(B);
2964
+ } catch (W) {
2965
+ const B = W.message || T.errorMessage;
2966
+ L(B), n == null || n(B);
2956
2967
  } finally {
2957
2968
  P(!1);
2958
2969
  }
2959
2970
  }
2960
- }, Y = (O) => ({
2961
- ...y.input,
2962
- ...R[O] ? y.inputError : {}
2963
- }), q = () => ({
2964
- ...y.button,
2965
- ...M || h ? y.buttonLoading : {},
2966
- ...!u || M || h ? y.buttonDisabled : {}
2971
+ }, Z = (q) => ({
2972
+ ...S.input,
2973
+ ...R[q] ? S.inputError : {}
2974
+ }), O = () => ({
2975
+ ...S.button,
2976
+ ...M || u ? S.buttonLoading : {},
2977
+ ...!d || M || u ? S.buttonDisabled : {}
2967
2978
  });
2968
- return h ? /* @__PURE__ */ d("div", { className: p, style: y.container, children: [
2969
- /* @__PURE__ */ s("h2", { style: y.title, children: F.verifyingText }),
2979
+ return u ? /* @__PURE__ */ c("div", { className: p, style: S.container, children: [
2980
+ /* @__PURE__ */ s("h2", { style: S.title, children: T.verifyingText }),
2970
2981
  /* @__PURE__ */ s("div", { style: { textAlign: "center", padding: "2rem" }, children: /* @__PURE__ */ s("div", { style: { fontSize: "1rem", color: "#6b7280" }, children: "Please wait while we verify your magic link..." }) })
2971
- ] }) : /* @__PURE__ */ d("div", { className: p, style: y.container, children: [
2972
- /* @__PURE__ */ s("h2", { style: y.title, children: F.title }),
2973
- /* @__PURE__ */ s("p", { style: y.description, children: F.description }),
2974
- /* @__PURE__ */ d("form", { onSubmit: G, style: y.form, children: [
2975
- /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
2976
- /* @__PURE__ */ s("label", { style: y.label, children: F.emailLabel }),
2982
+ ] }) : /* @__PURE__ */ c("div", { className: p, style: S.container, children: [
2983
+ /* @__PURE__ */ s("h2", { style: S.title, children: T.title }),
2984
+ /* @__PURE__ */ s("p", { style: S.description, children: T.description }),
2985
+ /* @__PURE__ */ c("form", { onSubmit: j, style: S.form, children: [
2986
+ /* @__PURE__ */ c("div", { style: S.fieldGroup, children: [
2987
+ /* @__PURE__ */ s("label", { style: S.label, children: T.emailLabel }),
2977
2988
  /* @__PURE__ */ s(
2978
2989
  "input",
2979
2990
  {
2980
2991
  id: "email",
2981
2992
  name: "email",
2982
2993
  type: "email",
2983
- value: u,
2984
- onChange: (O) => {
2985
- b(O.target.value), R.email && $((V) => ({ ...V, email: !1 }));
2994
+ value: d,
2995
+ onChange: (q) => {
2996
+ m(q.target.value), R.email && U((W) => ({ ...W, email: !1 }));
2986
2997
  },
2987
- placeholder: F.emailPlaceholder,
2988
- style: Y("email"),
2989
- disabled: M || h
2998
+ placeholder: T.emailPlaceholder,
2999
+ style: Z("email"),
3000
+ disabled: M || u
2990
3001
  }
2991
3002
  )
2992
3003
  ] }),
@@ -3006,27 +3017,27 @@ function qn({
3006
3017
  children: "New user? Add your name"
3007
3018
  }
3008
3019
  ) }),
3009
- l && /* @__PURE__ */ d(_, { children: [
3010
- /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
3011
- /* @__PURE__ */ s("label", { style: y.label, children: F.nameLabel }),
3020
+ l && /* @__PURE__ */ c(_, { children: [
3021
+ /* @__PURE__ */ c("div", { style: S.fieldGroup, children: [
3022
+ /* @__PURE__ */ s("label", { style: S.label, children: T.nameLabel }),
3012
3023
  /* @__PURE__ */ s(
3013
3024
  "input",
3014
3025
  {
3015
3026
  id: "name",
3016
3027
  name: "name",
3017
3028
  type: "text",
3018
- value: g,
3019
- onChange: (O) => {
3020
- T(O.target.value), R.name && $((V) => ({ ...V, name: !1 }));
3029
+ value: h,
3030
+ onChange: (q) => {
3031
+ v(q.target.value), R.name && U((W) => ({ ...W, name: !1 }));
3021
3032
  },
3022
- placeholder: F.namePlaceholder,
3023
- style: Y("name"),
3024
- disabled: M || h
3033
+ placeholder: T.namePlaceholder,
3034
+ style: Z("name"),
3035
+ disabled: M || u
3025
3036
  }
3026
3037
  )
3027
3038
  ] }),
3028
- /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
3029
- /* @__PURE__ */ s("label", { style: y.label, children: F.lastNameLabel }),
3039
+ /* @__PURE__ */ c("div", { style: S.fieldGroup, children: [
3040
+ /* @__PURE__ */ s("label", { style: S.label, children: T.lastNameLabel }),
3030
3041
  /* @__PURE__ */ s(
3031
3042
  "input",
3032
3043
  {
@@ -3034,10 +3045,10 @@ function qn({
3034
3045
  name: "lastName",
3035
3046
  type: "text",
3036
3047
  value: I,
3037
- onChange: (O) => N(O.target.value),
3038
- placeholder: F.lastNamePlaceholder,
3039
- style: y.input,
3040
- disabled: M || h
3048
+ onChange: (q) => F(q.target.value),
3049
+ placeholder: T.lastNamePlaceholder,
3050
+ style: S.input,
3051
+ disabled: M || u
3041
3052
  }
3042
3053
  )
3043
3054
  ] }),
@@ -3046,7 +3057,7 @@ function qn({
3046
3057
  {
3047
3058
  type: "button",
3048
3059
  onClick: () => {
3049
- D(!1), T(""), N("");
3060
+ D(!1), v(""), F("");
3050
3061
  },
3051
3062
  style: {
3052
3063
  background: "none",
@@ -3060,30 +3071,30 @@ function qn({
3060
3071
  }
3061
3072
  ) })
3062
3073
  ] }),
3063
- /* @__PURE__ */ s("button", { type: "submit", disabled: !u || M || h, style: q(), children: M ? F.loadingText : F.submitButton }),
3064
- S && /* @__PURE__ */ s("div", { style: y.errorText, children: S }),
3065
- E && /* @__PURE__ */ s("div", { style: y.successText, children: E })
3074
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !d || M || u, style: O(), children: M ? T.loadingText : T.submitButton }),
3075
+ b && /* @__PURE__ */ s("div", { style: S.errorText, children: b }),
3076
+ E && /* @__PURE__ */ s("div", { style: S.successText, children: E })
3066
3077
  ] }),
3067
- a && /* @__PURE__ */ d("div", { style: y.linkContainer, children: [
3068
- /* @__PURE__ */ d("div", { children: [
3069
- /* @__PURE__ */ d("span", { style: y.divider, children: [
3070
- F.loginText,
3078
+ a && /* @__PURE__ */ c("div", { style: S.linkContainer, children: [
3079
+ /* @__PURE__ */ c("div", { children: [
3080
+ /* @__PURE__ */ c("span", { style: S.divider, children: [
3081
+ T.loginText,
3071
3082
  " "
3072
3083
  ] }),
3073
- /* @__PURE__ */ s("a", { onClick: i, style: y.link, children: F.loginLink })
3084
+ /* @__PURE__ */ s("a", { onClick: i, style: S.link, children: T.loginLink })
3074
3085
  ] }),
3075
- /* @__PURE__ */ s("div", { style: y.divider, children: "•" }),
3076
- /* @__PURE__ */ d("div", { children: [
3077
- /* @__PURE__ */ d("span", { style: y.divider, children: [
3078
- F.signupText,
3086
+ /* @__PURE__ */ s("div", { style: S.divider, children: "•" }),
3087
+ /* @__PURE__ */ c("div", { children: [
3088
+ /* @__PURE__ */ c("span", { style: S.divider, children: [
3089
+ T.signupText,
3079
3090
  " "
3080
3091
  ] }),
3081
- /* @__PURE__ */ s("a", { onClick: o, style: y.link, children: F.signupLink })
3092
+ /* @__PURE__ */ s("a", { onClick: o, style: S.link, children: T.signupLink })
3082
3093
  ] })
3083
3094
  ] })
3084
3095
  ] });
3085
3096
  }
3086
- const Zt = {
3097
+ const Jt = {
3087
3098
  title: "Verifying Magic Link",
3088
3099
  verifyingMessage: "Please wait while we verify your magic link...",
3089
3100
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -3091,7 +3102,7 @@ const Zt = {
3091
3102
  redirectingMessage: "Redirecting you to the dashboard...",
3092
3103
  retryButton: "Try Again",
3093
3104
  backToLoginButton: "Back to Login"
3094
- }, Je = {
3105
+ }, Qe = {
3095
3106
  container: {
3096
3107
  maxWidth: "400px",
3097
3108
  width: "100%",
@@ -3178,7 +3189,7 @@ const Zt = {
3178
3189
  cursor: "pointer",
3179
3190
  transition: "all 0.15s ease-in-out"
3180
3191
  }
3181
- }, Kt = () => /* @__PURE__ */ s("div", { style: Je.spinner }), Jt = () => /* @__PURE__ */ d(
3192
+ }, Yt = () => /* @__PURE__ */ s("div", { style: Qe.spinner }), Qt = () => /* @__PURE__ */ c(
3182
3193
  "svg",
3183
3194
  {
3184
3195
  width: "48",
@@ -3195,7 +3206,7 @@ const Zt = {
3195
3206
  /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3196
3207
  ]
3197
3208
  }
3198
- ), Yt = () => /* @__PURE__ */ d(
3209
+ ), Xt = () => /* @__PURE__ */ c(
3199
3210
  "svg",
3200
3211
  {
3201
3212
  width: "48",
@@ -3213,12 +3224,12 @@ const Zt = {
3213
3224
  /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3214
3225
  ]
3215
3226
  }
3216
- ), Qt = {
3217
- loading: /* @__PURE__ */ s(Kt, {}),
3218
- success: /* @__PURE__ */ s(Jt, {}),
3219
- error: /* @__PURE__ */ s(Yt, {})
3227
+ ), en = {
3228
+ loading: /* @__PURE__ */ s(Yt, {}),
3229
+ success: /* @__PURE__ */ s(Qt, {}),
3230
+ error: /* @__PURE__ */ s(Xt, {})
3220
3231
  };
3221
- function On({
3232
+ function _n({
3222
3233
  copy: r = {},
3223
3234
  styles: e = {},
3224
3235
  icons: t = {},
@@ -3229,18 +3240,18 @@ function On({
3229
3240
  className: p,
3230
3241
  token: f,
3231
3242
  email: w,
3232
- appId: u,
3233
- tenantSlug: b,
3234
- autoRedirectDelay: g = 3e3
3243
+ appId: d,
3244
+ tenantSlug: m,
3245
+ autoRedirectDelay: h = 3e3
3235
3246
  }) {
3236
- const [T, I] = A("verifying"), [N, M] = A(""), { verifyMagicLink: P } = le(), h = { ...Zt, ...r }, x = { ...Je, ...e }, S = { ...Qt, ...t }, L = () => {
3247
+ const [v, I] = x("verifying"), [F, M] = x(""), { verifyMagicLink: P } = ce(), u = { ...Jt, ...r }, A = { ...Qe, ...e }, b = { ...en, ...t }, L = () => {
3237
3248
  if (typeof window > "u") return {};
3238
3249
  const l = new URLSearchParams(window.location.search);
3239
3250
  return {
3240
3251
  token: f || l.get("token") || "",
3241
3252
  email: w || l.get("email") || "",
3242
- appId: u || l.get("appId") || "",
3243
- tenantSlug: b || l.get("tenantSlug") || void 0
3253
+ appId: d || l.get("appId") || "",
3254
+ tenantSlug: m || l.get("tenantSlug") || void 0
3244
3255
  };
3245
3256
  }, E = async () => {
3246
3257
  I("verifying"), M("");
@@ -3253,69 +3264,69 @@ function On({
3253
3264
  email: l.email,
3254
3265
  tenantSlug: l.tenantSlug
3255
3266
  });
3256
- I("success"), n == null || n(D), g > 0 && setTimeout(() => {
3267
+ I("success"), n == null || n(D), h > 0 && setTimeout(() => {
3257
3268
  I("redirecting");
3258
- }, g);
3269
+ }, h);
3259
3270
  } catch (l) {
3260
- const D = l.message || h.errorMessage;
3271
+ const D = l.message || u.errorMessage;
3261
3272
  M(D), I("error"), i == null || i(D);
3262
3273
  }
3263
- }, C = () => {
3274
+ }, N = () => {
3264
3275
  o == null || o(), E();
3265
3276
  }, R = () => {
3266
3277
  a == null || a();
3267
3278
  };
3268
- X(() => {
3279
+ ee(() => {
3269
3280
  E();
3270
3281
  }, []);
3271
- const $ = () => {
3272
- switch (T) {
3282
+ const U = () => {
3283
+ switch (v) {
3273
3284
  case "verifying":
3274
- return /* @__PURE__ */ d("div", { style: x.message, children: [
3275
- S.loading,
3276
- h.verifyingMessage
3285
+ return /* @__PURE__ */ c("div", { style: A.message, children: [
3286
+ b.loading,
3287
+ u.verifyingMessage
3277
3288
  ] });
3278
3289
  case "success":
3279
- return /* @__PURE__ */ d(_, { children: [
3280
- S.success,
3281
- /* @__PURE__ */ s("div", { style: x.successMessage, children: h.successMessage })
3290
+ return /* @__PURE__ */ c(_, { children: [
3291
+ b.success,
3292
+ /* @__PURE__ */ s("div", { style: A.successMessage, children: u.successMessage })
3282
3293
  ] });
3283
3294
  case "redirecting":
3284
- return /* @__PURE__ */ d(_, { children: [
3285
- S.loading,
3286
- /* @__PURE__ */ s("div", { style: x.message, children: h.redirectingMessage })
3295
+ return /* @__PURE__ */ c(_, { children: [
3296
+ b.loading,
3297
+ /* @__PURE__ */ s("div", { style: A.message, children: u.redirectingMessage })
3287
3298
  ] });
3288
3299
  case "error":
3289
- return /* @__PURE__ */ d(_, { children: [
3290
- S.error,
3291
- /* @__PURE__ */ s("div", { style: x.errorMessage, children: N || h.errorMessage }),
3292
- /* @__PURE__ */ d("div", { style: x.buttonContainer, children: [
3300
+ return /* @__PURE__ */ c(_, { children: [
3301
+ b.error,
3302
+ /* @__PURE__ */ s("div", { style: A.errorMessage, children: F || u.errorMessage }),
3303
+ /* @__PURE__ */ c("div", { style: A.buttonContainer, children: [
3293
3304
  /* @__PURE__ */ s(
3294
3305
  "button",
3295
3306
  {
3296
- onClick: C,
3297
- style: x.retryButton,
3307
+ onClick: N,
3308
+ style: A.retryButton,
3298
3309
  onMouseOver: (l) => {
3299
3310
  l.currentTarget.style.backgroundColor = "#2563eb";
3300
3311
  },
3301
3312
  onMouseOut: (l) => {
3302
3313
  l.currentTarget.style.backgroundColor = "#3b82f6";
3303
3314
  },
3304
- children: h.retryButton
3315
+ children: u.retryButton
3305
3316
  }
3306
3317
  ),
3307
3318
  /* @__PURE__ */ s(
3308
3319
  "button",
3309
3320
  {
3310
3321
  onClick: R,
3311
- style: x.backButton,
3322
+ style: A.backButton,
3312
3323
  onMouseOver: (l) => {
3313
3324
  l.currentTarget.style.backgroundColor = "#e5e7eb";
3314
3325
  },
3315
3326
  onMouseOut: (l) => {
3316
3327
  l.currentTarget.style.backgroundColor = "#f3f4f6";
3317
3328
  },
3318
- children: h.backToLoginButton
3329
+ children: u.backToLoginButton
3319
3330
  }
3320
3331
  )
3321
3332
  ] })
@@ -3324,18 +3335,18 @@ function On({
3324
3335
  return null;
3325
3336
  }
3326
3337
  };
3327
- return /* @__PURE__ */ d("div", { style: x.container, className: p, children: [
3338
+ return /* @__PURE__ */ c("div", { style: A.container, className: p, children: [
3328
3339
  /* @__PURE__ */ s("style", { children: `
3329
3340
  @keyframes spin {
3330
3341
  0% { transform: rotate(0deg); }
3331
3342
  100% { transform: rotate(360deg); }
3332
3343
  }
3333
3344
  ` }),
3334
- /* @__PURE__ */ s("h1", { style: x.title, children: h.title }),
3335
- $()
3345
+ /* @__PURE__ */ s("h1", { style: A.title, children: u.title }),
3346
+ U()
3336
3347
  ] });
3337
3348
  }
3338
- const Xt = {
3349
+ const tn = {
3339
3350
  title: "Reset Password",
3340
3351
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3341
3352
  emailLabel: "Email",
@@ -3357,7 +3368,7 @@ const Xt = {
3357
3368
  resetLoadingText: "Resetting...",
3358
3369
  resetSuccessMessage: "Password reset successfully!",
3359
3370
  passwordMismatchError: "Passwords do not match"
3360
- }, en = {
3371
+ }, nn = {
3361
3372
  container: {
3362
3373
  maxWidth: "400px",
3363
3374
  margin: "0 auto",
@@ -3449,7 +3460,7 @@ const Xt = {
3449
3460
  cursor: "pointer"
3450
3461
  }
3451
3462
  };
3452
- function zn({
3463
+ function Wn({
3453
3464
  copy: r = {},
3454
3465
  styles: e = {},
3455
3466
  mode: t = "request",
@@ -3460,101 +3471,101 @@ function zn({
3460
3471
  onModeChange: p,
3461
3472
  className: f
3462
3473
  }) {
3463
- const [w, u] = A(""), [b, g] = A(n), [T, I] = A(""), [N, M] = A(""), [P, h] = A(!1), [x, S] = A(""), [L, E] = A(""), [C, R] = A({}), { requestPasswordReset: $, confirmPasswordReset: l } = le(), { tenant: D } = ge(), U = { ...Xt, ...r }, c = { ...en, ...e }, H = () => {
3464
- const q = {};
3465
- return w.trim() || (q.email = !0), R(q), Object.keys(q).length === 0;
3466
- }, F = () => {
3467
- const q = {};
3468
- return b.trim() || (q.token = !0), T.trim() || (q.newPassword = !0), N.trim() || (q.confirmPassword = !0), R(q), Object.keys(q).length === 0;
3469
- }, y = async (q) => {
3470
- if (q.preventDefault(), !!H()) {
3474
+ const [w, d] = x(""), [m, h] = x(n), [v, I] = x(""), [F, M] = x(""), [P, u] = x(!1), [A, b] = x(""), [L, E] = x(""), [N, R] = x({}), { requestPasswordReset: U, confirmPasswordReset: l } = ce(), { tenant: D } = ge(), $ = { ...tn, ...r }, g = { ...nn, ...e }, C = () => {
3475
+ const O = {};
3476
+ return w.trim() || (O.email = !0), R(O), Object.keys(O).length === 0;
3477
+ }, T = () => {
3478
+ const O = {};
3479
+ return m.trim() || (O.token = !0), v.trim() || (O.newPassword = !0), F.trim() || (O.confirmPassword = !0), R(O), Object.keys(O).length === 0;
3480
+ }, S = async (O) => {
3481
+ if (O.preventDefault(), !!C()) {
3471
3482
  if (!(D != null && D.id)) {
3472
- S("Tenant not found");
3483
+ b("Tenant not found");
3473
3484
  return;
3474
3485
  }
3475
- h(!0), S(""), E("");
3486
+ u(!0), b(""), E("");
3476
3487
  try {
3477
- await $({ email: w, tenantId: D.id }), E(U.successMessage), i == null || i();
3478
- } catch (O) {
3479
- const V = O.message || U.errorMessage;
3480
- S(V), o == null || o(V);
3488
+ await U({ email: w, tenantId: D.id }), E($.successMessage), i == null || i();
3489
+ } catch (q) {
3490
+ const W = q.message || $.errorMessage;
3491
+ b(W), o == null || o(W);
3481
3492
  } finally {
3482
- h(!1);
3493
+ u(!1);
3483
3494
  }
3484
3495
  }
3485
- }, m = async (q) => {
3486
- if (q.preventDefault(), !!F()) {
3487
- if (T !== N) {
3488
- S(U.passwordMismatchError), R({ confirmPassword: !0 });
3496
+ }, y = async (O) => {
3497
+ if (O.preventDefault(), !!T()) {
3498
+ if (v !== F) {
3499
+ b($.passwordMismatchError), R({ confirmPassword: !0 });
3489
3500
  return;
3490
3501
  }
3491
- h(!0), S(""), E("");
3502
+ u(!0), b(""), E("");
3492
3503
  try {
3493
- await l({ token: b, newPassword: T }), E(U.resetSuccessMessage), i == null || i();
3494
- } catch (O) {
3495
- const V = O.message || U.errorMessage;
3496
- S(V), o == null || o(V);
3504
+ await l({ token: m, newPassword: v }), E($.resetSuccessMessage), i == null || i();
3505
+ } catch (q) {
3506
+ const W = q.message || $.errorMessage;
3507
+ b(W), o == null || o(W);
3497
3508
  } finally {
3498
- h(!1);
3509
+ u(!1);
3499
3510
  }
3500
3511
  }
3501
- }, v = (q) => ({
3502
- ...c.input,
3503
- ...C[q] ? c.inputError : {}
3504
- }), G = () => ({
3505
- ...c.button,
3506
- ...P ? c.buttonLoading : {}
3512
+ }, k = (O) => ({
3513
+ ...g.input,
3514
+ ...N[O] ? g.inputError : {}
3515
+ }), j = () => ({
3516
+ ...g.button,
3517
+ ...P ? g.buttonLoading : {}
3507
3518
  });
3508
3519
  if (t === "reset") {
3509
- const q = b && T && N;
3510
- return /* @__PURE__ */ d("div", { className: f, style: c.container, children: [
3511
- /* @__PURE__ */ s("h2", { style: c.title, children: U.resetTitle }),
3512
- /* @__PURE__ */ s("p", { style: c.subtitle, children: U.resetSubtitle }),
3513
- /* @__PURE__ */ d("form", { onSubmit: m, style: c.form, children: [
3514
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3515
- /* @__PURE__ */ s("label", { style: c.label, children: U.tokenLabel }),
3520
+ const O = m && v && F;
3521
+ return /* @__PURE__ */ c("div", { className: f, style: g.container, children: [
3522
+ /* @__PURE__ */ s("h2", { style: g.title, children: $.resetTitle }),
3523
+ /* @__PURE__ */ s("p", { style: g.subtitle, children: $.resetSubtitle }),
3524
+ /* @__PURE__ */ c("form", { onSubmit: y, style: g.form, children: [
3525
+ /* @__PURE__ */ c("div", { style: g.fieldGroup, children: [
3526
+ /* @__PURE__ */ s("label", { style: g.label, children: $.tokenLabel }),
3516
3527
  /* @__PURE__ */ s(
3517
3528
  "input",
3518
3529
  {
3519
3530
  type: "text",
3520
- value: b,
3521
- onChange: (O) => {
3522
- g(O.target.value), C.token && R((V) => ({ ...V, token: !1 }));
3531
+ value: m,
3532
+ onChange: (q) => {
3533
+ h(q.target.value), N.token && R((W) => ({ ...W, token: !1 }));
3523
3534
  },
3524
- placeholder: U.tokenPlaceholder,
3525
- style: v("token"),
3535
+ placeholder: $.tokenPlaceholder,
3536
+ style: k("token"),
3526
3537
  disabled: P
3527
3538
  }
3528
3539
  )
3529
3540
  ] }),
3530
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3531
- /* @__PURE__ */ s("label", { style: c.label, children: U.newPasswordLabel }),
3541
+ /* @__PURE__ */ c("div", { style: g.fieldGroup, children: [
3542
+ /* @__PURE__ */ s("label", { style: g.label, children: $.newPasswordLabel }),
3532
3543
  /* @__PURE__ */ s(
3533
3544
  "input",
3534
3545
  {
3535
3546
  type: "password",
3536
- value: T,
3537
- onChange: (O) => {
3538
- I(O.target.value), C.newPassword && R((V) => ({ ...V, newPassword: !1 }));
3547
+ value: v,
3548
+ onChange: (q) => {
3549
+ I(q.target.value), N.newPassword && R((W) => ({ ...W, newPassword: !1 }));
3539
3550
  },
3540
- placeholder: U.newPasswordPlaceholder,
3541
- style: v("newPassword"),
3551
+ placeholder: $.newPasswordPlaceholder,
3552
+ style: k("newPassword"),
3542
3553
  disabled: P
3543
3554
  }
3544
3555
  )
3545
3556
  ] }),
3546
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3547
- /* @__PURE__ */ s("label", { style: c.label, children: U.confirmPasswordLabel }),
3557
+ /* @__PURE__ */ c("div", { style: g.fieldGroup, children: [
3558
+ /* @__PURE__ */ s("label", { style: g.label, children: $.confirmPasswordLabel }),
3548
3559
  /* @__PURE__ */ s(
3549
3560
  "input",
3550
3561
  {
3551
3562
  type: "password",
3552
- value: N,
3553
- onChange: (O) => {
3554
- M(O.target.value), C.confirmPassword && R((V) => ({ ...V, confirmPassword: !1 })), x === U.passwordMismatchError && S("");
3563
+ value: F,
3564
+ onChange: (q) => {
3565
+ M(q.target.value), N.confirmPassword && R((W) => ({ ...W, confirmPassword: !1 })), A === $.passwordMismatchError && b("");
3555
3566
  },
3556
- placeholder: U.confirmPasswordPlaceholder,
3557
- style: v("confirmPassword"),
3567
+ placeholder: $.confirmPasswordPlaceholder,
3568
+ style: k("confirmPassword"),
3558
3569
  disabled: P
3559
3570
  }
3560
3571
  )
@@ -3563,43 +3574,43 @@ function zn({
3563
3574
  "button",
3564
3575
  {
3565
3576
  type: "submit",
3566
- disabled: !q || P,
3577
+ disabled: !O || P,
3567
3578
  style: {
3568
- ...G(),
3569
- ...!q || P ? c.buttonDisabled : {}
3579
+ ...j(),
3580
+ ...!O || P ? g.buttonDisabled : {}
3570
3581
  },
3571
- children: P ? U.resetLoadingText : U.resetSubmitButton
3582
+ children: P ? $.resetLoadingText : $.resetSubmitButton
3572
3583
  }
3573
3584
  ),
3574
- x && /* @__PURE__ */ s("div", { style: c.errorText, children: x }),
3575
- L && /* @__PURE__ */ s("div", { style: c.successText, children: L })
3585
+ A && /* @__PURE__ */ s("div", { style: g.errorText, children: A }),
3586
+ L && /* @__PURE__ */ s("div", { style: g.successText, children: L })
3576
3587
  ] }),
3577
- /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3578
- /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: U.backToLoginLink }),
3579
- p && /* @__PURE__ */ d(_, { children: [
3588
+ /* @__PURE__ */ c("div", { style: g.linkContainer, children: [
3589
+ /* @__PURE__ */ s("a", { onClick: a, style: g.link, children: $.backToLoginLink }),
3590
+ p && /* @__PURE__ */ c(_, { children: [
3580
3591
  /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3581
- /* @__PURE__ */ s("a", { onClick: () => p("request"), style: c.link, children: "Request New Link" })
3592
+ /* @__PURE__ */ s("a", { onClick: () => p("request"), style: g.link, children: "Request New Link" })
3582
3593
  ] })
3583
3594
  ] })
3584
3595
  ] });
3585
3596
  }
3586
- const Y = w;
3587
- return /* @__PURE__ */ d("div", { className: f, style: c.container, children: [
3588
- /* @__PURE__ */ s("h2", { style: c.title, children: U.title }),
3589
- /* @__PURE__ */ s("p", { style: c.subtitle, children: U.subtitle }),
3590
- /* @__PURE__ */ d("form", { onSubmit: y, style: c.form, children: [
3591
- /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3592
- /* @__PURE__ */ s("label", { style: c.label, children: U.emailLabel }),
3597
+ const Z = w;
3598
+ return /* @__PURE__ */ c("div", { className: f, style: g.container, children: [
3599
+ /* @__PURE__ */ s("h2", { style: g.title, children: $.title }),
3600
+ /* @__PURE__ */ s("p", { style: g.subtitle, children: $.subtitle }),
3601
+ /* @__PURE__ */ c("form", { onSubmit: S, style: g.form, children: [
3602
+ /* @__PURE__ */ c("div", { style: g.fieldGroup, children: [
3603
+ /* @__PURE__ */ s("label", { style: g.label, children: $.emailLabel }),
3593
3604
  /* @__PURE__ */ s(
3594
3605
  "input",
3595
3606
  {
3596
3607
  type: "email",
3597
3608
  value: w,
3598
- onChange: (q) => {
3599
- u(q.target.value), C.email && R((O) => ({ ...O, email: !1 }));
3609
+ onChange: (O) => {
3610
+ d(O.target.value), N.email && R((q) => ({ ...q, email: !1 }));
3600
3611
  },
3601
- placeholder: U.emailPlaceholder,
3602
- style: v("email"),
3612
+ placeholder: $.emailPlaceholder,
3613
+ style: k("email"),
3603
3614
  disabled: P
3604
3615
  }
3605
3616
  )
@@ -3608,27 +3619,27 @@ function zn({
3608
3619
  "button",
3609
3620
  {
3610
3621
  type: "submit",
3611
- disabled: !Y || P,
3622
+ disabled: !Z || P,
3612
3623
  style: {
3613
- ...G(),
3614
- ...!Y || P ? c.buttonDisabled : {}
3624
+ ...j(),
3625
+ ...!Z || P ? g.buttonDisabled : {}
3615
3626
  },
3616
- children: P ? U.loadingText : U.submitButton
3627
+ children: P ? $.loadingText : $.submitButton
3617
3628
  }
3618
3629
  ),
3619
- x && /* @__PURE__ */ s("div", { style: c.errorText, children: x }),
3620
- L && /* @__PURE__ */ s("div", { style: c.successText, children: L })
3630
+ A && /* @__PURE__ */ s("div", { style: g.errorText, children: A }),
3631
+ L && /* @__PURE__ */ s("div", { style: g.successText, children: L })
3621
3632
  ] }),
3622
- /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3623
- /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: U.backToLoginLink }),
3624
- p && /* @__PURE__ */ d(_, { children: [
3633
+ /* @__PURE__ */ c("div", { style: g.linkContainer, children: [
3634
+ /* @__PURE__ */ s("a", { onClick: a, style: g.link, children: $.backToLoginLink }),
3635
+ p && /* @__PURE__ */ c(_, { children: [
3625
3636
  /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3626
- /* @__PURE__ */ s("a", { onClick: () => p("reset"), style: c.link, children: "I have a token" })
3637
+ /* @__PURE__ */ s("a", { onClick: () => p("reset"), style: g.link, children: "I have a token" })
3627
3638
  ] })
3628
3639
  ] })
3629
3640
  ] });
3630
3641
  }
3631
- const tn = () => /* @__PURE__ */ s(
3642
+ const rn = () => /* @__PURE__ */ s(
3632
3643
  "div",
3633
3644
  {
3634
3645
  style: {
@@ -3640,7 +3651,7 @@ const tn = () => /* @__PURE__ */ s(
3640
3651
  },
3641
3652
  children: /* @__PURE__ */ s("div", { children: "Loading..." })
3642
3653
  }
3643
- ), nn = ({ error: r, retry: e }) => /* @__PURE__ */ d(
3654
+ ), sn = ({ error: r, retry: e }) => /* @__PURE__ */ c(
3644
3655
  "div",
3645
3656
  {
3646
3657
  style: {
@@ -3674,43 +3685,43 @@ const tn = () => /* @__PURE__ */ s(
3674
3685
  ]
3675
3686
  }
3676
3687
  );
3677
- function _n({
3688
+ function Vn({
3678
3689
  children: r,
3679
3690
  loadingFallback: e,
3680
3691
  errorFallback: t,
3681
3692
  requireTenant: n = !0
3682
3693
  }) {
3683
- const { isAppLoading: i, appError: o, retryApp: a } = ye(), p = Se(), f = Ee(), w = Ge(), u = Ze(), b = (p == null ? void 0 : p.isTenantLoading) ?? !1, g = (p == null ? void 0 : p.tenantError) ?? null, T = (p == null ? void 0 : p.tenantSlug) ?? null, I = (p == null ? void 0 : p.retryTenant) ?? (() => {
3684
- }), N = (f == null ? void 0 : f.isAuthReady) ?? !0, M = (w == null ? void 0 : w.isReady) ?? !0, P = (u == null ? void 0 : u.isReady) ?? !0, h = n && p && T, E = i || h && b || f && !N || w && !M || u && !P, C = o || (h ? g : null), R = () => {
3685
- o && a(), g && p && I();
3694
+ const { isAppLoading: i, appError: o, retryApp: a } = we(), p = ve(), f = Ne(), w = Ke(), d = Je(), m = (p == null ? void 0 : p.isTenantLoading) ?? !1, h = (p == null ? void 0 : p.tenantError) ?? null, v = (p == null ? void 0 : p.tenantSlug) ?? null, I = (p == null ? void 0 : p.retryTenant) ?? (() => {
3695
+ }), F = (f == null ? void 0 : f.isAuthReady) ?? !0, M = (w == null ? void 0 : w.isReady) ?? !0, P = (d == null ? void 0 : d.isReady) ?? !0, u = n && p && v, E = i || u && m || f && !F || w && !M || d && !P, N = o || (u ? h : null), R = () => {
3696
+ o && a(), h && p && I();
3686
3697
  };
3687
3698
  if (E)
3688
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(tn, {}) });
3689
- if (C) {
3690
- const $ = typeof t == "function" ? t(C, R) : t || /* @__PURE__ */ s(nn, { error: C, retry: R });
3691
- return /* @__PURE__ */ s(_, { children: $ });
3699
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(rn, {}) });
3700
+ if (N) {
3701
+ const U = typeof t == "function" ? t(N, R) : t || /* @__PURE__ */ s(sn, { error: N, retry: R });
3702
+ return /* @__PURE__ */ s(_, { children: U });
3692
3703
  }
3693
3704
  return /* @__PURE__ */ s(_, { children: r });
3694
3705
  }
3695
- function Wn(r = !0) {
3696
- const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = ye(), o = Se(), a = Ee(), p = Ge(), f = Ze(), w = (o == null ? void 0 : o.isTenantLoading) ?? !1, u = (o == null ? void 0 : o.tenantError) ?? null, b = (o == null ? void 0 : o.tenant) ?? null, g = (o == null ? void 0 : o.tenantSlug) ?? null, T = (o == null ? void 0 : o.retryTenant) ?? (() => {
3697
- }), I = (a == null ? void 0 : a.isAuthReady) ?? !0, N = (p == null ? void 0 : p.isReady) ?? !0, M = (f == null ? void 0 : f.isReady) ?? !0, P = r && o && g, L = e || P && w || a && !I || p && !N || f && !M, E = t || (P ? u : null);
3706
+ function jn(r = !0) {
3707
+ const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = we(), o = ve(), a = Ne(), p = Ke(), f = Je(), w = (o == null ? void 0 : o.isTenantLoading) ?? !1, d = (o == null ? void 0 : o.tenantError) ?? null, m = (o == null ? void 0 : o.tenant) ?? null, h = (o == null ? void 0 : o.tenantSlug) ?? null, v = (o == null ? void 0 : o.retryTenant) ?? (() => {
3708
+ }), I = (a == null ? void 0 : a.isAuthReady) ?? !0, F = (p == null ? void 0 : p.isReady) ?? !0, M = (f == null ? void 0 : f.isReady) ?? !0, P = r && o && h, L = e || P && w || a && !I || p && !F || f && !M, E = t || (P ? d : null);
3698
3709
  return {
3699
3710
  isLoading: L,
3700
3711
  error: E,
3701
- isReady: !L && !E && i !== null && (!P || b !== null),
3712
+ isReady: !L && !E && i !== null && (!P || m !== null),
3702
3713
  retry: () => {
3703
- t && n(), u && o && T();
3714
+ t && n(), d && o && v();
3704
3715
  },
3705
3716
  // Individual states
3706
3717
  app: { isLoading: e, error: t, data: i },
3707
- tenant: o ? { isLoading: w, error: u, data: b } : null,
3718
+ tenant: o ? { isLoading: w, error: d, data: m } : null,
3708
3719
  auth: a ? { isReady: I } : null,
3709
- featureFlags: p ? { isReady: N } : null,
3720
+ featureFlags: p ? { isReady: F } : null,
3710
3721
  subscription: f ? { isReady: M } : null
3711
3722
  };
3712
3723
  }
3713
- function Vn({
3724
+ function Gn({
3714
3725
  tenants: r,
3715
3726
  currentTenantId: e,
3716
3727
  onSelect: t,
@@ -3722,35 +3733,35 @@ function Vn({
3722
3733
  disabled: f = !1,
3723
3734
  showCurrentTenant: w = !0
3724
3735
  }) {
3725
- var x;
3726
- const u = Ee(), [b, g] = A(!1), T = Ve(null), I = r ?? (u == null ? void 0 : u.userTenants) ?? [], N = e ?? ((x = u == null ? void 0 : u.currentUser) == null ? void 0 : x.tenantId) ?? null, M = async (S) => {
3727
- g(!1), t ? t(S) : u != null && u.switchToTenant && await u.switchToTenant(S);
3736
+ var A;
3737
+ const d = Ne(), [m, h] = x(!1), v = Ge(null), I = r ?? (d == null ? void 0 : d.userTenants) ?? [], F = e ?? ((A = d == null ? void 0 : d.currentUser) == null ? void 0 : A.tenantId) ?? null, M = async (b) => {
3738
+ h(!1), t ? t(b) : d != null && d.switchToTenant && await d.switchToTenant(b);
3728
3739
  };
3729
- X(() => {
3730
- const S = (L) => {
3731
- T.current && !T.current.contains(L.target) && g(!1);
3740
+ ee(() => {
3741
+ const b = (L) => {
3742
+ v.current && !v.current.contains(L.target) && h(!1);
3732
3743
  };
3733
- return document.addEventListener("mousedown", S), () => document.removeEventListener("mousedown", S);
3744
+ return document.addEventListener("mousedown", b), () => document.removeEventListener("mousedown", b);
3734
3745
  }, []);
3735
- const P = I.find((S) => S.id === N);
3746
+ const P = I.find((b) => b.id === F);
3736
3747
  if (I.length === 0)
3737
3748
  return null;
3738
3749
  if (I.length === 1 && w)
3739
3750
  return /* @__PURE__ */ s("div", { className: n, children: /* @__PURE__ */ s("span", { children: I[0].name }) });
3740
- const h = (S, L) => /* @__PURE__ */ d("span", { style: { fontWeight: L ? "bold" : "normal" }, children: [
3741
- S.name,
3742
- S.role && /* @__PURE__ */ d("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3751
+ const u = (b, L) => /* @__PURE__ */ c("span", { style: { fontWeight: L ? "bold" : "normal" }, children: [
3752
+ b.name,
3753
+ b.role && /* @__PURE__ */ c("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3743
3754
  "(",
3744
- S.role,
3755
+ b.role,
3745
3756
  ")"
3746
3757
  ] })
3747
3758
  ] });
3748
- return /* @__PURE__ */ d("div", { ref: T, className: n, style: { position: "relative" }, children: [
3749
- /* @__PURE__ */ d(
3759
+ return /* @__PURE__ */ c("div", { ref: v, className: n, style: { position: "relative" }, children: [
3760
+ /* @__PURE__ */ c(
3750
3761
  "button",
3751
3762
  {
3752
3763
  type: "button",
3753
- onClick: () => !f && g(!b),
3764
+ onClick: () => !f && h(!m),
3754
3765
  disabled: f,
3755
3766
  style: {
3756
3767
  cursor: f ? "not-allowed" : "pointer",
@@ -3758,11 +3769,11 @@ function Vn({
3758
3769
  },
3759
3770
  children: [
3760
3771
  P ? P.name : p,
3761
- /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: b ? "▲" : "▼" })
3772
+ /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: m ? "▲" : "▼" })
3762
3773
  ]
3763
3774
  }
3764
3775
  ),
3765
- b && /* @__PURE__ */ s(
3776
+ m && /* @__PURE__ */ s(
3766
3777
  "div",
3767
3778
  {
3768
3779
  className: i,
@@ -3779,13 +3790,13 @@ function Vn({
3779
3790
  maxHeight: 300,
3780
3791
  overflowY: "auto"
3781
3792
  },
3782
- children: I.map((S) => {
3783
- const L = S.id === N;
3793
+ children: I.map((b) => {
3794
+ const L = b.id === F;
3784
3795
  return /* @__PURE__ */ s(
3785
3796
  "div",
3786
3797
  {
3787
3798
  className: o,
3788
- onClick: () => M(S.id),
3799
+ onClick: () => M(b.id),
3789
3800
  style: {
3790
3801
  padding: "8px 12px",
3791
3802
  cursor: "pointer",
@@ -3797,16 +3808,16 @@ function Vn({
3797
3808
  onMouseLeave: (E) => {
3798
3809
  L || (E.target.style.backgroundColor = "transparent");
3799
3810
  },
3800
- children: a ? a(S, L) : h(S, L)
3811
+ children: a ? a(b, L) : u(b, L)
3801
3812
  },
3802
- S.id
3813
+ b.id
3803
3814
  );
3804
3815
  })
3805
3816
  }
3806
3817
  )
3807
3818
  ] });
3808
3819
  }
3809
- class jn {
3820
+ class Zn {
3810
3821
  constructor(e, t) {
3811
3822
  this.httpService = e, this.sessionManager = t;
3812
3823
  }
@@ -3874,7 +3885,7 @@ class jn {
3874
3885
  };
3875
3886
  }
3876
3887
  }
3877
- class Gn {
3888
+ class Kn {
3878
3889
  constructor(e, t) {
3879
3890
  this.httpService = e, this.sessionManager = t;
3880
3891
  }
@@ -3925,7 +3936,7 @@ class Gn {
3925
3936
  });
3926
3937
  }
3927
3938
  }
3928
- class Zn {
3939
+ class Jn {
3929
3940
  constructor(e) {
3930
3941
  this.httpService = e;
3931
3942
  }
@@ -3934,7 +3945,7 @@ class Zn {
3934
3945
  return await this.httpService.get("/health");
3935
3946
  }
3936
3947
  }
3937
- class Kn {
3948
+ class Yn {
3938
3949
  // Date string to Date object
3939
3950
  static toDate(e) {
3940
3951
  return new Date(e);
@@ -4056,136 +4067,136 @@ class Kn {
4056
4067
  }), t;
4057
4068
  }
4058
4069
  }
4059
- const Ye = "returnTo", Pe = "zone_return_to", Re = "zone_return_to";
4060
- function Jn(r = {}) {
4070
+ const Xe = "returnTo", Ie = "zone_return_to", Me = "zone_return_to";
4071
+ function Qn(r = {}) {
4061
4072
  const {
4062
4073
  zoneRoots: e = {},
4063
- returnToParam: t = Ye,
4074
+ returnToParam: t = Xe,
4064
4075
  returnToStorage: n = "url"
4065
- } = r, i = ut(), [o, a] = ht(), { isAuthenticated: p, currentUser: f } = le(), { tenant: w } = he(), u = Z(() => ({ ...De, ...e }), [e]), b = !!w, g = f == null ? void 0 : f.userType, T = Z(() => {
4076
+ } = r, i = gt(), [o, a] = pt(), { isAuthenticated: p, currentUser: f } = ce(), { tenant: w } = he(), d = J(() => ({ ...Ue, ...e }), [e]), m = !!w, h = f == null ? void 0 : f.userType, v = J(() => {
4066
4077
  switch (n) {
4067
4078
  case "url":
4068
4079
  return o.get(t);
4069
4080
  case "session":
4070
- return sessionStorage.getItem(Pe);
4081
+ return sessionStorage.getItem(Ie);
4071
4082
  case "local":
4072
- return localStorage.getItem(Re);
4083
+ return localStorage.getItem(Me);
4073
4084
  default:
4074
4085
  return null;
4075
4086
  }
4076
- }, [n, o, t]), I = re(() => {
4087
+ }, [n, o, t]), I = se(() => {
4077
4088
  switch (n) {
4078
4089
  case "url": {
4079
- const h = new URLSearchParams(o);
4080
- h.delete(t), a(h, { replace: !0 });
4090
+ const u = new URLSearchParams(o);
4091
+ u.delete(t), a(u, { replace: !0 });
4081
4092
  break;
4082
4093
  }
4083
4094
  case "session":
4084
- sessionStorage.removeItem(Pe);
4095
+ sessionStorage.removeItem(Ie);
4085
4096
  break;
4086
4097
  case "local":
4087
- localStorage.removeItem(Re);
4098
+ localStorage.removeItem(Me);
4088
4099
  break;
4089
4100
  }
4090
- }, [n, o, t, a]), N = re(
4091
- (h) => {
4101
+ }, [n, o, t, a]), F = se(
4102
+ (u) => {
4092
4103
  switch (n) {
4093
4104
  case "url": {
4094
- const x = new URLSearchParams(o);
4095
- x.set(t, h), a(x, { replace: !0 });
4105
+ const A = new URLSearchParams(o);
4106
+ A.set(t, u), a(A, { replace: !0 });
4096
4107
  break;
4097
4108
  }
4098
4109
  case "session":
4099
- sessionStorage.setItem(Pe, h);
4110
+ sessionStorage.setItem(Ie, u);
4100
4111
  break;
4101
4112
  case "local":
4102
- localStorage.setItem(Re, h);
4113
+ localStorage.setItem(Me, u);
4103
4114
  break;
4104
4115
  }
4105
4116
  },
4106
4117
  [n, o, t, a]
4107
- ), M = re(
4108
- (h) => {
4109
- const x = u[h] || u.default;
4110
- i(x);
4118
+ ), M = se(
4119
+ (u) => {
4120
+ const A = d[u] || d.default;
4121
+ i(A);
4111
4122
  },
4112
- [i, u]
4113
- ), P = re(() => b ? p ? g === se.TENANT_ADMIN ? u.tenantAdmin : u.tenantUser : u.tenantGuest : p ? g === se.TENANT_ADMIN ? u.publicAdmin : u.publicUser : u.publicGuest, [b, p, g, u]);
4123
+ [i, d]
4124
+ ), P = se(() => m ? p ? h === ie.TENANT_ADMIN ? d.tenantAdmin : d.tenantUser : d.tenantGuest : p ? h === ie.TENANT_ADMIN ? d.publicAdmin : d.publicUser : d.publicGuest, [m, p, h, d]);
4114
4125
  return {
4115
- returnToUrl: T,
4126
+ returnToUrl: v,
4116
4127
  clearReturnTo: I,
4117
- setReturnTo: N,
4128
+ setReturnTo: F,
4118
4129
  navigateToZone: M,
4119
4130
  getSmartRedirect: P
4120
4131
  };
4121
4132
  }
4122
- function Yn(r, e, t = Ye, n = "url") {
4133
+ function Xn(r, e, t = Xe, n = "url") {
4123
4134
  if (!e || n !== "url")
4124
4135
  return r;
4125
4136
  const i = new URL(r, window.location.origin);
4126
4137
  return i.searchParams.set(t, e), i.pathname + i.search;
4127
4138
  }
4128
4139
  export {
4129
- Ln as AdminZone,
4130
- Kn as ApiMappers,
4131
- He as AppApiService,
4132
- _n as AppLoader,
4133
- hn as AppProvider,
4134
- gt as AuthApiService,
4135
- yn as AuthProvider,
4136
- In as AuthenticatedZone,
4137
- Ke as DEFAULT_ZONE_PRESETS,
4138
- De as DEFAULT_ZONE_ROOTS,
4139
- $n as FeatureFlag,
4140
- Tt as FeatureFlagApiService,
4141
- wn as FeatureFlagProvider,
4142
- Mn as GuestZone,
4143
- Zn as HealthApiService,
4144
- oe as HttpService,
4145
- xn as LandingRoute,
4146
- Hn as LoginForm,
4147
- qn as MagicLinkForm,
4148
- On as MagicLinkVerify,
4149
- Fn as OpenZone,
4150
- zn as PasswordRecoveryForm,
4151
- jn as PermissionApiService,
4152
- Tn as Protected,
4153
- kn as ProtectedRoute,
4154
- Rn as PublicZone,
4155
- Be as RoleApiService,
4156
- Sn as RoutingProvider,
4157
- xe as SessionManager,
4158
- Bn as SignupForm,
4159
- At as SubscriptionApiService,
4160
- Un as SubscriptionGuard,
4161
- Gn as SubscriptionPlanApiService,
4162
- bn as SubscriptionProvider,
4163
- fe as TenantApiService,
4164
- Nn as TenantAuthenticatedZone,
4165
- Cn as TenantGuestZone,
4166
- Dn as TenantOpenZone,
4167
- pn as TenantProvider,
4168
- An as TenantRoute,
4169
- Vn as TenantSelector,
4170
- Pn as TenantZone,
4171
- pt as UserApiService,
4172
- se as UserType,
4173
- En as UserZone,
4174
- ae as ZoneRoute,
4175
- Yn as buildRedirectUrl,
4176
- gn as useApi,
4177
- ye as useApp,
4178
- Wn as useAppLoaderState,
4179
- le as useAuth,
4180
- kt as useFeatureFlags,
4181
- vn as useRouting,
4182
- Pt as useRoutingOptional,
4183
- mn as useSettings,
4184
- xt as useSubscription,
4140
+ Fn as AdminZone,
4141
+ Yn as ApiMappers,
4142
+ qe as AppApiService,
4143
+ Vn as AppLoader,
4144
+ pn as AppProvider,
4145
+ ft as AuthApiService,
4146
+ bn as AuthProvider,
4147
+ Ln as AuthenticatedZone,
4148
+ Ye as DEFAULT_ZONE_PRESETS,
4149
+ Ue as DEFAULT_ZONE_ROOTS,
4150
+ Bn as FeatureFlag,
4151
+ xt as FeatureFlagApiService,
4152
+ Sn as FeatureFlagProvider,
4153
+ En as GuestZone,
4154
+ Jn as HealthApiService,
4155
+ ae as HttpService,
4156
+ Rn as LandingRoute,
4157
+ qn as LoginForm,
4158
+ zn as MagicLinkForm,
4159
+ _n as MagicLinkVerify,
4160
+ Dn as OpenZone,
4161
+ Wn as PasswordRecoveryForm,
4162
+ Zn as PermissionApiService,
4163
+ xn as Protected,
4164
+ An as ProtectedRoute,
4165
+ Mn as PublicZone,
4166
+ Oe as RoleApiService,
4167
+ Tn as RoutingProvider,
4168
+ Re as SessionManager,
4169
+ On as SignupForm,
4170
+ Pt as SubscriptionApiService,
4171
+ Hn as SubscriptionGuard,
4172
+ Kn as SubscriptionPlanApiService,
4173
+ vn as SubscriptionProvider,
4174
+ me as TenantApiService,
4175
+ Cn as TenantAuthenticatedZone,
4176
+ $n as TenantGuestZone,
4177
+ Un as TenantOpenZone,
4178
+ mn as TenantProvider,
4179
+ Pn as TenantRoute,
4180
+ Gn as TenantSelector,
4181
+ In as TenantZone,
4182
+ mt as UserApiService,
4183
+ ie as UserType,
4184
+ Nn as UserZone,
4185
+ le as ZoneRoute,
4186
+ Xn as buildRedirectUrl,
4187
+ fn as useApi,
4188
+ we as useApp,
4189
+ jn as useAppLoaderState,
4190
+ ce as useAuth,
4191
+ At as useFeatureFlags,
4192
+ kn as useRouting,
4193
+ It as useRoutingOptional,
4194
+ wn as useSettings,
4195
+ Rt as useSubscription,
4185
4196
  he as useTenant,
4186
4197
  ge as useTenantInfo,
4187
- Se as useTenantOptional,
4188
- fn as useTenantSettings,
4189
- Jn as useZoneNavigation
4198
+ ve as useTenantOptional,
4199
+ yn as useTenantSettings,
4200
+ Qn as useZoneNavigation
4190
4201
  };
4191
4202
  //# sourceMappingURL=index.es.js.map