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

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,210 +1,272 @@
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;
1
+ import { createAuthClient as be } from "better-auth/client";
2
+ class j extends Error {
3
+ constructor(e, s) {
4
+ super(s), this.name = "EdgeSparkError", this.code = e;
5
5
  }
6
6
  }
7
- class d extends x {
7
+ class u extends j {
8
8
  constructor(e) {
9
9
  super("CONFIG_ERROR", e), this.name = "EdgeSparkConfigError";
10
10
  }
11
11
  }
12
- class ne extends x {
12
+ class de extends j {
13
13
  constructor(e) {
14
14
  super("RUNTIME_ERROR", e), this.name = "EdgeSparkRuntimeError";
15
15
  }
16
16
  }
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;
17
+ class w extends j {
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;
20
20
  }
21
21
  }
22
- function re() {
22
+ function ce() {
23
23
  if (typeof window > "u" || typeof document > "u")
24
- throw new ne(
24
+ throw new de(
25
25
  "@edgespark/web is browser-only. Create the client from a real browser runtime."
26
26
  );
27
27
  }
28
- function H() {
29
- return re(), window.location.origin;
28
+ function W() {
29
+ return ce(), window.location.origin;
30
30
  }
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);
31
+ function ge(t) {
32
+ return t instanceof URL ? t : typeof t == "string" ? new URL(t, window.location.href) : new URL(t.url, window.location.href);
33
33
  }
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()}.`
34
+ function ve(t) {
35
+ if (t.origin !== W())
36
+ throw new u(
37
+ `Cross-origin requests are not supported by this SDK. Received ${t.origin}, expected ${W()}.`
38
38
  );
39
39
  }
40
- function ue() {
40
+ function ye() {
41
41
  return {
42
- async fetch(s, e) {
43
- const t = de(s);
44
- return ce(t), fetch(s, {
42
+ async fetch(t, e) {
43
+ const s = ge(t);
44
+ return ve(s), fetch(t, {
45
45
  ...e,
46
46
  credentials: "include"
47
47
  });
48
48
  }
49
49
  };
50
50
  }
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 } : {},
51
+ const ue = "/api/_es/auth", Pe = "edgespark-auth-session", K = "__edgespark_auth_sync__", he = Symbol("edgespark.notifyAuthTabs");
52
+ function me(t) {
53
+ return be({
54
+ baseURL: W(),
55
+ basePath: ue,
56
+ ...t != null && t.disableDefaultRedirectPlugin ? { disableDefaultFetchPlugins: !0 } : {},
57
57
  fetchOptions: {
58
58
  credentials: "include"
59
59
  }
60
60
  });
61
61
  }
62
- function v(s) {
63
- var e, t;
64
- return (t = (e = s.$store) == null ? void 0 : e.atoms) == null ? void 0 : t.session;
62
+ function _(t) {
63
+ var e, s;
64
+ return (s = (e = t.$store) == null ? void 0 : e.atoms) == null ? void 0 : s.session;
65
65
  }
66
- function B(s) {
67
- if (s instanceof m)
68
- return s;
69
- const e = s;
70
- return new m(
66
+ function Le(t) {
67
+ return JSON.stringify({
68
+ source: t,
69
+ timestamp: Date.now()
70
+ });
71
+ }
72
+ function Ee(t) {
73
+ if (typeof t != "string")
74
+ return null;
75
+ try {
76
+ const e = JSON.parse(t);
77
+ return e && typeof e == "object" ? e : null;
78
+ } catch {
79
+ return null;
80
+ }
81
+ }
82
+ function Se(t) {
83
+ if (!(t && typeof t == "object") || "error" in t && t.error)
84
+ return !1;
85
+ const e = "data" in t ? t.data : t;
86
+ return e && typeof e == "object" ? "token" in e && typeof e.token == "string" && e.token.length > 0 ? !0 : "session" in e && "user" in e && !!e.session && !!e.user : !1;
87
+ }
88
+ function M(t) {
89
+ if (t instanceof w)
90
+ return t;
91
+ const e = t;
92
+ return new w(
71
93
  (e == null ? void 0 : e.message) || "Failed to load the current session.",
72
94
  {
73
95
  code: (e == null ? void 0 : e.code) ?? "SESSION_LOOKUP_FAILED",
74
- cause: s,
96
+ cause: t,
75
97
  status: e == null ? void 0 : e.status
76
98
  }
77
99
  );
78
100
  }
79
- async function he(s) {
80
- var e;
81
- await ((e = v(s)) == null ? void 0 : e.get().refetch());
101
+ async function _e(t) {
102
+ var e, s;
103
+ await ((e = _(t)) == null ? void 0 : e.get().refetch()), (s = t[he]) == null || s.call(t);
82
104
  }
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;
105
+ function Te() {
106
+ const t = me(), e = `${Date.now()}-${Math.random().toString(36).slice(2)}`, s = typeof BroadcastChannel < "u" ? new BroadcastChannel(Pe) : null, i = 2, r = 500;
107
+ let a = null, c = !1;
108
+ const p = () => {
109
+ var l;
110
+ return c ? Promise.resolve(((l = _(t)) == null ? void 0 : l.get().data) ?? null) : (a || (a = (async () => {
111
+ var m, f, g, v;
112
+ let o = !1, d = null;
91
113
  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));
114
+ for (let L = 0; L <= i; L++) {
115
+ const E = await t.getSession(), y = ((m = _(t)) == null ? void 0 : m.get().data) ?? null;
116
+ if ((f = E.data) != null && f.session && ((g = E.data) != null && g.user))
117
+ return c = !0, E.data;
118
+ if (y != null && y.session && (y != null && y.user))
119
+ return c = !0, y;
120
+ if (E.error ? d = E.error : o = !0, !E.error && L < i) {
121
+ await new Promise((k) => setTimeout(k, r));
100
122
  continue;
101
123
  }
102
- p < e && await new Promise((A) => setTimeout(A, t));
124
+ L < i && await new Promise((k) => setTimeout(k, r));
103
125
  }
104
- if (!a)
105
- throw i = null, new m("Failed to load the current session.", {
126
+ if (!o)
127
+ throw a = null, new w("Failed to load the current session.", {
106
128
  code: "SESSION_LOOKUP_FAILED",
107
- cause: l
129
+ cause: d
108
130
  });
109
- const h = ((S = v(s)) == null ? void 0 : S.get().data) ?? null;
110
- return r = !0, h;
131
+ const h = ((v = _(t)) == null ? void 0 : v.get().data) ?? null;
132
+ return c = !0, h;
111
133
  } catch (h) {
112
- throw i = null, B(h);
134
+ throw a = null, M(h);
113
135
  }
114
- })()), i);
136
+ })()), a);
115
137
  };
116
- o().catch(() => {
138
+ p().catch(() => {
117
139
  });
118
- const u = async () => {
119
- var c, a;
140
+ const T = async () => {
141
+ var l, o;
120
142
  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.", {
143
+ const d = await t.getSession();
144
+ if ((l = d.data) != null && l.session && ((o = d.data) != null && o.user))
145
+ return d.data;
146
+ throw d.error ? M(d.error) : new w("No authenticated session is available.", {
125
147
  code: "UNAUTHENTICATED"
126
148
  });
127
- } catch (l) {
128
- throw B(l);
149
+ } catch (d) {
150
+ throw M(d);
151
+ }
152
+ }, P = async () => {
153
+ var l;
154
+ try {
155
+ await ((l = _(t)) == null ? void 0 : l.get().refetch());
156
+ } catch {
129
157
  }
130
- }, w = (c) => {
131
- let a = !1, l = !1, P;
132
- const L = (h) => {
133
- h !== P && (P = h, c(h));
158
+ }, b = () => {
159
+ const l = Le(e);
160
+ try {
161
+ s == null || s.postMessage(l);
162
+ } catch {
163
+ }
164
+ try {
165
+ window.localStorage.setItem(K, l);
166
+ } catch {
167
+ }
168
+ }, G = (l) => {
169
+ const o = Ee(l);
170
+ !o || o.source === e || P();
171
+ };
172
+ s == null || s.addEventListener("message", (l) => {
173
+ G(l.data);
174
+ }), typeof window < "u" && window.addEventListener("storage", (l) => {
175
+ l.key !== K || l.newValue === null || G(l.newValue);
176
+ });
177
+ const Y = async () => {
178
+ await P(), b();
179
+ }, we = (l) => {
180
+ let o = !1, d = !1, m;
181
+ const f = (h) => {
182
+ h !== m && (m = h, l(h));
134
183
  };
135
- o().then((h) => {
136
- a || (l = !0, L(h));
184
+ p().then((h) => {
185
+ o || (d = !0, f(h));
137
186
  }).catch(() => {
138
- a || (l = !0);
187
+ o || (d = !0);
139
188
  });
140
- const y = v(s);
141
- if (!y)
189
+ const g = _(t);
190
+ if (!g)
142
191
  return () => {
143
- a = !0;
192
+ o = !0;
144
193
  };
145
- const S = y.subscribe((h) => {
146
- if (a || !l || h.error && !h.data)
194
+ const v = g.subscribe((h) => {
195
+ if (o || !d || h.error && !h.data)
147
196
  return;
148
- const p = h.data ?? null;
149
- L(p);
197
+ const L = h.data ?? null;
198
+ f(L);
150
199
  });
151
200
  return () => {
152
- a = !0, S();
201
+ o = !0, v();
153
202
  };
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;
159
- try {
160
- await ((l = v(s)) == null ? void 0 : l.get().refetch());
161
- } catch {
203
+ }, fe = async (...l) => {
204
+ const o = await t.signOut(...l);
205
+ return o && typeof o == "object" && "error" in o && o.error || await Y(), o;
206
+ }, pe = (l) => new Proxy(l, {
207
+ get(o, d, m) {
208
+ const f = Reflect.get(o, d, m);
209
+ return typeof f != "function" ? f : async (...g) => {
210
+ const v = await f.apply(o, g);
211
+ return Se(v) && await Y(), v;
212
+ };
162
213
  }
163
- return a;
164
- };
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);
214
+ });
215
+ return new Proxy(t, {
216
+ get(l, o, d) {
217
+ if (o === "requireSession")
218
+ return T;
219
+ if (o === "onSessionChange")
220
+ return we;
221
+ if (o === "signOut")
222
+ return fe;
223
+ if (o === he)
224
+ return b;
225
+ if (o === "signIn" || o === "signUp") {
226
+ const m = Reflect.get(l, o, d);
227
+ return m && typeof m == "object" ? pe(m) : m;
228
+ }
229
+ return Reflect.get(l, o, d);
168
230
  }
169
231
  });
170
232
  }
171
- function we() {
172
- return ae({ disableDefaultRedirectPlugin: !0 });
233
+ function Ce() {
234
+ return me({ disableDefaultRedirectPlugin: !0 });
173
235
  }
174
- function k(s) {
236
+ function O(t) {
175
237
  const e = (() => {
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.");
238
+ if (t instanceof URL)
239
+ return t;
240
+ const s = t.trim();
241
+ if (!s)
242
+ throw new u("redirectTo must not be an empty string.");
181
243
  try {
182
- return new URL(t, window.location.href);
244
+ return new URL(s, window.location.href);
183
245
  } catch {
184
- throw new d(
185
- `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(s)}`
246
+ throw new u(
247
+ `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(t)}`
186
248
  );
187
249
  }
188
250
  })();
189
251
  if (e.protocol !== "http:" && e.protocol !== "https:")
190
- throw new d(
252
+ throw new u(
191
253
  `redirectTo must resolve to an http(s) URL. Received protocol: ${e.protocol}`
192
254
  );
193
255
  return e;
194
256
  }
195
- function be(s, e) {
257
+ function Ie(t, e) {
196
258
  return e ? {
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;
259
+ common: { ...t.common, ...e.common },
260
+ signIn: { ...t.signIn, ...e.signIn },
261
+ signUp: { ...t.signUp, ...e.signUp },
262
+ verifyEmail: { ...t.verifyEmail, ...e.verifyEmail },
263
+ forgotPassword: { ...t.forgotPassword, ...e.forgotPassword },
264
+ resetPassword: { ...t.resetPassword, ...e.resetPassword },
265
+ oauth: { ...t.oauth, ...e.oauth },
266
+ errors: { ...t.errors, ...e.errors }
267
+ } : t;
206
268
  }
207
- const U = {
269
+ const B = {
208
270
  common: {
209
271
  loading: "Loading sign-in…",
210
272
  redirecting: "Redirecting…",
@@ -267,7 +329,7 @@ const U = {
267
329
  invalidCode: "Enter the 6-digit verification code.",
268
330
  generic: "Something went wrong. Please try again."
269
331
  }
270
- }, M = {
332
+ }, V = {
271
333
  common: {
272
334
  loading: "加载中…",
273
335
  redirecting: "跳转中…",
@@ -330,7 +392,7 @@ const U = {
330
392
  invalidCode: "请输入 6 位验证码",
331
393
  generic: "出现错误,请稍后重试"
332
394
  }
333
- }, W = {
395
+ }, J = {
334
396
  common: {
335
397
  loading: "サインインを読み込み中…",
336
398
  redirecting: "リダイレクト中…",
@@ -393,7 +455,7 @@ const U = {
393
455
  invalidCode: "6桁の認証コードを入力してください",
394
456
  generic: "エラーが発生しました。もう一度お試しください"
395
457
  }
396
- }, j = {
458
+ }, Z = {
397
459
  common: {
398
460
  loading: "로그인 로딩 중…",
399
461
  redirecting: "리디렉션 중…",
@@ -456,7 +518,7 @@ const U = {
456
518
  invalidCode: "6자리 인증 코드를 입력해 주세요",
457
519
  generic: "문제가 발생했습니다. 다시 시도해 주세요"
458
520
  }
459
- }, O = {
521
+ }, F = {
460
522
  common: {
461
523
  loading: "Cargando inicio de sesión…",
462
524
  redirecting: "Redirigiendo…",
@@ -519,7 +581,7 @@ const U = {
519
581
  invalidCode: "Ingresa el código de verificación de 6 dígitos.",
520
582
  generic: "Algo salió mal. Por favor, inténtalo de nuevo."
521
583
  }
522
- }, G = {
584
+ }, Q = {
523
585
  common: {
524
586
  loading: "Carregando login…",
525
587
  redirecting: "Redirecionando…",
@@ -582,7 +644,7 @@ const U = {
582
644
  invalidCode: "Insira o código de verificação de 6 dígitos.",
583
645
  generic: "Algo deu errado. Por favor, tente novamente."
584
646
  }
585
- }, Y = {
647
+ }, X = {
586
648
  common: {
587
649
  loading: "Chargement de la connexion…",
588
650
  redirecting: "Redirection…",
@@ -645,7 +707,7 @@ const U = {
645
707
  invalidCode: "Saisissez le code de vérification à 6 chiffres.",
646
708
  generic: "Une erreur est survenue. Veuillez réessayer."
647
709
  }
648
- }, K = {
710
+ }, ee = {
649
711
  common: {
650
712
  loading: "Anmeldung wird geladen…",
651
713
  redirecting: "Weiterleitung…",
@@ -708,7 +770,7 @@ const U = {
708
770
  invalidCode: "Geben Sie den 6-stelligen Bestätigungscode ein.",
709
771
  generic: "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
710
772
  }
711
- }, J = {
773
+ }, te = {
712
774
  common: {
713
775
  loading: "Caricamento accesso…",
714
776
  redirecting: "Reindirizzamento…",
@@ -771,7 +833,7 @@ const U = {
771
833
  invalidCode: "Inserisci il codice di verifica a 6 cifre.",
772
834
  generic: "Qualcosa è andato storto. Riprova."
773
835
  }
774
- }, Z = {
836
+ }, se = {
775
837
  common: {
776
838
  loading: "Загрузка входа…",
777
839
  redirecting: "Перенаправление…",
@@ -834,7 +896,7 @@ const U = {
834
896
  invalidCode: "Введите 6-значный код подтверждения.",
835
897
  generic: "Произошла ошибка. Пожалуйста, попробуйте снова."
836
898
  }
837
- }, Q = {
899
+ }, ie = {
838
900
  common: {
839
901
  loading: "جارٍ تحميل تسجيل الدخول…",
840
902
  redirecting: "جارٍ إعادة التوجيه…",
@@ -897,7 +959,7 @@ const U = {
897
959
  invalidCode: "يرجى إدخال رمز التحقّق المكوّن من 6 أرقام.",
898
960
  generic: "حدث خطأ. يرجى المحاولة مرة أخرى."
899
961
  }
900
- }, X = {
962
+ }, ne = {
901
963
  common: {
902
964
  loading: "सधाइन की जुलातीअ लोड हो रही है…",
903
965
  redirecting: "रीडायरेक्ट हो रहا है…",
@@ -960,62 +1022,62 @@ const U = {
960
1022
  invalidCode: "कृपया 6 अंकों का सत्यापन कोड दर्ज करें।",
961
1023
  generic: "कुछ गलत हो गई। कृपया फिर से प्रयास करें।"
962
1024
  }
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
1025
+ }, re = {
1026
+ en: B,
1027
+ "en-US": B,
1028
+ zh: V,
1029
+ "zh-CN": V,
1030
+ "zh-TW": V,
1031
+ ja: J,
1032
+ "ja-JP": J,
1033
+ ko: Z,
1034
+ "ko-KR": Z,
1035
+ es: F,
1036
+ "es-ES": F,
1037
+ "es-MX": F,
1038
+ pt: Q,
1039
+ "pt-BR": Q,
1040
+ fr: X,
1041
+ "fr-FR": X,
1042
+ de: ee,
1043
+ "de-DE": ee,
1044
+ it: te,
1045
+ "it-IT": te,
1046
+ ru: se,
1047
+ "ru-RU": se,
1048
+ ar: ie,
1049
+ "ar-SA": ie,
1050
+ hi: ne,
1051
+ "hi-IN": ne
990
1052
  };
991
- function pe() {
1053
+ function Re() {
992
1054
  if (typeof navigator > "u")
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;
1055
+ return B;
1056
+ const t = navigator.languages ?? [navigator.language];
1057
+ for (const e of t) {
1058
+ const s = re[e] ?? re[e.split("-")[0]];
1059
+ if (s) return s;
998
1060
  }
999
- return U;
1061
+ return B;
1000
1062
  }
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
1063
+ function N(t, e = "Authentication failed.") {
1064
+ if (t instanceof w)
1065
+ return t;
1066
+ if (typeof t == "object" && t !== null) {
1067
+ const s = t;
1068
+ return new w(s.message || e, {
1069
+ code: s.code,
1070
+ status: s.status,
1071
+ cause: t
1010
1072
  });
1011
1073
  }
1012
- return typeof s == "string" ? new m(s) : new m(e, { cause: s });
1074
+ return typeof t == "string" ? new w(t) : new w(e, { cause: t });
1013
1075
  }
1014
- async function _(s) {
1015
- var t, i;
1016
- const e = await s.getSession();
1076
+ async function C(t) {
1077
+ var s, i;
1078
+ const e = await t.getSession();
1017
1079
  if (e.error)
1018
- throw new m(
1080
+ throw new w(
1019
1081
  e.error.message || "Failed to load the current session.",
1020
1082
  {
1021
1083
  code: e.error.code ?? "SESSION_LOOKUP_FAILED",
@@ -1023,7 +1085,7 @@ async function _(s) {
1023
1085
  cause: e.error
1024
1086
  }
1025
1087
  );
1026
- return (t = e.data) != null && t.user && ((i = e.data) != null && i.session) ? {
1088
+ return (s = e.data) != null && s.user && ((i = e.data) != null && i.session) ? {
1027
1089
  user: e.data.user,
1028
1090
  session: e.data
1029
1091
  } : {
@@ -1031,7 +1093,7 @@ async function _(s) {
1031
1093
  session: null
1032
1094
  };
1033
1095
  }
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 = {
1096
+ const $e = "data-edgespark-auth", n = "edgespark-auth", z = "es_auth_completion", I = "es_auth_email", oe = "oauth", R = "verify-sign-in", S = "verify-sign-up", ae = 200, q = 2, D = {
1035
1097
  google: "Google",
1036
1098
  apple: "Apple",
1037
1099
  microsoft: "Microsoft",
@@ -1039,24 +1101,24 @@ const fe = "data-edgespark-auth", n = "edgespark-auth", F = "es_auth_completion"
1039
1101
  gitlab: "GitLab",
1040
1102
  discord: "Discord"
1041
1103
  };
1042
- function I(s) {
1043
- return "redirectTo" in s;
1104
+ function $(t) {
1105
+ return "redirectTo" in t;
1044
1106
  }
1045
- function q(s) {
1046
- return "onSuccess" in s && !("redirectTo" in s);
1107
+ function H(t) {
1108
+ return "onSuccess" in t && !("redirectTo" in t);
1047
1109
  }
1048
- function D(s) {
1049
- return !s || typeof s != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s.trim());
1110
+ function x(t) {
1111
+ return !t || typeof t != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim());
1050
1112
  }
1051
- function ge(s) {
1052
- return /^\d{6}$/.test(s.trim());
1113
+ function Ue(t) {
1114
+ return /^\d{6}$/.test(t.trim());
1053
1115
  }
1054
- function ve(s) {
1055
- return s === "email" || s === "name" || s === "password" || s === "confirmPassword" || s === "code" || s === "newPassword";
1116
+ function Ae(t) {
1117
+ return t === "email" || t === "name" || t === "password" || t === "confirmPassword" || t === "code" || t === "newPassword";
1056
1118
  }
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 = {
1119
+ class Be {
1120
+ constructor(e, s, i, r, a) {
1121
+ if (this.container = e, this.auth = s, this.options = i, this.loadConfig = r, this.runtimeOptions = a, this.state = {
1060
1122
  view: "loading",
1061
1123
  busy: !0,
1062
1124
  busyLabel: void 0,
@@ -1069,27 +1131,27 @@ class Pe {
1069
1131
  code: "",
1070
1132
  newPassword: ""
1071
1133
  }, 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))
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();
1134
+ throw new u("authUI.mount(container, options) requires a real HTMLElement container.");
1135
+ this.labels = Ie(Re(), i.labels), this.root = document.createElement("div"), this.root.setAttribute($e, ""), e.innerHTML = "", e.appendChild(this.root), this.render(), this.initialize();
1074
1136
  }
1075
1137
  destroy() {
1076
1138
  this.destroyed || (this.destroyed = !0, this.clearCountdown(), this.clearFocusRestoreTimer(), this.container.innerHTML = "");
1077
1139
  }
1078
1140
  async initialize() {
1079
1141
  try {
1080
- const e = this.consumeManagedReturnContext(), [t, i] = await Promise.all([
1142
+ const e = this.consumeManagedReturnContext(), [s, i] = await Promise.all([
1081
1143
  this.loadConfig(),
1082
1144
  this.readMountSession(e)
1083
1145
  ]);
1084
1146
  if (this.destroyed)
1085
1147
  return;
1086
- if (this.config = t, i.user && i.session) {
1148
+ if (this.config = s, i.user && i.session) {
1087
1149
  switch (e.marker) {
1088
- case te:
1089
- case T:
1150
+ case oe:
1151
+ case R:
1090
1152
  await this.completeAuth("sign-in", i);
1091
1153
  return;
1092
- case g:
1154
+ case S:
1093
1155
  await this.completeAuth("sign-up", i);
1094
1156
  return;
1095
1157
  default:
@@ -1107,20 +1169,20 @@ class Pe {
1107
1169
  }
1108
1170
  async readMountSession(e) {
1109
1171
  if (!e.marker)
1110
- return _(this.auth);
1111
- let t = null;
1112
- for (let i = 0; i <= z; i++) {
1172
+ return C(this.auth);
1173
+ let s = null;
1174
+ for (let i = 0; i <= q; i++) {
1113
1175
  try {
1114
- const r = await _(this.auth);
1176
+ const r = await C(this.auth);
1115
1177
  if (r.user && r.session)
1116
1178
  return r;
1117
1179
  } catch (r) {
1118
- t = r;
1180
+ s = r;
1119
1181
  }
1120
- i < z && await new Promise((r) => setTimeout(r, se));
1182
+ i < q && await new Promise((r) => setTimeout(r, ae));
1121
1183
  }
1122
- if (t)
1123
- throw t;
1184
+ if (s)
1185
+ throw s;
1124
1186
  return {
1125
1187
  user: null,
1126
1188
  session: null
@@ -1182,7 +1244,7 @@ class Pe {
1182
1244
  }
1183
1245
  renderSignInView() {
1184
1246
  var i, r;
1185
- const e = this.renderOAuthProviders(), t = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1247
+ const e = this.renderOAuthProviders(), s = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1186
1248
  return `
