@skylabs-digital/react-identity-access 2.24.0 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
- import { jsx as s, Fragment as _, jsxs as u } from "react/jsx-runtime";
2
- import { createContext as pe, useMemo as K, useState as k, useCallback as se, useEffect as re, useContext as ae, useRef as Me } from "react";
3
- import { useLocation as ke, Navigate as Se, useNavigate as ft, useSearchParams as pt } from "react-router-dom";
1
+ import { jsx as s, Fragment as _, jsxs as d } from "react/jsx-runtime";
2
+ import { createContext as fe, useMemo as K, useState as k, useCallback as se, useEffect as re, useContext as ae, useRef as Me } from "react";
3
+ import { useLocation as ke, Navigate as ve, useNavigate as pt, useSearchParams as ft } from "react-router-dom";
4
4
  class le {
5
5
  constructor(e, t = 1e4) {
6
6
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
@@ -13,28 +13,28 @@ class le {
13
13
  }
14
14
  async executeRequest(e, t, r, i) {
15
15
  const o = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, a = (i == null ? void 0 : i.timeout) || this.timeout;
16
- let f = {
16
+ let p = {
17
17
  "Content-Type": "application/json",
18
18
  ...i == null ? void 0 : i.headers
19
19
  };
20
20
  if (!(i != null && i.skipAuth) && this.sessionManager) {
21
- const c = await this.sessionManager.getValidAccessToken();
22
- f = { ...f, Authorization: `Bearer ${c}` };
21
+ const f = await this.sessionManager.getValidAccessToken();
22
+ p = { ...p, Authorization: `Bearer ${f}` };
23
23
  }
24
- const m = new AbortController(), b = setTimeout(() => m.abort(), a);
24
+ const w = new AbortController(), y = setTimeout(() => w.abort(), a);
25
25
  try {
26
- const c = await fetch(o, {
26
+ const f = await fetch(o, {
27
27
  method: e,
28
- headers: f,
28
+ headers: p,
29
29
  body: r ? JSON.stringify(r) : void 0,
30
- signal: m.signal
30
+ signal: w.signal
31
31
  });
32
- if (clearTimeout(b), !c.ok)
33
- throw new Error(`HTTP ${c.status}: ${c.statusText}`);
34
- const L = c.headers.get("content-type");
35
- return !L || !L.includes("application/json") ? {} : await c.json();
36
- } catch (c) {
37
- throw clearTimeout(b), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${a}ms`) : c;
32
+ if (clearTimeout(y), !f.ok)
33
+ throw new Error(`HTTP ${f.status}: ${f.statusText}`);
34
+ const x = f.headers.get("content-type");
35
+ return !x || !x.includes("application/json") ? {} : await f.json();
36
+ } catch (f) {
37
+ throw clearTimeout(y), f instanceof Error && f.name === "AbortError" ? new Error(`Request timeout after ${a}ms`) : f;
38
38
  }
39
39
  }
40
40
  async get(e, t) {
@@ -50,7 +50,7 @@ class le {
50
50
  return this.executeRequest("DELETE", e, void 0, t);
51
51
  }
52
52
  }
53
- class Oe {
53
+ class qe {
54
54
  constructor(e, t) {
55
55
  this.httpService = e, this.sessionManager = t;
56
56
  }
@@ -109,32 +109,32 @@ class Oe {
109
109
  })).data;
110
110
  }
111
111
  }
112
- const Le = pe(null);
113
- function gr({ config: n, children: e }) {
112
+ const Le = fe(null);
113
+ function mr({ config: n, children: e }) {
114
114
  const t = K(
115
115
  () => {
116
- var p, R, I;
116
+ var h, R, N;
117
117
  return {
118
- enabled: ((p = n.cache) == null ? void 0 : p.enabled) ?? !0,
118
+ enabled: ((h = n.cache) == null ? void 0 : h.enabled) ?? !0,
119
119
  ttl: ((R = n.cache) == null ? void 0 : R.ttl) ?? 3e5,
120
120
  // 5 minutes default
121
- storageKey: ((I = n.cache) == null ? void 0 : I.storageKey) ?? `app_cache_${n.appId}`
121
+ storageKey: ((N = n.cache) == null ? void 0 : N.storageKey) ?? `app_cache_${n.appId}`
122
122
  };
123
123
  },
124
124
  [n.cache, n.appId]
125
125
  ), [r, i] = k(() => {
126
126
  if (!t.enabled) return null;
127
127
  try {
128
- const p = localStorage.getItem(t.storageKey);
129
- if (!p) return null;
130
- const R = JSON.parse(p);
128
+ const h = localStorage.getItem(t.storageKey);
129
+ if (!h) return null;
130
+ const R = JSON.parse(h);
131
131
  return Date.now() - R.timestamp < t.ttl && R.appId === n.appId ? R.data : (localStorage.removeItem(t.storageKey), null);
132
132
  } catch {
133
133
  return null;
134
134
  }
135
- }), [o, a] = k(!r), [f, m] = k(null), b = K(() => {
136
- const p = () => {
137
- c();
135
+ }), [o, a] = k(!r), [p, w] = k(null), y = K(() => {
136
+ const h = () => {
137
+ f();
138
138
  };
139
139
  return {
140
140
  appId: n.appId,
@@ -142,59 +142,59 @@ function gr({ config: n, children: e }) {
142
142
  // App info
143
143
  appInfo: r,
144
144
  isAppLoading: o,
145
- appError: f,
146
- retryApp: p
145
+ appError: p,
146
+ retryApp: h
147
147
  };
148
- }, [n, r, o, f]), c = se(
149
- async (p = !1) => {
150
- if (!(!p && t.enabled && r))
148
+ }, [n, r, o, p]), f = se(
149
+ async (h = !1) => {
150
+ if (!(!h && t.enabled && r))
151
151
  try {
152
- a(!0), m(null);
153
- const R = new le(n.baseUrl), M = await new Oe(R, {}).getPublicAppInfo(n.appId);
154
- if (i(M), t.enabled)
152
+ a(!0), w(null);
153
+ const R = new le(n.baseUrl), D = await new qe(R, {}).getPublicAppInfo(n.appId);
154
+ if (i(D), t.enabled)
155
155
  try {
156
156
  const E = {
157
- data: M,
157
+ data: D,
158
158
  timestamp: Date.now(),
159
159
  appId: n.appId
160
160
  };
161
161
  localStorage.setItem(t.storageKey, JSON.stringify(E));
162
162
  } catch (E) {
163
- console.warn("Failed to cache app info:", E);
163
+ process.env.NODE_ENV === "development" && console.warn("[AppProvider] Failed to cache app info:", E);
164
164
  }
165
165
  } catch (R) {
166
- const I = R instanceof Error ? R : new Error("Failed to load app information");
167
- m(I), i(null);
166
+ const N = R instanceof Error ? R : new Error("Failed to load app information");
167
+ w(N), i(null);
168
168
  } finally {
169
169
  a(!1);
170
170
  }
171
171
  },
172
172
  [n.baseUrl, n.appId, t, r]
173
- ), L = se(async () => {
173
+ ), x = se(async () => {
174
174
  if (!(!t.enabled || !r))
175
175
  try {
176
- const p = localStorage.getItem(t.storageKey);
177
- if (!p) return;
178
- const R = JSON.parse(p);
176
+ const h = localStorage.getItem(t.storageKey);
177
+ if (!h) return;
178
+ const R = JSON.parse(h);
179
179
  if (Date.now() - R.timestamp > t.ttl * 0.5) {
180
- const M = new le(n.baseUrl), x = await new Oe(M, {}).getPublicAppInfo(n.appId);
181
- i(x);
182
- const h = {
183
- data: x,
180
+ const D = new le(n.baseUrl), P = await new qe(D, {}).getPublicAppInfo(n.appId);
181
+ i(P);
182
+ const u = {
183
+ data: P,
184
184
  timestamp: Date.now(),
185
185
  appId: n.appId
186
186
  };
187
- localStorage.setItem(t.storageKey, JSON.stringify(h));
187
+ localStorage.setItem(t.storageKey, JSON.stringify(u));
188
188
  }
189
- } catch (p) {
190
- console.warn("Background app refresh failed:", p);
189
+ } catch (h) {
190
+ process.env.NODE_ENV === "development" && console.warn("[AppProvider] Background app refresh failed:", h);
191
191
  }
192
192
  }, [n, t, r]);
193
193
  return re(() => {
194
- r ? L() : c();
195
- }, []), /* @__PURE__ */ s(Le.Provider, { value: b, children: e });
194
+ r ? x() : f();
195
+ }, []), /* @__PURE__ */ s(Le.Provider, { value: y, children: e });
196
196
  }
197
- function ve() {
197
+ function Se() {
198
198
  const n = ae(Le);
199
199
  if (!n)
200
200
  throw new Error("useApp must be used within an AppProvider");
@@ -203,7 +203,7 @@ function ve() {
203
203
  function Qe() {
204
204
  return ae(Le);
205
205
  }
206
- const mr = ve;
206
+ const yr = Se;
207
207
  class ne extends Error {
208
208
  constructor(e, t) {
209
209
  const r = {
@@ -354,7 +354,7 @@ const ie = class ie {
354
354
  const t = this.sessionGeneration;
355
355
  this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
356
356
  }).catch((r) => {
357
- r instanceof ne || this.sessionGeneration === t && (console.warn(
357
+ r instanceof ne || this.sessionGeneration === t && (process.env.NODE_ENV === "development" && console.warn(
358
358
  "[SessionManager] Background refresh failed, retrying in 30s:",
359
359
  r.message
360
360
  ), this.backgroundRetryTimerId = setTimeout(() => {
@@ -456,8 +456,8 @@ const ie = class ie {
456
456
  if (a instanceof ne)
457
457
  throw a;
458
458
  if (t = a, i < this.maxRefreshRetries) {
459
- const f = this.retryBackoffBase * Math.pow(2, i);
460
- await this.sleep(f);
459
+ const p = this.retryBackoffBase * Math.pow(2, i);
460
+ await this.sleep(p);
461
461
  }
462
462
  }
463
463
  }
@@ -485,8 +485,8 @@ const ie = class ie {
485
485
  if (!i.ok) {
486
486
  let a = "";
487
487
  try {
488
- const f = await i.json();
489
- a = (f.message || f.error || "").toLowerCase();
488
+ const p = await i.json();
489
+ a = (p.message || p.error || "").toLowerCase();
490
490
  } catch {
491
491
  a = i.statusText.toLowerCase();
492
492
  }
@@ -836,13 +836,13 @@ function bt(n, e) {
836
836
  const r = n.split(".");
837
837
  return r.length >= 3 && r[0] !== "www" ? r[0] : null;
838
838
  }
839
- function St(n, e = "tenant", t) {
839
+ function vt(n, e = "tenant", t) {
840
840
  const i = new URLSearchParams(n).get(e);
841
841
  return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
842
842
  }
843
- function vt(n, e, t) {
843
+ function St(n, e, t) {
844
844
  const { tenantMode: r, baseDomain: i, selectorParam: o, fixedTenantSlug: a } = n;
845
- return r === "fixed" ? a || null : r === "subdomain" ? bt(e.hostname, i) : r === "selector" ? St(e.search, o, t) : null;
845
+ return r === "fixed" ? a || null : r === "subdomain" ? bt(e.hostname, i) : r === "selector" ? vt(e.search, o, t) : null;
846
846
  }
847
847
  function Tt(n, e, t) {
848
848
  if (t)
@@ -850,7 +850,7 @@ function Tt(n, e, t) {
850
850
  const r = e.split(".");
851
851
  return r.length === 2 ? `${n}.${e}` : r.length >= 3 ? (r[0] = n, r.join(".")) : null;
852
852
  }
853
- const fe = "_auth";
853
+ const pe = "_auth";
854
854
  function _e(n) {
855
855
  const e = JSON.stringify(n);
856
856
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
@@ -868,32 +868,18 @@ function kt(n) {
868
868
  }
869
869
  function xt() {
870
870
  if (typeof window > "u")
871
- return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
872
- const e = new URLSearchParams(window.location.search).get(fe);
873
- if (console.log("[CrossDomainAuth] extractAuthTokensFromUrl called", {
874
- hasAuthParam: !!e,
875
- searchParams: window.location.search,
876
- encodedLength: e == null ? void 0 : e.length
877
- }), !e) return null;
878
- const t = kt(e);
879
- return console.log("[CrossDomainAuth] Token decode result:", {
880
- success: !!t,
881
- hasAccessToken: !!(t != null && t.accessToken),
882
- hasRefreshToken: !!(t != null && t.refreshToken),
883
- expiresIn: t == null ? void 0 : t.expiresIn
884
- }), t;
871
+ return null;
872
+ const e = new URLSearchParams(window.location.search).get(pe);
873
+ return e ? kt(e) : null;
885
874
  }
886
875
  function At() {
887
876
  if (typeof window > "u") return;
888
877
  const n = new URL(window.location.href);
889
- n.searchParams.delete(fe), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
890
- oldUrl: window.location.href,
891
- newUrl: n.toString()
892
- }), window.history.replaceState({}, "", n.toString());
878
+ n.searchParams.delete(pe), window.history.replaceState({}, "", n.toString());
893
879
  }
894
- const Fe = pe(null);
895
- function yr({ config: n, children: e }) {
896
- const { baseUrl: t, appInfo: r, appId: i } = ve(), o = se(() => typeof window > "u" ? null : vt(
880
+ const Ne = fe(null);
881
+ function wr({ config: n, children: e }) {
882
+ const { baseUrl: t, appInfo: r, appId: i } = Se(), o = se(() => typeof window > "u" ? null : St(
897
883
  {
898
884
  tenantMode: n.tenantMode || "selector",
899
885
  baseDomain: n.baseDomain,
@@ -905,119 +891,119 @@ function yr({ config: n, children: e }) {
905
891
  search: window.location.search
906
892
  },
907
893
  window.localStorage
908
- ), [n.tenantMode, n.baseDomain, n.selectorParam, n.fixedTenantSlug]), [a, f] = k(() => o()), m = K(
894
+ ), [n.tenantMode, n.baseDomain, n.selectorParam, n.fixedTenantSlug]), [a, p] = k(() => o()), w = K(
909
895
  () => {
910
- var d, U, F;
896
+ var c, H, I;
911
897
  return {
912
- enabled: ((d = n.cache) == null ? void 0 : d.enabled) ?? !0,
913
- ttl: ((U = n.cache) == null ? void 0 : U.ttl) ?? 5 * 60 * 1e3,
898
+ enabled: ((c = n.cache) == null ? void 0 : c.enabled) ?? !0,
899
+ ttl: ((H = n.cache) == null ? void 0 : H.ttl) ?? 5 * 60 * 1e3,
914
900
  // 5 minutes default
915
- storageKey: ((F = n.cache) == null ? void 0 : F.storageKey) ?? `tenant_cache_${a || "default"}`
901
+ storageKey: ((I = n.cache) == null ? void 0 : I.storageKey) ?? `tenant_cache_${a || "default"}`
916
902
  };
917
903
  },
918
904
  [n.cache, a]
919
- ), [b, c] = k(() => {
905
+ ), [y, f] = k(() => {
920
906
  if (n.initialTenant) return n.initialTenant;
921
- if (!m.enabled || !a) return null;
907
+ if (!w.enabled || !a) return null;
922
908
  try {
923
- const d = localStorage.getItem(m.storageKey);
924
- if (!d) return null;
925
- const U = JSON.parse(d);
926
- return Date.now() - U.timestamp < m.ttl && U.tenantSlug === a ? U.data : (localStorage.removeItem(m.storageKey), null);
909
+ const c = localStorage.getItem(w.storageKey);
910
+ if (!c) return null;
911
+ const H = JSON.parse(c);
912
+ return Date.now() - H.timestamp < w.ttl && H.tenantSlug === a ? H.data : (localStorage.removeItem(w.storageKey), null);
927
913
  } catch {
928
914
  return null;
929
915
  }
930
- }), [L, p] = k(!b && !n.initialTenant), [R, I] = k(null), [M, E] = k(null), [x, h] = k(!1), [A, w] = k(null);
916
+ }), [x, h] = k(!y && !n.initialTenant), [R, N] = k(null), [D, E] = k(null), [P, u] = k(!1), [S, C] = k(null);
931
917
  re(() => {
932
918
  if (n.tenantMode === "fixed") return;
933
- const d = o();
934
- f(d);
919
+ const c = o();
920
+ p(c);
935
921
  }, [o, n.tenantMode]);
936
- const v = (r == null ? void 0 : r.settingsSchema) || null, N = se(
937
- async (d, U = !1) => {
938
- if (!(!U && m.enabled && b && b.domain === d))
922
+ const M = (r == null ? void 0 : r.settingsSchema) || null, T = se(
923
+ async (c, H = !1) => {
924
+ if (!(!H && w.enabled && y && y.domain === c))
939
925
  try {
940
- p(!0), I(null);
941
- const F = new le(t), g = await new be(F, i).getPublicTenantInfo(d);
942
- if (c(g), m.enabled)
926
+ h(!0), N(null);
927
+ const I = new le(t), m = await new be(I, i).getPublicTenantInfo(c);
928
+ if (f(m), w.enabled)
943
929
  try {
944
- const S = {
945
- data: g,
930
+ const v = {
931
+ data: m,
946
932
  timestamp: Date.now(),
947
- tenantSlug: d
933
+ tenantSlug: c
948
934
  };
949
- localStorage.setItem(m.storageKey, JSON.stringify(S));
950
- } catch (S) {
951
- console.warn("Failed to cache tenant info:", S);
935
+ localStorage.setItem(w.storageKey, JSON.stringify(v));
936
+ } catch (v) {
937
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", v);
952
938
  }
953
- } catch (F) {
954
- const y = F instanceof Error ? F : new Error("Failed to load tenant information");
955
- I(y), c(null);
939
+ } catch (I) {
940
+ const g = I instanceof Error ? I : new Error("Failed to load tenant information");
941
+ N(g), f(null);
956
942
  } finally {
957
- p(!1);
943
+ h(!1);
958
944
  }
959
945
  },
960
- [t, i, m, b]
961
- ), B = se(async () => {
962
- if (!(!m.enabled || !b || !a))
946
+ [t, i, w, y]
947
+ ), $ = se(async () => {
948
+ if (!(!w.enabled || !y || !a))
963
949
  try {
964
- const d = localStorage.getItem(m.storageKey);
965
- if (!d) return;
966
- const U = JSON.parse(d);
967
- if (Date.now() - U.timestamp > m.ttl * 0.5) {
968
- const y = new le(t), S = await new be(y, i).getPublicTenantInfo(a);
969
- c(S);
950
+ const c = localStorage.getItem(w.storageKey);
951
+ if (!c) return;
952
+ const H = JSON.parse(c);
953
+ if (Date.now() - H.timestamp > w.ttl * 0.5) {
954
+ const g = new le(t), v = await new be(g, i).getPublicTenantInfo(a);
955
+ f(v);
970
956
  const Q = {
971
- data: S,
957
+ data: v,
972
958
  timestamp: Date.now(),
973
959
  tenantSlug: a
974
960
  };
975
- localStorage.setItem(m.storageKey, JSON.stringify(Q));
961
+ localStorage.setItem(w.storageKey, JSON.stringify(Q));
976
962
  }
977
- } catch (d) {
978
- console.warn("Background tenant refresh failed:", d);
963
+ } catch (c) {
964
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", c);
979
965
  }
980
- }, [t, i, m, b, a]), l = se(async () => {
981
- if (b != null && b.id)
966
+ }, [t, i, w, y, a]), l = se(async () => {
967
+ if (y != null && y.id)
982
968
  try {
983
- h(!0), w(null);
984
- const d = new le(t), F = await new be(d, b.appId).getTenantSettings(b.id);
985
- E(F);
986
- } catch (d) {
987
- const U = d instanceof Error ? d : new Error("Failed to load tenant settings");
988
- w(U), E(null);
969
+ u(!0), C(null);
970
+ const c = new le(t), I = await new be(c, y.appId).getTenantSettings(y.id);
971
+ E(I);
972
+ } catch (c) {
973
+ const H = c instanceof Error ? c : new Error("Failed to load tenant settings");
974
+ C(H), E(null);
989
975
  } finally {
990
- h(!1);
976
+ u(!1);
991
977
  }
992
- }, [t, b]), H = se(() => {
978
+ }, [t, y]), U = se(() => {
993
979
  l();
994
- }, [l]), P = se(
995
- (d) => {
996
- if (!v)
980
+ }, [l]), b = se(
981
+ (c) => {
982
+ if (!M)
997
983
  return { isValid: !0, errors: [] };
998
- const U = [];
984
+ const H = [];
999
985
  try {
1000
- return v.properties && Object.entries(v.properties).forEach(([F, y]) => {
1001
- var S;
1002
- const g = d[F];
1003
- if ((S = v.required) != null && S.includes(F) && g == null) {
1004
- U.push(`Field '${F}' is required`);
986
+ return M.properties && Object.entries(M.properties).forEach(([I, g]) => {
987
+ var v;
988
+ const m = c[I];
989
+ if ((v = M.required) != null && v.includes(I) && m == null) {
990
+ H.push(`Field '${I}' is required`);
1005
991
  return;
1006
992
  }
1007
- if (g != null) {
1008
- if (y.type) {
1009
- const Q = y.type, J = typeof g;
1010
- Q === "string" && J !== "string" ? U.push(`Field '${F}' must be a string`) : (Q === "number" || Q === "integer") && J !== "number" ? U.push(`Field '${F}' must be a number`) : Q === "boolean" && J !== "boolean" ? U.push(`Field '${F}' must be a boolean`) : Q === "array" && !Array.isArray(g) && U.push(`Field '${F}' must be an array`);
993
+ if (m != null) {
994
+ if (g.type) {
995
+ const Q = g.type, J = typeof m;
996
+ Q === "string" && J !== "string" ? H.push(`Field '${I}' must be a string`) : (Q === "number" || Q === "integer") && J !== "number" ? H.push(`Field '${I}' must be a number`) : Q === "boolean" && J !== "boolean" ? H.push(`Field '${I}' must be a boolean`) : Q === "array" && !Array.isArray(m) && H.push(`Field '${I}' must be an array`);
1011
997
  }
1012
- y.minLength !== void 0 && typeof g == "string" && g.length < y.minLength && U.push(
1013
- `Field '${F}' must be at least ${y.minLength} characters long`
1014
- ), y.maxLength !== void 0 && typeof g == "string" && g.length > y.maxLength && U.push(
1015
- `Field '${F}' must be no more than ${y.maxLength} characters long`
1016
- ), y.minimum !== void 0 && typeof g == "number" && g < y.minimum && U.push(`Field '${F}' must be at least ${y.minimum}`), y.maximum !== void 0 && typeof g == "number" && g > y.maximum && U.push(`Field '${F}' must be no more than ${y.maximum}`), y.pattern && typeof g == "string" && (new RegExp(y.pattern).test(g) || U.push(`Field '${F}' does not match the required pattern`)), y.enum && !y.enum.includes(g) && U.push(`Field '${F}' must be one of: ${y.enum.join(", ")}`);
998
+ g.minLength !== void 0 && typeof m == "string" && m.length < g.minLength && H.push(
999
+ `Field '${I}' must be at least ${g.minLength} characters long`
1000
+ ), g.maxLength !== void 0 && typeof m == "string" && m.length > g.maxLength && H.push(
1001
+ `Field '${I}' must be no more than ${g.maxLength} characters long`
1002
+ ), g.minimum !== void 0 && typeof m == "number" && m < g.minimum && H.push(`Field '${I}' must be at least ${g.minimum}`), g.maximum !== void 0 && typeof m == "number" && m > g.maximum && H.push(`Field '${I}' must be no more than ${g.maximum}`), g.pattern && typeof m == "string" && (new RegExp(g.pattern).test(m) || H.push(`Field '${I}' does not match the required pattern`)), g.enum && !g.enum.includes(m) && H.push(`Field '${I}' must be one of: ${g.enum.join(", ")}`);
1017
1003
  }
1018
1004
  }), {
1019
- isValid: U.length === 0,
1020
- errors: U
1005
+ isValid: H.length === 0,
1006
+ errors: H
1021
1007
  };
1022
1008
  } catch {
1023
1009
  return {
@@ -1026,97 +1012,97 @@ function yr({ config: n, children: e }) {
1026
1012
  };
1027
1013
  }
1028
1014
  },
1029
- [v]
1015
+ [M]
1030
1016
  );
1031
1017
  re(() => {
1032
- !n.initialTenant && a ? b ? B() : N(a) : !n.initialTenant && !a && (c(null), I(null), p(!1));
1033
- }, [n.initialTenant, a, b, N, B]), re(() => {
1034
- b != null && b.id ? l() : (E(null), w(null), h(!1));
1035
- }, [b == null ? void 0 : b.id, l]);
1036
- const D = se(
1037
- (d, U) => {
1038
- const { mode: F = "reload", tokens: y, redirectPath: g } = U || {}, S = n.tenantMode || "selector";
1039
- if (S === "fixed") {
1040
- console.warn(
1018
+ !n.initialTenant && a ? y ? $() : T(a) : !n.initialTenant && !a && (f(null), N(null), h(!1));
1019
+ }, [n.initialTenant, a, y, T, $]), re(() => {
1020
+ y != null && y.id ? l() : (E(null), C(null), u(!1));
1021
+ }, [y == null ? void 0 : y.id, l]);
1022
+ const L = se(
1023
+ (c, H) => {
1024
+ const { mode: I = "reload", tokens: g, redirectPath: m } = H || {}, v = n.tenantMode || "selector";
1025
+ if (v === "fixed") {
1026
+ process.env.NODE_ENV === "development" && console.warn(
1041
1027
  "[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
1042
1028
  n.fixedTenantSlug
1043
- ), g && (window.location.href = g);
1029
+ ), m && (window.location.href = m);
1044
1030
  return;
1045
1031
  }
1046
- if (localStorage.setItem("tenant", d), S === "subdomain") {
1032
+ if (localStorage.setItem("tenant", c), v === "subdomain") {
1047
1033
  const Q = window.location.hostname, J = Tt(
1048
- d,
1034
+ c,
1049
1035
  Q,
1050
1036
  n.baseDomain
1051
1037
  );
1052
1038
  if (!J) {
1053
- console.warn(
1039
+ process.env.NODE_ENV === "development" && console.warn(
1054
1040
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
1055
1041
  Q
1056
1042
  );
1057
1043
  return;
1058
1044
  }
1059
- const q = g || window.location.pathname, O = new URL(`${window.location.protocol}//${J}${q}`);
1060
- new URLSearchParams(window.location.search).forEach((T, V) => {
1061
- V !== fe && O.searchParams.set(V, T);
1062
- }), y && O.searchParams.set(fe, _e(y)), window.location.href = O.toString();
1063
- } else if (S === "selector") {
1064
- const Q = g || window.location.pathname, J = new URLSearchParams(window.location.search);
1065
- if (J.set(n.selectorParam || "tenant", d), J.delete(fe), y && J.set(fe, _e(y)), F === "reload") {
1066
- const q = `${Q}?${J.toString()}${window.location.hash}`;
1067
- window.location.href = q;
1045
+ const O = m || window.location.pathname, q = new URL(`${window.location.protocol}//${J}${O}`);
1046
+ new URLSearchParams(window.location.search).forEach((A, V) => {
1047
+ V !== pe && q.searchParams.set(V, A);
1048
+ }), g && q.searchParams.set(pe, _e(g)), window.location.href = q.toString();
1049
+ } else if (v === "selector") {
1050
+ const Q = m || window.location.pathname, J = new URLSearchParams(window.location.search);
1051
+ if (J.set(n.selectorParam || "tenant", c), J.delete(pe), g && J.set(pe, _e(g)), I === "reload") {
1052
+ const O = `${Q}?${J.toString()}${window.location.hash}`;
1053
+ window.location.href = O;
1068
1054
  } else {
1069
- const q = `${Q}?${J.toString()}${window.location.hash}`;
1070
- window.history.pushState({}, "", q), f(d), N(d);
1055
+ const O = `${Q}?${J.toString()}${window.location.hash}`;
1056
+ window.history.pushState({}, "", O), p(c), T(c);
1071
1057
  }
1072
1058
  }
1073
1059
  },
1074
- [n.tenantMode, n.selectorParam, n.baseDomain, N]
1075
- ), C = K(() => ({
1060
+ [n.tenantMode, n.selectorParam, n.baseDomain, T]
1061
+ ), F = K(() => ({
1076
1062
  // Tenant info
1077
- tenant: b,
1063
+ tenant: y,
1078
1064
  tenantSlug: a,
1079
- isTenantLoading: L,
1065
+ isTenantLoading: x,
1080
1066
  tenantError: R,
1081
1067
  retryTenant: () => {
1082
- a && N(a);
1068
+ a && T(a);
1083
1069
  },
1084
1070
  // Settings
1085
- settings: M,
1086
- settingsSchema: v,
1087
- isSettingsLoading: x,
1088
- settingsError: A,
1071
+ settings: D,
1072
+ settingsSchema: M,
1073
+ isSettingsLoading: P,
1074
+ settingsError: S,
1089
1075
  // Actions
1090
- refreshSettings: H,
1091
- switchTenant: D,
1076
+ refreshSettings: U,
1077
+ switchTenant: L,
1092
1078
  // Validation
1093
- validateSettings: P
1079
+ validateSettings: b
1094
1080
  }), [
1095
- b,
1081
+ y,
1096
1082
  a,
1097
- L,
1098
- R,
1099
- M,
1100
- v,
1101
1083
  x,
1102
- A,
1103
- H,
1084
+ R,
1104
1085
  D,
1105
- P
1086
+ M,
1087
+ P,
1088
+ S,
1089
+ U,
1090
+ L,
1091
+ b
1106
1092
  ]);
1107
- return /* @__PURE__ */ s(Fe.Provider, { value: C, children: e });
1093
+ return /* @__PURE__ */ s(Ne.Provider, { value: F, children: e });
1108
1094
  }
1109
1095
  function ge() {
1110
- const n = ae(Fe);
1096
+ const n = ae(Ne);
1111
1097
  if (!n)
1112
1098
  throw new Error("useTenant must be used within a TenantProvider");
1113
1099
  return n;
1114
1100
  }
1115
1101
  function xe() {
1116
- return ae(Fe);
1102
+ return ae(Ne);
1117
1103
  }
1118
- const wr = ge;
1119
- function br() {
1104
+ const br = ge;
1105
+ function vr() {
1120
1106
  const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = ge();
1121
1107
  return {
1122
1108
  settings: n,
@@ -1136,30 +1122,25 @@ function me() {
1136
1122
  retry: i
1137
1123
  };
1138
1124
  }
1139
- const Ne = pe(null);
1125
+ const De = fe(null);
1140
1126
  function Sr({ config: n = {}, children: e }) {
1141
- const { appId: t, baseUrl: r } = ve(), { tenant: i, tenantSlug: o, switchTenant: a } = ge(), [f, m] = k(n.initialRoles || []), [b, c] = k(!n.initialRoles), [L, p] = k(null), [R, I] = k(!1), [M, E] = k(null), [x, h] = k(() => {
1127
+ const { appId: t, baseUrl: r } = Se(), { tenant: i, tenantSlug: o, switchTenant: a } = ge(), [p, w] = k(n.initialRoles || []), [y, f] = k(!n.initialRoles), [x, h] = k(null), [R, N] = k(!1), [D, E] = k(null), [P, u] = k(() => {
1142
1128
  try {
1143
- const T = localStorage.getItem("userTenants");
1144
- return T ? JSON.parse(T) : [];
1129
+ const A = localStorage.getItem("userTenants");
1130
+ return A ? JSON.parse(A) : [];
1145
1131
  } catch {
1146
1132
  return [];
1147
1133
  }
1148
- }), [A, w] = k(!1), v = Me({ done: !1, urlTokens: null });
1149
- v.current.done || (v.current.done = !0, v.current.urlTokens = xt(), v.current.urlTokens && console.log(
1150
- "[AuthProvider] SYNC: URL tokens found, will block isAuthReady until user loaded"
1151
- ));
1152
- const [N, B] = k(() => {
1153
- const T = v.current.urlTokens !== null;
1154
- return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", T), T;
1155
- }), l = K(() => {
1156
- const T = we.getInstance({
1134
+ }), [S, C] = k(!1), M = Me({ done: !1, urlTokens: null });
1135
+ M.current.done || (M.current.done = !0, M.current.urlTokens = xt());
1136
+ const [T, $] = k(() => M.current.urlTokens !== null), l = K(() => {
1137
+ const A = we.getInstance({
1157
1138
  tenantSlug: o,
1158
1139
  baseUrl: r,
1159
1140
  refreshQueueTimeout: n.refreshQueueTimeout,
1160
1141
  proactiveRefreshMargin: n.proactiveRefreshMargin,
1161
1142
  onSessionExpired: (V) => {
1162
- p(null), E(null), h([]), w(!1);
1143
+ h(null), E(null), u([]), C(!1);
1163
1144
  try {
1164
1145
  localStorage.removeItem("userTenants");
1165
1146
  } catch {
@@ -1167,46 +1148,46 @@ function Sr({ config: n = {}, children: e }) {
1167
1148
  n.onSessionExpired ? n.onSessionExpired(V) : n.onRefreshFailed && n.onRefreshFailed();
1168
1149
  }
1169
1150
  });
1170
- return v.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), T.setTokens({
1171
- accessToken: v.current.urlTokens.accessToken,
1172
- refreshToken: v.current.urlTokens.refreshToken,
1173
- expiresIn: v.current.urlTokens.expiresIn
1174
- }), console.log("[AuthProvider] SYNC: Session valid:", T.hasValidSession())), T;
1175
- }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [H, P] = k(() => {
1176
- if (v.current.urlTokens) return !1;
1177
- const T = l.getTokens();
1178
- return T ? l.hasValidSession() || !!T.refreshToken : !1;
1179
- }), D = v.current.done && !N && !H, C = K(() => {
1180
- const T = new le(r);
1181
- return T.setSessionManager(l), T;
1182
- }, [r, l]), d = K(() => new yt(new le(r)), [r]), U = K(() => new wt(C, l), [C, l]), F = K(() => new ze(new le(r)), [r]), y = K(() => L || l.getUser(), [L, l]), g = K(() => y != null && y.roleId && f.find((T) => T.id === y.roleId) || null, [y, f]), S = K(() => (g == null ? void 0 : g.permissions) || [], [g]), Q = K(() => l.hasValidSession() && L !== null, [l, L]), J = Me(async () => {
1183
- }), q = K(() => {
1184
- const T = async ($ = !1) => {
1151
+ return M.current.urlTokens && A.setTokens({
1152
+ accessToken: M.current.urlTokens.accessToken,
1153
+ refreshToken: M.current.urlTokens.refreshToken,
1154
+ expiresIn: M.current.urlTokens.expiresIn
1155
+ }), A;
1156
+ }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [U, b] = k(() => {
1157
+ if (M.current.urlTokens) return !1;
1158
+ const A = l.getTokens();
1159
+ return A ? l.hasValidSession() || !!A.refreshToken : !1;
1160
+ }), L = M.current.done && !T && !U, F = K(() => {
1161
+ const A = new le(r);
1162
+ return A.setSessionManager(l), A;
1163
+ }, [r, l]), c = K(() => new yt(new le(r)), [r]), H = K(() => new wt(F, l), [F, l]), I = K(() => new ze(new le(r)), [r]), g = K(() => x || l.getUser(), [x, l]), m = K(() => g != null && g.roleId && p.find((A) => A.id === g.roleId) || null, [g, p]), v = K(() => (m == null ? void 0 : m.permissions) || [], [m]), Q = K(() => l.hasValidSession() && x !== null, [l, x]), J = Me(async () => {
1164
+ }), O = K(() => {
1165
+ const A = async (B = !1) => {
1185
1166
  try {
1186
- if (!l.hasValidSession() || !$ && L)
1167
+ if (!l.hasValidSession() || !B && x)
1187
1168
  return;
1188
1169
  const z = l.getUserId();
1189
1170
  if (!z) {
1190
- console.warn("[AuthProvider] No userId available in token or storage");
1171
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] No userId available in token or storage");
1191
1172
  return;
1192
1173
  }
1193
- I(!0), E(null);
1194
- const Z = await U.getUserById(z);
1195
- p(Z), l.setUser(Z);
1174
+ N(!0), E(null);
1175
+ const Z = await H.getUserById(z);
1176
+ h(Z), l.setUser(Z);
1196
1177
  } catch (z) {
1197
1178
  const Z = z instanceof Error ? z : new Error("Failed to load user data");
1198
- E(Z), console.error("[AuthProvider] Failed to load user data:", Z);
1179
+ E(Z), process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data:", Z);
1199
1180
  } finally {
1200
- I(!1);
1181
+ N(!1);
1201
1182
  }
1202
1183
  }, V = async () => {
1203
- await T();
1204
- }, de = async ($) => {
1184
+ await A();
1185
+ }, de = async (B) => {
1205
1186
  var Be;
1206
- const { username: z, password: Z, tenantSlug: W, redirectPath: Y } = $;
1187
+ const { username: z, password: Z, tenantSlug: W, redirectPath: Y } = B;
1207
1188
  let X = i == null ? void 0 : i.id, ee = o, te = l;
1208
- W && (X = (await new be(C, t).getPublicTenantInfo(W)).id, ee = W);
1209
- const G = await d.login({
1189
+ W && (X = (await new be(F, t).getPublicTenantInfo(W)).id, ee = W);
1190
+ const G = await c.login({
1210
1191
  username: z,
1211
1192
  password: Z,
1212
1193
  appId: t,
@@ -1220,22 +1201,22 @@ function Sr({ config: n = {}, children: e }) {
1220
1201
  refreshToken: G.refreshToken,
1221
1202
  expiresIn: G.expiresIn
1222
1203
  }), G.user) {
1223
- te.setUser(G.user), p(G.user);
1204
+ te.setUser(G.user), h(G.user);
1224
1205
  try {
1225
- await T();
1206
+ await A();
1226
1207
  } catch (Te) {
1227
- console.warn("Failed to load complete user data after login:", Te);
1208
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", Te);
1228
1209
  }
1229
1210
  }
1230
1211
  if (G.tenants && G.tenants.length > 0) {
1231
- h(G.tenants);
1212
+ u(G.tenants);
1232
1213
  try {
1233
1214
  localStorage.setItem("userTenants", JSON.stringify(G.tenants));
1234
1215
  } catch {
1235
1216
  }
1236
1217
  }
1237
1218
  const Pe = ((Be = G.user) == null ? void 0 : Be.tenantId) !== null;
1238
- w(Pe);
1219
+ C(Pe);
1239
1220
  const Re = {
1240
1221
  accessToken: G.accessToken,
1241
1222
  refreshToken: G.refreshToken,
@@ -1246,21 +1227,21 @@ function Sr({ config: n = {}, children: e }) {
1246
1227
  if (Y && Y !== window.location.pathname)
1247
1228
  return a(ee || o || "", { tokens: Re, redirectPath: Y }), G;
1248
1229
  if (!Pe && G.tenants && G.tenants.length > 0) {
1249
- const Te = $.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1230
+ const Te = B.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1250
1231
  if (G.tenants.length === 1 && Te) {
1251
- const qe = G.tenants[0];
1252
- return a(qe.subdomain, { tokens: Re, redirectPath: Y }), G;
1232
+ const Oe = G.tenants[0];
1233
+ return a(Oe.subdomain, { tokens: Re, redirectPath: Y }), G;
1253
1234
  } else G.tenants.length > 1 && n.onTenantSelectionRequired && n.onTenantSelectionRequired(G.tenants);
1254
1235
  }
1255
1236
  return G;
1256
- }, he = async ($) => {
1257
- const { email: z, phoneNumber: Z, name: W, password: Y, lastName: X, tenantId: ee } = $;
1237
+ }, he = async (B) => {
1238
+ const { email: z, phoneNumber: Z, name: W, password: Y, lastName: X, tenantId: ee } = B;
1258
1239
  if (!z && !Z)
1259
1240
  throw new Error("Either email or phoneNumber is required");
1260
1241
  if (!W || !Y)
1261
1242
  throw new Error("Name and password are required");
1262
1243
  const te = ee ?? (i == null ? void 0 : i.id);
1263
- return await d.signup({
1244
+ return await c.signup({
1264
1245
  email: z,
1265
1246
  phoneNumber: Z,
1266
1247
  name: W,
@@ -1269,13 +1250,13 @@ function Sr({ config: n = {}, children: e }) {
1269
1250
  lastName: X,
1270
1251
  appId: t
1271
1252
  });
1272
- }, et = async ($) => {
1273
- const { email: z, phoneNumber: Z, name: W, password: Y, tenantName: X, lastName: ee } = $;
1253
+ }, et = async (B) => {
1254
+ const { email: z, phoneNumber: Z, name: W, password: Y, tenantName: X, lastName: ee } = B;
1274
1255
  if (!z && !Z)
1275
1256
  throw new Error("Either email or phoneNumber is required");
1276
1257
  if (!W || !Y || !X)
1277
1258
  throw new Error("Name, password, and tenantName are required");
1278
- return await d.signupTenantAdmin({
1259
+ return await c.signupTenantAdmin({
1279
1260
  email: z,
1280
1261
  phoneNumber: Z,
1281
1262
  name: W,
@@ -1284,22 +1265,22 @@ function Sr({ config: n = {}, children: e }) {
1284
1265
  appId: t,
1285
1266
  lastName: ee
1286
1267
  });
1287
- }, tt = async ($) => {
1288
- const { currentPassword: z, newPassword: Z } = $, W = await l.getAuthHeaders();
1289
- await d.changePassword({ currentPassword: z, newPassword: Z }, W);
1290
- }, rt = async ($) => {
1291
- const { email: z, tenantId: Z } = $, W = Z ?? (i == null ? void 0 : i.id);
1268
+ }, tt = async (B) => {
1269
+ const { currentPassword: z, newPassword: Z } = B, W = await l.getAuthHeaders();
1270
+ await c.changePassword({ currentPassword: z, newPassword: Z }, W);
1271
+ }, rt = async (B) => {
1272
+ const { email: z, tenantId: Z } = B, W = Z ?? (i == null ? void 0 : i.id);
1292
1273
  if (!W)
1293
1274
  throw new Error("tenantId is required for password reset");
1294
- await d.requestPasswordReset({ email: z, tenantId: W });
1295
- }, nt = async ($) => {
1296
- const { token: z, newPassword: Z } = $;
1297
- await d.confirmPasswordReset({ token: z, newPassword: Z });
1298
- }, st = async ($) => {
1299
- const { email: z, frontendUrl: Z, name: W, lastName: Y, tenantId: X } = $, ee = X ?? (i == null ? void 0 : i.id);
1275
+ await c.requestPasswordReset({ email: z, tenantId: W });
1276
+ }, nt = async (B) => {
1277
+ const { token: z, newPassword: Z } = B;
1278
+ await c.confirmPasswordReset({ token: z, newPassword: Z });
1279
+ }, st = async (B) => {
1280
+ const { email: z, frontendUrl: Z, name: W, lastName: Y, tenantId: X } = B, ee = X ?? (i == null ? void 0 : i.id);
1300
1281
  if (!ee)
1301
1282
  throw new Error("tenantId is required for magic link authentication");
1302
- return await d.sendMagicLink({
1283
+ return await c.sendMagicLink({
1303
1284
  email: z,
1304
1285
  tenantId: ee,
1305
1286
  frontendUrl: Z,
@@ -1307,11 +1288,11 @@ function Sr({ config: n = {}, children: e }) {
1307
1288
  lastName: Y,
1308
1289
  appId: t
1309
1290
  });
1310
- }, it = async ($) => {
1311
- const { token: z, email: Z, tenantSlug: W } = $;
1291
+ }, it = async (B) => {
1292
+ const { token: z, email: Z, tenantSlug: W } = B;
1312
1293
  let Y = i == null ? void 0 : i.id, X = o, ee = l;
1313
- W && (Y = (await new be(C, t).getPublicTenantInfo(W)).id, X = W);
1314
- const te = await d.verifyMagicLink({
1294
+ W && (Y = (await new be(F, t).getPublicTenantInfo(W)).id, X = W);
1295
+ const te = await c.verifyMagicLink({
1315
1296
  token: z,
1316
1297
  email: Z,
1317
1298
  appId: t,
@@ -1325,11 +1306,14 @@ function Sr({ config: n = {}, children: e }) {
1325
1306
  refreshToken: te.refreshToken,
1326
1307
  expiresIn: te.expiresIn
1327
1308
  }), te.user) {
1328
- ee.setUser(te.user), p(te.user);
1309
+ ee.setUser(te.user), h(te.user);
1329
1310
  try {
1330
- await T();
1311
+ await A();
1331
1312
  } catch (ye) {
1332
- console.warn("Failed to load complete user data after magic link login:", ye);
1313
+ process.env.NODE_ENV === "development" && console.warn(
1314
+ "[AuthProvider] Failed to load complete user data after magic link:",
1315
+ ye
1316
+ );
1333
1317
  }
1334
1318
  }
1335
1319
  return G && X && X !== o && a(X, {
@@ -1340,53 +1324,53 @@ function Sr({ config: n = {}, children: e }) {
1340
1324
  }
1341
1325
  }), te;
1342
1326
  }, ot = async () => {
1343
- const $ = l.getTokens();
1344
- if (!($ != null && $.refreshToken))
1327
+ const B = l.getTokens();
1328
+ if (!(B != null && B.refreshToken))
1345
1329
  throw new Error("No refresh token available");
1346
- const z = await d.refreshToken({
1347
- refreshToken: $.refreshToken
1330
+ const z = await c.refreshToken({
1331
+ refreshToken: B.refreshToken
1348
1332
  });
1349
1333
  l.setTokens({
1350
1334
  accessToken: z.accessToken,
1351
- refreshToken: z.refreshToken || $.refreshToken,
1335
+ refreshToken: z.refreshToken || B.refreshToken,
1352
1336
  expiresIn: z.expiresIn
1353
1337
  });
1354
1338
  }, at = () => {
1355
- l.clearSession(), p(null), E(null), h([]), w(!1);
1339
+ l.clearSession(), h(null), E(null), u([]), C(!1);
1356
1340
  try {
1357
1341
  localStorage.removeItem("userTenants");
1358
1342
  } catch {
1359
1343
  }
1360
- }, lt = ($) => {
1361
- l.setTokens($);
1344
+ }, lt = (B) => {
1345
+ l.setTokens(B);
1362
1346
  }, ct = () => l.hasValidSession(), dt = () => {
1363
- l.clearSession(), p(null), E(null);
1347
+ l.clearSession(), h(null), E(null);
1364
1348
  }, ut = async () => {
1365
1349
  if (t)
1366
1350
  try {
1367
- c(!0);
1368
- const { roles: $ } = await F.getRolesByApp(t);
1369
- m($);
1370
- } catch ($) {
1371
- console.error("Failed to fetch roles:", $);
1351
+ f(!0);
1352
+ const { roles: B } = await I.getRolesByApp(t);
1353
+ w(B);
1354
+ } catch (B) {
1355
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", B);
1372
1356
  } finally {
1373
- c(!1);
1357
+ f(!1);
1374
1358
  }
1375
1359
  }, ht = async () => {
1376
1360
  await ut();
1377
- }, Ae = ($) => {
1378
- if (!S || S.length === 0)
1361
+ }, Ae = (B) => {
1362
+ if (!v || v.length === 0)
1379
1363
  return !1;
1380
- if (typeof $ == "string")
1381
- return S.includes($);
1382
- const z = `${$.resource}.${$.action}`;
1383
- return S.includes(z);
1364
+ if (typeof B == "string")
1365
+ return v.includes(B);
1366
+ const z = `${B.resource}.${B.action}`;
1367
+ return v.includes(z);
1384
1368
  };
1385
1369
  return {
1386
1370
  // RFC-003: Authentication state
1387
1371
  isAuthenticated: Q,
1388
1372
  sessionManager: l,
1389
- authenticatedHttpService: C,
1373
+ authenticatedHttpService: F,
1390
1374
  login: de,
1391
1375
  signup: he,
1392
1376
  signupTenantAdmin: et,
@@ -1400,40 +1384,40 @@ function Sr({ config: n = {}, children: e }) {
1400
1384
  setTokens: lt,
1401
1385
  hasValidSession: ct,
1402
1386
  clearSession: dt,
1403
- currentUser: L,
1387
+ currentUser: x,
1404
1388
  isUserLoading: R,
1405
- userError: M,
1406
- loadUserData: T,
1389
+ userError: D,
1390
+ loadUserData: A,
1407
1391
  refreshUser: V,
1408
- isAuthInitializing: !D,
1409
- isAuthReady: D,
1410
- userRole: g,
1411
- userPermissions: S,
1412
- availableRoles: f,
1413
- rolesLoading: b,
1392
+ isAuthInitializing: !L,
1393
+ isAuthReady: L,
1394
+ userRole: m,
1395
+ userPermissions: v,
1396
+ availableRoles: p,
1397
+ rolesLoading: y,
1414
1398
  hasPermission: Ae,
1415
- hasAnyPermission: ($) => $.some((z) => Ae(z)),
1416
- hasAllPermissions: ($) => $.every((z) => Ae(z)),
1417
- getUserPermissionStrings: () => S || [],
1399
+ hasAnyPermission: (B) => B.some((z) => Ae(z)),
1400
+ hasAllPermissions: (B) => B.every((z) => Ae(z)),
1401
+ getUserPermissionStrings: () => v || [],
1418
1402
  refreshRoles: ht,
1419
1403
  // RFC-004: Multi-tenant user membership
1420
- userTenants: x,
1421
- hasTenantContext: A,
1422
- switchToTenant: async ($, z) => {
1404
+ userTenants: P,
1405
+ hasTenantContext: S,
1406
+ switchToTenant: async (B, z) => {
1423
1407
  const { redirectPath: Z } = z || {}, W = l.getTokens();
1424
1408
  if (!(W != null && W.refreshToken))
1425
1409
  throw new Error("No refresh token available for tenant switch");
1426
- const Y = await d.switchTenant({
1410
+ const Y = await c.switchTenant({
1427
1411
  refreshToken: W.refreshToken,
1428
- tenantId: $
1412
+ tenantId: B
1429
1413
  });
1430
1414
  l.setTokens({
1431
1415
  accessToken: Y.accessToken,
1432
1416
  refreshToken: W.refreshToken,
1433
1417
  // Keep the same refresh token
1434
1418
  expiresIn: Y.expiresIn
1435
- }), p(Y.user), l.setUser(Y.user), w(!0);
1436
- const X = x.find((ee) => ee.id === $);
1419
+ }), h(Y.user), l.setUser(Y.user), C(!0);
1420
+ const X = P.find((ee) => ee.id === B);
1437
1421
  X && a(X.subdomain, {
1438
1422
  tokens: {
1439
1423
  accessToken: Y.accessToken,
@@ -1444,8 +1428,8 @@ function Sr({ config: n = {}, children: e }) {
1444
1428
  });
1445
1429
  },
1446
1430
  refreshUserTenants: async () => {
1447
- const $ = await l.getAuthHeaders(), z = await d.getUserTenants($);
1448
- h(z);
1431
+ const B = await l.getAuthHeaders(), z = await c.getUserTenants(B);
1432
+ u(z);
1449
1433
  try {
1450
1434
  localStorage.setItem("userTenants", JSON.stringify(z));
1451
1435
  } catch {
@@ -1456,69 +1440,69 @@ function Sr({ config: n = {}, children: e }) {
1456
1440
  }, [
1457
1441
  Q,
1458
1442
  l,
1459
- C,
1460
- d,
1461
- U,
1462
1443
  F,
1444
+ c,
1445
+ H,
1446
+ I,
1463
1447
  t,
1464
1448
  i,
1465
1449
  o,
1466
1450
  a,
1467
- f,
1468
- L,
1469
- R,
1470
- M,
1451
+ p,
1471
1452
  x,
1472
- A,
1453
+ R,
1473
1454
  D,
1474
- g,
1475
- S
1455
+ P,
1456
+ S,
1457
+ L,
1458
+ m,
1459
+ v
1476
1460
  ]);
1477
- J.current = q.loadUserData, re(() => {
1461
+ J.current = O.loadUserData, re(() => {
1478
1462
  !n.initialRoles && t && (async () => {
1479
1463
  try {
1480
- c(!0);
1464
+ f(!0);
1481
1465
  const V = new le(r), de = new ze(V), { roles: he } = await de.getRolesByApp(t);
1482
- m(he);
1466
+ w(he);
1483
1467
  } catch (V) {
1484
- console.error("Failed to fetch roles:", V);
1468
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", V);
1485
1469
  } finally {
1486
- c(!1);
1470
+ f(!1);
1487
1471
  }
1488
1472
  })();
1489
1473
  }, [t, r, n.initialRoles]);
1490
- const [O, j] = k(!1);
1474
+ const [q, j] = k(!1);
1491
1475
  return re(() => {
1492
- O || (j(!0), v.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), At(), B(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), q.loadUserData().catch((T) => {
1493
- console.error("[AuthProvider] Failed to load user data:", T);
1476
+ q || (j(!0), M.current.urlTokens && (At(), $(!0), O.loadUserData().catch((A) => {
1477
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data after URL tokens:", A);
1494
1478
  }).finally(() => {
1495
- console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), B(!1);
1479
+ $(!1);
1496
1480
  })));
1497
- }, [q, O]), re(() => {
1498
- let T = !1;
1481
+ }, [O, q]), re(() => {
1482
+ let A = !1;
1499
1483
  return (async () => {
1500
1484
  var he;
1501
- if (!l.hasValidSession() && ((he = l.getTokens()) != null && he.refreshToken) && await l.waitForPendingRefresh(), T) return;
1485
+ if (!l.hasValidSession() && ((he = l.getTokens()) != null && he.refreshToken) && await l.waitForPendingRefresh(), A) return;
1502
1486
  const de = l.getUser();
1503
- de && l.hasValidSession() && p(de), P(!1);
1487
+ de && l.hasValidSession() && h(de), b(!1);
1504
1488
  })(), () => {
1505
- T = !0;
1489
+ A = !0;
1506
1490
  };
1507
1491
  }, [l]), re(() => {
1508
- O && (v.current.urlTokens || (!L && !R && !M && l.hasValidSession() ? (console.log("[AuthProvider] Auto-loading user data..."), J.current().catch(() => {
1492
+ q && (M.current.urlTokens || (!x && !R && !D && l.hasValidSession() ? J.current().catch(() => {
1509
1493
  }).finally(() => {
1510
- P(!1);
1511
- })) : P(!1)));
1512
- }, [L, R, M, l, O]), /* @__PURE__ */ s(Ne.Provider, { value: q, children: e });
1494
+ b(!1);
1495
+ }) : b(!1)));
1496
+ }, [x, R, D, l, q]), /* @__PURE__ */ s(De.Provider, { value: O, children: e });
1513
1497
  }
1514
1498
  function ue() {
1515
- const n = ae(Ne);
1499
+ const n = ae(De);
1516
1500
  if (!n)
1517
1501
  throw new Error("useAuth must be used within an AuthProvider");
1518
1502
  return n;
1519
1503
  }
1520
- function De() {
1521
- return ae(Ne);
1504
+ function Fe() {
1505
+ return ae(De);
1522
1506
  }
1523
1507
  class Pt {
1524
1508
  constructor(e, t) {
@@ -1600,55 +1584,55 @@ class Pt {
1600
1584
  })).data;
1601
1585
  }
1602
1586
  }
1603
- const Ce = pe(null);
1604
- function vr({ config: n = {}, children: e }) {
1605
- const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [f, m] = k([]), [b, c] = k(!1), [L, p] = k(null), [R, I] = k(!1), M = K(() => {
1606
- const h = new le(i);
1607
- return new Pt(h);
1587
+ const Ce = fe(null);
1588
+ function Tr({ config: n = {}, children: e }) {
1589
+ const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [p, w] = k([]), [y, f] = k(!1), [x, h] = k(null), [R, N] = k(!1), D = K(() => {
1590
+ const u = new le(i);
1591
+ return new Pt(u);
1608
1592
  }, [i]), E = async () => {
1609
1593
  if (!(a != null && a.id)) {
1610
- m([]);
1594
+ w([]);
1611
1595
  return;
1612
1596
  }
1613
- c(!0), p(null);
1597
+ f(!0), h(null);
1614
1598
  try {
1615
- const h = await M.getTenantFeatureFlags(a.id, o);
1616
- m(h);
1617
- } catch (h) {
1618
- const A = h instanceof Error ? h.message : "Failed to fetch feature flags";
1619
- p(A), n.onError && n.onError(h instanceof Error ? h : new Error(A));
1599
+ const u = await D.getTenantFeatureFlags(a.id, o);
1600
+ w(u);
1601
+ } catch (u) {
1602
+ const S = u instanceof Error ? u.message : "Failed to fetch feature flags";
1603
+ h(S), n.onError && n.onError(u instanceof Error ? u : new Error(S));
1620
1604
  } finally {
1621
- c(!1);
1605
+ f(!1);
1622
1606
  }
1623
1607
  };
1624
1608
  re(() => {
1625
1609
  if (!i || !o) return;
1626
- E().finally(() => I(!0));
1627
- const h = n.refreshInterval || 5 * 60 * 1e3, A = setInterval(E, h);
1628
- return () => clearInterval(A);
1610
+ E().finally(() => N(!0));
1611
+ const u = n.refreshInterval || 5 * 60 * 1e3, S = setInterval(E, u);
1612
+ return () => clearInterval(S);
1629
1613
  }, [a == null ? void 0 : a.id, i, o, n.refreshInterval]);
1630
- const x = K(() => {
1631
- const h = (B) => {
1632
- const l = f.find((H) => H.key === B);
1614
+ const P = K(() => {
1615
+ const u = ($) => {
1616
+ const l = p.find((U) => U.key === $);
1633
1617
  return (l == null ? void 0 : l.value) === !0;
1634
- }, A = (B) => f.find((l) => l.key === B), w = (B) => {
1635
- const l = f.find((H) => H.key === B);
1618
+ }, S = ($) => p.find((l) => l.key === $), C = ($) => {
1619
+ const l = p.find((U) => U.key === $);
1636
1620
  return l ? l.value ? "enabled" : "disabled" : "not_found";
1637
- }, v = async () => {
1621
+ }, M = async () => {
1638
1622
  await E();
1639
- }, N = !!(i && o) && (R || !(a != null && a.id));
1623
+ }, T = !!(i && o) && (R || !(a != null && a.id));
1640
1624
  return {
1641
- featureFlags: f,
1642
- loading: b,
1643
- error: L,
1644
- isReady: N,
1645
- isEnabled: h,
1646
- getFlag: A,
1647
- getFlagState: w,
1648
- refresh: v
1625
+ featureFlags: p,
1626
+ loading: y,
1627
+ error: x,
1628
+ isReady: T,
1629
+ isEnabled: u,
1630
+ getFlag: S,
1631
+ getFlagState: C,
1632
+ refresh: M
1649
1633
  };
1650
- }, [f, b, L, i, o, a == null ? void 0 : a.id, R]);
1651
- return /* @__PURE__ */ s(Ce.Provider, { value: x, children: e });
1634
+ }, [p, y, x, i, o, a == null ? void 0 : a.id, R]);
1635
+ return /* @__PURE__ */ s(Ce.Provider, { value: P, children: e });
1652
1636
  }
1653
1637
  function Rt() {
1654
1638
  const n = ae(Ce);
@@ -1659,7 +1643,7 @@ function Rt() {
1659
1643
  function Ke() {
1660
1644
  return ae(Ce);
1661
1645
  }
1662
- class It {
1646
+ class Et {
1663
1647
  constructor(e, t) {
1664
1648
  this.httpService = e, this.sessionManager = t;
1665
1649
  }
@@ -1725,68 +1709,68 @@ class It {
1725
1709
  )).data;
1726
1710
  }
1727
1711
  }
1728
- const Ue = pe(void 0);
1729
- function Tr({ config: n = {}, children: e }) {
1730
- const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, f] = k(null), [m, b] = k(!1), [c, L] = k(null), [p, R] = k(!1), I = K(() => {
1731
- const x = new le(i);
1732
- return new It(x);
1733
- }, [i]), M = async () => {
1712
+ const $e = fe(void 0);
1713
+ function kr({ config: n = {}, children: e }) {
1714
+ const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, p] = k(null), [w, y] = k(!1), [f, x] = k(null), [h, R] = k(!1), N = K(() => {
1715
+ const P = new le(i);
1716
+ return new Et(P);
1717
+ }, [i]), D = async () => {
1734
1718
  if (!(o != null && o.id)) {
1735
- f(null);
1719
+ p(null);
1736
1720
  return;
1737
1721
  }
1738
- b(!0), L(null);
1722
+ y(!0), x(null);
1739
1723
  try {
1740
- const x = await I.getTenantSubscriptionFeatures(o.id);
1741
- f(x);
1742
- } catch (x) {
1743
- const h = x instanceof Error ? x.message : "Failed to fetch subscription";
1744
- L(h), n.onError && n.onError(x instanceof Error ? x : new Error(h));
1724
+ const P = await N.getTenantSubscriptionFeatures(o.id);
1725
+ p(P);
1726
+ } catch (P) {
1727
+ const u = P instanceof Error ? P.message : "Failed to fetch subscription";
1728
+ x(u), n.onError && n.onError(P instanceof Error ? P : new Error(u));
1745
1729
  } finally {
1746
- b(!1);
1730
+ y(!1);
1747
1731
  }
1748
1732
  };
1749
1733
  re(() => {
1750
- if (!i || (M().finally(() => R(!0)), !n.refreshInterval)) return;
1751
- const x = n.refreshInterval || 10 * 60 * 1e3, h = setInterval(M, x);
1752
- return () => clearInterval(h);
1734
+ if (!i || (D().finally(() => R(!0)), !n.refreshInterval)) return;
1735
+ const P = n.refreshInterval || 10 * 60 * 1e3, u = setInterval(D, P);
1736
+ return () => clearInterval(u);
1753
1737
  }, [o == null ? void 0 : o.id, i, n.refreshInterval]);
1754
1738
  const E = K(() => {
1755
- const x = (a == null ? void 0 : a.features) || [], h = (l) => {
1756
- const H = x.find((P) => P.key === l);
1757
- return H ? H.type === "BOOLEAN" || H.type === "boolean" ? H.value === !0 : !!H.value : !1;
1758
- }, A = (l) => x.find((H) => H.key === l), w = (l, H) => {
1759
- const P = x.find((D) => D.key === l);
1760
- return P ? P.value : H;
1761
- }, v = (l) => !a || !a.isActive ? !1 : l.includes(a.planId), N = async () => {
1762
- await M();
1763
- }, B = !!i && (p || !(o != null && o.id));
1739
+ const P = (a == null ? void 0 : a.features) || [], u = (l) => {
1740
+ const U = P.find((b) => b.key === l);
1741
+ return U ? U.type === "BOOLEAN" || U.type === "boolean" ? U.value === !0 : !!U.value : !1;
1742
+ }, S = (l) => P.find((U) => U.key === l), C = (l, U) => {
1743
+ const b = P.find((L) => L.key === l);
1744
+ return b ? b.value : U;
1745
+ }, M = (l) => !a || !a.isActive ? !1 : l.includes(a.planId), T = async () => {
1746
+ await D();
1747
+ }, $ = !!i && (h || !(o != null && o.id));
1764
1748
  return {
1765
1749
  subscription: a,
1766
- features: x,
1767
- loading: m,
1768
- error: c,
1769
- isReady: B,
1770
- isFeatureEnabled: h,
1771
- getFeature: A,
1772
- getFeatureValue: w,
1773
- hasAllowedPlan: v,
1774
- refresh: N
1750
+ features: P,
1751
+ loading: w,
1752
+ error: f,
1753
+ isReady: $,
1754
+ isFeatureEnabled: u,
1755
+ getFeature: S,
1756
+ getFeatureValue: C,
1757
+ hasAllowedPlan: M,
1758
+ refresh: T
1775
1759
  };
1776
- }, [a, m, c, i, o == null ? void 0 : o.id, p]);
1777
- return /* @__PURE__ */ s(Ue.Provider, { value: E, children: e });
1760
+ }, [a, w, f, i, o == null ? void 0 : o.id, h]);
1761
+ return /* @__PURE__ */ s($e.Provider, { value: E, children: e });
1778
1762
  }
1779
- function Et() {
1780
- const n = ae(Ue);
1763
+ function It() {
1764
+ const n = ae($e);
1781
1765
  if (n === void 0)
1782
1766
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1783
1767
  return n;
1784
1768
  }
1785
1769
  function Ze() {
1786
- return ae(Ue) ?? null;
1770
+ return ae($e) ?? null;
1787
1771
  }
1788
1772
  var oe = /* @__PURE__ */ ((n) => (n.SUPERUSER = "SUPERUSER", n.TENANT_ADMIN = "TENANT_ADMIN", n.USER = "USER", n))(oe || {});
1789
- const $e = {
1773
+ const Ue = {
1790
1774
  publicGuest: "/",
1791
1775
  publicUser: "/account",
1792
1776
  publicAdmin: "/admin",
@@ -1811,11 +1795,11 @@ const $e = {
1811
1795
  admin: { tenant: "required", auth: "required", userType: oe.TENANT_ADMIN },
1812
1796
  // Fully open
1813
1797
  open: { tenant: "optional", auth: "optional" }
1814
- }, He = pe(null);
1815
- function kr({ config: n = {}, children: e }) {
1798
+ }, He = fe(null);
1799
+ function xr({ config: n = {}, children: e }) {
1816
1800
  const t = K(() => {
1817
1801
  const r = {
1818
- ...$e,
1802
+ ...Ue,
1819
1803
  ...n.zoneRoots
1820
1804
  }, i = {
1821
1805
  ...Je,
@@ -1833,7 +1817,7 @@ function kr({ config: n = {}, children: e }) {
1833
1817
  }, [n]);
1834
1818
  return /* @__PURE__ */ s(He.Provider, { value: t, children: e });
1835
1819
  }
1836
- function xr() {
1820
+ function Ar() {
1837
1821
  const n = ae(He);
1838
1822
  if (!n)
1839
1823
  throw new Error("useRouting must be used within a RoutingProvider");
@@ -1842,7 +1826,7 @@ function xr() {
1842
1826
  function Mt() {
1843
1827
  const n = ae(He);
1844
1828
  return n || {
1845
- zoneRoots: $e,
1829
+ zoneRoots: Ue,
1846
1830
  presets: Je,
1847
1831
  loadingFallback: null,
1848
1832
  accessDeniedFallback: null,
@@ -1851,7 +1835,7 @@ function Mt() {
1851
1835
  returnToStorage: "url"
1852
1836
  };
1853
1837
  }
1854
- const We = () => /* @__PURE__ */ u(
1838
+ const We = () => /* @__PURE__ */ d(
1855
1839
  "div",
1856
1840
  {
1857
1841
  style: {
@@ -1892,7 +1876,7 @@ const We = () => /* @__PURE__ */ u(
1892
1876
  userType: n,
1893
1877
  minUserType: e,
1894
1878
  missingPermissions: t
1895
- }) => /* @__PURE__ */ u(
1879
+ }) => /* @__PURE__ */ d(
1896
1880
  "div",
1897
1881
  {
1898
1882
  style: {
@@ -1910,19 +1894,19 @@ const We = () => /* @__PURE__ */ u(
1910
1894
  children: [
1911
1895
  /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1912
1896
  /* @__PURE__ */ s("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1913
- e && n ? /* @__PURE__ */ u(_, { children: [
1914
- /* @__PURE__ */ u("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1897
+ e && n ? /* @__PURE__ */ d(_, { children: [
1898
+ /* @__PURE__ */ d("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1915
1899
  "This content requires ",
1916
1900
  /* @__PURE__ */ s("strong", { children: e }),
1917
1901
  " access level or higher."
1918
1902
  ] }),
1919
- /* @__PURE__ */ u("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1903
+ /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1920
1904
  "Your current access level: ",
1921
1905
  /* @__PURE__ */ s("strong", { children: n })
1922
1906
  ] })
1923
- ] }) : /* @__PURE__ */ u(_, { children: [
1907
+ ] }) : /* @__PURE__ */ d(_, { children: [
1924
1908
  /* @__PURE__ */ s("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1925
- t && t.length > 0 && /* @__PURE__ */ u("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1909
+ t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1926
1910
  "Required permissions: ",
1927
1911
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
1928
1912
  ] })
@@ -1937,28 +1921,28 @@ const We = () => /* @__PURE__ */ u(
1937
1921
  };
1938
1922
  return t[n] >= t[e];
1939
1923
  };
1940
- function Ar({
1924
+ function Pr({
1941
1925
  children: n,
1942
1926
  fallback: e,
1943
1927
  minUserType: t,
1944
1928
  requiredPermissions: r,
1945
1929
  requireAllPermissions: i = !1
1946
1930
  }) {
1947
- const { hasValidSession: o, sessionManager: a, hasPermission: f, hasAnyPermission: m, hasAllPermissions: b } = ue();
1931
+ const { hasValidSession: o, sessionManager: a, hasPermission: p, hasAnyPermission: w, hasAllPermissions: y } = ue();
1948
1932
  if (!o())
1949
1933
  return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(We, {}) });
1950
- const c = a.getUser();
1951
- if (!c)
1934
+ const f = a.getUser();
1935
+ if (!f)
1952
1936
  return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(We, {}) });
1953
- if (t && !Lt(c.userType, t))
1954
- return /* @__PURE__ */ s(Ve, { userType: c.userType, minUserType: t });
1955
- if (r && r.length > 0 && !(i ? b(r) : m(r))) {
1956
- const p = r.filter((R) => !f(R)).map((R) => typeof R == "string" ? R : R.name);
1957
- return /* @__PURE__ */ s(Ve, { missingPermissions: p });
1937
+ if (t && !Lt(f.userType, t))
1938
+ return /* @__PURE__ */ s(Ve, { userType: f.userType, minUserType: t });
1939
+ if (r && r.length > 0 && !(i ? y(r) : w(r))) {
1940
+ const h = r.filter((R) => !p(R)).map((R) => typeof R == "string" ? R : R.name);
1941
+ return /* @__PURE__ */ s(Ve, { missingPermissions: h });
1958
1942
  }
1959
1943
  return /* @__PURE__ */ s(_, { children: n });
1960
1944
  }
1961
- const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
1945
+ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1962
1946
  "div",
1963
1947
  {
1964
1948
  style: {
@@ -1971,7 +1955,7 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
1971
1955
  backgroundColor: "#f9fafb",
1972
1956
  textAlign: "center"
1973
1957
  },
1974
- children: /* @__PURE__ */ u(
1958
+ children: /* @__PURE__ */ d(
1975
1959
  "div",
1976
1960
  {
1977
1961
  style: {
@@ -1985,7 +1969,7 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
1985
1969
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1986
1970
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1987
1971
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1988
- /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1972
+ /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1989
1973
  "Redirecting to ",
1990
1974
  n,
1991
1975
  "..."
@@ -2011,7 +1995,7 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2011
1995
  backgroundColor: "#f9fafb",
2012
1996
  textAlign: "center"
2013
1997
  },
2014
- children: /* @__PURE__ */ u(
1998
+ children: /* @__PURE__ */ d(
2015
1999
  "div",
2016
2000
  {
2017
2001
  style: {
@@ -2024,19 +2008,19 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2024
2008
  children: [
2025
2009
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
2026
2010
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
2027
- e && n ? /* @__PURE__ */ u(_, { children: [
2028
- /* @__PURE__ */ u("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
2011
+ e && n ? /* @__PURE__ */ d(_, { children: [
2012
+ /* @__PURE__ */ d("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
2029
2013
  "This page requires ",
2030
2014
  /* @__PURE__ */ s("strong", { children: e }),
2031
2015
  " access."
2032
2016
  ] }),
2033
- /* @__PURE__ */ u("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2017
+ /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2034
2018
  "Your current user type: ",
2035
2019
  /* @__PURE__ */ s("strong", { children: n })
2036
2020
  ] })
2037
- ] }) : /* @__PURE__ */ u(_, { children: [
2021
+ ] }) : /* @__PURE__ */ d(_, { children: [
2038
2022
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
2039
- t && t.length > 0 && /* @__PURE__ */ u("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2023
+ t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2040
2024
  "Required permissions: ",
2041
2025
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
2042
2026
  ] })
@@ -2045,8 +2029,8 @@ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2045
2029
  }
2046
2030
  )
2047
2031
  }
2048
- ), Nt = (n, e) => n === e;
2049
- function Pr({
2032
+ ), Dt = (n, e) => n === e;
2033
+ function Rr({
2050
2034
  children: n,
2051
2035
  redirectTo: e = "/login",
2052
2036
  requiredUserType: t,
@@ -2054,34 +2038,34 @@ function Pr({
2054
2038
  requireAllPermissions: i = !1,
2055
2039
  fallback: o
2056
2040
  }) {
2057
- const { hasValidSession: a, sessionManager: f, hasPermission: m, hasAnyPermission: b, hasAllPermissions: c } = ue(), L = ke();
2041
+ const { hasValidSession: a, sessionManager: p, hasPermission: w, hasAnyPermission: y, hasAllPermissions: f } = ue(), x = ke();
2058
2042
  if (re(() => {
2059
2043
  process.env.NODE_ENV === "development" && console.warn(
2060
2044
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
2061
2045
  );
2062
2046
  }, []), !a())
2063
- return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ u(_, { children: [
2064
- /* @__PURE__ */ s(Ft, { redirectPath: e }),
2065
- /* @__PURE__ */ s(Se, { to: e, state: { from: L.pathname }, replace: !0 })
2047
+ return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ d(_, { children: [
2048
+ /* @__PURE__ */ s(Nt, { redirectPath: e }),
2049
+ /* @__PURE__ */ s(ve, { to: e, state: { from: x.pathname }, replace: !0 })
2066
2050
  ] });
2067
- const p = f.getUser();
2068
- if (!p)
2069
- return /* @__PURE__ */ s(Se, { to: e, state: { from: L.pathname }, replace: !0 });
2070
- if (t && !Nt(p.userType, t))
2051
+ const h = p.getUser();
2052
+ if (!h)
2053
+ return /* @__PURE__ */ s(ve, { to: e, state: { from: x.pathname }, replace: !0 });
2054
+ if (t && !Dt(h.userType, t))
2071
2055
  return /* @__PURE__ */ s(
2072
2056
  je,
2073
2057
  {
2074
- userType: p.userType,
2058
+ userType: h.userType,
2075
2059
  requiredUserType: t
2076
2060
  }
2077
2061
  );
2078
- if (r && r.length > 0 && !(i ? c(r) : b(r))) {
2079
- const I = r.filter((M) => !m(M)).map((M) => typeof M == "string" ? M : M.name);
2080
- return /* @__PURE__ */ s(je, { missingPermissions: I });
2062
+ if (r && r.length > 0 && !(i ? f(r) : y(r))) {
2063
+ const N = r.filter((D) => !w(D)).map((D) => typeof D == "string" ? D : D.name);
2064
+ return /* @__PURE__ */ s(je, { missingPermissions: N });
2081
2065
  }
2082
2066
  return /* @__PURE__ */ s(_, { children: n });
2083
2067
  }
2084
- const Dt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2068
+ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
2085
2069
  "div",
2086
2070
  {
2087
2071
  style: {
@@ -2094,7 +2078,7 @@ const Dt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2094
2078
  backgroundColor: "#f9fafb",
2095
2079
  textAlign: "center"
2096
2080
  },
2097
- children: /* @__PURE__ */ u(
2081
+ children: /* @__PURE__ */ d(
2098
2082
  "div",
2099
2083
  {
2100
2084
  style: {
@@ -2108,7 +2092,7 @@ const Dt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2108
2092
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
2109
2093
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
2110
2094
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
2111
- /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2095
+ /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2112
2096
  "Redirecting to ",
2113
2097
  n,
2114
2098
  "..."
@@ -2118,15 +2102,15 @@ const Dt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2118
2102
  )
2119
2103
  }
2120
2104
  );
2121
- function Rr({ children: n, redirectTo: e = "/", fallback: t }) {
2105
+ function Er({ children: n, redirectTo: e = "/", fallback: t }) {
2122
2106
  const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2123
2107
  return re(() => {
2124
2108
  process.env.NODE_ENV === "development" && console.warn(
2125
2109
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
2126
2110
  );
2127
- }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ u(_, { children: [
2128
- /* @__PURE__ */ s(Dt, { redirectPath: e }),
2129
- /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2111
+ }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2112
+ /* @__PURE__ */ s(Ft, { redirectPath: e }),
2113
+ /* @__PURE__ */ s(ve, { to: e, state: { from: a.pathname }, replace: !0 })
2130
2114
  ] });
2131
2115
  }
2132
2116
  const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
@@ -2142,7 +2126,7 @@ const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
2142
2126
  backgroundColor: "#f9fafb",
2143
2127
  textAlign: "center"
2144
2128
  },
2145
- children: /* @__PURE__ */ u(
2129
+ children: /* @__PURE__ */ d(
2146
2130
  "div",
2147
2131
  {
2148
2132
  style: {
@@ -2156,7 +2140,7 @@ const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
2156
2140
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
2157
2141
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
2158
2142
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
2159
- /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2143
+ /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2160
2144
  "Redirecting to ",
2161
2145
  n,
2162
2146
  "..."
@@ -2172,19 +2156,19 @@ function Ir({ children: n, redirectTo: e = "/dashboard", fallback: t }) {
2172
2156
  process.env.NODE_ENV === "development" && console.warn(
2173
2157
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
2174
2158
  );
2175
- }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ u(_, { children: [
2159
+ }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2176
2160
  /* @__PURE__ */ s(Ct, { redirectPath: e }),
2177
- /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2161
+ /* @__PURE__ */ s(ve, { to: e, state: { from: a.pathname }, replace: !0 })
2178
2162
  ] }) : /* @__PURE__ */ s(_, { children: n });
2179
2163
  }
2180
- function Ut(n, e) {
2164
+ function $t(n, e) {
2181
2165
  return e ? n ? Array.isArray(e) ? e.includes(n) : n === e : !1 : !0;
2182
2166
  }
2183
2167
  function Ge(n, e) {
2184
2168
  return !n || n === "optional" ? "skip" : n === "required" ? e ? "pass" : "fail" : n === "forbidden" ? e ? "fail" : "pass" : "skip";
2185
2169
  }
2186
- function $t(n, e) {
2187
- return Ge(n.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Ge(n.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : n.userType && e.isAuthenticated && !Ut(e.userType, n.userType) ? "wrong_user_type" : n.permissions && n.permissions.length > 0 && !(n.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(n.permissions) ? "missing_permissions" : null;
2170
+ function Ut(n, e) {
2171
+ return Ge(n.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Ge(n.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : n.userType && e.isAuthenticated && !$t(e.userType, n.userType) ? "wrong_user_type" : n.permissions && n.permissions.length > 0 && !(n.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(n.permissions) ? "missing_permissions" : null;
2188
2172
  }
2189
2173
  function Ht(n, e) {
2190
2174
  return n.hasTenant ? n.isAuthenticated ? n.userType === oe.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : n.isAuthenticated ? n.userType === oe.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
@@ -2195,7 +2179,7 @@ function Bt(n, e, t, r, i) {
2195
2179
  const o = typeof e == "string" ? e : t, a = n.includes("?") ? "&" : "?";
2196
2180
  return `${n}${a}${r}=${encodeURIComponent(o)}`;
2197
2181
  }
2198
- function qt(n, e, t) {
2182
+ function Ot(n, e, t) {
2199
2183
  if (!n || t === "url") return;
2200
2184
  const r = typeof n == "string" ? n : e, i = "zone_return_to";
2201
2185
  t === "session" ? sessionStorage.setItem(i, r) : t === "local" && localStorage.setItem(i, r);
@@ -2208,83 +2192,83 @@ const ce = ({
2208
2192
  userType: i,
2209
2193
  requiredPermissions: o,
2210
2194
  requireAllPermissions: a = !0,
2211
- returnTo: f,
2212
- onAccessDenied: m,
2213
- redirectTo: b,
2214
- loadingFallback: c,
2215
- accessDeniedFallback: L
2195
+ returnTo: p,
2196
+ onAccessDenied: w,
2197
+ redirectTo: y,
2198
+ loadingFallback: f,
2199
+ accessDeniedFallback: x
2216
2200
  }) => {
2217
- const p = ke(), { isAuthenticated: R, isAuthInitializing: I, currentUser: M, userPermissions: E } = ue(), { tenant: x, isTenantLoading: h } = ge(), A = Mt(), w = K(() => {
2201
+ const h = ke(), { isAuthenticated: R, isAuthInitializing: N, currentUser: D, userPermissions: E } = ue(), { tenant: P, isTenantLoading: u } = ge(), S = Mt(), C = K(() => {
2218
2202
  if (e)
2219
- return A.presets[e];
2220
- }, [e, A.presets]), v = K(
2203
+ return S.presets[e];
2204
+ }, [e, S.presets]), M = K(
2221
2205
  () => ({
2222
- tenant: t ?? (w == null ? void 0 : w.tenant),
2223
- auth: r ?? (w == null ? void 0 : w.auth),
2224
- userType: i ?? (w == null ? void 0 : w.userType),
2225
- permissions: o ?? (w == null ? void 0 : w.requiredPermissions),
2206
+ tenant: t ?? (C == null ? void 0 : C.tenant),
2207
+ auth: r ?? (C == null ? void 0 : C.auth),
2208
+ userType: i ?? (C == null ? void 0 : C.userType),
2209
+ permissions: o ?? (C == null ? void 0 : C.requiredPermissions),
2226
2210
  requireAllPermissions: a
2227
2211
  }),
2228
- [t, r, i, o, w, a]
2229
- ), N = K(
2212
+ [t, r, i, o, C, a]
2213
+ ), T = K(
2230
2214
  () => ({
2231
- hasTenant: !!x,
2215
+ hasTenant: !!P,
2232
2216
  isAuthenticated: R,
2233
- userType: M == null ? void 0 : M.userType,
2217
+ userType: D == null ? void 0 : D.userType,
2234
2218
  permissions: E,
2235
- isLoading: I || h
2219
+ isLoading: N || u
2236
2220
  }),
2237
2221
  [
2238
- x,
2222
+ P,
2239
2223
  R,
2240
- M == null ? void 0 : M.userType,
2224
+ D == null ? void 0 : D.userType,
2241
2225
  E,
2242
- I,
2243
- h
2226
+ N,
2227
+ u
2244
2228
  ]
2245
- ), B = K(() => N.isLoading ? null : $t(v, N), [v, N]), l = K(() => B ? b || Ht(N, A.zoneRoots) : null, [B, b, N, A.zoneRoots]), H = K(() => !B || !l ? null : {
2246
- type: B,
2229
+ ), $ = K(() => T.isLoading ? null : Ut(M, T), [M, T]), l = K(() => $ ? y || Ht(T, S.zoneRoots) : null, [$, y, T, S.zoneRoots]), U = K(() => !$ || !l ? null : {
2230
+ type: $,
2247
2231
  required: {
2248
- tenant: v.tenant,
2249
- auth: v.auth,
2250
- userType: v.userType,
2251
- permissions: v.permissions
2232
+ tenant: M.tenant,
2233
+ auth: M.auth,
2234
+ userType: M.userType,
2235
+ permissions: M.permissions
2252
2236
  },
2253
2237
  current: {
2254
- hasTenant: N.hasTenant,
2255
- isAuthenticated: N.isAuthenticated,
2256
- userType: N.userType,
2257
- permissions: N.permissions
2238
+ hasTenant: T.hasTenant,
2239
+ isAuthenticated: T.isAuthenticated,
2240
+ userType: T.userType,
2241
+ permissions: T.permissions
2258
2242
  },
2259
2243
  redirectTo: l
2260
- }, [B, l, v, N]);
2244
+ }, [$, l, M, T]);
2261
2245
  if (re(() => {
2262
- H && (m ? m(H) : A.onAccessDenied && A.onAccessDenied(H));
2263
- }, [H, m, A]), re(() => {
2264
- H && f && qt(f, p.pathname + p.search, A.returnToStorage);
2246
+ U && (w ? w(U) : S.onAccessDenied && S.onAccessDenied(U));
2247
+ }, [U, w, S]), re(() => {
2248
+ U && p && Ot(p, h.pathname + h.search, S.returnToStorage);
2265
2249
  }, [
2266
- H,
2267
- f,
2268
- p.pathname,
2269
- p.search,
2270
- A.returnToStorage
2271
- ]), N.isLoading)
2272
- return /* @__PURE__ */ s(_, { children: c ?? A.loadingFallback ?? null });
2273
- if (H && l) {
2274
- const P = L ?? A.accessDeniedFallback;
2275
- if (P)
2276
- return /* @__PURE__ */ s(_, { children: P });
2277
- const D = Bt(
2250
+ U,
2251
+ p,
2252
+ h.pathname,
2253
+ h.search,
2254
+ S.returnToStorage
2255
+ ]), T.isLoading)
2256
+ return /* @__PURE__ */ s(_, { children: f ?? S.loadingFallback ?? null });
2257
+ if (U && l) {
2258
+ const b = x ?? S.accessDeniedFallback;
2259
+ if (b)
2260
+ return /* @__PURE__ */ s(_, { children: b });
2261
+ const L = Bt(
2278
2262
  l,
2279
- f,
2280
- p.pathname + p.search,
2281
- A.returnToParam,
2282
- A.returnToStorage
2263
+ p,
2264
+ h.pathname + h.search,
2265
+ S.returnToParam,
2266
+ S.returnToStorage
2283
2267
  );
2284
- return /* @__PURE__ */ s(Se, { to: D, replace: !0 });
2268
+ return /* @__PURE__ */ s(ve, { to: L, replace: !0 });
2285
2269
  }
2286
2270
  return /* @__PURE__ */ s(_, { children: n });
2287
- }, Er = (n) => /* @__PURE__ */ s(ce, { tenant: "required", ...n }), Mr = (n) => /* @__PURE__ */ s(ce, { tenant: "forbidden", ...n }), Lr = (n) => /* @__PURE__ */ s(ce, { auth: "required", ...n }), Fr = (n) => /* @__PURE__ */ s(ce, { auth: "forbidden", ...n }), Nr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.TENANT_ADMIN, ...n }), Dr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.USER, ...n }), Cr = (n) => /* @__PURE__ */ s(ce, { tenant: "optional", auth: "optional", ...n }), Ur = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "required", ...n }), $r = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "optional", ...n }), Hr = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "forbidden", ...n }), Ot = () => /* @__PURE__ */ u(
2271
+ }, Mr = (n) => /* @__PURE__ */ s(ce, { tenant: "required", ...n }), Lr = (n) => /* @__PURE__ */ s(ce, { tenant: "forbidden", ...n }), Nr = (n) => /* @__PURE__ */ s(ce, { auth: "required", ...n }), Dr = (n) => /* @__PURE__ */ s(ce, { auth: "forbidden", ...n }), Fr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.TENANT_ADMIN, ...n }), Cr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.USER, ...n }), $r = (n) => /* @__PURE__ */ s(ce, { tenant: "optional", auth: "optional", ...n }), Ur = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "required", ...n }), Hr = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "optional", ...n }), Br = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "forbidden", ...n }), qt = () => /* @__PURE__ */ d(
2288
2272
  "div",
2289
2273
  {
2290
2274
  style: {
@@ -2301,14 +2285,14 @@ const ce = ({
2301
2285
  ]
2302
2286
  }
2303
2287
  );
2304
- function Br({
2288
+ function Or({
2305
2289
  children: n,
2306
- fallback: e = /* @__PURE__ */ s(Ot, {}),
2290
+ fallback: e = /* @__PURE__ */ s(qt, {}),
2307
2291
  allowedPlans: t,
2308
2292
  requiredFeature: r
2309
2293
  }) {
2310
- const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: f } = Et();
2311
- return f ? /* @__PURE__ */ s(
2294
+ const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: p } = It();
2295
+ return p ? /* @__PURE__ */ s(
2312
2296
  "div",
2313
2297
  {
2314
2298
  style: {
@@ -2320,7 +2304,7 @@ function Br({
2320
2304
  }
2321
2305
  ) : i ? i.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ s(_, { children: e }) : r && !a(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: n }) : /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: e });
2322
2306
  }
2323
- const zt = ({ flagName: n }) => /* @__PURE__ */ u(
2307
+ const zt = ({ flagName: n }) => /* @__PURE__ */ d(
2324
2308
  "div",
2325
2309
  {
2326
2310
  style: {
@@ -2339,7 +2323,7 @@ const zt = ({ flagName: n }) => /* @__PURE__ */ u(
2339
2323
  children: [
2340
2324
  /* @__PURE__ */ s("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
2341
2325
  /* @__PURE__ */ s("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
2342
- /* @__PURE__ */ u("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2326
+ /* @__PURE__ */ d("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2343
2327
  'Feature flag "',
2344
2328
  n,
2345
2329
  '" is disabled'
@@ -2364,7 +2348,7 @@ function qr({ name: n, children: e, fallback: t }) {
2364
2348
  }
2365
2349
  ) : r(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(zt, { flagName: n }) });
2366
2350
  }
2367
- const _t = () => /* @__PURE__ */ u(
2351
+ const _t = () => /* @__PURE__ */ d(
2368
2352
  "svg",
2369
2353
  {
2370
2354
  width: "16",
@@ -2381,7 +2365,7 @@ const _t = () => /* @__PURE__ */ u(
2381
2365
  /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "3" })
2382
2366
  ]
2383
2367
  }
2384
- ), Wt = () => /* @__PURE__ */ u(
2368
+ ), Wt = () => /* @__PURE__ */ d(
2385
2369
  "svg",
2386
2370
  {
2387
2371
  width: "16",
@@ -2414,7 +2398,11 @@ const _t = () => /* @__PURE__ */ u(
2414
2398
  magicLinkText: "Prefer passwordless?",
2415
2399
  magicLinkLink: "Use Magic Link",
2416
2400
  errorMessage: "Invalid credentials",
2417
- loadingText: "Signing in..."
2401
+ loadingText: "Signing in...",
2402
+ tenantNotFoundError: "Tenant not found",
2403
+ dividerBullet: "•",
2404
+ showPasswordAriaLabel: "Show password",
2405
+ hidePasswordAriaLabel: "Hide password"
2418
2406
  }, Gt = {
2419
2407
  container: {
2420
2408
  maxWidth: "400px",
@@ -2520,9 +2508,12 @@ const _t = () => /* @__PURE__ */ u(
2520
2508
  margin: "0.5rem 0",
2521
2509
  color: "#6b7280",
2522
2510
  fontSize: "0.875rem"
2511
+ },
2512
+ inputWithIcon: {
2513
+ paddingRight: "2.5rem"
2523
2514
  }
2524
2515
  };
2525
- function Or({
2516
+ function zr({
2526
2517
  copy: n = {},
2527
2518
  styles: e = {},
2528
2519
  icons: t = {},
@@ -2530,120 +2521,119 @@ function Or({
2530
2521
  onError: i,
2531
2522
  onForgotPassword: o,
2532
2523
  onSignupClick: a,
2533
- onMagicLinkClick: f,
2534
- showForgotPassword: m = !0,
2535
- showSignupLink: b = !0,
2536
- showMagicLinkOption: c = !0,
2537
- className: L
2524
+ onMagicLinkClick: p,
2525
+ showForgotPassword: w = !0,
2526
+ showSignupLink: y = !0,
2527
+ showMagicLinkOption: f = !0,
2528
+ className: x
2538
2529
  }) {
2539
- const [p, R] = k(""), [I, M] = k(""), [E, x] = k(!1), [h, A] = k(!1), [w, v] = k(""), [N, B] = k({}), { login: l } = ue(), { tenant: H } = me(), P = { ...jt, ...n }, D = { ...Gt, ...e }, C = { ...Vt, ...t }, d = () => {
2540
- const g = {};
2541
- return p.trim() || (g.username = !0), I.trim() || (g.password = !0), B(g), Object.keys(g).length === 0;
2542
- }, U = async (g) => {
2543
- if (g.preventDefault(), !!d()) {
2544
- if (!(H != null && H.id)) {
2545
- v("Tenant not found");
2530
+ const [h, R] = k(""), [N, D] = k(""), [E, P] = k(!1), [u, S] = k(!1), [C, M] = k(""), [T, $] = k({}), { login: l } = ue(), { tenant: U } = me(), b = { ...jt, ...n }, L = { ...Gt, ...e }, F = { ...Vt, ...t }, c = () => {
2531
+ const m = {};
2532
+ return h.trim() || (m.username = !0), N.trim() || (m.password = !0), $(m), Object.keys(m).length === 0;
2533
+ }, H = async (m) => {
2534
+ if (m.preventDefault(), !!c()) {
2535
+ if (!(U != null && U.id)) {
2536
+ M(b.tenantNotFoundError);
2546
2537
  return;
2547
2538
  }
2548
- A(!0), v("");
2539
+ S(!0), M("");
2549
2540
  try {
2550
- const S = await l({
2551
- username: p,
2552
- password: I
2541
+ const v = await l({
2542
+ username: h,
2543
+ password: N
2553
2544
  // tenantId inferred from context automatically
2554
2545
  });
2555
- r == null || r(S);
2556
- } catch (S) {
2557
- const Q = S.message || P.errorMessage;
2558
- v(Q), i == null || i(Q);
2546
+ r == null || r(v);
2547
+ } catch (v) {
2548
+ const Q = v.message || b.errorMessage;
2549
+ M(Q), i == null || i(Q);
2559
2550
  } finally {
2560
- A(!1);
2551
+ S(!1);
2561
2552
  }
2562
2553
  }
2563
- }, F = (g) => ({
2564
- ...D.input,
2565
- ...N[g] ? D.inputError : {}
2566
- }), y = () => ({
2567
- ...D.button,
2568
- ...h ? D.buttonLoading : {},
2569
- ...!p || !I || h ? D.buttonDisabled : {}
2554
+ }, I = (m) => ({
2555
+ ...L.input,
2556
+ ...T[m] ? L.inputError : {}
2557
+ }), g = () => ({
2558
+ ...L.button,
2559
+ ...u ? L.buttonLoading : {},
2560
+ ...!h || !N || u ? L.buttonDisabled : {}
2570
2561
  });
2571
- return /* @__PURE__ */ u("div", { className: L, style: D.container, children: [
2572
- /* @__PURE__ */ s("h2", { style: D.title, children: P.title }),
2573
- /* @__PURE__ */ u("form", { onSubmit: U, style: D.form, children: [
2574
- /* @__PURE__ */ u("div", { style: D.fieldGroup, children: [
2575
- /* @__PURE__ */ s("label", { style: D.label, children: P.usernameLabel }),
2562
+ return /* @__PURE__ */ d("div", { className: x, style: L.container, children: [
2563
+ /* @__PURE__ */ s("h2", { style: L.title, children: b.title }),
2564
+ /* @__PURE__ */ d("form", { onSubmit: H, style: L.form, children: [
2565
+ /* @__PURE__ */ d("div", { style: L.fieldGroup, children: [
2566
+ /* @__PURE__ */ s("label", { style: L.label, children: b.usernameLabel }),
2576
2567
  /* @__PURE__ */ s(
2577
2568
  "input",
2578
2569
  {
2579
2570
  id: "username",
2580
2571
  name: "username",
2581
2572
  type: "text",
2582
- value: p,
2583
- onChange: (g) => {
2584
- R(g.target.value), N.username && B((S) => ({ ...S, username: !1 }));
2573
+ value: h,
2574
+ onChange: (m) => {
2575
+ R(m.target.value), T.username && $((v) => ({ ...v, username: !1 }));
2585
2576
  },
2586
- placeholder: P.usernamePlaceholder,
2587
- style: F("username"),
2588
- disabled: h
2577
+ placeholder: b.usernamePlaceholder,
2578
+ style: I("username"),
2579
+ disabled: u
2589
2580
  }
2590
2581
  )
2591
2582
  ] }),
2592
- /* @__PURE__ */ u("div", { style: D.fieldGroup, children: [
2593
- /* @__PURE__ */ s("label", { style: D.label, children: P.passwordLabel }),
2594
- /* @__PURE__ */ u("div", { style: D.inputContainer, children: [
2583
+ /* @__PURE__ */ d("div", { style: L.fieldGroup, children: [
2584
+ /* @__PURE__ */ s("label", { style: L.label, children: b.passwordLabel }),
2585
+ /* @__PURE__ */ d("div", { style: L.inputContainer, children: [
2595
2586
  /* @__PURE__ */ s(
2596
2587
  "input",
2597
2588
  {
2598
2589
  id: "password",
2599
2590
  name: "password",
2600
2591
  type: E ? "text" : "password",
2601
- value: I,
2602
- onChange: (g) => {
2603
- M(g.target.value), N.password && B((S) => ({ ...S, password: !1 }));
2592
+ value: N,
2593
+ onChange: (m) => {
2594
+ D(m.target.value), T.password && $((v) => ({ ...v, password: !1 }));
2604
2595
  },
2605
- placeholder: P.passwordPlaceholder,
2596
+ placeholder: b.passwordPlaceholder,
2606
2597
  style: {
2607
- ...F("password"),
2608
- paddingRight: "2.5rem"
2609
- // Make room for the icon
2598
+ ...I("password"),
2599
+ ...L.inputWithIcon
2610
2600
  },
2611
- disabled: h
2601
+ disabled: u
2612
2602
  }
2613
2603
  ),
2614
2604
  /* @__PURE__ */ s(
2615
2605
  "button",
2616
2606
  {
2617
2607
  type: "button",
2618
- onClick: () => x(!E),
2619
- style: D.passwordToggle,
2620
- disabled: h,
2621
- "aria-label": E ? "Hide password" : "Show password",
2622
- children: E ? C.hidePassword : C.showPassword
2608
+ onClick: () => P(!E),
2609
+ style: L.passwordToggle,
2610
+ disabled: u,
2611
+ "aria-label": E ? b.hidePasswordAriaLabel : b.showPasswordAriaLabel,
2612
+ children: E ? F.hidePassword : F.showPassword
2623
2613
  }
2624
2614
  )
2625
2615
  ] })
2626
2616
  ] }),
2627
- /* @__PURE__ */ s("button", { type: "submit", disabled: !p || !I || h, style: y(), children: h ? P.loadingText : P.submitButton }),
2628
- w && /* @__PURE__ */ s("div", { style: D.errorText, children: w })
2617
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !h || !N || u, style: g(), children: u ? b.loadingText : b.submitButton }),
2618
+ C && /* @__PURE__ */ s("div", { style: L.errorText, children: C })
2629
2619
  ] }),
2630
- (m || b || c) && /* @__PURE__ */ u("div", { style: D.linkContainer, children: [
2631
- c && /* @__PURE__ */ u("div", { children: [
2632
- /* @__PURE__ */ u("span", { style: D.divider, children: [
2633
- P.magicLinkText,
2620
+ (w || y || f) && /* @__PURE__ */ d("div", { style: L.linkContainer, children: [
2621
+ f && /* @__PURE__ */ d("div", { children: [
2622
+ /* @__PURE__ */ d("span", { style: L.divider, children: [
2623
+ b.magicLinkText,
2634
2624
  " "
2635
2625
  ] }),
2636
- /* @__PURE__ */ s("a", { onClick: f, style: D.link, children: P.magicLinkLink })
2626
+ /* @__PURE__ */ s("a", { onClick: p, style: L.link, children: b.magicLinkLink })
2637
2627
  ] }),
2638
- c && (m || b) && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2639
- m && /* @__PURE__ */ s("a", { onClick: o, style: D.link, children: P.forgotPasswordLink }),
2640
- m && b && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2641
- b && /* @__PURE__ */ u("div", { children: [
2642
- /* @__PURE__ */ u("span", { style: D.divider, children: [
2643
- P.signupText,
2628
+ f && (w || y) && /* @__PURE__ */ s("div", { style: L.divider, children: b.dividerBullet }),
2629
+ w && /* @__PURE__ */ s("a", { onClick: o, style: L.link, children: b.forgotPasswordLink }),
2630
+ w && y && /* @__PURE__ */ s("div", { style: L.divider, children: b.dividerBullet }),
2631
+ y && /* @__PURE__ */ d("div", { children: [
2632
+ /* @__PURE__ */ d("span", { style: L.divider, children: [
2633
+ b.signupText,
2644
2634
  " "
2645
2635
  ] }),
2646
- /* @__PURE__ */ s("a", { onClick: a, style: D.link, children: P.signupLink })
2636
+ /* @__PURE__ */ s("a", { onClick: a, style: L.link, children: b.signupLink })
2647
2637
  ] })
2648
2638
  ] })
2649
2639
  ] });
@@ -2673,7 +2663,10 @@ const Qt = {
2673
2663
  loadingText: "Creating account...",
2674
2664
  passwordMismatchError: "Passwords do not match",
2675
2665
  isAdminLabel: "Create new organization",
2676
- isAdminDescription: "Check this if you want to create a new organization"
2666
+ isAdminDescription: "Check this if you want to create a new organization",
2667
+ contactMethodHint: "At least one contact method (email or phone) is required",
2668
+ tenantNotFoundError: "Tenant not found",
2669
+ dividerBullet: "•"
2677
2670
  }, Kt = {
2678
2671
  container: {
2679
2672
  maxWidth: "400px",
@@ -2771,9 +2764,15 @@ const Qt = {
2771
2764
  margin: "0.5rem 0",
2772
2765
  color: "#6b7280",
2773
2766
  fontSize: "0.875rem"
2767
+ },
2768
+ hintText: {
2769
+ fontSize: "0.875rem",
2770
+ color: "#6b7280",
2771
+ textAlign: "center",
2772
+ margin: "0.5rem 0"
2774
2773
  }
2775
2774
  };
2776
- function zr({
2775
+ function _r({
2777
2776
  copy: n = {},
2778
2777
  styles: e = {},
2779
2778
  signupType: t = "user",
@@ -2781,113 +2780,113 @@ function zr({
2781
2780
  onError: i,
2782
2781
  onLoginClick: o,
2783
2782
  onMagicLinkClick: a,
2784
- showLoginLink: f = !0,
2785
- showMagicLinkOption: m = !0,
2786
- className: b
2783
+ showLoginLink: p = !0,
2784
+ showMagicLinkOption: w = !0,
2785
+ className: y
2787
2786
  }) {
2788
- const [c, L] = k(""), [p, R] = k(""), [I, M] = k(""), [E, x] = k(""), [h, A] = k(""), [w, v] = k(""), [N, B] = k(""), [l, H] = k(!1), [P, D] = k(""), [C, d] = k({}), { signup: U, signupTenantAdmin: F } = ue(), { tenant: y } = me(), g = { ...Qt, ...n }, S = { ...Kt, ...e }, Q = () => {
2789
- const T = {};
2790
- return c.trim() || (T.name = !0), !I.trim() && !E.trim() && (T.email = !0, T.phoneNumber = !0), h.trim() || (T.password = !0), w.trim() || (T.confirmPassword = !0), t === "tenant" && !N.trim() && (T.tenantName = !0), d(T), Object.keys(T).length === 0;
2791
- }, J = async (T) => {
2792
- if (T.preventDefault(), !!Q()) {
2793
- if (h !== w) {
2794
- D(g.passwordMismatchError), d({ confirmPassword: !0 });
2787
+ const [f, x] = k(""), [h, R] = k(""), [N, D] = k(""), [E, P] = k(""), [u, S] = k(""), [C, M] = k(""), [T, $] = k(""), [l, U] = k(!1), [b, L] = k(""), [F, c] = k({}), { signup: H, signupTenantAdmin: I } = ue(), { tenant: g } = me(), m = { ...Qt, ...n }, v = { ...Kt, ...e }, Q = () => {
2788
+ const A = {};
2789
+ return f.trim() || (A.name = !0), !N.trim() && !E.trim() && (A.email = !0, A.phoneNumber = !0), u.trim() || (A.password = !0), C.trim() || (A.confirmPassword = !0), t === "tenant" && !T.trim() && (A.tenantName = !0), c(A), Object.keys(A).length === 0;
2790
+ }, J = async (A) => {
2791
+ if (A.preventDefault(), !!Q()) {
2792
+ if (u !== C) {
2793
+ L(m.passwordMismatchError), c({ confirmPassword: !0 });
2795
2794
  return;
2796
2795
  }
2797
- if (t === "user" && !(y != null && y.id)) {
2798
- D("Tenant not found");
2796
+ if (t === "user" && !(g != null && g.id)) {
2797
+ L(m.tenantNotFoundError);
2799
2798
  return;
2800
2799
  }
2801
- H(!0), D("");
2800
+ U(!0), L("");
2802
2801
  try {
2803
2802
  let V;
2804
- t === "tenant" ? V = await F({
2805
- email: I || void 0,
2803
+ t === "tenant" ? V = await I({
2804
+ email: N || void 0,
2806
2805
  phoneNumber: E || void 0,
2807
- name: c,
2808
- password: h,
2809
- tenantName: N,
2810
- lastName: p || void 0
2811
- }) : V = await U({
2812
- email: I || void 0,
2806
+ name: f,
2807
+ password: u,
2808
+ tenantName: T,
2809
+ lastName: h || void 0
2810
+ }) : V = await H({
2811
+ email: N || void 0,
2813
2812
  phoneNumber: E || void 0,
2814
- name: c,
2815
- password: h,
2816
- tenantId: y.id,
2817
- lastName: p || void 0
2813
+ name: f,
2814
+ password: u,
2815
+ tenantId: g.id,
2816
+ lastName: h || void 0
2818
2817
  }), r == null || r(V);
2819
2818
  } catch (V) {
2820
- const de = V.message || g.errorMessage;
2821
- D(de), i == null || i(de);
2819
+ const de = V.message || m.errorMessage;
2820
+ L(de), i == null || i(de);
2822
2821
  } finally {
2823
- H(!1);
2822
+ U(!1);
2824
2823
  }
2825
2824
  }
2826
- }, q = (T) => ({
2827
- ...S.input,
2828
- ...C[T] ? S.inputError : {}
2829
- }), O = () => ({
2830
- ...S.button,
2831
- ...l ? S.buttonLoading : {},
2832
- ...!c || !I && !E || !h || !w || l || t === "tenant" && !N ? S.buttonDisabled : {}
2833
- }), j = c && (I || E) && h && w && (t === "user" || N);
2834
- return /* @__PURE__ */ u("div", { className: b, style: S.container, children: [
2835
- /* @__PURE__ */ s("h2", { style: S.title, children: g.title }),
2836
- /* @__PURE__ */ u("form", { onSubmit: J, style: S.form, children: [
2837
- /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2838
- /* @__PURE__ */ s("label", { style: S.label, children: g.nameLabel }),
2825
+ }, O = (A) => ({
2826
+ ...v.input,
2827
+ ...F[A] ? v.inputError : {}
2828
+ }), q = () => ({
2829
+ ...v.button,
2830
+ ...l ? v.buttonLoading : {},
2831
+ ...!f || !N && !E || !u || !C || l || t === "tenant" && !T ? v.buttonDisabled : {}
2832
+ }), j = f && (N || E) && u && C && (t === "user" || T);
2833
+ return /* @__PURE__ */ d("div", { className: y, style: v.container, children: [
2834
+ /* @__PURE__ */ s("h2", { style: v.title, children: m.title }),
2835
+ /* @__PURE__ */ d("form", { onSubmit: J, style: v.form, children: [
2836
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2837
+ /* @__PURE__ */ s("label", { style: v.label, children: m.nameLabel }),
2839
2838
  /* @__PURE__ */ s(
2840
2839
  "input",
2841
2840
  {
2842
2841
  id: "name",
2843
2842
  name: "name",
2844
2843
  type: "text",
2845
- value: c,
2846
- onChange: (T) => {
2847
- L(T.target.value), C.name && d((V) => ({ ...V, name: !1 }));
2844
+ value: f,
2845
+ onChange: (A) => {
2846
+ x(A.target.value), F.name && c((V) => ({ ...V, name: !1 }));
2848
2847
  },
2849
- placeholder: g.namePlaceholder,
2850
- style: q("name"),
2848
+ placeholder: m.namePlaceholder,
2849
+ style: O("name"),
2851
2850
  disabled: l
2852
2851
  }
2853
2852
  )
2854
2853
  ] }),
2855
- /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2856
- /* @__PURE__ */ s("label", { style: S.label, children: g.lastNameLabel }),
2854
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2855
+ /* @__PURE__ */ s("label", { style: v.label, children: m.lastNameLabel }),
2857
2856
  /* @__PURE__ */ s(
2858
2857
  "input",
2859
2858
  {
2860
2859
  id: "lastName",
2861
2860
  name: "lastName",
2862
2861
  type: "text",
2863
- value: p,
2864
- onChange: (T) => R(T.target.value),
2865
- placeholder: g.lastNamePlaceholder,
2866
- style: S.input,
2862
+ value: h,
2863
+ onChange: (A) => R(A.target.value),
2864
+ placeholder: m.lastNamePlaceholder,
2865
+ style: v.input,
2867
2866
  disabled: l
2868
2867
  }
2869
2868
  )
2870
2869
  ] }),
2871
- /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2872
- /* @__PURE__ */ s("label", { style: S.label, children: g.emailLabel }),
2870
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2871
+ /* @__PURE__ */ s("label", { style: v.label, children: m.emailLabel }),
2873
2872
  /* @__PURE__ */ s(
2874
2873
  "input",
2875
2874
  {
2876
2875
  id: "email",
2877
2876
  name: "email",
2878
2877
  type: "email",
2879
- value: I,
2880
- onChange: (T) => {
2881
- M(T.target.value), C.email && d((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2878
+ value: N,
2879
+ onChange: (A) => {
2880
+ D(A.target.value), F.email && c((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2882
2881
  },
2883
- placeholder: g.emailPlaceholder,
2884
- style: q("email"),
2882
+ placeholder: m.emailPlaceholder,
2883
+ style: O("email"),
2885
2884
  disabled: l
2886
2885
  }
2887
2886
  )
2888
2887
  ] }),
2889
- /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2890
- /* @__PURE__ */ s("label", { style: S.label, children: g.phoneNumberLabel }),
2888
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2889
+ /* @__PURE__ */ s("label", { style: v.label, children: m.phoneNumberLabel }),
2891
2890
  /* @__PURE__ */ s(
2892
2891
  "input",
2893
2892
  {
@@ -2895,99 +2894,88 @@ function zr({
2895
2894
  name: "phoneNumber",
2896
2895
  type: "tel",
2897
2896
  value: E,
2898
- onChange: (T) => {
2899
- x(T.target.value), C.phoneNumber && d((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2897
+ onChange: (A) => {
2898
+ P(A.target.value), F.phoneNumber && c((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2900
2899
  },
2901
- placeholder: g.phoneNumberPlaceholder,
2902
- style: q("phoneNumber"),
2900
+ placeholder: m.phoneNumberPlaceholder,
2901
+ style: O("phoneNumber"),
2903
2902
  disabled: l
2904
2903
  }
2905
2904
  )
2906
2905
  ] }),
2907
- /* @__PURE__ */ s(
2908
- "div",
2909
- {
2910
- style: {
2911
- fontSize: "0.875rem",
2912
- color: "#6b7280",
2913
- textAlign: "center",
2914
- margin: "0.5rem 0"
2915
- },
2916
- children: "At least one contact method (email or phone) is required"
2917
- }
2918
- ),
2919
- /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2920
- /* @__PURE__ */ s("label", { style: S.label, children: g.passwordLabel }),
2906
+ /* @__PURE__ */ s("div", { style: v.hintText, children: m.contactMethodHint }),
2907
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2908
+ /* @__PURE__ */ s("label", { style: v.label, children: m.passwordLabel }),
2921
2909
  /* @__PURE__ */ s(
2922
2910
  "input",
2923
2911
  {
2924
2912
  id: "password",
2925
2913
  name: "password",
2926
2914
  type: "password",
2927
- value: h,
2928
- onChange: (T) => {
2929
- A(T.target.value), C.password && d((V) => ({ ...V, password: !1 }));
2915
+ value: u,
2916
+ onChange: (A) => {
2917
+ S(A.target.value), F.password && c((V) => ({ ...V, password: !1 }));
2930
2918
  },
2931
- placeholder: g.passwordPlaceholder,
2932
- style: q("password"),
2919
+ placeholder: m.passwordPlaceholder,
2920
+ style: O("password"),
2933
2921
  disabled: l
2934
2922
  }
2935
2923
  )
2936
2924
  ] }),
2937
- /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2938
- /* @__PURE__ */ s("label", { style: S.label, children: g.confirmPasswordLabel }),
2925
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2926
+ /* @__PURE__ */ s("label", { style: v.label, children: m.confirmPasswordLabel }),
2939
2927
  /* @__PURE__ */ s(
2940
2928
  "input",
2941
2929
  {
2942
2930
  id: "confirmPassword",
2943
2931
  name: "confirmPassword",
2944
2932
  type: "password",
2945
- value: w,
2946
- onChange: (T) => {
2947
- v(T.target.value), C.confirmPassword && d((V) => ({ ...V, confirmPassword: !1 })), P === g.passwordMismatchError && D("");
2933
+ value: C,
2934
+ onChange: (A) => {
2935
+ M(A.target.value), F.confirmPassword && c((V) => ({ ...V, confirmPassword: !1 })), b === m.passwordMismatchError && L("");
2948
2936
  },
2949
- placeholder: g.confirmPasswordPlaceholder,
2950
- style: q("confirmPassword"),
2937
+ placeholder: m.confirmPasswordPlaceholder,
2938
+ style: O("confirmPassword"),
2951
2939
  disabled: l
2952
2940
  }
2953
2941
  )
2954
2942
  ] }),
2955
- t === "tenant" && /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2956
- /* @__PURE__ */ s("label", { style: S.label, children: g.tenantNameLabel }),
2943
+ t === "tenant" && /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2944
+ /* @__PURE__ */ s("label", { style: v.label, children: m.tenantNameLabel }),
2957
2945
  /* @__PURE__ */ s(
2958
2946
  "input",
2959
2947
  {
2960
2948
  id: "tenantName",
2961
2949
  name: "tenantName",
2962
2950
  type: "text",
2963
- value: N,
2964
- onChange: (T) => {
2965
- B(T.target.value), C.tenantName && d((V) => ({ ...V, tenantName: !1 }));
2951
+ value: T,
2952
+ onChange: (A) => {
2953
+ $(A.target.value), F.tenantName && c((V) => ({ ...V, tenantName: !1 }));
2966
2954
  },
2967
- placeholder: g.tenantNamePlaceholder,
2968
- style: q("tenantName"),
2955
+ placeholder: m.tenantNamePlaceholder,
2956
+ style: O("tenantName"),
2969
2957
  disabled: l
2970
2958
  }
2971
2959
  )
2972
2960
  ] }),
2973
- /* @__PURE__ */ s("button", { type: "submit", disabled: !j || l, style: O(), children: l ? g.loadingText : g.submitButton }),
2974
- P && /* @__PURE__ */ s("div", { style: S.errorText, children: P })
2961
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !j || l, style: q(), children: l ? m.loadingText : m.submitButton }),
2962
+ b && /* @__PURE__ */ s("div", { style: v.errorText, children: b })
2975
2963
  ] }),
2976
- (f || m) && /* @__PURE__ */ u("div", { style: S.linkContainer, children: [
2977
- m && /* @__PURE__ */ u("div", { children: [
2978
- /* @__PURE__ */ u("span", { style: S.divider, children: [
2979
- g.magicLinkText,
2964
+ (p || w) && /* @__PURE__ */ d("div", { style: v.linkContainer, children: [
2965
+ w && /* @__PURE__ */ d("div", { children: [
2966
+ /* @__PURE__ */ d("span", { style: v.divider, children: [
2967
+ m.magicLinkText,
2980
2968
  " "
2981
2969
  ] }),
2982
- /* @__PURE__ */ s("a", { onClick: a, style: S.link, children: g.magicLinkLink })
2970
+ /* @__PURE__ */ s("a", { onClick: a, style: v.link, children: m.magicLinkLink })
2983
2971
  ] }),
2984
- m && f && /* @__PURE__ */ s("div", { style: S.divider, children: "•" }),
2985
- f && /* @__PURE__ */ u("div", { children: [
2986
- /* @__PURE__ */ u("span", { style: S.divider, children: [
2987
- g.loginText,
2972
+ w && p && /* @__PURE__ */ s("div", { style: v.divider, children: m.dividerBullet }),
2973
+ p && /* @__PURE__ */ d("div", { children: [
2974
+ /* @__PURE__ */ d("span", { style: v.divider, children: [
2975
+ m.loginText,
2988
2976
  " "
2989
2977
  ] }),
2990
- /* @__PURE__ */ s("a", { onClick: o, style: S.link, children: g.loginLink })
2978
+ /* @__PURE__ */ s("a", { onClick: o, style: v.link, children: m.loginLink })
2991
2979
  ] })
2992
2980
  ] })
2993
2981
  ] });
@@ -3009,7 +2997,13 @@ const Zt = {
3009
2997
  errorMessage: "Failed to send magic link. Please try again.",
3010
2998
  loadingText: "Sending magic link...",
3011
2999
  verifyingText: "Verifying magic link...",
3012
- description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
3000
+ verifyingDescription: "Please wait while we verify your magic link...",
3001
+ description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you.",
3002
+ showNameToggle: "New user? Add your name",
3003
+ hideNameToggle: "Existing user? Hide name fields",
3004
+ tenantNotFoundError: "Tenant not found",
3005
+ missingTenantOrEmailError: "Missing tenant or email",
3006
+ dividerBullet: "•"
3013
3007
  }, Jt = {
3014
3008
  container: {
3015
3009
  maxWidth: "400px",
@@ -3111,9 +3105,29 @@ const Zt = {
3111
3105
  margin: "0.5rem 0",
3112
3106
  color: "#6b7280",
3113
3107
  fontSize: "0.875rem"
3108
+ },
3109
+ verifyingContainer: {
3110
+ textAlign: "center",
3111
+ padding: "2rem"
3112
+ },
3113
+ verifyingText: {
3114
+ fontSize: "1rem",
3115
+ color: "#6b7280"
3116
+ },
3117
+ toggleContainer: {
3118
+ textAlign: "center",
3119
+ marginTop: "0.5rem"
3120
+ },
3121
+ toggleLink: {
3122
+ background: "none",
3123
+ border: "none",
3124
+ color: "#3b82f6",
3125
+ fontSize: "0.875rem",
3126
+ cursor: "pointer",
3127
+ textDecoration: "underline"
3114
3128
  }
3115
3129
  };
3116
- function _r({
3130
+ function Wr({
3117
3131
  copy: n = {},
3118
3132
  styles: e = {},
3119
3133
  onSuccess: t,
@@ -3121,181 +3135,167 @@ function _r({
3121
3135
  onLoginClick: i,
3122
3136
  onSignupClick: o,
3123
3137
  showTraditionalLinks: a = !0,
3124
- className: f,
3125
- verifyToken: m,
3126
- frontendUrl: b
3138
+ className: p,
3139
+ verifyToken: w,
3140
+ frontendUrl: y
3127
3141
  }) {
3128
- const [c, L] = k(""), [p, R] = k(""), [I, M] = k(""), [E, x] = k(!1), [h, A] = k(!1), [w, v] = k(""), [N, B] = k(""), [l, H] = k({}), [P, D] = k(!1), { sendMagicLink: C, verifyMagicLink: d } = ue(), { tenant: U } = me(), F = { ...Zt, ...n }, y = { ...Jt, ...e };
3142
+ const [f, x] = k(""), [h, R] = k(""), [N, D] = k(""), [E, P] = k(!1), [u, S] = k(!1), [C, M] = k(""), [T, $] = k(""), [l, U] = k({}), [b, L] = k(!1), { sendMagicLink: F, verifyMagicLink: c } = ue(), { tenant: H } = me(), I = { ...Zt, ...n }, g = { ...Jt, ...e };
3129
3143
  re(() => {
3130
- m && g(m);
3131
- }, [m]);
3132
- const g = async (O) => {
3133
- if (!U || !c) {
3134
- v("Missing tenant or email");
3144
+ w && m(w);
3145
+ }, [w]);
3146
+ const m = async (q) => {
3147
+ if (!H || !f) {
3148
+ M(I.missingTenantOrEmailError);
3135
3149
  return;
3136
3150
  }
3137
- A(!0), v("");
3151
+ S(!0), M("");
3138
3152
  try {
3139
- const j = await d({
3140
- token: O,
3141
- email: c
3153
+ const j = await c({
3154
+ token: q,
3155
+ email: f
3142
3156
  // tenantId inferred from context automatically
3143
3157
  });
3144
3158
  t == null || t(j);
3145
3159
  } catch (j) {
3146
- const T = j.message || "Failed to verify magic link";
3147
- v(T), r == null || r(T);
3160
+ const A = j.message || "Failed to verify magic link";
3161
+ M(A), r == null || r(A);
3148
3162
  } finally {
3149
- A(!1);
3163
+ S(!1);
3150
3164
  }
3151
- }, S = () => {
3152
- const O = {};
3153
- return c.trim() || (O.email = !0), P && !p.trim() && (O.name = !0), H(O), Object.keys(O).length === 0;
3154
- }, Q = async (O) => {
3155
- if (O.preventDefault(), !!S()) {
3156
- if (!(U != null && U.id)) {
3157
- v("Tenant not found");
3165
+ }, v = () => {
3166
+ const q = {};
3167
+ return f.trim() || (q.email = !0), b && !h.trim() && (q.name = !0), U(q), Object.keys(q).length === 0;
3168
+ }, Q = async (q) => {
3169
+ if (q.preventDefault(), !!v()) {
3170
+ if (!(H != null && H.id)) {
3171
+ M(I.tenantNotFoundError);
3158
3172
  return;
3159
3173
  }
3160
- x(!0), v(""), B("");
3174
+ P(!0), M(""), $("");
3161
3175
  try {
3162
- const j = b || (typeof window < "u" ? window.location.origin : ""), T = await C({
3163
- email: c,
3164
- tenantId: U.id,
3176
+ const j = y || (typeof window < "u" ? window.location.origin : ""), A = await F({
3177
+ email: f,
3178
+ tenantId: H.id,
3165
3179
  frontendUrl: j,
3166
- name: P ? p : void 0,
3167
- lastName: P ? I : void 0
3180
+ name: b ? h : void 0,
3181
+ lastName: b ? N : void 0
3168
3182
  });
3169
- B(F.successMessage), t == null || t(T);
3183
+ $(I.successMessage), t == null || t(A);
3170
3184
  } catch (j) {
3171
- const T = j.message || F.errorMessage;
3172
- v(T), r == null || r(T);
3185
+ const A = j.message || I.errorMessage;
3186
+ M(A), r == null || r(A);
3173
3187
  } finally {
3174
- x(!1);
3188
+ P(!1);
3175
3189
  }
3176
3190
  }
3177
- }, J = (O) => ({
3178
- ...y.input,
3179
- ...l[O] ? y.inputError : {}
3180
- }), q = () => ({
3181
- ...y.button,
3182
- ...E || h ? y.buttonLoading : {},
3183
- ...!c || E || h ? y.buttonDisabled : {}
3191
+ }, J = (q) => ({
3192
+ ...g.input,
3193
+ ...l[q] ? g.inputError : {}
3194
+ }), O = () => ({
3195
+ ...g.button,
3196
+ ...E || u ? g.buttonLoading : {},
3197
+ ...!f || E || u ? g.buttonDisabled : {}
3184
3198
  });
3185
- return h ? /* @__PURE__ */ u("div", { className: f, style: y.container, children: [
3186
- /* @__PURE__ */ s("h2", { style: y.title, children: F.verifyingText }),
3187
- /* @__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..." }) })
3188
- ] }) : /* @__PURE__ */ u("div", { className: f, style: y.container, children: [
3189
- /* @__PURE__ */ s("h2", { style: y.title, children: F.title }),
3190
- /* @__PURE__ */ s("p", { style: y.description, children: F.description }),
3191
- /* @__PURE__ */ u("form", { onSubmit: Q, style: y.form, children: [
3192
- /* @__PURE__ */ u("div", { style: y.fieldGroup, children: [
3193
- /* @__PURE__ */ s("label", { style: y.label, children: F.emailLabel }),
3199
+ return u ? /* @__PURE__ */ d("div", { className: p, style: g.container, children: [
3200
+ /* @__PURE__ */ s("h2", { style: g.title, children: I.verifyingText }),
3201
+ /* @__PURE__ */ s("div", { style: g.verifyingContainer, children: /* @__PURE__ */ s("div", { style: g.verifyingText, children: I.verifyingDescription }) })
3202
+ ] }) : /* @__PURE__ */ d("div", { className: p, style: g.container, children: [
3203
+ /* @__PURE__ */ s("h2", { style: g.title, children: I.title }),
3204
+ /* @__PURE__ */ s("p", { style: g.description, children: I.description }),
3205
+ /* @__PURE__ */ d("form", { onSubmit: Q, style: g.form, children: [
3206
+ /* @__PURE__ */ d("div", { style: g.fieldGroup, children: [
3207
+ /* @__PURE__ */ s("label", { style: g.label, children: I.emailLabel }),
3194
3208
  /* @__PURE__ */ s(
3195
3209
  "input",
3196
3210
  {
3197
3211
  id: "email",
3198
3212
  name: "email",
3199
3213
  type: "email",
3200
- value: c,
3201
- onChange: (O) => {
3202
- L(O.target.value), l.email && H((j) => ({ ...j, email: !1 }));
3214
+ value: f,
3215
+ onChange: (q) => {
3216
+ x(q.target.value), l.email && U((j) => ({ ...j, email: !1 }));
3203
3217
  },
3204
- placeholder: F.emailPlaceholder,
3218
+ placeholder: I.emailPlaceholder,
3205
3219
  style: J("email"),
3206
- disabled: E || h
3220
+ disabled: E || u
3207
3221
  }
3208
3222
  )
3209
3223
  ] }),
3210
- !P && /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
3224
+ !b && /* @__PURE__ */ s("div", { style: g.toggleContainer, children: /* @__PURE__ */ s(
3211
3225
  "button",
3212
3226
  {
3213
3227
  type: "button",
3214
- onClick: () => D(!0),
3215
- style: {
3216
- background: "none",
3217
- border: "none",
3218
- color: "#3b82f6",
3219
- fontSize: "0.875rem",
3220
- cursor: "pointer",
3221
- textDecoration: "underline"
3222
- },
3223
- children: "New user? Add your name"
3228
+ onClick: () => L(!0),
3229
+ style: g.toggleLink,
3230
+ children: I.showNameToggle
3224
3231
  }
3225
3232
  ) }),
3226
- P && /* @__PURE__ */ u(_, { children: [
3227
- /* @__PURE__ */ u("div", { style: y.fieldGroup, children: [
3228
- /* @__PURE__ */ s("label", { style: y.label, children: F.nameLabel }),
3233
+ b && /* @__PURE__ */ d(_, { children: [
3234
+ /* @__PURE__ */ d("div", { style: g.fieldGroup, children: [
3235
+ /* @__PURE__ */ s("label", { style: g.label, children: I.nameLabel }),
3229
3236
  /* @__PURE__ */ s(
3230
3237
  "input",
3231
3238
  {
3232
3239
  id: "name",
3233
3240
  name: "name",
3234
3241
  type: "text",
3235
- value: p,
3236
- onChange: (O) => {
3237
- R(O.target.value), l.name && H((j) => ({ ...j, name: !1 }));
3242
+ value: h,
3243
+ onChange: (q) => {
3244
+ R(q.target.value), l.name && U((j) => ({ ...j, name: !1 }));
3238
3245
  },
3239
- placeholder: F.namePlaceholder,
3246
+ placeholder: I.namePlaceholder,
3240
3247
  style: J("name"),
3241
- disabled: E || h
3248
+ disabled: E || u
3242
3249
  }
3243
3250
  )
3244
3251
  ] }),
3245
- /* @__PURE__ */ u("div", { style: y.fieldGroup, children: [
3246
- /* @__PURE__ */ s("label", { style: y.label, children: F.lastNameLabel }),
3252
+ /* @__PURE__ */ d("div", { style: g.fieldGroup, children: [
3253
+ /* @__PURE__ */ s("label", { style: g.label, children: I.lastNameLabel }),
3247
3254
  /* @__PURE__ */ s(
3248
3255
  "input",
3249
3256
  {
3250
3257
  id: "lastName",
3251
3258
  name: "lastName",
3252
3259
  type: "text",
3253
- value: I,
3254
- onChange: (O) => M(O.target.value),
3255
- placeholder: F.lastNamePlaceholder,
3256
- style: y.input,
3257
- disabled: E || h
3260
+ value: N,
3261
+ onChange: (q) => D(q.target.value),
3262
+ placeholder: I.lastNamePlaceholder,
3263
+ style: g.input,
3264
+ disabled: E || u
3258
3265
  }
3259
3266
  )
3260
3267
  ] }),
3261
- /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
3268
+ /* @__PURE__ */ s("div", { style: g.toggleContainer, children: /* @__PURE__ */ s(
3262
3269
  "button",
3263
3270
  {
3264
3271
  type: "button",
3265
3272
  onClick: () => {
3266
- D(!1), R(""), M("");
3267
- },
3268
- style: {
3269
- background: "none",
3270
- border: "none",
3271
- color: "#6b7280",
3272
- fontSize: "0.875rem",
3273
- cursor: "pointer",
3274
- textDecoration: "underline"
3273
+ L(!1), R(""), D("");
3275
3274
  },
3276
- children: "Existing user? Hide name fields"
3275
+ style: g.toggleLink,
3276
+ children: I.hideNameToggle
3277
3277
  }
3278
3278
  ) })
3279
3279
  ] }),
3280
- /* @__PURE__ */ s("button", { type: "submit", disabled: !c || E || h, style: q(), children: E ? F.loadingText : F.submitButton }),
3281
- w && /* @__PURE__ */ s("div", { style: y.errorText, children: w }),
3282
- N && /* @__PURE__ */ s("div", { style: y.successText, children: N })
3280
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !f || E || u, style: O(), children: E ? I.loadingText : I.submitButton }),
3281
+ C && /* @__PURE__ */ s("div", { style: g.errorText, children: C }),
3282
+ T && /* @__PURE__ */ s("div", { style: g.successText, children: T })
3283
3283
  ] }),
3284
- a && /* @__PURE__ */ u("div", { style: y.linkContainer, children: [
3285
- /* @__PURE__ */ u("div", { children: [
3286
- /* @__PURE__ */ u("span", { style: y.divider, children: [
3287
- F.loginText,
3284
+ a && /* @__PURE__ */ d("div", { style: g.linkContainer, children: [
3285
+ /* @__PURE__ */ d("div", { children: [
3286
+ /* @__PURE__ */ d("span", { style: g.divider, children: [
3287
+ I.loginText,
3288
3288
  " "
3289
3289
  ] }),
3290
- /* @__PURE__ */ s("a", { onClick: i, style: y.link, children: F.loginLink })
3290
+ /* @__PURE__ */ s("a", { onClick: i, style: g.link, children: I.loginLink })
3291
3291
  ] }),
3292
- /* @__PURE__ */ s("div", { style: y.divider, children: "•" }),
3293
- /* @__PURE__ */ u("div", { children: [
3294
- /* @__PURE__ */ u("span", { style: y.divider, children: [
3295
- F.signupText,
3292
+ /* @__PURE__ */ s("div", { style: g.divider, children: I.dividerBullet }),
3293
+ /* @__PURE__ */ d("div", { children: [
3294
+ /* @__PURE__ */ d("span", { style: g.divider, children: [
3295
+ I.signupText,
3296
3296
  " "
3297
3297
  ] }),
3298
- /* @__PURE__ */ s("a", { onClick: o, style: y.link, children: F.signupLink })
3298
+ /* @__PURE__ */ s("a", { onClick: o, style: g.link, children: I.signupLink })
3299
3299
  ] })
3300
3300
  ] })
3301
3301
  ] });
@@ -3307,7 +3307,8 @@ const Yt = {
3307
3307
  errorMessage: "Failed to verify magic link. The link may be expired or invalid.",
3308
3308
  redirectingMessage: "Redirecting you to the dashboard...",
3309
3309
  retryButton: "Try Again",
3310
- backToLoginButton: "Back to Login"
3310
+ backToLoginButton: "Back to Login",
3311
+ missingParamsError: "Missing required parameters: token or email"
3311
3312
  }, Ye = {
3312
3313
  container: {
3313
3314
  maxWidth: "400px",
@@ -3394,8 +3395,14 @@ const Yt = {
3394
3395
  fontWeight: "500",
3395
3396
  cursor: "pointer",
3396
3397
  transition: "all 0.15s ease-in-out"
3398
+ },
3399
+ retryButtonHover: {
3400
+ backgroundColor: "#2563eb"
3401
+ },
3402
+ backButtonHover: {
3403
+ backgroundColor: "#e5e7eb"
3397
3404
  }
3398
- }, Xt = () => /* @__PURE__ */ s("div", { style: Ye.spinner }), er = () => /* @__PURE__ */ u(
3405
+ }, Xt = () => /* @__PURE__ */ s("div", { style: Ye.spinner }), er = () => /* @__PURE__ */ d(
3399
3406
  "svg",
3400
3407
  {
3401
3408
  width: "48",
@@ -3412,7 +3419,7 @@ const Yt = {
3412
3419
  /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3413
3420
  ]
3414
3421
  }
3415
- ), tr = () => /* @__PURE__ */ u(
3422
+ ), tr = () => /* @__PURE__ */ d(
3416
3423
  "svg",
3417
3424
  {
3418
3425
  width: "48",
@@ -3435,7 +3442,7 @@ const Yt = {
3435
3442
  success: /* @__PURE__ */ s(er, {}),
3436
3443
  error: /* @__PURE__ */ s(tr, {})
3437
3444
  };
3438
- function Wr({
3445
+ function Vr({
3439
3446
  copy: n = {},
3440
3447
  styles: e = {},
3441
3448
  icons: t = {},
@@ -3443,96 +3450,102 @@ function Wr({
3443
3450
  onError: i,
3444
3451
  onRetry: o,
3445
3452
  onBackToLogin: a,
3446
- className: f,
3447
- token: m,
3448
- email: b,
3449
- appId: c,
3450
- tenantSlug: L,
3451
- autoRedirectDelay: p = 3e3
3453
+ className: p,
3454
+ token: w,
3455
+ email: y,
3456
+ appId: f,
3457
+ tenantSlug: x,
3458
+ autoRedirectDelay: h = 3e3
3452
3459
  }) {
3453
- const [R, I] = k("verifying"), [M, E] = k(""), { verifyMagicLink: x } = ue(), h = { ...Yt, ...n }, A = { ...Ye, ...e }, w = { ...rr, ...t }, v = () => {
3460
+ const [R, N] = k("verifying"), [D, E] = k(""), { verifyMagicLink: P } = ue(), u = { ...Yt, ...n }, S = { ...Ye, ...e }, C = { ...rr, ...t }, M = () => {
3454
3461
  if (typeof window > "u") return {};
3455
- const P = new URLSearchParams(window.location.search);
3462
+ const b = new URLSearchParams(window.location.search);
3456
3463
  return {
3457
- token: m || P.get("token") || "",
3458
- email: b || P.get("email") || "",
3459
- appId: c || P.get("appId") || "",
3460
- tenantSlug: L || P.get("tenantSlug") || void 0
3464
+ token: w || b.get("token") || "",
3465
+ email: y || b.get("email") || "",
3466
+ appId: f || b.get("appId") || "",
3467
+ tenantSlug: x || b.get("tenantSlug") || void 0
3461
3468
  };
3462
- }, N = async () => {
3463
- I("verifying"), E("");
3469
+ }, T = async () => {
3470
+ N("verifying"), E("");
3464
3471
  try {
3465
- const P = v();
3466
- if (!P.token || !P.email)
3467
- throw new Error("Missing required parameters: token or email");
3468
- const D = await x({
3469
- token: P.token,
3470
- email: P.email,
3471
- tenantSlug: P.tenantSlug
3472
+ const b = M();
3473
+ if (!b.token || !b.email)
3474
+ throw new Error(u.missingParamsError);
3475
+ const L = await P({
3476
+ token: b.token,
3477
+ email: b.email,
3478
+ tenantSlug: b.tenantSlug
3472
3479
  });
3473
- I("success"), r == null || r(D), p > 0 && setTimeout(() => {
3474
- I("redirecting");
3475
- }, p);
3476
- } catch (P) {
3477
- const D = P.message || h.errorMessage;
3478
- E(D), I("error"), i == null || i(D);
3480
+ N("success"), r == null || r(L), h > 0 && setTimeout(() => {
3481
+ N("redirecting");
3482
+ }, h);
3483
+ } catch (b) {
3484
+ const L = b.message || u.errorMessage;
3485
+ E(L), N("error"), i == null || i(L);
3479
3486
  }
3480
- }, B = () => {
3481
- o == null || o(), N();
3487
+ }, $ = () => {
3488
+ o == null || o(), T();
3482
3489
  }, l = () => {
3483
3490
  a == null || a();
3484
3491
  };
3485
3492
  re(() => {
3486
- N();
3493
+ T();
3487
3494
  }, []);
3488
- const H = () => {
3495
+ const U = () => {
3489
3496
  switch (R) {
3490
3497
  case "verifying":
3491
- return /* @__PURE__ */ u("div", { style: A.message, children: [
3492
- w.loading,
3493
- h.verifyingMessage
3498
+ return /* @__PURE__ */ d("div", { style: S.message, children: [
3499
+ C.loading,
3500
+ u.verifyingMessage
3494
3501
  ] });
3495
3502
  case "success":
3496
- return /* @__PURE__ */ u(_, { children: [
3497
- w.success,
3498
- /* @__PURE__ */ s("div", { style: A.successMessage, children: h.successMessage })
3503
+ return /* @__PURE__ */ d(_, { children: [
3504
+ C.success,
3505
+ /* @__PURE__ */ s("div", { style: S.successMessage, children: u.successMessage })
3499
3506
  ] });
3500
3507
  case "redirecting":
3501
- return /* @__PURE__ */ u(_, { children: [
3502
- w.loading,
3503
- /* @__PURE__ */ s("div", { style: A.message, children: h.redirectingMessage })
3508
+ return /* @__PURE__ */ d(_, { children: [
3509
+ C.loading,
3510
+ /* @__PURE__ */ s("div", { style: S.message, children: u.redirectingMessage })
3504
3511
  ] });
3505
3512
  case "error":
3506
- return /* @__PURE__ */ u(_, { children: [
3507
- w.error,
3508
- /* @__PURE__ */ s("div", { style: A.errorMessage, children: M || h.errorMessage }),
3509
- /* @__PURE__ */ u("div", { style: A.buttonContainer, children: [
3513
+ return /* @__PURE__ */ d(_, { children: [
3514
+ C.error,
3515
+ /* @__PURE__ */ s("div", { style: S.errorMessage, children: D || u.errorMessage }),
3516
+ /* @__PURE__ */ d("div", { style: S.buttonContainer, children: [
3510
3517
  /* @__PURE__ */ s(
3511
3518
  "button",
3512
3519
  {
3513
- onClick: B,
3514
- style: A.retryButton,
3515
- onMouseOver: (P) => {
3516
- P.currentTarget.style.backgroundColor = "#2563eb";
3520
+ onClick: $,
3521
+ style: S.retryButton,
3522
+ onMouseOver: (b) => {
3523
+ Object.assign(b.currentTarget.style, S.retryButtonHover);
3517
3524
  },
3518
- onMouseOut: (P) => {
3519
- P.currentTarget.style.backgroundColor = "#3b82f6";
3525
+ onMouseOut: (b) => {
3526
+ const L = S.retryButton || {};
3527
+ Object.keys(S.retryButtonHover || {}).forEach((F) => {
3528
+ b.currentTarget.style[F] = L[F] ?? "";
3529
+ });
3520
3530
  },
3521
- children: h.retryButton
3531
+ children: u.retryButton
3522
3532
  }
3523
3533
  ),
3524
3534
  /* @__PURE__ */ s(
3525
3535
  "button",
3526
3536
  {
3527
3537
  onClick: l,
3528
- style: A.backButton,
3529
- onMouseOver: (P) => {
3530
- P.currentTarget.style.backgroundColor = "#e5e7eb";
3538
+ style: S.backButton,
3539
+ onMouseOver: (b) => {
3540
+ Object.assign(b.currentTarget.style, S.backButtonHover);
3531
3541
  },
3532
- onMouseOut: (P) => {
3533
- P.currentTarget.style.backgroundColor = "#f3f4f6";
3542
+ onMouseOut: (b) => {
3543
+ const L = S.backButton || {};
3544
+ Object.keys(S.backButtonHover || {}).forEach((F) => {
3545
+ b.currentTarget.style[F] = L[F] ?? "";
3546
+ });
3534
3547
  },
3535
- children: h.backToLoginButton
3548
+ children: u.backToLoginButton
3536
3549
  }
3537
3550
  )
3538
3551
  ] })
@@ -3541,15 +3554,15 @@ function Wr({
3541
3554
  return null;
3542
3555
  }
3543
3556
  };
3544
- return /* @__PURE__ */ u("div", { style: A.container, className: f, children: [
3557
+ return /* @__PURE__ */ d("div", { style: S.container, className: p, children: [
3545
3558
  /* @__PURE__ */ s("style", { children: `
3546
3559
  @keyframes spin {
3547
3560
  0% { transform: rotate(0deg); }
3548
3561
  100% { transform: rotate(360deg); }
3549
3562
  }
3550
3563
  ` }),
3551
- /* @__PURE__ */ s("h1", { style: A.title, children: h.title }),
3552
- H()
3564
+ /* @__PURE__ */ s("h1", { style: S.title, children: u.title }),
3565
+ U()
3553
3566
  ] });
3554
3567
  }
3555
3568
  const nr = {
@@ -3573,7 +3586,11 @@ const nr = {
3573
3586
  resetSubmitButton: "Reset Password",
3574
3587
  resetLoadingText: "Resetting...",
3575
3588
  resetSuccessMessage: "Password reset successfully!",
3576
- passwordMismatchError: "Passwords do not match"
3589
+ passwordMismatchError: "Passwords do not match",
3590
+ requestNewLinkLink: "Request New Link",
3591
+ haveTokenLink: "I have a token",
3592
+ tenantNotFoundError: "Tenant not found",
3593
+ dividerBullet: "•"
3577
3594
  }, sr = {
3578
3595
  container: {
3579
3596
  maxWidth: "400px",
@@ -3664,9 +3681,13 @@ const nr = {
3664
3681
  textDecoration: "none",
3665
3682
  fontSize: "0.875rem",
3666
3683
  cursor: "pointer"
3684
+ },
3685
+ modeSwitchDivider: {
3686
+ margin: "0 0.5rem",
3687
+ color: "#6b7280"
3667
3688
  }
3668
3689
  };
3669
- function Vr({
3690
+ function jr({
3670
3691
  copy: n = {},
3671
3692
  styles: e = {},
3672
3693
  mode: t = "request",
@@ -3674,105 +3695,105 @@ function Vr({
3674
3695
  onSuccess: i,
3675
3696
  onError: o,
3676
3697
  onBackToLogin: a,
3677
- onModeChange: f,
3678
- className: m
3698
+ onModeChange: p,
3699
+ className: w
3679
3700
  }) {
3680
- const [b, c] = k(""), [L, p] = k(r), [R, I] = k(""), [M, E] = k(""), [x, h] = k(!1), [A, w] = k(""), [v, N] = k(""), [B, l] = k({}), { requestPasswordReset: H, confirmPasswordReset: P } = ue(), { tenant: D } = me(), C = { ...nr, ...n }, d = { ...sr, ...e }, U = () => {
3681
- const q = {};
3682
- return b.trim() || (q.email = !0), l(q), Object.keys(q).length === 0;
3683
- }, F = () => {
3684
- const q = {};
3685
- return L.trim() || (q.token = !0), R.trim() || (q.newPassword = !0), M.trim() || (q.confirmPassword = !0), l(q), Object.keys(q).length === 0;
3686
- }, y = async (q) => {
3687
- if (q.preventDefault(), !!U()) {
3688
- if (!(D != null && D.id)) {
3689
- w("Tenant not found");
3701
+ const [y, f] = k(""), [x, h] = k(r), [R, N] = k(""), [D, E] = k(""), [P, u] = k(!1), [S, C] = k(""), [M, T] = k(""), [$, l] = k({}), { requestPasswordReset: U, confirmPasswordReset: b } = ue(), { tenant: L } = me(), F = { ...nr, ...n }, c = { ...sr, ...e }, H = () => {
3702
+ const O = {};
3703
+ return y.trim() || (O.email = !0), l(O), Object.keys(O).length === 0;
3704
+ }, I = () => {
3705
+ const O = {};
3706
+ return x.trim() || (O.token = !0), R.trim() || (O.newPassword = !0), D.trim() || (O.confirmPassword = !0), l(O), Object.keys(O).length === 0;
3707
+ }, g = async (O) => {
3708
+ if (O.preventDefault(), !!H()) {
3709
+ if (!(L != null && L.id)) {
3710
+ C(F.tenantNotFoundError);
3690
3711
  return;
3691
3712
  }
3692
- h(!0), w(""), N("");
3713
+ u(!0), C(""), T("");
3693
3714
  try {
3694
- await H({ email: b, tenantId: D.id }), N(C.successMessage), i == null || i();
3695
- } catch (O) {
3696
- const j = O.message || C.errorMessage;
3697
- w(j), o == null || o(j);
3715
+ await U({ email: y, tenantId: L.id }), T(F.successMessage), i == null || i();
3716
+ } catch (q) {
3717
+ const j = q.message || F.errorMessage;
3718
+ C(j), o == null || o(j);
3698
3719
  } finally {
3699
- h(!1);
3720
+ u(!1);
3700
3721
  }
3701
3722
  }
3702
- }, g = async (q) => {
3703
- if (q.preventDefault(), !!F()) {
3704
- if (R !== M) {
3705
- w(C.passwordMismatchError), l({ confirmPassword: !0 });
3723
+ }, m = async (O) => {
3724
+ if (O.preventDefault(), !!I()) {
3725
+ if (R !== D) {
3726
+ C(F.passwordMismatchError), l({ confirmPassword: !0 });
3706
3727
  return;
3707
3728
  }
3708
- h(!0), w(""), N("");
3729
+ u(!0), C(""), T("");
3709
3730
  try {
3710
- await P({ token: L, newPassword: R }), N(C.resetSuccessMessage), i == null || i();
3711
- } catch (O) {
3712
- const j = O.message || C.errorMessage;
3713
- w(j), o == null || o(j);
3731
+ await b({ token: x, newPassword: R }), T(F.resetSuccessMessage), i == null || i();
3732
+ } catch (q) {
3733
+ const j = q.message || F.errorMessage;
3734
+ C(j), o == null || o(j);
3714
3735
  } finally {
3715
- h(!1);
3736
+ u(!1);
3716
3737
  }
3717
3738
  }
3718
- }, S = (q) => ({
3719
- ...d.input,
3720
- ...B[q] ? d.inputError : {}
3739
+ }, v = (O) => ({
3740
+ ...c.input,
3741
+ ...$[O] ? c.inputError : {}
3721
3742
  }), Q = () => ({
3722
- ...d.button,
3723
- ...x ? d.buttonLoading : {}
3743
+ ...c.button,
3744
+ ...P ? c.buttonLoading : {}
3724
3745
  });
3725
3746
  if (t === "reset") {
3726
- const q = L && R && M;
3727
- return /* @__PURE__ */ u("div", { className: m, style: d.container, children: [
3728
- /* @__PURE__ */ s("h2", { style: d.title, children: C.resetTitle }),
3729
- /* @__PURE__ */ s("p", { style: d.subtitle, children: C.resetSubtitle }),
3730
- /* @__PURE__ */ u("form", { onSubmit: g, style: d.form, children: [
3731
- /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3732
- /* @__PURE__ */ s("label", { style: d.label, children: C.tokenLabel }),
3747
+ const O = x && R && D;
3748
+ return /* @__PURE__ */ d("div", { className: w, style: c.container, children: [
3749
+ /* @__PURE__ */ s("h2", { style: c.title, children: F.resetTitle }),
3750
+ /* @__PURE__ */ s("p", { style: c.subtitle, children: F.resetSubtitle }),
3751
+ /* @__PURE__ */ d("form", { onSubmit: m, style: c.form, children: [
3752
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3753
+ /* @__PURE__ */ s("label", { style: c.label, children: F.tokenLabel }),
3733
3754
  /* @__PURE__ */ s(
3734
3755
  "input",
3735
3756
  {
3736
3757
  type: "text",
3737
- value: L,
3738
- onChange: (O) => {
3739
- p(O.target.value), B.token && l((j) => ({ ...j, token: !1 }));
3758
+ value: x,
3759
+ onChange: (q) => {
3760
+ h(q.target.value), $.token && l((j) => ({ ...j, token: !1 }));
3740
3761
  },
3741
- placeholder: C.tokenPlaceholder,
3742
- style: S("token"),
3743
- disabled: x
3762
+ placeholder: F.tokenPlaceholder,
3763
+ style: v("token"),
3764
+ disabled: P
3744
3765
  }
3745
3766
  )
3746
3767
  ] }),
3747
- /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3748
- /* @__PURE__ */ s("label", { style: d.label, children: C.newPasswordLabel }),
3768
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3769
+ /* @__PURE__ */ s("label", { style: c.label, children: F.newPasswordLabel }),
3749
3770
  /* @__PURE__ */ s(
3750
3771
  "input",
3751
3772
  {
3752
3773
  type: "password",
3753
3774
  value: R,
3754
- onChange: (O) => {
3755
- I(O.target.value), B.newPassword && l((j) => ({ ...j, newPassword: !1 }));
3775
+ onChange: (q) => {
3776
+ N(q.target.value), $.newPassword && l((j) => ({ ...j, newPassword: !1 }));
3756
3777
  },
3757
- placeholder: C.newPasswordPlaceholder,
3758
- style: S("newPassword"),
3759
- disabled: x
3778
+ placeholder: F.newPasswordPlaceholder,
3779
+ style: v("newPassword"),
3780
+ disabled: P
3760
3781
  }
3761
3782
  )
3762
3783
  ] }),
3763
- /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3764
- /* @__PURE__ */ s("label", { style: d.label, children: C.confirmPasswordLabel }),
3784
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3785
+ /* @__PURE__ */ s("label", { style: c.label, children: F.confirmPasswordLabel }),
3765
3786
  /* @__PURE__ */ s(
3766
3787
  "input",
3767
3788
  {
3768
3789
  type: "password",
3769
- value: M,
3770
- onChange: (O) => {
3771
- E(O.target.value), B.confirmPassword && l((j) => ({ ...j, confirmPassword: !1 })), A === C.passwordMismatchError && w("");
3790
+ value: D,
3791
+ onChange: (q) => {
3792
+ E(q.target.value), $.confirmPassword && l((j) => ({ ...j, confirmPassword: !1 })), S === F.passwordMismatchError && C("");
3772
3793
  },
3773
- placeholder: C.confirmPasswordPlaceholder,
3774
- style: S("confirmPassword"),
3775
- disabled: x
3794
+ placeholder: F.confirmPasswordPlaceholder,
3795
+ style: v("confirmPassword"),
3796
+ disabled: P
3776
3797
  }
3777
3798
  )
3778
3799
  ] }),
@@ -3780,44 +3801,44 @@ function Vr({
3780
3801
  "button",
3781
3802
  {
3782
3803
  type: "submit",
3783
- disabled: !q || x,
3804
+ disabled: !O || P,
3784
3805
  style: {
3785
3806
  ...Q(),
3786
- ...!q || x ? d.buttonDisabled : {}
3807
+ ...!O || P ? c.buttonDisabled : {}
3787
3808
  },
3788
- children: x ? C.resetLoadingText : C.resetSubmitButton
3809
+ children: P ? F.resetLoadingText : F.resetSubmitButton
3789
3810
  }
3790
3811
  ),
3791
- A && /* @__PURE__ */ s("div", { style: d.errorText, children: A }),
3792
- v && /* @__PURE__ */ s("div", { style: d.successText, children: v })
3812
+ S && /* @__PURE__ */ s("div", { style: c.errorText, children: S }),
3813
+ M && /* @__PURE__ */ s("div", { style: c.successText, children: M })
3793
3814
  ] }),
3794
- /* @__PURE__ */ u("div", { style: d.linkContainer, children: [
3795
- /* @__PURE__ */ s("a", { onClick: a, style: d.link, children: C.backToLoginLink }),
3796
- f && /* @__PURE__ */ u(_, { children: [
3797
- /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3798
- /* @__PURE__ */ s("a", { onClick: () => f("request"), style: d.link, children: "Request New Link" })
3815
+ /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3816
+ /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: F.backToLoginLink }),
3817
+ p && /* @__PURE__ */ d(_, { children: [
3818
+ /* @__PURE__ */ s("span", { style: c.modeSwitchDivider, children: F.dividerBullet }),
3819
+ /* @__PURE__ */ s("a", { onClick: () => p("request"), style: c.link, children: F.requestNewLinkLink })
3799
3820
  ] })
3800
3821
  ] })
3801
3822
  ] });
3802
3823
  }
3803
- const J = b;
3804
- return /* @__PURE__ */ u("div", { className: m, style: d.container, children: [
3805
- /* @__PURE__ */ s("h2", { style: d.title, children: C.title }),
3806
- /* @__PURE__ */ s("p", { style: d.subtitle, children: C.subtitle }),
3807
- /* @__PURE__ */ u("form", { onSubmit: y, style: d.form, children: [
3808
- /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3809
- /* @__PURE__ */ s("label", { style: d.label, children: C.emailLabel }),
3824
+ const J = y;
3825
+ return /* @__PURE__ */ d("div", { className: w, style: c.container, children: [
3826
+ /* @__PURE__ */ s("h2", { style: c.title, children: F.title }),
3827
+ /* @__PURE__ */ s("p", { style: c.subtitle, children: F.subtitle }),
3828
+ /* @__PURE__ */ d("form", { onSubmit: g, style: c.form, children: [
3829
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3830
+ /* @__PURE__ */ s("label", { style: c.label, children: F.emailLabel }),
3810
3831
  /* @__PURE__ */ s(
3811
3832
  "input",
3812
3833
  {
3813
3834
  type: "email",
3814
- value: b,
3815
- onChange: (q) => {
3816
- c(q.target.value), B.email && l((O) => ({ ...O, email: !1 }));
3835
+ value: y,
3836
+ onChange: (O) => {
3837
+ f(O.target.value), $.email && l((q) => ({ ...q, email: !1 }));
3817
3838
  },
3818
- placeholder: C.emailPlaceholder,
3819
- style: S("email"),
3820
- disabled: x
3839
+ placeholder: F.emailPlaceholder,
3840
+ style: v("email"),
3841
+ disabled: P
3821
3842
  }
3822
3843
  )
3823
3844
  ] }),
@@ -3825,22 +3846,22 @@ function Vr({
3825
3846
  "button",
3826
3847
  {
3827
3848
  type: "submit",
3828
- disabled: !J || x,
3849
+ disabled: !J || P,
3829
3850
  style: {
3830
3851
  ...Q(),
3831
- ...!J || x ? d.buttonDisabled : {}
3852
+ ...!J || P ? c.buttonDisabled : {}
3832
3853
  },
3833
- children: x ? C.loadingText : C.submitButton
3854
+ children: P ? F.loadingText : F.submitButton
3834
3855
  }
3835
3856
  ),
3836
- A && /* @__PURE__ */ s("div", { style: d.errorText, children: A }),
3837
- v && /* @__PURE__ */ s("div", { style: d.successText, children: v })
3857
+ S && /* @__PURE__ */ s("div", { style: c.errorText, children: S }),
3858
+ M && /* @__PURE__ */ s("div", { style: c.successText, children: M })
3838
3859
  ] }),
3839
- /* @__PURE__ */ u("div", { style: d.linkContainer, children: [
3840
- /* @__PURE__ */ s("a", { onClick: a, style: d.link, children: C.backToLoginLink }),
3841
- f && /* @__PURE__ */ u(_, { children: [
3842
- /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3843
- /* @__PURE__ */ s("a", { onClick: () => f("reset"), style: d.link, children: "I have a token" })
3860
+ /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3861
+ /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: F.backToLoginLink }),
3862
+ p && /* @__PURE__ */ d(_, { children: [
3863
+ /* @__PURE__ */ s("span", { style: c.modeSwitchDivider, children: F.dividerBullet }),
3864
+ /* @__PURE__ */ s("a", { onClick: () => p("reset"), style: c.link, children: F.haveTokenLink })
3844
3865
  ] })
3845
3866
  ] })
3846
3867
  ] });
@@ -3857,7 +3878,7 @@ const ir = () => /* @__PURE__ */ s(
3857
3878
  },
3858
3879
  children: /* @__PURE__ */ s("div", { children: "Loading..." })
3859
3880
  }
3860
- ), or = ({ error: n, retry: e }) => /* @__PURE__ */ u(
3881
+ ), or = ({ error: n, retry: e }) => /* @__PURE__ */ d(
3861
3882
  "div",
3862
3883
  {
3863
3884
  style: {
@@ -3891,139 +3912,169 @@ const ir = () => /* @__PURE__ */ s(
3891
3912
  ]
3892
3913
  }
3893
3914
  );
3894
- function jr({
3915
+ function Gr({
3895
3916
  children: n,
3896
3917
  loadingFallback: e,
3897
3918
  errorFallback: t,
3898
3919
  requireTenant: r = !0
3899
3920
  }) {
3900
- const { isAppLoading: i, appError: o, retryApp: a } = ve(), f = xe(), m = De(), b = Ke(), c = Ze(), L = (f == null ? void 0 : f.isTenantLoading) ?? !1, p = (f == null ? void 0 : f.tenantError) ?? null, R = (f == null ? void 0 : f.tenantSlug) ?? null, I = (f == null ? void 0 : f.retryTenant) ?? (() => {
3901
- }), M = (m == null ? void 0 : m.isAuthReady) ?? !0, E = (b == null ? void 0 : b.isReady) ?? !0, x = (c == null ? void 0 : c.isReady) ?? !0, h = r && f && R, N = i || h && L || m && !M || b && !E || c && !x, B = o || (h ? p : null), l = () => {
3902
- o && a(), p && f && I();
3921
+ const { isAppLoading: i, appError: o, retryApp: a } = Se(), p = xe(), w = Fe(), y = Ke(), f = Ze(), x = (p == null ? void 0 : p.isTenantLoading) ?? !1, h = (p == null ? void 0 : p.tenantError) ?? null, R = (p == null ? void 0 : p.tenantSlug) ?? null, N = (p == null ? void 0 : p.retryTenant) ?? (() => {
3922
+ }), D = (w == null ? void 0 : w.isAuthReady) ?? !0, E = (y == null ? void 0 : y.isReady) ?? !0, P = (f == null ? void 0 : f.isReady) ?? !0, u = r && p && R, T = i || u && x || w && !D || y && !E || f && !P, $ = o || (u ? h : null), l = () => {
3923
+ o && a(), h && p && N();
3903
3924
  };
3904
- if (N)
3925
+ if (T)
3905
3926
  return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(ir, {}) });
3906
- if (B) {
3907
- const H = typeof t == "function" ? t(B, l) : t || /* @__PURE__ */ s(or, { error: B, retry: l });
3908
- return /* @__PURE__ */ s(_, { children: H });
3927
+ if ($) {
3928
+ const U = typeof t == "function" ? t($, l) : t || /* @__PURE__ */ s(or, { error: $, retry: l });
3929
+ return /* @__PURE__ */ s(_, { children: U });
3909
3930
  }
3910
3931
  return /* @__PURE__ */ s(_, { children: n });
3911
3932
  }
3912
- function Gr(n = !0) {
3913
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = ve(), o = xe(), a = De(), f = Ke(), m = Ze(), b = (o == null ? void 0 : o.isTenantLoading) ?? !1, c = (o == null ? void 0 : o.tenantError) ?? null, L = (o == null ? void 0 : o.tenant) ?? null, p = (o == null ? void 0 : o.tenantSlug) ?? null, R = (o == null ? void 0 : o.retryTenant) ?? (() => {
3914
- }), I = (a == null ? void 0 : a.isAuthReady) ?? !0, M = (f == null ? void 0 : f.isReady) ?? !0, E = (m == null ? void 0 : m.isReady) ?? !0, x = n && o && p, v = e || x && b || a && !I || f && !M || m && !E, N = t || (x ? c : null);
3933
+ function Qr(n = !0) {
3934
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = Se(), o = xe(), a = Fe(), p = Ke(), w = Ze(), y = (o == null ? void 0 : o.isTenantLoading) ?? !1, f = (o == null ? void 0 : o.tenantError) ?? null, x = (o == null ? void 0 : o.tenant) ?? null, h = (o == null ? void 0 : o.tenantSlug) ?? null, R = (o == null ? void 0 : o.retryTenant) ?? (() => {
3935
+ }), N = (a == null ? void 0 : a.isAuthReady) ?? !0, D = (p == null ? void 0 : p.isReady) ?? !0, E = (w == null ? void 0 : w.isReady) ?? !0, P = n && o && h, M = e || P && y || a && !N || p && !D || w && !E, T = t || (P ? f : null);
3915
3936
  return {
3916
- isLoading: v,
3917
- error: N,
3918
- isReady: !v && !N && i !== null && (!x || L !== null),
3937
+ isLoading: M,
3938
+ error: T,
3939
+ isReady: !M && !T && i !== null && (!P || x !== null),
3919
3940
  retry: () => {
3920
- t && r(), c && o && R();
3941
+ t && r(), f && o && R();
3921
3942
  },
3922
3943
  // Individual states
3923
3944
  app: { isLoading: e, error: t, data: i },
3924
- tenant: o ? { isLoading: b, error: c, data: L } : null,
3925
- auth: a ? { isReady: I } : null,
3926
- featureFlags: f ? { isReady: M } : null,
3927
- subscription: m ? { isReady: E } : null
3945
+ tenant: o ? { isLoading: y, error: f, data: x } : null,
3946
+ auth: a ? { isReady: N } : null,
3947
+ featureFlags: p ? { isReady: D } : null,
3948
+ subscription: w ? { isReady: E } : null
3928
3949
  };
3929
3950
  }
3930
- function Qr({
3951
+ const ar = {
3952
+ wrapper: {
3953
+ position: "relative"
3954
+ },
3955
+ button: {
3956
+ cursor: "pointer",
3957
+ opacity: 1
3958
+ },
3959
+ buttonDisabled: {
3960
+ cursor: "not-allowed",
3961
+ opacity: 0.6
3962
+ },
3963
+ dropdown: {
3964
+ position: "absolute",
3965
+ top: "100%",
3966
+ left: 0,
3967
+ right: 0,
3968
+ zIndex: 1e3,
3969
+ backgroundColor: "white",
3970
+ border: "1px solid #ccc",
3971
+ borderRadius: 4,
3972
+ boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
3973
+ maxHeight: 300,
3974
+ overflowY: "auto"
3975
+ },
3976
+ item: {
3977
+ padding: "8px 12px",
3978
+ cursor: "pointer",
3979
+ backgroundColor: "transparent"
3980
+ },
3981
+ itemSelected: {
3982
+ backgroundColor: "#f0f0f0"
3983
+ },
3984
+ itemHover: {
3985
+ backgroundColor: "#f5f5f5"
3986
+ },
3987
+ itemRole: {
3988
+ opacity: 0.7,
3989
+ marginLeft: 8
3990
+ },
3991
+ arrow: {
3992
+ marginLeft: 8
3993
+ }
3994
+ };
3995
+ function Kr({
3931
3996
  tenants: n,
3932
3997
  currentTenantId: e,
3933
3998
  onSelect: t,
3934
- className: r = "",
3935
- dropdownClassName: i = "",
3936
- itemClassName: o = "",
3937
- renderItem: a,
3938
- placeholder: f = "Select tenant",
3939
- disabled: m = !1,
3940
- showCurrentTenant: b = !0
3999
+ styles: r = {},
4000
+ className: i = "",
4001
+ dropdownClassName: o = "",
4002
+ itemClassName: a = "",
4003
+ renderItem: p,
4004
+ placeholder: w = "Select tenant",
4005
+ disabled: y = !1,
4006
+ showCurrentTenant: f = !0
3941
4007
  }) {
3942
- var A;
3943
- const c = De(), [L, p] = k(!1), R = Me(null), I = n ?? (c == null ? void 0 : c.userTenants) ?? [], M = e ?? ((A = c == null ? void 0 : c.currentUser) == null ? void 0 : A.tenantId) ?? null, E = async (w) => {
3944
- p(!1), t ? t(w) : c != null && c.switchToTenant && await c.switchToTenant(w);
4008
+ var M;
4009
+ const x = { ...ar, ...r }, h = Fe(), [R, N] = k(!1), D = Me(null), E = n ?? (h == null ? void 0 : h.userTenants) ?? [], P = e ?? ((M = h == null ? void 0 : h.currentUser) == null ? void 0 : M.tenantId) ?? null, u = async (T) => {
4010
+ N(!1), t ? t(T) : h != null && h.switchToTenant && await h.switchToTenant(T);
3945
4011
  };
3946
4012
  re(() => {
3947
- const w = (v) => {
3948
- R.current && !R.current.contains(v.target) && p(!1);
4013
+ const T = ($) => {
4014
+ D.current && !D.current.contains($.target) && N(!1);
3949
4015
  };
3950
- return document.addEventListener("mousedown", w), () => document.removeEventListener("mousedown", w);
4016
+ return document.addEventListener("mousedown", T), () => document.removeEventListener("mousedown", T);
3951
4017
  }, []);
3952
- const x = I.find((w) => w.id === M);
3953
- if (I.length === 0)
4018
+ const S = E.find((T) => T.id === P);
4019
+ if (E.length === 0)
3954
4020
  return null;
3955
- if (I.length === 1 && b)
3956
- return /* @__PURE__ */ s("div", { className: r, children: /* @__PURE__ */ s("span", { children: I[0].name }) });
3957
- const h = (w, v) => /* @__PURE__ */ u("span", { style: { fontWeight: v ? "bold" : "normal" }, children: [
3958
- w.name,
3959
- w.role && /* @__PURE__ */ u("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
4021
+ if (E.length === 1 && f)
4022
+ return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: E[0].name }) });
4023
+ const C = (T, $) => /* @__PURE__ */ d("span", { style: { fontWeight: $ ? "bold" : "normal" }, children: [
4024
+ T.name,
4025
+ T.role && /* @__PURE__ */ d("span", { style: x.itemRole, children: [
3960
4026
  "(",
3961
- w.role,
4027
+ T.role,
3962
4028
  ")"
3963
4029
  ] })
3964
4030
  ] });
3965
- return /* @__PURE__ */ u("div", { ref: R, className: r, style: { position: "relative" }, children: [
3966
- /* @__PURE__ */ u(
4031
+ return /* @__PURE__ */ d("div", { ref: D, className: i, style: x.wrapper, children: [
4032
+ /* @__PURE__ */ d(
3967
4033
  "button",
3968
4034
  {
3969
4035
  type: "button",
3970
- onClick: () => !m && p(!L),
3971
- disabled: m,
4036
+ onClick: () => !y && N(!R),
4037
+ disabled: y,
3972
4038
  style: {
3973
- cursor: m ? "not-allowed" : "pointer",
3974
- opacity: m ? 0.6 : 1
4039
+ ...x.button,
4040
+ ...y ? x.buttonDisabled : {}
3975
4041
  },
3976
4042
  children: [
3977
- x ? x.name : f,
3978
- /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: L ? "▲" : "▼" })
4043
+ S ? S.name : w,
4044
+ /* @__PURE__ */ s("span", { style: x.arrow, children: R ? "▲" : "▼" })
3979
4045
  ]
3980
4046
  }
3981
4047
  ),
3982
- L && /* @__PURE__ */ s(
3983
- "div",
3984
- {
3985
- className: i,
3986
- style: {
3987
- position: "absolute",
3988
- top: "100%",
3989
- left: 0,
3990
- right: 0,
3991
- zIndex: 1e3,
3992
- backgroundColor: "white",
3993
- border: "1px solid #ccc",
3994
- borderRadius: 4,
3995
- boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
3996
- maxHeight: 300,
3997
- overflowY: "auto"
4048
+ R && /* @__PURE__ */ s("div", { className: o, style: x.dropdown, children: E.map((T) => {
4049
+ const $ = T.id === P;
4050
+ return /* @__PURE__ */ s(
4051
+ "div",
4052
+ {
4053
+ className: a,
4054
+ onClick: () => u(T.id),
4055
+ style: {
4056
+ ...x.item,
4057
+ ...$ ? x.itemSelected : {}
4058
+ },
4059
+ onMouseEnter: (l) => {
4060
+ $ || Object.assign(l.currentTarget.style, x.itemHover);
4061
+ },
4062
+ onMouseLeave: (l) => {
4063
+ if (!$) {
4064
+ const U = x.item || {};
4065
+ Object.keys(x.itemHover || {}).forEach((b) => {
4066
+ l.currentTarget.style[b] = U[b] ?? "";
4067
+ });
4068
+ }
4069
+ },
4070
+ children: p ? p(T, $) : C(T, $)
3998
4071
  },
3999
- children: I.map((w) => {
4000
- const v = w.id === M;
4001
- return /* @__PURE__ */ s(
4002
- "div",
4003
- {
4004
- className: o,
4005
- onClick: () => E(w.id),
4006
- style: {
4007
- padding: "8px 12px",
4008
- cursor: "pointer",
4009
- backgroundColor: v ? "#f0f0f0" : "transparent"
4010
- },
4011
- onMouseEnter: (N) => {
4012
- v || (N.target.style.backgroundColor = "#f5f5f5");
4013
- },
4014
- onMouseLeave: (N) => {
4015
- v || (N.target.style.backgroundColor = "transparent");
4016
- },
4017
- children: a ? a(w, v) : h(w, v)
4018
- },
4019
- w.id
4020
- );
4021
- })
4022
- }
4023
- )
4072
+ T.id
4073
+ );
4074
+ }) })
4024
4075
  ] });
4025
4076
  }
4026
- class Kr {
4077
+ class Zr {
4027
4078
  constructor(e, t) {
4028
4079
  this.httpService = e, this.sessionManager = t;
4029
4080
  }
@@ -4091,7 +4142,7 @@ class Kr {
4091
4142
  };
4092
4143
  }
4093
4144
  }
4094
- class Zr {
4145
+ class Jr {
4095
4146
  constructor(e, t) {
4096
4147
  this.httpService = e, this.sessionManager = t;
4097
4148
  }
@@ -4142,7 +4193,7 @@ class Zr {
4142
4193
  });
4143
4194
  }
4144
4195
  }
4145
- class Jr {
4196
+ class Yr {
4146
4197
  constructor(e) {
4147
4198
  this.httpService = e;
4148
4199
  }
@@ -4151,7 +4202,7 @@ class Jr {
4151
4202
  return await this.httpService.get("/health");
4152
4203
  }
4153
4204
  }
4154
- class Yr {
4205
+ class Xr {
4155
4206
  // Date string to Date object
4156
4207
  static toDate(e) {
4157
4208
  return new Date(e);
@@ -4273,139 +4324,139 @@ class Yr {
4273
4324
  }), t;
4274
4325
  }
4275
4326
  }
4276
- const Xe = "returnTo", Ie = "zone_return_to", Ee = "zone_return_to";
4277
- function Xr(n = {}) {
4327
+ const Xe = "returnTo", Ee = "zone_return_to", Ie = "zone_return_to";
4328
+ function en(n = {}) {
4278
4329
  const {
4279
4330
  zoneRoots: e = {},
4280
4331
  returnToParam: t = Xe,
4281
4332
  returnToStorage: r = "url"
4282
- } = n, i = ft(), [o, a] = pt(), { isAuthenticated: f, currentUser: m } = ue(), { tenant: b } = ge(), c = K(() => ({ ...$e, ...e }), [e]), L = !!b, p = m == null ? void 0 : m.userType, R = K(() => {
4333
+ } = n, i = pt(), [o, a] = ft(), { isAuthenticated: p, currentUser: w } = ue(), { tenant: y } = ge(), f = K(() => ({ ...Ue, ...e }), [e]), x = !!y, h = w == null ? void 0 : w.userType, R = K(() => {
4283
4334
  switch (r) {
4284
4335
  case "url":
4285
4336
  return o.get(t);
4286
4337
  case "session":
4287
- return sessionStorage.getItem(Ie);
4338
+ return sessionStorage.getItem(Ee);
4288
4339
  case "local":
4289
- return localStorage.getItem(Ee);
4340
+ return localStorage.getItem(Ie);
4290
4341
  default:
4291
4342
  return null;
4292
4343
  }
4293
- }, [r, o, t]), I = se(() => {
4344
+ }, [r, o, t]), N = se(() => {
4294
4345
  switch (r) {
4295
4346
  case "url": {
4296
- const h = new URLSearchParams(o);
4297
- h.delete(t), a(h, { replace: !0 });
4347
+ const u = new URLSearchParams(o);
4348
+ u.delete(t), a(u, { replace: !0 });
4298
4349
  break;
4299
4350
  }
4300
4351
  case "session":
4301
- sessionStorage.removeItem(Ie);
4352
+ sessionStorage.removeItem(Ee);
4302
4353
  break;
4303
4354
  case "local":
4304
- localStorage.removeItem(Ee);
4355
+ localStorage.removeItem(Ie);
4305
4356
  break;
4306
4357
  }
4307
- }, [r, o, t, a]), M = se(
4308
- (h) => {
4358
+ }, [r, o, t, a]), D = se(
4359
+ (u) => {
4309
4360
  switch (r) {
4310
4361
  case "url": {
4311
- const A = new URLSearchParams(o);
4312
- A.set(t, h), a(A, { replace: !0 });
4362
+ const S = new URLSearchParams(o);
4363
+ S.set(t, u), a(S, { replace: !0 });
4313
4364
  break;
4314
4365
  }
4315
4366
  case "session":
4316
- sessionStorage.setItem(Ie, h);
4367
+ sessionStorage.setItem(Ee, u);
4317
4368
  break;
4318
4369
  case "local":
4319
- localStorage.setItem(Ee, h);
4370
+ localStorage.setItem(Ie, u);
4320
4371
  break;
4321
4372
  }
4322
4373
  },
4323
4374
  [r, o, t, a]
4324
4375
  ), E = se(
4325
- (h) => {
4326
- const A = c[h] || c.default;
4327
- i(A);
4376
+ (u) => {
4377
+ const S = f[u] || f.default;
4378
+ i(S);
4328
4379
  },
4329
- [i, c]
4330
- ), x = se(() => L ? f ? p === oe.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : f ? p === oe.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [L, f, p, c]);
4380
+ [i, f]
4381
+ ), P = se(() => x ? p ? h === oe.TENANT_ADMIN ? f.tenantAdmin : f.tenantUser : f.tenantGuest : p ? h === oe.TENANT_ADMIN ? f.publicAdmin : f.publicUser : f.publicGuest, [x, p, h, f]);
4331
4382
  return {
4332
4383
  returnToUrl: R,
4333
- clearReturnTo: I,
4334
- setReturnTo: M,
4384
+ clearReturnTo: N,
4385
+ setReturnTo: D,
4335
4386
  navigateToZone: E,
4336
- getSmartRedirect: x
4387
+ getSmartRedirect: P
4337
4388
  };
4338
4389
  }
4339
- function en(n, e, t = Xe, r = "url") {
4390
+ function tn(n, e, t = Xe, r = "url") {
4340
4391
  if (!e || r !== "url")
4341
4392
  return n;
4342
4393
  const i = new URL(n, window.location.origin);
4343
4394
  return i.searchParams.set(t, e), i.pathname + i.search;
4344
4395
  }
4345
4396
  export {
4346
- Nr as AdminZone,
4347
- Yr as ApiMappers,
4348
- Oe as AppApiService,
4349
- jr as AppLoader,
4350
- gr as AppProvider,
4397
+ Fr as AdminZone,
4398
+ Xr as ApiMappers,
4399
+ qe as AppApiService,
4400
+ Gr as AppLoader,
4401
+ mr as AppProvider,
4351
4402
  yt as AuthApiService,
4352
4403
  Sr as AuthProvider,
4353
- Lr as AuthenticatedZone,
4404
+ Nr as AuthenticatedZone,
4354
4405
  Je as DEFAULT_ZONE_PRESETS,
4355
- $e as DEFAULT_ZONE_ROOTS,
4406
+ Ue as DEFAULT_ZONE_ROOTS,
4356
4407
  qr as FeatureFlag,
4357
4408
  Pt as FeatureFlagApiService,
4358
- vr as FeatureFlagProvider,
4359
- Fr as GuestZone,
4360
- Jr as HealthApiService,
4409
+ Tr as FeatureFlagProvider,
4410
+ Dr as GuestZone,
4411
+ Yr as HealthApiService,
4361
4412
  le as HttpService,
4362
4413
  Ir as LandingRoute,
4363
- Or as LoginForm,
4364
- _r as MagicLinkForm,
4365
- Wr as MagicLinkVerify,
4366
- Cr as OpenZone,
4367
- Vr as PasswordRecoveryForm,
4368
- Kr as PermissionApiService,
4369
- Ar as Protected,
4370
- Pr as ProtectedRoute,
4371
- Mr as PublicZone,
4414
+ zr as LoginForm,
4415
+ Wr as MagicLinkForm,
4416
+ Vr as MagicLinkVerify,
4417
+ $r as OpenZone,
4418
+ jr as PasswordRecoveryForm,
4419
+ Zr as PermissionApiService,
4420
+ Pr as Protected,
4421
+ Rr as ProtectedRoute,
4422
+ Lr as PublicZone,
4372
4423
  ze as RoleApiService,
4373
- kr as RoutingProvider,
4424
+ xr as RoutingProvider,
4374
4425
  ne as SessionExpiredError,
4375
4426
  we as SessionManager,
4376
- zr as SignupForm,
4377
- It as SubscriptionApiService,
4378
- Br as SubscriptionGuard,
4379
- Zr as SubscriptionPlanApiService,
4380
- Tr as SubscriptionProvider,
4427
+ _r as SignupForm,
4428
+ Et as SubscriptionApiService,
4429
+ Or as SubscriptionGuard,
4430
+ Jr as SubscriptionPlanApiService,
4431
+ kr as SubscriptionProvider,
4381
4432
  be as TenantApiService,
4382
4433
  Ur as TenantAuthenticatedZone,
4383
- Hr as TenantGuestZone,
4384
- $r as TenantOpenZone,
4385
- yr as TenantProvider,
4386
- Rr as TenantRoute,
4387
- Qr as TenantSelector,
4388
- Er as TenantZone,
4434
+ Br as TenantGuestZone,
4435
+ Hr as TenantOpenZone,
4436
+ wr as TenantProvider,
4437
+ Er as TenantRoute,
4438
+ Kr as TenantSelector,
4439
+ Mr as TenantZone,
4389
4440
  mt as TokenRefreshError,
4390
4441
  gt as TokenRefreshTimeoutError,
4391
4442
  wt as UserApiService,
4392
4443
  oe as UserType,
4393
- Dr as UserZone,
4444
+ Cr as UserZone,
4394
4445
  ce as ZoneRoute,
4395
- en as buildRedirectUrl,
4396
- mr as useApi,
4397
- ve as useApp,
4398
- Gr as useAppLoaderState,
4446
+ tn as buildRedirectUrl,
4447
+ yr as useApi,
4448
+ Se as useApp,
4449
+ Qr as useAppLoaderState,
4399
4450
  ue as useAuth,
4400
4451
  Rt as useFeatureFlags,
4401
- xr as useRouting,
4452
+ Ar as useRouting,
4402
4453
  Mt as useRoutingOptional,
4403
- br as useSettings,
4404
- Et as useSubscription,
4454
+ vr as useSettings,
4455
+ It as useSubscription,
4405
4456
  ge as useTenant,
4406
4457
  me as useTenantInfo,
4407
4458
  xe as useTenantOptional,
4408
- wr as useTenantSettings,
4409
- Xr as useZoneNavigation
4459
+ br as useTenantSettings,
4460
+ en as useZoneNavigation
4410
4461
  };
4411
4462
  //# sourceMappingURL=index.es.js.map