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