@skylabs-digital/react-identity-access 2.12.0 → 2.14.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 ue, useMemo as Z, useState as A, useCallback as re, useEffect as X, useContext as oe, useRef as We } from "react";
3
+ import { useLocation as be, Navigate as me, useNavigate as dt, useSearchParams as ut } 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, o) {
16
+ return this.executeRequest(e, t, n, o, !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, o, i = !1) {
19
+ const a = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, p = (o == null ? void 0 : o.timeout) || this.timeout;
20
+ let f = {
21
21
  "Content-Type": "application/json",
22
- ...s == null ? void 0 : s.headers
22
+ ...o == null ? void 0 : o.headers
23
23
  };
24
- if (!(s != null && s.skipAuth) && this.sessionManager)
24
+ if (!(o != null && o.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 b = await this.sessionManager.getAuthHeaders();
27
+ f = { ...f, ...b };
28
+ } catch (b) {
29
+ console.warn("Failed to inject auth headers:", b);
30
30
  }
31
- const b = new AbortController(), p = setTimeout(() => b.abort(), m);
31
+ const w = new AbortController(), u = setTimeout(() => w.abort(), p);
32
32
  try {
33
- const S = await fetch(a, {
33
+ const b = await fetch(a, {
34
34
  method: e,
35
- headers: y,
36
- body: r ? JSON.stringify(r) : void 0,
37
- signal: b.signal
35
+ headers: f,
36
+ body: n ? JSON.stringify(n) : void 0,
37
+ signal: w.signal
38
38
  });
39
- if (clearTimeout(p), S.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
39
+ if (clearTimeout(u), b.status === 401 && !(o != null && o.skipRetry) && !i && this.sessionManager)
40
40
  try {
41
41
  const T = this.sessionManager.getTokens();
42
42
  if (T != null && T.refreshToken)
43
- return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, r, s, !0);
43
+ return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, n, o, !0);
44
44
  } catch {
45
- throw new Error(`HTTP ${S.status}: ${S.statusText}`);
45
+ throw new Error(`HTTP ${b.status}: ${b.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 (!b.ok)
48
+ throw new Error(`HTTP ${b.status}: ${b.statusText}`);
49
+ const g = b.headers.get("content-type");
50
+ return !g || !g.includes("application/json") ? {} : await b.json();
51
+ } catch (b) {
52
+ throw clearTimeout(u), b instanceof Error && b.name === "AbortError" ? new Error(`Request timeout after ${p}ms`) : b;
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 $e {
69
69
  constructor(e, t) {
70
70
  this.httpService = e, this.sessionManager = t;
71
71
  }
@@ -76,14 +76,14 @@ 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 o = `/apps/${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o, {
82
82
  headers: t
83
83
  });
84
84
  return {
85
- apps: o.data,
86
- meta: o.meta
85
+ apps: i.data,
86
+ meta: i.meta
87
87
  };
88
88
  }
89
89
  async getAppById(e) {
@@ -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 o = 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: o }
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 = ue(null);
128
+ function un({ config: r, children: e }) {
129
+ const t = Z(
130
130
  () => {
131
- var f, T, I;
131
+ var g, T, I;
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: ((T = r.cache) == null ? void 0 : T.ttl) ?? 3e5,
135
135
  // 5 minutes default
136
- storageKey: ((I = i.cache) == null ? void 0 : I.storageKey) ?? `app_cache_${i.appId}`
136
+ storageKey: ((I = r.cache) == null ? void 0 : I.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, o] = 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 T = JSON.parse(g);
146
+ return Date.now() - T.timestamp < t.ttl && T.appId === r.appId ? T.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
+ }), [i, a] = A(!n), [p, f] = A(null), w = Z(() => {
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,
159
- isAppLoading: o,
160
- appError: m,
161
- retryApp: f
158
+ appInfo: n,
159
+ isAppLoading: i,
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, i, 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 T = new ie(r.baseUrl), N = await new $e(T, {}).getPublicAppInfo(r.appId);
169
+ if (o(N), t.enabled)
170
170
  try {
171
- const R = {
172
- data: C,
171
+ const M = {
172
+ data: N,
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(M));
177
+ } catch (M) {
178
+ console.warn("Failed to cache app info:", M);
179
179
  }
180
180
  } catch (T) {
181
181
  const I = T instanceof Error ? T : new Error("Failed to load app information");
182
- y(I), s(null);
182
+ f(I), o(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
+ ), b = 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);
191
+ const g = localStorage.getItem(t.storageKey);
192
+ if (!g) return;
193
+ const T = JSON.parse(g);
194
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,
195
+ const N = new ie(r.baseUrl), P = await new $e(N, {}).getPublicAppInfo(r.appId);
196
+ o(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 ? b() : u();
210
+ }, []), /* @__PURE__ */ s(Re.Provider, { value: w, 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 Ve() {
219
+ return oe(Re);
220
220
  }
221
- const Kt = ge;
222
- class ke {
221
+ const hn = 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,13 +256,13 @@ 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: o, tokenType: i } = this.tokenStorage.get() || {};
260
260
  return e ? {
261
261
  accessToken: e,
262
262
  refreshToken: t,
263
- expiresAt: r,
264
- expiresIn: s,
265
- tokenType: o
263
+ expiresAt: n,
264
+ expiresIn: o,
265
+ tokenType: i
266
266
  } : null;
267
267
  }
268
268
  clearTokens() {
@@ -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: o }) => o(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: o }) => o(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 o = await n.json();
324
324
  this.setTokens({
325
- accessToken: s.accessToken,
326
- refreshToken: s.refreshToken || e,
327
- expiresIn: s.expiresIn
325
+ accessToken: o.accessToken,
326
+ refreshToken: o.refreshToken || e,
327
+ expiresIn: o.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], o = atob(n.replace(/-/g, "+").replace(/_/g, "/"));
356
+ return JSON.parse(o);
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 ht {
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 He {
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,37 +466,37 @@ 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 o = `/roles/app/${e}${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o);
472
472
  return {
473
- roles: o.data,
474
- meta: o.meta
473
+ roles: i.data,
474
+ meta: i.meta
475
475
  };
476
476
  }
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(), o = new URLSearchParams();
497
+ t != null && t.page && o.append("page", t.page.toString()), t != null && t.limit && o.append("limit", t.limit.toString()), t != null && t.sortBy && o.append("sortBy", t.sortBy), t != null && t.sortOrder && o.append("sortOrder", t.sortOrder);
498
+ const i = `/roles/user/${e}${o.toString() ? `?${o.toString()}` : ""}`, a = await this.httpService.get(i, {
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 gt {
508
508
  constructor(e, t) {
509
509
  this.httpService = e, this.sessionManager = t;
510
510
  }
@@ -515,14 +515,14 @@ 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 o = `/users/${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o, {
521
521
  headers: t
522
522
  });
523
523
  return {
524
- users: o.data,
525
- meta: o.meta
524
+ users: i.data,
525
+ meta: i.meta
526
526
  };
527
527
  }
528
528
  async getUserById(e) {
@@ -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 fe {
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,14 +559,14 @@ 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 o = `/tenants/${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o, {
565
565
  headers: t
566
566
  });
567
567
  return {
568
- tenants: o.data,
569
- meta: o.meta
568
+ tenants: i.data,
569
+ meta: i.meta
570
570
  };
571
571
  }
572
572
  async getTenantById(e) {
@@ -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 pt(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 o = e.toLowerCase(), i = r.toLowerCase();
630
+ if (i === o || i === `www.${o}`)
631
631
  return null;
632
- if (o.endsWith(`.${s}`)) {
633
- const a = o.slice(0, -(s.length + 1));
632
+ if (i.endsWith(`.${o}`)) {
633
+ const a = i.slice(0, -(o.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 ft(r, e = "tenant", t) {
642
+ const o = new URLSearchParams(r).get(e);
643
+ return o ? (t && t.setItem("tenant", o), o) : 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 mt(r, e, t) {
646
+ const { tenantMode: n, baseDomain: o, selectorParam: i } = r;
647
+ return n === "subdomain" ? pt(e.hostname, o) : n === "selector" ? ft(e.search, i, t) : null;
648
648
  }
649
- function at(i, e, t) {
649
+ function yt(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 Be(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 wt(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 bt() {
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 = wt(e);
681
681
  return console.log("[CrossDomainAuth] Token decode result:", {
682
682
  success: !!t,
683
683
  hasAccessToken: !!(t != null && t.accessToken),
@@ -685,135 +685,135 @@ function ct() {
685
685
  expiresIn: t == null ? void 0 : t.expiresIn
686
686
  }), t;
687
687
  }
688
- function dt() {
688
+ function St() {
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 = ue(null);
697
+ function gn({ config: r, children: e }) {
698
+ const { baseUrl: t, appInfo: n, appId: o } = ye(), i = re(() => typeof window > "u" ? null : mt(
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(() => i()), f = Z(
710
710
  () => {
711
- var l, H, M;
711
+ var c, H, F;
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: ((H = r.cache) == null ? void 0 : H.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: ((F = r.cache) == null ? void 0 : F.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
+ ), [w, 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 H = JSON.parse(c);
727
+ return Date.now() - H.timestamp < f.ttl && H.tenantSlug === a ? H.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);
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))
731
+ }), [b, g] = A(!w && !r.initialTenant), [T, I] = A(null), [N, M] = A(null), [P, h] = A(!1), [x, S] = A(null);
732
+ X(() => {
733
+ const c = i();
734
+ p(c);
735
+ }, [i]);
736
+ const L = (n == null ? void 0 : n.settingsSchema) || null, E = re(
737
+ async (c, H = !1) => {
738
+ if (!(!H && f.enabled && w && w.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), I(null);
741
+ const F = new ie(t), m = await new fe(F, o).getPublicTenantInfo(c);
742
+ if (u(m), f.enabled)
743
743
  try {
744
- const w = {
745
- data: u,
744
+ const v = {
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(v));
750
+ } catch (v) {
751
+ console.warn("Failed to cache tenant info:", v);
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 (F) {
754
+ const y = F instanceof Error ? F : new Error("Failed to load tenant information");
755
+ I(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, o, f, w]
761
+ ), C = re(async () => {
762
+ if (!(!f.enabled || !w || !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 H = JSON.parse(c);
767
+ if (Date.now() - H.timestamp > f.ttl * 0.5) {
768
+ const y = new ie(t), v = await new fe(y, o).getPublicTenantInfo(a);
769
+ u(v);
770
+ const G = {
771
+ data: v,
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 () => {
781
- if (b != null && b.id)
780
+ }, [t, o, f, w, a]), R = re(async () => {
781
+ if (w != null && w.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), S(null);
784
+ const c = new ie(t), F = await new fe(c, w.appId).getTenantSettings(w.id);
785
+ M(F);
786
+ } catch (c) {
787
+ const H = c instanceof Error ? c : new Error("Failed to load tenant settings");
788
+ S(H), M(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, w]), $ = re(() => {
793
+ R();
794
+ }, [R]), l = re(
795
+ (c) => {
796
+ if (!L)
797
797
  return { isValid: !0, errors: [] };
798
798
  const H = [];
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 L.properties && Object.entries(L.properties).forEach(([F, y]) => {
801
+ var v;
802
+ const m = c[F];
803
+ if ((v = L.required) != null && v.includes(F) && m == null) {
804
+ H.push(`Field '${F}' 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" ? H.push(`Field '${F}' must be a string`) : (G === "number" || G === "integer") && J !== "number" ? H.push(`Field '${F}' must be a number`) : G === "boolean" && J !== "boolean" ? H.push(`Field '${F}' must be a boolean`) : G === "array" && !Array.isArray(m) && H.push(`Field '${F}' 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 && H.push(
813
+ `Field '${F}' must be at least ${y.minLength} characters long`
814
+ ), y.maxLength !== void 0 && typeof m == "string" && m.length > y.maxLength && H.push(
815
+ `Field '${F}' must be no more than ${y.maxLength} characters long`
816
+ ), y.minimum !== void 0 && typeof m == "number" && m < y.minimum && H.push(`Field '${F}' must be at least ${y.minimum}`), y.maximum !== void 0 && typeof m == "number" && m > y.maximum && H.push(`Field '${F}' must be no more than ${y.maximum}`), y.pattern && typeof m == "string" && (new RegExp(y.pattern).test(m) || H.push(`Field '${F}' does not match the required pattern`)), y.enum && !y.enum.includes(m) && H.push(`Field '${F}' must be one of: ${y.enum.join(", ")}`);
817
817
  }
818
818
  }), {
819
819
  isValid: H.length === 0,
@@ -826,401 +826,401 @@ function Yt({ config: i, children: e }) {
826
826
  };
827
827
  }
828
828
  },
829
- [E]
829
+ [L]
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 ? w ? C() : E(a) : !r.initialTenant && !a && (u(null), I(null), g(!1));
833
+ }, [r.initialTenant, a, w, E, C]), X(() => {
834
+ w != null && w.id ? R() : (M(null), S(null), h(!1));
835
+ }, [w == null ? void 0 : w.id, R]);
836
+ const D = re(
837
+ (c, H) => {
838
+ const { mode: F = "reload", tokens: y, redirectPath: m } = H || {}, v = r.tenantMode || "selector";
839
+ if (localStorage.setItem("tenant", c), v === "subdomain") {
840
+ const G = window.location.hostname, J = yt(
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((k, K) => {
854
+ K !== de && O.searchParams.set(K, k);
855
+ }), y && O.searchParams.set(de, Be(y)), window.location.href = O.toString();
856
+ } else if (v === "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, Be(y)), F === "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), E(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, E]
868
+ ), U = Z(() => ({
869
869
  // Tenant info
870
- tenant: b,
870
+ tenant: w,
871
871
  tenantSlug: a,
872
- isTenantLoading: S,
872
+ isTenantLoading: b,
873
873
  tenantError: T,
874
874
  retryTenant: () => {
875
- a && U(a);
875
+ a && E(a);
876
876
  },
877
877
  // Settings
878
- settings: C,
879
- settingsSchema: E,
880
- isSettingsLoading: x,
881
- settingsError: $,
878
+ settings: N,
879
+ settingsSchema: L,
880
+ isSettingsLoading: P,
881
+ settingsError: x,
882
882
  // Actions
883
- refreshSettings: O,
884
- switchTenant: L,
883
+ refreshSettings: $,
884
+ switchTenant: D,
885
885
  // Validation
886
- validateSettings: c
886
+ validateSettings: l
887
887
  }), [
888
- b,
888
+ w,
889
889
  a,
890
- S,
890
+ b,
891
891
  T,
892
- C,
893
- E,
892
+ N,
893
+ L,
894
+ P,
894
895
  x,
895
896
  $,
896
- O,
897
- L,
898
- c
897
+ D,
898
+ l
899
899
  ]);
900
- return /* @__PURE__ */ n(Ae.Provider, { value: F, children: e });
900
+ return /* @__PURE__ */ s(Ie.Provider, { value: U, children: e });
901
901
  }
902
- function ye() {
903
- const i = se(Ae);
904
- if (!i)
902
+ function he() {
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 pn = he;
912
+ function fn() {
913
+ const { settings: r, settingsSchema: e, isSettingsLoading: t, settingsError: n, validateSettings: o } = he();
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: o
920
920
  };
921
921
  }
922
- function ce() {
923
- const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = ye();
922
+ function ge() {
923
+ const { tenant: r, tenantSlug: e, isTenantLoading: t, tenantError: n, retryTenant: o } = he();
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: o
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 = ue(null);
933
+ function mn({ config: r = {}, children: e }) {
934
+ const { appId: t, baseUrl: n } = ye(), { tenant: o, tenantSlug: i, switchTenant: a } = he(), [p, f] = A(r.initialRoles || []), [w, u] = A(!r.initialRoles), [b, g] = A(null), [T, I] = A(!1), [N, M] = A(null), [P, h] = A(0), [x, S] = A(() => {
935
935
  try {
936
- const v = localStorage.getItem("userTenants");
937
- return v ? JSON.parse(v) : [];
936
+ const k = localStorage.getItem("userTenants");
937
+ return k ? JSON.parse(k) : [];
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
+ }), [L, E] = A(!1), C = We({ done: !1, urlTokens: null });
942
+ C.current.done || (C.current.done = !0, C.current.urlTokens = bt(), 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({
950
- tenantSlug: o,
951
- onRefreshFailed: i.onRefreshFailed,
952
- baseUrl: r
945
+ const [R, $] = A(() => {
946
+ const k = C.current.urlTokens !== null;
947
+ return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", k), k;
948
+ }), l = Z(() => {
949
+ const k = new Ae({
950
+ tenantSlug: i,
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"), k.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:", k.hasValidSession())), k;
959
+ }, [i, n, r.onRefreshFailed]), D = C.current.done && !R, U = Z(() => {
960
+ const k = new ie(n);
961
+ return k.setSessionManager(l), k;
962
+ }, [n, l]), c = Z(() => new ht(new ie(n)), [n]), H = Z(() => new gt(U, l), [U, l]), F = Z(() => new He(new ie(n)), [n]), y = Z(() => b || l.getUser(), [b, l]), m = Z(() => y != null && y.roleId && p.find((k) => k.id === y.roleId) || null, [y, p]), v = Z(() => (m == null ? void 0 : m.permissions) || [], [m]), G = Z(() => l.hasValidSession() && b !== null, [l, b]), J = 5 * 60 * 1e3, q = Z(() => {
963
+ const k = async (B = !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 (!B && z - P < J && b)
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);
975
+ I(!0), M(null);
976
976
  const Q = await H.getUserById(W);
977
- f(Q), c.setUser(Q), g(Date.now());
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
+ M(Y), console.error("[AuthProvider] Failed to load user data:", Y);
981
981
  } finally {
982
982
  I(!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
+ }, K = async () => {
985
+ await k();
986
+ }, ce = async (B) => {
987
+ var Ce;
988
+ const { username: z, password: Y, tenantSlug: W, redirectPath: Q } = B;
989
+ let ee = o == null ? void 0 : o.id, te = i, ne = l;
990
+ W && (ee = (await new fe(U, 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
+ }), pe = W && W !== i;
997
+ if (pe && (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 k();
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
+ S(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 = ((Ce = j.user) == null ? void 0 : Ce.tenantId) !== null;
1020
+ if (E(ke), pe && te && te !== i && 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 = B.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 (B) => {
1043
+ const { email: z, phoneNumber: Y, name: W, password: Q, lastName: ee, tenantId: te } = B;
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 ?? (o == null ? void 0 : o.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
+ }, Ye = async (B) => {
1059
+ const { email: z, phoneNumber: Y, name: W, password: Q, tenantName: ee, lastName: te } = B;
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
+ }, Qe = async (B) => {
1074
+ const { currentPassword: z, newPassword: Y } = B, W = await l.getAuthHeaders();
1075
+ await c.changePassword({ currentPassword: z, newPassword: Y }, W);
1076
+ }, Xe = async (B) => {
1077
+ const { email: z, tenantId: Y } = B, W = Y ?? (o == null ? void 0 : o.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
+ }, et = async (B) => {
1082
+ const { token: z, newPassword: Y } = B;
1083
+ await c.confirmPasswordReset({ token: z, newPassword: Y });
1084
+ }, tt = async (B) => {
1085
+ const { email: z, frontendUrl: Y, name: W, lastName: Q, tenantId: ee } = B, te = ee ?? (o == null ? void 0 : o.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
+ }, nt = async (B) => {
1097
+ const { token: z, email: Y, tenantSlug: W } = B;
1098
+ let Q = o == null ? void 0 : o.id, ee = i, te = l;
1099
+ W && (Q = (await new fe(U, 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 !== i;
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 k();
1117
+ } catch (pe) {
1118
+ console.warn("Failed to load complete user data after magic link login:", pe);
1119
1119
  }
1120
1120
  }
1121
- return G && X && X !== o && a(X, {
1121
+ return j && ee && ee !== i && 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
+ }, rt = async () => {
1129
+ const B = l.getTokens();
1130
+ if (!(B != null && B.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: B.refreshToken
1134
1134
  });
1135
- c.setTokens({
1135
+ l.setTokens({
1136
1136
  accessToken: z.accessToken,
1137
- refreshToken: z.refreshToken || N.refreshToken,
1137
+ refreshToken: z.refreshToken || B.refreshToken,
1138
1138
  expiresIn: z.expiresIn
1139
1139
  });
1140
- }, Ye = () => {
1141
- c.clearSession(), f(null), R(null), A([]), U(!1);
1140
+ }, st = () => {
1141
+ l.clearSession(), g(null), M(null), S([]), E(!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
+ }, ot = (B) => {
1147
+ l.setTokens(B);
1148
+ }, it = () => l.hasValidSession(), at = () => {
1149
+ l.clearSession(), g(null), M(null);
1150
+ }, lt = 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: B } = await F.getRolesByApp(t);
1155
+ f(B);
1156
+ } catch (B) {
1157
+ console.error("Failed to fetch roles:", B);
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
+ }, ct = async () => {
1162
+ await lt();
1163
+ }, Te = (B) => {
1164
+ if (!v || v.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 B == "string")
1167
+ return v.includes(B);
1168
+ const z = `${B.resource}.${B.action}`;
1169
+ return v.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,
1173
+ isAuthenticated: G,
1174
+ sessionManager: l,
1175
+ authenticatedHttpService: U,
1176
+ login: ce,
1177
+ signup: ve,
1178
+ signupTenantAdmin: Ye,
1179
+ sendMagicLink: tt,
1180
+ verifyMagicLink: nt,
1181
+ changePassword: Qe,
1182
+ requestPasswordReset: Xe,
1183
+ confirmPasswordReset: et,
1184
+ refreshToken: rt,
1185
+ logout: st,
1186
+ setTokens: ot,
1187
+ hasValidSession: it,
1188
+ clearSession: at,
1189
+ currentUser: b,
1190
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,
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,
1191
+ userError: N,
1192
+ loadUserData: k,
1193
+ refreshUser: K,
1194
+ isAuthInitializing: !D,
1195
+ isAuthReady: D,
1196
+ userRole: m,
1197
+ userPermissions: v,
1198
+ availableRoles: p,
1199
+ rolesLoading: w,
1200
+ hasPermission: Te,
1201
+ hasAnyPermission: (B) => B.some((z) => Te(z)),
1202
+ hasAllPermissions: (B) => B.every((z) => Te(z)),
1203
+ getUserPermissionStrings: () => v || [],
1204
+ refreshRoles: ct,
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: L,
1208
+ switchToTenant: async (B, 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: B
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), E(!0);
1222
+ const ee = x.find((te) => te.id === B);
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 B = await l.getAuthHeaders(), z = await c.getUserTenants(B);
1234
+ S(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,
1245
+ U,
1246
+ c,
1247
1247
  H,
1248
- M,
1248
+ F,
1249
1249
  t,
1250
- s,
1251
1250
  o,
1251
+ i,
1252
1252
  a,
1253
- m,
1254
- S,
1253
+ p,
1254
+ b,
1255
1255
  T,
1256
- C,
1257
- $,
1258
- E,
1259
- L,
1260
- u,
1261
- w,
1256
+ N,
1262
1257
  x,
1263
- K
1258
+ L,
1259
+ D,
1260
+ m,
1261
+ v,
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 K = new ie(n), ce = new He(K), { roles: ve } = await ce.getRolesByApp(t);
1270
+ f(ve);
1271
+ } catch (K) {
1272
+ console.error("Failed to fetch roles:", K);
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"), St(), $(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), q.loadUserData().catch((k) => {
1281
+ console.error("[AuthProvider] Failed to load user data:", k);
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"), $(!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 k = l.getUser();
1287
+ k && l.hasValidSession() && g(k);
1288
+ }, [l]), X(() => {
1289
+ O && (C.current.urlTokens || !b && !T && 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
+ }, [b, T, q, l, O]), X(() => {
1292
+ if (!l.hasValidSession() || !b)
1293
1293
  return;
1294
- const v = setInterval(() => {
1295
- B.loadUserData().catch(() => {
1294
+ const k = 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(k);
1299
+ }, [l, b, 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 vt {
1311
1311
  constructor(e, t) {
1312
1312
  this.httpService = e, this.sessionManager = t;
1313
1313
  }
@@ -1326,14 +1326,14 @@ 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 o = `/feature-flags/${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o, {
1332
1332
  headers: t
1333
1333
  });
1334
1334
  return {
1335
- featureFlags: o.data,
1336
- meta: o.meta
1335
+ featureFlags: i.data,
1336
+ meta: i.meta
1337
1337
  };
1338
1338
  }
1339
1339
  async getFeatureFlagById(e) {
@@ -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 o = `/tenant-feature-flags${n.toString() ? `?${n.toString()}` : ""}`;
1374
+ return (await this.httpService.get(o, {
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()}` : ""}`;
1385
- return (await this.httpService.get(o, {
1382
+ const o = new URLSearchParams();
1383
+ o.append("tenantId", t), o.append("appId", n);
1384
+ const i = `/tenant-feature-flags/${e}${o.toString() ? `?${o.toString()}` : ""}`;
1385
+ return (await this.httpService.get(i, {
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 = ue(null);
1391
+ function yn({ config: r = {}, children: e }) {
1392
+ const t = Ve(), n = Se(), o = (t == null ? void 0 : t.baseUrl) ?? "", i = (t == null ? void 0 : t.appId) ?? "", a = (n == null ? void 0 : n.tenant) ?? null, [p, f] = A([]), [w, u] = A(!1), [b, g] = A(null), [T, I] = A(!1), N = Z(() => {
1393
+ const h = new ie(o);
1394
+ return new vt(h);
1395
+ }, [o]), M = 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 N.getTenantFeatureFlags(a.id, i);
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 (!o || !i) return;
1413
+ M().finally(() => I(!0));
1414
+ const h = r.refreshInterval || 5 * 60 * 1e3, x = setInterval(M, h);
1415
+ return () => clearInterval(x);
1416
+ }, [a == null ? void 0 : a.id, o, i, r.refreshInterval]);
1417
+ const P = Z(() => {
1418
+ const h = (C) => {
1419
+ const R = p.find(($) => $.key === C);
1420
+ return (R == null ? void 0 : R.value) === !0;
1421
+ }, x = (C) => p.find((R) => R.key === C), S = (C) => {
1422
+ const R = p.find(($) => $.key === C);
1423
+ return R ? R.value ? "enabled" : "disabled" : "not_found";
1424
+ }, L = async () => {
1425
+ await M();
1426
+ }, E = !!(o && i) && (T || !(a != null && a.id));
1427
1427
  return {
1428
- featureFlags: m,
1429
- loading: b,
1430
- error: S,
1431
- isReady: U,
1432
- isEnabled: g,
1433
- getFlag: $,
1434
- getFlagState: A,
1435
- refresh: E
1428
+ featureFlags: p,
1429
+ loading: w,
1430
+ error: b,
1431
+ isReady: E,
1432
+ isEnabled: h,
1433
+ getFlag: x,
1434
+ getFlagState: S,
1435
+ refresh: L
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, w, b, o, i, a == null ? void 0 : a.id, T]);
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 Tt() {
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 je() {
1447
+ return oe(Ee);
1448
1448
  }
1449
- class gt {
1449
+ class kt {
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,141 @@ 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 () => {
1521
- if (!(o != null && o.id)) {
1522
- m(null);
1515
+ const Fe = ue(void 0);
1516
+ function wn({ config: r = {}, children: e }) {
1517
+ const t = Ve(), n = Se(), o = (t == null ? void 0 : t.baseUrl) ?? "", i = (n == null ? void 0 : n.tenant) ?? null, [a, p] = A(null), [f, w] = A(!1), [u, b] = A(null), [g, T] = A(!1), I = Z(() => {
1518
+ const P = new ie(o);
1519
+ return new kt(P);
1520
+ }, [o]), N = async () => {
1521
+ if (!(i != null && i.id)) {
1522
+ p(null);
1523
1523
  return;
1524
1524
  }
1525
- b(!0), S(null);
1525
+ w(!0), b(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 I.getTenantSubscriptionFeatures(i.id);
1528
+ p(P);
1529
+ } catch (P) {
1530
+ const h = P instanceof Error ? P.message : "Failed to fetch subscription";
1531
+ b(h), r.onError && r.onError(P instanceof Error ? P : new Error(h));
1532
1532
  } finally {
1533
- b(!1);
1533
+ w(!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 (!o || (N().finally(() => T(!0)), !r.refreshInterval)) return;
1538
+ const P = r.refreshInterval || 10 * 60 * 1e3, h = setInterval(N, P);
1539
+ return () => clearInterval(h);
1540
+ }, [i == null ? void 0 : i.id, o, r.refreshInterval]);
1541
+ const M = Z(() => {
1542
+ const P = (a == null ? void 0 : a.features) || [], h = (R) => {
1543
+ const $ = P.find((l) => l.key === R);
1544
+ return $ ? $.type === "BOOLEAN" || $.type === "boolean" ? $.value === !0 : !!$.value : !1;
1545
+ }, x = (R) => P.find(($) => $.key === R), S = (R, $) => {
1546
+ const l = P.find((D) => D.key === R);
1547
+ return l ? l.value : $;
1548
+ }, L = (R) => !a || !a.isActive ? !1 : R.includes(a.planId), E = async () => {
1549
+ await N();
1550
+ }, C = !!o && (g || !(i != null && i.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,
1561
- refresh: U
1553
+ features: P,
1554
+ loading: f,
1555
+ error: u,
1556
+ isReady: C,
1557
+ isFeatureEnabled: h,
1558
+ getFeature: x,
1559
+ getFeatureValue: S,
1560
+ hasAllowedPlan: L,
1561
+ refresh: E
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, o, i == null ? void 0 : i.id, g]);
1564
+ return /* @__PURE__ */ s(Fe.Provider, { value: M, children: e });
1565
1565
  }
1566
- function pt() {
1567
- const i = se(Re);
1568
- if (i === void 0)
1566
+ function At() {
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
+ }
1572
+ function Ge() {
1573
+ return oe(Fe) ?? null;
1574
+ }
1575
+ var se = /* @__PURE__ */ ((r) => (r.SUPERUSER = "SUPERUSER", r.TENANT_ADMIN = "TENANT_ADMIN", r.USER = "USER", r))(se || {});
1576
+ const Ne = {
1577
+ publicGuest: "/",
1578
+ publicUser: "/account",
1579
+ publicAdmin: "/admin",
1580
+ tenantGuest: "/login",
1581
+ tenantUser: "/dashboard",
1582
+ tenantAdmin: "/admin/dashboard",
1583
+ default: "/"
1584
+ }, Ze = {
1585
+ // Public/Landing zones
1586
+ landing: { tenant: "forbidden", auth: "optional" },
1587
+ publicOnly: { tenant: "forbidden", auth: "forbidden" },
1588
+ // Auth zones
1589
+ login: { tenant: "required", auth: "forbidden" },
1590
+ guest: { auth: "forbidden" },
1591
+ authenticated: { auth: "required" },
1592
+ // Tenant zones
1593
+ tenant: { tenant: "required" },
1594
+ tenantOpen: { tenant: "required", auth: "optional" },
1595
+ tenantAuth: { tenant: "required", auth: "required" },
1596
+ // User type zones
1597
+ user: { tenant: "required", auth: "required", userType: se.USER },
1598
+ admin: { tenant: "required", auth: "required", userType: se.TENANT_ADMIN },
1599
+ // Fully open
1600
+ open: { tenant: "optional", auth: "optional" }
1601
+ }, De = ue(null);
1602
+ function bn({ config: r = {}, children: e }) {
1603
+ const t = Z(() => {
1604
+ const n = {
1605
+ ...Ne,
1606
+ ...r.zoneRoots
1607
+ }, o = {
1608
+ ...Ze,
1609
+ ...r.presets
1610
+ };
1611
+ return {
1612
+ zoneRoots: n,
1613
+ presets: o,
1614
+ loadingFallback: r.loadingFallback ?? null,
1615
+ accessDeniedFallback: r.accessDeniedFallback ?? null,
1616
+ onAccessDenied: r.onAccessDenied,
1617
+ returnToParam: r.returnToParam ?? "returnTo",
1618
+ returnToStorage: r.returnToStorage ?? "url"
1619
+ };
1620
+ }, [r]);
1621
+ return /* @__PURE__ */ s(De.Provider, { value: t, children: e });
1571
1622
  }
1572
- function ze() {
1573
- return se(Re) ?? null;
1623
+ function Sn() {
1624
+ const r = oe(De);
1625
+ if (!r)
1626
+ throw new Error("useRouting must be used within a RoutingProvider");
1627
+ return r;
1574
1628
  }
1575
- var fe = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(fe || {});
1576
- const $e = () => /* @__PURE__ */ d(
1629
+ function xt() {
1630
+ const r = oe(De);
1631
+ return r || {
1632
+ zoneRoots: Ne,
1633
+ presets: Ze,
1634
+ loadingFallback: null,
1635
+ accessDeniedFallback: null,
1636
+ onAccessDenied: void 0,
1637
+ returnToParam: "returnTo",
1638
+ returnToStorage: "url"
1639
+ };
1640
+ }
1641
+ const qe = () => /* @__PURE__ */ d(
1577
1642
  "div",
1578
1643
  {
1579
1644
  style: {
@@ -1589,10 +1654,10 @@ const $e = () => /* @__PURE__ */ d(
1589
1654
  margin: "20px 0"
1590
1655
  },
1591
1656
  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(
1657
+ /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "🔒" }),
1658
+ /* @__PURE__ */ s("h3", { style: { color: "#495057", marginBottom: "10px" }, children: "Access Required" }),
1659
+ /* @__PURE__ */ s("p", { style: { color: "#6c757d", fontSize: "14px", marginBottom: "15px" }, children: "You need to be signed in to view this content." }),
1660
+ /* @__PURE__ */ s(
1596
1661
  "button",
1597
1662
  {
1598
1663
  style: {
@@ -1610,8 +1675,8 @@ const $e = () => /* @__PURE__ */ d(
1610
1675
  )
1611
1676
  ]
1612
1677
  }
1613
- ), He = ({
1614
- userType: i,
1678
+ ), Oe = ({
1679
+ userType: r,
1615
1680
  minUserType: e,
1616
1681
  missingPermissions: t
1617
1682
  }) => /* @__PURE__ */ d(
@@ -1630,57 +1695,57 @@ const $e = () => /* @__PURE__ */ d(
1630
1695
  margin: "20px 0"
1631
1696
  },
1632
1697
  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: [
1698
+ /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1699
+ /* @__PURE__ */ s("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1700
+ e && r ? /* @__PURE__ */ d(_, { children: [
1636
1701
  /* @__PURE__ */ d("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1637
1702
  "This content requires ",
1638
- /* @__PURE__ */ n("strong", { children: e }),
1703
+ /* @__PURE__ */ s("strong", { children: e }),
1639
1704
  " access level or higher."
1640
1705
  ] }),
1641
1706
  /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1642
1707
  "Your current access level: ",
1643
- /* @__PURE__ */ n("strong", { children: i })
1708
+ /* @__PURE__ */ s("strong", { children: r })
1644
1709
  ] })
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." }),
1710
+ ] }) : /* @__PURE__ */ d(_, { children: [
1711
+ /* @__PURE__ */ s("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1647
1712
  t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1648
1713
  "Required permissions: ",
1649
- /* @__PURE__ */ n("strong", { children: t.join(", ") })
1714
+ /* @__PURE__ */ s("strong", { children: t.join(", ") })
1650
1715
  ] })
1651
1716
  ] })
1652
1717
  ]
1653
1718
  }
1654
- ), ft = (i, e) => {
1719
+ ), Pt = (r, e) => {
1655
1720
  const t = {
1656
- [fe.USER]: 1,
1657
- [fe.TENANT_ADMIN]: 2,
1658
- [fe.SUPERUSER]: 3
1721
+ [se.USER]: 1,
1722
+ [se.TENANT_ADMIN]: 2,
1723
+ [se.SUPERUSER]: 3
1659
1724
  };
1660
- return t[i] >= t[e];
1725
+ return t[r] >= t[e];
1661
1726
  };
1662
- function rr({
1663
- children: i,
1727
+ function vn({
1728
+ children: r,
1664
1729
  fallback: e,
1665
1730
  minUserType: t,
1666
- requiredPermissions: r,
1667
- requireAllPermissions: s = !1
1731
+ requiredPermissions: n,
1732
+ requireAllPermissions: o = !1
1668
1733
  }) {
1669
- const { hasValidSession: o, sessionManager: a, hasPermission: m, hasAnyPermission: y, hasAllPermissions: b } = oe();
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 });
1734
+ const { hasValidSession: i, sessionManager: a, hasPermission: p, hasAnyPermission: f, hasAllPermissions: w } = le();
1735
+ if (!i())
1736
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(qe, {}) });
1737
+ const u = a.getUser();
1738
+ if (!u)
1739
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(qe, {}) });
1740
+ if (t && !Pt(u.userType, t))
1741
+ return /* @__PURE__ */ s(Oe, { userType: u.userType, minUserType: t });
1742
+ if (n && n.length > 0 && !(o ? w(n) : f(n))) {
1743
+ const g = n.filter((T) => !p(T)).map((T) => typeof T == "string" ? T : T.name);
1744
+ return /* @__PURE__ */ s(Oe, { missingPermissions: g });
1745
+ }
1746
+ return /* @__PURE__ */ s(_, { children: r });
1682
1747
  }
1683
- const mt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1748
+ const Rt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1684
1749
  "div",
1685
1750
  {
1686
1751
  style: {
@@ -1704,23 +1769,23 @@ const mt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1704
1769
  maxWidth: "400px"
1705
1770
  },
1706
1771
  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." }),
1772
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1773
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1774
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
1710
1775
  /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1711
1776
  "Redirecting to ",
1712
- i,
1777
+ r,
1713
1778
  "..."
1714
1779
  ] })
1715
1780
  ]
1716
1781
  }
1717
1782
  )
1718
1783
  }
1719
- ), Ne = ({
1720
- userType: i,
1784
+ ), ze = ({
1785
+ userType: r,
1721
1786
  requiredUserType: e,
1722
1787
  missingPermissions: t
1723
- }) => /* @__PURE__ */ n(
1788
+ }) => /* @__PURE__ */ s(
1724
1789
  "div",
1725
1790
  {
1726
1791
  style: {
@@ -1744,62 +1809,66 @@ const mt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1744
1809
  maxWidth: "400px"
1745
1810
  },
1746
1811
  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: [
1812
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1813
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1814
+ e && r ? /* @__PURE__ */ d(_, { children: [
1750
1815
  /* @__PURE__ */ d("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1751
1816
  "This page requires ",
1752
- /* @__PURE__ */ n("strong", { children: e }),
1817
+ /* @__PURE__ */ s("strong", { children: e }),
1753
1818
  " access."
1754
1819
  ] }),
1755
1820
  /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1756
1821
  "Your current user type: ",
1757
- /* @__PURE__ */ n("strong", { children: i })
1822
+ /* @__PURE__ */ s("strong", { children: r })
1758
1823
  ] })
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." }),
1824
+ ] }) : /* @__PURE__ */ d(_, { children: [
1825
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1761
1826
  t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1762
1827
  "Required permissions: ",
1763
- /* @__PURE__ */ n("strong", { children: t.join(", ") })
1828
+ /* @__PURE__ */ s("strong", { children: t.join(", ") })
1764
1829
  ] })
1765
1830
  ] })
1766
1831
  ]
1767
1832
  }
1768
1833
  )
1769
1834
  }
1770
- ), yt = (i, e) => i === e;
1771
- function nr({
1772
- children: i,
1835
+ ), It = (r, e) => r === e;
1836
+ function Tn({
1837
+ children: r,
1773
1838
  redirectTo: e = "/login",
1774
1839
  requiredUserType: t,
1775
- requiredPermissions: r,
1776
- requireAllPermissions: s = !1,
1777
- fallback: o
1840
+ requiredPermissions: n,
1841
+ requireAllPermissions: o = !1,
1842
+ fallback: i
1778
1843
  }) {
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 })
1844
+ const { hasValidSession: a, sessionManager: p, hasPermission: f, hasAnyPermission: w, hasAllPermissions: u } = le(), b = be();
1845
+ if (X(() => {
1846
+ process.env.NODE_ENV === "development" && console.warn(
1847
+ "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
1848
+ );
1849
+ }, []), !a())
1850
+ return i ? /* @__PURE__ */ s(_, { children: i }) : /* @__PURE__ */ d(_, { children: [
1851
+ /* @__PURE__ */ s(Rt, { redirectPath: e }),
1852
+ /* @__PURE__ */ s(me, { to: e, state: { from: b.pathname }, replace: !0 })
1784
1853
  ] });
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,
1854
+ const g = p.getUser();
1855
+ if (!g)
1856
+ return /* @__PURE__ */ s(me, { to: e, state: { from: b.pathname }, replace: !0 });
1857
+ if (t && !It(g.userType, t))
1858
+ return /* @__PURE__ */ s(
1859
+ ze,
1791
1860
  {
1792
- userType: f.userType,
1861
+ userType: g.userType,
1793
1862
  requiredUserType: t
1794
1863
  }
1795
1864
  );
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 });
1865
+ if (n && n.length > 0 && !(o ? u(n) : w(n))) {
1866
+ const I = n.filter((N) => !f(N)).map((N) => typeof N == "string" ? N : N.name);
1867
+ return /* @__PURE__ */ s(ze, { missingPermissions: I });
1799
1868
  }
1800
- return /* @__PURE__ */ n(j, { children: i });
1869
+ return /* @__PURE__ */ s(_, { children: r });
1801
1870
  }
1802
- const wt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1871
+ const Mt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1803
1872
  "div",
1804
1873
  {
1805
1874
  style: {
@@ -1823,12 +1892,12 @@ const wt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1823
1892
  maxWidth: "400px"
1824
1893
  },
1825
1894
  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." }),
1895
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
1896
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
1897
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
1829
1898
  /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1830
1899
  "Redirecting to ",
1831
- i,
1900
+ r,
1832
1901
  "..."
1833
1902
  ] })
1834
1903
  ]
@@ -1836,14 +1905,18 @@ const wt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1836
1905
  )
1837
1906
  }
1838
1907
  );
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 })
1908
+ function kn({ children: r, redirectTo: e = "/", fallback: t }) {
1909
+ const { tenant: n, isLoading: o, error: i } = ge(), a = be();
1910
+ return X(() => {
1911
+ process.env.NODE_ENV === "development" && console.warn(
1912
+ "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
1913
+ );
1914
+ }, []), o || i ? null : n ? /* @__PURE__ */ s(_, { children: r }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
1915
+ /* @__PURE__ */ s(Mt, { redirectPath: e }),
1916
+ /* @__PURE__ */ s(me, { to: e, state: { from: a.pathname }, replace: !0 })
1844
1917
  ] });
1845
1918
  }
1846
- const bt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1919
+ const Lt = ({ redirectPath: r }) => /* @__PURE__ */ s(
1847
1920
  "div",
1848
1921
  {
1849
1922
  style: {
@@ -1867,12 +1940,12 @@ const bt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1867
1940
  maxWidth: "400px"
1868
1941
  },
1869
1942
  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." }),
1943
+ /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
1944
+ /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
1945
+ /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
1873
1946
  /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1874
1947
  "Redirecting to ",
1875
- i,
1948
+ r,
1876
1949
  "..."
1877
1950
  ] })
1878
1951
  ]
@@ -1880,14 +1953,125 @@ const bt = ({ redirectPath: i }) => /* @__PURE__ */ n(
1880
1953
  )
1881
1954
  }
1882
1955
  );
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 });
1956
+ function An({ children: r, redirectTo: e = "/dashboard", fallback: t }) {
1957
+ const { tenant: n, isLoading: o, error: i } = ge(), a = be();
1958
+ return X(() => {
1959
+ process.env.NODE_ENV === "development" && console.warn(
1960
+ "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
1961
+ );
1962
+ }, []), o || i ? null : n ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
1963
+ /* @__PURE__ */ s(Lt, { redirectPath: e }),
1964
+ /* @__PURE__ */ s(me, { to: e, state: { from: a.pathname }, replace: !0 })
1965
+ ] }) : /* @__PURE__ */ s(_, { children: r });
1966
+ }
1967
+ function Et(r, e) {
1968
+ return e ? r ? Array.isArray(e) ? e.includes(r) : r === e : !1 : !0;
1889
1969
  }
1890
- const St = () => /* @__PURE__ */ d(
1970
+ function _e(r, e) {
1971
+ return !r || r === "optional" ? "skip" : r === "required" ? e ? "pass" : "fail" : r === "forbidden" ? e ? "fail" : "pass" : "skip";
1972
+ }
1973
+ function Ft(r, e) {
1974
+ return _e(r.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : _e(r.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : r.userType && e.isAuthenticated && !Et(e.userType, r.userType) ? "wrong_user_type" : r.permissions && r.permissions.length > 0 && !(r.requireAllPermissions !== !1 ? (i) => i.every((a) => e.permissions.includes(a)) : (i) => i.some((a) => e.permissions.includes(a)))(r.permissions) ? "missing_permissions" : null;
1975
+ }
1976
+ function Nt(r, e) {
1977
+ 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;
1978
+ }
1979
+ function Dt(r, e, t, n, o) {
1980
+ if (!e || o !== "url")
1981
+ return r;
1982
+ const i = typeof e == "string" ? e : t, a = r.includes("?") ? "&" : "?";
1983
+ return `${r}${a}${n}=${encodeURIComponent(i)}`;
1984
+ }
1985
+ function Ct(r, e, t) {
1986
+ if (!r || t === "url") return;
1987
+ const n = typeof r == "string" ? r : e, o = "zone_return_to";
1988
+ t === "session" ? sessionStorage.setItem(o, n) : t === "local" && localStorage.setItem(o, n);
1989
+ }
1990
+ const ae = ({
1991
+ children: r,
1992
+ preset: e,
1993
+ tenant: t,
1994
+ auth: n,
1995
+ userType: o,
1996
+ requiredPermissions: i,
1997
+ requireAllPermissions: a = !0,
1998
+ returnTo: p,
1999
+ onAccessDenied: f,
2000
+ redirectTo: w,
2001
+ loadingFallback: u,
2002
+ accessDeniedFallback: b
2003
+ }) => {
2004
+ const g = be(), { isAuthenticated: T, isAuthInitializing: I, currentUser: N, userPermissions: M } = le(), { tenant: P, isTenantLoading: h } = he(), x = xt(), S = Z(() => {
2005
+ if (e)
2006
+ return x.presets[e];
2007
+ }, [e, x.presets]), L = Z(
2008
+ () => ({
2009
+ tenant: t ?? (S == null ? void 0 : S.tenant),
2010
+ auth: n ?? (S == null ? void 0 : S.auth),
2011
+ userType: o ?? (S == null ? void 0 : S.userType),
2012
+ permissions: i ?? (S == null ? void 0 : S.requiredPermissions),
2013
+ requireAllPermissions: a
2014
+ }),
2015
+ [t, n, o, i, S, a]
2016
+ ), E = Z(
2017
+ () => ({
2018
+ hasTenant: !!P,
2019
+ isAuthenticated: T,
2020
+ userType: N == null ? void 0 : N.userType,
2021
+ permissions: M,
2022
+ isLoading: I || h
2023
+ }),
2024
+ [
2025
+ P,
2026
+ T,
2027
+ N == null ? void 0 : N.userType,
2028
+ M,
2029
+ I,
2030
+ h
2031
+ ]
2032
+ ), C = Z(() => E.isLoading ? null : Ft(L, E), [L, E]), R = Z(() => C ? w || Nt(E, x.zoneRoots) : null, [C, w, E, x.zoneRoots]), $ = Z(() => !C || !R ? null : {
2033
+ type: C,
2034
+ required: {
2035
+ tenant: L.tenant,
2036
+ auth: L.auth,
2037
+ userType: L.userType,
2038
+ permissions: L.permissions
2039
+ },
2040
+ current: {
2041
+ hasTenant: E.hasTenant,
2042
+ isAuthenticated: E.isAuthenticated,
2043
+ userType: E.userType,
2044
+ permissions: E.permissions
2045
+ },
2046
+ redirectTo: R
2047
+ }, [C, R, L, E]);
2048
+ if (X(() => {
2049
+ $ && (f ? f($) : x.onAccessDenied && x.onAccessDenied($));
2050
+ }, [$, f, x]), X(() => {
2051
+ $ && p && Ct(p, g.pathname + g.search, x.returnToStorage);
2052
+ }, [
2053
+ $,
2054
+ p,
2055
+ g.pathname,
2056
+ g.search,
2057
+ x.returnToStorage
2058
+ ]), E.isLoading)
2059
+ return /* @__PURE__ */ s(_, { children: u ?? x.loadingFallback ?? null });
2060
+ if ($ && R) {
2061
+ const l = b ?? x.accessDeniedFallback;
2062
+ if (l)
2063
+ return /* @__PURE__ */ s(_, { children: l });
2064
+ const D = Dt(
2065
+ R,
2066
+ p,
2067
+ g.pathname + g.search,
2068
+ x.returnToParam,
2069
+ x.returnToStorage
2070
+ );
2071
+ return /* @__PURE__ */ s(me, { to: D, replace: !0 });
2072
+ }
2073
+ return /* @__PURE__ */ s(_, { children: r });
2074
+ }, xn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", ...r }), Pn = (r) => /* @__PURE__ */ s(ae, { tenant: "forbidden", ...r }), Rn = (r) => /* @__PURE__ */ s(ae, { auth: "required", ...r }), In = (r) => /* @__PURE__ */ s(ae, { auth: "forbidden", ...r }), Mn = (r) => /* @__PURE__ */ s(ae, { auth: "required", userType: se.TENANT_ADMIN, ...r }), Ln = (r) => /* @__PURE__ */ s(ae, { auth: "required", userType: se.USER, ...r }), En = (r) => /* @__PURE__ */ s(ae, { tenant: "optional", auth: "optional", ...r }), Fn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "required", ...r }), Nn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "optional", ...r }), Dn = (r) => /* @__PURE__ */ s(ae, { tenant: "required", auth: "forbidden", ...r }), Ut = () => /* @__PURE__ */ d(
1891
2075
  "div",
1892
2076
  {
1893
2077
  style: {
@@ -1899,19 +2083,19 @@ const St = () => /* @__PURE__ */ d(
1899
2083
  color: "#dc2626"
1900
2084
  },
1901
2085
  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." })
2086
+ /* @__PURE__ */ s("h3", { style: { margin: "0 0 1rem 0" }, children: "🔒 Subscription Required" }),
2087
+ /* @__PURE__ */ s("p", { style: { margin: 0 }, children: "This feature requires a higher subscription plan. Please upgrade your plan to access this content." })
1904
2088
  ]
1905
2089
  }
1906
2090
  );
1907
- function or({
1908
- children: i,
1909
- fallback: e = /* @__PURE__ */ n(St, {}),
2091
+ function Cn({
2092
+ children: r,
2093
+ fallback: e = /* @__PURE__ */ s(Ut, {}),
1910
2094
  allowedPlans: t,
1911
- requiredFeature: r
2095
+ requiredFeature: n
1912
2096
  }) {
1913
- const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: a, loading: m } = pt();
1914
- return m ? /* @__PURE__ */ n(
2097
+ const { subscription: o, hasAllowedPlan: i, isFeatureEnabled: a, loading: p } = At();
2098
+ return p ? /* @__PURE__ */ s(
1915
2099
  "div",
1916
2100
  {
1917
2101
  style: {
@@ -1921,9 +2105,9 @@ function or({
1921
2105
  },
1922
2106
  children: "Loading subscription..."
1923
2107
  }
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 });
2108
+ ) : o ? o.isActive ? t && t.length > 0 && !i(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
2109
  }
1926
- const vt = ({ flagName: i }) => /* @__PURE__ */ d(
2110
+ const $t = ({ flagName: r }) => /* @__PURE__ */ d(
1927
2111
  "div",
1928
2112
  {
1929
2113
  style: {
@@ -1940,19 +2124,19 @@ const vt = ({ flagName: i }) => /* @__PURE__ */ d(
1940
2124
  color: "#6c757d"
1941
2125
  },
1942
2126
  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" }),
2127
+ /* @__PURE__ */ s("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
2128
+ /* @__PURE__ */ s("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
1945
2129
  /* @__PURE__ */ d("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
1946
2130
  'Feature flag "',
1947
- i,
2131
+ r,
1948
2132
  '" is disabled'
1949
2133
  ] })
1950
2134
  ]
1951
2135
  }
1952
2136
  );
1953
- function ar({ name: i, children: e, fallback: t }) {
1954
- const { isEnabled: r, loading: s } = ht();
1955
- return s ? /* @__PURE__ */ n(
2137
+ function Un({ name: r, children: e, fallback: t }) {
2138
+ const { isEnabled: n, loading: o } = Tt();
2139
+ return o ? /* @__PURE__ */ s(
1956
2140
  "div",
1957
2141
  {
1958
2142
  style: {
@@ -1965,9 +2149,9 @@ function ar({ name: i, children: e, fallback: t }) {
1965
2149
  },
1966
2150
  children: "Loading feature flags..."
1967
2151
  }
1968
- ) : r(i) ? /* @__PURE__ */ n(j, { children: e }) : /* @__PURE__ */ n(j, { children: t || /* @__PURE__ */ n(vt, { flagName: i }) });
2152
+ ) : n(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s($t, { flagName: r }) });
1969
2153
  }
1970
- const kt = () => /* @__PURE__ */ d(
2154
+ const Ht = () => /* @__PURE__ */ d(
1971
2155
  "svg",
1972
2156
  {
1973
2157
  width: "16",
@@ -1980,11 +2164,11 @@ const kt = () => /* @__PURE__ */ d(
1980
2164
  strokeLinejoin: "round",
1981
2165
  style: { flexShrink: 0 },
1982
2166
  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" })
2167
+ /* @__PURE__ */ s("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
2168
+ /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "3" })
1985
2169
  ]
1986
2170
  }
1987
- ), Tt = () => /* @__PURE__ */ d(
2171
+ ), Bt = () => /* @__PURE__ */ d(
1988
2172
  "svg",
1989
2173
  {
1990
2174
  width: "16",
@@ -1997,14 +2181,14 @@ const kt = () => /* @__PURE__ */ d(
1997
2181
  strokeLinejoin: "round",
1998
2182
  style: { flexShrink: 0 },
1999
2183
  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" })
2184
+ /* @__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" }),
2185
+ /* @__PURE__ */ s("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2002
2186
  ]
2003
2187
  }
2004
- ), xt = {
2005
- showPassword: /* @__PURE__ */ n(kt, {}),
2006
- hidePassword: /* @__PURE__ */ n(Tt, {})
2007
- }, At = {
2188
+ ), qt = {
2189
+ showPassword: /* @__PURE__ */ s(Ht, {}),
2190
+ hidePassword: /* @__PURE__ */ s(Bt, {})
2191
+ }, Ot = {
2008
2192
  title: "Sign In",
2009
2193
  usernameLabel: "Email or Phone",
2010
2194
  usernamePlaceholder: "Enter your email or phone number",
@@ -2018,7 +2202,7 @@ const kt = () => /* @__PURE__ */ d(
2018
2202
  magicLinkLink: "Use Magic Link",
2019
2203
  errorMessage: "Invalid credentials",
2020
2204
  loadingText: "Signing in..."
2021
- }, Pt = {
2205
+ }, zt = {
2022
2206
  container: {
2023
2207
  maxWidth: "400px",
2024
2208
  width: "100%",
@@ -2125,133 +2309,133 @@ const kt = () => /* @__PURE__ */ d(
2125
2309
  fontSize: "0.875rem"
2126
2310
  }
2127
2311
  };
2128
- function lr({
2129
- copy: i = {},
2312
+ function $n({
2313
+ copy: r = {},
2130
2314
  styles: e = {},
2131
2315
  icons: t = {},
2132
- onSuccess: r,
2133
- onError: s,
2134
- onForgotPassword: o,
2316
+ onSuccess: n,
2317
+ onError: o,
2318
+ onForgotPassword: i,
2135
2319
  onSignupClick: a,
2136
- onMagicLinkClick: m,
2137
- showForgotPassword: y = !0,
2138
- showSignupLink: b = !0,
2139
- showMagicLinkOption: p = !0,
2140
- className: S
2320
+ onMagicLinkClick: p,
2321
+ showForgotPassword: f = !0,
2322
+ showSignupLink: w = !0,
2323
+ showMagicLinkOption: u = !0,
2324
+ className: b
2141
2325
  }) {
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");
2326
+ const [g, T] = A(""), [I, N] = A(""), [M, P] = A(!1), [h, x] = A(!1), [S, L] = A(""), [E, C] = A({}), { login: R } = le(), { tenant: $ } = ge(), l = { ...Ot, ...r }, D = { ...zt, ...e }, U = { ...qt, ...t }, c = () => {
2327
+ const m = {};
2328
+ return g.trim() || (m.username = !0), I.trim() || (m.password = !0), C(m), Object.keys(m).length === 0;
2329
+ }, H = async (m) => {
2330
+ if (m.preventDefault(), !!c()) {
2331
+ if (!($ != null && $.id)) {
2332
+ L("Tenant not found");
2149
2333
  return;
2150
2334
  }
2151
- $(!0), E("");
2335
+ x(!0), L("");
2152
2336
  try {
2153
- const w = await P({
2154
- username: f,
2337
+ const v = await R({
2338
+ username: g,
2155
2339
  password: I
2156
2340
  // tenantId inferred from context automatically
2157
2341
  });
2158
- r == null || r(w);
2159
- } catch (w) {
2160
- const _ = w.message || c.errorMessage;
2161
- E(_), s == null || s(_);
2342
+ n == null || n(v);
2343
+ } catch (v) {
2344
+ const G = v.message || l.errorMessage;
2345
+ L(G), o == null || o(G);
2162
2346
  } finally {
2163
- $(!1);
2347
+ x(!1);
2164
2348
  }
2165
2349
  }
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 : {}
2350
+ }, F = (m) => ({
2351
+ ...D.input,
2352
+ ...E[m] ? D.inputError : {}
2353
+ }), y = () => ({
2354
+ ...D.button,
2355
+ ...h ? D.buttonLoading : {},
2356
+ ...!g || !I || h ? D.buttonDisabled : {}
2173
2357
  });
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(
2358
+ return /* @__PURE__ */ d("div", { className: b, style: D.container, children: [
2359
+ /* @__PURE__ */ s("h2", { style: D.title, children: l.title }),
2360
+ /* @__PURE__ */ d("form", { onSubmit: H, style: D.form, children: [
2361
+ /* @__PURE__ */ d("div", { style: D.fieldGroup, children: [
2362
+ /* @__PURE__ */ s("label", { style: D.label, children: l.usernameLabel }),
2363
+ /* @__PURE__ */ s(
2180
2364
  "input",
2181
2365
  {
2182
2366
  id: "username",
2183
2367
  name: "username",
2184
2368
  type: "text",
2185
- value: f,
2186
- onChange: (u) => {
2187
- T(u.target.value), U.username && D((w) => ({ ...w, username: !1 }));
2369
+ value: g,
2370
+ onChange: (m) => {
2371
+ T(m.target.value), E.username && C((v) => ({ ...v, username: !1 }));
2188
2372
  },
2189
- placeholder: c.usernamePlaceholder,
2190
- style: M("username"),
2191
- disabled: g
2373
+ placeholder: l.usernamePlaceholder,
2374
+ style: F("username"),
2375
+ disabled: h
2192
2376
  }
2193
2377
  )
2194
2378
  ] }),
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(
2379
+ /* @__PURE__ */ d("div", { style: D.fieldGroup, children: [
2380
+ /* @__PURE__ */ s("label", { style: D.label, children: l.passwordLabel }),
2381
+ /* @__PURE__ */ d("div", { style: D.inputContainer, children: [
2382
+ /* @__PURE__ */ s(
2199
2383
  "input",
2200
2384
  {
2201
2385
  id: "password",
2202
2386
  name: "password",
2203
- type: R ? "text" : "password",
2387
+ type: M ? "text" : "password",
2204
2388
  value: I,
2205
- onChange: (u) => {
2206
- C(u.target.value), U.password && D((w) => ({ ...w, password: !1 }));
2389
+ onChange: (m) => {
2390
+ N(m.target.value), E.password && C((v) => ({ ...v, password: !1 }));
2207
2391
  },
2208
- placeholder: c.passwordPlaceholder,
2392
+ placeholder: l.passwordPlaceholder,
2209
2393
  style: {
2210
- ...M("password"),
2394
+ ...F("password"),
2211
2395
  paddingRight: "2.5rem"
2212
2396
  // Make room for the icon
2213
2397
  },
2214
- disabled: g
2398
+ disabled: h
2215
2399
  }
2216
2400
  ),
2217
- /* @__PURE__ */ n(
2401
+ /* @__PURE__ */ s(
2218
2402
  "button",
2219
2403
  {
2220
2404
  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
2405
+ onClick: () => P(!M),
2406
+ style: D.passwordToggle,
2407
+ disabled: h,
2408
+ "aria-label": M ? "Hide password" : "Show password",
2409
+ children: M ? U.hidePassword : U.showPassword
2226
2410
  }
2227
2411
  )
2228
2412
  ] })
2229
2413
  ] }),
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 })
2414
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !g || !I || h, style: y(), children: h ? l.loadingText : l.submitButton }),
2415
+ S && /* @__PURE__ */ s("div", { style: D.errorText, children: S })
2232
2416
  ] }),
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,
2417
+ (f || w || u) && /* @__PURE__ */ d("div", { style: D.linkContainer, children: [
2418
+ u && /* @__PURE__ */ d("div", { children: [
2419
+ /* @__PURE__ */ d("span", { style: D.divider, children: [
2420
+ l.magicLinkText,
2237
2421
  " "
2238
2422
  ] }),
2239
- /* @__PURE__ */ n("a", { onClick: m, style: L.link, children: c.magicLinkLink })
2423
+ /* @__PURE__ */ s("a", { onClick: p, style: D.link, children: l.magicLinkLink })
2240
2424
  ] }),
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: "•" }),
2244
- b && /* @__PURE__ */ d("div", { children: [
2245
- /* @__PURE__ */ d("span", { style: L.divider, children: [
2246
- c.signupText,
2425
+ u && (f || w) && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2426
+ f && /* @__PURE__ */ s("a", { onClick: i, style: D.link, children: l.forgotPasswordLink }),
2427
+ f && w && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2428
+ w && /* @__PURE__ */ d("div", { children: [
2429
+ /* @__PURE__ */ d("span", { style: D.divider, children: [
2430
+ l.signupText,
2247
2431
  " "
2248
2432
  ] }),
2249
- /* @__PURE__ */ n("a", { onClick: a, style: L.link, children: c.signupLink })
2433
+ /* @__PURE__ */ s("a", { onClick: a, style: D.link, children: l.signupLink })
2250
2434
  ] })
2251
2435
  ] })
2252
2436
  ] });
2253
2437
  }
2254
- const Mt = {
2438
+ const _t = {
2255
2439
  title: "Create Account",
2256
2440
  nameLabel: "First Name",
2257
2441
  namePlaceholder: "Enter your first name",
@@ -2277,7 +2461,7 @@ const Mt = {
2277
2461
  passwordMismatchError: "Passwords do not match",
2278
2462
  isAdminLabel: "Create new organization",
2279
2463
  isAdminDescription: "Check this if you want to create a new organization"
2280
- }, It = {
2464
+ }, Wt = {
2281
2465
  container: {
2282
2466
  maxWidth: "400px",
2283
2467
  width: "100%",
@@ -2376,138 +2560,138 @@ const Mt = {
2376
2560
  fontSize: "0.875rem"
2377
2561
  }
2378
2562
  };
2379
- function cr({
2380
- copy: i = {},
2563
+ function Hn({
2564
+ copy: r = {},
2381
2565
  styles: e = {},
2382
2566
  signupType: t = "user",
2383
- onSuccess: r,
2384
- onError: s,
2385
- onLoginClick: o,
2567
+ onSuccess: n,
2568
+ onError: o,
2569
+ onLoginClick: i,
2386
2570
  onMagicLinkClick: a,
2387
- showLoginLink: m = !0,
2388
- showMagicLinkOption: y = !0,
2389
- className: b
2571
+ showLoginLink: p = !0,
2572
+ showMagicLinkOption: f = !0,
2573
+ className: w
2390
2574
  }) {
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 });
2575
+ const [u, b] = A(""), [g, T] = A(""), [I, N] = A(""), [M, P] = A(""), [h, x] = A(""), [S, L] = A(""), [E, C] = A(""), [R, $] = A(!1), [l, D] = A(""), [U, c] = A({}), { signup: H, signupTenantAdmin: F } = le(), { tenant: y } = ge(), m = { ..._t, ...r }, v = { ...Wt, ...e }, G = () => {
2576
+ const k = {};
2577
+ return u.trim() || (k.name = !0), !I.trim() && !M.trim() && (k.email = !0, k.phoneNumber = !0), h.trim() || (k.password = !0), S.trim() || (k.confirmPassword = !0), t === "tenant" && !E.trim() && (k.tenantName = !0), c(k), Object.keys(k).length === 0;
2578
+ }, J = async (k) => {
2579
+ if (k.preventDefault(), !!G()) {
2580
+ if (h !== S) {
2581
+ D(m.passwordMismatchError), c({ confirmPassword: !0 });
2398
2582
  return;
2399
2583
  }
2400
- if (t === "user" && !(h != null && h.id)) {
2401
- L("Tenant not found");
2584
+ if (t === "user" && !(y != null && y.id)) {
2585
+ D("Tenant not found");
2402
2586
  return;
2403
2587
  }
2404
- O(!0), L("");
2588
+ $(!0), D("");
2405
2589
  try {
2406
- let J;
2407
- t === "tenant" ? J = await M({
2590
+ let K;
2591
+ t === "tenant" ? K = await F({
2408
2592
  email: I || void 0,
2409
- phoneNumber: R || void 0,
2410
- name: p,
2411
- password: g,
2412
- tenantName: U,
2413
- lastName: f || void 0
2414
- }) : J = await H({
2593
+ phoneNumber: M || void 0,
2594
+ name: u,
2595
+ password: h,
2596
+ tenantName: E,
2597
+ lastName: g || void 0
2598
+ }) : K = await H({
2415
2599
  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);
2600
+ phoneNumber: M || void 0,
2601
+ name: u,
2602
+ password: h,
2603
+ tenantId: y.id,
2604
+ lastName: g || void 0
2605
+ }), n == null || n(K);
2606
+ } catch (K) {
2607
+ const ce = K.message || m.errorMessage;
2608
+ D(ce), o == null || o(ce);
2425
2609
  } finally {
2426
- O(!1);
2610
+ $(!1);
2427
2611
  }
2428
2612
  }
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(
2613
+ }, q = (k) => ({
2614
+ ...v.input,
2615
+ ...U[k] ? v.inputError : {}
2616
+ }), O = () => ({
2617
+ ...v.button,
2618
+ ...R ? v.buttonLoading : {},
2619
+ ...!u || !I && !M || !h || !S || R || t === "tenant" && !E ? v.buttonDisabled : {}
2620
+ }), V = u && (I || M) && h && S && (t === "user" || E);
2621
+ return /* @__PURE__ */ d("div", { className: w, style: v.container, children: [
2622
+ /* @__PURE__ */ s("h2", { style: v.title, children: m.title }),
2623
+ /* @__PURE__ */ d("form", { onSubmit: J, style: v.form, children: [
2624
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2625
+ /* @__PURE__ */ s("label", { style: v.label, children: m.nameLabel }),
2626
+ /* @__PURE__ */ s(
2443
2627
  "input",
2444
2628
  {
2445
2629
  id: "name",
2446
2630
  name: "name",
2447
2631
  type: "text",
2448
- value: p,
2449
- onChange: (v) => {
2450
- S(v.target.value), F.name && l((J) => ({ ...J, name: !1 }));
2632
+ value: u,
2633
+ onChange: (k) => {
2634
+ b(k.target.value), U.name && c((K) => ({ ...K, name: !1 }));
2451
2635
  },
2452
- placeholder: u.namePlaceholder,
2453
- style: B("name"),
2454
- disabled: P
2636
+ placeholder: m.namePlaceholder,
2637
+ style: q("name"),
2638
+ disabled: R
2455
2639
  }
2456
2640
  )
2457
2641
  ] }),
2458
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2459
- /* @__PURE__ */ n("label", { style: w.label, children: u.lastNameLabel }),
2460
- /* @__PURE__ */ n(
2642
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2643
+ /* @__PURE__ */ s("label", { style: v.label, children: m.lastNameLabel }),
2644
+ /* @__PURE__ */ s(
2461
2645
  "input",
2462
2646
  {
2463
2647
  id: "lastName",
2464
2648
  name: "lastName",
2465
2649
  type: "text",
2466
- value: f,
2467
- onChange: (v) => T(v.target.value),
2468
- placeholder: u.lastNamePlaceholder,
2469
- style: w.input,
2470
- disabled: P
2650
+ value: g,
2651
+ onChange: (k) => T(k.target.value),
2652
+ placeholder: m.lastNamePlaceholder,
2653
+ style: v.input,
2654
+ disabled: R
2471
2655
  }
2472
2656
  )
2473
2657
  ] }),
2474
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2475
- /* @__PURE__ */ n("label", { style: w.label, children: u.emailLabel }),
2476
- /* @__PURE__ */ n(
2658
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2659
+ /* @__PURE__ */ s("label", { style: v.label, children: m.emailLabel }),
2660
+ /* @__PURE__ */ s(
2477
2661
  "input",
2478
2662
  {
2479
2663
  id: "email",
2480
2664
  name: "email",
2481
2665
  type: "email",
2482
2666
  value: I,
2483
- onChange: (v) => {
2484
- C(v.target.value), F.email && l((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2667
+ onChange: (k) => {
2668
+ N(k.target.value), U.email && c((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2485
2669
  },
2486
- placeholder: u.emailPlaceholder,
2487
- style: B("email"),
2488
- disabled: P
2670
+ placeholder: m.emailPlaceholder,
2671
+ style: q("email"),
2672
+ disabled: R
2489
2673
  }
2490
2674
  )
2491
2675
  ] }),
2492
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2493
- /* @__PURE__ */ n("label", { style: w.label, children: u.phoneNumberLabel }),
2494
- /* @__PURE__ */ n(
2676
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2677
+ /* @__PURE__ */ s("label", { style: v.label, children: m.phoneNumberLabel }),
2678
+ /* @__PURE__ */ s(
2495
2679
  "input",
2496
2680
  {
2497
2681
  id: "phoneNumber",
2498
2682
  name: "phoneNumber",
2499
2683
  type: "tel",
2500
- value: R,
2501
- onChange: (v) => {
2502
- x(v.target.value), F.phoneNumber && l((J) => ({ ...J, email: !1, phoneNumber: !1 }));
2684
+ value: M,
2685
+ onChange: (k) => {
2686
+ P(k.target.value), U.phoneNumber && c((K) => ({ ...K, email: !1, phoneNumber: !1 }));
2503
2687
  },
2504
- placeholder: u.phoneNumberPlaceholder,
2505
- style: B("phoneNumber"),
2506
- disabled: P
2688
+ placeholder: m.phoneNumberPlaceholder,
2689
+ style: q("phoneNumber"),
2690
+ disabled: R
2507
2691
  }
2508
2692
  )
2509
2693
  ] }),
2510
- /* @__PURE__ */ n(
2694
+ /* @__PURE__ */ s(
2511
2695
  "div",
2512
2696
  {
2513
2697
  style: {
@@ -2519,83 +2703,83 @@ function cr({
2519
2703
  children: "At least one contact method (email or phone) is required"
2520
2704
  }
2521
2705
  ),
2522
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2523
- /* @__PURE__ */ n("label", { style: w.label, children: u.passwordLabel }),
2524
- /* @__PURE__ */ n(
2706
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2707
+ /* @__PURE__ */ s("label", { style: v.label, children: m.passwordLabel }),
2708
+ /* @__PURE__ */ s(
2525
2709
  "input",
2526
2710
  {
2527
2711
  id: "password",
2528
2712
  name: "password",
2529
2713
  type: "password",
2530
- value: g,
2531
- onChange: (v) => {
2532
- $(v.target.value), F.password && l((J) => ({ ...J, password: !1 }));
2714
+ value: h,
2715
+ onChange: (k) => {
2716
+ x(k.target.value), U.password && c((K) => ({ ...K, password: !1 }));
2533
2717
  },
2534
- placeholder: u.passwordPlaceholder,
2535
- style: B("password"),
2536
- disabled: P
2718
+ placeholder: m.passwordPlaceholder,
2719
+ style: q("password"),
2720
+ disabled: R
2537
2721
  }
2538
2722
  )
2539
2723
  ] }),
2540
- /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2541
- /* @__PURE__ */ n("label", { style: w.label, children: u.confirmPasswordLabel }),
2542
- /* @__PURE__ */ n(
2724
+ /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2725
+ /* @__PURE__ */ s("label", { style: v.label, children: m.confirmPasswordLabel }),
2726
+ /* @__PURE__ */ s(
2543
2727
  "input",
2544
2728
  {
2545
2729
  id: "confirmPassword",
2546
2730
  name: "confirmPassword",
2547
2731
  type: "password",
2548
- value: A,
2549
- onChange: (v) => {
2550
- E(v.target.value), F.confirmPassword && l((J) => ({ ...J, confirmPassword: !1 })), c === u.passwordMismatchError && L("");
2732
+ value: S,
2733
+ onChange: (k) => {
2734
+ L(k.target.value), U.confirmPassword && c((K) => ({ ...K, confirmPassword: !1 })), l === m.passwordMismatchError && D("");
2551
2735
  },
2552
- placeholder: u.confirmPasswordPlaceholder,
2553
- style: B("confirmPassword"),
2554
- disabled: P
2736
+ placeholder: m.confirmPasswordPlaceholder,
2737
+ style: q("confirmPassword"),
2738
+ disabled: R
2555
2739
  }
2556
2740
  )
2557
2741
  ] }),
2558
- t === "tenant" && /* @__PURE__ */ d("div", { style: w.fieldGroup, children: [
2559
- /* @__PURE__ */ n("label", { style: w.label, children: u.tenantNameLabel }),
2560
- /* @__PURE__ */ n(
2742
+ t === "tenant" && /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2743
+ /* @__PURE__ */ s("label", { style: v.label, children: m.tenantNameLabel }),
2744
+ /* @__PURE__ */ s(
2561
2745
  "input",
2562
2746
  {
2563
2747
  id: "tenantName",
2564
2748
  name: "tenantName",
2565
2749
  type: "text",
2566
- value: U,
2567
- onChange: (v) => {
2568
- D(v.target.value), F.tenantName && l((J) => ({ ...J, tenantName: !1 }));
2750
+ value: E,
2751
+ onChange: (k) => {
2752
+ C(k.target.value), U.tenantName && c((K) => ({ ...K, tenantName: !1 }));
2569
2753
  },
2570
- placeholder: u.tenantNamePlaceholder,
2571
- style: B("tenantName"),
2572
- disabled: P
2754
+ placeholder: m.tenantNamePlaceholder,
2755
+ style: q("tenantName"),
2756
+ disabled: R
2573
2757
  }
2574
2758
  )
2575
2759
  ] }),
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 })
2760
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !V || R, style: O(), children: R ? m.loadingText : m.submitButton }),
2761
+ l && /* @__PURE__ */ s("div", { style: v.errorText, children: l })
2578
2762
  ] }),
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,
2763
+ (p || f) && /* @__PURE__ */ d("div", { style: v.linkContainer, children: [
2764
+ f && /* @__PURE__ */ d("div", { children: [
2765
+ /* @__PURE__ */ d("span", { style: v.divider, children: [
2766
+ m.magicLinkText,
2583
2767
  " "
2584
2768
  ] }),
2585
- /* @__PURE__ */ n("a", { onClick: a, style: w.link, children: u.magicLinkLink })
2769
+ /* @__PURE__ */ s("a", { onClick: a, style: v.link, children: m.magicLinkLink })
2586
2770
  ] }),
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,
2771
+ f && p && /* @__PURE__ */ s("div", { style: v.divider, children: "•" }),
2772
+ p && /* @__PURE__ */ d("div", { children: [
2773
+ /* @__PURE__ */ d("span", { style: v.divider, children: [
2774
+ m.loginText,
2591
2775
  " "
2592
2776
  ] }),
2593
- /* @__PURE__ */ n("a", { onClick: o, style: w.link, children: u.loginLink })
2777
+ /* @__PURE__ */ s("a", { onClick: i, style: v.link, children: m.loginLink })
2594
2778
  ] })
2595
2779
  ] })
2596
2780
  ] });
2597
2781
  }
2598
- const Rt = {
2782
+ const Vt = {
2599
2783
  title: "Sign In with Magic Link",
2600
2784
  emailLabel: "Email",
2601
2785
  emailPlaceholder: "Enter your email",
@@ -2613,7 +2797,7 @@ const Rt = {
2613
2797
  loadingText: "Sending magic link...",
2614
2798
  verifyingText: "Verifying magic link...",
2615
2799
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2616
- }, Lt = {
2800
+ }, jt = {
2617
2801
  container: {
2618
2802
  maxWidth: "400px",
2619
2803
  width: "100%",
@@ -2716,105 +2900,105 @@ const Rt = {
2716
2900
  fontSize: "0.875rem"
2717
2901
  }
2718
2902
  };
2719
- function dr({
2720
- copy: i = {},
2903
+ function Bn({
2904
+ copy: r = {},
2721
2905
  styles: e = {},
2722
2906
  onSuccess: t,
2723
- onError: r,
2724
- onLoginClick: s,
2725
- onSignupClick: o,
2907
+ onError: n,
2908
+ onLoginClick: o,
2909
+ onSignupClick: i,
2726
2910
  showTraditionalLinks: a = !0,
2727
- className: m,
2728
- verifyToken: y,
2729
- frontendUrl: b
2911
+ className: p,
2912
+ verifyToken: f,
2913
+ frontendUrl: w
2730
2914
  }) {
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");
2915
+ const [u, b] = A(""), [g, T] = A(""), [I, N] = A(""), [M, P] = A(!1), [h, x] = A(!1), [S, L] = A(""), [E, C] = A(""), [R, $] = A({}), [l, D] = A(!1), { sendMagicLink: U, verifyMagicLink: c } = le(), { tenant: H } = ge(), F = { ...Vt, ...r }, y = { ...jt, ...e };
2916
+ X(() => {
2917
+ f && m(f);
2918
+ }, [f]);
2919
+ const m = async (O) => {
2920
+ if (!H || !u) {
2921
+ L("Missing tenant or email");
2738
2922
  return;
2739
2923
  }
2740
- $(!0), E("");
2924
+ x(!0), L("");
2741
2925
  try {
2742
- const V = await l({
2743
- token: q,
2744
- email: p
2926
+ const V = await c({
2927
+ token: O,
2928
+ email: u
2745
2929
  // tenantId inferred from context automatically
2746
2930
  });
2747
2931
  t == null || t(V);
2748
2932
  } catch (V) {
2749
- const v = V.message || "Failed to verify magic link";
2750
- E(v), r == null || r(v);
2933
+ const k = V.message || "Failed to verify magic link";
2934
+ L(k), n == null || n(k);
2751
2935
  } finally {
2752
- $(!1);
2936
+ x(!1);
2753
2937
  }
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()) {
2938
+ }, v = () => {
2939
+ const O = {};
2940
+ return u.trim() || (O.email = !0), l && !g.trim() && (O.name = !0), $(O), Object.keys(O).length === 0;
2941
+ }, G = async (O) => {
2942
+ if (O.preventDefault(), !!v()) {
2759
2943
  if (!(H != null && H.id)) {
2760
- E("Tenant not found");
2944
+ L("Tenant not found");
2761
2945
  return;
2762
2946
  }
2763
- x(!0), E(""), D("");
2947
+ P(!0), L(""), C("");
2764
2948
  try {
2765
- const V = b || (typeof window < "u" ? window.location.origin : ""), v = await F({
2766
- email: p,
2949
+ const V = w || (typeof window < "u" ? window.location.origin : ""), k = await U({
2950
+ email: u,
2767
2951
  tenantId: H.id,
2768
2952
  frontendUrl: V,
2769
- name: c ? f : void 0,
2770
- lastName: c ? I : void 0
2953
+ name: l ? g : void 0,
2954
+ lastName: l ? I : void 0
2771
2955
  });
2772
- D(M.successMessage), t == null || t(v);
2956
+ C(F.successMessage), t == null || t(k);
2773
2957
  } catch (V) {
2774
- const v = V.message || M.errorMessage;
2775
- E(v), r == null || r(v);
2958
+ const k = V.message || F.errorMessage;
2959
+ L(k), n == null || n(k);
2776
2960
  } finally {
2777
- x(!1);
2961
+ P(!1);
2778
2962
  }
2779
2963
  }
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 : {}
2964
+ }, J = (O) => ({
2965
+ ...y.input,
2966
+ ...R[O] ? y.inputError : {}
2967
+ }), q = () => ({
2968
+ ...y.button,
2969
+ ...M || h ? y.buttonLoading : {},
2970
+ ...!u || M || h ? y.buttonDisabled : {}
2787
2971
  });
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(
2972
+ return h ? /* @__PURE__ */ d("div", { className: p, style: y.container, children: [
2973
+ /* @__PURE__ */ s("h2", { style: y.title, children: F.verifyingText }),
2974
+ /* @__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..." }) })
2975
+ ] }) : /* @__PURE__ */ d("div", { className: p, style: y.container, children: [
2976
+ /* @__PURE__ */ s("h2", { style: y.title, children: F.title }),
2977
+ /* @__PURE__ */ s("p", { style: y.description, children: F.description }),
2978
+ /* @__PURE__ */ d("form", { onSubmit: G, style: y.form, children: [
2979
+ /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
2980
+ /* @__PURE__ */ s("label", { style: y.label, children: F.emailLabel }),
2981
+ /* @__PURE__ */ s(
2798
2982
  "input",
2799
2983
  {
2800
2984
  id: "email",
2801
2985
  name: "email",
2802
2986
  type: "email",
2803
- value: p,
2804
- onChange: (q) => {
2805
- S(q.target.value), P.email && O((V) => ({ ...V, email: !1 }));
2987
+ value: u,
2988
+ onChange: (O) => {
2989
+ b(O.target.value), R.email && $((V) => ({ ...V, email: !1 }));
2806
2990
  },
2807
- placeholder: M.emailPlaceholder,
2808
- style: K("email"),
2809
- disabled: R || g
2991
+ placeholder: F.emailPlaceholder,
2992
+ style: J("email"),
2993
+ disabled: M || h
2810
2994
  }
2811
2995
  )
2812
2996
  ] }),
2813
- !c && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2997
+ !l && /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
2814
2998
  "button",
2815
2999
  {
2816
3000
  type: "button",
2817
- onClick: () => L(!0),
3001
+ onClick: () => D(!0),
2818
3002
  style: {
2819
3003
  background: "none",
2820
3004
  border: "none",
@@ -2826,47 +3010,47 @@ function dr({
2826
3010
  children: "New user? Add your name"
2827
3011
  }
2828
3012
  ) }),
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(
3013
+ l && /* @__PURE__ */ d(_, { children: [
3014
+ /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
3015
+ /* @__PURE__ */ s("label", { style: y.label, children: F.nameLabel }),
3016
+ /* @__PURE__ */ s(
2833
3017
  "input",
2834
3018
  {
2835
3019
  id: "name",
2836
3020
  name: "name",
2837
3021
  type: "text",
2838
- value: f,
2839
- onChange: (q) => {
2840
- T(q.target.value), P.name && O((V) => ({ ...V, name: !1 }));
3022
+ value: g,
3023
+ onChange: (O) => {
3024
+ T(O.target.value), R.name && $((V) => ({ ...V, name: !1 }));
2841
3025
  },
2842
- placeholder: M.namePlaceholder,
2843
- style: K("name"),
2844
- disabled: R || g
3026
+ placeholder: F.namePlaceholder,
3027
+ style: J("name"),
3028
+ disabled: M || h
2845
3029
  }
2846
3030
  )
2847
3031
  ] }),
2848
- /* @__PURE__ */ d("div", { style: h.fieldGroup, children: [
2849
- /* @__PURE__ */ n("label", { style: h.label, children: M.lastNameLabel }),
2850
- /* @__PURE__ */ n(
3032
+ /* @__PURE__ */ d("div", { style: y.fieldGroup, children: [
3033
+ /* @__PURE__ */ s("label", { style: y.label, children: F.lastNameLabel }),
3034
+ /* @__PURE__ */ s(
2851
3035
  "input",
2852
3036
  {
2853
3037
  id: "lastName",
2854
3038
  name: "lastName",
2855
3039
  type: "text",
2856
3040
  value: I,
2857
- onChange: (q) => C(q.target.value),
2858
- placeholder: M.lastNamePlaceholder,
2859
- style: h.input,
2860
- disabled: R || g
3041
+ onChange: (O) => N(O.target.value),
3042
+ placeholder: F.lastNamePlaceholder,
3043
+ style: y.input,
3044
+ disabled: M || h
2861
3045
  }
2862
3046
  )
2863
3047
  ] }),
2864
- /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
3048
+ /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
2865
3049
  "button",
2866
3050
  {
2867
3051
  type: "button",
2868
3052
  onClick: () => {
2869
- L(!1), T(""), C("");
3053
+ D(!1), T(""), N("");
2870
3054
  },
2871
3055
  style: {
2872
3056
  background: "none",
@@ -2880,30 +3064,30 @@ function dr({
2880
3064
  }
2881
3065
  ) })
2882
3066
  ] }),
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 })
3067
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !u || M || h, style: q(), children: M ? F.loadingText : F.submitButton }),
3068
+ S && /* @__PURE__ */ s("div", { style: y.errorText, children: S }),
3069
+ E && /* @__PURE__ */ s("div", { style: y.successText, children: E })
2886
3070
  ] }),
2887
- a && /* @__PURE__ */ d("div", { style: h.linkContainer, children: [
3071
+ a && /* @__PURE__ */ d("div", { style: y.linkContainer, children: [
2888
3072
  /* @__PURE__ */ d("div", { children: [
2889
- /* @__PURE__ */ d("span", { style: h.divider, children: [
2890
- M.loginText,
3073
+ /* @__PURE__ */ d("span", { style: y.divider, children: [
3074
+ F.loginText,
2891
3075
  " "
2892
3076
  ] }),
2893
- /* @__PURE__ */ n("a", { onClick: s, style: h.link, children: M.loginLink })
3077
+ /* @__PURE__ */ s("a", { onClick: o, style: y.link, children: F.loginLink })
2894
3078
  ] }),
2895
- /* @__PURE__ */ n("div", { style: h.divider, children: "•" }),
3079
+ /* @__PURE__ */ s("div", { style: y.divider, children: "•" }),
2896
3080
  /* @__PURE__ */ d("div", { children: [
2897
- /* @__PURE__ */ d("span", { style: h.divider, children: [
2898
- M.signupText,
3081
+ /* @__PURE__ */ d("span", { style: y.divider, children: [
3082
+ F.signupText,
2899
3083
  " "
2900
3084
  ] }),
2901
- /* @__PURE__ */ n("a", { onClick: o, style: h.link, children: M.signupLink })
3085
+ /* @__PURE__ */ s("a", { onClick: i, style: y.link, children: F.signupLink })
2902
3086
  ] })
2903
3087
  ] })
2904
3088
  ] });
2905
3089
  }
2906
- const Et = {
3090
+ const Gt = {
2907
3091
  title: "Verifying Magic Link",
2908
3092
  verifyingMessage: "Please wait while we verify your magic link...",
2909
3093
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2911,7 +3095,7 @@ const Et = {
2911
3095
  redirectingMessage: "Redirecting you to the dashboard...",
2912
3096
  retryButton: "Try Again",
2913
3097
  backToLoginButton: "Back to Login"
2914
- }, Oe = {
3098
+ }, Ke = {
2915
3099
  container: {
2916
3100
  maxWidth: "400px",
2917
3101
  width: "100%",
@@ -2998,7 +3182,7 @@ const Et = {
2998
3182
  cursor: "pointer",
2999
3183
  transition: "all 0.15s ease-in-out"
3000
3184
  }
3001
- }, Ft = () => /* @__PURE__ */ n("div", { style: Oe.spinner }), Ct = () => /* @__PURE__ */ d(
3185
+ }, Zt = () => /* @__PURE__ */ s("div", { style: Ke.spinner }), Kt = () => /* @__PURE__ */ d(
3002
3186
  "svg",
3003
3187
  {
3004
3188
  width: "48",
@@ -3011,11 +3195,11 @@ const Et = {
3011
3195
  strokeLinejoin: "round",
3012
3196
  style: { margin: "0 auto 1rem auto", display: "block" },
3013
3197
  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" })
3198
+ /* @__PURE__ */ s("path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14" }),
3199
+ /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3016
3200
  ]
3017
3201
  }
3018
- ), Dt = () => /* @__PURE__ */ d(
3202
+ ), Jt = () => /* @__PURE__ */ d(
3019
3203
  "svg",
3020
3204
  {
3021
3205
  width: "48",
@@ -3028,114 +3212,114 @@ const Et = {
3028
3212
  strokeLinejoin: "round",
3029
3213
  style: { margin: "0 auto 1rem auto", display: "block" },
3030
3214
  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" })
3215
+ /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "10" }),
3216
+ /* @__PURE__ */ s("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
3217
+ /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3034
3218
  ]
3035
3219
  }
3036
- ), $t = {
3037
- loading: /* @__PURE__ */ n(Ft, {}),
3038
- success: /* @__PURE__ */ n(Ct, {}),
3039
- error: /* @__PURE__ */ n(Dt, {})
3220
+ ), Yt = {
3221
+ loading: /* @__PURE__ */ s(Zt, {}),
3222
+ success: /* @__PURE__ */ s(Kt, {}),
3223
+ error: /* @__PURE__ */ s(Jt, {})
3040
3224
  };
3041
- function ur({
3042
- copy: i = {},
3225
+ function qn({
3226
+ copy: r = {},
3043
3227
  styles: e = {},
3044
3228
  icons: t = {},
3045
- onSuccess: r,
3046
- onError: s,
3047
- onRetry: o,
3229
+ onSuccess: n,
3230
+ onError: o,
3231
+ onRetry: i,
3048
3232
  onBackToLogin: a,
3049
- className: m,
3050
- token: y,
3051
- email: b,
3052
- appId: p,
3053
- tenantSlug: S,
3054
- autoRedirectDelay: f = 3e3
3233
+ className: p,
3234
+ token: f,
3235
+ email: w,
3236
+ appId: u,
3237
+ tenantSlug: b,
3238
+ autoRedirectDelay: g = 3e3
3055
3239
  }) {
3056
- const [T, I] = k("verifying"), [C, R] = k(""), { verifyMagicLink: x } = oe(), g = { ...Et, ...i }, $ = { ...Oe, ...e }, A = { ...$t, ...t }, E = () => {
3240
+ const [T, I] = A("verifying"), [N, M] = A(""), { verifyMagicLink: P } = le(), h = { ...Gt, ...r }, x = { ...Ke, ...e }, S = { ...Yt, ...t }, L = () => {
3057
3241
  if (typeof window > "u") return {};
3058
- const c = new URLSearchParams(window.location.search);
3242
+ const l = new URLSearchParams(window.location.search);
3059
3243
  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
3244
+ token: f || l.get("token") || "",
3245
+ email: w || l.get("email") || "",
3246
+ appId: u || l.get("appId") || "",
3247
+ tenantSlug: b || l.get("tenantSlug") || void 0
3064
3248
  };
3065
- }, U = async () => {
3066
- I("verifying"), R("");
3249
+ }, E = async () => {
3250
+ I("verifying"), M("");
3067
3251
  try {
3068
- const c = E();
3069
- if (!c.token || !c.email)
3252
+ const l = L();
3253
+ if (!l.token || !l.email)
3070
3254
  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
3255
+ const D = await P({
3256
+ token: l.token,
3257
+ email: l.email,
3258
+ tenantSlug: l.tenantSlug
3075
3259
  });
3076
- I("success"), r == null || r(L), f > 0 && setTimeout(() => {
3260
+ I("success"), n == null || n(D), g > 0 && setTimeout(() => {
3077
3261
  I("redirecting");
3078
- }, f);
3079
- } catch (c) {
3080
- const L = c.message || g.errorMessage;
3081
- R(L), I("error"), s == null || s(L);
3262
+ }, g);
3263
+ } catch (l) {
3264
+ const D = l.message || h.errorMessage;
3265
+ M(D), I("error"), o == null || o(D);
3082
3266
  }
3083
- }, D = () => {
3084
- o == null || o(), U();
3085
- }, P = () => {
3267
+ }, C = () => {
3268
+ i == null || i(), E();
3269
+ }, R = () => {
3086
3270
  a == null || a();
3087
3271
  };
3088
- re(() => {
3089
- U();
3272
+ X(() => {
3273
+ E();
3090
3274
  }, []);
3091
- const O = () => {
3275
+ const $ = () => {
3092
3276
  switch (T) {
3093
3277
  case "verifying":
3094
- return /* @__PURE__ */ d("div", { style: $.message, children: [
3095
- A.loading,
3096
- g.verifyingMessage
3278
+ return /* @__PURE__ */ d("div", { style: x.message, children: [
3279
+ S.loading,
3280
+ h.verifyingMessage
3097
3281
  ] });
3098
3282
  case "success":
3099
- return /* @__PURE__ */ d(j, { children: [
3100
- A.success,
3101
- /* @__PURE__ */ n("div", { style: $.successMessage, children: g.successMessage })
3283
+ return /* @__PURE__ */ d(_, { children: [
3284
+ S.success,
3285
+ /* @__PURE__ */ s("div", { style: x.successMessage, children: h.successMessage })
3102
3286
  ] });
3103
3287
  case "redirecting":
3104
- return /* @__PURE__ */ d(j, { children: [
3105
- A.loading,
3106
- /* @__PURE__ */ n("div", { style: $.message, children: g.redirectingMessage })
3288
+ return /* @__PURE__ */ d(_, { children: [
3289
+ S.loading,
3290
+ /* @__PURE__ */ s("div", { style: x.message, children: h.redirectingMessage })
3107
3291
  ] });
3108
3292
  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(
3293
+ return /* @__PURE__ */ d(_, { children: [
3294
+ S.error,
3295
+ /* @__PURE__ */ s("div", { style: x.errorMessage, children: N || h.errorMessage }),
3296
+ /* @__PURE__ */ d("div", { style: x.buttonContainer, children: [
3297
+ /* @__PURE__ */ s(
3114
3298
  "button",
3115
3299
  {
3116
- onClick: D,
3117
- style: $.retryButton,
3118
- onMouseOver: (c) => {
3119
- c.currentTarget.style.backgroundColor = "#2563eb";
3300
+ onClick: C,
3301
+ style: x.retryButton,
3302
+ onMouseOver: (l) => {
3303
+ l.currentTarget.style.backgroundColor = "#2563eb";
3120
3304
  },
3121
- onMouseOut: (c) => {
3122
- c.currentTarget.style.backgroundColor = "#3b82f6";
3305
+ onMouseOut: (l) => {
3306
+ l.currentTarget.style.backgroundColor = "#3b82f6";
3123
3307
  },
3124
- children: g.retryButton
3308
+ children: h.retryButton
3125
3309
  }
3126
3310
  ),
3127
- /* @__PURE__ */ n(
3311
+ /* @__PURE__ */ s(
3128
3312
  "button",
3129
3313
  {
3130
- onClick: P,
3131
- style: $.backButton,
3132
- onMouseOver: (c) => {
3133
- c.currentTarget.style.backgroundColor = "#e5e7eb";
3314
+ onClick: R,
3315
+ style: x.backButton,
3316
+ onMouseOver: (l) => {
3317
+ l.currentTarget.style.backgroundColor = "#e5e7eb";
3134
3318
  },
3135
- onMouseOut: (c) => {
3136
- c.currentTarget.style.backgroundColor = "#f3f4f6";
3319
+ onMouseOut: (l) => {
3320
+ l.currentTarget.style.backgroundColor = "#f3f4f6";
3137
3321
  },
3138
- children: g.backToLoginButton
3322
+ children: h.backToLoginButton
3139
3323
  }
3140
3324
  )
3141
3325
  ] })
@@ -3144,18 +3328,18 @@ function ur({
3144
3328
  return null;
3145
3329
  }
3146
3330
  };
3147
- return /* @__PURE__ */ d("div", { style: $.container, className: m, children: [
3148
- /* @__PURE__ */ n("style", { children: `
3331
+ return /* @__PURE__ */ d("div", { style: x.container, className: p, children: [
3332
+ /* @__PURE__ */ s("style", { children: `
3149
3333
  @keyframes spin {
3150
3334
  0% { transform: rotate(0deg); }
3151
3335
  100% { transform: rotate(360deg); }
3152
3336
  }
3153
3337
  ` }),
3154
- /* @__PURE__ */ n("h1", { style: $.title, children: g.title }),
3155
- O()
3338
+ /* @__PURE__ */ s("h1", { style: x.title, children: h.title }),
3339
+ $()
3156
3340
  ] });
3157
3341
  }
3158
- const Ht = {
3342
+ const Qt = {
3159
3343
  title: "Reset Password",
3160
3344
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3161
3345
  emailLabel: "Email",
@@ -3177,7 +3361,7 @@ const Ht = {
3177
3361
  resetLoadingText: "Resetting...",
3178
3362
  resetSuccessMessage: "Password reset successfully!",
3179
3363
  passwordMismatchError: "Passwords do not match"
3180
- }, Nt = {
3364
+ }, Xt = {
3181
3365
  container: {
3182
3366
  maxWidth: "400px",
3183
3367
  margin: "0 auto",
@@ -3269,186 +3453,186 @@ const Ht = {
3269
3453
  cursor: "pointer"
3270
3454
  }
3271
3455
  };
3272
- function hr({
3273
- copy: i = {},
3456
+ function On({
3457
+ copy: r = {},
3274
3458
  styles: e = {},
3275
3459
  mode: t = "request",
3276
- token: r = "",
3277
- onSuccess: s,
3278
- onError: o,
3460
+ token: n = "",
3461
+ onSuccess: o,
3462
+ onError: i,
3279
3463
  onBackToLogin: a,
3280
- onModeChange: m,
3281
- className: y
3464
+ onModeChange: p,
3465
+ className: f
3282
3466
  }) {
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");
3467
+ const [w, u] = A(""), [b, g] = A(n), [T, I] = A(""), [N, M] = A(""), [P, h] = A(!1), [x, S] = A(""), [L, E] = A(""), [C, R] = A({}), { requestPasswordReset: $, confirmPasswordReset: l } = le(), { tenant: D } = ge(), U = { ...Qt, ...r }, c = { ...Xt, ...e }, H = () => {
3468
+ const q = {};
3469
+ return w.trim() || (q.email = !0), R(q), Object.keys(q).length === 0;
3470
+ }, F = () => {
3471
+ const q = {};
3472
+ return b.trim() || (q.token = !0), T.trim() || (q.newPassword = !0), N.trim() || (q.confirmPassword = !0), R(q), Object.keys(q).length === 0;
3473
+ }, y = async (q) => {
3474
+ if (q.preventDefault(), !!H()) {
3475
+ if (!(D != null && D.id)) {
3476
+ S("Tenant not found");
3293
3477
  return;
3294
3478
  }
3295
- g(!0), A(""), U("");
3479
+ h(!0), S(""), E("");
3296
3480
  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);
3481
+ await $({ email: w, tenantId: D.id }), E(U.successMessage), o == null || o();
3482
+ } catch (O) {
3483
+ const V = O.message || U.errorMessage;
3484
+ S(V), i == null || i(V);
3301
3485
  } finally {
3302
- g(!1);
3486
+ h(!1);
3303
3487
  }
3304
3488
  }
3305
- }, u = async (B) => {
3306
- if (B.preventDefault(), !!M()) {
3307
- if (T !== C) {
3308
- A(F.passwordMismatchError), P({ confirmPassword: !0 });
3489
+ }, m = async (q) => {
3490
+ if (q.preventDefault(), !!F()) {
3491
+ if (T !== N) {
3492
+ S(U.passwordMismatchError), R({ confirmPassword: !0 });
3309
3493
  return;
3310
3494
  }
3311
- g(!0), A(""), U("");
3495
+ h(!0), S(""), E("");
3312
3496
  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);
3497
+ await l({ token: b, newPassword: T }), E(U.resetSuccessMessage), o == null || o();
3498
+ } catch (O) {
3499
+ const V = O.message || U.errorMessage;
3500
+ S(V), i == null || i(V);
3317
3501
  } finally {
3318
- g(!1);
3502
+ h(!1);
3319
3503
  }
3320
3504
  }
3321
- }, w = (B) => ({
3322
- ...l.input,
3323
- ...D[B] ? l.inputError : {}
3324
- }), _ = () => ({
3325
- ...l.button,
3326
- ...x ? l.buttonLoading : {}
3505
+ }, v = (q) => ({
3506
+ ...c.input,
3507
+ ...C[q] ? c.inputError : {}
3508
+ }), G = () => ({
3509
+ ...c.button,
3510
+ ...P ? c.buttonLoading : {}
3327
3511
  });
3328
3512
  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(
3513
+ const q = b && T && N;
3514
+ return /* @__PURE__ */ d("div", { className: f, style: c.container, children: [
3515
+ /* @__PURE__ */ s("h2", { style: c.title, children: U.resetTitle }),
3516
+ /* @__PURE__ */ s("p", { style: c.subtitle, children: U.resetSubtitle }),
3517
+ /* @__PURE__ */ d("form", { onSubmit: m, style: c.form, children: [
3518
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3519
+ /* @__PURE__ */ s("label", { style: c.label, children: U.tokenLabel }),
3520
+ /* @__PURE__ */ s(
3337
3521
  "input",
3338
3522
  {
3339
3523
  type: "text",
3340
- value: S,
3341
- onChange: (q) => {
3342
- f(q.target.value), D.token && P((V) => ({ ...V, token: !1 }));
3524
+ value: b,
3525
+ onChange: (O) => {
3526
+ g(O.target.value), C.token && R((V) => ({ ...V, token: !1 }));
3343
3527
  },
3344
- placeholder: F.tokenPlaceholder,
3345
- style: w("token"),
3346
- disabled: x
3528
+ placeholder: U.tokenPlaceholder,
3529
+ style: v("token"),
3530
+ disabled: P
3347
3531
  }
3348
3532
  )
3349
3533
  ] }),
3350
- /* @__PURE__ */ d("div", { style: l.fieldGroup, children: [
3351
- /* @__PURE__ */ n("label", { style: l.label, children: F.newPasswordLabel }),
3352
- /* @__PURE__ */ n(
3534
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3535
+ /* @__PURE__ */ s("label", { style: c.label, children: U.newPasswordLabel }),
3536
+ /* @__PURE__ */ s(
3353
3537
  "input",
3354
3538
  {
3355
3539
  type: "password",
3356
3540
  value: T,
3357
- onChange: (q) => {
3358
- I(q.target.value), D.newPassword && P((V) => ({ ...V, newPassword: !1 }));
3541
+ onChange: (O) => {
3542
+ I(O.target.value), C.newPassword && R((V) => ({ ...V, newPassword: !1 }));
3359
3543
  },
3360
- placeholder: F.newPasswordPlaceholder,
3361
- style: w("newPassword"),
3362
- disabled: x
3544
+ placeholder: U.newPasswordPlaceholder,
3545
+ style: v("newPassword"),
3546
+ disabled: P
3363
3547
  }
3364
3548
  )
3365
3549
  ] }),
3366
- /* @__PURE__ */ d("div", { style: l.fieldGroup, children: [
3367
- /* @__PURE__ */ n("label", { style: l.label, children: F.confirmPasswordLabel }),
3368
- /* @__PURE__ */ n(
3550
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3551
+ /* @__PURE__ */ s("label", { style: c.label, children: U.confirmPasswordLabel }),
3552
+ /* @__PURE__ */ s(
3369
3553
  "input",
3370
3554
  {
3371
3555
  type: "password",
3372
- value: C,
3373
- onChange: (q) => {
3374
- R(q.target.value), D.confirmPassword && P((V) => ({ ...V, confirmPassword: !1 })), $ === F.passwordMismatchError && A("");
3556
+ value: N,
3557
+ onChange: (O) => {
3558
+ M(O.target.value), C.confirmPassword && R((V) => ({ ...V, confirmPassword: !1 })), x === U.passwordMismatchError && S("");
3375
3559
  },
3376
- placeholder: F.confirmPasswordPlaceholder,
3377
- style: w("confirmPassword"),
3378
- disabled: x
3560
+ placeholder: U.confirmPasswordPlaceholder,
3561
+ style: v("confirmPassword"),
3562
+ disabled: P
3379
3563
  }
3380
3564
  )
3381
3565
  ] }),
3382
- /* @__PURE__ */ n(
3566
+ /* @__PURE__ */ s(
3383
3567
  "button",
3384
3568
  {
3385
3569
  type: "submit",
3386
- disabled: !B || x,
3570
+ disabled: !q || P,
3387
3571
  style: {
3388
- ..._(),
3389
- ...!B || x ? l.buttonDisabled : {}
3572
+ ...G(),
3573
+ ...!q || P ? c.buttonDisabled : {}
3390
3574
  },
3391
- children: x ? F.resetLoadingText : F.resetSubmitButton
3575
+ children: P ? U.resetLoadingText : U.resetSubmitButton
3392
3576
  }
3393
3577
  ),
3394
- $ && /* @__PURE__ */ n("div", { style: l.errorText, children: $ }),
3395
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3578
+ x && /* @__PURE__ */ s("div", { style: c.errorText, children: x }),
3579
+ L && /* @__PURE__ */ s("div", { style: c.successText, children: L })
3396
3580
  ] }),
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" })
3581
+ /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3582
+ /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: U.backToLoginLink }),
3583
+ p && /* @__PURE__ */ d(_, { children: [
3584
+ /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3585
+ /* @__PURE__ */ s("a", { onClick: () => p("request"), style: c.link, children: "Request New Link" })
3402
3586
  ] })
3403
3587
  ] })
3404
3588
  ] });
3405
3589
  }
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(
3590
+ const J = w;
3591
+ return /* @__PURE__ */ d("div", { className: f, style: c.container, children: [
3592
+ /* @__PURE__ */ s("h2", { style: c.title, children: U.title }),
3593
+ /* @__PURE__ */ s("p", { style: c.subtitle, children: U.subtitle }),
3594
+ /* @__PURE__ */ d("form", { onSubmit: y, style: c.form, children: [
3595
+ /* @__PURE__ */ d("div", { style: c.fieldGroup, children: [
3596
+ /* @__PURE__ */ s("label", { style: c.label, children: U.emailLabel }),
3597
+ /* @__PURE__ */ s(
3414
3598
  "input",
3415
3599
  {
3416
3600
  type: "email",
3417
- value: b,
3418
- onChange: (B) => {
3419
- p(B.target.value), D.email && P((q) => ({ ...q, email: !1 }));
3601
+ value: w,
3602
+ onChange: (q) => {
3603
+ u(q.target.value), C.email && R((O) => ({ ...O, email: !1 }));
3420
3604
  },
3421
- placeholder: F.emailPlaceholder,
3422
- style: w("email"),
3423
- disabled: x
3605
+ placeholder: U.emailPlaceholder,
3606
+ style: v("email"),
3607
+ disabled: P
3424
3608
  }
3425
3609
  )
3426
3610
  ] }),
3427
- /* @__PURE__ */ n(
3611
+ /* @__PURE__ */ s(
3428
3612
  "button",
3429
3613
  {
3430
3614
  type: "submit",
3431
- disabled: !K || x,
3615
+ disabled: !J || P,
3432
3616
  style: {
3433
- ..._(),
3434
- ...!K || x ? l.buttonDisabled : {}
3617
+ ...G(),
3618
+ ...!J || P ? c.buttonDisabled : {}
3435
3619
  },
3436
- children: x ? F.loadingText : F.submitButton
3620
+ children: P ? U.loadingText : U.submitButton
3437
3621
  }
3438
3622
  ),
3439
- $ && /* @__PURE__ */ n("div", { style: l.errorText, children: $ }),
3440
- E && /* @__PURE__ */ n("div", { style: l.successText, children: E })
3623
+ x && /* @__PURE__ */ s("div", { style: c.errorText, children: x }),
3624
+ L && /* @__PURE__ */ s("div", { style: c.successText, children: L })
3441
3625
  ] }),
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" })
3626
+ /* @__PURE__ */ d("div", { style: c.linkContainer, children: [
3627
+ /* @__PURE__ */ s("a", { onClick: a, style: c.link, children: U.backToLoginLink }),
3628
+ p && /* @__PURE__ */ d(_, { children: [
3629
+ /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3630
+ /* @__PURE__ */ s("a", { onClick: () => p("reset"), style: c.link, children: "I have a token" })
3447
3631
  ] })
3448
3632
  ] })
3449
3633
  ] });
3450
3634
  }
3451
- const Ut = () => /* @__PURE__ */ n(
3635
+ const en = () => /* @__PURE__ */ s(
3452
3636
  "div",
3453
3637
  {
3454
3638
  style: {
@@ -3458,9 +3642,9 @@ const Ut = () => /* @__PURE__ */ n(
3458
3642
  height: "100vh",
3459
3643
  fontFamily: "system-ui, sans-serif"
3460
3644
  },
3461
- children: /* @__PURE__ */ n("div", { children: "Loading..." })
3645
+ children: /* @__PURE__ */ s("div", { children: "Loading..." })
3462
3646
  }
3463
- ), Bt = ({ error: i, retry: e }) => /* @__PURE__ */ d(
3647
+ ), tn = ({ error: r, retry: e }) => /* @__PURE__ */ d(
3464
3648
  "div",
3465
3649
  {
3466
3650
  style: {
@@ -3474,9 +3658,9 @@ const Ut = () => /* @__PURE__ */ n(
3474
3658
  padding: "20px"
3475
3659
  },
3476
3660
  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(
3661
+ /* @__PURE__ */ s("h2", { style: { color: "#dc3545", marginBottom: "16px" }, children: "Error" }),
3662
+ /* @__PURE__ */ s("p", { style: { color: "#6c757d", marginBottom: "24px" }, children: r.message || "Unable to load application" }),
3663
+ /* @__PURE__ */ s(
3480
3664
  "button",
3481
3665
  {
3482
3666
  onClick: e,
@@ -3494,98 +3678,98 @@ const Ut = () => /* @__PURE__ */ n(
3494
3678
  ]
3495
3679
  }
3496
3680
  );
3497
- function gr({
3498
- children: i,
3681
+ function zn({
3682
+ children: r,
3499
3683
  loadingFallback: e,
3500
3684
  errorFallback: t,
3501
- requireTenant: r = !0
3685
+ requireTenant: n = !0
3502
3686
  }) {
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();
3687
+ const { isAppLoading: o, appError: i, retryApp: a } = ye(), p = Se(), f = Le(), w = je(), u = Ge(), b = (p == null ? void 0 : p.isTenantLoading) ?? !1, g = (p == null ? void 0 : p.tenantError) ?? null, T = (p == null ? void 0 : p.tenantSlug) ?? null, I = (p == null ? void 0 : p.retryTenant) ?? (() => {
3688
+ }), N = (f == null ? void 0 : f.isAuthReady) ?? !0, M = (w == null ? void 0 : w.isReady) ?? !0, P = (u == null ? void 0 : u.isReady) ?? !0, h = n && p && T, E = o || h && b || f && !N || w && !M || u && !P, C = i || (h ? g : null), R = () => {
3689
+ i && a(), g && p && I();
3506
3690
  };
3507
- 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 });
3691
+ if (E)
3692
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(en, {}) });
3693
+ if (C) {
3694
+ const $ = typeof t == "function" ? t(C, R) : t || /* @__PURE__ */ s(tn, { error: C, retry: R });
3695
+ return /* @__PURE__ */ s(_, { children: $ });
3512
3696
  }
3513
- return /* @__PURE__ */ n(j, { children: i });
3697
+ return /* @__PURE__ */ s(_, { children: r });
3514
3698
  }
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);
3699
+ function _n(r = !0) {
3700
+ const { isAppLoading: e, appError: t, retryApp: n, appInfo: o } = ye(), i = Se(), a = Le(), p = je(), f = Ge(), w = (i == null ? void 0 : i.isTenantLoading) ?? !1, u = (i == null ? void 0 : i.tenantError) ?? null, b = (i == null ? void 0 : i.tenant) ?? null, g = (i == null ? void 0 : i.tenantSlug) ?? null, T = (i == null ? void 0 : i.retryTenant) ?? (() => {
3701
+ }), I = (a == null ? void 0 : a.isAuthReady) ?? !0, N = (p == null ? void 0 : p.isReady) ?? !0, M = (f == null ? void 0 : f.isReady) ?? !0, P = r && i && g, L = e || P && w || a && !I || p && !N || f && !M, E = t || (P ? u : null);
3518
3702
  return {
3519
- isLoading: E,
3520
- error: U,
3521
- isReady: !E && !U && s !== null && (!x || S !== null),
3703
+ isLoading: L,
3704
+ error: E,
3705
+ isReady: !L && !E && o !== null && (!P || b !== null),
3522
3706
  retry: () => {
3523
- t && r(), p && o && T();
3707
+ t && n(), u && i && T();
3524
3708
  },
3525
3709
  // Individual states
3526
- app: { isLoading: e, error: t, data: s },
3527
- tenant: o ? { isLoading: b, error: p, data: S } : null,
3710
+ app: { isLoading: e, error: t, data: o },
3711
+ tenant: i ? { isLoading: w, error: u, data: b } : null,
3528
3712
  auth: a ? { isReady: I } : null,
3529
- featureFlags: m ? { isReady: C } : null,
3530
- subscription: y ? { isReady: R } : null
3713
+ featureFlags: p ? { isReady: N } : null,
3714
+ subscription: f ? { isReady: M } : null
3531
3715
  };
3532
3716
  }
3533
- function fr({
3534
- tenants: i,
3717
+ function Wn({
3718
+ tenants: r,
3535
3719
  currentTenantId: e,
3536
3720
  onSelect: t,
3537
- className: r = "",
3538
- dropdownClassName: s = "",
3539
- itemClassName: o = "",
3721
+ className: n = "",
3722
+ dropdownClassName: o = "",
3723
+ itemClassName: i = "",
3540
3724
  renderItem: a,
3541
- placeholder: m = "Select tenant",
3542
- disabled: y = !1,
3543
- showCurrentTenant: b = !0
3725
+ placeholder: p = "Select tenant",
3726
+ disabled: f = !1,
3727
+ showCurrentTenant: w = !0
3544
3728
  }) {
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);
3729
+ var x;
3730
+ const u = Le(), [b, g] = A(!1), T = We(null), I = r ?? (u == null ? void 0 : u.userTenants) ?? [], N = e ?? ((x = u == null ? void 0 : u.currentUser) == null ? void 0 : x.tenantId) ?? null, M = async (S) => {
3731
+ g(!1), t ? t(S) : u != null && u.switchToTenant && await u.switchToTenant(S);
3548
3732
  };
3549
- re(() => {
3550
- const A = (E) => {
3551
- T.current && !T.current.contains(E.target) && f(!1);
3733
+ X(() => {
3734
+ const S = (L) => {
3735
+ T.current && !T.current.contains(L.target) && g(!1);
3552
3736
  };
3553
- return document.addEventListener("mousedown", A), () => document.removeEventListener("mousedown", A);
3737
+ return document.addEventListener("mousedown", S), () => document.removeEventListener("mousedown", S);
3554
3738
  }, []);
3555
- const x = I.find((A) => A.id === C);
3739
+ const P = I.find((S) => S.id === N);
3556
3740
  if (I.length === 0)
3557
3741
  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: [
3742
+ if (I.length === 1 && w)
3743
+ return /* @__PURE__ */ s("div", { className: n, children: /* @__PURE__ */ s("span", { children: I[0].name }) });
3744
+ const h = (S, L) => /* @__PURE__ */ d("span", { style: { fontWeight: L ? "bold" : "normal" }, children: [
3745
+ S.name,
3746
+ S.role && /* @__PURE__ */ d("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3563
3747
  "(",
3564
- A.role,
3748
+ S.role,
3565
3749
  ")"
3566
3750
  ] })
3567
3751
  ] });
3568
- return /* @__PURE__ */ d("div", { ref: T, className: r, style: { position: "relative" }, children: [
3752
+ return /* @__PURE__ */ d("div", { ref: T, className: n, style: { position: "relative" }, children: [
3569
3753
  /* @__PURE__ */ d(
3570
3754
  "button",
3571
3755
  {
3572
3756
  type: "button",
3573
- onClick: () => !y && f(!S),
3574
- disabled: y,
3757
+ onClick: () => !f && g(!b),
3758
+ disabled: f,
3575
3759
  style: {
3576
- cursor: y ? "not-allowed" : "pointer",
3577
- opacity: y ? 0.6 : 1
3760
+ cursor: f ? "not-allowed" : "pointer",
3761
+ opacity: f ? 0.6 : 1
3578
3762
  },
3579
3763
  children: [
3580
- x ? x.name : m,
3581
- /* @__PURE__ */ n("span", { style: { marginLeft: 8 }, children: S ? "▲" : "▼" })
3764
+ P ? P.name : p,
3765
+ /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: b ? "▲" : "▼" })
3582
3766
  ]
3583
3767
  }
3584
3768
  ),
3585
- S && /* @__PURE__ */ n(
3769
+ b && /* @__PURE__ */ s(
3586
3770
  "div",
3587
3771
  {
3588
- className: s,
3772
+ className: o,
3589
3773
  style: {
3590
3774
  position: "absolute",
3591
3775
  top: "100%",
@@ -3599,34 +3783,34 @@ function fr({
3599
3783
  maxHeight: 300,
3600
3784
  overflowY: "auto"
3601
3785
  },
3602
- children: I.map((A) => {
3603
- const E = A.id === C;
3604
- return /* @__PURE__ */ n(
3786
+ children: I.map((S) => {
3787
+ const L = S.id === N;
3788
+ return /* @__PURE__ */ s(
3605
3789
  "div",
3606
3790
  {
3607
- className: o,
3608
- onClick: () => R(A.id),
3791
+ className: i,
3792
+ onClick: () => M(S.id),
3609
3793
  style: {
3610
3794
  padding: "8px 12px",
3611
3795
  cursor: "pointer",
3612
- backgroundColor: E ? "#f0f0f0" : "transparent"
3796
+ backgroundColor: L ? "#f0f0f0" : "transparent"
3613
3797
  },
3614
- onMouseEnter: (U) => {
3615
- E || (U.target.style.backgroundColor = "#f5f5f5");
3798
+ onMouseEnter: (E) => {
3799
+ L || (E.target.style.backgroundColor = "#f5f5f5");
3616
3800
  },
3617
- onMouseLeave: (U) => {
3618
- E || (U.target.style.backgroundColor = "transparent");
3801
+ onMouseLeave: (E) => {
3802
+ L || (E.target.style.backgroundColor = "transparent");
3619
3803
  },
3620
- children: a ? a(A, E) : g(A, E)
3804
+ children: a ? a(S, L) : h(S, L)
3621
3805
  },
3622
- A.id
3806
+ S.id
3623
3807
  );
3624
3808
  })
3625
3809
  }
3626
3810
  )
3627
3811
  ] });
3628
3812
  }
3629
- class mr {
3813
+ class Vn {
3630
3814
  constructor(e, t) {
3631
3815
  this.httpService = e, this.sessionManager = t;
3632
3816
  }
@@ -3645,14 +3829,14 @@ class mr {
3645
3829
  async getPermissions(e) {
3646
3830
  if (!this.sessionManager)
3647
3831
  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, {
3832
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
3833
+ 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);
3834
+ const o = `/permissions/${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o, {
3651
3835
  headers: t
3652
3836
  });
3653
3837
  return {
3654
- permissions: o.data,
3655
- meta: o.meta
3838
+ permissions: i.data,
3839
+ meta: i.meta
3656
3840
  };
3657
3841
  }
3658
3842
  async getPermissionById(e) {
@@ -3666,12 +3850,12 @@ class mr {
3666
3850
  async updatePermission(e, t) {
3667
3851
  if (!this.sessionManager)
3668
3852
  throw new Error("SessionManager is required for private endpoints");
3669
- const r = await this.sessionManager.getAuthHeaders();
3853
+ const n = await this.sessionManager.getAuthHeaders();
3670
3854
  return (await this.httpService.put(
3671
3855
  `/permissions/${e}`,
3672
3856
  t,
3673
3857
  {
3674
- headers: r
3858
+ headers: n
3675
3859
  }
3676
3860
  )).data;
3677
3861
  }
@@ -3685,16 +3869,16 @@ class mr {
3685
3869
  }
3686
3870
  // Public endpoint - no auth required
3687
3871
  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);
3872
+ const n = new URLSearchParams();
3873
+ 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);
3874
+ const o = `/permissions/apps/${e}${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o);
3691
3875
  return {
3692
- permissions: o.data,
3693
- meta: o.meta
3876
+ permissions: i.data,
3877
+ meta: i.meta
3694
3878
  };
3695
3879
  }
3696
3880
  }
3697
- class yr {
3881
+ class jn {
3698
3882
  constructor(e, t) {
3699
3883
  this.httpService = e, this.sessionManager = t;
3700
3884
  }
@@ -3709,14 +3893,14 @@ class yr {
3709
3893
  )).data;
3710
3894
  }
3711
3895
  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, {
3896
+ const t = await this.sessionManager.getAuthHeaders(), n = new URLSearchParams();
3897
+ 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);
3898
+ const o = `/subscription-plans/${n.toString() ? `?${n.toString()}` : ""}`, i = await this.httpService.get(o, {
3715
3899
  headers: t
3716
3900
  });
3717
3901
  return {
3718
- plans: o.data,
3719
- meta: o.meta
3902
+ plans: i.data,
3903
+ meta: i.meta
3720
3904
  };
3721
3905
  }
3722
3906
  async getSubscriptionPlanById(e) {
@@ -3729,12 +3913,12 @@ class yr {
3729
3913
  )).data;
3730
3914
  }
3731
3915
  async updateSubscriptionPlan(e, t) {
3732
- const r = await this.sessionManager.getAuthHeaders();
3916
+ const n = await this.sessionManager.getAuthHeaders();
3733
3917
  return (await this.httpService.put(
3734
3918
  `/subscription-plans/${e}`,
3735
3919
  t,
3736
3920
  {
3737
- headers: r
3921
+ headers: n
3738
3922
  }
3739
3923
  )).data;
3740
3924
  }
@@ -3745,7 +3929,7 @@ class yr {
3745
3929
  });
3746
3930
  }
3747
3931
  }
3748
- class wr {
3932
+ class Gn {
3749
3933
  constructor(e) {
3750
3934
  this.httpService = e;
3751
3935
  }
@@ -3754,7 +3938,7 @@ class wr {
3754
3938
  return await this.httpService.get("/health");
3755
3939
  }
3756
3940
  }
3757
- class br {
3941
+ class Zn {
3758
3942
  // Date string to Date object
3759
3943
  static toDate(e) {
3760
3944
  return new Date(e);
@@ -3871,54 +4055,141 @@ class br {
3871
4055
  // Transform query parameters for API calls
3872
4056
  static transformQueryParams(e) {
3873
4057
  const t = new URLSearchParams();
3874
- return Object.entries(e).forEach(([r, s]) => {
3875
- s != null && s !== "" && t.append(r, String(s));
4058
+ return Object.entries(e).forEach(([n, o]) => {
4059
+ o != null && o !== "" && t.append(n, String(o));
3876
4060
  }), t;
3877
4061
  }
3878
4062
  }
4063
+ const Je = "returnTo", xe = "zone_return_to", Pe = "zone_return_to";
4064
+ function Kn(r = {}) {
4065
+ const {
4066
+ zoneRoots: e = {},
4067
+ returnToParam: t = Je,
4068
+ returnToStorage: n = "url"
4069
+ } = r, o = dt(), [i, a] = ut(), { isAuthenticated: p, currentUser: f } = le(), { tenant: w } = he(), u = Z(() => ({ ...Ne, ...e }), [e]), b = !!w, g = f == null ? void 0 : f.userType, T = Z(() => {
4070
+ switch (n) {
4071
+ case "url":
4072
+ return i.get(t);
4073
+ case "session":
4074
+ return sessionStorage.getItem(xe);
4075
+ case "local":
4076
+ return localStorage.getItem(Pe);
4077
+ default:
4078
+ return null;
4079
+ }
4080
+ }, [n, i, t]), I = re(() => {
4081
+ switch (n) {
4082
+ case "url": {
4083
+ const h = new URLSearchParams(i);
4084
+ h.delete(t), a(h, { replace: !0 });
4085
+ break;
4086
+ }
4087
+ case "session":
4088
+ sessionStorage.removeItem(xe);
4089
+ break;
4090
+ case "local":
4091
+ localStorage.removeItem(Pe);
4092
+ break;
4093
+ }
4094
+ }, [n, i, t, a]), N = re(
4095
+ (h) => {
4096
+ switch (n) {
4097
+ case "url": {
4098
+ const x = new URLSearchParams(i);
4099
+ x.set(t, h), a(x, { replace: !0 });
4100
+ break;
4101
+ }
4102
+ case "session":
4103
+ sessionStorage.setItem(xe, h);
4104
+ break;
4105
+ case "local":
4106
+ localStorage.setItem(Pe, h);
4107
+ break;
4108
+ }
4109
+ },
4110
+ [n, i, t, a]
4111
+ ), M = re(
4112
+ (h) => {
4113
+ const x = u[h] || u.default;
4114
+ o(x);
4115
+ },
4116
+ [o, u]
4117
+ ), P = re(() => b ? p ? g === se.TENANT_ADMIN ? u.tenantAdmin : u.tenantUser : u.tenantGuest : p ? g === se.TENANT_ADMIN ? u.publicAdmin : u.publicUser : u.publicGuest, [b, p, g, u]);
4118
+ return {
4119
+ returnToUrl: T,
4120
+ clearReturnTo: I,
4121
+ setReturnTo: N,
4122
+ navigateToZone: M,
4123
+ getSmartRedirect: P
4124
+ };
4125
+ }
4126
+ function Jn(r, e, t = Je, n = "url") {
4127
+ if (!e || n !== "url")
4128
+ return r;
4129
+ const o = new URL(r, window.location.origin);
4130
+ return o.searchParams.set(t, e), o.pathname + o.search;
4131
+ }
3879
4132
  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
4133
+ Mn as AdminZone,
4134
+ Zn as ApiMappers,
4135
+ $e as AppApiService,
4136
+ zn as AppLoader,
4137
+ un as AppProvider,
4138
+ ht as AuthApiService,
4139
+ mn as AuthProvider,
4140
+ Rn as AuthenticatedZone,
4141
+ Ze as DEFAULT_ZONE_PRESETS,
4142
+ Ne as DEFAULT_ZONE_ROOTS,
4143
+ Un as FeatureFlag,
4144
+ vt as FeatureFlagApiService,
4145
+ yn as FeatureFlagProvider,
4146
+ In as GuestZone,
4147
+ Gn as HealthApiService,
4148
+ ie as HttpService,
4149
+ An as LandingRoute,
4150
+ $n as LoginForm,
4151
+ Bn as MagicLinkForm,
4152
+ qn as MagicLinkVerify,
4153
+ En as OpenZone,
4154
+ On as PasswordRecoveryForm,
4155
+ Vn as PermissionApiService,
4156
+ vn as Protected,
4157
+ Tn as ProtectedRoute,
4158
+ Pn as PublicZone,
4159
+ He as RoleApiService,
4160
+ bn as RoutingProvider,
4161
+ Ae as SessionManager,
4162
+ Hn as SignupForm,
4163
+ kt as SubscriptionApiService,
4164
+ Cn as SubscriptionGuard,
4165
+ jn as SubscriptionPlanApiService,
4166
+ wn as SubscriptionProvider,
4167
+ fe as TenantApiService,
4168
+ Fn as TenantAuthenticatedZone,
4169
+ Dn as TenantGuestZone,
4170
+ Nn as TenantOpenZone,
4171
+ gn as TenantProvider,
4172
+ kn as TenantRoute,
4173
+ Wn as TenantSelector,
4174
+ xn as TenantZone,
4175
+ gt as UserApiService,
4176
+ se as UserType,
4177
+ Ln as UserZone,
4178
+ ae as ZoneRoute,
4179
+ Jn as buildRedirectUrl,
4180
+ hn as useApi,
4181
+ ye as useApp,
4182
+ _n as useAppLoaderState,
4183
+ le as useAuth,
4184
+ Tt as useFeatureFlags,
4185
+ Sn as useRouting,
4186
+ xt as useRoutingOptional,
4187
+ fn as useSettings,
4188
+ At as useSubscription,
4189
+ he as useTenant,
4190
+ ge as useTenantInfo,
4191
+ Se as useTenantOptional,
4192
+ pn as useTenantSettings,
4193
+ Kn as useZoneNavigation
3923
4194
  };
3924
4195
  //# sourceMappingURL=index.es.js.map