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

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,432 @@
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 Ue } from "better-auth/client";
2
+ class ee 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 m extends ee {
8
8
  constructor(e) {
9
9
  super("CONFIG_ERROR", e), this.name = "EdgeSparkConfigError";
10
10
  }
11
11
  }
12
- class ne extends x {
12
+ class Se extends ee {
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 y extends ee {
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 Pe() {
23
23
  if (typeof window > "u" || typeof document > "u")
24
- throw new ne(
24
+ throw new Se(
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 Q() {
29
+ return Pe(), 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 Be(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 ke(t) {
35
+ if (t.origin !== Q())
36
+ throw new m(
37
+ `Cross-origin requests are not supported by this SDK. Received ${t.origin}, expected ${Q()}.`
38
38
  );
39
39
  }
40
- function ue() {
40
+ function Me() {
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 = Be(t);
44
+ return ke(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 Ee = "/api/_es/auth", Oe = "edgespark-auth-session", Le = "__edgespark_auth_sync__", S = "__edgespark_auth_pending_sign_in__", _e = Symbol("edgespark.notifyAuthTabs"), Ie = 10 * 60 * 1e3, Ve = /* @__PURE__ */ new Set([
52
+ "signOut",
53
+ "revokeSession",
54
+ "revokeSessions",
55
+ "revokeOtherSessions"
56
+ ]);
57
+ class Ne {
58
+ constructor(e) {
59
+ this.value = e;
60
+ }
61
+ deref() {
62
+ return this.value;
63
+ }
64
+ }
65
+ const ie = globalThis.WeakRef, ne = globalThis.FinalizationRegistry;
66
+ let z, re = !1;
67
+ const A = /* @__PURE__ */ new Map(), D = ne ? new ne((t) => {
68
+ A.delete(t);
69
+ }) : null;
70
+ function Ce(t) {
71
+ return Ue({
72
+ baseURL: Q(),
73
+ basePath: Ee,
74
+ ...t != null && t.disableDefaultRedirectPlugin ? { disableDefaultFetchPlugins: !0 } : {},
57
75
  fetchOptions: {
58
76
  credentials: "include"
59
77
  }
60
78
  });
61
79
  }
62
- function v(s) {
63
- var e, t;
64
- return (t = (e = s.$store) == null ? void 0 : e.atoms) == null ? void 0 : t.session;
80
+ function T(t) {
81
+ var e, s;
82
+ return (s = (e = t.$store) == null ? void 0 : e.atoms) == null ? void 0 : s.session;
83
+ }
84
+ function Fe(t) {
85
+ return JSON.stringify({
86
+ source: t,
87
+ timestamp: Date.now()
88
+ });
89
+ }
90
+ function ze(t) {
91
+ if (typeof t != "string")
92
+ return null;
93
+ try {
94
+ const e = JSON.parse(t);
95
+ return e && typeof e == "object" ? e : null;
96
+ } catch {
97
+ return null;
98
+ }
99
+ }
100
+ async function X(t) {
101
+ var e;
102
+ try {
103
+ return await ((e = T(t)) == null ? void 0 : e.get().refetch()), !0;
104
+ } catch {
105
+ return !1;
106
+ }
107
+ }
108
+ function Te() {
109
+ return z === void 0 && (z = typeof BroadcastChannel < "u" ? new BroadcastChannel(Oe) : null), z;
110
+ }
111
+ function oe(t) {
112
+ const e = ze(t);
113
+ if (e)
114
+ for (const [s, i] of A) {
115
+ if (s === e.source)
116
+ continue;
117
+ const n = i.deref();
118
+ if (!n) {
119
+ A.delete(s);
120
+ continue;
121
+ }
122
+ X(n);
123
+ }
124
+ }
125
+ function De() {
126
+ var t;
127
+ re || (re = !0, (t = Te()) == null || t.addEventListener("message", (e) => {
128
+ oe(e.data);
129
+ }), typeof window < "u" && window.addEventListener("storage", (e) => {
130
+ e.key !== Le || e.newValue === null || oe(e.newValue);
131
+ }));
132
+ }
133
+ function qe(t, e) {
134
+ ie ? A.set(t, new ie(e)) : (A.clear(), A.set(t, new Ne(e))), D == null || D.register(e, t), De();
65
135
  }
66
- function B(s) {
67
- if (s instanceof m)
68
- return s;
69
- const e = s;
70
- return new m(
136
+ function _(t) {
137
+ var s;
138
+ const e = Fe(t);
139
+ try {
140
+ (s = Te()) == null || s.postMessage(e);
141
+ } catch {
142
+ }
143
+ try {
144
+ window.localStorage.setItem(Le, e);
145
+ } catch {
146
+ }
147
+ }
148
+ function q(t) {
149
+ if (!(typeof window > "u"))
150
+ try {
151
+ window.sessionStorage.setItem(
152
+ S,
153
+ JSON.stringify({
154
+ path: t,
155
+ createdAt: Date.now()
156
+ })
157
+ );
158
+ } catch {
159
+ }
160
+ }
161
+ function U() {
162
+ if (!(typeof window > "u"))
163
+ try {
164
+ window.sessionStorage.removeItem(S);
165
+ } catch {
166
+ }
167
+ }
168
+ function He(t) {
169
+ return !!(t != null && t.session && (t != null && t.user));
170
+ }
171
+ function ae() {
172
+ if (typeof window > "u")
173
+ return !1;
174
+ try {
175
+ const t = window.sessionStorage.getItem(S);
176
+ if (!t)
177
+ return !1;
178
+ window.sessionStorage.removeItem(S);
179
+ const e = JSON.parse(t);
180
+ return !e || typeof e != "object" || typeof e.createdAt != "number" ? !1 : Date.now() - e.createdAt <= Ie;
181
+ } catch {
182
+ return !1;
183
+ }
184
+ }
185
+ function je() {
186
+ if (typeof window > "u")
187
+ return !1;
188
+ try {
189
+ const t = window.sessionStorage.getItem(S);
190
+ if (!t)
191
+ return !1;
192
+ const e = JSON.parse(t);
193
+ return !e || typeof e != "object" || typeof e.createdAt != "number" || Date.now() - e.createdAt > Ie ? (window.sessionStorage.removeItem(S), !1) : !0;
194
+ } catch {
195
+ return !1;
196
+ }
197
+ }
198
+ function xe(t) {
199
+ if (!(t && typeof t == "object") || "error" in t && t.error)
200
+ return !1;
201
+ const e = "data" in t ? t.data : t;
202
+ 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;
203
+ }
204
+ function We(t) {
205
+ if (!(t && typeof t == "object") || "error" in t && t.error)
206
+ return !1;
207
+ const e = "data" in t ? t.data : t;
208
+ return e && typeof e == "object" ? "url" in e && typeof e.url == "string" : !1;
209
+ }
210
+ function Ge(t) {
211
+ if (R(t) || !(t && typeof t == "object"))
212
+ return !1;
213
+ const e = "data" in t ? t.data : t;
214
+ return e && typeof e == "object" ? "user" in e && !!e.user && "token" in e && e.token === null && !("url" in e) : !1;
215
+ }
216
+ function Ye(t, e) {
217
+ if (t.length !== 1 || t[0] !== "changePassword")
218
+ return !1;
219
+ const [s] = e;
220
+ return !!(s && typeof s == "object" && "revokeOtherSessions" in s && s.revokeOtherSessions === !0);
221
+ }
222
+ function R(t) {
223
+ return !!(t && typeof t == "object" && "error" in t && t.error);
224
+ }
225
+ function Ke(t) {
226
+ if (R(t) || !(t && typeof t == "object"))
227
+ return !1;
228
+ const e = "data" in t ? t.data : t;
229
+ return e && typeof e == "object" ? "message" in e && e.message === "User deleted" : !1;
230
+ }
231
+ function Je(t) {
232
+ return !!(t && (typeof t == "object" || typeof t == "function") && "then" in t && typeof t.then == "function");
233
+ }
234
+ function H(t) {
235
+ if (t instanceof y)
236
+ return t;
237
+ const e = t;
238
+ return new y(
71
239
  (e == null ? void 0 : e.message) || "Failed to load the current session.",
72
240
  {
73
241
  code: (e == null ? void 0 : e.code) ?? "SESSION_LOOKUP_FAILED",
74
- cause: s,
242
+ cause: t,
75
243
  status: e == null ? void 0 : e.status
76
244
  }
77
245
  );
78
246
  }
79
- async function he(s) {
80
- var e;
81
- await ((e = v(s)) == null ? void 0 : e.get().refetch());
247
+ async function Ze(t) {
248
+ var s, i;
249
+ let e = null;
250
+ try {
251
+ await ((s = T(t)) == null ? void 0 : s.get().refetch());
252
+ } catch (n) {
253
+ e = n;
254
+ } finally {
255
+ (i = t[_e]) == null || i.call(t);
256
+ }
257
+ if (e)
258
+ throw e;
82
259
  }
83
- function me() {
84
- const s = ae(), e = 2, t = 500;
85
- let i = null, r = !1;
86
- const o = () => {
260
+ function Qe() {
261
+ const t = Ce(), e = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
262
+ qe(e, t);
263
+ const s = 2, i = 500;
264
+ let n = null, a = !1, h;
265
+ const w = (o) => (h = o, o), P = () => {
87
266
  var c;
88
- return r ? Promise.resolve(((c = v(s)) == null ? void 0 : c.get().data) ?? null) : (i || (i = (async () => {
89
- var P, L, y, S;
90
- let a = !1, l = null;
91
- try {
92
- for (let p = 0; p <= e; p++) {
93
- const f = await s.getSession(), b = ((P = v(s)) == null ? void 0 : P.get().data) ?? null;
94
- if ((L = f.data) != null && L.session && ((y = f.data) != null && y.user))
95
- return r = !0, f.data;
96
- if (b != null && b.session && (b != null && b.user))
97
- return r = !0, b;
98
- if (f.error ? l = f.error : a = !0, !f.error && p < e) {
99
- await new Promise((A) => setTimeout(A, t));
100
- continue;
101
- }
102
- p < e && await new Promise((A) => setTimeout(A, t));
267
+ const o = (c = T(t)) == null ? void 0 : c.get();
268
+ return o != null && o.error && !o.data && h !== void 0 ? h : (o == null ? void 0 : o.data) ?? h ?? null;
269
+ }, E = () => a ? Promise.resolve(P()) : (n || (n = (async () => {
270
+ var l, u, g;
271
+ let o = !1, c = null;
272
+ try {
273
+ for (let p = 0; p <= s; p++) {
274
+ let d = null;
275
+ try {
276
+ d = await t.getSession();
277
+ } catch (v) {
278
+ c = v;
279
+ }
280
+ const b = ((l = T(t)) == null ? void 0 : l.get().data) ?? null;
281
+ if ((u = d == null ? void 0 : d.data) != null && u.session && ((g = d.data) != null && g.user))
282
+ return a = !0, ae() && _(e), w(d.data);
283
+ if (b != null && b.session && (b != null && b.user))
284
+ return a = !0, ae() && _(e), w(b);
285
+ if (d != null && d.error ? c = d.error : d && (o = !0), d && !d.error && je() && p < s) {
286
+ await new Promise(
287
+ (v) => setTimeout(v, i)
288
+ );
289
+ continue;
103
290
  }
104
- if (!a)
105
- throw i = null, new m("Failed to load the current session.", {
106
- code: "SESSION_LOOKUP_FAILED",
107
- cause: l
108
- });
109
- const h = ((S = v(s)) == null ? void 0 : S.get().data) ?? null;
110
- return r = !0, h;
111
- } catch (h) {
112
- throw i = null, B(h);
291
+ if (d && !d.error) {
292
+ const v = P();
293
+ return a = !0, w(v);
294
+ }
295
+ p < s && await new Promise(
296
+ (v) => setTimeout(v, i)
297
+ );
113
298
  }
114
- })()), i);
115
- };
116
- o().catch(() => {
299
+ if (!o)
300
+ throw n = null, new y("Failed to load the current session.", {
301
+ code: "SESSION_LOOKUP_FAILED",
302
+ cause: c
303
+ });
304
+ const f = P();
305
+ return a = !0, w(f);
306
+ } catch (f) {
307
+ throw n = null, H(f);
308
+ }
309
+ })()), n);
310
+ E().catch(() => {
117
311
  });
118
- const u = async () => {
119
- var c, a;
312
+ const L = async () => {
313
+ var o, c;
120
314
  try {
121
- const l = await s.getSession();
122
- if ((c = l.data) != null && c.session && ((a = l.data) != null && a.user))
315
+ const l = await t.getSession();
316
+ if ((o = l.data) != null && o.session && ((c = l.data) != null && c.user))
123
317
  return l.data;
124
- throw l.error ? B(l.error) : new m("No authenticated session is available.", {
318
+ throw l.error ? H(l.error) : new y("No authenticated session is available.", {
125
319
  code: "UNAUTHENTICATED"
126
320
  });
127
321
  } catch (l) {
128
- throw B(l);
322
+ throw H(l);
129
323
  }
130
- }, w = (c) => {
131
- let a = !1, l = !1, P;
132
- const L = (h) => {
133
- h !== P && (P = h, c(h));
324
+ }, $ = async () => {
325
+ await X(t), _(e);
326
+ }, Re = async () => {
327
+ var l;
328
+ const o = await X(t), c = ((l = T(t)) == null ? void 0 : l.get().data) ?? null;
329
+ He(c) ? (U(), _(e)) : o || _(e);
330
+ }, Ae = (o) => {
331
+ let c = !1, l = !1, u;
332
+ const g = (d) => {
333
+ d !== u && (u = d, o(d));
134
334
  };
135
- o().then((h) => {
136
- a || (l = !0, L(h));
335
+ E().then((d) => {
336
+ c || (l = !0, g(w(d)));
137
337
  }).catch(() => {
138
- a || (l = !0);
338
+ c || (l = !0);
139
339
  });
140
- const y = v(s);
141
- if (!y)
340
+ const f = T(t);
341
+ if (!f)
142
342
  return () => {
143
- a = !0;
343
+ c = !0;
144
344
  };
145
- const S = y.subscribe((h) => {
146
- if (a || !l || h.error && !h.data)
345
+ const p = f.subscribe((d) => {
346
+ if (c || !l || d.error && !d.data)
147
347
  return;
148
- const p = h.data ?? null;
149
- L(p);
348
+ const b = d.data ?? null;
349
+ g(w(b));
150
350
  });
151
351
  return () => {
152
- a = !0, S();
352
+ c = !0, p();
153
353
  };
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 {
162
- }
163
- return a;
354
+ }, $e = async (o, c, l) => {
355
+ const u = o[0], g = o.length >= 2 && u === "emailOtp" && o[1] === "verifyEmail";
356
+ return o.length === 1 && (u === "deleteUser" || u === "deleteUserCallback") ? (U(), Ke(l) && await $(), l) : o.length === 1 && u && Ve.has(u) ? (U(), R(l) || await $(), l) : Ye(o, c) && !R(l) ? (U(), await $(), l) : o.length === 1 && u === "changeEmail" && !R(l) ? (await $(), l) : ((u === "signIn" || u === "signUp" || g) && xe(l) ? (U(), await $()) : (u === "signIn" || u === "signUp") && We(l) || u === "signUp" && Ge(l) ? q(o) : u === "verifyEmail" && !R(l) && (q(o), await Re()), l);
357
+ }, te = /* @__PURE__ */ new WeakMap(), se = (o, c) => {
358
+ if (!o || typeof o != "object" && typeof o != "function")
359
+ return o;
360
+ const l = te.get(o);
361
+ if (l)
362
+ return l;
363
+ const u = new Proxy(o, {
364
+ get(g, f, p) {
365
+ if (c.length === 0) {
366
+ if (f === "requireSession")
367
+ return L;
368
+ if (f === "onSessionChange")
369
+ return Ae;
370
+ if (f === _e)
371
+ return () => {
372
+ _(e);
373
+ };
374
+ }
375
+ const d = Reflect.get(g, f, p);
376
+ return typeof f != "string" ? d : se(d, [...c, f]);
377
+ },
378
+ apply(g, f, p) {
379
+ const d = Reflect.apply(
380
+ g,
381
+ f,
382
+ p
383
+ );
384
+ return Je(d) ? Promise.resolve(d).then(
385
+ (b) => $e(c, p, b)
386
+ ) : d;
387
+ }
388
+ });
389
+ return te.set(o, u), u;
164
390
  };
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);
168
- }
169
- });
391
+ return se(t, []);
170
392
  }
171
- function we() {
172
- return ae({ disableDefaultRedirectPlugin: !0 });
393
+ function Xe() {
394
+ return Ce({ disableDefaultRedirectPlugin: !0 });
173
395
  }
174
- function k(s) {
396
+ function B(t) {
175
397
  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.");
398
+ if (t instanceof URL)
399
+ return t;
400
+ const s = t.trim();
401
+ if (!s)
402
+ throw new m("redirectTo must not be an empty string.");
181
403
  try {
182
- return new URL(t, window.location.href);
404
+ return new URL(s, window.location.href);
183
405
  } catch {
184
- throw new d(
185
- `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(s)}`
406
+ throw new m(
407
+ `redirectTo must be a valid relative path or URL. Received: ${JSON.stringify(t)}`
186
408
  );
187
409
  }
188
410
  })();
189
411
  if (e.protocol !== "http:" && e.protocol !== "https:")
190
- throw new d(
412
+ throw new m(
191
413
  `redirectTo must resolve to an http(s) URL. Received protocol: ${e.protocol}`
192
414
  );
193
415
  return e;
194
416
  }
195
- function be(s, e) {
417
+ function et(t, e) {
196
418
  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;
419
+ common: { ...t.common, ...e.common },
420
+ signIn: { ...t.signIn, ...e.signIn },
421
+ signUp: { ...t.signUp, ...e.signUp },
422
+ verifyEmail: { ...t.verifyEmail, ...e.verifyEmail },
423
+ forgotPassword: { ...t.forgotPassword, ...e.forgotPassword },
424
+ resetPassword: { ...t.resetPassword, ...e.resetPassword },
425
+ oauth: { ...t.oauth, ...e.oauth },
426
+ errors: { ...t.errors, ...e.errors }
427
+ } : t;
206
428
  }
207
- const U = {
429
+ const F = {
208
430
  common: {
209
431
  loading: "Loading sign-in…",
210
432
  redirecting: "Redirecting…",
@@ -267,7 +489,7 @@ const U = {
267
489
  invalidCode: "Enter the 6-digit verification code.",
268
490
  generic: "Something went wrong. Please try again."
269
491
  }
270
- }, M = {
492
+ }, j = {
271
493
  common: {
272
494
  loading: "加载中…",
273
495
  redirecting: "跳转中…",
@@ -330,7 +552,7 @@ const U = {
330
552
  invalidCode: "请输入 6 位验证码",
331
553
  generic: "出现错误,请稍后重试"
332
554
  }
333
- }, W = {
555
+ }, le = {
334
556
  common: {
335
557
  loading: "サインインを読み込み中…",
336
558
  redirecting: "リダイレクト中…",
@@ -393,7 +615,7 @@ const U = {
393
615
  invalidCode: "6桁の認証コードを入力してください",
394
616
  generic: "エラーが発生しました。もう一度お試しください"
395
617
  }
396
- }, j = {
618
+ }, de = {
397
619
  common: {
398
620
  loading: "로그인 로딩 중…",
399
621
  redirecting: "리디렉션 중…",
@@ -456,7 +678,7 @@ const U = {
456
678
  invalidCode: "6자리 인증 코드를 입력해 주세요",
457
679
  generic: "문제가 발생했습니다. 다시 시도해 주세요"
458
680
  }
459
- }, O = {
681
+ }, x = {
460
682
  common: {
461
683
  loading: "Cargando inicio de sesión…",
462
684
  redirecting: "Redirigiendo…",
@@ -519,7 +741,7 @@ const U = {
519
741
  invalidCode: "Ingresa el código de verificación de 6 dígitos.",
520
742
  generic: "Algo salió mal. Por favor, inténtalo de nuevo."
521
743
  }
522
- }, G = {
744
+ }, ce = {
523
745
  common: {
524
746
  loading: "Carregando login…",
525
747
  redirecting: "Redirecionando…",
@@ -582,7 +804,7 @@ const U = {
582
804
  invalidCode: "Insira o código de verificação de 6 dígitos.",
583
805
  generic: "Algo deu errado. Por favor, tente novamente."
584
806
  }
585
- }, Y = {
807
+ }, ue = {
586
808
  common: {
587
809
  loading: "Chargement de la connexion…",
588
810
  redirecting: "Redirection…",
@@ -645,7 +867,7 @@ const U = {
645
867
  invalidCode: "Saisissez le code de vérification à 6 chiffres.",
646
868
  generic: "Une erreur est survenue. Veuillez réessayer."
647
869
  }
648
- }, K = {
870
+ }, he = {
649
871
  common: {
650
872
  loading: "Anmeldung wird geladen…",
651
873
  redirecting: "Weiterleitung…",
@@ -708,7 +930,7 @@ const U = {
708
930
  invalidCode: "Geben Sie den 6-stelligen Bestätigungscode ein.",
709
931
  generic: "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
710
932
  }
711
- }, J = {
933
+ }, me = {
712
934
  common: {
713
935
  loading: "Caricamento accesso…",
714
936
  redirecting: "Reindirizzamento…",
@@ -771,7 +993,7 @@ const U = {
771
993
  invalidCode: "Inserisci il codice di verifica a 6 cifre.",
772
994
  generic: "Qualcosa è andato storto. Riprova."
773
995
  }
774
- }, Z = {
996
+ }, fe = {
775
997
  common: {
776
998
  loading: "Загрузка входа…",
777
999
  redirecting: "Перенаправление…",
@@ -834,7 +1056,7 @@ const U = {
834
1056
  invalidCode: "Введите 6-значный код подтверждения.",
835
1057
  generic: "Произошла ошибка. Пожалуйста, попробуйте снова."
836
1058
  }
837
- }, Q = {
1059
+ }, we = {
838
1060
  common: {
839
1061
  loading: "جارٍ تحميل تسجيل الدخول…",
840
1062
  redirecting: "جارٍ إعادة التوجيه…",
@@ -897,7 +1119,7 @@ const U = {
897
1119
  invalidCode: "يرجى إدخال رمز التحقّق المكوّن من 6 أرقام.",
898
1120
  generic: "حدث خطأ. يرجى المحاولة مرة أخرى."
899
1121
  }
900
- }, X = {
1122
+ }, ge = {
901
1123
  common: {
902
1124
  loading: "सधाइन की जुलातीअ लोड हो रही है…",
903
1125
  redirecting: "रीडायरेक्ट हो रहا है…",
@@ -960,62 +1182,62 @@ const U = {
960
1182
  invalidCode: "कृपया 6 अंकों का सत्यापन कोड दर्ज करें।",
961
1183
  generic: "कुछ गलत हो गई। कृपया फिर से प्रयास करें।"
962
1184
  }
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
1185
+ }, pe = {
1186
+ en: F,
1187
+ "en-US": F,
1188
+ zh: j,
1189
+ "zh-CN": j,
1190
+ "zh-TW": j,
1191
+ ja: le,
1192
+ "ja-JP": le,
1193
+ ko: de,
1194
+ "ko-KR": de,
1195
+ es: x,
1196
+ "es-ES": x,
1197
+ "es-MX": x,
1198
+ pt: ce,
1199
+ "pt-BR": ce,
1200
+ fr: ue,
1201
+ "fr-FR": ue,
1202
+ de: he,
1203
+ "de-DE": he,
1204
+ it: me,
1205
+ "it-IT": me,
1206
+ ru: fe,
1207
+ "ru-RU": fe,
1208
+ ar: we,
1209
+ "ar-SA": we,
1210
+ hi: ge,
1211
+ "hi-IN": ge
990
1212
  };
991
- function pe() {
1213
+ function tt() {
992
1214
  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;
1215
+ return F;
1216
+ const t = navigator.languages ?? [navigator.language];
1217
+ for (const e of t) {
1218
+ const s = pe[e] ?? pe[e.split("-")[0]];
1219
+ if (s) return s;
998
1220
  }
999
- return U;
1221
+ return F;
1000
1222
  }
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
1223
+ function W(t, e = "Authentication failed.") {
1224
+ if (t instanceof y)
1225
+ return t;
1226
+ if (typeof t == "object" && t !== null) {
1227
+ const s = t;
1228
+ return new y(s.message || e, {
1229
+ code: s.code,
1230
+ status: s.status,
1231
+ cause: t
1010
1232
  });
1011
1233
  }
1012
- return typeof s == "string" ? new m(s) : new m(e, { cause: s });
1234
+ return typeof t == "string" ? new y(t) : new y(e, { cause: t });
1013
1235
  }
1014
- async function _(s) {
1015
- var t, i;
1016
- const e = await s.getSession();
1236
+ async function k(t) {
1237
+ var s, i;
1238
+ const e = await t.getSession();
1017
1239
  if (e.error)
1018
- throw new m(
1240
+ throw new y(
1019
1241
  e.error.message || "Failed to load the current session.",
1020
1242
  {
1021
1243
  code: e.error.code ?? "SESSION_LOOKUP_FAILED",
@@ -1023,7 +1245,7 @@ async function _(s) {
1023
1245
  cause: e.error
1024
1246
  }
1025
1247
  );
1026
- return (t = e.data) != null && t.user && ((i = e.data) != null && i.session) ? {
1248
+ return (s = e.data) != null && s.user && ((i = e.data) != null && i.session) ? {
1027
1249
  user: e.data.user,
1028
1250
  session: e.data
1029
1251
  } : {
@@ -1031,7 +1253,7 @@ async function _(s) {
1031
1253
  session: null
1032
1254
  };
1033
1255
  }
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 = {
1256
+ const st = "data-edgespark-auth", r = "edgespark-auth", G = "es_auth_completion", M = "es_auth_email", be = "oauth", O = "verify-sign-in", I = "verify-sign-up", ye = 200, Y = 2, K = {
1035
1257
  google: "Google",
1036
1258
  apple: "Apple",
1037
1259
  microsoft: "Microsoft",
@@ -1039,24 +1261,27 @@ const fe = "data-edgespark-auth", n = "edgespark-auth", F = "es_auth_completion"
1039
1261
  gitlab: "GitLab",
1040
1262
  discord: "Discord"
1041
1263
  };
1042
- function I(s) {
1043
- return "redirectTo" in s;
1264
+ function C(t) {
1265
+ return "redirectTo" in t;
1044
1266
  }
1045
- function q(s) {
1046
- return "onSuccess" in s && !("redirectTo" in s);
1267
+ function J(t) {
1268
+ return "onSuccess" in t && !("redirectTo" in t);
1047
1269
  }
1048
- function D(s) {
1049
- return !s || typeof s != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s.trim());
1270
+ function Z(t) {
1271
+ return !t || typeof t != "string" ? !1 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim());
1050
1272
  }
1051
- function ge(s) {
1052
- return /^\d{6}$/.test(s.trim());
1273
+ function it(t) {
1274
+ return /^\d{6}$/.test(t.trim());
1053
1275
  }
1054
- function ve(s) {
1055
- return s === "email" || s === "name" || s === "password" || s === "confirmPassword" || s === "code" || s === "newPassword";
1276
+ function nt(t) {
1277
+ return t === "email" || t === "name" || t === "password" || t === "confirmPassword" || t === "code" || t === "newPassword";
1056
1278
  }
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 = {
1279
+ function rt(t) {
1280
+ return !!(t.error || t.errorDescription);
1281
+ }
1282
+ class ot {
1283
+ constructor(e, s, i, n, a) {
1284
+ if (this.container = e, this.auth = s, this.options = i, this.loadConfig = n, this.runtimeOptions = a, this.state = {
1060
1285
  view: "loading",
1061
1286
  busy: !0,
1062
1287
  busyLabel: void 0,
@@ -1069,58 +1294,75 @@ class Pe {
1069
1294
  code: "",
1070
1295
  newPassword: ""
1071
1296
  }, 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();
1297
+ throw new m("authUI.mount(container, options) requires a real HTMLElement container.");
1298
+ this.labels = et(tt(), i.labels), this.root = document.createElement("div"), this.root.setAttribute(st, ""), e.innerHTML = "", e.appendChild(this.root), this.render(), this.initialize();
1074
1299
  }
1075
1300
  destroy() {
1076
1301
  this.destroyed || (this.destroyed = !0, this.clearCountdown(), this.clearFocusRestoreTimer(), this.container.innerHTML = "");
1077
1302
  }
1078
1303
  async initialize() {
1304
+ const e = this.consumeManagedReturnContext();
1079
1305
  try {
1080
- const e = this.consumeManagedReturnContext(), [t, i] = await Promise.all([
1306
+ const [s, i] = await Promise.allSettled([
1081
1307
  this.loadConfig(),
1082
1308
  this.readMountSession(e)
1083
1309
  ]);
1084
1310
  if (this.destroyed)
1085
1311
  return;
1086
- if (this.config = t, i.user && i.session) {
1087
- switch (e.marker) {
1088
- case te:
1089
- case T:
1090
- await this.completeAuth("sign-in", i);
1091
- return;
1092
- case g:
1093
- await this.completeAuth("sign-up", i);
1094
- return;
1095
- default:
1096
- break;
1312
+ if (i.status === "rejected") {
1313
+ if (e.marker && !rt(e) && C(this.options)) {
1314
+ this.redirectAfterManagedReturnLookupFailure();
1315
+ return;
1316
+ }
1317
+ } else {
1318
+ const a = i.value;
1319
+ if (a.user && a.session) {
1320
+ switch (e.marker) {
1321
+ case be:
1322
+ case O:
1323
+ await this.completeAuth("sign-in", a);
1324
+ return;
1325
+ case I:
1326
+ await this.completeAuth("sign-up", a);
1327
+ return;
1328
+ default:
1329
+ break;
1330
+ }
1331
+ this.handleExistingSessionOnMount(a);
1332
+ return;
1097
1333
  }
1098
- this.handleExistingSessionOnMount(i);
1099
- return;
1100
1334
  }
1101
- if (this.handleSessionlessManagedReturn(e))
1335
+ if (s.status === "rejected")
1336
+ throw i.status === "rejected" ? i.reason : s.reason;
1337
+ if (this.config = s.value, this.handleSessionlessManagedReturn(e))
1102
1338
  return;
1339
+ if (i.status === "rejected")
1340
+ throw i.reason;
1341
+ const n = i.value;
1103
1342
  this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.render();
1104
- } catch (e) {
1105
- this.handleError(e, "Failed to load the authentication UI.");
1343
+ } catch (s) {
1344
+ this.handleError(s, "Failed to load the authentication UI.");
1106
1345
  }
1107
1346
  }
1347
+ redirectAfterManagedReturnLookupFailure() {
1348
+ C(this.options) && (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(B(this.options.redirectTo).toString()));
1349
+ }
1108
1350
  async readMountSession(e) {
1109
1351
  if (!e.marker)
1110
- return _(this.auth);
1111
- let t = null;
1112
- for (let i = 0; i <= z; i++) {
1352
+ return k(this.auth);
1353
+ let s = null;
1354
+ for (let i = 0; i <= Y; i++) {
1113
1355
  try {
1114
- const r = await _(this.auth);
1115
- if (r.user && r.session)
1116
- return r;
1117
- } catch (r) {
1118
- t = r;
1356
+ const n = await k(this.auth);
1357
+ if (n.user && n.session)
1358
+ return n;
1359
+ } catch (n) {
1360
+ s = n;
1119
1361
  }
1120
- i < z && await new Promise((r) => setTimeout(r, se));
1362
+ i < Y && await new Promise((n) => setTimeout(n, ye));
1121
1363
  }
1122
- if (t)
1123
- throw t;
1364
+ if (s)
1365
+ throw s;
1124
1366
  return {
1125
1367
  user: null,
1126
1368
  session: null
@@ -1135,8 +1377,8 @@ class Pe {
1135
1377
  return;
1136
1378
  }
1137
1379
  this.root.innerHTML = `
1138
- <div class="${n}__shell">
1139
- <div class="${n}__card">
1380
+ <div class="${r}__shell">
1381
+ <div class="${r}__card">
1140
1382
  ${this.renderStatus()}
1141
1383
  ${this.renderCurrentView()}
1142
1384
  </div>
@@ -1146,9 +1388,9 @@ class Pe {
1146
1388
  renderLoading() {
1147
1389
  const e = this.renderStatus();
1148
1390
  return `
1149
- <div class="${n}__shell">
1150
- <div class="${n}__card">
1151
- ${e || `<div class="${n}__status ${n}__status--info">${this.escape(this.labels.common.loading)}</div>`}
1391
+ <div class="${r}__shell">
1392
+ <div class="${r}__card">
1393
+ ${e || `<div class="${r}__status ${r}__status--info">${this.escape(this.labels.common.loading)}</div>`}
1152
1394
  </div>
1153
1395
  </div>
1154
1396
  `;
@@ -1156,11 +1398,11 @@ class Pe {
1156
1398
  renderStatus() {
1157
1399
  const e = [];
1158
1400
  return this.state.error && e.push(
1159
- `<div class="${n}__status ${n}__status--error">${this.escape(this.state.error)}</div>`
1401
+ `<div class="${r}__status ${r}__status--error">${this.escape(this.state.error)}</div>`
1160
1402
  ), this.state.notice && e.push(
1161
- `<div class="${n}__status ${n}__status--info">${this.escape(this.state.notice)}</div>`
1403
+ `<div class="${r}__status ${r}__status--info">${this.escape(this.state.notice)}</div>`
1162
1404
  ), this.state.busy && this.state.busyLabel && e.push(
1163
- `<div class="${n}__status ${n}__status--muted">${this.escape(this.state.busyLabel)}</div>`
1405
+ `<div class="${r}__status ${r}__status--muted">${this.escape(this.state.busyLabel)}</div>`
1164
1406
  ), e.join("");
1165
1407
  }
1166
1408
  renderCurrentView() {
@@ -1177,38 +1419,38 @@ class Pe {
1177
1419
  return this.renderResetPasswordView();
1178
1420
  case "loading":
1179
1421
  default:
1180
- return `<p class="${n}__copy">${this.escape(this.labels.common.loading)}</p>`;
1422
+ return `<p class="${r}__copy">${this.escape(this.labels.common.loading)}</p>`;
1181
1423
  }
1182
1424
  }
1183
1425
  renderSignInView() {
1184
- var i, r;
1185
- const e = this.renderOAuthProviders(), t = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1426
+ var i, n;
1427
+ const e = this.renderOAuthProviders(), s = ((i = this.config) == null ? void 0 : i.emailPasswordEnabled) ?? !0;
1186
1428
  return `
1187
- <section class="${n}__section">
1188
- <header class="${n}__header">
1189
- <h1 class="${n}__title">${this.escape(this.labels.signIn.title)}</h1>
1190
- <p class="${n}__copy">${this.escape(this.labels.signIn.subtitle)}</p>
1429
+ <section class="${r}__section">
1430
+ <header class="${r}__header">
1431
+ <h1 class="${r}__title">${this.escape(this.labels.signIn.title)}</h1>
1432
+ <p class="${r}__copy">${this.escape(this.labels.signIn.subtitle)}</p>
1191
1433
  </header>
1192
1434
  ${e}
1193
- ${e && t ? `<div class="${n}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1194
- ${t ? `
1195
- <form class="${n}__form" data-view="sign-in" novalidate>
1435
+ ${e && s ? `<div class="${r}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1436
+ ${s ? `
1437
+ <form class="${r}__form" data-view="sign-in" novalidate>
1196
1438
  ${this.renderInput("email", this.labels.signIn.emailLabel, "email", this.state.email, "email")}
1197
1439
  ${this.renderInput("password", this.labels.signIn.passwordLabel, "password", this.state.password, "current-password")}
1198
- <button class="${n}__button ${n}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1440
+ <button class="${r}__button ${r}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1199
1441
  ${this.escape(this.labels.signIn.submitButton)}
1200
1442
  </button>
1201
1443
  </form>
1202
- <div class="${n}__actions">
1444
+ <div class="${r}__actions">
1203
1445
  ${this.canUsePasswordResetEmailOtp() ? `
1204
- <button class="${n}__link" type="button" data-action="forgot-password" ${this.state.busy ? "disabled" : ""}>
1446
+ <button class="${r}__link" type="button" data-action="forgot-password" ${this.state.busy ? "disabled" : ""}>
1205
1447
  ${this.escape(this.labels.signIn.forgotPassword)}
1206
1448
  </button>
1207
1449
  ` : ""}
1208
- ${(r = this.config) != null && r.disableSignUp ? "" : `
1209
- <p class="${n}__meta">
1450
+ ${(n = this.config) != null && n.disableSignUp ? "" : `
1451
+ <p class="${r}__meta">
1210
1452
  ${this.escape(this.labels.signIn.signUpPrompt)}
1211
- <button class="${n}__link" type="button" data-action="switch-sign-up" ${this.state.busy ? "disabled" : ""}>
1453
+ <button class="${r}__link" type="button" data-action="switch-sign-up" ${this.state.busy ? "disabled" : ""}>
1212
1454
  ${this.escape(this.labels.signIn.switchToSignUp)}
1213
1455
  </button>
1214
1456
  </p>
@@ -1221,25 +1463,25 @@ class Pe {
1221
1463
  renderSignUpView() {
1222
1464
  const e = this.renderOAuthProviders();
1223
1465
  return `
1224
- <section class="${n}__section">
1225
- <header class="${n}__header">
1226
- <h1 class="${n}__title">${this.escape(this.labels.signUp.title)}</h1>
1227
- <p class="${n}__copy">${this.escape(this.labels.signUp.subtitle)}</p>
1466
+ <section class="${r}__section">
1467
+ <header class="${r}__header">
1468
+ <h1 class="${r}__title">${this.escape(this.labels.signUp.title)}</h1>
1469
+ <p class="${r}__copy">${this.escape(this.labels.signUp.subtitle)}</p>
1228
1470
  </header>
1229
1471
  ${e}
1230
- ${e ? `<div class="${n}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1231
- <form class="${n}__form" data-view="sign-up" novalidate>
1472
+ ${e ? `<div class="${r}__divider"><span>${this.escape(this.labels.oauth.dividerText)}</span></div>` : ""}
1473
+ <form class="${r}__form" data-view="sign-up" novalidate>
1232
1474
  ${this.renderInput("name", this.labels.signUp.nameLabel, "text", this.state.name, "name")}
1233
1475
  ${this.renderInput("email", this.labels.signUp.emailLabel, "email", this.state.email, "email")}
1234
1476
  ${this.renderInput("password", this.labels.signUp.passwordLabel, "password", this.state.password, "new-password")}
1235
1477
  ${this.renderInput("confirmPassword", this.labels.signUp.confirmPasswordLabel, "password", this.state.confirmPassword, "new-password")}
1236
- <button class="${n}__button ${n}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1478
+ <button class="${r}__button ${r}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1237
1479
  ${this.escape(this.labels.signUp.submitButton)}
1238
1480
  </button>
1239
1481
  </form>
1240
- <p class="${n}__meta">
1482
+ <p class="${r}__meta">
1241
1483
  ${this.escape(this.labels.signUp.signInPrompt)}
1242
- <button class="${n}__link" type="button" data-action="switch-sign-in" ${this.state.busy ? "disabled" : ""}>
1484
+ <button class="${r}__link" type="button" data-action="switch-sign-in" ${this.state.busy ? "disabled" : ""}>
1243
1485
  ${this.escape(this.labels.signUp.switchToSignIn)}
1244
1486
  </button>
1245
1487
  </p>
@@ -1252,20 +1494,20 @@ class Pe {
1252
1494
  this.labels.verifyEmail.resendCountdown
1253
1495
  );
1254
1496
  return `
1255
- <section class="${n}__section">
1256
- <header class="${n}__header">
1257
- <h1 class="${n}__title">${this.escape(this.labels.verifyEmail.title)}</h1>
1258
- <p class="${n}__copy">${this.escape(this.labels.verifyEmail.subtitle)}</p>
1497
+ <section class="${r}__section">
1498
+ <header class="${r}__header">
1499
+ <h1 class="${r}__title">${this.escape(this.labels.verifyEmail.title)}</h1>
1500
+ <p class="${r}__copy">${this.escape(this.labels.verifyEmail.subtitle)}</p>
1259
1501
  </header>
1260
- <p class="${n}__copy">
1502
+ <p class="${r}__copy">
1261
1503
  <strong>${this.escape(this.labels.verifyEmail.sentToLabel)}:</strong>
1262
1504
  ${this.escape(this.state.email)}
1263
1505
  </p>
1264
- <div class="${n}__stack">
1265
- <button class="${n}__button ${n}__button--secondary" type="button" data-action="resend-verification" ${this.state.busy || this.isCountdownActive() ? "disabled" : ""}>
1506
+ <div class="${r}__stack">
1507
+ <button class="${r}__button ${r}__button--secondary" type="button" data-action="resend-verification" ${this.state.busy || this.isCountdownActive() ? "disabled" : ""}>
1266
1508
  ${this.escape(e)}
1267
1509
  </button>
1268
- <button class="${n}__link" type="button" data-action="use-different-email" ${this.state.busy ? "disabled" : ""}>
1510
+ <button class="${r}__link" type="button" data-action="use-different-email" ${this.state.busy ? "disabled" : ""}>
1269
1511
  ${this.escape(this.labels.verifyEmail.changeEmailButton)}
1270
1512
  </button>
1271
1513
  </div>
@@ -1274,18 +1516,18 @@ class Pe {
1274
1516
  }
1275
1517
  renderForgotPasswordView() {
1276
1518
  return `
1277
- <section class="${n}__section">
1278
- <header class="${n}__header">
1279
- <h1 class="${n}__title">${this.escape(this.labels.forgotPassword.title)}</h1>
1280
- <p class="${n}__copy">${this.escape(this.labels.forgotPassword.subtitle)}</p>
1519
+ <section class="${r}__section">
1520
+ <header class="${r}__header">
1521
+ <h1 class="${r}__title">${this.escape(this.labels.forgotPassword.title)}</h1>
1522
+ <p class="${r}__copy">${this.escape(this.labels.forgotPassword.subtitle)}</p>
1281
1523
  </header>
1282
- <form class="${n}__form" data-view="forgot-password" novalidate>
1524
+ <form class="${r}__form" data-view="forgot-password" novalidate>
1283
1525
  ${this.renderInput("email", this.labels.forgotPassword.emailLabel, "email", this.state.email, "email")}
1284
- <button class="${n}__button ${n}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1526
+ <button class="${r}__button ${r}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1285
1527
  ${this.escape(this.labels.forgotPassword.submitButton)}
1286
1528
  </button>
1287
1529
  </form>
1288
- <button class="${n}__link" type="button" data-action="switch-sign-in" ${this.state.busy ? "disabled" : ""}>
1530
+ <button class="${r}__link" type="button" data-action="switch-sign-in" ${this.state.busy ? "disabled" : ""}>
1289
1531
  ${this.escape(this.labels.common.backToSignIn)}
1290
1532
  </button>
1291
1533
  </section>
@@ -1297,71 +1539,71 @@ class Pe {
1297
1539
  this.labels.resetPassword.resendCountdown
1298
1540
  );
1299
1541
  return `
1300
- <section class="${n}__section">
1301
- <header class="${n}__header">
1302
- <h1 class="${n}__title">${this.escape(this.labels.resetPassword.title)}</h1>
1303
- <p class="${n}__copy">${this.escape(this.labels.resetPassword.subtitle)}</p>
1542
+ <section class="${r}__section">
1543
+ <header class="${r}__header">
1544
+ <h1 class="${r}__title">${this.escape(this.labels.resetPassword.title)}</h1>
1545
+ <p class="${r}__copy">${this.escape(this.labels.resetPassword.subtitle)}</p>
1304
1546
  </header>
1305
- <form class="${n}__form" data-view="reset-password" novalidate>
1547
+ <form class="${r}__form" data-view="reset-password" novalidate>
1306
1548
  ${this.renderInput("code", this.labels.resetPassword.codeLabel, "text", this.state.code, "one-time-code")}
1307
1549
  ${this.renderInput("newPassword", this.labels.resetPassword.newPasswordLabel, "password", this.state.newPassword, "new-password")}
1308
1550
  ${this.renderInput("confirmPassword", this.labels.resetPassword.confirmPasswordLabel, "password", this.state.confirmPassword, "new-password")}
1309
- <button class="${n}__button ${n}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1551
+ <button class="${r}__button ${r}__button--primary" type="submit" ${this.state.busy ? "disabled" : ""}>
1310
1552
  ${this.escape(this.labels.resetPassword.submitButton)}
1311
1553
  </button>
1312
1554
  </form>
1313
- <button class="${n}__button ${n}__button--secondary" type="button" data-action="resend-reset-code" ${this.state.busy || this.isCountdownActive() ? "disabled" : ""}>
1555
+ <button class="${r}__button ${r}__button--secondary" type="button" data-action="resend-reset-code" ${this.state.busy || this.isCountdownActive() ? "disabled" : ""}>
1314
1556
  ${this.escape(e)}
1315
1557
  </button>
1316
- <button class="${n}__link" type="button" data-action="switch-sign-in" ${this.state.busy ? "disabled" : ""}>
1558
+ <button class="${r}__link" type="button" data-action="switch-sign-in" ${this.state.busy ? "disabled" : ""}>
1317
1559
  ${this.escape(this.labels.common.backToSignIn)}
1318
1560
  </button>
1319
1561
  </section>
1320
1562
  `;
1321
1563
  }
1322
1564
  renderOAuthProviders() {
1323
- var t;
1324
- const e = ((t = this.config) == null ? void 0 : t.oauthProviders) ?? [];
1565
+ var s;
1566
+ const e = ((s = this.config) == null ? void 0 : s.oauthProviders) ?? [];
1325
1567
  return e.length === 0 ? "" : `
1326
- <div class="${n}__stack">
1568
+ <div class="${r}__stack">
1327
1569
  ${e.map((i) => `
1328
- <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]}`)}
1570
+ <button class="${r}__button ${r}__button--secondary" type="button" data-action="oauth" data-provider="${i}" ${this.state.busy ? "disabled" : ""}>
1571
+ ${this.escape(`${this.labels.oauth.continueWith} ${K[i]}`)}
1330
1572
  </button>
1331
1573
  `).join("")}
1332
1574
  </div>
1333
1575
  `;
1334
1576
  }
1335
- renderInput(e, t, i, r, o) {
1577
+ renderInput(e, s, i, n, a) {
1336
1578
  return `
1337
- <label class="${n}__field">
1338
- <span class="${n}__label">${this.escape(t)}</span>
1579
+ <label class="${r}__field">
1580
+ <span class="${r}__label">${this.escape(s)}</span>
1339
1581
  <input
1340
- class="${n}__input"
1582
+ class="${r}__input"
1341
1583
  name="${this.escape(e)}"
1342
1584
  type="${this.escape(i)}"
1343
- value="${this.escape(r)}"
1344
- autocomplete="${this.escape(o)}"
1585
+ value="${this.escape(n)}"
1586
+ autocomplete="${this.escape(a)}"
1345
1587
  ${this.state.busy ? "disabled" : ""}
1346
1588
  />
1347
1589
  </label>
1348
1590
  `;
1349
1591
  }
1350
1592
  bindDOM() {
1351
- this.root.querySelectorAll("form[data-view]").forEach((r) => {
1352
- r.addEventListener("submit", (o) => {
1353
- o.preventDefault();
1354
- const u = r.dataset.view;
1355
- u === "sign-in" && this.handleSignIn(), u === "sign-up" && this.handleSignUp(), u === "forgot-password" && this.handleForgotPassword(), u === "reset-password" && this.handleResetPassword();
1593
+ this.root.querySelectorAll("form[data-view]").forEach((n) => {
1594
+ n.addEventListener("submit", (a) => {
1595
+ a.preventDefault();
1596
+ const h = n.dataset.view;
1597
+ h === "sign-in" && this.handleSignIn(), h === "sign-up" && this.handleSignUp(), h === "forgot-password" && this.handleForgotPassword(), h === "reset-password" && this.handleResetPassword();
1356
1598
  });
1357
- }), this.root.querySelectorAll("input[name]").forEach((r) => {
1358
- r.addEventListener("input", () => {
1359
- ve(r.name) && (this.state[r.name] = r.value);
1599
+ }), this.root.querySelectorAll("input[name]").forEach((n) => {
1600
+ n.addEventListener("input", () => {
1601
+ nt(n.name) && (this.state[n.name] = n.value);
1360
1602
  });
1361
- }), this.root.querySelectorAll("[data-action]").forEach((r) => {
1362
- r.addEventListener("click", () => {
1363
- const o = r.dataset.action;
1364
- o === "switch-sign-up" && this.switchView("sign-up"), o === "switch-sign-in" && this.switchView("sign-in"), o === "forgot-password" && this.switchView("forgot-password"), o === "resend-verification" && this.resendVerificationEmail(), o === "use-different-email" && this.switchView(this.verificationCompletionAction === "sign-in" ? "sign-in" : "sign-up"), o === "resend-reset-code" && this.resendResetCode(), o === "oauth" && this.handleOAuthSignIn(r.dataset.provider);
1603
+ }), this.root.querySelectorAll("[data-action]").forEach((n) => {
1604
+ n.addEventListener("click", () => {
1605
+ const a = n.dataset.action;
1606
+ 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(n.dataset.provider);
1365
1607
  });
1366
1608
  });
1367
1609
  }
@@ -1369,7 +1611,7 @@ class Pe {
1369
1611
  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
1612
  }
1371
1613
  async handleSignIn() {
1372
- if (!D(this.state.email)) {
1614
+ if (!Z(this.state.email)) {
1373
1615
  this.failValidation(this.labels.errors.invalidEmail);
1374
1616
  return;
1375
1617
  }
@@ -1381,7 +1623,7 @@ class Pe {
1381
1623
  const e = await this.auth.signIn.email({
1382
1624
  email: this.state.email.trim(),
1383
1625
  password: this.state.password,
1384
- callbackURL: this.getManagedReturnURL(T, this.state.email.trim())
1626
+ callbackURL: this.getManagedReturnURL(O, this.state.email.trim())
1385
1627
  });
1386
1628
  if (e.error)
1387
1629
  throw e.error;
@@ -1389,12 +1631,12 @@ class Pe {
1389
1631
  });
1390
1632
  }
1391
1633
  async handleSignUp() {
1392
- var e, t;
1634
+ var e, s;
1393
1635
  if (!this.state.name.trim()) {
1394
1636
  this.failValidation(this.labels.errors.requiredField);
1395
1637
  return;
1396
1638
  }
1397
- if (!D(this.state.email)) {
1639
+ if (!Z(this.state.email)) {
1398
1640
  this.failValidation(this.labels.errors.invalidEmail);
1399
1641
  return;
1400
1642
  }
@@ -1404,7 +1646,7 @@ class Pe {
1404
1646
  }
1405
1647
  if (this.state.password.length < (((e = this.config) == null ? void 0 : e.minPasswordLength) ?? 8)) {
1406
1648
  this.failValidation(
1407
- this.labels.errors.passwordTooShort.replace("{min}", String(((t = this.config) == null ? void 0 : t.minPasswordLength) ?? 8))
1649
+ this.labels.errors.passwordTooShort.replace("{min}", String(((s = this.config) == null ? void 0 : s.minPasswordLength) ?? 8))
1408
1650
  );
1409
1651
  return;
1410
1652
  }
@@ -1413,16 +1655,16 @@ class Pe {
1413
1655
  return;
1414
1656
  }
1415
1657
  await this.runAction("Creating account…", async () => {
1416
- var r;
1658
+ var n;
1417
1659
  const i = await this.auth.signUp.email({
1418
1660
  name: this.state.name.trim(),
1419
1661
  email: this.state.email.trim(),
1420
1662
  password: this.state.password,
1421
- callbackURL: this.getManagedReturnURL(g, this.state.email.trim())
1663
+ callbackURL: this.getManagedReturnURL(I, this.state.email.trim())
1422
1664
  });
1423
1665
  if (i.error)
1424
1666
  throw i.error;
1425
- if ((r = this.config) != null && r.requireEmailVerification) {
1667
+ if ((n = this.config) != null && n.requireEmailVerification) {
1426
1668
  this.verificationCompletionAction = "sign-up", this.state.view = "verify-email", this.state.notice = "Check your inbox to verify your email address.", this.startCountdown();
1427
1669
  return;
1428
1670
  }
@@ -1430,28 +1672,28 @@ class Pe {
1430
1672
  });
1431
1673
  }
1432
1674
  async handleOAuthSignIn(e) {
1433
- await this.runAction(`Redirecting to ${N[e]}…`, async () => {
1434
- const t = await this.auth.signIn.social({
1675
+ await this.runAction(`Redirecting to ${K[e]}…`, async () => {
1676
+ const s = await this.auth.signIn.social({
1435
1677
  provider: e,
1436
1678
  callbackURL: this.getManagedReturnURL("oauth"),
1437
1679
  errorCallbackURL: this.getManagedReturnURL("oauth")
1438
1680
  });
1439
- if (t.error)
1440
- throw t.error;
1441
- const i = this.extractRedirectURL(t.data);
1681
+ if (s.error)
1682
+ throw s.error;
1683
+ const i = this.extractRedirectURL(s.data);
1442
1684
  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);
1685
+ throw new m(`OAuth sign-in did not return a redirect URL for provider "${e}".`);
1686
+ this.terminalActionInProgress = !0, this.state.busy = !0, this.state.busyLabel = `Opening ${K[e]}…`, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(i);
1445
1687
  });
1446
1688
  }
1447
1689
  async handleForgotPassword() {
1448
1690
  if (!this.canUsePasswordResetEmailOtp()) {
1449
1691
  this.handleError(
1450
- new d("Password reset via email OTP is not enabled for this project.")
1692
+ new m("Password reset via email OTP is not enabled for this project.")
1451
1693
  );
1452
1694
  return;
1453
1695
  }
1454
- if (!D(this.state.email)) {
1696
+ if (!Z(this.state.email)) {
1455
1697
  this.failValidation(this.labels.errors.invalidEmail);
1456
1698
  return;
1457
1699
  }
@@ -1468,14 +1710,14 @@ class Pe {
1468
1710
  this.isCountdownActive() || await this.handleForgotPassword();
1469
1711
  }
1470
1712
  async handleResetPassword() {
1471
- var e, t;
1713
+ var e, s;
1472
1714
  if (!this.canUsePasswordResetEmailOtp()) {
1473
1715
  this.handleError(
1474
- new d("Password reset via email OTP is not enabled for this project.")
1716
+ new m("Password reset via email OTP is not enabled for this project.")
1475
1717
  );
1476
1718
  return;
1477
1719
  }
1478
- if (!ge(this.state.code)) {
1720
+ if (!it(this.state.code)) {
1479
1721
  this.failValidation(this.labels.errors.invalidCode);
1480
1722
  return;
1481
1723
  }
@@ -1485,7 +1727,7 @@ class Pe {
1485
1727
  }
1486
1728
  if (this.state.newPassword.length < (((e = this.config) == null ? void 0 : e.minPasswordLength) ?? 8)) {
1487
1729
  this.failValidation(
1488
- this.labels.errors.passwordTooShort.replace("{min}", String(((t = this.config) == null ? void 0 : t.minPasswordLength) ?? 8))
1730
+ this.labels.errors.passwordTooShort.replace("{min}", String(((s = this.config) == null ? void 0 : s.minPasswordLength) ?? 8))
1489
1731
  );
1490
1732
  return;
1491
1733
  }
@@ -1509,89 +1751,95 @@ class Pe {
1509
1751
  }
1510
1752
  async sendVerificationEmail(e) {
1511
1753
  !e && this.isCountdownActive() || await this.runAction("Sending verification email…", async () => {
1512
- const t = await this.auth.sendVerificationEmail({
1754
+ const s = await this.auth.sendVerificationEmail({
1513
1755
  email: this.state.email.trim(),
1514
1756
  callbackURL: this.getManagedReturnURL(
1515
- this.verificationCompletionAction === "sign-up" ? g : T,
1757
+ this.verificationCompletionAction === "sign-up" ? I : O,
1516
1758
  this.state.email.trim()
1517
1759
  )
1518
1760
  });
1519
- if (t.error)
1520
- throw t.error;
1761
+ if (s.error)
1762
+ throw s.error;
1521
1763
  this.handleVerificationEmailSent(this.state.email.trim(), !0);
1522
1764
  });
1523
1765
  }
1524
- async completeAuth(e, t) {
1766
+ async completeAuth(e, s) {
1525
1767
  const i = await this.retryAuthCompletionDataIfNeeded(
1526
- t ?? await this.resolveAuthCompletionData()
1768
+ s ?? await this.resolveAuthCompletionData()
1527
1769
  );
1770
+ if (this.destroyed)
1771
+ return;
1528
1772
  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());
1773
+ if (this.destroyed)
1774
+ return;
1775
+ if (i.lookupError && C(this.options)) {
1776
+ 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(B(this.options.redirectTo).toString());
1531
1777
  return;
1532
1778
  }
1533
1779
  if (e === "sign-in")
1534
- throw i.lookupError ?? new ne(
1780
+ throw i.lookupError ?? new Se(
1535
1781
  "Managed sign-in completed without an authenticated session."
1536
1782
  );
1537
1783
  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();
1538
1784
  return;
1539
1785
  }
1540
- const r = {
1786
+ const n = {
1541
1787
  action: e,
1542
1788
  user: i.user,
1543
1789
  session: i.session
1544
1790
  };
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());
1547
- return;
1548
- }
1549
- if (q(this.options)) {
1550
- this.destroy(), this.options.onSuccess(r);
1551
- return;
1791
+ if (await this.syncPublicSessionBestEffort(), !this.destroyed) {
1792
+ if (C(this.options)) {
1793
+ this.terminalActionInProgress = !0, this.invokeRedirectModeSuccessHook(n), this.state.busy = !0, this.state.busyLabel = this.labels.common.redirecting, this.state.error = null, this.state.notice = null, this.render(), window.location.assign(B(this.options.redirectTo).toString());
1794
+ return;
1795
+ }
1796
+ if (J(this.options)) {
1797
+ this.options.onSuccess(n), this.terminalActionInProgress = !0;
1798
+ return;
1799
+ }
1552
1800
  }
1553
1801
  }
1554
1802
  async retryAuthCompletionDataIfNeeded(e) {
1555
1803
  if (e.session)
1556
1804
  return e;
1557
- let t = e.lookupError;
1558
- for (let i = 0; i < z; i++) {
1559
- await new Promise((r) => setTimeout(r, se));
1805
+ let s = e.lookupError;
1806
+ for (let i = 0; i < Y; i++) {
1807
+ await new Promise((n) => setTimeout(n, ye));
1560
1808
  try {
1561
- const r = await _(this.auth);
1562
- if (r.user && r.session)
1809
+ const n = await k(this.auth);
1810
+ if (n.user && n.session)
1563
1811
  return {
1564
- user: r.user,
1565
- session: r.session
1812
+ user: n.user,
1813
+ session: n.session
1566
1814
  };
1567
- } catch (r) {
1568
- t = r;
1815
+ } catch (n) {
1816
+ s = n;
1569
1817
  }
1570
1818
  }
1571
1819
  return {
1572
1820
  ...e,
1573
- lookupError: t ?? e.lookupError
1821
+ lookupError: s ?? e.lookupError
1574
1822
  };
1575
1823
  }
1576
1824
  async syncPublicSessionBestEffort() {
1577
- var e, t;
1825
+ var e, s;
1578
1826
  try {
1579
- await ((t = (e = this.runtimeOptions) == null ? void 0 : e.syncPublicSession) == null ? void 0 : t.call(e));
1827
+ await ((s = (e = this.runtimeOptions) == null ? void 0 : e.syncPublicSession) == null ? void 0 : s.call(e));
1580
1828
  } catch {
1581
1829
  }
1582
1830
  }
1583
1831
  async resolveAuthCompletionData(e) {
1584
1832
  try {
1585
- const t = await _(this.auth), i = this.extractUser(e);
1833
+ const s = await k(this.auth), i = this.extractUser(e);
1586
1834
  return {
1587
- user: t.user ?? i,
1588
- session: t.session
1835
+ user: s.user ?? i,
1836
+ session: s.session
1589
1837
  };
1590
- } catch (t) {
1838
+ } catch (s) {
1591
1839
  return {
1592
1840
  user: this.extractUser(e),
1593
1841
  session: null,
1594
- lookupError: t
1842
+ lookupError: s
1595
1843
  };
1596
1844
  }
1597
1845
  }
@@ -1601,26 +1849,28 @@ class Pe {
1601
1849
  user: null,
1602
1850
  session: null
1603
1851
  };
1604
- if (q(this.options)) {
1605
- this.destroy(), this.options.onSuccess(e);
1606
- return;
1852
+ if (await this.syncPublicSessionBestEffort(), !this.destroyed) {
1853
+ if (J(this.options)) {
1854
+ this.clearCountdown(), this.options.onSuccess(e), this.terminalActionInProgress = !0;
1855
+ return;
1856
+ }
1857
+ 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();
1607
1858
  }
1608
- this.invokeRedirectModeSuccessHook(e), this.clearCountdown(), this.state.view = "sign-in", this.state.password = "", this.state.confirmPassword = "", this.state.newPassword = "", this.state.code = "", this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = null, this.state.notice = "Password updated. Sign in with your new password.", this.render();
1609
1859
  }
1610
1860
  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());
1861
+ if (C(this.options)) {
1862
+ 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(B(this.options.redirectTo).toString());
1613
1863
  return;
1614
1864
  }
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(
1865
+ if (J(this.options))
1866
+ throw this.state.view = "sign-in", this.state.busy = !1, this.state.busyLabel = void 0, this.state.notice = null, new m(
1617
1867
  "authUI.mount(container, { onSuccess }) cannot run while a session already exists. Check es.auth.getSession() before mounting controlled auth UI."
1618
1868
  );
1619
1869
  }
1620
- async runAction(e, t) {
1870
+ async runAction(e, s) {
1621
1871
  this.state.busy = !0, this.state.busyLabel = e, this.state.error = null, this.state.notice = null, this.render();
1622
1872
  try {
1623
- await t();
1873
+ await s();
1624
1874
  } catch (i) {
1625
1875
  if (this.maybeHandleVerificationRequired(i))
1626
1876
  return;
@@ -1630,45 +1880,45 @@ class Pe {
1630
1880
  !this.destroyed && !this.terminalActionInProgress && (this.state.busy = !1, this.state.busyLabel = void 0, this.render());
1631
1881
  }
1632
1882
  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);
1883
+ return W(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
1884
  }
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();
1885
+ handleVerificationEmailSent(e, s) {
1886
+ this.state.notice = s ? `We sent another verification email to ${e}.` : `We sent a verification email to ${e}.`, this.startCountdown();
1637
1887
  }
1638
1888
  invokeRedirectModeSuccessHook(e) {
1639
- var t, i;
1640
- if (!(!I(this.options) || !this.options.onSuccess))
1889
+ var s, i;
1890
+ if (!(!C(this.options) || !this.options.onSuccess))
1641
1891
  try {
1642
1892
  this.options.onSuccess(e);
1643
- } catch (r) {
1644
- const o = V(r, "Post-auth callback failed.");
1893
+ } catch (n) {
1894
+ const a = W(n, "Post-auth callback failed.");
1645
1895
  try {
1646
- (i = (t = this.options).onError) == null || i.call(t, o);
1896
+ (i = (s = this.options).onError) == null || i.call(s, a);
1647
1897
  } catch {
1648
1898
  }
1649
1899
  }
1650
1900
  }
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);
1901
+ handleError(e, s) {
1902
+ var n, a;
1903
+ const i = W(e, s);
1904
+ this.state.busy = !1, this.state.busyLabel = void 0, this.state.error = i.message, this.render(), (a = (n = this.options).onError) == null || a.call(n, i);
1655
1905
  }
1656
1906
  failValidation(e) {
1657
1907
  this.state.error = e, this.state.notice = null, this.render();
1658
1908
  }
1659
- getManagedReturnURL(e, t) {
1909
+ getManagedReturnURL(e, s) {
1660
1910
  if (!e)
1661
1911
  return window.location.href;
1662
1912
  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();
1913
+ return i.searchParams.set(G, e), s ? i.searchParams.set(M, s) : i.searchParams.delete(M), i.toString();
1664
1914
  }
1665
1915
  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,
1916
+ const e = new URL(window.location.href), s = e.searchParams.get(G), i = e.searchParams.get(M), n = s ? e.searchParams.get("error") : null, a = s ? e.searchParams.get("error_description") : null;
1917
+ return (s || i) && (e.searchParams.delete(G), e.searchParams.delete(M), s && (e.searchParams.delete("error"), e.searchParams.delete("error_description")), window.history.replaceState(null, "", e.toString())), {
1918
+ marker: s,
1669
1919
  email: i,
1670
- error: r,
1671
- errorDescription: o
1920
+ error: n,
1921
+ errorDescription: a
1672
1922
  };
1673
1923
  }
1674
1924
  startCountdown(e = 60) {
@@ -1696,14 +1946,14 @@ class Pe {
1696
1946
  this.pendingFocusSnapshot && (this.clearFocusRestoreTimer(), this.focusRestoreTimer = window.setTimeout(() => {
1697
1947
  if (this.focusRestoreTimer = null, this.destroyed || !this.pendingFocusSnapshot)
1698
1948
  return;
1699
- const e = this.pendingFocusSnapshot, t = `input[name="${this.escape(e.name)}"][type="${this.escape(e.type)}"]`, i = this.root.querySelector(t);
1949
+ const e = this.pendingFocusSnapshot, s = `input[name="${this.escape(e.name)}"][type="${this.escape(e.type)}"]`, i = this.root.querySelector(s);
1700
1950
  if (!(!i || i.disabled)) {
1701
1951
  if (i.focus(), e.selectionStart !== null && e.selectionEnd !== null)
1702
1952
  try {
1703
1953
  i.setSelectionRange(e.selectionStart, e.selectionEnd);
1704
1954
  } catch {
1705
- const r = i.value.length;
1706
- i.setSelectionRange(r, r);
1955
+ const n = i.value.length;
1956
+ i.setSelectionRange(n, n);
1707
1957
  }
1708
1958
  this.pendingFocusSnapshot = null;
1709
1959
  }
@@ -1718,24 +1968,24 @@ class Pe {
1718
1968
  extractRedirectURL(e) {
1719
1969
  if (!e || typeof e != "object")
1720
1970
  return null;
1721
- const t = e;
1722
- return t.redirect && typeof t.url == "string" && t.url.length > 0 ? t.url : null;
1971
+ const s = e;
1972
+ return s.redirect && typeof s.url == "string" && s.url.length > 0 ? s.url : null;
1723
1973
  }
1724
1974
  extractUser(e) {
1725
1975
  if (!e || typeof e != "object")
1726
1976
  return null;
1727
- const t = e;
1728
- return t.user && typeof t.user == "object" ? t.user : null;
1977
+ const s = e;
1978
+ return s.user && typeof s.user == "object" ? s.user : null;
1729
1979
  }
1730
1980
  canUsePasswordResetEmailOtp() {
1731
1981
  var e;
1732
1982
  return !!((e = this.config) != null && e.passwordResetEmailOtpEnabled);
1733
1983
  }
1734
1984
  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(
1985
+ return e.email && (this.state.email = e.email), e.marker === I && !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 === O || e.marker === I ? (this.verificationCompletionAction = e.marker === I ? "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 y(
1736
1986
  e.errorDescription ?? "Verification failed. Request a new verification email and try again.",
1737
1987
  { 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(
1988
+ )) : this.render(), !0) : e.marker === be && (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 y(
1739
1989
  e.errorDescription ?? "OAuth sign-in failed.",
1740
1990
  { code: e.error ?? "OAUTH_ERROR" }
1741
1991
  )), !0) : !1;
@@ -1746,136 +1996,136 @@ class Pe {
1746
1996
  getCountdownSecondsRemaining() {
1747
1997
  return this.countdownUntil ? Math.max(0, Math.ceil((this.countdownUntil - Date.now()) / 1e3)) : 0;
1748
1998
  }
1749
- countdownText(e, t) {
1999
+ countdownText(e, s) {
1750
2000
  const i = this.getCountdownSecondsRemaining();
1751
- return i <= 0 ? e : t.replace("{seconds}", String(i));
2001
+ return i <= 0 ? e : s.replace("{seconds}", String(i));
1752
2002
  }
1753
2003
  escape(e) {
1754
2004
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1755
2005
  }
1756
2006
  }
1757
- function Le(s) {
1758
- return "data" in s && s.data ? s.data : s;
2007
+ function at(t) {
2008
+ return "data" in t && t.data ? t.data : t;
1759
2009
  }
1760
- const ye = [
2010
+ const lt = [
1761
2011
  { id: "google", key: "providerGoogle" },
1762
2012
  { id: "apple", key: "providerApple" },
1763
2013
  { id: "microsoft", key: "providerMicrosoft" },
1764
2014
  { id: "github", key: "providerGithub" },
1765
2015
  { id: "gitlab", key: "providerGitlab" },
1766
2016
  { id: "discord", key: "providerDiscord" }
1767
- ], ie = 2, Ee = 500;
1768
- async function Se() {
1769
- const s = `${window.location.origin}${oe}/config`;
2017
+ ], ve = 2, dt = 500;
2018
+ async function ct() {
2019
+ const t = `${window.location.origin}${Ee}/config`;
1770
2020
  let e;
1771
- for (let t = 0; t <= ie; t++)
2021
+ for (let s = 0; s <= ve; s++)
1772
2022
  try {
1773
- const i = await fetch(s, { method: "GET", credentials: "include" });
2023
+ const i = await fetch(t, { method: "GET", credentials: "include" });
1774
2024
  if (!i.ok)
1775
- throw new d(`Failed to load auth config: HTTP ${i.status}`);
1776
- const r = await i.json();
1777
- return Ce(Le(r));
2025
+ throw new m(`Failed to load auth config: HTTP ${i.status}`);
2026
+ const n = await i.json();
2027
+ return ht(at(n));
1778
2028
  } catch (i) {
1779
- e = i, t < ie && await new Promise((r) => setTimeout(r, Ee));
2029
+ e = i, s < ve && await new Promise((n) => setTimeout(n, dt));
1780
2030
  }
1781
2031
  throw e;
1782
2032
  }
1783
- let R = null;
1784
- async function _e() {
1785
- return R || (R = Se().catch((s) => {
1786
- throw R = null, s;
1787
- })), R;
2033
+ let V = null;
2034
+ async function ut() {
2035
+ return V || (V = ct().catch((t) => {
2036
+ throw V = null, t;
2037
+ })), V;
1788
2038
  }
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);
2039
+ function ht(t) {
2040
+ var s, i, n, a, h, w, P;
2041
+ const e = lt.filter(({ key: E }) => {
2042
+ const L = t[E];
2043
+ return typeof L == "object" && L !== null && "enabled" in L && !!L.enabled;
2044
+ }).map(({ id: E }) => E);
1795
2045
  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),
2046
+ disableSignUp: !!t.disableSignUp,
2047
+ emailPasswordEnabled: !!((s = t.providerEmailPassword) != null && s.enabled),
2048
+ minPasswordLength: ((n = (i = t.providerEmailPassword) == null ? void 0 : i.config) == null ? void 0 : n.minPasswordLength) ?? 8,
2049
+ requireEmailVerification: !!((h = (a = t.providerEmailPassword) == null ? void 0 : a.config) != null && h.requireEmailVerification),
2050
+ passwordResetEmailOtpEnabled: !!((P = (w = t.providerEmailPassword) == null ? void 0 : w.config) != null && P.requirePasswordResetEmailVerification),
1801
2051
  oauthProviders: e
1802
2052
  };
1803
2053
  }
1804
- const $ = /* @__PURE__ */ new WeakMap();
1805
- function Te(s) {
1806
- if (!s)
1807
- throw new d(
2054
+ const N = /* @__PURE__ */ new WeakMap();
2055
+ function mt(t) {
2056
+ if (!t)
2057
+ throw new m(
1808
2058
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1809
2059
  );
1810
- const e = "redirectTo" in s, t = "onSuccess" in s && typeof s.onSuccess == "function";
1811
- if (!e && !t)
1812
- throw new d(
2060
+ const e = "redirectTo" in t, s = "onSuccess" in t && typeof t.onSuccess == "function";
2061
+ if (!e && !s)
2062
+ throw new m(
1813
2063
  "authUI.mount(container, options) requires either { redirectTo } or { onSuccess }."
1814
2064
  );
1815
- if ("redirectTo" in s) {
1816
- const i = s.redirectTo;
2065
+ if ("redirectTo" in t) {
2066
+ const i = t.redirectTo;
1817
2067
  if (!(typeof i == "string" || i instanceof URL))
1818
- throw new d(
2068
+ throw new m(
1819
2069
  "authUI.mount(container, options) expected redirectTo to be a string or URL."
1820
2070
  );
1821
2071
  }
1822
- if ("onSuccess" in s && s.onSuccess !== void 0 && typeof s.onSuccess != "function")
1823
- throw new d(
2072
+ if ("onSuccess" in t && t.onSuccess !== void 0 && typeof t.onSuccess != "function")
2073
+ throw new m(
1824
2074
  "authUI.mount(container, options) expected onSuccess to be a function."
1825
2075
  );
1826
- if ("onError" in s && s.onError !== void 0 && typeof s.onError != "function")
1827
- throw new d(
2076
+ if ("onError" in t && t.onError !== void 0 && typeof t.onError != "function")
2077
+ throw new m(
1828
2078
  "authUI.mount(container, options) expected onError to be a function."
1829
2079
  );
1830
2080
  }
1831
- function Ie(s) {
1832
- if (!(s instanceof HTMLElement))
1833
- throw new d("authUI.mount(container, options) requires a real HTMLElement container.");
2081
+ function ft(t) {
2082
+ if (!(t instanceof HTMLElement))
2083
+ throw new m("authUI.mount(container, options) requires a real HTMLElement container.");
1834
2084
  }
1835
- function Re(s, e) {
2085
+ function wt(t, e) {
1836
2086
  return {
1837
- mount(t, i) {
2087
+ mount(s, i) {
1838
2088
  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 = {
2089
+ mt(i), ft(s), (w = N.get(s)) == null || w.destroy();
2090
+ const n = new ot(s, t, i, ut, e), a = n.destroy.bind(n), h = {
1841
2091
  destroy() {
1842
- o(), $.get(t) === u && $.delete(t);
2092
+ a(), N.get(s) === h && N.delete(s);
1843
2093
  }
1844
2094
  };
1845
- return $.set(t, u), u;
2095
+ return N.set(s, h), h;
1846
2096
  }
1847
2097
  };
1848
2098
  }
1849
- function Ue() {
1850
- re();
1851
- const s = me(), e = we(), t = ue(), i = Re(e, {
2099
+ function pt() {
2100
+ Pe();
2101
+ const t = Qe(), e = Xe(), s = Me(), i = wt(e, {
1852
2102
  syncPublicSession: async () => {
1853
- await he(s);
2103
+ await Ze(t);
1854
2104
  }
1855
2105
  });
1856
2106
  return {
1857
- auth: s,
1858
- api: t,
2107
+ auth: t,
2108
+ api: s,
1859
2109
  authUI: i
1860
2110
  };
1861
2111
  }
1862
2112
  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
2113
+ y as EdgeSparkAuthError,
2114
+ m as EdgeSparkConfigError,
2115
+ ee as EdgeSparkError,
2116
+ Se as EdgeSparkRuntimeError,
2117
+ we as ar,
2118
+ pt as createEdgeSpark,
2119
+ he as de,
2120
+ tt as detectLocale,
2121
+ F as enUS,
2122
+ x as es,
2123
+ ue as fr,
2124
+ ge as hi,
2125
+ me as it,
2126
+ le as ja,
2127
+ de as ko,
2128
+ ce as ptBR,
2129
+ fe as ru,
2130
+ j as zhCN
1881
2131
  };