1187
1249
  <section class="${n}__section">
1188
1250
  <header class="${n}__header">
@@ -1190,8 +1252,8 @@ class Pe {
1190
1252
  <p class="${n}__copy">${this.escape(this.labels.signIn.subtitle)}</p>
1191
1253
  </header>
1192
1254
  ${e}
1193
- ${e && t ? `<div class="${n}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1194
- ${t ? `
1255
+ ${e && s ? `<div class="${n}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1256
+ ${s ? `
1195
1257
  <form class="${n}__form" data-view="sign-in" novalidate>
1196
1258
  ${this.renderInput("email", this.labels.signIn.emailLabel, "email", this.state.email, "email")}
1197
1259
  ${this.renderInput("password", this.labels.signIn.passwordLabel, "password", this.state.password, "current-password")}
@@ -1320,28 +1382,28 @@ class Pe {
1320
1382
  `;
1321
1383
  }
1322
1384
  renderOAuthProviders() {
1323
- var t;
1324
- const e = ((t = this.config) == null ? void 0 : t.oauthProviders) ?? [];
1385
+ var s;
1386
+ const e = ((s = this.config) == null ? void 0 : s.oauthProviders) ?? [];
1325
1387
  return e.length === 0 ? "" : `
1326
1388
  <div class="${n}__stack">
1327
1389
  ${e.map((i) => `
1328
1390
  <button class="${n}__button ${n}__button--secondary" type="button" data-action="oauth" data-provider="${i}" ${this.state.busy ? "disabled" : ""}>
1329
- ${this.escape(`${this.labels.oauth.continueWith} ${N[i]}`)}
1391
+ ${this.escape(`${this.labels.oauth.continueWith} ${D[i]}`)}
1330
1392
  </button>
1331
1393
  `).join("")}
1332
1394
  </div>
1333
1395
  `;
1334
1396
  }
1335
- renderInput(e, t, i, r, o) {
1397
+ renderInput(e, s, i, r, a) {
1336
1398
  return `
1337
1399
  <label class="${n}__field">
1338
- <span class="${n}__label">${this.escape(t)}</span>
1400
+ <span class="${n}__label">${this.escape(s)}</span>
1339
1401
  <input
1340
1402
  class="${n}__input"
1341
1403
  name="${this.escape(e)}"
1342
1404
  type="${this.escape(i)}"
1343
1405
  value="${this.escape(r)}"
1344
- autocomplete="${this.escape(o)}"
1406
+ autocomplete="${this.escape(a)}"
1345
1407
  ${this.state.busy ? "disabled" : ""}
1346
1408
  />
1347
1409
  </label>
@@ -1349,19 +1411,19 @@ class Pe {
1349
1411
  }
1350
1412
  bindDOM() {
1351
1413
  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();
1414
+ r.addEventListener("submit", (a) => {
1415
+ a.preventDefault();
1416
+ const c = r.dataset.view;
1417
+ c === "sign-in" && this.handleSignIn(), c === "sign-up" && this.handleSignUp(), c === "forgot-password" && this.handleForgotPassword(), c === "reset-password" && this.handleResetPassword();
1356
1418
  });
1357
1419
  }), this.root.querySelectorAll("input[name]").forEach((r) => {
1358
1420
  r.addEventListener("input", () => {
1359
- ve(r.name) && (this.state[r.name] = r.value);
1421
+ Ae(r.name) && (this.state[r.name] = r.value);
1360
1422
  });
1361
1423
  }), this.root.querySelectorAll("[data-action]").forEach((r) => {
1362
1424
  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);
1425
+ const a = r.dataset.action;
1426
+ 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(r.dataset.provider);
1365
1427
  });
1366
1428
  });
