@voltro/plugin-auth-social 0.90.0 → 0.91.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/plugin.js CHANGED
@@ -1,22 +1,22 @@
1
- import { SocialAuthError as e, SocialConfigError as t } from "./errors.js";
2
- import { isSocialProviderId as n, socialProvider as r } from "./providers.js";
3
- import { socialBeginLogin as i } from "./login.js";
4
- import { socialCompleteLogin as a } from "./callback.js";
5
- import { completeSocialSignIn as o } from "./signIn.js";
6
- import { ACCOUNT_MERGE_TABLE as s, SOCIAL_IDENTITY_TABLE as c, dataStoreSocialIdentityStore as l, linkSocialIdentity as u, socialAuthTables as d } from "./identityStore.js";
7
- import { completeGuestSocialUpgrade as f } from "./guestUpgrade.js";
8
- import { completeGuestSocialMerge as p, guestMergeTarget as m } from "./accountMerge.js";
9
- import { decodeGuestUpgradeHandoff as ee, encodeGuestUpgradeHandoff as h, guestIdentityOf as te } from "./guestHandoff.js";
10
- import { isNativeVerifier as ne, nativeUpgradeRequestOf as re, openNativeUpgradeCode as ie, sealNativeUpgradeCode as ae, signNativeUpgradeTicket as oe, verifierMatches as se, verifyNativeUpgradeTicket as ce } from "./nativeGuestUpgrade.js";
11
- import { steamBeginOpenId as le, steamCompleteOpenId as ue } from "./steam.js";
12
- import { verifyPlatformTicket as de } from "./platform.js";
13
- import { Effect as g, Result as _ } from "effect";
14
- import { and as fe, eq as v } from "@voltro/database";
15
- import { definePlugin as pe } from "@voltro/protocol";
16
- import { SESSION_HEADER_NAME as me, buildSetCookie as y, readCookie as b } from "@voltro/protocol/session";
17
- import { CSRF_COOKIE_NAME as x, CSRF_HEADER_NAME as he, configSessionSecrets as S, dataStoreGuestAuth as ge, dataStoreSessionRegistry as _e, deferredUserStore as ve, issueCsrfToken as ye, parseGuestCredential as be, readSessionFromHeaders as C, signAuthClaims as xe, verifyAuthClaims as w, verifyCsrf as Se } from "@voltro/plugin-auth";
1
+ import { socialBeginLogin as e } from "./login.js";
2
+ import { socialCompleteLogin as t } from "./callback.js";
3
+ import { completeSocialSignIn as n } from "./signIn.js";
4
+ import { completeGuestSocialUpgrade as r } from "./guestUpgrade.js";
5
+ import { completeGuestSocialMerge as i, guestMergeTarget as a } from "./accountMerge.js";
6
+ import { decodeGuestUpgradeHandoff as o, encodeGuestUpgradeHandoff as s, guestIdentityOf as c } from "./guestHandoff.js";
7
+ import { isNativeVerifier as l, nativeUpgradeRequestOf as u, openNativeUpgradeCode as d, sealNativeUpgradeCode as f, signNativeUpgradeTicket as p, verifierMatches as m, verifyNativeUpgradeTicket as h } from "./nativeGuestUpgrade.js";
8
+ import { ACCOUNT_MERGE_TABLE as g, SOCIAL_IDENTITY_TABLE as _, dataStoreSocialIdentityStore as v, linkSocialIdentity as ee, socialAuthTables as y } from "./identityStore.js";
9
+ import { SocialAuthError as b, SocialConfigError as x } from "./errors.js";
10
+ import { isSocialProviderId as S, socialProvider as te } from "./providers.js";
11
+ import { verifyPlatformTicket as ne } from "./platform.js";
12
+ import { steamBeginOpenId as re, steamCompleteOpenId as ie } from "./steam.js";
13
+ import { Effect as C, Result as w } from "effect";
14
+ import { and as ae, eq as T } from "@voltro/database";
15
+ import { definePlugin as oe } from "@voltro/protocol";
16
+ import { SESSION_HEADER_NAME as se, buildSetCookie as E, readCookie as D } from "@voltro/protocol/session";
17
+ import { CSRF_COOKIE_NAME as O, CSRF_HEADER_NAME as ce, configSessionSecrets as k, dataStoreGuestAuth as le, dataStoreSessionRegistry as ue, deferredUserStore as de, issueCsrfToken as fe, parseGuestCredential as pe, readSessionFromHeaders as A, signAuthClaims as me, verifyAuthClaims as j, verifyCsrf as he } from "@voltro/plugin-auth";
18
18
  // src/plugin.ts
