@skylabs-digital/react-identity-access 3.0.0 → 3.1.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 B, jsxs as f } from "react/jsx-runtime";
2
- import fe, { createContext as pe, useState as N, useRef as ke, useCallback as re, useMemo as q, useEffect as ne, useContext as se } from "react";
3
- import { useLocation as Se, Navigate as ge, useNavigate as pt, useSearchParams as ft } from "react-router-dom";
4
- class de {
2
+ import me, { createContext as fe, useState as N, useRef as Ee, useCallback as te, useMemo as V, useEffect as re, useContext as ne } from "react";
3
+ import { useLocation as xe, Navigate as be, useNavigate as wt, useSearchParams as vt } from "react-router-dom";
4
+ class he {
5
5
  constructor(e, t = 1e4) {
6
6
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
7
7
  }
@@ -21,7 +21,7 @@ class de {
21
21
  const c = await this.sessionManager.getValidAccessToken();
22
22
  d = { ...d, Authorization: `Bearer ${c}` };
23
23
  }
24
- const T = new AbortController(), P = setTimeout(() => T.abort(), l);
24
+ const T = new AbortController(), R = setTimeout(() => T.abort(), l);
25
25
  try {
26
26
  const c = await fetch(a, {
27
27
  method: e,
@@ -29,12 +29,12 @@ class de {
29
29
  body: n ? JSON.stringify(n) : void 0,
30
30
  signal: T.signal
31
31
  });
32
- if (clearTimeout(P), !c.ok)
32
+ if (clearTimeout(R), !c.ok)
33
33
  throw new Error(`HTTP ${c.status}: ${c.statusText}`);
34
- const k = c.headers.get("content-type");
35
- return !k || !k.includes("application/json") ? {} : await c.json();
34
+ const S = c.headers.get("content-type");
35
+ return !S || !S.includes("application/json") ? {} : await c.json();
36
36
  } catch (c) {
37
- throw clearTimeout(P), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${l}ms`) : c;
37
+ throw clearTimeout(R), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${l}ms`) : c;
38
38
  }
39
39
  }
40
40
  async get(e, t) {
@@ -50,7 +50,7 @@ class de {
50
50
  return this.executeRequest("DELETE", e, void 0, t);
51
51
  }
52
52
  }
53
- function le(r) {
53
+ function ce(r) {
54
54
  if (!r) return "";
55
55
  const e = new URLSearchParams();
56
56
  for (const [n, i] of Object.entries(r))
@@ -58,7 +58,7 @@ function le(r) {
58
58
  const t = e.toString();
59
59
  return t ? `?${t}` : "";
60
60
  }
61
- class Ge {
61
+ class Je {
62
62
  constructor(e) {
63
63
  this.httpService = e;
64
64
  }
@@ -67,7 +67,7 @@ class Ge {
67
67
  }
68
68
  async getApps(e) {
69
69
  const t = await this.httpService.get(
70
- `/apps/${le(e)}`
70
+ `/apps/${ce(e)}`
71
71
  );
72
72
  return { apps: t.data, meta: t.meta };
73
73
  }
@@ -98,27 +98,27 @@ class Ge {
98
98
  return (await this.httpService.get(`/apps/${e}/export-config`)).data;
99
99
  }
100
100
  }
101
- const De = pe(null), mt = 5 * 60 * 1e3;
102
- function lr({ config: r, children: e }) {
103
- var S, m, g;
104
- const { appId: t, baseUrl: n } = r, i = ((S = r.cache) == null ? void 0 : S.enabled) ?? !0, a = ((m = r.cache) == null ? void 0 : m.ttl) ?? mt, l = ((g = r.cache) == null ? void 0 : g.storageKey) ?? `app_cache_${t}`, [d, T] = N(() => {
101
+ const $e = fe(null), Tt = 5 * 60 * 1e3;
102
+ function Sr({ config: r, children: e }) {
103
+ var k, m, g;
104
+ const { appId: t, baseUrl: n } = r, i = ((k = r.cache) == null ? void 0 : k.enabled) ?? !0, a = ((m = r.cache) == null ? void 0 : m.ttl) ?? Tt, l = ((g = r.cache) == null ? void 0 : g.storageKey) ?? `app_cache_${t}`, [d, T] = N(() => {
105
105
  if (!i) return null;
106
106
  try {
107
107
  const b = localStorage.getItem(l);
108
108
  if (!b) return null;
109
- const D = JSON.parse(b);
110
- return Date.now() - D.timestamp < a && D.appId === t ? D.data : (localStorage.removeItem(l), null);
109
+ const C = JSON.parse(b);
110
+ return Date.now() - C.timestamp < a && C.appId === t ? C.data : (localStorage.removeItem(l), null);
111
111
  } catch {
112
112
  return null;
113
113
  }
114
- }), [P, c] = N(!d), [k, h] = N(null), E = ke(d);
115
- E.current = d;
116
- const R = re(
114
+ }), [R, c] = N(!d), [S, h] = N(null), x = Ee(d);
115
+ x.current = d;
116
+ const P = te(
117
117
  async (b = !1) => {
118
- if (!(!b && i && E.current))
118
+ if (!(!b && i && x.current))
119
119
  try {
120
120
  c(!0), h(null);
121
- const o = await new Ge(new de(n)).getPublicAppInfo(t);
121
+ const o = await new Je(new he(n)).getPublicAppInfo(t);
122
122
  if (T(o), i)
123
123
  try {
124
124
  const p = {
@@ -130,60 +130,60 @@ function lr({ config: r, children: e }) {
130
130
  } catch (p) {
131
131
  process.env.NODE_ENV === "development" && console.warn("[AppProvider] Failed to cache app info:", p);
132
132
  }
133
- } catch (D) {
134
- const o = D instanceof Error ? D : new Error("Failed to load app information");
133
+ } catch (C) {
134
+ const o = C instanceof Error ? C : new Error("Failed to load app information");
135
135
  h(o), T(null);
136
136
  } finally {
137
137
  c(!1);
138
138
  }
139
139
  },
140
140
  [n, t, i, l]
141
- ), I = re(async () => {
142
- if (!(!i || !E.current))
141
+ ), I = te(async () => {
142
+ if (!(!i || !x.current))
143
143
  try {
144
144
  const b = localStorage.getItem(l);
145
145
  if (!b) return;
146
- const D = JSON.parse(b);
147
- if (Date.now() - D.timestamp <= a * 0.5) return;
148
- const p = await new Ge(new de(n)).getPublicAppInfo(t);
146
+ const C = JSON.parse(b);
147
+ if (Date.now() - C.timestamp <= a * 0.5) return;
148
+ const p = await new Je(new he(n)).getPublicAppInfo(t);
149
149
  T(p);
150
- const x = {
150
+ const E = {
151
151
  data: p,
152
152
  timestamp: Date.now(),
153
153
  appId: t
154
154
  };
155
- localStorage.setItem(l, JSON.stringify(x));
155
+ localStorage.setItem(l, JSON.stringify(E));
156
156
  } catch (b) {
157
157
  process.env.NODE_ENV === "development" && console.warn("[AppProvider] Background app refresh failed:", b);
158
158
  }
159
- }, [n, t, i, a, l]), A = q(
159
+ }, [n, t, i, a, l]), A = V(
160
160
  () => ({
161
161
  appId: t,
162
162
  baseUrl: n,
163
163
  appInfo: d,
164
- isAppLoading: P,
165
- appError: k,
164
+ isAppLoading: R,
165
+ appError: S,
166
166
  retryApp: () => {
167
- R(!0);
167
+ P(!0);
168
168
  }
169
169
  }),
170
- [t, n, d, P, k, R]
170
+ [t, n, d, R, S, P]
171
171
  );
172
- return ne(() => {
173
- E.current ? I() : R();
174
- }, []), /* @__PURE__ */ s(De.Provider, { value: A, children: e });
172
+ return re(() => {
173
+ x.current ? I() : P();
174
+ }, []), /* @__PURE__ */ s($e.Provider, { value: A, children: e });
175
175
  }
176
- function xe() {
177
- const r = se(De);
176
+ function Re() {
177
+ const r = ne($e);
178
178
  if (!r)
179
179
  throw new Error("useApp must be used within an AppProvider");
180
180
  return r;
181
181
  }
182
- function Ce() {
183
- return se(De);
182
+ function Ue() {
183
+ return ne($e);
184
184
  }
185
- const cr = xe;
186
- class te extends Error {
185
+ const kr = Re;
186
+ class ee extends Error {
187
187
  constructor(e, t) {
188
188
  const n = {
189
189
  token_expired: "Refresh token has expired",
@@ -193,21 +193,111 @@ class te extends Error {
193
193
  super(t || n[e]), this.name = "SessionExpiredError", this.reason = e;
194
194
  }
195
195
  }
196
- class gt extends Error {
196
+ class St extends Error {
197
197
  constructor(e) {
198
198
  super(`Token refresh timed out after ${e}ms`), this.name = "TokenRefreshTimeoutError", this.timeoutMs = e;
199
199
  }
200
200
  }
201
- class yt extends Error {
201
+ class kt extends Error {
202
202
  constructor(e, t) {
203
203
  super(
204
204
  `Token refresh failed after ${e} attempts: ${(t == null ? void 0 : t.message) || "Unknown error"}`
205
205
  ), this.name = "TokenRefreshError", this.attempts = e, this.lastError = t;
206
206
  }
207
207
  }
208
- const K = class K {
208
+ class oe extends Error {
209
+ constructor(e, t, n) {
210
+ super(`Invalid configuration "${e}": ${n} (received: ${Et(t)})`), this.name = "ConfigurationError", this.field = e, this.received = t;
211
+ }
212
+ }
213
+ function Et(r) {
214
+ if (r === void 0) return "undefined";
215
+ try {
216
+ const e = JSON.stringify(r);
217
+ return e === void 0 ? typeof r : e.length > 50 ? `${e.slice(0, 47)}...` : e;
218
+ } catch {
219
+ return typeof r;
220
+ }
221
+ }
222
+ function Ze(r) {
223
+ return JSON.parse(atob(r.replace(/-/g, "+").replace(/_/g, "/")));
224
+ }
225
+ function Ae(r) {
226
+ const e = r.split(".");
227
+ if (e.length !== 3) return null;
228
+ try {
229
+ return { header: Ze(e[0]), payload: Ze(e[1]) };
230
+ } catch {
231
+ return null;
232
+ }
233
+ }
234
+ function Ke(r) {
235
+ const e = Ae(r), t = e == null ? void 0 : e.payload.exp;
236
+ return typeof t == "number" ? t * 1e3 : void 0;
237
+ }
238
+ function xt(r, e) {
239
+ var n;
240
+ const t = (n = Ae(r)) == null ? void 0 : n.payload[e];
241
+ return typeof t == "string" ? t : void 0;
242
+ }
243
+ const Rt = /^(javascript|data|vbscript|file):/i, At = /^https?:\/\//i;
244
+ function Pt(r, e = "baseUrl") {
245
+ if (!(r == null || r === "")) {
246
+ if (typeof r != "string")
247
+ throw new oe(e, r, "must be a string");
248
+ if (Rt.test(r))
249
+ throw new oe(e, r, "dangerous URL scheme is not allowed");
250
+ if (!At.test(r))
251
+ throw new oe(e, r, "must start with http:// or https://");
252
+ }
253
+ }
254
+ function ge(r, e, t = {}) {
255
+ if (e === void 0) return;
256
+ if (typeof e != "number" || !Number.isFinite(e))
257
+ throw new oe(r, e, "must be a finite number");
258
+ const { min: n = 0, max: i = Number.MAX_SAFE_INTEGER } = t;
259
+ if (e < n)
260
+ throw new oe(r, e, `must be >= ${n}`);
261
+ if (e > i)
262
+ throw new oe(r, e, `must be <= ${i}`);
263
+ }
264
+ function Ye(r, e) {
265
+ if (e !== void 0 && typeof e != "boolean")
266
+ throw new oe(r, e, "must be a boolean");
267
+ }
268
+ function It(r, e = "accessToken") {
269
+ if (typeof r != "string" || r.length === 0)
270
+ throw new oe(e, r, "must be a non-empty string");
271
+ if (!r.includes(".")) return;
272
+ const t = r.split(".");
273
+ if (t.length !== 3)
274
+ throw new oe(
275
+ e,
276
+ `<${t.length}-segment token>`,
277
+ "JWT must have exactly 3 segments (header.payload.signature)"
278
+ );
279
+ if (Ae(r) === null)
280
+ throw new oe(
281
+ e,
282
+ "<malformed JWT>",
283
+ "JWT header or payload is not valid base64url-encoded JSON"
284
+ );
285
+ }
286
+ function Lt(r) {
287
+ if (r !== void 0 && (typeof r != "number" || !Number.isFinite(r) || r <= 0))
288
+ throw new oe("expiresIn", r, "must be a finite positive number (seconds)");
289
+ }
290
+ function Ft(r) {
291
+ if (r !== void 0 && (typeof r != "number" || !Number.isFinite(r) || r <= 0))
292
+ throw new oe(
293
+ "expiresAt",
294
+ r,
295
+ "must be a finite positive timestamp (ms since epoch)"
296
+ );
297
+ }
298
+ const ie = class ie {
209
299
  constructor(e = {}) {
210
- this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, this.consecutiveBackgroundFailures = 0, 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.enableCookieSession = e.enableCookieSession ?? !1, 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();
300
+ this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, this.consecutiveBackgroundFailures = 0, this.memoryStore = null, this.visibilityListener = null, ie.validateConfig(e), 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.enableCookieSession = e.enableCookieSession ?? !1, 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.attachVisibilityListener(), this.scheduleProactiveRefresh();
211
301
  }
212
302
  /**
213
303
  * Get or create a SessionManager instance for the given config.
@@ -215,69 +305,95 @@ const K = class K {
215
305
  * Mutable config (callbacks, baseUrl) is updated on the existing instance.
216
306
  */
217
307
  static getInstance(e = {}) {
218
- const t = K.resolveStorageKey(e), n = K.instances.get(t);
308
+ const t = ie.resolveStorageKey(e), n = ie.instances.get(t);
219
309
  if (n)
220
310
  return n.updateConfig(e), n;
221
- const i = new K(e);
222
- return K.instances.set(t, i), i;
311
+ const i = new ie(e);
312
+ return ie.instances.set(t, i), i;
223
313
  }
224
314
  /** Reset all singleton instances. For testing only. */
225
315
  static resetAllInstances() {
226
- for (const e of K.instances.values())
316
+ for (const e of ie.instances.values())
227
317
  e.destroy();
228
- K.instances.clear();
318
+ ie.instances.clear();
229
319
  }
230
320
  static resolveStorageKey(e) {
231
321
  return e.storageKey || "auth_tokens";
232
322
  }
323
+ static validateConfig(e) {
324
+ Pt(e.baseUrl), Ye("enableCookieSession", e.enableCookieSession), Ye("autoRefresh", e.autoRefresh), ge("refreshThreshold", e.refreshThreshold, { min: 0 }), ge("proactiveRefreshMargin", e.proactiveRefreshMargin, { min: 0 }), ge("refreshQueueTimeout", e.refreshQueueTimeout, { min: 1 }), ge("maxRefreshRetries", e.maxRefreshRetries, { min: 0 }), ge("retryBackoffBase", e.retryBackoffBase, { min: 1 });
325
+ }
233
326
  /** Update mutable config (callbacks, baseUrl) on an existing instance. */
234
327
  updateConfig(e) {
235
328
  e.onSessionExpired !== void 0 && (this.onSessionExpired = e.onSessionExpired), e.onRefreshFailed !== void 0 && (this.onRefreshFailed = e.onRefreshFailed), e.baseUrl && (this.baseUrl = e.baseUrl), e.enableCookieSession !== void 0 && (this.enableCookieSession = e.enableCookieSession);
236
329
  }
237
- // --- Storage helpers ---
238
330
  createTokenStorage(e) {
239
- return {
331
+ return ie.probeLocalStorage() || this.activateMemoryFallback(), {
240
332
  get: () => {
333
+ const t = this.storageGet(e);
334
+ if (!t) return null;
241
335
  try {
242
- const t = localStorage.getItem(e);
243
- return t ? JSON.parse(t) : null;
336
+ return JSON.parse(t);
244
337
  } catch {
245
338
  return null;
246
339
  }
247
340
  },
248
341
  set: (t) => {
249
- try {
250
- localStorage.setItem(e, JSON.stringify(t));
251
- } catch {
252
- }
342
+ this.storageSet(e, JSON.stringify(t));
253
343
  },
254
344
  clear: () => {
255
- try {
256
- localStorage.removeItem(e);
257
- } catch {
258
- }
345
+ this.storageRemove(e);
259
346
  }
260
347
  };
261
348
  }
262
- // --- Token CRUD ---
263
- static decodeJwtPayload(e) {
349
+ static probeLocalStorage() {
350
+ if (typeof localStorage > "u") return !1;
264
351
  try {
265
- const t = e.split(".");
266
- return t.length !== 3 ? null : JSON.parse(atob(t[1].replace(/-/g, "+").replace(/_/g, "/")));
352
+ return localStorage.setItem("__sm_probe__", "1"), localStorage.removeItem("__sm_probe__"), !0;
267
353
  } catch {
268
- return null;
354
+ return !1;
269
355
  }
270
356
  }
271
- static extractJwtExpiry(e) {
272
- const t = K.decodeJwtPayload(e);
273
- return typeof (t == null ? void 0 : t.exp) == "number" ? t.exp * 1e3 : void 0;
357
+ activateMemoryFallback() {
358
+ return this.memoryStore || (this.memoryStore = /* @__PURE__ */ new Map(), process.env.NODE_ENV === "development" && console.warn(
359
+ "[SessionManager] localStorage unavailable falling back to in-memory session. Cross-tab and reload persistence are lost."
360
+ )), this.memoryStore;
361
+ }
362
+ storageGet(e) {
363
+ if (this.memoryStore) return this.memoryStore.get(e) ?? null;
364
+ try {
365
+ return localStorage.getItem(e);
366
+ } catch {
367
+ return this.activateMemoryFallback().get(e) ?? null;
368
+ }
274
369
  }
275
- static extractJwtClaim(e, t) {
276
- const n = K.decodeJwtPayload(e), i = n == null ? void 0 : n[t];
277
- return typeof i == "string" ? i : void 0;
370
+ storageSet(e, t) {
371
+ if (this.memoryStore) {
372
+ this.memoryStore.set(e, t);
373
+ return;
374
+ }
375
+ try {
376
+ localStorage.setItem(e, t);
377
+ } catch {
378
+ this.activateMemoryFallback().set(e, t);
379
+ }
278
380
  }
381
+ storageRemove(e) {
382
+ if (this.memoryStore) {
383
+ this.memoryStore.delete(e);
384
+ return;
385
+ }
386
+ try {
387
+ localStorage.removeItem(e);
388
+ } catch {
389
+ }
390
+ }
391
+ // --- Token CRUD ---
279
392
  setTokens(e) {
280
- const t = e.expiresAt || (e.expiresIn ? Date.now() + e.expiresIn * 1e3 : void 0) || K.extractJwtExpiry(e.accessToken), n = {
393
+ if (It(e.accessToken, "accessToken"), e.refreshToken !== void 0 && typeof e.refreshToken != "string")
394
+ throw new oe("refreshToken", e.refreshToken, "must be a string");
395
+ Lt(e.expiresIn), Ft(e.expiresAt);
396
+ const t = e.expiresAt || (e.expiresIn ? Date.now() + e.expiresIn * 1e3 : void 0) || Ke(e.accessToken), n = {
281
397
  ...e,
282
398
  expiresAt: t
283
399
  }, i = this.tokenStorage.get() || {};
@@ -287,7 +403,7 @@ const K = class K {
287
403
  const { accessToken: e, refreshToken: t, expiresAt: n, expiresIn: i, tokenType: a } = this.tokenStorage.get() || {};
288
404
  if (!e)
289
405
  return null;
290
- const l = n || K.extractJwtExpiry(e);
406
+ const l = n || Ke(e);
291
407
  return {
292
408
  accessToken: e,
293
409
  refreshToken: t,
@@ -328,6 +444,26 @@ const K = class K {
328
444
  cancelProactiveTimer() {
329
445
  this.proactiveTimerId !== null && (clearTimeout(this.proactiveTimerId), this.proactiveTimerId = null), this.backgroundRetryTimerId !== null && (clearTimeout(this.backgroundRetryTimerId), this.backgroundRetryTimerId = null);
330
446
  }
447
+ attachVisibilityListener() {
448
+ if (!this.visibilityListener && !(typeof document > "u" || typeof document.addEventListener != "function")) {
449
+ this.visibilityListener = () => {
450
+ document.visibilityState !== "visible" || this.isDestroyed || this.scheduleProactiveRefresh();
451
+ };
452
+ try {
453
+ document.addEventListener("visibilitychange", this.visibilityListener);
454
+ } catch {
455
+ this.visibilityListener = null;
456
+ }
457
+ }
458
+ }
459
+ detachVisibilityListener() {
460
+ if (this.visibilityListener && typeof document < "u")
461
+ try {
462
+ document.removeEventListener("visibilitychange", this.visibilityListener);
463
+ } catch {
464
+ }
465
+ this.visibilityListener = null;
466
+ }
331
467
  backgroundRefresh() {
332
468
  if (this.isDestroyed) return;
333
469
  const e = this.getTokens();
@@ -336,13 +472,13 @@ const K = class K {
336
472
  this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
337
473
  this.consecutiveBackgroundFailures = 0;
338
474
  }).catch((n) => {
339
- if (!(n instanceof te)) {
475
+ if (!(n instanceof ee)) {
340
476
  if (this.sessionGeneration === t) {
341
- if (this.consecutiveBackgroundFailures++, this.consecutiveBackgroundFailures >= K.MAX_BACKGROUND_FAILURES) {
477
+ if (this.consecutiveBackgroundFailures++, this.consecutiveBackgroundFailures >= ie.MAX_BACKGROUND_FAILURES) {
342
478
  process.env.NODE_ENV === "development" && console.error(
343
479
  `[SessionManager] Background refresh failed ${this.consecutiveBackgroundFailures} consecutive times — expiring session`
344
480
  ), this.consecutiveBackgroundFailures = 0, this.handleSessionExpired(
345
- new te("token_invalid", "Background refresh failed repeatedly")
481
+ new ee("token_invalid", "Background refresh failed repeatedly")
346
482
  );
347
483
  return;
348
484
  }
@@ -409,13 +545,13 @@ const K = class K {
409
545
  async getValidAccessToken() {
410
546
  const e = this.getTokens();
411
547
  if (!(e != null && e.accessToken)) {
412
- const t = new te("token_invalid", "No tokens available");
548
+ const t = new ee("token_invalid", "No tokens available");
413
549
  throw this.handleSessionExpired(t), t;
414
550
  }
415
551
  if (!this.shouldRefreshToken(e) && !this.isTokenExpired(e))
416
552
  return e.accessToken;
417
553
  if (!e.refreshToken) {
418
- const t = new te("token_invalid", "No refresh token available");
554
+ const t = new ee("token_invalid", "No refresh token available");
419
555
  throw this.handleSessionExpired(t), t;
420
556
  }
421
557
  return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken);
@@ -427,14 +563,14 @@ const K = class K {
427
563
  try {
428
564
  return { Authorization: `Bearer ${await this.getValidAccessToken()}` };
429
565
  } catch (e) {
430
- return e instanceof te && this.onRefreshFailed && this.onRefreshFailed(), {};
566
+ return e instanceof ee && this.onRefreshFailed && this.onRefreshFailed(), {};
431
567
  }
432
568
  }
433
569
  enqueueForToken() {
434
570
  return new Promise((e, t) => {
435
571
  const n = setTimeout(() => {
436
572
  const i = this.refreshQueue.findIndex((a) => a.timeoutId === n);
437
- i !== -1 && this.refreshQueue.splice(i, 1), t(new gt(this.refreshQueueTimeout));
573
+ i !== -1 && this.refreshQueue.splice(i, 1), t(new St(this.refreshQueueTimeout));
438
574
  }, this.refreshQueueTimeout);
439
575
  this.refreshQueue.push({ resolve: e, reject: t, timeoutId: n });
440
576
  });
@@ -447,7 +583,7 @@ const K = class K {
447
583
  return this.resolveQueue(n), n;
448
584
  } catch (t) {
449
585
  const n = t instanceof Error ? t : new Error("Token refresh failed");
450
- throw n instanceof te ? (this.rejectQueue(n), this.handleSessionExpired(n)) : this.rejectQueue(n), n;
586
+ throw n instanceof ee ? (this.rejectQueue(n), this.handleSessionExpired(n)) : this.rejectQueue(n), n;
451
587
  } finally {
452
588
  this.refreshPromise = null;
453
589
  }
@@ -470,13 +606,13 @@ const K = class K {
470
606
  const n = this.sessionGeneration;
471
607
  for (let i = 0; i <= this.maxRefreshRetries; i++) {
472
608
  if (this.sessionGeneration !== n)
473
- throw new te("token_invalid", "Session cleared during refresh");
609
+ throw new ee("token_invalid", "Session cleared during refresh");
474
610
  try {
475
611
  await this.performTokenRefresh(e, n);
476
612
  return;
477
613
  } catch (a) {
478
614
  const l = a instanceof Error ? a : new Error(String(a));
479
- if (l instanceof te)
615
+ if (l instanceof ee)
480
616
  throw l;
481
617
  if (t = l, i < this.maxRefreshRetries) {
482
618
  const d = this.retryBackoffBase * Math.pow(2, i);
@@ -484,7 +620,7 @@ const K = class K {
484
620
  }
485
621
  }
486
622
  }
487
- throw new yt(this.maxRefreshRetries + 1, t);
623
+ throw new kt(this.maxRefreshRetries + 1, t);
488
624
  }
489
625
  /**
490
626
  * Single refresh attempt with error classification.
@@ -503,7 +639,7 @@ const K = class K {
503
639
  const n = this.getTokens();
504
640
  if (n != null && n.accessToken && !this.isTokenExpired(n) && !this.shouldRefreshToken(n))
505
641
  return;
506
- const i = (n == null ? void 0 : n.refreshToken) || e, a = `${this.baseUrl}/auth/refresh`, l = K.extractJwtClaim(i, "deviceId"), d = { refreshToken: i };
642
+ const i = (n == null ? void 0 : n.refreshToken) || e, a = `${this.baseUrl}/auth/refresh`, l = xt(i, "deviceId"), d = { refreshToken: i };
507
643
  l && (d.deviceId = l);
508
644
  let T;
509
645
  try {
@@ -519,20 +655,20 @@ const K = class K {
519
655
  if (!T.ok) {
520
656
  let c = "";
521
657
  try {
522
- const k = await T.json();
523
- c = (k.message || k.error || "").toLowerCase();
658
+ const S = await T.json();
659
+ c = (S.message || S.error || "").toLowerCase();
524
660
  } catch {
525
661
  c = T.statusText.toLowerCase();
526
662
  }
527
- throw T.status === 401 ? c.includes("expired") ? new te("token_expired") : c.includes("invalid") ? new te("token_invalid") : new te("token_invalid", `Unauthorized: ${c}`) : T.status === 400 ? c.includes("inactive") ? new te("user_inactive") : c.includes("expired") || c.includes("invalid") ? new te("token_invalid", c) : c.includes("reuse") || c.includes("revoked") ? new te("token_invalid", c) : new Error(`Token refresh failed (400): ${c}`) : new Error(`Token refresh failed: ${T.status} ${c}`);
663
+ throw T.status === 401 ? c.includes("expired") ? new ee("token_expired") : c.includes("invalid") ? new ee("token_invalid") : new ee("token_invalid", `Unauthorized: ${c}`) : T.status === 400 ? c.includes("inactive") ? new ee("user_inactive") : c.includes("expired") || c.includes("invalid") ? new ee("token_invalid", c) : c.includes("reuse") || c.includes("revoked") ? new ee("token_invalid", c) : new Error(`Token refresh failed (400): ${c}`) : new Error(`Token refresh failed: ${T.status} ${c}`);
528
664
  }
529
665
  if (this.sessionGeneration !== t)
530
- throw new te("token_invalid", "Session cleared during refresh");
531
- const P = await T.json();
666
+ throw new ee("token_invalid", "Session cleared during refresh");
667
+ const R = await T.json();
532
668
  this.setTokens({
533
- accessToken: P.accessToken,
534
- refreshToken: P.refreshToken || i,
535
- expiresIn: P.expiresIn
669
+ accessToken: R.accessToken,
670
+ refreshToken: R.refreshToken || i,
671
+ expiresIn: R.expiresIn
536
672
  });
537
673
  }
538
674
  // --- Session expiry handler ---
@@ -555,7 +691,7 @@ const K = class K {
555
691
  // --- Session lifecycle ---
556
692
  clearSession() {
557
693
  this.sessionGeneration++, this.cancelProactiveTimer(), this.clearTokens();
558
- const e = new te("token_invalid", "Session cleared");
694
+ const e = new ee("token_invalid", "Session cleared");
559
695
  this.rejectQueue(e);
560
696
  }
561
697
  /**
@@ -563,15 +699,15 @@ const K = class K {
563
699
  * Cancels all timers and rejects pending queue entries.
564
700
  */
565
701
  destroy() {
566
- this.isDestroyed = !0, K.instances.delete(this.storageKey), this.cancelProactiveTimer();
567
- const e = new te("token_invalid", "SessionManager destroyed");
702
+ this.isDestroyed = !0, ie.instances.delete(this.storageKey), this.cancelProactiveTimer(), this.detachVisibilityListener();
703
+ const e = new ee("token_invalid", "SessionManager destroyed");
568
704
  this.rejectQueue(e);
569
705
  }
570
706
  // --- JWT helpers ---
571
707
  getTokenPayload() {
572
- var t;
708
+ var t, n;
573
709
  const e = (t = this.getTokens()) == null ? void 0 : t.accessToken;
574
- return e ? K.decodeJwtPayload(e) ?? null : null;
710
+ return e ? ((n = Ae(e)) == null ? void 0 : n.payload) ?? null : null;
575
711
  }
576
712
  /**
577
713
  * Get userId from token (source of truth) or fallback to stored user
@@ -591,11 +727,11 @@ const K = class K {
591
727
  return new Promise((t) => setTimeout(t, e));
592
728
  }
593
729
  };
594
- K.instances = /* @__PURE__ */ new Map(), K.MAX_BACKGROUND_FAILURES = 3;
595
- let Ne = K;
596
- class bt {
730
+ ie.instances = /* @__PURE__ */ new Map(), ie.MAX_BACKGROUND_FAILURES = 3;
731
+ let Me = ie;
732
+ class Nt {
597
733
  constructor(e) {
598
- this.httpService = e, this.pendingVerifications = /* @__PURE__ */ new Map();
734
+ this.httpService = e, this.pendingVerifications = /* @__PURE__ */ new Map(), this.pendingMagicLinks = /* @__PURE__ */ new Map();
599
735
  }
600
736
  // Public endpoints - no auth required
601
737
  async login(e) {
@@ -626,10 +762,17 @@ class bt {
626
762
  await this.httpService.post("/auth/password-reset/request", e);
627
763
  }
628
764
  async sendMagicLink(e) {
629
- return await this.httpService.post(
630
- "/auth/magic-link/send",
631
- e
632
- );
765
+ const t = JSON.stringify([
766
+ e.email,
767
+ e.tenantId,
768
+ e.appId ?? "",
769
+ e.frontendUrl ?? ""
770
+ ]), n = this.pendingMagicLinks.get(t);
771
+ if (n) return n;
772
+ const i = this.httpService.post("/auth/magic-link/send", e).finally(() => {
773
+ this.pendingMagicLinks.delete(t);
774
+ });
775
+ return this.pendingMagicLinks.set(t, i), i;
633
776
  }
634
777
  async verifyMagicLink(e) {
635
778
  const t = e.token, n = this.pendingVerifications.get(t);
@@ -646,7 +789,7 @@ class bt {
646
789
  await this.httpService.post("/auth/change-password", e);
647
790
  }
648
791
  }
649
- class wt {
792
+ class Ct {
650
793
  constructor(e) {
651
794
  this.httpService = e;
652
795
  }
@@ -664,7 +807,7 @@ class wt {
664
807
  }
665
808
  async getRolesByApp(e, t) {
666
809
  const n = await this.httpService.get(
667
- `/roles/app/${e}${le(t)}`,
810
+ `/roles/app/${e}${ce(t)}`,
668
811
  { skipAuth: !0 }
669
812
  );
670
813
  return { roles: n.data, meta: n.meta };
@@ -677,12 +820,12 @@ class wt {
677
820
  }
678
821
  async getUserRoles(e, t) {
679
822
  const n = await this.httpService.get(
680
- `/roles/user/${e}${le(t)}`
823
+ `/roles/user/${e}${ce(t)}`
681
824
  );
682
825
  return { roles: n.data, meta: n.meta };
683
826
  }
684
827
  }
685
- class vt {
828
+ class Dt {
686
829
  constructor(e) {
687
830
  this.httpService = e;
688
831
  }
@@ -691,7 +834,7 @@ class vt {
691
834
  }
692
835
  async getUsers(e) {
693
836
  const t = await this.httpService.get(
694
- `/users/${le(e)}`
837
+ `/users/${ce(e)}`
695
838
  );
696
839
  return { users: t.data, meta: t.meta };
697
840
  }
@@ -705,7 +848,7 @@ class vt {
705
848
  await this.httpService.delete(`/users/${e}`);
706
849
  }
707
850
  }
708
- class me {
851
+ class ye {
709
852
  constructor(e, t) {
710
853
  this.httpService = e, this.appId = t;
711
854
  }
@@ -714,7 +857,7 @@ class me {
714
857
  }
715
858
  async getTenants(e) {
716
859
  const t = await this.httpService.get(
717
- `/tenants/${le(e)}`
860
+ `/tenants/${ce(e)}`
718
861
  );
719
862
  return { tenants: t.data, meta: t.meta };
720
863
  }
@@ -749,7 +892,7 @@ class me {
749
892
  )).data;
750
893
  }
751
894
  }
752
- function Tt(r, e) {
895
+ function Mt(r, e) {
753
896
  if (r === "localhost" || r.startsWith("127.") || r.startsWith("192.168."))
754
897
  return null;
755
898
  if (e) {
@@ -765,24 +908,24 @@ function Tt(r, e) {
765
908
  const n = r.split(".");
766
909
  return n.length >= 3 && n[0] !== "www" ? n[0] : null;
767
910
  }
768
- function kt(r, e = "tenant", t) {
911
+ function $t(r, e = "tenant", t) {
769
912
  const i = new URLSearchParams(r).get(e);
770
913
  return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
771
914
  }
772
- function St(r, e, t) {
915
+ function Ut(r, e, t) {
773
916
  const { tenantMode: n, baseDomain: i, selectorParam: a, fixedTenantSlug: l } = r;
774
- return n === "fixed" ? l || null : n === "subdomain" ? Tt(e.hostname, i) : n === "selector" ? kt(e.search, a, t) : null;
917
+ return n === "fixed" ? l || null : n === "subdomain" ? Mt(e.hostname, i) : n === "selector" ? $t(e.search, a, t) : null;
775
918
  }
776
- function xt(r, e, t) {
919
+ function Bt(r, e, t) {
777
920
  if (t)
778
921
  return `${r}.${t}`;
779
922
  const n = e.split(".");
780
923
  return n.length === 2 ? `${r}.${e}` : n.length >= 3 ? (n[0] = r, n.join(".")) : null;
781
924
  }
782
- const Ue = pe(null);
783
- function ur({ config: r, children: e }) {
925
+ const Be = fe(null);
926
+ function Er({ config: r, children: e }) {
784
927
  var j, Z, $;
785
- const { baseUrl: t, appInfo: n, appId: i } = xe(), a = re(() => typeof window > "u" ? null : St(
928
+ const { baseUrl: t, appInfo: n, appId: i } = Re(), a = te(() => typeof window > "u" ? null : Ut(
786
929
  {
787
930
  tenantMode: r.tenantMode || "selector",
788
931
  baseDomain: r.baseDomain,
@@ -794,111 +937,111 @@ function ur({ config: r, children: e }) {
794
937
  search: window.location.search
795
938
  },
796
939
  window.localStorage
797
- ), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [l, d] = N(() => a()), T = ((j = r.cache) == null ? void 0 : j.enabled) ?? !0, P = ((Z = r.cache) == null ? void 0 : Z.ttl) ?? 5 * 60 * 1e3, c = (($ = r.cache) == null ? void 0 : $.storageKey) ?? `tenant_cache_${l || "default"}`, k = q(
798
- () => ({ enabled: T, ttl: P, storageKey: c }),
799
- [T, P, c]
800
- ), [h, E] = N(() => {
940
+ ), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [l, d] = N(() => a()), T = ((j = r.cache) == null ? void 0 : j.enabled) ?? !0, R = ((Z = r.cache) == null ? void 0 : Z.ttl) ?? 5 * 60 * 1e3, c = (($ = r.cache) == null ? void 0 : $.storageKey) ?? `tenant_cache_${l || "default"}`, S = V(
941
+ () => ({ enabled: T, ttl: R, storageKey: c }),
942
+ [T, R, c]
943
+ ), [h, x] = N(() => {
801
944
  if (r.initialTenant) return r.initialTenant;
802
- if (!k.enabled || !l) return null;
945
+ if (!S.enabled || !l) return null;
803
946
  try {
804
- const M = localStorage.getItem(k.storageKey);
805
- if (!M) return null;
806
- const F = JSON.parse(M);
807
- return Date.now() - F.timestamp < k.ttl && F.tenantSlug === l ? F.data : (localStorage.removeItem(k.storageKey), null);
947
+ const U = localStorage.getItem(S.storageKey);
948
+ if (!U) return null;
949
+ const L = JSON.parse(U);
950
+ return Date.now() - L.timestamp < S.ttl && L.tenantSlug === l ? L.data : (localStorage.removeItem(S.storageKey), null);
808
951
  } catch {
809
952
  return null;
810
953
  }
811
- }), [R, I] = N(!h && !r.initialTenant), [A, S] = N(null), [m, g] = N(null), [b, D] = N(!1), [o, p] = N(null);
812
- ne(() => {
954
+ }), [P, I] = N(!h && !r.initialTenant), [A, k] = N(null), [m, g] = N(null), [b, C] = N(!1), [o, p] = N(null);
955
+ re(() => {
813
956
  if (r.tenantMode === "fixed") return;
814
- const M = a();
815
- d(M);
957
+ const U = a();
958
+ d(U);
816
959
  }, [a, r.tenantMode]);
817
- const x = (n == null ? void 0 : n.settingsSchema) || null, y = re(
818
- async (M, F = !1) => {
819
- if (!(!F && k.enabled && h && h.subdomain === M))
960
+ const E = (n == null ? void 0 : n.settingsSchema) || null, y = te(
961
+ async (U, L = !1) => {
962
+ if (!(!L && S.enabled && h && h.subdomain === U))
820
963
  try {
821
- I(!0), S(null);
822
- const V = new de(t), W = await new me(V, i).getPublicTenantInfo(M);
823
- if (E(W), k.enabled)
964
+ I(!0), k(null);
965
+ const q = new he(t), W = await new ye(q, i).getPublicTenantInfo(U);
966
+ if (x(W), S.enabled)
824
967
  try {
825
- const Y = {
968
+ const K = {
826
969
  data: W,
827
970
  timestamp: Date.now(),
828
- tenantSlug: M
971
+ tenantSlug: U
829
972
  };
830
- localStorage.setItem(k.storageKey, JSON.stringify(Y));
831
- } catch (Y) {
832
- process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", Y);
973
+ localStorage.setItem(S.storageKey, JSON.stringify(K));
974
+ } catch (K) {
975
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", K);
833
976
  }
834
- } catch (V) {
835
- const O = V instanceof Error ? V : new Error("Failed to load tenant information");
836
- S(O), E(null);
977
+ } catch (q) {
978
+ const _ = q instanceof Error ? q : new Error("Failed to load tenant information");
979
+ k(_), x(null);
837
980
  } finally {
838
981
  I(!1);
839
982
  }
840
983
  },
841
- [t, i, k, h]
842
- ), u = re(async () => {
843
- if (!(!k.enabled || !h || !l))
984
+ [t, i, S, h]
985
+ ), u = te(async () => {
986
+ if (!(!S.enabled || !h || !l))
844
987
  try {
845
- const M = localStorage.getItem(k.storageKey);
846
- if (!M) return;
847
- const F = JSON.parse(M);
848
- if (Date.now() - F.timestamp > k.ttl * 0.5) {
849
- const O = new de(t), Y = await new me(O, i).getPublicTenantInfo(l);
850
- E(Y);
851
- const X = {
852
- data: Y,
988
+ const U = localStorage.getItem(S.storageKey);
989
+ if (!U) return;
990
+ const L = JSON.parse(U);
991
+ if (Date.now() - L.timestamp > S.ttl * 0.5) {
992
+ const _ = new he(t), K = await new ye(_, i).getPublicTenantInfo(l);
993
+ x(K);
994
+ const Y = {
995
+ data: K,
853
996
  timestamp: Date.now(),
854
997
  tenantSlug: l
855
998
  };
856
- localStorage.setItem(k.storageKey, JSON.stringify(X));
999
+ localStorage.setItem(S.storageKey, JSON.stringify(Y));
857
1000
  }
858
- } catch (M) {
859
- process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", M);
1001
+ } catch (U) {
1002
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", U);
860
1003
  }
861
- }, [t, i, k, h, l]), v = re(async () => {
1004
+ }, [t, i, S, h, l]), v = te(async () => {
862
1005
  if (h != null && h.id)
863
1006
  try {
864
- D(!0), p(null);
865
- const M = new de(t), V = await new me(M, h.appId).getTenantSettings(h.id);
866
- g(V);
867
- } catch (M) {
868
- const F = M instanceof Error ? M : new Error("Failed to load tenant settings");
869
- p(F), g(null);
1007
+ C(!0), p(null);
1008
+ const U = new he(t), q = await new ye(U, h.appId).getTenantSettings(h.id);
1009
+ g(q);
1010
+ } catch (U) {
1011
+ const L = U instanceof Error ? U : new Error("Failed to load tenant settings");
1012
+ p(L), g(null);
870
1013
  } finally {
871
- D(!1);
1014
+ C(!1);
872
1015
  }
873
- }, [t, h]), C = re(() => {
1016
+ }, [t, h]), D = te(() => {
874
1017
  v();
875
- }, [v]), ie = re(
876
- (M) => {
877
- if (!x)
1018
+ }, [v]), se = te(
1019
+ (U) => {
1020
+ if (!E)
878
1021
  return { isValid: !0, errors: [] };
879
- const F = [];
1022
+ const L = [];
880
1023
  try {
881
- return x.properties && Object.entries(x.properties).forEach(([V, O]) => {
882
- var Y;
883
- const W = M[V];
884
- if ((Y = x.required) != null && Y.includes(V) && W == null) {
885
- F.push(`Field '${V}' is required`);
1024
+ return E.properties && Object.entries(E.properties).forEach(([q, _]) => {
1025
+ var K;
1026
+ const W = U[q];
1027
+ if ((K = E.required) != null && K.includes(q) && W == null) {
1028
+ L.push(`Field '${q}' is required`);
886
1029
  return;
887
1030
  }
888
1031
  if (W != null) {
889
- if (O.type) {
890
- const X = O.type, ae = typeof W;
891
- X === "string" && ae !== "string" ? F.push(`Field '${V}' must be a string`) : (X === "number" || X === "integer") && ae !== "number" ? F.push(`Field '${V}' must be a number`) : X === "boolean" && ae !== "boolean" ? F.push(`Field '${V}' must be a boolean`) : X === "array" && !Array.isArray(W) && F.push(`Field '${V}' must be an array`);
1032
+ if (_.type) {
1033
+ const Y = _.type, le = typeof W;
1034
+ Y === "string" && le !== "string" ? L.push(`Field '${q}' must be a string`) : (Y === "number" || Y === "integer") && le !== "number" ? L.push(`Field '${q}' must be a number`) : Y === "boolean" && le !== "boolean" ? L.push(`Field '${q}' must be a boolean`) : Y === "array" && !Array.isArray(W) && L.push(`Field '${q}' must be an array`);
892
1035
  }
893
- O.minLength !== void 0 && typeof W == "string" && W.length < O.minLength && F.push(
894
- `Field '${V}' must be at least ${O.minLength} characters long`
895
- ), O.maxLength !== void 0 && typeof W == "string" && W.length > O.maxLength && F.push(
896
- `Field '${V}' must be no more than ${O.maxLength} characters long`
897
- ), O.minimum !== void 0 && typeof W == "number" && W < O.minimum && F.push(`Field '${V}' must be at least ${O.minimum}`), O.maximum !== void 0 && typeof W == "number" && W > O.maximum && F.push(`Field '${V}' must be no more than ${O.maximum}`), O.pattern && typeof W == "string" && (new RegExp(O.pattern).test(W) || F.push(`Field '${V}' does not match the required pattern`)), O.enum && !O.enum.includes(W) && F.push(`Field '${V}' must be one of: ${O.enum.join(", ")}`);
1036
+ _.minLength !== void 0 && typeof W == "string" && W.length < _.minLength && L.push(
1037
+ `Field '${q}' must be at least ${_.minLength} characters long`
1038
+ ), _.maxLength !== void 0 && typeof W == "string" && W.length > _.maxLength && L.push(
1039
+ `Field '${q}' must be no more than ${_.maxLength} characters long`
1040
+ ), _.minimum !== void 0 && typeof W == "number" && W < _.minimum && L.push(`Field '${q}' must be at least ${_.minimum}`), _.maximum !== void 0 && typeof W == "number" && W > _.maximum && L.push(`Field '${q}' must be no more than ${_.maximum}`), _.pattern && typeof W == "string" && (new RegExp(_.pattern).test(W) || L.push(`Field '${q}' does not match the required pattern`)), _.enum && !_.enum.includes(W) && L.push(`Field '${q}' must be one of: ${_.enum.join(", ")}`);
898
1041
  }
899
1042
  }), {
900
- isValid: F.length === 0,
901
- errors: F
1043
+ isValid: L.length === 0,
1044
+ errors: L
902
1045
  };
903
1046
  } catch {
904
1047
  return {
@@ -907,98 +1050,98 @@ function ur({ config: r, children: e }) {
907
1050
  };
908
1051
  }
909
1052
  },
910
- [x]
1053
+ [E]
911
1054
  );
912
- ne(() => {
913
- !r.initialTenant && l ? h ? u() : y(l) : !r.initialTenant && !l && (E(null), S(null), I(!1));
914
- }, [r.initialTenant, l, h, y, u]), ne(() => {
915
- h != null && h.id ? v() : (g(null), p(null), D(!1));
1055
+ re(() => {
1056
+ !r.initialTenant && l ? h ? u() : y(l) : !r.initialTenant && !l && (x(null), k(null), I(!1));
1057
+ }, [r.initialTenant, l, h, y, u]), re(() => {
1058
+ h != null && h.id ? v() : (g(null), p(null), C(!1));
916
1059
  }, [h == null ? void 0 : h.id, v]);
917
- const L = re(
918
- (M, F) => {
919
- const { mode: V = "reload", redirectPath: O } = F || {}, W = r.tenantMode || "selector";
1060
+ const F = te(
1061
+ (U, L) => {
1062
+ const { mode: q = "reload", redirectPath: _ } = L || {}, W = r.tenantMode || "selector";
920
1063
  if (W === "fixed") {
921
1064
  process.env.NODE_ENV === "development" && console.warn(
922
1065
  "[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
923
1066
  r.fixedTenantSlug
924
- ), O && (window.location.href = O);
1067
+ ), _ && (window.location.href = _);
925
1068
  return;
926
1069
  }
927
- if (localStorage.setItem("tenant", M), W === "subdomain") {
928
- const Y = window.location.hostname, X = xt(
929
- M,
930
- Y,
1070
+ if (localStorage.setItem("tenant", U), W === "subdomain") {
1071
+ const K = window.location.hostname, Y = Bt(
1072
+ U,
1073
+ K,
931
1074
  r.baseDomain
932
1075
  );
933
- if (!X) {
1076
+ if (!Y) {
934
1077
  process.env.NODE_ENV === "development" && console.warn(
935
1078
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
936
- Y
1079
+ K
937
1080
  );
938
1081
  return;
939
1082
  }
940
- const ae = O || window.location.pathname, we = new URL(`${window.location.protocol}//${X}${ae}`);
941
- new URLSearchParams(window.location.search).forEach((Re, Ie) => {
942
- we.searchParams.set(Ie, Re);
943
- }), window.location.href = we.toString();
1083
+ const le = _ || window.location.pathname, Te = new URL(`${window.location.protocol}//${Y}${le}`);
1084
+ new URLSearchParams(window.location.search).forEach((Fe, Ne) => {
1085
+ Te.searchParams.set(Ne, Fe);
1086
+ }), window.location.href = Te.toString();
944
1087
  } else if (W === "selector") {
945
- const Y = O || window.location.pathname, X = new URLSearchParams(window.location.search);
946
- if (X.set(r.selectorParam || "tenant", M), V === "reload") {
947
- const ae = `${Y}?${X.toString()}${window.location.hash}`;
948
- window.location.href = ae;
1088
+ const K = _ || window.location.pathname, Y = new URLSearchParams(window.location.search);
1089
+ if (Y.set(r.selectorParam || "tenant", U), q === "reload") {
1090
+ const le = `${K}?${Y.toString()}${window.location.hash}`;
1091
+ window.location.href = le;
949
1092
  } else {
950
- const ae = `${Y}?${X.toString()}${window.location.hash}`;
951
- window.history.pushState({}, "", ae), d(M), y(M);
1093
+ const le = `${K}?${Y.toString()}${window.location.hash}`;
1094
+ window.history.pushState({}, "", le), d(U), y(U);
952
1095
  }
953
1096
  }
954
1097
  },
955
1098
  [r.tenantMode, r.selectorParam, r.baseDomain, r.fixedTenantSlug, y]
956
- ), H = q(() => ({
1099
+ ), H = V(() => ({
957
1100
  // Tenant info
958
1101
  tenant: h,
959
1102
  tenantSlug: l,
960
- isTenantLoading: R,
1103
+ isTenantLoading: P,
961
1104
  tenantError: A,
962
1105
  retryTenant: () => {
963
1106
  l && y(l);
964
1107
  },
965
1108
  // Settings
966
1109
  settings: m,
967
- settingsSchema: x,
1110
+ settingsSchema: E,
968
1111
  isSettingsLoading: b,
969
1112
  settingsError: o,
970
1113
  // Actions
971
- refreshSettings: C,
972
- switchTenant: L,
1114
+ refreshSettings: D,
1115
+ switchTenant: F,
973
1116
  // Validation
974
- validateSettings: ie
1117
+ validateSettings: se
975
1118
  }), [
976
1119
  h,
977
1120
  l,
978
- R,
1121
+ P,
979
1122
  A,
980
1123
  m,
981
- x,
1124
+ E,
982
1125
  b,
983
1126
  o,
984
- C,
985
- L,
986
- ie
1127
+ D,
1128
+ F,
1129
+ se
987
1130
  ]);
988
- return /* @__PURE__ */ s(Ue.Provider, { value: H, children: e });
1131
+ return /* @__PURE__ */ s(Be.Provider, { value: H, children: e });
989
1132
  }
990
- function be() {
991
- const r = se(Ue);
1133
+ function ve() {
1134
+ const r = ne(Be);
992
1135
  if (!r)
993
1136
  throw new Error("useTenant must be used within a TenantProvider");
994
1137
  return r;
995
1138
  }
996
- function he() {
997
- return se(Ue);
1139
+ function pe() {
1140
+ return ne(Be);
998
1141
  }
999
- const dr = be;
1000
- function hr() {
1001
- const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = be();
1142
+ const xr = ve;
1143
+ function Rr() {
1144
+ const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = ve();
1002
1145
  return {
1003
1146
  settings: r,
1004
1147
  settingsSchema: e,
@@ -1007,8 +1150,8 @@ function hr() {
1007
1150
  validateSettings: i
1008
1151
  };
1009
1152
  }
1010
- function et() {
1011
- const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } = be();
1153
+ function ot() {
1154
+ const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } = ve();
1012
1155
  return {
1013
1156
  tenant: r,
1014
1157
  tenantSlug: e,
@@ -1017,265 +1160,265 @@ function et() {
1017
1160
  retry: i
1018
1161
  };
1019
1162
  }
1020
- const $e = "userTenants";
1021
- function Et() {
1163
+ const _e = "userTenants";
1164
+ function _t() {
1022
1165
  try {
1023
- const r = localStorage.getItem($e);
1166
+ const r = localStorage.getItem(_e);
1024
1167
  return r ? JSON.parse(r) : [];
1025
1168
  } catch {
1026
1169
  return [];
1027
1170
  }
1028
1171
  }
1029
- function He(r) {
1172
+ function Xe(r) {
1030
1173
  try {
1031
- localStorage.setItem($e, JSON.stringify(r));
1174
+ localStorage.setItem(_e, JSON.stringify(r));
1032
1175
  } catch {
1033
1176
  }
1034
1177
  }
1035
- function Qe() {
1178
+ function et() {
1036
1179
  try {
1037
- localStorage.removeItem($e);
1180
+ localStorage.removeItem(_e);
1038
1181
  } catch {
1039
1182
  }
1040
1183
  }
1041
- const Ee = pe(null), Pe = pe(null);
1042
- function pr({ config: r = {}, children: e }) {
1043
- const t = Ce(), n = he(), i = (t == null ? void 0 : t.baseUrl) ?? r.baseUrl ?? "", a = (t == null ? void 0 : t.appId) ?? r.appId, l = (n == null ? void 0 : n.tenant) ?? null, d = (n == null ? void 0 : n.tenantSlug) ?? null, T = (n == null ? void 0 : n.switchTenant) ?? (() => {
1184
+ const Pe = fe(null), Ie = fe(null);
1185
+ function Ar({ config: r = {}, children: e }) {
1186
+ const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? r.baseUrl ?? "", a = (t == null ? void 0 : t.appId) ?? r.appId, l = (n == null ? void 0 : n.tenant) ?? null, d = (n == null ? void 0 : n.tenantSlug) ?? null, T = (n == null ? void 0 : n.switchTenant) ?? (() => {
1044
1187
  });
1045
1188
  if (!i)
1046
1189
  throw new Error(
1047
1190
  "[AuthProvider] baseUrl is required. Provide it via AppProvider or AuthConfig.baseUrl."
1048
1191
  );
1049
- const [P, c] = N(r.initialRoles || []), [k, h] = N(!r.initialRoles), [E, R] = N(null), [I, A] = N(!1), [S, m] = N(null), [g, b] = N(() => Et()), D = ke({ done: !1 });
1050
- D.current.done || (D.current.done = !0);
1051
- const o = q(() => Ne.getInstance({
1192
+ const [R, c] = N(r.initialRoles || []), [S, h] = N(!r.initialRoles), [x, P] = N(null), [I, A] = N(!1), [k, m] = N(null), [g, b] = N(() => _t()), C = Ee({ done: !1 });
1193
+ C.current.done || (C.current.done = !0);
1194
+ const o = V(() => Me.getInstance({
1052
1195
  baseUrl: i,
1053
1196
  enableCookieSession: r.enableCookieSession,
1054
1197
  refreshQueueTimeout: r.refreshQueueTimeout,
1055
1198
  proactiveRefreshMargin: r.proactiveRefreshMargin,
1056
1199
  onSessionExpired: (w) => {
1057
- R(null), m(null), b([]), Qe(), r.onSessionExpired ? r.onSessionExpired(w) : r.onRefreshFailed && r.onRefreshFailed();
1200
+ P(null), m(null), b([]), et(), r.onSessionExpired ? r.onSessionExpired(w) : r.onRefreshFailed && r.onRefreshFailed();
1058
1201
  }
1059
1202
  }), [
1060
1203
  i,
1061
1204
  r.enableCookieSession,
1062
1205
  r.refreshQueueTimeout,
1063
1206
  r.proactiveRefreshMargin
1064
- ]), [p, x] = N(() => {
1207
+ ]), [p, E] = N(() => {
1065
1208
  const w = o.getTokens();
1066
1209
  return w ? o.hasValidSession() || !!w.refreshToken : !!r.enableCookieSession;
1067
- }), y = D.current.done && !p, u = q(() => {
1068
- const w = new de(i);
1210
+ }), y = C.current.done && !p, u = V(() => {
1211
+ const w = new he(i);
1069
1212
  return w.setSessionManager(o), w;
1070
- }, [i, o]), v = q(
1071
- () => new bt(u),
1213
+ }, [i, o]), v = V(
1214
+ () => new Nt(u),
1072
1215
  [u]
1073
- ), C = q(
1074
- () => new vt(u),
1216
+ ), D = V(
1217
+ () => new Dt(u),
1075
1218
  [u]
1076
- ), ie = q(
1077
- () => new wt(u),
1219
+ ), se = V(
1220
+ () => new Ct(u),
1078
1221
  [u]
1079
- ), L = q(() => E != null && E.roleId && P.find((w) => w.id === E.roleId) || null, [E, P]), H = q(() => (L == null ? void 0 : L.permissions) || [], [L]), j = q(
1080
- () => o.hasValidSession() && E !== null,
1081
- [o, E]
1082
- ), Z = q(() => (E == null ? void 0 : E.tenantId) != null, [E]), $ = ke(null), M = async (w = !1) => {
1222
+ ), F = V(() => x != null && x.roleId && R.find((w) => w.id === x.roleId) || null, [x, R]), H = V(() => (F == null ? void 0 : F.permissions) || [], [F]), j = V(
1223
+ () => o.hasValidSession() && x !== null,
1224
+ [o, x]
1225
+ ), Z = V(() => (x == null ? void 0 : x.tenantId) != null, [x]), $ = Ee(null), U = async (w = !1) => {
1083
1226
  try {
1084
- if (!o.hasValidSession() || !w && E) return;
1085
- const U = o.getUserId();
1086
- if (!U) {
1227
+ if (!o.hasValidSession() || !w && x) return;
1228
+ const M = o.getUserId();
1229
+ if (!M) {
1087
1230
  process.env.NODE_ENV === "development" && console.warn("[AuthProvider] No userId available in token or storage");
1088
1231
  return;
1089
1232
  }
1090
1233
  A(!0), m(null);
1091
- const z = await C.getUserById(U);
1092
- R(z), o.setUser(z);
1093
- } catch (U) {
1094
- const z = U instanceof Error ? U : new Error("Failed to load user data");
1234
+ const z = await D.getUserById(M);
1235
+ P(z), o.setUser(z);
1236
+ } catch (M) {
1237
+ const z = M instanceof Error ? M : new Error("Failed to load user data");
1095
1238
  m(z), process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data:", z);
1096
1239
  } finally {
1097
1240
  A(!1);
1098
1241
  }
1099
- }, F = async (w) => {
1100
- var je;
1101
- const { username: U, password: z, tenantSlug: _, redirectPath: Q } = w;
1102
- let ee = l == null ? void 0 : l.id, J = d;
1103
- _ && (ee = (await new me(u, a).getPublicTenantInfo(_)).id, J = _);
1242
+ }, L = async (w) => {
1243
+ var He;
1244
+ const { username: M, password: z, tenantSlug: O, redirectPath: Q } = w;
1245
+ let X = l == null ? void 0 : l.id, J = d;
1246
+ O && (X = (await new ye(u, a).getPublicTenantInfo(O)).id, J = O);
1104
1247
  const G = await v.login({
1105
- username: U,
1248
+ username: M,
1106
1249
  password: z,
1107
1250
  appId: a,
1108
- tenantId: ee
1109
- }), ve = _ && _ !== d;
1251
+ tenantId: X
1252
+ }), Se = O && O !== d;
1110
1253
  if (o.setTokens({
1111
1254
  accessToken: G.accessToken,
1112
1255
  refreshToken: G.refreshToken,
1113
1256
  expiresIn: G.expiresIn
1114
1257
  }), G.user) {
1115
- o.setUser(G.user), R(G.user);
1258
+ o.setUser(G.user), P(G.user);
1116
1259
  try {
1117
- await M();
1118
- } catch (Te) {
1119
- process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", Te);
1260
+ await U();
1261
+ } catch (ke) {
1262
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", ke);
1120
1263
  }
1121
1264
  }
1122
- G.tenants && G.tenants.length > 0 && (b(G.tenants), He(G.tenants));
1123
- const ze = ((je = G.user) == null ? void 0 : je.tenantId) !== null;
1124
- if (ve && J)
1265
+ G.tenants && G.tenants.length > 0 && (b(G.tenants), Xe(G.tenants));
1266
+ const Ge = ((He = G.user) == null ? void 0 : He.tenantId) !== null;
1267
+ if (Se && J)
1125
1268
  return T(J, { redirectPath: Q }), G;
1126
1269
  if (Q && Q !== window.location.pathname)
1127
1270
  return T(J || d || "", { redirectPath: Q }), G;
1128
- if (!ze && G.tenants && G.tenants.length > 0) {
1129
- const Te = w.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
1130
- if (G.tenants.length === 1 && Te) {
1131
- const We = G.tenants[0];
1132
- return T(We.subdomain, { redirectPath: Q }), G;
1271
+ if (!Ge && G.tenants && G.tenants.length > 0) {
1272
+ const ke = w.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
1273
+ if (G.tenants.length === 1 && ke) {
1274
+ const Qe = G.tenants[0];
1275
+ return T(Qe.subdomain, { redirectPath: Q }), G;
1133
1276
  } else G.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(G.tenants);
1134
1277
  }
1135
1278
  return G;
1136
- }, V = async (w) => {
1137
- const { email: U, phoneNumber: z, name: _, password: Q, lastName: ee, tenantId: J } = w;
1138
- if (!U && !z)
1279
+ }, q = async (w) => {
1280
+ const { email: M, phoneNumber: z, name: O, password: Q, lastName: X, tenantId: J } = w;
1281
+ if (!M && !z)
1139
1282
  throw new Error("Either email or phoneNumber is required");
1140
- if (!_ || !Q)
1283
+ if (!O || !Q)
1141
1284
  throw new Error("Name and password are required");
1142
1285
  return v.signup({
1143
- email: U,
1286
+ email: M,
1144
1287
  phoneNumber: z,
1145
- name: _,
1288
+ name: O,
1146
1289
  password: Q,
1147
1290
  tenantId: J ?? (l == null ? void 0 : l.id),
1148
- lastName: ee,
1291
+ lastName: X,
1149
1292
  appId: a
1150
1293
  });
1151
- }, O = async (w) => {
1152
- const { email: U, phoneNumber: z, name: _, password: Q, tenantName: ee, lastName: J } = w;
1153
- if (!U && !z)
1294
+ }, _ = async (w) => {
1295
+ const { email: M, phoneNumber: z, name: O, password: Q, tenantName: X, lastName: J } = w;
1296
+ if (!M && !z)
1154
1297
  throw new Error("Either email or phoneNumber is required");
1155
- if (!_ || !Q || !ee)
1298
+ if (!O || !Q || !X)
1156
1299
  throw new Error("Name, password, and tenantName are required");
1157
1300
  return v.signupTenantAdmin({
1158
- email: U,
1301
+ email: M,
1159
1302
  phoneNumber: z,
1160
- name: _,
1303
+ name: O,
1161
1304
  password: Q,
1162
- tenantName: ee,
1305
+ tenantName: X,
1163
1306
  appId: a,
1164
1307
  lastName: J
1165
1308
  });
1166
1309
  }, W = async (w) => {
1167
1310
  await v.changePassword(w);
1168
- }, Y = async (w) => {
1169
- const { email: U, tenantId: z } = w, _ = z ?? (l == null ? void 0 : l.id);
1170
- if (!_)
1311
+ }, K = async (w) => {
1312
+ const { email: M, tenantId: z } = w, O = z ?? (l == null ? void 0 : l.id);
1313
+ if (!O)
1171
1314
  throw new Error("tenantId is required for password reset");
1172
- await v.requestPasswordReset({ email: U, tenantId: _ });
1173
- }, X = async (w) => {
1315
+ await v.requestPasswordReset({ email: M, tenantId: O });
1316
+ }, Y = async (w) => {
1174
1317
  await v.confirmPasswordReset(w);
1175
- }, ae = async (w) => {
1176
- const { email: U, frontendUrl: z, name: _, lastName: Q, tenantId: ee } = w, J = ee ?? (l == null ? void 0 : l.id);
1318
+ }, le = async (w) => {
1319
+ const { email: M, frontendUrl: z, name: O, lastName: Q, tenantId: X } = w, J = X ?? (l == null ? void 0 : l.id);
1177
1320
  if (!J)
1178
1321
  throw new Error("tenantId is required for magic link authentication");
1179
1322
  return v.sendMagicLink({
1180
- email: U,
1323
+ email: M,
1181
1324
  tenantId: J,
1182
1325
  frontendUrl: z,
1183
- name: _,
1326
+ name: O,
1184
1327
  lastName: Q,
1185
1328
  appId: a
1186
1329
  });
1187
- }, we = async (w) => {
1188
- const { token: U, email: z, tenantSlug: _ } = w;
1189
- let Q = l == null ? void 0 : l.id, ee = d;
1190
- _ && (Q = (await new me(u, a).getPublicTenantInfo(_)).id, ee = _);
1330
+ }, Te = async (w) => {
1331
+ const { token: M, email: z, tenantSlug: O } = w;
1332
+ let Q = l == null ? void 0 : l.id, X = d;
1333
+ O && (Q = (await new ye(u, a).getPublicTenantInfo(O)).id, X = O);
1191
1334
  const J = await v.verifyMagicLink({
1192
- token: U,
1335
+ token: M,
1193
1336
  email: z,
1194
1337
  appId: a,
1195
1338
  tenantId: Q
1196
- }), G = _ && _ !== d;
1339
+ }), G = O && O !== d;
1197
1340
  if (o.setTokens({
1198
1341
  accessToken: J.accessToken,
1199
1342
  refreshToken: J.refreshToken,
1200
1343
  expiresIn: J.expiresIn
1201
1344
  }), J.user) {
1202
- o.setUser(J.user), R(J.user);
1345
+ o.setUser(J.user), P(J.user);
1203
1346
  try {
1204
- await M();
1205
- } catch (ve) {
1206
- process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after magic link:", ve);
1347
+ await U();
1348
+ } catch (Se) {
1349
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after magic link:", Se);
1207
1350
  }
1208
1351
  }
1209
- return G && ee && ee !== d && T(ee), J;
1210
- }, Ve = async () => {
1352
+ return G && X && X !== d && T(X), J;
1353
+ }, We = async () => {
1211
1354
  const w = o.getTokens();
1212
1355
  if (!(w != null && w.refreshToken))
1213
1356
  throw new Error("No refresh token available");
1214
- const U = await v.refreshToken({
1357
+ const M = await v.refreshToken({
1215
1358
  refreshToken: w.refreshToken
1216
1359
  });
1217
1360
  o.setTokens({
1218
- accessToken: U.accessToken,
1219
- refreshToken: U.refreshToken || w.refreshToken,
1220
- expiresIn: U.expiresIn
1361
+ accessToken: M.accessToken,
1362
+ refreshToken: M.refreshToken || w.refreshToken,
1363
+ expiresIn: M.expiresIn
1221
1364
  });
1222
- }, Re = () => {
1223
- o.clearSession(), R(null), m(null), b([]), Qe();
1224
- }, Ie = (w) => {
1365
+ }, Fe = () => {
1366
+ o.clearSession(), P(null), m(null), b([]), et();
1367
+ }, Ne = (w) => {
1225
1368
  o.setTokens(w);
1226
- }, ot = () => o.hasValidSession(), at = () => {
1227
- o.clearSession(), R(null), m(null);
1228
- }, lt = async () => {
1369
+ }, ht = () => o.hasValidSession(), pt = () => {
1370
+ o.clearSession(), P(null), m(null);
1371
+ }, ft = async () => {
1229
1372
  if (a)
1230
1373
  try {
1231
1374
  h(!0);
1232
- const { roles: w } = await ie.getRolesByApp(a);
1375
+ const { roles: w } = await se.getRolesByApp(a);
1233
1376
  c(w);
1234
1377
  } catch (w) {
1235
1378
  process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", w);
1236
1379
  } finally {
1237
1380
  h(!1);
1238
1381
  }
1239
- }, ct = async (w, U) => {
1240
- const { redirectPath: z } = U || {}, _ = o.getTokens();
1241
- if (!(_ != null && _.refreshToken))
1382
+ }, mt = async (w, M) => {
1383
+ const { redirectPath: z } = M || {}, O = o.getTokens();
1384
+ if (!(O != null && O.refreshToken))
1242
1385
  throw new Error("No refresh token available for tenant switch");
1243
1386
  const Q = await v.switchTenant({
1244
- refreshToken: _.refreshToken,
1387
+ refreshToken: O.refreshToken,
1245
1388
  tenantId: w
1246
1389
  });
1247
1390
  o.setTokens({
1248
1391
  accessToken: Q.accessToken,
1249
- refreshToken: _.refreshToken,
1392
+ refreshToken: O.refreshToken,
1250
1393
  expiresIn: Q.expiresIn
1251
- }), R(Q.user), o.setUser(Q.user);
1252
- const ee = g.find((J) => J.id === w);
1253
- ee && T(ee.subdomain, { redirectPath: z });
1254
- }, ut = async () => {
1394
+ }), P(Q.user), o.setUser(Q.user);
1395
+ const X = g.find((J) => J.id === w);
1396
+ X && T(X.subdomain, { redirectPath: z });
1397
+ }, gt = async () => {
1255
1398
  const w = await v.getUserTenants();
1256
- return b(w), He(w), w;
1399
+ return b(w), Xe(w), w;
1257
1400
  };
1258
1401
  $.current = {
1259
- login: F,
1260
- signup: V,
1261
- signupTenantAdmin: O,
1262
- sendMagicLink: ae,
1263
- verifyMagicLink: we,
1402
+ login: L,
1403
+ signup: q,
1404
+ signupTenantAdmin: _,
1405
+ sendMagicLink: le,
1406
+ verifyMagicLink: Te,
1264
1407
  changePassword: W,
1265
- requestPasswordReset: Y,
1266
- confirmPasswordReset: X,
1267
- refreshToken: Ve,
1268
- logout: Re,
1269
- setTokens: Ie,
1270
- hasValidSession: ot,
1271
- clearSession: at,
1272
- loadUserData: M,
1273
- refreshUser: () => M(),
1274
- refreshRoles: lt,
1275
- switchToTenant: ct,
1276
- refreshUserTenants: ut
1408
+ requestPasswordReset: K,
1409
+ confirmPasswordReset: Y,
1410
+ refreshToken: We,
1411
+ logout: Fe,
1412
+ setTokens: Ne,
1413
+ hasValidSession: ht,
1414
+ clearSession: pt,
1415
+ loadUserData: U,
1416
+ refreshUser: () => U(),
1417
+ refreshRoles: ft,
1418
+ switchToTenant: mt,
1419
+ refreshUserTenants: gt
1277
1420
  };
1278
- const dt = q(
1421
+ const yt = V(
1279
1422
  () => ({
1280
1423
  login: (w) => $.current.login(w),
1281
1424
  signup: (w) => $.current.signup(w),
@@ -1293,100 +1436,100 @@ function pr({ config: r = {}, children: e }) {
1293
1436
  loadUserData: (w) => $.current.loadUserData(w),
1294
1437
  refreshUser: () => $.current.refreshUser(),
1295
1438
  refreshRoles: () => $.current.refreshRoles(),
1296
- switchToTenant: (w, U) => $.current.switchToTenant(w, U),
1439
+ switchToTenant: (w, M) => $.current.switchToTenant(w, M),
1297
1440
  refreshUserTenants: () => $.current.refreshUserTenants()
1298
1441
  }),
1299
1442
  []
1300
- ), ht = q(() => {
1301
- const w = (U) => !H || H.length === 0 ? !1 : typeof U == "string" ? H.includes(U) : H.includes(`${U.resource}.${U.action}`);
1443
+ ), bt = V(() => {
1444
+ const w = (M) => !H || H.length === 0 ? !1 : typeof M == "string" ? H.includes(M) : H.includes(`${M.resource}.${M.action}`);
1302
1445
  return {
1303
1446
  isAuthenticated: j,
1304
1447
  isAuthInitializing: !y,
1305
1448
  isAuthReady: y,
1306
- currentUser: E,
1449
+ currentUser: x,
1307
1450
  isUserLoading: I,
1308
- userError: S,
1309
- userRole: L,
1451
+ userError: k,
1452
+ userRole: F,
1310
1453
  userPermissions: H,
1311
- availableRoles: P,
1312
- rolesLoading: k,
1454
+ availableRoles: R,
1455
+ rolesLoading: S,
1313
1456
  userTenants: g,
1314
1457
  hasTenantContext: Z,
1315
1458
  sessionManager: o,
1316
1459
  authenticatedHttpService: u,
1317
1460
  hasPermission: w,
1318
- hasAnyPermission: (U) => U.some((z) => w(z)),
1319
- hasAllPermissions: (U) => U.every((z) => w(z)),
1461
+ hasAnyPermission: (M) => M.some((z) => w(z)),
1462
+ hasAllPermissions: (M) => M.every((z) => w(z)),
1320
1463
  getUserPermissionStrings: () => H || []
1321
1464
  };
1322
1465
  }, [
1323
1466
  j,
1324
1467
  y,
1325
- E,
1468
+ x,
1326
1469
  I,
1327
- S,
1328
- L,
1329
- H,
1330
- P,
1331
1470
  k,
1471
+ F,
1472
+ H,
1473
+ R,
1474
+ S,
1332
1475
  g,
1333
1476
  Z,
1334
1477
  o,
1335
1478
  u
1336
1479
  ]);
1337
- return ne(() => {
1480
+ return re(() => {
1338
1481
  if (r.initialRoles || !a) return;
1339
1482
  let w = !1;
1340
- return h(!0), ie.getRolesByApp(a).then(({ roles: U }) => {
1341
- w || c(U);
1342
- }).catch((U) => {
1343
- process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", U);
1483
+ return h(!0), se.getRolesByApp(a).then(({ roles: M }) => {
1484
+ w || c(M);
1485
+ }).catch((M) => {
1486
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", M);
1344
1487
  }).finally(() => {
1345
1488
  w || h(!1);
1346
1489
  }), () => {
1347
1490
  w = !0;
1348
1491
  };
1349
- }, [a, r.initialRoles, ie]), ne(() => {
1492
+ }, [a, r.initialRoles, se]), re(() => {
1350
1493
  let w = !1;
1351
1494
  return (async () => {
1352
- var _;
1353
- if (!o.hasValidSession() && ((_ = o.getTokens()) != null && _.refreshToken) && await o.waitForPendingRefresh(), w || !o.hasValidSession() && !o.getTokens() && r.enableCookieSession && (await o.attemptCookieSessionRestore(), w))
1495
+ var O;
1496
+ if (!o.hasValidSession() && ((O = o.getTokens()) != null && O.refreshToken) && await o.waitForPendingRefresh(), w || !o.hasValidSession() && !o.getTokens() && r.enableCookieSession && (await o.attemptCookieSessionRestore(), w))
1354
1497
  return;
1355
1498
  const z = o.getUser();
1356
- z && o.hasValidSession() && R(z), x(!1);
1499
+ z && o.hasValidSession() && P(z), E(!1);
1357
1500
  })(), () => {
1358
1501
  w = !0;
1359
1502
  };
1360
- }, [o, r.enableCookieSession]), ne(() => {
1361
- !E && !I && !S && o.hasValidSession() ? $.current.loadUserData().catch(() => {
1503
+ }, [o, r.enableCookieSession]), re(() => {
1504
+ !x && !I && !k && o.hasValidSession() ? $.current.loadUserData().catch(() => {
1362
1505
  }).finally(() => {
1363
- x(!1);
1364
- }) : x(!1);
1365
- }, [E, I, S, o]), /* @__PURE__ */ s(Pe.Provider, { value: dt, children: /* @__PURE__ */ s(Ee.Provider, { value: ht, children: e }) });
1506
+ E(!1);
1507
+ }) : E(!1);
1508
+ }, [x, I, k, o]), /* @__PURE__ */ s(Ie.Provider, { value: yt, children: /* @__PURE__ */ s(Pe.Provider, { value: bt, children: e }) });
1366
1509
  }
1367
- function fr() {
1368
- const r = se(Ee);
1510
+ function Pr() {
1511
+ const r = ne(Pe);
1369
1512
  if (!r)
1370
1513
  throw new Error("useAuthState must be used within an AuthProvider");
1371
1514
  return r;
1372
1515
  }
1373
- function mr() {
1374
- const r = se(Pe);
1516
+ function Ir() {
1517
+ const r = ne(Ie);
1375
1518
  if (!r)
1376
1519
  throw new Error("useAuthActions must be used within an AuthProvider");
1377
1520
  return r;
1378
1521
  }
1379
- function ue() {
1380
- const r = se(Ee), e = se(Pe);
1522
+ function de() {
1523
+ const r = ne(Pe), e = ne(Ie);
1381
1524
  if (!r || !e)
1382
1525
  throw new Error("useAuth must be used within an AuthProvider");
1383
- return q(() => ({ ...r, ...e }), [r, e]);
1526
+ return V(() => ({ ...r, ...e }), [r, e]);
1384
1527
  }
1385
- function Me() {
1386
- const r = se(Ee), e = se(Pe);
1387
- return q(() => !r || !e ? null : { ...r, ...e }, [r, e]);
1528
+ function Oe() {
1529
+ const r = ne(Pe), e = ne(Ie);
1530
+ return V(() => !r || !e ? null : { ...r, ...e }, [r, e]);
1388
1531
  }
1389
- class Pt {
1532
+ class Ot {
1390
1533
  constructor(e) {
1391
1534
  this.httpService = e;
1392
1535
  }
@@ -1398,7 +1541,7 @@ class Pt {
1398
1541
  }
1399
1542
  async getFeatureFlags(e) {
1400
1543
  const t = await this.httpService.get(
1401
- `/feature-flags/${le(e)}`
1544
+ `/feature-flags/${ce(e)}`
1402
1545
  );
1403
1546
  return { featureFlags: t.data, meta: t.meta };
1404
1547
  }
@@ -1417,7 +1560,7 @@ class Pt {
1417
1560
  async getTenantFeatureFlags(e, t) {
1418
1561
  if (!e || !t)
1419
1562
  throw new Error("Tenant ID and App ID are required");
1420
- const n = le({ tenantId: e, appId: t });
1563
+ const n = ce({ tenantId: e, appId: t });
1421
1564
  return (await this.httpService.get(
1422
1565
  `/tenant-feature-flags${n}`,
1423
1566
  { headers: { "X-Tenant-ID": e }, skipAuth: !0 }
@@ -1426,18 +1569,18 @@ class Pt {
1426
1569
  async getTenantFeatureFlag(e, t, n) {
1427
1570
  if (!e || !t || !n)
1428
1571
  throw new Error("Flag Key, Tenant ID and App ID are required");
1429
- const i = le({ tenantId: t, appId: n });
1572
+ const i = ce({ tenantId: t, appId: n });
1430
1573
  return (await this.httpService.get(
1431
1574
  `/tenant-feature-flags/${e}${i}`,
1432
1575
  { headers: { "X-Tenant-ID": t }, skipAuth: !0 }
1433
1576
  )).data;
1434
1577
  }
1435
1578
  }
1436
- const Be = pe(null);
1437
- function gr({ config: r = {}, children: e }) {
1438
- const t = Ce(), n = he(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (t == null ? void 0 : t.appId) ?? "", l = (n == null ? void 0 : n.tenant) ?? null, [d, T] = N([]), [P, c] = N(!1), [k, h] = N(null), [E, R] = N(!1), I = q(() => {
1439
- const m = new de(i);
1440
- return new Pt(m);
1579
+ const Ve = fe(null);
1580
+ function Lr({ config: r = {}, children: e }) {
1581
+ const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (t == null ? void 0 : t.appId) ?? "", l = (n == null ? void 0 : n.tenant) ?? null, [d, T] = N([]), [R, c] = N(!1), [S, h] = N(null), [x, P] = N(!1), I = V(() => {
1582
+ const m = new he(i);
1583
+ return new Ot(m);
1441
1584
  }, [i]), A = async () => {
1442
1585
  if (!(l != null && l.id)) {
1443
1586
  T([]);
@@ -1454,45 +1597,45 @@ function gr({ config: r = {}, children: e }) {
1454
1597
  c(!1);
1455
1598
  }
1456
1599
  };
1457
- ne(() => {
1600
+ re(() => {
1458
1601
  if (!i || !a) return;
1459
- A().finally(() => R(!0));
1602
+ A().finally(() => P(!0));
1460
1603
  const m = r.refreshInterval || 5 * 60 * 1e3, g = setInterval(A, m);
1461
1604
  return () => clearInterval(g);
1462
1605
  }, [l == null ? void 0 : l.id, i, a, r.refreshInterval]);
1463
- const S = q(() => {
1606
+ const k = V(() => {
1464
1607
  const m = (p) => {
1465
- const x = d.find((y) => y.key === p);
1466
- return (x == null ? void 0 : x.value) === !0;
1467
- }, g = (p) => d.find((x) => x.key === p), b = (p) => {
1468
- const x = d.find((y) => y.key === p);
1469
- return x ? x.value ? "enabled" : "disabled" : "not_found";
1470
- }, D = async () => {
1608
+ const E = d.find((y) => y.key === p);
1609
+ return (E == null ? void 0 : E.value) === !0;
1610
+ }, g = (p) => d.find((E) => E.key === p), b = (p) => {
1611
+ const E = d.find((y) => y.key === p);
1612
+ return E ? E.value ? "enabled" : "disabled" : "not_found";
1613
+ }, C = async () => {
1471
1614
  await A();
1472
- }, o = !!(i && a) && (E || !(l != null && l.id));
1615
+ }, o = !!(i && a) && (x || !(l != null && l.id));
1473
1616
  return {
1474
1617
  featureFlags: d,
1475
- loading: P,
1476
- error: k,
1618
+ loading: R,
1619
+ error: S,
1477
1620
  isReady: o,
1478
1621
  isEnabled: m,
1479
1622
  getFlag: g,
1480
1623
  getFlagState: b,
1481
- refresh: D
1624
+ refresh: C
1482
1625
  };
1483
- }, [d, P, k, i, a, l == null ? void 0 : l.id, E]);
1484
- return /* @__PURE__ */ s(Be.Provider, { value: S, children: e });
1626
+ }, [d, R, S, i, a, l == null ? void 0 : l.id, x]);
1627
+ return /* @__PURE__ */ s(Ve.Provider, { value: k, children: e });
1485
1628
  }
1486
- function At() {
1487
- const r = se(Be);
1629
+ function Vt() {
1630
+ const r = ne(Ve);
1488
1631
  if (!r)
1489
1632
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1490
1633
  return r;
1491
1634
  }
1492
- function tt() {
1493
- return se(Be);
1635
+ function at() {
1636
+ return ne(Ve);
1494
1637
  }
1495
- class Rt {
1638
+ class qt {
1496
1639
  constructor(e) {
1497
1640
  this.httpService = e;
1498
1641
  }
@@ -1532,68 +1675,68 @@ class Rt {
1532
1675
  )).data;
1533
1676
  }
1534
1677
  }
1535
- const Oe = pe(void 0);
1536
- function yr({ config: r = {}, children: e }) {
1537
- const t = Ce(), n = he(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [l, d] = N(null), [T, P] = N(!1), [c, k] = N(null), [h, E] = N(!1), R = q(() => {
1538
- const S = new de(i);
1539
- return new Rt(S);
1678
+ const qe = fe(void 0);
1679
+ function Fr({ config: r = {}, children: e }) {
1680
+ const t = Ue(), n = pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [l, d] = N(null), [T, R] = N(!1), [c, S] = N(null), [h, x] = N(!1), P = V(() => {
1681
+ const k = new he(i);
1682
+ return new qt(k);
1540
1683
  }, [i]), I = async () => {
1541
1684
  if (!(a != null && a.id)) {
1542
1685
  d(null);
1543
1686
  return;
1544
1687
  }
1545
- P(!0), k(null);
1688
+ R(!0), S(null);
1546
1689
  try {
1547
- const S = await R.getTenantSubscriptionFeatures(a.id);
1548
- d(S);
1549
- } catch (S) {
1550
- const m = S instanceof Error ? S.message : "Failed to fetch subscription";
1551
- k(m), r.onError && r.onError(S instanceof Error ? S : new Error(m));
1690
+ const k = await P.getTenantSubscriptionFeatures(a.id);
1691
+ d(k);
1692
+ } catch (k) {
1693
+ const m = k instanceof Error ? k.message : "Failed to fetch subscription";
1694
+ S(m), r.onError && r.onError(k instanceof Error ? k : new Error(m));
1552
1695
  } finally {
1553
- P(!1);
1696
+ R(!1);
1554
1697
  }
1555
1698
  };
1556
- ne(() => {
1557
- if (!i || (I().finally(() => E(!0)), !r.refreshInterval)) return;
1558
- const S = r.refreshInterval || 10 * 60 * 1e3, m = setInterval(I, S);
1699
+ re(() => {
1700
+ if (!i || (I().finally(() => x(!0)), !r.refreshInterval)) return;
1701
+ const k = r.refreshInterval || 10 * 60 * 1e3, m = setInterval(I, k);
1559
1702
  return () => clearInterval(m);
1560
1703
  }, [a == null ? void 0 : a.id, i, r.refreshInterval]);
1561
- const A = q(() => {
1562
- const S = (l == null ? void 0 : l.features) || [], m = (x) => {
1563
- const y = S.find((u) => u.key === x);
1704
+ const A = V(() => {
1705
+ const k = (l == null ? void 0 : l.features) || [], m = (E) => {
1706
+ const y = k.find((u) => u.key === E);
1564
1707
  return y ? y.type === "BOOLEAN" || y.type === "boolean" ? y.value === !0 : !!y.value : !1;
1565
- }, g = (x) => S.find((y) => y.key === x), b = (x, y) => {
1566
- const u = S.find((v) => v.key === x);
1708
+ }, g = (E) => k.find((y) => y.key === E), b = (E, y) => {
1709
+ const u = k.find((v) => v.key === E);
1567
1710
  return u ? u.value : y;
1568
- }, D = (x) => !l || !l.isActive ? !1 : x.includes(l.planId), o = async () => {
1711
+ }, C = (E) => !l || !l.isActive ? !1 : E.includes(l.planId), o = async () => {
1569
1712
  await I();
1570
1713
  }, p = !!i && (h || !(a != null && a.id));
1571
1714
  return {
1572
1715
  subscription: l,
1573
- features: S,
1716
+ features: k,
1574
1717
  loading: T,
1575
1718
  error: c,
1576
1719
  isReady: p,
1577
1720
  isFeatureEnabled: m,
1578
1721
  getFeature: g,
1579
1722
  getFeatureValue: b,
1580
- hasAllowedPlan: D,
1723
+ hasAllowedPlan: C,
1581
1724
  refresh: o
1582
1725
  };
1583
1726
  }, [l, T, c, i, a == null ? void 0 : a.id, h]);
1584
- return /* @__PURE__ */ s(Oe.Provider, { value: A, children: e });
1727
+ return /* @__PURE__ */ s(qe.Provider, { value: A, children: e });
1585
1728
  }
1586
- function It() {
1587
- const r = se(Oe);
1729
+ function zt() {
1730
+ const r = ne(qe);
1588
1731
  if (r === void 0)
1589
1732
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1590
1733
  return r;
1591
1734
  }
1592
- function rt() {
1593
- return se(Oe) ?? null;
1735
+ function lt() {
1736
+ return ne(qe) ?? null;
1594
1737
  }
1595
- var oe = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(oe || {});
1596
- const _e = {
1738
+ var ae = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(ae || {});
1739
+ const ze = {
1597
1740
  publicGuest: "/",
1598
1741
  publicUser: "/account",
1599
1742
  publicAdmin: "/admin",
@@ -1601,7 +1744,7 @@ const _e = {
1601
1744
  tenantUser: "/dashboard",
1602
1745
  tenantAdmin: "/admin/dashboard",
1603
1746
  default: "/"
1604
- }, nt = {
1747
+ }, ct = {
1605
1748
  // Public/Landing zones
1606
1749
  landing: { tenant: "forbidden", auth: "optional" },
1607
1750
  publicOnly: { tenant: "forbidden", auth: "forbidden" },
@@ -1614,26 +1757,26 @@ const _e = {
1614
1757
  tenantOpen: { tenant: "required", auth: "optional" },
1615
1758
  tenantAuth: { tenant: "required", auth: "required" },
1616
1759
  // User type zones
1617
- user: { tenant: "required", auth: "required", userType: oe.USER },
1618
- admin: { tenant: "required", auth: "required", userType: oe.TENANT_ADMIN },
1760
+ user: { tenant: "required", auth: "required", userType: ae.USER },
1761
+ admin: { tenant: "required", auth: "required", userType: ae.TENANT_ADMIN },
1619
1762
  // Fully open
1620
1763
  open: { tenant: "optional", auth: "optional" }
1621
- }, qe = pe(null), Ft = {
1622
- zoneRoots: _e,
1623
- presets: nt,
1764
+ }, je = fe(null), jt = {
1765
+ zoneRoots: ze,
1766
+ presets: ct,
1624
1767
  loadingFallback: null,
1625
1768
  accessDeniedFallback: null,
1626
1769
  onAccessDenied: void 0,
1627
1770
  returnToParam: "returnTo",
1628
1771
  returnToStorage: "url"
1629
1772
  };
1630
- function br({ config: r = {}, children: e }) {
1631
- const t = q(() => {
1773
+ function Nr({ config: r = {}, children: e }) {
1774
+ const t = V(() => {
1632
1775
  const n = {
1633
- ..._e,
1776
+ ...ze,
1634
1777
  ...r.zoneRoots
1635
1778
  }, i = {
1636
- ...nt,
1779
+ ...ct,
1637
1780
  ...r.presets
1638
1781
  };
1639
1782
  return {
@@ -1646,18 +1789,18 @@ function br({ config: r = {}, children: e }) {
1646
1789
  returnToStorage: r.returnToStorage ?? "url"
1647
1790
  };
1648
1791
  }, [r]);
1649
- return /* @__PURE__ */ s(qe.Provider, { value: t, children: e });
1792
+ return /* @__PURE__ */ s(je.Provider, { value: t, children: e });
1650
1793
  }
1651
- function wr() {
1652
- const r = se(qe);
1794
+ function Cr() {
1795
+ const r = ne(je);
1653
1796
  if (!r)
1654
1797
  throw new Error("useRouting must be used within a RoutingProvider");
1655
1798
  return r;
1656
1799
  }
1657
- function Lt() {
1658
- return se(qe) ?? Ft;
1800
+ function Wt() {
1801
+ return ne(je) ?? jt;
1659
1802
  }
1660
- const Je = () => /* @__PURE__ */ f(
1803
+ const tt = () => /* @__PURE__ */ f(
1661
1804
  "div",
1662
1805
  {
1663
1806
  style: {
@@ -1694,7 +1837,7 @@ const Je = () => /* @__PURE__ */ f(
1694
1837
  )
1695
1838
  ]
1696
1839
  }
1697
- ), Ze = ({
1840
+ ), rt = ({
1698
1841
  userType: r,
1699
1842
  minUserType: e,
1700
1843
  missingPermissions: t
@@ -1735,36 +1878,36 @@ const Je = () => /* @__PURE__ */ f(
1735
1878
  ] })
1736
1879
  ]
1737
1880
  }
1738
- ), Nt = (r, e) => {
1881
+ ), Gt = (r, e) => {
1739
1882
  const t = {
1740
- [oe.USER]: 1,
1741
- [oe.TENANT_ADMIN]: 2,
1742
- [oe.SUPERUSER]: 3
1883
+ [ae.USER]: 1,
1884
+ [ae.TENANT_ADMIN]: 2,
1885
+ [ae.SUPERUSER]: 3
1743
1886
  };
1744
1887
  return t[r] >= t[e];
1745
1888
  };
1746
- function vr({
1889
+ function Dr({
1747
1890
  children: r,
1748
1891
  fallback: e,
1749
1892
  minUserType: t,
1750
1893
  requiredPermissions: n,
1751
1894
  requireAllPermissions: i = !1
1752
1895
  }) {
1753
- const { hasValidSession: a, sessionManager: l, hasPermission: d, hasAnyPermission: T, hasAllPermissions: P } = ue();
1896
+ const { hasValidSession: a, sessionManager: l, hasPermission: d, hasAnyPermission: T, hasAllPermissions: R } = de();
1754
1897
  if (!a())
1755
- return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(Je, {}) });
1898
+ return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(tt, {}) });
1756
1899
  const c = l.getUser();
1757
1900
  if (!c)
1758
- return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(Je, {}) });
1759
- if (t && !Nt(c.userType, t))
1760
- return /* @__PURE__ */ s(Ze, { userType: c.userType, minUserType: t });
1761
- if (n && n.length > 0 && !(i ? P(n) : T(n))) {
1762
- const h = n.filter((E) => !d(E)).map((E) => typeof E == "string" ? E : E.name);
1763
- return /* @__PURE__ */ s(Ze, { missingPermissions: h });
1901
+ return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(tt, {}) });
1902
+ if (t && !Gt(c.userType, t))
1903
+ return /* @__PURE__ */ s(rt, { userType: c.userType, minUserType: t });
1904
+ if (n && n.length > 0 && !(i ? R(n) : T(n))) {
1905
+ const h = n.filter((x) => !d(x)).map((x) => typeof x == "string" ? x : x.name);
1906
+ return /* @__PURE__ */ s(rt, { missingPermissions: h });
1764
1907
  }
1765
1908
  return /* @__PURE__ */ s(B, { children: r });
1766
1909
  }
1767
- const Dt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1910
+ const Ht = ({ redirectPath: r }) => /* @__PURE__ */ s(
1768
1911
  "div",
1769
1912
  {
1770
1913
  style: {
@@ -1800,7 +1943,7 @@ const Dt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1800
1943
  }
1801
1944
  )
1802
1945
  }
1803
- ), Ke = ({
1946
+ ), nt = ({
1804
1947
  userType: r,
1805
1948
  requiredUserType: e,
1806
1949
  missingPermissions: t
@@ -1851,8 +1994,8 @@ const Dt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1851
1994
  }
1852
1995
  )
1853
1996
  }
1854
- ), Ct = (r, e) => r === e;
1855
- function Tr({
1997
+ ), Qt = (r, e) => r === e;
1998
+ function Mr({
1856
1999
  children: r,
1857
2000
  redirectTo: e = "/login",
1858
2001
  requiredUserType: t,
@@ -1860,34 +2003,34 @@ function Tr({
1860
2003
  requireAllPermissions: i = !1,
1861
2004
  fallback: a
1862
2005
  }) {
1863
- const { hasValidSession: l, sessionManager: d, hasPermission: T, hasAnyPermission: P, hasAllPermissions: c } = ue(), k = Se();
1864
- if (ne(() => {
2006
+ const { hasValidSession: l, sessionManager: d, hasPermission: T, hasAnyPermission: R, hasAllPermissions: c } = de(), S = xe();
2007
+ if (re(() => {
1865
2008
  process.env.NODE_ENV === "development" && console.warn(
1866
2009
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
1867
2010
  );
1868
2011
  }, []), !l())
1869
2012
  return a ? /* @__PURE__ */ s(B, { children: a }) : /* @__PURE__ */ f(B, { children: [
1870
- /* @__PURE__ */ s(Dt, { redirectPath: e }),
1871
- /* @__PURE__ */ s(ge, { to: e, state: { from: k.pathname }, replace: !0 })
2013
+ /* @__PURE__ */ s(Ht, { redirectPath: e }),
2014
+ /* @__PURE__ */ s(be, { to: e, state: { from: S.pathname }, replace: !0 })
1872
2015
  ] });
1873
2016
  const h = d.getUser();
1874
2017
  if (!h)
1875
- return /* @__PURE__ */ s(ge, { to: e, state: { from: k.pathname }, replace: !0 });
1876
- if (t && !Ct(h.userType, t))
2018
+ return /* @__PURE__ */ s(be, { to: e, state: { from: S.pathname }, replace: !0 });
2019
+ if (t && !Qt(h.userType, t))
1877
2020
  return /* @__PURE__ */ s(
1878
- Ke,
2021
+ nt,
1879
2022
  {
1880
2023
  userType: h.userType,
1881
2024
  requiredUserType: t
1882
2025
  }
1883
2026
  );
1884
- if (n && n.length > 0 && !(i ? c(n) : P(n))) {
1885
- const R = n.filter((I) => !T(I)).map((I) => typeof I == "string" ? I : I.name);
1886
- return /* @__PURE__ */ s(Ke, { missingPermissions: R });
2027
+ if (n && n.length > 0 && !(i ? c(n) : R(n))) {
2028
+ const P = n.filter((I) => !T(I)).map((I) => typeof I == "string" ? I : I.name);
2029
+ return /* @__PURE__ */ s(nt, { missingPermissions: P });
1887
2030
  }
1888
2031
  return /* @__PURE__ */ s(B, { children: r });
1889
2032
  }
1890
- const Ut = ({ redirectPath: r }) => /* @__PURE__ */ s(
2033
+ const Jt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1891
2034
  "div",
1892
2035
  {
1893
2036
  style: {
@@ -1924,18 +2067,18 @@ const Ut = ({ redirectPath: r }) => /* @__PURE__ */ s(
1924
2067
  )
1925
2068
  }
1926
2069
  );
1927
- function kr({ children: r, redirectTo: e = "/", fallback: t }) {
1928
- const { tenant: n, isLoading: i, error: a } = et(), l = Se();
1929
- return ne(() => {
2070
+ function $r({ children: r, redirectTo: e = "/", fallback: t }) {
2071
+ const { tenant: n, isLoading: i, error: a } = ot(), l = xe();
2072
+ return re(() => {
1930
2073
  process.env.NODE_ENV === "development" && console.warn(
1931
2074
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
1932
2075
  );
1933
2076
  }, []), i || a ? null : n ? /* @__PURE__ */ s(B, { children: r }) : t ? /* @__PURE__ */ s(B, { children: t }) : /* @__PURE__ */ f(B, { children: [
1934
- /* @__PURE__ */ s(Ut, { redirectPath: e }),
1935
- /* @__PURE__ */ s(ge, { to: e, state: { from: l.pathname }, replace: !0 })
2077
+ /* @__PURE__ */ s(Jt, { redirectPath: e }),
2078
+ /* @__PURE__ */ s(be, { to: e, state: { from: l.pathname }, replace: !0 })
1936
2079
  ] });
1937
2080
  }
1938
- const $t = ({ redirectPath: r }) => /* @__PURE__ */ s(
2081
+ const Zt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1939
2082
  "div",
1940
2083
  {
1941
2084
  style: {
@@ -1972,41 +2115,41 @@ const $t = ({ redirectPath: r }) => /* @__PURE__ */ s(
1972
2115
  )
1973
2116
  }
1974
2117
  );
1975
- function Sr({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
1976
- const { tenant: n, isLoading: i, error: a } = et(), l = Se();
1977
- return ne(() => {
2118
+ function Ur({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
2119
+ const { tenant: n, isLoading: i, error: a } = ot(), l = xe();
2120
+ return re(() => {
1978
2121
  process.env.NODE_ENV === "development" && console.warn(
1979
2122
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
1980
2123
  );
1981
2124
  }, []), i || a ? null : n ? t ? /* @__PURE__ */ s(B, { children: t }) : /* @__PURE__ */ f(B, { children: [
1982
- /* @__PURE__ */ s($t, { redirectPath: e }),
1983
- /* @__PURE__ */ s(ge, { to: e, state: { from: l.pathname }, replace: !0 })
2125
+ /* @__PURE__ */ s(Zt, { redirectPath: e }),
2126
+ /* @__PURE__ */ s(be, { to: e, state: { from: l.pathname }, replace: !0 })
1984
2127
  ] }) : /* @__PURE__ */ s(B, { children: r });
1985
2128
  }
1986
- function Mt(r, e) {
2129
+ function Kt(r, e) {
1987
2130
  return e ? r ? Array.isArray(e) ? e.includes(r) : r === e : !1 : !0;
1988
2131
  }
1989
- function Ye(r, e) {
2132
+ function st(r, e) {
1990
2133
  return !r || r === "optional" ? "skip" : r === "required" ? e ? "pass" : "fail" : r === "forbidden" ? e ? "fail" : "pass" : "skip";
1991
2134
  }
1992
- function Bt(r, e) {
1993
- return Ye(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Ye(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !Mt(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (a) => a.every((l) => e.permissions.includes(l)) : (a) => a.some((l) => e.permissions.includes(l)))(r.permissions) ? "missing_permissions" : null;
2135
+ function Yt(r, e) {
2136
+ return st(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : st(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !Kt(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (a) => a.every((l) => e.permissions.includes(l)) : (a) => a.some((l) => e.permissions.includes(l)))(r.permissions) ? "missing_permissions" : null;
1994
2137
  }
1995
- function Ot(r, e) {
1996
- return r.hasTenant ? r.isAuthenticated ? r.userType === oe.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : r.isAuthenticated ? r.userType === oe.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
2138
+ function Xt(r, e) {
2139
+ return r.hasTenant ? r.isAuthenticated ? r.userType === ae.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : r.isAuthenticated ? r.userType === ae.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
1997
2140
  }
1998
- function _t(r, e, t, n, i) {
2141
+ function er(r, e, t, n, i) {
1999
2142
  if (!e || i !== "url")
2000
2143
  return r;
2001
2144
  const a = typeof e == "string" ? e : t, l = r.includes("?") ? "&" : "?";
2002
2145
  return `${r}${l}${n}=${encodeURIComponent(a)}`;
2003
2146
  }
2004
- function qt(r, e, t) {
2147
+ function tr(r, e, t) {
2005
2148
  if (!r || t === "url") return;
2006
2149
  const n = typeof r == "string" ? r : e, i = "zone_return_to";
2007
2150
  t === "session" ? sessionStorage.setItem(i, n) : t === "local" && localStorage.setItem(i, n);
2008
2151
  }
2009
- const ce = ({
2152
+ const ue = ({
2010
2153
  children: r,
2011
2154
  preset: e,
2012
2155
  tenant: t,
@@ -2016,14 +2159,14 @@ const ce = ({
2016
2159
  requireAllPermissions: l = !0,
2017
2160
  returnTo: d,
2018
2161
  onAccessDenied: T,
2019
- redirectTo: P,
2162
+ redirectTo: R,
2020
2163
  loadingFallback: c,
2021
- accessDeniedFallback: k
2164
+ accessDeniedFallback: S
2022
2165
  }) => {
2023
- const h = Se(), { isAuthenticated: E, isAuthInitializing: R, currentUser: I, userPermissions: A } = ue(), { tenant: S, isTenantLoading: m } = be(), g = Lt(), b = q(() => {
2166
+ const h = xe(), { isAuthenticated: x, isAuthInitializing: P, currentUser: I, userPermissions: A } = de(), { tenant: k, isTenantLoading: m } = ve(), g = Wt(), b = V(() => {
2024
2167
  if (e)
2025
2168
  return g.presets[e];
2026
- }, [e, g.presets]), D = q(
2169
+ }, [e, g.presets]), C = V(
2027
2170
  () => ({
2028
2171
  tenant: t ?? (b == null ? void 0 : b.tenant),
2029
2172
  auth: n ?? (b == null ? void 0 : b.auth),
@@ -2032,29 +2175,29 @@ const ce = ({
2032
2175
  requireAllPermissions: l
2033
2176
  }),
2034
2177
  [t, n, i, a, b, l]
2035
- ), o = q(
2178
+ ), o = V(
2036
2179
  () => ({
2037
- hasTenant: !!S,
2038
- isAuthenticated: E,
2180
+ hasTenant: !!k,
2181
+ isAuthenticated: x,
2039
2182
  userType: I == null ? void 0 : I.userType,
2040
2183
  permissions: A,
2041
- isLoading: R || m
2184
+ isLoading: P || m
2042
2185
  }),
2043
2186
  [
2044
- S,
2045
- E,
2187
+ k,
2188
+ x,
2046
2189
  I == null ? void 0 : I.userType,
2047
2190
  A,
2048
- R,
2191
+ P,
2049
2192
  m
2050
2193
  ]
2051
- ), p = q(() => o.isLoading ? null : Bt(D, o), [D, o]), x = q(() => p ? P || Ot(o, g.zoneRoots) : null, [p, P, o, g.zoneRoots]), y = q(() => !p || !x ? null : {
2194
+ ), p = V(() => o.isLoading ? null : Yt(C, o), [C, o]), E = V(() => p ? R || Xt(o, g.zoneRoots) : null, [p, R, o, g.zoneRoots]), y = V(() => !p || !E ? null : {
2052
2195
  type: p,
2053
2196
  required: {
2054
- tenant: D.tenant,
2055
- auth: D.auth,
2056
- userType: D.userType,
2057
- permissions: D.permissions
2197
+ tenant: C.tenant,
2198
+ auth: C.auth,
2199
+ userType: C.userType,
2200
+ permissions: C.permissions
2058
2201
  },
2059
2202
  current: {
2060
2203
  hasTenant: o.hasTenant,
@@ -2062,12 +2205,12 @@ const ce = ({
2062
2205
  userType: o.userType,
2063
2206
  permissions: o.permissions
2064
2207
  },
2065
- redirectTo: x
2066
- }, [p, x, D, o]);
2067
- if (ne(() => {
2208
+ redirectTo: E
2209
+ }, [p, E, C, o]);
2210
+ if (re(() => {
2068
2211
  y && (T ? T(y) : g.onAccessDenied && g.onAccessDenied(y));
2069
- }, [y, T, g]), ne(() => {
2070
- y && d && qt(d, h.pathname + h.search, g.returnToStorage);
2212
+ }, [y, T, g]), re(() => {
2213
+ y && d && tr(d, h.pathname + h.search, g.returnToStorage);
2071
2214
  }, [
2072
2215
  y,
2073
2216
  d,
@@ -2076,21 +2219,21 @@ const ce = ({
2076
2219
  g.returnToStorage
2077
2220
  ]), o.isLoading)
2078
2221
  return /* @__PURE__ */ s(B, { children: c ?? g.loadingFallback ?? null });
2079
- if (y && x) {
2080
- const u = k ?? g.accessDeniedFallback;
2222
+ if (y && E) {
2223
+ const u = S ?? g.accessDeniedFallback;
2081
2224
  if (u)
2082
2225
  return /* @__PURE__ */ s(B, { children: u });
2083
- const v = _t(
2084
- x,
2226
+ const v = er(
2227
+ E,
2085
2228
  d,
2086
2229
  h.pathname + h.search,
2087
2230
  g.returnToParam,
2088
2231
  g.returnToStorage
2089
2232
  );
2090
- return /* @__PURE__ */ s(ge, { to: v, replace: !0 });
2233
+ return /* @__PURE__ */ s(be, { to: v, replace: !0 });
2091
2234
  }
2092
2235
  return /* @__PURE__ */ s(B, { children: r });
2093
- }, xr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", ...r }), Er = (r) => /* @__PURE__ */ s(ce, { tenant: "forbidden", ...r }), Pr = (r) => /* @__PURE__ */ s(ce, { auth: "required", ...r }), Ar = (r) => /* @__PURE__ */ s(ce, { auth: "forbidden", ...r }), Rr = (r) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.TENANT_ADMIN, ...r }), Ir = (r) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.USER, ...r }), Fr = (r) => /* @__PURE__ */ s(ce, { tenant: "optional", auth: "optional", ...r }), Lr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "required", ...r }), Nr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "optional", ...r }), Dr = (r) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "forbidden", ...r }), Vt = () => /* @__PURE__ */ f(
2236
+ }, Br = (r) => /* @__PURE__ */ s(ue, { tenant: "required", ...r }), _r = (r) => /* @__PURE__ */ s(ue, { tenant: "forbidden", ...r }), Or = (r) => /* @__PURE__ */ s(ue, { auth: "required", ...r }), Vr = (r) => /* @__PURE__ */ s(ue, { auth: "forbidden", ...r }), qr = (r) => /* @__PURE__ */ s(ue, { auth: "required", userType: ae.TENANT_ADMIN, ...r }), zr = (r) => /* @__PURE__ */ s(ue, { auth: "required", userType: ae.USER, ...r }), jr = (r) => /* @__PURE__ */ s(ue, { tenant: "optional", auth: "optional", ...r }), Wr = (r) => /* @__PURE__ */ s(ue, { tenant: "required", auth: "required", ...r }), Gr = (r) => /* @__PURE__ */ s(ue, { tenant: "required", auth: "optional", ...r }), Hr = (r) => /* @__PURE__ */ s(ue, { tenant: "required", auth: "forbidden", ...r }), rr = () => /* @__PURE__ */ f(
2094
2237
  "div",
2095
2238
  {
2096
2239
  style: {
@@ -2107,13 +2250,13 @@ const ce = ({
2107
2250
  ]
2108
2251
  }
2109
2252
  );
2110
- function Cr({
2253
+ function Qr({
2111
2254
  children: r,
2112
- fallback: e = /* @__PURE__ */ s(Vt, {}),
2255
+ fallback: e = /* @__PURE__ */ s(rr, {}),
2113
2256
  allowedPlans: t,
2114
2257
  requiredFeature: n
2115
2258
  }) {
2116
- const { subscription: i, hasAllowedPlan: a, isFeatureEnabled: l, loading: d } = It();
2259
+ const { subscription: i, hasAllowedPlan: a, isFeatureEnabled: l, loading: d } = zt();
2117
2260
  return d ? /* @__PURE__ */ s(
2118
2261
  "div",
2119
2262
  {
@@ -2126,7 +2269,7 @@ function Cr({
2126
2269
  }
2127
2270
  ) : i ? i.isActive ? t && t.length > 0 && !a(t) ? /* @__PURE__ */ s(B, { children: e }) : n && !l(n) ? /* @__PURE__ */ s(B, { children: e }) : /* @__PURE__ */ s(B, { children: r }) : /* @__PURE__ */ s(B, { children: e }) : /* @__PURE__ */ s(B, { children: e });
2128
2271
  }
2129
- const zt = ({ flagName: r }) => /* @__PURE__ */ f(
2272
+ const nr = ({ flagName: r }) => /* @__PURE__ */ f(
2130
2273
  "div",
2131
2274
  {
2132
2275
  style: {
@@ -2153,8 +2296,8 @@ const zt = ({ flagName: r }) => /* @__PURE__ */ f(
2153
2296
  ]
2154
2297
  }
2155
2298
  );
2156
- function Ur({ name: r, children: e, fallback: t }) {
2157
- const { isEnabled: n, loading: i } = At();
2299
+ function Jr({ name: r, children: e, fallback: t }) {
2300
+ const { isEnabled: n, loading: i } = Vt();
2158
2301
  return i ? /* @__PURE__ */ s(
2159
2302
  "div",
2160
2303
  {
@@ -2168,29 +2311,29 @@ function Ur({ name: r, children: e, fallback: t }) {
2168
2311
  },
2169
2312
  children: "Loading feature flags..."
2170
2313
  }
2171
- ) : n(r) ? /* @__PURE__ */ s(B, { children: e }) : /* @__PURE__ */ s(B, { children: t || /* @__PURE__ */ s(zt, { flagName: r }) });
2172
- }
2173
- function ye(r) {
2174
- const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError: a } = r, [l, d] = N(!1), [T, P] = N(""), [c, k] = N({}), h = re((A, S) => {
2175
- k((m) => ({ ...m, [A]: S }));
2176
- }, []), E = re((A) => {
2177
- k((S) => {
2178
- if (!S[A]) return S;
2179
- const m = { ...S };
2314
+ ) : n(r) ? /* @__PURE__ */ s(B, { children: e }) : /* @__PURE__ */ s(B, { children: t || /* @__PURE__ */ s(nr, { flagName: r }) });
2315
+ }
2316
+ function we(r) {
2317
+ const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError: a } = r, [l, d] = N(!1), [T, R] = N(""), [c, S] = N({}), h = te((A, k) => {
2318
+ S((m) => ({ ...m, [A]: k }));
2319
+ }, []), x = te((A) => {
2320
+ S((k) => {
2321
+ if (!k[A]) return k;
2322
+ const m = { ...k };
2180
2323
  return delete m[A], m;
2181
2324
  });
2182
- }, []), R = re(() => {
2183
- P(""), k({});
2184
- }, []), I = re(
2325
+ }, []), P = te(() => {
2326
+ R(""), S({});
2327
+ }, []), I = te(
2185
2328
  async (A) => {
2186
2329
  if (A && A.preventDefault(), !(n && !n())) {
2187
- d(!0), P("");
2330
+ d(!0), R("");
2188
2331
  try {
2189
- const S = await e();
2190
- return i == null || i(S), S;
2191
- } catch (S) {
2192
- const m = S instanceof Error ? S.message : t;
2193
- P(m), a == null || a(m);
2332
+ const k = await e();
2333
+ return i == null || i(k), k;
2334
+ } catch (k) {
2335
+ const m = k instanceof Error ? k.message : t;
2336
+ R(m), a == null || a(m);
2194
2337
  return;
2195
2338
  } finally {
2196
2339
  d(!1);
@@ -2202,15 +2345,15 @@ function ye(r) {
2202
2345
  return {
2203
2346
  loading: l,
2204
2347
  error: T,
2205
- setError: P,
2348
+ setError: R,
2206
2349
  fieldErrors: c,
2207
2350
  setFieldError: h,
2208
- clearFieldError: E,
2209
- resetErrors: R,
2351
+ clearFieldError: x,
2352
+ resetErrors: P,
2210
2353
  handleSubmit: I
2211
2354
  };
2212
2355
  }
2213
- const Xe = {
2356
+ const it = {
2214
2357
  container: {
2215
2358
  maxWidth: "400px",
2216
2359
  width: "100%",
@@ -2374,18 +2517,18 @@ const Xe = {
2374
2517
  color: "#6b7280"
2375
2518
  }
2376
2519
  };
2377
- function Ae(r, e) {
2520
+ function Le(r, e) {
2378
2521
  return {
2379
- ...Xe,
2522
+ ...it,
2380
2523
  ...e,
2381
2524
  button: {
2382
- ...Xe.button,
2525
+ ...it.button,
2383
2526
  backgroundColor: r,
2384
2527
  ...(e == null ? void 0 : e.button) || {}
2385
2528
  }
2386
2529
  };
2387
2530
  }
2388
- const jt = () => fe.createElement(
2531
+ const sr = () => me.createElement(
2389
2532
  "svg",
2390
2533
  {
2391
2534
  width: "16",
@@ -2398,9 +2541,9 @@ const jt = () => fe.createElement(
2398
2541
  strokeLinejoin: "round",
2399
2542
  style: { flexShrink: 0 }
2400
2543
  },
2401
- fe.createElement("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
2402
- fe.createElement("circle", { cx: "12", cy: "12", r: "3" })
2403
- ), Wt = () => fe.createElement(
2544
+ me.createElement("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
2545
+ me.createElement("circle", { cx: "12", cy: "12", r: "3" })
2546
+ ), ir = () => me.createElement(
2404
2547
  "svg",
2405
2548
  {
2406
2549
  width: "16",
@@ -2413,14 +2556,14 @@ const jt = () => fe.createElement(
2413
2556
  strokeLinejoin: "round",
2414
2557
  style: { flexShrink: 0 }
2415
2558
  },
2416
- fe.createElement("path", {
2559
+ me.createElement("path", {
2417
2560
  d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"
2418
2561
  }),
2419
- fe.createElement("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2420
- ), Gt = {
2421
- showPassword: /* @__PURE__ */ s(jt, {}),
2422
- hidePassword: /* @__PURE__ */ s(Wt, {})
2423
- }, Ht = {
2562
+ me.createElement("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2563
+ ), or = {
2564
+ showPassword: /* @__PURE__ */ s(sr, {}),
2565
+ hidePassword: /* @__PURE__ */ s(ir, {})
2566
+ }, ar = {
2424
2567
  title: "Sign In",
2425
2568
  usernameLabel: "Email or Phone",
2426
2569
  usernamePlaceholder: "Enter your email or phone number",
@@ -2439,7 +2582,7 @@ const jt = () => fe.createElement(
2439
2582
  showPasswordAriaLabel: "Show password",
2440
2583
  hidePasswordAriaLabel: "Hide password"
2441
2584
  };
2442
- function $r({
2585
+ function Zr({
2443
2586
  copy: r = {},
2444
2587
  styles: e = {},
2445
2588
  icons: t = {},
@@ -2449,28 +2592,28 @@ function $r({
2449
2592
  onSignupClick: l,
2450
2593
  onMagicLinkClick: d,
2451
2594
  showForgotPassword: T = !0,
2452
- showSignupLink: P = !0,
2595
+ showSignupLink: R = !0,
2453
2596
  showMagicLinkOption: c = !0,
2454
- className: k
2597
+ className: S
2455
2598
  }) {
2456
- const [h, E] = N(""), [R, I] = N(""), [A, S] = N(!1), { login: m } = ue(), g = { ...Ht, ...r }, b = Ae("#3b82f6", e), D = { ...Gt, ...t }, o = ye({
2599
+ const [h, x] = N(""), [P, I] = N(""), [A, k] = N(!1), { login: m } = de(), g = { ...ar, ...r }, b = Le("#3b82f6", e), C = { ...or, ...t }, o = we({
2457
2600
  defaultErrorMessage: g.errorMessage,
2458
2601
  validate: () => {
2459
2602
  const u = [];
2460
- return h.trim() || u.push("username"), R.trim() || u.push("password"), u.forEach((v) => o.setFieldError(v, !0)), u.length === 0;
2603
+ return h.trim() || u.push("username"), P.trim() || u.push("password"), u.forEach((v) => o.setFieldError(v, !0)), u.length === 0;
2461
2604
  },
2462
- submit: () => m({ username: h, password: R }),
2605
+ submit: () => m({ username: h, password: P }),
2463
2606
  onSuccess: n,
2464
2607
  onError: i
2465
2608
  }), p = (u) => ({
2466
2609
  ...b.input,
2467
2610
  ...o.fieldErrors[u] ? b.inputError : {}
2468
- }), x = !h || !R || o.loading, y = {
2611
+ }), E = !h || !P || o.loading, y = {
2469
2612
  ...b.button,
2470
2613
  ...o.loading ? b.buttonLoading : {},
2471
- ...x ? b.buttonDisabled : {}
2614
+ ...E ? b.buttonDisabled : {}
2472
2615
  };
2473
- return /* @__PURE__ */ f("div", { className: k, style: b.container, children: [
2616
+ return /* @__PURE__ */ f("div", { className: S, style: b.container, children: [
2474
2617
  /* @__PURE__ */ s("h2", { style: b.title, children: g.title }),
2475
2618
  /* @__PURE__ */ f("form", { onSubmit: o.handleSubmit, style: b.form, children: [
2476
2619
  /* @__PURE__ */ f("div", { style: b.fieldGroup, children: [
@@ -2483,7 +2626,7 @@ function $r({
2483
2626
  type: "text",
2484
2627
  value: h,
2485
2628
  onChange: (u) => {
2486
- E(u.target.value), o.clearFieldError("username");
2629
+ x(u.target.value), o.clearFieldError("username");
2487
2630
  },
2488
2631
  placeholder: g.usernamePlaceholder,
2489
2632
  style: p("username"),
@@ -2500,7 +2643,7 @@ function $r({
2500
2643
  id: "password",
2501
2644
  name: "password",
2502
2645
  type: A ? "text" : "password",
2503
- value: R,
2646
+ value: P,
2504
2647
  onChange: (u) => {
2505
2648
  I(u.target.value), o.clearFieldError("password");
2506
2649
  },
@@ -2513,19 +2656,19 @@ function $r({
2513
2656
  "button",
2514
2657
  {
2515
2658
  type: "button",
2516
- onClick: () => S(!A),
2659
+ onClick: () => k(!A),
2517
2660
  style: b.passwordToggle,
2518
2661
  disabled: o.loading,
2519
2662
  "aria-label": A ? g.hidePasswordAriaLabel : g.showPasswordAriaLabel,
2520
- children: A ? D.hidePassword : D.showPassword
2663
+ children: A ? C.hidePassword : C.showPassword
2521
2664
  }
2522
2665
  )
2523
2666
  ] })
2524
2667
  ] }),
2525
- /* @__PURE__ */ s("button", { type: "submit", disabled: x, style: y, children: o.loading ? g.loadingText : g.submitButton }),
2668
+ /* @__PURE__ */ s("button", { type: "submit", disabled: E, style: y, children: o.loading ? g.loadingText : g.submitButton }),
2526
2669
  o.error && /* @__PURE__ */ s("div", { style: b.errorText, children: o.error })
2527
2670
  ] }),
2528
- (T || P || c) && /* @__PURE__ */ f("div", { style: b.linkContainer, children: [
2671
+ (T || R || c) && /* @__PURE__ */ f("div", { style: b.linkContainer, children: [
2529
2672
  c && /* @__PURE__ */ f("div", { children: [
2530
2673
  /* @__PURE__ */ f("span", { style: b.divider, children: [
2531
2674
  g.magicLinkText,
@@ -2533,10 +2676,10 @@ function $r({
2533
2676
  ] }),
2534
2677
  /* @__PURE__ */ s("a", { onClick: d, style: b.link, children: g.magicLinkLink })
2535
2678
  ] }),
2536
- c && (T || P) && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2679
+ c && (T || R) && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2537
2680
  T && /* @__PURE__ */ s("a", { onClick: a, style: b.link, children: g.forgotPasswordLink }),
2538
- T && P && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2539
- P && /* @__PURE__ */ f("div", { children: [
2681
+ T && R && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2682
+ R && /* @__PURE__ */ f("div", { children: [
2540
2683
  /* @__PURE__ */ f("span", { style: b.divider, children: [
2541
2684
  g.signupText,
2542
2685
  " "
@@ -2546,7 +2689,7 @@ function $r({
2546
2689
  ] })
2547
2690
  ] });
2548
2691
  }
2549
- const Qt = {
2692
+ const lr = {
2550
2693
  title: "Create Account",
2551
2694
  nameLabel: "First Name",
2552
2695
  namePlaceholder: "Enter your first name",
@@ -2576,7 +2719,7 @@ const Qt = {
2576
2719
  tenantNotFoundError: "Tenant not found",
2577
2720
  dividerBullet: "•"
2578
2721
  };
2579
- function Mr({
2722
+ function Kr({
2580
2723
  copy: r = {},
2581
2724
  styles: e = {},
2582
2725
  signupType: t = "user",
@@ -2586,24 +2729,24 @@ function Mr({
2586
2729
  onMagicLinkClick: l,
2587
2730
  showLoginLink: d = !0,
2588
2731
  showMagicLinkOption: T = !0,
2589
- className: P
2732
+ className: R
2590
2733
  }) {
2591
- var M;
2592
- const [c, k] = N(""), [h, E] = N(""), [R, I] = N(""), [A, S] = N(""), [m, g] = N(""), [b, D] = N(""), [o, p] = N(""), { signup: x, signupTenantAdmin: y } = ue(), u = ((M = he()) == null ? void 0 : M.tenant) ?? null, v = { ...Qt, ...r }, C = Ae("#10b981", e), ie = !!c && (!!R || !!A) && !!m && !!b && (t === "user" || !!o), L = ye({
2734
+ var U;
2735
+ const [c, S] = N(""), [h, x] = N(""), [P, I] = N(""), [A, k] = N(""), [m, g] = N(""), [b, C] = N(""), [o, p] = N(""), { signup: E, signupTenantAdmin: y } = de(), u = ((U = pe()) == null ? void 0 : U.tenant) ?? null, v = { ...lr, ...r }, D = Le("#10b981", e), se = !!c && (!!P || !!A) && !!m && !!b && (t === "user" || !!o), F = we({
2593
2736
  defaultErrorMessage: v.errorMessage,
2594
2737
  validate: () => {
2595
- const F = [];
2596
- return c.trim() || F.push("name"), !R.trim() && !A.trim() && (F.push("email"), F.push("phoneNumber")), m.trim() || F.push("password"), b.trim() || F.push("confirmPassword"), t === "tenant" && !o.trim() && F.push("tenantName"), F.forEach((V) => L.setFieldError(V, !0)), F.length > 0 ? !1 : m !== b ? (L.setError(v.passwordMismatchError), L.setFieldError("confirmPassword", !0), !1) : t === "user" && !(u != null && u.id) ? (L.setError(v.tenantNotFoundError), !1) : !0;
2738
+ const L = [];
2739
+ return c.trim() || L.push("name"), !P.trim() && !A.trim() && (L.push("email"), L.push("phoneNumber")), m.trim() || L.push("password"), b.trim() || L.push("confirmPassword"), t === "tenant" && !o.trim() && L.push("tenantName"), L.forEach((q) => F.setFieldError(q, !0)), L.length > 0 ? !1 : m !== b ? (F.setError(v.passwordMismatchError), F.setFieldError("confirmPassword", !0), !1) : t === "user" && !(u != null && u.id) ? (F.setError(v.tenantNotFoundError), !1) : !0;
2597
2740
  },
2598
2741
  submit: async () => t === "tenant" ? y({
2599
- email: R || void 0,
2742
+ email: P || void 0,
2600
2743
  phoneNumber: A || void 0,
2601
2744
  name: c,
2602
2745
  password: m,
2603
2746
  tenantName: o,
2604
2747
  lastName: h || void 0
2605
- }) : x({
2606
- email: R || void 0,
2748
+ }) : E({
2749
+ email: P || void 0,
2607
2750
  phoneNumber: A || void 0,
2608
2751
  name: c,
2609
2752
  password: m,
@@ -2612,21 +2755,21 @@ function Mr({
2612
2755
  }),
2613
2756
  onSuccess: n,
2614
2757
  onError: i
2615
- }), H = (F) => ({
2616
- ...C.input,
2617
- ...L.fieldErrors[F] ? C.inputError : {}
2618
- }), j = !ie || L.loading, Z = {
2619
- ...C.button,
2620
- ...L.loading ? C.buttonLoading : {},
2621
- ...j ? C.buttonDisabled : {}
2758
+ }), H = (L) => ({
2759
+ ...D.input,
2760
+ ...F.fieldErrors[L] ? D.inputError : {}
2761
+ }), j = !se || F.loading, Z = {
2762
+ ...D.button,
2763
+ ...F.loading ? D.buttonLoading : {},
2764
+ ...j ? D.buttonDisabled : {}
2622
2765
  }, $ = () => {
2623
- L.clearFieldError("email"), L.clearFieldError("phoneNumber");
2766
+ F.clearFieldError("email"), F.clearFieldError("phoneNumber");
2624
2767
  };
2625
- return /* @__PURE__ */ f("div", { className: P, style: C.container, children: [
2626
- /* @__PURE__ */ s("h2", { style: C.title, children: v.title }),
2627
- /* @__PURE__ */ f("form", { onSubmit: L.handleSubmit, style: C.form, children: [
2628
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2629
- /* @__PURE__ */ s("label", { style: C.label, children: v.nameLabel }),
2768
+ return /* @__PURE__ */ f("div", { className: R, style: D.container, children: [
2769
+ /* @__PURE__ */ s("h2", { style: D.title, children: v.title }),
2770
+ /* @__PURE__ */ f("form", { onSubmit: F.handleSubmit, style: D.form, children: [
2771
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2772
+ /* @__PURE__ */ s("label", { style: D.label, children: v.nameLabel }),
2630
2773
  /* @__PURE__ */ s(
2631
2774
  "input",
2632
2775
  {
@@ -2634,17 +2777,17 @@ function Mr({
2634
2777
  name: "name",
2635
2778
  type: "text",
2636
2779
  value: c,
2637
- onChange: (F) => {
2638
- k(F.target.value), L.clearFieldError("name");
2780
+ onChange: (L) => {
2781
+ S(L.target.value), F.clearFieldError("name");
2639
2782
  },
2640
2783
  placeholder: v.namePlaceholder,
2641
2784
  style: H("name"),
2642
- disabled: L.loading
2785
+ disabled: F.loading
2643
2786
  }
2644
2787
  )
2645
2788
  ] }),
2646
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2647
- /* @__PURE__ */ s("label", { style: C.label, children: v.lastNameLabel }),
2789
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2790
+ /* @__PURE__ */ s("label", { style: D.label, children: v.lastNameLabel }),
2648
2791
  /* @__PURE__ */ s(
2649
2792
  "input",
2650
2793
  {
@@ -2652,33 +2795,33 @@ function Mr({
2652
2795
  name: "lastName",
2653
2796
  type: "text",
2654
2797
  value: h,
2655
- onChange: (F) => E(F.target.value),
2798
+ onChange: (L) => x(L.target.value),
2656
2799
  placeholder: v.lastNamePlaceholder,
2657
- style: C.input,
2658
- disabled: L.loading
2800
+ style: D.input,
2801
+ disabled: F.loading
2659
2802
  }
2660
2803
  )
2661
2804
  ] }),
2662
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2663
- /* @__PURE__ */ s("label", { style: C.label, children: v.emailLabel }),
2805
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2806
+ /* @__PURE__ */ s("label", { style: D.label, children: v.emailLabel }),
2664
2807
  /* @__PURE__ */ s(
2665
2808
  "input",
2666
2809
  {
2667
2810
  id: "email",
2668
2811
  name: "email",
2669
2812
  type: "email",
2670
- value: R,
2671
- onChange: (F) => {
2672
- I(F.target.value), $();
2813
+ value: P,
2814
+ onChange: (L) => {
2815
+ I(L.target.value), $();
2673
2816
  },
2674
2817
  placeholder: v.emailPlaceholder,
2675
2818
  style: H("email"),
2676
- disabled: L.loading
2819
+ disabled: F.loading
2677
2820
  }
2678
2821
  )
2679
2822
  ] }),
2680
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2681
- /* @__PURE__ */ s("label", { style: C.label, children: v.phoneNumberLabel }),
2823
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2824
+ /* @__PURE__ */ s("label", { style: D.label, children: v.phoneNumberLabel }),
2682
2825
  /* @__PURE__ */ s(
2683
2826
  "input",
2684
2827
  {
@@ -2686,18 +2829,18 @@ function Mr({
2686
2829
  name: "phoneNumber",
2687
2830
  type: "tel",
2688
2831
  value: A,
2689
- onChange: (F) => {
2690
- S(F.target.value), $();
2832
+ onChange: (L) => {
2833
+ k(L.target.value), $();
2691
2834
  },
2692
2835
  placeholder: v.phoneNumberPlaceholder,
2693
2836
  style: H("phoneNumber"),
2694
- disabled: L.loading
2837
+ disabled: F.loading
2695
2838
  }
2696
2839
  )
2697
2840
  ] }),
2698
- /* @__PURE__ */ s("div", { style: C.hintText, children: v.contactMethodHint }),
2699
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2700
- /* @__PURE__ */ s("label", { style: C.label, children: v.passwordLabel }),
2841
+ /* @__PURE__ */ s("div", { style: D.hintText, children: v.contactMethodHint }),
2842
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2843
+ /* @__PURE__ */ s("label", { style: D.label, children: v.passwordLabel }),
2701
2844
  /* @__PURE__ */ s(
2702
2845
  "input",
2703
2846
  {
@@ -2705,17 +2848,17 @@ function Mr({
2705
2848
  name: "password",
2706
2849
  type: "password",
2707
2850
  value: m,
2708
- onChange: (F) => {
2709
- g(F.target.value), L.clearFieldError("password");
2851
+ onChange: (L) => {
2852
+ g(L.target.value), F.clearFieldError("password");
2710
2853
  },
2711
2854
  placeholder: v.passwordPlaceholder,
2712
2855
  style: H("password"),
2713
- disabled: L.loading
2856
+ disabled: F.loading
2714
2857
  }
2715
2858
  )
2716
2859
  ] }),
2717
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2718
- /* @__PURE__ */ s("label", { style: C.label, children: v.confirmPasswordLabel }),
2860
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2861
+ /* @__PURE__ */ s("label", { style: D.label, children: v.confirmPasswordLabel }),
2719
2862
  /* @__PURE__ */ s(
2720
2863
  "input",
2721
2864
  {
@@ -2723,17 +2866,17 @@ function Mr({
2723
2866
  name: "confirmPassword",
2724
2867
  type: "password",
2725
2868
  value: b,
2726
- onChange: (F) => {
2727
- D(F.target.value), L.clearFieldError("confirmPassword"), L.error === v.passwordMismatchError && L.setError("");
2869
+ onChange: (L) => {
2870
+ C(L.target.value), F.clearFieldError("confirmPassword"), F.error === v.passwordMismatchError && F.setError("");
2728
2871
  },
2729
2872
  placeholder: v.confirmPasswordPlaceholder,
2730
2873
  style: H("confirmPassword"),
2731
- disabled: L.loading
2874
+ disabled: F.loading
2732
2875
  }
2733
2876
  )
2734
2877
  ] }),
2735
- t === "tenant" && /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2736
- /* @__PURE__ */ s("label", { style: C.label, children: v.tenantNameLabel }),
2878
+ t === "tenant" && /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2879
+ /* @__PURE__ */ s("label", { style: D.label, children: v.tenantNameLabel }),
2737
2880
  /* @__PURE__ */ s(
2738
2881
  "input",
2739
2882
  {
@@ -2741,38 +2884,38 @@ function Mr({
2741
2884
  name: "tenantName",
2742
2885
  type: "text",
2743
2886
  value: o,
2744
- onChange: (F) => {
2745
- p(F.target.value), L.clearFieldError("tenantName");
2887
+ onChange: (L) => {
2888
+ p(L.target.value), F.clearFieldError("tenantName");
2746
2889
  },
2747
2890
  placeholder: v.tenantNamePlaceholder,
2748
2891
  style: H("tenantName"),
2749
- disabled: L.loading
2892
+ disabled: F.loading
2750
2893
  }
2751
2894
  )
2752
2895
  ] }),
2753
- /* @__PURE__ */ s("button", { type: "submit", disabled: j, style: Z, children: L.loading ? v.loadingText : v.submitButton }),
2754
- L.error && /* @__PURE__ */ s("div", { style: C.errorText, children: L.error })
2896
+ /* @__PURE__ */ s("button", { type: "submit", disabled: j, style: Z, children: F.loading ? v.loadingText : v.submitButton }),
2897
+ F.error && /* @__PURE__ */ s("div", { style: D.errorText, children: F.error })
2755
2898
  ] }),
2756
- (d || T) && /* @__PURE__ */ f("div", { style: C.linkContainer, children: [
2899
+ (d || T) && /* @__PURE__ */ f("div", { style: D.linkContainer, children: [
2757
2900
  T && /* @__PURE__ */ f("div", { children: [
2758
- /* @__PURE__ */ f("span", { style: C.divider, children: [
2901
+ /* @__PURE__ */ f("span", { style: D.divider, children: [
2759
2902
  v.magicLinkText,
2760
2903
  " "
2761
2904
  ] }),
2762
- /* @__PURE__ */ s("a", { onClick: l, style: C.link, children: v.magicLinkLink })
2905
+ /* @__PURE__ */ s("a", { onClick: l, style: D.link, children: v.magicLinkLink })
2763
2906
  ] }),
2764
- T && d && /* @__PURE__ */ s("div", { style: C.divider, children: v.dividerBullet }),
2907
+ T && d && /* @__PURE__ */ s("div", { style: D.divider, children: v.dividerBullet }),
2765
2908
  d && /* @__PURE__ */ f("div", { children: [
2766
- /* @__PURE__ */ f("span", { style: C.divider, children: [
2909
+ /* @__PURE__ */ f("span", { style: D.divider, children: [
2767
2910
  v.loginText,
2768
2911
  " "
2769
2912
  ] }),
2770
- /* @__PURE__ */ s("a", { onClick: a, style: C.link, children: v.loginLink })
2913
+ /* @__PURE__ */ s("a", { onClick: a, style: D.link, children: v.loginLink })
2771
2914
  ] })
2772
2915
  ] })
2773
2916
  ] });
2774
2917
  }
2775
- const Jt = {
2918
+ const cr = {
2776
2919
  title: "Sign In with Magic Link",
2777
2920
  emailLabel: "Email",
2778
2921
  emailPlaceholder: "Enter your email",
@@ -2797,7 +2940,7 @@ const Jt = {
2797
2940
  missingTenantOrEmailError: "Missing tenant or email",
2798
2941
  dividerBullet: "•"
2799
2942
  };
2800
- function Br({
2943
+ function Yr({
2801
2944
  copy: r = {},
2802
2945
  styles: e = {},
2803
2946
  onSuccess: t,
@@ -2807,37 +2950,37 @@ function Br({
2807
2950
  showTraditionalLinks: l = !0,
2808
2951
  className: d,
2809
2952
  verifyToken: T,
2810
- frontendUrl: P
2953
+ frontendUrl: R
2811
2954
  }) {
2812
2955
  var H;
2813
- const [c, k] = N(""), [h, E] = N(""), [R, I] = N(""), [A, S] = N(!1), [m, g] = N(""), [b, D] = N(!1), { sendMagicLink: o, verifyMagicLink: p } = ue(), x = ((H = he()) == null ? void 0 : H.tenant) ?? null, y = { ...Jt, ...r }, u = Ae("#3b82f6", e), v = ye({
2956
+ const [c, S] = N(""), [h, x] = N(""), [P, I] = N(""), [A, k] = N(!1), [m, g] = N(""), [b, C] = N(!1), { sendMagicLink: o, verifyMagicLink: p } = de(), E = ((H = pe()) == null ? void 0 : H.tenant) ?? null, y = { ...cr, ...r }, u = Le("#3b82f6", e), v = we({
2814
2957
  defaultErrorMessage: y.errorMessage,
2815
2958
  validate: () => {
2816
2959
  const j = [];
2817
- return c.trim() || j.push("email"), b && !h.trim() && j.push("name"), j.forEach((Z) => v.setFieldError(Z, !0)), j.length > 0 ? !1 : x != null && x.id ? !0 : (v.setError(y.tenantNotFoundError), !1);
2960
+ return c.trim() || j.push("email"), b && !h.trim() && j.push("name"), j.forEach((Z) => v.setFieldError(Z, !0)), j.length > 0 ? !1 : E != null && E.id ? !0 : (v.setError(y.tenantNotFoundError), !1);
2818
2961
  },
2819
2962
  submit: async () => {
2820
2963
  g("");
2821
- const j = P || (typeof window < "u" ? window.location.origin : ""), Z = await o({
2964
+ const j = R || (typeof window < "u" ? window.location.origin : ""), Z = await o({
2822
2965
  email: c,
2823
- tenantId: x.id,
2966
+ tenantId: E.id,
2824
2967
  frontendUrl: j,
2825
2968
  name: b ? h : void 0,
2826
- lastName: b ? R : void 0
2969
+ lastName: b ? P : void 0
2827
2970
  });
2828
2971
  return g(y.successMessage), Z;
2829
2972
  },
2830
2973
  onSuccess: t,
2831
2974
  onError: n
2832
2975
  });
2833
- ne(() => {
2976
+ re(() => {
2834
2977
  if (!T) return;
2835
2978
  (async () => {
2836
- if (!x || !c) {
2979
+ if (!E || !c) {
2837
2980
  v.setError(y.missingTenantOrEmailError);
2838
2981
  return;
2839
2982
  }
2840
- S(!0), v.setError("");
2983
+ k(!0), v.setError("");
2841
2984
  try {
2842
2985
  const Z = await p({ token: T, email: c });
2843
2986
  t == null || t(Z);
@@ -2845,17 +2988,17 @@ function Br({
2845
2988
  const $ = Z instanceof Error ? Z.message : "Failed to verify magic link";
2846
2989
  v.setError($), n == null || n($);
2847
2990
  } finally {
2848
- S(!1);
2991
+ k(!1);
2849
2992
  }
2850
2993
  })();
2851
2994
  }, [T]);
2852
- const C = (j) => ({
2995
+ const D = (j) => ({
2853
2996
  ...u.input,
2854
2997
  ...v.fieldErrors[j] ? u.inputError : {}
2855
- }), ie = !c || v.loading || A, L = {
2998
+ }), se = !c || v.loading || A, F = {
2856
2999
  ...u.button,
2857
3000
  ...v.loading || A ? u.buttonLoading : {},
2858
- ...ie ? u.buttonDisabled : {}
3001
+ ...se ? u.buttonDisabled : {}
2859
3002
  };
2860
3003
  return A ? /* @__PURE__ */ f("div", { className: d, style: u.container, children: [
2861
3004
  /* @__PURE__ */ s("h2", { style: u.title, children: y.verifyingText }),
@@ -2874,10 +3017,10 @@ function Br({
2874
3017
  type: "email",
2875
3018
  value: c,
2876
3019
  onChange: (j) => {
2877
- k(j.target.value), v.clearFieldError("email");
3020
+ S(j.target.value), v.clearFieldError("email");
2878
3021
  },
2879
3022
  placeholder: y.emailPlaceholder,
2880
- style: C("email"),
3023
+ style: D("email"),
2881
3024
  disabled: v.loading || A
2882
3025
  }
2883
3026
  )
@@ -2886,7 +3029,7 @@ function Br({
2886
3029
  "button",
2887
3030
  {
2888
3031
  type: "button",
2889
- onClick: () => D(!0),
3032
+ onClick: () => C(!0),
2890
3033
  style: u.toggleLink,
2891
3034
  children: y.showNameToggle
2892
3035
  }
@@ -2902,10 +3045,10 @@ function Br({
2902
3045
  type: "text",
2903
3046
  value: h,
2904
3047
  onChange: (j) => {
2905
- E(j.target.value), v.clearFieldError("name");
3048
+ x(j.target.value), v.clearFieldError("name");
2906
3049
  },
2907
3050
  placeholder: y.namePlaceholder,
2908
- style: C("name"),
3051
+ style: D("name"),
2909
3052
  disabled: v.loading || A
2910
3053
  }
2911
3054
  )
@@ -2918,7 +3061,7 @@ function Br({
2918
3061
  id: "lastName",
2919
3062
  name: "lastName",
2920
3063
  type: "text",
2921
- value: R,
3064
+ value: P,
2922
3065
  onChange: (j) => I(j.target.value),
2923
3066
  placeholder: y.lastNamePlaceholder,
2924
3067
  style: u.input,
@@ -2931,14 +3074,14 @@ function Br({
2931
3074
  {
2932
3075
  type: "button",
2933
3076
  onClick: () => {
2934
- D(!1), E(""), I("");
3077
+ C(!1), x(""), I("");
2935
3078
  },
2936
3079
  style: u.toggleLink,
2937
3080
  children: y.hideNameToggle
2938
3081
  }
2939
3082
  ) })
2940
3083
  ] }),
2941
- /* @__PURE__ */ s("button", { type: "submit", disabled: ie, style: L, children: v.loading ? y.loadingText : y.submitButton }),
3084
+ /* @__PURE__ */ s("button", { type: "submit", disabled: se, style: F, children: v.loading ? y.loadingText : y.submitButton }),
2942
3085
  v.error && /* @__PURE__ */ s("div", { style: u.errorText, children: v.error }),
2943
3086
  m && /* @__PURE__ */ s("div", { style: u.successText, children: m })
2944
3087
  ] }),
@@ -2961,7 +3104,7 @@ function Br({
2961
3104
  ] })
2962
3105
  ] });
2963
3106
  }
2964
- const Zt = {
3107
+ const ur = {
2965
3108
  title: "Verifying Magic Link",
2966
3109
  verifyingMessage: "Please wait while we verify your magic link...",
2967
3110
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2970,7 +3113,7 @@ const Zt = {
2970
3113
  retryButton: "Try Again",
2971
3114
  backToLoginButton: "Back to Login",
2972
3115
  missingParamsError: "Missing required parameters: token or email"
2973
- }, st = {
3116
+ }, ut = {
2974
3117
  container: {
2975
3118
  maxWidth: "400px",
2976
3119
  width: "100%",
@@ -3063,7 +3206,7 @@ const Zt = {
3063
3206
  backButtonHover: {
3064
3207
  backgroundColor: "#e5e7eb"
3065
3208
  }
3066
- }, Kt = () => /* @__PURE__ */ s("div", { style: st.spinner }), Yt = () => /* @__PURE__ */ f(
3209
+ }, dr = () => /* @__PURE__ */ s("div", { style: ut.spinner }), hr = () => /* @__PURE__ */ f(
3067
3210
  "svg",
3068
3211
  {
3069
3212
  width: "48",
@@ -3080,7 +3223,7 @@ const Zt = {
3080
3223
  /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3081
3224
  ]
3082
3225
  }
3083
- ), Xt = () => /* @__PURE__ */ f(
3226
+ ), pr = () => /* @__PURE__ */ f(
3084
3227
  "svg",
3085
3228
  {
3086
3229
  width: "48",
@@ -3098,12 +3241,12 @@ const Zt = {
3098
3241
  /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3099
3242
  ]
3100
3243
  }
3101
- ), er = {
3102
- loading: /* @__PURE__ */ s(Kt, {}),
3103
- success: /* @__PURE__ */ s(Yt, {}),
3104
- error: /* @__PURE__ */ s(Xt, {})
3244
+ ), fr = {
3245
+ loading: /* @__PURE__ */ s(dr, {}),
3246
+ success: /* @__PURE__ */ s(hr, {}),
3247
+ error: /* @__PURE__ */ s(pr, {})
3105
3248
  };
3106
- function Or({
3249
+ function Xr({
3107
3250
  copy: r = {},
3108
3251
  styles: e = {},
3109
3252
  icons: t = {},
@@ -3113,48 +3256,48 @@ function Or({
3113
3256
  onBackToLogin: l,
3114
3257
  className: d,
3115
3258
  token: T,
3116
- email: P,
3259
+ email: R,
3117
3260
  appId: c,
3118
- tenantSlug: k,
3261
+ tenantSlug: S,
3119
3262
  autoRedirectDelay: h = 3e3
3120
3263
  }) {
3121
- const [E, R] = N("verifying"), [I, A] = N(""), { verifyMagicLink: S } = ue(), m = { ...Zt, ...r }, g = { ...st, ...e }, b = { ...er, ...t }, D = () => {
3264
+ const [x, P] = N("verifying"), [I, A] = N(""), { verifyMagicLink: k } = de(), m = { ...ur, ...r }, g = { ...ut, ...e }, b = { ...fr, ...t }, C = () => {
3122
3265
  if (typeof window > "u") return {};
3123
3266
  const u = new URLSearchParams(window.location.search);
3124
3267
  return {
3125
3268
  token: T || u.get("token") || "",
3126
- email: P || u.get("email") || "",
3269
+ email: R || u.get("email") || "",
3127
3270
  appId: c || u.get("appId") || "",
3128
- tenantSlug: k || u.get("tenantSlug") || void 0
3271
+ tenantSlug: S || u.get("tenantSlug") || void 0
3129
3272
  };
3130
3273
  }, o = async () => {
3131
- R("verifying"), A("");
3274
+ P("verifying"), A("");
3132
3275
  try {
3133
- const u = D();
3276
+ const u = C();
3134
3277
  if (!u.token || !u.email)
3135
3278
  throw new Error(m.missingParamsError);
3136
- const v = await S({
3279
+ const v = await k({
3137
3280
  token: u.token,
3138
3281
  email: u.email,
3139
3282
  tenantSlug: u.tenantSlug
3140
3283
  });
3141
- R("success"), n == null || n(v), h > 0 && setTimeout(() => {
3142
- R("redirecting");
3284
+ P("success"), n == null || n(v), h > 0 && setTimeout(() => {
3285
+ P("redirecting");
3143
3286
  }, h);
3144
3287
  } catch (u) {
3145
3288
  const v = u.message || m.errorMessage;
3146
- A(v), R("error"), i == null || i(v);
3289
+ A(v), P("error"), i == null || i(v);
3147
3290
  }
3148
3291
  }, p = () => {
3149
3292
  a == null || a(), o();
3150
- }, x = () => {
3293
+ }, E = () => {
3151
3294
  l == null || l();
3152
3295
  };
3153
- ne(() => {
3296
+ re(() => {
3154
3297
  o();
3155
3298
  }, []);
3156
3299
  const y = () => {
3157
- switch (E) {
3300
+ switch (x) {
3158
3301
  case "verifying":
3159
3302
  return /* @__PURE__ */ f("div", { style: g.message, children: [
3160
3303
  b.loading,
@@ -3185,8 +3328,8 @@ function Or({
3185
3328
  },
3186
3329
  onMouseOut: (u) => {
3187
3330
  const v = g.retryButton || {};
3188
- Object.keys(g.retryButtonHover || {}).forEach((C) => {
3189
- u.currentTarget.style[C] = v[C] ?? "";
3331
+ Object.keys(g.retryButtonHover || {}).forEach((D) => {
3332
+ u.currentTarget.style[D] = v[D] ?? "";
3190
3333
  });
3191
3334
  },
3192
3335
  children: m.retryButton
@@ -3195,15 +3338,15 @@ function Or({
3195
3338
  /* @__PURE__ */ s(
3196
3339
  "button",
3197
3340
  {
3198
- onClick: x,
3341
+ onClick: E,
3199
3342
  style: g.backButton,
3200
3343
  onMouseOver: (u) => {
3201
3344
  Object.assign(u.currentTarget.style, g.backButtonHover);
3202
3345
  },
3203
3346
  onMouseOut: (u) => {
3204
3347
  const v = g.backButton || {};
3205
- Object.keys(g.backButtonHover || {}).forEach((C) => {
3206
- u.currentTarget.style[C] = v[C] ?? "";
3348
+ Object.keys(g.backButtonHover || {}).forEach((D) => {
3349
+ u.currentTarget.style[D] = v[D] ?? "";
3207
3350
  });
3208
3351
  },
3209
3352
  children: m.backToLoginButton
@@ -3226,7 +3369,7 @@ function Or({
3226
3369
  y()
3227
3370
  ] });
3228
3371
  }
3229
- const tr = {
3372
+ const mr = {
3230
3373
  title: "Reset Password",
3231
3374
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3232
3375
  emailLabel: "Email",
@@ -3253,7 +3396,7 @@ const tr = {
3253
3396
  tenantNotFoundError: "Tenant not found",
3254
3397
  dividerBullet: "•"
3255
3398
  };
3256
- function _r({
3399
+ function en({
3257
3400
  copy: r = {},
3258
3401
  styles: e = {},
3259
3402
  mode: t = "request",
@@ -3264,32 +3407,32 @@ function _r({
3264
3407
  onModeChange: d,
3265
3408
  className: T
3266
3409
  }) {
3267
- var ie;
3268
- const [P, c] = N(""), [k, h] = N(n), [E, R] = N(""), [I, A] = N(""), [S, m] = N(""), { requestPasswordReset: g, confirmPasswordReset: b } = ue(), D = ((ie = he()) == null ? void 0 : ie.tenant) ?? null, o = { ...tr, ...r }, p = Ae("#f59e0b", e), x = ye({
3410
+ var se;
3411
+ const [R, c] = N(""), [S, h] = N(n), [x, P] = N(""), [I, A] = N(""), [k, m] = N(""), { requestPasswordReset: g, confirmPasswordReset: b } = de(), C = ((se = pe()) == null ? void 0 : se.tenant) ?? null, o = { ...mr, ...r }, p = Le("#f59e0b", e), E = we({
3269
3412
  defaultErrorMessage: o.errorMessage,
3270
- validate: () => P.trim() ? D != null && D.id ? !0 : (x.setError(o.tenantNotFoundError), !1) : (x.setFieldError("email", !0), !1),
3413
+ validate: () => R.trim() ? C != null && C.id ? !0 : (E.setError(o.tenantNotFoundError), !1) : (E.setFieldError("email", !0), !1),
3271
3414
  submit: async () => {
3272
- m(""), await g({ email: P, tenantId: D.id }), m(o.successMessage);
3415
+ m(""), await g({ email: R, tenantId: C.id }), m(o.successMessage);
3273
3416
  },
3274
3417
  onSuccess: () => i == null ? void 0 : i(),
3275
3418
  onError: a
3276
- }), y = ye({
3419
+ }), y = we({
3277
3420
  defaultErrorMessage: o.errorMessage,
3278
3421
  validate: () => {
3279
- const L = [];
3280
- return k.trim() || L.push("token"), E.trim() || L.push("newPassword"), I.trim() || L.push("confirmPassword"), L.forEach((H) => y.setFieldError(H, !0)), L.length > 0 ? !1 : E !== I ? (y.setError(o.passwordMismatchError), y.setFieldError("confirmPassword", !0), !1) : !0;
3422
+ const F = [];
3423
+ return S.trim() || F.push("token"), x.trim() || F.push("newPassword"), I.trim() || F.push("confirmPassword"), F.forEach((H) => y.setFieldError(H, !0)), F.length > 0 ? !1 : x !== I ? (y.setError(o.passwordMismatchError), y.setFieldError("confirmPassword", !0), !1) : !0;
3281
3424
  },
3282
3425
  submit: async () => {
3283
- m(""), await b({ token: k, newPassword: E }), m(o.resetSuccessMessage);
3426
+ m(""), await b({ token: S, newPassword: x }), m(o.resetSuccessMessage);
3284
3427
  },
3285
3428
  onSuccess: () => i == null ? void 0 : i(),
3286
3429
  onError: a
3287
3430
  });
3288
3431
  if (t === "reset") {
3289
- const L = ($) => ({
3432
+ const F = ($) => ({
3290
3433
  ...p.input,
3291
3434
  ...y.fieldErrors[$] ? p.inputError : {}
3292
- }), j = !(!!k && !!E && !!I) || y.loading, Z = {
3435
+ }), j = !(!!S && !!x && !!I) || y.loading, Z = {
3293
3436
  ...p.button,
3294
3437
  ...y.loading ? p.buttonLoading : {},
3295
3438
  ...j ? p.buttonDisabled : {}
@@ -3304,12 +3447,12 @@ function _r({
3304
3447
  "input",
3305
3448
  {
3306
3449
  type: "text",
3307
- value: k,
3450
+ value: S,
3308
3451
  onChange: ($) => {
3309
3452
  h($.target.value), y.clearFieldError("token");
3310
3453
  },
3311
3454
  placeholder: o.tokenPlaceholder,
3312
- style: L("token"),
3455
+ style: F("token"),
3313
3456
  disabled: y.loading
3314
3457
  }
3315
3458
  )
@@ -3320,12 +3463,12 @@ function _r({
3320
3463
  "input",
3321
3464
  {
3322
3465
  type: "password",
3323
- value: E,
3466
+ value: x,
3324
3467
  onChange: ($) => {
3325
- R($.target.value), y.clearFieldError("newPassword");
3468
+ P($.target.value), y.clearFieldError("newPassword");
3326
3469
  },
3327
3470
  placeholder: o.newPasswordPlaceholder,
3328
- style: L("newPassword"),
3471
+ style: F("newPassword"),
3329
3472
  disabled: y.loading
3330
3473
  }
3331
3474
  )
@@ -3341,14 +3484,14 @@ function _r({
3341
3484
  A($.target.value), y.clearFieldError("confirmPassword"), y.error === o.passwordMismatchError && y.setError("");
3342
3485
  },
3343
3486
  placeholder: o.confirmPasswordPlaceholder,
3344
- style: L("confirmPassword"),
3487
+ style: F("confirmPassword"),
3345
3488
  disabled: y.loading
3346
3489
  }
3347
3490
  )
3348
3491
  ] }),
3349
3492
  /* @__PURE__ */ s("button", { type: "submit", disabled: j, style: Z, children: y.loading ? o.resetLoadingText : o.resetSubmitButton }),
3350
3493
  y.error && /* @__PURE__ */ s("div", { style: p.errorText, children: y.error }),
3351
- S && /* @__PURE__ */ s("div", { style: p.successText, children: S })
3494
+ k && /* @__PURE__ */ s("div", { style: p.successText, children: k })
3352
3495
  ] }),
3353
3496
  /* @__PURE__ */ f("div", { style: p.linkContainer, children: [
3354
3497
  /* @__PURE__ */ s("a", { onClick: l, style: p.link, children: o.backToLoginLink }),
@@ -3359,37 +3502,37 @@ function _r({
3359
3502
  ] })
3360
3503
  ] });
3361
3504
  }
3362
- const u = (L) => ({
3505
+ const u = (F) => ({
3363
3506
  ...p.input,
3364
- ...x.fieldErrors[L] ? p.inputError : {}
3365
- }), v = !P || x.loading, C = {
3507
+ ...E.fieldErrors[F] ? p.inputError : {}
3508
+ }), v = !R || E.loading, D = {
3366
3509
  ...p.button,
3367
- ...x.loading ? p.buttonLoading : {},
3510
+ ...E.loading ? p.buttonLoading : {},
3368
3511
  ...v ? p.buttonDisabled : {}
3369
3512
  };
3370
3513
  return /* @__PURE__ */ f("div", { className: T, style: p.container, children: [
3371
3514
  /* @__PURE__ */ s("h2", { style: p.title, children: o.title }),
3372
3515
  /* @__PURE__ */ s("p", { style: p.subtitle, children: o.subtitle }),
3373
- /* @__PURE__ */ f("form", { onSubmit: x.handleSubmit, style: p.form, children: [
3516
+ /* @__PURE__ */ f("form", { onSubmit: E.handleSubmit, style: p.form, children: [
3374
3517
  /* @__PURE__ */ f("div", { style: p.fieldGroup, children: [
3375
3518
  /* @__PURE__ */ s("label", { style: p.label, children: o.emailLabel }),
3376
3519
  /* @__PURE__ */ s(
3377
3520
  "input",
3378
3521
  {
3379
3522
  type: "email",
3380
- value: P,
3381
- onChange: (L) => {
3382
- c(L.target.value), x.clearFieldError("email");
3523
+ value: R,
3524
+ onChange: (F) => {
3525
+ c(F.target.value), E.clearFieldError("email");
3383
3526
  },
3384
3527
  placeholder: o.emailPlaceholder,
3385
3528
  style: u("email"),
3386
- disabled: x.loading
3529
+ disabled: E.loading
3387
3530
  }
3388
3531
  )
3389
3532
  ] }),
3390
- /* @__PURE__ */ s("button", { type: "submit", disabled: v, style: C, children: x.loading ? o.loadingText : o.submitButton }),
3391
- x.error && /* @__PURE__ */ s("div", { style: p.errorText, children: x.error }),
3392
- S && /* @__PURE__ */ s("div", { style: p.successText, children: S })
3533
+ /* @__PURE__ */ s("button", { type: "submit", disabled: v, style: D, children: E.loading ? o.loadingText : o.submitButton }),
3534
+ E.error && /* @__PURE__ */ s("div", { style: p.errorText, children: E.error }),
3535
+ k && /* @__PURE__ */ s("div", { style: p.successText, children: k })
3393
3536
  ] }),
3394
3537
  /* @__PURE__ */ f("div", { style: p.linkContainer, children: [
3395
3538
  /* @__PURE__ */ s("a", { onClick: l, style: p.link, children: o.backToLoginLink }),
@@ -3400,7 +3543,7 @@ function _r({
3400
3543
  ] })
3401
3544
  ] });
3402
3545
  }
3403
- const rr = () => /* @__PURE__ */ s(
3546
+ const gr = () => /* @__PURE__ */ s(
3404
3547
  "div",
3405
3548
  {
3406
3549
  style: {
@@ -3412,7 +3555,7 @@ const rr = () => /* @__PURE__ */ s(
3412
3555
  },
3413
3556
  children: /* @__PURE__ */ s("div", { children: "Loading..." })
3414
3557
  }
3415
- ), nr = ({ error: r, retry: e }) => /* @__PURE__ */ f(
3558
+ ), yr = ({ error: r, retry: e }) => /* @__PURE__ */ f(
3416
3559
  "div",
3417
3560
  {
3418
3561
  style: {
@@ -3446,43 +3589,43 @@ const rr = () => /* @__PURE__ */ s(
3446
3589
  ]
3447
3590
  }
3448
3591
  );
3449
- function qr({
3592
+ function tn({
3450
3593
  children: r,
3451
3594
  loadingFallback: e,
3452
3595
  errorFallback: t,
3453
3596
  requireTenant: n = !0
3454
3597
  }) {
3455
- const { isAppLoading: i, appError: a, retryApp: l } = xe(), d = he(), T = Me(), P = tt(), c = rt(), k = (d == null ? void 0 : d.isTenantLoading) ?? !1, h = (d == null ? void 0 : d.tenantError) ?? null, E = (d == null ? void 0 : d.tenantSlug) ?? null, R = (d == null ? void 0 : d.retryTenant) ?? (() => {
3456
- }), I = (T == null ? void 0 : T.isAuthReady) ?? !0, A = (P == null ? void 0 : P.isReady) ?? !0, S = (c == null ? void 0 : c.isReady) ?? !0, m = n && d && E, o = i || m && k || T && !I || P && !A || c && !S, p = a || (m ? h : null), x = () => {
3457
- a && l(), h && d && R();
3598
+ const { isAppLoading: i, appError: a, retryApp: l } = Re(), d = pe(), T = Oe(), R = at(), c = lt(), S = (d == null ? void 0 : d.isTenantLoading) ?? !1, h = (d == null ? void 0 : d.tenantError) ?? null, x = (d == null ? void 0 : d.tenantSlug) ?? null, P = (d == null ? void 0 : d.retryTenant) ?? (() => {
3599
+ }), I = (T == null ? void 0 : T.isAuthReady) ?? !0, A = (R == null ? void 0 : R.isReady) ?? !0, k = (c == null ? void 0 : c.isReady) ?? !0, m = n && d && x, o = i || m && S || T && !I || R && !A || c && !k, p = a || (m ? h : null), E = () => {
3600
+ a && l(), h && d && P();
3458
3601
  };
3459
3602
  if (o)
3460
- return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(rr, {}) });
3603
+ return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(gr, {}) });
3461
3604
  if (p) {
3462
- const y = typeof t == "function" ? t(p, x) : t || /* @__PURE__ */ s(nr, { error: p, retry: x });
3605
+ const y = typeof t == "function" ? t(p, E) : t || /* @__PURE__ */ s(yr, { error: p, retry: E });
3463
3606
  return /* @__PURE__ */ s(B, { children: y });
3464
3607
  }
3465
3608
  return /* @__PURE__ */ s(B, { children: r });
3466
3609
  }
3467
- function Vr(r = !0) {
3468
- const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = xe(), a = he(), l = Me(), d = tt(), T = rt(), P = (a == null ? void 0 : a.isTenantLoading) ?? !1, c = (a == null ? void 0 : a.tenantError) ?? null, k = (a == null ? void 0 : a.tenant) ?? null, h = (a == null ? void 0 : a.tenantSlug) ?? null, E = (a == null ? void 0 : a.retryTenant) ?? (() => {
3469
- }), R = (l == null ? void 0 : l.isAuthReady) ?? !0, I = (d == null ? void 0 : d.isReady) ?? !0, A = (T == null ? void 0 : T.isReady) ?? !0, S = r && a && h, D = e || S && P || l && !R || d && !I || T && !A, o = t || (S ? c : null);
3610
+ function rn(r = !0) {
3611
+ const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = Re(), a = pe(), l = Oe(), d = at(), T = lt(), R = (a == null ? void 0 : a.isTenantLoading) ?? !1, c = (a == null ? void 0 : a.tenantError) ?? null, S = (a == null ? void 0 : a.tenant) ?? null, h = (a == null ? void 0 : a.tenantSlug) ?? null, x = (a == null ? void 0 : a.retryTenant) ?? (() => {
3612
+ }), P = (l == null ? void 0 : l.isAuthReady) ?? !0, I = (d == null ? void 0 : d.isReady) ?? !0, A = (T == null ? void 0 : T.isReady) ?? !0, k = r && a && h, C = e || k && R || l && !P || d && !I || T && !A, o = t || (k ? c : null);
3470
3613
  return {
3471
- isLoading: D,
3614
+ isLoading: C,
3472
3615
  error: o,
3473
- isReady: !D && !o && i !== null && (!S || k !== null),
3616
+ isReady: !C && !o && i !== null && (!k || S !== null),
3474
3617
  retry: () => {
3475
- t && n(), c && a && E();
3618
+ t && n(), c && a && x();
3476
3619
  },
3477
3620
  // Individual states
3478
3621
  app: { isLoading: e, error: t, data: i },
3479
- tenant: a ? { isLoading: P, error: c, data: k } : null,
3480
- auth: l ? { isReady: R } : null,
3622
+ tenant: a ? { isLoading: R, error: c, data: S } : null,
3623
+ auth: l ? { isReady: P } : null,
3481
3624
  featureFlags: d ? { isReady: I } : null,
3482
3625
  subscription: T ? { isReady: A } : null
3483
3626
  };
3484
3627
  }
3485
- const sr = {
3628
+ const br = {
3486
3629
  wrapper: {
3487
3630
  position: "relative"
3488
3631
  },
@@ -3526,7 +3669,7 @@ const sr = {
3526
3669
  marginLeft: 8
3527
3670
  }
3528
3671
  };
3529
- function zr({
3672
+ function nn({
3530
3673
  tenants: r,
3531
3674
  currentTenantId: e,
3532
3675
  onSelect: t,
@@ -3536,68 +3679,68 @@ function zr({
3536
3679
  itemClassName: l = "",
3537
3680
  renderItem: d,
3538
3681
  placeholder: T = "Select tenant",
3539
- disabled: P = !1,
3682
+ disabled: R = !1,
3540
3683
  showCurrentTenant: c = !0
3541
3684
  }) {
3542
- var D;
3543
- const k = { ...sr, ...n }, h = Me(), [E, R] = N(!1), I = ke(null), A = r ?? (h == null ? void 0 : h.userTenants) ?? [], S = e ?? ((D = h == null ? void 0 : h.currentUser) == null ? void 0 : D.tenantId) ?? null, m = async (o) => {
3544
- R(!1), t ? t(o) : h != null && h.switchToTenant && await h.switchToTenant(o);
3685
+ var C;
3686
+ const S = { ...br, ...n }, h = Oe(), [x, P] = N(!1), I = Ee(null), A = r ?? (h == null ? void 0 : h.userTenants) ?? [], k = e ?? ((C = h == null ? void 0 : h.currentUser) == null ? void 0 : C.tenantId) ?? null, m = async (o) => {
3687
+ P(!1), t ? t(o) : h != null && h.switchToTenant && await h.switchToTenant(o);
3545
3688
  };
3546
- ne(() => {
3689
+ re(() => {
3547
3690
  const o = (p) => {
3548
- I.current && !I.current.contains(p.target) && R(!1);
3691
+ I.current && !I.current.contains(p.target) && P(!1);
3549
3692
  };
3550
3693
  return document.addEventListener("mousedown", o), () => document.removeEventListener("mousedown", o);
3551
3694
  }, []);
3552
- const g = A.find((o) => o.id === S);
3695
+ const g = A.find((o) => o.id === k);
3553
3696
  if (A.length === 0)
3554
3697
  return null;
3555
3698
  if (A.length === 1 && c)
3556
3699
  return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: A[0].name }) });
3557
3700
  const b = (o, p) => /* @__PURE__ */ f("span", { style: { fontWeight: p ? "bold" : "normal" }, children: [
3558
3701
  o.name,
3559
- o.role && /* @__PURE__ */ f("span", { style: k.itemRole, children: [
3702
+ o.role && /* @__PURE__ */ f("span", { style: S.itemRole, children: [
3560
3703
  "(",
3561
3704
  o.role,
3562
3705
  ")"
3563
3706
  ] })
3564
3707
  ] });
3565
- return /* @__PURE__ */ f("div", { ref: I, className: i, style: k.wrapper, children: [
3708
+ return /* @__PURE__ */ f("div", { ref: I, className: i, style: S.wrapper, children: [
3566
3709
  /* @__PURE__ */ f(
3567
3710
  "button",
3568
3711
  {
3569
3712
  type: "button",
3570
- onClick: () => !P && R(!E),
3571
- disabled: P,
3713
+ onClick: () => !R && P(!x),
3714
+ disabled: R,
3572
3715
  style: {
3573
- ...k.button,
3574
- ...P ? k.buttonDisabled : {}
3716
+ ...S.button,
3717
+ ...R ? S.buttonDisabled : {}
3575
3718
  },
3576
3719
  children: [
3577
3720
  g ? g.name : T,
3578
- /* @__PURE__ */ s("span", { style: k.arrow, children: E ? "▲" : "▼" })
3721
+ /* @__PURE__ */ s("span", { style: S.arrow, children: x ? "▲" : "▼" })
3579
3722
  ]
3580
3723
  }
3581
3724
  ),
3582
- E && /* @__PURE__ */ s("div", { className: a, style: k.dropdown, children: A.map((o) => {
3583
- const p = o.id === S;
3725
+ x && /* @__PURE__ */ s("div", { className: a, style: S.dropdown, children: A.map((o) => {
3726
+ const p = o.id === k;
3584
3727
  return /* @__PURE__ */ s(
3585
3728
  "div",
3586
3729
  {
3587
3730
  className: l,
3588
3731
  onClick: () => m(o.id),
3589
3732
  style: {
3590
- ...k.item,
3591
- ...p ? k.itemSelected : {}
3733
+ ...S.item,
3734
+ ...p ? S.itemSelected : {}
3592
3735
  },
3593
- onMouseEnter: (x) => {
3594
- p || Object.assign(x.currentTarget.style, k.itemHover);
3736
+ onMouseEnter: (E) => {
3737
+ p || Object.assign(E.currentTarget.style, S.itemHover);
3595
3738
  },
3596
- onMouseLeave: (x) => {
3739
+ onMouseLeave: (E) => {
3597
3740
  if (!p) {
3598
- const y = k.item || {};
3599
- Object.keys(k.itemHover || {}).forEach((u) => {
3600
- x.currentTarget.style[u] = y[u] ?? "";
3741
+ const y = S.item || {};
3742
+ Object.keys(S.itemHover || {}).forEach((u) => {
3743
+ E.currentTarget.style[u] = y[u] ?? "";
3601
3744
  });
3602
3745
  }
3603
3746
  },
@@ -3608,7 +3751,7 @@ function zr({
3608
3751
  }) })
3609
3752
  ] });
3610
3753
  }
3611
- class jr {
3754
+ class sn {
3612
3755
  constructor(e) {
3613
3756
  this.httpService = e;
3614
3757
  }
@@ -3617,7 +3760,7 @@ class jr {
3617
3760
  }
3618
3761
  async getPermissions(e) {
3619
3762
  const t = await this.httpService.get(
3620
- `/permissions/${le(e)}`
3763
+ `/permissions/${ce(e)}`
3621
3764
  );
3622
3765
  return { permissions: t.data, meta: t.meta };
3623
3766
  }
@@ -3635,13 +3778,13 @@ class jr {
3635
3778
  }
3636
3779
  async getAppPermissions(e, t) {
3637
3780
  const n = await this.httpService.get(
3638
- `/permissions/apps/${e}${le(t)}`,
3781
+ `/permissions/apps/${e}${ce(t)}`,
3639
3782
  { skipAuth: !0 }
3640
3783
  );
3641
3784
  return { permissions: n.data, meta: n.meta };
3642
3785
  }
3643
3786
  }
3644
- class Wr {
3787
+ class on {
3645
3788
  constructor(e) {
3646
3789
  this.httpService = e;
3647
3790
  }
@@ -3653,7 +3796,7 @@ class Wr {
3653
3796
  }
3654
3797
  async getSubscriptionPlans(e) {
3655
3798
  const t = await this.httpService.get(
3656
- `/subscription-plans/${le(e)}`
3799
+ `/subscription-plans/${ce(e)}`
3657
3800
  );
3658
3801
  return { plans: t.data, meta: t.meta };
3659
3802
  }
@@ -3672,7 +3815,7 @@ class Wr {
3672
3815
  await this.httpService.delete(`/subscription-plans/${e}`);
3673
3816
  }
3674
3817
  }
3675
- class Gr {
3818
+ class an {
3676
3819
  constructor(e) {
3677
3820
  this.httpService = e;
3678
3821
  }
@@ -3681,24 +3824,24 @@ class Gr {
3681
3824
  return await this.httpService.get("/health");
3682
3825
  }
3683
3826
  }
3684
- const it = "returnTo", Fe = "zone_return_to", Le = "zone_return_to";
3685
- function Hr(r = {}) {
3827
+ const dt = "returnTo", Ce = "zone_return_to", De = "zone_return_to";
3828
+ function ln(r = {}) {
3686
3829
  const {
3687
3830
  zoneRoots: e = {},
3688
- returnToParam: t = it,
3831
+ returnToParam: t = dt,
3689
3832
  returnToStorage: n = "url"
3690
- } = r, i = pt(), [a, l] = ft(), { isAuthenticated: d, currentUser: T } = ue(), { tenant: P } = be(), c = q(() => ({ ..._e, ...e }), [e]), k = !!P, h = T == null ? void 0 : T.userType, E = q(() => {
3833
+ } = r, i = wt(), [a, l] = vt(), { isAuthenticated: d, currentUser: T } = de(), { tenant: R } = ve(), c = V(() => ({ ...ze, ...e }), [e]), S = !!R, h = T == null ? void 0 : T.userType, x = V(() => {
3691
3834
  switch (n) {
3692
3835
  case "url":
3693
3836
  return a.get(t);
3694
3837
  case "session":
3695
- return sessionStorage.getItem(Fe);
3838
+ return sessionStorage.getItem(Ce);
3696
3839
  case "local":
3697
- return localStorage.getItem(Le);
3840
+ return localStorage.getItem(De);
3698
3841
  default:
3699
3842
  return null;
3700
3843
  }
3701
- }, [n, a, t]), R = re(() => {
3844
+ }, [n, a, t]), P = te(() => {
3702
3845
  switch (n) {
3703
3846
  case "url": {
3704
3847
  const m = new URLSearchParams(a);
@@ -3706,13 +3849,13 @@ function Hr(r = {}) {
3706
3849
  break;
3707
3850
  }
3708
3851
  case "session":
3709
- sessionStorage.removeItem(Fe);
3852
+ sessionStorage.removeItem(Ce);
3710
3853
  break;
3711
3854
  case "local":
3712
- localStorage.removeItem(Le);
3855
+ localStorage.removeItem(De);
3713
3856
  break;
3714
3857
  }
3715
- }, [n, a, t, l]), I = re(
3858
+ }, [n, a, t, l]), I = te(
3716
3859
  (m) => {
3717
3860
  switch (n) {
3718
3861
  case "url": {
@@ -3721,101 +3864,102 @@ function Hr(r = {}) {
3721
3864
  break;
3722
3865
  }
3723
3866
  case "session":
3724
- sessionStorage.setItem(Fe, m);
3867
+ sessionStorage.setItem(Ce, m);
3725
3868
  break;
3726
3869
  case "local":
3727
- localStorage.setItem(Le, m);
3870
+ localStorage.setItem(De, m);
3728
3871
  break;
3729
3872
  }
3730
3873
  },
3731
3874
  [n, a, t, l]
3732
- ), A = re(
3875
+ ), A = te(
3733
3876
  (m) => {
3734
3877
  const g = c[m] || c.default;
3735
3878
  i(g);
3736
3879
  },
3737
3880
  [i, c]
3738
- ), S = re(() => k ? d ? h === oe.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : d ? h === oe.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [k, d, h, c]);
3881
+ ), k = te(() => S ? d ? h === ae.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : d ? h === ae.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [S, d, h, c]);
3739
3882
  return {
3740
- returnToUrl: E,
3741
- clearReturnTo: R,
3883
+ returnToUrl: x,
3884
+ clearReturnTo: P,
3742
3885
  setReturnTo: I,
3743
3886
  navigateToZone: A,
3744
- getSmartRedirect: S
3887
+ getSmartRedirect: k
3745
3888
  };
3746
3889
  }
3747
- function Qr(r, e, t = it, n = "url") {
3890
+ function cn(r, e, t = dt, n = "url") {
3748
3891
  if (!e || n !== "url")
3749
3892
  return r;
3750
3893
  const i = new URL(r, window.location.origin);
3751
3894
  return i.searchParams.set(t, e), i.pathname + i.search;
3752
3895
  }
3753
3896
  export {
3754
- Rr as AdminZone,
3755
- Ge as AppApiService,
3756
- qr as AppLoader,
3757
- lr as AppProvider,
3758
- bt as AuthApiService,
3759
- pr as AuthProvider,
3760
- Pr as AuthenticatedZone,
3761
- nt as DEFAULT_ZONE_PRESETS,
3762
- _e as DEFAULT_ZONE_ROOTS,
3763
- Ur as FeatureFlag,
3764
- Pt as FeatureFlagApiService,
3765
- gr as FeatureFlagProvider,
3766
- Ar as GuestZone,
3767
- Gr as HealthApiService,
3768
- de as HttpService,
3769
- Sr as LandingRoute,
3770
- $r as LoginForm,
3771
- Br as MagicLinkForm,
3772
- Or as MagicLinkVerify,
3773
- Fr as OpenZone,
3774
- _r as PasswordRecoveryForm,
3775
- jr as PermissionApiService,
3776
- vr as Protected,
3777
- Tr as ProtectedRoute,
3778
- Er as PublicZone,
3779
- wt as RoleApiService,
3780
- br as RoutingProvider,
3781
- te as SessionExpiredError,
3782
- Ne as SessionManager,
3783
- Mr as SignupForm,
3784
- Rt as SubscriptionApiService,
3785
- Cr as SubscriptionGuard,
3786
- Wr as SubscriptionPlanApiService,
3787
- yr as SubscriptionProvider,
3788
- me as TenantApiService,
3789
- Lr as TenantAuthenticatedZone,
3790
- Dr as TenantGuestZone,
3791
- Nr as TenantOpenZone,
3792
- ur as TenantProvider,
3793
- kr as TenantRoute,
3794
- zr as TenantSelector,
3795
- xr as TenantZone,
3796
- yt as TokenRefreshError,
3797
- gt as TokenRefreshTimeoutError,
3798
- vt as UserApiService,
3799
- oe as UserType,
3800
- Ir as UserZone,
3801
- ce as ZoneRoute,
3802
- Qr as buildRedirectUrl,
3803
- cr as useApi,
3804
- xe as useApp,
3805
- Vr as useAppLoaderState,
3806
- ue as useAuth,
3807
- mr as useAuthActions,
3808
- Me as useAuthOptional,
3809
- fr as useAuthState,
3810
- At as useFeatureFlags,
3811
- wr as useRouting,
3812
- Lt as useRoutingOptional,
3813
- hr as useSettings,
3814
- It as useSubscription,
3815
- be as useTenant,
3816
- et as useTenantInfo,
3817
- he as useTenantOptional,
3818
- dr as useTenantSettings,
3819
- Hr as useZoneNavigation
3897
+ qr as AdminZone,
3898
+ Je as AppApiService,
3899
+ tn as AppLoader,
3900
+ Sr as AppProvider,
3901
+ Nt as AuthApiService,
3902
+ Ar as AuthProvider,
3903
+ Or as AuthenticatedZone,
3904
+ oe as ConfigurationError,
3905
+ ct as DEFAULT_ZONE_PRESETS,
3906
+ ze as DEFAULT_ZONE_ROOTS,
3907
+ Jr as FeatureFlag,
3908
+ Ot as FeatureFlagApiService,
3909
+ Lr as FeatureFlagProvider,
3910
+ Vr as GuestZone,
3911
+ an as HealthApiService,
3912
+ he as HttpService,
3913
+ Ur as LandingRoute,
3914
+ Zr as LoginForm,
3915
+ Yr as MagicLinkForm,
3916
+ Xr as MagicLinkVerify,
3917
+ jr as OpenZone,
3918
+ en as PasswordRecoveryForm,
3919
+ sn as PermissionApiService,
3920
+ Dr as Protected,
3921
+ Mr as ProtectedRoute,
3922
+ _r as PublicZone,
3923
+ Ct as RoleApiService,
3924
+ Nr as RoutingProvider,
3925
+ ee as SessionExpiredError,
3926
+ Me as SessionManager,
3927
+ Kr as SignupForm,
3928
+ qt as SubscriptionApiService,
3929
+ Qr as SubscriptionGuard,
3930
+ on as SubscriptionPlanApiService,
3931
+ Fr as SubscriptionProvider,
3932
+ ye as TenantApiService,
3933
+ Wr as TenantAuthenticatedZone,
3934
+ Hr as TenantGuestZone,
3935
+ Gr as TenantOpenZone,
3936
+ Er as TenantProvider,
3937
+ $r as TenantRoute,
3938
+ nn as TenantSelector,
3939
+ Br as TenantZone,
3940
+ kt as TokenRefreshError,
3941
+ St as TokenRefreshTimeoutError,
3942
+ Dt as UserApiService,
3943
+ ae as UserType,
3944
+ zr as UserZone,
3945
+ ue as ZoneRoute,
3946
+ cn as buildRedirectUrl,
3947
+ kr as useApi,
3948
+ Re as useApp,
3949
+ rn as useAppLoaderState,
3950
+ de as useAuth,
3951
+ Ir as useAuthActions,
3952
+ Oe as useAuthOptional,
3953
+ Pr as useAuthState,
3954
+ Vt as useFeatureFlags,
3955
+ Cr as useRouting,
3956
+ Wt as useRoutingOptional,
3957
+ Rr as useSettings,
3958
+ zt as useSubscription,
3959
+ ve as useTenant,
3960
+ ot as useTenantInfo,
3961
+ pe as useTenantOptional,
3962
+ xr as useTenantSettings,
3963
+ ln as useZoneNavigation
3820
3964
  };
3821
3965
  //# sourceMappingURL=index.es.js.map