@skylabs-digital/react-identity-access 2.12.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as n, Fragment as j, jsxs as d } from "react/jsx-runtime";
2
- import { createContext as he, useMemo as te, useState as k, useCallback as ie, useEffect as re, useContext as se, useRef as Ue } from "react";
3
- import { useLocation as Te, Navigate as me } from "react-router-dom";
4
- class ne {
1
+ import { jsx as s, Fragment as _, jsxs as d } from "react/jsx-runtime";
2
+ import { createContext as me, useMemo as K, useState as A, useCallback as re, useEffect as X, useContext as oe, useRef as ze } from "react";
3
+ import { useLocation as be, Navigate as fe, useNavigate as lt, useSearchParams as ct } from "react-router-dom";
4
+ class ie {
5
5
  // SessionManager instance
6
6
  constructor(e, t = 1e4) {
7
7
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
@@ -12,60 +12,60 @@ class ne {
12
12
  getBaseUrl() {
13
13
  return this.baseUrl;
14
14
  }
15
- async request(e, t, r, s) {
16
- return this.executeRequest(e, t, r, s, !1);
15
+ async request(e, t, n, i) {
16
+ return this.executeRequest(e, t, n, i, !1);
17
17
  }
18
- async executeRequest(e, t, r, s, o = !1) {
19
- const a = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, m = (s == null ? void 0 : s.timeout) || this.timeout;
20
- let y = {
18
+ async executeRequest(e, t, n, i, o = !1) {
19
+ const a = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, p = (i == null ? void 0 : i.timeout) || this.timeout;
20
+ let f = {
21
21
  "Content-Type": "application/json",
22
- ...s == null ? void 0 : s.headers
22
+ ...i == null ? void 0 : i.headers
23
23
  };
24
- if (!(s != null && s.skipAuth) && this.sessionManager)
24
+ if (!(i != null && i.skipAuth) && this.sessionManager)
25
25
  try {
26
- const S = await this.sessionManager.getAuthHeaders();
27
- y = { ...y, ...S };
28
- } catch (S) {
29
- console.warn("Failed to inject auth headers:", S);
26
+ const w = await this.sessionManager.getAuthHeaders();
27
+ f = { ...f, ...w };
28
+ } catch (w) {
29
+ console.warn("Failed to inject auth headers:", w);
30
30
  }
31
- const b = new AbortController(), p = setTimeout(() => b.abort(), m);
31
+ const b = new AbortController(), u = setTimeout(() => b.abort(), p);
32
32
  try {
33
- const S = await fetch(a, {
33
+ const w = await fetch(a, {
34
34
  method: e,
35
- headers: y,
36
- body: r ? JSON.stringify(r) : void 0,
35
+ headers: f,
36
+ body: n ? JSON.stringify(n) : void 0,
37
37
  signal: b.signal
38
38
  });
39
- if (clearTimeout(p), S.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
39
+ if (clearTimeout(u), w.status === 401 && !(i != null && i.skipRetry) && !o && this.sessionManager)
40
40
  try {
41
- const T = this.sessionManager.getTokens();
42
- if (T != null && T.refreshToken)
43
- return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, r, s, !0);
41
+ const v = this.sessionManager.getTokens();
42
+ if (v != null && v.refreshToken)
43
+ return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, n, i, !0);
44
44
  } catch {
45
- throw new Error(`HTTP ${S.status}: ${S.statusText}`);
45
+ throw new Error(`HTTP ${w.status}: ${w.statusText}`);
46
46
  }
47
- if (!S.ok)
48
- throw new Error(`HTTP ${S.status}: ${S.statusText}`);
49
- const f = S.headers.get("content-type");
50
- return !f || !f.includes("application/json") ? {} : await S.json();
51
- } catch (S) {
52
- throw clearTimeout(p), S instanceof Error && S.name === "AbortError" ? new Error(`Request timeout after ${m}ms`) : S;
47
+ if (!w.ok)
48
+ throw new Error(`HTTP ${w.status}: ${w.statusText}`);
49
+ const g = w.headers.get("content-type");
50
+ return !g || !g.includes("application/json") ? {} : await w.json();
51
+ } catch (w) {
52
+ throw clearTimeout(u), w instanceof Error && w.name === "AbortError" ? new Error(`Request timeout after ${p}ms`) : w;
53
53
  }
54
54
  }
55
55
  async get(e, t) {
56
56
  return this.request("GET", e, void 0, t);
57
57
  }
58
- async post(e, t, r) {
59
- return this.request("POST", e, t, r);
58
+ async post(e, t, n) {
59
+ return this.request("POST", e, t, n);
60
60
  }
61
- async put(e, t, r) {
62
- return this.request("PUT", e, t, r);
61
+ async put(e, t, n) {
62
+ return this.request("PUT", e, t, n);
63
63
  }
64
64
  async delete(e, t) {
65
65
  return this.request("DELETE", e, void 0, t);
66
66
  }
67
67
  }
68
- class Fe {
68
+ class Ce {
69
69
  constructor(e, t) {
70
70
  this.httpService = e, this.sessionManager = t;
71
71
  }
@@ -76,9 +76,9 @@ class Fe {
76
76
  })).data;
77
77
  }
78
78
  async getApps(e) {
79
- const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
80
- e != null && e.page && r.append("page", e.page.toString()), e != null && e.limit && r.append("limit", e.limit.toString()), e != null && e.sortBy && r.append("sortBy", e.sortBy), e != null && e.sortOrder && r.append("sortOrder", e.sortOrder);
81
- const s = `/apps/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
79
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
80
+ e != null && e.page && n.append("page", e.page.toString()), e != null && e.limit && n.append("limit", e.limit.toString()), e != null && e.sortBy && n.append("sortBy", e.sortBy), e != null && e.sortOrder && n.append("sortOrder", e.sortOrder);
81
+ const i = `/apps/${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i, {
82
82
  headers: t
83
83
  });
84
84
  return {
@@ -93,28 +93,28 @@ class Fe {
93
93
  })).data;
94
94
  }
95
95
  async updateApp(e, t) {
96
- const r = await this.sessionManager.getAuthHeaders();
96
+ const n = await this.sessionManager.getAuthHeaders();
97
97
  return (await this.httpService.put(`/apps/${e}`, t, {
98
- headers: r
98
+ headers: n
99
99
  })).data;
100
100
  }
101
101
  async getPublicAppInfo(e) {
102
102
  return (await this.httpService.get(`/apps/${e}/public`)).data;
103
103
  }
104
104
  async setDefaultSubscriptionPlan(e, t) {
105
- const r = await this.sessionManager.getAuthHeaders();
105
+ const n = await this.sessionManager.getAuthHeaders();
106
106
  return (await this.httpService.put(
107
107
  `/apps/${e}/default-subscription-plan`,
108
108
  { planId: t },
109
- { headers: r }
109
+ { headers: n }
110
110
  )).data;
111
111
  }
112
- async updateSettingsSchema(e, t, r) {
113
- const s = await this.sessionManager.getAuthHeaders();
112
+ async updateSettingsSchema(e, t, n) {
113
+ const i = await this.sessionManager.getAuthHeaders();
114
114
  return (await this.httpService.put(
115
115
  `/apps/${e}/settings-schema`,
116
- { schema: t, defaultSettings: r },
117
- { headers: s }
116
+ { schema: t, defaultSettings: n },
117
+ { headers: i }
118
118
  )).data;
119
119
  }
120
120
  async exportConfig(e) {
@@ -124,102 +124,102 @@ class Fe {
124
124
  })).data;
125
125
  }
126
126
  }
127
- const xe = he(null);
128
- function Jt({ config: i, children: e }) {
129
- const t = te(
127
+ const Re = me(null);
128
+ function dn({ config: r, children: e }) {
129
+ const t = K(
130
130
  () => {
131
- var f, T, I;
131
+ var g, v, M;
132
132
  return {
133
- enabled: ((f = i.cache) == null ? void 0 : f.enabled) ?? !0,
134
- ttl: ((T = i.cache) == null ? void 0 : T.ttl) ?? 3e5,
133
+ enabled: ((g = r.cache) == null ? void 0 : g.enabled) ?? !0,
134
+ ttl: ((v = r.cache) == null ? void 0 : v.ttl) ?? 3e5,
135
135
  // 5 minutes default
136
- storageKey: ((I = i.cache) == null ? void 0 : I.storageKey) ?? `app_cache_${i.appId}`
136
+ storageKey: ((M = r.cache) == null ? void 0 : M.storageKey) ?? `app_cache_${r.appId}`
137
137
  };
138
138
  },
139
- [i.cache, i.appId]
140
- ), [r, s] = k(() => {
139
+ [r.cache, r.appId]
140
+ ), [n, i] = A(() => {
141
141
  if (!t.enabled) return null;
142
142
  try {
143
- const f = localStorage.getItem(t.storageKey);
144
- if (!f) return null;
145
- const T = JSON.parse(f);
146
- return Date.now() - T.timestamp < t.ttl && T.appId === i.appId ? T.data : (localStorage.removeItem(t.storageKey), null);
143
+ const g = localStorage.getItem(t.storageKey);
144
+ if (!g) return null;
145
+ const v = JSON.parse(g);
146
+ return Date.now() - v.timestamp < t.ttl && v.appId === r.appId ? v.data : (localStorage.removeItem(t.storageKey), null);
147
147
  } catch {
148
148
  return null;
149
149
  }
150
- }), [o, a] = k(!r), [m, y] = k(null), b = te(() => {
151
- const f = () => {
152
- p();
150
+ }), [o, a] = A(!n), [p, f] = A(null), b = K(() => {
151
+ const g = () => {
152
+ u();
153
153
  };
154
154
  return {
155
- appId: i.appId,
156
- baseUrl: i.baseUrl,
155
+ appId: r.appId,
156
+ baseUrl: r.baseUrl,
157
157
  // App info
158
- appInfo: r,
158
+ appInfo: n,
159
159
  isAppLoading: o,
160
- appError: m,
161
- retryApp: f
160
+ appError: p,
161
+ retryApp: g
162
162
  };
163
- }, [i, r, o, m]), p = ie(
164
- async (f = !1) => {
165
- if (!(!f && t.enabled && r))
163
+ }, [r, n, o, p]), u = re(
164
+ async (g = !1) => {
165
+ if (!(!g && t.enabled && n))
166
166
  try {
167
- a(!0), y(null);
168
- const T = new ne(i.baseUrl), C = await new Fe(T, {}).getPublicAppInfo(i.appId);
169
- if (s(C), t.enabled)
167
+ a(!0), f(null);
168
+ const v = new ie(r.baseUrl), F = await new Ce(v, {}).getPublicAppInfo(r.appId);
169
+ if (i(F), t.enabled)
170
170
  try {
171
- const R = {
172
- data: C,
171
+ const L = {
172
+ data: F,
173
173
  timestamp: Date.now(),
174
- appId: i.appId
174
+ appId: r.appId
175
175
  };
176
- localStorage.setItem(t.storageKey, JSON.stringify(R));
177
- } catch (R) {
178
- console.warn("Failed to cache app info:", R);
176
+ localStorage.setItem(t.storageKey, JSON.stringify(L));
177
+ } catch (L) {
178
+ console.warn("Failed to cache app info:", L);
179
179
  }
180
- } catch (T) {
181
- const I = T instanceof Error ? T : new Error("Failed to load app information");
182
- y(I), s(null);
180
+ } catch (v) {
181
+ const M = v instanceof Error ? v : new Error("Failed to load app information");
182
+ f(M), i(null);
183
183
  } finally {
184
184
  a(!1);
185
185
  }
186
186
  },
187
- [i.baseUrl, i.appId, t, r]
188
- ), S = ie(async () => {
189
- if (!(!t.enabled || !r))
187
+ [r.baseUrl, r.appId, t, n]
188
+ ), w = re(async () => {
189
+ if (!(!t.enabled || !n))
190
190
  try {
191
- const f = localStorage.getItem(t.storageKey);
192
- if (!f) return;
193
- const T = JSON.parse(f);
194
- if (Date.now() - T.timestamp > t.ttl * 0.5) {
195
- const C = new ne(i.baseUrl), x = await new Fe(C, {}).getPublicAppInfo(i.appId);
196
- s(x);
197
- const g = {
198
- data: x,
191
+ const g = localStorage.getItem(t.storageKey);
192
+ if (!g) return;
193
+ const v = JSON.parse(g);
194
+ if (Date.now() - v.timestamp > t.ttl * 0.5) {
195
+ const F = new ie(r.baseUrl), P = await new Ce(F, {}).getPublicAppInfo(r.appId);
196
+ i(P);
197
+ const h = {
198
+ data: P,
199
199
  timestamp: Date.now(),
200
- appId: i.appId
200
+ appId: r.appId
201
201
  };
202
- localStorage.setItem(t.storageKey, JSON.stringify(g));
202
+ localStorage.setItem(t.storageKey, JSON.stringify(h));
203
203
  }
204
- } catch (f) {
205
- console.warn("Background app refresh failed:", f);
204
+ } catch (g) {
205
+ console.warn("Background app refresh failed:", g);
206
206
  }
207
- }, [i, t, r]);
208
- return re(() => {
209
- r ? S() : p();
210
- }, []), /* @__PURE__ */ n(xe.Provider, { value: b, children: e });
207
+ }, [r, t, n]);
208
+ return X(() => {
209
+ n ? w() : u();
210
+ }, []), /* @__PURE__ */ s(Re.Provider, { value: b, children: e });
211
211
  }
212
- function ge() {
213
- const i = se(xe);
214
- if (!i)
212
+ function ye() {
213
+ const r = oe(Re);
214
+ if (!r)
215
215
  throw new Error("useApp must be used within an AppProvider");
216
- return i;
216
+ return r;
217
217
  }
218
- function Be() {
219
- return se(xe);
218
+ function _e() {
219
+ return oe(Re);
220
220
  }
221
- const Kt = ge;
222
- class ke {
221
+ const un = ye;
222
+ class Ae {
223
223
  constructor(e = {}) {
224
224
  this.refreshPromise = null, this.refreshQueue = [], e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : this.storageKey = e.storageKey || "auth_tokens", this.autoRefresh = e.autoRefresh ?? !0, this.refreshThreshold = e.refreshThreshold || 3e5, this.onRefreshFailed = e.onRefreshFailed, this.baseUrl = e.baseUrl || "", this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey);
225
225
  }
@@ -256,12 +256,12 @@ class ke {
256
256
  this.tokenStorage.set(t);
257
257
  }
258
258
  getTokens() {
259
- const { accessToken: e, refreshToken: t, expiresAt: r, expiresIn: s, tokenType: o } = this.tokenStorage.get() || {};
259
+ const { accessToken: e, refreshToken: t, expiresAt: n, expiresIn: i, tokenType: o } = this.tokenStorage.get() || {};
260
260
  return e ? {
261
261
  accessToken: e,
262
262
  refreshToken: t,
263
- expiresAt: r,
264
- expiresIn: s,
263
+ expiresAt: n,
264
+ expiresIn: i,
265
265
  tokenType: o
266
266
  } : null;
267
267
  }
@@ -291,17 +291,17 @@ class ke {
291
291
  if (!e.refreshToken)
292
292
  return this.clearSession(), this.onRefreshFailed && this.onRefreshFailed(), {};
293
293
  if (this.refreshPromise)
294
- return new Promise((t, r) => {
295
- this.refreshQueue.push({ resolve: t, reject: r });
294
+ return new Promise((t, n) => {
295
+ this.refreshQueue.push({ resolve: t, reject: n });
296
296
  });
297
297
  this.refreshPromise = this.performTokenRefresh(e.refreshToken);
298
298
  try {
299
299
  await this.refreshPromise;
300
- const t = this.getTokens(), r = t != null && t.accessToken ? { Authorization: `Bearer ${t.accessToken}` } : {};
301
- return this.refreshQueue.forEach(({ resolve: s }) => s(r)), this.refreshQueue = [], r;
300
+ const t = this.getTokens(), n = t != null && t.accessToken ? { Authorization: `Bearer ${t.accessToken}` } : {};
301
+ return this.refreshQueue.forEach(({ resolve: i }) => i(n)), this.refreshQueue = [], n;
302
302
  } catch (t) {
303
- const r = t instanceof Error ? t : new Error("Token refresh failed");
304
- return this.refreshQueue.forEach(({ reject: s }) => s(r)), this.refreshQueue = [], this.clearSession(), this.onRefreshFailed && this.onRefreshFailed(), {};
303
+ const n = t instanceof Error ? t : new Error("Token refresh failed");
304
+ return this.refreshQueue.forEach(({ reject: i }) => i(n)), this.refreshQueue = [], this.clearSession(), this.onRefreshFailed && this.onRefreshFailed(), {};
305
305
  } finally {
306
306
  this.refreshPromise = null;
307
307
  }
@@ -309,7 +309,7 @@ class ke {
309
309
  async performTokenRefresh(e) {
310
310
  if (!this.baseUrl)
311
311
  throw new Error("Base URL not configured for token refresh");
312
- const t = `${this.baseUrl}/auth/refresh`, r = await fetch(t, {
312
+ const t = `${this.baseUrl}/auth/refresh`, n = await fetch(t, {
313
313
  method: "POST",
314
314
  headers: {
315
315
  "Content-Type": "application/json"
@@ -318,13 +318,13 @@ class ke {
318
318
  refreshToken: e
319
319
  })
320
320
  });
321
- if (!r.ok)
322
- throw new Error(`Token refresh failed: ${r.status} ${r.statusText}`);
323
- const s = await r.json();
321
+ if (!n.ok)
322
+ throw new Error(`Token refresh failed: ${n.status} ${n.statusText}`);
323
+ const i = await n.json();
324
324
  this.setTokens({
325
- accessToken: s.accessToken,
326
- refreshToken: s.refreshToken || e,
327
- expiresIn: s.expiresIn
325
+ accessToken: i.accessToken,
326
+ refreshToken: i.refreshToken || e,
327
+ expiresIn: i.expiresIn
328
328
  });
329
329
  }
330
330
  setUser(e) {
@@ -352,8 +352,8 @@ class ke {
352
352
  if (!(e != null && e.accessToken)) return null;
353
353
  const t = e.accessToken.split(".");
354
354
  if (t.length !== 3) return null;
355
- const r = t[1], s = atob(r.replace(/-/g, "+").replace(/_/g, "/"));
356
- return JSON.parse(s);
355
+ const n = t[1], i = atob(n.replace(/-/g, "+").replace(/_/g, "/"));
356
+ return JSON.parse(i);
357
357
  } catch {
358
358
  return null;
359
359
  }
@@ -372,7 +372,7 @@ class ke {
372
372
  return e !== null && !this.isTokenExpired(e);
373
373
  }
374
374
  }
375
- class rt {
375
+ class dt {
376
376
  constructor(e) {
377
377
  this.httpService = e;
378
378
  }
@@ -428,7 +428,7 @@ class rt {
428
428
  });
429
429
  }
430
430
  }
431
- class Ce {
431
+ class De {
432
432
  constructor(e, t) {
433
433
  this.httpService = e, this.sessionManager = t;
434
434
  }
@@ -451,9 +451,9 @@ class Ce {
451
451
  async updateRole(e, t) {
452
452
  if (!this.sessionManager)
453
453
  throw new Error("SessionManager is required for private endpoints");
454
- const r = await this.sessionManager.getAuthHeaders();
454
+ const n = await this.sessionManager.getAuthHeaders();
455
455
  return (await this.httpService.put(`/roles/${e}`, t, {
456
- headers: r
456
+ headers: n
457
457
  })).data;
458
458
  }
459
459
  async deleteRole(e) {
@@ -466,9 +466,9 @@ class Ce {
466
466
  }
467
467
  // Public endpoint - no auth required
468
468
  async getRolesByApp(e, t) {
469
- const r = new URLSearchParams();
470
- t != null && t.page && r.append("page", t.page.toString()), t != null && t.limit && r.append("limit", t.limit.toString()), t != null && t.sortBy && r.append("sortBy", t.sortBy), t != null && t.sortOrder && r.append("sortOrder", t.sortOrder);
471
- const s = `/roles/app/${e}${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s);
469
+ const n = new URLSearchParams();
470
+ t != null && t.page && n.append("page", t.page.toString()), t != null && t.limit && n.append("limit", t.limit.toString()), t != null && t.sortBy && n.append("sortBy", t.sortBy), t != null && t.sortOrder && n.append("sortOrder", t.sortOrder);
471
+ const i = `/roles/app/${e}${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i);
472
472
  return {
473
473
  roles: o.data,
474
474
  meta: o.meta
@@ -477,26 +477,26 @@ class Ce {
477
477
  async assignRole(e, t) {
478
478
  if (!this.sessionManager)
479
479
  throw new Error("SessionManager is required for private endpoints");
480
- const r = await this.sessionManager.getAuthHeaders();
480
+ const n = await this.sessionManager.getAuthHeaders();
481
481
  await this.httpService.post(`/roles/${e}/assign`, t, {
482
- headers: r
482
+ headers: n
483
483
  });
484
484
  }
485
485
  async revokeRole(e, t) {
486
486
  if (!this.sessionManager)
487
487
  throw new Error("SessionManager is required for private endpoints");
488
- const r = await this.sessionManager.getAuthHeaders();
488
+ const n = await this.sessionManager.getAuthHeaders();
489
489
  await this.httpService.post(`/roles/${e}/revoke`, t, {
490
- headers: r
490
+ headers: n
491
491
  });
492
492
  }
493
493
  async getUserRoles(e, t) {
494
494
  if (!this.sessionManager)
495
495
  throw new Error("SessionManager is required for private endpoints");
496
- const r = await this.sessionManager.getAuthHeaders(), s = new URLSearchParams();
497
- t != null && t.page && s.append("page", t.page.toString()), t != null && t.limit && s.append("limit", t.limit.toString()), t != null && t.sortBy && s.append("sortBy", t.sortBy), t != null && t.sortOrder && s.append("sortOrder", t.sortOrder);
498
- const o = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, a = await this.httpService.get(o, {
499
- headers: r
496
+ const n = await this.sessionManager.getAuthHeaders(), i = new URLSearchParams();
497
+ t != null && t.page && i.append("page", t.page.toString()), t != null && t.limit && i.append("limit", t.limit.toString()), t != null && t.sortBy && i.append("sortBy", t.sortBy), t != null && t.sortOrder && i.append("sortOrder", t.sortOrder);
498
+ const o = `/roles/user/${e}${i.toString() ? `?${i.toString()}` : ""}`, a = await this.httpService.get(o, {
499
+ headers: n
500
500
  });
501
501
  return {
502
502
  roles: a.data,
@@ -504,7 +504,7 @@ class Ce {
504
504
  };
505
505
  }
506
506
  }
507
- class nt {
507
+ class ut {
508
508
  constructor(e, t) {
509
509
  this.httpService = e, this.sessionManager = t;
510
510
  }
@@ -515,9 +515,9 @@ class nt {
515
515
  })).data;
516
516
  }
517
517
  async getUsers(e) {
518
- const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
519
- e != null && e.page && r.append("page", e.page.toString()), e != null && e.limit && r.append("limit", e.limit.toString()), e != null && e.sortBy && r.append("sortBy", e.sortBy), e != null && e.sortOrder && r.append("sortOrder", e.sortOrder);
520
- const s = `/users/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
518
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
519
+ e != null && e.page && n.append("page", e.page.toString()), e != null && e.limit && n.append("limit", e.limit.toString()), e != null && e.sortBy && n.append("sortBy", e.sortBy), e != null && e.sortOrder && n.append("sortOrder", e.sortOrder);
520
+ const i = `/users/${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i, {
521
521
  headers: t
522
522
  });
523
523
  return {
@@ -532,9 +532,9 @@ class nt {
532
532
  })).data;
533
533
  }
534
534
  async updateUser(e, t) {
535
- const r = await this.sessionManager.getAuthHeaders();
535
+ const n = await this.sessionManager.getAuthHeaders();
536
536
  return (await this.httpService.put(`/users/${e}`, t, {
537
- headers: r
537
+ headers: n
538
538
  })).data;
539
539
  }
540
540
  async deleteUser(e) {
@@ -544,9 +544,9 @@ class nt {
544
544
  });
545
545
  }
546
546
  }
547
- class ue {
548
- constructor(e, t, r) {
549
- this.httpService = e, this.appId = t, this.sessionManager = r;
547
+ class pe {
548
+ constructor(e, t, n) {
549
+ this.httpService = e, this.appId = t, this.sessionManager = n;
550
550
  }
551
551
  async createTenant(e) {
552
552
  if (!this.sessionManager)
@@ -559,9 +559,9 @@ class ue {
559
559
  async getTenants(e) {
560
560
  if (!this.sessionManager)
561
561
  throw new Error("SessionManager is required for private endpoints");
562
- const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
563
- e != null && e.page && r.append("page", e.page.toString()), e != null && e.limit && r.append("limit", e.limit.toString()), e != null && e.sortBy && r.append("sortBy", e.sortBy), e != null && e.sortOrder && r.append("sortOrder", e.sortOrder);
564
- const s = `/tenants/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
562
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
563
+ e != null && e.page && n.append("page", e.page.toString()), e != null && e.limit && n.append("limit", e.limit.toString()), e != null && e.sortBy && n.append("sortBy", e.sortBy), e != null && e.sortOrder && n.append("sortOrder", e.sortOrder);
564
+ const i = `/tenants/${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i, {
565
565
  headers: t
566
566
  });
567
567
  return {
@@ -580,20 +580,20 @@ class ue {
580
580
  async updateTenant(e, t) {
581
581
  if (!this.sessionManager)
582
582
  throw new Error("SessionManager is required for private endpoints");
583
- const r = await this.sessionManager.getAuthHeaders();
583
+ const n = await this.sessionManager.getAuthHeaders();
584
584
  return (await this.httpService.put(`/tenants/${e}`, t, {
585
- headers: r
585
+ headers: n
586
586
  })).data;
587
587
  }
588
588
  async adminUpdateTenant(e, t) {
589
589
  if (!this.sessionManager)
590
590
  throw new Error("SessionManager is required for private endpoints");
591
- const r = await this.sessionManager.getAuthHeaders();
591
+ const n = await this.sessionManager.getAuthHeaders();
592
592
  return (await this.httpService.put(
593
593
  `/tenants/${e}/admin-update`,
594
594
  t,
595
595
  {
596
- headers: r
596
+ headers: n
597
597
  }
598
598
  )).data;
599
599
  }
@@ -612,72 +612,72 @@ class ue {
612
612
  async updateTenantSettings(e, t) {
613
613
  if (!this.sessionManager)
614
614
  throw new Error("SessionManager is required for private endpoints");
615
- const r = await this.sessionManager.getAuthHeaders();
615
+ const n = await this.sessionManager.getAuthHeaders();
616
616
  return (await this.httpService.put(
617
617
  `/tenants/${e}/settings`,
618
618
  t,
619
619
  {
620
- headers: r
620
+ headers: n
621
621
  }
622
622
  )).data;
623
623
  }
624
624
  }
625
- function st(i, e) {
626
- if (i === "localhost" || i.startsWith("127.") || i.startsWith("192.168."))
625
+ function ht(r, e) {
626
+ if (r === "localhost" || r.startsWith("127.") || r.startsWith("192.168."))
627
627
  return null;
628
628
  if (e) {
629
- const s = e.toLowerCase(), o = i.toLowerCase();
630
- if (o === s || o === `www.${s}`)
629
+ const i = e.toLowerCase(), o = r.toLowerCase();
630
+ if (o === i || o === `www.${i}`)
631
631
  return null;
632
- if (o.endsWith(`.${s}`)) {
633
- const a = o.slice(0, -(s.length + 1));
632
+ if (o.endsWith(`.${i}`)) {
633
+ const a = o.slice(0, -(i.length + 1));
634
634
  return a === "www" ? null : a;
635
635
  }
636
636
  return null;
637
637
  }
638
- const r = i.split(".");
639
- return r.length >= 3 && r[0] !== "www" ? r[0] : null;
638
+ const n = r.split(".");
639
+ return n.length >= 3 && n[0] !== "www" ? n[0] : null;
640
640
  }
641
- function it(i, e = "tenant", t) {
642
- const s = new URLSearchParams(i).get(e);
643
- return s ? (t && t.setItem("tenant", s), s) : t ? t.getItem("tenant") : null;
641
+ function gt(r, e = "tenant", t) {
642
+ const i = new URLSearchParams(r).get(e);
643
+ return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
644
644
  }
645
- function ot(i, e, t) {
646
- const { tenantMode: r, baseDomain: s, selectorParam: o } = i;
647
- return r === "subdomain" ? st(e.hostname, s) : r === "selector" ? it(e.search, o, t) : null;
645
+ function pt(r, e, t) {
646
+ const { tenantMode: n, baseDomain: i, selectorParam: o } = r;
647
+ return n === "subdomain" ? ht(e.hostname, i) : n === "selector" ? gt(e.search, o, t) : null;
648
648
  }
649
- function at(i, e, t) {
649
+ function ft(r, e, t) {
650
650
  if (t)
651
- return `${i}.${t}`;
652
- const r = e.split(".");
653
- return r.length === 2 ? `${i}.${e}` : r.length >= 3 ? (r[0] = i, r.join(".")) : null;
651
+ return `${r}.${t}`;
652
+ const n = e.split(".");
653
+ return n.length === 2 ? `${r}.${e}` : n.length >= 3 ? (n[0] = r, n.join(".")) : null;
654
654
  }
655
- const le = "_auth";
656
- function De(i) {
657
- const e = JSON.stringify(i);
655
+ const de = "_auth";
656
+ function $e(r) {
657
+ const e = JSON.stringify(r);
658
658
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
659
659
  }
660
- function lt(i) {
660
+ function mt(r) {
661
661
  try {
662
- let e = i.replace(/-/g, "+").replace(/_/g, "/");
662
+ let e = r.replace(/-/g, "+").replace(/_/g, "/");
663
663
  for (; e.length % 4; )
664
664
  e += "=";
665
- const t = atob(e), r = JSON.parse(t);
666
- return typeof r.accessToken == "string" && typeof r.refreshToken == "string" && typeof r.expiresIn == "number" ? r : null;
665
+ const t = atob(e), n = JSON.parse(t);
666
+ return typeof n.accessToken == "string" && typeof n.refreshToken == "string" && typeof n.expiresIn == "number" ? n : null;
667
667
  } catch {
668
668
  return null;
669
669
  }
670
670
  }
671
- function ct() {
671
+ function yt() {
672
672
  if (typeof window > "u")
673
673
  return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
674
- const e = new URLSearchParams(window.location.search).get(le);
674
+ const e = new URLSearchParams(window.location.search).get(de);
675
675
  if (console.log("[CrossDomainAuth] extractAuthTokensFromUrl called", {
676
676
  hasAuthParam: !!e,
677
677
  searchParams: window.location.search,
678
678
  encodedLength: e == null ? void 0 : e.length
679
679
  }), !e) return null;
680
- const t = lt(e);
680
+ const t = mt(e);
681
681
  return console.log("[CrossDomainAuth] Token decode result:", {
682
682
  success: !!t,
683
683
  hasAccessToken: !!(t != null && t.accessToken),
@@ -685,139 +685,139 @@ function ct() {
685
685
  expiresIn: t == null ? void 0 : t.expiresIn
686
686
  }), t;
687
687
  }
688
- function dt() {
688
+ function wt() {
689
689
  if (typeof window > "u") return;
690
- const i = new URL(window.location.href);
691
- i.searchParams.delete(le), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
690
+ const r = new URL(window.location.href);
691
+ r.searchParams.delete(de), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
692
692
  oldUrl: window.location.href,
693
- newUrl: i.toString()
694
- }), window.history.replaceState({}, "", i.toString());
693
+ newUrl: r.toString()
694
+ }), window.history.replaceState({}, "", r.toString());
695
695
  }
696
- const Ae = he(null);
697
- function Yt({ config: i, children: e }) {
698
- const { baseUrl: t, appInfo: r, appId: s } = ge(), o = ie(() => typeof window > "u" ? null : ot(
696
+ const Ie = me(null);
697
+ function hn({ config: r, children: e }) {
698
+ const { baseUrl: t, appInfo: n, appId: i } = ye(), o = re(() => typeof window > "u" ? null : pt(
699
699
  {
700
- tenantMode: i.tenantMode || "selector",
701
- baseDomain: i.baseDomain,
702
- selectorParam: i.selectorParam
700
+ tenantMode: r.tenantMode || "selector",
701
+ baseDomain: r.baseDomain,
702
+ selectorParam: r.selectorParam
703
703
  },
704
704
  {
705
705
  hostname: window.location.hostname,
706
706
  search: window.location.search
707
707
  },
708
708
  window.localStorage
709
- ), [i.tenantMode, i.baseDomain, i.selectorParam]), [a, m] = k(() => o()), y = te(
709
+ ), [r.tenantMode, r.baseDomain, r.selectorParam]), [a, p] = A(() => o()), f = K(
710
710
  () => {
711
- var l, H, M;
711
+ var c, $, E;
712
712
  return {
713
- enabled: ((l = i.cache) == null ? void 0 : l.enabled) ?? !0,
714
- ttl: ((H = i.cache) == null ? void 0 : H.ttl) ?? 5 * 60 * 1e3,
713
+ enabled: ((c = r.cache) == null ? void 0 : c.enabled) ?? !0,
714
+ ttl: (($ = r.cache) == null ? void 0 : $.ttl) ?? 5 * 60 * 1e3,
715
715
  // 5 minutes default
716
- storageKey: ((M = i.cache) == null ? void 0 : M.storageKey) ?? `tenant_cache_${a || "default"}`
716
+ storageKey: ((E = r.cache) == null ? void 0 : E.storageKey) ?? `tenant_cache_${a || "default"}`
717
717
  };
718
718
  },
719
- [i.cache, a]
720
- ), [b, p] = k(() => {
721
- if (i.initialTenant) return i.initialTenant;
722
- if (!y.enabled || !a) return null;
719
+ [r.cache, a]
720
+ ), [b, u] = A(() => {
721
+ if (r.initialTenant) return r.initialTenant;
722
+ if (!f.enabled || !a) return null;
723
723
  try {
724
- const l = localStorage.getItem(y.storageKey);
725
- if (!l) return null;
726
- const H = JSON.parse(l);
727
- return Date.now() - H.timestamp < y.ttl && H.tenantSlug === a ? H.data : (localStorage.removeItem(y.storageKey), null);
724
+ const c = localStorage.getItem(f.storageKey);
725
+ if (!c) return null;
726
+ const $ = JSON.parse(c);
727
+ return Date.now() - $.timestamp < f.ttl && $.tenantSlug === a ? $.data : (localStorage.removeItem(f.storageKey), null);
728
728
  } catch {
729
729
  return null;
730
730
  }
731
- }), [S, f] = k(!b && !i.initialTenant), [T, I] = k(null), [C, R] = k(null), [x, g] = k(!1), [$, A] = k(null);
732
- re(() => {
733
- const l = o();
734
- m(l);
731
+ }), [w, g] = A(!b && !r.initialTenant), [v, M] = A(null), [F, L] = A(null), [P, h] = A(!1), [x, k] = A(null);
732
+ X(() => {
733
+ const c = o();
734
+ p(c);
735
735
  }, [o]);
736
- const E = (r == null ? void 0 : r.settingsSchema) || null, U = ie(
737
- async (l, H = !1) => {
738
- if (!(!H && y.enabled && b && b.domain === l))
736
+ const I = (n == null ? void 0 : n.settingsSchema) || null, U = re(
737
+ async (c, $ = !1) => {
738
+ if (!(!$ && f.enabled && b && b.domain === c))
739
739
  try {
740
- f(!0), I(null);
741
- const M = new ne(t), u = await new ue(M, s).getPublicTenantInfo(l);
742
- if (p(u), y.enabled)
740
+ g(!0), M(null);
741
+ const E = new ie(t), m = await new pe(E, i).getPublicTenantInfo(c);
742
+ if (u(m), f.enabled)
743
743
  try {
744
- const w = {
745
- data: u,
744
+ const S = {
745
+ data: m,
746
746
  timestamp: Date.now(),
747
- tenantSlug: l
747
+ tenantSlug: c
748
748
  };
749
- localStorage.setItem(y.storageKey, JSON.stringify(w));
750
- } catch (w) {
751
- console.warn("Failed to cache tenant info:", w);
749
+ localStorage.setItem(f.storageKey, JSON.stringify(S));
750
+ } catch (S) {
751
+ console.warn("Failed to cache tenant info:", S);
752
752
  }
753
- } catch (M) {
754
- const h = M instanceof Error ? M : new Error("Failed to load tenant information");
755
- I(h), p(null);
753
+ } catch (E) {
754
+ const y = E instanceof Error ? E : new Error("Failed to load tenant information");
755
+ M(y), u(null);
756
756
  } finally {
757
- f(!1);
757
+ g(!1);
758
758
  }
759
759
  },
760
- [t, s, y, b]
761
- ), D = ie(async () => {
762
- if (!(!y.enabled || !b || !a))
760
+ [t, i, f, b]
761
+ ), C = re(async () => {
762
+ if (!(!f.enabled || !b || !a))
763
763
  try {
764
- const l = localStorage.getItem(y.storageKey);
765
- if (!l) return;
766
- const H = JSON.parse(l);
767
- if (Date.now() - H.timestamp > y.ttl * 0.5) {
768
- const h = new ne(t), w = await new ue(h, s).getPublicTenantInfo(a);
769
- p(w);
770
- const _ = {
771
- data: w,
764
+ const c = localStorage.getItem(f.storageKey);
765
+ if (!c) return;
766
+ const $ = JSON.parse(c);
767
+ if (Date.now() - $.timestamp > f.ttl * 0.5) {
768
+ const y = new ie(t), S = await new pe(y, i).getPublicTenantInfo(a);
769
+ u(S);
770
+ const G = {
771
+ data: S,
772
772
  timestamp: Date.now(),
773
773
  tenantSlug: a
774
774
  };
775
- localStorage.setItem(y.storageKey, JSON.stringify(_));
775
+ localStorage.setItem(f.storageKey, JSON.stringify(G));
776
776
  }
777
- } catch (l) {
778
- console.warn("Background tenant refresh failed:", l);
777
+ } catch (c) {
778
+ console.warn("Background tenant refresh failed:", c);
779
779
  }
780
- }, [t, s, y, b, a]), P = ie(async () => {
780
+ }, [t, i, f, b, a]), R = re(async () => {
781
781
  if (b != null && b.id)
782
782
  try {
783
- g(!0), A(null);
784
- const l = new ne(t), M = await new ue(l, b.appId).getTenantSettings(b.id);
785
- R(M);
786
- } catch (l) {
787
- const H = l instanceof Error ? l : new Error("Failed to load tenant settings");
788
- A(H), R(null);
783
+ h(!0), k(null);
784
+ const c = new ie(t), E = await new pe(c, b.appId).getTenantSettings(b.id);
785
+ L(E);
786
+ } catch (c) {
787
+ const $ = c instanceof Error ? c : new Error("Failed to load tenant settings");
788
+ k($), L(null);
789
789
  } finally {
790
- g(!1);
790
+ h(!1);
791
791
  }
792
- }, [t, b]), O = ie(() => {
793
- P();
794
- }, [P]), c = ie(
795
- (l) => {
796
- if (!E)
792
+ }, [t, b]), B = re(() => {
793
+ R();
794
+ }, [R]), l = re(
795
+ (c) => {
796
+ if (!I)
797
797
  return { isValid: !0, errors: [] };
798
- const H = [];
798
+ const $ = [];
799
799
  try {
800
- return E.properties && Object.entries(E.properties).forEach(([M, h]) => {
801
- var w;
802
- const u = l[M];
803
- if ((w = E.required) != null && w.includes(M) && u == null) {
804
- H.push(`Field '${M}' is required`);
800
+ return I.properties && Object.entries(I.properties).forEach(([E, y]) => {
801
+ var S;
802
+ const m = c[E];
803
+ if ((S = I.required) != null && S.includes(E) && m == null) {
804
+ $.push(`Field '${E}' is required`);
805
805
  return;
806
806
  }
807
- if (u != null) {
808
- if (h.type) {
809
- const _ = h.type, K = typeof u;
810
- _ === "string" && K !== "string" ? H.push(`Field '${M}' must be a string`) : (_ === "number" || _ === "integer") && K !== "number" ? H.push(`Field '${M}' must be a number`) : _ === "boolean" && K !== "boolean" ? H.push(`Field '${M}' must be a boolean`) : _ === "array" && !Array.isArray(u) && H.push(`Field '${M}' must be an array`);
807
+ if (m != null) {
808
+ if (y.type) {
809
+ const G = y.type, J = typeof m;
810
+ G === "string" && J !== "string" ? $.push(`Field '${E}' must be a string`) : (G === "number" || G === "integer") && J !== "number" ? $.push(`Field '${E}' must be a number`) : G === "boolean" && J !== "boolean" ? $.push(`Field '${E}' must be a boolean`) : G === "array" && !Array.isArray(m) && $.push(`Field '${E}' must be an array`);
811
811
  }
812
- h.minLength !== void 0 && typeof u == "string" && u.length < h.minLength && H.push(
813
- `Field '${M}' must be at least ${h.minLength} characters long`
814
- ), h.maxLength !== void 0 && typeof u == "string" && u.length > h.maxLength && H.push(
815
- `Field '${M}' must be no more than ${h.maxLength} characters long`
816
- ), h.minimum !== void 0 && typeof u == "number" && u < h.minimum && H.push(`Field '${M}' must be at least ${h.minimum}`), h.maximum !== void 0 && typeof u == "number" && u > h.maximum && H.push(`Field '${M}' must be no more than ${h.maximum}`), h.pattern && typeof u == "string" && (new RegExp(h.pattern).test(u) || H.push(`Field '${M}' does not match the required pattern`)), h.enum && !h.enum.includes(u) && H.push(`Field '${M}' must be one of: ${h.enum.join(", ")}`);
812
+ y.minLength !== void 0 && typeof m == "string" && m.length < y.minLength && $.push(
813
+ `Field '${E}' must be at least ${y.minLength} characters long`
814
+ ), y.maxLength !== void 0 && typeof m == "string" && m.length > y.maxLength && $.push(
815
+ `Field '${E}' must be no more than ${y.maxLength} characters long`
816
+ ), y.minimum !== void 0 && typeof m == "number" && m < y.minimum && $.push(`Field '${E}' must be at least ${y.minimum}`), y.maximum !== void 0 && typeof m == "number" && m > y.maximum && $.push(`Field '${E}' must be no more than ${y.maximum}`), y.pattern && typeof m == "string" && (new RegExp(y.pattern).test(m) || $.push(`Field '${E}' does not match the required pattern`)), y.enum && !y.enum.includes(m) && $.push(`Field '${E}' must be one of: ${y.enum.join(", ")}`);
817
817
  }
818
818
  }), {
819
- isValid: H.length === 0,
820
- errors: H
819
+ isValid: $.length === 0,
820
+ errors: $
821
821
  };
822
822
  } catch {
823
823
  return {
@@ -826,401 +826,401 @@ function Yt({ config: i, children: e }) {
826
826
  };
827
827
  }
828
828
  },
829
- [E]
829
+ [I]
830
830
  );
831
- re(() => {
832
- !i.initialTenant && a ? b ? D() : U(a) : !i.initialTenant && !a && (p(null), I(null), f(!1));
833
- }, [i.initialTenant, a, b, U, D]), re(() => {
834
- b != null && b.id ? P() : (R(null), A(null), g(!1));
835
- }, [b == null ? void 0 : b.id, P]);
836
- const L = ie(
837
- (l, H) => {
838
- const { mode: M = "reload", tokens: h, redirectPath: u } = H || {}, w = i.tenantMode || "selector";
839
- if (localStorage.setItem("tenant", l), w === "subdomain") {
840
- const _ = window.location.hostname, K = at(
841
- l,
842
- _,
843
- i.baseDomain
831
+ X(() => {
832
+ !r.initialTenant && a ? b ? C() : U(a) : !r.initialTenant && !a && (u(null), M(null), g(!1));
833
+ }, [r.initialTenant, a, b, U, C]), X(() => {
834
+ b != null && b.id ? R() : (L(null), k(null), h(!1));
835
+ }, [b == null ? void 0 : b.id, R]);
836
+ const N = re(
837
+ (c, $) => {
838
+ const { mode: E = "reload", tokens: y, redirectPath: m } = $ || {}, S = r.tenantMode || "selector";
839
+ if (localStorage.setItem("tenant", c), S === "subdomain") {
840
+ const G = window.location.hostname, J = ft(
841
+ c,
842
+ G,
843
+ r.baseDomain
844
844
  );
845
- if (!K) {
845
+ if (!J) {
846
846
  console.warn(
847
847
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
848
- _
848
+ G
849
849
  );
850
850
  return;
851
851
  }
852
- const B = u || window.location.pathname, q = new URL(`${window.location.protocol}//${K}${B}`);
853
- new URLSearchParams(window.location.search).forEach((v, J) => {
854
- J !== le && q.searchParams.set(J, v);
855
- }), h && q.searchParams.set(le, De(h)), window.location.href = q.toString();
856
- } else if (w === "selector") {
857
- const _ = u || window.location.pathname, K = new URLSearchParams(window.location.search);
858
- if (K.set(i.selectorParam || "tenant", l), K.delete(le), h && K.set(le, De(h)), M === "reload") {
859
- const B = `${_}?${K.toString()}${window.location.hash}`;
860
- window.location.href = B;
852
+ const q = m || window.location.pathname, O = new URL(`${window.location.protocol}//${J}${q}`);
853
+ new URLSearchParams(window.location.search).forEach((T, Z) => {
854
+ Z !== de && O.searchParams.set(Z, T);
855
+ }), y && O.searchParams.set(de, $e(y)), window.location.href = O.toString();
856
+ } else if (S === "selector") {
857
+ const G = m || window.location.pathname, J = new URLSearchParams(window.location.search);
858
+ if (J.set(r.selectorParam || "tenant", c), J.delete(de), y && J.set(de, $e(y)), E === "reload") {
859
+ const q = `${G}?${J.toString()}${window.location.hash}`;
860
+ window.location.href = q;
861
861
  } else {
862
- const B = `${_}?${K.toString()}${window.location.hash}`;
863
- window.history.pushState({}, "", B), m(l), U(l);
862
+ const q = `${G}?${J.toString()}${window.location.hash}`;
863
+ window.history.pushState({}, "", q), p(c), U(c);
864
864
  }
865
865
  }
866
866
  },
867
- [i.tenantMode, i.selectorParam, i.baseDomain, U]
868
- ), F = te(() => ({
867
+ [r.tenantMode, r.selectorParam, r.baseDomain, U]
868
+ ), D = K(() => ({
869
869
  // Tenant info
870
870
  tenant: b,
871
871
  tenantSlug: a,
872
- isTenantLoading: S,
873
- tenantError: T,
872
+ isTenantLoading: w,
873
+ tenantError: v,
874
874
  retryTenant: () => {
875
875
  a && U(a);
876
876
  },
877
877
  // Settings
878
- settings: C,
879
- settingsSchema: E,
880
- isSettingsLoading: x,
881
- settingsError: $,
878
+ settings: F,
879
+ settingsSchema: I,
880
+ isSettingsLoading: P,
881
+ settingsError: x,
882
882
  // Actions
883
- refreshSettings: O,
884
- switchTenant: L,
883
+ refreshSettings: B,
884
+ switchTenant: N,
885
885
  // Validation
886
- validateSettings: c
886
+ validateSettings: l
887
887
  }), [
888
888
  b,
889
889
  a,
890
- S,
891
- T,
892
- C,
893
- E,
890
+ w,
891
+ v,
892
+ F,
893
+ I,
894
+ P,
894
895
  x,
895
- $,
896
- O,
897
- L,
898
- c
896
+ B,
897
+ N,
898
+ l
899
899
  ]);
900
- return /* @__PURE__ */ n(Ae.Provider, { value: F, children: e });
900
+ return /* @__PURE__ */ s(Ie.Provider, { value: D, children: e });
901
901
  }
902
- function ye() {
903
- const i = se(Ae);
904
- if (!i)
902
+ function ue() {
903
+ const r = oe(Ie);
904
+ if (!r)
905
905
  throw new Error("useTenant must be used within a TenantProvider");
906
- return i;
906
+ return r;
907
907
  }
908
- function we() {
909
- return se(Ae);
908
+ function Se() {
909
+ return oe(Ie);
910
910
  }
911
- const Qt = ye;
912
- function Xt() {
913
- const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = ye();
911
+ const gn = ue;
912
+ function pn() {
913
+ const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: i } = ue();
914
914
  return {
915
- settings: i,
915
+ settings: r,
916
916
  settingsSchema: e,
917
917
  isLoading: t,
918
- error: r,
919
- validateSettings: s
918
+ error: n,
919
+ validateSettings: i
920
920
  };
921
921
  }
922
- function ce() {
923
- const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = ye();
922
+ function he() {
923
+ const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: i } = ue();
924
924
  return {
925
- tenant: i,
925
+ tenant: r,
926
926
  tenantSlug: e,
927
927
  isLoading: t,
928
- error: r,
929
- retry: s
928
+ error: n,
929
+ retry: i
930
930
  };
931
931
  }
932
- const Pe = he(null);
933
- function Zt({ config: i = {}, children: e }) {
934
- const { appId: t, baseUrl: r } = ge(), { tenant: s, tenantSlug: o, switchTenant: a } = ye(), [m, y] = k(i.initialRoles || []), [b, p] = k(!i.initialRoles), [S, f] = k(null), [T, I] = k(!1), [C, R] = k(null), [x, g] = k(0), [$, A] = k(() => {
932
+ const Me = me(null);
933
+ function fn({ config: r = {}, children: e }) {
934
+ const { appId: t, baseUrl: n } = ye(), { tenant: i, tenantSlug: o, switchTenant: a } = ue(), [p, f] = A(r.initialRoles || []), [b, u] = A(!r.initialRoles), [w, g] = A(null), [v, M] = A(!1), [F, L] = A(null), [P, h] = A(0), [x, k] = A(() => {
935
935
  try {
936
- const v = localStorage.getItem("userTenants");
937
- return v ? JSON.parse(v) : [];
936
+ const T = localStorage.getItem("userTenants");
937
+ return T ? JSON.parse(T) : [];
938
938
  } catch {
939
939
  return [];
940
940
  }
941
- }), [E, U] = k(!1), D = Ue({ done: !1, urlTokens: null });
942
- D.current.done || (D.current.done = !0, D.current.urlTokens = ct(), D.current.urlTokens && console.log(
941
+ }), [I, U] = A(!1), C = ze({ done: !1, urlTokens: null });
942
+ C.current.done || (C.current.done = !0, C.current.urlTokens = yt(), C.current.urlTokens && console.log(
943
943
  "[AuthProvider] SYNC: URL tokens found, will block isAuthReady until user loaded"
944
944
  ));
945
- const [P, O] = k(() => {
946
- const v = D.current.urlTokens !== null;
947
- return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", v), v;
948
- }), c = te(() => {
949
- const v = new ke({
945
+ const [R, B] = A(() => {
946
+ const T = C.current.urlTokens !== null;
947
+ return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", T), T;
948
+ }), l = K(() => {
949
+ const T = new Ae({
950
950
  tenantSlug: o,
951
- onRefreshFailed: i.onRefreshFailed,
952
- baseUrl: r
951
+ onRefreshFailed: r.onRefreshFailed,
952
+ baseUrl: n
953
953
  });
954
- return D.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), v.setTokens({
955
- accessToken: D.current.urlTokens.accessToken,
956
- refreshToken: D.current.urlTokens.refreshToken,
957
- expiresIn: D.current.urlTokens.expiresIn
958
- }), console.log("[AuthProvider] SYNC: Session valid:", v.hasValidSession())), v;
959
- }, [o, r, i.onRefreshFailed]), L = D.current.done && !P, F = te(() => {
960
- const v = new ne(r);
961
- return v.setSessionManager(c), v;
962
- }, [r, c]), l = te(() => new rt(new ne(r)), [r]), H = te(() => new nt(F, c), [F, c]), M = te(() => new Ce(new ne(r)), [r]), h = te(() => S || c.getUser(), [S, c]), u = te(() => h != null && h.roleId && m.find((v) => v.id === h.roleId) || null, [h, m]), w = te(() => (u == null ? void 0 : u.permissions) || [], [u]), _ = te(() => c.hasValidSession() && S !== null, [c, S]), K = 5 * 60 * 1e3, B = te(() => {
963
- const v = async (N = !1) => {
954
+ return C.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), T.setTokens({
955
+ accessToken: C.current.urlTokens.accessToken,
956
+ refreshToken: C.current.urlTokens.refreshToken,
957
+ expiresIn: C.current.urlTokens.expiresIn
958
+ }), console.log("[AuthProvider] SYNC: Session valid:", T.hasValidSession())), T;
959
+ }, [o, n, r.onRefreshFailed]), N = C.current.done && !R, D = K(() => {
960
+ const T = new ie(n);
961
+ return T.setSessionManager(l), T;
962
+ }, [n, l]), c = K(() => new dt(new ie(n)), [n]), $ = K(() => new ut(D, l), [D, l]), E = K(() => new De(new ie(n)), [n]), y = K(() => w || l.getUser(), [w, l]), m = K(() => y != null && y.roleId && p.find((T) => T.id === y.roleId) || null, [y, p]), S = K(() => (m == null ? void 0 : m.permissions) || [], [m]), G = K(() => l.hasValidSession() && w !== null, [l, w]), J = 5 * 60 * 1e3, q = K(() => {
963
+ const T = async (H = !1) => {
964
964
  try {
965
- if (!c.hasValidSession())
965
+ if (!l.hasValidSession())
966
966
  return;
967
967
  const z = Date.now();
968
- if (!N && z - x < K && S)
968
+ if (!H && z - P < J && w)
969
969
  return;
970
- const W = c.getUserId();
970
+ const W = l.getUserId();
971
971
  if (!W) {
972
972
  console.warn("[AuthProvider] No userId available in token or storage");
973
973
  return;
974
974
  }
975
- I(!0), R(null);
976
- const Q = await H.getUserById(W);
977
- f(Q), c.setUser(Q), g(Date.now());
975
+ M(!0), L(null);
976
+ const Q = await $.getUserById(W);
977
+ g(Q), l.setUser(Q), h(Date.now());
978
978
  } catch (z) {
979
979
  const Y = z instanceof Error ? z : new Error("Failed to load user data");
980
- R(Y), console.error("[AuthProvider] Failed to load user data:", Y);
980
+ L(Y), console.error("[AuthProvider] Failed to load user data:", Y);
981
981
  } finally {
982
- I(!1);
982
+ M(!1);
983
983
  }
984
- }, J = async () => {
985
- await v();
986
- }, ae = async (N) => {
987
- var Le;
988
- const { username: z, password: Y, tenantSlug: W, redirectPath: Q } = N;
989
- let X = s == null ? void 0 : s.id, Z = o, ee = c;
990
- W && (X = (await new ue(F, t).getPublicTenantInfo(W)).id, Z = W);
991
- const G = await l.login({
984
+ }, Z = async () => {
985
+ await T();
986
+ }, ce = async (H) => {
987
+ var Ne;
988
+ const { username: z, password: Y, tenantSlug: W, redirectPath: Q } = H;
989
+ let ee = i == null ? void 0 : i.id, te = o, ne = l;
990
+ W && (ee = (await new pe(D, t).getPublicTenantInfo(W)).id, te = W);
991
+ const j = await c.login({
992
992
  username: z,
993
993
  password: Y,
994
994
  appId: t,
995
- tenantId: X
996
- }), de = W && W !== o;
997
- if (de && (ee = new ke({
998
- tenantSlug: Z,
999
- baseUrl: r
1000
- })), ee.setTokens({
1001
- accessToken: G.accessToken,
1002
- refreshToken: G.refreshToken,
1003
- expiresIn: G.expiresIn
1004
- }), G.user) {
1005
- ee.setUser(G.user), f(G.user);
995
+ tenantId: ee
996
+ }), ge = W && W !== o;
997
+ if (ge && (ne = new Ae({
998
+ tenantSlug: te,
999
+ baseUrl: n
1000
+ })), ne.setTokens({
1001
+ accessToken: j.accessToken,
1002
+ refreshToken: j.refreshToken,
1003
+ expiresIn: j.expiresIn
1004
+ }), j.user) {
1005
+ ne.setUser(j.user), g(j.user);
1006
1006
  try {
1007
- await v();
1008
- } catch (pe) {
1009
- console.warn("Failed to load complete user data after login:", pe);
1007
+ await T();
1008
+ } catch (we) {
1009
+ console.warn("Failed to load complete user data after login:", we);
1010
1010
  }
1011
1011
  }
1012
- if (G.tenants && G.tenants.length > 0) {
1013
- A(G.tenants);
1012
+ if (j.tenants && j.tenants.length > 0) {
1013
+ k(j.tenants);
1014
1014
  try {
1015
- localStorage.setItem("userTenants", JSON.stringify(G.tenants));
1015
+ localStorage.setItem("userTenants", JSON.stringify(j.tenants));
1016
1016
  } catch {
1017
1017
  }
1018
1018
  }
1019
- const ve = ((Le = G.user) == null ? void 0 : Le.tenantId) !== null;
1020
- if (U(ve), de && Z && Z !== o && a(Z, {
1019
+ const ke = ((Ne = j.user) == null ? void 0 : Ne.tenantId) !== null;
1020
+ if (U(ke), ge && te && te !== o && a(te, {
1021
1021
  tokens: {
1022
- accessToken: G.accessToken,
1023
- refreshToken: G.refreshToken,
1024
- expiresIn: G.expiresIn
1022
+ accessToken: j.accessToken,
1023
+ refreshToken: j.refreshToken,
1024
+ expiresIn: j.expiresIn
1025
1025
  },
1026
1026
  redirectPath: Q
1027
- }), !ve && G.tenants && G.tenants.length > 0) {
1028
- const pe = N.autoSwitch !== !1 && i.autoSwitchSingleTenant !== !1;
1029
- if (G.tenants.length === 1 && pe) {
1030
- const Ee = G.tenants[0];
1031
- a(Ee.subdomain, {
1027
+ }), !ke && j.tenants && j.tenants.length > 0) {
1028
+ const we = H.autoSwitch !== !1 && r.autoSwitchSingleTenant !== !1;
1029
+ if (j.tenants.length === 1 && we) {
1030
+ const Ue = j.tenants[0];
1031
+ a(Ue.subdomain, {
1032
1032
  tokens: {
1033
- accessToken: G.accessToken,
1034
- refreshToken: G.refreshToken,
1035
- expiresIn: G.expiresIn
1033
+ accessToken: j.accessToken,
1034
+ refreshToken: j.refreshToken,
1035
+ expiresIn: j.expiresIn
1036
1036
  },
1037
1037
  redirectPath: Q
1038
1038
  });
1039
- } else G.tenants.length > 1 && i.onTenantSelectionRequired && i.onTenantSelectionRequired(G.tenants);
1039
+ } else j.tenants.length > 1 && r.onTenantSelectionRequired && r.onTenantSelectionRequired(j.tenants);
1040
1040
  }
1041
- return G;
1042
- }, be = async (N) => {
1043
- const { email: z, phoneNumber: Y, name: W, password: Q, lastName: X, tenantId: Z } = N;
1041
+ return j;
1042
+ }, ve = async (H) => {
1043
+ const { email: z, phoneNumber: Y, name: W, password: Q, lastName: ee, tenantId: te } = H;
1044
1044
  if (!z && !Y)
1045
1045
  throw new Error("Either email or phoneNumber is required");
1046
1046
  if (!W || !Q)
1047
1047
  throw new Error("Name and password are required");
1048
- const ee = Z ?? (s == null ? void 0 : s.id);
1049
- return await l.signup({
1048
+ const ne = te ?? (i == null ? void 0 : i.id);
1049
+ return await c.signup({
1050
1050
  email: z,
1051
1051
  phoneNumber: Y,
1052
1052
  name: W,
1053
1053
  password: Q,
1054
- tenantId: ee,
1055
- lastName: X,
1054
+ tenantId: ne,
1055
+ lastName: ee,
1056
1056
  appId: t
1057
1057
  });
1058
- }, We = async (N) => {
1059
- const { email: z, phoneNumber: Y, name: W, password: Q, tenantName: X, lastName: Z } = N;
1058
+ }, Ke = async (H) => {
1059
+ const { email: z, phoneNumber: Y, name: W, password: Q, tenantName: ee, lastName: te } = H;
1060
1060
  if (!z && !Y)
1061
1061
  throw new Error("Either email or phoneNumber is required");
1062
- if (!W || !Q || !X)
1062
+ if (!W || !Q || !ee)
1063
1063
  throw new Error("Name, password, and tenantName are required");
1064
- return await l.signupTenantAdmin({
1064
+ return await c.signupTenantAdmin({
1065
1065
  email: z,
1066
1066
  phoneNumber: Y,
1067
1067
  name: W,
1068
1068
  password: Q,
1069
- tenantName: X,
1069
+ tenantName: ee,
1070
1070
  appId: t,
1071
- lastName: Z
1071
+ lastName: te
1072
1072
  });
1073
- }, je = async (N) => {
1074
- const { currentPassword: z, newPassword: Y } = N, W = await c.getAuthHeaders();
1075
- await l.changePassword({ currentPassword: z, newPassword: Y }, W);
1076
- }, Ve = async (N) => {
1077
- const { email: z, tenantId: Y } = N, W = Y ?? (s == null ? void 0 : s.id);
1073
+ }, Je = async (H) => {
1074
+ const { currentPassword: z, newPassword: Y } = H, W = await l.getAuthHeaders();
1075
+ await c.changePassword({ currentPassword: z, newPassword: Y }, W);
1076
+ }, Ye = async (H) => {
1077
+ const { email: z, tenantId: Y } = H, W = Y ?? (i == null ? void 0 : i.id);
1078
1078
  if (!W)
1079
1079
  throw new Error("tenantId is required for password reset");
1080
- await l.requestPasswordReset({ email: z, tenantId: W });
1081
- }, Ge = async (N) => {
1082
- const { token: z, newPassword: Y } = N;
1083
- await l.confirmPasswordReset({ token: z, newPassword: Y });
1084
- }, _e = async (N) => {
1085
- const { email: z, frontendUrl: Y, name: W, lastName: Q, tenantId: X } = N, Z = X ?? (s == null ? void 0 : s.id);
1086
- if (!Z)
1080
+ await c.requestPasswordReset({ email: z, tenantId: W });
1081
+ }, Qe = async (H) => {
1082
+ const { token: z, newPassword: Y } = H;
1083
+ await c.confirmPasswordReset({ token: z, newPassword: Y });
1084
+ }, Xe = async (H) => {
1085
+ const { email: z, frontendUrl: Y, name: W, lastName: Q, tenantId: ee } = H, te = ee ?? (i == null ? void 0 : i.id);
1086
+ if (!te)
1087
1087
  throw new Error("tenantId is required for magic link authentication");
1088
- return await l.sendMagicLink({
1088
+ return await c.sendMagicLink({
1089
1089
  email: z,
1090
- tenantId: Z,
1090
+ tenantId: te,
1091
1091
  frontendUrl: Y,
1092
1092
  name: W,
1093
1093
  lastName: Q,
1094
1094
  appId: t
1095
1095
  });
1096
- }, Je = async (N) => {
1097
- const { token: z, email: Y, tenantSlug: W } = N;
1098
- let Q = s == null ? void 0 : s.id, X = o, Z = c;
1099
- W && (Q = (await new ue(F, t).getPublicTenantInfo(W)).id, X = W);
1100
- const ee = await l.verifyMagicLink({
1096
+ }, et = async (H) => {
1097
+ const { token: z, email: Y, tenantSlug: W } = H;
1098
+ let Q = i == null ? void 0 : i.id, ee = o, te = l;
1099
+ W && (Q = (await new pe(D, t).getPublicTenantInfo(W)).id, ee = W);
1100
+ const ne = await c.verifyMagicLink({
1101
1101
  token: z,
1102
1102
  email: Y,
1103
1103
  appId: t,
1104
1104
  tenantId: Q
1105
- }), G = W && W !== o;
1106
- if (G && (Z = new ke({
1107
- tenantSlug: X,
1108
- baseUrl: r
1109
- })), Z.setTokens({
1110
- accessToken: ee.accessToken,
1111
- refreshToken: ee.refreshToken,
1112
- expiresIn: ee.expiresIn
1113
- }), ee.user) {
1114
- Z.setUser(ee.user), f(ee.user);
1105
+ }), j = W && W !== o;
1106
+ if (j && (te = new Ae({
1107
+ tenantSlug: ee,
1108
+ baseUrl: n
1109
+ })), te.setTokens({
1110
+ accessToken: ne.accessToken,
1111
+ refreshToken: ne.refreshToken,
1112
+ expiresIn: ne.expiresIn
1113
+ }), ne.user) {
1114
+ te.setUser(ne.user), g(ne.user);
1115
1115
  try {
1116
- await v();
1117
- } catch (de) {
1118
- console.warn("Failed to load complete user data after magic link login:", de);
1116
+ await T();
1117
+ } catch (ge) {
1118
+ console.warn("Failed to load complete user data after magic link login:", ge);
1119
1119
  }
1120
1120
  }
1121
- return G && X && X !== o && a(X, {
1121
+ return j && ee && ee !== o && a(ee, {
1122
1122
  tokens: {
1123
- accessToken: ee.accessToken,
1124
- refreshToken: ee.refreshToken,
1125
- expiresIn: ee.expiresIn
1123
+ accessToken: ne.accessToken,
1124
+ refreshToken: ne.refreshToken,
1125
+ expiresIn: ne.expiresIn
1126
1126
  }
1127
- }), ee;
1128
- }, Ke = async () => {
1129
- const N = c.getTokens();
1130
- if (!(N != null && N.refreshToken))
1127
+ }), ne;
1128
+ }, tt = async () => {
1129
+ const H = l.getTokens();
1130
+ if (!(H != null && H.refreshToken))
1131
1131
  throw new Error("No refresh token available");
1132
- const z = await l.refreshToken({
1133
- refreshToken: N.refreshToken
1132
+ const z = await c.refreshToken({
1133
+ refreshToken: H.refreshToken
1134
1134
  });
1135
- c.setTokens({
1135
+ l.setTokens({
1136
1136
  accessToken: z.accessToken,
1137
- refreshToken: z.refreshToken || N.refreshToken,
1137
+ refreshToken: z.refreshToken || H.refreshToken,
1138
1138
  expiresIn: z.expiresIn
1139
1139
  });
1140
- }, Ye = () => {
1141
- c.clearSession(), f(null), R(null), A([]), U(!1);
1140
+ }, nt = () => {
1141
+ l.clearSession(), g(null), L(null), k([]), U(!1);
1142
1142
  try {
1143
1143
  localStorage.removeItem("userTenants");
1144
1144
  } catch {
1145
1145
  }
1146
- }, Qe = (N) => {
1147
- c.setTokens(N);
1148
- }, Xe = () => c.hasValidSession(), Ze = () => {
1149
- c.clearSession(), f(null), R(null);
1150
- }, et = async () => {
1146
+ }, rt = (H) => {
1147
+ l.setTokens(H);
1148
+ }, st = () => l.hasValidSession(), it = () => {
1149
+ l.clearSession(), g(null), L(null);
1150
+ }, ot = async () => {
1151
1151
  if (t)
1152
1152
  try {
1153
- p(!0);
1154
- const { roles: N } = await M.getRolesByApp(t);
1155
- y(N);
1156
- } catch (N) {
1157
- console.error("Failed to fetch roles:", N);
1153
+ u(!0);
1154
+ const { roles: H } = await E.getRolesByApp(t);
1155
+ f(H);
1156
+ } catch (H) {
1157
+ console.error("Failed to fetch roles:", H);
1158
1158
  } finally {
1159
- p(!1);
1159
+ u(!1);
1160
1160
  }
1161
- }, tt = async () => {
1162
- await et();
1163
- }, Se = (N) => {
1164
- if (!w || w.length === 0)
1161
+ }, at = async () => {
1162
+ await ot();
1163
+ }, Te = (H) => {
1164
+ if (!S || S.length === 0)
1165
1165
  return !1;
1166
- if (typeof N == "string")
1167
- return w.includes(N);
1168
- const z = `${N.resource}.${N.action}`;
1169
- return w.includes(z);
1166
+ if (typeof H == "string")
1167
+ return S.includes(H);
1168
+ const z = `${H.resource}.${H.action}`;
1169
+ return S.includes(z);
1170
1170
  };
1171
1171
  return {
1172
1172
  // RFC-003: Authentication state
1173
- isAuthenticated: _,
1174
- sessionManager: c,
1175
- authenticatedHttpService: F,
1176
- login: ae,
1177
- signup: be,
1178
- signupTenantAdmin: We,
1179
- sendMagicLink: _e,
1180
- verifyMagicLink: Je,
1181
- changePassword: je,
1182
- requestPasswordReset: Ve,
1183
- confirmPasswordReset: Ge,
1184
- refreshToken: Ke,
1185
- logout: Ye,
1186
- setTokens: Qe,
1187
- hasValidSession: Xe,
1188
- clearSession: Ze,
1189
- currentUser: S,
1190
- isUserLoading: T,
1191
- userError: C,
1192
- loadUserData: v,
1193
- refreshUser: J,
1194
- isAuthInitializing: !L,
1195
- isAuthReady: L,
1196
- userRole: u,
1197
- userPermissions: w,
1198
- availableRoles: m,
1173
+ isAuthenticated: G,
1174
+ sessionManager: l,
1175
+ authenticatedHttpService: D,
1176
+ login: ce,
1177
+ signup: ve,
1178
+ signupTenantAdmin: Ke,
1179
+ sendMagicLink: Xe,
1180
+ verifyMagicLink: et,
1181
+ changePassword: Je,
1182
+ requestPasswordReset: Ye,
1183
+ confirmPasswordReset: Qe,
1184
+ refreshToken: tt,
1185
+ logout: nt,
1186
+ setTokens: rt,
1187
+ hasValidSession: st,
1188
+ clearSession: it,
1189
+ currentUser: w,
1190
+ isUserLoading: v,
1191
+ userError: F,
1192
+ loadUserData: T,
1193
+ refreshUser: Z,
1194
+ isAuthInitializing: !N,
1195
+ isAuthReady: N,
1196
+ userRole: m,
1197
+ userPermissions: S,
1198
+ availableRoles: p,
1199
1199
  rolesLoading: b,
1200
- hasPermission: Se,
1201
- hasAnyPermission: (N) => N.some((z) => Se(z)),
1202
- hasAllPermissions: (N) => N.every((z) => Se(z)),
1203
- getUserPermissionStrings: () => w || [],
1204
- refreshRoles: tt,
1200
+ hasPermission: Te,
1201
+ hasAnyPermission: (H) => H.some((z) => Te(z)),
1202
+ hasAllPermissions: (H) => H.every((z) => Te(z)),
1203
+ getUserPermissionStrings: () => S || [],
1204
+ refreshRoles: at,
1205
1205
  // RFC-004: Multi-tenant user membership
1206
- userTenants: $,
1207
- hasTenantContext: E,
1208
- switchToTenant: async (N, z) => {
1209
- const { redirectPath: Y } = z || {}, W = c.getTokens();
1206
+ userTenants: x,
1207
+ hasTenantContext: I,
1208
+ switchToTenant: async (H, z) => {
1209
+ const { redirectPath: Y } = z || {}, W = l.getTokens();
1210
1210
  if (!(W != null && W.refreshToken))
1211
1211
  throw new Error("No refresh token available for tenant switch");
1212
- const Q = await l.switchTenant({
1212
+ const Q = await c.switchTenant({
1213
1213
  refreshToken: W.refreshToken,
1214
- tenantId: N
1214
+ tenantId: H
1215
1215
  });
1216
- c.setTokens({
1216
+ l.setTokens({
1217
1217
  accessToken: Q.accessToken,
1218
1218
  refreshToken: W.refreshToken,
1219
1219
  // Keep the same refresh token
1220
1220
  expiresIn: Q.expiresIn
1221
- }), f(Q.user), c.setUser(Q.user), U(!0);
1222
- const X = $.find((Z) => Z.id === N);
1223
- X && a(X.subdomain, {
1221
+ }), g(Q.user), l.setUser(Q.user), U(!0);
1222
+ const ee = x.find((te) => te.id === H);
1223
+ ee && a(ee.subdomain, {
1224
1224
  tokens: {
1225
1225
  accessToken: Q.accessToken,
1226
1226
  refreshToken: W.refreshToken,
@@ -1230,8 +1230,8 @@ function Zt({ config: i = {}, children: e }) {
1230
1230
  });
1231
1231
  },
1232
1232
  refreshUserTenants: async () => {
1233
- const N = await c.getAuthHeaders(), z = await l.getUserTenants(N);
1234
- A(z);
1233
+ const H = await l.getAuthHeaders(), z = await c.getUserTenants(H);
1234
+ k(z);
1235
1235
  try {
1236
1236
  localStorage.setItem("userTenants", JSON.stringify(z));
1237
1237
  } catch {
@@ -1240,74 +1240,74 @@ function Zt({ config: i = {}, children: e }) {
1240
1240
  }
1241
1241
  };
1242
1242
  }, [
1243
- _,
1244
- c,
1245
- F,
1243
+ G,
1246
1244
  l,
1247
- H,
1248
- M,
1245
+ D,
1246
+ c,
1247
+ $,
1248
+ E,
1249
1249
  t,
1250
- s,
1250
+ i,
1251
1251
  o,
1252
1252
  a,
1253
- m,
1254
- S,
1255
- T,
1256
- C,
1257
- $,
1258
- E,
1259
- L,
1260
- u,
1253
+ p,
1261
1254
  w,
1255
+ v,
1256
+ F,
1262
1257
  x,
1263
- K
1258
+ I,
1259
+ N,
1260
+ m,
1261
+ S,
1262
+ P,
1263
+ J
1264
1264
  ]);
1265
- re(() => {
1266
- !i.initialRoles && t && (async () => {
1265
+ X(() => {
1266
+ !r.initialRoles && t && (async () => {
1267
1267
  try {
1268
- p(!0);
1269
- const J = new ne(r), ae = new Ce(J), { roles: be } = await ae.getRolesByApp(t);
1270
- y(be);
1271
- } catch (J) {
1272
- console.error("Failed to fetch roles:", J);
1268
+ u(!0);
1269
+ const Z = new ie(n), ce = new De(Z), { roles: ve } = await ce.getRolesByApp(t);
1270
+ f(ve);
1271
+ } catch (Z) {
1272
+ console.error("Failed to fetch roles:", Z);
1273
1273
  } finally {
1274
- p(!1);
1274
+ u(!1);
1275
1275
  }
1276
1276
  })();
1277
- }, [t, r, i.initialRoles]);
1278
- const [q, V] = k(!1);
1279
- return re(() => {
1280
- q || (V(!0), D.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), dt(), O(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), B.loadUserData().catch((v) => {
1281
- console.error("[AuthProvider] Failed to load user data:", v);
1277
+ }, [t, n, r.initialRoles]);
1278
+ const [O, V] = A(!1);
1279
+ return X(() => {
1280
+ O || (V(!0), C.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), wt(), B(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), q.loadUserData().catch((T) => {
1281
+ console.error("[AuthProvider] Failed to load user data:", T);
1282
1282
  }).finally(() => {
1283
- console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), O(!1);
1283
+ console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), B(!1);
1284
1284
  })));
1285
- }, [B, q]), re(() => {
1286
- const v = c.getUser();
1287
- v && c.hasValidSession() && f(v);
1288
- }, [c]), re(() => {
1289
- q && (D.current.urlTokens || !S && !T && c.hasValidSession() && (console.log("[AuthProvider] Auto-loading user data..."), B.loadUserData().catch(() => {
1285
+ }, [q, O]), X(() => {
1286
+ const T = l.getUser();
1287
+ T && l.hasValidSession() && g(T);
1288
+ }, [l]), X(() => {
1289
+ O && (C.current.urlTokens || !w && !v && l.hasValidSession() && (console.log("[AuthProvider] Auto-loading user data..."), q.loadUserData().catch(() => {
1290
1290
  })));
1291
- }, [S, T, B, c, q]), re(() => {
1292
- if (!c.hasValidSession() || !S)
1291
+ }, [w, v, q, l, O]), X(() => {
1292
+ if (!l.hasValidSession() || !w)
1293
1293
  return;
1294
- const v = setInterval(() => {
1295
- B.loadUserData().catch(() => {
1294
+ const T = setInterval(() => {
1295
+ q.loadUserData().catch(() => {
1296
1296
  });
1297
- }, K);
1298
- return () => clearInterval(v);
1299
- }, [c, S, B, K]), /* @__PURE__ */ n(Pe.Provider, { value: B, children: e });
1297
+ }, J);
1298
+ return () => clearInterval(T);
1299
+ }, [l, w, q, J]), /* @__PURE__ */ s(Me.Provider, { value: q, children: e });
1300
1300
  }
1301
- function oe() {
1302
- const i = se(Pe);
1303
- if (!i)
1301
+ function le() {
1302
+ const r = oe(Me);
1303
+ if (!r)
1304
1304
  throw new Error("useAuth must be used within an AuthProvider");
1305
- return i;
1305
+ return r;
1306
1306
  }
1307
- function Me() {
1308
- return se(Pe);
1307
+ function Le() {
1308
+ return oe(Me);
1309
1309
  }
1310
- class ut {
1310
+ class bt {
1311
1311
  constructor(e, t) {
1312
1312
  this.httpService = e, this.sessionManager = t;
1313
1313
  }
@@ -1326,9 +1326,9 @@ class ut {
1326
1326
  async getFeatureFlags(e) {
1327
1327
  if (!this.sessionManager)
1328
1328
  throw new Error("SessionManager is required for private endpoints");
1329
- const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
1330
- e != null && e.page && r.append("page", e.page.toString()), e != null && e.limit && r.append("limit", e.limit.toString()), e != null && e.sortBy && r.append("sortBy", e.sortBy), e != null && e.sortOrder && r.append("sortOrder", e.sortOrder);
1331
- const s = `/feature-flags/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
1329
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
1330
+ e != null && e.page && n.append("page", e.page.toString()), e != null && e.limit && n.append("limit", e.limit.toString()), e != null && e.sortBy && n.append("sortBy", e.sortBy), e != null && e.sortOrder && n.append("sortOrder", e.sortOrder);
1331
+ const i = `/feature-flags/${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i, {
1332
1332
  headers: t
1333
1333
  });
1334
1334
  return {
@@ -1347,12 +1347,12 @@ class ut {
1347
1347
  async updateFeatureFlag(e, t) {
1348
1348
  if (!this.sessionManager)
1349
1349
  throw new Error("SessionManager is required for private endpoints");
1350
- const r = await this.sessionManager.getAuthHeaders();
1350
+ const n = await this.sessionManager.getAuthHeaders();
1351
1351
  return (await this.httpService.put(
1352
1352
  `/feature-flags/${e}`,
1353
1353
  t,
1354
1354
  {
1355
- headers: r
1355
+ headers: n
1356
1356
  }
1357
1357
  )).data;
1358
1358
  }
@@ -1368,85 +1368,85 @@ class ut {
1368
1368
  async getTenantFeatureFlags(e, t) {
1369
1369
  if (!e || !t)
1370
1370
  throw new Error("Tenant ID and App ID are required");
1371
- const r = new URLSearchParams();
1372
- r.append("tenantId", e), r.append("appId", t);
1373
- const s = `/tenant-feature-flags${r.toString() ? `?${r.toString()}` : ""}`;
1374
- return (await this.httpService.get(s, {
1371
+ const n = new URLSearchParams();
1372
+ n.append("tenantId", e), n.append("appId", t);
1373
+ const i = `/tenant-feature-flags${n.toString() ? `?${n.toString()}` : ""}`;
1374
+ return (await this.httpService.get(i, {
1375
1375
  headers: { "X-Tenant-ID": e }
1376
1376
  })).data;
1377
1377
  }
1378
1378
  // Public endpoint - no auth required
1379
- async getTenantFeatureFlag(e, t, r) {
1380
- if (!e || !t || !r)
1379
+ async getTenantFeatureFlag(e, t, n) {
1380
+ if (!e || !t || !n)
1381
1381
  throw new Error("Flag Key, Tenant ID and App ID are required");
1382
- const s = new URLSearchParams();
1383
- s.append("tenantId", t), s.append("appId", r);
1384
- const o = `/tenant-feature-flags/${e}${s.toString() ? `?${s.toString()}` : ""}`;
1382
+ const i = new URLSearchParams();
1383
+ i.append("tenantId", t), i.append("appId", n);
1384
+ const o = `/tenant-feature-flags/${e}${i.toString() ? `?${i.toString()}` : ""}`;
1385
1385
  return (await this.httpService.get(o, {
1386
1386
  headers: { "X-Tenant-ID": t }
1387
1387
  })).data;
1388
1388
  }
1389
1389
  }
1390
- const Ie = he(null);
1391
- function er({ config: i = {}, children: e }) {
1392
- const t = Be(), r = we(), s = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [m, y] = k([]), [b, p] = k(!1), [S, f] = k(null), [T, I] = k(!1), C = te(() => {
1393
- const g = new ne(s);
1394
- return new ut(g);
1395
- }, [s]), R = async () => {
1390
+ const Ee = me(null);
1391
+ function mn({ config: r = {}, children: e }) {
1392
+ const t = _e(), n = Se(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [p, f] = A([]), [b, u] = A(!1), [w, g] = A(null), [v, M] = A(!1), F = K(() => {
1393
+ const h = new ie(i);
1394
+ return new bt(h);
1395
+ }, [i]), L = async () => {
1396
1396
  if (!(a != null && a.id)) {
1397
- y([]);
1397
+ f([]);
1398
1398
  return;
1399
1399
  }
1400
- p(!0), f(null);
1400
+ u(!0), g(null);
1401
1401
  try {
1402
- const g = await C.getTenantFeatureFlags(a.id, o);
1403
- y(g);
1404
- } catch (g) {
1405
- const $ = g instanceof Error ? g.message : "Failed to fetch feature flags";
1406
- f($), i.onError && i.onError(g instanceof Error ? g : new Error($));
1402
+ const h = await F.getTenantFeatureFlags(a.id, o);
1403
+ f(h);
1404
+ } catch (h) {
1405
+ const x = h instanceof Error ? h.message : "Failed to fetch feature flags";
1406
+ g(x), r.onError && r.onError(h instanceof Error ? h : new Error(x));
1407
1407
  } finally {
1408
- p(!1);
1408
+ u(!1);
1409
1409
  }
1410
1410
  };
1411
- re(() => {
1412
- if (!s || !o) return;
1413
- R().finally(() => I(!0));
1414
- const g = i.refreshInterval || 5 * 60 * 1e3, $ = setInterval(R, g);
1415
- return () => clearInterval($);
1416
- }, [a == null ? void 0 : a.id, s, o, i.refreshInterval]);
1417
- const x = te(() => {
1418
- const g = (D) => {
1419
- const P = m.find((O) => O.key === D);
1420
- return (P == null ? void 0 : P.value) === !0;
1421
- }, $ = (D) => m.find((P) => P.key === D), A = (D) => {
1422
- const P = m.find((O) => O.key === D);
1423
- return P ? P.value ? "enabled" : "disabled" : "not_found";
1424
- }, E = async () => {
1425
- await R();
1426
- }, U = !!(s && o) && (T || !(a != null && a.id));
1411
+ X(() => {
1412
+ if (!i || !o) return;
1413
+ L().finally(() => M(!0));
1414
+ const h = r.refreshInterval || 5 * 60 * 1e3, x = setInterval(L, h);
1415
+ return () => clearInterval(x);
1416
+ }, [a == null ? void 0 : a.id, i, o, r.refreshInterval]);
1417
+ const P = K(() => {
1418
+ const h = (C) => {
1419
+ const R = p.find((B) => B.key === C);
1420
+ return (R == null ? void 0 : R.value) === !0;
1421
+ }, x = (C) => p.find((R) => R.key === C), k = (C) => {
1422
+ const R = p.find((B) => B.key === C);
1423
+ return R ? R.value ? "enabled" : "disabled" : "not_found";
1424
+ }, I = async () => {
1425
+ await L();
1426
+ }, U = !!(i && o) && (v || !(a != null && a.id));
1427
1427
  return {
1428
- featureFlags: m,
1428
+ featureFlags: p,
1429
1429
  loading: b,
1430
- error: S,
1430
+ error: w,
1431
1431
  isReady: U,
1432
- isEnabled: g,
1433
- getFlag: $,
1434
- getFlagState: A,
1435
- refresh: E
1432
+ isEnabled: h,
1433
+ getFlag: x,
1434
+ getFlagState: k,
1435
+ refresh: I
1436
1436
  };
1437
- }, [m, b, S, s, o, a == null ? void 0 : a.id, T]);
1438
- return /* @__PURE__ */ n(Ie.Provider, { value: x, children: e });
1437
+ }, [p, b, w, i, o, a == null ? void 0 : a.id, v]);
1438
+ return /* @__PURE__ */ s(Ee.Provider, { value: P, children: e });
1439
1439
  }
1440
- function ht() {
1441
- const i = se(Ie);
1442
- if (!i)
1440
+ function St() {
1441
+ const r = oe(Ee);
1442
+ if (!r)
1443
1443
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1444
- return i;
1444
+ return r;
1445
1445
  }
1446
- function qe() {
1447
- return se(Ie);
1446
+ function We() {
1447
+ return oe(Ee);
1448
1448
  }
1449
- class gt {
1449
+ class vt {
1450
1450
  constructor(e, t) {
1451
1451
  this.httpService = e, this.sessionManager = t;
1452
1452
  }
@@ -1476,23 +1476,23 @@ class gt {
1476
1476
  async updateSubscription(e, t) {
1477
1477
  if (!this.sessionManager)
1478
1478
  throw new Error("SessionManager is required for private endpoints");
1479
- const r = await this.sessionManager.getAuthHeaders();
1479
+ const n = await this.sessionManager.getAuthHeaders();
1480
1480
  return (await this.httpService.put(
1481
1481
  `/subscriptions/${e}`,
1482
1482
  t,
1483
1483
  {
1484
- headers: r
1484
+ headers: n
1485
1485
  }
1486
1486
  )).data;
1487
1487
  }
1488
1488
  async changeSubscriptionPlan(e, t) {
1489
1489
  if (!this.sessionManager)
1490
1490
  throw new Error("SessionManager is required for private endpoints");
1491
- const r = await this.sessionManager.getAuthHeaders();
1491
+ const n = await this.sessionManager.getAuthHeaders();
1492
1492
  return (await this.httpService.put(
1493
1493
  `/subscriptions/${e}/plan`,
1494
1494
  { planId: t },
1495
- { headers: r }
1495
+ { headers: n }
1496
1496
  )).data;
1497
1497
  }
1498
1498
  // Public endpoint - no auth required
@@ -1504,76 +1504,76 @@ class gt {
1504
1504
  async processPayment(e, t) {
1505
1505
  if (!this.sessionManager)
1506
1506
  throw new Error("SessionManager is required for private endpoints");
1507
- const r = await this.sessionManager.getAuthHeaders();
1507
+ const n = await this.sessionManager.getAuthHeaders();
1508
1508
  return (await this.httpService.post(
1509
1509
  `/subscriptions/${e}/process-payment`,
1510
1510
  t,
1511
- { headers: r }
1511
+ { headers: n }
1512
1512
  )).data;
1513
1513
  }
1514
1514
  }
1515
- const Re = he(void 0);
1516
- function tr({ config: i = {}, children: e }) {
1517
- const t = Be(), r = we(), s = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, m] = k(null), [y, b] = k(!1), [p, S] = k(null), [f, T] = k(!1), I = te(() => {
1518
- const x = new ne(s);
1519
- return new gt(x);
1520
- }, [s]), C = async () => {
1515
+ const Fe = me(void 0);
1516
+ function yn({ config: r = {}, children: e }) {
1517
+ const t = _e(), n = Se(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (n == null ? void 0 : n.tenant) ?? null, [a, p] = A(null), [f, b] = A(!1), [u, w] = A(null), [g, v] = A(!1), M = K(() => {
1518
+ const P = new ie(i);
1519
+ return new vt(P);
1520
+ }, [i]), F = async () => {
1521
1521
  if (!(o != null && o.id)) {
1522
- m(null);
1522
+ p(null);
1523
1523
  return;
1524
1524
  }
1525
- b(!0), S(null);
1525
+ b(!0), w(null);
1526
1526
  try {
1527
- const x = await I.getTenantSubscriptionFeatures(o.id);
1528
- m(x);
1529
- } catch (x) {
1530
- const g = x instanceof Error ? x.message : "Failed to fetch subscription";
1531
- S(g), i.onError && i.onError(x instanceof Error ? x : new Error(g));
1527
+ const P = await M.getTenantSubscriptionFeatures(o.id);
1528
+ p(P);
1529
+ } catch (P) {
1530
+ const h = P instanceof Error ? P.message : "Failed to fetch subscription";
1531
+ w(h), r.onError && r.onError(P instanceof Error ? P : new Error(h));
1532
1532
  } finally {
1533
1533
  b(!1);
1534
1534
  }
1535
1535
  };
1536
- re(() => {
1537
- if (!s || (C().finally(() => T(!0)), !i.refreshInterval)) return;
1538
- const x = i.refreshInterval || 10 * 60 * 1e3, g = setInterval(C, x);
1539
- return () => clearInterval(g);
1540
- }, [o == null ? void 0 : o.id, s, i.refreshInterval]);
1541
- const R = te(() => {
1542
- const x = (a == null ? void 0 : a.features) || [], g = (P) => {
1543
- const O = x.find((c) => c.key === P);
1544
- return O ? O.type === "BOOLEAN" || O.type === "boolean" ? O.value === !0 : !!O.value : !1;
1545
- }, $ = (P) => x.find((O) => O.key === P), A = (P, O) => {
1546
- const c = x.find((L) => L.key === P);
1547
- return c ? c.value : O;
1548
- }, E = (P) => !a || !a.isActive ? !1 : P.includes(a.planId), U = async () => {
1549
- await C();
1550
- }, D = !!s && (f || !(o != null && o.id));
1536
+ X(() => {
1537
+ if (!i || (F().finally(() => v(!0)), !r.refreshInterval)) return;
1538
+ const P = r.refreshInterval || 10 * 60 * 1e3, h = setInterval(F, P);
1539
+ return () => clearInterval(h);
1540
+ }, [o == null ? void 0 : o.id, i, r.refreshInterval]);
1541
+ const L = K(() => {
1542
+ const P = (a == null ? void 0 : a.features) || [], h = (R) => {
1543
+ const B = P.find((l) => l.key === R);
1544
+ return B ? B.type === "BOOLEAN" || B.type === "boolean" ? B.value === !0 : !!B.value : !1;
1545
+ }, x = (R) => P.find((B) => B.key === R), k = (R, B) => {
1546
+ const l = P.find((N) => N.key === R);
1547
+ return l ? l.value : B;
1548
+ }, I = (R) => !a || !a.isActive ? !1 : R.includes(a.planId), U = async () => {
1549
+ await F();
1550
+ }, C = !!i && (g || !(o != null && o.id));
1551
1551
  return {
1552
1552
  subscription: a,
1553
- features: x,
1554
- loading: y,
1555
- error: p,
1556
- isReady: D,
1557
- isFeatureEnabled: g,
1558
- getFeature: $,
1559
- getFeatureValue: A,
1560
- hasAllowedPlan: E,
1553
+ features: P,
1554
+ loading: f,
1555
+ error: u,
1556
+ isReady: C,
1557
+ isFeatureEnabled: h,
1558
+ getFeature: x,
1559
+ getFeatureValue: k,
1560
+ hasAllowedPlan: I,
1561
1561
  refresh: U
1562
1562
  };
1563
- }, [a, y, p, s, o == null ? void 0 : o.id, f]);
1564
- return /* @__PURE__ */ n(Re.Provider, { value: R, children: e });
1563
+ }, [a, f, u, i, o == null ? void 0 : o.id, g]);
1564
+ return /* @__PURE__ */ s(Fe.Provider, { value: L, children: e });
1565
1565
  }
1566
- function pt() {
1567
- const i = se(Re);
1568
- if (i === void 0)
1566
+ function Tt() {
1567
+ const r = oe(Fe);
1568
+ if (r === void 0)
1569
1569
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1570
- return i;
1570
+ return r;
1571
1571
  }
1572
- function ze() {
1573
- return se(Re) ?? null;
1572
+ function Ve() {
1573
+ return oe(Fe) ?? null;
1574
1574
  }
1575
- var fe = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(fe || {});
1576
- const $e = () => /* @__PURE__ */ d(
1575
+ var se = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(se || {});
1576
+ const He = () => /* @__PURE__ */ d(
1577
1577
  "div",
1578
1578
  {
1579
1579
  style: {
@@ -1589,10 +1589,10 @@ const $e = () => /* @__PURE__ */ d(
1589
1589
  margin: "20px 0"
1590
1590
  },
1591
1591
  children: [
1592
- /* @__PURE__ */ n("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "🔒" }),
1593
- /* @__PURE__ */ n("h3", { style: { color: "#495057", marginBottom: "10px" }, children: "Access Required" }),
1594
- /* @__PURE__ */ n("p", { style: { color: "#6c757d", fontSize: "14px", marginBottom: "15px" }, children: "You need to be signed in to view this content." }),
1595
- /* @__PURE__ */ n(
1592
+ /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "🔒" }),
1593
+ /* @__PURE__ */ s("h3", { style: { color: "#495057", marginBottom: "10px" }, children: "Access Required" }),
1594
+ /* @__PURE__ */ s("p", { style: { color: "#6c757d", fontSize: "14px", marginBottom: "15px" }, children: "You need to be signed in to view this content." }),
1595
+ /* @__PURE__ */ s(
1596
1596
  "button",
1597
1597
  {
1598
1598
  style: {
@@ -1610,8 +1610,8 @@ const $e = () => /* @__PURE__ */ d(
1610
1610
  )
1611
1611
  ]
1612
1612
  }
1613
- ), He = ({
1614
- userType: i,
1613
+ ), Be = ({
1614
+ userType: r,
1615
1615
  minUserType: e,
1616
1616
  missingPermissions: t
1617
1617
  }) => /* @__PURE__ */ d(
@@ -1630,57 +1630,57 @@ const $e = () => /* @__PURE__ */ d(
1630
1630
  margin: "20px 0"
1631
1631
  },
1632
1632
  children: [
1633
- /* @__PURE__ */ n("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1634
- /* @__PURE__ */ n("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1635
- e && i ? /* @__PURE__ */ d(j, { children: [
1633
+ /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1634
+ /* @__PURE__ */ s("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1635
+ e && r ? /* @__PURE__ */ d(_, { children: [
1636
1636
  /* @__PURE__ */ d("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1637
1637
  "This content requires ",
1638
- /* @__PURE__ */ n("strong", { children: e }),
1638
+ /* @__PURE__ */ s("strong", { children: e }),
1639
1639
  " access level or higher."
1640
1640
  ] }),
1641
1641
  /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1642
1642
  "Your current access level: ",
1643
- /* @__PURE__ */ n("strong", { children: i })
1643
+ /* @__PURE__ */ s("strong", { children: r })
1644
1644
  ] })
1645
- ] }) : /* @__PURE__ */ d(j, { children: [
1646
- /* @__PURE__ */ n("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1645
+ ] }) : /* @__PURE__ */ d(_, { children: [
1646
+ /* @__PURE__ */ s("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1647
1647
  t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1648
1648
  "Required permissions: ",
1649
- /* @__PURE__ */ n("strong", { children: t.join(", ") })
1649
+ /* @__PURE__ */ s("strong", { children: t.join(", ") })
1650
1650
  ] })
1651
1651
  ] })
1652
1652
  ]
1653
1653
  }
1654
- ), ft = (i, e) => {
1654
+ ), kt = (r, e) => {
1655
1655
  const t = {
1656
- [fe.USER]: 1,
1657
- [fe.TENANT_ADMIN]: 2,
1658
- [fe.SUPERUSER]: 3
1656
+ [se.USER]: 1,
1657
+ [se.TENANT_ADMIN]: 2,
1658
+ [se.SUPERUSER]: 3
1659
1659
  };
1660
- return t[i] >= t[e];
1660
+ return t[r] >= t[e];
1661
1661
  };
1662
- function rr({
1663
- children: i,
1662
+ function wn({
1663
+ children: r,
1664
1664
  fallback: e,
1665
1665
  minUserType: t,
1666
- requiredPermissions: r,
1667
- requireAllPermissions: s = !1
1666
+ requiredPermissions: n,
1667
+ requireAllPermissions: i = !1
1668
1668
  }) {
1669
- const { hasValidSession: o, sessionManager: a, hasPermission: m, hasAnyPermission: y, hasAllPermissions: b } = oe();
1669
+ const { hasValidSession: o, sessionManager: a, hasPermission: p, hasAnyPermission: f, hasAllPermissions: b } = le();
1670
1670
  if (!o())
1671
- return /* @__PURE__ */ n(j, { children: e || /* @__PURE__ */ n($e, {}) });
1672
- const p = a.getUser();
1673
- if (!p)
1674
- return /* @__PURE__ */ n(j, { children: e || /* @__PURE__ */ n($e, {}) });
1675
- if (t && !ft(p.userType, t))
1676
- return /* @__PURE__ */ n(He, { userType: p.userType, minUserType: t });
1677
- if (r && r.length > 0 && !(s ? b(r) : y(r))) {
1678
- const f = r.filter((T) => !m(T)).map((T) => typeof T == "string" ? T : T.name);
1679
- return /* @__PURE__ */ n(He, { missingPermissions: f });
1680
- }
1681
- return /* @__PURE__ */ n(j, { children: i });
1671
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(He, {}) });
1672
+ const u = a.getUser();
1673
+ if (!u)
1674
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(He, {}) });
1675
+ if (t && !kt(u.userType, t))
1676
+ return /* @__PURE__ */ s(Be, { userType: u.userType, minUserType: t });
1677
+ if (n && n.length > 0 && !(i ? b(n) : f(n))) {
1678
+ const g = n.filter((v) => !p(v)).map((v) => typeof v == "string" ? v : v.name);
1679
+ return /* @__PURE__ */ s(Be, { missingPermissions: g });
1680
+ }
1681
+ return /* @__PURE__ */ s(_, { children: r });
1682
1682
  }
1683
- const mt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1683
+ const At = ({ redirectPath: r }) => /* @__PURE__ */ s(
1684
1684
  "div",
1685
1685
  {
1686
1686
  style: {
@@ -1704,23 +1704,23 @@ const mt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1704
1704
  maxWidth: "400px"
1705
1705
  },
1706
1706
  children: [
1707
- /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1708
- /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1709
- /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1707
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1708
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1709
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1710
1710
  /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1711
1711
  "Redirecting to ",
1712
- i,
1712
+ r,
1713
1713
  "..."
1714
1714
  ] })
1715
1715
  ]
1716
1716
  }
1717
1717
  )
1718
1718
  }
1719
- ), Ne = ({
1720
- userType: i,
1719
+ ), qe = ({
1720
+ userType: r,
1721
1721
  requiredUserType: e,
1722
1722
  missingPermissions: t
1723
- }) => /* @__PURE__ */ n(
1723
+ }) => /* @__PURE__ */ s(
1724
1724
  "div",
1725
1725
  {
1726
1726
  style: {
@@ -1744,62 +1744,66 @@ const mt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1744
1744
  maxWidth: "400px"
1745
1745
  },
1746
1746
  children: [
1747
- /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1748
- /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1749
- e && i ? /* @__PURE__ */ d(j, { children: [
1747
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1748
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1749
+ e && r ? /* @__PURE__ */ d(_, { children: [
1750
1750
  /* @__PURE__ */ d("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1751
1751
  "This page requires ",
1752
- /* @__PURE__ */ n("strong", { children: e }),
1752
+ /* @__PURE__ */ s("strong", { children: e }),
1753
1753
  " access."
1754
1754
  ] }),
1755
1755
  /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1756
1756
  "Your current user type: ",
1757
- /* @__PURE__ */ n("strong", { children: i })
1757
+ /* @__PURE__ */ s("strong", { children: r })
1758
1758
  ] })
1759
- ] }) : /* @__PURE__ */ d(j, { children: [
1760
- /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1759
+ ] }) : /* @__PURE__ */ d(_, { children: [
1760
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1761
1761
  t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1762
1762
  "Required permissions: ",
1763
- /* @__PURE__ */ n("strong", { children: t.join(", ") })
1763
+ /* @__PURE__ */ s("strong", { children: t.join(", ") })
1764
1764
  ] })
1765
1765
  ] })
1766
1766
  ]
1767
1767
  }
1768
1768
  )
1769
1769
  }
1770
- ), yt = (i, e) => i === e;
1771
- function nr({
1772
- children: i,
1770
+ ), xt = (r, e) => r === e;
1771
+ function bn({
1772
+ children: r,
1773
1773
  redirectTo: e = "/login",
1774
1774
  requiredUserType: t,
1775
- requiredPermissions: r,
1776
- requireAllPermissions: s = !1,
1775
+ requiredPermissions: n,
1776
+ requireAllPermissions: i = !1,
1777
1777
  fallback: o
1778
1778
  }) {
1779
- const { hasValidSession: a, sessionManager: m, hasPermission: y, hasAnyPermission: b, hasAllPermissions: p } = oe(), S = Te();
1780
- if (!a())
1781
- return o ? /* @__PURE__ */ n(j, { children: o }) : /* @__PURE__ */ d(j, { children: [
1782
- /* @__PURE__ */ n(mt, { redirectPath: e }),
1783
- /* @__PURE__ */ n(me, { to: e, state: { from: S.pathname }, replace: !0 })
1779
+ const { hasValidSession: a, sessionManager: p, hasPermission: f, hasAnyPermission: b, hasAllPermissions: u } = le(), w = be();
1780
+ if (X(() => {
1781
+ process.env.NODE_ENV === "development" && console.warn(
1782
+ "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
1783
+ );
1784
+ }, []), !a())
1785
+ return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ d(_, { children: [
1786
+ /* @__PURE__ */ s(At, { redirectPath: e }),
1787
+ /* @__PURE__ */ s(fe, { to: e, state: { from: w.pathname }, replace: !0 })
1784
1788
  ] });
1785
- const f = m.getUser();
1786
- if (!f)
1787
- return /* @__PURE__ */ n(me, { to: e, state: { from: S.pathname }, replace: !0 });
1788
- if (t && !yt(f.userType, t))
1789
- return /* @__PURE__ */ n(
1790
- Ne,
1789
+ const g = p.getUser();
1790
+ if (!g)
1791
+ return /* @__PURE__ */ s(fe, { to: e, state: { from: w.pathname }, replace: !0 });
1792
+ if (t && !xt(g.userType, t))
1793
+ return /* @__PURE__ */ s(
1794
+ qe,
1791
1795
  {
1792
- userType: f.userType,
1796
+ userType: g.userType,
1793
1797
  requiredUserType: t
1794
1798
  }
1795
1799
  );
1796
- if (r && r.length > 0 && !(s ? p(r) : b(r))) {
1797
- const I = r.filter((C) => !y(C)).map((C) => typeof C == "string" ? C : C.name);
1798
- return /* @__PURE__ */ n(Ne, { missingPermissions: I });
1800
+ if (n && n.length > 0 && !(i ? u(n) : b(n))) {
1801
+ const M = n.filter((F) => !f(F)).map((F) => typeof F == "string" ? F : F.name);
1802
+ return /* @__PURE__ */ s(qe, { missingPermissions: M });
1799
1803
  }
1800
- return /* @__PURE__ */ n(j, { children: i });
1804
+ return /* @__PURE__ */ s(_, { children: r });
1801
1805
  }
1802
- const wt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1806
+ const Pt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1803
1807
  "div",
1804
1808
  {
1805
1809
  style: {
@@ -1823,12 +1827,12 @@ const wt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1823
1827
  maxWidth: "400px"
1824
1828
  },
1825
1829
  children: [
1826
- /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
1827
- /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
1828
- /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
1830
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
1831
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
1832
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
1829
1833
  /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1830
1834
  "Redirecting to ",
1831
- i,
1835
+ r,
1832
1836
  "..."
1833
1837
  ] })
1834
1838
  ]
@@ -1836,14 +1840,18 @@ const wt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1836
1840
  )
1837
1841
  }
1838
1842
  );
1839
- function sr({ children: i, redirectTo: e = "/", fallback: t }) {
1840
- const { tenant: r, isLoading: s, error: o } = ce(), a = Te();
1841
- return s || o ? null : r ? /* @__PURE__ */ n(j, { children: i }) : t ? /* @__PURE__ */ n(j, { children: t }) : /* @__PURE__ */ d(j, { children: [
1842
- /* @__PURE__ */ n(wt, { redirectPath: e }),
1843
- /* @__PURE__ */ n(me, { to: e, state: { from: a.pathname }, replace: !0 })
1843
+ function Sn({ children: r, redirectTo: e = "/", fallback: t }) {
1844
+ const { tenant: n, isLoading: i, error: o } = he(), a = be();
1845
+ return X(() => {
1846
+ process.env.NODE_ENV === "development" && console.warn(
1847
+ "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
1848
+ );
1849
+ }, []), i || o ? null : n ? /* @__PURE__ */ s(_, { children: r }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
1850
+ /* @__PURE__ */ s(Pt, { redirectPath: e }),
1851
+ /* @__PURE__ */ s(fe, { to: e, state: { from: a.pathname }, replace: !0 })
1844
1852
  ] });
1845
1853
  }
1846
- const bt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1854
+ const Rt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1847
1855
  "div",
1848
1856
  {
1849
1857
  style: {
@@ -1867,12 +1875,12 @@ const bt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1867
1875
  maxWidth: "400px"
1868
1876
  },
1869
1877
  children: [
1870
- /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
1871
- /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
1872
- /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
1878
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
1879
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
1880
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
1873
1881
  /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1874
1882
  "Redirecting to ",
1875
- i,
1883
+ r,
1876
1884
  "..."
1877
1885
  ] })
1878
1886
  ]
@@ -1880,14 +1888,144 @@ const bt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1880
1888
  )
1881
1889
  }
1882
1890
  );
1883
- function ir({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1884
- const { tenant: r, isLoading: s, error: o } = ce(), a = Te();
1885
- return s || o ? null : r ? t ? /* @__PURE__ */ n(j, { children: t }) : /* @__PURE__ */ d(j, { children: [
1886
- /* @__PURE__ */ n(bt, { redirectPath: e }),
1887
- /* @__PURE__ */ n(me, { to: e, state: { from: a.pathname }, replace: !0 })
1888
- ] }) : /* @__PURE__ */ n(j, { children: i });
1891
+ function vn({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
1892
+ const { tenant: n, isLoading: i, error: o } = he(), a = be();
1893
+ return X(() => {
1894
+ process.env.NODE_ENV === "development" && console.warn(
1895
+ "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
1896
+ );
1897
+ }, []), i || o ? null : n ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
1898
+ /* @__PURE__ */ s(Rt, { redirectPath: e }),
1899
+ /* @__PURE__ */ s(fe, { to: e, state: { from: a.pathname }, replace: !0 })
1900
+ ] }) : /* @__PURE__ */ s(_, { children: r });
1889
1901
  }
1890
- const St = () => /* @__PURE__ */ d(
1902
+ const je = {
1903
+ publicGuest: "/",
1904
+ publicUser: "/account",
1905
+ publicAdmin: "/admin",
1906
+ tenantGuest: "/login",
1907
+ tenantUser: "/dashboard",
1908
+ tenantAdmin: "/admin/dashboard",
1909
+ default: "/"
1910
+ }, It = {
1911
+ // Public/Landing zones
1912
+ landing: { tenant: "forbidden", auth: "optional" },
1913
+ publicOnly: { tenant: "forbidden", auth: "forbidden" },
1914
+ // Auth zones
1915
+ login: { tenant: "required", auth: "forbidden" },
1916
+ guest: { auth: "forbidden" },
1917
+ authenticated: { auth: "required" },
1918
+ // Tenant zones
1919
+ tenant: { tenant: "required" },
1920
+ tenantOpen: { tenant: "required", auth: "optional" },
1921
+ tenantAuth: { tenant: "required", auth: "required" },
1922
+ // User type zones
1923
+ user: { tenant: "required", auth: "required", userType: se.USER },
1924
+ admin: { tenant: "required", auth: "required", userType: se.TENANT_ADMIN },
1925
+ // Fully open
1926
+ open: { tenant: "optional", auth: "optional" }
1927
+ }, Mt = "returnTo";
1928
+ function Lt(r, e) {
1929
+ return e ? r ? Array.isArray(e) ? e.includes(r) : r === e : !1 : !0;
1930
+ }
1931
+ function Oe(r, e) {
1932
+ return !r || r === "optional" ? "skip" : r === "required" ? e ? "pass" : "fail" : r === "forbidden" ? e ? "fail" : "pass" : "skip";
1933
+ }
1934
+ function Et(r, e) {
1935
+ return Oe(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Oe(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !Lt(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(r.permissions) ? "missing_permissions" : null;
1936
+ }
1937
+ function Ft(r, e) {
1938
+ return r.hasTenant ? r.isAuthenticated ? r.userType === se.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : r.isAuthenticated ? r.userType === se.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
1939
+ }
1940
+ function Nt(r, e, t, n, i) {
1941
+ if (!e || i !== "url")
1942
+ return r;
1943
+ const o = typeof e == "string" ? e : t, a = r.includes("?") ? "&" : "?";
1944
+ return `${r}${a}${n}=${encodeURIComponent(o)}`;
1945
+ }
1946
+ function Ut(r, e, t) {
1947
+ if (!r || t === "url") return;
1948
+ const n = typeof r == "string" ? r : e;
1949
+ sessionStorage.setItem("zone_return_to", n);
1950
+ }
1951
+ const ae = ({
1952
+ children: r,
1953
+ preset: e,
1954
+ tenant: t,
1955
+ auth: n,
1956
+ userType: i,
1957
+ requiredPermissions: o,
1958
+ requireAllPermissions: a = !0,
1959
+ returnTo: p,
1960
+ onAccessDenied: f,
1961
+ redirectTo: b,
1962
+ loadingFallback: u,
1963
+ accessDeniedFallback: w
1964
+ }) => {
1965
+ const g = be(), { isAuthenticated: v, isAuthInitializing: M, currentUser: F, userPermissions: L } = le(), { tenant: P, isTenantLoading: h } = ue(), x = K(() => {
1966
+ if (e)
1967
+ return It[e];
1968
+ }, [e]), k = K(
1969
+ () => ({
1970
+ tenant: t ?? (x == null ? void 0 : x.tenant),
1971
+ auth: n ?? (x == null ? void 0 : x.auth),
1972
+ userType: i ?? (x == null ? void 0 : x.userType),
1973
+ permissions: o ?? (x == null ? void 0 : x.requiredPermissions),
1974
+ requireAllPermissions: a
1975
+ }),
1976
+ [t, n, i, o, x, a]
1977
+ ), I = K(
1978
+ () => ({
1979
+ hasTenant: !!P,
1980
+ isAuthenticated: v,
1981
+ userType: F == null ? void 0 : F.userType,
1982
+ permissions: L,
1983
+ isLoading: M || h
1984
+ }),
1985
+ [
1986
+ P,
1987
+ v,
1988
+ F == null ? void 0 : F.userType,
1989
+ L,
1990
+ M,
1991
+ h
1992
+ ]
1993
+ ), U = K(() => I.isLoading ? null : Et(k, I), [k, I]), C = je, R = K(() => U ? b || Ft(I, C) : null, [U, b, I, C]), B = K(() => !U || !R ? null : {
1994
+ type: U,
1995
+ required: {
1996
+ tenant: k.tenant,
1997
+ auth: k.auth,
1998
+ userType: k.userType,
1999
+ permissions: k.permissions
2000
+ },
2001
+ current: {
2002
+ hasTenant: I.hasTenant,
2003
+ isAuthenticated: I.isAuthenticated,
2004
+ userType: I.userType,
2005
+ permissions: I.permissions
2006
+ },
2007
+ redirectTo: R
2008
+ }, [U, R, k, I]);
2009
+ if (X(() => {
2010
+ B && f && f(B);
2011
+ }, [B, f]), X(() => {
2012
+ B && p && Ut(p, g.pathname + g.search, "session");
2013
+ }, [B, p, g.pathname, g.search]), I.isLoading)
2014
+ return /* @__PURE__ */ s(_, { children: u || null });
2015
+ if (B && R) {
2016
+ if (w)
2017
+ return /* @__PURE__ */ s(_, { children: w });
2018
+ const l = Nt(
2019
+ R,
2020
+ p,
2021
+ g.pathname + g.search,
2022
+ Mt,
2023
+ "url"
2024
+ );
2025
+ return /* @__PURE__ */ s(fe, { to: l, replace: !0 });
2026
+ }
2027
+ return /* @__PURE__ */ s(_, { children: r });
2028
+ }, Tn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", ...r }), kn = (r) => /* @__PURE__ */ s(ae, { tenant: "forbidden", ...r }), An = (r) => /* @__PURE__ */ s(ae, { auth: "required", ...r }), xn = (r) => /* @__PURE__ */ s(ae, { auth: "forbidden", ...r }), Pn = (r) => /* @__PURE__ */ s(ae, { auth: "required", userType: se.TENANT_ADMIN, ...r }), Rn = (r) => /* @__PURE__ */ s(ae, { auth: "required", userType: se.USER, ...r }), In = (r) => /* @__PURE__ */ s(ae, { tenant: "optional", auth: "optional", ...r }), Mn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "required", ...r }), Ln = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "optional", ...r }), En = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "forbidden", ...r }), Ct = () => /* @__PURE__ */ d(
1891
2029
  "div",
1892
2030
  {
1893
2031
  style: {
@@ -1899,19 +2037,19 @@ const St = () => /* @__PURE__ */ d(
1899
2037
  color: "#dc2626"
1900
2038
  },
1901
2039
  children: [
1902
- /* @__PURE__ */ n("h3", { style: { margin: "0 0 1rem 0" }, children: "🔒 Subscription Required" }),
1903
- /* @__PURE__ */ n("p", { style: { margin: 0 }, children: "This feature requires a higher subscription plan. Please upgrade your plan to access this content." })
2040
+ /* @__PURE__ */ s("h3", { style: { margin: "0 0 1rem 0" }, children: "🔒 Subscription Required" }),
2041
+ /* @__PURE__ */ s("p", { style: { margin: 0 }, children: "This feature requires a higher subscription plan. Please upgrade your plan to access this content." })
1904
2042
  ]
1905
2043
  }
1906
2044
  );
1907
- function or({
1908
- children: i,
1909
- fallback: e = /* @__PURE__ */ n(St, {}),
2045
+ function Fn({
2046
+ children: r,
2047
+ fallback: e = /* @__PURE__ */ s(Ct, {}),
1910
2048
  allowedPlans: t,
1911
- requiredFeature: r
2049
+ requiredFeature: n
1912
2050
  }) {
1913
- const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: a, loading: m } = pt();
1914
- return m ? /* @__PURE__ */ n(
2051
+ const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: p } = Tt();
2052
+ return p ? /* @__PURE__ */ s(
1915
2053
  "div",
1916
2054
  {
1917
2055
  style: {
@@ -1921,9 +2059,9 @@ function or({
1921
2059
  },
1922
2060
  children: "Loading subscription..."
1923
2061
  }
1924
- ) : s ? s.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ n(j, { children: e }) : r && !a(r) ? /* @__PURE__ */ n(j, { children: e }) : /* @__PURE__ */ n(j, { children: i }) : /* @__PURE__ */ n(j, { children: e }) : /* @__PURE__ */ n(j, { children: e });
2062
+ ) : i ? i.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ s(_, { children: e }) : n && !a(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: r }) : /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: e });
1925
2063
  }
1926
- const vt = ({ flagName: i }) => /* @__PURE__ */ d(
2064
+ const Dt = ({ flagName: r }) => /* @__PURE__ */ d(
1927
2065
  "div",
1928
2066
  {
1929
2067
  style: {
@@ -1940,19 +2078,19 @@ const vt = ({ flagName: i }) => /* @__PURE__ */ d(
1940
2078
  color: "#6c757d"
1941
2079
  },
1942
2080
  children: [
1943
- /* @__PURE__ */ n("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
1944
- /* @__PURE__ */ n("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
2081
+ /* @__PURE__ */ s("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
2082
+ /* @__PURE__ */ s("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
1945
2083
  /* @__PURE__ */ d("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
1946
2084
  'Feature flag "',
1947
- i,
2085
+ r,
1948
2086
  '" is disabled'
1949
2087
  ] })
1950
2088
  ]
1951
2089
  }
1952
2090
  );
1953
- function ar({ name: i, children: e, fallback: t }) {
1954
- const { isEnabled: r, loading: s } = ht();
1955
- return s ? /* @__PURE__ */ n(
2091
+ function Nn({ name: r, children: e, fallback: t }) {
2092
+ const { isEnabled: n, loading: i } = St();
2093
+ return i ? /* @__PURE__ */ s(
1956
2094
  "div",
1957
2095
  {
1958
2096
  style: {
@@ -1965,9 +2103,9 @@ function ar({ name: i, children: e, fallback: t }) {
1965
2103
  },
1966
2104
  children: "Loading feature flags..."
1967
2105
  }
1968
- ) : r(i) ? /* @__PURE__ */ n(j, { children: e }) : /* @__PURE__ */ n(j, { children: t || /* @__PURE__ */ n(vt, { flagName: i }) });
2106
+ ) : n(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(Dt, { flagName: r }) });
1969
2107
  }
1970
- const kt = () => /* @__PURE__ */ d(
2108
+ const $t = () => /* @__PURE__ */ d(
1971
2109
  "svg",
1972
2110
  {
1973
2111
  width: "16",
@@ -1980,11 +2118,11 @@ const kt = () => /* @__PURE__ */ d(
1980
2118
  strokeLinejoin: "round",
1981
2119
  style: { flexShrink: 0 },
1982
2120
  children: [
1983
- /* @__PURE__ */ n("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
1984
- /* @__PURE__ */ n("circle", { cx: "12", cy: "12", r: "3" })
2121
+ /* @__PURE__ */ s("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
2122
+ /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "3" })
1985
2123
  ]
1986
2124
  }
1987
- ), Tt = () => /* @__PURE__ */ d(
2125
+ ), Ht = () => /* @__PURE__ */ d(
1988
2126
  "svg",
1989
2127
  {
1990
2128
  width: "16",
@@ -1997,14 +2135,14 @@ const kt = () => /* @__PURE__ */ d(
1997
2135
  strokeLinejoin: "round",
1998
2136
  style: { flexShrink: 0 },
1999
2137
  children: [
2000
- /* @__PURE__ */ n("path", { 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" }),
2001
- /* @__PURE__ */ n("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2138
+ /* @__PURE__ */ s("path", { 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" }),
2139
+ /* @__PURE__ */ s("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2002
2140
  ]
2003
2141
  }
2004
- ), xt = {
2005
- showPassword: /* @__PURE__ */ n(kt, {}),
2006
- hidePassword: /* @__PURE__ */ n(Tt, {})
2007
- }, At = {
2142
+ ), Bt = {
2143
+ showPassword: /* @__PURE__ */ s($t, {}),
2144
+ hidePassword: /* @__PURE__ */ s(Ht, {})
2145
+ }, qt = {
2008
2146
  title: "Sign In",
2009
2147
  usernameLabel: "Email or Phone",
2010
2148
  usernamePlaceholder: "Enter your email or phone number",
@@ -2018,7 +2156,7 @@ const kt = () => /* @__PURE__ */ d(
2018
2156
  magicLinkLink: "Use Magic Link",
2019
2157
  errorMessage: "Invalid credentials",
2020
2158
  loadingText: "Signing in..."
2021
- }, Pt = {
2159
+ }, Ot = {
2022
2160
  container: {
2023
2161
  maxWidth: "400px",
2024
2162
  width: "100%",
@@ -2125,133 +2263,133 @@ const kt = () => /* @__PURE__ */ d(
2125
2263
  fontSize: "0.875rem"
2126
2264
  }
2127
2265
  };
2128
- function lr({
2129
- copy: i = {},
2266
+ function Un({
2267
+ copy: r = {},
2130
2268
  styles: e = {},
2131
2269
  icons: t = {},
2132
- onSuccess: r,
2133
- onError: s,
2270
+ onSuccess: n,
2271
+ onError: i,
2134
2272
  onForgotPassword: o,
2135
2273
  onSignupClick: a,
2136
- onMagicLinkClick: m,
2137
- showForgotPassword: y = !0,
2274
+ onMagicLinkClick: p,
2275
+ showForgotPassword: f = !0,
2138
2276
  showSignupLink: b = !0,
2139
- showMagicLinkOption: p = !0,
2140
- className: S
2277
+ showMagicLinkOption: u = !0,
2278
+ className: w
2141
2279
  }) {
2142
- const [f, T] = k(""), [I, C] = k(""), [R, x] = k(!1), [g, $] = k(!1), [A, E] = k(""), [U, D] = k({}), { login: P } = oe(), { tenant: O } = ce(), c = { ...At, ...i }, L = { ...Pt, ...e }, F = { ...xt, ...t }, l = () => {
2143
- const u = {};
2144
- return f.trim() || (u.username = !0), I.trim() || (u.password = !0), D(u), Object.keys(u).length === 0;
2145
- }, H = async (u) => {
2146
- if (u.preventDefault(), !!l()) {
2147
- if (!(O != null && O.id)) {
2148
- E("Tenant not found");
2280
+ const [g, v] = A(""), [M, F] = A(""), [L, P] = A(!1), [h, x] = A(!1), [k, I] = A(""), [U, C] = A({}), { login: R } = le(), { tenant: B } = he(), l = { ...qt, ...r }, N = { ...Ot, ...e }, D = { ...Bt, ...t }, c = () => {
2281
+ const m = {};
2282
+ return g.trim() || (m.username = !0), M.trim() || (m.password = !0), C(m), Object.keys(m).length === 0;
2283
+ }, $ = async (m) => {
2284
+ if (m.preventDefault(), !!c()) {
2285
+ if (!(B != null && B.id)) {
2286
+ I("Tenant not found");
2149
2287
  return;
2150
2288
  }
2151
- $(!0), E("");
2289
+ x(!0), I("");
2152
2290
  try {
2153
- const w = await P({
2154
- username: f,
2155
- password: I
2291
+ const S = await R({
2292
+ username: g,
2293
+ password: M
2156
2294
  // tenantId inferred from context automatically
2157
2295
  });
2158
- r == null || r(w);
2159
- } catch (w) {
2160
- const _ = w.message || c.errorMessage;
2161
- E(_), s == null || s(_);
2296
+ n == null || n(S);
2297
+ } catch (S) {
2298
+ const G = S.message || l.errorMessage;
2299
+ I(G), i == null || i(G);
2162
2300
  } finally {
2163
- $(!1);
2301
+ x(!1);
2164
2302
  }
2165
2303
  }
2166
- }, M = (u) => ({
2167
- ...L.input,
2168
- ...U[u] ? L.inputError : {}
2169
- }), h = () => ({
2170
- ...L.button,
2171
- ...g ? L.buttonLoading : {},
2172
- ...!f || !I || g ? L.buttonDisabled : {}
2304
+ }, E = (m) => ({
2305
+ ...N.input,
2306
+ ...U[m] ? N.inputError : {}
2307
+ }), y = () => ({
2308
+ ...N.button,
2309
+ ...h ? N.buttonLoading : {},
2310
+ ...!g || !M || h ? N.buttonDisabled : {}
2173
2311
  });
2174
- return /* @__PURE__ */ d("div", { className: S, style: L.container, children: [
2175
- /* @__PURE__ */ n("h2", { style: L.title, children: c.title }),
2176
- /* @__PURE__ */ d("form", { onSubmit: H, style: L.form, children: [
2177
- /* @__PURE__ */ d("div", { style: L.fieldGroup, children: [
2178
- /* @__PURE__ */ n("label", { style: L.label, children: c.usernameLabel }),
2179
- /* @__PURE__ */ n(
2312
+ return /* @__PURE__ */ d("div", { className: w, style: N.container, children: [
2313
+ /* @__PURE__ */ s("h2", { style: N.title, children: l.title }),
2314
+ /* @__PURE__ */ d("form", { onSubmit: $, style: N.form, children: [
2315
+ /* @__PURE__ */ d("div", { style: N.fieldGroup, children: [
2316
+ /* @__PURE__ */ s("label", { style: N.label, children: l.usernameLabel }),
2317
+ /* @__PURE__ */ s(
2180
2318
  "input",
2181
2319
  {
2182
2320
  id: "username",
2183
2321
  name: "username",
2184
2322
  type: "text",
2185
- value: f,
2186
- onChange: (u) => {
2187
- T(u.target.value), U.username && D((w) => ({ ...w, username: !1 }));
2323
+ value: g,
2324
+ onChange: (m) => {
2325
+ v(m.target.value), U.username && C((S) => ({ ...S, username: !1 }));
2188
2326
  },
2189
- placeholder: c.usernamePlaceholder,
2190
- style: M("username"),
2191
- disabled: g
2327
+ placeholder: l.usernamePlaceholder,
2328
+ style: E("username"),
2329
+ disabled: h
2192
2330
  }
2193
2331
  )
2194
2332
  ] }),
2195
- /* @__PURE__ */ d("div", { style: L.fieldGroup, children: [
2196
- /* @__PURE__ */ n("label", { style: L.label, children: c.passwordLabel }),
2197
- /* @__PURE__ */ d("div", { style: L.inputContainer, children: [
2198
- /* @__PURE__ */ n(
2333
+ /* @__PURE__ */ d("div", { style: N.fieldGroup, children: [
2334
+ /* @__PURE__ */ s("label", { style: N.label, children: l.passwordLabel }),
2335
+ /* @__PURE__ */ d("div", { style: N.inputContainer, children: [
2336
+ /* @__PURE__ */ s(
2199
2337
  "input",
2200
2338
  {
2201
2339
  id: "password",
2202
2340
  name: "password",
2203
- type: R ? "text" : "password",
2204
- value: I,
2205
- onChange: (u) => {
2206
- C(u.target.value), U.password && D((w) => ({ ...w, password: !1 }));
2341
+ type: L ? "text" : "password",
2342
+ value: M,
2343
+ onChange: (m) => {
2344
+ F(m.target.value), U.password && C((S) => ({ ...S, password: !1 }));
2207
2345
  },
2208
- placeholder: c.passwordPlaceholder,
2346
+ placeholder: l.passwordPlaceholder,
2209
2347
  style: {
2210
- ...M("password"),
2348
+ ...E("password"),
2211
2349
  paddingRight: "2.5rem"
2212
2350
  // Make room for the icon
2213
2351
  },
2214
- disabled: g
2352
+ disabled: h
2215
2353
  }
2216
2354
  ),
2217
- /* @__PURE__ */ n(
2355
+ /* @__PURE__ */ s(
2218
2356
  "button",
2219
2357
  {
2220
2358
  type: "button",
2221
- onClick: () => x(!R),
2222
- style: L.passwordToggle,
2223
- disabled: g,
2224
- "aria-label": R ? "Hide password" : "Show password",
2225
- children: R ? F.hidePassword : F.showPassword
2359
+ onClick: () => P(!L),
2360
+ style: N.passwordToggle,
2361
+ disabled: h,
2362
+ "aria-label": L ? "Hide password" : "Show password",
2363
+ children: L ? D.hidePassword : D.showPassword
2226
2364
  }
2227
2365
  )
2228
2366
  ] })
2229
2367
  ] }),
2230
- /* @__PURE__ */ n("button", { type: "submit", disabled: !f || !I || g, style: h(), children: g ? c.loadingText : c.submitButton }),
2231
- A && /* @__PURE__ */ n("div", { style: L.errorText, children: A })
2368
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !g || !M || h, style: y(), children: h ? l.loadingText : l.submitButton }),
2369
+ k && /* @__PURE__ */ s("div", { style: N.errorText, children: k })
2232
2370
  ] }),
2233
- (y || b || p) && /* @__PURE__ */ d("div", { style: L.linkContainer, children: [
2234
- p && /* @__PURE__ */ d("div", { children: [
2235
- /* @__PURE__ */ d("span", { style: L.divider, children: [
2236
- c.magicLinkText,
2371
+ (f || b || u) && /* @__PURE__ */ d("div", { style: N.linkContainer, children: [
2372
+ u && /* @__PURE__ */ d("div", { children: [
2373
+ /* @__PURE__ */ d("span", { style: N.divider, children: [
2374
+ l.magicLinkText,
2237
2375
  " "
2238
2376
  ] }),
2239
- /* @__PURE__ */ n("a", { onClick: m, style: L.link, children: c.magicLinkLink })
2377
+ /* @__PURE__ */ s("a", { onClick: p, style: N.link, children: l.magicLinkLink })
2240
2378
  ] }),
2241
- p && (y || b) && /* @__PURE__ */ n("div", { style: L.divider, children: "•" }),
2242
- y && /* @__PURE__ */ n("a", { onClick: o, style: L.link, children: c.forgotPasswordLink }),
2243
- y && b && /* @__PURE__ */ n("div", { style: L.divider, children: "•" }),
2379
+ u && (f || b) && /* @__PURE__ */ s("div", { style: N.divider, children: "•" }),
2380
+ f && /* @__PURE__ */ s("a", { onClick: o, style: N.link, children: l.forgotPasswordLink }),
2381
+ f && b && /* @__PURE__ */ s("div", { style: N.divider, children: "•" }),
2244
2382
  b && /* @__PURE__ */ d("div", { children: [
2245
- /* @__PURE__ */ d("span", { style: L.divider, children: [
2246
- c.signupText,
2383
+ /* @__PURE__ */ d("span", { style: N.divider, children: [
2384
+ l.signupText,
2247
2385
  " "
2248
2386
  ] }),
2249
- /* @__PURE__ */ n("a", { onClick: a, style: L.link, children: c.signupLink })
2387
+ /* @__PURE__ */ s("a", { onClick: a, style: N.link, children: l.signupLink })
2250
2388
  ] })
2251
2389
  ] })
2252
2390
  ] });
2253
2391
  }
2254
- const Mt = {
2392
+ const zt = {
2255
2393
  title: "Create Account",
2256
2394
  nameLabel: "First Name",
2257
2395
  namePlaceholder: "Enter your first name",
@@ -2277,7 +2415,7 @@ const Mt = {
2277
2415
  passwordMismatchError: "Passwords do not match",
2278
2416
  isAdminLabel: "Create new organization",
2279
2417
  isAdminDescription: "Check this if you want to create a new organization"
2280
- }, It = {
2418
+ }, _t = {
2281
2419
  container: {
2282
2420
  maxWidth: "400px",
2283
2421
  width: "100%",
@@ -2376,138 +2514,138 @@ const Mt = {
2376
2514
  fontSize: "0.875rem"
2377
2515
  }
2378
2516
  };
2379
- function cr({
2380
- copy: i = {},
2517
+ function Cn({
2518
+ copy: r = {},
2381
2519
  styles: e = {},
2382
2520
  signupType: t = "user",
2383
- onSuccess: r,
2384
- onError: s,
2521
+ onSuccess: n,
2522
+ onError: i,
2385
2523
  onLoginClick: o,
2386
2524
  onMagicLinkClick: a,
2387
- showLoginLink: m = !0,
2388
- showMagicLinkOption: y = !0,
2525
+ showLoginLink: p = !0,
2526
+ showMagicLinkOption: f = !0,
2389
2527
  className: b
2390
2528
  }) {
2391
- const [p, S] = k(""), [f, T] = k(""), [I, C] = k(""), [R, x] = k(""), [g, $] = k(""), [A, E] = k(""), [U, D] = k(""), [P, O] = k(!1), [c, L] = k(""), [F, l] = k({}), { signup: H, signupTenantAdmin: M } = oe(), { tenant: h } = ce(), u = { ...Mt, ...i }, w = { ...It, ...e }, _ = () => {
2392
- const v = {};
2393
- return p.trim() || (v.name = !0), !I.trim() && !R.trim() && (v.email = !0, v.phoneNumber = !0), g.trim() || (v.password = !0), A.trim() || (v.confirmPassword = !0), t === "tenant" && !U.trim() && (v.tenantName = !0), l(v), Object.keys(v).length === 0;
2394
- }, K = async (v) => {
2395
- if (v.preventDefault(), !!_()) {
2396
- if (g !== A) {
2397
- L(u.passwordMismatchError), l({ confirmPassword: !0 });
2529
+ const [u, w] = A(""), [g, v] = A(""), [M, F] = A(""), [L, P] = A(""), [h, x] = A(""), [k, I] = A(""), [U, C] = A(""), [R, B] = A(!1), [l, N] = A(""), [D, c] = A({}), { signup: $, signupTenantAdmin: E } = le(), { tenant: y } = he(), m = { ...zt, ...r }, S = { ..._t, ...e }, G = () => {
2530
+ const T = {};
2531
+ return u.trim() || (T.name = !0), !M.trim() && !L.trim() && (T.email = !0, T.phoneNumber = !0), h.trim() || (T.password = !0), k.trim() || (T.confirmPassword = !0), t === "tenant" && !U.trim() && (T.tenantName = !0), c(T), Object.keys(T).length === 0;
2532
+ }, J = async (T) => {
2533
+ if (T.preventDefault(), !!G()) {
2534
+ if (h !== k) {
2535
+ N(m.passwordMismatchError), c({ confirmPassword: !0 });
2398
2536
  return;
2399
2537
  }
2400
- if (t === "user" && !(h != null && h.id)) {
2401
- L("Tenant not found");
2538
+ if (t === "user" && !(y != null && y.id)) {
2539
+ N("Tenant not found");
2402
2540
  return;
2403
2541
  }
2404
- O(!0), L("");
2542
+ B(!0), N("");
2405
2543
  try {
2406
- let J;
2407
- t === "tenant" ? J = await M({
2408
- email: I || void 0,
2409
- phoneNumber: R || void 0,
2410
- name: p,
2411
- password: g,
2544
+ let Z;
2545
+ t === "tenant" ? Z = await E({
2546
+ email: M || void 0,
2547
+ phoneNumber: L || void 0,
2548
+ name: u,
2549
+ password: h,
2412
2550
  tenantName: U,
2413
- lastName: f || void 0
2414
- }) : J = await H({
2415
- email: I || void 0,
2416
- phoneNumber: R || void 0,
2417
- name: p,
2418
- password: g,
2419
- tenantId: h.id,
2420
- lastName: f || void 0
2421
- }), r == null || r(J);
2422
- } catch (J) {
2423
- const ae = J.message || u.errorMessage;
2424
- L(ae), s == null || s(ae);
2551
+ lastName: g || void 0
2552
+ }) : Z = await $({
2553
+ email: M || void 0,
2554
+ phoneNumber: L || void 0,
2555
+ name: u,
2556
+ password: h,
2557
+ tenantId: y.id,
2558
+ lastName: g || void 0
2559
+ }), n == null || n(Z);
2560
+ } catch (Z) {
2561
+ const ce = Z.message || m.errorMessage;
2562
+ N(ce), i == null || i(ce);
2425
2563
  } finally {
2426
- O(!1);
2564
+ B(!1);
2427
2565
  }
2428
2566
  }
2429
- }, B = (v) => ({
2430
- ...w.input,
2431
- ...F[v] ? w.inputError : {}
2432
- }), q = () => ({
2433
- ...w.button,
2434
- ...P ? w.buttonLoading : {},
2435
- ...!p || !I && !R || !g || !A || P || t === "tenant" && !U ? w.buttonDisabled : {}
2436
- }), V = p && (I || R) && g && A && (t === "user" || U);
2437
- return /* @__PURE__ */ d("div", { className: b, style: w.container, children: [
2438
- /* @__PURE__ */ n("h2", { style: w.title, children: u.title }),
2439
- /* @__PURE__ */ d("form", { onSubmit: K, style: w.form, children: [
2440
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2441
- /* @__PURE__ */ n("label", { style: w.label, children: u.nameLabel }),
2442
- /* @__PURE__ */ n(
2567
+ }, q = (T) => ({
2568
+ ...S.input,
2569
+ ...D[T] ? S.inputError : {}
2570
+ }), O = () => ({
2571
+ ...S.button,
2572
+ ...R ? S.buttonLoading : {},
2573
+ ...!u || !M && !L || !h || !k || R || t === "tenant" && !U ? S.buttonDisabled : {}
2574
+ }), V = u && (M || L) && h && k && (t === "user" || U);
2575
+ return /* @__PURE__ */ d("div", { className: b, style: S.container, children: [
2576
+ /* @__PURE__ */ s("h2", { style: S.title, children: m.title }),
2577
+ /* @__PURE__ */ d("form", { onSubmit: J, style: S.form, children: [
2578
+ /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2579
+ /* @__PURE__ */ s("label", { style: S.label, children: m.nameLabel }),
2580
+ /* @__PURE__ */ s(
2443
2581
  "input",
2444
2582
  {
2445
2583
  id: "name",
2446
2584
  name: "name",
2447
2585
  type: "text",
2448
- value: p,
2449
- onChange: (v) => {
2450
- S(v.target.value), F.name && l((J) => ({ ...J, name: !1 }));
2586
+ value: u,
2587
+ onChange: (T) => {
2588
+ w(T.target.value), D.name && c((Z) => ({ ...Z, name: !1 }));
2451
2589
  },
2452
- placeholder: u.namePlaceholder,
2453
- style: B("name"),
2454
- disabled: P
2590
+ placeholder: m.namePlaceholder,
2591
+ style: q("name"),
2592
+ disabled: R
2455
2593
  }
2456
2594
  )
2457
2595
  ] }),
2458
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2459
- /* @__PURE__ */ n("label", { style: w.label, children: u.lastNameLabel }),
2460
- /* @__PURE__ */ n(
2596
+ /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2597
+ /* @__PURE__ */ s("label", { style: S.label, children: m.lastNameLabel }),
2598
+ /* @__PURE__ */ s(
2461
2599
  "input",
2462
2600
  {
2463
2601
  id: "lastName",
2464
2602
  name: "lastName",
2465
2603
  type: "text",
2466
- value: f,
2467
- onChange: (v) => T(v.target.value),
2468
- placeholder: u.lastNamePlaceholder,
2469
- style: w.input,
2470
- disabled: P
2604
+ value: g,
2605
+ onChange: (T) => v(T.target.value),
2606
+ placeholder: m.lastNamePlaceholder,
2607
+ style: S.input,
2608
+ disabled: R
2471
2609
  }
2472
2610
  )
2473
2611
  ] }),
2474
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2475
- /* @__PURE__ */ n("label", { style: w.label, children: u.emailLabel }),
2476
- /* @__PURE__ */ n(
2612
+ /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2613
+ /* @__PURE__ */ s("label", { style: S.label, children: m.emailLabel }),
2614
+ /* @__PURE__ */ s(
2477
2615
  "input",
2478
2616
  {
2479
2617
  id: "email",
2480
2618
  name: "email",
2481
2619
  type: "email",
2482
- value: I,
2483
- onChange: (v) => {
2484
- C(v.target.value), F.email && l((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2620
+ value: M,
2621
+ onChange: (T) => {
2622
+ F(T.target.value), D.email && c((Z) => ({ ...Z, email: !1, phoneNumber: !1 }));
2485
2623
  },
2486
- placeholder: u.emailPlaceholder,
2487
- style: B("email"),
2488
- disabled: P
2624
+ placeholder: m.emailPlaceholder,
2625
+ style: q("email"),
2626
+ disabled: R
2489
2627
  }
2490
2628
  )
2491
2629
  ] }),
2492
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2493
- /* @__PURE__ */ n("label", { style: w.label, children: u.phoneNumberLabel }),
2494
- /* @__PURE__ */ n(
2630
+ /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2631
+ /* @__PURE__ */ s("label", { style: S.label, children: m.phoneNumberLabel }),
2632
+ /* @__PURE__ */ s(
2495
2633
  "input",
2496
2634
  {
2497
2635
  id: "phoneNumber",
2498
2636
  name: "phoneNumber",
2499
2637
  type: "tel",
2500
- value: R,
2501
- onChange: (v) => {
2502
- x(v.target.value), F.phoneNumber && l((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2638
+ value: L,
2639
+ onChange: (T) => {
2640
+ P(T.target.value), D.phoneNumber && c((Z) => ({ ...Z, email: !1, phoneNumber: !1 }));
2503
2641
  },
2504
- placeholder: u.phoneNumberPlaceholder,
2505
- style: B("phoneNumber"),
2506
- disabled: P
2642
+ placeholder: m.phoneNumberPlaceholder,
2643
+ style: q("phoneNumber"),
2644
+ disabled: R
2507
2645
  }
2508
2646
  )
2509
2647
  ] }),
2510
- /* @__PURE__ */ n(
2648
+ /* @__PURE__ */ s(
2511
2649
  "div",
2512
2650
  {
2513
2651
  style: {
@@ -2519,83 +2657,83 @@ function cr({
2519
2657
  children: "At least one contact method (email or phone) is required"
2520
2658
  }
2521
2659
  ),
2522
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2523
- /* @__PURE__ */ n("label", { style: w.label, children: u.passwordLabel }),
2524
- /* @__PURE__ */ n(
2660
+ /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2661
+ /* @__PURE__ */ s("label", { style: S.label, children: m.passwordLabel }),
2662
+ /* @__PURE__ */ s(
2525
2663
  "input",
2526
2664
  {
2527
2665
  id: "password",
2528
2666
  name: "password",
2529
2667
  type: "password",
2530
- value: g,
2531
- onChange: (v) => {
2532
- $(v.target.value), F.password && l((J) => ({ ...J, password: !1 }));
2668
+ value: h,
2669
+ onChange: (T) => {
2670
+ x(T.target.value), D.password && c((Z) => ({ ...Z, password: !1 }));
2533
2671
  },
2534
- placeholder: u.passwordPlaceholder,
2535
- style: B("password"),
2536
- disabled: P
2672
+ placeholder: m.passwordPlaceholder,
2673
+ style: q("password"),
2674
+ disabled: R
2537
2675
  }
2538
2676
  )
2539
2677
  ] }),
2540
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2541
- /* @__PURE__ */ n("label", { style: w.label, children: u.confirmPasswordLabel }),
2542
- /* @__PURE__ */ n(
2678
+ /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2679
+ /* @__PURE__ */ s("label", { style: S.label, children: m.confirmPasswordLabel }),
2680
+ /* @__PURE__ */ s(
2543
2681
  "input",
2544
2682
  {
2545
2683
  id: "confirmPassword",
2546
2684
  name: "confirmPassword",
2547
2685
  type: "password",
2548
- value: A,
2549
- onChange: (v) => {
2550
- E(v.target.value), F.confirmPassword && l((J) => ({ ...J, confirmPassword: !1 })), c === u.passwordMismatchError && L("");
2686
+ value: k,
2687
+ onChange: (T) => {
2688
+ I(T.target.value), D.confirmPassword && c((Z) => ({ ...Z, confirmPassword: !1 })), l === m.passwordMismatchError && N("");
2551
2689
  },
2552
- placeholder: u.confirmPasswordPlaceholder,
2553
- style: B("confirmPassword"),
2554
- disabled: P
2690
+ placeholder: m.confirmPasswordPlaceholder,
2691
+ style: q("confirmPassword"),
2692
+ disabled: R
2555
2693
  }
2556
2694
  )
2557
2695
  ] }),
2558
- t === "tenant" && /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2559
- /* @__PURE__ */ n("label", { style: w.label, children: u.tenantNameLabel }),
2560
- /* @__PURE__ */ n(
2696
+ t === "tenant" && /* @__PURE__ */ d("div", { style: S.fieldGroup, children: [
2697
+ /* @__PURE__ */ s("label", { style: S.label, children: m.tenantNameLabel }),
2698
+ /* @__PURE__ */ s(
2561
2699
  "input",
2562
2700
  {
2563
2701
  id: "tenantName",
2564
2702
  name: "tenantName",
2565
2703
  type: "text",
2566
2704
  value: U,
2567
- onChange: (v) => {
2568
- D(v.target.value), F.tenantName && l((J) => ({ ...J, tenantName: !1 }));
2705
+ onChange: (T) => {
2706
+ C(T.target.value), D.tenantName && c((Z) => ({ ...Z, tenantName: !1 }));
2569
2707
  },
2570
- placeholder: u.tenantNamePlaceholder,
2571
- style: B("tenantName"),
2572
- disabled: P
2708
+ placeholder: m.tenantNamePlaceholder,
2709
+ style: q("tenantName"),
2710
+ disabled: R
2573
2711
  }
2574
2712
  )
2575
2713
  ] }),
2576
- /* @__PURE__ */ n("button", { type: "submit", disabled: !V || P, style: q(), children: P ? u.loadingText : u.submitButton }),
2577
- c && /* @__PURE__ */ n("div", { style: w.errorText, children: c })
2714
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !V || R, style: O(), children: R ? m.loadingText : m.submitButton }),
2715
+ l && /* @__PURE__ */ s("div", { style: S.errorText, children: l })
2578
2716
  ] }),
2579
- (m || y) && /* @__PURE__ */ d("div", { style: w.linkContainer, children: [
2580
- y && /* @__PURE__ */ d("div", { children: [
2581
- /* @__PURE__ */ d("span", { style: w.divider, children: [
2582
- u.magicLinkText,
2717
+ (p || f) && /* @__PURE__ */ d("div", { style: S.linkContainer, children: [
2718
+ f && /* @__PURE__ */ d("div", { children: [
2719
+ /* @__PURE__ */ d("span", { style: S.divider, children: [
2720
+ m.magicLinkText,
2583
2721
  " "
2584
2722
  ] }),
2585
- /* @__PURE__ */ n("a", { onClick: a, style: w.link, children: u.magicLinkLink })
2723
+ /* @__PURE__ */ s("a", { onClick: a, style: S.link, children: m.magicLinkLink })
2586
2724
  ] }),
2587
- y && m && /* @__PURE__ */ n("div", { style: w.divider, children: "•" }),
2588
- m && /* @__PURE__ */ d("div", { children: [
2589
- /* @__PURE__ */ d("span", { style: w.divider, children: [
2590
- u.loginText,
2725
+ f && p && /* @__PURE__ */ s("div", { style: S.divider, children: "•" }),
2726
+ p && /* @__PURE__ */ d("div", { children: [
2727
+ /* @__PURE__ */ d("span", { style: S.divider, children: [
2728
+ m.loginText,
2591
2729
  " "
2592
2730
  ] }),
2593
- /* @__PURE__ */ n("a", { onClick: o, style: w.link, children: u.loginLink })
2731
+ /* @__PURE__ */ s("a", { onClick: o, style: S.link, children: m.loginLink })
2594
2732
  ] })
2595
2733
  ] })
2596
2734
  ] });
2597
2735
  }
2598
- const Rt = {
2736
+ const Wt = {
2599
2737
  title: "Sign In with Magic Link",
2600
2738
  emailLabel: "Email",
2601
2739
  emailPlaceholder: "Enter your email",
@@ -2613,7 +2751,7 @@ const Rt = {
2613
2751
  loadingText: "Sending magic link...",
2614
2752
  verifyingText: "Verifying magic link...",
2615
2753
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2616
- }, Lt = {
2754
+ }, Vt = {
2617
2755
  container: {
2618
2756
  maxWidth: "400px",
2619
2757
  width: "100%",
@@ -2716,105 +2854,105 @@ const Rt = {
2716
2854
  fontSize: "0.875rem"
2717
2855
  }
2718
2856
  };
2719
- function dr({
2720
- copy: i = {},
2857
+ function Dn({
2858
+ copy: r = {},
2721
2859
  styles: e = {},
2722
2860
  onSuccess: t,
2723
- onError: r,
2724
- onLoginClick: s,
2861
+ onError: n,
2862
+ onLoginClick: i,
2725
2863
  onSignupClick: o,
2726
2864
  showTraditionalLinks: a = !0,
2727
- className: m,
2728
- verifyToken: y,
2865
+ className: p,
2866
+ verifyToken: f,
2729
2867
  frontendUrl: b
2730
2868
  }) {
2731
- const [p, S] = k(""), [f, T] = k(""), [I, C] = k(""), [R, x] = k(!1), [g, $] = k(!1), [A, E] = k(""), [U, D] = k(""), [P, O] = k({}), [c, L] = k(!1), { sendMagicLink: F, verifyMagicLink: l } = oe(), { tenant: H } = ce(), M = { ...Rt, ...i }, h = { ...Lt, ...e };
2732
- re(() => {
2733
- y && u(y);
2734
- }, [y]);
2735
- const u = async (q) => {
2736
- if (!H || !p) {
2737
- E("Missing tenant or email");
2869
+ const [u, w] = A(""), [g, v] = A(""), [M, F] = A(""), [L, P] = A(!1), [h, x] = A(!1), [k, I] = A(""), [U, C] = A(""), [R, B] = A({}), [l, N] = A(!1), { sendMagicLink: D, verifyMagicLink: c } = le(), { tenant: $ } = he(), E = { ...Wt, ...r }, y = { ...Vt, ...e };
2870
+ X(() => {
2871
+ f && m(f);
2872
+ }, [f]);
2873
+ const m = async (O) => {
2874
+ if (!$ || !u) {
2875
+ I("Missing tenant or email");
2738
2876
  return;
2739
2877
  }
2740
- $(!0), E("");
2878
+ x(!0), I("");
2741
2879
  try {
2742
- const V = await l({
2743
- token: q,
2744
- email: p
2880
+ const V = await c({
2881
+ token: O,
2882
+ email: u
2745
2883
  // tenantId inferred from context automatically
2746
2884
  });
2747
2885
  t == null || t(V);
2748
2886
  } catch (V) {
2749
- const v = V.message || "Failed to verify magic link";
2750
- E(v), r == null || r(v);
2887
+ const T = V.message || "Failed to verify magic link";
2888
+ I(T), n == null || n(T);
2751
2889
  } finally {
2752
- $(!1);
2890
+ x(!1);
2753
2891
  }
2754
- }, w = () => {
2755
- const q = {};
2756
- return p.trim() || (q.email = !0), c && !f.trim() && (q.name = !0), O(q), Object.keys(q).length === 0;
2757
- }, _ = async (q) => {
2758
- if (q.preventDefault(), !!w()) {
2759
- if (!(H != null && H.id)) {
2760
- E("Tenant not found");
2892
+ }, S = () => {
2893
+ const O = {};
2894
+ return u.trim() || (O.email = !0), l && !g.trim() && (O.name = !0), B(O), Object.keys(O).length === 0;
2895
+ }, G = async (O) => {
2896
+ if (O.preventDefault(), !!S()) {
2897
+ if (!($ != null && $.id)) {
2898
+ I("Tenant not found");
2761
2899
  return;
2762
2900
  }
2763
- x(!0), E(""), D("");
2901
+ P(!0), I(""), C("");
2764
2902
  try {
2765
- const V = b || (typeof window < "u" ? window.location.origin : ""), v = await F({
2766
- email: p,
2767
- tenantId: H.id,
2903
+ const V = b || (typeof window < "u" ? window.location.origin : ""), T = await D({
2904
+ email: u,
2905
+ tenantId: $.id,
2768
2906
  frontendUrl: V,
2769
- name: c ? f : void 0,
2770
- lastName: c ? I : void 0
2907
+ name: l ? g : void 0,
2908
+ lastName: l ? M : void 0
2771
2909
  });
2772
- D(M.successMessage), t == null || t(v);
2910
+ C(E.successMessage), t == null || t(T);
2773
2911
  } catch (V) {
2774
- const v = V.message || M.errorMessage;
2775
- E(v), r == null || r(v);
2912
+ const T = V.message || E.errorMessage;
2913
+ I(T), n == null || n(T);
2776
2914
  } finally {
2777
- x(!1);
2915
+ P(!1);
2778
2916
  }
2779
2917
  }
2780
- }, K = (q) => ({
2781
- ...h.input,
2782
- ...P[q] ? h.inputError : {}
2783
- }), B = () => ({
2784
- ...h.button,
2785
- ...R || g ? h.buttonLoading : {},
2786
- ...!p || R || g ? h.buttonDisabled : {}
2918
+ }, J = (O) => ({
2919
+ ...y.input,
2920
+ ...R[O] ? y.inputError : {}
2921
+ }), q = () => ({
2922
+ ...y.button,
2923
+ ...L || h ? y.buttonLoading : {},
2924
+ ...!u || L || h ? y.buttonDisabled : {}
2787
2925
  });
2788
- return g ? /* @__PURE__ */ d("div", { className: m, style: h.container, children: [
2789
- /* @__PURE__ */ n("h2", { style: h.title, children: M.verifyingText }),
2790
- /* @__PURE__ */ n("div", { style: { textAlign: "center", padding: "2rem" }, children: /* @__PURE__ */ n("div", { style: { fontSize: "1rem", color: "#6b7280" }, children: "Please wait while we verify your magic link..." }) })
2791
- ] }) : /* @__PURE__ */ d("div", { className: m, style: h.container, children: [
2792
- /* @__PURE__ */ n("h2", { style: h.title, children: M.title }),
2793
- /* @__PURE__ */ n("p", { style: h.description, children: M.description }),
2794
- /* @__PURE__ */ d("form", { onSubmit: _, style: h.form, children: [
2795
- /* @__PURE__ */ d("div", { style: h.fieldGroup, children: [
2796
- /* @__PURE__ */ n("label", { style: h.label, children: M.emailLabel }),
2797
- /* @__PURE__ */ n(
2926
+ return h ? /* @__PURE__ */ d("div", { className: p, style: y.container, children: [
2927
+ /* @__PURE__ */ s("h2", { style: y.title, children: E.verifyingText }),
2928
+ /* @__PURE__ */ s("div", { style: { textAlign: "center", padding: "2rem" }, children: /* @__PURE__ */ s("div", { style: { fontSize: "1rem", color: "#6b7280" }, children: "Please wait while we verify your magic link..." }) })
2929
+ ] }) : /* @__PURE__ */ d("div", { className: p, style: y.container, children: [
2930
+ /* @__PURE__ */ s("h2", { style: y.title, children: E.title }),
2931
+ /* @__PURE__ */ s("p", { style: y.description, children: E.description }),
2932
+ /* @__PURE__ */ d("form", { onSubmit: G, style: y.form, children: [
2933
+ /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
2934
+ /* @__PURE__ */ s("label", { style: y.label, children: E.emailLabel }),
2935
+ /* @__PURE__ */ s(
2798
2936
  "input",
2799
2937
  {
2800
2938
  id: "email",
2801
2939
  name: "email",
2802
2940
  type: "email",
2803
- value: p,
2804
- onChange: (q) => {
2805
- S(q.target.value), P.email && O((V) => ({ ...V, email: !1 }));
2941
+ value: u,
2942
+ onChange: (O) => {
2943
+ w(O.target.value), R.email && B((V) => ({ ...V, email: !1 }));
2806
2944
  },
2807
- placeholder: M.emailPlaceholder,
2808
- style: K("email"),
2809
- disabled: R || g
2945
+ placeholder: E.emailPlaceholder,
2946
+ style: J("email"),
2947
+ disabled: L || h
2810
2948
  }
2811
2949
  )
2812
2950
  ] }),
2813
- !c && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2951
+ !l && /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
2814
2952
  "button",
2815
2953
  {
2816
2954
  type: "button",
2817
- onClick: () => L(!0),
2955
+ onClick: () => N(!0),
2818
2956
  style: {
2819
2957
  background: "none",
2820
2958
  border: "none",
@@ -2826,47 +2964,47 @@ function dr({
2826
2964
  children: "New user? Add your name"
2827
2965
  }
2828
2966
  ) }),
2829
- c && /* @__PURE__ */ d(j, { children: [
2830
- /* @__PURE__ */ d("div", { style: h.fieldGroup, children: [
2831
- /* @__PURE__ */ n("label", { style: h.label, children: M.nameLabel }),
2832
- /* @__PURE__ */ n(
2967
+ l && /* @__PURE__ */ d(_, { children: [
2968
+ /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
2969
+ /* @__PURE__ */ s("label", { style: y.label, children: E.nameLabel }),
2970
+ /* @__PURE__ */ s(
2833
2971
  "input",
2834
2972
  {
2835
2973
  id: "name",
2836
2974
  name: "name",
2837
2975
  type: "text",
2838
- value: f,
2839
- onChange: (q) => {
2840
- T(q.target.value), P.name && O((V) => ({ ...V, name: !1 }));
2976
+ value: g,
2977
+ onChange: (O) => {
2978
+ v(O.target.value), R.name && B((V) => ({ ...V, name: !1 }));
2841
2979
  },
2842
- placeholder: M.namePlaceholder,
2843
- style: K("name"),
2844
- disabled: R || g
2980
+ placeholder: E.namePlaceholder,
2981
+ style: J("name"),
2982
+ disabled: L || h
2845
2983
  }
2846
2984
  )
2847
2985
  ] }),
2848
- /* @__PURE__ */ d("div", { style: h.fieldGroup, children: [
2849
- /* @__PURE__ */ n("label", { style: h.label, children: M.lastNameLabel }),
2850
- /* @__PURE__ */ n(
2986
+ /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
2987
+ /* @__PURE__ */ s("label", { style: y.label, children: E.lastNameLabel }),
2988
+ /* @__PURE__ */ s(
2851
2989
  "input",
2852
2990
  {
2853
2991
  id: "lastName",
2854
2992
  name: "lastName",
2855
2993
  type: "text",
2856
- value: I,
2857
- onChange: (q) => C(q.target.value),
2858
- placeholder: M.lastNamePlaceholder,
2859
- style: h.input,
2860
- disabled: R || g
2994
+ value: M,
2995
+ onChange: (O) => F(O.target.value),
2996
+ placeholder: E.lastNamePlaceholder,
2997
+ style: y.input,
2998
+ disabled: L || h
2861
2999
  }
2862
3000
  )
2863
3001
  ] }),
2864
- /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
3002
+ /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
2865
3003
  "button",
2866
3004
  {
2867
3005
  type: "button",
2868
3006
  onClick: () => {
2869
- L(!1), T(""), C("");
3007
+ N(!1), v(""), F("");
2870
3008
  },
2871
3009
  style: {
2872
3010
  background: "none",
@@ -2880,30 +3018,30 @@ function dr({
2880
3018
  }
2881
3019
  ) })
2882
3020
  ] }),
2883
- /* @__PURE__ */ n("button", { type: "submit", disabled: !p || R || g, style: B(), children: R ? M.loadingText : M.submitButton }),
2884
- A && /* @__PURE__ */ n("div", { style: h.errorText, children: A }),
2885
- U && /* @__PURE__ */ n("div", { style: h.successText, children: U })
3021
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !u || L || h, style: q(), children: L ? E.loadingText : E.submitButton }),
3022
+ k && /* @__PURE__ */ s("div", { style: y.errorText, children: k }),
3023
+ U && /* @__PURE__ */ s("div", { style: y.successText, children: U })
2886
3024
  ] }),
2887
- a && /* @__PURE__ */ d("div", { style: h.linkContainer, children: [
3025
+ a && /* @__PURE__ */ d("div", { style: y.linkContainer, children: [
2888
3026
  /* @__PURE__ */ d("div", { children: [
2889
- /* @__PURE__ */ d("span", { style: h.divider, children: [
2890
- M.loginText,
3027
+ /* @__PURE__ */ d("span", { style: y.divider, children: [
3028
+ E.loginText,
2891
3029
  " "
2892
3030
  ] }),
2893
- /* @__PURE__ */ n("a", { onClick: s, style: h.link, children: M.loginLink })
3031
+ /* @__PURE__ */ s("a", { onClick: i, style: y.link, children: E.loginLink })
2894
3032
  ] }),
2895
- /* @__PURE__ */ n("div", { style: h.divider, children: "•" }),
3033
+ /* @__PURE__ */ s("div", { style: y.divider, children: "•" }),
2896
3034
  /* @__PURE__ */ d("div", { children: [
2897
- /* @__PURE__ */ d("span", { style: h.divider, children: [
2898
- M.signupText,
3035
+ /* @__PURE__ */ d("span", { style: y.divider, children: [
3036
+ E.signupText,
2899
3037
  " "
2900
3038
  ] }),
2901
- /* @__PURE__ */ n("a", { onClick: o, style: h.link, children: M.signupLink })
3039
+ /* @__PURE__ */ s("a", { onClick: o, style: y.link, children: E.signupLink })
2902
3040
  ] })
2903
3041
  ] })
2904
3042
  ] });
2905
3043
  }
2906
- const Et = {
3044
+ const jt = {
2907
3045
  title: "Verifying Magic Link",
2908
3046
  verifyingMessage: "Please wait while we verify your magic link...",
2909
3047
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2911,7 +3049,7 @@ const Et = {
2911
3049
  redirectingMessage: "Redirecting you to the dashboard...",
2912
3050
  retryButton: "Try Again",
2913
3051
  backToLoginButton: "Back to Login"
2914
- }, Oe = {
3052
+ }, Ge = {
2915
3053
  container: {
2916
3054
  maxWidth: "400px",
2917
3055
  width: "100%",
@@ -2998,7 +3136,7 @@ const Et = {
2998
3136
  cursor: "pointer",
2999
3137
  transition: "all 0.15s ease-in-out"
3000
3138
  }
3001
- }, Ft = () => /* @__PURE__ */ n("div", { style: Oe.spinner }), Ct = () => /* @__PURE__ */ d(
3139
+ }, Gt = () => /* @__PURE__ */ s("div", { style: Ge.spinner }), Zt = () => /* @__PURE__ */ d(
3002
3140
  "svg",
3003
3141
  {
3004
3142
  width: "48",
@@ -3011,11 +3149,11 @@ const Et = {
3011
3149
  strokeLinejoin: "round",
3012
3150
  style: { margin: "0 auto 1rem auto", display: "block" },
3013
3151
  children: [
3014
- /* @__PURE__ */ n("path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14" }),
3015
- /* @__PURE__ */ n("polyline", { points: "22,4 12,14.01 9,11.01" })
3152
+ /* @__PURE__ */ s("path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14" }),
3153
+ /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3016
3154
  ]
3017
3155
  }
3018
- ), Dt = () => /* @__PURE__ */ d(
3156
+ ), Kt = () => /* @__PURE__ */ d(
3019
3157
  "svg",
3020
3158
  {
3021
3159
  width: "48",
@@ -3028,114 +3166,114 @@ const Et = {
3028
3166
  strokeLinejoin: "round",
3029
3167
  style: { margin: "0 auto 1rem auto", display: "block" },
3030
3168
  children: [
3031
- /* @__PURE__ */ n("circle", { cx: "12", cy: "12", r: "10" }),
3032
- /* @__PURE__ */ n("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
3033
- /* @__PURE__ */ n("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3169
+ /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "10" }),
3170
+ /* @__PURE__ */ s("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
3171
+ /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3034
3172
  ]
3035
3173
  }
3036
- ), $t = {
3037
- loading: /* @__PURE__ */ n(Ft, {}),
3038
- success: /* @__PURE__ */ n(Ct, {}),
3039
- error: /* @__PURE__ */ n(Dt, {})
3174
+ ), Jt = {
3175
+ loading: /* @__PURE__ */ s(Gt, {}),
3176
+ success: /* @__PURE__ */ s(Zt, {}),
3177
+ error: /* @__PURE__ */ s(Kt, {})
3040
3178
  };
3041
- function ur({
3042
- copy: i = {},
3179
+ function $n({
3180
+ copy: r = {},
3043
3181
  styles: e = {},
3044
3182
  icons: t = {},
3045
- onSuccess: r,
3046
- onError: s,
3183
+ onSuccess: n,
3184
+ onError: i,
3047
3185
  onRetry: o,
3048
3186
  onBackToLogin: a,
3049
- className: m,
3050
- token: y,
3187
+ className: p,
3188
+ token: f,
3051
3189
  email: b,
3052
- appId: p,
3053
- tenantSlug: S,
3054
- autoRedirectDelay: f = 3e3
3190
+ appId: u,
3191
+ tenantSlug: w,
3192
+ autoRedirectDelay: g = 3e3
3055
3193
  }) {
3056
- const [T, I] = k("verifying"), [C, R] = k(""), { verifyMagicLink: x } = oe(), g = { ...Et, ...i }, $ = { ...Oe, ...e }, A = { ...$t, ...t }, E = () => {
3194
+ const [v, M] = A("verifying"), [F, L] = A(""), { verifyMagicLink: P } = le(), h = { ...jt, ...r }, x = { ...Ge, ...e }, k = { ...Jt, ...t }, I = () => {
3057
3195
  if (typeof window > "u") return {};
3058
- const c = new URLSearchParams(window.location.search);
3196
+ const l = new URLSearchParams(window.location.search);
3059
3197
  return {
3060
- token: y || c.get("token") || "",
3061
- email: b || c.get("email") || "",
3062
- appId: p || c.get("appId") || "",
3063
- tenantSlug: S || c.get("tenantSlug") || void 0
3198
+ token: f || l.get("token") || "",
3199
+ email: b || l.get("email") || "",
3200
+ appId: u || l.get("appId") || "",
3201
+ tenantSlug: w || l.get("tenantSlug") || void 0
3064
3202
  };
3065
3203
  }, U = async () => {
3066
- I("verifying"), R("");
3204
+ M("verifying"), L("");
3067
3205
  try {
3068
- const c = E();
3069
- if (!c.token || !c.email)
3206
+ const l = I();
3207
+ if (!l.token || !l.email)
3070
3208
  throw new Error("Missing required parameters: token or email");
3071
- const L = await x({
3072
- token: c.token,
3073
- email: c.email,
3074
- tenantSlug: c.tenantSlug
3209
+ const N = await P({
3210
+ token: l.token,
3211
+ email: l.email,
3212
+ tenantSlug: l.tenantSlug
3075
3213
  });
3076
- I("success"), r == null || r(L), f > 0 && setTimeout(() => {
3077
- I("redirecting");
3078
- }, f);
3079
- } catch (c) {
3080
- const L = c.message || g.errorMessage;
3081
- R(L), I("error"), s == null || s(L);
3214
+ M("success"), n == null || n(N), g > 0 && setTimeout(() => {
3215
+ M("redirecting");
3216
+ }, g);
3217
+ } catch (l) {
3218
+ const N = l.message || h.errorMessage;
3219
+ L(N), M("error"), i == null || i(N);
3082
3220
  }
3083
- }, D = () => {
3221
+ }, C = () => {
3084
3222
  o == null || o(), U();
3085
- }, P = () => {
3223
+ }, R = () => {
3086
3224
  a == null || a();
3087
3225
  };
3088
- re(() => {
3226
+ X(() => {
3089
3227
  U();
3090
3228
  }, []);
3091
- const O = () => {
3092
- switch (T) {
3229
+ const B = () => {
3230
+ switch (v) {
3093
3231
  case "verifying":
3094
- return /* @__PURE__ */ d("div", { style: $.message, children: [
3095
- A.loading,
3096
- g.verifyingMessage
3232
+ return /* @__PURE__ */ d("div", { style: x.message, children: [
3233
+ k.loading,
3234
+ h.verifyingMessage
3097
3235
  ] });
3098
3236
  case "success":
3099
- return /* @__PURE__ */ d(j, { children: [
3100
- A.success,
3101
- /* @__PURE__ */ n("div", { style: $.successMessage, children: g.successMessage })
3237
+ return /* @__PURE__ */ d(_, { children: [
3238
+ k.success,
3239
+ /* @__PURE__ */ s("div", { style: x.successMessage, children: h.successMessage })
3102
3240
  ] });
3103
3241
  case "redirecting":
3104
- return /* @__PURE__ */ d(j, { children: [
3105
- A.loading,
3106
- /* @__PURE__ */ n("div", { style: $.message, children: g.redirectingMessage })
3242
+ return /* @__PURE__ */ d(_, { children: [
3243
+ k.loading,
3244
+ /* @__PURE__ */ s("div", { style: x.message, children: h.redirectingMessage })
3107
3245
  ] });
3108
3246
  case "error":
3109
- return /* @__PURE__ */ d(j, { children: [
3110
- A.error,
3111
- /* @__PURE__ */ n("div", { style: $.errorMessage, children: C || g.errorMessage }),
3112
- /* @__PURE__ */ d("div", { style: $.buttonContainer, children: [
3113
- /* @__PURE__ */ n(
3247
+ return /* @__PURE__ */ d(_, { children: [
3248
+ k.error,
3249
+ /* @__PURE__ */ s("div", { style: x.errorMessage, children: F || h.errorMessage }),
3250
+ /* @__PURE__ */ d("div", { style: x.buttonContainer, children: [
3251
+ /* @__PURE__ */ s(
3114
3252
  "button",
3115
3253
  {
3116
- onClick: D,
3117
- style: $.retryButton,
3118
- onMouseOver: (c) => {
3119
- c.currentTarget.style.backgroundColor = "#2563eb";
3254
+ onClick: C,
3255
+ style: x.retryButton,
3256
+ onMouseOver: (l) => {
3257
+ l.currentTarget.style.backgroundColor = "#2563eb";
3120
3258
  },
3121
- onMouseOut: (c) => {
3122
- c.currentTarget.style.backgroundColor = "#3b82f6";
3259
+ onMouseOut: (l) => {
3260
+ l.currentTarget.style.backgroundColor = "#3b82f6";
3123
3261
  },
3124
- children: g.retryButton
3262
+ children: h.retryButton
3125
3263
  }
3126
3264
  ),
3127
- /* @__PURE__ */ n(
3265
+ /* @__PURE__ */ s(
3128
3266
  "button",
3129
3267
  {
3130
- onClick: P,
3131
- style: $.backButton,
3132
- onMouseOver: (c) => {
3133
- c.currentTarget.style.backgroundColor = "#e5e7eb";
3268
+ onClick: R,
3269
+ style: x.backButton,
3270
+ onMouseOver: (l) => {
3271
+ l.currentTarget.style.backgroundColor = "#e5e7eb";
3134
3272
  },
3135
- onMouseOut: (c) => {
3136
- c.currentTarget.style.backgroundColor = "#f3f4f6";
3273
+ onMouseOut: (l) => {
3274
+ l.currentTarget.style.backgroundColor = "#f3f4f6";
3137
3275
  },
3138
- children: g.backToLoginButton
3276
+ children: h.backToLoginButton
3139
3277
  }
3140
3278
  )
3141
3279
  ] })
@@ -3144,18 +3282,18 @@ function ur({
3144
3282
  return null;
3145
3283
  }
3146
3284
  };
3147
- return /* @__PURE__ */ d("div", { style: $.container, className: m, children: [
3148
- /* @__PURE__ */ n("style", { children: `
3285
+ return /* @__PURE__ */ d("div", { style: x.container, className: p, children: [
3286
+ /* @__PURE__ */ s("style", { children: `
3149
3287
  @keyframes spin {
3150
3288
  0% { transform: rotate(0deg); }
3151
3289
  100% { transform: rotate(360deg); }
3152
3290
  }
3153
3291
  ` }),
3154
- /* @__PURE__ */ n("h1", { style: $.title, children: g.title }),
3155
- O()
3292
+ /* @__PURE__ */ s("h1", { style: x.title, children: h.title }),
3293
+ B()
3156
3294
  ] });
3157
3295
  }
3158
- const Ht = {
3296
+ const Yt = {
3159
3297
  title: "Reset Password",
3160
3298
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3161
3299
  emailLabel: "Email",
@@ -3177,7 +3315,7 @@ const Ht = {
3177
3315
  resetLoadingText: "Resetting...",
3178
3316
  resetSuccessMessage: "Password reset successfully!",
3179
3317
  passwordMismatchError: "Passwords do not match"
3180
- }, Nt = {
3318
+ }, Qt = {
3181
3319
  container: {
3182
3320
  maxWidth: "400px",
3183
3321
  margin: "0 auto",
@@ -3269,186 +3407,186 @@ const Ht = {
3269
3407
  cursor: "pointer"
3270
3408
  }
3271
3409
  };
3272
- function hr({
3273
- copy: i = {},
3410
+ function Hn({
3411
+ copy: r = {},
3274
3412
  styles: e = {},
3275
3413
  mode: t = "request",
3276
- token: r = "",
3277
- onSuccess: s,
3414
+ token: n = "",
3415
+ onSuccess: i,
3278
3416
  onError: o,
3279
3417
  onBackToLogin: a,
3280
- onModeChange: m,
3281
- className: y
3418
+ onModeChange: p,
3419
+ className: f
3282
3420
  }) {
3283
- const [b, p] = k(""), [S, f] = k(r), [T, I] = k(""), [C, R] = k(""), [x, g] = k(!1), [$, A] = k(""), [E, U] = k(""), [D, P] = k({}), { requestPasswordReset: O, confirmPasswordReset: c } = oe(), { tenant: L } = ce(), F = { ...Ht, ...i }, l = { ...Nt, ...e }, H = () => {
3284
- const B = {};
3285
- return b.trim() || (B.email = !0), P(B), Object.keys(B).length === 0;
3286
- }, M = () => {
3287
- const B = {};
3288
- return S.trim() || (B.token = !0), T.trim() || (B.newPassword = !0), C.trim() || (B.confirmPassword = !0), P(B), Object.keys(B).length === 0;
3289
- }, h = async (B) => {
3290
- if (B.preventDefault(), !!H()) {
3291
- if (!(L != null && L.id)) {
3292
- A("Tenant not found");
3421
+ const [b, u] = A(""), [w, g] = A(n), [v, M] = A(""), [F, L] = A(""), [P, h] = A(!1), [x, k] = A(""), [I, U] = A(""), [C, R] = A({}), { requestPasswordReset: B, confirmPasswordReset: l } = le(), { tenant: N } = he(), D = { ...Yt, ...r }, c = { ...Qt, ...e }, $ = () => {
3422
+ const q = {};
3423
+ return b.trim() || (q.email = !0), R(q), Object.keys(q).length === 0;
3424
+ }, E = () => {
3425
+ const q = {};
3426
+ return w.trim() || (q.token = !0), v.trim() || (q.newPassword = !0), F.trim() || (q.confirmPassword = !0), R(q), Object.keys(q).length === 0;
3427
+ }, y = async (q) => {
3428
+ if (q.preventDefault(), !!$()) {
3429
+ if (!(N != null && N.id)) {
3430
+ k("Tenant not found");
3293
3431
  return;
3294
3432
  }
3295
- g(!0), A(""), U("");
3433
+ h(!0), k(""), U("");
3296
3434
  try {
3297
- await O({ email: b, tenantId: L.id }), U(F.successMessage), s == null || s();
3298
- } catch (q) {
3299
- const V = q.message || F.errorMessage;
3300
- A(V), o == null || o(V);
3435
+ await B({ email: b, tenantId: N.id }), U(D.successMessage), i == null || i();
3436
+ } catch (O) {
3437
+ const V = O.message || D.errorMessage;
3438
+ k(V), o == null || o(V);
3301
3439
  } finally {
3302
- g(!1);
3440
+ h(!1);
3303
3441
  }
3304
3442
  }
3305
- }, u = async (B) => {
3306
- if (B.preventDefault(), !!M()) {
3307
- if (T !== C) {
3308
- A(F.passwordMismatchError), P({ confirmPassword: !0 });
3443
+ }, m = async (q) => {
3444
+ if (q.preventDefault(), !!E()) {
3445
+ if (v !== F) {
3446
+ k(D.passwordMismatchError), R({ confirmPassword: !0 });
3309
3447
  return;
3310
3448
  }
3311
- g(!0), A(""), U("");
3449
+ h(!0), k(""), U("");
3312
3450
  try {
3313
- await c({ token: S, newPassword: T }), U(F.resetSuccessMessage), s == null || s();
3314
- } catch (q) {
3315
- const V = q.message || F.errorMessage;
3316
- A(V), o == null || o(V);
3451
+ await l({ token: w, newPassword: v }), U(D.resetSuccessMessage), i == null || i();
3452
+ } catch (O) {
3453
+ const V = O.message || D.errorMessage;
3454
+ k(V), o == null || o(V);
3317
3455
  } finally {
3318
- g(!1);
3456
+ h(!1);
3319
3457
  }
3320
3458
  }
3321
- }, w = (B) => ({
3322
- ...l.input,
3323
- ...D[B] ? l.inputError : {}
3324
- }), _ = () => ({
3325
- ...l.button,
3326
- ...x ? l.buttonLoading : {}
3459
+ }, S = (q) => ({
3460
+ ...c.input,
3461
+ ...C[q] ? c.inputError : {}
3462
+ }), G = () => ({
3463
+ ...c.button,
3464
+ ...P ? c.buttonLoading : {}
3327
3465
  });
3328
3466
  if (t === "reset") {
3329
- const B = S && T && C;
3330
- return /* @__PURE__ */ d("div", { className: y, style: l.container, children: [
3331
- /* @__PURE__ */ n("h2", { style: l.title, children: F.resetTitle }),
3332
- /* @__PURE__ */ n("p", { style: l.subtitle, children: F.resetSubtitle }),
3333
- /* @__PURE__ */ d("form", { onSubmit: u, style: l.form, children: [
3334
- /* @__PURE__ */ d("div", { style: l.fieldGroup, children: [
3335
- /* @__PURE__ */ n("label", { style: l.label, children: F.tokenLabel }),
3336
- /* @__PURE__ */ n(
3467
+ const q = w && v && F;
3468
+ return /* @__PURE__ */ d("div", { className: f, style: c.container, children: [
3469
+ /* @__PURE__ */ s("h2", { style: c.title, children: D.resetTitle }),
3470
+ /* @__PURE__ */ s("p", { style: c.subtitle, children: D.resetSubtitle }),
3471
+ /* @__PURE__ */ d("form", { onSubmit: m, style: c.form, children: [
3472
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3473
+ /* @__PURE__ */ s("label", { style: c.label, children: D.tokenLabel }),
3474
+ /* @__PURE__ */ s(
3337
3475
  "input",
3338
3476
  {
3339
3477
  type: "text",
3340
- value: S,
3341
- onChange: (q) => {
3342
- f(q.target.value), D.token && P((V) => ({ ...V, token: !1 }));
3478
+ value: w,
3479
+ onChange: (O) => {
3480
+ g(O.target.value), C.token && R((V) => ({ ...V, token: !1 }));
3343
3481
  },
3344
- placeholder: F.tokenPlaceholder,
3345
- style: w("token"),
3346
- disabled: x
3482
+ placeholder: D.tokenPlaceholder,
3483
+ style: S("token"),
3484
+ disabled: P
3347
3485
  }
3348
3486
  )
3349
3487
  ] }),
3350
- /* @__PURE__ */ d("div", { style: l.fieldGroup, children: [
3351
- /* @__PURE__ */ n("label", { style: l.label, children: F.newPasswordLabel }),
3352
- /* @__PURE__ */ n(
3488
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3489
+ /* @__PURE__ */ s("label", { style: c.label, children: D.newPasswordLabel }),
3490
+ /* @__PURE__ */ s(
3353
3491
  "input",
3354
3492
  {
3355
3493
  type: "password",
3356
- value: T,
3357
- onChange: (q) => {
3358
- I(q.target.value), D.newPassword && P((V) => ({ ...V, newPassword: !1 }));
3494
+ value: v,
3495
+ onChange: (O) => {
3496
+ M(O.target.value), C.newPassword && R((V) => ({ ...V, newPassword: !1 }));
3359
3497
  },
3360
- placeholder: F.newPasswordPlaceholder,
3361
- style: w("newPassword"),
3362
- disabled: x
3498
+ placeholder: D.newPasswordPlaceholder,
3499
+ style: S("newPassword"),
3500
+ disabled: P
3363
3501
  }
3364
3502
  )
3365
3503
  ] }),
3366
- /* @__PURE__ */ d("div", { style: l.fieldGroup, children: [
3367
- /* @__PURE__ */ n("label", { style: l.label, children: F.confirmPasswordLabel }),
3368
- /* @__PURE__ */ n(
3504
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3505
+ /* @__PURE__ */ s("label", { style: c.label, children: D.confirmPasswordLabel }),
3506
+ /* @__PURE__ */ s(
3369
3507
  "input",
3370
3508
  {
3371
3509
  type: "password",
3372
- value: C,
3373
- onChange: (q) => {
3374
- R(q.target.value), D.confirmPassword && P((V) => ({ ...V, confirmPassword: !1 })), $ === F.passwordMismatchError && A("");
3510
+ value: F,
3511
+ onChange: (O) => {
3512
+ L(O.target.value), C.confirmPassword && R((V) => ({ ...V, confirmPassword: !1 })), x === D.passwordMismatchError && k("");
3375
3513
  },
3376
- placeholder: F.confirmPasswordPlaceholder,
3377
- style: w("confirmPassword"),
3378
- disabled: x
3514
+ placeholder: D.confirmPasswordPlaceholder,
3515
+ style: S("confirmPassword"),
3516
+ disabled: P
3379
3517
  }
3380
3518
  )
3381
3519
  ] }),
3382
- /* @__PURE__ */ n(
3520
+ /* @__PURE__ */ s(
3383
3521
  "button",
3384
3522
  {
3385
3523
  type: "submit",
3386
- disabled: !B || x,
3524
+ disabled: !q || P,
3387
3525
  style: {
3388
- ..._(),
3389
- ...!B || x ? l.buttonDisabled : {}
3526
+ ...G(),
3527
+ ...!q || P ? c.buttonDisabled : {}
3390
3528
  },
3391
- children: x ? F.resetLoadingText : F.resetSubmitButton
3529
+ children: P ? D.resetLoadingText : D.resetSubmitButton
3392
3530
  }
3393
3531
  ),
3394
- $ && /* @__PURE__ */ n("div", { style: l.errorText, children: $ }),
3395
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3532
+ x && /* @__PURE__ */ s("div", { style: c.errorText, children: x }),
3533
+ I && /* @__PURE__ */ s("div", { style: c.successText, children: I })
3396
3534
  ] }),
3397
- /* @__PURE__ */ d("div", { style: l.linkContainer, children: [
3398
- /* @__PURE__ */ n("a", { onClick: a, style: l.link, children: F.backToLoginLink }),
3399
- m && /* @__PURE__ */ d(j, { children: [
3400
- /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3401
- /* @__PURE__ */ n("a", { onClick: () => m("request"), style: l.link, children: "Request New Link" })
3535
+ /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3536
+ /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: D.backToLoginLink }),
3537
+ p && /* @__PURE__ */ d(_, { children: [
3538
+ /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3539
+ /* @__PURE__ */ s("a", { onClick: () => p("request"), style: c.link, children: "Request New Link" })
3402
3540
  ] })
3403
3541
  ] })
3404
3542
  ] });
3405
3543
  }
3406
- const K = b;
3407
- return /* @__PURE__ */ d("div", { className: y, style: l.container, children: [
3408
- /* @__PURE__ */ n("h2", { style: l.title, children: F.title }),
3409
- /* @__PURE__ */ n("p", { style: l.subtitle, children: F.subtitle }),
3410
- /* @__PURE__ */ d("form", { onSubmit: h, style: l.form, children: [
3411
- /* @__PURE__ */ d("div", { style: l.fieldGroup, children: [
3412
- /* @__PURE__ */ n("label", { style: l.label, children: F.emailLabel }),
3413
- /* @__PURE__ */ n(
3544
+ const J = b;
3545
+ return /* @__PURE__ */ d("div", { className: f, style: c.container, children: [
3546
+ /* @__PURE__ */ s("h2", { style: c.title, children: D.title }),
3547
+ /* @__PURE__ */ s("p", { style: c.subtitle, children: D.subtitle }),
3548
+ /* @__PURE__ */ d("form", { onSubmit: y, style: c.form, children: [
3549
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3550
+ /* @__PURE__ */ s("label", { style: c.label, children: D.emailLabel }),
3551
+ /* @__PURE__ */ s(
3414
3552
  "input",
3415
3553
  {
3416
3554
  type: "email",
3417
3555
  value: b,
3418
- onChange: (B) => {
3419
- p(B.target.value), D.email && P((q) => ({ ...q, email: !1 }));
3556
+ onChange: (q) => {
3557
+ u(q.target.value), C.email && R((O) => ({ ...O, email: !1 }));
3420
3558
  },
3421
- placeholder: F.emailPlaceholder,
3422
- style: w("email"),
3423
- disabled: x
3559
+ placeholder: D.emailPlaceholder,
3560
+ style: S("email"),
3561
+ disabled: P
3424
3562
  }
3425
3563
  )
3426
3564
  ] }),
3427
- /* @__PURE__ */ n(
3565
+ /* @__PURE__ */ s(
3428
3566
  "button",
3429
3567
  {
3430
3568
  type: "submit",
3431
- disabled: !K || x,
3569
+ disabled: !J || P,
3432
3570
  style: {
3433
- ..._(),
3434
- ...!K || x ? l.buttonDisabled : {}
3571
+ ...G(),
3572
+ ...!J || P ? c.buttonDisabled : {}
3435
3573
  },
3436
- children: x ? F.loadingText : F.submitButton
3574
+ children: P ? D.loadingText : D.submitButton
3437
3575
  }
3438
3576
  ),
3439
- $ && /* @__PURE__ */ n("div", { style: l.errorText, children: $ }),
3440
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3577
+ x && /* @__PURE__ */ s("div", { style: c.errorText, children: x }),
3578
+ I && /* @__PURE__ */ s("div", { style: c.successText, children: I })
3441
3579
  ] }),
3442
- /* @__PURE__ */ d("div", { style: l.linkContainer, children: [
3443
- /* @__PURE__ */ n("a", { onClick: a, style: l.link, children: F.backToLoginLink }),
3444
- m && /* @__PURE__ */ d(j, { children: [
3445
- /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3446
- /* @__PURE__ */ n("a", { onClick: () => m("reset"), style: l.link, children: "I have a token" })
3580
+ /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3581
+ /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: D.backToLoginLink }),
3582
+ p && /* @__PURE__ */ d(_, { children: [
3583
+ /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3584
+ /* @__PURE__ */ s("a", { onClick: () => p("reset"), style: c.link, children: "I have a token" })
3447
3585
  ] })
3448
3586
  ] })
3449
3587
  ] });
3450
3588
  }
3451
- const Ut = () => /* @__PURE__ */ n(
3589
+ const Xt = () => /* @__PURE__ */ s(
3452
3590
  "div",
3453
3591
  {
3454
3592
  style: {
@@ -3458,9 +3596,9 @@ const Ut = () => /* @__PURE__ */ n(
3458
3596
  height: "100vh",
3459
3597
  fontFamily: "system-ui, sans-serif"
3460
3598
  },
3461
- children: /* @__PURE__ */ n("div", { children: "Loading..." })
3599
+ children: /* @__PURE__ */ s("div", { children: "Loading..." })
3462
3600
  }
3463
- ), Bt = ({ error: i, retry: e }) => /* @__PURE__ */ d(
3601
+ ), en = ({ error: r, retry: e }) => /* @__PURE__ */ d(
3464
3602
  "div",
3465
3603
  {
3466
3604
  style: {
@@ -3474,9 +3612,9 @@ const Ut = () => /* @__PURE__ */ n(
3474
3612
  padding: "20px"
3475
3613
  },
3476
3614
  children: [
3477
- /* @__PURE__ */ n("h2", { style: { color: "#dc3545", marginBottom: "16px" }, children: "Error" }),
3478
- /* @__PURE__ */ n("p", { style: { color: "#6c757d", marginBottom: "24px" }, children: i.message || "Unable to load application" }),
3479
- /* @__PURE__ */ n(
3615
+ /* @__PURE__ */ s("h2", { style: { color: "#dc3545", marginBottom: "16px" }, children: "Error" }),
3616
+ /* @__PURE__ */ s("p", { style: { color: "#6c757d", marginBottom: "24px" }, children: r.message || "Unable to load application" }),
3617
+ /* @__PURE__ */ s(
3480
3618
  "button",
3481
3619
  {
3482
3620
  onClick: e,
@@ -3494,98 +3632,98 @@ const Ut = () => /* @__PURE__ */ n(
3494
3632
  ]
3495
3633
  }
3496
3634
  );
3497
- function gr({
3498
- children: i,
3635
+ function Bn({
3636
+ children: r,
3499
3637
  loadingFallback: e,
3500
3638
  errorFallback: t,
3501
- requireTenant: r = !0
3639
+ requireTenant: n = !0
3502
3640
  }) {
3503
- const { isAppLoading: s, appError: o, retryApp: a } = ge(), m = we(), y = Me(), b = qe(), p = ze(), S = (m == null ? void 0 : m.isTenantLoading) ?? !1, f = (m == null ? void 0 : m.tenantError) ?? null, T = (m == null ? void 0 : m.tenantSlug) ?? null, I = (m == null ? void 0 : m.retryTenant) ?? (() => {
3504
- }), C = (y == null ? void 0 : y.isAuthReady) ?? !0, R = (b == null ? void 0 : b.isReady) ?? !0, x = (p == null ? void 0 : p.isReady) ?? !0, g = r && m && T, U = s || g && S || y && !C || b && !R || p && !x, D = o || (g ? f : null), P = () => {
3505
- o && a(), f && m && I();
3641
+ const { isAppLoading: i, appError: o, retryApp: a } = ye(), p = Se(), f = Le(), b = We(), u = Ve(), w = (p == null ? void 0 : p.isTenantLoading) ?? !1, g = (p == null ? void 0 : p.tenantError) ?? null, v = (p == null ? void 0 : p.tenantSlug) ?? null, M = (p == null ? void 0 : p.retryTenant) ?? (() => {
3642
+ }), F = (f == null ? void 0 : f.isAuthReady) ?? !0, L = (b == null ? void 0 : b.isReady) ?? !0, P = (u == null ? void 0 : u.isReady) ?? !0, h = n && p && v, U = i || h && w || f && !F || b && !L || u && !P, C = o || (h ? g : null), R = () => {
3643
+ o && a(), g && p && M();
3506
3644
  };
3507
3645
  if (U)
3508
- return /* @__PURE__ */ n(j, { children: e || /* @__PURE__ */ n(Ut, {}) });
3509
- if (D) {
3510
- const O = typeof t == "function" ? t(D, P) : t || /* @__PURE__ */ n(Bt, { error: D, retry: P });
3511
- return /* @__PURE__ */ n(j, { children: O });
3646
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Xt, {}) });
3647
+ if (C) {
3648
+ const B = typeof t == "function" ? t(C, R) : t || /* @__PURE__ */ s(en, { error: C, retry: R });
3649
+ return /* @__PURE__ */ s(_, { children: B });
3512
3650
  }
3513
- return /* @__PURE__ */ n(j, { children: i });
3651
+ return /* @__PURE__ */ s(_, { children: r });
3514
3652
  }
3515
- function pr(i = !0) {
3516
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: s } = ge(), o = we(), a = Me(), m = qe(), y = ze(), b = (o == null ? void 0 : o.isTenantLoading) ?? !1, p = (o == null ? void 0 : o.tenantError) ?? null, S = (o == null ? void 0 : o.tenant) ?? null, f = (o == null ? void 0 : o.tenantSlug) ?? null, T = (o == null ? void 0 : o.retryTenant) ?? (() => {
3517
- }), I = (a == null ? void 0 : a.isAuthReady) ?? !0, C = (m == null ? void 0 : m.isReady) ?? !0, R = (y == null ? void 0 : y.isReady) ?? !0, x = i && o && f, E = e || x && b || a && !I || m && !C || y && !R, U = t || (x ? p : null);
3653
+ function qn(r = !0) {
3654
+ const { isAppLoading: e, appError: t, retryApp: n, appInfo: i } = ye(), o = Se(), a = Le(), p = We(), f = Ve(), b = (o == null ? void 0 : o.isTenantLoading) ?? !1, u = (o == null ? void 0 : o.tenantError) ?? null, w = (o == null ? void 0 : o.tenant) ?? null, g = (o == null ? void 0 : o.tenantSlug) ?? null, v = (o == null ? void 0 : o.retryTenant) ?? (() => {
3655
+ }), M = (a == null ? void 0 : a.isAuthReady) ?? !0, F = (p == null ? void 0 : p.isReady) ?? !0, L = (f == null ? void 0 : f.isReady) ?? !0, P = r && o && g, I = e || P && b || a && !M || p && !F || f && !L, U = t || (P ? u : null);
3518
3656
  return {
3519
- isLoading: E,
3657
+ isLoading: I,
3520
3658
  error: U,
3521
- isReady: !E && !U && s !== null && (!x || S !== null),
3659
+ isReady: !I && !U && i !== null && (!P || w !== null),
3522
3660
  retry: () => {
3523
- t && r(), p && o && T();
3661
+ t && n(), u && o && v();
3524
3662
  },
3525
3663
  // Individual states
3526
- app: { isLoading: e, error: t, data: s },
3527
- tenant: o ? { isLoading: b, error: p, data: S } : null,
3528
- auth: a ? { isReady: I } : null,
3529
- featureFlags: m ? { isReady: C } : null,
3530
- subscription: y ? { isReady: R } : null
3664
+ app: { isLoading: e, error: t, data: i },
3665
+ tenant: o ? { isLoading: b, error: u, data: w } : null,
3666
+ auth: a ? { isReady: M } : null,
3667
+ featureFlags: p ? { isReady: F } : null,
3668
+ subscription: f ? { isReady: L } : null
3531
3669
  };
3532
3670
  }
3533
- function fr({
3534
- tenants: i,
3671
+ function On({
3672
+ tenants: r,
3535
3673
  currentTenantId: e,
3536
3674
  onSelect: t,
3537
- className: r = "",
3538
- dropdownClassName: s = "",
3675
+ className: n = "",
3676
+ dropdownClassName: i = "",
3539
3677
  itemClassName: o = "",
3540
3678
  renderItem: a,
3541
- placeholder: m = "Select tenant",
3542
- disabled: y = !1,
3679
+ placeholder: p = "Select tenant",
3680
+ disabled: f = !1,
3543
3681
  showCurrentTenant: b = !0
3544
3682
  }) {
3545
- var $;
3546
- const p = Me(), [S, f] = k(!1), T = Ue(null), I = i ?? (p == null ? void 0 : p.userTenants) ?? [], C = e ?? (($ = p == null ? void 0 : p.currentUser) == null ? void 0 : $.tenantId) ?? null, R = async (A) => {
3547
- f(!1), t ? t(A) : p != null && p.switchToTenant && await p.switchToTenant(A);
3683
+ var x;
3684
+ const u = Le(), [w, g] = A(!1), v = ze(null), M = r ?? (u == null ? void 0 : u.userTenants) ?? [], F = e ?? ((x = u == null ? void 0 : u.currentUser) == null ? void 0 : x.tenantId) ?? null, L = async (k) => {
3685
+ g(!1), t ? t(k) : u != null && u.switchToTenant && await u.switchToTenant(k);
3548
3686
  };
3549
- re(() => {
3550
- const A = (E) => {
3551
- T.current && !T.current.contains(E.target) && f(!1);
3687
+ X(() => {
3688
+ const k = (I) => {
3689
+ v.current && !v.current.contains(I.target) && g(!1);
3552
3690
  };
3553
- return document.addEventListener("mousedown", A), () => document.removeEventListener("mousedown", A);
3691
+ return document.addEventListener("mousedown", k), () => document.removeEventListener("mousedown", k);
3554
3692
  }, []);
3555
- const x = I.find((A) => A.id === C);
3556
- if (I.length === 0)
3693
+ const P = M.find((k) => k.id === F);
3694
+ if (M.length === 0)
3557
3695
  return null;
3558
- if (I.length === 1 && b)
3559
- return /* @__PURE__ */ n("div", { className: r, children: /* @__PURE__ */ n("span", { children: I[0].name }) });
3560
- const g = (A, E) => /* @__PURE__ */ d("span", { style: { fontWeight: E ? "bold" : "normal" }, children: [
3561
- A.name,
3562
- A.role && /* @__PURE__ */ d("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3696
+ if (M.length === 1 && b)
3697
+ return /* @__PURE__ */ s("div", { className: n, children: /* @__PURE__ */ s("span", { children: M[0].name }) });
3698
+ const h = (k, I) => /* @__PURE__ */ d("span", { style: { fontWeight: I ? "bold" : "normal" }, children: [
3699
+ k.name,
3700
+ k.role && /* @__PURE__ */ d("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3563
3701
  "(",
3564
- A.role,
3702
+ k.role,
3565
3703
  ")"
3566
3704
  ] })
3567
3705
  ] });
3568
- return /* @__PURE__ */ d("div", { ref: T, className: r, style: { position: "relative" }, children: [
3706
+ return /* @__PURE__ */ d("div", { ref: v, className: n, style: { position: "relative" }, children: [
3569
3707
  /* @__PURE__ */ d(
3570
3708
  "button",
3571
3709
  {
3572
3710
  type: "button",
3573
- onClick: () => !y && f(!S),
3574
- disabled: y,
3711
+ onClick: () => !f && g(!w),
3712
+ disabled: f,
3575
3713
  style: {
3576
- cursor: y ? "not-allowed" : "pointer",
3577
- opacity: y ? 0.6 : 1
3714
+ cursor: f ? "not-allowed" : "pointer",
3715
+ opacity: f ? 0.6 : 1
3578
3716
  },
3579
3717
  children: [
3580
- x ? x.name : m,
3581
- /* @__PURE__ */ n("span", { style: { marginLeft: 8 }, children: S ? "▲" : "▼" })
3718
+ P ? P.name : p,
3719
+ /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: w ? "▲" : "▼" })
3582
3720
  ]
3583
3721
  }
3584
3722
  ),
3585
- S && /* @__PURE__ */ n(
3723
+ w && /* @__PURE__ */ s(
3586
3724
  "div",
3587
3725
  {
3588
- className: s,
3726
+ className: i,
3589
3727
  style: {
3590
3728
  position: "absolute",
3591
3729
  top: "100%",
@@ -3599,34 +3737,34 @@ function fr({
3599
3737
  maxHeight: 300,
3600
3738
  overflowY: "auto"
3601
3739
  },
3602
- children: I.map((A) => {
3603
- const E = A.id === C;
3604
- return /* @__PURE__ */ n(
3740
+ children: M.map((k) => {
3741
+ const I = k.id === F;
3742
+ return /* @__PURE__ */ s(
3605
3743
  "div",
3606
3744
  {
3607
3745
  className: o,
3608
- onClick: () => R(A.id),
3746
+ onClick: () => L(k.id),
3609
3747
  style: {
3610
3748
  padding: "8px 12px",
3611
3749
  cursor: "pointer",
3612
- backgroundColor: E ? "#f0f0f0" : "transparent"
3750
+ backgroundColor: I ? "#f0f0f0" : "transparent"
3613
3751
  },
3614
3752
  onMouseEnter: (U) => {
3615
- E || (U.target.style.backgroundColor = "#f5f5f5");
3753
+ I || (U.target.style.backgroundColor = "#f5f5f5");
3616
3754
  },
3617
3755
  onMouseLeave: (U) => {
3618
- E || (U.target.style.backgroundColor = "transparent");
3756
+ I || (U.target.style.backgroundColor = "transparent");
3619
3757
  },
3620
- children: a ? a(A, E) : g(A, E)
3758
+ children: a ? a(k, I) : h(k, I)
3621
3759
  },
3622
- A.id
3760
+ k.id
3623
3761
  );
3624
3762
  })
3625
3763
  }
3626
3764
  )
3627
3765
  ] });
3628
3766
  }
3629
- class mr {
3767
+ class zn {
3630
3768
  constructor(e, t) {
3631
3769
  this.httpService = e, this.sessionManager = t;
3632
3770
  }
@@ -3645,9 +3783,9 @@ class mr {
3645
3783
  async getPermissions(e) {
3646
3784
  if (!this.sessionManager)
3647
3785
  throw new Error("SessionManager is required for private endpoints");
3648
- const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
3649
- e != null && e.page && r.append("page", e.page.toString()), e != null && e.limit && r.append("limit", e.limit.toString()), e != null && e.sortBy && r.append("sortBy", e.sortBy), e != null && e.sortOrder && r.append("sortOrder", e.sortOrder);
3650
- const s = `/permissions/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
3786
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
3787
+ e != null && e.page && n.append("page", e.page.toString()), e != null && e.limit && n.append("limit", e.limit.toString()), e != null && e.sortBy && n.append("sortBy", e.sortBy), e != null && e.sortOrder && n.append("sortOrder", e.sortOrder);
3788
+ const i = `/permissions/${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i, {
3651
3789
  headers: t
3652
3790
  });
3653
3791
  return {
@@ -3666,12 +3804,12 @@ class mr {
3666
3804
  async updatePermission(e, t) {
3667
3805
  if (!this.sessionManager)
3668
3806
  throw new Error("SessionManager is required for private endpoints");
3669
- const r = await this.sessionManager.getAuthHeaders();
3807
+ const n = await this.sessionManager.getAuthHeaders();
3670
3808
  return (await this.httpService.put(
3671
3809
  `/permissions/${e}`,
3672
3810
  t,
3673
3811
  {
3674
- headers: r
3812
+ headers: n
3675
3813
  }
3676
3814
  )).data;
3677
3815
  }
@@ -3685,16 +3823,16 @@ class mr {
3685
3823
  }
3686
3824
  // Public endpoint - no auth required
3687
3825
  async getAppPermissions(e, t) {
3688
- const r = new URLSearchParams();
3689
- t != null && t.page && r.append("page", t.page.toString()), t != null && t.limit && r.append("limit", t.limit.toString()), t != null && t.sortBy && r.append("sortBy", t.sortBy), t != null && t.sortOrder && r.append("sortOrder", t.sortOrder);
3690
- const s = `/permissions/apps/${e}${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s);
3826
+ const n = new URLSearchParams();
3827
+ t != null && t.page && n.append("page", t.page.toString()), t != null && t.limit && n.append("limit", t.limit.toString()), t != null && t.sortBy && n.append("sortBy", t.sortBy), t != null && t.sortOrder && n.append("sortOrder", t.sortOrder);
3828
+ const i = `/permissions/apps/${e}${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i);
3691
3829
  return {
3692
3830
  permissions: o.data,
3693
3831
  meta: o.meta
3694
3832
  };
3695
3833
  }
3696
3834
  }
3697
- class yr {
3835
+ class _n {
3698
3836
  constructor(e, t) {
3699
3837
  this.httpService = e, this.sessionManager = t;
3700
3838
  }
@@ -3709,9 +3847,9 @@ class yr {
3709
3847
  )).data;
3710
3848
  }
3711
3849
  async getSubscriptionPlans(e) {
3712
- const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
3713
- e != null && e.page && r.append("page", e.page.toString()), e != null && e.limit && r.append("limit", e.limit.toString()), e != null && e.sortBy && r.append("sortBy", e.sortBy), e != null && e.sortOrder && r.append("sortOrder", e.sortOrder), e != null && e.appId && r.append("appId", e.appId);
3714
- const s = `/subscription-plans/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
3850
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
3851
+ e != null && e.page && n.append("page", e.page.toString()), e != null && e.limit && n.append("limit", e.limit.toString()), e != null && e.sortBy && n.append("sortBy", e.sortBy), e != null && e.sortOrder && n.append("sortOrder", e.sortOrder), e != null && e.appId && n.append("appId", e.appId);
3852
+ const i = `/subscription-plans/${n.toString() ? `?${n.toString()}` : ""}`, o = await this.httpService.get(i, {
3715
3853
  headers: t
3716
3854
  });
3717
3855
  return {
@@ -3729,12 +3867,12 @@ class yr {
3729
3867
  )).data;
3730
3868
  }
3731
3869
  async updateSubscriptionPlan(e, t) {
3732
- const r = await this.sessionManager.getAuthHeaders();
3870
+ const n = await this.sessionManager.getAuthHeaders();
3733
3871
  return (await this.httpService.put(
3734
3872
  `/subscription-plans/${e}`,
3735
3873
  t,
3736
3874
  {
3737
- headers: r
3875
+ headers: n
3738
3876
  }
3739
3877
  )).data;
3740
3878
  }
@@ -3745,7 +3883,7 @@ class yr {
3745
3883
  });
3746
3884
  }
3747
3885
  }
3748
- class wr {
3886
+ class Wn {
3749
3887
  constructor(e) {
3750
3888
  this.httpService = e;
3751
3889
  }
@@ -3754,7 +3892,7 @@ class wr {
3754
3892
  return await this.httpService.get("/health");
3755
3893
  }
3756
3894
  }
3757
- class br {
3895
+ class Vn {
3758
3896
  // Date string to Date object
3759
3897
  static toDate(e) {
3760
3898
  return new Date(e);
@@ -3871,54 +4009,138 @@ class br {
3871
4009
  // Transform query parameters for API calls
3872
4010
  static transformQueryParams(e) {
3873
4011
  const t = new URLSearchParams();
3874
- return Object.entries(e).forEach(([r, s]) => {
3875
- s != null && s !== "" && t.append(r, String(s));
4012
+ return Object.entries(e).forEach(([n, i]) => {
4013
+ i != null && i !== "" && t.append(n, String(i));
3876
4014
  }), t;
3877
4015
  }
3878
4016
  }
4017
+ const Ze = "returnTo", xe = "zone_return_to", Pe = "zone_return_to";
4018
+ function jn(r = {}) {
4019
+ const {
4020
+ zoneRoots: e = {},
4021
+ returnToParam: t = Ze,
4022
+ returnToStorage: n = "url"
4023
+ } = r, i = lt(), [o, a] = ct(), { isAuthenticated: p, currentUser: f } = le(), { tenant: b } = ue(), u = K(() => ({ ...je, ...e }), [e]), w = !!b, g = f == null ? void 0 : f.userType, v = K(() => {
4024
+ switch (n) {
4025
+ case "url":
4026
+ return o.get(t);
4027
+ case "session":
4028
+ return sessionStorage.getItem(xe);
4029
+ case "local":
4030
+ return localStorage.getItem(Pe);
4031
+ default:
4032
+ return null;
4033
+ }
4034
+ }, [n, o, t]), M = re(() => {
4035
+ switch (n) {
4036
+ case "url": {
4037
+ const h = new URLSearchParams(o);
4038
+ h.delete(t), a(h, { replace: !0 });
4039
+ break;
4040
+ }
4041
+ case "session":
4042
+ sessionStorage.removeItem(xe);
4043
+ break;
4044
+ case "local":
4045
+ localStorage.removeItem(Pe);
4046
+ break;
4047
+ }
4048
+ }, [n, o, t, a]), F = re(
4049
+ (h) => {
4050
+ switch (n) {
4051
+ case "url": {
4052
+ const x = new URLSearchParams(o);
4053
+ x.set(t, h), a(x, { replace: !0 });
4054
+ break;
4055
+ }
4056
+ case "session":
4057
+ sessionStorage.setItem(xe, h);
4058
+ break;
4059
+ case "local":
4060
+ localStorage.setItem(Pe, h);
4061
+ break;
4062
+ }
4063
+ },
4064
+ [n, o, t, a]
4065
+ ), L = re(
4066
+ (h) => {
4067
+ const x = u[h] || u.default;
4068
+ i(x);
4069
+ },
4070
+ [i, u]
4071
+ ), P = re(() => w ? p ? g === se.TENANT_ADMIN ? u.tenantAdmin : u.tenantUser : u.tenantGuest : p ? g === se.TENANT_ADMIN ? u.publicAdmin : u.publicUser : u.publicGuest, [w, p, g, u]);
4072
+ return {
4073
+ returnToUrl: v,
4074
+ clearReturnTo: M,
4075
+ setReturnTo: F,
4076
+ navigateToZone: L,
4077
+ getSmartRedirect: P
4078
+ };
4079
+ }
4080
+ function Gn(r, e, t = Ze, n = "url") {
4081
+ if (!e || n !== "url")
4082
+ return r;
4083
+ const i = new URL(r, window.location.origin);
4084
+ return i.searchParams.set(t, e), i.pathname + i.search;
4085
+ }
3879
4086
  export {
3880
- br as ApiMappers,
3881
- Fe as AppApiService,
3882
- gr as AppLoader,
3883
- Jt as AppProvider,
3884
- rt as AuthApiService,
3885
- Zt as AuthProvider,
3886
- ar as FeatureFlag,
3887
- ut as FeatureFlagApiService,
3888
- er as FeatureFlagProvider,
3889
- wr as HealthApiService,
3890
- ne as HttpService,
3891
- ir as LandingRoute,
3892
- lr as LoginForm,
3893
- dr as MagicLinkForm,
3894
- ur as MagicLinkVerify,
3895
- hr as PasswordRecoveryForm,
3896
- mr as PermissionApiService,
3897
- rr as Protected,
3898
- nr as ProtectedRoute,
3899
- Ce as RoleApiService,
3900
- ke as SessionManager,
3901
- cr as SignupForm,
3902
- gt as SubscriptionApiService,
3903
- or as SubscriptionGuard,
3904
- yr as SubscriptionPlanApiService,
3905
- tr as SubscriptionProvider,
3906
- ue as TenantApiService,
3907
- Yt as TenantProvider,
3908
- sr as TenantRoute,
3909
- fr as TenantSelector,
3910
- nt as UserApiService,
3911
- fe as UserType,
3912
- Kt as useApi,
3913
- ge as useApp,
3914
- pr as useAppLoaderState,
3915
- oe as useAuth,
3916
- ht as useFeatureFlags,
3917
- Xt as useSettings,
3918
- pt as useSubscription,
3919
- ye as useTenant,
3920
- ce as useTenantInfo,
3921
- we as useTenantOptional,
3922
- Qt as useTenantSettings
4087
+ Pn as AdminZone,
4088
+ Vn as ApiMappers,
4089
+ Ce as AppApiService,
4090
+ Bn as AppLoader,
4091
+ dn as AppProvider,
4092
+ dt as AuthApiService,
4093
+ fn as AuthProvider,
4094
+ An as AuthenticatedZone,
4095
+ It as DEFAULT_ZONE_PRESETS,
4096
+ je as DEFAULT_ZONE_ROOTS,
4097
+ Nn as FeatureFlag,
4098
+ bt as FeatureFlagApiService,
4099
+ mn as FeatureFlagProvider,
4100
+ xn as GuestZone,
4101
+ Wn as HealthApiService,
4102
+ ie as HttpService,
4103
+ vn as LandingRoute,
4104
+ Un as LoginForm,
4105
+ Dn as MagicLinkForm,
4106
+ $n as MagicLinkVerify,
4107
+ In as OpenZone,
4108
+ Hn as PasswordRecoveryForm,
4109
+ zn as PermissionApiService,
4110
+ wn as Protected,
4111
+ bn as ProtectedRoute,
4112
+ kn as PublicZone,
4113
+ De as RoleApiService,
4114
+ Ae as SessionManager,
4115
+ Cn as SignupForm,
4116
+ vt as SubscriptionApiService,
4117
+ Fn as SubscriptionGuard,
4118
+ _n as SubscriptionPlanApiService,
4119
+ yn as SubscriptionProvider,
4120
+ pe as TenantApiService,
4121
+ Mn as TenantAuthenticatedZone,
4122
+ En as TenantGuestZone,
4123
+ Ln as TenantOpenZone,
4124
+ hn as TenantProvider,
4125
+ Sn as TenantRoute,
4126
+ On as TenantSelector,
4127
+ Tn as TenantZone,
4128
+ ut as UserApiService,
4129
+ se as UserType,
4130
+ Rn as UserZone,
4131
+ ae as ZoneRoute,
4132
+ Gn as buildRedirectUrl,
4133
+ un as useApi,
4134
+ ye as useApp,
4135
+ qn as useAppLoaderState,
4136
+ le as useAuth,
4137
+ St as useFeatureFlags,
4138
+ pn as useSettings,
4139
+ Tt as useSubscription,
4140
+ ue as useTenant,
4141
+ he as useTenantInfo,
4142
+ Se as useTenantOptional,
4143
+ gn as useTenantSettings,
4144
+ jn as useZoneNavigation
3923
4145
  };
3924
4146
  //# sourceMappingURL=index.es.js.map