19
- var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
19
+ var ge = "/auth/social", _e = 600, ve = "voltro:oauth", M = {
20
20
  google: [{
21
21
  name: "VOLTRO_GOOGLE_CLIENT_ID",
22
22
  secret: !1,
@@ -93,12 +93,12 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
93
93
  secret: !0,
94
94
  description: "Epic Account Services OAuth client secret."
95
95
  }]
96
- }, E = (e, t) => ({
96
+ }, N = (e, t) => ({
97
97
  status: e,
98
98
  body: JSON.stringify(t),
99
99
  contentType: "application/json; charset=utf-8",
100
100
  headers: { "cache-control": "no-store" }
101
- }), Ee = (e, t) => e + (e.includes("?") ? "&" : "?") + new URLSearchParams(t).toString(), D = (e, t) => ({
101
+ }), ye = (e, t) => e + (e.includes("?") ? "&" : "?") + new URLSearchParams(t).toString(), P = (e, t) => ({
102
102
  status: 302,
103
103
  body: "",
104
104
  contentType: "text/plain; charset=utf-8",
@@ -108,16 +108,16 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
108
108
  location: e,
109
109
  ...t === void 0 ? {} : { "set-cookie": t }
110
110
  }
111
- }), De = (e, t) => xe({ ...e }, t.current.secret, "social-login"), Oe = (e, t) => {
111
+ }), be = (e, t) => me({ ...e }, t.current.secret, "social-login"), xe = (e, t) => {
112
112
  if (!e) return null;
113
113
  try {
114
- let n = [t.current, t.previous].filter((e) => e !== void 0).map((t) => w(e, t.secret, "social-login")).find((e) => e !== null);
114
+ let n = [t.current, t.previous].filter((e) => e !== void 0).map((t) => j(e, t.secret, "social-login")).find((e) => e !== null);
115
115
  if (!n) return null;
116
116
  let r = n;
117
117
  if (typeof r.p != "string" || typeof r.s != "string" || typeof r.v != "string" || typeof r.n != "string" || typeof r.exp != "number" || typeof r.audience != "string" || typeof r.redirectUri != "string") return null;
118
- let i = r.guest === void 0 ? void 0 : te(r.guest);
118
+ let i = r.guest === void 0 ? void 0 : c(r.guest);
119
119
  if (i === null) return null;
120
- let a = r.native, o = a === void 0 ? void 0 : re(a, typeof a?.r == "string" ? [a.r] : []);
120
+ let a = r.native, o = a === void 0 ? void 0 : u(a, typeof a?.r == "string" ? [a.r] : []);
121
121
  if (o === null || o !== void 0 && i === void 0) return null;
122
122
  let s = r.link;
123
123
  return s !== void 0 && (typeof s.u != "string" || typeof s.t != "string" || typeof s.sid != "string" || i !== void 0) ? null : {
@@ -139,122 +139,122 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
139
139
  } catch {
140
140
  return null;
141
141
  }
142
- }, ke = (e) => e.method === "POST" && (e.headers["content-type"] ?? "").includes("application/x-www-form-urlencoded") ? new URLSearchParams(Buffer.from(e.rawBody).toString("utf8")) : new URLSearchParams(e.query), O = (w) => {
143
- let O = { current: typeof w.users == "function" ? void 0 : w.users }, k = {
144
- ...w,
145
- users: typeof w.users == "function" ? ve(() => O.current) : w.users
146
- }, A = k.prefix ?? Ce, j = k.stateTtlSeconds ?? we, M = k.stateCookieName ?? Te, Ae = k.linkPolicy ?? "never", N = k.auth.cookieSecure ?? !0, je = k.providers ?? {}, Me = Object.keys(je);
147
- if (Me.find((e) => !n(e)) !== void 0) throw new t("socialAuthPlugin: unknown provider configuration");
148
- let P = Me.filter(n), F = k.steam, Ne = F === void 0 ? P : [...P, "steam"], I = (e) => e === "steam" ? F !== void 0 : e !== void 0 && n(e) && P.includes(e), L = /* @__PURE__ */ new Map();
149
- for (let e of k.platforms ?? []) {
150
- if (L.has(e.id)) throw new t(`socialAuthPlugin: platform ${e.id} is configured twice`);
151
- L.set(e.id, e);
142
+ }, Se = (e) => e.method === "POST" && (e.headers["content-type"] ?? "").includes("application/x-www-form-urlencoded") ? new URLSearchParams(Buffer.from(e.rawBody).toString("utf8")) : new URLSearchParams(e.query), Ce = (j) => {
143
+ let Ce = { current: typeof j.users == "function" ? void 0 : j.users }, F = {
144
+ ...j,
145
+ users: typeof j.users == "function" ? de(() => Ce.current) : j.users
146
+ }, I = F.prefix ?? ge, L = F.stateTtlSeconds ?? _e, R = F.stateCookieName ?? ve, we = F.linkPolicy ?? "never", z = F.auth.cookieSecure ?? !0, Te = F.providers ?? {}, Ee = Object.keys(Te);
147
+ if (Ee.find((e) => !S(e)) !== void 0) throw new x("socialAuthPlugin: unknown provider configuration");
148
+ let B = Ee.filter(S), V = F.steam, De = V === void 0 ? B : [...B, "steam"], Oe = (e) => e === "steam" ? V !== void 0 : e !== void 0 && S(e) && B.includes(e), H = /* @__PURE__ */ new Map();
149
+ for (let e of F.platforms ?? []) {
150
+ if (H.has(e.id)) throw new x(`socialAuthPlugin: platform ${e.id} is configured twice`);
151
+ H.set(e.id, e);
152
152
  }
153
- if (!Number.isSafeInteger(j) || j <= 0 || j > 3600) throw new t("socialAuthPlugin: stateTtlSeconds must be an integer from 1 to 3600");
154
- let R = (k.appBaseUrl ?? k.auth.appBaseUrl ?? "").replace(/\/+$/, ""), z = M + ":upgrade", B = k.guestUpgrade, V = JSON.stringify([
155
- R,
156
- A,
157
- k.name ?? "",
158
- k.auth.defaultTenantId
153
+ if (!Number.isSafeInteger(L) || L <= 0 || L > 3600) throw new x("socialAuthPlugin: stateTtlSeconds must be an integer from 1 to 3600");
154
+ let U = (F.appBaseUrl ?? F.auth.appBaseUrl ?? "").replace(/\/+$/, ""), W = R + ":upgrade", G = F.guestUpgrade, K = JSON.stringify([
155
+ U,
156
+ I,
157
+ F.name ?? "",
158
+ F.auth.defaultTenantId
159
159
  ]);
160
- if (F !== void 0 && !/^https?:\/\//.test(R)) throw new t("socialAuthPlugin: steam needs an absolute app URL — set `appBaseUrl`");
161
- let H = `${R}${A}/steam/callback`, U = F?.hotStore === void 0 ? void 0 : () => Promise.resolve(F.hotStore);
162
- if (B) {
163
- if (B.guest.tenantId !== k.auth.defaultTenantId || k.auth.ensureActor !== void 0 && B.configForTransaction === void 0) throw new t("Guest upgrade requires matching server tenants and transaction-bound actor hooks");
164
- if (k.identities !== void 0) throw new t("Guest upgrade requires transaction-bound SQL social identities");
160
+ if (V !== void 0 && !/^https?:\/\//.test(U)) throw new x("socialAuthPlugin: steam needs an absolute app URL — set `appBaseUrl`");
161
+ let ke = `${U}${I}/steam/callback`, Ae = V?.hotStore === void 0 ? void 0 : () => Promise.resolve(V.hotStore);
162
+ if (G) {
163
+ if (G.guest.tenantId !== F.auth.defaultTenantId || F.auth.ensureActor !== void 0 && G.configForTransaction === void 0) throw new x("Guest upgrade requires matching server tenants and transaction-bound actor hooks");
164
+ if (F.identities !== void 0) throw new x("Guest upgrade requires transaction-bound SQL social identities");
165
165
  let e = !1;
166
166
  try {
167
- let t = new URL(R), n = new URL(B.confirmationRedirect, t);
168
- e = /^https?:$/.test(t.protocol) && n.origin === t.origin && !n.username && !n.password && !B.confirmationRedirect.startsWith("//") && !B.confirmationRedirect.includes("\\");
167
+ let t = new URL(U), n = new URL(G.confirmationRedirect, t);
168
+ e = /^https?:$/.test(t.protocol) && n.origin === t.origin && !n.username && !n.password && !G.confirmationRedirect.startsWith("//") && !G.confirmationRedirect.includes("\\");
169
169
  } catch {}
170
- if (!e) throw new t("Guest upgrade confirmation must be a same-origin application page");
171
- for (let e of B.native?.redirectUris ?? ["acme://valid"]) {
172
- let n = null;
170
+ if (!e) throw new x("Guest upgrade confirmation must be a same-origin application page");
171
+ for (let e of G.native?.redirectUris ?? ["acme://valid"]) {
172
+ let t = null;
173
173
  try {
174
- n = new URL(e);
174
+ t = new URL(e);
175
175
  } catch {}
176
- if (!n || e.includes("*") || n.hash || n.username || n.password || /^(javascript|data|file):$/.test(n.protocol) || n.protocol === "http:" && ![
176
+ if (!t || e.includes("*") || t.hash || t.username || t.password || /^(javascript|data|file):$/.test(t.protocol) || t.protocol === "http:" && ![
177
177
  "127.0.0.1",
178
178
  "[::1]",
179
179
  "localhost"
180
- ].includes(n.hostname)) throw new t("Native guest upgrade redirect URIs must be exact app URIs (custom scheme, https or loopback http)");
180
+ ].includes(t.hostname)) throw new x("Native guest upgrade redirect URIs must be exact app URIs (custom scheme, https or loopback http)");
181
181
  }
182
- if (B.native && B.native.redirectUris.length === 0) throw new t("Native guest upgrade needs at least one redirect URI");
182
+ if (G.native && G.native.redirectUris.length === 0) throw new x("Native guest upgrade needs at least one redirect URI");
183
183
  }
184
- let W = (e) => {
185
- if (!B) throw new t("Guest upgrade is not configured");
186
- return B.service?.(e) ?? ge(e, B.guest);
187
- }, G = (e) => y(e, "", {
184
+ let q = (e) => {
185
+ if (!G) throw new x("Guest upgrade is not configured");
186
+ return G.service?.(e) ?? le(e, G.guest);
187
+ }, J = (e) => E(e, "", {
188
188
  maxAgeSeconds: 0,
189
- path: A,
190
- secure: N,
189
+ path: I,
190
+ secure: z,
191
191
  httpOnly: !0,
192
192
  sameSite: "lax",
193
- ...k.auth.cookieDomain ? { domain: k.auth.cookieDomain } : {}
194
- }), K = (e) => {
195
- let n = je[e] ?? {}, r = process.env, i = n.clientId ?? r[T[e][0].name] ?? "";
196
- if (!i) throw new t(`socialAuthPlugin: ${e} has no client id — pass \`providers.${e}.clientId\` or set ${T[e][0].name}`);
197
- let a = n.redirectUri ?? `${R}${A}/${e}/callback`, o = !1;
193
+ ...F.auth.cookieDomain ? { domain: F.auth.cookieDomain } : {}
194
+ }), je = (e) => {
195
+ let t = Te[e] ?? {}, n = process.env, r = t.clientId ?? n[M[e][0].name] ?? "";
196
+ if (!r) throw new x(`socialAuthPlugin: ${e} has no client id — pass \`providers.${e}.clientId\` or set ${M[e][0].name}`);
197
+ let i = t.redirectUri ?? `${U}${I}/${e}/callback`, a = !1;
198
198
  try {
199
- let e = new URL(a);
200
- o = (e.protocol === "https:" || e.protocol === "http:") && e.username === "" && e.password === "" && e.hash === "";
199
+ let e = new URL(i);
200
+ a = (e.protocol === "https:" || e.protocol === "http:") && e.username === "" && e.password === "" && e.hash === "";
201
201
  } catch {}
202
- if (!o) throw new t(`socialAuthPlugin: ${e} needs an absolute redirect URI — set \`appBaseUrl\` (or \`providers.${e}.redirectUri\`)`);
203
- let s = {
202
+ if (!a) throw new x(`socialAuthPlugin: ${e} needs an absolute redirect URI — set \`appBaseUrl\` (or \`providers.${e}.redirectUri\`)`);
203
+ let o = {
204
204
  id: e,
205
- clientId: i,
206
- redirectUri: a,
207
- endpoints: n.endpoints ?? {},
208
- ...n.scopes === void 0 ? {} : { scopes: n.scopes }
205
+ clientId: r,
206
+ redirectUri: i,
207
+ endpoints: t.endpoints ?? {},
208
+ ...t.scopes === void 0 ? {} : { scopes: t.scopes }
209
209
  };
210
210
  if (e === "apple") {
211
- let e = n.appleKey ?? (r.VOLTRO_APPLE_TEAM_ID && r.VOLTRO_APPLE_KEY_ID && r.VOLTRO_APPLE_PRIVATE_KEY ? {
212
- teamId: r.VOLTRO_APPLE_TEAM_ID,
213
- keyId: r.VOLTRO_APPLE_KEY_ID,
214
- privateKey: r.VOLTRO_APPLE_PRIVATE_KEY.replace(/\\n/g, "\n")
211
+ let e = t.appleKey ?? (n.VOLTRO_APPLE_TEAM_ID && n.VOLTRO_APPLE_KEY_ID && n.VOLTRO_APPLE_PRIVATE_KEY ? {
212
+ teamId: n.VOLTRO_APPLE_TEAM_ID,
213
+ keyId: n.VOLTRO_APPLE_KEY_ID,
214
+ privateKey: n.VOLTRO_APPLE_PRIVATE_KEY.replace(/\\n/g, "\n")
215
215
  } : void 0);
216
- if (!e) throw new t("socialAuthPlugin: apple needs `appleKey` (teamId + keyId + .p8) or VOLTRO_APPLE_TEAM_ID / VOLTRO_APPLE_KEY_ID / VOLTRO_APPLE_PRIVATE_KEY");
216
+ if (!e) throw new x("socialAuthPlugin: apple needs `appleKey` (teamId + keyId + .p8) or VOLTRO_APPLE_TEAM_ID / VOLTRO_APPLE_KEY_ID / VOLTRO_APPLE_PRIVATE_KEY");
217
217
  return {
218
- ...s,
218
+ ...o,
219
219
  appleKey: e
220
220
  };
221
221
  }
222
- let c = n.clientSecret ?? r[T[e][1].name] ?? "";
223
- if (!c) throw new t(`socialAuthPlugin: ${e} has no client secret — pass \`providers.${e}.clientSecret\` or set ${T[e][1].name}`);
222
+ let s = t.clientSecret ?? n[M[e][1].name] ?? "";
223
+ if (!s) throw new x(`socialAuthPlugin: ${e} has no client secret — pass \`providers.${e}.clientSecret\` or set ${M[e][1].name}`);
224
224
  return {
225
- ...s,
226
- clientSecret: c
225
+ ...o,
226
+ clientSecret: s
227
227
  };
228
- }, q = k.identities ?? null, J, Pe, Fe, Ie = () => {
229
- if (q) return q;
230
- if (!J) throw new t("socialAuthPlugin: privacy hooks need the app DataStore or an `identities` store");
231
- return q = l(J), q;
232
- }, Le = (e) => g.promise(async () => J === void 0 ? [] : (await J.query({
233
- table: s,
234
- predicate: v("targetId", e),
228
+ }, Y = F.identities ?? null, X, Me, Ne, Pe = () => {
229
+ if (Y) return Y;
230
+ if (!X) throw new x("socialAuthPlugin: privacy hooks need the app DataStore or an `identities` store");
231
+ return Y = v(X), Y;
232
+ }, Fe = (e) => C.promise(async () => X === void 0 ? [] : (await X.query({
233
+ table: g,
234
+ predicate: T("targetId", e),
235
235
  order: [],
236
236
  take: void 0,
237
237
  skip: void 0,
238
238
  projection: void 0
239
- })).filter((t) => t.targetId === e)), Y = (e) => {
240
- if (q) return q;
241
- let n = e.store;
242
- if (!n) throw new t("socialAuthPlugin: no identity store — pass `identities`, or run on an app with a DataStore");
243
- return q = l(n), q;
244
- }, Re = (e) => {
245
- if (!e.startsWith(`${A}/`)) return null;
246
- let [t, ...n] = e.slice(A.length + 1).split("/");
247
- return I(t) ? n.length === 0 ? {
239
+ })).filter((t) => t.targetId === e)), Z = (e) => {
240
+ if (Y) return Y;
241
+ let t = e.store;
242
+ if (!t) throw new x("socialAuthPlugin: no identity store — pass `identities`, or run on an app with a DataStore");
243
+ return Y = v(t), Y;
244
+ }, Ie = (e) => {
245
+ if (!e.startsWith(`${I}/`)) return null;
246
+ let [t, ...n] = e.slice(I.length + 1).split("/");
247
+ return Oe(t) ? n.length === 0 ? {
248
248
  id: t,
249
249
  isCallback: !1
250
250
  } : n.length === 1 && n[0] === "callback" ? {
251
251
  id: t,
252
252
  isCallback: !0
253
253
  } : null : null;
254
- }, X = (e, t, n) => {
255
- let r = [G(M), ...B ? [G(z)] : []];
256
- if (!k.failureRedirect) return {
257
- ...E(e, {
254
+ }, Q = (e, t, n) => {
255
+ let r = [J(R), ...G ? [J(W)] : []];
256
+ if (!F.failureRedirect) return {
257
+ ...N(e, {
258
258
  error: t,
259
259
  message: n
260
260
  }),
@@ -263,7 +263,7 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
263
263
  "set-cookie": r
264
264
  }
265
265
  };
266
- let i = k.failureRedirect.includes("?") ? "&" : "?", a = D(`${k.failureRedirect}${i}social_error=${encodeURIComponent(t)}`);
266
+ let i = F.failureRedirect.includes("?") ? "&" : "?", a = P(`${F.failureRedirect}${i}social_error=${encodeURIComponent(t)}`);
267
267
  return {
268
268
  ...a,
269
269
  headers: {
@@ -271,188 +271,188 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
271
271
  "set-cookie": r
272
272
  }
273
273
  };
274
- }, Z = (e, t, n, a, o) => {
275
- if (t === "steam") {
276
- let e = le({
277
- returnTo: H,
278
- ...F?.realm === void 0 ? {} : { realm: F.realm }
279
- }), t = y(M, De({
274
+ }, Le = (t, n, r, i, a) => {
275
+ if (n === "steam") {
276
+ let e = re({
277
+ returnTo: ke,
278
+ ...V?.realm === void 0 ? {} : { realm: V.realm }
279
+ }), t = E(R, be({
280
280
  p: "steam",
281
281
  s: e.state,
282
282
  v: "",
283
283
  n: "",
284
- exp: Math.floor(Date.now() / 1e3) + j,
285
- audience: V,
286
- redirectUri: H,
287
- ...n === void 0 ? {} : { guest: n },
288
- ...o === void 0 || n !== void 0 ? {} : { link: o }
289
- }, S(k.auth)), {
290
- maxAgeSeconds: j,
284
+ exp: Math.floor(Date.now() / 1e3) + L,
285
+ audience: K,
286
+ redirectUri: ke,
287
+ ...r === void 0 ? {} : { guest: r },
288
+ ...a === void 0 || r !== void 0 ? {} : { link: a }
289
+ }, k(F.auth)), {
290
+ maxAgeSeconds: L,
291
291
  httpOnly: !0,
292
292
  sameSite: "lax",
293
- secure: N,
294
- ...k.auth.cookieDomain ? { domain: k.auth.cookieDomain } : {},
295
- path: A
296
- }), r = D(e.url, t);
297
- return B ? {
298
- ...r,
293
+ secure: z,
294
+ ...F.auth.cookieDomain ? { domain: F.auth.cookieDomain } : {},
295
+ path: I
296
+ }), n = P(e.url, t);
297
+ return G ? {
298
+ ...n,
299
299
  headers: {
300
- ...r.headers,
301
- "set-cookie": [t, G(z)]
300
+ ...n.headers,
301
+ "set-cookie": [t, J(W)]
302
302
  }
303
- } : r;
303
+ } : n;
304
304
  }
305
- let s = K(t), c = r(t, s.endpoints), l = i({
306
- provider: t,
307
- clientId: s.clientId,
308
- redirectUri: s.redirectUri,
309
- ...s.scopes === void 0 ? {} : { scopes: s.scopes },
310
- endpoints: s.endpoints,
311
- ...new URLSearchParams(e.query).get("login_hint") ? { loginHint: new URLSearchParams(e.query).get("login_hint") } : {}
312
- }), u = y(M, De({
313
- p: t,
314
- s: l.state,
315
- v: l.codeVerifier,
316
- n: l.nonce,
317
- exp: Math.floor(Date.now() / 1e3) + j,
318
- audience: V,
319
- redirectUri: s.redirectUri,
320
- ...n === void 0 ? {} : { guest: n },
321
- ...n !== void 0 && a !== void 0 ? { native: a } : {},
322
- ...o === void 0 || n !== void 0 ? {} : { link: o }
323
- }, S(k.auth)), {
324
- maxAgeSeconds: j,
305
+ let o = je(n), s = te(n, o.endpoints), c = e({
306
+ provider: n,
307
+ clientId: o.clientId,
308
+ redirectUri: o.redirectUri,
309
+ ...o.scopes === void 0 ? {} : { scopes: o.scopes },
310
+ endpoints: o.endpoints,
311
+ ...new URLSearchParams(t.query).get("login_hint") ? { loginHint: new URLSearchParams(t.query).get("login_hint") } : {}
312
+ }), l = E(R, be({
313
+ p: n,
314
+ s: c.state,
315
+ v: c.codeVerifier,
316
+ n: c.nonce,
317
+ exp: Math.floor(Date.now() / 1e3) + L,
318
+ audience: K,
319
+ redirectUri: o.redirectUri,
320
+ ...r === void 0 ? {} : { guest: r },
321
+ ...r !== void 0 && i !== void 0 ? { native: i } : {},
322
+ ...a === void 0 || r !== void 0 ? {} : { link: a }
323
+ }, k(F.auth)), {
324
+ maxAgeSeconds: L,
325
325
  httpOnly: !0,
326
- sameSite: c.responseMode === "form_post" ? "none" : "lax",
327
- secure: c.responseMode === "form_post" || N,
328
- ...k.auth.cookieDomain ? { domain: k.auth.cookieDomain } : {},
329
- path: A
330
- }), d = D(l.url, u);
331
- return B ? {
332
- ...d,
326
+ sameSite: s.responseMode === "form_post" ? "none" : "lax",
327
+ secure: s.responseMode === "form_post" || z,
328
+ ...F.auth.cookieDomain ? { domain: F.auth.cookieDomain } : {},
329
+ path: I
330
+ }), u = P(c.url, l);
331
+ return G ? {
332
+ ...u,
333
333
  headers: {
334
- ...d.headers,
335
- "set-cookie": [u, G(z)]
334
+ ...u.headers,
335
+ "set-cookie": [l, J(W)]
336
336
  }
337
- } : d;
338
- }, ze = (e) => {
339
- let t = new URL(H);
337
+ } : u;
338
+ }, Re = (e) => {
339
+ let t = new URL(ke);
340
340
  return t.searchParams.set("state", e), t.href;
341
- }, Be = async (e, n) => {
342
- if (!F || !U) throw new t("socialAuthPlugin: steam has no hot store for replay protection");
343
- let r = new URL(A + "/steam/callback", R + "/");
344
- r.search = new URLSearchParams(e.query).toString();
345
- let i = await g.runPromise(g.result(ue({
346
- callbackUrl: r.href,
347
- expectedReturnTo: ze(n?.s ?? ""),
348
- expectedState: n?.s ?? "",
349
- hotStore: await U(),
350
- namespace: "auth-social:steam:" + V,
351
- ...F.multiNode === void 0 ? {} : { multiNode: F.multiNode },
352
- ...F.timeoutMs === void 0 ? {} : { timeoutMs: F.timeoutMs },
353
- ...F.fetchImpl === void 0 ? {} : { fetchImpl: F.fetchImpl },
354
- ...F.verificationUrl === void 0 ? {} : { verificationUrl: F.verificationUrl }
341
+ }, ze = async (e, t) => {
342
+ if (!V || !Ae) throw new x("socialAuthPlugin: steam has no hot store for replay protection");
343
+ let n = new URL(I + "/steam/callback", U + "/");
344
+ n.search = new URLSearchParams(e.query).toString();
345
+ let r = await C.runPromise(C.result(ie({
346
+ callbackUrl: n.href,
347
+ expectedReturnTo: Re(t?.s ?? ""),
348
+ expectedState: t?.s ?? "",
349
+ hotStore: await Ae(),
350
+ namespace: "auth-social:steam:" + K,
351
+ ...V.multiNode === void 0 ? {} : { multiNode: V.multiNode },
352
+ ...V.timeoutMs === void 0 ? {} : { timeoutMs: V.timeoutMs },
353
+ ...V.fetchImpl === void 0 ? {} : { fetchImpl: V.fetchImpl },
354
+ ...V.verificationUrl === void 0 ? {} : { verificationUrl: V.verificationUrl }
355
355
  })));
356
- if (_.isFailure(i)) throw i.failure;
357
- return i.success;
358
- }, Ve = async (e, t) => {
359
- let n = ke(e), r = Oe(b(e.headers.cookie, M), S(k.auth)), i = t === "steam" ? null : K(t), s = r && r.p === t && r.audience === V && r.redirectUri === (i === null ? H : i.redirectUri) ? r : null, c = B?.native && s?.guest && s.native ? s.native : null, l = (e) => {
360
- let t = D(e);
356
+ if (w.isFailure(r)) throw r.failure;
357
+ return r.success;
358
+ }, Be = async (e, r) => {
359
+ let i = Se(e), a = xe(D(e.headers.cookie, R), k(F.auth)), o = r === "steam" ? null : je(r), c = a && a.p === r && a.audience === K && a.redirectUri === (o === null ? ke : o.redirectUri) ? a : null, l = G?.native && c?.guest && c.native ? c.native : null, u = (e) => {
360
+ let t = P(e);
361
361
  return {
362
362
  ...t,
363
363
  headers: {
364
364
  ...t.headers,
365
- "set-cookie": [G(M)]
365
+ "set-cookie": [J(R)]
366
366
  }
367
367
  };
368
- }, d = (e, t, n) => c ? l(Ee(c.r, {
368
+ }, d = (e, t, n) => l ? u(ye(l.r, {
369
369
  error: t,
370
- state: c.ns
371
- })) : X(e, t, n);
372
- if (n.get("error")) return d(400, "exchange_failed", `${t} refused the authorization`);
373
- if (s?.guest) {
374
- if (!B || !e.store || s.guest.tenantId !== B.guest.tenantId) return d(403, "credential_rejected", "Guest upgrade was refused.");
375
- let t = await g.runPromise(g.result(W(e.store).isLive(s.guest)));
376
- if (_.isFailure(t)) return d(503, "store_unavailable", "Guest upgrade storage is unavailable.");
370
+ state: l.ns
371
+ })) : Q(e, t, n);
372
+ if (i.get("error")) return d(400, "exchange_failed", `${r} refused the authorization`);
373
+ if (c?.guest) {
374
+ if (!G || !e.store || c.guest.tenantId !== G.guest.tenantId) return d(403, "credential_rejected", "Guest upgrade was refused.");
375
+ let t = await C.runPromise(C.result(q(e.store).isLive(c.guest)));
376
+ if (w.isFailure(t)) return d(503, "store_unavailable", "Guest upgrade storage is unavailable.");
377
377
  if (!t.success) return d(403, "credential_rejected", "Guest upgrade was refused.");
378
378
  }
379
- if (s?.link) {
379
+ if (c?.link) {
380
380
  let t = await Ke(e);
381
381
  if (t === "unavailable") return d(503, "store_unavailable", "Account storage is unavailable.");
382
- if (!t || t.id !== s.link.u || t.tenantId !== s.link.t || t.sessionId !== s.link.sid) return d(403, "credential_rejected", "Sign in again to connect this provider.");
382
+ if (!t || t.id !== c.link.u || t.tenantId !== c.link.t || t.sessionId !== c.link.sid) return d(403, "credential_rejected", "Sign in again to connect this provider.");
383
383
  }
384
- let f = i === null ? await Be(e, s) : await a({
385
- provider: t,
386
- clientId: i.clientId,
387
- ...i.clientSecret === void 0 ? {} : { clientSecret: i.clientSecret },
388
- ...i.appleKey === void 0 ? {} : { appleKey: i.appleKey },
389
- redirectUri: i.redirectUri,
390
- code: n.get("code") ?? "",
391
- state: n.get("state") ?? "",
392
- expectedState: s?.s ?? "",
393
- codeVerifier: s?.v ?? "",
394
- expectedNonce: s?.n ?? "",
395
- ...n.get("user") ? { appleUserPayload: n.get("user") } : {},
396
- endpoints: i.endpoints
384
+ let p = o === null ? await ze(e, c) : await t({
385
+ provider: r,
386
+ clientId: o.clientId,
387
+ ...o.clientSecret === void 0 ? {} : { clientSecret: o.clientSecret },
388
+ ...o.appleKey === void 0 ? {} : { appleKey: o.appleKey },
389
+ redirectUri: o.redirectUri,
390
+ code: i.get("code") ?? "",
391
+ state: i.get("state") ?? "",
392
+ expectedState: c?.s ?? "",
393
+ codeVerifier: c?.v ?? "",
394
+ expectedNonce: c?.n ?? "",
395
+ ...i.get("user") ? { appleUserPayload: i.get("user") } : {},
396
+ endpoints: o.endpoints
397
397
  });
398
- if (s?.guest && B) {
399
- let e = Math.min(s.exp, Math.floor(Date.now() / 1e3) + j), t = h({
400
- guest: s.guest,
401
- profile: f,
398
+ if (c?.guest && G) {
399
+ let e = Math.min(c.exp, Math.floor(Date.now() / 1e3) + L), t = s({
400
+ guest: c.guest,
401
+ profile: p,
402
402
  exp: e,
403
- audience: V
404
- }, S(k.auth));
405
- if (c) {
406
- let n = ae({
403
+ audience: K
404
+ }, k(F.auth));
405
+ if (l) {
406
+ let n = f({
407
407
  handoff: t,
408
- ch: c.ch,
409
- guestId: s.guest.id,
408
+ ch: l.ch,
409
+ guestId: c.guest.id,
410
410
  exp: Math.min(e, Math.floor(Date.now() / 1e3) + 120)
411
- }, S(k.auth), V);
412
- return l(Ee(c.r, {
411
+ }, k(F.auth), K);
412
+ return u(ye(l.r, {
413
413
  code: n,
414
- state: c.ns
414
+ state: l.ns
415
415
  }));
416
416
  }
417
- let n = D(B.confirmationRedirect);
417
+ let n = P(G.confirmationRedirect);
418
418
  return {
419
419
  ...n,
420
420
  headers: {
421
421
  ...n.headers,
422
- "set-cookie": [G(M), y(z, t, {
422
+ "set-cookie": [J(R), E(W, t, {
423
423
  maxAgeSeconds: Math.max(0, e - Math.floor(Date.now() / 1e3)),
424
- path: A,
424
+ path: I,
425
425
  httpOnly: !0,
426
426
  sameSite: "lax",
427
- secure: N,
428
- ...k.auth.cookieDomain ? { domain: k.auth.cookieDomain } : {}
427
+ secure: z,
428
+ ...F.auth.cookieDomain ? { domain: F.auth.cookieDomain } : {}
429
429
  })]
430
430
  }
431
431
  };
432
432
  }
433
- if (s?.link) {
434
- let n = await g.runPromise(g.result(u(Y(e), s.link.u, {
435
- provider: f.provider,
436
- providerAccountId: f.providerAccountId,
437
- email: f.email,
438
- emailVerified: f.emailVerified
433
+ if (c?.link) {
434
+ let t = await C.runPromise(C.result(ee(Z(e), c.link.u, {
435
+ provider: p.provider,
436
+ providerAccountId: p.providerAccountId,
437
+ email: p.email,
438
+ emailVerified: p.emailVerified
439
439
  })));
440
- return _.isFailure(n) ? d(409, "identity_in_use", "This provider account is already connected to another account.") : l(Ee(k.linkRedirect ?? k.successRedirect ?? k.auth.successRedirect ?? "/", { social_linked: t }));
440
+ return w.isFailure(t) ? d(409, "identity_in_use", "This provider account is already connected to another account.") : u(ye(F.linkRedirect ?? F.successRedirect ?? F.auth.successRedirect ?? "/", { social_linked: r }));
441
441
  }
442
- let p = await g.runPromise(o({
443
- profile: f,
444
- identities: Y(e),
445
- users: k.users,
446
- config: k.auth,
447
- policy: Ae,
442
+ let m = await C.runPromise(n({
443
+ profile: p,
444
+ identities: Z(e),
445
+ users: F.users,
446
+ config: F.auth,
447
+ policy: we,
448
448
  ipAddress: e.remoteAddr ?? null,
449
449
  userAgent: e.headers["user-agent"] ?? null
450
450
  }));
451
- if (p.kind === "refused") return X(p.status, p.code, p.message);
452
- let m = y(M, "", {
451
+ if (m.kind === "refused") return Q(m.status, m.code, m.message);
452
+ let h = E(R, "", {
453
453
  maxAgeSeconds: 0,
454
- path: A,
455
- secure: N
454
+ path: I,
455
+ secure: z
456
456
  });
457
457
  return {
458
458
  status: 302,
@@ -461,125 +461,125 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
461
461
  headers: {
462
462
  "cache-control": "no-store",
463
463
  "referrer-policy": "no-referrer",
464
- location: k.successRedirect ?? k.auth.successRedirect ?? "/",
465
- "set-cookie": [m, p.setCookie]
464
+ location: F.successRedirect ?? F.auth.successRedirect ?? "/",
465
+ "set-cookie": [h, m.setCookie]
466
466
  }
467
467
  };
468
- }, Q = (e, t) => ({
469
- ...E(e, t),
468
+ }, $ = (e, t) => ({
469
+ ...N(e, t),
470
470
  headers: { "cache-control": "no-store" }
471
- }), He = async (e, t, r) => {
472
- let i = B?.native;
473
- if (!B || !i) return E(404, { error: "not_found" });
471
+ }), Ve = async (e, t, n) => {
472
+ let i = G?.native;
473
+ if (!G || !i) return N(404, { error: "not_found" });
474
474
  let a = async (t) => {
475
- if (!e.store) return Q(503, { error: "store_unavailable" });
476
- let n = await g.runPromise(g.result(W(e.store).isLive(t)));
477
- return _.isFailure(n) ? Q(503, { error: "store_unavailable" }) : n.success ? null : Q(403, { error: "credential_rejected" });
475
+ if (!e.store) return $(503, { error: "store_unavailable" });
476
+ let n = await C.runPromise(C.result(q(e.store).isLive(t)));
477
+ return w.isFailure(n) ? $(503, { error: "store_unavailable" }) : n.success ? null : $(403, { error: "credential_rejected" });
478
478
  };
479
479
  if (t === "begin") {
480
- if (e.method !== "GET") return E(405, { error: "method_not_allowed" });
481
- let t = ce(new URLSearchParams(e.query).get("t"), r, V, i.redirectUris);
482
- return !t || !n(t.provider) || !P.includes(t.provider) || t.guest.tenantId !== B.guest.tenantId ? Q(403, { error: "upgrade_ticket_rejected" }) : await a(t.guest) ?? Z(e, t.provider, t.guest, t.native);
480
+ if (e.method !== "GET") return N(405, { error: "method_not_allowed" });
481
+ let t = h(new URLSearchParams(e.query).get("t"), n, K, i.redirectUris);
482
+ return !t || !S(t.provider) || !B.includes(t.provider) || t.guest.tenantId !== G.guest.tenantId ? $(403, { error: "upgrade_ticket_rejected" }) : await a(t.guest) ?? Le(e, t.provider, t.guest, t.native);
483
483
  }
484
- if (e.method !== "POST") return E(405, { error: "method_not_allowed" });
485
- if ((e.headers["content-type"] ?? "").split(";")[0]?.trim() !== "application/json") return E(415, { error: "json_required" });
486
- if (e.rawBody.byteLength > 8192) return E(413, { error: "body_too_large" });
487
- let o;
484
+ if (e.method !== "POST") return N(405, { error: "method_not_allowed" });
485
+ if ((e.headers["content-type"] ?? "").split(";")[0]?.trim() !== "application/json") return N(415, { error: "json_required" });
486
+ if (e.rawBody.byteLength > 8192) return N(413, { error: "body_too_large" });
487
+ let s;
488
488
  try {
489
- o = JSON.parse(new TextDecoder().decode(e.rawBody));
489
+ s = JSON.parse(new TextDecoder().decode(e.rawBody));
490
490
  } catch {
491
- return Q(400, { error: "invalid_input" });
491
+ return $(400, { error: "invalid_input" });
492
492
  }
493
- if (!o || typeof o != "object" || Array.isArray(o)) return Q(400, { error: "invalid_input" });
494
- let s = o;
493
+ if (!s || typeof s != "object" || Array.isArray(s)) return $(400, { error: "invalid_input" });
494
+ let f = s;
495
495
  if (t.startsWith("start/")) {
496
- let o = t.slice(6);
497
- if (!n(o) || !P.includes(o)) return E(404, { error: "not_found" });
498
- let c = e.headers[me], l = typeof B.guest.secret == "function" ? B.guest.secret() : B.guest.secret, u = typeof c == "string" && c ? te(C({ [me]: c }, l)?.subject) : null;
499
- if (!u || u.tenantId !== B.guest.tenantId) return Q(403, { error: "credential_rejected" });
500
- let d = re({
501
- ch: s.codeChallenge,
502
- r: s.redirectUri,
503
- ns: s.state
496
+ let r = t.slice(6);
497
+ if (!S(r) || !B.includes(r)) return N(404, { error: "not_found" });
498
+ let o = e.headers[se], s = typeof G.guest.secret == "function" ? G.guest.secret() : G.guest.secret, l = typeof o == "string" && o ? c(A({ [se]: o }, s)?.subject) : null;
499
+ if (!l || l.tenantId !== G.guest.tenantId) return $(403, { error: "credential_rejected" });
500
+ let d = u({
501
+ ch: f.codeChallenge,
502
+ r: f.redirectUri,
503
+ ns: f.state
504
504
  }, i.redirectUris);
505
- if (!d || Object.keys(s).some((e) => e !== "codeChallenge" && e !== "redirectUri" && e !== "state")) return Q(400, { error: "invalid_input" });
506
- let f = await a(u);
507
- if (f) return f;
508
- let p = oe({
509
- guest: u,
510
- provider: o,
505
+ if (!d || Object.keys(f).some((e) => e !== "codeChallenge" && e !== "redirectUri" && e !== "state")) return $(400, { error: "invalid_input" });
506
+ let m = await a(l);
507
+ if (m) return m;
508
+ let h = p({
509
+ guest: l,
510
+ provider: r,
511
511
  native: d,
512
- exp: Math.floor(Date.now() / 1e3) + j,
513
- audience: V
514
- }, r), m = new URL(A + "/upgrade/native/begin", K(o).redirectUri);
515
- return m.search = new URLSearchParams({ t: p }).toString(), Q(200, { authorizationUrl: m.toString() });
512
+ exp: Math.floor(Date.now() / 1e3) + L,
513
+ audience: K
514
+ }, n), g = new URL(I + "/upgrade/native/begin", je(r).redirectUri);
515
+ return g.search = new URLSearchParams({ t: h }).toString(), $(200, { authorizationUrl: g.toString() });
516
516
  }
517
- if (t !== "complete") return E(404, { error: "not_found" });
518
- if (Object.keys(s).some((e) => e !== "code" && e !== "codeVerifier" && e !== "credential" && e !== "confirmed") || s.confirmed !== !0 || typeof s.credential != "string" || !ne(s.codeVerifier)) return Q(400, { error: "invalid_input" });
519
- let c = ie(s.code, r, V);
520
- if (!c || !se(s.codeVerifier, c.ch)) return Q(400, { error: "invalid_code" });
521
- let l = ee(c.handoff, r, V), u = be(s.credential);
522
- if (!l || l.guest.id !== c.guestId || l.guest.tenantId !== B.guest.tenantId || !u || u.guestId !== l.guest.id || u.deviceId !== l.guest.metadata?.guestDeviceId) return Q(403, { error: "upgrade_handoff_rejected" });
523
- let d = await a(l.guest);
524
- if (d) return d;
525
- let p = await g.runPromise(f({
526
- profile: l.profile,
527
- credential: s.credential,
517
+ if (t !== "complete") return N(404, { error: "not_found" });
518
+ if (Object.keys(f).some((e) => e !== "code" && e !== "codeVerifier" && e !== "credential" && e !== "confirmed") || f.confirmed !== !0 || typeof f.credential != "string" || !l(f.codeVerifier)) return $(400, { error: "invalid_input" });
519
+ let g = d(f.code, n, K);
520
+ if (!g || !m(f.codeVerifier, g.ch)) return $(400, { error: "invalid_code" });
521
+ let _ = o(g.handoff, n, K), v = pe(f.credential);
522
+ if (!_ || _.guest.id !== g.guestId || _.guest.tenantId !== G.guest.tenantId || !v || v.guestId !== _.guest.id || v.deviceId !== _.guest.metadata?.guestDeviceId) return $(403, { error: "upgrade_handoff_rejected" });
523
+ let ee = await a(_.guest);
524
+ if (ee) return ee;
525
+ let y = await C.runPromise(r({
526
+ profile: _.profile,
527
+ credential: f.credential,
528
528
  store: e.store,
529
- guest: B.guest,
530
- service: W(e.store),
531
- users: k.users,
532
- config: k.auth,
533
- ...B.configForTransaction ? { configForTransaction: B.configForTransaction } : {},
529
+ guest: G.guest,
530
+ service: q(e.store),
531
+ users: F.users,
532
+ config: F.auth,
533
+ ...G.configForTransaction ? { configForTransaction: G.configForTransaction } : {},
534
534
  ipAddress: e.remoteAddr ?? null,
535
535
  userAgent: e.headers["user-agent"] ?? null
536
536
  }));
537
- return p.kind === "refused" ? Q(p.status, {
538
- error: p.code,
539
- message: p.message
540
- }) : Q(200, {
537
+ return y.kind === "refused" ? $(y.status, {
538
+ error: y.code,
539
+ message: y.message
540
+ }) : $(200, {
541
541
  ok: !0,
542
542
  upgraded: !0,
543
- subject: p.subject,
544
- session: p.session.value,
545
- expiresAt: p.session.expiresAt
543
+ subject: y.subject,
544
+ session: y.session.value,
545
+ expiresAt: y.session.expiresAt
546
546
  });
547
- }, $ = /* @__PURE__ */ new Map(), Ue = async (e, t) => {
548
- let n = ($.get(e) ?? Promise.resolve()).then(t, t), r = n.then(() => void 0, () => void 0);
549
- $.set(e, r);
547
+ }, He = /* @__PURE__ */ new Map(), Ue = async (e, t) => {
548
+ let n = (He.get(e) ?? Promise.resolve()).then(t, t), r = n.then(() => void 0, () => void 0);
549
+ He.set(e, r);
550
550
  try {
551
551
  return await n;
552
552
  } finally {
553
- $.get(e) === r && $.delete(e);
553
+ He.get(e) === r && He.delete(e);
554
554
  }
555
- }, We = async (t) => {
556
- let [n, r, ...i] = t.path.slice((A + "/platform/").length).split("/"), a = n === void 0 ? void 0 : L.get(n);
557
- if (!a || i.length !== 0 || r !== "sign-in" && r !== "link" || r === "link" && !B) return E(404, { error: "not_found" });
558
- if (t.method !== "POST") return E(405, { error: "method_not_allowed" });
559
- if ((t.headers["content-type"] ?? "").split(";")[0]?.trim() !== "application/json") return E(415, { error: "json_required" });
560
- if (t.rawBody.byteLength > 16384) return E(413, { error: "body_too_large" });
555
+ }, We = async (e) => {
556
+ let [t, i, ...a] = e.path.slice((I + "/platform/").length).split("/"), o = t === void 0 ? void 0 : H.get(t);
557
+ if (!o || a.length !== 0 || i !== "sign-in" && i !== "link" || i === "link" && !G) return N(404, { error: "not_found" });
558
+ if (e.method !== "POST") return N(405, { error: "method_not_allowed" });
559
+ if ((e.headers["content-type"] ?? "").split(";")[0]?.trim() !== "application/json") return N(415, { error: "json_required" });
560
+ if (e.rawBody.byteLength > 16384) return N(413, { error: "body_too_large" });
561
561
  let s;
562
562
  try {
563
- s = JSON.parse(new TextDecoder().decode(t.rawBody));
563
+ s = JSON.parse(new TextDecoder().decode(e.rawBody));
564
564
  } catch {
565
- return Q(400, { error: "invalid_input" });
565
+ return $(400, { error: "invalid_input" });
566
566
  }
567
- if (!s || typeof s != "object" || Array.isArray(s)) return Q(400, { error: "invalid_input" });
568
- let c = s, l = r === "link" ? ["ticket", "credential"] : ["ticket"];
569
- if (Object.keys(c).some((e) => !l.includes(e)) || typeof c.ticket != "string" || c.ticket.length === 0 || r === "link" && (typeof c.credential != "string" || !be(c.credential))) return Q(400, { error: "invalid_input" });
570
- if (!t.store && (r === "link" || !k.identities)) return Q(503, { error: "store_unavailable" });
567
+ if (!s || typeof s != "object" || Array.isArray(s)) return $(400, { error: "invalid_input" });
568
+ let c = s, l = i === "link" ? ["ticket", "credential"] : ["ticket"];
569
+ if (Object.keys(c).some((e) => !l.includes(e)) || typeof c.ticket != "string" || c.ticket.length === 0 || i === "link" && (typeof c.credential != "string" || !pe(c.credential))) return $(400, { error: "invalid_input" });
570
+ if (!e.store && (i === "link" || !F.identities)) return $(503, { error: "store_unavailable" });
571
571
  let u;
572
572
  try {
573
- u = await de(a, c.ticket);
574
- } catch (t) {
575
- if (t instanceof e) return Q(t.status, {
576
- error: t.code,
577
- message: t.message
573
+ u = await ne(o, c.ticket);
574
+ } catch (e) {
575
+ if (e instanceof b) return $(e.status, {
576
+ error: e.code,
577
+ message: e.message
578
578
  });
579
- throw t;
579
+ throw e;
580
580
  }
581
581
  let d = {
582
- provider: a.id,
582
+ provider: o.id,
583
583
  providerAccountId: u.accountId,
584
584
  email: null,
585
585
  emailVerified: !1,
@@ -590,69 +590,69 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
590
590
  avatarUrl: null,
591
591
  nameIsFirstAuthorizationOnly: !1,
592
592
  raw: {}
593
- }, p = {
594
- ipAddress: t.remoteAddr ?? null,
595
- userAgent: t.headers["user-agent"] ?? null
596
- }, m = await Ue(a.id + "\0" + u.accountId, () => r === "sign-in" ? g.runPromise(o({
593
+ }, f = {
594
+ ipAddress: e.remoteAddr ?? null,
595
+ userAgent: e.headers["user-agent"] ?? null
596
+ }, p = await Ue(o.id + "\0" + u.accountId, () => i === "sign-in" ? C.runPromise(n({
597
597
  profile: d,
598
- identities: Y(t),
599
- users: k.users,
600
- config: k.auth,
601
- policy: Ae,
602
- ...p
603
- })) : g.runPromise(f({
598
+ identities: Z(e),
599
+ users: F.users,
600
+ config: F.auth,
601
+ policy: we,
602
+ ...f
603
+ })) : C.runPromise(r({
604
604
  profile: d,
605
605
  credential: c.credential,
606
- store: t.store,
607
- guest: B.guest,
608
- service: W(t.store),
609
- users: k.users,
610
- config: k.auth,
611
- ...B.configForTransaction ? { configForTransaction: B.configForTransaction } : {},
612
- ...p
606
+ store: e.store,
607
+ guest: G.guest,
608
+ service: q(e.store),
609
+ users: F.users,
610
+ config: F.auth,
611
+ ...G.configForTransaction ? { configForTransaction: G.configForTransaction } : {},
612
+ ...f
613
613
  })));
614
- return m.kind === "refused" ? Q(m.status, {
615
- error: m.code,
616
- message: m.message
617
- }) : Q(200, {
614
+ return p.kind === "refused" ? $(p.status, {
615
+ error: p.code,
616
+ message: p.message
617
+ }) : $(200, {
618
618
  ok: !0,
619
- subject: m.subject,
620
- session: m.session.value,
621
- expiresAt: m.session.expiresAt,
622
- created: m.created
619
+ subject: p.subject,
620
+ session: p.session.value,
621
+ expiresAt: p.session.expiresAt,
622
+ created: p.created
623
623
  });
624
624
  }, Ge = async (e) => {
625
- if (!B) return E(404, { error: "not_found" });
626
- let t = e.path.slice((A + "/upgrade/").length), n = S(k.auth);
627
- if (t.startsWith("native/")) return He(e, t.slice(7), n);
625
+ if (!G) return N(404, { error: "not_found" });
626
+ let t = e.path.slice((I + "/upgrade/").length), n = k(F.auth);
627
+ if (t.startsWith("native/")) return Ve(e, t.slice(7), n);
628
628
  if (t === "csrf") {
629
- if (e.method !== "GET") return E(405, { error: "method_not_allowed" });
630
- let t = ye(n.current.secret);
629
+ if (e.method !== "GET") return N(405, { error: "method_not_allowed" });
630
+ let t = fe(n.current.secret);
631
631
  return {
632
- ...E(200, { token: t }),
632
+ ...N(200, { token: t }),
633
633
  headers: {
634
634
  "cache-control": "no-store",
635
- "set-cookie": y(x, t, {
635
+ "set-cookie": E(O, t, {
636
636
  path: "/",
637
637
  httpOnly: !1,
638
- secure: N,
638
+ secure: z,
639
639
  sameSite: "lax",
640
- maxAgeSeconds: j,
641
- ...k.auth.cookieDomain ? { domain: k.auth.cookieDomain } : {}
640
+ maxAgeSeconds: L,
641
+ ...F.auth.cookieDomain ? { domain: F.auth.cookieDomain } : {}
642
642
  })
643
643
  }
644
644
  };
645
645
  }
646
- let r = () => ee(b(e.headers.cookie, z), n, V);
646
+ let s = () => o(D(e.headers.cookie, W), n, K);
647
647
  if (t === "receipt") {
648
- if (e.method !== "GET") return E(405, { error: "method_not_allowed" });
649
- let t = C(e.headers, n)?.subject;
650
- if (!e.store || t?.type !== "user" || t.kind === "guest" || !/^guest_[A-Za-z0-9_-]+$/.test(t.id) || t.tenantId !== B.guest.tenantId || typeof t.metadata?.sessionId != "string") return E(403, { error: "credential_rejected" });
648
+ if (e.method !== "GET") return N(405, { error: "method_not_allowed" });
649
+ let t = A(e.headers, n)?.subject;
650
+ if (!e.store || t?.type !== "user" || t.kind === "guest" || !/^guest_[A-Za-z0-9_-]+$/.test(t.id) || t.tenantId !== G.guest.tenantId || typeof t.metadata?.sessionId != "string") return N(403, { error: "credential_rejected" });
651
651
  try {
652
- let n = await g.runPromise(_e(e.store).findSession(t.metadata.sessionId));
653
- if (!n || n.userId !== t.id || n.tenantId !== t.tenantId || !(n.expiresAt.getTime() > Date.now())) return E(403, { error: "credential_rejected" });
652
+ let n = await C.runPromise(ue(e.store).findSession(t.metadata.sessionId));
653
+ if (!n || n.userId !== t.id || n.tenantId !== t.tenantId || !(n.expiresAt.getTime() > Date.now())) return N(403, { error: "credential_rejected" });
654
654
  let r = {
655
- predicate: fe(v("id", t.id), v("tenantId", t.tenantId)),
655
+ predicate: ae(T("id", t.id), T("tenantId", t.tenantId)),
656
656
  order: [],
657
657
  take: void 0,
658
658
  skip: void 0,
@@ -664,7 +664,7 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
664
664
  table: "authGuests",
665
665
  ...r
666
666
  }))[0];
667
- return !i || i.id !== t.id || i.tenantId !== t.tenantId || a || i.deactivatedAt !== null && i.deactivatedAt !== void 0 ? E(403, { error: "credential_rejected" }) : E(200, {
667
+ return !i || i.id !== t.id || i.tenantId !== t.tenantId || a || i.deactivatedAt !== null && i.deactivatedAt !== void 0 ? N(403, { error: "credential_rejected" }) : N(200, {
668
668
  upgraded: !0,
669
669
  subject: {
670
670
  type: "user",
@@ -673,128 +673,128 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
673
673
  }
674
674
  });
675
675
  } catch {
676
- return E(503, { error: "store_unavailable" });
676
+ return N(503, { error: "store_unavailable" });
677
677
  }
678
678
  }
679
679
  if (t === "pending") {
680
- if (e.method !== "GET") return E(405, { error: "method_not_allowed" });
681
- let t = r();
682
- if (!t || t.guest.tenantId !== B.guest.tenantId || !e.store) return E(403, { error: "upgrade_handoff_rejected" });
683
- let n = await g.runPromise(g.result(W(e.store).isLive(t.guest)));
684
- if (_.isFailure(n)) return E(503, { error: "store_unavailable" });
685
- if (!n.success) return E(403, { error: "credential_rejected" });
686
- let i = await g.runPromise(g.result(m(e.store, t.profile)));
687
- return _.isFailure(i) ? E(503, { error: "store_unavailable" }) : E(200, {
680
+ if (e.method !== "GET") return N(405, { error: "method_not_allowed" });
681
+ let t = s();
682
+ if (!t || t.guest.tenantId !== G.guest.tenantId || !e.store) return N(403, { error: "upgrade_handoff_rejected" });
683
+ let n = await C.runPromise(C.result(q(e.store).isLive(t.guest)));
684
+ if (w.isFailure(n)) return N(503, { error: "store_unavailable" });
685
+ if (!n.success) return N(403, { error: "credential_rejected" });
686
+ let r = await C.runPromise(C.result(a(e.store, t.profile)));
687
+ return w.isFailure(r) ? N(503, { error: "store_unavailable" }) : N(200, {
688
688
  guestId: t.guest.id,
689
689
  provider: t.profile.provider,
690
690
  email: t.profile.email,
691
691
  emailVerified: t.profile.emailVerified,
692
692
  expiresAt: t.exp * 1e3,
693
- conflict: i.success.kind === "none" ? null : i.success.kind
693
+ conflict: r.success.kind === "none" ? null : r.success.kind
694
694
  });
695
695
  }
696
- let i = I(t);
697
- if (!i && t !== "complete" && t !== "merge") return E(404, { error: "not_found" });
698
- if (e.method !== "POST") return E(405, { error: "method_not_allowed" });
699
- if ((e.headers["content-type"] ?? "").split(";")[0]?.trim() !== "application/json") return E(415, { error: "json_required" });
700
- if (e.rawBody.byteLength > 1024) return E(413, { error: "body_too_large" });
701
- if (![n.current, n.previous].filter((e) => e !== void 0).some((t) => Se(e.headers[he], b(e.headers.cookie, x), t.secret))) return E(403, { error: "csrf_rejected" });
702
- let a;
696
+ let l = Oe(t);
697
+ if (!l && t !== "complete" && t !== "merge") return N(404, { error: "not_found" });
698
+ if (e.method !== "POST") return N(405, { error: "method_not_allowed" });
699
+ if ((e.headers["content-type"] ?? "").split(";")[0]?.trim() !== "application/json") return N(415, { error: "json_required" });
700
+ if (e.rawBody.byteLength > 1024) return N(413, { error: "body_too_large" });
701
+ if (![n.current, n.previous].filter((e) => e !== void 0).some((t) => he(e.headers[ce], D(e.headers.cookie, O), t.secret))) return N(403, { error: "csrf_rejected" });
702
+ let u;
703
703
  try {
704
- a = JSON.parse(new TextDecoder().decode(e.rawBody));
704
+ u = JSON.parse(new TextDecoder().decode(e.rawBody));
705
705
  } catch {
706
- return E(400, { error: "invalid_input" });
706
+ return N(400, { error: "invalid_input" });
707
707
  }
708
- if (!a || typeof a != "object" || Array.isArray(a)) return E(400, { error: "invalid_input" });
709
- let o = a;
710
- if (!e.store) return E(503, { error: "store_unavailable" });
711
- let s = W(e.store);
712
- if (i && I(t)) {
713
- if (Object.keys(o).length !== 0) return E(400, { error: "invalid_input" });
714
- let n = typeof B.guest.secret == "function" ? B.guest.secret() : B.guest.secret, r = te(C(e.headers, n)?.subject);
715
- if (!r || r.tenantId !== B.guest.tenantId) return E(403, { error: "credential_rejected" });
716
- let i = await g.runPromise(g.result(s.isLive(r)));
717
- if (_.isFailure(i)) return E(503, { error: "store_unavailable" });
718
- if (!i.success) return E(403, { error: "credential_rejected" });
719
- let a = Z(e, t, r);
708
+ if (!u || typeof u != "object" || Array.isArray(u)) return N(400, { error: "invalid_input" });
709
+ let d = u;
710
+ if (!e.store) return N(503, { error: "store_unavailable" });
711
+ let f = q(e.store);
712
+ if (l && Oe(t)) {
713
+ if (Object.keys(d).length !== 0) return N(400, { error: "invalid_input" });
714
+ let n = typeof G.guest.secret == "function" ? G.guest.secret() : G.guest.secret, r = c(A(e.headers, n)?.subject);
715
+ if (!r || r.tenantId !== G.guest.tenantId) return N(403, { error: "credential_rejected" });
716
+ let i = await C.runPromise(C.result(f.isLive(r)));
717
+ if (w.isFailure(i)) return N(503, { error: "store_unavailable" });
718
+ if (!i.success) return N(403, { error: "credential_rejected" });
719
+ let a = Le(e, t, r);
720
720
  return {
721
- ...E(200, { authorizationUrl: a.headers?.location }),
721
+ ...N(200, { authorizationUrl: a.headers?.location }),
722
722
  headers: {
723
723
  "cache-control": "no-store",
724
724
  "set-cookie": a.headers?.["set-cookie"] ?? []
725
725
  }
726
726
  };
727
727
  }
728
- let c = t === "merge";
729
- if (Object.keys(o).some((e) => e !== "credential" && e !== "confirmed" && !(c && e === "requestId")) || typeof o.credential != "string" || o.confirmed !== !0 || c && typeof o.requestId != "string") return E(400, { error: "invalid_input" });
730
- let l = r(), u = be(o.credential);
731
- if (!l || !u || l.guest.tenantId !== B.guest.tenantId || u.guestId !== l.guest.id || u.deviceId !== l.guest.metadata?.guestDeviceId) return E(403, { error: "upgrade_handoff_rejected" });
732
- if (c) {
733
- let t = await g.runPromise(p({
734
- profile: l.profile,
735
- credential: o.credential,
736
- guestId: l.guest.id,
737
- requestId: o.requestId,
728
+ let p = t === "merge";
729
+ if (Object.keys(d).some((e) => e !== "credential" && e !== "confirmed" && !(p && e === "requestId")) || typeof d.credential != "string" || d.confirmed !== !0 || p && typeof d.requestId != "string") return N(400, { error: "invalid_input" });
730
+ let m = s(), h = pe(d.credential);
731
+ if (!m || !h || m.guest.tenantId !== G.guest.tenantId || h.guestId !== m.guest.id || h.deviceId !== m.guest.metadata?.guestDeviceId) return N(403, { error: "upgrade_handoff_rejected" });
732
+ if (p) {
733
+ let t = await C.runPromise(i({
734
+ profile: m.profile,
735
+ credential: d.credential,
736
+ guestId: m.guest.id,
737
+ requestId: d.requestId,
738
738
  store: e.store,
739
- guest: B.guest,
740
- service: s,
741
- users: k.users,
742
- config: k.auth,
743
- registry: Pe,
744
- privacy: Fe,
739
+ guest: G.guest,
740
+ service: f,
741
+ users: F.users,
742
+ config: F.auth,
743
+ registry: Me,
744
+ privacy: Ne,
745
745
  ipAddress: e.remoteAddr ?? null,
746
746
  userAgent: e.headers["user-agent"] ?? null
747
747
  }));
748
- return t.kind === "refused" ? E(t.status, {
748
+ return t.kind === "refused" ? N(t.status, {
749
749
  error: t.code,
750
750
  message: t.message
751
751
  }) : {
752
- ...E(200, {
752
+ ...N(200, {
753
753
  merged: !0,
754
754
  subject: t.subject,
755
755
  replayed: t.merged.replayed
756
756
  }),
757
757
  headers: {
758
758
  "cache-control": "no-store",
759
- "set-cookie": [G(z), t.setCookie]
759
+ "set-cookie": [J(W), t.setCookie]
760
760
  }
761
761
  };
762
762
  }
763
- let d = await g.runPromise(g.result(s.isLive(l.guest)));
764
- if (_.isFailure(d)) return E(503, { error: "store_unavailable" });
765
- if (!d.success) return E(403, { error: "credential_rejected" });
766
- let h = await g.runPromise(f({
767
- profile: l.profile,
768
- credential: o.credential,
763
+ let g = await C.runPromise(C.result(f.isLive(m.guest)));
764
+ if (w.isFailure(g)) return N(503, { error: "store_unavailable" });
765
+ if (!g.success) return N(403, { error: "credential_rejected" });
766
+ let _ = await C.runPromise(r({
767
+ profile: m.profile,
768
+ credential: d.credential,
769
769
  store: e.store,
770
- guest: B.guest,
771
- service: s,
772
- users: k.users,
773
- config: k.auth,
774
- ...B.configForTransaction ? { configForTransaction: B.configForTransaction } : {},
770
+ guest: G.guest,
771
+ service: f,
772
+ users: F.users,
773
+ config: F.auth,
774
+ ...G.configForTransaction ? { configForTransaction: G.configForTransaction } : {},
775
775
  ipAddress: e.remoteAddr ?? null,
776
776
  userAgent: e.headers["user-agent"] ?? null
777
777
  }));
778
- return h.kind === "refused" ? E(h.status, {
779
- error: h.code,
780
- message: h.message
778
+ return _.kind === "refused" ? N(_.status, {
779
+ error: _.code,
780
+ message: _.message
781
781
  }) : {
782
- ...E(200, {
782
+ ...N(200, {
783
783
  upgraded: !0,
784
- subject: h.subject
784
+ subject: _.subject
785
785
  }),
786
786
  headers: {
787
787
  "cache-control": "no-store",
788
- "set-cookie": [G(z), h.setCookie]
788
+ "set-cookie": [J(W), _.setCookie]
789
789
  }
790
790
  };
791
791
  }, Ke = async (e) => {
792
- let t = C(e.headers, S(k.auth))?.subject;
792
+ let t = A(e.headers, k(F.auth))?.subject;
793
793
  if (!e.store || t?.type !== "user" || t.kind === "guest" || typeof t.tenantId != "string" || typeof t.metadata?.sessionId != "string") return null;
794
794
  try {
795
- let n = await g.runPromise(_e(e.store).findSession(t.metadata.sessionId));
795
+ let n = await C.runPromise(ue(e.store).findSession(t.metadata.sessionId));
796
796
  if (!n || n.userId !== t.id || n.tenantId !== t.tenantId || !(n.expiresAt.getTime() > Date.now()) || n.rotatedAt !== null && n.rotatedAt !== void 0) return null;
797
- let r = await g.runPromise(k.users.findById(t.id));
797
+ let r = await C.runPromise(F.users.findById(t.id));
798
798
  return !r || r.tenantId !== t.tenantId ? null : {
799
799
  id: t.id,
800
800
  tenantId: t.tenantId,
@@ -804,102 +804,102 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
804
804
  return "unavailable";
805
805
  }
806
806
  }, qe = (e) => {
807
- let t = S(k.auth);
808
- return [t.current, t.previous].filter((e) => e !== void 0).some((t) => Se(e.headers[he], b(e.headers.cookie, x), t.secret));
807
+ let t = k(F.auth);
808
+ return [t.current, t.previous].filter((e) => e !== void 0).some((t) => he(e.headers[ce], D(e.headers.cookie, O), t.secret));
809
809
  }, Je = async (e) => {
810
- let t = e.path.slice((A + "/links").length).replace(/^\//, "");
810
+ let t = e.path.slice((I + "/links").length).replace(/^\//, "");
811
811
  if (t === "csrf") {
812
- if (e.method !== "GET") return E(405, { error: "method_not_allowed" });
813
- let t = S(k.auth), n = ye(t.current.secret);
812
+ if (e.method !== "GET") return N(405, { error: "method_not_allowed" });
813
+ let t = k(F.auth), n = fe(t.current.secret);
814
814
  return {
815
- ...E(200, { token: n }),
815
+ ...N(200, { token: n }),
816
816
  headers: {
817
817
  "cache-control": "no-store",
818
- "set-cookie": y(x, n, {
818
+ "set-cookie": E(O, n, {
819
819
  path: "/",
820
820
  httpOnly: !1,
821
- secure: N,
821
+ secure: z,
822
822
  sameSite: "lax",
823
- maxAgeSeconds: j,
824
- ...k.auth.cookieDomain ? { domain: k.auth.cookieDomain } : {}
823
+ maxAgeSeconds: L,
824
+ ...F.auth.cookieDomain ? { domain: F.auth.cookieDomain } : {}
825
825
  })
826
826
  }
827
827
  };
828
828
  }
829
829
  let n = await Ke(e);
830
- if (n === "unavailable") return Q(503, { error: "store_unavailable" });
831
- if (!n) return Q(401, { error: "credential_rejected" });
830
+ if (n === "unavailable") return $(503, { error: "store_unavailable" });
831
+ if (!n) return $(401, { error: "credential_rejected" });
832
832
  if (t === "") {
833
- if (e.method !== "GET") return E(405, { error: "method_not_allowed" });
834
- let t = await g.runPromise(Y(e).listForUser(n.id));
835
- return Q(200, { links: t.filter((e) => e.userId === n.id).map((e) => ({
833
+ if (e.method !== "GET") return N(405, { error: "method_not_allowed" });
834
+ let t = await C.runPromise(Z(e).listForUser(n.id));
835
+ return $(200, { links: t.filter((e) => e.userId === n.id).map((e) => ({
836
836
  provider: e.provider,
837
837
  connectedAt: e.createdAt.getTime(),
838
838
  lastUsedAt: e.lastLoginAt?.getTime() ?? null
839
839
  })) });
840
840
  }
841
841
  let [r, i, ...a] = t.split("/");
842
- if (!I(r) || a.length > 0 || i !== void 0 && i !== "remove") return E(404, { error: "not_found" });
843
- if (e.method !== "POST") return E(405, { error: "method_not_allowed" });
844
- if (!qe(e)) return E(403, { error: "csrf_rejected" });
842
+ if (!Oe(r) || a.length > 0 || i !== void 0 && i !== "remove") return N(404, { error: "not_found" });
843
+ if (e.method !== "POST") return N(405, { error: "method_not_allowed" });
844
+ if (!qe(e)) return N(403, { error: "csrf_rejected" });
845
845
  if (i === void 0) {
846
- let t = Z(e, r, void 0, void 0, {
846
+ let t = Le(e, r, void 0, void 0, {
847
847
  u: n.id,
848
848
  t: n.tenantId,
849
849
  sid: n.sessionId
850
850
  }), i = t.headers?.location;
851
851
  return t.status !== 302 || !i ? t : {
852
- ...E(200, { authorizationUrl: i }),
852
+ ...N(200, { authorizationUrl: i }),
853
853
  headers: {
854
854
  "cache-control": "no-store",
855
855
  "set-cookie": t.headers["set-cookie"]
856
856
  }
857
857
  };
858
858
  }
859
- let o = await g.runPromise(k.users.findById(n.id)), s = typeof o?.passwordHash == "string" && o.passwordHash.length > 0;
860
- if (k.identities === void 0) {
861
- if (!e.store) return Q(503, { error: "store_unavailable" });
859
+ let o = await C.runPromise(F.users.findById(n.id)), s = typeof o?.passwordHash == "string" && o.passwordHash.length > 0;
860
+ if (F.identities === void 0) {
861
+ if (!e.store) return $(503, { error: "store_unavailable" });
862
862
  let t = await e.store.transactional(async (e) => {
863
863
  let t = (await e.query({
864
- table: c,
865
- predicate: v("userId", n.id),
864
+ table: _,
865
+ predicate: T("userId", n.id),
866
866
  order: [],
867
867
  take: 64,
868
868
  skip: void 0,
869
869
  projection: void 0,
870
870
  lock: "update"
871
871
  })).filter((e) => e.userId === n.id), i = t.find((e) => e.provider === r);
872
- return i ? !s && t.length <= 1 ? "last_sign_in_method" : (await e.delete(c, String(i.id)), "removed") : "not_found";
872
+ return i ? !s && t.length <= 1 ? "last_sign_in_method" : (await e.delete(_, String(i.id)), "removed") : "not_found";
873
873
  });
874
- return t === "removed" ? Q(200, { removed: r }) : Q(t === "not_found" ? 404 : 409, { error: t });
874
+ return t === "removed" ? $(200, { removed: r }) : $(t === "not_found" ? 404 : 409, { error: t });
875
875
  }
876
- let l = await g.runPromise(Y(e).listForUser(n.id));
877
- return l.some((e) => e.provider === r) ? !s && l.length <= 1 ? Q(409, { error: "last_sign_in_method" }) : (await g.runPromise(Y(e).remove(n.id, r)), Q(200, { removed: r })) : Q(404, { error: "not_found" });
876
+ let c = await C.runPromise(Z(e).listForUser(n.id));
877
+ return c.some((e) => e.provider === r) ? !s && c.length <= 1 ? $(409, { error: "last_sign_in_method" }) : (await C.runPromise(Z(e).remove(n.id, r)), $(200, { removed: r })) : $(404, { error: "not_found" });
878
878
  }, Ye = {
879
879
  method: "*",
880
- path: A,
881
- handle: async (t) => {
882
- if (t.path === A + "/providers") return t.method === "GET" ? Q(200, { providers: [...Ne] }) : E(405, { error: "method_not_allowed" });
883
- if (t.path === A + "/links" || t.path.startsWith(A + "/links/")) try {
884
- return await Je(t);
885
- } catch (t) {
886
- if (t instanceof e) return X(t.status, t.code, t.message);
887
- throw t;
880
+ path: I,
881
+ handle: async (e) => {
882
+ if (e.path === I + "/providers") return e.method === "GET" ? $(200, { providers: [...De] }) : N(405, { error: "method_not_allowed" });
883
+ if (e.path === I + "/links" || e.path.startsWith(I + "/links/")) try {
884
+ return await Je(e);
885
+ } catch (e) {
886
+ if (e instanceof b) return Q(e.status, e.code, e.message);
887
+ throw e;
888
888
  }
889
- if (t.path.startsWith(A + "/platform/")) return We(t);
890
- if (t.path.startsWith(A + "/upgrade/")) try {
891
- return await Ge(t);
892
- } catch (t) {
893
- if (t instanceof e) return X(t.status, t.code, t.message);
894
- throw t;
889
+ if (e.path.startsWith(I + "/platform/")) return We(e);
890
+ if (e.path.startsWith(I + "/upgrade/")) try {
891
+ return await Ge(e);
892
+ } catch (e) {
893
+ if (e instanceof b) return Q(e.status, e.code, e.message);
894
+ throw e;
895
895
  }
896
- let n = Re(t.path);
897
- if (!n) return E(404, { error: "not_found" });
896
+ let t = Ie(e.path);
897
+ if (!t) return N(404, { error: "not_found" });
898
898
  try {
899
- return n.isCallback ? t.method !== "GET" && t.method !== "POST" ? E(405, { error: "method_not_allowed" }) : await Ve(t, n.id) : t.method === "GET" ? Z(t, n.id) : E(405, { error: "method_not_allowed" });
900
- } catch (t) {
901
- if (t instanceof e) return X(t.status, t.code, t.message);
902
- throw t;
899
+ return t.isCallback ? e.method !== "GET" && e.method !== "POST" ? N(405, { error: "method_not_allowed" }) : await Be(e, t.id) : e.method === "GET" ? Le(e, t.id) : N(405, { error: "method_not_allowed" });
900
+ } catch (e) {
901
+ if (e instanceof b) return Q(e.status, e.code, e.message);
902
+ throw e;
903
903
  }
904
904
  }
905
905
  }, Xe = [
@@ -913,65 +913,65 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
913
913
  "network:outbound:id.twitch.tv",
914
914
  "network:outbound:login.microsoftonline.com",
915
915
  "network:outbound:api.epicgames.dev",
916
- ...F === void 0 ? [] : ["network:outbound:steamcommunity.com"],
917
- ...[...L.values()].flatMap((e) => e.permissions)
916
+ ...V === void 0 ? [] : ["network:outbound:steamcommunity.com"],
917
+ ...[...H.values()].flatMap((e) => e.permissions)
918
918
  ], Ze = (e, t) => {
919
- let n = je[e];
919
+ let n = Te[e];
920
920
  return t === 0 ? n?.clientId !== void 0 : e === "apple" ? t === 1 ? n?.appleKey?.teamId !== void 0 : t === 2 ? n?.appleKey?.keyId !== void 0 : n?.appleKey?.privateKey !== void 0 : n?.clientSecret !== void 0;
921
- }, Qe = P.flatMap((e) => T[e].map((t, n) => ({
921
+ }, Qe = B.flatMap((e) => M[e].map((t, n) => ({
922
922
  name: t.name,
923
923
  required: !Ze(e, n),
924
924
  secret: t.secret,
925
925
  description: t.description
926
- }))), $e = k.auth.secret === void 0 && k.auth.secrets === void 0 ? [{
926
+ }))), $e = F.auth.secret === void 0 && F.auth.secrets === void 0 ? [{
927
927
  name: "VOLTRO_SESSION_SECRET",
928
928
  required: !0,
929
929
  secret: !0,
930
930
  generate: "base64url",
931
931
  description: "Project key for signed login handoffs and ordinary sessions."
932
932
  }] : [];
933
- return pe({
934
- name: k.name ? `@voltro/plugin-auth-social#${k.name}` : "@voltro/plugin-auth-social",
933
+ return oe({
934
+ name: F.name ? `@voltro/plugin-auth-social#${F.name}` : "@voltro/plugin-auth-social",
935
935
  description: "Social login — Google / GitHub / Apple / Discord / Twitch / Microsoft / Epic, and game sign-in with Steam / EOS / console tickets. Mandatory S256 + state, JWKS-verified ID tokens, a deliberate account-linking policy, and sessions issued through @voltro/plugin-auth.",
936
936
  permissions: Xe,
937
937
  declaredEnv: [
938
938
  ...Qe,
939
- ...[...L.values()].flatMap((e) => e.declaredEnv),
939
+ ...[...H.values()].flatMap((e) => e.declaredEnv),
940
940
  ...$e
941
941
  ],
942
- extendSchema: { tables: d },
942
+ extendSchema: { tables: y },
943
943
  httpRoutes: [Ye],
944
944
  subjectPrivacy: {
945
- tables: [c, s],
945
+ tables: [_, g],
946
946
  kinds: ["user"]
947
947
  },
948
948
  subjectMerge: {
949
- tables: [c, s],
949
+ tables: [_, g],
950
950
  kinds: ["guest"]
951
951
  },
952
- onMergeAccounts: (e) => g.promise(async () => {
952
+ onMergeAccounts: (e) => C.promise(async () => {
953
953
  let t = (t, n, r) => e.store.query({
954
954
  table: t,
955
- predicate: v(n, r),
955
+ predicate: T(n, r),
956
956
  order: [],
957
957
  take: void 0,
958
958
  skip: void 0,
959
959
  projection: void 0,
960
960
  lock: "update"
961
- }), n = new Set((await t(c, "userId", e.targetId)).map((e) => String(e.provider)));
962
- for (let r of await t(c, "userId", e.sourceId)) r.userId === e.sourceId && (n.has(String(r.provider)) ? await e.store.delete(c, String(r.id)) : (await e.store.update(c, String(r.id), { userId: e.targetId }), n.add(String(r.provider))));
961
+ }), n = new Set((await t(_, "userId", e.targetId)).map((e) => String(e.provider)));
962
+ for (let r of await t(_, "userId", e.sourceId)) r.userId === e.sourceId && (n.has(String(r.provider)) ? await e.store.delete(_, String(r.id)) : (await e.store.update(_, String(r.id), { userId: e.targetId }), n.add(String(r.provider))));
963
963
  }),
964
964
  bindDataStore: (e, t) => {
965
- if (J ??= e, F !== void 0 && U === void 0 && t?.hotStore !== void 0) {
965
+ if (X ??= e, V !== void 0 && Ae === void 0 && t?.hotStore !== void 0) {
966
966
  let e = t.hotStore;
967
- U = () => e();
967
+ Ae = () => e();
968
968
  }
969
- Pe ??= t?.accountMergeRegistry, Fe ??= t?.privacyRegistry, typeof w.users == "function" && O.current === void 0 && (O.current = w.users(t?.sql === void 0 ? { store: e } : {
969
+ Me ??= t?.accountMergeRegistry, Ne ??= t?.privacyRegistry, typeof j.users == "function" && Ce.current === void 0 && (Ce.current = j.users(t?.sql === void 0 ? { store: e } : {
970
970
  store: e,
971
971
  sql: t.sql
972
972
  }));
973
973
  },
974
- onExport: (e) => g.suspend(() => Ie().listForUser(e).pipe(g.flatMap((t) => g.map(Le(e), (n) => ({
974
+ onExport: (e) => C.suspend(() => Pe().listForUser(e).pipe(C.flatMap((t) => C.map(Fe(e), (n) => ({
975
975
  connections: t.filter((t) => t.userId === e).map((e) => ({
976
976
  provider: e.provider,
977
977
  email: e.email,
@@ -984,26 +984,26 @@ var Ce = "/auth/social", we = 600, Te = "voltro:oauth", T = {
984
984
  mergedAt: new Date(e.mergedAt).toISOString()
985
985
  }))
986
986
  }))))),
987
- onErase: (e) => g.suspend(() => {
988
- let t = Ie();
989
- return t.listForUser(e).pipe(g.flatMap((n) => g.forEach(n.filter((t) => t.userId === e), (n) => t.remove(e, n.provider), { discard: !0 })), g.andThen(g.flatMap(Le(e), (e) => g.promise(async () => {
990
- for (let t of e) await J.delete(s, String(t.id));
987
+ onErase: (e) => C.suspend(() => {
988
+ let t = Pe();
989
+ return t.listForUser(e).pipe(C.flatMap((n) => C.forEach(n.filter((t) => t.userId === e), (n) => t.remove(e, n.provider), { discard: !0 })), C.andThen(C.flatMap(Fe(e), (e) => C.promise(async () => {
990
+ for (let t of e) await X.delete(g, String(t.id));
991
991
  }))));
992
992
  }),
993
- onActivate: (e) => g.sync(() => {
994
- for (let e of P) K(e);
995
- for (let e of L.values()) e.check();
996
- let n = S(k.auth);
997
- if (xe({ exp: Math.floor(Date.now() / 1e3) + j }, n.current.secret, "social-login"), n.previous && n.previous.secret.length < 32) throw new t("socialAuthPlugin: previous project signing key is too short");
993
+ onActivate: (e) => C.sync(() => {
994
+ for (let e of B) je(e);
995
+ for (let e of H.values()) e.check();
996
+ let t = k(F.auth);
997
+ if (me({ exp: Math.floor(Date.now() / 1e3) + L }, t.current.secret, "social-login"), t.previous && t.previous.secret.length < 32) throw new x("socialAuthPlugin: previous project signing key is too short");
998
998
  e.logger.info("social auth active", {
999
- prefix: A,
1000
- providers: Ne.join(","),
1001
- platforms: [...L.keys()].join(","),
1002
- linkPolicy: Ae,
1003
- stateTtlSeconds: j
999
+ prefix: I,
1000
+ providers: De.join(","),
1001
+ platforms: [...H.keys()].join(","),
1002
+ linkPolicy: we,
1003
+ stateTtlSeconds: L
1004
1004
  });
1005
1005
  }),
1006
- onDeactivate: () => g.void
1006
+ onDeactivate: () => C.void
1007
1007
  });
1008
1008
  };
1009
- export { O as socialAuthPlugin };
1009
+ export { Ce as socialAuthPlugin };