1367
1429
  }
@@ -1369,7 +1431,7 @@ class Pe {
1369
1431
  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();
1370
1432
  }
1371
1433
  async handleSignIn() {
1372
- if (!D(this.state.email)) {
1434
+ if (!x(this.state.email)) {
1373
1435
  this.failValidation(this.labels.errors.invalidEmail);
1374
1436
  return;
1375
1437
  }
@@ -1381,7 +1443,7 @@ class Pe {
1381
1443
  const e = await this.auth.signIn.email({
1382
1444
  email: this.state.email.trim(),
1383
1445
  password: this.state.password,
1384
- callbackURL: this.getManagedReturnURL(T, this.state.email.trim())
1446
+ callbackURL: this.getManagedReturnURL(R, this.state.email.trim())
1385
1447
  });
1386
1448
  if (e.error)
1387
1449
  throw e.error;
@@ -1389,12 +1451,12 @@ class Pe {
1389
1451
  });
1390
1452
  }
1391
1453
  async handleSignUp() {
1392
- var e, t;
1454
+ var e, s;
1393
1455
  if (!this.state.name.trim()) {
1394
1456
  this.failValidation(this.labels.errors.requiredField);
1395
1457
  return;
1396
1458
  }
1397
- if (!D(this.state.email)) {
1459
+ if (!x(this.state.email)) {
1398
1460
  this.failValidation(this.labels.errors.invalidEmail);
1399
1461
  return;
1400
1462
  }
@@ -1404,7 +1466,7 @@ class Pe {
1404
1466
  }
1405
1467
  if (this.state.password.length < (((e = this.config) == null ? void 0 : e.minPasswordLength) ?? 8)) {
1406
1468
  this.failValidation(
1407
- this.labels.errors.passwordTooShort.replace("{min}", String(((t = this.config) == null ? void 0 : t.minPasswordLength) ?? 8))
1469
+ this.labels.errors.passwordTooShort.replace("{min}", String(((s = this.config) == null ? void 0 : s.minPasswordLength) ?? 8))
1408
1470
  );
1409
1471
  return;
1410
1472
  }
@@ -1418,7 +1480,7 @@ class Pe {
1418
1480
  name: this.state.name.trim(),
1419
1481
  email: this.state.email.trim(),
1420
1482
  password: this.state.password,
1421
- callbackURL: this.getManagedReturnURL(g, this.state.email.trim())
1483
+ callbackURL: this.getManagedReturnURL(S, this.state.email.trim())
1422
1484
  });
1423
1485
  if (i.error)
1424
1486
  throw i.error;
@@ -1430,28 +1492,28 @@ class Pe {
1430
1492
  });
1431
1493
  }
