@skylabs-digital/react-identity-access 3.0.0 → 3.1.1

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(), A = 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(A), !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(A), 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
+ }), [A, 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]), R = V(
160
160
  () => ({
161
161
  appId: t,
162
162
  baseUrl: n,
163
163
  appInfo: d,
164
- isAppLoading: P,
165
- appError: k,
164
+ isAppLoading: A,
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, A, 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: R, children: e });
175
175
  }
176
- function xe() {
177
- const r = se(De);
176
+ function Ae() {
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 = Ae;
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 Re(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 = Re(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 = Re(r)) == null ? void 0 : n.payload[e];
241
+ return typeof t == "string" ? t : void 0;
242
+ }
243
+ const At = /^(javascript|data|vbscript|file):/i, Rt = /^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 (At.test(r))
249
+ throw new oe(e, r, "dangerous URL scheme is not allowed");
250
+ if (!Rt.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 (Re(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
+ }
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
+ }
278
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 A = await T.json();
532
668
  this.setTokens({
533
- accessToken: P.accessToken,
534
- refreshToken: P.refreshToken || i,
535
- expiresIn: P.expiresIn
669
+ accessToken: A.accessToken,
670
+ refreshToken: A.refreshToken || i,
671
+ expiresIn: A.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 = Re(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,27 +727,32 @@ 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
- // Public endpoints - no auth required
736
+ // Public endpoints - no auth required.
737
+ // Must pass `{ skipAuth: true }` so HttpService does NOT call
738
+ // SessionManager.getValidAccessToken (which throws when no tokens exist).
601
739
  async login(e) {
602
- return await this.httpService.post("/auth/login", e);
740
+ return this.httpService.post("/auth/login", e, { skipAuth: !0 });
603
741
  }
604
742
  async signup(e) {
605
- return await this.httpService.post("/auth/signup", e);
743
+ return this.httpService.post("/auth/signup", e, { skipAuth: !0 });
606
744
  }
607
745
  async signupTenantAdmin(e) {
608
- return await this.httpService.post(
746
+ return this.httpService.post(
609
747
  "/auth/signup/tenant-admin",
610
- e
748
+ e,
749
+ { skipAuth: !0 }
611
750
  );
612
751
  }
613
752
  async refreshToken(e) {
614
- return await this.httpService.post("/auth/refresh", e);
753
+ return this.httpService.post("/auth/refresh", e, {
754
+ skipAuth: !0
755
+ });
615
756
  }
616
757
  async switchTenant(e) {
617
758
  return await this.httpService.post(
@@ -623,30 +764,37 @@ class bt {
623
764
  return this.httpService.get("/auth/tenants");
624
765
  }
625
766
  async requestPasswordReset(e) {
626
- await this.httpService.post("/auth/password-reset/request", e);
767
+ await this.httpService.post("/auth/password-reset/request", e, { skipAuth: !0 });
627
768
  }
628
769
  async sendMagicLink(e) {
629
- return await this.httpService.post(
630
- "/auth/magic-link/send",
631
- e
632
- );
770
+ const t = JSON.stringify([
771
+ e.email,
772
+ e.tenantId,
773
+ e.appId ?? "",
774
+ e.frontendUrl ?? ""
775
+ ]), n = this.pendingMagicLinks.get(t);
776
+ if (n) return n;
777
+ const i = this.httpService.post("/auth/magic-link/send", e, { skipAuth: !0 }).finally(() => {
778
+ this.pendingMagicLinks.delete(t);
779
+ });
780
+ return this.pendingMagicLinks.set(t, i), i;
633
781
  }
634
782
  async verifyMagicLink(e) {
635
783
  const t = e.token, n = this.pendingVerifications.get(t);
636
784
  if (n) return n;
637
- const i = this.httpService.post("/auth/magic-link/verify", e).finally(() => {
785
+ const i = this.httpService.post("/auth/magic-link/verify", e, { skipAuth: !0 }).finally(() => {
638
786
  this.pendingVerifications.delete(t);
639
787
  });
640
788
  return this.pendingVerifications.set(t, i), i;
641
789
  }
642
790
  async confirmPasswordReset(e) {
643
- await this.httpService.post("/auth/password-reset/confirm", e);
791
+ await this.httpService.post("/auth/password-reset/confirm", e, { skipAuth: !0 });
644
792
  }
645
793
  async changePassword(e) {
646
794
  await this.httpService.post("/auth/change-password", e);
647
795
  }
648
796
  }
649
- class wt {
797
+ class Ct {
650
798
  constructor(e) {
651
799
  this.httpService = e;
652
800
  }
@@ -664,7 +812,7 @@ class wt {
664
812
  }
665
813
  async getRolesByApp(e, t) {
666
814
  const n = await this.httpService.get(
667
- `/roles/app/${e}${le(t)}`,
815
+ `/roles/app/${e}${ce(t)}`,
668
816
  { skipAuth: !0 }
669
817
  );
670
818
  return { roles: n.data, meta: n.meta };
@@ -677,12 +825,12 @@ class wt {
677
825
  }
678
826
  async getUserRoles(e, t) {
679
827
  const n = await this.httpService.get(
680
- `/roles/user/${e}${le(t)}`
828
+ `/roles/user/${e}${ce(t)}`
681
829
  );
682
830
  return { roles: n.data, meta: n.meta };
683
831
  }
684
832
  }
685
- class vt {
833
+ class Dt {
686
834
  constructor(e) {
687
835
  this.httpService = e;
688
836
  }
@@ -691,7 +839,7 @@ class vt {
691
839
  }
692
840
  async getUsers(e) {
693
841
  const t = await this.httpService.get(
694
- `/users/${le(e)}`
842
+ `/users/${ce(e)}`
695
843
  );
696
844
  return { users: t.data, meta: t.meta };
697
845
  }
@@ -705,7 +853,7 @@ class vt {
705
853
  await this.httpService.delete(`/users/${e}`);
706
854
  }
707
855
  }
708
- class me {
856
+ class ye {
709
857
  constructor(e, t) {
710
858
  this.httpService = e, this.appId = t;
711
859
  }
@@ -714,7 +862,7 @@ class me {
714
862
  }
715
863
  async getTenants(e) {
716
864
  const t = await this.httpService.get(
717
- `/tenants/${le(e)}`
865
+ `/tenants/${ce(e)}`
718
866
  );
719
867
  return { tenants: t.data, meta: t.meta };
720
868
  }
@@ -749,7 +897,7 @@ class me {
749
897
  )).data;
750
898
  }
751
899
  }
752
- function Tt(r, e) {
900
+ function Mt(r, e) {
753
901
  if (r === "localhost" || r.startsWith("127.") || r.startsWith("192.168."))
754
902
  return null;
755
903
  if (e) {
@@ -765,24 +913,24 @@ function Tt(r, e) {
765
913
  const n = r.split(".");
766
914
  return n.length >= 3 && n[0] !== "www" ? n[0] : null;
767
915
  }
768
- function kt(r, e = "tenant", t) {
916
+ function $t(r, e = "tenant", t) {
769
917
  const i = new URLSearchParams(r).get(e);
770
918
  return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
771
919
  }
772
- function St(r, e, t) {
920
+ function Ut(r, e, t) {
773
921
  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;
922
+ return n === "fixed" ? l || null : n === "subdomain" ? Mt(e.hostname, i) : n === "selector" ? $t(e.search, a, t) : null;
775
923
  }
776
- function xt(r, e, t) {
924
+ function Bt(r, e, t) {
777
925
  if (t)
778
926
  return `${r}.${t}`;
779
927
  const n = e.split(".");
780
928
  return n.length === 2 ? `${r}.${e}` : n.length >= 3 ? (n[0] = r, n.join(".")) : null;
781
929
  }
782
- const Ue = pe(null);
783
- function ur({ config: r, children: e }) {
930
+ const Be = fe(null);
931
+ function Er({ config: r, children: e }) {
784
932
  var j, Z, $;
785
- const { baseUrl: t, appInfo: n, appId: i } = xe(), a = re(() => typeof window > "u" ? null : St(
933
+ const { baseUrl: t, appInfo: n, appId: i } = Ae(), a = te(() => typeof window > "u" ? null : Ut(
786
934
  {
787
935
  tenantMode: r.tenantMode || "selector",
788
936
  baseDomain: r.baseDomain,
@@ -794,111 +942,111 @@ function ur({ config: r, children: e }) {
794
942
  search: window.location.search
795
943
  },
796
944
  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(() => {
945
+ ), [r.tenantMode, r.baseDomain, r.selectorParam, r.fixedTenantSlug]), [l, d] = N(() => a()), T = ((j = r.cache) == null ? void 0 : j.enabled) ?? !0, A = ((Z = r.cache) == null ? void 0 : Z.ttl) ?? 5 * 60 * 1e3, c = (($ = r.cache) == null ? void 0 : $.storageKey) ?? `tenant_cache_${l || "default"}`, S = V(
946
+ () => ({ enabled: T, ttl: A, storageKey: c }),
947
+ [T, A, c]
948
+ ), [h, x] = N(() => {
801
949
  if (r.initialTenant) return r.initialTenant;
802
- if (!k.enabled || !l) return null;
950
+ if (!S.enabled || !l) return null;
803
951
  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);
952
+ const U = localStorage.getItem(S.storageKey);
953
+ if (!U) return null;
954
+ const L = JSON.parse(U);
955
+ return Date.now() - L.timestamp < S.ttl && L.tenantSlug === l ? L.data : (localStorage.removeItem(S.storageKey), null);
808
956
  } catch {
809
957
  return null;
810
958
  }
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(() => {
959
+ }), [P, I] = N(!h && !r.initialTenant), [R, k] = N(null), [m, g] = N(null), [b, C] = N(!1), [o, p] = N(null);
960
+ re(() => {
813
961
  if (r.tenantMode === "fixed") return;
814
- const M = a();
815
- d(M);
962
+ const U = a();
963
+ d(U);
816
964
  }, [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))
965
+ const E = (n == null ? void 0 : n.settingsSchema) || null, y = te(
966
+ async (U, L = !1) => {
967
+ if (!(!L && S.enabled && h && h.subdomain === U))
820
968
  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)
969
+ I(!0), k(null);
970
+ const q = new he(t), W = await new ye(q, i).getPublicTenantInfo(U);
971
+ if (x(W), S.enabled)
824
972
  try {
825
- const Y = {
973
+ const K = {
826
974
  data: W,
827
975
  timestamp: Date.now(),
828
- tenantSlug: M
976
+ tenantSlug: U
829
977
  };
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);
978
+ localStorage.setItem(S.storageKey, JSON.stringify(K));
979
+ } catch (K) {
980
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Failed to cache tenant info:", K);
833
981
  }
834
- } catch (V) {
835
- const O = V instanceof Error ? V : new Error("Failed to load tenant information");
836
- S(O), E(null);
982
+ } catch (q) {
983
+ const _ = q instanceof Error ? q : new Error("Failed to load tenant information");
984
+ k(_), x(null);
837
985
  } finally {
838
986
  I(!1);
839
987
  }
840
988
  },
841
- [t, i, k, h]
842
- ), u = re(async () => {
843
- if (!(!k.enabled || !h || !l))
989
+ [t, i, S, h]
990
+ ), u = te(async () => {
991
+ if (!(!S.enabled || !h || !l))
844
992
  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,
993
+ const U = localStorage.getItem(S.storageKey);
994
+ if (!U) return;
995
+ const L = JSON.parse(U);
996
+ if (Date.now() - L.timestamp > S.ttl * 0.5) {
997
+ const _ = new he(t), K = await new ye(_, i).getPublicTenantInfo(l);
998
+ x(K);
999
+ const Y = {
1000
+ data: K,
853
1001
  timestamp: Date.now(),
854
1002
  tenantSlug: l
855
1003
  };
856
- localStorage.setItem(k.storageKey, JSON.stringify(X));
1004
+ localStorage.setItem(S.storageKey, JSON.stringify(Y));
857
1005
  }
858
- } catch (M) {
859
- process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", M);
1006
+ } catch (U) {
1007
+ process.env.NODE_ENV === "development" && console.warn("[TenantProvider] Background tenant refresh failed:", U);
860
1008
  }
861
- }, [t, i, k, h, l]), v = re(async () => {
1009
+ }, [t, i, S, h, l]), v = te(async () => {
862
1010
  if (h != null && h.id)
863
1011
  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);
1012
+ C(!0), p(null);
1013
+ const U = new he(t), q = await new ye(U, h.appId).getTenantSettings(h.id);
1014
+ g(q);
1015
+ } catch (U) {
1016
+ const L = U instanceof Error ? U : new Error("Failed to load tenant settings");
1017
+ p(L), g(null);
870
1018
  } finally {
871
- D(!1);
1019
+ C(!1);
872
1020
  }
873
- }, [t, h]), C = re(() => {
1021
+ }, [t, h]), D = te(() => {
874
1022
  v();
875
- }, [v]), ie = re(
876
- (M) => {
877
- if (!x)
1023
+ }, [v]), se = te(
1024
+ (U) => {
1025
+ if (!E)
878
1026
  return { isValid: !0, errors: [] };
879
- const F = [];
1027
+ const L = [];
880
1028
  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`);
1029
+ return E.properties && Object.entries(E.properties).forEach(([q, _]) => {
1030
+ var K;
1031
+ const W = U[q];
1032
+ if ((K = E.required) != null && K.includes(q) && W == null) {
1033
+ L.push(`Field '${q}' is required`);
886
1034
  return;
887
1035
  }
888
1036
  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`);
1037
+ if (_.type) {
1038
+ const Y = _.type, le = typeof W;
1039
+ 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
1040
  }
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(", ")}`);
1041
+ _.minLength !== void 0 && typeof W == "string" && W.length < _.minLength && L.push(
1042
+ `Field '${q}' must be at least ${_.minLength} characters long`
1043
+ ), _.maxLength !== void 0 && typeof W == "string" && W.length > _.maxLength && L.push(
1044
+ `Field '${q}' must be no more than ${_.maxLength} characters long`
1045
+ ), _.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
1046
  }
899
1047
  }), {
900
- isValid: F.length === 0,
901
- errors: F
1048
+ isValid: L.length === 0,
1049
+ errors: L
902
1050
  };
903
1051
  } catch {
904
1052
  return {
@@ -907,98 +1055,98 @@ function ur({ config: r, children: e }) {
907
1055
  };
908
1056
  }
909
1057
  },
910
- [x]
1058
+ [E]
911
1059
  );
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));
1060
+ re(() => {
1061
+ !r.initialTenant && l ? h ? u() : y(l) : !r.initialTenant && !l && (x(null), k(null), I(!1));
1062
+ }, [r.initialTenant, l, h, y, u]), re(() => {
1063
+ h != null && h.id ? v() : (g(null), p(null), C(!1));
916
1064
  }, [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";
1065
+ const F = te(
1066
+ (U, L) => {
1067
+ const { mode: q = "reload", redirectPath: _ } = L || {}, W = r.tenantMode || "selector";
920
1068
  if (W === "fixed") {
921
1069
  process.env.NODE_ENV === "development" && console.warn(
922
1070
  "[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
923
1071
  r.fixedTenantSlug
924
- ), O && (window.location.href = O);
1072
+ ), _ && (window.location.href = _);
925
1073
  return;
926
1074
  }
927
- if (localStorage.setItem("tenant", M), W === "subdomain") {
928
- const Y = window.location.hostname, X = xt(
929
- M,
930
- Y,
1075
+ if (localStorage.setItem("tenant", U), W === "subdomain") {
1076
+ const K = window.location.hostname, Y = Bt(
1077
+ U,
1078
+ K,
931
1079
  r.baseDomain
932
1080
  );
933
- if (!X) {
1081
+ if (!Y) {
934
1082
  process.env.NODE_ENV === "development" && console.warn(
935
1083
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
936
- Y
1084
+ K
937
1085
  );
938
1086
  return;
939
1087
  }
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();
1088
+ const le = _ || window.location.pathname, Te = new URL(`${window.location.protocol}//${Y}${le}`);
1089
+ new URLSearchParams(window.location.search).forEach((Fe, Ne) => {
1090
+ Te.searchParams.set(Ne, Fe);
1091
+ }), window.location.href = Te.toString();
944
1092
  } 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;
1093
+ const K = _ || window.location.pathname, Y = new URLSearchParams(window.location.search);
1094
+ if (Y.set(r.selectorParam || "tenant", U), q === "reload") {
1095
+ const le = `${K}?${Y.toString()}${window.location.hash}`;
1096
+ window.location.href = le;
949
1097
  } else {
950
- const ae = `${Y}?${X.toString()}${window.location.hash}`;
951
- window.history.pushState({}, "", ae), d(M), y(M);
1098
+ const le = `${K}?${Y.toString()}${window.location.hash}`;
1099
+ window.history.pushState({}, "", le), d(U), y(U);
952
1100
  }
953
1101
  }
954
1102
  },
955
1103
  [r.tenantMode, r.selectorParam, r.baseDomain, r.fixedTenantSlug, y]
956
- ), H = q(() => ({
1104
+ ), H = V(() => ({
957
1105
  // Tenant info
958
1106
  tenant: h,
959
1107
  tenantSlug: l,
960
- isTenantLoading: R,
961
- tenantError: A,
1108
+ isTenantLoading: P,
1109
+ tenantError: R,
962
1110
  retryTenant: () => {
963
1111
  l && y(l);
964
1112
  },
965
1113
  // Settings
966
1114
  settings: m,
967
- settingsSchema: x,
1115
+ settingsSchema: E,
968
1116
  isSettingsLoading: b,
969
1117
  settingsError: o,
970
1118
  // Actions
971
- refreshSettings: C,
972
- switchTenant: L,
1119
+ refreshSettings: D,
1120
+ switchTenant: F,
973
1121
  // Validation
974
- validateSettings: ie
1122
+ validateSettings: se
975
1123
  }), [
976
1124
  h,
977
1125
  l,
1126
+ P,
978
1127
  R,
979
- A,
980
1128
  m,
981
- x,
1129
+ E,
982
1130
  b,
983
1131
  o,
984
- C,
985
- L,
986
- ie
1132
+ D,
1133
+ F,
1134
+ se
987
1135
  ]);
988
- return /* @__PURE__ */ s(Ue.Provider, { value: H, children: e });
1136
+ return /* @__PURE__ */ s(Be.Provider, { value: H, children: e });
989
1137
  }
990
- function be() {
991
- const r = se(Ue);
1138
+ function ve() {
1139
+ const r = ne(Be);
992
1140
  if (!r)
993
1141
  throw new Error("useTenant must be used within a TenantProvider");
994
1142
  return r;
995
1143
  }
996
- function he() {
997
- return se(Ue);
1144
+ function pe() {
1145
+ return ne(Be);
998
1146
  }
999
- const dr = be;
1000
- function hr() {
1001
- const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = be();
1147
+ const xr = ve;
1148
+ function Ar() {
1149
+ const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = ve();
1002
1150
  return {
1003
1151
  settings: r,
1004
1152
  settingsSchema: e,
@@ -1007,8 +1155,8 @@ function hr() {
1007
1155
  validateSettings: i
1008
1156
  };
1009
1157
  }
1010
- function et() {
1011
- const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } = be();
1158
+ function ot() {
1159
+ const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } = ve();
1012
1160
  return {
1013
1161
  tenant: r,
1014
1162
  tenantSlug: e,
@@ -1017,265 +1165,265 @@ function et() {
1017
1165
  retry: i
1018
1166
  };
1019
1167
  }
1020
- const $e = "userTenants";
1021
- function Et() {
1168
+ const _e = "userTenants";
1169
+ function _t() {
1022
1170
  try {
1023
- const r = localStorage.getItem($e);
1171
+ const r = localStorage.getItem(_e);
1024
1172
  return r ? JSON.parse(r) : [];
1025
1173
  } catch {
1026
1174
  return [];
1027
1175
  }
1028
1176
  }
1029
- function He(r) {
1177
+ function Xe(r) {
1030
1178
  try {
1031
- localStorage.setItem($e, JSON.stringify(r));
1179
+ localStorage.setItem(_e, JSON.stringify(r));
1032
1180
  } catch {
1033
1181
  }
1034
1182
  }
1035
- function Qe() {
1183
+ function et() {
1036
1184
  try {
1037
- localStorage.removeItem($e);
1185
+ localStorage.removeItem(_e);
1038
1186
  } catch {
1039
1187
  }
1040
1188
  }
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) ?? (() => {
1189
+ const Pe = fe(null), Ie = fe(null);
1190
+ function Rr({ config: r = {}, children: e }) {
1191
+ 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
1192
  });
1045
1193
  if (!i)
1046
1194
  throw new Error(
1047
1195
  "[AuthProvider] baseUrl is required. Provide it via AppProvider or AuthConfig.baseUrl."
1048
1196
  );
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({
1197
+ const [A, c] = N(r.initialRoles || []), [S, h] = N(!r.initialRoles), [x, P] = N(null), [I, R] = N(!1), [k, m] = N(null), [g, b] = N(() => _t()), C = Ee({ done: !1 });
1198
+ C.current.done || (C.current.done = !0);
1199
+ const o = V(() => Me.getInstance({
1052
1200
  baseUrl: i,
1053
1201
  enableCookieSession: r.enableCookieSession,
1054
1202
  refreshQueueTimeout: r.refreshQueueTimeout,
1055
1203
  proactiveRefreshMargin: r.proactiveRefreshMargin,
1056
1204
  onSessionExpired: (w) => {
1057
- R(null), m(null), b([]), Qe(), r.onSessionExpired ? r.onSessionExpired(w) : r.onRefreshFailed && r.onRefreshFailed();
1205
+ P(null), m(null), b([]), et(), r.onSessionExpired ? r.onSessionExpired(w) : r.onRefreshFailed && r.onRefreshFailed();
1058
1206
  }
1059
1207
  }), [
1060
1208
  i,
1061
1209
  r.enableCookieSession,
1062
1210
  r.refreshQueueTimeout,
1063
1211
  r.proactiveRefreshMargin
1064
- ]), [p, x] = N(() => {
1212
+ ]), [p, E] = N(() => {
1065
1213
  const w = o.getTokens();
1066
1214
  return w ? o.hasValidSession() || !!w.refreshToken : !!r.enableCookieSession;
1067
- }), y = D.current.done && !p, u = q(() => {
1068
- const w = new de(i);
1215
+ }), y = C.current.done && !p, u = V(() => {
1216
+ const w = new he(i);
1069
1217
  return w.setSessionManager(o), w;
1070
- }, [i, o]), v = q(
1071
- () => new bt(u),
1218
+ }, [i, o]), v = V(
1219
+ () => new Nt(u),
1072
1220
  [u]
1073
- ), C = q(
1074
- () => new vt(u),
1221
+ ), D = V(
1222
+ () => new Dt(u),
1075
1223
  [u]
1076
- ), ie = q(
1077
- () => new wt(u),
1224
+ ), se = V(
1225
+ () => new Ct(u),
1078
1226
  [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) => {
1227
+ ), F = V(() => x != null && x.roleId && A.find((w) => w.id === x.roleId) || null, [x, A]), H = V(() => (F == null ? void 0 : F.permissions) || [], [F]), j = V(
1228
+ () => o.hasValidSession() && x !== null,
1229
+ [o, x]
1230
+ ), Z = V(() => (x == null ? void 0 : x.tenantId) != null, [x]), $ = Ee(null), U = async (w = !1) => {
1083
1231
  try {
1084
- if (!o.hasValidSession() || !w && E) return;
1085
- const U = o.getUserId();
1086
- if (!U) {
1232
+ if (!o.hasValidSession() || !w && x) return;
1233
+ const M = o.getUserId();
1234
+ if (!M) {
1087
1235
  process.env.NODE_ENV === "development" && console.warn("[AuthProvider] No userId available in token or storage");
1088
1236
  return;
1089
1237
  }
1090
- 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");
1238
+ R(!0), m(null);
1239
+ const z = await D.getUserById(M);
1240
+ P(z), o.setUser(z);
1241
+ } catch (M) {
1242
+ const z = M instanceof Error ? M : new Error("Failed to load user data");
1095
1243
  m(z), process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to load user data:", z);
1096
1244
  } finally {
1097
- A(!1);
1245
+ R(!1);
1098
1246
  }
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 = _);
1247
+ }, L = async (w) => {
1248
+ var He;
1249
+ const { username: M, password: z, tenantSlug: O, redirectPath: Q } = w;
1250
+ let X = l == null ? void 0 : l.id, J = d;
1251
+ O && (X = (await new ye(u, a).getPublicTenantInfo(O)).id, J = O);
1104
1252
  const G = await v.login({
1105
- username: U,
1253
+ username: M,
1106
1254
  password: z,
1107
1255
  appId: a,
1108
- tenantId: ee
1109
- }), ve = _ && _ !== d;
1256
+ tenantId: X
1257
+ }), Se = O && O !== d;
1110
1258
  if (o.setTokens({
1111
1259
  accessToken: G.accessToken,
1112
1260
  refreshToken: G.refreshToken,
1113
1261
  expiresIn: G.expiresIn
1114
1262
  }), G.user) {
1115
- o.setUser(G.user), R(G.user);
1263
+ o.setUser(G.user), P(G.user);
1116
1264
  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);
1265
+ await U();
1266
+ } catch (ke) {
1267
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after login:", ke);
1120
1268
  }
1121
1269
  }
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)
1270
+ G.tenants && G.tenants.length > 0 && (b(G.tenants), Xe(G.tenants));
1271
+ const Ge = ((He = G.user) == null ? void 0 : He.tenantId) !== null;
1272
+ if (Se && J)
1125
1273
  return T(J, { redirectPath: Q }), G;
1126
1274
  if (Q && Q !== window.location.pathname)
1127
1275
  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;
1276
+ if (!Ge && G.tenants && G.tenants.length > 0) {
1277
+ const ke = w.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
1278
+ if (G.tenants.length === 1 && ke) {
1279
+ const Qe = G.tenants[0];
1280
+ return T(Qe.subdomain, { redirectPath: Q }), G;
1133
1281
  } else G.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(G.tenants);
1134
1282
  }
1135
1283
  return G;
1136
- }, V = async (w) => {
1137
- const { email: U, phoneNumber: z, name: _, password: Q, lastName: ee, tenantId: J } = w;
1138
- if (!U && !z)
1284
+ }, q = async (w) => {
1285
+ const { email: M, phoneNumber: z, name: O, password: Q, lastName: X, tenantId: J } = w;
1286
+ if (!M && !z)
1139
1287
  throw new Error("Either email or phoneNumber is required");
1140
- if (!_ || !Q)
1288
+ if (!O || !Q)
1141
1289
  throw new Error("Name and password are required");
1142
1290
  return v.signup({
1143
- email: U,
1291
+ email: M,
1144
1292
  phoneNumber: z,
1145
- name: _,
1293
+ name: O,
1146
1294
  password: Q,
1147
1295
  tenantId: J ?? (l == null ? void 0 : l.id),
1148
- lastName: ee,
1296
+ lastName: X,
1149
1297
  appId: a
1150
1298
  });
1151
- }, O = async (w) => {
1152
- const { email: U, phoneNumber: z, name: _, password: Q, tenantName: ee, lastName: J } = w;
1153
- if (!U && !z)
1299
+ }, _ = async (w) => {
1300
+ const { email: M, phoneNumber: z, name: O, password: Q, tenantName: X, lastName: J } = w;
1301
+ if (!M && !z)
1154
1302
  throw new Error("Either email or phoneNumber is required");
1155
- if (!_ || !Q || !ee)
1303
+ if (!O || !Q || !X)
1156
1304
  throw new Error("Name, password, and tenantName are required");
1157
1305
  return v.signupTenantAdmin({
1158
- email: U,
1306
+ email: M,
1159
1307
  phoneNumber: z,
1160
- name: _,
1308
+ name: O,
1161
1309
  password: Q,
1162
- tenantName: ee,
1310
+ tenantName: X,
1163
1311
  appId: a,
1164
1312
  lastName: J
1165
1313
  });
1166
1314
  }, W = async (w) => {
1167
1315
  await v.changePassword(w);
1168
- }, Y = async (w) => {
1169
- const { email: U, tenantId: z } = w, _ = z ?? (l == null ? void 0 : l.id);
1170
- if (!_)
1316
+ }, K = async (w) => {
1317
+ const { email: M, tenantId: z } = w, O = z ?? (l == null ? void 0 : l.id);
1318
+ if (!O)
1171
1319
  throw new Error("tenantId is required for password reset");
1172
- await v.requestPasswordReset({ email: U, tenantId: _ });
1173
- }, X = async (w) => {
1320
+ await v.requestPasswordReset({ email: M, tenantId: O });
1321
+ }, Y = async (w) => {
1174
1322
  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);
1323
+ }, le = async (w) => {
1324
+ const { email: M, frontendUrl: z, name: O, lastName: Q, tenantId: X } = w, J = X ?? (l == null ? void 0 : l.id);
1177
1325
  if (!J)
1178
1326
  throw new Error("tenantId is required for magic link authentication");
1179
1327
  return v.sendMagicLink({
1180
- email: U,
1328
+ email: M,
1181
1329
  tenantId: J,
1182
1330
  frontendUrl: z,
1183
- name: _,
1331
+ name: O,
1184
1332
  lastName: Q,
1185
1333
  appId: a
1186
1334
  });
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 = _);
1335
+ }, Te = async (w) => {
1336
+ const { token: M, email: z, tenantSlug: O } = w;
1337
+ let Q = l == null ? void 0 : l.id, X = d;
1338
+ O && (Q = (await new ye(u, a).getPublicTenantInfo(O)).id, X = O);
1191
1339
  const J = await v.verifyMagicLink({
1192
- token: U,
1340
+ token: M,
1193
1341
  email: z,
1194
1342
  appId: a,
1195
1343
  tenantId: Q
1196
- }), G = _ && _ !== d;
1344
+ }), G = O && O !== d;
1197
1345
  if (o.setTokens({
1198
1346
  accessToken: J.accessToken,
1199
1347
  refreshToken: J.refreshToken,
1200
1348
  expiresIn: J.expiresIn
1201
1349
  }), J.user) {
1202
- o.setUser(J.user), R(J.user);
1350
+ o.setUser(J.user), P(J.user);
1203
1351
  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);
1352
+ await U();
1353
+ } catch (Se) {
1354
+ process.env.NODE_ENV === "development" && console.warn("[AuthProvider] Failed to load complete user data after magic link:", Se);
1207
1355
  }
1208
1356
  }
1209
- return G && ee && ee !== d && T(ee), J;
1210
- }, Ve = async () => {
1357
+ return G && X && X !== d && T(X), J;
1358
+ }, We = async () => {
1211
1359
  const w = o.getTokens();
1212
1360
  if (!(w != null && w.refreshToken))
1213
1361
  throw new Error("No refresh token available");
1214
- const U = await v.refreshToken({
1362
+ const M = await v.refreshToken({
1215
1363
  refreshToken: w.refreshToken
1216
1364
  });
1217
1365
  o.setTokens({
1218
- accessToken: U.accessToken,
1219
- refreshToken: U.refreshToken || w.refreshToken,
1220
- expiresIn: U.expiresIn
1366
+ accessToken: M.accessToken,
1367
+ refreshToken: M.refreshToken || w.refreshToken,
1368
+ expiresIn: M.expiresIn
1221
1369
  });
1222
- }, Re = () => {
1223
- o.clearSession(), R(null), m(null), b([]), Qe();
1224
- }, Ie = (w) => {
1370
+ }, Fe = () => {
1371
+ o.clearSession(), P(null), m(null), b([]), et();
1372
+ }, Ne = (w) => {
1225
1373
  o.setTokens(w);
1226
- }, ot = () => o.hasValidSession(), at = () => {
1227
- o.clearSession(), R(null), m(null);
1228
- }, lt = async () => {
1374
+ }, ht = () => o.hasValidSession(), pt = () => {
1375
+ o.clearSession(), P(null), m(null);
1376
+ }, ft = async () => {
1229
1377
  if (a)
1230
1378
  try {
1231
1379
  h(!0);
1232
- const { roles: w } = await ie.getRolesByApp(a);
1380
+ const { roles: w } = await se.getRolesByApp(a);
1233
1381
  c(w);
1234
1382
  } catch (w) {
1235
1383
  process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", w);
1236
1384
  } finally {
1237
1385
  h(!1);
1238
1386
  }
1239
- }, ct = async (w, U) => {
1240
- const { redirectPath: z } = U || {}, _ = o.getTokens();
1241
- if (!(_ != null && _.refreshToken))
1387
+ }, mt = async (w, M) => {
1388
+ const { redirectPath: z } = M || {}, O = o.getTokens();
1389
+ if (!(O != null && O.refreshToken))
1242
1390
  throw new Error("No refresh token available for tenant switch");
1243
1391
  const Q = await v.switchTenant({
1244
- refreshToken: _.refreshToken,
1392
+ refreshToken: O.refreshToken,
1245
1393
  tenantId: w
1246
1394
  });
1247
1395
  o.setTokens({
1248
1396
  accessToken: Q.accessToken,
1249
- refreshToken: _.refreshToken,
1397
+ refreshToken: O.refreshToken,
1250
1398
  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 () => {
1399
+ }), P(Q.user), o.setUser(Q.user);
1400
+ const X = g.find((J) => J.id === w);
1401
+ X && T(X.subdomain, { redirectPath: z });
1402
+ }, gt = async () => {
1255
1403
  const w = await v.getUserTenants();
1256
- return b(w), He(w), w;
1404
+ return b(w), Xe(w), w;
1257
1405
  };
1258
1406
  $.current = {
1259
- login: F,
1260
- signup: V,
1261
- signupTenantAdmin: O,
1262
- sendMagicLink: ae,
1263
- verifyMagicLink: we,
1407
+ login: L,
1408
+ signup: q,
1409
+ signupTenantAdmin: _,
1410
+ sendMagicLink: le,
1411
+ verifyMagicLink: Te,
1264
1412
  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
1413
+ requestPasswordReset: K,
1414
+ confirmPasswordReset: Y,
1415
+ refreshToken: We,
1416
+ logout: Fe,
1417
+ setTokens: Ne,
1418
+ hasValidSession: ht,
1419
+ clearSession: pt,
1420
+ loadUserData: U,
1421
+ refreshUser: () => U(),
1422
+ refreshRoles: ft,
1423
+ switchToTenant: mt,
1424
+ refreshUserTenants: gt
1277
1425
  };
1278
- const dt = q(
1426
+ const yt = V(
1279
1427
  () => ({
1280
1428
  login: (w) => $.current.login(w),
1281
1429
  signup: (w) => $.current.signup(w),
@@ -1293,100 +1441,100 @@ function pr({ config: r = {}, children: e }) {
1293
1441
  loadUserData: (w) => $.current.loadUserData(w),
1294
1442
  refreshUser: () => $.current.refreshUser(),
1295
1443
  refreshRoles: () => $.current.refreshRoles(),
1296
- switchToTenant: (w, U) => $.current.switchToTenant(w, U),
1444
+ switchToTenant: (w, M) => $.current.switchToTenant(w, M),
1297
1445
  refreshUserTenants: () => $.current.refreshUserTenants()
1298
1446
  }),
1299
1447
  []
1300
- ), ht = q(() => {
1301
- const w = (U) => !H || H.length === 0 ? !1 : typeof U == "string" ? H.includes(U) : H.includes(`${U.resource}.${U.action}`);
1448
+ ), bt = V(() => {
1449
+ const w = (M) => !H || H.length === 0 ? !1 : typeof M == "string" ? H.includes(M) : H.includes(`${M.resource}.${M.action}`);
1302
1450
  return {
1303
1451
  isAuthenticated: j,
1304
1452
  isAuthInitializing: !y,
1305
1453
  isAuthReady: y,
1306
- currentUser: E,
1454
+ currentUser: x,
1307
1455
  isUserLoading: I,
1308
- userError: S,
1309
- userRole: L,
1456
+ userError: k,
1457
+ userRole: F,
1310
1458
  userPermissions: H,
1311
- availableRoles: P,
1312
- rolesLoading: k,
1459
+ availableRoles: A,
1460
+ rolesLoading: S,
1313
1461
  userTenants: g,
1314
1462
  hasTenantContext: Z,
1315
1463
  sessionManager: o,
1316
1464
  authenticatedHttpService: u,
1317
1465
  hasPermission: w,
1318
- hasAnyPermission: (U) => U.some((z) => w(z)),
1319
- hasAllPermissions: (U) => U.every((z) => w(z)),
1466
+ hasAnyPermission: (M) => M.some((z) => w(z)),
1467
+ hasAllPermissions: (M) => M.every((z) => w(z)),
1320
1468
  getUserPermissionStrings: () => H || []
1321
1469
  };
1322
1470
  }, [
1323
1471
  j,
1324
1472
  y,
1325
- E,
1473
+ x,
1326
1474
  I,
1327
- S,
1328
- L,
1329
- H,
1330
- P,
1331
1475
  k,
1476
+ F,
1477
+ H,
1478
+ A,
1479
+ S,
1332
1480
  g,
1333
1481
  Z,
1334
1482
  o,
1335
1483
  u
1336
1484
  ]);
1337
- return ne(() => {
1485
+ return re(() => {
1338
1486
  if (r.initialRoles || !a) return;
1339
1487
  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);
1488
+ return h(!0), se.getRolesByApp(a).then(({ roles: M }) => {
1489
+ w || c(M);
1490
+ }).catch((M) => {
1491
+ process.env.NODE_ENV === "development" && console.error("[AuthProvider] Failed to fetch roles:", M);
1344
1492
  }).finally(() => {
1345
1493
  w || h(!1);
1346
1494
  }), () => {
1347
1495
  w = !0;
1348
1496
  };
1349
- }, [a, r.initialRoles, ie]), ne(() => {
1497
+ }, [a, r.initialRoles, se]), re(() => {
1350
1498
  let w = !1;
1351
1499
  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))
1500
+ var O;
1501
+ if (!o.hasValidSession() && ((O = o.getTokens()) != null && O.refreshToken) && await o.waitForPendingRefresh(), w || !o.hasValidSession() && !o.getTokens() && r.enableCookieSession && (await o.attemptCookieSessionRestore(), w))
1354
1502
  return;
1355
1503
  const z = o.getUser();
1356
- z && o.hasValidSession() && R(z), x(!1);
1504
+ z && o.hasValidSession() && P(z), E(!1);
1357
1505
  })(), () => {
1358
1506
  w = !0;
1359
1507
  };
1360
- }, [o, r.enableCookieSession]), ne(() => {
1361
- !E && !I && !S && o.hasValidSession() ? $.current.loadUserData().catch(() => {
1508
+ }, [o, r.enableCookieSession]), re(() => {
1509
+ !x && !I && !k && o.hasValidSession() ? $.current.loadUserData().catch(() => {
1362
1510
  }).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 }) });
1511
+ E(!1);
1512
+ }) : E(!1);
1513
+ }, [x, I, k, o]), /* @__PURE__ */ s(Ie.Provider, { value: yt, children: /* @__PURE__ */ s(Pe.Provider, { value: bt, children: e }) });
1366
1514
  }
1367
- function fr() {
1368
- const r = se(Ee);
1515
+ function Pr() {
1516
+ const r = ne(Pe);
1369
1517
  if (!r)
1370
1518
  throw new Error("useAuthState must be used within an AuthProvider");
1371
1519
  return r;
1372
1520
  }
1373
- function mr() {
1374
- const r = se(Pe);
1521
+ function Ir() {
1522
+ const r = ne(Ie);
1375
1523
  if (!r)
1376
1524
  throw new Error("useAuthActions must be used within an AuthProvider");
1377
1525
  return r;
1378
1526
  }
1379
- function ue() {
1380
- const r = se(Ee), e = se(Pe);
1527
+ function de() {
1528
+ const r = ne(Pe), e = ne(Ie);
1381
1529
  if (!r || !e)
1382
1530
  throw new Error("useAuth must be used within an AuthProvider");
1383
- return q(() => ({ ...r, ...e }), [r, e]);
1531
+ return V(() => ({ ...r, ...e }), [r, e]);
1384
1532
  }
1385
- function Me() {
1386
- const r = se(Ee), e = se(Pe);
1387
- return q(() => !r || !e ? null : { ...r, ...e }, [r, e]);
1533
+ function Oe() {
1534
+ const r = ne(Pe), e = ne(Ie);
1535
+ return V(() => !r || !e ? null : { ...r, ...e }, [r, e]);
1388
1536
  }
1389
- class Pt {
1537
+ class Ot {
1390
1538
  constructor(e) {
1391
1539
  this.httpService = e;
1392
1540
  }
@@ -1398,7 +1546,7 @@ class Pt {
1398
1546
  }
1399
1547
  async getFeatureFlags(e) {
1400
1548
  const t = await this.httpService.get(
1401
- `/feature-flags/${le(e)}`
1549
+ `/feature-flags/${ce(e)}`
1402
1550
  );
1403
1551
  return { featureFlags: t.data, meta: t.meta };
1404
1552
  }
@@ -1417,7 +1565,7 @@ class Pt {
1417
1565
  async getTenantFeatureFlags(e, t) {
1418
1566
  if (!e || !t)
1419
1567
  throw new Error("Tenant ID and App ID are required");
1420
- const n = le({ tenantId: e, appId: t });
1568
+ const n = ce({ tenantId: e, appId: t });
1421
1569
  return (await this.httpService.get(
1422
1570
  `/tenant-feature-flags${n}`,
1423
1571
  { headers: { "X-Tenant-ID": e }, skipAuth: !0 }
@@ -1426,19 +1574,19 @@ class Pt {
1426
1574
  async getTenantFeatureFlag(e, t, n) {
1427
1575
  if (!e || !t || !n)
1428
1576
  throw new Error("Flag Key, Tenant ID and App ID are required");
1429
- const i = le({ tenantId: t, appId: n });
1577
+ const i = ce({ tenantId: t, appId: n });
1430
1578
  return (await this.httpService.get(
1431
1579
  `/tenant-feature-flags/${e}${i}`,
1432
1580
  { headers: { "X-Tenant-ID": t }, skipAuth: !0 }
1433
1581
  )).data;
1434
1582
  }
1435
1583
  }
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);
1441
- }, [i]), A = async () => {
1584
+ const Ve = fe(null);
1585
+ function Lr({ config: r = {}, children: e }) {
1586
+ 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([]), [A, c] = N(!1), [S, h] = N(null), [x, P] = N(!1), I = V(() => {
1587
+ const m = new he(i);
1588
+ return new Ot(m);
1589
+ }, [i]), R = async () => {
1442
1590
  if (!(l != null && l.id)) {
1443
1591
  T([]);
1444
1592
  return;
@@ -1454,45 +1602,45 @@ function gr({ config: r = {}, children: e }) {
1454
1602
  c(!1);
1455
1603
  }
1456
1604
  };
1457
- ne(() => {
1605
+ re(() => {
1458
1606
  if (!i || !a) return;
1459
- A().finally(() => R(!0));
1460
- const m = r.refreshInterval || 5 * 60 * 1e3, g = setInterval(A, m);
1607
+ R().finally(() => P(!0));
1608
+ const m = r.refreshInterval || 5 * 60 * 1e3, g = setInterval(R, m);
1461
1609
  return () => clearInterval(g);
1462
1610
  }, [l == null ? void 0 : l.id, i, a, r.refreshInterval]);
1463
- const S = q(() => {
1611
+ const k = V(() => {
1464
1612
  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 () => {
1471
- await A();
1472
- }, o = !!(i && a) && (E || !(l != null && l.id));
1613
+ const E = d.find((y) => y.key === p);
1614
+ return (E == null ? void 0 : E.value) === !0;
1615
+ }, g = (p) => d.find((E) => E.key === p), b = (p) => {
1616
+ const E = d.find((y) => y.key === p);
1617
+ return E ? E.value ? "enabled" : "disabled" : "not_found";
1618
+ }, C = async () => {
1619
+ await R();
1620
+ }, o = !!(i && a) && (x || !(l != null && l.id));
1473
1621
  return {
1474
1622
  featureFlags: d,
1475
- loading: P,
1476
- error: k,
1623
+ loading: A,
1624
+ error: S,
1477
1625
  isReady: o,
1478
1626
  isEnabled: m,
1479
1627
  getFlag: g,
1480
1628
  getFlagState: b,
1481
- refresh: D
1629
+ refresh: C
1482
1630
  };
1483
- }, [d, P, k, i, a, l == null ? void 0 : l.id, E]);
1484
- return /* @__PURE__ */ s(Be.Provider, { value: S, children: e });
1631
+ }, [d, A, S, i, a, l == null ? void 0 : l.id, x]);
1632
+ return /* @__PURE__ */ s(Ve.Provider, { value: k, children: e });
1485
1633
  }
1486
- function At() {
1487
- const r = se(Be);
1634
+ function Vt() {
1635
+ const r = ne(Ve);
1488
1636
  if (!r)
1489
1637
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1490
1638
  return r;
1491
1639
  }
1492
- function tt() {
1493
- return se(Be);
1640
+ function at() {
1641
+ return ne(Ve);
1494
1642
  }
1495
- class Rt {
1643
+ class qt {
1496
1644
  constructor(e) {
1497
1645
  this.httpService = e;
1498
1646
  }
@@ -1532,68 +1680,68 @@ class Rt {
1532
1680
  )).data;
1533
1681
  }
1534
1682
  }
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);
1683
+ const qe = fe(void 0);
1684
+ function Fr({ config: r = {}, children: e }) {
1685
+ 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, A] = N(!1), [c, S] = N(null), [h, x] = N(!1), P = V(() => {
1686
+ const k = new he(i);
1687
+ return new qt(k);
1540
1688
  }, [i]), I = async () => {
1541
1689
  if (!(a != null && a.id)) {
1542
1690
  d(null);
1543
1691
  return;
1544
1692
  }
1545
- P(!0), k(null);
1693
+ A(!0), S(null);
1546
1694
  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));
1695
+ const k = await P.getTenantSubscriptionFeatures(a.id);
1696
+ d(k);
1697
+ } catch (k) {
1698
+ const m = k instanceof Error ? k.message : "Failed to fetch subscription";
1699
+ S(m), r.onError && r.onError(k instanceof Error ? k : new Error(m));
1552
1700
  } finally {
1553
- P(!1);
1701
+ A(!1);
1554
1702
  }
1555
1703
  };
1556
- ne(() => {
1557
- if (!i || (I().finally(() => E(!0)), !r.refreshInterval)) return;
1558
- const S = r.refreshInterval || 10 * 60 * 1e3, m = setInterval(I, S);
1704
+ re(() => {
1705
+ if (!i || (I().finally(() => x(!0)), !r.refreshInterval)) return;
1706
+ const k = r.refreshInterval || 10 * 60 * 1e3, m = setInterval(I, k);
1559
1707
  return () => clearInterval(m);
1560
1708
  }, [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);
1709
+ const R = V(() => {
1710
+ const k = (l == null ? void 0 : l.features) || [], m = (E) => {
1711
+ const y = k.find((u) => u.key === E);
1564
1712
  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);
1713
+ }, g = (E) => k.find((y) => y.key === E), b = (E, y) => {
1714
+ const u = k.find((v) => v.key === E);
1567
1715
  return u ? u.value : y;
1568
- }, D = (x) => !l || !l.isActive ? !1 : x.includes(l.planId), o = async () => {
1716
+ }, C = (E) => !l || !l.isActive ? !1 : E.includes(l.planId), o = async () => {
1569
1717
  await I();
1570
1718
  }, p = !!i && (h || !(a != null && a.id));
1571
1719
  return {
1572
1720
  subscription: l,
1573
- features: S,
1721
+ features: k,
1574
1722
  loading: T,
1575
1723
  error: c,
1576
1724
  isReady: p,
1577
1725
  isFeatureEnabled: m,
1578
1726
  getFeature: g,
1579
1727
  getFeatureValue: b,
1580
- hasAllowedPlan: D,
1728
+ hasAllowedPlan: C,
1581
1729
  refresh: o
1582
1730
  };
1583
1731
  }, [l, T, c, i, a == null ? void 0 : a.id, h]);
1584
- return /* @__PURE__ */ s(Oe.Provider, { value: A, children: e });
1732
+ return /* @__PURE__ */ s(qe.Provider, { value: R, children: e });
1585
1733
  }
1586
- function It() {
1587
- const r = se(Oe);
1734
+ function zt() {
1735
+ const r = ne(qe);
1588
1736
  if (r === void 0)
1589
1737
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1590
1738
  return r;
1591
1739
  }
1592
- function rt() {
1593
- return se(Oe) ?? null;
1740
+ function lt() {
1741
+ return ne(qe) ?? null;
1594
1742
  }
1595
- var oe = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(oe || {});
1596
- const _e = {
1743
+ var ae = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(ae || {});
1744
+ const ze = {
1597
1745
  publicGuest: "/",
1598
1746
  publicUser: "/account",
1599
1747
  publicAdmin: "/admin",
@@ -1601,7 +1749,7 @@ const _e = {
1601
1749
  tenantUser: "/dashboard",
1602
1750
  tenantAdmin: "/admin/dashboard",
1603
1751
  default: "/"
1604
- }, nt = {
1752
+ }, ct = {
1605
1753
  // Public/Landing zones
1606
1754
  landing: { tenant: "forbidden", auth: "optional" },
1607
1755
  publicOnly: { tenant: "forbidden", auth: "forbidden" },
@@ -1614,26 +1762,26 @@ const _e = {
1614
1762
  tenantOpen: { tenant: "required", auth: "optional" },
1615
1763
  tenantAuth: { tenant: "required", auth: "required" },
1616
1764
  // User type zones
1617
- user: { tenant: "required", auth: "required", userType: oe.USER },
1618
- admin: { tenant: "required", auth: "required", userType: oe.TENANT_ADMIN },
1765
+ user: { tenant: "required", auth: "required", userType: ae.USER },
1766
+ admin: { tenant: "required", auth: "required", userType: ae.TENANT_ADMIN },
1619
1767
  // Fully open
1620
1768
  open: { tenant: "optional", auth: "optional" }
1621
- }, qe = pe(null), Ft = {
1622
- zoneRoots: _e,
1623
- presets: nt,
1769
+ }, je = fe(null), jt = {
1770
+ zoneRoots: ze,
1771
+ presets: ct,
1624
1772
  loadingFallback: null,
1625
1773
  accessDeniedFallback: null,
1626
1774
  onAccessDenied: void 0,
1627
1775
  returnToParam: "returnTo",
1628
1776
  returnToStorage: "url"
1629
1777
  };
1630
- function br({ config: r = {}, children: e }) {
1631
- const t = q(() => {
1778
+ function Nr({ config: r = {}, children: e }) {
1779
+ const t = V(() => {
1632
1780
  const n = {
1633
- ..._e,
1781
+ ...ze,
1634
1782
  ...r.zoneRoots
1635
1783
  }, i = {
1636
- ...nt,
1784
+ ...ct,
1637
1785
  ...r.presets
1638
1786
  };
1639
1787
  return {
@@ -1646,18 +1794,18 @@ function br({ config: r = {}, children: e }) {
1646
1794
  returnToStorage: r.returnToStorage ?? "url"
1647
1795
  };
1648
1796
  }, [r]);
1649
- return /* @__PURE__ */ s(qe.Provider, { value: t, children: e });
1797
+ return /* @__PURE__ */ s(je.Provider, { value: t, children: e });
1650
1798
  }
1651
- function wr() {
1652
- const r = se(qe);
1799
+ function Cr() {
1800
+ const r = ne(je);
1653
1801
  if (!r)
1654
1802
  throw new Error("useRouting must be used within a RoutingProvider");
1655
1803
  return r;
1656
1804
  }
1657
- function Lt() {
1658
- return se(qe) ?? Ft;
1805
+ function Wt() {
1806
+ return ne(je) ?? jt;
1659
1807
  }
1660
- const Je = () => /* @__PURE__ */ f(
1808
+ const tt = () => /* @__PURE__ */ f(
1661
1809
  "div",
1662
1810
  {
1663
1811
  style: {
@@ -1694,7 +1842,7 @@ const Je = () => /* @__PURE__ */ f(
1694
1842
  )
1695
1843
  ]
1696
1844
  }
1697
- ), Ze = ({
1845
+ ), rt = ({
1698
1846
  userType: r,
1699
1847
  minUserType: e,
1700
1848
  missingPermissions: t
@@ -1735,36 +1883,36 @@ const Je = () => /* @__PURE__ */ f(
1735
1883
  ] })
1736
1884
  ]
1737
1885
  }
1738
- ), Nt = (r, e) => {
1886
+ ), Gt = (r, e) => {
1739
1887
  const t = {
1740
- [oe.USER]: 1,
1741
- [oe.TENANT_ADMIN]: 2,
1742
- [oe.SUPERUSER]: 3
1888
+ [ae.USER]: 1,
1889
+ [ae.TENANT_ADMIN]: 2,
1890
+ [ae.SUPERUSER]: 3
1743
1891
  };
1744
1892
  return t[r] >= t[e];
1745
1893
  };
1746
- function vr({
1894
+ function Dr({
1747
1895
  children: r,
1748
1896
  fallback: e,
1749
1897
  minUserType: t,
1750
1898
  requiredPermissions: n,
1751
1899
  requireAllPermissions: i = !1
1752
1900
  }) {
1753
- const { hasValidSession: a, sessionManager: l, hasPermission: d, hasAnyPermission: T, hasAllPermissions: P } = ue();
1901
+ const { hasValidSession: a, sessionManager: l, hasPermission: d, hasAnyPermission: T, hasAllPermissions: A } = de();
1754
1902
  if (!a())
1755
- return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(Je, {}) });
1903
+ return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(tt, {}) });
1756
1904
  const c = l.getUser();
1757
1905
  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 });
1906
+ return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(tt, {}) });
1907
+ if (t && !Gt(c.userType, t))
1908
+ return /* @__PURE__ */ s(rt, { userType: c.userType, minUserType: t });
1909
+ if (n && n.length > 0 && !(i ? A(n) : T(n))) {
1910
+ const h = n.filter((x) => !d(x)).map((x) => typeof x == "string" ? x : x.name);
1911
+ return /* @__PURE__ */ s(rt, { missingPermissions: h });
1764
1912
  }
1765
1913
  return /* @__PURE__ */ s(B, { children: r });
1766
1914
  }
1767
- const Dt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1915
+ const Ht = ({ redirectPath: r }) => /* @__PURE__ */ s(
1768
1916
  "div",
1769
1917
  {
1770
1918
  style: {
@@ -1800,7 +1948,7 @@ const Dt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1800
1948
  }
1801
1949
  )
1802
1950
  }
1803
- ), Ke = ({
1951
+ ), nt = ({
1804
1952
  userType: r,
1805
1953
  requiredUserType: e,
1806
1954
  missingPermissions: t
@@ -1851,8 +1999,8 @@ const Dt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1851
1999
  }
1852
2000
  )
1853
2001
  }
1854
- ), Ct = (r, e) => r === e;
1855
- function Tr({
2002
+ ), Qt = (r, e) => r === e;
2003
+ function Mr({
1856
2004
  children: r,
1857
2005
  redirectTo: e = "/login",
1858
2006
  requiredUserType: t,
@@ -1860,34 +2008,34 @@ function Tr({
1860
2008
  requireAllPermissions: i = !1,
1861
2009
  fallback: a
1862
2010
  }) {
1863
- const { hasValidSession: l, sessionManager: d, hasPermission: T, hasAnyPermission: P, hasAllPermissions: c } = ue(), k = Se();
1864
- if (ne(() => {
2011
+ const { hasValidSession: l, sessionManager: d, hasPermission: T, hasAnyPermission: A, hasAllPermissions: c } = de(), S = xe();
2012
+ if (re(() => {
1865
2013
  process.env.NODE_ENV === "development" && console.warn(
1866
2014
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
1867
2015
  );
1868
2016
  }, []), !l())
1869
2017
  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 })
2018
+ /* @__PURE__ */ s(Ht, { redirectPath: e }),
2019
+ /* @__PURE__ */ s(be, { to: e, state: { from: S.pathname }, replace: !0 })
1872
2020
  ] });
1873
2021
  const h = d.getUser();
1874
2022
  if (!h)
1875
- return /* @__PURE__ */ s(ge, { to: e, state: { from: k.pathname }, replace: !0 });
1876
- if (t && !Ct(h.userType, t))
2023
+ return /* @__PURE__ */ s(be, { to: e, state: { from: S.pathname }, replace: !0 });
2024
+ if (t && !Qt(h.userType, t))
1877
2025
  return /* @__PURE__ */ s(
1878
- Ke,
2026
+ nt,
1879
2027
  {
1880
2028
  userType: h.userType,
1881
2029
  requiredUserType: t
1882
2030
  }
1883
2031
  );
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 });
2032
+ if (n && n.length > 0 && !(i ? c(n) : A(n))) {
2033
+ const P = n.filter((I) => !T(I)).map((I) => typeof I == "string" ? I : I.name);
2034
+ return /* @__PURE__ */ s(nt, { missingPermissions: P });
1887
2035
  }
1888
2036
  return /* @__PURE__ */ s(B, { children: r });
1889
2037
  }
1890
- const Ut = ({ redirectPath: r }) => /* @__PURE__ */ s(
2038
+ const Jt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1891
2039
  "div",
1892
2040
  {
1893
2041
  style: {
@@ -1924,18 +2072,18 @@ const Ut = ({ redirectPath: r }) => /* @__PURE__ */ s(
1924
2072
  )
1925
2073
  }
1926
2074
  );
1927
- function kr({ children: r, redirectTo: e = "/", fallback: t }) {
1928
- const { tenant: n, isLoading: i, error: a } = et(), l = Se();
1929
- return ne(() => {
2075
+ function $r({ children: r, redirectTo: e = "/", fallback: t }) {
2076
+ const { tenant: n, isLoading: i, error: a } = ot(), l = xe();
2077
+ return re(() => {
1930
2078
  process.env.NODE_ENV === "development" && console.warn(
1931
2079
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
1932
2080
  );
1933
2081
  }, []), 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 })
2082
+ /* @__PURE__ */ s(Jt, { redirectPath: e }),
2083
+ /* @__PURE__ */ s(be, { to: e, state: { from: l.pathname }, replace: !0 })
1936
2084
  ] });
1937
2085
  }
1938
- const $t = ({ redirectPath: r }) => /* @__PURE__ */ s(
2086
+ const Zt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1939
2087
  "div",
1940
2088
  {
1941
2089
  style: {
@@ -1972,41 +2120,41 @@ const $t = ({ redirectPath: r }) => /* @__PURE__ */ s(
1972
2120
  )
1973
2121
  }
1974
2122
  );
1975
- function Sr({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
1976
- const { tenant: n, isLoading: i, error: a } = et(), l = Se();
1977
- return ne(() => {
2123
+ function Ur({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
2124
+ const { tenant: n, isLoading: i, error: a } = ot(), l = xe();
2125
+ return re(() => {
1978
2126
  process.env.NODE_ENV === "development" && console.warn(
1979
2127
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
1980
2128
  );
1981
2129
  }, []), 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 })
2130
+ /* @__PURE__ */ s(Zt, { redirectPath: e }),
2131
+ /* @__PURE__ */ s(be, { to: e, state: { from: l.pathname }, replace: !0 })
1984
2132
  ] }) : /* @__PURE__ */ s(B, { children: r });
1985
2133
  }
1986
- function Mt(r, e) {
2134
+ function Kt(r, e) {
1987
2135
  return e ? r ? Array.isArray(e) ? e.includes(r) : r === e : !1 : !0;
1988
2136
  }
1989
- function Ye(r, e) {
2137
+ function st(r, e) {
1990
2138
  return !r || r === "optional" ? "skip" : r === "required" ? e ? "pass" : "fail" : r === "forbidden" ? e ? "fail" : "pass" : "skip";
1991
2139
  }
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;
2140
+ function Yt(r, e) {
2141
+ 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
2142
  }
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;
2143
+ function Xt(r, e) {
2144
+ 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
2145
  }
1998
- function _t(r, e, t, n, i) {
2146
+ function er(r, e, t, n, i) {
1999
2147
  if (!e || i !== "url")
2000
2148
  return r;
2001
2149
  const a = typeof e == "string" ? e : t, l = r.includes("?") ? "&" : "?";
2002
2150
  return `${r}${l}${n}=${encodeURIComponent(a)}`;
2003
2151
  }
2004
- function qt(r, e, t) {
2152
+ function tr(r, e, t) {
2005
2153
  if (!r || t === "url") return;
2006
2154
  const n = typeof r == "string" ? r : e, i = "zone_return_to";
2007
2155
  t === "session" ? sessionStorage.setItem(i, n) : t === "local" && localStorage.setItem(i, n);
2008
2156
  }
2009
- const ce = ({
2157
+ const ue = ({
2010
2158
  children: r,
2011
2159
  preset: e,
2012
2160
  tenant: t,
@@ -2016,14 +2164,14 @@ const ce = ({
2016
2164
  requireAllPermissions: l = !0,
2017
2165
  returnTo: d,
2018
2166
  onAccessDenied: T,
2019
- redirectTo: P,
2167
+ redirectTo: A,
2020
2168
  loadingFallback: c,
2021
- accessDeniedFallback: k
2169
+ accessDeniedFallback: S
2022
2170
  }) => {
2023
- const h = Se(), { isAuthenticated: E, isAuthInitializing: R, currentUser: I, userPermissions: A } = ue(), { tenant: S, isTenantLoading: m } = be(), g = Lt(), b = q(() => {
2171
+ const h = xe(), { isAuthenticated: x, isAuthInitializing: P, currentUser: I, userPermissions: R } = de(), { tenant: k, isTenantLoading: m } = ve(), g = Wt(), b = V(() => {
2024
2172
  if (e)
2025
2173
  return g.presets[e];
2026
- }, [e, g.presets]), D = q(
2174
+ }, [e, g.presets]), C = V(
2027
2175
  () => ({
2028
2176
  tenant: t ?? (b == null ? void 0 : b.tenant),
2029
2177
  auth: n ?? (b == null ? void 0 : b.auth),
@@ -2032,29 +2180,29 @@ const ce = ({
2032
2180
  requireAllPermissions: l
2033
2181
  }),
2034
2182
  [t, n, i, a, b, l]
2035
- ), o = q(
2183
+ ), o = V(
2036
2184
  () => ({
2037
- hasTenant: !!S,
2038
- isAuthenticated: E,
2185
+ hasTenant: !!k,
2186
+ isAuthenticated: x,
2039
2187
  userType: I == null ? void 0 : I.userType,
2040
- permissions: A,
2041
- isLoading: R || m
2188
+ permissions: R,
2189
+ isLoading: P || m
2042
2190
  }),
2043
2191
  [
2044
- S,
2045
- E,
2192
+ k,
2193
+ x,
2046
2194
  I == null ? void 0 : I.userType,
2047
- A,
2048
2195
  R,
2196
+ P,
2049
2197
  m
2050
2198
  ]
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 : {
2199
+ ), p = V(() => o.isLoading ? null : Yt(C, o), [C, o]), E = V(() => p ? A || Xt(o, g.zoneRoots) : null, [p, A, o, g.zoneRoots]), y = V(() => !p || !E ? null : {
2052
2200
  type: p,
2053
2201
  required: {
2054
- tenant: D.tenant,
2055
- auth: D.auth,
2056
- userType: D.userType,
2057
- permissions: D.permissions
2202
+ tenant: C.tenant,
2203
+ auth: C.auth,
2204
+ userType: C.userType,
2205
+ permissions: C.permissions
2058
2206
  },
2059
2207
  current: {
2060
2208
  hasTenant: o.hasTenant,
@@ -2062,12 +2210,12 @@ const ce = ({
2062
2210
  userType: o.userType,
2063
2211
  permissions: o.permissions
2064
2212
  },
2065
- redirectTo: x
2066
- }, [p, x, D, o]);
2067
- if (ne(() => {
2213
+ redirectTo: E
2214
+ }, [p, E, C, o]);
2215
+ if (re(() => {
2068
2216
  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);
2217
+ }, [y, T, g]), re(() => {
2218
+ y && d && tr(d, h.pathname + h.search, g.returnToStorage);
2071
2219
  }, [
2072
2220
  y,
2073
2221
  d,
@@ -2076,21 +2224,21 @@ const ce = ({
2076
2224
  g.returnToStorage
2077
2225
  ]), o.isLoading)
2078
2226
  return /* @__PURE__ */ s(B, { children: c ?? g.loadingFallback ?? null });
2079
- if (y && x) {
2080
- const u = k ?? g.accessDeniedFallback;
2227
+ if (y && E) {
2228
+ const u = S ?? g.accessDeniedFallback;
2081
2229
  if (u)
2082
2230
  return /* @__PURE__ */ s(B, { children: u });
2083
- const v = _t(
2084
- x,
2231
+ const v = er(
2232
+ E,
2085
2233
  d,
2086
2234
  h.pathname + h.search,
2087
2235
  g.returnToParam,
2088
2236
  g.returnToStorage
2089
2237
  );
2090
- return /* @__PURE__ */ s(ge, { to: v, replace: !0 });
2238
+ return /* @__PURE__ */ s(be, { to: v, replace: !0 });
2091
2239
  }
2092
2240
  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(
2241
+ }, 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
2242
  "div",
2095
2243
  {
2096
2244
  style: {
@@ -2107,13 +2255,13 @@ const ce = ({
2107
2255
  ]
2108
2256
  }
2109
2257
  );
2110
- function Cr({
2258
+ function Qr({
2111
2259
  children: r,
2112
- fallback: e = /* @__PURE__ */ s(Vt, {}),
2260
+ fallback: e = /* @__PURE__ */ s(rr, {}),
2113
2261
  allowedPlans: t,
2114
2262
  requiredFeature: n
2115
2263
  }) {
2116
- const { subscription: i, hasAllowedPlan: a, isFeatureEnabled: l, loading: d } = It();
2264
+ const { subscription: i, hasAllowedPlan: a, isFeatureEnabled: l, loading: d } = zt();
2117
2265
  return d ? /* @__PURE__ */ s(
2118
2266
  "div",
2119
2267
  {
@@ -2126,7 +2274,7 @@ function Cr({
2126
2274
  }
2127
2275
  ) : 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
2276
  }
2129
- const zt = ({ flagName: r }) => /* @__PURE__ */ f(
2277
+ const nr = ({ flagName: r }) => /* @__PURE__ */ f(
2130
2278
  "div",
2131
2279
  {
2132
2280
  style: {
@@ -2153,8 +2301,8 @@ const zt = ({ flagName: r }) => /* @__PURE__ */ f(
2153
2301
  ]
2154
2302
  }
2155
2303
  );
2156
- function Ur({ name: r, children: e, fallback: t }) {
2157
- const { isEnabled: n, loading: i } = At();
2304
+ function Jr({ name: r, children: e, fallback: t }) {
2305
+ const { isEnabled: n, loading: i } = Vt();
2158
2306
  return i ? /* @__PURE__ */ s(
2159
2307
  "div",
2160
2308
  {
@@ -2168,29 +2316,29 @@ function Ur({ name: r, children: e, fallback: t }) {
2168
2316
  },
2169
2317
  children: "Loading feature flags..."
2170
2318
  }
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 };
2180
- return delete m[A], m;
2319
+ ) : n(r) ? /* @__PURE__ */ s(B, { children: e }) : /* @__PURE__ */ s(B, { children: t || /* @__PURE__ */ s(nr, { flagName: r }) });
2320
+ }
2321
+ function we(r) {
2322
+ const { submit: e, defaultErrorMessage: t, validate: n, onSuccess: i, onError: a } = r, [l, d] = N(!1), [T, A] = N(""), [c, S] = N({}), h = te((R, k) => {
2323
+ S((m) => ({ ...m, [R]: k }));
2324
+ }, []), x = te((R) => {
2325
+ S((k) => {
2326
+ if (!k[R]) return k;
2327
+ const m = { ...k };
2328
+ return delete m[R], m;
2181
2329
  });
2182
- }, []), R = re(() => {
2183
- P(""), k({});
2184
- }, []), I = re(
2185
- async (A) => {
2186
- if (A && A.preventDefault(), !(n && !n())) {
2187
- d(!0), P("");
2330
+ }, []), P = te(() => {
2331
+ A(""), S({});
2332
+ }, []), I = te(
2333
+ async (R) => {
2334
+ if (R && R.preventDefault(), !(n && !n())) {
2335
+ d(!0), A("");
2188
2336
  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);
2337
+ const k = await e();
2338
+ return i == null || i(k), k;
2339
+ } catch (k) {
2340
+ const m = k instanceof Error ? k.message : t;
2341
+ A(m), a == null || a(m);
2194
2342
  return;
2195
2343
  } finally {
2196
2344
  d(!1);
@@ -2202,15 +2350,15 @@ function ye(r) {
2202
2350
  return {
2203
2351
  loading: l,
2204
2352
  error: T,
2205
- setError: P,
2353
+ setError: A,
2206
2354
  fieldErrors: c,
2207
2355
  setFieldError: h,
2208
- clearFieldError: E,
2209
- resetErrors: R,
2356
+ clearFieldError: x,
2357
+ resetErrors: P,
2210
2358
  handleSubmit: I
2211
2359
  };
2212
2360
  }
2213
- const Xe = {
2361
+ const it = {
2214
2362
  container: {
2215
2363
  maxWidth: "400px",
2216
2364
  width: "100%",
@@ -2374,18 +2522,18 @@ const Xe = {
2374
2522
  color: "#6b7280"
2375
2523
  }
2376
2524
  };
2377
- function Ae(r, e) {
2525
+ function Le(r, e) {
2378
2526
  return {
2379
- ...Xe,
2527
+ ...it,
2380
2528
  ...e,
2381
2529
  button: {
2382
- ...Xe.button,
2530
+ ...it.button,
2383
2531
  backgroundColor: r,
2384
2532
  ...(e == null ? void 0 : e.button) || {}
2385
2533
  }
2386
2534
  };
2387
2535
  }
2388
- const jt = () => fe.createElement(
2536
+ const sr = () => me.createElement(
2389
2537
  "svg",
2390
2538
  {
2391
2539
  width: "16",
@@ -2398,9 +2546,9 @@ const jt = () => fe.createElement(
2398
2546
  strokeLinejoin: "round",
2399
2547
  style: { flexShrink: 0 }
2400
2548
  },
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(
2549
+ me.createElement("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
2550
+ me.createElement("circle", { cx: "12", cy: "12", r: "3" })
2551
+ ), ir = () => me.createElement(
2404
2552
  "svg",
2405
2553
  {
2406
2554
  width: "16",
@@ -2413,14 +2561,14 @@ const jt = () => fe.createElement(
2413
2561
  strokeLinejoin: "round",
2414
2562
  style: { flexShrink: 0 }
2415
2563
  },
2416
- fe.createElement("path", {
2564
+ me.createElement("path", {
2417
2565
  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
2566
  }),
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 = {
2567
+ me.createElement("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2568
+ ), or = {
2569
+ showPassword: /* @__PURE__ */ s(sr, {}),
2570
+ hidePassword: /* @__PURE__ */ s(ir, {})
2571
+ }, ar = {
2424
2572
  title: "Sign In",
2425
2573
  usernameLabel: "Email or Phone",
2426
2574
  usernamePlaceholder: "Enter your email or phone number",
@@ -2439,7 +2587,7 @@ const jt = () => fe.createElement(
2439
2587
  showPasswordAriaLabel: "Show password",
2440
2588
  hidePasswordAriaLabel: "Hide password"
2441
2589
  };
2442
- function $r({
2590
+ function Zr({
2443
2591
  copy: r = {},
2444
2592
  styles: e = {},
2445
2593
  icons: t = {},
@@ -2449,28 +2597,28 @@ function $r({
2449
2597
  onSignupClick: l,
2450
2598
  onMagicLinkClick: d,
2451
2599
  showForgotPassword: T = !0,
2452
- showSignupLink: P = !0,
2600
+ showSignupLink: A = !0,
2453
2601
  showMagicLinkOption: c = !0,
2454
- className: k
2602
+ className: S
2455
2603
  }) {
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({
2604
+ const [h, x] = N(""), [P, I] = N(""), [R, k] = N(!1), { login: m } = de(), g = { ...ar, ...r }, b = Le("#3b82f6", e), C = { ...or, ...t }, o = we({
2457
2605
  defaultErrorMessage: g.errorMessage,
2458
2606
  validate: () => {
2459
2607
  const u = [];
2460
- return h.trim() || u.push("username"), R.trim() || u.push("password"), u.forEach((v) => o.setFieldError(v, !0)), u.length === 0;
2608
+ return h.trim() || u.push("username"), P.trim() || u.push("password"), u.forEach((v) => o.setFieldError(v, !0)), u.length === 0;
2461
2609
  },
2462
- submit: () => m({ username: h, password: R }),
2610
+ submit: () => m({ username: h, password: P }),
2463
2611
  onSuccess: n,
2464
2612
  onError: i
2465
2613
  }), p = (u) => ({
2466
2614
  ...b.input,
2467
2615
  ...o.fieldErrors[u] ? b.inputError : {}
2468
- }), x = !h || !R || o.loading, y = {
2616
+ }), E = !h || !P || o.loading, y = {
2469
2617
  ...b.button,
2470
2618
  ...o.loading ? b.buttonLoading : {},
2471
- ...x ? b.buttonDisabled : {}
2619
+ ...E ? b.buttonDisabled : {}
2472
2620
  };
2473
- return /* @__PURE__ */ f("div", { className: k, style: b.container, children: [
2621
+ return /* @__PURE__ */ f("div", { className: S, style: b.container, children: [
2474
2622
  /* @__PURE__ */ s("h2", { style: b.title, children: g.title }),
2475
2623
  /* @__PURE__ */ f("form", { onSubmit: o.handleSubmit, style: b.form, children: [
2476
2624
  /* @__PURE__ */ f("div", { style: b.fieldGroup, children: [
@@ -2483,7 +2631,7 @@ function $r({
2483
2631
  type: "text",
2484
2632
  value: h,
2485
2633
  onChange: (u) => {
2486
- E(u.target.value), o.clearFieldError("username");
2634
+ x(u.target.value), o.clearFieldError("username");
2487
2635
  },
2488
2636
  placeholder: g.usernamePlaceholder,
2489
2637
  style: p("username"),
@@ -2499,8 +2647,8 @@ function $r({
2499
2647
  {
2500
2648
  id: "password",
2501
2649
  name: "password",
2502
- type: A ? "text" : "password",
2503
- value: R,
2650
+ type: R ? "text" : "password",
2651
+ value: P,
2504
2652
  onChange: (u) => {
2505
2653
  I(u.target.value), o.clearFieldError("password");
2506
2654
  },
@@ -2513,19 +2661,19 @@ function $r({
2513
2661
  "button",
2514
2662
  {
2515
2663
  type: "button",
2516
- onClick: () => S(!A),
2664
+ onClick: () => k(!R),
2517
2665
  style: b.passwordToggle,
2518
2666
  disabled: o.loading,
2519
- "aria-label": A ? g.hidePasswordAriaLabel : g.showPasswordAriaLabel,
2520
- children: A ? D.hidePassword : D.showPassword
2667
+ "aria-label": R ? g.hidePasswordAriaLabel : g.showPasswordAriaLabel,
2668
+ children: R ? C.hidePassword : C.showPassword
2521
2669
  }
2522
2670
  )
2523
2671
  ] })
2524
2672
  ] }),
2525
- /* @__PURE__ */ s("button", { type: "submit", disabled: x, style: y, children: o.loading ? g.loadingText : g.submitButton }),
2673
+ /* @__PURE__ */ s("button", { type: "submit", disabled: E, style: y, children: o.loading ? g.loadingText : g.submitButton }),
2526
2674
  o.error && /* @__PURE__ */ s("div", { style: b.errorText, children: o.error })
2527
2675
  ] }),
2528
- (T || P || c) && /* @__PURE__ */ f("div", { style: b.linkContainer, children: [
2676
+ (T || A || c) && /* @__PURE__ */ f("div", { style: b.linkContainer, children: [
2529
2677
  c && /* @__PURE__ */ f("div", { children: [
2530
2678
  /* @__PURE__ */ f("span", { style: b.divider, children: [
2531
2679
  g.magicLinkText,
@@ -2533,10 +2681,10 @@ function $r({
2533
2681
  ] }),
2534
2682
  /* @__PURE__ */ s("a", { onClick: d, style: b.link, children: g.magicLinkLink })
2535
2683
  ] }),
2536
- c && (T || P) && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2684
+ c && (T || A) && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2537
2685
  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: [
2686
+ T && A && /* @__PURE__ */ s("div", { style: b.divider, children: g.dividerBullet }),
2687
+ A && /* @__PURE__ */ f("div", { children: [
2540
2688
  /* @__PURE__ */ f("span", { style: b.divider, children: [
2541
2689
  g.signupText,
2542
2690
  " "
@@ -2546,7 +2694,7 @@ function $r({
2546
2694
  ] })
2547
2695
  ] });
2548
2696
  }
2549
- const Qt = {
2697
+ const lr = {
2550
2698
  title: "Create Account",
2551
2699
  nameLabel: "First Name",
2552
2700
  namePlaceholder: "Enter your first name",
@@ -2576,7 +2724,7 @@ const Qt = {
2576
2724
  tenantNotFoundError: "Tenant not found",
2577
2725
  dividerBullet: "•"
2578
2726
  };
2579
- function Mr({
2727
+ function Kr({
2580
2728
  copy: r = {},
2581
2729
  styles: e = {},
2582
2730
  signupType: t = "user",
@@ -2586,25 +2734,25 @@ function Mr({
2586
2734
  onMagicLinkClick: l,
2587
2735
  showLoginLink: d = !0,
2588
2736
  showMagicLinkOption: T = !0,
2589
- className: P
2737
+ className: A
2590
2738
  }) {
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({
2739
+ var U;
2740
+ const [c, S] = N(""), [h, x] = N(""), [P, I] = N(""), [R, 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 || !!R) && !!m && !!b && (t === "user" || !!o), F = we({
2593
2741
  defaultErrorMessage: v.errorMessage,
2594
2742
  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;
2743
+ const L = [];
2744
+ return c.trim() || L.push("name"), !P.trim() && !R.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
2745
  },
2598
2746
  submit: async () => t === "tenant" ? y({
2599
- email: R || void 0,
2600
- phoneNumber: A || void 0,
2747
+ email: P || void 0,
2748
+ phoneNumber: R || void 0,
2601
2749
  name: c,
2602
2750
  password: m,
2603
2751
  tenantName: o,
2604
2752
  lastName: h || void 0
2605
- }) : x({
2606
- email: R || void 0,
2607
- phoneNumber: A || void 0,
2753
+ }) : E({
2754
+ email: P || void 0,
2755
+ phoneNumber: R || void 0,
2608
2756
  name: c,
2609
2757
  password: m,
2610
2758
  tenantId: u.id,
@@ -2612,21 +2760,21 @@ function Mr({
2612
2760
  }),
2613
2761
  onSuccess: n,
2614
2762
  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 : {}
2763
+ }), H = (L) => ({
2764
+ ...D.input,
2765
+ ...F.fieldErrors[L] ? D.inputError : {}
2766
+ }), j = !se || F.loading, Z = {
2767
+ ...D.button,
2768
+ ...F.loading ? D.buttonLoading : {},
2769
+ ...j ? D.buttonDisabled : {}
2622
2770
  }, $ = () => {
2623
- L.clearFieldError("email"), L.clearFieldError("phoneNumber");
2771
+ F.clearFieldError("email"), F.clearFieldError("phoneNumber");
2624
2772
  };
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 }),
2773
+ return /* @__PURE__ */ f("div", { className: A, style: D.container, children: [
2774
+ /* @__PURE__ */ s("h2", { style: D.title, children: v.title }),
2775
+ /* @__PURE__ */ f("form", { onSubmit: F.handleSubmit, style: D.form, children: [
2776
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2777
+ /* @__PURE__ */ s("label", { style: D.label, children: v.nameLabel }),
2630
2778
  /* @__PURE__ */ s(
2631
2779
  "input",
2632
2780
  {
@@ -2634,17 +2782,17 @@ function Mr({
2634
2782
  name: "name",
2635
2783
  type: "text",
2636
2784
  value: c,
2637
- onChange: (F) => {
2638
- k(F.target.value), L.clearFieldError("name");
2785
+ onChange: (L) => {
2786
+ S(L.target.value), F.clearFieldError("name");
2639
2787
  },
2640
2788
  placeholder: v.namePlaceholder,
2641
2789
  style: H("name"),
2642
- disabled: L.loading
2790
+ disabled: F.loading
2643
2791
  }
2644
2792
  )
2645
2793
  ] }),
2646
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2647
- /* @__PURE__ */ s("label", { style: C.label, children: v.lastNameLabel }),
2794
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2795
+ /* @__PURE__ */ s("label", { style: D.label, children: v.lastNameLabel }),
2648
2796
  /* @__PURE__ */ s(
2649
2797
  "input",
2650
2798
  {
@@ -2652,52 +2800,52 @@ function Mr({
2652
2800
  name: "lastName",
2653
2801
  type: "text",
2654
2802
  value: h,
2655
- onChange: (F) => E(F.target.value),
2803
+ onChange: (L) => x(L.target.value),
2656
2804
  placeholder: v.lastNamePlaceholder,
2657
- style: C.input,
2658
- disabled: L.loading
2805
+ style: D.input,
2806
+ disabled: F.loading
2659
2807
  }
2660
2808
  )
2661
2809
  ] }),
2662
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2663
- /* @__PURE__ */ s("label", { style: C.label, children: v.emailLabel }),
2810
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2811
+ /* @__PURE__ */ s("label", { style: D.label, children: v.emailLabel }),
2664
2812
  /* @__PURE__ */ s(
2665
2813
  "input",
2666
2814
  {
2667
2815
  id: "email",
2668
2816
  name: "email",
2669
2817
  type: "email",
2670
- value: R,
2671
- onChange: (F) => {
2672
- I(F.target.value), $();
2818
+ value: P,
2819
+ onChange: (L) => {
2820
+ I(L.target.value), $();
2673
2821
  },
2674
2822
  placeholder: v.emailPlaceholder,
2675
2823
  style: H("email"),
2676
- disabled: L.loading
2824
+ disabled: F.loading
2677
2825
  }
2678
2826
  )
2679
2827
  ] }),
2680
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2681
- /* @__PURE__ */ s("label", { style: C.label, children: v.phoneNumberLabel }),
2828
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2829
+ /* @__PURE__ */ s("label", { style: D.label, children: v.phoneNumberLabel }),
2682
2830
  /* @__PURE__ */ s(
2683
2831
  "input",
2684
2832
  {
2685
2833
  id: "phoneNumber",
2686
2834
  name: "phoneNumber",
2687
2835
  type: "tel",
2688
- value: A,
2689
- onChange: (F) => {
2690
- S(F.target.value), $();
2836
+ value: R,
2837
+ onChange: (L) => {
2838
+ k(L.target.value), $();
2691
2839
  },
2692
2840
  placeholder: v.phoneNumberPlaceholder,
2693
2841
  style: H("phoneNumber"),
2694
- disabled: L.loading
2842
+ disabled: F.loading
2695
2843
  }
2696
2844
  )
2697
2845
  ] }),
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 }),
2846
+ /* @__PURE__ */ s("div", { style: D.hintText, children: v.contactMethodHint }),
2847
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2848
+ /* @__PURE__ */ s("label", { style: D.label, children: v.passwordLabel }),
2701
2849
  /* @__PURE__ */ s(
2702
2850
  "input",
2703
2851
  {
@@ -2705,17 +2853,17 @@ function Mr({
2705
2853
  name: "password",
2706
2854
  type: "password",
2707
2855
  value: m,
2708
- onChange: (F) => {
2709
- g(F.target.value), L.clearFieldError("password");
2856
+ onChange: (L) => {
2857
+ g(L.target.value), F.clearFieldError("password");
2710
2858
  },
2711
2859
  placeholder: v.passwordPlaceholder,
2712
2860
  style: H("password"),
2713
- disabled: L.loading
2861
+ disabled: F.loading
2714
2862
  }
2715
2863
  )
2716
2864
  ] }),
2717
- /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2718
- /* @__PURE__ */ s("label", { style: C.label, children: v.confirmPasswordLabel }),
2865
+ /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2866
+ /* @__PURE__ */ s("label", { style: D.label, children: v.confirmPasswordLabel }),
2719
2867
  /* @__PURE__ */ s(
2720
2868
  "input",
2721
2869
  {
@@ -2723,17 +2871,17 @@ function Mr({
2723
2871
  name: "confirmPassword",
2724
2872
  type: "password",
2725
2873
  value: b,
2726
- onChange: (F) => {
2727
- D(F.target.value), L.clearFieldError("confirmPassword"), L.error === v.passwordMismatchError && L.setError("");
2874
+ onChange: (L) => {
2875
+ C(L.target.value), F.clearFieldError("confirmPassword"), F.error === v.passwordMismatchError && F.setError("");
2728
2876
  },
2729
2877
  placeholder: v.confirmPasswordPlaceholder,
2730
2878
  style: H("confirmPassword"),
2731
- disabled: L.loading
2879
+ disabled: F.loading
2732
2880
  }
2733
2881
  )
2734
2882
  ] }),
2735
- t === "tenant" && /* @__PURE__ */ f("div", { style: C.fieldGroup, children: [
2736
- /* @__PURE__ */ s("label", { style: C.label, children: v.tenantNameLabel }),
2883
+ t === "tenant" && /* @__PURE__ */ f("div", { style: D.fieldGroup, children: [
2884
+ /* @__PURE__ */ s("label", { style: D.label, children: v.tenantNameLabel }),
2737
2885
  /* @__PURE__ */ s(
2738
2886
  "input",
2739
2887
  {
@@ -2741,38 +2889,38 @@ function Mr({
2741
2889
  name: "tenantName",
2742
2890
  type: "text",
2743
2891
  value: o,
2744
- onChange: (F) => {
2745
- p(F.target.value), L.clearFieldError("tenantName");
2892
+ onChange: (L) => {
2893
+ p(L.target.value), F.clearFieldError("tenantName");
2746
2894
  },
2747
2895
  placeholder: v.tenantNamePlaceholder,
2748
2896
  style: H("tenantName"),
2749
- disabled: L.loading
2897
+ disabled: F.loading
2750
2898
  }
2751
2899
  )
2752
2900
  ] }),
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 })
2901
+ /* @__PURE__ */ s("button", { type: "submit", disabled: j, style: Z, children: F.loading ? v.loadingText : v.submitButton }),
2902
+ F.error && /* @__PURE__ */ s("div", { style: D.errorText, children: F.error })
2755
2903
  ] }),
2756
- (d || T) && /* @__PURE__ */ f("div", { style: C.linkContainer, children: [
2904
+ (d || T) && /* @__PURE__ */ f("div", { style: D.linkContainer, children: [
2757
2905
  T && /* @__PURE__ */ f("div", { children: [
2758
- /* @__PURE__ */ f("span", { style: C.divider, children: [
2906
+ /* @__PURE__ */ f("span", { style: D.divider, children: [
2759
2907
  v.magicLinkText,
2760
2908
  " "
2761
2909
  ] }),
2762
- /* @__PURE__ */ s("a", { onClick: l, style: C.link, children: v.magicLinkLink })
2910
+ /* @__PURE__ */ s("a", { onClick: l, style: D.link, children: v.magicLinkLink })
2763
2911
  ] }),
2764
- T && d && /* @__PURE__ */ s("div", { style: C.divider, children: v.dividerBullet }),
2912
+ T && d && /* @__PURE__ */ s("div", { style: D.divider, children: v.dividerBullet }),
2765
2913
  d && /* @__PURE__ */ f("div", { children: [
2766
- /* @__PURE__ */ f("span", { style: C.divider, children: [
2914
+ /* @__PURE__ */ f("span", { style: D.divider, children: [
2767
2915
  v.loginText,
2768
2916
  " "
2769
2917
  ] }),
2770
- /* @__PURE__ */ s("a", { onClick: a, style: C.link, children: v.loginLink })
2918
+ /* @__PURE__ */ s("a", { onClick: a, style: D.link, children: v.loginLink })
2771
2919
  ] })
2772
2920
  ] })
2773
2921
  ] });
2774
2922
  }
2775
- const Jt = {
2923
+ const cr = {
2776
2924
  title: "Sign In with Magic Link",
2777
2925
  emailLabel: "Email",
2778
2926
  emailPlaceholder: "Enter your email",
@@ -2797,7 +2945,7 @@ const Jt = {
2797
2945
  missingTenantOrEmailError: "Missing tenant or email",
2798
2946
  dividerBullet: "•"
2799
2947
  };
2800
- function Br({
2948
+ function Yr({
2801
2949
  copy: r = {},
2802
2950
  styles: e = {},
2803
2951
  onSuccess: t,
@@ -2807,37 +2955,37 @@ function Br({
2807
2955
  showTraditionalLinks: l = !0,
2808
2956
  className: d,
2809
2957
  verifyToken: T,
2810
- frontendUrl: P
2958
+ frontendUrl: A
2811
2959
  }) {
2812
2960
  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({
2961
+ const [c, S] = N(""), [h, x] = N(""), [P, I] = N(""), [R, 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
2962
  defaultErrorMessage: y.errorMessage,
2815
2963
  validate: () => {
2816
2964
  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);
2965
+ 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
2966
  },
2819
2967
  submit: async () => {
2820
2968
  g("");
2821
- const j = P || (typeof window < "u" ? window.location.origin : ""), Z = await o({
2969
+ const j = A || (typeof window < "u" ? window.location.origin : ""), Z = await o({
2822
2970
  email: c,
2823
- tenantId: x.id,
2971
+ tenantId: E.id,
2824
2972
  frontendUrl: j,
2825
2973
  name: b ? h : void 0,
2826
- lastName: b ? R : void 0
2974
+ lastName: b ? P : void 0
2827
2975
  });
2828
2976
  return g(y.successMessage), Z;
2829
2977
  },
2830
2978
  onSuccess: t,
2831
2979
  onError: n
2832
2980
  });
2833
- ne(() => {
2981
+ re(() => {
2834
2982
  if (!T) return;
2835
2983
  (async () => {
2836
- if (!x || !c) {
2984
+ if (!E || !c) {
2837
2985
  v.setError(y.missingTenantOrEmailError);
2838
2986
  return;
2839
2987
  }
2840
- S(!0), v.setError("");
2988
+ k(!0), v.setError("");
2841
2989
  try {
2842
2990
  const Z = await p({ token: T, email: c });
2843
2991
  t == null || t(Z);
@@ -2845,19 +2993,19 @@ function Br({
2845
2993
  const $ = Z instanceof Error ? Z.message : "Failed to verify magic link";
2846
2994
  v.setError($), n == null || n($);
2847
2995
  } finally {
2848
- S(!1);
2996
+ k(!1);
2849
2997
  }
2850
2998
  })();
2851
2999
  }, [T]);
2852
- const C = (j) => ({
3000
+ const D = (j) => ({
2853
3001
  ...u.input,
2854
3002
  ...v.fieldErrors[j] ? u.inputError : {}
2855
- }), ie = !c || v.loading || A, L = {
3003
+ }), se = !c || v.loading || R, F = {
2856
3004
  ...u.button,
2857
- ...v.loading || A ? u.buttonLoading : {},
2858
- ...ie ? u.buttonDisabled : {}
3005
+ ...v.loading || R ? u.buttonLoading : {},
3006
+ ...se ? u.buttonDisabled : {}
2859
3007
  };
2860
- return A ? /* @__PURE__ */ f("div", { className: d, style: u.container, children: [
3008
+ return R ? /* @__PURE__ */ f("div", { className: d, style: u.container, children: [
2861
3009
  /* @__PURE__ */ s("h2", { style: u.title, children: y.verifyingText }),
2862
3010
  /* @__PURE__ */ s("div", { style: u.verifyingContainer, children: /* @__PURE__ */ s("div", { style: u.verifyingText, children: y.verifyingDescription }) })
2863
3011
  ] }) : /* @__PURE__ */ f("div", { className: d, style: u.container, children: [
@@ -2874,11 +3022,11 @@ function Br({
2874
3022
  type: "email",
2875
3023
  value: c,
2876
3024
  onChange: (j) => {
2877
- k(j.target.value), v.clearFieldError("email");
3025
+ S(j.target.value), v.clearFieldError("email");
2878
3026
  },
2879
3027
  placeholder: y.emailPlaceholder,
2880
- style: C("email"),
2881
- disabled: v.loading || A
3028
+ style: D("email"),
3029
+ disabled: v.loading || R
2882
3030
  }
2883
3031
  )
2884
3032
  ] }),
@@ -2886,7 +3034,7 @@ function Br({
2886
3034
  "button",
2887
3035
  {
2888
3036
  type: "button",
2889
- onClick: () => D(!0),
3037
+ onClick: () => C(!0),
2890
3038
  style: u.toggleLink,
2891
3039
  children: y.showNameToggle
2892
3040
  }
@@ -2902,11 +3050,11 @@ function Br({
2902
3050
  type: "text",
2903
3051
  value: h,
2904
3052
  onChange: (j) => {
2905
- E(j.target.value), v.clearFieldError("name");
3053
+ x(j.target.value), v.clearFieldError("name");
2906
3054
  },
2907
3055
  placeholder: y.namePlaceholder,
2908
- style: C("name"),
2909
- disabled: v.loading || A
3056
+ style: D("name"),
3057
+ disabled: v.loading || R
2910
3058
  }
2911
3059
  )
2912
3060
  ] }),
@@ -2918,11 +3066,11 @@ function Br({
2918
3066
  id: "lastName",
2919
3067
  name: "lastName",
2920
3068
  type: "text",
2921
- value: R,
3069
+ value: P,
2922
3070
  onChange: (j) => I(j.target.value),
2923
3071
  placeholder: y.lastNamePlaceholder,
2924
3072
  style: u.input,
2925
- disabled: v.loading || A
3073
+ disabled: v.loading || R
2926
3074
  }
2927
3075
  )
2928
3076
  ] }),
@@ -2931,14 +3079,14 @@ function Br({
2931
3079
  {
2932
3080
  type: "button",
2933
3081
  onClick: () => {
2934
- D(!1), E(""), I("");
3082
+ C(!1), x(""), I("");
2935
3083
  },
2936
3084
  style: u.toggleLink,
2937
3085
  children: y.hideNameToggle
2938
3086
  }
2939
3087
  ) })
2940
3088
  ] }),
2941
- /* @__PURE__ */ s("button", { type: "submit", disabled: ie, style: L, children: v.loading ? y.loadingText : y.submitButton }),
3089
+ /* @__PURE__ */ s("button", { type: "submit", disabled: se, style: F, children: v.loading ? y.loadingText : y.submitButton }),
2942
3090
  v.error && /* @__PURE__ */ s("div", { style: u.errorText, children: v.error }),
2943
3091
  m && /* @__PURE__ */ s("div", { style: u.successText, children: m })
2944
3092
  ] }),
@@ -2961,7 +3109,7 @@ function Br({
2961
3109
  ] })
2962
3110
  ] });
2963
3111
  }
2964
- const Zt = {
3112
+ const ur = {
2965
3113
  title: "Verifying Magic Link",
2966
3114
  verifyingMessage: "Please wait while we verify your magic link...",
2967
3115
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2970,7 +3118,7 @@ const Zt = {
2970
3118
  retryButton: "Try Again",
2971
3119
  backToLoginButton: "Back to Login",
2972
3120
  missingParamsError: "Missing required parameters: token or email"
2973
- }, st = {
3121
+ }, ut = {
2974
3122
  container: {
2975
3123
  maxWidth: "400px",
2976
3124
  width: "100%",
@@ -3063,7 +3211,7 @@ const Zt = {
3063
3211
  backButtonHover: {
3064
3212
  backgroundColor: "#e5e7eb"
3065
3213
  }
3066
- }, Kt = () => /* @__PURE__ */ s("div", { style: st.spinner }), Yt = () => /* @__PURE__ */ f(
3214
+ }, dr = () => /* @__PURE__ */ s("div", { style: ut.spinner }), hr = () => /* @__PURE__ */ f(
3067
3215
  "svg",
3068
3216
  {
3069
3217
  width: "48",
@@ -3080,7 +3228,7 @@ const Zt = {
3080
3228
  /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3081
3229
  ]
3082
3230
  }
3083
- ), Xt = () => /* @__PURE__ */ f(
3231
+ ), pr = () => /* @__PURE__ */ f(
3084
3232
  "svg",
3085
3233
  {
3086
3234
  width: "48",
@@ -3098,12 +3246,12 @@ const Zt = {
3098
3246
  /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3099
3247
  ]
3100
3248
  }
3101
- ), er = {
3102
- loading: /* @__PURE__ */ s(Kt, {}),
3103
- success: /* @__PURE__ */ s(Yt, {}),
3104
- error: /* @__PURE__ */ s(Xt, {})
3249
+ ), fr = {
3250
+ loading: /* @__PURE__ */ s(dr, {}),
3251
+ success: /* @__PURE__ */ s(hr, {}),
3252
+ error: /* @__PURE__ */ s(pr, {})
3105
3253
  };
3106
- function Or({
3254
+ function Xr({
3107
3255
  copy: r = {},
3108
3256
  styles: e = {},
3109
3257
  icons: t = {},
@@ -3113,48 +3261,48 @@ function Or({
3113
3261
  onBackToLogin: l,
3114
3262
  className: d,
3115
3263
  token: T,
3116
- email: P,
3264
+ email: A,
3117
3265
  appId: c,
3118
- tenantSlug: k,
3266
+ tenantSlug: S,
3119
3267
  autoRedirectDelay: h = 3e3
3120
3268
  }) {
3121
- const [E, R] = N("verifying"), [I, A] = N(""), { verifyMagicLink: S } = ue(), m = { ...Zt, ...r }, g = { ...st, ...e }, b = { ...er, ...t }, D = () => {
3269
+ const [x, P] = N("verifying"), [I, R] = N(""), { verifyMagicLink: k } = de(), m = { ...ur, ...r }, g = { ...ut, ...e }, b = { ...fr, ...t }, C = () => {
3122
3270
  if (typeof window > "u") return {};
3123
3271
  const u = new URLSearchParams(window.location.search);
3124
3272
  return {
3125
3273
  token: T || u.get("token") || "",
3126
- email: P || u.get("email") || "",
3274
+ email: A || u.get("email") || "",
3127
3275
  appId: c || u.get("appId") || "",
3128
- tenantSlug: k || u.get("tenantSlug") || void 0
3276
+ tenantSlug: S || u.get("tenantSlug") || void 0
3129
3277
  };
3130
3278
  }, o = async () => {
3131
- R("verifying"), A("");
3279
+ P("verifying"), R("");
3132
3280
  try {
3133
- const u = D();
3281
+ const u = C();
3134
3282
  if (!u.token || !u.email)
3135
3283
  throw new Error(m.missingParamsError);
3136
- const v = await S({
3284
+ const v = await k({
3137
3285
  token: u.token,
3138
3286
  email: u.email,
3139
3287
  tenantSlug: u.tenantSlug
3140
3288
  });
3141
- R("success"), n == null || n(v), h > 0 && setTimeout(() => {
3142
- R("redirecting");
3289
+ P("success"), n == null || n(v), h > 0 && setTimeout(() => {
3290
+ P("redirecting");
3143
3291
  }, h);
3144
3292
  } catch (u) {
3145
3293
  const v = u.message || m.errorMessage;
3146
- A(v), R("error"), i == null || i(v);
3294
+ R(v), P("error"), i == null || i(v);
3147
3295
  }
3148
3296
  }, p = () => {
3149
3297
  a == null || a(), o();
3150
- }, x = () => {
3298
+ }, E = () => {
3151
3299
  l == null || l();
3152
3300
  };
3153
- ne(() => {
3301
+ re(() => {
3154
3302
  o();
3155
3303
  }, []);
3156
3304
  const y = () => {
3157
- switch (E) {
3305
+ switch (x) {
3158
3306
  case "verifying":
3159
3307
  return /* @__PURE__ */ f("div", { style: g.message, children: [
3160
3308
  b.loading,
@@ -3185,8 +3333,8 @@ function Or({
3185
3333
  },
3186
3334
  onMouseOut: (u) => {
3187
3335
  const v = g.retryButton || {};
3188
- Object.keys(g.retryButtonHover || {}).forEach((C) => {
3189
- u.currentTarget.style[C] = v[C] ?? "";
3336
+ Object.keys(g.retryButtonHover || {}).forEach((D) => {
3337
+ u.currentTarget.style[D] = v[D] ?? "";
3190
3338
  });
3191
3339
  },
3192
3340
  children: m.retryButton
@@ -3195,15 +3343,15 @@ function Or({
3195
3343
  /* @__PURE__ */ s(
3196
3344
  "button",
3197
3345
  {
3198
- onClick: x,
3346
+ onClick: E,
3199
3347
  style: g.backButton,
3200
3348
  onMouseOver: (u) => {
3201
3349
  Object.assign(u.currentTarget.style, g.backButtonHover);
3202
3350
  },
3203
3351
  onMouseOut: (u) => {
3204
3352
  const v = g.backButton || {};
3205
- Object.keys(g.backButtonHover || {}).forEach((C) => {
3206
- u.currentTarget.style[C] = v[C] ?? "";
3353
+ Object.keys(g.backButtonHover || {}).forEach((D) => {
3354
+ u.currentTarget.style[D] = v[D] ?? "";
3207
3355
  });
3208
3356
  },
3209
3357
  children: m.backToLoginButton
@@ -3226,7 +3374,7 @@ function Or({
3226
3374
  y()
3227
3375
  ] });
3228
3376
  }
3229
- const tr = {
3377
+ const mr = {
3230
3378
  title: "Reset Password",
3231
3379
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3232
3380
  emailLabel: "Email",
@@ -3253,7 +3401,7 @@ const tr = {
3253
3401
  tenantNotFoundError: "Tenant not found",
3254
3402
  dividerBullet: "•"
3255
3403
  };
3256
- function _r({
3404
+ function en({
3257
3405
  copy: r = {},
3258
3406
  styles: e = {},
3259
3407
  mode: t = "request",
@@ -3264,32 +3412,32 @@ function _r({
3264
3412
  onModeChange: d,
3265
3413
  className: T
3266
3414
  }) {
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({
3415
+ var se;
3416
+ const [A, c] = N(""), [S, h] = N(n), [x, P] = N(""), [I, R] = 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
3417
  defaultErrorMessage: o.errorMessage,
3270
- validate: () => P.trim() ? D != null && D.id ? !0 : (x.setError(o.tenantNotFoundError), !1) : (x.setFieldError("email", !0), !1),
3418
+ validate: () => A.trim() ? C != null && C.id ? !0 : (E.setError(o.tenantNotFoundError), !1) : (E.setFieldError("email", !0), !1),
3271
3419
  submit: async () => {
3272
- m(""), await g({ email: P, tenantId: D.id }), m(o.successMessage);
3420
+ m(""), await g({ email: A, tenantId: C.id }), m(o.successMessage);
3273
3421
  },
3274
3422
  onSuccess: () => i == null ? void 0 : i(),
3275
3423
  onError: a
3276
- }), y = ye({
3424
+ }), y = we({
3277
3425
  defaultErrorMessage: o.errorMessage,
3278
3426
  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;
3427
+ const F = [];
3428
+ 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
3429
  },
3282
3430
  submit: async () => {
3283
- m(""), await b({ token: k, newPassword: E }), m(o.resetSuccessMessage);
3431
+ m(""), await b({ token: S, newPassword: x }), m(o.resetSuccessMessage);
3284
3432
  },
3285
3433
  onSuccess: () => i == null ? void 0 : i(),
3286
3434
  onError: a
3287
3435
  });
3288
3436
  if (t === "reset") {
3289
- const L = ($) => ({
3437
+ const F = ($) => ({
3290
3438
  ...p.input,
3291
3439
  ...y.fieldErrors[$] ? p.inputError : {}
3292
- }), j = !(!!k && !!E && !!I) || y.loading, Z = {
3440
+ }), j = !(!!S && !!x && !!I) || y.loading, Z = {
3293
3441
  ...p.button,
3294
3442
  ...y.loading ? p.buttonLoading : {},
3295
3443
  ...j ? p.buttonDisabled : {}
@@ -3304,12 +3452,12 @@ function _r({
3304
3452
  "input",
3305
3453
  {
3306
3454
  type: "text",
3307
- value: k,
3455
+ value: S,
3308
3456
  onChange: ($) => {
3309
3457
  h($.target.value), y.clearFieldError("token");
3310
3458
  },
3311
3459
  placeholder: o.tokenPlaceholder,
3312
- style: L("token"),
3460
+ style: F("token"),
3313
3461
  disabled: y.loading
3314
3462
  }
3315
3463
  )
@@ -3320,12 +3468,12 @@ function _r({
3320
3468
  "input",
3321
3469
  {
3322
3470
  type: "password",
3323
- value: E,
3471
+ value: x,
3324
3472
  onChange: ($) => {
3325
- R($.target.value), y.clearFieldError("newPassword");
3473
+ P($.target.value), y.clearFieldError("newPassword");
3326
3474
  },
3327
3475
  placeholder: o.newPasswordPlaceholder,
3328
- style: L("newPassword"),
3476
+ style: F("newPassword"),
3329
3477
  disabled: y.loading
3330
3478
  }
3331
3479
  )
@@ -3338,17 +3486,17 @@ function _r({
3338
3486
  type: "password",
3339
3487
  value: I,
3340
3488
  onChange: ($) => {
3341
- A($.target.value), y.clearFieldError("confirmPassword"), y.error === o.passwordMismatchError && y.setError("");
3489
+ R($.target.value), y.clearFieldError("confirmPassword"), y.error === o.passwordMismatchError && y.setError("");
3342
3490
  },
3343
3491
  placeholder: o.confirmPasswordPlaceholder,
3344
- style: L("confirmPassword"),
3492
+ style: F("confirmPassword"),
3345
3493
  disabled: y.loading
3346
3494
  }
3347
3495
  )
3348
3496
  ] }),
3349
3497
  /* @__PURE__ */ s("button", { type: "submit", disabled: j, style: Z, children: y.loading ? o.resetLoadingText : o.resetSubmitButton }),
3350
3498
  y.error && /* @__PURE__ */ s("div", { style: p.errorText, children: y.error }),
3351
- S && /* @__PURE__ */ s("div", { style: p.successText, children: S })
3499
+ k && /* @__PURE__ */ s("div", { style: p.successText, children: k })
3352
3500
  ] }),
3353
3501
  /* @__PURE__ */ f("div", { style: p.linkContainer, children: [
3354
3502
  /* @__PURE__ */ s("a", { onClick: l, style: p.link, children: o.backToLoginLink }),
@@ -3359,37 +3507,37 @@ function _r({
3359
3507
  ] })
3360
3508
  ] });
3361
3509
  }
3362
- const u = (L) => ({
3510
+ const u = (F) => ({
3363
3511
  ...p.input,
3364
- ...x.fieldErrors[L] ? p.inputError : {}
3365
- }), v = !P || x.loading, C = {
3512
+ ...E.fieldErrors[F] ? p.inputError : {}
3513
+ }), v = !A || E.loading, D = {
3366
3514
  ...p.button,
3367
- ...x.loading ? p.buttonLoading : {},
3515
+ ...E.loading ? p.buttonLoading : {},
3368
3516
  ...v ? p.buttonDisabled : {}
3369
3517
  };
3370
3518
  return /* @__PURE__ */ f("div", { className: T, style: p.container, children: [
3371
3519
  /* @__PURE__ */ s("h2", { style: p.title, children: o.title }),
3372
3520
  /* @__PURE__ */ s("p", { style: p.subtitle, children: o.subtitle }),
3373
- /* @__PURE__ */ f("form", { onSubmit: x.handleSubmit, style: p.form, children: [
3521
+ /* @__PURE__ */ f("form", { onSubmit: E.handleSubmit, style: p.form, children: [
3374
3522
  /* @__PURE__ */ f("div", { style: p.fieldGroup, children: [
3375
3523
  /* @__PURE__ */ s("label", { style: p.label, children: o.emailLabel }),
3376
3524
  /* @__PURE__ */ s(
3377
3525
  "input",
3378
3526
  {
3379
3527
  type: "email",
3380
- value: P,
3381
- onChange: (L) => {
3382
- c(L.target.value), x.clearFieldError("email");
3528
+ value: A,
3529
+ onChange: (F) => {
3530
+ c(F.target.value), E.clearFieldError("email");
3383
3531
  },
3384
3532
  placeholder: o.emailPlaceholder,
3385
3533
  style: u("email"),
3386
- disabled: x.loading
3534
+ disabled: E.loading
3387
3535
  }
3388
3536
  )
3389
3537
  ] }),
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 })
3538
+ /* @__PURE__ */ s("button", { type: "submit", disabled: v, style: D, children: E.loading ? o.loadingText : o.submitButton }),
3539
+ E.error && /* @__PURE__ */ s("div", { style: p.errorText, children: E.error }),
3540
+ k && /* @__PURE__ */ s("div", { style: p.successText, children: k })
3393
3541
  ] }),
3394
3542
  /* @__PURE__ */ f("div", { style: p.linkContainer, children: [
3395
3543
  /* @__PURE__ */ s("a", { onClick: l, style: p.link, children: o.backToLoginLink }),
@@ -3400,7 +3548,7 @@ function _r({
3400
3548
  ] })
3401
3549
  ] });
3402
3550
  }
3403
- const rr = () => /* @__PURE__ */ s(
3551
+ const gr = () => /* @__PURE__ */ s(
3404
3552
  "div",
3405
3553
  {
3406
3554
  style: {
@@ -3412,7 +3560,7 @@ const rr = () => /* @__PURE__ */ s(
3412
3560
  },
3413
3561
  children: /* @__PURE__ */ s("div", { children: "Loading..." })
3414
3562
  }
3415
- ), nr = ({ error: r, retry: e }) => /* @__PURE__ */ f(
3563
+ ), yr = ({ error: r, retry: e }) => /* @__PURE__ */ f(
3416
3564
  "div",
3417
3565
  {
3418
3566
  style: {
@@ -3446,43 +3594,43 @@ const rr = () => /* @__PURE__ */ s(
3446
3594
  ]
3447
3595
  }
3448
3596
  );
3449
- function qr({
3597
+ function tn({
3450
3598
  children: r,
3451
3599
  loadingFallback: e,
3452
3600
  errorFallback: t,
3453
3601
  requireTenant: n = !0
3454
3602
  }) {
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();
3603
+ const { isAppLoading: i, appError: a, retryApp: l } = Ae(), d = pe(), T = Oe(), A = 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) ?? (() => {
3604
+ }), I = (T == null ? void 0 : T.isAuthReady) ?? !0, R = (A == null ? void 0 : A.isReady) ?? !0, k = (c == null ? void 0 : c.isReady) ?? !0, m = n && d && x, o = i || m && S || T && !I || A && !R || c && !k, p = a || (m ? h : null), E = () => {
3605
+ a && l(), h && d && P();
3458
3606
  };
3459
3607
  if (o)
3460
- return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(rr, {}) });
3608
+ return /* @__PURE__ */ s(B, { children: e || /* @__PURE__ */ s(gr, {}) });
3461
3609
  if (p) {
3462
- const y = typeof t == "function" ? t(p, x) : t || /* @__PURE__ */ s(nr, { error: p, retry: x });
3610
+ const y = typeof t == "function" ? t(p, E) : t || /* @__PURE__ */ s(yr, { error: p, retry: E });
3463
3611
  return /* @__PURE__ */ s(B, { children: y });
3464
3612
  }
3465
3613
  return /* @__PURE__ */ s(B, { children: r });
3466
3614
  }
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);
3615
+ function rn(r = !0) {
3616
+ const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = Ae(), a = pe(), l = Oe(), d = at(), T = lt(), A = (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) ?? (() => {
3617
+ }), P = (l == null ? void 0 : l.isAuthReady) ?? !0, I = (d == null ? void 0 : d.isReady) ?? !0, R = (T == null ? void 0 : T.isReady) ?? !0, k = r && a && h, C = e || k && A || l && !P || d && !I || T && !R, o = t || (k ? c : null);
3470
3618
  return {
3471
- isLoading: D,
3619
+ isLoading: C,
3472
3620
  error: o,
3473
- isReady: !D && !o && i !== null && (!S || k !== null),
3621
+ isReady: !C && !o && i !== null && (!k || S !== null),
3474
3622
  retry: () => {
3475
- t && n(), c && a && E();
3623
+ t && n(), c && a && x();
3476
3624
  },
3477
3625
  // Individual states
3478
3626
  app: { isLoading: e, error: t, data: i },
3479
- tenant: a ? { isLoading: P, error: c, data: k } : null,
3480
- auth: l ? { isReady: R } : null,
3627
+ tenant: a ? { isLoading: A, error: c, data: S } : null,
3628
+ auth: l ? { isReady: P } : null,
3481
3629
  featureFlags: d ? { isReady: I } : null,
3482
- subscription: T ? { isReady: A } : null
3630
+ subscription: T ? { isReady: R } : null
3483
3631
  };
3484
3632
  }
3485
- const sr = {
3633
+ const br = {
3486
3634
  wrapper: {
3487
3635
  position: "relative"
3488
3636
  },
@@ -3526,7 +3674,7 @@ const sr = {
3526
3674
  marginLeft: 8
3527
3675
  }
3528
3676
  };
3529
- function zr({
3677
+ function nn({
3530
3678
  tenants: r,
3531
3679
  currentTenantId: e,
3532
3680
  onSelect: t,
@@ -3536,68 +3684,68 @@ function zr({
3536
3684
  itemClassName: l = "",
3537
3685
  renderItem: d,
3538
3686
  placeholder: T = "Select tenant",
3539
- disabled: P = !1,
3687
+ disabled: A = !1,
3540
3688
  showCurrentTenant: c = !0
3541
3689
  }) {
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);
3690
+ var C;
3691
+ const S = { ...br, ...n }, h = Oe(), [x, P] = N(!1), I = Ee(null), R = 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) => {
3692
+ P(!1), t ? t(o) : h != null && h.switchToTenant && await h.switchToTenant(o);
3545
3693
  };
3546
- ne(() => {
3694
+ re(() => {
3547
3695
  const o = (p) => {
3548
- I.current && !I.current.contains(p.target) && R(!1);
3696
+ I.current && !I.current.contains(p.target) && P(!1);
3549
3697
  };
3550
3698
  return document.addEventListener("mousedown", o), () => document.removeEventListener("mousedown", o);
3551
3699
  }, []);
3552
- const g = A.find((o) => o.id === S);
3553
- if (A.length === 0)
3700
+ const g = R.find((o) => o.id === k);
3701
+ if (R.length === 0)
3554
3702
  return null;
3555
- if (A.length === 1 && c)
3556
- return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: A[0].name }) });
3703
+ if (R.length === 1 && c)
3704
+ return /* @__PURE__ */ s("div", { className: i, children: /* @__PURE__ */ s("span", { children: R[0].name }) });
3557
3705
  const b = (o, p) => /* @__PURE__ */ f("span", { style: { fontWeight: p ? "bold" : "normal" }, children: [
3558
3706
  o.name,
3559
- o.role && /* @__PURE__ */ f("span", { style: k.itemRole, children: [
3707
+ o.role && /* @__PURE__ */ f("span", { style: S.itemRole, children: [
3560
3708
  "(",
3561
3709
  o.role,
3562
3710
  ")"
3563
3711
  ] })
3564
3712
  ] });
3565
- return /* @__PURE__ */ f("div", { ref: I, className: i, style: k.wrapper, children: [
3713
+ return /* @__PURE__ */ f("div", { ref: I, className: i, style: S.wrapper, children: [
3566
3714
  /* @__PURE__ */ f(
3567
3715
  "button",
3568
3716
  {
3569
3717
  type: "button",
3570
- onClick: () => !P && R(!E),
3571
- disabled: P,
3718
+ onClick: () => !A && P(!x),
3719
+ disabled: A,
3572
3720
  style: {
3573
- ...k.button,
3574
- ...P ? k.buttonDisabled : {}
3721
+ ...S.button,
3722
+ ...A ? S.buttonDisabled : {}
3575
3723
  },
3576
3724
  children: [
3577
3725
  g ? g.name : T,
3578
- /* @__PURE__ */ s("span", { style: k.arrow, children: E ? "▲" : "▼" })
3726
+ /* @__PURE__ */ s("span", { style: S.arrow, children: x ? "▲" : "▼" })
3579
3727
  ]
3580
3728
  }
3581
3729
  ),
3582
- E && /* @__PURE__ */ s("div", { className: a, style: k.dropdown, children: A.map((o) => {
3583
- const p = o.id === S;
3730
+ x && /* @__PURE__ */ s("div", { className: a, style: S.dropdown, children: R.map((o) => {
3731
+ const p = o.id === k;
3584
3732
  return /* @__PURE__ */ s(
3585
3733
  "div",
3586
3734
  {
3587
3735
  className: l,
3588
3736
  onClick: () => m(o.id),
3589
3737
  style: {
3590
- ...k.item,
3591
- ...p ? k.itemSelected : {}
3738
+ ...S.item,
3739
+ ...p ? S.itemSelected : {}
3592
3740
  },
3593
- onMouseEnter: (x) => {
3594
- p || Object.assign(x.currentTarget.style, k.itemHover);
3741
+ onMouseEnter: (E) => {
3742
+ p || Object.assign(E.currentTarget.style, S.itemHover);
3595
3743
  },
3596
- onMouseLeave: (x) => {
3744
+ onMouseLeave: (E) => {
3597
3745
  if (!p) {
3598
- const y = k.item || {};
3599
- Object.keys(k.itemHover || {}).forEach((u) => {
3600
- x.currentTarget.style[u] = y[u] ?? "";
3746
+ const y = S.item || {};
3747
+ Object.keys(S.itemHover || {}).forEach((u) => {
3748
+ E.currentTarget.style[u] = y[u] ?? "";
3601
3749
  });
3602
3750
  }
3603
3751
  },
@@ -3608,7 +3756,7 @@ function zr({
3608
3756
  }) })
3609
3757
  ] });
3610
3758
  }
3611
- class jr {
3759
+ class sn {
3612
3760
  constructor(e) {
3613
3761
  this.httpService = e;
3614
3762
  }
@@ -3617,7 +3765,7 @@ class jr {
3617
3765
  }
3618
3766
  async getPermissions(e) {
3619
3767
  const t = await this.httpService.get(
3620
- `/permissions/${le(e)}`
3768
+ `/permissions/${ce(e)}`
3621
3769
  );
3622
3770
  return { permissions: t.data, meta: t.meta };
3623
3771
  }
@@ -3635,13 +3783,13 @@ class jr {
3635
3783
  }
3636
3784
  async getAppPermissions(e, t) {
3637
3785
  const n = await this.httpService.get(
3638
- `/permissions/apps/${e}${le(t)}`,
3786
+ `/permissions/apps/${e}${ce(t)}`,
3639
3787
  { skipAuth: !0 }
3640
3788
  );
3641
3789
  return { permissions: n.data, meta: n.meta };
3642
3790
  }
3643
3791
  }
3644
- class Wr {
3792
+ class on {
3645
3793
  constructor(e) {
3646
3794
  this.httpService = e;
3647
3795
  }
@@ -3653,7 +3801,7 @@ class Wr {
3653
3801
  }
3654
3802
  async getSubscriptionPlans(e) {
3655
3803
  const t = await this.httpService.get(
3656
- `/subscription-plans/${le(e)}`
3804
+ `/subscription-plans/${ce(e)}`
3657
3805
  );
3658
3806
  return { plans: t.data, meta: t.meta };
3659
3807
  }
@@ -3672,7 +3820,7 @@ class Wr {
3672
3820
  await this.httpService.delete(`/subscription-plans/${e}`);
3673
3821
  }
3674
3822
  }
3675
- class Gr {
3823
+ class an {
3676
3824
  constructor(e) {
3677
3825
  this.httpService = e;
3678
3826
  }
@@ -3681,24 +3829,24 @@ class Gr {
3681
3829
  return await this.httpService.get("/health");
3682
3830
  }
3683
3831
  }
3684
- const it = "returnTo", Fe = "zone_return_to", Le = "zone_return_to";
3685
- function Hr(r = {}) {
3832
+ const dt = "returnTo", Ce = "zone_return_to", De = "zone_return_to";
3833
+ function ln(r = {}) {
3686
3834
  const {
3687
3835
  zoneRoots: e = {},
3688
- returnToParam: t = it,
3836
+ returnToParam: t = dt,
3689
3837
  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(() => {
3838
+ } = r, i = wt(), [a, l] = vt(), { isAuthenticated: d, currentUser: T } = de(), { tenant: A } = ve(), c = V(() => ({ ...ze, ...e }), [e]), S = !!A, h = T == null ? void 0 : T.userType, x = V(() => {
3691
3839
  switch (n) {
3692
3840
  case "url":
3693
3841
  return a.get(t);
3694
3842
  case "session":
3695
- return sessionStorage.getItem(Fe);
3843
+ return sessionStorage.getItem(Ce);
3696
3844
  case "local":
3697
- return localStorage.getItem(Le);
3845
+ return localStorage.getItem(De);
3698
3846
  default:
3699
3847
  return null;
3700
3848
  }
3701
- }, [n, a, t]), R = re(() => {
3849
+ }, [n, a, t]), P = te(() => {
3702
3850
  switch (n) {
3703
3851
  case "url": {
3704
3852
  const m = new URLSearchParams(a);
@@ -3706,13 +3854,13 @@ function Hr(r = {}) {
3706
3854
  break;
3707
3855
  }
3708
3856
  case "session":
3709
- sessionStorage.removeItem(Fe);
3857
+ sessionStorage.removeItem(Ce);
3710
3858
  break;
3711
3859
  case "local":
3712
- localStorage.removeItem(Le);
3860
+ localStorage.removeItem(De);
3713
3861
  break;
3714
3862
  }
3715
- }, [n, a, t, l]), I = re(
3863
+ }, [n, a, t, l]), I = te(
3716
3864
  (m) => {
3717
3865
  switch (n) {
3718
3866
  case "url": {
@@ -3721,101 +3869,102 @@ function Hr(r = {}) {
3721
3869
  break;
3722
3870
  }
3723
3871
  case "session":
3724
- sessionStorage.setItem(Fe, m);
3872
+ sessionStorage.setItem(Ce, m);
3725
3873
  break;
3726
3874
  case "local":
3727
- localStorage.setItem(Le, m);
3875
+ localStorage.setItem(De, m);
3728
3876
  break;
3729
3877
  }
3730
3878
  },
3731
3879
  [n, a, t, l]
3732
- ), A = re(
3880
+ ), R = te(
3733
3881
  (m) => {
3734
3882
  const g = c[m] || c.default;
3735
3883
  i(g);
3736
3884
  },
3737
3885
  [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]);
3886
+ ), 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
3887
  return {
3740
- returnToUrl: E,
3741
- clearReturnTo: R,
3888
+ returnToUrl: x,
3889
+ clearReturnTo: P,
3742
3890
  setReturnTo: I,
3743
- navigateToZone: A,
3744
- getSmartRedirect: S
3891
+ navigateToZone: R,
3892
+ getSmartRedirect: k
3745
3893
  };
3746
3894
  }
3747
- function Qr(r, e, t = it, n = "url") {
3895
+ function cn(r, e, t = dt, n = "url") {
3748
3896
  if (!e || n !== "url")
3749
3897
  return r;
3750
3898
  const i = new URL(r, window.location.origin);
3751
3899
  return i.searchParams.set(t, e), i.pathname + i.search;
3752
3900
  }
3753
3901
  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
3902
+ qr as AdminZone,
3903
+ Je as AppApiService,
3904
+ tn as AppLoader,
3905
+ Sr as AppProvider,
3906
+ Nt as AuthApiService,
3907
+ Rr as AuthProvider,
3908
+ Or as AuthenticatedZone,
3909
+ oe as ConfigurationError,
3910
+ ct as DEFAULT_ZONE_PRESETS,
3911
+ ze as DEFAULT_ZONE_ROOTS,
3912
+ Jr as FeatureFlag,
3913
+ Ot as FeatureFlagApiService,
3914
+ Lr as FeatureFlagProvider,
3915
+ Vr as GuestZone,
3916
+ an as HealthApiService,
3917
+ he as HttpService,
3918
+ Ur as LandingRoute,
3919
+ Zr as LoginForm,
3920
+ Yr as MagicLinkForm,
3921
+ Xr as MagicLinkVerify,
3922
+ jr as OpenZone,
3923
+ en as PasswordRecoveryForm,
3924
+ sn as PermissionApiService,
3925
+ Dr as Protected,
3926
+ Mr as ProtectedRoute,
3927
+ _r as PublicZone,
3928
+ Ct as RoleApiService,
3929
+ Nr as RoutingProvider,
3930
+ ee as SessionExpiredError,
3931
+ Me as SessionManager,
3932
+ Kr as SignupForm,
3933
+ qt as SubscriptionApiService,
3934
+ Qr as SubscriptionGuard,
3935
+ on as SubscriptionPlanApiService,
3936
+ Fr as SubscriptionProvider,
3937
+ ye as TenantApiService,
3938
+ Wr as TenantAuthenticatedZone,
3939
+ Hr as TenantGuestZone,
3940
+ Gr as TenantOpenZone,
3941
+ Er as TenantProvider,
3942
+ $r as TenantRoute,
3943
+ nn as TenantSelector,
3944
+ Br as TenantZone,
3945
+ kt as TokenRefreshError,
3946
+ St as TokenRefreshTimeoutError,
3947
+ Dt as UserApiService,
3948
+ ae as UserType,
3949
+ zr as UserZone,
3950
+ ue as ZoneRoute,
3951
+ cn as buildRedirectUrl,
3952
+ kr as useApi,
3953
+ Ae as useApp,
3954
+ rn as useAppLoaderState,
3955
+ de as useAuth,
3956
+ Ir as useAuthActions,
3957
+ Oe as useAuthOptional,
3958
+ Pr as useAuthState,
3959
+ Vt as useFeatureFlags,
3960
+ Cr as useRouting,
3961
+ Wt as useRoutingOptional,
3962
+ Ar as useSettings,
3963
+ zt as useSubscription,
3964
+ ve as useTenant,
3965
+ ot as useTenantInfo,
3966
+ pe as useTenantOptional,
3967
+ xr as useTenantSettings,
3968
+ ln as useZoneNavigation
3820
3969
  };
3821
3970
  //# sourceMappingURL=index.es.js.map