@voltro/plugin-auth-social 0.89.2 → 0.91.0

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