@edgespark/web 0.0.1-beta.0 → 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,136 +1,159 @@
1
- import { createAuthClient as Z } from "better-auth/client";
2
- class R extends Error {
1
+ import { createAuthClient as te } from "better-auth/client";
2
+ class U extends Error {
3
3
  constructor(e, s) {
4
4
  super(s), this.name = "EdgeSparkError", this.code = e;
5
5
  }
6
6
  }
7
- class d extends R {
7
+ class u extends U {
8
8
  constructor(e) {
9
9
  super("CONFIG_ERROR", e), this.name = "EdgeSparkConfigError";
10
10
  }
11
11
  }
12
- class G extends R {
12
+ class K extends U {
13
13
  constructor(e) {
14
14
  super("RUNTIME_ERROR", e), this.name = "EdgeSparkRuntimeError";
15
15
  }
16
16
  }
17
- class u extends R {
17
+ class w extends U {
18
18
  constructor(e, s) {
19
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 K() {
22
+ function J() {
23
23
  if (typeof window > "u" || typeof document > "u")
24
- throw new G(
24
+ throw new K(
25
25
  "@edgespark/web is browser-only. Create the client from a real browser runtime."
26
26
  );
27
27
  }
28
- function T() {
29
- return K(), window.location.origin;
28
+ function I() {
29
+ return J(), window.location.origin;
30
30
  }
31
- function Q(t) {
31
+ function se(t) {
32
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 X(t) {
35
- if (t.origin !== T())
36
- throw new d(
37
- `Cross-origin requests are not supported by this SDK. Received ${t.origin}, expected ${T()}.`
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()}.`
38
38
  );
39
39
  }
40
- function ee() {
40
+ function ne() {
41
41
  return {
42
42
  async fetch(t, e) {
43
- const s = Q(t);
44
- return X(s), fetch(t, {
43
+ const s = se(t);
44
+ return ie(s), fetch(t, {
45
45
  ...e,
46
46
  credentials: "include"
47
47
  });
48
48
  }
49
49
  };
50
50
  }
51
- const Y = "/api/_es/auth";
52
- function J(t) {
53
- return Z({
54
- baseURL: T(),
55
- basePath: Y,
51
+ const Z = "/api/_es/auth";
52
+ function Q(t) {
53
+ return te({
54
+ baseURL: I(),
55
+ basePath: Z,
56
56
  ...t != null && t.disableDefaultRedirectPlugin ? { disableDefaultFetchPlugins: !0 } : {},
57
57
  fetchOptions: {
58
58
  credentials: "include"
59
59
  }
60
60
  });
61
61
  }
62
- function I(t) {
62
+ function P(t) {
63
63
  var e, s;
64
64
  return (s = (e = t.$store) == null ? void 0 : e.atoms) == null ? void 0 : s.session;
65
65
  }
66
- async function te(t) {
66
+ async function oe(t) {
67
67
  var e;
68
- await ((e = I(t)) == null ? void 0 : e.get().refetch());
68
+ await ((e = P(t)) == null ? void 0 : e.get().refetch());
69
69
  }
70
- function se() {
71
- const t = J(), e = t.getSession().then((o) => o.data ?? null), s = async () => {
72
- var r, l;
73
- const o = await t.getSession();
74
- if ((r = o.data) != null && r.session && ((l = o.data) != null && l.user))
75
- return o.data;
76
- throw new u("No authenticated session is available.", {
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));
77
+ }
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.", {
77
90
  code: "UNAUTHENTICATED",
78
- cause: o.error
91
+ cause: l.error
79
92
  });
80
- }, i = (o) => {
81
- let r = !1, l = !1, c;
82
- e.then((b) => {
83
- r || (l = !0, c = b, o(b));
93
+ }, c = (l) => {
94
+ let r = !1, d = !1, A;
95
+ const B = (m) => {
96
+ m !== A && (A = m, l(m));
97
+ };
98
+ o().then((m) => {
99
+ r || (d = !0, B(m));
84
100
  });
85
- const h = I(t);
86
- if (!h)
101
+ const M = P(t);
102
+ if (!M)
87
103
  return () => {
88
104
  r = !0;
89
105
  };
90
- const m = h.subscribe((b) => {
91
- if (r || !l) return;
92
- const L = b.data ?? null;
93
- L !== c && (c = L, o(L));
106
+ const X = M.subscribe((m) => {
107
+ if (r || !d)
108
+ return;
109
+ const ee = m.data ?? null;
110
+ B(ee);
94
111
  });
95
112
  return () => {
96
- r = !0, m();
113
+ r = !0, X();
97
114
  };
98
- }, a = async (...o) => {
99
- var l;
100
- const r = await t.signOut(...o);
101
- return await ((l = I(t)) == null ? void 0 : l.get().refetch()), r;
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;
120
+ try {
121
+ await ((d = P(t)) == null ? void 0 : d.get().refetch());
122
+ } catch {
123
+ }
124
+ return r;
102
125
  };
103
126
  return new Proxy(t, {
104
- get(o, r, l) {
105
- return r === "requireSession" ? s : r === "onSessionChange" ? i : r === "signOut" ? a : Reflect.get(o, r, l);
127
+ get(l, r, d) {
128
+ return r === "requireSession" ? a : r === "onSessionChange" ? c : r === "signOut" ? h : Reflect.get(l, r, d);
106
129
  }
107
130
  });
108
131
  }
109
- function ie() {
110
- return J({ disableDefaultRedirectPlugin: !0 });
132
+ function re() {
133
+ return Q({ disableDefaultRedirectPlugin: !0 });
111
134
  }
112
- function U(t) {
135
+ function k(t) {
113
136
  const e = (() => {
114
137
  if (t instanceof URL)
115
138
  return t;
116
139
  const s = t.trim();
117
140
  if (!s)
118
- throw new d("redirectTo must not be an empty string.");
141
+ throw new u("redirectTo must not be an empty string.");
119
142
  try {
120
143
  return new URL(s, window.location.href);
121
144
  } catch {
122
- throw new d(
145
+ throw new u(
123
146
  `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(t)}`
124
147
  );
125
148
  }
126
149
  })();
127
150
  if (e.protocol !== "http:" && e.protocol !== "https:")
128
- throw new d(
151
+ throw new u(
129
152
  `redirectTo must resolve to an http(s) URL. Received protocol: ${e.protocol}`
130
153
  );
131
154
  return e;
132
155
  }
133
- function ne(t, e) {
156
+ function le(t, e) {
134
157
  return e ? {
135
158
  common: { ...t.common, ...e.common },
136
159
  signIn: { ...t.signIn, ...e.signIn },
@@ -142,7 +165,7 @@ function ne(t, e) {
142
165
  errors: { ...t.errors, ...e.errors }
143
166
  } : t;
144
167
  }
145
- const P = {
168
+ const y = {
146
169
  common: {
147
170
  loading: "Loading sign-in…",
148
171
  redirecting: "Redirecting…",
@@ -205,7 +228,7 @@ const P = {
205
228
  invalidCode: "Enter the 6-digit verification code.",
206
229
  generic: "Something went wrong. Please try again."
207
230
  }
208
- }, y = {
231
+ }, L = {
209
232
  common: {
210
233
  loading: "加载中…",
211
234
  redirecting: "跳转中…",
@@ -268,7 +291,7 @@ const P = {
268
291
  invalidCode: "请输入 6 位验证码",
269
292
  generic: "出现错误,请稍后重试"
270
293
  }
271
- }, A = {
294
+ }, V = {
272
295
  common: {
273
296
  loading: "サインインを読み込み中…",
274
297
  redirecting: "リダイレクト中…",
@@ -331,7 +354,7 @@ const P = {
331
354
  invalidCode: "6桁の認証コードを入力してください",
332
355
  generic: "エラーが発生しました。もう一度お試しください"
333
356
  }
334
- }, B = {
357
+ }, O = {
335
358
  common: {
336
359
  loading: "로그인 로딩 중…",
337
360
  redirecting: "리디렉션 중…",
@@ -457,7 +480,7 @@ const P = {
457
480
  invalidCode: "Ingresa el código de verificación de 6 dígitos.",
458
481
  generic: "Algo salió mal. Por favor, inténtalo de nuevo."
459
482
  }
460
- }, M = {
483
+ }, z = {
461
484
  common: {
462
485
  loading: "Carregando login…",
463
486
  redirecting: "Redirecionando…",
@@ -520,7 +543,7 @@ const P = {
520
543
  invalidCode: "Insira o código de verificação de 6 dígitos.",
521
544
  generic: "Algo deu errado. Por favor, tente novamente."
522
545
  }
523
- }, k = {
546
+ }, F = {
524
547
  common: {
525
548
  loading: "Chargement de la connexion…",
526
549
  redirecting: "Redirection…",
@@ -583,7 +606,7 @@ const P = {
583
606
  invalidCode: "Saisissez le code de vérification à 6 chiffres.",
584
607
  generic: "Une erreur est survenue. Veuillez réessayer."
585
608
  }
586
- }, V = {
609
+ }, q = {
587
610
  common: {
588
611
  loading: "Anmeldung wird geladen…",
589
612
  redirecting: "Weiterleitung…",
@@ -646,7 +669,7 @@ const P = {
646
669
  invalidCode: "Geben Sie den 6-stelligen Bestätigungscode ein.",
647
670
  generic: "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
648
671
  }
649
- }, O = {
672
+ }, N = {
650
673
  common: {
651
674
  loading: "Caricamento accesso…",
652
675
  redirecting: "Reindirizzamento…",
@@ -709,7 +732,7 @@ const P = {
709
732
  invalidCode: "Inserisci il codice di verifica a 6 cifre.",
710
733
  generic: "Qualcosa è andato storto. Riprova."
711
734
  }
712
- }, F = {
735
+ }, D = {
713
736
  common: {
714
737
  loading: "Загрузка входа…",
715
738
  redirecting: "Перенаправление…",
@@ -772,7 +795,7 @@ const P = {
772
795
  invalidCode: "Введите 6-значный код подтверждения.",
773
796
  generic: "Произошла ошибка. Пожалуйста, попробуйте снова."
774
797
  }
775
- }, z = {
798
+ }, x = {
776
799
  common: {
777
800
  loading: "جارٍ تحميل تسجيل الدخول…",
778
801
  redirecting: "جارٍ إعادة التوجيه…",
@@ -835,7 +858,7 @@ const P = {
835
858
  invalidCode: "يرجى إدخال رمز التحقّق المكوّن من 6 أرقام.",
836
859
  generic: "حدث خطأ. يرجى المحاولة مرة أخرى."
837
860
  }
838
- }, q = {
861
+ }, H = {
839
862
  common: {
840
863
  loading: "सधाइन की जुलातीअ लोड हो रही है…",
841
864
  redirecting: "रीडायरेक्ट हो रहا है…",
@@ -898,58 +921,58 @@ const P = {
898
921
  invalidCode: "कृपया 6 अंकों का सत्यापन कोड दर्ज करें।",
899
922
  generic: "कुछ गलत हो गई। कृपया फिर से प्रयास करें।"
900
923
  }
901
- }, N = {
902
- en: P,
903
- "en-US": P,
904
- zh: y,
905
- "zh-CN": y,
906
- "zh-TW": y,
907
- ja: A,
908
- "ja-JP": A,
909
- ko: B,
910
- "ko-KR": B,
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,
911
934
  es: E,
912
935
  "es-ES": E,
913
936
  "es-MX": E,
914
- pt: M,
915
- "pt-BR": M,
916
- fr: k,
917
- "fr-FR": k,
918
- de: V,
919
- "de-DE": V,
920
- it: O,
921
- "it-IT": O,
922
- ru: F,
923
- "ru-RU": F,
924
- ar: z,
925
- "ar-SA": z,
926
- hi: q,
927
- "hi-IN": q
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
928
951
  };
929
- function ae() {
952
+ function de() {
930
953
  if (typeof navigator > "u")
931
- return P;
954
+ return y;
932
955
  const t = navigator.languages ?? [navigator.language];
933
956
  for (const e of t) {
934
- const s = N[e] ?? N[e.split("-")[0]];
957
+ const s = W[e] ?? W[e.split("-")[0]];
935
958
  if (s) return s;
936
959
  }
937
- return P;
960
+ return y;
938
961
  }
939
- function x(t, e = "Authentication failed.") {
940
- if (t instanceof u)
962
+ function S(t, e = "Authentication failed.") {
963
+ if (t instanceof w)
941
964
  return t;
942
965
  if (typeof t == "object" && t !== null) {
943
966
  const s = t;
944
- return new u(s.message || e, {
967
+ return new w(s.message || e, {
945
968
  code: s.code,
946
969
  status: s.status,
947
970
  cause: t
948
971
  });
949
972
  }
950
- return typeof t == "string" ? new u(t) : new u(e, { cause: t });
973
+ return typeof t == "string" ? new w(t) : new w(e, { cause: t });
951
974
  }
952
- async function D(t) {
975
+ async function j(t) {
953
976
  var s, i;
954
977
  const e = await t.getSession();
955
978
  return (s = e.data) != null && s.user && ((i = e.data) != null && i.session) ? {
@@ -960,7 +983,7 @@ async function D(t) {
960
983
  session: null
961
984
  };
962
985
  }
963
- const oe = "data-edgespark-auth", n = "edgespark-auth", S = "es_auth_completion", p = "es_auth_email", W = "oauth", g = "verify-sign-in", w = "verify-sign-up", C = {
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", _ = {
964
987
  google: "Google",
965
988
  apple: "Apple",
966
989
  microsoft: "Microsoft",
@@ -968,24 +991,24 @@ const oe = "data-edgespark-auth", n = "edgespark-auth", S = "es_auth_completion"
968
991
  gitlab: "GitLab",
969
992
  discord: "Discord"
970
993
  };
971
- function H(t) {
994
+ function R(t) {
972
995
  return "redirectTo" in t;
973
996
  }
974
- function _(t) {
997
+ function T(t) {
975
998
  return "onSuccess" in t && !("redirectTo" in t);
976
999
  }
977
1000
  function $(t) {
978
1001
  return !t || typeof t != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim());
979
1002
  }
980
- function re(t) {
1003
+ function ue(t) {
981
1004
  return /^\d{6}$/.test(t.trim());
982
1005
  }
983
- function le(t) {
1006
+ function he(t) {
984
1007
  return t === "email" || t === "name" || t === "password" || t === "confirmPassword" || t === "code" || t === "newPassword";
985
1008
  }
986
- class de {
987
- constructor(e, s, i, a, o) {
988
- if (this.container = e, this.auth = s, this.options = i, this.loadConfig = a, this.runtimeOptions = o, this.state = {
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 = {
989
1012
  view: "loading",
990
1013
  busy: !0,
991
1014
  busyLabel: void 0,
@@ -998,8 +1021,8 @@ class de {
998
1021
  code: "",
999
1022
  newPassword: ""
1000
1023
  }, 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))
1001
- throw new d("authUI.mount(container, options) requires a real HTMLElement container.");
1002
- this.labels = ne(ae(), i.labels), this.root = document.createElement("div"), this.root.setAttribute(oe, ""), e.innerHTML = "", e.appendChild(this.root), this.render(), this.initialize();
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();
1003
1026
  }
1004
1027
  destroy() {
1005
1028
  this.destroyed || (this.destroyed = !0, this.clearCountdown(), this.clearFocusRestoreTimer(), this.container.innerHTML = "");
@@ -1008,17 +1031,17 @@ class de {
1008
1031
  try {
1009
1032
  const e = this.consumeManagedReturnContext(), [s, i] = await Promise.all([
1010
1033
  this.loadConfig(),
1011
- D(this.auth)
1034
+ j(this.auth)
1012
1035
  ]);
1013
1036
  if (this.destroyed)
1014
1037
  return;
1015
1038
  if (this.config = s, i.user && i.session) {
1016
1039
  switch (e.marker) {
1017
- case W:
1040
+ case G:
1018
1041
  case g:
1019
1042
  await this.completeAuth("sign-in", i);
1020
1043
  return;
1021
- case w:
1044
+ case b:
1022
1045
  await this.completeAuth("sign-up", i);
1023
1046
  return;
1024
1047
  default:
@@ -1089,7 +1112,7 @@ class de {
1089
1112
  }
1090
1113
  }
1091
1114
  renderSignInView() {
1092
- var i, a;
1115
+ var i, o;
1093
1116
  const e = this.renderOAuthProviders(), s = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1094
1117
  return `
1095
1118
  <section class="${n}__section">
@@ -1113,7 +1136,7 @@ class de {
1113
1136
  ${this.escape(this.labels.signIn.forgotPassword)}
1114
1137
  </button>
1115
1138
  ` : ""}
1116
- ${(a = this.config) != null && a.disableSignUp ? "" : `
1139
+ ${(o = this.config) != null && o.disableSignUp ? "" : `
1117
1140
  <p class="${n}__meta">
1118
1141
  ${this.escape(this.labels.signIn.signUpPrompt)}
1119
1142
  <button class="${n}__link" type="button" data-action="switch-sign-up" ${this.state.busy ? "disabled" : ""}>
@@ -1234,13 +1257,13 @@ class de {
1234
1257
  <div class="${n}__stack">
1235
1258
  ${e.map((i) => `
1236
1259
  <button class="${n}__button ${n}__button--secondary" type="button" data-action="oauth" data-provider="${i}" ${this.state.busy ? "disabled" : ""}>
1237
- ${this.escape(`${this.labels.oauth.continueWith} ${C[i]}`)}
1260
+ ${this.escape(`${this.labels.oauth.continueWith} ${_[i]}`)}
1238
1261
  </button>
1239
1262
  `).join("")}
1240
1263
  </div>
1241
1264
  `;
1242
1265
  }
1243
- renderInput(e, s, i, a, o) {
1266
+ renderInput(e, s, i, o, a) {
1244
1267
  return `
1245
1268
  <label class="${n}__field">
1246
1269
  <span class="${n}__label">${this.escape(s)}</span>
@@ -1248,28 +1271,28 @@ class de {
1248
1271
  class="${n}__input"
1249
1272
  name="${this.escape(e)}"
1250
1273
  type="${this.escape(i)}"
1251
- value="${this.escape(a)}"
1252
- autocomplete="${this.escape(o)}"
1274
+ value="${this.escape(o)}"
1275
+ autocomplete="${this.escape(a)}"
1253
1276
  ${this.state.busy ? "disabled" : ""}
1254
1277
  />
1255
1278
  </label>
1256
1279
  `;
1257
1280
  }
1258
1281
  bindDOM() {
1259
- this.root.querySelectorAll("form[data-view]").forEach((a) => {
1260
- a.addEventListener("submit", (o) => {
1261
- o.preventDefault();
1262
- const r = a.dataset.view;
1263
- r === "sign-in" && this.handleSignIn(), r === "sign-up" && this.handleSignUp(), r === "forgot-password" && this.handleForgotPassword(), r === "reset-password" && this.handleResetPassword();
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();
1264
1287
  });
1265
- }), this.root.querySelectorAll("input[name]").forEach((a) => {
1266
- a.addEventListener("input", () => {
1267
- le(a.name) && (this.state[a.name] = a.value);
1288
+ }), this.root.querySelectorAll("input[name]").forEach((o) => {
1289
+ o.addEventListener("input", () => {
1290
+ he(o.name) && (this.state[o.name] = o.value);
1268
1291
  });
1269
- }), this.root.querySelectorAll("[data-action]").forEach((a) => {
1270
- a.addEventListener("click", () => {
1271
- const o = a.dataset.action;
1272
- 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(a.dataset.provider);
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);
1273
1296
  });
1274
1297
  });
1275
1298
  }
@@ -1321,16 +1344,16 @@ class de {
1321
1344
  return;
1322
1345
  }
1323
1346
  await this.runAction("Creating account…", async () => {
1324
- var a;
1347
+ var o;
1325
1348
  const i = await this.auth.signUp.email({
1326
1349
  name: this.state.name.trim(),
1327
1350
  email: this.state.email.trim(),
1328
1351
  password: this.state.password,
1329
- callbackURL: this.getManagedReturnURL(w, this.state.email.trim())
1352
+ callbackURL: this.getManagedReturnURL(b, this.state.email.trim())
1330
1353
  });
1331
1354
  if (i.error)
1332
1355
  throw i.error;
1333
- if ((a = this.config) != null && a.requireEmailVerification) {
1356
+ if ((o = this.config) != null && o.requireEmailVerification) {
1334
1357
  this.verificationCompletionAction = "sign-up", this.state.view = "verify-email", this.state.notice = "Check your inbox to verify your email address.", this.startCountdown();
1335
1358
  return;
1336
1359
  }
@@ -1338,7 +1361,7 @@ class de {
1338
1361
  });
1339
1362
  }
1340
1363
  async handleOAuthSignIn(e) {
1341
- await this.runAction(`Redirecting to ${C[e]}…`, async () => {
1364
+ await this.runAction(`Redirecting to ${_[e]}…`, async () => {
1342
1365
  const s = await this.auth.signIn.social({
1343
1366
  provider: e,
1344
1367
  callbackURL: this.getManagedReturnURL("oauth"),
@@ -1348,14 +1371,14 @@ class de {
1348
1371
  throw s.error;
1349
1372
  const i = this.extractRedirectURL(s.data);
1350
1373
  if (!i)
1351
- throw new d(`OAuth sign-in did not return a redirect URL for provider "${e}".`);
1352
- this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = `Opening ${C[e]}…`, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(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);
1353
1376
  });
1354
1377
  }
1355
1378
  async handleForgotPassword() {
1356
1379
  if (!this.canUsePasswordResetEmailOtp()) {
1357
1380
  this.handleError(
1358
- new d("Password reset via email OTP is not enabled for this project.")
1381
+ new u("Password reset via email OTP is not enabled for this project.")
1359
1382
  );
1360
1383
  return;
1361
1384
  }
@@ -1378,11 +1401,11 @@ class de {
1378
1401
  async handleResetPassword() {
1379
1402
  if (!this.canUsePasswordResetEmailOtp()) {
1380
1403
  this.handleError(
1381
- new d("Password reset via email OTP is not enabled for this project.")
1404
+ new u("Password reset via email OTP is not enabled for this project.")
1382
1405
  );
1383
1406
  return;
1384
1407
  }
1385
- if (!re(this.state.code)) {
1408
+ if (!ue(this.state.code)) {
1386
1409
  this.failValidation(this.labels.errors.invalidCode);
1387
1410
  return;
1388
1411
  }
@@ -1413,7 +1436,7 @@ class de {
1413
1436
  const s = await this.auth.sendVerificationEmail({
1414
1437
  email: this.state.email.trim(),
1415
1438
  callbackURL: this.getManagedReturnURL(
1416
- this.verificationCompletionAction === "sign-up" ? w : g,
1439
+ this.verificationCompletionAction === "sign-up" ? b : g,
1417
1440
  this.state.email.trim()
1418
1441
  )
1419
1442
  });
@@ -1423,55 +1446,54 @@ class de {
1423
1446
  });
1424
1447
  }
1425
1448
  async completeAuth(e, s) {
1426
- var o, r, l, c;
1449
+ var a, c;
1427
1450
  const i = s ?? await this.resolveAuthCompletionData();
1428
1451
  if (!i.user || !i.session) {
1429
1452
  if (e === "sign-in")
1430
- throw new G("Managed sign-in completed without an authenticated session.");
1453
+ throw new K("Managed sign-in completed without an authenticated session.");
1431
1454
  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();
1432
1455
  return;
1433
1456
  }
1434
- const a = {
1457
+ const o = {
1435
1458
  action: e,
1436
1459
  user: i.user,
1437
1460
  session: i.session
1438
1461
  };
1439
- if (await ((r = (o = this.runtimeOptions) == null ? void 0 : o.syncPublicSession) == null ? void 0 : r.call(o)), H(this.options)) {
1440
- this.terminalActionInProgress = !0, (c = (l = this.options).onSuccess) == null || c.call(l, a), this.state.busy = !0, this.state.busyLabel = this.labels.common.redirecting, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(U(this.options.redirectTo).toString());
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());
1441
1464
  return;
1442
1465
  }
1443
- if (_(this.options)) {
1444
- this.destroy(), this.options.onSuccess(a);
1466
+ if (T(this.options)) {
1467
+ this.destroy(), this.options.onSuccess(o);
1445
1468
  return;
1446
1469
  }
1447
1470
  }
1448
1471
  async resolveAuthCompletionData(e) {
1449
- const s = await D(this.auth), i = this.extractUser(e);
1472
+ const s = await j(this.auth), i = this.extractUser(e);
1450
1473
  return {
1451
1474
  user: s.user ?? i,
1452
1475
  session: s.session
1453
1476
  };
1454
1477
  }
1455
1478
  async completePasswordReset() {
1456
- var s, i;
1457
1479
  const e = {
1458
1480
  action: "password-reset",
1459
1481
  user: null,
1460
1482
  session: null
1461
1483
  };
1462
- if (_(this.options)) {
1484
+ if (T(this.options)) {
1463
1485
  this.destroy(), this.options.onSuccess(e);
1464
1486
  return;
1465
1487
  }
1466
- (i = (s = this.options).onSuccess) == null || i.call(s, 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();
1488
+ 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();
1467
1489
  }
1468
1490
  handleExistingSessionOnMount(e) {
1469
- if (H(this.options)) {
1470
- 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(U(this.options.redirectTo).toString());
1491
+ if (R(this.options)) {
1492
+ 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());
1471
1493
  return;
1472
1494
  }
1473
- if (_(this.options))
1474
- throw this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, new d(
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(
1475
1497
  "authUI.mount(container, { onSuccess }) cannot run while a session already exists. Check es.auth.getSession() before mounting controlled auth UI."
1476
1498
  );
1477
1499
  }
@@ -1488,15 +1510,28 @@ class de {
1488
1510
  !this.destroyed && !this.terminalActionInProgress && (this.state.busy = !1, this.state.busyLabel = void 0, this.render());
1489
1511
  }
1490
1512
  maybeHandleVerificationRequired(e) {
1491
- return x(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);
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);
1492
1514
  }
1493
1515
  handleVerificationEmailSent(e, s) {
1494
1516
  this.state.notice = s ? `We sent another verification email to ${e}.` : `We sent a verification email to ${e}.`, this.startCountdown();
1495
1517
  }
1518
+ invokeRedirectModeSuccessHook(e) {
1519
+ var s, i;
1520
+ if (!(!R(this.options) || !this.options.onSuccess))
1521
+ try {
1522
+ this.options.onSuccess(e);
1523
+ } catch (o) {
1524
+ const a = S(o, "Post-auth callback failed.");
1525
+ try {
1526
+ (i = (s = this.options).onError) == null || i.call(s, a);
1527
+ } catch {
1528
+ }
1529
+ }
1530
+ }
1496
1531
  handleError(e, s) {
1497
- var a, o;
1498
- const i = x(e, s);
1499
- this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = i.message, this.render(), (o = (a = this.options).onError) == null || o.call(a, i);
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);
1500
1535
  }
1501
1536
  failValidation(e) {
1502
1537
  this.state.error = e, this.state.notice = null, this.render();
@@ -1505,15 +1540,15 @@ class de {
1505
1540
  if (!e)
1506
1541
  return window.location.href;
1507
1542
  const i = new URL(window.location.href);
1508
- return i.searchParams.set(S, e), s ? i.searchParams.set(p, s) : i.searchParams.delete(p), i.toString();
1543
+ return i.searchParams.set(C, e), s ? i.searchParams.set(p, s) : i.searchParams.delete(p), i.toString();
1509
1544
  }
1510
1545
  consumeManagedReturnContext() {
1511
- const e = new URL(window.location.href), s = e.searchParams.get(S), i = e.searchParams.get(p), a = e.searchParams.get("error"), o = e.searchParams.get("error_description");
1512
- return (s || i || a || o) && (e.searchParams.delete(S), e.searchParams.delete(p), e.searchParams.delete("error"), e.searchParams.delete("error_description"), window.history.replaceState(null, "", e.toString())), {
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())), {
1513
1548
  marker: s,
1514
1549
  email: i,
1515
- error: a,
1516
- errorDescription: o
1550
+ error: o,
1551
+ errorDescription: a
1517
1552
  };
1518
1553
  }
1519
1554
  startCountdown(e = 60) {
@@ -1547,8 +1582,8 @@ class de {
1547
1582
  try {
1548
1583
  i.setSelectionRange(e.selectionStart, e.selectionEnd);
1549
1584
  } catch {
1550
- const a = i.value.length;
1551
- i.setSelectionRange(a, a);
1585
+ const o = i.value.length;
1586
+ i.setSelectionRange(o, o);
1552
1587
  }
1553
1588
  this.pendingFocusSnapshot = null;
1554
1589
  }
@@ -1577,10 +1612,10 @@ class de {
1577
1612
  return !!((e = this.config) != null && e.passwordResetEmailOtpEnabled);
1578
1613
  }
1579
1614
  handleSessionlessManagedReturn(e) {
1580
- return e.email && (this.state.email = e.email), e.marker === w && !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 === w ? (this.verificationCompletionAction = e.marker === w ? "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 u(
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(
1581
1616
  e.errorDescription ?? "Verification failed. Request a new verification email and try again.",
1582
1617
  { code: e.error ?? "VERIFY_EMAIL_ERROR" }
1583
- )) : this.render(), !0) : e.marker === W && (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 u(
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(
1584
1619
  e.errorDescription ?? "OAuth sign-in failed.",
1585
1620
  { code: e.error ?? "OAUTH_ERROR" }
1586
1621
  )), !0) : !1;
@@ -1599,103 +1634,103 @@ class de {
1599
1634
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1600
1635
  }
1601
1636
  }
1602
- function ce(t) {
1637
+ function we(t) {
1603
1638
  return "data" in t && t.data ? t.data : t;
1604
1639
  }
1605
- const ue = [
1640
+ const be = [
1606
1641
  { id: "google", key: "providerGoogle" },
1607
1642
  { id: "apple", key: "providerApple" },
1608
1643
  { id: "microsoft", key: "providerMicrosoft" },
1609
1644
  { id: "github", key: "providerGithub" },
1610
1645
  { id: "gitlab", key: "providerGitlab" },
1611
1646
  { id: "discord", key: "providerDiscord" }
1612
- ], j = 2, he = 500;
1613
- async function me() {
1614
- const t = `${window.location.origin}${Y}/config`;
1647
+ ], Y = 2, pe = 500;
1648
+ async function ge() {
1649
+ const t = `${window.location.origin}${Z}/config`;
1615
1650
  let e;
1616
- for (let s = 0; s <= j; s++)
1651
+ for (let s = 0; s <= Y; s++)
1617
1652
  try {
1618
1653
  const i = await fetch(t, { method: "GET", credentials: "include" });
1619
1654
  if (!i.ok)
1620
- throw new d(`Failed to load auth config: HTTP ${i.status}`);
1621
- const a = await i.json();
1622
- return be(ce(a));
1655
+ throw new u(`Failed to load auth config: HTTP ${i.status}`);
1656
+ const o = await i.json();
1657
+ return ve(we(o));
1623
1658
  } catch (i) {
1624
- e = i, s < j && await new Promise((a) => setTimeout(a, he));
1659
+ e = i, s < Y && await new Promise((o) => setTimeout(o, pe));
1625
1660
  }
1626
1661
  throw e;
1627
1662
  }
1628
1663
  let f = null;
1629
- async function we() {
1630
- return f || (f = me().catch((t) => {
1664
+ async function fe() {
1665
+ return f || (f = ge().catch((t) => {
1631
1666
  throw f = null, t;
1632
1667
  })), f;
1633
1668
  }
1634
- function be(t) {
1635
- var s, i, a, o, r, l, c;
1636
- const e = ue.filter(({ key: h }) => {
1637
- const m = t[h];
1638
- return typeof m == "object" && m !== null && "enabled" in m && !!m.enabled;
1639
- }).map(({ id: h }) => h);
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);
1640
1675
  return {
1641
1676
  disableSignUp: !!t.disableSignUp,
1642
1677
  emailPasswordEnabled: !!((s = t.providerEmailPassword) != null && s.enabled),
1643
- minPasswordLength: ((a = (i = t.providerEmailPassword) == null ? void 0 : i.config) == null ? void 0 : a.minPasswordLength) ?? 8,
1644
- requireEmailVerification: !!((r = (o = t.providerEmailPassword) == null ? void 0 : o.config) != null && r.requireEmailVerification),
1645
- passwordResetEmailOtpEnabled: !!((c = (l = t.providerEmailPassword) == null ? void 0 : l.config) != null && c.requirePasswordResetEmailVerification),
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),
1646
1681
  oauthProviders: e
1647
1682
  };
1648
1683
  }
1649
1684
  const v = /* @__PURE__ */ new WeakMap();
1650
- function pe(t) {
1685
+ function Pe(t) {
1651
1686
  if (!t)
1652
- throw new d(
1687
+ throw new u(
1653
1688
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1654
1689
  );
1655
1690
  const e = "redirectTo" in t, s = "onSuccess" in t && typeof t.onSuccess == "function";
1656
1691
  if (!e && !s)
1657
- throw new d(
1692
+ throw new u(
1658
1693
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1659
1694
  );
1660
1695
  if ("redirectTo" in t) {
1661
1696
  const i = t.redirectTo;
1662
1697
  if (!(typeof i == "string" || i instanceof URL))
1663
- throw new d(
1698
+ throw new u(
1664
1699
  "authUI.mount(container, options) expected redirectTo to be a string or URL."
1665
1700
  );
1666
1701
  }
1667
1702
  if ("onSuccess" in t && t.onSuccess !== void 0 && typeof t.onSuccess != "function")
1668
- throw new d(
1703
+ throw new u(
1669
1704
  "authUI.mount(container, options) expected onSuccess to be a function."
1670
1705
  );
1671
1706
  if ("onError" in t && t.onError !== void 0 && typeof t.onError != "function")
1672
- throw new d(
1707
+ throw new u(
1673
1708
  "authUI.mount(container, options) expected onError to be a function."
1674
1709
  );
1675
1710
  }
1676
- function ge(t) {
1711
+ function ye(t) {
1677
1712
  if (!(t instanceof HTMLElement))
1678
- throw new d("authUI.mount(container, options) requires a real HTMLElement container.");
1713
+ throw new u("authUI.mount(container, options) requires a real HTMLElement container.");
1679
1714
  }
1680
- function fe(t, e) {
1715
+ function Le(t, e) {
1681
1716
  return {
1682
1717
  mount(s, i) {
1683
- var l;
1684
- pe(i), ge(s), (l = v.get(s)) == null || l.destroy();
1685
- const a = new de(s, t, i, we, e), o = a.destroy.bind(a), r = {
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 = {
1686
1721
  destroy() {
1687
- o(), v.get(s) === r && v.delete(s);
1722
+ a(), v.get(s) === c && v.delete(s);
1688
1723
  }
1689
1724
  };
1690
- return v.set(s, r), r;
1725
+ return v.set(s, c), c;
1691
1726
  }
1692
1727
  };
1693
1728
  }
1694
- function Pe() {
1695
- K();
1696
- const t = se(), e = ie(), s = ee(), i = fe(e, {
1729
+ function Se() {
1730
+ J();
1731
+ const t = ae(), e = re(), s = ne(), i = Le(e, {
1697
1732
  syncPublicSession: async () => {
1698
- await te(t);
1733
+ await oe(t);
1699
1734
  }
1700
1735
  });
1701
1736
  return {
@@ -1705,22 +1740,22 @@ function Pe() {
1705
1740
  };
1706
1741
  }
1707
1742
  export {
1708
- u as EdgeSparkAuthError,
1709
- d as EdgeSparkConfigError,
1710
- R as EdgeSparkError,
1711
- G as EdgeSparkRuntimeError,
1712
- z as ar,
1713
- Pe as createEdgeSpark,
1714
- V as de,
1715
- ae as detectLocale,
1716
- P as enUS,
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,
1717
1752
  E as es,
1718
- k as fr,
1719
- q as hi,
1720
- O as it,
1721
- A as ja,
1722
- B as ko,
1723
- M as ptBR,
1724
- F as ru,
1725
- y as zhCN
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
1726
1761
  };