@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/CHANGELOG.md +1943 -0
- package/README.md +4 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/accountMerge.js +149 -0
- package/dist/guestHandoff.js +12 -12
- package/dist/guestUpgrade.js +26 -26
- package/dist/identityStore.js +27 -18
- package/dist/index.d.ts +164 -5
- package/dist/index.js +18 -16
- package/dist/platformServices.js +80 -0
- package/dist/plugin.js +661 -392
- package/dist/providers.js +2 -2
- package/dist/signIn.js +16 -16
- package/dist/steam.js +49 -49
- package/dist/web/guestUpgradeClient.js +63 -38
- package/dist/web/linksClient.js +74 -0
- package/dist/web.d.ts +64 -4
- package/dist/web.js +3 -1
- package/package.json +6 -6
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: (
|
|
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
|
-
|
|
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;
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
1
|
+
import { socialAuthPlugin as e } from "./plugin.js";
|
|
2
|
+
import { socialBeginLogin as t } from "./login.js";
|
|
3
|
+
import { socialCompleteLogin as n } from "./callback.js";
|
|
4
|
+
import { completeSocialSignIn as r } from "./signIn.js";
|
|
5
|
+
import { decideSocialLink as i } from "./linking.js";
|
|
6
|
+
import { ACCOUNT_MERGE_TABLE as a, SOCIAL_IDENTITY_TABLE as o, SocialIdentityConflict as s, accountMergesTable as c, dataStoreSocialIdentityStore as l, linkSocialIdentity as u, memorySocialIdentityStore as d, socialAuthTables as f, socialIdentitiesTable as p } from "./identityStore.js";
|
|
7
|
+
import { APPLE_CLIENT_SECRET_DEFAULT_TTL_S as m, APPLE_CLIENT_SECRET_MAX_TTL_S as h, _resetAppleSecretCache as g, appleClientSecret as _, isApplePrivateRelayEmail as v, parseAppleUserPayload as y } from "./apple.js";
|
|
8
|
+
import { fetchGithubIdentity as b } from "./github.js";
|
|
9
|
+
import { fetchDiscordIdentity as x } from "./discord.js";
|
|
10
|
+
import { fetchEpicIdentity as S } from "./epic.js";
|
|
11
|
+
import { steamBeginOpenId as C, steamCompleteOpenId as w, verifySteamWebApiTicket as T } from "./steam.js";
|
|
12
|
+
import { PlatformServicesError as E, PlatformServicesPort as D, devPlatformServices as O, steamPlatformServices as k } from "./platformServices.js";
|
|
13
|
+
import { definePlatformLogin as A, eosPlatformLogin as j, steamPlatformLogin as M, verifyPlatformTicket as N } from "./platform.js";
|
|
14
|
+
import { completeGuestSocialUpgrade as P } from "./guestUpgrade.js";
|
|
15
|
+
import { completeGuestSocialMerge as F, guestMergeTarget as I } from "./accountMerge.js";
|
|
16
|
+
import { SOCIAL_PROVIDERS as L, SOCIAL_PROVIDER_IDS as R, isSocialProviderId as z, isSocialWebProviderId as B, socialProvider as V } from "./providers.js";
|
|
17
|
+
import { PlatformTicketError as H, SocialAccountLinkError as U, SocialAuthError as W, SocialConfigError as G, SocialExchangeError as K, SocialIdTokenError as q, SocialStateMismatchError as J } from "./errors.js";
|
|
18
|
+
export { a as ACCOUNT_MERGE_TABLE, m as APPLE_CLIENT_SECRET_DEFAULT_TTL_S, h as APPLE_CLIENT_SECRET_MAX_TTL_S, E as PlatformServicesError, D as PlatformServicesPort, H as PlatformTicketError, o as SOCIAL_IDENTITY_TABLE, L as SOCIAL_PROVIDERS, R as SOCIAL_PROVIDER_IDS, U as SocialAccountLinkError, W as SocialAuthError, G as SocialConfigError, K as SocialExchangeError, q as SocialIdTokenError, s as SocialIdentityConflict, J as SocialStateMismatchError, g as _resetAppleSecretCache, c as accountMergesTable, _ as appleClientSecret, F as completeGuestSocialMerge, P as completeGuestSocialUpgrade, r as completeSocialSignIn, l as dataStoreSocialIdentityStore, i as decideSocialLink, A as definePlatformLogin, O as devPlatformServices, j as eosPlatformLogin, x as fetchDiscordIdentity, S as fetchEpicIdentity, b as fetchGithubIdentity, I as guestMergeTarget, v as isApplePrivateRelayEmail, z as isSocialProviderId, B as isSocialWebProviderId, u as linkSocialIdentity, d as memorySocialIdentityStore, y as parseAppleUserPayload, e as socialAuthPlugin, f as socialAuthTables, t as socialBeginLogin, n as socialCompleteLogin, p as socialIdentitiesTable, V as socialProvider, C as steamBeginOpenId, w as steamCompleteOpenId, M as steamPlatformLogin, k as steamPlatformServices, N as verifyPlatformTicket, T as verifySteamWebApiTicket };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Context as e, Effect as t, Schema as n } from "effect";
|
|
2
|
+
// src/platformServices.ts
|
|
3
|
+
var r = class extends n.TaggedError()("PlatformServicesError", { code: n.Literals([
|
|
4
|
+
"invalid_input",
|
|
5
|
+
"unsupported",
|
|
6
|
+
"unavailable",
|
|
7
|
+
"rejected"
|
|
8
|
+
]) }) {}, i = (e) => new r({ code: e }), a = class extends e.Service()("@voltro/PlatformServicesPort") {}, o = (e, t) => {
|
|
9
|
+
if (typeof e != "string" || !e || e.length > t || e.includes("\0")) throw i("invalid_input");
|
|
10
|
+
return e;
|
|
11
|
+
}, s = (e) => ({
|
|
12
|
+
platform: o(e?.platform, 64),
|
|
13
|
+
platformAccountId: o(e?.platformAccountId, 64)
|
|
14
|
+
}), c = (e) => {
|
|
15
|
+
let t = e.details ?? {};
|
|
16
|
+
if (typeof t != "object" || Array.isArray(t) || Object.keys(t).length > 20) throw i("invalid_input");
|
|
17
|
+
return {
|
|
18
|
+
...s(e),
|
|
19
|
+
status: o(e.status, 256),
|
|
20
|
+
details: Object.freeze(Object.fromEntries(Object.entries(t).map(([e, t]) => [o(e, 64), o(t, 256)])))
|
|
21
|
+
};
|
|
22
|
+
}, l = (e) => t.try({
|
|
23
|
+
try: e,
|
|
24
|
+
catch: (e) => e instanceof r ? e : i("invalid_input")
|
|
25
|
+
}), u = (e = {}) => {
|
|
26
|
+
let n = e.max ?? 1e3, r = [];
|
|
27
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > 1e5) throw i("invalid_input");
|
|
28
|
+
let a = (e) => {
|
|
29
|
+
r.push(Object.freeze(e)), r.length > n && r.shift();
|
|
30
|
+
};
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
unlockAchievement: (e) => t.flatMap(l(() => ({
|
|
33
|
+
...s(e),
|
|
34
|
+
achievementId: o(e.achievementId, 128)
|
|
35
|
+
})), (e) => t.sync(() => a({
|
|
36
|
+
kind: "achievement",
|
|
37
|
+
...e
|
|
38
|
+
}))),
|
|
39
|
+
setPresence: (e) => t.flatMap(l(() => c(e)), (e) => t.sync(() => a({
|
|
40
|
+
kind: "presence",
|
|
41
|
+
...e
|
|
42
|
+
}))),
|
|
43
|
+
calls: () => Object.freeze([...r])
|
|
44
|
+
});
|
|
45
|
+
}, d = "https://partner.steam-api.com/ISteamUserStats/SetUserStatsForGame/v1/", f = (e) => {
|
|
46
|
+
let n = o(e?.appId, 32), a = o(e.publisherKey, 256), u = e.timeoutMs ?? 5e3;
|
|
47
|
+
if (!/^[0-9]+$/.test(n) || !Number.isSafeInteger(u) || u < 100 || u > 6e4) throw i("invalid_input");
|
|
48
|
+
let f = e.fetchImpl ?? fetch, p = e.endpoint ?? d, m = e.achievementName ?? ((e) => e);
|
|
49
|
+
return Object.freeze({
|
|
50
|
+
unlockAchievement: (e) => t.flatMap(l(() => {
|
|
51
|
+
let t = s(e);
|
|
52
|
+
if (t.platform !== "steam" || !/^[0-9]{17,20}$/.test(t.platformAccountId)) throw i("invalid_input");
|
|
53
|
+
return {
|
|
54
|
+
steamId: t.platformAccountId,
|
|
55
|
+
name: o(m(o(e.achievementId, 128)), 128)
|
|
56
|
+
};
|
|
57
|
+
}), ({ steamId: e, name: o }) => t.tryPromise({
|
|
58
|
+
try: async () => {
|
|
59
|
+
let t = new URLSearchParams({
|
|
60
|
+
key: a,
|
|
61
|
+
appid: n,
|
|
62
|
+
steamid: e,
|
|
63
|
+
count: "1",
|
|
64
|
+
"name[0]": o,
|
|
65
|
+
"value[0]": "1"
|
|
66
|
+
}), r = await f(p, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: t,
|
|
69
|
+
signal: AbortSignal.timeout(u),
|
|
70
|
+
headers: { "content-type": "application/x-www-form-urlencoded" }
|
|
71
|
+
});
|
|
72
|
+
if (await r.body?.cancel().catch(() => void 0), r.status === 401 || r.status === 403) throw i("rejected");
|
|
73
|
+
if (!r.ok) throw i("unavailable");
|
|
74
|
+
},
|
|
75
|
+
catch: (e) => e instanceof r ? e : i("unavailable")
|
|
76
|
+
})),
|
|
77
|
+
setPresence: (e) => t.flatMap(l(() => c(e)), () => t.fail(i("unsupported")))
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
export { r as PlatformServicesError, a as PlatformServicesPort, u as devPlatformServices, f as steamPlatformServices };
|