@voltro/plugin-auth-social 0.89.1 → 0.90.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/README.md CHANGED
@@ -25,6 +25,10 @@ Opt-in same-ID guest promotion, signed browser confirmation and the durable
25
25
  transaction/installed-port contract, confirmed device proof and recovery limits.
26
26
  Existing-account conflicts require a separately confirmed merge.
27
27
 
28
+ Sign in with Steam in the browser (`steam` option, OpenID with hot-store replay protection) and
29
+ `PlatformServicesPort` for platform achievements and rich presence (`devPlatformServices`,
30
+ `steamPlatformServices`) are built.
31
+
28
32
  ## License
29
33
 
30
34
  Proprietary. © 2026 Voltro UG. Your use is governed by the
@@ -0,0 +1,149 @@
1
+ import { ACCOUNT_MERGE_TABLE as e, dataStoreSocialIdentityStore as t } from "./identityStore.js";
2
+ import { transactionSessionStore as n } from "./guestUpgrade.js";
3
+ import { Effect as r, Result as i } from "effect";
4
+ import { and as a, classifyConstraintViolation as o, eq as s, extractDbCause as c, generateId as l } from "@voltro/database";
5
+ import { GuestAuthError as u, dataStoreGuestAuth as d, issueUserSession as f } from "@voltro/plugin-auth";
6
+ // src/accountMerge.ts
7
+ var p = /^[A-Za-z0-9_-]{1,128}$/, m = (e, t) => ({
8
+ table: e,
9
+ predicate: t,
10
+ order: [],
11
+ take: void 0,
12
+ skip: void 0,
13
+ projection: void 0
14
+ }), h = (e, t, n) => ({
15
+ kind: "refused",
16
+ status: e,
17
+ code: t,
18
+ message: n
19
+ }), g = class extends Error {
20
+ result;
21
+ constructor(e) {
22
+ super(e.code), this.result = e;
23
+ }
24
+ }, _ = (e) => ({
25
+ id: String(e.id),
26
+ tenantId: String(e.tenantId),
27
+ email: typeof e.email == "string" ? e.email : null,
28
+ passwordHash: typeof e.passwordHash == "string" ? e.passwordHash : null,
29
+ createdAt: e.createdAt instanceof Date ? e.createdAt : new Date(String(e.createdAt)),
30
+ mfaSecret: typeof e.mfaSecret == "string" ? e.mfaSecret : null,
31
+ mfaEnrolledAt: e.mfaEnrolledAt instanceof Date ? e.mfaEnrolledAt : null,
32
+ emailVerifiedAt: e.emailVerifiedAt instanceof Date ? e.emailVerifiedAt : null
33
+ }), v = (e, n) => r.gen(function* () {
34
+ let i = yield* t(e).findByProviderAccount(n.provider, n.providerAccountId);
35
+ if (i !== null) return {
36
+ kind: "provider",
37
+ targetId: i.userId
38
+ };
39
+ let a = n.email === null || n.email.length === 0 ? null : n.email;
40
+ return a !== null && (yield* r.promise(() => e.query(m("users", s("email", a))))).length !== 0 ? { kind: "email" } : { kind: "none" };
41
+ }), y = (v) => r.gen(function* () {
42
+ let y = v.guest.tenantId;
43
+ if (v.config.defaultTenantId !== y) return h(500, "config", "Account merge requires a matching tenant.");
44
+ if (!p.test(v.requestId)) return h(400, "invalid_input", "A merge needs a request ID.");
45
+ if (v.registry === void 0) return h(409, "account_merge_unavailable", "This app cannot merge accounts.");
46
+ let b = v.profile, x = yield* t(v.store).findByProviderAccount(b.provider, b.providerAccountId);
47
+ if (x === null) return h(409, "account_merge_unavailable", "Sign in to that account first; its address alone cannot confirm it.");
48
+ let S = x.userId, C = (e, t) => r.runPromise(f(_(t), n(e, v.users, y), v.config, {
49
+ clearLoginFailures: !1,
50
+ ipAddress: v.ipAddress ?? null,
51
+ userAgent: v.userAgent ?? null
52
+ })), w = (e, t, n, r) => ({
53
+ kind: "ok",
54
+ userId: S,
55
+ subject: e.subject,
56
+ setCookie: e.setCookie,
57
+ session: {
58
+ value: e.value,
59
+ expiresAt: e.expiresAt
60
+ },
61
+ created: !1,
62
+ linked: !0,
63
+ oneTimeName: null,
64
+ merged: {
65
+ requestId: v.requestId,
66
+ sourceId: t,
67
+ targetId: S,
68
+ participants: n,
69
+ replayed: r,
70
+ residueErased: !1
71
+ }
72
+ }), T = async (t) => {
73
+ if (t.kind !== "ok") return t;
74
+ let n = a(s("tenantId", y), s("requestId", v.requestId)), o = (await v.store.query(m(e, n)))[0];
75
+ if (o?.residueErasedAt !== null && o?.residueErasedAt !== void 0) return {
76
+ ...t,
77
+ merged: {
78
+ ...t.merged,
79
+ residueErased: !0
80
+ }
81
+ };
82
+ if (v.privacy === void 0) return t;
83
+ let c = await r.runPromise(r.result(v.privacy.eraseSubject({
84
+ requestId: "merge-" + v.requestId,
85
+ target: {
86
+ tenantId: y,
87
+ subjectId: t.merged.sourceId,
88
+ kind: "guest"
89
+ }
90
+ })));
91
+ return i.isFailure(c) || o === void 0 ? t : (await v.store.update(e, String(o.id), { residueErasedAt: /* @__PURE__ */ new Date() }), {
92
+ ...t,
93
+ merged: {
94
+ ...t.merged,
95
+ residueErased: !0
96
+ }
97
+ });
98
+ }, E;
99
+ return yield* r.tryPromise({
100
+ try: async () => {
101
+ let t = (await v.store.query(m(e, a(s("tenantId", y), s("requestId", v.requestId)))))[0];
102
+ if (t !== void 0) {
103
+ if (t.sourceId !== v.guestId || t.targetId !== S || t.tenantId !== y) throw new g(h(409, "merge_request_reused", "This request ID belongs to another merge."));
104
+ return await v.store.transactional(async (e) => {
105
+ let n = (await e.query(m("users", a(s("id", S), s("tenantId", y)))))[0];
106
+ if (!n || n.deactivatedAt !== null && n.deactivatedAt !== void 0) throw new g(h(403, "credential_rejected", "The account is not available."));
107
+ return w(await C(e, n), v.guestId, JSON.parse(String(t.participants)), !0);
108
+ });
109
+ }
110
+ let n = v.registry.coverage("guest");
111
+ if (n.missing.length > 0) throw new g(h(409, "merge_coverage_missing", "Not every part of this app can merge accounts yet: " + n.missing.join(", ")));
112
+ let f = v.service ?? d(v.store, v.guest);
113
+ return await r.runPromise(f.mergeInto(v.credential, S, async (t) => {
114
+ if (t.subjectId !== v.guestId || t.tenantId !== y) throw new u({ code: "credential_rejected" });
115
+ let n = t.store, d = await r.runPromise(r.result(v.registry.mergeInTransaction({
116
+ requestId: v.requestId,
117
+ tenantId: y,
118
+ sourceId: t.subjectId,
119
+ sourceKind: "guest",
120
+ targetId: S,
121
+ store: n
122
+ })));
123
+ if (i.isFailure(d)) throw E = d.failure, new u({ code: "store_unavailable" });
124
+ let f = d.success;
125
+ try {
126
+ await n.insert(e, {
127
+ id: l({
128
+ kind: "typeid",
129
+ prefix: "amerge"
130
+ }, "amerge"),
131
+ tenantId: y,
132
+ requestId: v.requestId,
133
+ sourceId: t.subjectId,
134
+ targetId: S,
135
+ participants: JSON.stringify(f),
136
+ mergedAt: /* @__PURE__ */ new Date()
137
+ });
138
+ } catch (e) {
139
+ throw o(c(e), "insert")?.kind === "unique" ? new u({ code: "upgrade_conflict" }) : e;
140
+ }
141
+ let p = (await n.query(m("users", a(s("id", S), s("tenantId", y)))))[0];
142
+ if (!p) throw new u({ code: "credential_rejected" });
143
+ return w(await C(n, p), t.subjectId, f, !1);
144
+ }));
145
+ },
146
+ catch: (e) => e
147
+ }).pipe(r.flatMap((e) => r.promise(() => T(e).catch(() => e))), r.catch((e) => r.succeed(E === void 0 ? e instanceof g ? e.result : e instanceof u ? e.code === "credential_rejected" ? h(403, "credential_rejected", "The guest account could not be confirmed.") : e.code === "upgrade_conflict" ? h(409, "merge_conflict", "The merge collided with another change; try again.") : h(503, "store_unavailable", "Account storage is unavailable.") : h(503, "store_unavailable", "Account storage is unavailable.") : h(409, "merge_failed", "A part of this app could not merge the accounts; nothing changed."))));
148
+ });
149
+ export { y as completeGuestSocialMerge, v as guestMergeTarget };
@@ -10,15 +10,32 @@ var u = (e, t, n) => ({
10
10
  take: void 0,
11
11
  skip: void 0,
12
12
  projection: void 0
13
- }), d = (d) => {
14
- if (d.config.defaultTenantId !== d.guest.tenantId || d.config.ensureActor !== void 0 && d.configForTransaction === void 0) return n.succeed({
13
+ }), d = (e, t, o) => ({
14
+ ...t,
15
+ ...s(e),
16
+ listMemberships: (t) => n.promise(async () => (await e.query({
17
+ ...u("memberships", "userId", t),
18
+ predicate: r(i("userId", t), i("tenantId", o))
19
+ })).map((e) => {
20
+ if (e.userId !== t || e.tenantId !== o || typeof e.role != "string") throw new a({ code: "store_unavailable" });
21
+ let n = e.joinedAt instanceof Date ? e.joinedAt : new Date(String(e.joinedAt));
22
+ if (!Number.isFinite(n.getTime())) throw new a({ code: "store_unavailable" });
23
+ return {
24
+ userId: t,
25
+ tenantId: o,
26
+ role: e.role,
27
+ joinedAt: n
28
+ };
29
+ }))
30
+ }), f = (s) => {
31
+ if (s.config.defaultTenantId !== s.guest.tenantId || s.config.ensureActor !== void 0 && s.configForTransaction === void 0) return n.succeed({
15
32
  kind: "refused",
16
33
  status: 500,
17
34
  code: "config",
18
35
  message: "Guest upgrade requires a matching tenant and transaction-bound actor hooks."
19
36
  });
20
- let f = d.profile, p = f.email === null || f.email.length === 0 ? null : f.email;
21
- return (d.service ?? o(d.store, d.guest)).upgrade(d.credential, async (o) => {
37
+ let f = s.profile, p = f.email === null || f.email.length === 0 ? null : f.email;
38
+ return (s.service ?? o(s.store, s.guest)).upgrade(s.credential, async (o) => {
22
39
  let m = o.store, h = t(m);
23
40
  if (await n.runPromise(h.findByProviderAccount(f.provider, f.providerAccountId)) !== null || p !== null && (await m.query(u("users", "email", p))).length !== 0) throw new a({ code: "upgrade_conflict" });
24
41
  let g = {
@@ -30,7 +47,7 @@ var u = (e, t, n) => ({
30
47
  mfaSecret: null,
31
48
  mfaEnrolledAt: null,
32
49
  emailVerifiedAt: p !== null && f.emailVerified ? /* @__PURE__ */ new Date() : null
33
- }, _ = d.configForTransaction?.(m) ?? d.config;
50
+ }, _ = s.configForTransaction?.(m) ?? s.config;
34
51
  if (_.defaultTenantId !== o.tenantId || !(await n.runPromise(l(_.subjectGuards ?? [], g))).ok) throw new a({ code: "credential_rejected" });
35
52
  if (await m.insert("users", {
36
53
  ...g,
@@ -42,27 +59,10 @@ var u = (e, t, n) => ({
42
59
  email: p,
43
60
  emailVerified: p !== null && f.emailVerified
44
61
  }).pipe(n.as(!0), n.catchTag("SocialIdentityConflict", () => n.succeed(!1))))) throw new a({ code: "upgrade_conflict" });
45
- let v = {
46
- ...d.users,
47
- ...s(m),
48
- listMemberships: (e) => n.promise(async () => (await m.query({
49
- ...u("memberships", "userId", e),
50
- predicate: r(i("userId", e), i("tenantId", o.tenantId))
51
- })).map((t) => {
52
- if (t.userId !== e || t.tenantId !== o.tenantId || typeof t.role != "string") throw new a({ code: "store_unavailable" });
53
- let n = t.joinedAt instanceof Date ? t.joinedAt : new Date(String(t.joinedAt));
54
- if (!Number.isFinite(n.getTime())) throw new a({ code: "store_unavailable" });
55
- return {
56
- userId: e,
57
- tenantId: o.tenantId,
58
- role: t.role,
59
- joinedAt: n
60
- };
61
- }))
62
- }, y = await n.runPromise(c(g, v, _, {
62
+ let v = d(m, s.users, o.tenantId), y = await n.runPromise(c(g, v, _, {
63
63
  clearLoginFailures: !1,
64
- ipAddress: d.ipAddress ?? null,
65
- userAgent: d.userAgent ?? null
64
+ ipAddress: s.ipAddress ?? null,
65
+ userAgent: s.userAgent ?? null
66
66
  })), b = y.subject.type === "user" ? y.subject.metadata?.sessionId : null;
67
67
  if (typeof b != "string" || (await m.query(u("sessions", "id", b))).length !== 1) throw new a({ code: "store_unavailable" });
68
68
  let x = (await m.query({
@@ -93,4 +93,4 @@ var u = (e, t, n) => ({
93
93
  message: e.code === "upgrade_conflict" ? "The provider or email belongs to an existing account. Confirm both accounts before merging." : e.code === "credential_rejected" ? "Guest upgrade was refused." : "Guest upgrade storage is unavailable."
94
94
  })));
95
95
  };
96
- export { d as completeGuestSocialUpgrade };
96
+ export { f as completeGuestSocialUpgrade, d as transactionSessionStore };
@@ -10,18 +10,27 @@ var f = "_voltro_oauth_identities", p = l(f, {
10
10
  emailVerified: r().default(!1),
11
11
  createdAt: d().default("now"),
12
12
  lastLoginAt: d().nullable()
13
- }).unique("byOauthProviderAccount", ["provider", "providerAccountId"]).index(["userId"]), m = [p], h = class extends e.TaggedError("SocialIdentityConflict") {}, g = (e) => typeof e == "object" && !!e && e._tag === "ConstraintViolation" && e.kind === "unique" || i(o(e), "insert")?.kind === "unique", _ = () => s({
13
+ }).unique("byOauthProviderAccount", ["provider", "providerAccountId"]).index(["userId"]), m = "_voltro_account_merges", h = l(m, {
14
+ id: c({ prefix: "amerge" }),
15
+ tenantId: u(),
16
+ requestId: u(),
17
+ sourceId: u(),
18
+ targetId: u(),
19
+ participants: u(),
20
+ mergedAt: d().default("now"),
21
+ residueErasedAt: d().nullable()
22
+ }).unique("byAccountMergeRequest", ["tenantId", "requestId"]).index(["targetId"]), g = [p, h], _ = class extends e.TaggedError("SocialIdentityConflict") {}, v = (e) => typeof e == "object" && !!e && e._tag === "ConstraintViolation" && e.kind === "unique" || i(o(e), "insert")?.kind === "unique", y = () => s({
14
23
  kind: "typeid",
15
24
  prefix: "oauthid"
16
- }, "oauthid"), v = (e = []) => {
25
+ }, "oauthid"), b = (e = []) => {
17
26
  let n = [...e];
18
27
  return {
19
28
  findByProviderAccount: (e, r) => t.sync(() => n.find((t) => t.provider === e && t.providerAccountId === r) ?? null),
20
29
  listForUser: (e) => t.sync(() => n.filter((t) => t.userId === e)),
21
- insert: (e) => n.some((t) => t.provider === e.provider && t.providerAccountId === e.providerAccountId) ? t.fail(new h({ provider: e.provider })) : t.sync(() => {
30
+ insert: (e) => n.some((t) => t.provider === e.provider && t.providerAccountId === e.providerAccountId) ? t.fail(new _({ provider: e.provider })) : t.sync(() => {
22
31
  let t = {
23
32
  ...e,
24
- id: _(),
33
+ id: y(),
25
34
  createdAt: /* @__PURE__ */ new Date(),
26
35
  lastLoginAt: null
27
36
  };
@@ -39,23 +48,23 @@ var f = "_voltro_oauth_identities", p = l(f, {
39
48
  return t < 0 ? !1 : (n.splice(t, 1), !0);
40
49
  })
41
50
  };
42
- }, y = (e) => {
51
+ }, x = (e) => {
43
52
  if (e instanceof Date) return e;
44
53
  if (typeof e == "string" || typeof e == "number") {
45
54
  let t = new Date(e);
46
55
  return Number.isNaN(t.getTime()) ? null : t;
47
56
  }
48
57
  return null;
49
- }, b = (e) => ({
58
+ }, S = (e) => ({
50
59
  id: String(e.id ?? ""),
51
60
  userId: String(e.userId ?? ""),
52
61
  provider: String(e.provider ?? ""),
53
62
  providerAccountId: String(e.providerAccountId ?? ""),
54
63
  email: typeof e.email == "string" && e.email.length > 0 ? e.email : null,
55
64
  emailVerified: e.emailVerified === !0 || e.emailVerified === 1,
56
- createdAt: y(e.createdAt) ?? /* @__PURE__ */ new Date(0),
57
- lastLoginAt: y(e.lastLoginAt)
58
- }), x = (e) => ({
65
+ createdAt: x(e.createdAt) ?? /* @__PURE__ */ new Date(0),
66
+ lastLoginAt: x(e.lastLoginAt)
67
+ }), C = (e) => ({
59
68
  findByProviderAccount: (r, i) => t.promise(async () => {
60
69
  let t = (await e.query({
61
70
  table: f,
@@ -66,7 +75,7 @@ var f = "_voltro_oauth_identities", p = l(f, {
66
75
  projection: void 0,
67
76
  order: []
68
77
  }))[0];
69
- return t ? b(t) : null;
78
+ return t ? S(t) : null;
70
79
  }),
71
80
  listForUser: (n) => t.promise(async () => (await e.query({
72
81
  table: f,
@@ -78,11 +87,11 @@ var f = "_voltro_oauth_identities", p = l(f, {
78
87
  take: void 0,
79
88
  skip: void 0,
80
89
  projection: void 0
81
- })).map(b)),
90
+ })).map(S)),
82
91
  insert: (n) => t.tryPromise({
83
92
  try: async () => {
84
93
  let t = {
85
- id: _(),
94
+ id: y(),
86
95
  userId: n.userId,
87
96
  provider: n.provider,
88
97
  providerAccountId: n.providerAccountId,
@@ -91,13 +100,13 @@ var f = "_voltro_oauth_identities", p = l(f, {
91
100
  createdAt: /* @__PURE__ */ new Date(),
92
101
  lastLoginAt: null
93
102
  };
94
- if (!("insertIgnoreWithOutcome" in e) || e.insertIgnoreWithOutcome === void 0) return b(await e.insert(f, t));
103
+ if (!("insertIgnoreWithOutcome" in e) || e.insertIgnoreWithOutcome === void 0) return S(await e.insert(f, t));
95
104
  let r = await e.insertIgnoreWithOutcome(f, t, { conflictColumns: ["provider", "providerAccountId"] });
96
- if (r.outcome === "ignored") throw new h({ provider: n.provider });
97
- return b(r.row);
105
+ if (r.outcome === "ignored") throw new _({ provider: n.provider });
106
+ return S(r.row);
98
107
  },
99
108
  catch: (e) => e
100
- }).pipe(t.catch((e) => e instanceof h || g(e) ? t.fail(new h({ provider: n.provider })) : t.die(e))),
109
+ }).pipe(t.catch((e) => e instanceof _ || v(e) ? t.fail(new _({ provider: n.provider })) : t.die(e))),
101
110
  touch: (n, r) => t.promise(async () => {
102
111
  await e.update(f, n, { lastLoginAt: r });
103
112
  }),
@@ -113,11 +122,11 @@ var f = "_voltro_oauth_identities", p = l(f, {
113
122
  }))[0];
114
123
  return t ? e.delete(f, String(t.id ?? "")) : !1;
115
124
  })
116
- }), S = (e, n, r) => t.gen(function* () {
125
+ }), w = (e, n, r) => t.gen(function* () {
117
126
  let i = yield* e.findByProviderAccount(r.provider, r.providerAccountId);
118
127
  return i ? i.userId === n ? i : yield* t.fail(/* @__PURE__ */ Error(`linkSocialIdentity: this ${r.provider} account is already linked to another user`)) : yield* e.insert({
119
128
  ...r,
120
129
  userId: n
121
130
  });
122
131
  });
123
- export { f as SOCIAL_IDENTITY_TABLE, h as SocialIdentityConflict, x as dataStoreSocialIdentityStore, S as linkSocialIdentity, v as memorySocialIdentityStore, m as socialAuthTables, p as socialIdentitiesTable };
132
+ export { m as ACCOUNT_MERGE_TABLE, f as SOCIAL_IDENTITY_TABLE, _ as SocialIdentityConflict, h as accountMergesTable, C as dataStoreSocialIdentityStore, w as linkSocialIdentity, b as memorySocialIdentityStore, g as socialAuthTables, p as socialIdentitiesTable };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,34 @@
1
1
  import { AuthConfig } from '@voltro/plugin-auth';
2
+ import { Context } from 'effect';
2
3
  import { DataStore } from '@voltro/database';
3
4
  import { Effect } from 'effect';
4
5
  import { GuestAuthOptions } from '@voltro/plugin-auth';
5
6
  import { GuestAuthService } from '@voltro/plugin-auth';
6
7
  import { HotStoreShape } from '@voltro/kv/hot';
8
+ import { PluginAccountMergeRegistry } from '@voltro/protocol';
7
9
  import { PluginEnvVar } from '@voltro/protocol';
8
10
  import { PluginPermission } from '@voltro/protocol';
11
+ import { PluginPrivacyRegistry } from '@voltro/protocol';
9
12
  import { Predicate } from '@voltro/database';
13
+ import { Schema } from 'effect';
10
14
  import { Subject } from '@voltro/protocol';
11
15
  import { TableLike } from '@voltro/database';
12
16
  import { UserStore } from '@voltro/plugin-auth';
17
+ import { UserStoreResolver } from '@voltro/plugin-auth';
13
18
  import { VoidIfEmpty } from 'effect/Types';
14
19
  import { VoltroPlugin } from '@voltro/protocol';
15
20
  import { YieldableError } from 'effect/Cause';
16
21
 
22
+ export declare const ACCOUNT_MERGE_TABLE = "_voltro_account_merges";
23
+
24
+ /**
25
+ * One row per completed guest-into-account merge: the receipt a retried request
26
+ * finds when its first reply was lost. It names the merged guest and the account
27
+ * it went into; the guest no longer exists afterwards, so the row belongs to the
28
+ * target account (exported with it, erased with it).
29
+ */
30
+ export declare const accountMergesTable: TableLike;
31
+
17
32
  /** Default lifetime we mint. Minutes, not months — see the header. */
18
33
  export declare const APPLE_CLIENT_SECRET_DEFAULT_TTL_S = 900;
19
34
 
@@ -56,6 +71,8 @@ export declare interface AppleUserPayload {
56
71
  readonly email: string | null;
57
72
  }
58
73
 
74
+ export declare const completeGuestSocialMerge: (options: GuestSocialMergeOptions) => Effect.Effect<GuestSocialMergeResult>;
75
+
59
76
  /** Preserve the guest subject ID. Conflict with any existing local email or
60
77
  * provider link refuses with merge-required; this function never merges or
61
78
  * moves another account automatically. A provider account without an address
@@ -95,6 +112,13 @@ export declare const decideSocialLink: (input: SocialLinkInput) => SocialLinkDec
95
112
  */
96
113
  export declare const definePlatformLogin: (definition: PlatformLoginDefinition) => PlatformLogin;
97
114
 
115
+ /** Development stub: accepts every valid call and records it (newest last, at most `max`). */
116
+ export declare const devPlatformServices: (options?: {
117
+ readonly max?: number;
118
+ }) => PlatformServicesService & {
119
+ readonly calls: () => ReadonlyArray<PlatformServicesCall>;
120
+ };
121
+
98
122
  /** The authenticated Discord user, without an access token or arbitrary API
99
123
  * payload. Discord snowflakes remain strings; number coercion loses bits. */
100
124
  export declare interface DiscordIdentity {
@@ -172,6 +196,49 @@ export declare interface GithubIdentity {
172
196
  readonly emailVerified: boolean;
173
197
  }
174
198
 
199
+ /** Which account a merge would go into, or why it cannot: for the confirmation page. */
200
+ export declare const guestMergeTarget: (store: DataStore, profile: SocialProfile) => Effect.Effect<{
201
+ readonly kind: "provider";
202
+ readonly targetId: string;
203
+ } | {
204
+ readonly kind: "email";
205
+ } | {
206
+ readonly kind: "none";
207
+ }>;
208
+
209
+ export declare interface GuestSocialMergeOptions {
210
+ /** Verified server-side provider result from the sealed upgrade handoff. */
211
+ readonly profile: SocialProfile;
212
+ /** The guest's device credential; proves the source account. */
213
+ readonly credential: string;
214
+ /** The guest the handoff was sealed for; the credential must belong to it. */
215
+ readonly guestId: string;
216
+ /** Caller idempotency key, 1–128 characters `[A-Za-z0-9_-]`. */
217
+ readonly requestId: string;
218
+ readonly store: DataStore;
219
+ readonly guest: GuestAuthOptions;
220
+ readonly service?: GuestAuthService;
221
+ readonly users: UserStore;
222
+ readonly config: AuthConfig;
223
+ readonly registry: PluginAccountMergeRegistry | undefined;
224
+ /** The app's privacy registry: after the merge commits, whatever no plugin moved and that still
225
+ * names the guest (finished Room records, for example) is erased as in a privacy erasure. */
226
+ readonly privacy?: PluginPrivacyRegistry | undefined;
227
+ readonly ipAddress?: string | null;
228
+ readonly userAgent?: string | null;
229
+ }
230
+
231
+ export declare type GuestSocialMergeResult = (SocialSignInOk & {
232
+ readonly merged: {
233
+ readonly requestId: string;
234
+ readonly sourceId: string;
235
+ readonly targetId: string;
236
+ readonly participants: ReadonlyArray<string>;
237
+ readonly replayed: boolean;
238
+ readonly residueErased: boolean;
239
+ };
240
+ }) | SocialSignInRefused;
241
+
175
242
  export declare interface GuestSocialUpgradeOptions {
176
243
  /** Verified server-side provider result, never a client-submitted profile. */
177
244
  readonly profile: SocialProfile;
@@ -198,6 +265,8 @@ export declare const isApplePrivateRelayEmail: (email: string | null) => boolean
198
265
  /** Narrow an arbitrary string to a shipped provider id. */
199
266
  export declare const isSocialProviderId: (value: string) => value is SocialProviderId;
200
267
 
268
+ export declare const isSocialWebProviderId: (value: string) => value is SocialWebProviderId;
269
+
201
270
  /**
202
271
  * Attach a provider account to a user you have ALREADY authenticated.
203
272
  *
@@ -238,6 +307,10 @@ export declare interface PlatformAccount {
238
307
  readonly accountId: string;
239
308
  }
240
309
 
310
+ export declare interface PlatformAchievementInput extends PlatformServiceAccount {
311
+ readonly achievementId: string;
312
+ }
313
+
241
314
  /** One platform a game can sign in with. Build one with {@link steamPlatformLogin},
242
315
  * {@link eosPlatformLogin} or {@link definePlatformLogin}. */
243
316
  export declare interface PlatformLogin {
@@ -260,6 +333,49 @@ export declare interface PlatformLoginDefinition {
260
333
  readonly check?: () => void;
261
334
  }
262
335
 
336
+ export declare interface PlatformPresenceInput extends PlatformServiceAccount {
337
+ /** Short status key the platform shows (Steam: a `#token` of the game's rich presence localization). */
338
+ readonly status: string;
339
+ readonly details?: Readonly<Record<string, string>> | undefined;
340
+ }
341
+
342
+ export declare interface PlatformServiceAccount {
343
+ /** The platform login id (`steam`). */
344
+ readonly platform: string;
345
+ /** The player's account on that platform (a SteamID64 for Steam). */
346
+ readonly platformAccountId: string;
347
+ }
348
+
349
+ export declare type PlatformServicesCall = {
350
+ readonly kind: 'achievement';
351
+ readonly platform: string;
352
+ readonly platformAccountId: string;
353
+ readonly achievementId: string;
354
+ } | {
355
+ readonly kind: 'presence';
356
+ readonly platform: string;
357
+ readonly platformAccountId: string;
358
+ readonly status: string;
359
+ readonly details: Readonly<Record<string, string>>;
360
+ };
361
+
362
+ export declare class PlatformServicesError extends PlatformServicesError_base {
363
+ }
364
+
365
+ declare const PlatformServicesError_base: Schema.Class<PlatformServicesError, Schema.TaggedStruct<"PlatformServicesError", {
366
+ readonly code: Schema.Literals<readonly ["invalid_input", "unsupported", "unavailable", "rejected"]>;
367
+ }>, YieldableError>;
368
+
369
+ export declare class PlatformServicesPort extends PlatformServicesPort_base {
370
+ }
371
+
372
+ declare const PlatformServicesPort_base: Context.ServiceClass<PlatformServicesPort, "@voltro/PlatformServicesPort", PlatformServicesService>;
373
+
374
+ export declare interface PlatformServicesService {
375
+ readonly unlockAchievement: (input: PlatformAchievementInput) => Effect.Effect<void, PlatformServicesError>;
376
+ readonly setPresence: (input: PlatformPresenceInput) => Effect.Effect<void, PlatformServicesError>;
377
+ }
378
+
263
379
  /** The platform refused a game client's sign-in ticket. One class for every
264
380
  * reason, for the same reason as {@link SocialIdTokenError}: the caller must
265
381
  * refuse the sign-in either way, and the `message` says which check failed. */
@@ -333,11 +449,15 @@ export declare type SocialAuthErrorCode =
333
449
  * another app or deployment). */
334
450
  | 'ticket_rejected';
335
451
 
336
- export declare const socialAuthPlugin: (options: SocialAuthPluginOptions) => VoltroPlugin;
452
+ export declare const socialAuthPlugin: (input: SocialAuthPluginOptions) => VoltroPlugin;
337
453
 
338
454
  export declare interface SocialAuthPluginOptions {
455
+ /** Steam sign-in in the browser; see {@link SocialSteamWebOptions}. */
456
+ readonly steam?: SocialSteamWebOptions;
339
457
  /** Which providers this app offers. A key with an empty object takes every
340
- * credential from the environment. */
458
+ * credential from the environment. With no provider, platform or `steam`, the
459
+ * plugin still declares its tables and keeps linked identities in the account's
460
+ * export, erasure and merge; it offers no sign-in. */
341
461
  readonly providers?: Partial<Record<SocialProviderId, SocialProviderConfig>>;
342
462
  /**
343
463
  * Platforms a game client signs in with by ticket: `steamPlatformLogin()`,
@@ -346,8 +466,9 @@ export declare interface SocialAuthPluginOptions {
346
466
  * `POST {prefix}/platform/{id}/link`. A platform account needs no email.
347
467
  */
348
468
  readonly platforms?: ReadonlyArray<PlatformLogin>;
349
- /** The same user store `authRoutesPlugin` runs on. */
350
- readonly users: UserStore;
469
+ /** The same user store `authRoutesPlugin` runs on: a `UserStore`, or the same resolver
470
+ * (e.g. `appUserStore()`), which binds to the app database at boot. */
471
+ readonly users: UserStore | UserStoreResolver;
351
472
  /**
352
473
  * Where identities are recorded. Omit and the plugin builds a
353
474
  * DataStore-backed store over the route's boot store — which needs
@@ -371,6 +492,10 @@ export declare interface SocialAuthPluginOptions {
371
492
  /** Where to send the browser after a successful login. Falls back to
372
493
  * `auth.successRedirect`, then `/`. */
373
494
  readonly successRedirect?: string;
495
+ /** Where to send the browser after connecting a provider to the signed-in account
496
+ * (`POST {prefix}/links/<provider>`). `?social_linked=<provider>` is appended. Falls back to
497
+ * `successRedirect`. */
498
+ readonly linkRedirect?: string;
374
499
  /**
375
500
  * Where to send the browser after a REFUSED login. When set, the refusal's
376
501
  * stable `code` is appended as `?social_error=<code>` so the page can explain
@@ -390,7 +515,7 @@ export declare interface SocialAuthPluginOptions {
390
515
  }
391
516
 
392
517
  /** The tables this package contributes, as an array. */
393
- export declare const socialAuthTables: readonly [TableLike];
518
+ export declare const socialAuthTables: readonly [TableLike, TableLike];
394
519
 
395
520
  /**
396
521
  * Begin a social login: mint `state`, a PKCE `code_verifier` and an OIDC
@@ -857,6 +982,25 @@ export declare class SocialStateMismatchError extends SocialAuthError {
857
982
  constructor(message: string);
858
983
  }
859
984
 
985
+ /** Sign in with Steam in the browser (OpenID 2.0, `GET {prefix}/steam`). Steam answers no
986
+ * email: the Steam account alone is the identity, the same one `steamPlatformLogin` uses. */
987
+ declare interface SocialSteamWebOptions {
988
+ /** OpenID realm Steam shows the player; default the app's origin. */
989
+ readonly realm?: string;
990
+ /** Replay protection for Steam's one-time answers. Default: the app's hot store. */
991
+ readonly hotStore?: HotStoreShape;
992
+ /** True when more than one API process signs players in: the hot store must be cross-node (Redis). */
993
+ readonly multiNode?: boolean;
994
+ /** How long Steam may take to confirm a sign-in. Default 5000 ms. */
995
+ readonly timeoutMs?: number;
996
+ /** Loopback fixture only (tests); the asserted OpenID provider stays pinned to Steam. */
997
+ readonly verificationUrl?: string;
998
+ readonly fetchImpl?: typeof fetch;
999
+ }
1000
+
1001
+ /** A provider a browser can sign in with: the OAuth providers plus Steam (OpenID 2.0, `steam` in `socialAuthPlugin`). */
1002
+ export declare type SocialWebProviderId = SocialProviderId | 'steam';
1003
+
860
1004
  /** Steam OpenID 2.0 does not use OAuth PKCE. State is server minted and bound
861
1005
  * into the exact return_to which Steam signs. Persist this handoff securely. */
862
1006
  export declare const steamBeginOpenId: (options: {
@@ -918,6 +1062,21 @@ export declare interface SteamPlatformLoginOptions {
918
1062
  readonly fetchImpl?: typeof fetch;
919
1063
  }
920
1064
 
1065
+ /** Unlocks Steam achievements with `ISteamUserStats/SetUserStatsForGame` (publisher key). */
1066
+ export declare const steamPlatformServices: (options: SteamPlatformServicesOptions) => PlatformServicesService;
1067
+
1068
+ export declare interface SteamPlatformServicesOptions {
1069
+ readonly appId: string;
1070
+ /** Steamworks publisher Web API key (server only). */
1071
+ readonly publisherKey: string;
1072
+ /** Steam achievements are stats-backed: map a game achievement id to its Steam API name (default: the same id). */
1073
+ readonly achievementName?: ((achievementId: string) => string) | undefined;
1074
+ readonly fetchImpl?: typeof fetch;
1075
+ readonly timeoutMs?: number;
1076
+ /** Loopback fixture only. */
1077
+ readonly endpoint?: string;
1078
+ }
1079
+
921
1080
  export declare interface SteamWebApiTicketOptions {
922
1081
  readonly ticket: string;
923
1082
  readonly appId: number;