1432
1494
  async handleOAuthSignIn(e) {
1433
- await this.runAction(`Redirecting to ${N[e]}…`, async () => {
1434
- const t = await this.auth.signIn.social({
1495
+ await this.runAction(`Redirecting to ${D[e]}…`, async () => {
1496
+ const s = await this.auth.signIn.social({
1435
1497
  provider: e,
1436
1498
  callbackURL: this.getManagedReturnURL("oauth"),
1437
1499
  errorCallbackURL: this.getManagedReturnURL("oauth")
1438
1500
  });
1439
- if (t.error)
1440
- throw t.error;
1441
- const i = this.extractRedirectURL(t.data);
1501
+ if (s.error)
1502
+ throw s.error;
1503
+ const i = this.extractRedirectURL(s.data);
1442
1504
  if (!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);
1505
+ throw new u(`OAuth sign-in did not return a redirect URL for provider "${e}".`);
1506
+ this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = `Opening ${D[e]}…`, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(i);
1445
1507
  });
1446
1508
  }
1447
1509
  async handleForgotPassword() {
1448
1510
  if (!this.canUsePasswordResetEmailOtp()) {
1449
1511
  this.handleError(
1450
- new d("Password reset via email OTP is not enabled for this project.")
1512
+ new u("Password reset via email OTP is not enabled for this project.")
1451
1513
  );
1452
1514
  return;
1453
1515
  }
1454
- if (!D(this.state.email)) {
1516
+ if (!x(this.state.email)) {
1455
1517
  this.failValidation(this.labels.errors.invalidEmail);
1456
1518
  return;
1457
1519
  }
@@ -1468,14 +1530,14 @@ class Pe {
1468
1530
  this.isCountdownActive() || await this.handleForgotPassword();
1469
1531
  }
1470
1532
  async handleResetPassword() {
1471
- var e, t;
1533
+ var e, s;
1472
1534
  if (!this.canUsePasswordResetEmailOtp()) {
1473
1535
  this.handleError(
1474
- new d("Password reset via email OTP is not enabled for this project.")
1536
+ new u("Password reset via email OTP is not enabled for this project.")
1475
1537
  );
1476
1538
  return;
1477
1539
  }
1478
- if (!ge(this.state.code)) {
1540
+ if (!Ue(this.state.code)) {
1479
1541
  this.failValidation(this.labels.errors.invalidCode);
1480
1542
  return;
1481
1543
  }
@@ -1485,7 +1547,7 @@ class Pe {
1485
1547
  }
1486
1548
  if (this.state.newPassword.length < (((e = this.config) == null ? void 0 : e.minPasswordLength) ?? 8)) {
1487
1549
  this.failValidation(
1488
- this.labels.errors.passwordTooShort.replace("{min}", String(((t = this.config) == null ? void 0 : t.minPasswordLength) ?? 8))
1550
+ this.labels.errors.passwordTooShort.replace("{min}", String(((s = this.config) == null ? void 0 : s.minPasswordLength) ?? 8))
1489
1551
  );
1490
1552
  return;
1491
1553
  }
@@ -1509,29 +1571,29 @@ class Pe {
1509
1571
  }
1510
1572
  async sendVerificationEmail(e) {
1511
1573
  !e && this.isCountdownActive() || await this.runAction("Sending verification email…", async () => {
1512
- const t = await this.auth.sendVerificationEmail({
1574
+ const s = await this.auth.sendVerificationEmail({
1513
1575
  email: this.state.email.trim(),
1514
1576
  callbackURL: this.getManagedReturnURL(
1515
- this.verificationCompletionAction === "sign-up" ? g : T,
1577
+ this.verificationCompletionAction === "sign-up" ? S : R,
1516
1578
  this.state.email.trim()
1517
1579
  )
1518
1580
  });
1519
- if (t.error)
1520
- throw t.error;
1581
+ if (s.error)
1582
+ throw s.error;
1521
1583
  this.handleVerificationEmailSent(this.state.email.trim(), !0);
1522
1584
  });
1523
1585
  }
1524
- async completeAuth(e, t) {
1586
+ async completeAuth(e, s) {
1525
1587
  const i = await this.retryAuthCompletionDataIfNeeded(
1526
- t ?? await this.resolveAuthCompletionData()
1588
+ s ?? await this.resolveAuthCompletionData()
1527
1589
  );
1528
1590
  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());
1591
+ if (i.lookupError && $(this.options)) {
1592
+ 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(O(this.options.redirectTo).toString());
1531
1593
  return;
1532
1594
  }
1533
1595
  if (e === "sign-in")
1534
- throw i.lookupError ?? new ne(
1596
+ throw i.lookupError ?? new de(
1535
1597
  "Managed sign-in completed without an authenticated session."
1536
1598
  );
1537
1599
  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();
@@ -1542,11 +1604,11 @@ class Pe {
1542
1604
  user: i.user,
1543
1605
  session: i.session
1544
1606
  };
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());
1607
+ if (await this.syncPublicSessionBestEffort(), $(this.options)) {
1608
+ 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(O(this.options.redirectTo).toString());
1547
1609
  return;
1548
1610
  }
1549
- if (q(this.options)) {
1611
+ if (H(this.options)) {
1550
1612
  this.destroy(), this.options.onSuccess(r);
1551
1613
  return;
1552
1614
  }
@@ -1554,44 +1616,44 @@ class Pe {
1554
1616
  async retryAuthCompletionDataIfNeeded(e) {
1555
1617
  if (e.session)
1556
1618
  return e;
1557
- let t = e.lookupError;
1558
- for (let i = 0; i < z; i++) {
1559
- await new Promise((r) => setTimeout(r, se));
1619
+ let s = e.lookupError;
1620
+ for (let i = 0; i < q; i++) {
1621
+ await new Promise((r) => setTimeout(r, ae));
1560
1622
  try {
1561
- const r = await _(this.auth);
1623
+ const r = await C(this.auth);
1562
1624
  if (r.user && r.session)
1563
1625
  return {
1564
1626
  user: r.user,
1565
1627
  session: r.session
1566
1628
  };
1567
1629
  } catch (r) {
1568
- t = r;
1630
+ s = r;
1569
1631
  }
1570
1632
  }
1571
1633
  return {
1572
1634
  ...e,
1573
- lookupError: t ?? e.lookupError
1635
+ lookupError: s ?? e.lookupError
1574
1636
  };
1575
1637
  }
1576
1638
  async syncPublicSessionBestEffort() {
1577
- var e, t;
1639
+ var e, s;
1578
1640
  try {
1579
- await ((t = (e = this.runtimeOptions) == null ? void 0 : e.syncPublicSession) == null ? void 0 : t.call(e));
1641
+ await ((s = (e = this.runtimeOptions) == null ? void 0 : e.syncPublicSession) == null ? void 0 : s.call(e));
1580
1642
  } catch {
1581
1643
  }
1582
1644
  }
1583
1645
  async resolveAuthCompletionData(e) {
1584
1646
  try {
1585
- const t = await _(this.auth), i = this.extractUser(e);
1647
+ const s = await C(this.auth), i = this.extractUser(e);
1586
1648
  return {
1587
- user: t.user ?? i,
1588
- session: t.session
1649
+ user: s.user ?? i,
1650
+ session: s.session
1589
1651
  };
1590
- } catch (t) {
1652
+ } catch (s) {
1591
1653
  return {
1592
1654
  user: this.extractUser(e),
1593
1655
  session: null,
1594
- lookupError: t
1656
+ lookupError: s
1595
1657
  };
1596
1658
  }
1597
1659
  }
@@ -1601,26 +1663,26 @@ class Pe {
1601
1663
  user: null,
1602
1664
  session: null
1603
1665
  };
1604
- if (q(this.options)) {
1666
+ if (H(this.options)) {
1605
1667
  this.destroy(), this.options.onSuccess(e);
1606
1668
  return;
1607
1669
  }
1608
1670
  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();
1609
1671
  }
1610
1672
  handleExistingSessionOnMount(e) {
1611
- if (I(this.options)) {
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());
1673
+ if ($(this.options)) {
1674
+ 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(O(this.options.redirectTo).toString());
1613
1675
  return;
1614
1676
  }
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(
1677
+ if (H(this.options))
1678
+ throw this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, new u(
1617
1679
  "authUI.mount(container, { onSuccess }) cannot run while a session already exists. Check es.auth.getSession() before mounting controlled auth UI."
1618
1680
  );
1619
1681
  }
1620
- async runAction(e, t) {
1682
+ async runAction(e, s) {
1621
1683
  this.state.busy = !0, this.state.busyLabel = e, this.state.error = null, this.state.notice = null, this.render();
1622
1684
  try {
1623
- await t();
1685
+ await s();
1624
1686
  } catch (i) {
1625
1687
  if (this.maybeHandleVerificationRequired(i))
1626
1688
  return;
@@ -1630,45 +1692,45 @@ class Pe {
1630
1692
  !this.destroyed && !this.terminalActionInProgress && (this.state.busy = !1, this.state.busyLabel = void 0, this.render());
1631
1693
  }
1632
1694
  maybeHandleVerificationRequired(e) {
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);
1695
+ return N(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);
1634
1696
  }
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();
1697
+ handleVerificationEmailSent(e, s) {
1698
+ this.state.notice = s ? `We sent another verification email to ${e}.` : `We sent a verification email to ${e}.`, this.startCountdown();
1637
1699
  }
1638
1700
  invokeRedirectModeSuccessHook(e) {
1639
- var t, i;
1640
- if (!(!I(this.options) || !this.options.onSuccess))
1701
+ var s, i;
1702
+ if (!(!$(this.options) || !this.options.onSuccess))
1641
1703
  try {
1642
1704
  this.options.onSuccess(e);
1643
1705
  } catch (r) {
1644
- const o = V(r, "Post-auth callback failed.");
1706
+ const a = N(r, "Post-auth callback failed.");
1645
1707
  try {
1646
- (i = (t = this.options).onError) == null || i.call(t, o);
1708
+ (i = (s = this.options).onError) == null || i.call(s, a);
1647
1709
  } catch {
1648
1710
  }
1649
1711
  }
1650
1712
  }
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);
1713
+ handleError(e, s) {
1714
+ var r, a;
1715
+ const i = N(e, s);
1716
+ this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = i.message, this.render(), (a = (r = this.options).onError) == null || a.call(r, i);
1655
1717
  }
1656
1718
  failValidation(e) {
1657
1719
  this.state.error = e, this.state.notice = null, this.render();
1658
1720
  }
1659
- getManagedReturnURL(e, t) {
1721
+ getManagedReturnURL(e, s) {
1660
1722
  if (!e)
1661
1723
  return window.location.href;
1662
1724
  const i = new URL(window.location.href);
1663
- return i.searchParams.set(F, e), t ? i.searchParams.set(C, t) : i.searchParams.delete(C), i.toString();
1725
+ return i.searchParams.set(z, e), s ? i.searchParams.set(I, s) : i.searchParams.delete(I), i.toString();
1664
1726
  }
1665
1727
  consumeManagedReturnContext() {
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,
1728
+ const e = new URL(window.location.href), s = e.searchParams.get(z), i = e.searchParams.get(I), r = s ? e.searchParams.get("error") : null, a = s ? e.searchParams.get("error_description") : null;
1729
+ return (s || i) && (e.searchParams.delete(z), e.searchParams.delete(I), s && (e.searchParams.delete("error"), e.searchParams.delete("error_description")), window.history.replaceState(null, "", e.toString())), {
1730
+ marker: s,
1669
1731
  email: i,
1670
1732
  error: r,
1671
- errorDescription: o
1733
+ errorDescription: a
1672
1734
  };
1673
1735
  }
1674
1736
  startCountdown(e = 60) {
@@ -1696,7 +1758,7 @@ class Pe {
1696
1758
  this.pendingFocusSnapshot && (this.clearFocusRestoreTimer(), this.focusRestoreTimer = window.setTimeout(() => {
1697
1759
  if (this.focusRestoreTimer = null, this.destroyed || !this.pendingFocusSnapshot)
1698
1760
  return;
1699
- const e = this.pendingFocusSnapshot, t = `input[name="${this.escape(e.name)}"][type="${this.escape(e.type)}"]`, i = this.root.querySelector(t);
1761
+ const e = this.pendingFocusSnapshot, s = `input[name="${this.escape(e.name)}"][type="${this.escape(e.type)}"]`, i = this.root.querySelector(s);
1700
1762
  if (!(!i || i.disabled)) {
1701
1763
  if (i.focus(), e.selectionStart !== null && e.selectionEnd !== null)
1702
1764
  try {
@@ -1718,24 +1780,24 @@ class Pe {
1718
1780
  extractRedirectURL(e) {
1719
1781
  if (!e || typeof e != "object")
1720
1782
  return null;
1721
- const t = e;
1722
- return t.redirect && typeof t.url == "string" && t.url.length > 0 ? t.url : null;
1783
+ const s = e;
1784
+ return s.redirect && typeof s.url == "string" && s.url.length > 0 ? s.url : null;
1723
1785
  }
1724
1786
  extractUser(e) {
1725
1787
  if (!e || typeof e != "object")
1726
1788
  return null;
1727
- const t = e;
1728
- return t.user && typeof t.user == "object" ? t.user : null;
1789
+ const s = e;
1790
+ return s.user && typeof s.user == "object" ? s.user : null;
1729
1791
  }
1730
1792
  canUsePasswordResetEmailOtp() {
1731
1793
  var e;
1732
1794
  return !!((e = this.config) != null && e.passwordResetEmailOtpEnabled);
1733
1795
  }
1734
1796
  handleSessionlessManagedReturn(e) {
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(
1797
+ return e.email && (this.state.email = e.email), e.marker === S && !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 === R || e.marker === S ? (this.verificationCompletionAction = e.marker === S ? "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(
1736
1798
  e.errorDescription ?? "Verification failed. Request a new verification email and try again.",
1737
1799
  { code: e.error ?? "VERIFY_EMAIL_ERROR" }
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(
1800
+ )) : this.render(), !0) : e.marker === oe && (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(
1739
1801
  e.errorDescription ?? "OAuth sign-in failed.",
1740
1802
  { code: e.error ?? "OAUTH_ERROR" }
1741
1803
  )), !0) : !1;
@@ -1746,136 +1808,136 @@ class Pe {
1746
1808
  getCountdownSecondsRemaining() {
1747
1809
  return this.countdownUntil ? Math.max(0, Math.ceil((this.countdownUntil - Date.now()) / 1e3)) : 0;
1748
1810
  }
1749
- countdownText(e, t) {
1811
+ countdownText(e, s) {
1750
1812
  const i = this.getCountdownSecondsRemaining();
1751
- return i <= 0 ? e : t.replace("{seconds}", String(i));
1813
+ return i <= 0 ? e : s.replace("{seconds}", String(i));
1752
1814
  }
1753
1815
  escape(e) {
1754
1816
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1755
1817
  }
1756
1818
  }
1757
- function Le(s) {
1758
- return "data" in s && s.data ? s.data : s;
1819
+ function ke(t) {
1820
+ return "data" in t && t.data ? t.data : t;
1759
1821
  }
1760
- const ye = [
1822
+ const Me = [
1761
1823
  { id: "google", key: "providerGoogle" },
1762
1824
  { id: "apple", key: "providerApple" },
1763
1825
  { id: "microsoft", key: "providerMicrosoft" },
1764
1826
  { id: "github", key: "providerGithub" },
1765
1827
  { id: "gitlab", key: "providerGitlab" },
1766
1828
  { id: "discord", key: "providerDiscord" }
1767
- ], ie = 2, Ee = 500;
1768
- async function Se() {
1769
- const s = `${window.location.origin}${oe}/config`;
1829
+ ], le = 2, Oe = 500;
1830
+ async function Ve() {
1831
+ const t = `${window.location.origin}${ue}/config`;
1770
1832
  let e;
1771
- for (let t = 0; t <= ie; t++)
1833
+ for (let s = 0; s <= le; s++)
1772
1834
  try {
1773
- const i = await fetch(s, { method: "GET", credentials: "include" });
1835
+ const i = await fetch(t, { method: "GET", credentials: "include" });
1774
1836
  if (!i.ok)
1775
- throw new d(`Failed to load auth config: HTTP ${i.status}`);
1837
+ throw new u(`Failed to load auth config: HTTP ${i.status}`);
1776
1838
  const r = await i.json();
1777
- return Ce(Le(r));
1839
+ return Ne(ke(r));
1778
1840
  } catch (i) {
1779
- e = i, t < ie && await new Promise((r) => setTimeout(r, Ee));
1841
+ e = i, s < le && await new Promise((r) => setTimeout(r, Oe));
1780
1842
  }
1781
1843
  throw e;
1782
1844
  }
1783
- let R = null;
1784
- async function _e() {
1785
- return R || (R = Se().catch((s) => {
1786
- throw R = null, s;
1787
- })), R;
1845
+ let U = null;
1846
+ async function Fe() {
1847
+ return U || (U = Ve().catch((t) => {
1848
+ throw U = null, t;
1849
+ })), U;
1788
1850
  }
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);
1851
+ function Ne(t) {
1852
+ var s, i, r, a, c, p, T;
1853
+ const e = Me.filter(({ key: P }) => {
1854
+ const b = t[P];
1855
+ return typeof b == "object" && b !== null && "enabled" in b && !!b.enabled;
1856
+ }).map(({ id: P }) => P);
1795
1857
  return {
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),
1858
+ disableSignUp: !!t.disableSignUp,
1859
+ emailPasswordEnabled: !!((s = t.providerEmailPassword) != null && s.enabled),
1860
+ minPasswordLength: ((r = (i = t.providerEmailPassword) == null ? void 0 : i.config) == null ? void 0 : r.minPasswordLength) ?? 8,
1861
+ requireEmailVerification: !!((c = (a = t.providerEmailPassword) == null ? void 0 : a.config) != null && c.requireEmailVerification),
1862
+ passwordResetEmailOtpEnabled: !!((T = (p = t.providerEmailPassword) == null ? void 0 : p.config) != null && T.requirePasswordResetEmailVerification),
1801
1863
  oauthProviders: e
1802
1864
  };
1803
1865
  }
1804
- const $ = /* @__PURE__ */ new WeakMap();
1805
- function Te(s) {
1806
- if (!s)
1807
- throw new d(
1866
+ const A = /* @__PURE__ */ new WeakMap();
1867
+ function ze(t) {
1868
+ if (!t)
1869
+ throw new u(
1808
1870
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1809
1871
  );
1810
- const e = "redirectTo" in s, t = "onSuccess" in s && typeof s.onSuccess == "function";
1811
- if (!e && !t)
1812
- throw new d(
1872
+ const e = "redirectTo" in t, s = "onSuccess" in t && typeof t.onSuccess == "function";
1873
+ if (!e && !s)
1874
+ throw new u(
1813
1875
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1814
1876
  );
1815
- if ("redirectTo" in s) {
1816
- const i = s.redirectTo;
1877
+ if ("redirectTo" in t) {
1878
+ const i = t.redirectTo;
1817
1879
  if (!(typeof i == "string" || i instanceof URL))
1818
- throw new d(
1880
+ throw new u(
1819
1881
  "authUI.mount(container, options) expected redirectTo to be a string or URL."
1820
1882
  );
1821
1883
  }
1822
- if ("onSuccess" in s && s.onSuccess !== void 0 && typeof s.onSuccess != "function")
1823
- throw new d(
1884
+ if ("onSuccess" in t && t.onSuccess !== void 0 && typeof t.onSuccess != "function")
1885
+ throw new u(
1824
1886
  "authUI.mount(container, options) expected onSuccess to be a function."
1825
1887
  );
1826
- if ("onError" in s && s.onError !== void 0 && typeof s.onError != "function")
1827
- throw new d(
1888
+ if ("onError" in t && t.onError !== void 0 && typeof t.onError != "function")
1889
+ throw new u(
1828
1890
  "authUI.mount(container, options) expected onError to be a function."
1829
1891
  );
1830
1892
  }
1831
- function Ie(s) {
1832
- if (!(s instanceof HTMLElement))
1833
- throw new d("authUI.mount(container, options) requires a real HTMLElement container.");
1893
+ function qe(t) {
1894
+ if (!(t instanceof HTMLElement))
1895
+ throw new u("authUI.mount(container, options) requires a real HTMLElement container.");
1834
1896
  }
1835
- function Re(s, e) {
1897
+ function De(t, e) {
1836
1898
  return {
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 = {
1899
+ mount(s, i) {
1900
+ var p;
1901
+ ze(i), qe(s), (p = A.get(s)) == null || p.destroy();
1902
+ const r = new Be(s, t, i, Fe, e), a = r.destroy.bind(r), c = {
1841
1903
  destroy() {
1842
- o(), $.get(t) === u && $.delete(t);
1904
+ a(), A.get(s) === c && A.delete(s);
1843
1905
  }
1844
1906
  };
1845
- return $.set(t, u), u;
1907
+ return A.set(s, c), c;
1846
1908
  }
1847
1909
  };
1848
1910
  }
1849
- function Ue() {
1850
- re();
1851
- const s = me(), e = we(), t = ue(), i = Re(e, {
1911
+ function xe() {
1912
+ ce();
1913
+ const t = Te(), e = Ce(), s = ye(), i = De(e, {
1852
1914
  syncPublicSession: async () => {
1853
- await he(s);
1915
+ await _e(t);
1854
1916
  }
1855
1917
  });
1856
1918
  return {
1857
- auth: s,
1858
- api: t,
1919
+ auth: t,
1920
+ api: s,
1859
1921
  authUI: i
1860
1922
  };
1861
1923
  }
1862
1924
  export {
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
1925
+ w as EdgeSparkAuthError,
1926
+ u as EdgeSparkConfigError,
1927
+ j as EdgeSparkError,
1928
+ de as EdgeSparkRuntimeError,
1929
+ ie as ar,
1930
+ xe as createEdgeSpark,
1931
+ ee as de,
1932
+ Re as detectLocale,
1933
+ B as enUS,
1934
+ F as es,
1935
+ X as fr,
1936
+ ne as hi,
1937
+ te as it,
1938
+ J as ja,
1939
+ Z as ko,
1940
+ Q as ptBR,
1941
+ se as ru,
1942
+ V as zhCN
1881
1943
  };