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