@edgespark/web 0.0.1-beta.2 → 0.0.1-beta.4

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,171 +1,210 @@
1
- import { createAuthClient as te } from "better-auth/client";
2
- class U extends Error {
3
- constructor(e, s) {
4
- super(s), this.name = "EdgeSparkError", this.code = e;
1
+ import { createAuthClient as le } from "better-auth/client";
2
+ class x extends Error {
3
+ constructor(e, t) {
4
+ super(t), this.name = "EdgeSparkError", this.code = e;
5
5
  }
6
6
  }
7
- class u extends U {
7
+ class d extends x {
8
8
  constructor(e) {
9
9
  super("CONFIG_ERROR", e), this.name = "EdgeSparkConfigError";
10
10
  }
11
11
  }
12
- class K extends U {
12
+ class ne extends x {
13
13
  constructor(e) {
14
14
  super("RUNTIME_ERROR", e), this.name = "EdgeSparkRuntimeError";
15
15
  }
16
16
  }
17
- class w extends U {
18
- constructor(e, s) {
19
- super((s == null ? void 0 : s.code) ?? "AUTH_ERROR", e), this.name = "EdgeSparkAuthError", this.cause = s == null ? void 0 : s.cause, this.status = s == null ? void 0 : s.status;
17
+ class m extends x {
18
+ constructor(e, t) {
19
+ super((t == null ? void 0 : t.code) ?? "AUTH_ERROR", e), this.name = "EdgeSparkAuthError", this.cause = t == null ? void 0 : t.cause, this.status = t == null ? void 0 : t.status;
20
20
  }
21
21
  }
22
- function J() {
22
+ function re() {
23
23
  if (typeof window > "u" || typeof document > "u")
24
- throw new K(
24
+ throw new ne(
25
25
  "@edgespark/web is browser-only. Create the client from a real browser runtime."
26
26
  );
27
27
  }
28
- function I() {
29
- return J(), window.location.origin;
28
+ function H() {
29
+ return re(), window.location.origin;
30
30
  }
31
- function se(t) {
32
- return t instanceof URL ? t : typeof t == "string" ? new URL(t, window.location.href) : new URL(t.url, window.location.href);
31
+ function de(s) {
32
+ return s instanceof URL ? s : typeof s == "string" ? new URL(s, window.location.href) : new URL(s.url, window.location.href);
33
33
  }
34
- function ie(t) {
35
- if (t.origin !== I())
36
- throw new u(
37
- `Cross-origin requests are not supported by this SDK. Received ${t.origin}, expected ${I()}.`
34
+ function ce(s) {
35
+ if (s.origin !== H())
36
+ throw new d(
37
+ `Cross-origin requests are not supported by this SDK. Received ${s.origin}, expected ${H()}.`
38
38
  );
39
39
  }
40
- function ne() {
40
+ function ue() {
41
41
  return {
42
- async fetch(t, e) {
43
- const s = se(t);
44
- return ie(s), fetch(t, {
42
+ async fetch(s, e) {
43
+ const t = de(s);
44
+ return ce(t), fetch(s, {
45
45
  ...e,
46
46
  credentials: "include"
47
47
  });
48
48
  }
49
49
  };
50
50
  }
51
- const Z = "/api/_es/auth";
52
- function Q(t) {
53
- return te({
54
- baseURL: I(),
55
- basePath: Z,
56
- ...t != null && t.disableDefaultRedirectPlugin ? { disableDefaultFetchPlugins: !0 } : {},
51
+ const oe = "/api/_es/auth";
52
+ function ae(s) {
53
+ return le({
54
+ baseURL: H(),
55
+ basePath: oe,
56
+ ...s != null && s.disableDefaultRedirectPlugin ? { disableDefaultFetchPlugins: !0 } : {},
57
57
  fetchOptions: {
58
58
  credentials: "include"
59
59
  }
60
60
  });
61
61
  }
62
- function P(t) {
63
- var e, s;
64
- return (s = (e = t.$store) == null ? void 0 : e.atoms) == null ? void 0 : s.session;
62
+ function v(s) {
63
+ var e, t;
64
+ return (t = (e = s.$store) == null ? void 0 : e.atoms) == null ? void 0 : t.session;
65
+ }
66
+ function B(s) {
67
+ if (s instanceof m)
68
+ return s;
69
+ const e = s;
70
+ return new m(
71
+ (e == null ? void 0 : e.message) || "Failed to load the current session.",
72
+ {
73
+ code: (e == null ? void 0 : e.code) ?? "SESSION_LOOKUP_FAILED",
74
+ cause: s,
75
+ status: e == null ? void 0 : e.status
76
+ }
77
+ );
65
78
  }
66
- async function oe(t) {
79
+ async function he(s) {
67
80
  var e;
68
- await ((e = P(t)) == null ? void 0 : e.get().refetch());
81
+ await ((e = v(s)) == null ? void 0 : e.get().refetch());
69
82
  }
70
- function ae() {
71
- const t = Q(), e = 2, s = 500;
72
- let i = null;
73
- const o = () => (i || (i = (async () => {
74
- for (let l = 0; l <= e; l++) {
75
- if (!(await t.getSession()).error) return;
76
- l < e && await new Promise((d) => setTimeout(d, s));
83
+ function me() {
84
+ const s = ae(), e = 2, t = 500;
85
+ let i = null, r = !1;
86
+ const o = () => {
87
+ var c;
88
+ return r ? Promise.resolve(((c = v(s)) == null ? void 0 : c.get().data) ?? null) : (i || (i = (async () => {
89
+ var P, L, y, S;
90
+ let a = !1, l = null;
91
+ try {
92
+ for (let p = 0; p <= e; p++) {
93
+ const f = await s.getSession(), b = ((P = v(s)) == null ? void 0 : P.get().data) ?? null;
94
+ if ((L = f.data) != null && L.session && ((y = f.data) != null && y.user))
95
+ return r = !0, f.data;
96
+ if (b != null && b.session && (b != null && b.user))
97
+ return r = !0, b;
98
+ if (f.error ? l = f.error : a = !0, !f.error && p < e) {
99
+ await new Promise((A) => setTimeout(A, t));
100
+ continue;
101
+ }
102
+ p < e && await new Promise((A) => setTimeout(A, t));
103
+ }
104
+ if (!a)
105
+ throw i = null, new m("Failed to load the current session.", {
106
+ code: "SESSION_LOOKUP_FAILED",
107
+ cause: l
108
+ });
109
+ const h = ((S = v(s)) == null ? void 0 : S.get().data) ?? null;
110
+ return r = !0, h;
111
+ } catch (h) {
112
+ throw i = null, B(h);
113
+ }
114
+ })()), i);
115
+ };
116
+ o().catch(() => {
117
+ });
118
+ const u = async () => {
119
+ var c, a;
120
+ try {
121
+ const l = await s.getSession();
122
+ if ((c = l.data) != null && c.session && ((a = l.data) != null && a.user))
123
+ return l.data;
124
+ throw l.error ? B(l.error) : new m("No authenticated session is available.", {
125
+ code: "UNAUTHENTICATED"
126
+ });
127
+ } catch (l) {
128
+ throw B(l);
77
129
  }
78
- i = null;
79
- })()), i.then(() => {
80
- var l;
81
- return ((l = P(t)) == null ? void 0 : l.get().data) ?? null;
82
- }));
83
- o();
84
- const a = async () => {
85
- var r, d;
86
- const l = await t.getSession();
87
- if ((r = l.data) != null && r.session && ((d = l.data) != null && d.user))
88
- return l.data;
89
- throw new w("No authenticated session is available.", {
90
- code: "UNAUTHENTICATED",
91
- cause: l.error
92
- });
93
- }, c = (l) => {
94
- let r = !1, d = !1, A;
95
- const B = (m) => {
96
- m !== A && (A = m, l(m));
130
+ }, w = (c) => {
131
+ let a = !1, l = !1, P;
132
+ const L = (h) => {
133
+ h !== P && (P = h, c(h));
97
134
  };
98
- o().then((m) => {
99
- r || (d = !0, B(m));
135
+ o().then((h) => {
136
+ a || (l = !0, L(h));
137
+ }).catch(() => {
138
+ a || (l = !0);
100
139
  });
101
- const M = P(t);
102
- if (!M)
140
+ const y = v(s);
141
+ if (!y)
103
142
  return () => {
104
- r = !0;
143
+ a = !0;
105
144
  };
106
- const X = M.subscribe((m) => {
107
- if (r || !d)
145
+ const S = y.subscribe((h) => {
146
+ if (a || !l || h.error && !h.data)
108
147
  return;
109
- const ee = m.data ?? null;
110
- B(ee);
148
+ const p = h.data ?? null;
149
+ L(p);
111
150
  });
112
151
  return () => {
113
- r = !0, X();
152
+ a = !0, S();
114
153
  };
115
- }, h = async (...l) => {
116
- var d;
117
- const r = await t.signOut(...l);
118
- if (r && typeof r == "object" && "error" in r && r.error)
119
- return r;
154
+ }, E = async (...c) => {
155
+ var l;
156
+ const a = await s.signOut(...c);
157
+ if (a && typeof a == "object" && "error" in a && a.error)
158
+ return a;
120
159
  try {
121
- await ((d = P(t)) == null ? void 0 : d.get().refetch());
160
+ await ((l = v(s)) == null ? void 0 : l.get().refetch());
122
161
  } catch {
123
162
  }
124
- return r;
163
+ return a;
125
164
  };
126
- return new Proxy(t, {
127
- get(l, r, d) {
128
- return r === "requireSession" ? a : r === "onSessionChange" ? c : r === "signOut" ? h : Reflect.get(l, r, d);
165
+ return new Proxy(s, {
166
+ get(c, a, l) {
167
+ return a === "requireSession" ? u : a === "onSessionChange" ? w : a === "signOut" ? E : Reflect.get(c, a, l);
129
168
  }
130
169
  });
131
170
  }
132
- function re() {
133
- return Q({ disableDefaultRedirectPlugin: !0 });
171
+ function we() {
172
+ return ae({ disableDefaultRedirectPlugin: !0 });
134
173
  }
135
- function k(t) {
174
+ function k(s) {
136
175
  const e = (() => {
137
- if (t instanceof URL)
138
- return t;
139
- const s = t.trim();
140
- if (!s)
141
- throw new u("redirectTo must not be an empty string.");
176
+ if (s instanceof URL)
177
+ return s;
178
+ const t = s.trim();
179
+ if (!t)
180
+ throw new d("redirectTo must not be an empty string.");
142
181
  try {
143
- return new URL(s, window.location.href);
182
+ return new URL(t, window.location.href);
144
183
  } catch {
145
- throw new u(
146
- `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(t)}`
184
+ throw new d(
185
+ `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(s)}`
147
186
  );
148
187
  }
149
188
  })();
150
189
  if (e.protocol !== "http:" && e.protocol !== "https:")
151
- throw new u(
190
+ throw new d(
152
191
  `redirectTo must resolve to an http(s) URL. Received protocol: ${e.protocol}`
153
192
  );
154
193
  return e;
155
194
  }
156
- function le(t, e) {
195
+ function be(s, e) {
157
196
  return e ? {
158
- common: { ...t.common, ...e.common },
159
- signIn: { ...t.signIn, ...e.signIn },
160
- signUp: { ...t.signUp, ...e.signUp },
161
- verifyEmail: { ...t.verifyEmail, ...e.verifyEmail },
162
- forgotPassword: { ...t.forgotPassword, ...e.forgotPassword },
163
- resetPassword: { ...t.resetPassword, ...e.resetPassword },
164
- oauth: { ...t.oauth, ...e.oauth },
165
- errors: { ...t.errors, ...e.errors }
166
- } : t;
197
+ common: { ...s.common, ...e.common },
198
+ signIn: { ...s.signIn, ...e.signIn },
199
+ signUp: { ...s.signUp, ...e.signUp },
200
+ verifyEmail: { ...s.verifyEmail, ...e.verifyEmail },
201
+ forgotPassword: { ...s.forgotPassword, ...e.forgotPassword },
202
+ resetPassword: { ...s.resetPassword, ...e.resetPassword },
203
+ oauth: { ...s.oauth, ...e.oauth },
204
+ errors: { ...s.errors, ...e.errors }
205
+ } : s;
167
206
  }
168
- const y = {
207
+ const U = {
169
208
  common: {
170
209
  loading: "Loading sign-in…",
171
210
  redirecting: "Redirecting…",
@@ -228,7 +267,7 @@ const y = {
228
267
  invalidCode: "Enter the 6-digit verification code.",
229
268
  generic: "Something went wrong. Please try again."
230
269
  }
231
- }, L = {
270
+ }, M = {
232
271
  common: {
233
272
  loading: "加载中…",
234
273
  redirecting: "跳转中…",
@@ -291,7 +330,7 @@ const y = {
291
330
  invalidCode: "请输入 6 位验证码",
292
331
  generic: "出现错误,请稍后重试"
293
332
  }
294
- }, V = {
333
+ }, W = {
295
334
  common: {
296
335
  loading: "サインインを読み込み中…",
297
336
  redirecting: "リダイレクト中…",
@@ -354,7 +393,7 @@ const y = {
354
393
  invalidCode: "6桁の認証コードを入力してください",
355
394
  generic: "エラーが発生しました。もう一度お試しください"
356
395
  }
357
- }, O = {
396
+ }, j = {
358
397
  common: {
359
398
  loading: "로그인 로딩 중…",
360
399
  redirecting: "리디렉션 중…",
@@ -417,7 +456,7 @@ const y = {
417
456
  invalidCode: "6자리 인증 코드를 입력해 주세요",
418
457
  generic: "문제가 발생했습니다. 다시 시도해 주세요"
419
458
  }
420
- }, E = {
459
+ }, O = {
421
460
  common: {
422
461
  loading: "Cargando inicio de sesión…",
423
462
  redirecting: "Redirigiendo…",
@@ -480,7 +519,7 @@ const y = {
480
519
  invalidCode: "Ingresa el código de verificación de 6 dígitos.",
481
520
  generic: "Algo salió mal. Por favor, inténtalo de nuevo."
482
521
  }
483
- }, z = {
522
+ }, G = {
484
523
  common: {
485
524
  loading: "Carregando login…",
486
525
  redirecting: "Redirecionando…",
@@ -543,7 +582,7 @@ const y = {
543
582
  invalidCode: "Insira o código de verificação de 6 dígitos.",
544
583
  generic: "Algo deu errado. Por favor, tente novamente."
545
584
  }
546
- }, F = {
585
+ }, Y = {
547
586
  common: {
548
587
  loading: "Chargement de la connexion…",
549
588
  redirecting: "Redirection…",
@@ -606,7 +645,7 @@ const y = {
606
645
  invalidCode: "Saisissez le code de vérification à 6 chiffres.",
607
646
  generic: "Une erreur est survenue. Veuillez réessayer."
608
647
  }
609
- }, q = {
648
+ }, K = {
610
649
  common: {
611
650
  loading: "Anmeldung wird geladen…",
612
651
  redirecting: "Weiterleitung…",
@@ -669,7 +708,7 @@ const y = {
669
708
  invalidCode: "Geben Sie den 6-stelligen Bestätigungscode ein.",
670
709
  generic: "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
671
710
  }
672
- }, N = {
711
+ }, J = {
673
712
  common: {
674
713
  loading: "Caricamento accesso…",
675
714
  redirecting: "Reindirizzamento…",
@@ -732,7 +771,7 @@ const y = {
732
771
  invalidCode: "Inserisci il codice di verifica a 6 cifre.",
733
772
  generic: "Qualcosa è andato storto. Riprova."
734
773
  }
735
- }, D = {
774
+ }, Z = {
736
775
  common: {
737
776
  loading: "Загрузка входа…",
738
777
  redirecting: "Перенаправление…",
@@ -795,7 +834,7 @@ const y = {
795
834
  invalidCode: "Введите 6-значный код подтверждения.",
796
835
  generic: "Произошла ошибка. Пожалуйста, попробуйте снова."
797
836
  }
798
- }, x = {
837
+ }, Q = {
799
838
  common: {
800
839
  loading: "جارٍ تحميل تسجيل الدخول…",
801
840
  redirecting: "جارٍ إعادة التوجيه…",
@@ -858,7 +897,7 @@ const y = {
858
897
  invalidCode: "يرجى إدخال رمز التحقّق المكوّن من 6 أرقام.",
859
898
  generic: "حدث خطأ. يرجى المحاولة مرة أخرى."
860
899
  }
861
- }, H = {
900
+ }, X = {
862
901
  common: {
863
902
  loading: "सधाइन की जुलातीअ लोड हो रही है…",
864
903
  redirecting: "रीडायरेक्ट हो रहا है…",
@@ -921,61 +960,70 @@ const y = {
921
960
  invalidCode: "कृपया 6 अंकों का सत्यापन कोड दर्ज करें।",
922
961
  generic: "कुछ गलत हो गई। कृपया फिर से प्रयास करें।"
923
962
  }
924
- }, W = {
925
- en: y,
926
- "en-US": y,
927
- zh: L,
928
- "zh-CN": L,
929
- "zh-TW": L,
930
- ja: V,
931
- "ja-JP": V,
932
- ko: O,
933
- "ko-KR": O,
934
- es: E,
935
- "es-ES": E,
936
- "es-MX": E,
937
- pt: z,
938
- "pt-BR": z,
939
- fr: F,
940
- "fr-FR": F,
941
- de: q,
942
- "de-DE": q,
943
- it: N,
944
- "it-IT": N,
945
- ru: D,
946
- "ru-RU": D,
947
- ar: x,
948
- "ar-SA": x,
949
- hi: H,
950
- "hi-IN": H
963
+ }, ee = {
964
+ en: U,
965
+ "en-US": U,
966
+ zh: M,
967
+ "zh-CN": M,
968
+ "zh-TW": M,
969
+ ja: W,
970
+ "ja-JP": W,
971
+ ko: j,
972
+ "ko-KR": j,
973
+ es: O,
974
+ "es-ES": O,
975
+ "es-MX": O,
976
+ pt: G,
977
+ "pt-BR": G,
978
+ fr: Y,
979
+ "fr-FR": Y,
980
+ de: K,
981
+ "de-DE": K,
982
+ it: J,
983
+ "it-IT": J,
984
+ ru: Z,
985
+ "ru-RU": Z,
986
+ ar: Q,
987
+ "ar-SA": Q,
988
+ hi: X,
989
+ "hi-IN": X
951
990
  };
952
- function de() {
991
+ function pe() {
953
992
  if (typeof navigator > "u")
954
- return y;
955
- const t = navigator.languages ?? [navigator.language];
956
- for (const e of t) {
957
- const s = W[e] ?? W[e.split("-")[0]];
958
- if (s) return s;
993
+ return U;
994
+ const s = navigator.languages ?? [navigator.language];
995
+ for (const e of s) {
996
+ const t = ee[e] ?? ee[e.split("-")[0]];
997
+ if (t) return t;
959
998
  }
960
- return y;
999
+ return U;
961
1000
  }
962
- function S(t, e = "Authentication failed.") {
963
- if (t instanceof w)
964
- return t;
965
- if (typeof t == "object" && t !== null) {
966
- const s = t;
967
- return new w(s.message || e, {
968
- code: s.code,
969
- status: s.status,
970
- cause: t
1001
+ function V(s, e = "Authentication failed.") {
1002
+ if (s instanceof m)
1003
+ return s;
1004
+ if (typeof s == "object" && s !== null) {
1005
+ const t = s;
1006
+ return new m(t.message || e, {
1007
+ code: t.code,
1008
+ status: t.status,
1009
+ cause: s
971
1010
  });
972
1011
  }
973
- return typeof t == "string" ? new w(t) : new w(e, { cause: t });
1012
+ return typeof s == "string" ? new m(s) : new m(e, { cause: s });
974
1013
  }
975
- async function j(t) {
976
- var s, i;
977
- const e = await t.getSession();
978
- return (s = e.data) != null && s.user && ((i = e.data) != null && i.session) ? {
1014
+ async function _(s) {
1015
+ var t, i;
1016
+ const e = await s.getSession();
1017
+ if (e.error)
1018
+ throw new m(
1019
+ e.error.message || "Failed to load the current session.",
1020
+ {
1021
+ code: e.error.code ?? "SESSION_LOOKUP_FAILED",
1022
+ status: e.error.status,
1023
+ cause: e.error
1024
+ }
1025
+ );
1026
+ return (t = e.data) != null && t.user && ((i = e.data) != null && i.session) ? {
979
1027
  user: e.data.user,
980
1028
  session: e.data
981
1029
  } : {
@@ -983,7 +1031,7 @@ async function j(t) {
983
1031
  session: null
984
1032
  };
985
1033
  }
986
- const ce = "data-edgespark-auth", n = "edgespark-auth", C = "es_auth_completion", p = "es_auth_email", G = "oauth", g = "verify-sign-in", b = "verify-sign-up", _ = {
1034
+ const fe = "data-edgespark-auth", n = "edgespark-auth", F = "es_auth_completion", C = "es_auth_email", te = "oauth", T = "verify-sign-in", g = "verify-sign-up", se = 200, z = 2, N = {
987
1035
  google: "Google",
988
1036
  apple: "Apple",
989
1037
  microsoft: "Microsoft",
@@ -991,24 +1039,24 @@ const ce = "data-edgespark-auth", n = "edgespark-auth", C = "es_auth_completion"
991
1039
  gitlab: "GitLab",
992
1040
  discord: "Discord"
993
1041
  };
994
- function R(t) {
995
- return "redirectTo" in t;
1042
+ function I(s) {
1043
+ return "redirectTo" in s;
996
1044
  }
997
- function T(t) {
998
- return "onSuccess" in t && !("redirectTo" in t);
1045
+ function q(s) {
1046
+ return "onSuccess" in s && !("redirectTo" in s);
999
1047
  }
1000
- function $(t) {
1001
- return !t || typeof t != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim());
1048
+ function D(s) {
1049
+ return !s || typeof s != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s.trim());
1002
1050
  }
1003
- function ue(t) {
1004
- return /^\d{6}$/.test(t.trim());
1051
+ function ge(s) {
1052
+ return /^\d{6}$/.test(s.trim());
1005
1053
  }
1006
- function he(t) {
1007
- return t === "email" || t === "name" || t === "password" || t === "confirmPassword" || t === "code" || t === "newPassword";
1054
+ function ve(s) {
1055
+ return s === "email" || s === "name" || s === "password" || s === "confirmPassword" || s === "code" || s === "newPassword";
1008
1056
  }
1009
- class me {
1010
- constructor(e, s, i, o, a) {
1011
- if (this.container = e, this.auth = s, this.options = i, this.loadConfig = o, this.runtimeOptions = a, this.state = {
1057
+ class Pe {
1058
+ constructor(e, t, i, r, o) {
1059
+ if (this.container = e, this.auth = t, this.options = i, this.loadConfig = r, this.runtimeOptions = o, this.state = {
1012
1060
  view: "loading",
1013
1061
  busy: !0,
1014
1062
  busyLabel: void 0,
@@ -1021,27 +1069,27 @@ class me {
1021
1069
  code: "",
1022
1070
  newPassword: ""
1023
1071
  }, this.destroyed = !1, this.terminalActionInProgress = !1, this.config = null, this.countdownUntil = null, this.countdownTimer = null, this.pendingFocusSnapshot = null, this.focusRestoreTimer = null, this.verificationCompletionAction = null, !(e instanceof HTMLElement))
1024
- throw new u("authUI.mount(container, options) requires a real HTMLElement container.");
1025
- this.labels = le(de(), i.labels), this.root = document.createElement("div"), this.root.setAttribute(ce, ""), e.innerHTML = "", e.appendChild(this.root), this.render(), this.initialize();
1072
+ throw new d("authUI.mount(container, options) requires a real HTMLElement container.");
1073
+ this.labels = be(pe(), i.labels), this.root = document.createElement("div"), this.root.setAttribute(fe, ""), e.innerHTML = "", e.appendChild(this.root), this.render(), this.initialize();
1026
1074
  }
1027
1075
  destroy() {
1028
1076
  this.destroyed || (this.destroyed = !0, this.clearCountdown(), this.clearFocusRestoreTimer(), this.container.innerHTML = "");
1029
1077
  }
1030
1078
  async initialize() {
1031
1079
  try {
1032
- const e = this.consumeManagedReturnContext(), [s, i] = await Promise.all([
1080
+ const e = this.consumeManagedReturnContext(), [t, i] = await Promise.all([
1033
1081
  this.loadConfig(),
1034
- j(this.auth)
1082
+ this.readMountSession(e)
1035
1083
  ]);
1036
1084
  if (this.destroyed)
1037
1085
  return;
1038
- if (this.config = s, i.user && i.session) {
1086
+ if (this.config = t, i.user && i.session) {
1039
1087
  switch (e.marker) {
1040
- case G:
1041
- case g:
1088
+ case te:
1089
+ case T:
1042
1090
  await this.completeAuth("sign-in", i);
1043
1091
  return;
1044
- case b:
1092
+ case g:
1045
1093
  await this.completeAuth("sign-up", i);
1046
1094
  return;
1047
1095
  default:
@@ -1057,6 +1105,27 @@ class me {
1057
1105
  this.handleError(e, "Failed to load the authentication UI.");
1058
1106
  }
1059
1107
  }
1108
+ async readMountSession(e) {
1109
+ if (!e.marker)
1110
+ return _(this.auth);
1111
+ let t = null;
1112
+ for (let i = 0; i <= z; i++) {
1113
+ try {
1114
+ const r = await _(this.auth);
1115
+ if (r.user && r.session)
1116
+ return r;
1117
+ } catch (r) {
1118
+ t = r;
1119
+ }
1120
+ i < z && await new Promise((r) => setTimeout(r, se));
1121
+ }
1122
+ if (t)
1123
+ throw t;
1124
+ return {
1125
+ user: null,
1126
+ session: null
1127
+ };
1128
+ }
1060
1129
  render() {
1061
1130
  if (this.destroyed)
1062
1131
  return;
@@ -1112,8 +1181,8 @@ class me {
1112
1181
  }
1113
1182
  }
1114
1183
  renderSignInView() {
1115
- var i, o;
1116
- const e = this.renderOAuthProviders(), s = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1184
+ var i, r;
1185
+ const e = this.renderOAuthProviders(), t = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1117
1186
  return `
1118
1187
  <section class="${n}__section">
1119
1188
  <header class="${n}__header">
@@ -1121,8 +1190,8 @@ class me {
1121
1190
  <p class="${n}__copy">${this.escape(this.labels.signIn.subtitle)}</p>
1122
1191
  </header>
1123
1192
  ${e}
1124
- ${e && s ? `<div class="${n}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1125
- ${s ? `
1193
+ ${e && t ? `<div class="${n}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1194
+ ${t ? `
1126
1195
  <form class="${n}__form" data-view="sign-in" novalidate>
1127
1196
  ${this.renderInput("email", this.labels.signIn.emailLabel, "email", this.state.email, "email")}
1128
1197
  ${this.renderInput("password", this.labels.signIn.passwordLabel, "password", this.state.password, "current-password")}
@@ -1136,7 +1205,7 @@ class me {
1136
1205
  ${this.escape(this.labels.signIn.forgotPassword)}
1137
1206
  </button>
1138
1207
  ` : ""}
1139
- ${(o = this.config) != null && o.disableSignUp ? "" : `
1208
+ ${(r = this.config) != null && r.disableSignUp ? "" : `
1140
1209
  <p class="${n}__meta">
1141
1210
  ${this.escape(this.labels.signIn.signUpPrompt)}
1142
1211
  <button class="${n}__link" type="button" data-action="switch-sign-up" ${this.state.busy ? "disabled" : ""}>
@@ -1251,48 +1320,48 @@ class me {
1251
1320
  `;
1252
1321
  }
1253
1322
  renderOAuthProviders() {
1254
- var s;
1255
- const e = ((s = this.config) == null ? void 0 : s.oauthProviders) ?? [];
1323
+ var t;
1324
+ const e = ((t = this.config) == null ? void 0 : t.oauthProviders) ?? [];
1256
1325
  return e.length === 0 ? "" : `
1257
1326
  <div class="${n}__stack">
1258
1327
  ${e.map((i) => `
1259
1328
  <button class="${n}__button ${n}__button--secondary" type="button" data-action="oauth" data-provider="${i}" ${this.state.busy ? "disabled" : ""}>
1260
- ${this.escape(`${this.labels.oauth.continueWith} ${_[i]}`)}
1329
+ ${this.escape(`${this.labels.oauth.continueWith} ${N[i]}`)}
1261
1330
  </button>
1262
1331
  `).join("")}
1263
1332
  </div>
1264
1333
  `;
1265
1334
  }
1266
- renderInput(e, s, i, o, a) {
1335
+ renderInput(e, t, i, r, o) {
1267
1336
  return `
1268
1337
  <label class="${n}__field">
1269
- <span class="${n}__label">${this.escape(s)}</span>
1338
+ <span class="${n}__label">${this.escape(t)}</span>
1270
1339
  <input
1271
1340
  class="${n}__input"
1272
1341
  name="${this.escape(e)}"
1273
1342
  type="${this.escape(i)}"
1274
- value="${this.escape(o)}"
1275
- autocomplete="${this.escape(a)}"
1343
+ value="${this.escape(r)}"
1344
+ autocomplete="${this.escape(o)}"
1276
1345
  ${this.state.busy ? "disabled" : ""}
1277
1346
  />
1278
1347
  </label>
1279
1348
  `;
1280
1349
  }
1281
1350
  bindDOM() {
1282
- this.root.querySelectorAll("form[data-view]").forEach((o) => {
1283
- o.addEventListener("submit", (a) => {
1284
- a.preventDefault();
1285
- const c = o.dataset.view;
1286
- c === "sign-in" && this.handleSignIn(), c === "sign-up" && this.handleSignUp(), c === "forgot-password" && this.handleForgotPassword(), c === "reset-password" && this.handleResetPassword();
1351
+ this.root.querySelectorAll("form[data-view]").forEach((r) => {
1352
+ r.addEventListener("submit", (o) => {
1353
+ o.preventDefault();
1354
+ const u = r.dataset.view;
1355
+ u === "sign-in" && this.handleSignIn(), u === "sign-up" && this.handleSignUp(), u === "forgot-password" && this.handleForgotPassword(), u === "reset-password" && this.handleResetPassword();
1287
1356
  });
1288
- }), this.root.querySelectorAll("input[name]").forEach((o) => {
1289
- o.addEventListener("input", () => {
1290
- he(o.name) && (this.state[o.name] = o.value);
1357
+ }), this.root.querySelectorAll("input[name]").forEach((r) => {
1358
+ r.addEventListener("input", () => {
1359
+ ve(r.name) && (this.state[r.name] = r.value);
1291
1360
  });
1292
- }), this.root.querySelectorAll("[data-action]").forEach((o) => {
1293
- o.addEventListener("click", () => {
1294
- const a = o.dataset.action;
1295
- a === "switch-sign-up" && this.switchView("sign-up"), a === "switch-sign-in" && this.switchView("sign-in"), a === "forgot-password" && this.switchView("forgot-password"), a === "resend-verification" && this.resendVerificationEmail(), a === "use-different-email" && this.switchView(this.verificationCompletionAction === "sign-in" ? "sign-in" : "sign-up"), a === "resend-reset-code" && this.resendResetCode(), a === "oauth" && this.handleOAuthSignIn(o.dataset.provider);
1361
+ }), this.root.querySelectorAll("[data-action]").forEach((r) => {
1362
+ r.addEventListener("click", () => {
1363
+ const o = r.dataset.action;
1364
+ o === "switch-sign-up" && this.switchView("sign-up"), o === "switch-sign-in" && this.switchView("sign-in"), o === "forgot-password" && this.switchView("forgot-password"), o === "resend-verification" && this.resendVerificationEmail(), o === "use-different-email" && this.switchView(this.verificationCompletionAction === "sign-in" ? "sign-in" : "sign-up"), o === "resend-reset-code" && this.resendResetCode(), o === "oauth" && this.handleOAuthSignIn(r.dataset.provider);
1296
1365
  });
1297
1366
  });
1298
1367
  }
@@ -1300,7 +1369,7 @@ class me {
1300
1369
  this.clearCountdown(), e !== "verify-email" && (this.verificationCompletionAction = null), this.state.view = e, this.state.error = null, this.state.notice = null, this.state.busy = !1, this.state.busyLabel = void 0, this.terminalActionInProgress = !1, this.render();
1301
1370
  }
1302
1371
  async handleSignIn() {
1303
- if (!$(this.state.email)) {
1372
+ if (!D(this.state.email)) {
1304
1373
  this.failValidation(this.labels.errors.invalidEmail);
1305
1374
  return;
1306
1375
  }
@@ -1312,7 +1381,7 @@ class me {
1312
1381
  const e = await this.auth.signIn.email({
1313
1382
  email: this.state.email.trim(),
1314
1383
  password: this.state.password,
1315
- callbackURL: this.getManagedReturnURL(g, this.state.email.trim())
1384
+ callbackURL: this.getManagedReturnURL(T, this.state.email.trim())
1316
1385
  });
1317
1386
  if (e.error)
1318
1387
  throw e.error;
@@ -1320,12 +1389,12 @@ class me {
1320
1389
  });
1321
1390
  }
1322
1391
  async handleSignUp() {
1323
- var e, s;
1392
+ var e, t;
1324
1393
  if (!this.state.name.trim()) {
1325
1394
  this.failValidation(this.labels.errors.requiredField);
1326
1395
  return;
1327
1396
  }
1328
- if (!$(this.state.email)) {
1397
+ if (!D(this.state.email)) {
1329
1398
  this.failValidation(this.labels.errors.invalidEmail);
1330
1399
  return;
1331
1400
  }
@@ -1335,7 +1404,7 @@ class me {
1335
1404
  }
1336
1405
  if (this.state.password.length < (((e = this.config) == null ? void 0 : e.minPasswordLength) ?? 8)) {
1337
1406
  this.failValidation(
1338
- this.labels.errors.passwordTooShort.replace("{min}", String(((s = this.config) == null ? void 0 : s.minPasswordLength) ?? 8))
1407
+ this.labels.errors.passwordTooShort.replace("{min}", String(((t = this.config) == null ? void 0 : t.minPasswordLength) ?? 8))
1339
1408
  );
1340
1409
  return;
1341
1410
  }
@@ -1344,16 +1413,16 @@ class me {
1344
1413
  return;
1345
1414
  }
1346
1415
  await this.runAction("Creating account…", async () => {
1347
- var o;
1416
+ var r;
1348
1417
  const i = await this.auth.signUp.email({
1349
1418
  name: this.state.name.trim(),
1350
1419
  email: this.state.email.trim(),
1351
1420
  password: this.state.password,
1352
- callbackURL: this.getManagedReturnURL(b, this.state.email.trim())
1421
+ callbackURL: this.getManagedReturnURL(g, this.state.email.trim())
1353
1422
  });
1354
1423
  if (i.error)
1355
1424
  throw i.error;
1356
- if ((o = this.config) != null && o.requireEmailVerification) {
1425
+ if ((r = this.config) != null && r.requireEmailVerification) {
1357
1426
  this.verificationCompletionAction = "sign-up", this.state.view = "verify-email", this.state.notice = "Check your inbox to verify your email address.", this.startCountdown();
1358
1427
  return;
1359
1428
  }
@@ -1361,28 +1430,28 @@ class me {
1361
1430
  });
1362
1431
  }
1363
1432
  async handleOAuthSignIn(e) {
1364
- await this.runAction(`Redirecting to ${_[e]}…`, async () => {
1365
- const s = await this.auth.signIn.social({
1433
+ await this.runAction(`Redirecting to ${N[e]}…`, async () => {
1434
+ const t = await this.auth.signIn.social({
1366
1435
  provider: e,
1367
1436
  callbackURL: this.getManagedReturnURL("oauth"),
1368
1437
  errorCallbackURL: this.getManagedReturnURL("oauth")
1369
1438
  });
1370
- if (s.error)
1371
- throw s.error;
1372
- const i = this.extractRedirectURL(s.data);
1439
+ if (t.error)
1440
+ throw t.error;
1441
+ const i = this.extractRedirectURL(t.data);
1373
1442
  if (!i)
1374
- throw new u(`OAuth sign-in did not return a redirect URL for provider "${e}".`);
1375
- this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = `Opening ${_[e]}…`, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(i);
1443
+ throw new d(`OAuth sign-in did not return a redirect URL for provider "${e}".`);
1444
+ this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = `Opening ${N[e]}…`, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(i);
1376
1445
  });
1377
1446
  }
1378
1447
  async handleForgotPassword() {
1379
1448
  if (!this.canUsePasswordResetEmailOtp()) {
1380
1449
  this.handleError(
1381
- new u("Password reset via email OTP is not enabled for this project.")
1450
+ new d("Password reset via email OTP is not enabled for this project.")
1382
1451
  );
1383
1452
  return;
1384
1453
  }
1385
- if (!$(this.state.email)) {
1454
+ if (!D(this.state.email)) {
1386
1455
  this.failValidation(this.labels.errors.invalidEmail);
1387
1456
  return;
1388
1457
  }
@@ -1399,13 +1468,14 @@ class me {
1399
1468
  this.isCountdownActive() || await this.handleForgotPassword();
1400
1469
  }
1401
1470
  async handleResetPassword() {
1471
+ var e, t;
1402
1472
  if (!this.canUsePasswordResetEmailOtp()) {
1403
1473
  this.handleError(
1404
- new u("Password reset via email OTP is not enabled for this project.")
1474
+ new d("Password reset via email OTP is not enabled for this project.")
1405
1475
  );
1406
1476
  return;
1407
1477
  }
1408
- if (!ue(this.state.code)) {
1478
+ if (!ge(this.state.code)) {
1409
1479
  this.failValidation(this.labels.errors.invalidCode);
1410
1480
  return;
1411
1481
  }
@@ -1413,18 +1483,24 @@ class me {
1413
1483
  this.failValidation(this.labels.errors.requiredField);
1414
1484
  return;
1415
1485
  }
1486
+ if (this.state.newPassword.length < (((e = this.config) == null ? void 0 : e.minPasswordLength) ?? 8)) {
1487
+ this.failValidation(
1488
+ this.labels.errors.passwordTooShort.replace("{min}", String(((t = this.config) == null ? void 0 : t.minPasswordLength) ?? 8))
1489
+ );
1490
+ return;
1491
+ }
1416
1492
  if (this.state.newPassword !== this.state.confirmPassword) {
1417
1493
  this.failValidation(this.labels.errors.passwordMismatch);
1418
1494
  return;
1419
1495
  }
1420
1496
  await this.runAction("Updating password…", async () => {
1421
- const e = await this.passwordResetEndpoints().emailOtp.resetPassword({
1497
+ const i = await this.passwordResetEndpoints().emailOtp.resetPassword({
1422
1498
  email: this.state.email.trim(),
1423
1499
  otp: this.state.code.trim(),
1424
1500
  password: this.state.newPassword
1425
1501
  });
1426
- if (e.error)
1427
- throw e.error;
1502
+ if (i.error)
1503
+ throw i.error;
1428
1504
  await this.completePasswordReset();
1429
1505
  });
1430
1506
  }
@@ -1433,74 +1509,118 @@ class me {
1433
1509
  }
1434
1510
  async sendVerificationEmail(e) {
1435
1511
  !e && this.isCountdownActive() || await this.runAction("Sending verification email…", async () => {
1436
- const s = await this.auth.sendVerificationEmail({
1512
+ const t = await this.auth.sendVerificationEmail({
1437
1513
  email: this.state.email.trim(),
1438
1514
  callbackURL: this.getManagedReturnURL(
1439
- this.verificationCompletionAction === "sign-up" ? b : g,
1515
+ this.verificationCompletionAction === "sign-up" ? g : T,
1440
1516
  this.state.email.trim()
1441
1517
  )
1442
1518
  });
1443
- if (s.error)
1444
- throw s.error;
1519
+ if (t.error)
1520
+ throw t.error;
1445
1521
  this.handleVerificationEmailSent(this.state.email.trim(), !0);
1446
1522
  });
1447
1523
  }
1448
- async completeAuth(e, s) {
1449
- var a, c;
1450
- const i = s ?? await this.resolveAuthCompletionData();
1524
+ async completeAuth(e, t) {
1525
+ const i = await this.retryAuthCompletionDataIfNeeded(
1526
+ t ?? await this.resolveAuthCompletionData()
1527
+ );
1451
1528
  if (!i.user || !i.session) {
1529
+ if (i.lookupError && I(this.options)) {
1530
+ this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = this.labels.common.redirecting, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(k(this.options.redirectTo).toString());
1531
+ return;
1532
+ }
1452
1533
  if (e === "sign-in")
1453
- throw new K("Managed sign-in completed without an authenticated session.");
1534
+ throw i.lookupError ?? new ne(
1535
+ "Managed sign-in completed without an authenticated session."
1536
+ );
1454
1537
  this.state.view = "sign-in", this.state.password = "", this.state.confirmPassword = "", this.state.error = null, this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = "Account created. Sign in to continue.", this.render();
1455
1538
  return;
1456
1539
  }
1457
- const o = {
1540
+ const r = {
1458
1541
  action: e,
1459
1542
  user: i.user,
1460
1543
  session: i.session
1461
1544
  };
1462
- if (await ((c = (a = this.runtimeOptions) == null ? void 0 : a.syncPublicSession) == null ? void 0 : c.call(a)), R(this.options)) {
1463
- this.terminalActionInProgress = !0, this.invokeRedirectModeSuccessHook(o), this.state.busy = !0, this.state.busyLabel = this.labels.common.redirecting, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(k(this.options.redirectTo).toString());
1545
+ if (await this.syncPublicSessionBestEffort(), I(this.options)) {
1546
+ this.terminalActionInProgress = !0, this.invokeRedirectModeSuccessHook(r), this.state.busy = !0, this.state.busyLabel = this.labels.common.redirecting, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(k(this.options.redirectTo).toString());
1464
1547
  return;
1465
1548
  }
1466
- if (T(this.options)) {
1467
- this.destroy(), this.options.onSuccess(o);
1549
+ if (q(this.options)) {
1550
+ this.destroy(), this.options.onSuccess(r);
1468
1551
  return;
1469
1552
  }
1470
1553
  }
1471
- async resolveAuthCompletionData(e) {
1472
- const s = await j(this.auth), i = this.extractUser(e);
1554
+ async retryAuthCompletionDataIfNeeded(e) {
1555
+ if (e.session)
1556
+ return e;
1557
+ let t = e.lookupError;
1558
+ for (let i = 0; i < z; i++) {
1559
+ await new Promise((r) => setTimeout(r, se));
1560
+ try {
1561
+ const r = await _(this.auth);
1562
+ if (r.user && r.session)
1563
+ return {
1564
+ user: r.user,
1565
+ session: r.session
1566
+ };
1567
+ } catch (r) {
1568
+ t = r;
1569
+ }
1570
+ }
1473
1571
  return {
1474
- user: s.user ?? i,
1475
- session: s.session
1572
+ ...e,
1573
+ lookupError: t ?? e.lookupError
1476
1574
  };
1477
1575
  }
1576
+ async syncPublicSessionBestEffort() {
1577
+ var e, t;
1578
+ try {
1579
+ await ((t = (e = this.runtimeOptions) == null ? void 0 : e.syncPublicSession) == null ? void 0 : t.call(e));
1580
+ } catch {
1581
+ }
1582
+ }
1583
+ async resolveAuthCompletionData(e) {
1584
+ try {
1585
+ const t = await _(this.auth), i = this.extractUser(e);
1586
+ return {
1587
+ user: t.user ?? i,
1588
+ session: t.session
1589
+ };
1590
+ } catch (t) {
1591
+ return {
1592
+ user: this.extractUser(e),
1593
+ session: null,
1594
+ lookupError: t
1595
+ };
1596
+ }
1597
+ }
1478
1598
  async completePasswordReset() {
1479
1599
  const e = {
1480
1600
  action: "password-reset",
1481
1601
  user: null,
1482
1602
  session: null
1483
1603
  };
1484
- if (T(this.options)) {
1604
+ if (q(this.options)) {
1485
1605
  this.destroy(), this.options.onSuccess(e);
1486
1606
  return;
1487
1607
  }
1488
1608
  this.invokeRedirectModeSuccessHook(e), this.clearCountdown(), this.state.view = "sign-in", this.state.password = "", this.state.confirmPassword = "", this.state.newPassword = "", this.state.code = "", this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = null, this.state.notice = "Password updated. Sign in with your new password.", this.render();
1489
1609
  }
1490
1610
  handleExistingSessionOnMount(e) {
1491
- if (R(this.options)) {
1611
+ if (I(this.options)) {
1492
1612
  this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = this.labels.common.redirecting, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(k(this.options.redirectTo).toString());
1493
1613
  return;
1494
1614
  }
1495
- if (T(this.options))
1496
- throw this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, new u(
1615
+ if (q(this.options))
1616
+ throw this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, new d(
1497
1617
  "authUI.mount(container, { onSuccess }) cannot run while a session already exists. Check es.auth.getSession() before mounting controlled auth UI."
1498
1618
  );
1499
1619
  }
1500
- async runAction(e, s) {
1620
+ async runAction(e, t) {
1501
1621
  this.state.busy = !0, this.state.busyLabel = e, this.state.error = null, this.state.notice = null, this.render();
1502
1622
  try {
1503
- await s();
1623
+ await t();
1504
1624
  } catch (i) {
1505
1625
  if (this.maybeHandleVerificationRequired(i))
1506
1626
  return;
@@ -1510,45 +1630,45 @@ class me {
1510
1630
  !this.destroyed && !this.terminalActionInProgress && (this.state.busy = !1, this.state.busyLabel = void 0, this.render());
1511
1631
  }
1512
1632
  maybeHandleVerificationRequired(e) {
1513
- return S(e).code !== "EMAIL_NOT_VERIFIED" ? !1 : (this.verificationCompletionAction = "sign-in", this.state.view = "verify-email", this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = null, this.state.notice = `Verify your email to finish signing in as ${this.state.email.trim()}.`, this.render(), this.sendVerificationEmail(!0), !0);
1633
+ return V(e).code !== "EMAIL_NOT_VERIFIED" ? !1 : (this.verificationCompletionAction = "sign-in", this.state.view = "verify-email", this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = null, this.state.notice = `Verify your email to finish signing in as ${this.state.email.trim()}.`, this.render(), this.sendVerificationEmail(!0), !0);
1514
1634
  }
1515
- handleVerificationEmailSent(e, s) {
1516
- this.state.notice = s ? `We sent another verification email to ${e}.` : `We sent a verification email to ${e}.`, this.startCountdown();
1635
+ handleVerificationEmailSent(e, t) {
1636
+ this.state.notice = t ? `We sent another verification email to ${e}.` : `We sent a verification email to ${e}.`, this.startCountdown();
1517
1637
  }
1518
1638
  invokeRedirectModeSuccessHook(e) {
1519
- var s, i;
1520
- if (!(!R(this.options) || !this.options.onSuccess))
1639
+ var t, i;
1640
+ if (!(!I(this.options) || !this.options.onSuccess))
1521
1641
  try {
1522
1642
  this.options.onSuccess(e);
1523
- } catch (o) {
1524
- const a = S(o, "Post-auth callback failed.");
1643
+ } catch (r) {
1644
+ const o = V(r, "Post-auth callback failed.");
1525
1645
  try {
1526
- (i = (s = this.options).onError) == null || i.call(s, a);
1646
+ (i = (t = this.options).onError) == null || i.call(t, o);
1527
1647
  } catch {
1528
1648
  }
1529
1649
  }
1530
1650
  }
1531
- handleError(e, s) {
1532
- var o, a;
1533
- const i = S(e, s);
1534
- this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = i.message, this.render(), (a = (o = this.options).onError) == null || a.call(o, i);
1651
+ handleError(e, t) {
1652
+ var r, o;
1653
+ const i = V(e, t);
1654
+ this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = i.message, this.render(), (o = (r = this.options).onError) == null || o.call(r, i);
1535
1655
  }
1536
1656
  failValidation(e) {
1537
1657
  this.state.error = e, this.state.notice = null, this.render();
1538
1658
  }
1539
- getManagedReturnURL(e, s) {
1659
+ getManagedReturnURL(e, t) {
1540
1660
  if (!e)
1541
1661
  return window.location.href;
1542
1662
  const i = new URL(window.location.href);
1543
- return i.searchParams.set(C, e), s ? i.searchParams.set(p, s) : i.searchParams.delete(p), i.toString();
1663
+ return i.searchParams.set(F, e), t ? i.searchParams.set(C, t) : i.searchParams.delete(C), i.toString();
1544
1664
  }
1545
1665
  consumeManagedReturnContext() {
1546
- const e = new URL(window.location.href), s = e.searchParams.get(C), i = e.searchParams.get(p), o = s ? e.searchParams.get("error") : null, a = s ? e.searchParams.get("error_description") : null;
1547
- return (s || i) && (e.searchParams.delete(C), e.searchParams.delete(p), s && (e.searchParams.delete("error"), e.searchParams.delete("error_description")), window.history.replaceState(null, "", e.toString())), {
1548
- marker: s,
1666
+ const e = new URL(window.location.href), t = e.searchParams.get(F), i = e.searchParams.get(C), r = t ? e.searchParams.get("error") : null, o = t ? e.searchParams.get("error_description") : null;
1667
+ return (t || i) && (e.searchParams.delete(F), e.searchParams.delete(C), t && (e.searchParams.delete("error"), e.searchParams.delete("error_description")), window.history.replaceState(null, "", e.toString())), {
1668
+ marker: t,
1549
1669
  email: i,
1550
- error: o,
1551
- errorDescription: a
1670
+ error: r,
1671
+ errorDescription: o
1552
1672
  };
1553
1673
  }
1554
1674
  startCountdown(e = 60) {
@@ -1576,14 +1696,14 @@ class me {
1576
1696
  this.pendingFocusSnapshot && (this.clearFocusRestoreTimer(), this.focusRestoreTimer = window.setTimeout(() => {
1577
1697
  if (this.focusRestoreTimer = null, this.destroyed || !this.pendingFocusSnapshot)
1578
1698
  return;
1579
- const e = this.pendingFocusSnapshot, s = `input[name="${this.escape(e.name)}"][type="${this.escape(e.type)}"]`, i = this.root.querySelector(s);
1699
+ const e = this.pendingFocusSnapshot, t = `input[name="${this.escape(e.name)}"][type="${this.escape(e.type)}"]`, i = this.root.querySelector(t);
1580
1700
  if (!(!i || i.disabled)) {
1581
1701
  if (i.focus(), e.selectionStart !== null && e.selectionEnd !== null)
1582
1702
  try {
1583
1703
  i.setSelectionRange(e.selectionStart, e.selectionEnd);
1584
1704
  } catch {
1585
- const o = i.value.length;
1586
- i.setSelectionRange(o, o);
1705
+ const r = i.value.length;
1706
+ i.setSelectionRange(r, r);
1587
1707
  }
1588
1708
  this.pendingFocusSnapshot = null;
1589
1709
  }
@@ -1598,24 +1718,24 @@ class me {
1598
1718
  extractRedirectURL(e) {
1599
1719
  if (!e || typeof e != "object")
1600
1720
  return null;
1601
- const s = e;
1602
- return s.redirect && typeof s.url == "string" && s.url.length > 0 ? s.url : null;
1721
+ const t = e;
1722
+ return t.redirect && typeof t.url == "string" && t.url.length > 0 ? t.url : null;
1603
1723
  }
1604
1724
  extractUser(e) {
1605
1725
  if (!e || typeof e != "object")
1606
1726
  return null;
1607
- const s = e;
1608
- return s.user && typeof s.user == "object" ? s.user : null;
1727
+ const t = e;
1728
+ return t.user && typeof t.user == "object" ? t.user : null;
1609
1729
  }
1610
1730
  canUsePasswordResetEmailOtp() {
1611
1731
  var e;
1612
1732
  return !!((e = this.config) != null && e.passwordResetEmailOtpEnabled);
1613
1733
  }
1614
1734
  handleSessionlessManagedReturn(e) {
1615
- return e.email && (this.state.email = e.email), e.marker === b && !e.error ? (this.verificationCompletionAction = null, this.clearCountdown(), this.state.view = "sign-in", this.state.password = "", this.state.confirmPassword = "", this.state.error = null, this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = "Account created. Sign in to continue.", this.render(), !0) : e.marker === g || e.marker === b ? (this.verificationCompletionAction = e.marker === b ? "sign-up" : "sign-in", this.state.view = "verify-email", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, e.error || e.errorDescription ? this.handleError(new w(
1735
+ return e.email && (this.state.email = e.email), e.marker === g && !e.error ? (this.verificationCompletionAction = null, this.clearCountdown(), this.state.view = "sign-in", this.state.password = "", this.state.confirmPassword = "", this.state.error = null, this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = "Account created. Sign in to continue.", this.render(), !0) : e.marker === T || e.marker === g ? (this.verificationCompletionAction = e.marker === g ? "sign-up" : "sign-in", this.state.view = "verify-email", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, e.error || e.errorDescription ? this.handleError(new m(
1616
1736
  e.errorDescription ?? "Verification failed. Request a new verification email and try again.",
1617
1737
  { code: e.error ?? "VERIFY_EMAIL_ERROR" }
1618
- )) : this.render(), !0) : e.marker === G && (e.error || e.errorDescription) ? (this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, this.handleError(new w(
1738
+ )) : this.render(), !0) : e.marker === te && (e.error || e.errorDescription) ? (this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, this.handleError(new m(
1619
1739
  e.errorDescription ?? "OAuth sign-in failed.",
1620
1740
  { code: e.error ?? "OAUTH_ERROR" }
1621
1741
  )), !0) : !1;
@@ -1626,136 +1746,136 @@ class me {
1626
1746
  getCountdownSecondsRemaining() {
1627
1747
  return this.countdownUntil ? Math.max(0, Math.ceil((this.countdownUntil - Date.now()) / 1e3)) : 0;
1628
1748
  }
1629
- countdownText(e, s) {
1749
+ countdownText(e, t) {
1630
1750
  const i = this.getCountdownSecondsRemaining();
1631
- return i <= 0 ? e : s.replace("{seconds}", String(i));
1751
+ return i <= 0 ? e : t.replace("{seconds}", String(i));
1632
1752
  }
1633
1753
  escape(e) {
1634
1754
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1635
1755
  }
1636
1756
  }
1637
- function we(t) {
1638
- return "data" in t && t.data ? t.data : t;
1757
+ function Le(s) {
1758
+ return "data" in s && s.data ? s.data : s;
1639
1759
  }
1640
- const be = [
1760
+ const ye = [
1641
1761
  { id: "google", key: "providerGoogle" },
1642
1762
  { id: "apple", key: "providerApple" },
1643
1763
  { id: "microsoft", key: "providerMicrosoft" },
1644
1764
  { id: "github", key: "providerGithub" },
1645
1765
  { id: "gitlab", key: "providerGitlab" },
1646
1766
  { id: "discord", key: "providerDiscord" }
1647
- ], Y = 2, pe = 500;
1648
- async function ge() {
1649
- const t = `${window.location.origin}${Z}/config`;
1767
+ ], ie = 2, Ee = 500;
1768
+ async function Se() {
1769
+ const s = `${window.location.origin}${oe}/config`;
1650
1770
  let e;
1651
- for (let s = 0; s <= Y; s++)
1771
+ for (let t = 0; t <= ie; t++)
1652
1772
  try {
1653
- const i = await fetch(t, { method: "GET", credentials: "include" });
1773
+ const i = await fetch(s, { method: "GET", credentials: "include" });
1654
1774
  if (!i.ok)
1655
- throw new u(`Failed to load auth config: HTTP ${i.status}`);
1656
- const o = await i.json();
1657
- return ve(we(o));
1775
+ throw new d(`Failed to load auth config: HTTP ${i.status}`);
1776
+ const r = await i.json();
1777
+ return Ce(Le(r));
1658
1778
  } catch (i) {
1659
- e = i, s < Y && await new Promise((o) => setTimeout(o, pe));
1779
+ e = i, t < ie && await new Promise((r) => setTimeout(r, Ee));
1660
1780
  }
1661
1781
  throw e;
1662
1782
  }
1663
- let f = null;
1664
- async function fe() {
1665
- return f || (f = ge().catch((t) => {
1666
- throw f = null, t;
1667
- })), f;
1783
+ let R = null;
1784
+ async function _e() {
1785
+ return R || (R = Se().catch((s) => {
1786
+ throw R = null, s;
1787
+ })), R;
1668
1788
  }
1669
- function ve(t) {
1670
- var s, i, o, a, c, h, l;
1671
- const e = be.filter(({ key: r }) => {
1672
- const d = t[r];
1673
- return typeof d == "object" && d !== null && "enabled" in d && !!d.enabled;
1674
- }).map(({ id: r }) => r);
1789
+ function Ce(s) {
1790
+ var t, i, r, o, u, w, E;
1791
+ const e = ye.filter(({ key: c }) => {
1792
+ const a = s[c];
1793
+ return typeof a == "object" && a !== null && "enabled" in a && !!a.enabled;
1794
+ }).map(({ id: c }) => c);
1675
1795
  return {
1676
- disableSignUp: !!t.disableSignUp,
1677
- emailPasswordEnabled: !!((s = t.providerEmailPassword) != null && s.enabled),
1678
- minPasswordLength: ((o = (i = t.providerEmailPassword) == null ? void 0 : i.config) == null ? void 0 : o.minPasswordLength) ?? 8,
1679
- requireEmailVerification: !!((c = (a = t.providerEmailPassword) == null ? void 0 : a.config) != null && c.requireEmailVerification),
1680
- passwordResetEmailOtpEnabled: !!((l = (h = t.providerEmailPassword) == null ? void 0 : h.config) != null && l.requirePasswordResetEmailVerification),
1796
+ disableSignUp: !!s.disableSignUp,
1797
+ emailPasswordEnabled: !!((t = s.providerEmailPassword) != null && t.enabled),
1798
+ minPasswordLength: ((r = (i = s.providerEmailPassword) == null ? void 0 : i.config) == null ? void 0 : r.minPasswordLength) ?? 8,
1799
+ requireEmailVerification: !!((u = (o = s.providerEmailPassword) == null ? void 0 : o.config) != null && u.requireEmailVerification),
1800
+ passwordResetEmailOtpEnabled: !!((E = (w = s.providerEmailPassword) == null ? void 0 : w.config) != null && E.requirePasswordResetEmailVerification),
1681
1801
  oauthProviders: e
1682
1802
  };
1683
1803
  }
1684
- const v = /* @__PURE__ */ new WeakMap();
1685
- function Pe(t) {
1686
- if (!t)
1687
- throw new u(
1804
+ const $ = /* @__PURE__ */ new WeakMap();
1805
+ function Te(s) {
1806
+ if (!s)
1807
+ throw new d(
1688
1808
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1689
1809
  );
1690
- const e = "redirectTo" in t, s = "onSuccess" in t && typeof t.onSuccess == "function";
1691
- if (!e && !s)
1692
- throw new u(
1810
+ const e = "redirectTo" in s, t = "onSuccess" in s && typeof s.onSuccess == "function";
1811
+ if (!e && !t)
1812
+ throw new d(
1693
1813
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1694
1814
  );
1695
- if ("redirectTo" in t) {
1696
- const i = t.redirectTo;
1815
+ if ("redirectTo" in s) {
1816
+ const i = s.redirectTo;
1697
1817
  if (!(typeof i == "string" || i instanceof URL))
1698
- throw new u(
1818
+ throw new d(
1699
1819
  "authUI.mount(container, options) expected redirectTo to be a string or URL."
1700
1820
  );
1701
1821
  }
1702
- if ("onSuccess" in t && t.onSuccess !== void 0 && typeof t.onSuccess != "function")
1703
- throw new u(
1822
+ if ("onSuccess" in s && s.onSuccess !== void 0 && typeof s.onSuccess != "function")
1823
+ throw new d(
1704
1824
  "authUI.mount(container, options) expected onSuccess to be a function."
1705
1825
  );
1706
- if ("onError" in t && t.onError !== void 0 && typeof t.onError != "function")
1707
- throw new u(
1826
+ if ("onError" in s && s.onError !== void 0 && typeof s.onError != "function")
1827
+ throw new d(
1708
1828
  "authUI.mount(container, options) expected onError to be a function."
1709
1829
  );
1710
1830
  }
1711
- function ye(t) {
1712
- if (!(t instanceof HTMLElement))
1713
- throw new u("authUI.mount(container, options) requires a real HTMLElement container.");
1831
+ function Ie(s) {
1832
+ if (!(s instanceof HTMLElement))
1833
+ throw new d("authUI.mount(container, options) requires a real HTMLElement container.");
1714
1834
  }
1715
- function Le(t, e) {
1835
+ function Re(s, e) {
1716
1836
  return {
1717
- mount(s, i) {
1718
- var h;
1719
- Pe(i), ye(s), (h = v.get(s)) == null || h.destroy();
1720
- const o = new me(s, t, i, fe, e), a = o.destroy.bind(o), c = {
1837
+ mount(t, i) {
1838
+ var w;
1839
+ Te(i), Ie(t), (w = $.get(t)) == null || w.destroy();
1840
+ const r = new Pe(t, s, i, _e, e), o = r.destroy.bind(r), u = {
1721
1841
  destroy() {
1722
- a(), v.get(s) === c && v.delete(s);
1842
+ o(), $.get(t) === u && $.delete(t);
1723
1843
  }
1724
1844
  };
1725
- return v.set(s, c), c;
1845
+ return $.set(t, u), u;
1726
1846
  }
1727
1847
  };
1728
1848
  }
1729
- function Se() {
1730
- J();
1731
- const t = ae(), e = re(), s = ne(), i = Le(e, {
1849
+ function Ue() {
1850
+ re();
1851
+ const s = me(), e = we(), t = ue(), i = Re(e, {
1732
1852
  syncPublicSession: async () => {
1733
- await oe(t);
1853
+ await he(s);
1734
1854
  }
1735
1855
  });
1736
1856
  return {
1737
- auth: t,
1738
- api: s,
1857
+ auth: s,
1858
+ api: t,
1739
1859
  authUI: i
1740
1860
  };
1741
1861
  }
1742
1862
  export {
1743
- w as EdgeSparkAuthError,
1744
- u as EdgeSparkConfigError,
1745
- U as EdgeSparkError,
1746
- K as EdgeSparkRuntimeError,
1747
- x as ar,
1748
- Se as createEdgeSpark,
1749
- q as de,
1750
- de as detectLocale,
1751
- y as enUS,
1752
- E as es,
1753
- F as fr,
1754
- H as hi,
1755
- N as it,
1756
- V as ja,
1757
- O as ko,
1758
- z as ptBR,
1759
- D as ru,
1760
- L as zhCN
1863
+ m as EdgeSparkAuthError,
1864
+ d as EdgeSparkConfigError,
1865
+ x as EdgeSparkError,
1866
+ ne as EdgeSparkRuntimeError,
1867
+ Q as ar,
1868
+ Ue as createEdgeSpark,
1869
+ K as de,
1870
+ pe as detectLocale,
1871
+ U as enUS,
1872
+ O as es,
1873
+ Y as fr,
1874
+ X as hi,
1875
+ J as it,
1876
+ W as ja,
1877
+ j as ko,
1878
+ G as ptBR,
1879
+ Z as ru,
1880
+ M as zhCN
1761
1881
  };