@skylabs-digital/react-identity-access 2.25.0 → 2.27.0

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