@skylabs-digital/react-identity-access 1.6.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as n, Fragment as D, jsxs as l } from "react/jsx-runtime";
2
- import { createContext as ae, useState as p, useMemo as _, useCallback as oe, useEffect as Z, useContext as le } from "react";
3
- import { useLocation as he, Navigate as de } from "react-router-dom";
4
- class te {
1
+ import { jsx as n, Fragment as N, jsxs as l } from "react/jsx-runtime";
2
+ import { createContext as de, useMemo as Q, useState as v, useCallback as ne, useEffect as te, useContext as ue } from "react";
3
+ import { useLocation as we, Navigate as pe } from "react-router-dom";
4
+ class re {
5
5
  // SessionManager instance
6
6
  constructor(e, t = 1e4) {
7
7
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
@@ -15,41 +15,41 @@ class te {
15
15
  async request(e, t, r, s) {
16
16
  return this.executeRequest(e, t, r, s, !1);
17
17
  }
18
- async executeRequest(e, t, r, s, a = !1) {
19
- const b = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, E = (s == null ? void 0 : s.timeout) || this.timeout;
20
- let L = {
18
+ async executeRequest(e, t, r, s, o = !1) {
19
+ const p = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, I = (s == null ? void 0 : s.timeout) || this.timeout;
20
+ let A = {
21
21
  "Content-Type": "application/json",
22
22
  ...s == null ? void 0 : s.headers
23
23
  };
24
24
  if (!(s != null && s.skipAuth) && this.sessionManager)
25
25
  try {
26
- const m = await this.sessionManager.getAuthHeaders();
27
- L = { ...L, ...m };
28
- } catch (m) {
29
- console.warn("Failed to inject auth headers:", m);
26
+ const b = await this.sessionManager.getAuthHeaders();
27
+ A = { ...A, ...b };
28
+ } catch (b) {
29
+ console.warn("Failed to inject auth headers:", b);
30
30
  }
31
- const P = new AbortController(), f = setTimeout(() => P.abort(), E);
31
+ const x = new AbortController(), T = setTimeout(() => x.abort(), I);
32
32
  try {
33
- const m = await fetch(b, {
33
+ const b = await fetch(p, {
34
34
  method: e,
35
- headers: L,
35
+ headers: A,
36
36
  body: r ? JSON.stringify(r) : void 0,
37
- signal: P.signal
37
+ signal: x.signal
38
38
  });
39
- if (clearTimeout(f), m.status === 401 && !(s != null && s.skipRetry) && !a && this.sessionManager)
39
+ if (clearTimeout(T), b.status === 401 && !(s != null && s.skipRetry) && !o && this.sessionManager)
40
40
  try {
41
- const w = this.sessionManager.getTokens();
42
- if (w != null && w.refreshToken)
41
+ const h = this.sessionManager.getTokens();
42
+ if (h != null && h.refreshToken)
43
43
  return await this.sessionManager.getAuthHeaders(), this.executeRequest(e, t, r, s, !0);
44
44
  } catch {
45
- throw new Error(`HTTP ${m.status}: ${m.statusText}`);
45
+ throw new Error(`HTTP ${b.status}: ${b.statusText}`);
46
46
  }
47
- if (!m.ok)
48
- throw new Error(`HTTP ${m.status}: ${m.statusText}`);
49
- const M = m.headers.get("content-type");
50
- return !M || !M.includes("application/json") ? {} : await m.json();
51
- } catch (m) {
52
- throw clearTimeout(f), m instanceof Error && m.name === "AbortError" ? new Error(`Request timeout after ${E}ms`) : m;
47
+ if (!b.ok)
48
+ throw new Error(`HTTP ${b.status}: ${b.statusText}`);
49
+ const f = b.headers.get("content-type");
50
+ return !f || !f.includes("application/json") ? {} : await b.json();
51
+ } catch (b) {
52
+ throw clearTimeout(T), b instanceof Error && b.name === "AbortError" ? new Error(`Request timeout after ${I}ms`) : b;
53
53
  }
54
54
  }
55
55
  async get(e, t) {
@@ -65,7 +65,7 @@ class te {
65
65
  return this.request("DELETE", e, void 0, t);
66
66
  }
67
67
  }
68
- class Te {
68
+ class be {
69
69
  constructor(e, t) {
70
70
  this.httpService = e, this.sessionManager = t;
71
71
  }
@@ -78,12 +78,12 @@ class Te {
78
78
  async getApps(e) {
79
79
  const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
80
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()}` : ""}`, a = await this.httpService.get(s, {
81
+ const s = `/apps/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
82
82
  headers: t
83
83
  });
84
84
  return {
85
- apps: a.data,
86
- meta: a.meta
85
+ apps: o.data,
86
+ meta: o.meta
87
87
  };
88
88
  }
89
89
  async getAppById(e) {
@@ -124,7 +124,7 @@ class Te {
124
124
  })).data;
125
125
  }
126
126
  }
127
- const we = ae(null), Me = () => /* @__PURE__ */ n(
127
+ const Ae = de(null), De = () => /* @__PURE__ */ n(
128
128
  "div",
129
129
  {
130
130
  style: {
@@ -136,7 +136,7 @@ const we = ae(null), Me = () => /* @__PURE__ */ n(
136
136
  },
137
137
  children: /* @__PURE__ */ n("div", { children: "Loading application..." })
138
138
  }
139
- ), Ee = ({ error: i, retry: e }) => /* @__PURE__ */ l(
139
+ ), He = ({ error: i, retry: e }) => /* @__PURE__ */ l(
140
140
  "div",
141
141
  {
142
142
  style: {
@@ -170,55 +170,113 @@ const we = ae(null), Me = () => /* @__PURE__ */ n(
170
170
  ]
171
171
  }
172
172
  );
173
- function ht({ config: i, children: e }) {
174
- const [t, r] = p(null), [s, a] = p(!0), [b, E] = p(null), L = _(() => {
173
+ function St({ config: i, children: e }) {
174
+ const t = Q(
175
+ () => {
176
+ var f, h, S;
177
+ return {
178
+ enabled: ((f = i.cache) == null ? void 0 : f.enabled) ?? !0,
179
+ ttl: ((h = i.cache) == null ? void 0 : h.ttl) ?? 3e5,
180
+ // 5 minutes default
181
+ storageKey: ((S = i.cache) == null ? void 0 : S.storageKey) ?? `app_cache_${i.appId}`
182
+ };
183
+ },
184
+ [i.cache, i.appId]
185
+ ), [r, s] = v(() => {
186
+ if (!t.enabled) return null;
187
+ try {
188
+ const f = localStorage.getItem(t.storageKey);
189
+ if (!f) return null;
190
+ const h = JSON.parse(f);
191
+ return Date.now() - h.timestamp < t.ttl && h.appId === i.appId ? h.data : (localStorage.removeItem(t.storageKey), null);
192
+ } catch {
193
+ return null;
194
+ }
195
+ }), [o, p] = v(!r), [I, A] = v(null), x = Q(() => {
175
196
  const f = () => {
176
- P();
197
+ T();
177
198
  };
178
199
  return {
179
200
  appId: i.appId,
180
201
  baseUrl: i.baseUrl,
181
202
  // App info
182
- appInfo: t,
183
- isAppLoading: s,
184
- appError: b,
203
+ appInfo: r,
204
+ isAppLoading: o,
205
+ appError: I,
185
206
  retryApp: f
186
207
  };
187
- }, [i, t, s, b]), P = oe(async () => {
188
- try {
189
- a(!0), E(null);
190
- const f = new te(i.baseUrl), M = await new Te(f, {}).getPublicAppInfo(i.appId);
191
- r(M);
192
- } catch (f) {
193
- const m = f instanceof Error ? f : new Error("Failed to load app information");
194
- E(m), r(null);
195
- } finally {
196
- a(!1);
197
- }
198
- }, [i.baseUrl, i.appId]);
199
- if (Z(() => {
200
- P();
201
- }, [P]), s)
202
- return /* @__PURE__ */ n(D, { children: i.loadingFallback || /* @__PURE__ */ n(Me, {}) });
203
- if (b) {
204
- const f = typeof i.errorFallback == "function" ? i.errorFallback(b, () => P()) : i.errorFallback || /* @__PURE__ */ n(Ee, { error: b, retry: () => P() });
205
- return /* @__PURE__ */ n(D, { children: f });
206
- }
207
- return /* @__PURE__ */ n(we.Provider, { value: L, children: e });
208
+ }, [i, r, o, I]), T = ne(
209
+ async (f = !1) => {
210
+ if (!(!f && t.enabled && r))
211
+ try {
212
+ p(!0), A(null);
213
+ const h = new re(i.baseUrl), L = await new be(h, {}).getPublicAppInfo(i.appId);
214
+ if (s(L), t.enabled)
215
+ try {
216
+ const R = {
217
+ data: L,
218
+ timestamp: Date.now(),
219
+ appId: i.appId
220
+ };
221
+ localStorage.setItem(t.storageKey, JSON.stringify(R));
222
+ } catch (R) {
223
+ console.warn("Failed to cache app info:", R);
224
+ }
225
+ } catch (h) {
226
+ const S = h instanceof Error ? h : new Error("Failed to load app information");
227
+ A(S), s(null);
228
+ } finally {
229
+ p(!1);
230
+ }
231
+ },
232
+ [i.baseUrl, i.appId, t, r]
233
+ ), b = ne(async () => {
234
+ if (!(!t.enabled || !r))
235
+ try {
236
+ const f = localStorage.getItem(t.storageKey);
237
+ if (!f) return;
238
+ const h = JSON.parse(f);
239
+ if (Date.now() - h.timestamp > t.ttl * 0.5) {
240
+ const L = new re(i.baseUrl), q = await new be(L, {}).getPublicAppInfo(i.appId);
241
+ s(q);
242
+ const k = {
243
+ data: q,
244
+ timestamp: Date.now(),
245
+ appId: i.appId
246
+ };
247
+ localStorage.setItem(t.storageKey, JSON.stringify(k));
248
+ }
249
+ } catch (f) {
250
+ console.warn("Background app refresh failed:", f);
251
+ }
252
+ }, [i, t, r]);
253
+ if (te(() => {
254
+ r ? b() : T();
255
+ }, []), o)
256
+ return /* @__PURE__ */ n(N, { children: i.loadingFallback || /* @__PURE__ */ n(De, {}) });
257
+ if (I) {
258
+ const f = typeof i.errorFallback == "function" ? i.errorFallback(I, () => T()) : i.errorFallback || /* @__PURE__ */ n(He, { error: I, retry: () => T() });
259
+ return /* @__PURE__ */ n(N, { children: f });
260
+ }
261
+ return /* @__PURE__ */ n(Ae.Provider, { value: x, children: e });
208
262
  }
209
- function ne() {
210
- const i = le(we);
263
+ function he() {
264
+ const i = ue(Ae);
211
265
  if (!i)
212
266
  throw new Error("useApp must be used within an AppProvider");
213
267
  return i;
214
268
  }
215
- const gt = ne;
216
- class Le {
269
+ const vt = he;
270
+ class ye {
217
271
  constructor(e = {}) {
218
- this.refreshPromise = null, this.refreshQueue = [], 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 || {
272
+ 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);
273
+ }
274
+ // Helper to create a TokenStorage for a specific key
275
+ createTokenStorage(e) {
276
+ return {
219
277
  get: () => {
220
278
  try {
221
- const t = localStorage.getItem(this.storageKey);
279
+ const t = localStorage.getItem(e);
222
280
  return t ? JSON.parse(t) : null;
223
281
  } catch {
224
282
  return null;
@@ -226,13 +284,13 @@ class Le {
226
284
  },
227
285
  set: (t) => {
228
286
  try {
229
- localStorage.setItem(this.storageKey, JSON.stringify(t));
287
+ localStorage.setItem(e, JSON.stringify(t));
230
288
  } catch {
231
289
  }
232
290
  },
233
291
  clear: () => {
234
292
  try {
235
- localStorage.removeItem(this.storageKey);
293
+ localStorage.removeItem(e);
236
294
  } catch {
237
295
  }
238
296
  }
@@ -246,7 +304,14 @@ class Le {
246
304
  this.tokenStorage.set(t);
247
305
  }
248
306
  getTokens() {
249
- return this.tokenStorage.get();
307
+ const { accessToken: e, refreshToken: t, expiresAt: r, expiresIn: s, tokenType: o } = this.tokenStorage.get() || {};
308
+ return e ? {
309
+ accessToken: e,
310
+ refreshToken: t,
311
+ expiresAt: r,
312
+ expiresIn: s,
313
+ tokenType: o
314
+ } : null;
250
315
  }
251
316
  clearTokens() {
252
317
  this.tokenStorage.clear();
@@ -325,19 +390,43 @@ class Le {
325
390
  clearSession() {
326
391
  this.clearTokens(), this.clearUser();
327
392
  }
393
+ /**
394
+ * Decode JWT token and extract payload
395
+ * Returns null if token is invalid or cannot be decoded
396
+ */
397
+ getTokenPayload() {
398
+ try {
399
+ const e = this.getTokens();
400
+ if (!(e != null && e.accessToken)) return null;
401
+ const t = e.accessToken.split(".");
402
+ if (t.length !== 3) return null;
403
+ const r = t[1], s = atob(r.replace(/-/g, "+").replace(/_/g, "/"));
404
+ return JSON.parse(s);
405
+ } catch {
406
+ return null;
407
+ }
408
+ }
409
+ /**
410
+ * Get userId from token (source of truth) or fallback to stored user
411
+ */
412
+ getUserId() {
413
+ const e = this.getTokenPayload();
414
+ if (e != null && e.userId) return e.userId;
415
+ const t = this.getUser();
416
+ return (t == null ? void 0 : t.id) || null;
417
+ }
328
418
  hasValidSession() {
329
419
  const e = this.getTokens();
330
420
  return e !== null && !this.isTokenExpired(e);
331
421
  }
332
422
  }
333
- class Re {
423
+ class Ne {
334
424
  constructor(e) {
335
425
  this.httpService = e;
336
426
  }
337
427
  // Public endpoints - no auth required
338
428
  async login(e) {
339
- const t = await this.httpService.post("/auth/login", e);
340
- return console.log(t), t;
429
+ return await this.httpService.post("/auth/login", e);
341
430
  }
342
431
  async signup(e) {
343
432
  return await this.httpService.post("/auth/signup", e);
@@ -376,7 +465,7 @@ class Re {
376
465
  });
377
466
  }
378
467
  }
379
- class pe {
468
+ class Se {
380
469
  constructor(e, t) {
381
470
  this.httpService = e, this.sessionManager = t;
382
471
  }
@@ -416,10 +505,10 @@ class pe {
416
505
  async getRolesByApp(e, t) {
417
506
  const r = new URLSearchParams();
418
507
  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);
419
- const s = `/roles/app/${e}${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s);
508
+ const s = `/roles/app/${e}${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s);
420
509
  return {
421
- roles: a.data,
422
- meta: a.meta
510
+ roles: o.data,
511
+ meta: o.meta
423
512
  };
424
513
  }
425
514
  async assignRole(e, t) {
@@ -443,16 +532,16 @@ class pe {
443
532
  throw new Error("SessionManager is required for private endpoints");
444
533
  const r = await this.sessionManager.getAuthHeaders(), s = new URLSearchParams();
445
534
  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);
446
- const a = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, b = await this.httpService.get(a, {
535
+ const o = `/roles/user/${e}${s.toString() ? `?${s.toString()}` : ""}`, p = await this.httpService.get(o, {
447
536
  headers: r
448
537
  });
449
538
  return {
450
- roles: b.data,
451
- meta: b.meta
539
+ roles: p.data,
540
+ meta: p.meta
452
541
  };
453
542
  }
454
543
  }
455
- class Ce {
544
+ class Be {
456
545
  constructor(e, t) {
457
546
  this.httpService = e, this.sessionManager = t;
458
547
  }
@@ -465,12 +554,12 @@ class Ce {
465
554
  async getUsers(e) {
466
555
  const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
467
556
  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);
468
- const s = `/users/${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s, {
557
+ const s = `/users/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
469
558
  headers: t
470
559
  });
471
560
  return {
472
- users: a.data,
473
- meta: a.meta
561
+ users: o.data,
562
+ meta: o.meta
474
563
  };
475
564
  }
476
565
  async getUserById(e) {
@@ -492,7 +581,7 @@ class Ce {
492
581
  });
493
582
  }
494
583
  }
495
- class fe {
584
+ class ce {
496
585
  constructor(e, t, r) {
497
586
  this.httpService = e, this.appId = t, this.sessionManager = r;
498
587
  }
@@ -509,12 +598,12 @@ class fe {
509
598
  throw new Error("SessionManager is required for private endpoints");
510
599
  const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
511
600
  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);
512
- const s = `/tenants/${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s, {
601
+ const s = `/tenants/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
513
602
  headers: t
514
603
  });
515
604
  return {
516
- tenants: a.data,
517
- meta: a.meta
605
+ tenants: o.data,
606
+ meta: o.meta
518
607
  };
519
608
  }
520
609
  async getTenantById(e) {
@@ -570,7 +659,7 @@ class fe {
570
659
  )).data;
571
660
  }
572
661
  }
573
- const ve = ae(null), Ie = () => /* @__PURE__ */ n(
662
+ const Te = de(null), Ue = () => /* @__PURE__ */ n(
574
663
  "div",
575
664
  {
576
665
  style: {
@@ -582,7 +671,7 @@ const ve = ae(null), Ie = () => /* @__PURE__ */ n(
582
671
  },
583
672
  children: /* @__PURE__ */ n("div", { children: "Loading tenant..." })
584
673
  }
585
- ), Fe = ({ error: i, retry: e }) => /* @__PURE__ */ l(
674
+ ), qe = ({ error: i, retry: e }) => /* @__PURE__ */ l(
586
675
  "div",
587
676
  {
588
677
  style: {
@@ -616,77 +705,134 @@ const ve = ae(null), Ie = () => /* @__PURE__ */ n(
616
705
  ]
617
706
  }
618
707
  );
619
- function pt({ config: i, children: e }) {
620
- const { baseUrl: t, appInfo: r, appId: s } = ne(), [a, b] = p(i.initialTenant || null), [E, L] = p(!i.initialTenant), [P, f] = p(null), [m, M] = p(null), [w, v] = p(!1), [I, g] = p(null), U = oe(() => {
621
- const S = i.tenantMode || "selector", c = "tenant";
708
+ function xt({ config: i, children: e }) {
709
+ const { baseUrl: t, appInfo: r, appId: s } = he(), o = ne(() => {
710
+ const a = i.tenantMode || "selector", g = "tenant";
622
711
  if (typeof window > "u") return null;
623
- if (S === "subdomain") {
624
- const o = window.location.hostname.split(".");
625
- if (o.length >= 3) {
626
- const d = o[0];
627
- return localStorage.setItem(c, d), d;
712
+ if (a === "subdomain") {
713
+ const c = window.location.hostname.split(".");
714
+ if (c.length >= 3) {
715
+ const d = c[0];
716
+ return localStorage.setItem(g, d), d;
628
717
  }
629
- return localStorage.getItem(c);
630
- } else if (S === "selector") {
631
- const o = new URLSearchParams(window.location.search).get(i.selectorParam || "tenant");
632
- return o ? (localStorage.setItem(c, o), o) : localStorage.getItem(c);
718
+ return localStorage.getItem(g);
719
+ } else if (a === "selector") {
720
+ const c = new URLSearchParams(window.location.search).get(i.selectorParam || "tenant");
721
+ return c ? (localStorage.setItem(g, c), c) : localStorage.getItem(g);
633
722
  }
634
723
  return null;
635
- }, [i.tenantMode, i.selectorParam]), u = _(() => U(), [U]), y = (r == null ? void 0 : r.settingsSchema) || null, x = oe(
636
- async (S) => {
724
+ }, [i.tenantMode, i.selectorParam]), [p, I] = v(() => o()), A = Q(
725
+ () => {
726
+ var a, g, m;
727
+ return {
728
+ enabled: ((a = i.cache) == null ? void 0 : a.enabled) ?? !0,
729
+ ttl: ((g = i.cache) == null ? void 0 : g.ttl) ?? 5 * 60 * 1e3,
730
+ // 5 minutes default
731
+ storageKey: ((m = i.cache) == null ? void 0 : m.storageKey) ?? `tenant_cache_${p || "default"}`
732
+ };
733
+ },
734
+ [i.cache, p]
735
+ ), [x, T] = v(() => {
736
+ if (i.initialTenant) return i.initialTenant;
737
+ if (!A.enabled || !p) return null;
738
+ try {
739
+ const a = localStorage.getItem(A.storageKey);
740
+ if (!a) return null;
741
+ const g = JSON.parse(a);
742
+ return Date.now() - g.timestamp < A.ttl && g.tenantSlug === p ? g.data : (localStorage.removeItem(A.storageKey), null);
743
+ } catch {
744
+ return null;
745
+ }
746
+ }), [b, f] = v(!x && !i.initialTenant), [h, S] = v(null), [L, R] = v(null), [q, k] = v(!1), [u, P] = v(null);
747
+ te(() => {
748
+ const a = o();
749
+ I(a);
750
+ }, [o]);
751
+ const C = (r == null ? void 0 : r.settingsSchema) || null, H = ne(
752
+ async (a, g = !1) => {
753
+ if (!(!g && A.enabled && x && x.domain === a))
754
+ try {
755
+ f(!0), S(null);
756
+ const m = new re(t), d = await new ce(m, s).getPublicTenantInfo(a);
757
+ if (T(d), A.enabled)
758
+ try {
759
+ const y = {
760
+ data: d,
761
+ timestamp: Date.now(),
762
+ tenantSlug: a
763
+ };
764
+ localStorage.setItem(A.storageKey, JSON.stringify(y));
765
+ } catch (y) {
766
+ console.warn("Failed to cache tenant info:", y);
767
+ }
768
+ } catch (m) {
769
+ const c = m instanceof Error ? m : new Error("Failed to load tenant information");
770
+ S(c), T(null);
771
+ } finally {
772
+ f(!1);
773
+ }
774
+ },
775
+ [t, s, A, x]
776
+ ), W = ne(async () => {
777
+ if (!(!A.enabled || !x || !p))
637
778
  try {
638
- L(!0), f(null);
639
- const c = new te(t), o = await new fe(c, s).getPublicTenantInfo(S);
640
- b(o);
641
- } catch (c) {
642
- const h = c instanceof Error ? c : new Error("Failed to load tenant information");
643
- f(h), b(null);
644
- } finally {
645
- L(!1);
779
+ const a = localStorage.getItem(A.storageKey);
780
+ if (!a) return;
781
+ const g = JSON.parse(a);
782
+ if (Date.now() - g.timestamp > A.ttl * 0.5) {
783
+ const c = new re(t), y = await new ce(c, s).getPublicTenantInfo(p);
784
+ T(y);
785
+ const G = {
786
+ data: y,
787
+ timestamp: Date.now(),
788
+ tenantSlug: p
789
+ };
790
+ localStorage.setItem(A.storageKey, JSON.stringify(G));
791
+ }
792
+ } catch (a) {
793
+ console.warn("Background tenant refresh failed:", a);
646
794
  }
647
- },
648
- [t, s]
649
- ), F = oe(async () => {
650
- if (a != null && a.id)
795
+ }, [t, s, A, x, p]), F = ne(async () => {
796
+ if (x != null && x.id)
651
797
  try {
652
- v(!0), g(null);
653
- const S = new te(t), h = await new fe(S, a.appId).getTenantSettings(a.id);
654
- M(h);
655
- } catch (S) {
656
- const c = S instanceof Error ? S : new Error("Failed to load tenant settings");
657
- g(c), M(null);
798
+ k(!0), P(null);
799
+ const a = new re(t), m = await new ce(a, x.appId).getTenantSettings(x.id);
800
+ R(m);
801
+ } catch (a) {
802
+ const g = a instanceof Error ? a : new Error("Failed to load tenant settings");
803
+ P(g), R(null);
658
804
  } finally {
659
- v(!1);
805
+ k(!1);
660
806
  }
661
- }, [t, a]), B = oe(() => {
807
+ }, [t, x]), V = ne(() => {
662
808
  F();
663
- }, [F]), z = oe(
664
- (S) => {
665
- if (!y)
809
+ }, [F]), w = ne(
810
+ (a) => {
811
+ if (!C)
666
812
  return { isValid: !0, errors: [] };
667
- const c = [];
813
+ const g = [];
668
814
  try {
669
- return y.properties && Object.entries(y.properties).forEach(([h, o]) => {
670
- var G;
671
- const d = S[h];
672
- if ((G = y.required) != null && G.includes(h) && d == null) {
673
- c.push(`Field '${h}' is required`);
815
+ return C.properties && Object.entries(C.properties).forEach(([m, c]) => {
816
+ var y;
817
+ const d = a[m];
818
+ if ((y = C.required) != null && y.includes(m) && d == null) {
819
+ g.push(`Field '${m}' is required`);
674
820
  return;
675
821
  }
676
822
  if (d != null) {
677
- if (o.type) {
678
- const Y = o.type, H = typeof d;
679
- Y === "string" && H !== "string" ? c.push(`Field '${h}' must be a string`) : (Y === "number" || Y === "integer") && H !== "number" ? c.push(`Field '${h}' must be a number`) : Y === "boolean" && H !== "boolean" ? c.push(`Field '${h}' must be a boolean`) : Y === "array" && !Array.isArray(d) && c.push(`Field '${h}' must be an array`);
823
+ if (c.type) {
824
+ const G = c.type, ee = typeof d;
825
+ G === "string" && ee !== "string" ? g.push(`Field '${m}' must be a string`) : (G === "number" || G === "integer") && ee !== "number" ? g.push(`Field '${m}' must be a number`) : G === "boolean" && ee !== "boolean" ? g.push(`Field '${m}' must be a boolean`) : G === "array" && !Array.isArray(d) && g.push(`Field '${m}' must be an array`);
680
826
  }
681
- o.minLength !== void 0 && typeof d == "string" && d.length < o.minLength && c.push(
682
- `Field '${h}' must be at least ${o.minLength} characters long`
683
- ), o.maxLength !== void 0 && typeof d == "string" && d.length > o.maxLength && c.push(
684
- `Field '${h}' must be no more than ${o.maxLength} characters long`
685
- ), o.minimum !== void 0 && typeof d == "number" && d < o.minimum && c.push(`Field '${h}' must be at least ${o.minimum}`), o.maximum !== void 0 && typeof d == "number" && d > o.maximum && c.push(`Field '${h}' must be no more than ${o.maximum}`), o.pattern && typeof d == "string" && (new RegExp(o.pattern).test(d) || c.push(`Field '${h}' does not match the required pattern`)), o.enum && !o.enum.includes(d) && c.push(`Field '${h}' must be one of: ${o.enum.join(", ")}`);
827
+ c.minLength !== void 0 && typeof d == "string" && d.length < c.minLength && g.push(
828
+ `Field '${m}' must be at least ${c.minLength} characters long`
829
+ ), c.maxLength !== void 0 && typeof d == "string" && d.length > c.maxLength && g.push(
830
+ `Field '${m}' must be no more than ${c.maxLength} characters long`
831
+ ), c.minimum !== void 0 && typeof d == "number" && d < c.minimum && g.push(`Field '${m}' must be at least ${c.minimum}`), c.maximum !== void 0 && typeof d == "number" && d > c.maximum && g.push(`Field '${m}' must be no more than ${c.maximum}`), c.pattern && typeof d == "string" && (new RegExp(c.pattern).test(d) || g.push(`Field '${m}' does not match the required pattern`)), c.enum && !c.enum.includes(d) && g.push(`Field '${m}' must be one of: ${c.enum.join(", ")}`);
686
832
  }
687
833
  }), {
688
- isValid: c.length === 0,
689
- errors: c
834
+ isValid: g.length === 0,
835
+ errors: g
690
836
  };
691
837
  } catch {
692
838
  return {
@@ -695,60 +841,88 @@ function pt({ config: i, children: e }) {
695
841
  };
696
842
  }
697
843
  },
698
- [y]
844
+ [C]
699
845
  );
700
- Z(() => {
701
- !i.initialTenant && u ? x(u) : !i.initialTenant && !u && (b(null), f(null), L(!1));
702
- }, [i.initialTenant, u, x]), Z(() => {
703
- a != null && a.id ? F() : (M(null), g(null), v(!1));
704
- }, [a == null ? void 0 : a.id, F]);
705
- const q = _(() => ({
846
+ te(() => {
847
+ !i.initialTenant && p ? x ? W() : H(p) : !i.initialTenant && !p && (T(null), S(null), f(!1));
848
+ }, [i.initialTenant, p, x, H, W]), te(() => {
849
+ x != null && x.id ? F() : (R(null), P(null), k(!1));
850
+ }, [x == null ? void 0 : x.id, F]);
851
+ const M = ne(
852
+ (a, g = "reload") => {
853
+ const m = i.tenantMode || "selector";
854
+ if (localStorage.setItem("tenant", a), m === "subdomain") {
855
+ const c = window.location.hostname, d = c.split(".");
856
+ if (d.length >= 2) {
857
+ d[0] = a;
858
+ const y = d.join("."), G = `${window.location.protocol}//${y}${window.location.pathname}${window.location.search}`;
859
+ window.location.href = G;
860
+ } else
861
+ console.warn(
862
+ "[TenantProvider] Cannot switch subdomain, invalid hostname:",
863
+ c
864
+ );
865
+ } else if (m === "selector") {
866
+ const c = new URLSearchParams(window.location.search);
867
+ if (c.set(i.selectorParam || "tenant", a), g === "reload") {
868
+ const d = `${window.location.pathname}?${c.toString()}${window.location.hash}`;
869
+ window.location.href = d;
870
+ } else {
871
+ const d = `${window.location.pathname}?${c.toString()}${window.location.hash}`;
872
+ window.history.pushState({}, "", d), I(a), H(a);
873
+ }
874
+ }
875
+ },
876
+ [i.tenantMode, i.selectorParam, H, p]
877
+ ), E = Q(() => ({
706
878
  // Tenant info
707
- tenant: a,
708
- tenantSlug: u,
709
- isTenantLoading: E,
710
- tenantError: P,
879
+ tenant: x,
880
+ tenantSlug: p,
881
+ isTenantLoading: b,
882
+ tenantError: h,
711
883
  retryTenant: () => {
712
- u && x(u);
884
+ p && H(p);
713
885
  },
714
886
  // Settings
715
- settings: m,
716
- settingsSchema: y,
717
- isSettingsLoading: w,
718
- settingsError: I,
887
+ settings: L,
888
+ settingsSchema: C,
889
+ isSettingsLoading: q,
890
+ settingsError: u,
719
891
  // Actions
720
- refreshSettings: B,
892
+ refreshSettings: V,
893
+ switchTenant: M,
721
894
  // Validation
722
- validateSettings: z
895
+ validateSettings: w
723
896
  }), [
724
- a,
897
+ x,
898
+ p,
899
+ b,
900
+ h,
901
+ L,
902
+ C,
903
+ q,
725
904
  u,
726
- E,
727
- P,
728
- m,
729
- y,
730
- w,
731
- I,
732
- B,
733
- z
905
+ V,
906
+ M,
907
+ w
734
908
  ]);
735
- if (E)
736
- return /* @__PURE__ */ n(D, { children: i.loadingFallback || /* @__PURE__ */ n(Ie, {}) });
737
- if (P) {
738
- const S = typeof i.errorFallback == "function" ? i.errorFallback(P, () => x(u || "")) : i.errorFallback || /* @__PURE__ */ n(Fe, { error: P, retry: () => x(u || "") });
739
- return /* @__PURE__ */ n(D, { children: S });
909
+ if (b)
910
+ return /* @__PURE__ */ n(N, { children: i.loadingFallback || /* @__PURE__ */ n(Ue, {}) });
911
+ if (h) {
912
+ const a = typeof i.errorFallback == "function" ? i.errorFallback(h, () => H(p || "")) : i.errorFallback || /* @__PURE__ */ n(qe, { error: h, retry: () => H(p || "") });
913
+ return /* @__PURE__ */ n(N, { children: a });
740
914
  }
741
- return /* @__PURE__ */ n(ve.Provider, { value: q, children: e });
915
+ return /* @__PURE__ */ n(Te.Provider, { value: E, children: e });
742
916
  }
743
- function ge() {
744
- const i = le(ve);
917
+ function fe() {
918
+ const i = ue(Te);
745
919
  if (!i)
746
920
  throw new Error("useTenant must be used within a TenantProvider");
747
921
  return i;
748
922
  }
749
- const ft = ge;
750
- function mt() {
751
- const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = ge();
923
+ const kt = fe;
924
+ function At() {
925
+ const { settings: i, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: s } = fe();
752
926
  return {
753
927
  settings: i,
754
928
  settingsSchema: e,
@@ -757,8 +931,8 @@ function mt() {
757
931
  validateSettings: s
758
932
  };
759
933
  }
760
- function re() {
761
- const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = ge();
934
+ function se() {
935
+ const { tenant: i, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: s } = fe();
762
936
  return {
763
937
  tenant: i,
764
938
  tenantSlug: e,
@@ -767,249 +941,273 @@ function re() {
767
941
  retry: s
768
942
  };
769
943
  }
770
- const Se = ae(null);
771
- function yt({ config: i = {}, children: e }) {
772
- const { appId: t, baseUrl: r } = ne(), s = re(), a = (s == null ? void 0 : s.tenantSlug) || null, [b, E] = p(i.initialRoles || []), [L, P] = p(!i.initialRoles), [f, m] = p(null), [M, w] = p(!1), [v, I] = p(null), g = _(() => {
773
- const S = a ? `auth_tokens_${a}` : "auth_tokens", c = {
774
- get: () => {
775
- try {
776
- const h = localStorage.getItem(S);
777
- return h ? JSON.parse(h) : null;
778
- } catch {
779
- return null;
780
- }
781
- },
782
- set: (h) => {
783
- try {
784
- localStorage.setItem(S, JSON.stringify(h));
785
- } catch {
786
- }
787
- },
788
- clear: () => {
789
- try {
790
- localStorage.removeItem(S);
791
- } catch {
792
- }
793
- }
794
- };
795
- return new Le({
796
- onRefreshFailed: i.onRefreshFailed,
797
- tokenStorage: c,
798
- baseUrl: r
799
- });
800
- }, [a, r, i.onRefreshFailed]), U = _(() => {
801
- const S = new te(r);
802
- return S.setSessionManager(g), S;
803
- }, [r, g]), u = _(() => new Re(new te(r)), [r]), y = _(() => new Ce(U, g), [U, g]), x = _(() => new pe(new te(r)), [r]), F = _(() => f || g.getUser(), [f, g]), B = _(() => F != null && F.roleId && b.find((S) => S.id === F.roleId) || null, [F, b]), z = _(() => (B == null ? void 0 : B.permissions) || [], [B]);
804
- Z(() => {
805
- console.log("AuthProvider - userPermissions changed:", z);
806
- }, [z]);
807
- const q = _(() => {
808
- const S = async () => {
944
+ const Pe = de(null);
945
+ function Tt({ config: i = {}, children: e }) {
946
+ const { appId: t, baseUrl: r } = he(), { tenant: s, tenantSlug: o, switchTenant: p } = fe(), [I, A] = v(i.initialRoles || []), [x, T] = v(!i.initialRoles), [b, f] = v(null), [h, S] = v(!1), [L, R] = v(null), [q, k] = v(0), u = Q(() => new ye({
947
+ tenantSlug: o,
948
+ // SessionManager will generate storageKey internally
949
+ onRefreshFailed: i.onRefreshFailed,
950
+ baseUrl: r
951
+ }), [o, r, i.onRefreshFailed]), P = Q(() => {
952
+ const g = new re(r);
953
+ return g.setSessionManager(u), g;
954
+ }, [r, u]), C = Q(() => new Ne(new re(r)), [r]), H = Q(() => new Be(P, u), [P, u]), W = Q(() => new Se(new re(r)), [r]), F = Q(() => b || u.getUser(), [b, u]), V = Q(() => F != null && F.roleId && I.find((g) => g.id === F.roleId) || null, [F, I]), w = Q(() => (V == null ? void 0 : V.permissions) || [], [V]), M = Q(() => u.hasValidSession() && b !== null, [u, b]), E = 5 * 60 * 1e3, a = Q(() => {
955
+ const g = async ($ = !1) => {
809
956
  try {
810
- w(!0), I(null);
811
- const A = g.getUser();
812
- if (!(A != null && A.id))
813
- throw new Error("No user ID available in session");
814
- const $ = await y.getUserById(A.id);
815
- m($), g.setUser($);
816
- } catch (A) {
817
- const $ = A instanceof Error ? A : new Error("Failed to load user data");
818
- I($), console.error("Failed to load user data:", $);
957
+ if (!u.hasValidSession())
958
+ return;
959
+ const U = Date.now();
960
+ if (!$ && U - q < E && b)
961
+ return;
962
+ const j = u.getUserId();
963
+ if (!j) {
964
+ console.warn("[AuthProvider] No userId available in token or storage");
965
+ return;
966
+ }
967
+ S(!0), R(null);
968
+ const X = await H.getUserById(j);
969
+ f(X), u.setUser(X), k(Date.now());
970
+ } catch (U) {
971
+ const K = U instanceof Error ? U : new Error("Failed to load user data");
972
+ R(K), console.error("[AuthProvider] Failed to load user data:", K);
819
973
  } finally {
820
- w(!1);
974
+ S(!1);
821
975
  }
822
- }, c = async () => {
823
- await S();
824
- }, h = async (A, $, Q, X) => {
825
- const W = await u.login({
826
- username: A,
827
- password: $,
828
- appId: Q,
976
+ }, m = async () => {
977
+ await g();
978
+ }, c = async ($) => {
979
+ const { username: U, password: K, tenantSlug: j } = $;
980
+ let X = s == null ? void 0 : s.id, Y = o, Z = u;
981
+ j && (X = (await new ce(P, t).getPublicTenantInfo(j)).id, Y = j);
982
+ const J = await C.login({
983
+ username: U,
984
+ password: K,
985
+ appId: t,
829
986
  tenantId: X
830
- });
831
- if (g.setTokens({
832
- accessToken: W.accessToken,
833
- refreshToken: W.refreshToken,
834
- expiresIn: W.expiresIn
835
- }), W.user) {
836
- g.setUser(W.user), m(W.user);
987
+ }), ae = j && j !== o;
988
+ if (ae && (Z = new ye({
989
+ tenantSlug: Y,
990
+ baseUrl: r
991
+ })), Z.setTokens({
992
+ accessToken: J.accessToken,
993
+ refreshToken: J.refreshToken,
994
+ expiresIn: J.expiresIn
995
+ }), J.user) {
996
+ Z.setUser(J.user), f(J.user);
837
997
  try {
838
- await S();
839
- } catch (ee) {
840
- console.warn("Failed to load complete user data after login:", ee);
998
+ await g();
999
+ } catch (le) {
1000
+ console.warn("Failed to load complete user data after login:", le);
841
1001
  }
842
1002
  }
843
- return W;
844
- }, o = async (A, $, Q, X, W, ee, ce) => {
845
- if (!A && !$)
1003
+ return ae && Y && Y !== o && p(Y), J;
1004
+ }, d = async ($) => {
1005
+ const { email: U, phoneNumber: K, name: j, password: X, lastName: Y, tenantId: Z } = $;
1006
+ if (!U && !K)
846
1007
  throw new Error("Either email or phoneNumber is required");
847
- if (!Q || !X)
1008
+ if (!j || !X)
848
1009
  throw new Error("Name and password are required");
849
- return await u.signup({
850
- email: A,
851
- phoneNumber: $,
852
- name: Q,
1010
+ const J = Z ?? (s == null ? void 0 : s.id);
1011
+ return await C.signup({
1012
+ email: U,
1013
+ phoneNumber: K,
1014
+ name: j,
853
1015
  password: X,
854
- tenantId: W,
855
- lastName: ee,
856
- appId: ce
1016
+ tenantId: J,
1017
+ lastName: Y,
1018
+ appId: t
857
1019
  });
858
- }, d = async (A, $, Q, X, W, ee, ce) => {
859
- if (!A && !$)
1020
+ }, y = async ($) => {
1021
+ const { email: U, phoneNumber: K, name: j, password: X, tenantName: Y, lastName: Z } = $;
1022
+ if (!U && !K)
860
1023
  throw new Error("Either email or phoneNumber is required");
861
- if (!Q || !X || !W)
1024
+ if (!j || !X || !Y)
862
1025
  throw new Error("Name, password, and tenantName are required");
863
- return await u.signupTenantAdmin({
864
- email: A,
865
- phoneNumber: $,
866
- name: Q,
1026
+ return await C.signupTenantAdmin({
1027
+ email: U,
1028
+ phoneNumber: K,
1029
+ name: j,
867
1030
  password: X,
868
- tenantName: W,
869
- appId: ce,
870
- lastName: ee
1031
+ tenantName: Y,
1032
+ appId: t,
1033
+ lastName: Z
871
1034
  });
872
- }, G = async (A, $) => {
873
- const Q = await g.getAuthHeaders();
874
- await u.changePassword({ currentPassword: A, newPassword: $ }, Q);
875
- }, Y = async (A, $) => {
876
- await u.requestPasswordReset({ email: A, tenantId: $ });
877
- }, H = async (A, $) => {
878
- await u.confirmPasswordReset({ token: A, newPassword: $ });
879
- }, C = async (A, $, Q, X, W, ee) => await u.sendMagicLink({
880
- email: A,
881
- tenantId: $,
882
- frontendUrl: Q,
883
- name: X,
884
- lastName: W,
885
- appId: ee
886
- }), k = async (A, $, Q, X) => {
887
- const W = await u.verifyMagicLink({
888
- token: A,
889
- email: $,
890
- appId: Q,
891
- tenantId: X
1035
+ }, G = async ($) => {
1036
+ const { currentPassword: U, newPassword: K } = $, j = await u.getAuthHeaders();
1037
+ await C.changePassword({ currentPassword: U, newPassword: K }, j);
1038
+ }, ee = async ($) => {
1039
+ const { email: U, tenantId: K } = $, j = K ?? (s == null ? void 0 : s.id);
1040
+ if (!j)
1041
+ throw new Error("tenantId is required for password reset");
1042
+ await C.requestPasswordReset({ email: U, tenantId: j });
1043
+ }, z = async ($) => {
1044
+ const { token: U, newPassword: K } = $;
1045
+ await C.confirmPasswordReset({ token: U, newPassword: K });
1046
+ }, B = async ($) => {
1047
+ const { email: U, frontendUrl: K, name: j, lastName: X, tenantId: Y } = $, Z = Y ?? (s == null ? void 0 : s.id);
1048
+ if (!Z)
1049
+ throw new Error("tenantId is required for magic link authentication");
1050
+ return await C.sendMagicLink({
1051
+ email: U,
1052
+ tenantId: Z,
1053
+ frontendUrl: K,
1054
+ name: j,
1055
+ lastName: X,
1056
+ appId: t
892
1057
  });
893
- if (g.setTokens({
894
- accessToken: W.accessToken,
895
- refreshToken: W.refreshToken,
896
- expiresIn: W.expiresIn
897
- }), W.user) {
898
- g.setUser(W.user), m(W.user);
1058
+ }, O = async ($) => {
1059
+ const { token: U, email: K, tenantSlug: j } = $;
1060
+ let X = s == null ? void 0 : s.id, Y = o, Z = u;
1061
+ j && (X = (await new ce(P, t).getPublicTenantInfo(j)).id, Y = j);
1062
+ const J = await C.verifyMagicLink({
1063
+ token: U,
1064
+ email: K,
1065
+ appId: t,
1066
+ tenantId: X
1067
+ }), ae = j && j !== o;
1068
+ if (ae && (Z = new ye({
1069
+ tenantSlug: Y,
1070
+ baseUrl: r
1071
+ })), Z.setTokens({
1072
+ accessToken: J.accessToken,
1073
+ refreshToken: J.refreshToken,
1074
+ expiresIn: J.expiresIn
1075
+ }), J.user) {
1076
+ Z.setUser(J.user), f(J.user);
899
1077
  try {
900
- await S();
901
- } catch (ee) {
902
- console.warn("Failed to load complete user data after magic link login:", ee);
1078
+ await g();
1079
+ } catch (le) {
1080
+ console.warn("Failed to load complete user data after magic link login:", le);
903
1081
  }
904
1082
  }
905
- return W;
906
- }, T = async () => {
907
- const A = g.getTokens();
908
- if (!(A != null && A.refreshToken))
1083
+ return ae && Y && Y !== o && p(Y), J;
1084
+ }, D = async () => {
1085
+ const $ = u.getTokens();
1086
+ if (!($ != null && $.refreshToken))
909
1087
  throw new Error("No refresh token available");
910
- const $ = await u.refreshToken({
911
- refreshToken: A.refreshToken
1088
+ const U = await C.refreshToken({
1089
+ refreshToken: $.refreshToken
912
1090
  });
913
- g.setTokens({
914
- accessToken: $.accessToken,
915
- refreshToken: $.refreshToken || A.refreshToken,
916
- expiresIn: $.expiresIn
1091
+ u.setTokens({
1092
+ accessToken: U.accessToken,
1093
+ refreshToken: U.refreshToken || $.refreshToken,
1094
+ expiresIn: U.expiresIn
917
1095
  });
918
- }, J = () => {
919
- g.clearSession(), m(null), I(null);
920
- }, O = (A) => {
921
- g.setTokens(A);
922
- }, j = () => g.hasValidSession(), N = () => {
923
- g.clearSession(), m(null), I(null);
924
- }, K = async () => {
1096
+ }, _ = () => {
1097
+ u.clearSession(), f(null), R(null);
1098
+ }, ge = ($) => {
1099
+ u.setTokens($);
1100
+ }, Ce = () => u.hasValidSession(), Re = () => {
1101
+ u.clearSession(), f(null), R(null);
1102
+ }, Le = async () => {
925
1103
  if (t)
926
1104
  try {
927
- P(!0);
928
- const { roles: A } = await x.getRolesByApp(t);
929
- E(A);
930
- } catch (A) {
931
- console.error("Failed to fetch roles:", A);
1105
+ T(!0);
1106
+ const { roles: $ } = await W.getRolesByApp(t);
1107
+ A($);
1108
+ } catch ($) {
1109
+ console.error("Failed to fetch roles:", $);
932
1110
  } finally {
933
- P(!1);
1111
+ T(!1);
934
1112
  }
935
- }, R = async () => {
936
- await K();
937
- }, V = (A) => {
938
- if (!z || z.length === 0)
1113
+ }, Fe = async () => {
1114
+ await Le();
1115
+ }, me = ($) => {
1116
+ if (!w || w.length === 0)
939
1117
  return !1;
940
- if (typeof A == "string")
941
- return z.includes(A);
942
- const $ = `${A.resource}.${A.action}`;
943
- return z.includes($);
1118
+ if (typeof $ == "string")
1119
+ return w.includes($);
1120
+ const U = `${$.resource}.${$.action}`;
1121
+ return w.includes(U);
944
1122
  };
945
1123
  return {
946
- sessionManager: g,
947
- authenticatedHttpService: U,
948
- login: h,
949
- signup: o,
950
- signupTenantAdmin: d,
951
- sendMagicLink: C,
952
- verifyMagicLink: k,
1124
+ // RFC-003: Authentication state
1125
+ isAuthenticated: M,
1126
+ sessionManager: u,
1127
+ authenticatedHttpService: P,
1128
+ login: c,
1129
+ signup: d,
1130
+ signupTenantAdmin: y,
1131
+ sendMagicLink: B,
1132
+ verifyMagicLink: O,
953
1133
  changePassword: G,
954
- requestPasswordReset: Y,
955
- confirmPasswordReset: H,
956
- refreshToken: T,
957
- logout: J,
958
- setTokens: O,
959
- hasValidSession: j,
960
- clearSession: N,
961
- currentUser: f,
962
- isUserLoading: M,
963
- userError: v,
964
- refreshUser: c,
965
- userRole: B,
966
- userPermissions: z,
967
- availableRoles: b,
968
- rolesLoading: L,
969
- hasPermission: V,
970
- hasAnyPermission: (A) => A.some(($) => V($)),
971
- hasAllPermissions: (A) => A.every(($) => V($)),
972
- getUserPermissionStrings: () => z || [],
973
- refreshRoles: R
1134
+ requestPasswordReset: ee,
1135
+ confirmPasswordReset: z,
1136
+ refreshToken: D,
1137
+ logout: _,
1138
+ setTokens: ge,
1139
+ hasValidSession: Ce,
1140
+ clearSession: Re,
1141
+ currentUser: b,
1142
+ isUserLoading: h,
1143
+ userError: L,
1144
+ loadUserData: g,
1145
+ refreshUser: m,
1146
+ userRole: V,
1147
+ userPermissions: w,
1148
+ availableRoles: I,
1149
+ rolesLoading: x,
1150
+ hasPermission: me,
1151
+ hasAnyPermission: ($) => $.some((U) => me(U)),
1152
+ hasAllPermissions: ($) => $.every((U) => me(U)),
1153
+ getUserPermissionStrings: () => w || [],
1154
+ refreshRoles: Fe
974
1155
  };
975
1156
  }, [
976
- g,
977
- U,
1157
+ M,
978
1158
  u,
979
- y,
980
- x,
1159
+ P,
1160
+ C,
1161
+ H,
1162
+ W,
981
1163
  t,
1164
+ s,
1165
+ o,
1166
+ p,
1167
+ I,
982
1168
  b,
983
- f,
984
- M,
985
- v,
986
- B,
987
- z
1169
+ h,
1170
+ L,
1171
+ V,
1172
+ w,
1173
+ q,
1174
+ E
988
1175
  ]);
989
- return Z(() => {
1176
+ return te(() => {
990
1177
  !i.initialRoles && t && (async () => {
991
1178
  try {
992
- P(!0);
993
- const c = new te(r), h = new pe(c), { roles: o } = await h.getRolesByApp(t);
994
- E(o);
995
- } catch (c) {
996
- console.error("Failed to fetch roles:", c);
1179
+ T(!0);
1180
+ const m = new re(r), c = new Se(m), { roles: d } = await c.getRolesByApp(t);
1181
+ A(d);
1182
+ } catch (m) {
1183
+ console.error("Failed to fetch roles:", m);
997
1184
  } finally {
998
- P(!1);
1185
+ T(!1);
999
1186
  }
1000
1187
  })();
1001
- }, [t, r, i.initialRoles]), Z(() => {
1002
- const S = g.getUser();
1003
- S && g.hasValidSession() && m(S);
1004
- }, [g]), /* @__PURE__ */ n(Se.Provider, { value: q, children: e });
1188
+ }, [t, r, i.initialRoles]), te(() => {
1189
+ const g = u.getUser();
1190
+ g && u.hasValidSession() && f(g);
1191
+ }, [u]), te(() => {
1192
+ !b && !h && a.loadUserData().catch(() => {
1193
+ });
1194
+ }, [b, h, a]), te(() => {
1195
+ if (!u.hasValidSession() || !b)
1196
+ return;
1197
+ const g = setInterval(() => {
1198
+ a.loadUserData().catch(() => {
1199
+ });
1200
+ }, E);
1201
+ return () => clearInterval(g);
1202
+ }, [u, b, a, E]), /* @__PURE__ */ n(Pe.Provider, { value: a, children: e });
1005
1203
  }
1006
- function ie() {
1007
- const i = le(Se);
1204
+ function oe() {
1205
+ const i = ue(Pe);
1008
1206
  if (!i)
1009
1207
  throw new Error("useAuth must be used within an AuthProvider");
1010
1208
  return i;
1011
1209
  }
1012
- class He {
1210
+ class ze {
1013
1211
  constructor(e, t) {
1014
1212
  this.httpService = e, this.sessionManager = t;
1015
1213
  }
@@ -1030,12 +1228,12 @@ class He {
1030
1228
  throw new Error("SessionManager is required for private endpoints");
1031
1229
  const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
1032
1230
  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);
1033
- const s = `/feature-flags/${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s, {
1231
+ const s = `/feature-flags/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
1034
1232
  headers: t
1035
1233
  });
1036
1234
  return {
1037
- featureFlags: a.data,
1038
- meta: a.meta
1235
+ featureFlags: o.data,
1236
+ meta: o.meta
1039
1237
  };
1040
1238
  }
1041
1239
  async getFeatureFlagById(e) {
@@ -1083,64 +1281,64 @@ class He {
1083
1281
  throw new Error("Flag Key, Tenant ID and App ID are required");
1084
1282
  const s = new URLSearchParams();
1085
1283
  s.append("tenantId", t), s.append("appId", r);
1086
- const a = `/tenant-feature-flags/${e}${s.toString() ? `?${s.toString()}` : ""}`;
1087
- return (await this.httpService.get(a, {
1284
+ const o = `/tenant-feature-flags/${e}${s.toString() ? `?${s.toString()}` : ""}`;
1285
+ return (await this.httpService.get(o, {
1088
1286
  headers: { "X-Tenant-ID": t }
1089
1287
  })).data;
1090
1288
  }
1091
1289
  }
1092
- const xe = ae(null);
1093
- function bt({ config: i = {}, children: e }) {
1094
- const { baseUrl: t, appId: r } = ne(), { tenant: s } = re(), [a, b] = p([]), [E, L] = p(!1), [P, f] = p(null), m = _(() => {
1095
- const v = new te(t);
1096
- return new He(v);
1097
- }, [t]), M = async () => {
1290
+ const Me = de(null);
1291
+ function Pt({ config: i = {}, children: e }) {
1292
+ const { baseUrl: t, appId: r } = he(), { tenant: s } = se(), [o, p] = v([]), [I, A] = v(!1), [x, T] = v(null), b = Q(() => {
1293
+ const S = new re(t);
1294
+ return new ze(S);
1295
+ }, [t]), f = async () => {
1098
1296
  if (!(s != null && s.id)) {
1099
- b([]);
1297
+ p([]);
1100
1298
  return;
1101
1299
  }
1102
- L(!0), f(null);
1300
+ A(!0), T(null);
1103
1301
  try {
1104
- const v = await m.getTenantFeatureFlags(s.id, r);
1105
- b(v);
1106
- } catch (v) {
1107
- const I = v instanceof Error ? v.message : "Failed to fetch feature flags";
1108
- f(I), i.onError && i.onError(v instanceof Error ? v : new Error(I));
1302
+ const S = await b.getTenantFeatureFlags(s.id, r);
1303
+ p(S);
1304
+ } catch (S) {
1305
+ const L = S instanceof Error ? S.message : "Failed to fetch feature flags";
1306
+ T(L), i.onError && i.onError(S instanceof Error ? S : new Error(L));
1109
1307
  } finally {
1110
- L(!1);
1308
+ A(!1);
1111
1309
  }
1112
1310
  };
1113
- Z(() => {
1114
- M();
1115
- const v = i.refreshInterval || 5 * 60 * 1e3, I = setInterval(M, v);
1116
- return () => clearInterval(I);
1311
+ te(() => {
1312
+ f();
1313
+ const S = i.refreshInterval || 5 * 60 * 1e3, L = setInterval(f, S);
1314
+ return () => clearInterval(L);
1117
1315
  }, [s == null ? void 0 : s.id, i.refreshInterval]);
1118
- const w = _(() => ({
1119
- featureFlags: a,
1120
- loading: E,
1121
- error: P,
1122
- isEnabled: (u) => {
1123
- const y = a.find((x) => x.key === u);
1124
- return (y == null ? void 0 : y.value) === !0;
1316
+ const h = Q(() => ({
1317
+ featureFlags: o,
1318
+ loading: I,
1319
+ error: x,
1320
+ isEnabled: (k) => {
1321
+ const u = o.find((P) => P.key === k);
1322
+ return (u == null ? void 0 : u.value) === !0;
1125
1323
  },
1126
- getFlag: (u) => a.find((y) => y.key === u),
1127
- getFlagState: (u) => {
1128
- const y = a.find((x) => x.key === u);
1129
- return y ? y.value ? "enabled" : "disabled" : "not_found";
1324
+ getFlag: (k) => o.find((u) => u.key === k),
1325
+ getFlagState: (k) => {
1326
+ const u = o.find((P) => P.key === k);
1327
+ return u ? u.value ? "enabled" : "disabled" : "not_found";
1130
1328
  },
1131
1329
  refresh: async () => {
1132
- await M();
1330
+ await f();
1133
1331
  }
1134
- }), [a, E, P]);
1135
- return /* @__PURE__ */ n(xe.Provider, { value: w, children: e });
1332
+ }), [o, I, x]);
1333
+ return /* @__PURE__ */ n(Me.Provider, { value: h, children: e });
1136
1334
  }
1137
- function $e() {
1138
- const i = le(xe);
1335
+ function Oe() {
1336
+ const i = ue(Me);
1139
1337
  if (!i)
1140
1338
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1141
1339
  return i;
1142
1340
  }
1143
- class De {
1341
+ class je {
1144
1342
  constructor(e, t) {
1145
1343
  this.httpService = e, this.sessionManager = t;
1146
1344
  }
@@ -1206,64 +1404,64 @@ class De {
1206
1404
  )).data;
1207
1405
  }
1208
1406
  }
1209
- const ke = ae(void 0);
1210
- function wt({ config: i = {}, children: e }) {
1211
- const { baseUrl: t } = ne(), { tenant: r } = re(), [s, a] = p(null), [b, E] = p(!1), [L, P] = p(null), f = _(() => {
1212
- const w = new te(t);
1213
- return new De(w);
1214
- }, [t]), m = async () => {
1407
+ const Ie = de(void 0);
1408
+ function Mt({ config: i = {}, children: e }) {
1409
+ const { baseUrl: t } = he(), { tenant: r } = se(), [s, o] = v(null), [p, I] = v(!1), [A, x] = v(null), T = Q(() => {
1410
+ const h = new re(t);
1411
+ return new je(h);
1412
+ }, [t]), b = async () => {
1215
1413
  if (!(r != null && r.id)) {
1216
- a(null);
1414
+ o(null);
1217
1415
  return;
1218
1416
  }
1219
- E(!0), P(null);
1417
+ I(!0), x(null);
1220
1418
  try {
1221
- const w = await f.getTenantSubscriptionFeatures(r.id);
1222
- a(w);
1223
- } catch (w) {
1224
- const v = w instanceof Error ? w.message : "Failed to fetch subscription";
1225
- P(v), i.onError && i.onError(w instanceof Error ? w : new Error(v));
1419
+ const h = await T.getTenantSubscriptionFeatures(r.id);
1420
+ o(h);
1421
+ } catch (h) {
1422
+ const S = h instanceof Error ? h.message : "Failed to fetch subscription";
1423
+ x(S), i.onError && i.onError(h instanceof Error ? h : new Error(S));
1226
1424
  } finally {
1227
- E(!1);
1425
+ I(!1);
1228
1426
  }
1229
1427
  };
1230
- Z(() => {
1231
- if (m(), !i.refreshInterval) return;
1232
- const w = i.refreshInterval || 10 * 60 * 1e3, v = setInterval(m, w);
1233
- return () => clearInterval(v);
1428
+ te(() => {
1429
+ if (b(), !i.refreshInterval) return;
1430
+ const h = i.refreshInterval || 10 * 60 * 1e3, S = setInterval(b, h);
1431
+ return () => clearInterval(S);
1234
1432
  }, [r == null ? void 0 : r.id, i.refreshInterval]);
1235
- const M = _(() => {
1236
- const w = (s == null ? void 0 : s.features) || [];
1433
+ const f = Q(() => {
1434
+ const h = (s == null ? void 0 : s.features) || [];
1237
1435
  return {
1238
1436
  subscription: s,
1239
- features: w,
1240
- loading: b,
1241
- error: L,
1242
- isFeatureEnabled: (y) => {
1243
- const x = w.find((F) => F.key === y);
1244
- return x ? x.type === "BOOLEAN" || x.type === "boolean" ? x.value === !0 : !!x.value : !1;
1437
+ features: h,
1438
+ loading: p,
1439
+ error: A,
1440
+ isFeatureEnabled: (u) => {
1441
+ const P = h.find((C) => C.key === u);
1442
+ return P ? P.type === "BOOLEAN" || P.type === "boolean" ? P.value === !0 : !!P.value : !1;
1245
1443
  },
1246
- getFeature: (y) => w.find((x) => x.key === y),
1247
- getFeatureValue: (y, x) => {
1248
- const F = w.find((B) => B.key === y);
1249
- return F ? F.value : x;
1444
+ getFeature: (u) => h.find((P) => P.key === u),
1445
+ getFeatureValue: (u, P) => {
1446
+ const C = h.find((H) => H.key === u);
1447
+ return C ? C.value : P;
1250
1448
  },
1251
- hasAllowedPlan: (y) => !s || !s.isActive ? !1 : y.includes(s.planId),
1449
+ hasAllowedPlan: (u) => !s || !s.isActive ? !1 : u.includes(s.planId),
1252
1450
  refresh: async () => {
1253
- await m();
1451
+ await b();
1254
1452
  }
1255
1453
  };
1256
- }, [s, b, L]);
1257
- return /* @__PURE__ */ n(ke.Provider, { value: M, children: e });
1454
+ }, [s, p, A]);
1455
+ return /* @__PURE__ */ n(Ie.Provider, { value: f, children: e });
1258
1456
  }
1259
- function Be() {
1260
- const i = le(ke);
1457
+ function Ve() {
1458
+ const i = ue(Ie);
1261
1459
  if (i === void 0)
1262
1460
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1263
1461
  return i;
1264
1462
  }
1265
- var se = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(se || {});
1266
- const me = () => /* @__PURE__ */ l(
1463
+ var ie = /* @__PURE__ */ ((i) => (i.SUPERUSER = "SUPERUSER", i.TENANT_ADMIN = "TENANT_ADMIN", i.USER = "USER", i))(ie || {});
1464
+ const ve = () => /* @__PURE__ */ l(
1267
1465
  "div",
1268
1466
  {
1269
1467
  style: {
@@ -1300,7 +1498,7 @@ const me = () => /* @__PURE__ */ l(
1300
1498
  )
1301
1499
  ]
1302
1500
  }
1303
- ), ye = ({
1501
+ ), xe = ({
1304
1502
  userType: i,
1305
1503
  minUserType: e,
1306
1504
  missingPermissions: t
@@ -1322,7 +1520,7 @@ const me = () => /* @__PURE__ */ l(
1322
1520
  children: [
1323
1521
  /* @__PURE__ */ n("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1324
1522
  /* @__PURE__ */ n("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1325
- e && i ? /* @__PURE__ */ l(D, { children: [
1523
+ e && i ? /* @__PURE__ */ l(N, { children: [
1326
1524
  /* @__PURE__ */ l("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1327
1525
  "This content requires ",
1328
1526
  /* @__PURE__ */ n("strong", { children: e }),
@@ -1332,7 +1530,7 @@ const me = () => /* @__PURE__ */ l(
1332
1530
  "Your current access level: ",
1333
1531
  /* @__PURE__ */ n("strong", { children: i })
1334
1532
  ] })
1335
- ] }) : /* @__PURE__ */ l(D, { children: [
1533
+ ] }) : /* @__PURE__ */ l(N, { children: [
1336
1534
  /* @__PURE__ */ n("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1337
1535
  t && t.length > 0 && /* @__PURE__ */ l("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1338
1536
  "Required permissions: ",
@@ -1341,36 +1539,36 @@ const me = () => /* @__PURE__ */ l(
1341
1539
  ] })
1342
1540
  ]
1343
1541
  }
1344
- ), Ne = (i, e) => {
1542
+ ), We = (i, e) => {
1345
1543
  const t = {
1346
- [se.USER]: 1,
1347
- [se.TENANT_ADMIN]: 2,
1348
- [se.SUPERUSER]: 3
1544
+ [ie.USER]: 1,
1545
+ [ie.TENANT_ADMIN]: 2,
1546
+ [ie.SUPERUSER]: 3
1349
1547
  };
1350
1548
  return t[i] >= t[e];
1351
1549
  };
1352
- function vt({
1550
+ function It({
1353
1551
  children: i,
1354
1552
  fallback: e,
1355
1553
  minUserType: t,
1356
1554
  requiredPermissions: r,
1357
1555
  requireAllPermissions: s = !1
1358
1556
  }) {
1359
- const { hasValidSession: a, sessionManager: b, hasPermission: E, hasAnyPermission: L, hasAllPermissions: P } = ie();
1360
- if (!a())
1361
- return /* @__PURE__ */ n(D, { children: e || /* @__PURE__ */ n(me, {}) });
1362
- const f = b.getUser();
1363
- if (!f)
1364
- return /* @__PURE__ */ n(D, { children: e || /* @__PURE__ */ n(me, {}) });
1365
- if (t && !Ne(f.userType, t))
1366
- return /* @__PURE__ */ n(ye, { userType: f.userType, minUserType: t });
1367
- if (r && r.length > 0 && !(s ? P(r) : L(r))) {
1368
- const M = r.filter((w) => !E(w)).map((w) => typeof w == "string" ? w : w.name);
1369
- return /* @__PURE__ */ n(ye, { missingPermissions: M });
1370
- }
1371
- return /* @__PURE__ */ n(D, { children: i });
1557
+ const { hasValidSession: o, sessionManager: p, hasPermission: I, hasAnyPermission: A, hasAllPermissions: x } = oe();
1558
+ if (!o())
1559
+ return /* @__PURE__ */ n(N, { children: e || /* @__PURE__ */ n(ve, {}) });
1560
+ const T = p.getUser();
1561
+ if (!T)
1562
+ return /* @__PURE__ */ n(N, { children: e || /* @__PURE__ */ n(ve, {}) });
1563
+ if (t && !We(T.userType, t))
1564
+ return /* @__PURE__ */ n(xe, { userType: T.userType, minUserType: t });
1565
+ if (r && r.length > 0 && !(s ? x(r) : A(r))) {
1566
+ const f = r.filter((h) => !I(h)).map((h) => typeof h == "string" ? h : h.name);
1567
+ return /* @__PURE__ */ n(xe, { missingPermissions: f });
1568
+ }
1569
+ return /* @__PURE__ */ n(N, { children: i });
1372
1570
  }
1373
- const qe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1571
+ const Ge = ({ redirectPath: i }) => /* @__PURE__ */ n(
1374
1572
  "div",
1375
1573
  {
1376
1574
  style: {
@@ -1406,7 +1604,7 @@ const qe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1406
1604
  }
1407
1605
  )
1408
1606
  }
1409
- ), be = ({
1607
+ ), ke = ({
1410
1608
  userType: i,
1411
1609
  minUserType: e,
1412
1610
  missingPermissions: t
@@ -1436,7 +1634,7 @@ const qe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1436
1634
  children: [
1437
1635
  /* @__PURE__ */ n("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
1438
1636
  /* @__PURE__ */ n("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
1439
- e && i ? /* @__PURE__ */ l(D, { children: [
1637
+ e && i ? /* @__PURE__ */ l(N, { children: [
1440
1638
  /* @__PURE__ */ l("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
1441
1639
  "This page requires ",
1442
1640
  /* @__PURE__ */ n("strong", { children: e }),
@@ -1446,7 +1644,7 @@ const qe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1446
1644
  "Your current access level: ",
1447
1645
  /* @__PURE__ */ n("strong", { children: i })
1448
1646
  ] })
1449
- ] }) : /* @__PURE__ */ l(D, { children: [
1647
+ ] }) : /* @__PURE__ */ l(N, { children: [
1450
1648
  /* @__PURE__ */ n("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
1451
1649
  t && t.length > 0 && /* @__PURE__ */ l("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
1452
1650
  "Required permissions: ",
@@ -1457,40 +1655,40 @@ const qe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1457
1655
  }
1458
1656
  )
1459
1657
  }
1460
- ), Ue = (i, e) => {
1658
+ ), Ke = (i, e) => {
1461
1659
  const t = {
1462
- [se.USER]: 1,
1463
- [se.TENANT_ADMIN]: 2,
1464
- [se.SUPERUSER]: 3
1660
+ [ie.USER]: 1,
1661
+ [ie.TENANT_ADMIN]: 2,
1662
+ [ie.SUPERUSER]: 3
1465
1663
  };
1466
1664
  return t[i] >= t[e];
1467
1665
  };
1468
- function St({
1666
+ function Et({
1469
1667
  children: i,
1470
1668
  redirectTo: e = "/login",
1471
1669
  minUserType: t,
1472
1670
  requiredPermissions: r,
1473
1671
  requireAllPermissions: s = !1,
1474
- fallback: a
1672
+ fallback: o
1475
1673
  }) {
1476
- const { hasValidSession: b, sessionManager: E, hasPermission: L, hasAnyPermission: P, hasAllPermissions: f } = ie(), m = he();
1477
- if (!b())
1478
- return a ? /* @__PURE__ */ n(D, { children: a }) : /* @__PURE__ */ l(D, { children: [
1479
- /* @__PURE__ */ n(qe, { redirectPath: e }),
1480
- /* @__PURE__ */ n(de, { to: e, state: { from: m.pathname }, replace: !0 })
1674
+ const { hasValidSession: p, sessionManager: I, hasPermission: A, hasAnyPermission: x, hasAllPermissions: T } = oe(), b = we();
1675
+ if (!p())
1676
+ return o ? /* @__PURE__ */ n(N, { children: o }) : /* @__PURE__ */ l(N, { children: [
1677
+ /* @__PURE__ */ n(Ge, { redirectPath: e }),
1678
+ /* @__PURE__ */ n(pe, { to: e, state: { from: b.pathname }, replace: !0 })
1481
1679
  ] });
1482
- const M = E.getUser();
1483
- if (!M)
1484
- return /* @__PURE__ */ n(de, { to: e, state: { from: m.pathname }, replace: !0 });
1485
- if (t && !Ue(M.userType, t))
1486
- return /* @__PURE__ */ n(be, { userType: M.userType, minUserType: t });
1487
- if (r && r.length > 0 && !(s ? f(r) : P(r))) {
1488
- const v = r.filter((I) => !L(I)).map((I) => typeof I == "string" ? I : I.name);
1489
- return /* @__PURE__ */ n(be, { missingPermissions: v });
1490
- }
1491
- return /* @__PURE__ */ n(D, { children: i });
1680
+ const f = I.getUser();
1681
+ if (!f)
1682
+ return /* @__PURE__ */ n(pe, { to: e, state: { from: b.pathname }, replace: !0 });
1683
+ if (t && !Ke(f.userType, t))
1684
+ return /* @__PURE__ */ n(ke, { userType: f.userType, minUserType: t });
1685
+ if (r && r.length > 0 && !(s ? T(r) : x(r))) {
1686
+ const S = r.filter((L) => !A(L)).map((L) => typeof L == "string" ? L : L.name);
1687
+ return /* @__PURE__ */ n(ke, { missingPermissions: S });
1688
+ }
1689
+ return /* @__PURE__ */ n(N, { children: i });
1492
1690
  }
1493
- const ze = ({ redirectPath: i }) => /* @__PURE__ */ n(
1691
+ const _e = ({ redirectPath: i }) => /* @__PURE__ */ n(
1494
1692
  "div",
1495
1693
  {
1496
1694
  style: {
@@ -1527,14 +1725,14 @@ const ze = ({ redirectPath: i }) => /* @__PURE__ */ n(
1527
1725
  )
1528
1726
  }
1529
1727
  );
1530
- function xt({ children: i, redirectTo: e = "/", fallback: t }) {
1531
- const { tenant: r, isLoading: s, error: a } = re(), b = he();
1532
- return s || a ? null : r ? /* @__PURE__ */ n(D, { children: i }) : t ? /* @__PURE__ */ n(D, { children: t }) : /* @__PURE__ */ l(D, { children: [
1533
- /* @__PURE__ */ n(ze, { redirectPath: e }),
1534
- /* @__PURE__ */ n(de, { to: e, state: { from: b.pathname }, replace: !0 })
1728
+ function Ct({ children: i, redirectTo: e = "/", fallback: t }) {
1729
+ const { tenant: r, isLoading: s, error: o } = se(), p = we();
1730
+ return s || o ? null : r ? /* @__PURE__ */ n(N, { children: i }) : t ? /* @__PURE__ */ n(N, { children: t }) : /* @__PURE__ */ l(N, { children: [
1731
+ /* @__PURE__ */ n(_e, { redirectPath: e }),
1732
+ /* @__PURE__ */ n(pe, { to: e, state: { from: p.pathname }, replace: !0 })
1535
1733
  ] });
1536
1734
  }
1537
- const Oe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1735
+ const Je = ({ redirectPath: i }) => /* @__PURE__ */ n(
1538
1736
  "div",
1539
1737
  {
1540
1738
  style: {
@@ -1571,14 +1769,14 @@ const Oe = ({ redirectPath: i }) => /* @__PURE__ */ n(
1571
1769
  )
1572
1770
  }
1573
1771
  );
1574
- function kt({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1575
- const { tenant: r, isLoading: s, error: a } = re(), b = he();
1576
- return s || a ? null : r ? t ? /* @__PURE__ */ n(D, { children: t }) : /* @__PURE__ */ l(D, { children: [
1577
- /* @__PURE__ */ n(Oe, { redirectPath: e }),
1578
- /* @__PURE__ */ n(de, { to: e, state: { from: b.pathname }, replace: !0 })
1579
- ] }) : /* @__PURE__ */ n(D, { children: i });
1772
+ function Rt({ children: i, redirectTo: e = "/dashboard", fallback: t }) {
1773
+ const { tenant: r, isLoading: s, error: o } = se(), p = we();
1774
+ return s || o ? null : r ? t ? /* @__PURE__ */ n(N, { children: t }) : /* @__PURE__ */ l(N, { children: [
1775
+ /* @__PURE__ */ n(Je, { redirectPath: e }),
1776
+ /* @__PURE__ */ n(pe, { to: e, state: { from: p.pathname }, replace: !0 })
1777
+ ] }) : /* @__PURE__ */ n(N, { children: i });
1580
1778
  }
1581
- const je = () => /* @__PURE__ */ l(
1779
+ const Ye = () => /* @__PURE__ */ l(
1582
1780
  "div",
1583
1781
  {
1584
1782
  style: {
@@ -1595,14 +1793,14 @@ const je = () => /* @__PURE__ */ l(
1595
1793
  ]
1596
1794
  }
1597
1795
  );
1598
- function At({
1796
+ function Lt({
1599
1797
  children: i,
1600
- fallback: e = /* @__PURE__ */ n(je, {}),
1798
+ fallback: e = /* @__PURE__ */ n(Ye, {}),
1601
1799
  allowedPlans: t,
1602
1800
  requiredFeature: r
1603
1801
  }) {
1604
- const { subscription: s, hasAllowedPlan: a, isFeatureEnabled: b, loading: E } = Be();
1605
- return E ? /* @__PURE__ */ n(
1802
+ const { subscription: s, hasAllowedPlan: o, isFeatureEnabled: p, loading: I } = Ve();
1803
+ return I ? /* @__PURE__ */ n(
1606
1804
  "div",
1607
1805
  {
1608
1806
  style: {
@@ -1612,9 +1810,9 @@ function At({
1612
1810
  },
1613
1811
  children: "Loading subscription..."
1614
1812
  }
1615
- ) : s ? s.isActive ? t && t.length > 0 && !a(t) ? /* @__PURE__ */ n(D, { children: e }) : r && !b(r) ? /* @__PURE__ */ n(D, { children: e }) : /* @__PURE__ */ n(D, { children: i }) : /* @__PURE__ */ n(D, { children: e }) : /* @__PURE__ */ n(D, { children: e });
1813
+ ) : s ? s.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ n(N, { children: e }) : r && !p(r) ? /* @__PURE__ */ n(N, { children: e }) : /* @__PURE__ */ n(N, { children: i }) : /* @__PURE__ */ n(N, { children: e }) : /* @__PURE__ */ n(N, { children: e });
1616
1814
  }
1617
- const We = ({ flagName: i }) => /* @__PURE__ */ l(
1815
+ const Qe = ({ flagName: i }) => /* @__PURE__ */ l(
1618
1816
  "div",
1619
1817
  {
1620
1818
  style: {
@@ -1641,8 +1839,8 @@ const We = ({ flagName: i }) => /* @__PURE__ */ l(
1641
1839
  ]
1642
1840
  }
1643
1841
  );
1644
- function Pt({ name: i, children: e, fallback: t }) {
1645
- const { isEnabled: r, loading: s } = $e();
1842
+ function Ft({ name: i, children: e, fallback: t }) {
1843
+ const { isEnabled: r, loading: s } = Oe();
1646
1844
  return s ? /* @__PURE__ */ n(
1647
1845
  "div",
1648
1846
  {
@@ -1656,9 +1854,9 @@ function Pt({ name: i, children: e, fallback: t }) {
1656
1854
  },
1657
1855
  children: "Loading feature flags..."
1658
1856
  }
1659
- ) : (console.log(i, r(i)), r(i) ? /* @__PURE__ */ n(D, { children: e }) : /* @__PURE__ */ n(D, { children: t || /* @__PURE__ */ n(We, { flagName: i }) }));
1857
+ ) : r(i) ? /* @__PURE__ */ n(N, { children: e }) : /* @__PURE__ */ n(N, { children: t || /* @__PURE__ */ n(Qe, { flagName: i }) });
1660
1858
  }
1661
- const Ve = () => /* @__PURE__ */ l(
1859
+ const Xe = () => /* @__PURE__ */ l(
1662
1860
  "svg",
1663
1861
  {
1664
1862
  width: "16",
@@ -1675,7 +1873,7 @@ const Ve = () => /* @__PURE__ */ l(
1675
1873
  /* @__PURE__ */ n("circle", { cx: "12", cy: "12", r: "3" })
1676
1874
  ]
1677
1875
  }
1678
- ), Ge = () => /* @__PURE__ */ l(
1876
+ ), Ze = () => /* @__PURE__ */ l(
1679
1877
  "svg",
1680
1878
  {
1681
1879
  width: "16",
@@ -1692,10 +1890,10 @@ const Ve = () => /* @__PURE__ */ l(
1692
1890
  /* @__PURE__ */ n("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
1693
1891
  ]
1694
1892
  }
1695
- ), Ye = {
1696
- showPassword: /* @__PURE__ */ n(Ve, {}),
1697
- hidePassword: /* @__PURE__ */ n(Ge, {})
1698
- }, _e = {
1893
+ ), et = {
1894
+ showPassword: /* @__PURE__ */ n(Xe, {}),
1895
+ hidePassword: /* @__PURE__ */ n(Ze, {})
1896
+ }, tt = {
1699
1897
  title: "Sign In",
1700
1898
  usernameLabel: "Email or Phone",
1701
1899
  usernamePlaceholder: "Enter your email or phone number",
@@ -1709,7 +1907,7 @@ const Ve = () => /* @__PURE__ */ l(
1709
1907
  magicLinkLink: "Use Magic Link",
1710
1908
  errorMessage: "Invalid credentials",
1711
1909
  loadingText: "Signing in..."
1712
- }, Ke = {
1910
+ }, rt = {
1713
1911
  container: {
1714
1912
  maxWidth: "400px",
1715
1913
  width: "100%",
@@ -1816,129 +2014,133 @@ const Ve = () => /* @__PURE__ */ l(
1816
2014
  fontSize: "0.875rem"
1817
2015
  }
1818
2016
  };
1819
- function Tt({
2017
+ function $t({
1820
2018
  copy: i = {},
1821
2019
  styles: e = {},
1822
2020
  icons: t = {},
1823
2021
  onSuccess: r,
1824
2022
  onError: s,
1825
- onForgotPassword: a,
1826
- onSignupClick: b,
1827
- onMagicLinkClick: E,
1828
- showForgotPassword: L = !0,
1829
- showSignupLink: P = !0,
1830
- showMagicLinkOption: f = !0,
1831
- className: m
2023
+ onForgotPassword: o,
2024
+ onSignupClick: p,
2025
+ onMagicLinkClick: I,
2026
+ showForgotPassword: A = !0,
2027
+ showSignupLink: x = !0,
2028
+ showMagicLinkOption: T = !0,
2029
+ className: b
1832
2030
  }) {
1833
- const [M, w] = p(""), [v, I] = p(""), [g, U] = p(!1), [u, y] = p(!1), [x, F] = p(""), [B, z] = p({}), { login: q } = ie(), { tenant: S } = re(), { appId: c } = ne(), h = { ..._e, ...i }, o = { ...Ke, ...e }, d = { ...Ye, ...t }, G = () => {
1834
- const k = {};
1835
- return M.trim() || (k.username = !0), v.trim() || (k.password = !0), z(k), Object.keys(k).length === 0;
1836
- }, Y = async (k) => {
1837
- if (k.preventDefault(), !!G()) {
1838
- if (!(S != null && S.id)) {
1839
- F("Tenant not found");
2031
+ const [f, h] = v(""), [S, L] = v(""), [R, q] = v(!1), [k, u] = v(!1), [P, C] = v(""), [H, W] = v({}), { login: F } = oe(), { tenant: V } = se(), w = { ...tt, ...i }, M = { ...rt, ...e }, E = { ...et, ...t }, a = () => {
2032
+ const d = {};
2033
+ return f.trim() || (d.username = !0), S.trim() || (d.password = !0), W(d), Object.keys(d).length === 0;
2034
+ }, g = async (d) => {
2035
+ if (d.preventDefault(), !!a()) {
2036
+ if (!(V != null && V.id)) {
2037
+ C("Tenant not found");
1840
2038
  return;
1841
2039
  }
1842
- y(!0), F("");
2040
+ u(!0), C("");
1843
2041
  try {
1844
- const T = await q(M, v, c, S.id);
1845
- r == null || r(T);
1846
- } catch (T) {
1847
- const J = T.message || h.errorMessage;
1848
- F(J), s == null || s(J);
2042
+ const y = await F({
2043
+ username: f,
2044
+ password: S
2045
+ // tenantId inferred from context automatically
2046
+ });
2047
+ r == null || r(y);
2048
+ } catch (y) {
2049
+ const G = y.message || w.errorMessage;
2050
+ C(G), s == null || s(G);
1849
2051
  } finally {
1850
- y(!1);
2052
+ u(!1);
1851
2053
  }
1852
2054
  }
1853
- }, H = (k) => ({
1854
- ...o.input,
1855
- ...B[k] ? o.inputError : {}
1856
- }), C = () => ({
1857
- ...o.button,
1858
- ...u ? o.buttonLoading : {},
1859
- ...!M || !v || u ? o.buttonDisabled : {}
2055
+ }, m = (d) => ({
2056
+ ...M.input,
2057
+ ...H[d] ? M.inputError : {}
2058
+ }), c = () => ({
2059
+ ...M.button,
2060
+ ...k ? M.buttonLoading : {},
2061
+ ...!f || !S || k ? M.buttonDisabled : {}
1860
2062
  });
1861
- return /* @__PURE__ */ l("div", { className: m, style: o.container, children: [
1862
- /* @__PURE__ */ n("h2", { style: o.title, children: h.title }),
1863
- /* @__PURE__ */ l("form", { onSubmit: Y, style: o.form, children: [
1864
- /* @__PURE__ */ l("div", { style: o.fieldGroup, children: [
1865
- /* @__PURE__ */ n("label", { style: o.label, children: h.usernameLabel }),
2063
+ return /* @__PURE__ */ l("div", { className: b, style: M.container, children: [
2064
+ /* @__PURE__ */ n("h2", { style: M.title, children: w.title }),
2065
+ /* @__PURE__ */ l("form", { onSubmit: g, style: M.form, children: [
2066
+ /* @__PURE__ */ l("div", { style: M.fieldGroup, children: [
2067
+ /* @__PURE__ */ n("label", { style: M.label, children: w.usernameLabel }),
1866
2068
  /* @__PURE__ */ n(
1867
2069
  "input",
1868
2070
  {
1869
2071
  id: "username",
1870
2072
  name: "username",
1871
2073
  type: "text",
1872
- value: M,
1873
- onChange: (k) => {
1874
- w(k.target.value), B.username && z((T) => ({ ...T, username: !1 }));
2074
+ value: f,
2075
+ onChange: (d) => {
2076
+ h(d.target.value), H.username && W((y) => ({ ...y, username: !1 }));
1875
2077
  },
1876
- placeholder: h.usernamePlaceholder,
1877
- style: H("username"),
1878
- disabled: u
2078
+ placeholder: w.usernamePlaceholder,
2079
+ style: m("username"),
2080
+ disabled: k
1879
2081
  }
1880
2082
  )
1881
2083
  ] }),
1882
- /* @__PURE__ */ l("div", { style: o.fieldGroup, children: [
1883
- /* @__PURE__ */ n("label", { style: o.label, children: h.passwordLabel }),
1884
- /* @__PURE__ */ l("div", { style: o.inputContainer, children: [
2084
+ /* @__PURE__ */ l("div", { style: M.fieldGroup, children: [
2085
+ /* @__PURE__ */ n("label", { style: M.label, children: w.passwordLabel }),
2086
+ /* @__PURE__ */ l("div", { style: M.inputContainer, children: [
1885
2087
  /* @__PURE__ */ n(
1886
2088
  "input",
1887
2089
  {
1888
2090
  id: "password",
1889
2091
  name: "password",
1890
- type: g ? "text" : "password",
1891
- value: v,
1892
- onChange: (k) => {
1893
- I(k.target.value), B.password && z((T) => ({ ...T, password: !1 }));
2092
+ type: R ? "text" : "password",
2093
+ value: S,
2094
+ onChange: (d) => {
2095
+ L(d.target.value), H.password && W((y) => ({ ...y, password: !1 }));
1894
2096
  },
1895
- placeholder: h.passwordPlaceholder,
2097
+ placeholder: w.passwordPlaceholder,
1896
2098
  style: {
1897
- ...H("password"),
2099
+ ...m("password"),
1898
2100
  paddingRight: "2.5rem"
1899
2101
  // Make room for the icon
1900
2102
  },
1901
- disabled: u
2103
+ disabled: k
1902
2104
  }
1903
2105
  ),
1904
2106
  /* @__PURE__ */ n(
1905
2107
  "button",
1906
2108
  {
1907
2109
  type: "button",
1908
- onClick: () => U(!g),
1909
- style: o.passwordToggle,
1910
- disabled: u,
1911
- "aria-label": g ? "Hide password" : "Show password",
1912
- children: g ? d.hidePassword : d.showPassword
2110
+ onClick: () => q(!R),
2111
+ style: M.passwordToggle,
2112
+ disabled: k,
2113
+ "aria-label": R ? "Hide password" : "Show password",
2114
+ children: R ? E.hidePassword : E.showPassword
1913
2115
  }
1914
2116
  )
1915
2117
  ] })
1916
2118
  ] }),
1917
- /* @__PURE__ */ n("button", { type: "submit", disabled: !M || !v || u, style: C(), children: u ? h.loadingText : h.submitButton }),
1918
- x && /* @__PURE__ */ n("div", { style: o.errorText, children: x })
2119
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !f || !S || k, style: c(), children: k ? w.loadingText : w.submitButton }),
2120
+ P && /* @__PURE__ */ n("div", { style: M.errorText, children: P })
1919
2121
  ] }),
1920
- (L || P || f) && /* @__PURE__ */ l("div", { style: o.linkContainer, children: [
1921
- f && /* @__PURE__ */ l("div", { children: [
1922
- /* @__PURE__ */ l("span", { style: o.divider, children: [
1923
- h.magicLinkText,
2122
+ (A || x || T) && /* @__PURE__ */ l("div", { style: M.linkContainer, children: [
2123
+ T && /* @__PURE__ */ l("div", { children: [
2124
+ /* @__PURE__ */ l("span", { style: M.divider, children: [
2125
+ w.magicLinkText,
1924
2126
  " "
1925
2127
  ] }),
1926
- /* @__PURE__ */ n("a", { onClick: E, style: o.link, children: h.magicLinkLink })
2128
+ /* @__PURE__ */ n("a", { onClick: I, style: M.link, children: w.magicLinkLink })
1927
2129
  ] }),
1928
- f && (L || P) && /* @__PURE__ */ n("div", { style: o.divider, children: "•" }),
1929
- L && /* @__PURE__ */ n("a", { onClick: a, style: o.link, children: h.forgotPasswordLink }),
1930
- L && P && /* @__PURE__ */ n("div", { style: o.divider, children: "•" }),
1931
- P && /* @__PURE__ */ l("div", { children: [
1932
- /* @__PURE__ */ l("span", { style: o.divider, children: [
1933
- h.signupText,
2130
+ T && (A || x) && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2131
+ A && /* @__PURE__ */ n("a", { onClick: o, style: M.link, children: w.forgotPasswordLink }),
2132
+ A && x && /* @__PURE__ */ n("div", { style: M.divider, children: "•" }),
2133
+ x && /* @__PURE__ */ l("div", { children: [
2134
+ /* @__PURE__ */ l("span", { style: M.divider, children: [
2135
+ w.signupText,
1934
2136
  " "
1935
2137
  ] }),
1936
- /* @__PURE__ */ n("a", { onClick: b, style: o.link, children: h.signupLink })
2138
+ /* @__PURE__ */ n("a", { onClick: p, style: M.link, children: w.signupLink })
1937
2139
  ] })
1938
2140
  ] })
1939
2141
  ] });
1940
2142
  }
1941
- const Qe = {
2143
+ const nt = {
1942
2144
  title: "Create Account",
1943
2145
  nameLabel: "First Name",
1944
2146
  namePlaceholder: "Enter your first name",
@@ -1964,7 +2166,7 @@ const Qe = {
1964
2166
  passwordMismatchError: "Passwords do not match",
1965
2167
  isAdminLabel: "Create new organization",
1966
2168
  isAdminDescription: "Check this if you want to create a new organization"
1967
- }, Je = {
2169
+ }, st = {
1968
2170
  container: {
1969
2171
  maxWidth: "400px",
1970
2172
  width: "100%",
@@ -2063,136 +2265,134 @@ const Qe = {
2063
2265
  fontSize: "0.875rem"
2064
2266
  }
2065
2267
  };
2066
- function Mt({
2268
+ function Dt({
2067
2269
  copy: i = {},
2068
2270
  styles: e = {},
2069
2271
  signupType: t = "user",
2070
2272
  onSuccess: r,
2071
2273
  onError: s,
2072
- onLoginClick: a,
2073
- onMagicLinkClick: b,
2074
- showLoginLink: E = !0,
2075
- showMagicLinkOption: L = !0,
2076
- className: P
2274
+ onLoginClick: o,
2275
+ onMagicLinkClick: p,
2276
+ showLoginLink: I = !0,
2277
+ showMagicLinkOption: A = !0,
2278
+ className: x
2077
2279
  }) {
2078
- const [f, m] = p(""), [M, w] = p(""), [v, I] = p(""), [g, U] = p(""), [u, y] = p(""), [x, F] = p(""), [B, z] = p(""), [q, S] = p(!1), [c, h] = p(""), [o, d] = p({}), { signup: G, signupTenantAdmin: Y } = ie(), { tenant: H } = re(), { appId: C } = ne(), k = { ...Qe, ...i }, T = { ...Je, ...e }, J = () => {
2079
- const R = {};
2080
- return f.trim() || (R.name = !0), !v.trim() && !g.trim() && (R.email = !0, R.phoneNumber = !0), u.trim() || (R.password = !0), x.trim() || (R.confirmPassword = !0), t === "tenant" && !B.trim() && (R.tenantName = !0), d(R), Object.keys(R).length === 0;
2081
- }, O = async (R) => {
2082
- if (R.preventDefault(), !!J()) {
2083
- if (u !== x) {
2084
- h(k.passwordMismatchError), d({ confirmPassword: !0 });
2280
+ const [T, b] = v(""), [f, h] = v(""), [S, L] = v(""), [R, q] = v(""), [k, u] = v(""), [P, C] = v(""), [H, W] = v(""), [F, V] = v(!1), [w, M] = v(""), [E, a] = v({}), { signup: g, signupTenantAdmin: m } = oe(), { tenant: c } = se(), d = { ...nt, ...i }, y = { ...st, ...e }, G = () => {
2281
+ const D = {};
2282
+ return T.trim() || (D.name = !0), !S.trim() && !R.trim() && (D.email = !0, D.phoneNumber = !0), k.trim() || (D.password = !0), P.trim() || (D.confirmPassword = !0), t === "tenant" && !H.trim() && (D.tenantName = !0), a(D), Object.keys(D).length === 0;
2283
+ }, ee = async (D) => {
2284
+ if (D.preventDefault(), !!G()) {
2285
+ if (k !== P) {
2286
+ M(d.passwordMismatchError), a({ confirmPassword: !0 });
2085
2287
  return;
2086
2288
  }
2087
- if (t === "user" && !(H != null && H.id)) {
2088
- h("Tenant not found");
2289
+ if (t === "user" && !(c != null && c.id)) {
2290
+ M("Tenant not found");
2089
2291
  return;
2090
2292
  }
2091
- S(!0), h("");
2293
+ V(!0), M("");
2092
2294
  try {
2093
- let V;
2094
- t === "tenant" ? V = await Y(
2095
- v || void 0,
2096
- g || void 0,
2097
- f,
2098
- u,
2099
- B,
2100
- M || void 0,
2101
- C
2102
- ) : V = await G(
2103
- v || void 0,
2104
- g || void 0,
2105
- f,
2106
- u,
2107
- H.id,
2108
- M || void 0,
2109
- C
2110
- ), r == null || r(V);
2111
- } catch (V) {
2112
- const ue = V.message || k.errorMessage;
2113
- h(ue), s == null || s(ue);
2295
+ let _;
2296
+ t === "tenant" ? _ = await m({
2297
+ email: S || void 0,
2298
+ phoneNumber: R || void 0,
2299
+ name: T,
2300
+ password: k,
2301
+ tenantName: H,
2302
+ lastName: f || void 0
2303
+ }) : _ = await g({
2304
+ email: S || void 0,
2305
+ phoneNumber: R || void 0,
2306
+ name: T,
2307
+ password: k,
2308
+ tenantId: c.id,
2309
+ lastName: f || void 0
2310
+ }), r == null || r(_);
2311
+ } catch (_) {
2312
+ const ge = _.message || d.errorMessage;
2313
+ M(ge), s == null || s(ge);
2114
2314
  } finally {
2115
- S(!1);
2315
+ V(!1);
2116
2316
  }
2117
2317
  }
2118
- }, j = (R) => ({
2119
- ...T.input,
2120
- ...o[R] ? T.inputError : {}
2121
- }), N = () => ({
2122
- ...T.button,
2123
- ...q ? T.buttonLoading : {},
2124
- ...!f || !v && !g || !u || !x || q || t === "tenant" && !B ? T.buttonDisabled : {}
2125
- }), K = f && (v || g) && u && x && (t === "user" || B);
2126
- return /* @__PURE__ */ l("div", { className: P, style: T.container, children: [
2127
- /* @__PURE__ */ n("h2", { style: T.title, children: k.title }),
2128
- /* @__PURE__ */ l("form", { onSubmit: O, style: T.form, children: [
2129
- /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2130
- /* @__PURE__ */ n("label", { style: T.label, children: k.nameLabel }),
2318
+ }, z = (D) => ({
2319
+ ...y.input,
2320
+ ...E[D] ? y.inputError : {}
2321
+ }), B = () => ({
2322
+ ...y.button,
2323
+ ...F ? y.buttonLoading : {},
2324
+ ...!T || !S && !R || !k || !P || F || t === "tenant" && !H ? y.buttonDisabled : {}
2325
+ }), O = T && (S || R) && k && P && (t === "user" || H);
2326
+ return /* @__PURE__ */ l("div", { className: x, style: y.container, children: [
2327
+ /* @__PURE__ */ n("h2", { style: y.title, children: d.title }),
2328
+ /* @__PURE__ */ l("form", { onSubmit: ee, style: y.form, children: [
2329
+ /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2330
+ /* @__PURE__ */ n("label", { style: y.label, children: d.nameLabel }),
2131
2331
  /* @__PURE__ */ n(
2132
2332
  "input",
2133
2333
  {
2134
2334
  id: "name",
2135
2335
  name: "name",
2136
2336
  type: "text",
2137
- value: f,
2138
- onChange: (R) => {
2139
- m(R.target.value), o.name && d((V) => ({ ...V, name: !1 }));
2337
+ value: T,
2338
+ onChange: (D) => {
2339
+ b(D.target.value), E.name && a((_) => ({ ..._, name: !1 }));
2140
2340
  },
2141
- placeholder: k.namePlaceholder,
2142
- style: j("name"),
2143
- disabled: q
2341
+ placeholder: d.namePlaceholder,
2342
+ style: z("name"),
2343
+ disabled: F
2144
2344
  }
2145
2345
  )
2146
2346
  ] }),
2147
- /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2148
- /* @__PURE__ */ n("label", { style: T.label, children: k.lastNameLabel }),
2347
+ /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2348
+ /* @__PURE__ */ n("label", { style: y.label, children: d.lastNameLabel }),
2149
2349
  /* @__PURE__ */ n(
2150
2350
  "input",
2151
2351
  {
2152
2352
  id: "lastName",
2153
2353
  name: "lastName",
2154
2354
  type: "text",
2155
- value: M,
2156
- onChange: (R) => w(R.target.value),
2157
- placeholder: k.lastNamePlaceholder,
2158
- style: T.input,
2159
- disabled: q
2355
+ value: f,
2356
+ onChange: (D) => h(D.target.value),
2357
+ placeholder: d.lastNamePlaceholder,
2358
+ style: y.input,
2359
+ disabled: F
2160
2360
  }
2161
2361
  )
2162
2362
  ] }),
2163
- /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2164
- /* @__PURE__ */ n("label", { style: T.label, children: k.emailLabel }),
2363
+ /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2364
+ /* @__PURE__ */ n("label", { style: y.label, children: d.emailLabel }),
2165
2365
  /* @__PURE__ */ n(
2166
2366
  "input",
2167
2367
  {
2168
2368
  id: "email",
2169
2369
  name: "email",
2170
2370
  type: "email",
2171
- value: v,
2172
- onChange: (R) => {
2173
- I(R.target.value), o.email && d((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2371
+ value: S,
2372
+ onChange: (D) => {
2373
+ L(D.target.value), E.email && a((_) => ({ ..._, email: !1, phoneNumber: !1 }));
2174
2374
  },
2175
- placeholder: k.emailPlaceholder,
2176
- style: j("email"),
2177
- disabled: q
2375
+ placeholder: d.emailPlaceholder,
2376
+ style: z("email"),
2377
+ disabled: F
2178
2378
  }
2179
2379
  )
2180
2380
  ] }),
2181
- /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2182
- /* @__PURE__ */ n("label", { style: T.label, children: k.phoneNumberLabel }),
2381
+ /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2382
+ /* @__PURE__ */ n("label", { style: y.label, children: d.phoneNumberLabel }),
2183
2383
  /* @__PURE__ */ n(
2184
2384
  "input",
2185
2385
  {
2186
2386
  id: "phoneNumber",
2187
2387
  name: "phoneNumber",
2188
2388
  type: "tel",
2189
- value: g,
2190
- onChange: (R) => {
2191
- U(R.target.value), o.phoneNumber && d((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2389
+ value: R,
2390
+ onChange: (D) => {
2391
+ q(D.target.value), E.phoneNumber && a((_) => ({ ..._, email: !1, phoneNumber: !1 }));
2192
2392
  },
2193
- placeholder: k.phoneNumberPlaceholder,
2194
- style: j("phoneNumber"),
2195
- disabled: q
2393
+ placeholder: d.phoneNumberPlaceholder,
2394
+ style: z("phoneNumber"),
2395
+ disabled: F
2196
2396
  }
2197
2397
  )
2198
2398
  ] }),
@@ -2208,83 +2408,83 @@ function Mt({
2208
2408
  children: "At least one contact method (email or phone) is required"
2209
2409
  }
2210
2410
  ),
2211
- /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2212
- /* @__PURE__ */ n("label", { style: T.label, children: k.passwordLabel }),
2411
+ /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2412
+ /* @__PURE__ */ n("label", { style: y.label, children: d.passwordLabel }),
2213
2413
  /* @__PURE__ */ n(
2214
2414
  "input",
2215
2415
  {
2216
2416
  id: "password",
2217
2417
  name: "password",
2218
2418
  type: "password",
2219
- value: u,
2220
- onChange: (R) => {
2221
- y(R.target.value), o.password && d((V) => ({ ...V, password: !1 }));
2419
+ value: k,
2420
+ onChange: (D) => {
2421
+ u(D.target.value), E.password && a((_) => ({ ..._, password: !1 }));
2222
2422
  },
2223
- placeholder: k.passwordPlaceholder,
2224
- style: j("password"),
2225
- disabled: q
2423
+ placeholder: d.passwordPlaceholder,
2424
+ style: z("password"),
2425
+ disabled: F
2226
2426
  }
2227
2427
  )
2228
2428
  ] }),
2229
- /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2230
- /* @__PURE__ */ n("label", { style: T.label, children: k.confirmPasswordLabel }),
2429
+ /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2430
+ /* @__PURE__ */ n("label", { style: y.label, children: d.confirmPasswordLabel }),
2231
2431
  /* @__PURE__ */ n(
2232
2432
  "input",
2233
2433
  {
2234
2434
  id: "confirmPassword",
2235
2435
  name: "confirmPassword",
2236
2436
  type: "password",
2237
- value: x,
2238
- onChange: (R) => {
2239
- F(R.target.value), o.confirmPassword && d((V) => ({ ...V, confirmPassword: !1 })), c === k.passwordMismatchError && h("");
2437
+ value: P,
2438
+ onChange: (D) => {
2439
+ C(D.target.value), E.confirmPassword && a((_) => ({ ..._, confirmPassword: !1 })), w === d.passwordMismatchError && M("");
2240
2440
  },
2241
- placeholder: k.confirmPasswordPlaceholder,
2242
- style: j("confirmPassword"),
2243
- disabled: q
2441
+ placeholder: d.confirmPasswordPlaceholder,
2442
+ style: z("confirmPassword"),
2443
+ disabled: F
2244
2444
  }
2245
2445
  )
2246
2446
  ] }),
2247
- t === "tenant" && /* @__PURE__ */ l("div", { style: T.fieldGroup, children: [
2248
- /* @__PURE__ */ n("label", { style: T.label, children: k.tenantNameLabel }),
2447
+ t === "tenant" && /* @__PURE__ */ l("div", { style: y.fieldGroup, children: [
2448
+ /* @__PURE__ */ n("label", { style: y.label, children: d.tenantNameLabel }),
2249
2449
  /* @__PURE__ */ n(
2250
2450
  "input",
2251
2451
  {
2252
2452
  id: "tenantName",
2253
2453
  name: "tenantName",
2254
2454
  type: "text",
2255
- value: B,
2256
- onChange: (R) => {
2257
- z(R.target.value), o.tenantName && d((V) => ({ ...V, tenantName: !1 }));
2455
+ value: H,
2456
+ onChange: (D) => {
2457
+ W(D.target.value), E.tenantName && a((_) => ({ ..._, tenantName: !1 }));
2258
2458
  },
2259
- placeholder: k.tenantNamePlaceholder,
2260
- style: j("tenantName"),
2261
- disabled: q
2459
+ placeholder: d.tenantNamePlaceholder,
2460
+ style: z("tenantName"),
2461
+ disabled: F
2262
2462
  }
2263
2463
  )
2264
2464
  ] }),
2265
- /* @__PURE__ */ n("button", { type: "submit", disabled: !K || q, style: N(), children: q ? k.loadingText : k.submitButton }),
2266
- c && /* @__PURE__ */ n("div", { style: T.errorText, children: c })
2465
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !O || F, style: B(), children: F ? d.loadingText : d.submitButton }),
2466
+ w && /* @__PURE__ */ n("div", { style: y.errorText, children: w })
2267
2467
  ] }),
2268
- (E || L) && /* @__PURE__ */ l("div", { style: T.linkContainer, children: [
2269
- L && /* @__PURE__ */ l("div", { children: [
2270
- /* @__PURE__ */ l("span", { style: T.divider, children: [
2271
- k.magicLinkText,
2468
+ (I || A) && /* @__PURE__ */ l("div", { style: y.linkContainer, children: [
2469
+ A && /* @__PURE__ */ l("div", { children: [
2470
+ /* @__PURE__ */ l("span", { style: y.divider, children: [
2471
+ d.magicLinkText,
2272
2472
  " "
2273
2473
  ] }),
2274
- /* @__PURE__ */ n("a", { onClick: b, style: T.link, children: k.magicLinkLink })
2474
+ /* @__PURE__ */ n("a", { onClick: p, style: y.link, children: d.magicLinkLink })
2275
2475
  ] }),
2276
- L && E && /* @__PURE__ */ n("div", { style: T.divider, children: "•" }),
2277
- E && /* @__PURE__ */ l("div", { children: [
2278
- /* @__PURE__ */ l("span", { style: T.divider, children: [
2279
- k.loginText,
2476
+ A && I && /* @__PURE__ */ n("div", { style: y.divider, children: "•" }),
2477
+ I && /* @__PURE__ */ l("div", { children: [
2478
+ /* @__PURE__ */ l("span", { style: y.divider, children: [
2479
+ d.loginText,
2280
2480
  " "
2281
2481
  ] }),
2282
- /* @__PURE__ */ n("a", { onClick: a, style: T.link, children: k.loginLink })
2482
+ /* @__PURE__ */ n("a", { onClick: o, style: y.link, children: d.loginLink })
2283
2483
  ] })
2284
2484
  ] })
2285
2485
  ] });
2286
2486
  }
2287
- const Xe = {
2487
+ const it = {
2288
2488
  title: "Sign In with Magic Link",
2289
2489
  emailLabel: "Email",
2290
2490
  emailPlaceholder: "Enter your email",
@@ -2302,7 +2502,7 @@ const Xe = {
2302
2502
  loadingText: "Sending magic link...",
2303
2503
  verifyingText: "Verifying magic link...",
2304
2504
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
2305
- }, Ze = {
2505
+ }, ot = {
2306
2506
  container: {
2307
2507
  maxWidth: "400px",
2308
2508
  width: "100%",
@@ -2405,100 +2605,105 @@ const Xe = {
2405
2605
  fontSize: "0.875rem"
2406
2606
  }
2407
2607
  };
2408
- function Et({
2608
+ function Ht({
2409
2609
  copy: i = {},
2410
2610
  styles: e = {},
2411
2611
  onSuccess: t,
2412
2612
  onError: r,
2413
2613
  onLoginClick: s,
2414
- onSignupClick: a,
2415
- showTraditionalLinks: b = !0,
2416
- className: E,
2417
- verifyToken: L,
2418
- frontendUrl: P
2614
+ onSignupClick: o,
2615
+ showTraditionalLinks: p = !0,
2616
+ className: I,
2617
+ verifyToken: A,
2618
+ frontendUrl: x
2419
2619
  }) {
2420
- const [f, m] = p(""), [M, w] = p(""), [v, I] = p(""), [g, U] = p(!1), [u, y] = p(!1), [x, F] = p(""), [B, z] = p(""), [q, S] = p({}), [c, h] = p(!1), { sendMagicLink: o, verifyMagicLink: d } = ie(), { tenant: G } = re(), { appId: Y } = ne(), H = { ...Xe, ...i }, C = { ...Ze, ...e };
2421
- Z(() => {
2422
- L && k(L);
2423
- }, [L]);
2424
- const k = async (N) => {
2425
- y(!0), F("");
2620
+ const [T, b] = v(""), [f, h] = v(""), [S, L] = v(""), [R, q] = v(!1), [k, u] = v(!1), [P, C] = v(""), [H, W] = v(""), [F, V] = v({}), [w, M] = v(!1), { sendMagicLink: E, verifyMagicLink: a } = oe(), { tenant: g } = se(), m = { ...it, ...i }, c = { ...ot, ...e };
2621
+ te(() => {
2622
+ A && d(A);
2623
+ }, [A]);
2624
+ const d = async (B) => {
2625
+ if (!g || !T) {
2626
+ C("Missing tenant or email");
2627
+ return;
2628
+ }
2629
+ u(!0), C("");
2426
2630
  try {
2427
- if (!f || !Y)
2428
- throw new Error("Email and App ID are required for magic link verification");
2429
- const K = await d(N, f, Y, G == null ? void 0 : G.id);
2430
- t == null || t(K);
2431
- } catch (K) {
2432
- const R = K.message || "Failed to verify magic link";
2433
- F(R), r == null || r(R);
2631
+ const O = await a({
2632
+ token: B,
2633
+ email: T
2634
+ // tenantId inferred from context automatically
2635
+ });
2636
+ t == null || t(O);
2637
+ } catch (O) {
2638
+ const D = O.message || "Failed to verify magic link";
2639
+ C(D), r == null || r(D);
2434
2640
  } finally {
2435
- y(!1);
2641
+ u(!1);
2436
2642
  }
2437
- }, T = () => {
2438
- const N = {};
2439
- return f.trim() || (N.email = !0), c && !M.trim() && (N.name = !0), S(N), Object.keys(N).length === 0;
2440
- }, J = async (N) => {
2441
- if (N.preventDefault(), !!T()) {
2442
- if (!(G != null && G.id)) {
2443
- F("Tenant not found");
2643
+ }, y = () => {
2644
+ const B = {};
2645
+ return T.trim() || (B.email = !0), w && !f.trim() && (B.name = !0), V(B), Object.keys(B).length === 0;
2646
+ }, G = async (B) => {
2647
+ if (B.preventDefault(), !!y()) {
2648
+ if (!(g != null && g.id)) {
2649
+ C("Tenant not found");
2444
2650
  return;
2445
2651
  }
2446
- U(!0), F(""), z("");
2652
+ q(!0), C(""), W("");
2447
2653
  try {
2448
- const K = P || (typeof window < "u" ? window.location.origin : ""), R = await o(
2449
- f,
2450
- G.id,
2451
- K,
2452
- c ? M : void 0,
2453
- c ? v : void 0,
2454
- Y
2455
- );
2456
- z(H.successMessage), t == null || t(R);
2457
- } catch (K) {
2458
- const R = K.message || H.errorMessage;
2459
- F(R), r == null || r(R);
2654
+ const O = x || (typeof window < "u" ? window.location.origin : ""), D = await E({
2655
+ email: T,
2656
+ tenantId: g.id,
2657
+ frontendUrl: O,
2658
+ name: w ? f : void 0,
2659
+ lastName: w ? S : void 0
2660
+ });
2661
+ W(m.successMessage), t == null || t(D);
2662
+ } catch (O) {
2663
+ const D = O.message || m.errorMessage;
2664
+ C(D), r == null || r(D);
2460
2665
  } finally {
2461
- U(!1);
2666
+ q(!1);
2462
2667
  }
2463
2668
  }
2464
- }, O = (N) => ({
2465
- ...C.input,
2466
- ...q[N] ? C.inputError : {}
2467
- }), j = () => ({
2468
- ...C.button,
2469
- ...g || u ? C.buttonLoading : {},
2470
- ...!f || g || u ? C.buttonDisabled : {}
2669
+ }, ee = (B) => ({
2670
+ ...c.input,
2671
+ ...F[B] ? c.inputError : {}
2672
+ }), z = () => ({
2673
+ ...c.button,
2674
+ ...R || k ? c.buttonLoading : {},
2675
+ ...!T || R || k ? c.buttonDisabled : {}
2471
2676
  });
2472
- return u ? /* @__PURE__ */ l("div", { className: E, style: C.container, children: [
2473
- /* @__PURE__ */ n("h2", { style: C.title, children: H.verifyingText }),
2677
+ return k ? /* @__PURE__ */ l("div", { className: I, style: c.container, children: [
2678
+ /* @__PURE__ */ n("h2", { style: c.title, children: m.verifyingText }),
2474
2679
  /* @__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..." }) })
2475
- ] }) : /* @__PURE__ */ l("div", { className: E, style: C.container, children: [
2476
- /* @__PURE__ */ n("h2", { style: C.title, children: H.title }),
2477
- /* @__PURE__ */ n("p", { style: C.description, children: H.description }),
2478
- /* @__PURE__ */ l("form", { onSubmit: J, style: C.form, children: [
2479
- /* @__PURE__ */ l("div", { style: C.fieldGroup, children: [
2480
- /* @__PURE__ */ n("label", { style: C.label, children: H.emailLabel }),
2680
+ ] }) : /* @__PURE__ */ l("div", { className: I, style: c.container, children: [
2681
+ /* @__PURE__ */ n("h2", { style: c.title, children: m.title }),
2682
+ /* @__PURE__ */ n("p", { style: c.description, children: m.description }),
2683
+ /* @__PURE__ */ l("form", { onSubmit: G, style: c.form, children: [
2684
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
2685
+ /* @__PURE__ */ n("label", { style: c.label, children: m.emailLabel }),
2481
2686
  /* @__PURE__ */ n(
2482
2687
  "input",
2483
2688
  {
2484
2689
  id: "email",
2485
2690
  name: "email",
2486
2691
  type: "email",
2487
- value: f,
2488
- onChange: (N) => {
2489
- m(N.target.value), q.email && S((K) => ({ ...K, email: !1 }));
2692
+ value: T,
2693
+ onChange: (B) => {
2694
+ b(B.target.value), F.email && V((O) => ({ ...O, email: !1 }));
2490
2695
  },
2491
- placeholder: H.emailPlaceholder,
2492
- style: O("email"),
2493
- disabled: g || u
2696
+ placeholder: m.emailPlaceholder,
2697
+ style: ee("email"),
2698
+ disabled: R || k
2494
2699
  }
2495
2700
  )
2496
2701
  ] }),
2497
- !c && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2702
+ !w && /* @__PURE__ */ n("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ n(
2498
2703
  "button",
2499
2704
  {
2500
2705
  type: "button",
2501
- onClick: () => h(!0),
2706
+ onClick: () => M(!0),
2502
2707
  style: {
2503
2708
  background: "none",
2504
2709
  border: "none",
@@ -2510,38 +2715,38 @@ function Et({
2510
2715
  children: "New user? Add your name"
2511
2716
  }
2512
2717
  ) }),
2513
- c && /* @__PURE__ */ l(D, { children: [
2514
- /* @__PURE__ */ l("div", { style: C.fieldGroup, children: [
2515
- /* @__PURE__ */ n("label", { style: C.label, children: H.nameLabel }),
2718
+ w && /* @__PURE__ */ l(N, { children: [
2719
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
2720
+ /* @__PURE__ */ n("label", { style: c.label, children: m.nameLabel }),
2516
2721
  /* @__PURE__ */ n(
2517
2722
  "input",
2518
2723
  {
2519
2724
  id: "name",
2520
2725
  name: "name",
2521
2726
  type: "text",
2522
- value: M,
2523
- onChange: (N) => {
2524
- w(N.target.value), q.name && S((K) => ({ ...K, name: !1 }));
2727
+ value: f,
2728
+ onChange: (B) => {
2729
+ h(B.target.value), F.name && V((O) => ({ ...O, name: !1 }));
2525
2730
  },
2526
- placeholder: H.namePlaceholder,
2527
- style: O("name"),
2528
- disabled: g || u
2731
+ placeholder: m.namePlaceholder,
2732
+ style: ee("name"),
2733
+ disabled: R || k
2529
2734
  }
2530
2735
  )
2531
2736
  ] }),
2532
- /* @__PURE__ */ l("div", { style: C.fieldGroup, children: [
2533
- /* @__PURE__ */ n("label", { style: C.label, children: H.lastNameLabel }),
2737
+ /* @__PURE__ */ l("div", { style: c.fieldGroup, children: [
2738
+ /* @__PURE__ */ n("label", { style: c.label, children: m.lastNameLabel }),
2534
2739
  /* @__PURE__ */ n(
2535
2740
  "input",
2536
2741
  {
2537
2742
  id: "lastName",
2538
2743
  name: "lastName",
2539
2744
  type: "text",
2540
- value: v,
2541
- onChange: (N) => I(N.target.value),
2542
- placeholder: H.lastNamePlaceholder,
2543
- style: C.input,
2544
- disabled: g || u
2745
+ value: S,
2746
+ onChange: (B) => L(B.target.value),
2747
+ placeholder: m.lastNamePlaceholder,
2748
+ style: c.input,
2749
+ disabled: R || k
2545
2750
  }
2546
2751
  )
2547
2752
  ] }),
@@ -2550,7 +2755,7 @@ function Et({
2550
2755
  {
2551
2756
  type: "button",
2552
2757
  onClick: () => {
2553
- h(!1), w(""), I("");
2758
+ M(!1), h(""), L("");
2554
2759
  },
2555
2760
  style: {
2556
2761
  background: "none",
@@ -2564,30 +2769,30 @@ function Et({
2564
2769
  }
2565
2770
  ) })
2566
2771
  ] }),
2567
- /* @__PURE__ */ n("button", { type: "submit", disabled: !f || g || u, style: j(), children: g ? H.loadingText : H.submitButton }),
2568
- x && /* @__PURE__ */ n("div", { style: C.errorText, children: x }),
2569
- B && /* @__PURE__ */ n("div", { style: C.successText, children: B })
2772
+ /* @__PURE__ */ n("button", { type: "submit", disabled: !T || R || k, style: z(), children: R ? m.loadingText : m.submitButton }),
2773
+ P && /* @__PURE__ */ n("div", { style: c.errorText, children: P }),
2774
+ H && /* @__PURE__ */ n("div", { style: c.successText, children: H })
2570
2775
  ] }),
2571
- b && /* @__PURE__ */ l("div", { style: C.linkContainer, children: [
2776
+ p && /* @__PURE__ */ l("div", { style: c.linkContainer, children: [
2572
2777
  /* @__PURE__ */ l("div", { children: [
2573
- /* @__PURE__ */ l("span", { style: C.divider, children: [
2574
- H.loginText,
2778
+ /* @__PURE__ */ l("span", { style: c.divider, children: [
2779
+ m.loginText,
2575
2780
  " "
2576
2781
  ] }),
2577
- /* @__PURE__ */ n("a", { onClick: s, style: C.link, children: H.loginLink })
2782
+ /* @__PURE__ */ n("a", { onClick: s, style: c.link, children: m.loginLink })
2578
2783
  ] }),
2579
- /* @__PURE__ */ n("div", { style: C.divider, children: "•" }),
2784
+ /* @__PURE__ */ n("div", { style: c.divider, children: "•" }),
2580
2785
  /* @__PURE__ */ l("div", { children: [
2581
- /* @__PURE__ */ l("span", { style: C.divider, children: [
2582
- H.signupText,
2786
+ /* @__PURE__ */ l("span", { style: c.divider, children: [
2787
+ m.signupText,
2583
2788
  " "
2584
2789
  ] }),
2585
- /* @__PURE__ */ n("a", { onClick: a, style: C.link, children: H.signupLink })
2790
+ /* @__PURE__ */ n("a", { onClick: o, style: c.link, children: m.signupLink })
2586
2791
  ] })
2587
2792
  ] })
2588
2793
  ] });
2589
2794
  }
2590
- const et = {
2795
+ const at = {
2591
2796
  title: "Verifying Magic Link",
2592
2797
  verifyingMessage: "Please wait while we verify your magic link...",
2593
2798
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -2595,7 +2800,7 @@ const et = {
2595
2800
  redirectingMessage: "Redirecting you to the dashboard...",
2596
2801
  retryButton: "Try Again",
2597
2802
  backToLoginButton: "Back to Login"
2598
- }, Ae = {
2803
+ }, Ee = {
2599
2804
  container: {
2600
2805
  maxWidth: "400px",
2601
2806
  width: "100%",
@@ -2682,7 +2887,7 @@ const et = {
2682
2887
  cursor: "pointer",
2683
2888
  transition: "all 0.15s ease-in-out"
2684
2889
  }
2685
- }, tt = () => /* @__PURE__ */ n("div", { style: Ae.spinner }), rt = () => /* @__PURE__ */ l(
2890
+ }, lt = () => /* @__PURE__ */ n("div", { style: Ee.spinner }), ct = () => /* @__PURE__ */ l(
2686
2891
  "svg",
2687
2892
  {
2688
2893
  width: "48",
@@ -2699,7 +2904,7 @@ const et = {
2699
2904
  /* @__PURE__ */ n("polyline", { points: "22,4 12,14.01 9,11.01" })
2700
2905
  ]
2701
2906
  }
2702
- ), nt = () => /* @__PURE__ */ l(
2907
+ ), dt = () => /* @__PURE__ */ l(
2703
2908
  "svg",
2704
2909
  {
2705
2910
  width: "48",
@@ -2717,110 +2922,109 @@ const et = {
2717
2922
  /* @__PURE__ */ n("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
2718
2923
  ]
2719
2924
  }
2720
- ), st = {
2721
- loading: /* @__PURE__ */ n(tt, {}),
2722
- success: /* @__PURE__ */ n(rt, {}),
2723
- error: /* @__PURE__ */ n(nt, {})
2925
+ ), ut = {
2926
+ loading: /* @__PURE__ */ n(lt, {}),
2927
+ success: /* @__PURE__ */ n(ct, {}),
2928
+ error: /* @__PURE__ */ n(dt, {})
2724
2929
  };
2725
- function Lt({
2930
+ function Nt({
2726
2931
  copy: i = {},
2727
2932
  styles: e = {},
2728
2933
  icons: t = {},
2729
2934
  onSuccess: r,
2730
2935
  onError: s,
2731
- onRetry: a,
2732
- onBackToLogin: b,
2733
- className: E,
2734
- token: L,
2735
- email: P,
2736
- appId: f,
2737
- tenantId: m,
2738
- autoRedirectDelay: M = 3e3
2936
+ onRetry: o,
2937
+ onBackToLogin: p,
2938
+ className: I,
2939
+ token: A,
2940
+ email: x,
2941
+ appId: T,
2942
+ tenantSlug: b,
2943
+ autoRedirectDelay: f = 3e3
2739
2944
  }) {
2740
- const [w, v] = p("verifying"), [I, g] = p(""), { verifyMagicLink: U } = ie(), u = { ...et, ...i }, y = { ...Ae, ...e }, x = { ...st, ...t }, F = () => {
2945
+ const [h, S] = v("verifying"), [L, R] = v(""), { verifyMagicLink: q } = oe(), k = { ...at, ...i }, u = { ...Ee, ...e }, P = { ...ut, ...t }, C = () => {
2741
2946
  if (typeof window > "u") return {};
2742
- const c = new URLSearchParams(window.location.search);
2947
+ const w = new URLSearchParams(window.location.search);
2743
2948
  return {
2744
- token: L || c.get("token") || "",
2745
- email: P || c.get("email") || "",
2746
- appId: f || c.get("appId") || "",
2747
- tenantId: m || c.get("tenantId") || void 0
2949
+ token: A || w.get("token") || "",
2950
+ email: x || w.get("email") || "",
2951
+ appId: T || w.get("appId") || "",
2952
+ tenantSlug: b || w.get("tenantSlug") || void 0
2748
2953
  };
2749
- }, B = async () => {
2750
- v("verifying"), g("");
2954
+ }, H = async () => {
2955
+ S("verifying"), R("");
2751
2956
  try {
2752
- const c = F();
2753
- if (!c.token || !c.email || !c.appId)
2754
- throw new Error("Missing required parameters: token, email, or appId");
2755
- const h = await U(
2756
- c.token,
2757
- c.email,
2758
- c.appId,
2759
- c.tenantId
2760
- );
2761
- v("success"), r == null || r(h), M > 0 && setTimeout(() => {
2762
- v("redirecting");
2763
- }, M);
2764
- } catch (c) {
2765
- const h = c.message || u.errorMessage;
2766
- g(h), v("error"), s == null || s(h);
2957
+ const w = C();
2958
+ if (!w.token || !w.email)
2959
+ throw new Error("Missing required parameters: token or email");
2960
+ const M = await q({
2961
+ token: w.token,
2962
+ email: w.email,
2963
+ tenantSlug: w.tenantSlug
2964
+ });
2965
+ S("success"), r == null || r(M), f > 0 && setTimeout(() => {
2966
+ S("redirecting");
2967
+ }, f);
2968
+ } catch (w) {
2969
+ const M = w.message || k.errorMessage;
2970
+ R(M), S("error"), s == null || s(M);
2767
2971
  }
2768
- }, z = () => {
2769
- a == null || a(), B();
2770
- }, q = () => {
2771
- b == null || b();
2972
+ }, W = () => {
2973
+ o == null || o(), H();
2974
+ }, F = () => {
2975
+ p == null || p();
2772
2976
  };
2773
- Z(() => {
2774
- B();
2977
+ te(() => {
2978
+ H();
2775
2979
  }, []);
2776
- const S = () => {
2777
- switch (w) {
2980
+ const V = () => {
2981
+ switch (h) {
2778
2982
  case "verifying":
2779
- return /* @__PURE__ */ l("div", { style: y.message, children: [
2780
- x.loading,
2781
- u.verifyingMessage
2983
+ return /* @__PURE__ */ l("div", { style: u.message, children: [
2984
+ P.loading,
2985
+ k.verifyingMessage
2782
2986
  ] });
2783
2987
  case "success":
2784
- return /* @__PURE__ */ l(D, { children: [
2785
- x.success,
2786
- /* @__PURE__ */ n("div", { style: y.successMessage, children: u.successMessage })
2988
+ return /* @__PURE__ */ l(N, { children: [
2989
+ P.success,
2990
+ /* @__PURE__ */ n("div", { style: u.successMessage, children: k.successMessage })
2787
2991
  ] });
2788
2992
  case "redirecting":
2789
- return /* @__PURE__ */ l(D, { children: [
2790
- x.loading,
2791
- /* @__PURE__ */ n("div", { style: y.message, children: u.redirectingMessage })
2993
+ return /* @__PURE__ */ l(N, { children: [
2994
+ P.loading,
2995
+ /* @__PURE__ */ n("div", { style: u.message, children: k.redirectingMessage })
2792
2996
  ] });
2793
2997
  case "error":
2794
- return /* @__PURE__ */ l(D, { children: [
2795
- x.error,
2796
- /* @__PURE__ */ n("div", { style: y.errorMessage, children: I || u.errorMessage }),
2797
- /* @__PURE__ */ l("div", { style: y.buttonContainer, children: [
2998
+ return /* @__PURE__ */ l(N, { children: [
2999
+ P.error,
3000
+ /* @__PURE__ */ n("div", { style: u.errorMessage, children: L || k.errorMessage }),
3001
+ /* @__PURE__ */ l("div", { style: u.buttonContainer, children: [
2798
3002
  /* @__PURE__ */ n(
2799
3003
  "button",
2800
3004
  {
2801
- onClick: z,
2802
- style: y.retryButton,
2803
- onMouseOver: (c) => {
2804
- c.currentTarget.style.backgroundColor = "#2563eb";
3005
+ onClick: W,
3006
+ style: u.retryButton,
3007
+ onMouseOver: (w) => {
3008
+ w.currentTarget.style.backgroundColor = "#2563eb";
2805
3009
  },
2806
- onMouseOut: (c) => {
2807
- c.currentTarget.style.backgroundColor = "#3b82f6";
3010
+ onMouseOut: (w) => {
3011
+ w.currentTarget.style.backgroundColor = "#3b82f6";
2808
3012
  },
2809
- children: u.retryButton
3013
+ children: k.retryButton
2810
3014
  }
2811
3015
  ),
2812
3016
  /* @__PURE__ */ n(
2813
3017
  "button",
2814
3018
  {
2815
- onClick: q,
2816
- style: y.backButton,
2817
- onMouseOver: (c) => {
2818
- c.currentTarget.style.backgroundColor = "#e5e7eb";
3019
+ onClick: F,
3020
+ style: u.backButton,
3021
+ onMouseOver: (w) => {
3022
+ w.currentTarget.style.backgroundColor = "#e5e7eb";
2819
3023
  },
2820
- onMouseOut: (c) => {
2821
- c.currentTarget.style.backgroundColor = "#f3f4f6";
3024
+ onMouseOut: (w) => {
3025
+ w.currentTarget.style.backgroundColor = "#f3f4f6";
2822
3026
  },
2823
- children: u.backToLoginButton
3027
+ children: k.backToLoginButton
2824
3028
  }
2825
3029
  )
2826
3030
  ] })
@@ -2829,18 +3033,18 @@ function Lt({
2829
3033
  return null;
2830
3034
  }
2831
3035
  };
2832
- return /* @__PURE__ */ l("div", { style: y.container, className: E, children: [
3036
+ return /* @__PURE__ */ l("div", { style: u.container, className: I, children: [
2833
3037
  /* @__PURE__ */ n("style", { children: `
2834
3038
  @keyframes spin {
2835
3039
  0% { transform: rotate(0deg); }
2836
3040
  100% { transform: rotate(360deg); }
2837
3041
  }
2838
3042
  ` }),
2839
- /* @__PURE__ */ n("h1", { style: y.title, children: u.title }),
2840
- S()
3043
+ /* @__PURE__ */ n("h1", { style: u.title, children: k.title }),
3044
+ V()
2841
3045
  ] });
2842
3046
  }
2843
- const it = {
3047
+ const ht = {
2844
3048
  title: "Reset Password",
2845
3049
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
2846
3050
  emailLabel: "Email",
@@ -2862,7 +3066,7 @@ const it = {
2862
3066
  resetLoadingText: "Resetting...",
2863
3067
  resetSuccessMessage: "Password reset successfully!",
2864
3068
  passwordMismatchError: "Passwords do not match"
2865
- }, ot = {
3069
+ }, gt = {
2866
3070
  container: {
2867
3071
  maxWidth: "400px",
2868
3072
  margin: "0 auto",
@@ -2954,113 +3158,113 @@ const it = {
2954
3158
  cursor: "pointer"
2955
3159
  }
2956
3160
  };
2957
- function Rt({
3161
+ function Bt({
2958
3162
  copy: i = {},
2959
3163
  styles: e = {},
2960
3164
  mode: t = "request",
2961
3165
  token: r = "",
2962
3166
  onSuccess: s,
2963
- onError: a,
2964
- onBackToLogin: b,
2965
- onModeChange: E,
2966
- className: L
3167
+ onError: o,
3168
+ onBackToLogin: p,
3169
+ onModeChange: I,
3170
+ className: A
2967
3171
  }) {
2968
- const [P, f] = p(""), [m, M] = p(r), [w, v] = p(""), [I, g] = p(""), [U, u] = p(!1), [y, x] = p(""), [F, B] = p(""), [z, q] = p({}), { requestPasswordReset: S, confirmPasswordReset: c } = ie(), { tenant: h } = re(), o = { ...it, ...i }, d = { ...ot, ...e }, G = () => {
2969
- const O = {};
2970
- return P.trim() || (O.email = !0), q(O), Object.keys(O).length === 0;
2971
- }, Y = () => {
2972
- const O = {};
2973
- return m.trim() || (O.token = !0), w.trim() || (O.newPassword = !0), I.trim() || (O.confirmPassword = !0), q(O), Object.keys(O).length === 0;
2974
- }, H = async (O) => {
2975
- if (O.preventDefault(), !!G()) {
2976
- if (!(h != null && h.id)) {
2977
- x("Tenant not found");
3172
+ const [x, T] = v(""), [b, f] = v(r), [h, S] = v(""), [L, R] = v(""), [q, k] = v(!1), [u, P] = v(""), [C, H] = v(""), [W, F] = v({}), { requestPasswordReset: V, confirmPasswordReset: w } = oe(), { tenant: M } = se(), E = { ...ht, ...i }, a = { ...gt, ...e }, g = () => {
3173
+ const z = {};
3174
+ return x.trim() || (z.email = !0), F(z), Object.keys(z).length === 0;
3175
+ }, m = () => {
3176
+ const z = {};
3177
+ return b.trim() || (z.token = !0), h.trim() || (z.newPassword = !0), L.trim() || (z.confirmPassword = !0), F(z), Object.keys(z).length === 0;
3178
+ }, c = async (z) => {
3179
+ if (z.preventDefault(), !!g()) {
3180
+ if (!(M != null && M.id)) {
3181
+ P("Tenant not found");
2978
3182
  return;
2979
3183
  }
2980
- u(!0), x(""), B("");
3184
+ k(!0), P(""), H("");
2981
3185
  try {
2982
- await S(P, h.id), B(o.successMessage), s == null || s();
2983
- } catch (j) {
2984
- const N = j.message || o.errorMessage;
2985
- x(N), a == null || a(N);
3186
+ await V({ email: x, tenantId: M.id }), H(E.successMessage), s == null || s();
3187
+ } catch (B) {
3188
+ const O = B.message || E.errorMessage;
3189
+ P(O), o == null || o(O);
2986
3190
  } finally {
2987
- u(!1);
3191
+ k(!1);
2988
3192
  }
2989
3193
  }
2990
- }, C = async (O) => {
2991
- if (O.preventDefault(), !!Y()) {
2992
- if (w !== I) {
2993
- x(o.passwordMismatchError), q({ confirmPassword: !0 });
3194
+ }, d = async (z) => {
3195
+ if (z.preventDefault(), !!m()) {
3196
+ if (h !== L) {
3197
+ P(E.passwordMismatchError), F({ confirmPassword: !0 });
2994
3198
  return;
2995
3199
  }
2996
- u(!0), x(""), B("");
3200
+ k(!0), P(""), H("");
2997
3201
  try {
2998
- await c(m, w), B(o.resetSuccessMessage), s == null || s();
2999
- } catch (j) {
3000
- const N = j.message || o.errorMessage;
3001
- x(N), a == null || a(N);
3202
+ await w({ token: b, newPassword: h }), H(E.resetSuccessMessage), s == null || s();
3203
+ } catch (B) {
3204
+ const O = B.message || E.errorMessage;
3205
+ P(O), o == null || o(O);
3002
3206
  } finally {
3003
- u(!1);
3207
+ k(!1);
3004
3208
  }
3005
3209
  }
3006
- }, k = (O) => ({
3007
- ...d.input,
3008
- ...z[O] ? d.inputError : {}
3009
- }), T = () => ({
3010
- ...d.button,
3011
- ...U ? d.buttonLoading : {}
3210
+ }, y = (z) => ({
3211
+ ...a.input,
3212
+ ...W[z] ? a.inputError : {}
3213
+ }), G = () => ({
3214
+ ...a.button,
3215
+ ...q ? a.buttonLoading : {}
3012
3216
  });
3013
3217
  if (t === "reset") {
3014
- const O = m && w && I;
3015
- return /* @__PURE__ */ l("div", { className: L, style: d.container, children: [
3016
- /* @__PURE__ */ n("h2", { style: d.title, children: o.resetTitle }),
3017
- /* @__PURE__ */ n("p", { style: d.subtitle, children: o.resetSubtitle }),
3018
- /* @__PURE__ */ l("form", { onSubmit: C, style: d.form, children: [
3019
- /* @__PURE__ */ l("div", { style: d.fieldGroup, children: [
3020
- /* @__PURE__ */ n("label", { style: d.label, children: o.tokenLabel }),
3218
+ const z = b && h && L;
3219
+ return /* @__PURE__ */ l("div", { className: A, style: a.container, children: [
3220
+ /* @__PURE__ */ n("h2", { style: a.title, children: E.resetTitle }),
3221
+ /* @__PURE__ */ n("p", { style: a.subtitle, children: E.resetSubtitle }),
3222
+ /* @__PURE__ */ l("form", { onSubmit: d, style: a.form, children: [
3223
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3224
+ /* @__PURE__ */ n("label", { style: a.label, children: E.tokenLabel }),
3021
3225
  /* @__PURE__ */ n(
3022
3226
  "input",
3023
3227
  {
3024
3228
  type: "text",
3025
- value: m,
3026
- onChange: (j) => {
3027
- M(j.target.value), z.token && q((N) => ({ ...N, token: !1 }));
3229
+ value: b,
3230
+ onChange: (B) => {
3231
+ f(B.target.value), W.token && F((O) => ({ ...O, token: !1 }));
3028
3232
  },
3029
- placeholder: o.tokenPlaceholder,
3030
- style: k("token"),
3031
- disabled: U
3233
+ placeholder: E.tokenPlaceholder,
3234
+ style: y("token"),
3235
+ disabled: q
3032
3236
  }
3033
3237
  )
3034
3238
  ] }),
3035
- /* @__PURE__ */ l("div", { style: d.fieldGroup, children: [
3036
- /* @__PURE__ */ n("label", { style: d.label, children: o.newPasswordLabel }),
3239
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3240
+ /* @__PURE__ */ n("label", { style: a.label, children: E.newPasswordLabel }),
3037
3241
  /* @__PURE__ */ n(
3038
3242
  "input",
3039
3243
  {
3040
3244
  type: "password",
3041
- value: w,
3042
- onChange: (j) => {
3043
- v(j.target.value), z.newPassword && q((N) => ({ ...N, newPassword: !1 }));
3245
+ value: h,
3246
+ onChange: (B) => {
3247
+ S(B.target.value), W.newPassword && F((O) => ({ ...O, newPassword: !1 }));
3044
3248
  },
3045
- placeholder: o.newPasswordPlaceholder,
3046
- style: k("newPassword"),
3047
- disabled: U
3249
+ placeholder: E.newPasswordPlaceholder,
3250
+ style: y("newPassword"),
3251
+ disabled: q
3048
3252
  }
3049
3253
  )
3050
3254
  ] }),
3051
- /* @__PURE__ */ l("div", { style: d.fieldGroup, children: [
3052
- /* @__PURE__ */ n("label", { style: d.label, children: o.confirmPasswordLabel }),
3255
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3256
+ /* @__PURE__ */ n("label", { style: a.label, children: E.confirmPasswordLabel }),
3053
3257
  /* @__PURE__ */ n(
3054
3258
  "input",
3055
3259
  {
3056
3260
  type: "password",
3057
- value: I,
3058
- onChange: (j) => {
3059
- g(j.target.value), z.confirmPassword && q((N) => ({ ...N, confirmPassword: !1 })), y === o.passwordMismatchError && x("");
3261
+ value: L,
3262
+ onChange: (B) => {
3263
+ R(B.target.value), W.confirmPassword && F((O) => ({ ...O, confirmPassword: !1 })), u === E.passwordMismatchError && P("");
3060
3264
  },
3061
- placeholder: o.confirmPasswordPlaceholder,
3062
- style: k("confirmPassword"),
3063
- disabled: U
3265
+ placeholder: E.confirmPasswordPlaceholder,
3266
+ style: y("confirmPassword"),
3267
+ disabled: q
3064
3268
  }
3065
3269
  )
3066
3270
  ] }),
@@ -3068,44 +3272,44 @@ function Rt({
3068
3272
  "button",
3069
3273
  {
3070
3274
  type: "submit",
3071
- disabled: !O || U,
3275
+ disabled: !z || q,
3072
3276
  style: {
3073
- ...T(),
3074
- ...!O || U ? d.buttonDisabled : {}
3277
+ ...G(),
3278
+ ...!z || q ? a.buttonDisabled : {}
3075
3279
  },
3076
- children: U ? o.resetLoadingText : o.resetSubmitButton
3280
+ children: q ? E.resetLoadingText : E.resetSubmitButton
3077
3281
  }
3078
3282
  ),
3079
- y && /* @__PURE__ */ n("div", { style: d.errorText, children: y }),
3080
- F && /* @__PURE__ */ n("div", { style: d.successText, children: F })
3283
+ u && /* @__PURE__ */ n("div", { style: a.errorText, children: u }),
3284
+ C && /* @__PURE__ */ n("div", { style: a.successText, children: C })
3081
3285
  ] }),
3082
- /* @__PURE__ */ l("div", { style: d.linkContainer, children: [
3083
- /* @__PURE__ */ n("a", { onClick: b, style: d.link, children: o.backToLoginLink }),
3084
- E && /* @__PURE__ */ l(D, { children: [
3286
+ /* @__PURE__ */ l("div", { style: a.linkContainer, children: [
3287
+ /* @__PURE__ */ n("a", { onClick: p, style: a.link, children: E.backToLoginLink }),
3288
+ I && /* @__PURE__ */ l(N, { children: [
3085
3289
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3086
- /* @__PURE__ */ n("a", { onClick: () => E("request"), style: d.link, children: "Request New Link" })
3290
+ /* @__PURE__ */ n("a", { onClick: () => I("request"), style: a.link, children: "Request New Link" })
3087
3291
  ] })
3088
3292
  ] })
3089
3293
  ] });
3090
3294
  }
3091
- const J = P;
3092
- return /* @__PURE__ */ l("div", { className: L, style: d.container, children: [
3093
- /* @__PURE__ */ n("h2", { style: d.title, children: o.title }),
3094
- /* @__PURE__ */ n("p", { style: d.subtitle, children: o.subtitle }),
3095
- /* @__PURE__ */ l("form", { onSubmit: H, style: d.form, children: [
3096
- /* @__PURE__ */ l("div", { style: d.fieldGroup, children: [
3097
- /* @__PURE__ */ n("label", { style: d.label, children: o.emailLabel }),
3295
+ const ee = x;
3296
+ return /* @__PURE__ */ l("div", { className: A, style: a.container, children: [
3297
+ /* @__PURE__ */ n("h2", { style: a.title, children: E.title }),
3298
+ /* @__PURE__ */ n("p", { style: a.subtitle, children: E.subtitle }),
3299
+ /* @__PURE__ */ l("form", { onSubmit: c, style: a.form, children: [
3300
+ /* @__PURE__ */ l("div", { style: a.fieldGroup, children: [
3301
+ /* @__PURE__ */ n("label", { style: a.label, children: E.emailLabel }),
3098
3302
  /* @__PURE__ */ n(
3099
3303
  "input",
3100
3304
  {
3101
3305
  type: "email",
3102
- value: P,
3103
- onChange: (O) => {
3104
- f(O.target.value), z.email && q((j) => ({ ...j, email: !1 }));
3306
+ value: x,
3307
+ onChange: (z) => {
3308
+ T(z.target.value), W.email && F((B) => ({ ...B, email: !1 }));
3105
3309
  },
3106
- placeholder: o.emailPlaceholder,
3107
- style: k("email"),
3108
- disabled: U
3310
+ placeholder: E.emailPlaceholder,
3311
+ style: y("email"),
3312
+ disabled: q
3109
3313
  }
3110
3314
  )
3111
3315
  ] }),
@@ -3113,27 +3317,27 @@ function Rt({
3113
3317
  "button",
3114
3318
  {
3115
3319
  type: "submit",
3116
- disabled: !J || U,
3320
+ disabled: !ee || q,
3117
3321
  style: {
3118
- ...T(),
3119
- ...!J || U ? d.buttonDisabled : {}
3322
+ ...G(),
3323
+ ...!ee || q ? a.buttonDisabled : {}
3120
3324
  },
3121
- children: U ? o.loadingText : o.submitButton
3325
+ children: q ? E.loadingText : E.submitButton
3122
3326
  }
3123
3327
  ),
3124
- y && /* @__PURE__ */ n("div", { style: d.errorText, children: y }),
3125
- F && /* @__PURE__ */ n("div", { style: d.successText, children: F })
3328
+ u && /* @__PURE__ */ n("div", { style: a.errorText, children: u }),
3329
+ C && /* @__PURE__ */ n("div", { style: a.successText, children: C })
3126
3330
  ] }),
3127
- /* @__PURE__ */ l("div", { style: d.linkContainer, children: [
3128
- /* @__PURE__ */ n("a", { onClick: b, style: d.link, children: o.backToLoginLink }),
3129
- E && /* @__PURE__ */ l(D, { children: [
3331
+ /* @__PURE__ */ l("div", { style: a.linkContainer, children: [
3332
+ /* @__PURE__ */ n("a", { onClick: p, style: a.link, children: E.backToLoginLink }),
3333
+ I && /* @__PURE__ */ l(N, { children: [
3130
3334
  /* @__PURE__ */ n("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3131
- /* @__PURE__ */ n("a", { onClick: () => E("reset"), style: d.link, children: "I have a token" })
3335
+ /* @__PURE__ */ n("a", { onClick: () => I("reset"), style: a.link, children: "I have a token" })
3132
3336
  ] })
3133
3337
  ] })
3134
3338
  ] });
3135
3339
  }
3136
- class Ct {
3340
+ class Ut {
3137
3341
  constructor(e, t) {
3138
3342
  this.httpService = e, this.sessionManager = t;
3139
3343
  }
@@ -3154,12 +3358,12 @@ class Ct {
3154
3358
  throw new Error("SessionManager is required for private endpoints");
3155
3359
  const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
3156
3360
  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);
3157
- const s = `/permissions/${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s, {
3361
+ const s = `/permissions/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
3158
3362
  headers: t
3159
3363
  });
3160
3364
  return {
3161
- permissions: a.data,
3162
- meta: a.meta
3365
+ permissions: o.data,
3366
+ meta: o.meta
3163
3367
  };
3164
3368
  }
3165
3369
  async getPermissionById(e) {
@@ -3194,14 +3398,14 @@ class Ct {
3194
3398
  async getAppPermissions(e, t) {
3195
3399
  const r = new URLSearchParams();
3196
3400
  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);
3197
- const s = `/permissions/apps/${e}${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s);
3401
+ const s = `/permissions/apps/${e}${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s);
3198
3402
  return {
3199
- permissions: a.data,
3200
- meta: a.meta
3403
+ permissions: o.data,
3404
+ meta: o.meta
3201
3405
  };
3202
3406
  }
3203
3407
  }
3204
- class It {
3408
+ class qt {
3205
3409
  constructor(e, t) {
3206
3410
  this.httpService = e, this.sessionManager = t;
3207
3411
  }
@@ -3218,12 +3422,12 @@ class It {
3218
3422
  async getSubscriptionPlans(e) {
3219
3423
  const t = await this.sessionManager.getAuthHeaders(), r = new URLSearchParams();
3220
3424
  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);
3221
- const s = `/subscription-plans/${r.toString() ? `?${r.toString()}` : ""}`, a = await this.httpService.get(s, {
3425
+ const s = `/subscription-plans/${r.toString() ? `?${r.toString()}` : ""}`, o = await this.httpService.get(s, {
3222
3426
  headers: t
3223
3427
  });
3224
3428
  return {
3225
- plans: a.data,
3226
- meta: a.meta
3429
+ plans: o.data,
3430
+ meta: o.meta
3227
3431
  };
3228
3432
  }
3229
3433
  async getSubscriptionPlanById(e) {
@@ -3252,7 +3456,7 @@ class It {
3252
3456
  });
3253
3457
  }
3254
3458
  }
3255
- class Ft {
3459
+ class zt {
3256
3460
  constructor(e) {
3257
3461
  this.httpService = e;
3258
3462
  }
@@ -3261,7 +3465,7 @@ class Ft {
3261
3465
  return await this.httpService.get("/health");
3262
3466
  }
3263
3467
  }
3264
- class Ht {
3468
+ class Ot {
3265
3469
  // Date string to Date object
3266
3470
  static toDate(e) {
3267
3471
  return new Date(e);
@@ -3384,44 +3588,44 @@ class Ht {
3384
3588
  }
3385
3589
  }
3386
3590
  export {
3387
- Ht as ApiMappers,
3388
- Te as AppApiService,
3389
- ht as AppProvider,
3390
- Re as AuthApiService,
3391
- yt as AuthProvider,
3392
- Pt as FeatureFlag,
3393
- He as FeatureFlagApiService,
3394
- bt as FeatureFlagProvider,
3395
- Ft as HealthApiService,
3396
- te as HttpService,
3397
- kt as LandingRoute,
3398
- Tt as LoginForm,
3399
- Et as MagicLinkForm,
3400
- Lt as MagicLinkVerify,
3401
- Rt as PasswordRecoveryForm,
3402
- Ct as PermissionApiService,
3403
- vt as Protected,
3404
- St as ProtectedRoute,
3405
- pe as RoleApiService,
3406
- Le as SessionManager,
3407
- Mt as SignupForm,
3408
- De as SubscriptionApiService,
3409
- At as SubscriptionGuard,
3410
- It as SubscriptionPlanApiService,
3411
- wt as SubscriptionProvider,
3412
- fe as TenantApiService,
3413
- pt as TenantProvider,
3414
- xt as TenantRoute,
3415
- Ce as UserApiService,
3416
- se as UserType,
3417
- gt as useApi,
3418
- ne as useApp,
3419
- ie as useAuth,
3420
- $e as useFeatureFlags,
3421
- mt as useSettings,
3422
- Be as useSubscription,
3423
- ge as useTenant,
3424
- re as useTenantInfo,
3425
- ft as useTenantSettings
3591
+ Ot as ApiMappers,
3592
+ be as AppApiService,
3593
+ St as AppProvider,
3594
+ Ne as AuthApiService,
3595
+ Tt as AuthProvider,
3596
+ Ft as FeatureFlag,
3597
+ ze as FeatureFlagApiService,
3598
+ Pt as FeatureFlagProvider,
3599
+ zt as HealthApiService,
3600
+ re as HttpService,
3601
+ Rt as LandingRoute,
3602
+ $t as LoginForm,
3603
+ Ht as MagicLinkForm,
3604
+ Nt as MagicLinkVerify,
3605
+ Bt as PasswordRecoveryForm,
3606
+ Ut as PermissionApiService,
3607
+ It as Protected,
3608
+ Et as ProtectedRoute,
3609
+ Se as RoleApiService,
3610
+ ye as SessionManager,
3611
+ Dt as SignupForm,
3612
+ je as SubscriptionApiService,
3613
+ Lt as SubscriptionGuard,
3614
+ qt as SubscriptionPlanApiService,
3615
+ Mt as SubscriptionProvider,
3616
+ ce as TenantApiService,
3617
+ xt as TenantProvider,
3618
+ Ct as TenantRoute,
3619
+ Be as UserApiService,
3620
+ ie as UserType,
3621
+ vt as useApi,
3622
+ he as useApp,
3623
+ oe as useAuth,
3624
+ Oe as useFeatureFlags,
3625
+ At as useSettings,
3626
+ Ve as useSubscription,
3627
+ fe as useTenant,
3628
+ se as useTenantInfo,
3629
+ kt as useTenantSettings
3426
3630
  };
3427
3631
  //# sourceMappingURL=index.es.js.map