@hadoku/prefs-client 1.1.22 → 1.1.23

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.
@@ -0,0 +1,131 @@
1
+ import { A as AvatarCosmetics, a as CosmeticsView } from './cosmetics-contract-CKe1lNNV.js';
2
+
3
+ /**
4
+ * Avatars — the wire contract, shared by prefs-api and the client.
5
+ *
6
+ * Pure: no fetch, no DOM. prefs-api imports this file directly (as it does
7
+ * games-contract.ts), so the server answers in the very types the client is
8
+ * built from. The client half lives in ./avatar.ts.
9
+ *
10
+ * Design: hadoku_site docs/planning/avatars-2026-10-30.md
11
+ */
12
+
13
+ declare const AVATAR_SOURCES: readonly ["sprite", "discord", "steam", "upload"];
14
+ type AvatarSource = (typeof AVATAR_SOURCES)[number];
15
+ declare const LINK_PROVIDERS: readonly ["discord", "steam"];
16
+ type LinkProvider = (typeof LINK_PROVIDERS)[number];
17
+ /**
18
+ * The one avatar every app renders for a user.
19
+ *
20
+ * - `source` is what the picture is. `'sprite'` means the character is the
21
+ * picture; any other source carries `url`.
22
+ * - `url` (present exactly when `source` is not `'sprite'`) is an absolute
23
+ * https image URL, square, at least 184px, on a host the hadoku.me CSP admits.
24
+ * Render it as an `<img>`; never fetch it server-side.
25
+ * - `sprite` is the person's character (a watchparty character id) whenever
26
+ * they have one, WHATEVER the source: games use it as the piece and the
27
+ * name colour even when the picture is a Discord avatar. Absent = never
28
+ * picked; use your own default. The app that owns the art (watchparty, its
29
+ * public GET /watchparty/api/characters) owns its URL and revision.
30
+ *
31
+ * A source that stops being available (an unlink, an admin removal, an account
32
+ * whose custom avatar was removed) resolves to `sprite` with no action from the app.
33
+ */
34
+ interface ResolvedAvatar {
35
+ source: AvatarSource;
36
+ url?: string;
37
+ sprite?: string;
38
+ /**
39
+ * What the person wears (effect, gradient, font, overlay, message reveal,
40
+ * and the overlay's placement): only items they own. Absent when nothing is
41
+ * worn. Render it with `@wolffm/prefs-client/cosmetics`.
42
+ */
43
+ cosmetics?: AvatarCosmetics;
44
+ }
45
+ /** PUT /api/v1/_avatar — either or both. */
46
+ interface AvatarUpdate {
47
+ source?: AvatarSource;
48
+ /** A watchparty character id (SPRITE_ID_PATTERN). */
49
+ sprite?: string;
50
+ }
51
+ /** What the callback page posts to the window that opened it (same origin only). */
52
+ declare const LINK_MESSAGE_TYPE = "hadoku-avatar-link";
53
+ type LinkMessage = {
54
+ type: typeof LINK_MESSAGE_TYPE;
55
+ ok: true;
56
+ provider: LinkProvider;
57
+ } | {
58
+ type: typeof LINK_MESSAGE_TYPE;
59
+ ok: false;
60
+ error: string;
61
+ };
62
+ /** A linked account as its owner sees it. Never carries a token. */
63
+ interface LinkedAccountView {
64
+ /** null when the account has no custom avatar. */
65
+ avatarUrl: string | null;
66
+ linkedAt: number;
67
+ refreshedAt: number;
68
+ }
69
+ interface UploadView {
70
+ url: string;
71
+ width: number;
72
+ height: number;
73
+ uploadedAt: number;
74
+ }
75
+ /** GET /api/v1/_avatar — the caller's own avatar settings. */
76
+ interface AvatarSettings {
77
+ avatar: ResolvedAvatar;
78
+ /** What the user picked; null = never picked (resolves to sprite). */
79
+ choice: AvatarSource | null;
80
+ sprite: string | null;
81
+ linked: Partial<Record<LinkProvider, LinkedAccountView>>;
82
+ upload: UploadView | null;
83
+ /** Whether each provider is configured on the server. A false one cannot be linked yet. */
84
+ providers: Record<LinkProvider, boolean>;
85
+ limits: AvatarUploadLimits;
86
+ /** What the owner has earned and what they wear. */
87
+ cosmetics: CosmeticsView;
88
+ }
89
+ interface AvatarUploadLimits {
90
+ maxBytes: number;
91
+ minDimension: number;
92
+ maxDimension: number;
93
+ acceptedTypes: readonly string[];
94
+ /** Accepted uploads per user per rolling 24h. */
95
+ perDay: number;
96
+ /** Edge length of the stored square, in px. */
97
+ outputSize: number;
98
+ }
99
+ /** POST /api/v1/_avatar/link/:provider → where to send the browser. */
100
+ interface LinkStart {
101
+ authorizeUrl: string;
102
+ }
103
+ /** POST /api/v1/_avatar/resolve (service tier). At most RESOLVE_MAX_IDS ids. */
104
+ interface ResolveRequest {
105
+ userIds: string[];
106
+ }
107
+ /**
108
+ * One person as a server shows them: their avatar and their live display name.
109
+ * `name` is null for an unknown id or a closed (deleted, banned) account, so a
110
+ * server that stores only userIds (IDENTITY_MODEL R12) names people at display
111
+ * time and never keeps a copy.
112
+ */
113
+ interface ResolvedPerson extends ResolvedAvatar {
114
+ name: string | null;
115
+ }
116
+ interface ResolveResponse {
117
+ /** Every requested id is present; an unknown user resolves to `{ source: 'sprite', name: null }`. */
118
+ avatars: Record<string, ResolvedPerson>;
119
+ }
120
+ declare const RESOLVE_MAX_IDS = 100;
121
+ /** A watchparty character id, as prefs-api accepts one from the watchparty blob. */
122
+ declare const SPRITE_ID_PATTERN: RegExp;
123
+ /**
124
+ * Where Discord and Steam send the browser back. A hadoku.me page, not an API
125
+ * route: the session cookie is SameSite=Strict, so a navigation arriving from
126
+ * discord.com or steamcommunity.com carries no session. The page then POSTs
127
+ * the query string same-origin, where it does.
128
+ */
129
+ declare const LINK_CALLBACK_PATH = "/account/link/callback";
130
+
131
+ export { type AvatarSettings as A, type LinkProvider as L, type ResolvedPerson as R, SPRITE_ID_PATTERN as S, type UploadView as U, type AvatarSource as a, type AvatarUpdate as b, type LinkStart as c, AVATAR_SOURCES as d, type AvatarUploadLimits as e, LINK_CALLBACK_PATH as f, LINK_MESSAGE_TYPE as g, LINK_PROVIDERS as h, type LinkMessage as i, type LinkedAccountView as j, RESOLVE_MAX_IDS as k, type ResolveRequest as l, type ResolveResponse as m, type ResolvedAvatar as n };
package/dist/avatar.d.ts CHANGED
@@ -1,133 +1,7 @@
1
- import { A as AvatarCosmetics, C as CosmeticsView, L as LoadoutUpdate } from './cosmetics-contract-CWnMmEjr.js';
2
- export { a as CosmeticSlot, b as Loadout, P as Placement } from './cosmetics-contract-CWnMmEjr.js';
3
-
4
- /**
5
- * Avatars — the wire contract, shared by prefs-api and the client.
6
- *
7
- * Pure: no fetch, no DOM. prefs-api imports this file directly (as it does
8
- * games-contract.ts), so the server answers in the very types the client is
9
- * built from. The client half lives in ./avatar.ts.
10
- *
11
- * Design: hadoku_site docs/planning/avatars-2026-10-30.md
12
- */
13
-
14
- declare const AVATAR_SOURCES: readonly ["sprite", "discord", "steam", "upload"];
15
- type AvatarSource = (typeof AVATAR_SOURCES)[number];
16
- declare const LINK_PROVIDERS: readonly ["discord", "steam"];
17
- type LinkProvider = (typeof LINK_PROVIDERS)[number];
18
- /**
19
- * The one avatar every app renders for a user.
20
- *
21
- * - `source` is what the picture is. `'sprite'` means the character is the
22
- * picture; any other source carries `url`.
23
- * - `url` (present exactly when `source` is not `'sprite'`) is an absolute
24
- * https image URL, square, at least 184px, on a host the hadoku.me CSP admits.
25
- * Render it as an `<img>`; never fetch it server-side.
26
- * - `sprite` is the person's character (a watchparty character id) whenever
27
- * they have one, WHATEVER the source: games use it as the piece and the
28
- * name colour even when the picture is a Discord avatar. Absent = never
29
- * picked; use your own default. The app that owns the art (watchparty, its
30
- * public GET /watchparty/api/characters) owns its URL and revision.
31
- *
32
- * A source that stops being available (an unlink, an admin removal, an account
33
- * whose custom avatar was removed) resolves to `sprite` with no action from the app.
34
- */
35
- interface ResolvedAvatar {
36
- source: AvatarSource;
37
- url?: string;
38
- sprite?: string;
39
- /**
40
- * What the person wears (effect, gradient, font, overlay, message reveal,
41
- * and the overlay's placement): only items they own. Absent when nothing is
42
- * worn. Render it with `@wolffm/prefs-client/cosmetics`.
43
- */
44
- cosmetics?: AvatarCosmetics;
45
- }
46
- /** PUT /api/v1/_avatar — either or both. */
47
- interface AvatarUpdate {
48
- source?: AvatarSource;
49
- /** A watchparty character id (SPRITE_ID_PATTERN). */
50
- sprite?: string;
51
- }
52
- /** What the callback page posts to the window that opened it (same origin only). */
53
- declare const LINK_MESSAGE_TYPE = "hadoku-avatar-link";
54
- type LinkMessage = {
55
- type: typeof LINK_MESSAGE_TYPE;
56
- ok: true;
57
- provider: LinkProvider;
58
- } | {
59
- type: typeof LINK_MESSAGE_TYPE;
60
- ok: false;
61
- error: string;
62
- };
63
- /** A linked account as its owner sees it. Never carries a token. */
64
- interface LinkedAccountView {
65
- /** null when the account has no custom avatar. */
66
- avatarUrl: string | null;
67
- linkedAt: number;
68
- refreshedAt: number;
69
- }
70
- interface UploadView {
71
- url: string;
72
- width: number;
73
- height: number;
74
- uploadedAt: number;
75
- }
76
- /** GET /api/v1/_avatar — the caller's own avatar settings. */
77
- interface AvatarSettings {
78
- avatar: ResolvedAvatar;
79
- /** What the user picked; null = never picked (resolves to sprite). */
80
- choice: AvatarSource | null;
81
- sprite: string | null;
82
- linked: Partial<Record<LinkProvider, LinkedAccountView>>;
83
- upload: UploadView | null;
84
- /** Whether each provider is configured on the server. A false one cannot be linked yet. */
85
- providers: Record<LinkProvider, boolean>;
86
- limits: AvatarUploadLimits;
87
- /** What the owner has earned and what they wear. */
88
- cosmetics: CosmeticsView;
89
- }
90
- interface AvatarUploadLimits {
91
- maxBytes: number;
92
- minDimension: number;
93
- maxDimension: number;
94
- acceptedTypes: readonly string[];
95
- /** Accepted uploads per user per rolling 24h. */
96
- perDay: number;
97
- /** Edge length of the stored square, in px. */
98
- outputSize: number;
99
- }
100
- /** POST /api/v1/_avatar/link/:provider → where to send the browser. */
101
- interface LinkStart {
102
- authorizeUrl: string;
103
- }
104
- /** POST /api/v1/_avatar/resolve (service tier). At most RESOLVE_MAX_IDS ids. */
105
- interface ResolveRequest {
106
- userIds: string[];
107
- }
108
- /**
109
- * One person as a server shows them: their avatar and their live display name.
110
- * `name` is null for an unknown id or a closed (deleted, banned) account, so a
111
- * server that stores only userIds (IDENTITY_MODEL R12) names people at display
112
- * time and never keeps a copy.
113
- */
114
- interface ResolvedPerson extends ResolvedAvatar {
115
- name: string | null;
116
- }
117
- interface ResolveResponse {
118
- /** Every requested id is present; an unknown user resolves to `{ source: 'sprite', name: null }`. */
119
- avatars: Record<string, ResolvedPerson>;
120
- }
121
- declare const RESOLVE_MAX_IDS = 100;
122
- /** A watchparty character id, as prefs-api accepts one from the watchparty blob. */
123
- declare const SPRITE_ID_PATTERN: RegExp;
124
- /**
125
- * Where Discord and Steam send the browser back. A hadoku.me page, not an API
126
- * route: the session cookie is SameSite=Strict, so a navigation arriving from
127
- * discord.com or steamcommunity.com carries no session. The page then POSTs
128
- * the query string same-origin, where it does.
129
- */
130
- declare const LINK_CALLBACK_PATH = "/account/link/callback";
1
+ import { L as LoadoutUpdate } from './cosmetics-contract-CKe1lNNV.js';
2
+ export { A as AvatarCosmetics, C as CosmeticSlot, a as CosmeticsView, b as Loadout, P as Placement } from './cosmetics-contract-CKe1lNNV.js';
3
+ import { A as AvatarSettings, a as AvatarSource, b as AvatarUpdate, L as LinkProvider, c as LinkStart, R as ResolvedPerson } from './avatar-contract-DbFGb4K-.js';
4
+ export { d as AVATAR_SOURCES, e as AvatarUploadLimits, f as LINK_CALLBACK_PATH, g as LINK_MESSAGE_TYPE, h as LINK_PROVIDERS, i as LinkMessage, j as LinkedAccountView, k as RESOLVE_MAX_IDS, l as ResolveRequest, m as ResolveResponse, n as ResolvedAvatar, S as SPRITE_ID_PATTERN, U as UploadView } from './avatar-contract-DbFGb4K-.js';
131
5
 
132
6
  /** sessionStorage key the callback page reads to know it runs in the link popup. */
133
7
  declare const LINK_POPUP_MARK = "hadoku-avatar-link-popup";
@@ -190,4 +64,4 @@ interface ResolveAvatarsOptions extends AvatarClientOptions {
190
64
  */
191
65
  declare function resolveAvatars(opts: ResolveAvatarsOptions, userIds: readonly string[]): Promise<Record<string, ResolvedPerson>>;
192
66
 
193
- export { AVATAR_SOURCES, type AvatarClient, type AvatarClientOptions, AvatarCosmetics, AvatarError, type AvatarSettings, type AvatarSource, type AvatarUpdate, type AvatarUploadLimits, CosmeticsView, LINK_CALLBACK_PATH, LINK_MESSAGE_TYPE, LINK_POPUP_MARK, LINK_PROVIDERS, type LinkMessage, type LinkProvider, type LinkStart, type LinkedAccountView, LoadoutUpdate, RESOLVE_MAX_IDS, type ResolveAvatarsOptions, type ResolveRequest, type ResolveResponse, type ResolvedAvatar, type ResolvedPerson, SPRITE_ID_PATTERN, type UploadView, createAvatarClient, resolveAvatars };
67
+ export { type AvatarClient, type AvatarClientOptions, AvatarError, AvatarSettings, AvatarSource, AvatarUpdate, LINK_POPUP_MARK, LinkProvider, LinkStart, LoadoutUpdate, type ResolveAvatarsOptions, ResolvedPerson, createAvatarClient, resolveAvatars };
@@ -187,4 +187,4 @@ interface CosmeticGrantList {
187
187
  }[];
188
188
  }
189
189
 
190
- export { type AvatarCosmetics as A, type Box as B, type CosmeticsView as C, EARNED_COSMETICS as E, type LoadoutUpdate as L, type OverlayArt as O, type Placement as P, type CosmeticSlot as a, type Loadout as b, COSMETICS as c, COSMETICS_BY_ID as d, COSMETIC_ID_PATTERN as e, COSMETIC_SLOTS as f, type CosmeticGrantList as g, type CosmeticGrantRequest as h, type CosmeticItem as i, type CosmeticPeople as j, PLACEMENT_DEFAULT as k, PLACEMENT_LIMITS as l, PLACEMENT_ZONE as m, cleanLoadout as n, cleanWorn as o, emptyLoadout as p, fitPlacement as q, overlayBounds as r, ownedFrom as s, wornCosmetics as w };
190
+ export { type AvatarCosmetics as A, type Box as B, type CosmeticSlot as C, EARNED_COSMETICS as E, type LoadoutUpdate as L, type OverlayArt as O, type Placement as P, type CosmeticsView as a, type Loadout as b, COSMETICS as c, COSMETICS_BY_ID as d, COSMETIC_ID_PATTERN as e, COSMETIC_SLOTS as f, type CosmeticGrantList as g, type CosmeticGrantRequest as h, type CosmeticItem as i, type CosmeticPeople as j, PLACEMENT_DEFAULT as k, PLACEMENT_LIMITS as l, PLACEMENT_ZONE as m, cleanLoadout as n, cleanWorn as o, emptyLoadout as p, fitPlacement as q, overlayBounds as r, ownedFrom as s, wornCosmetics as w };
@@ -1,5 +1,5 @@
1
- import { A as AvatarCosmetics, P as Placement } from './cosmetics-contract-CWnMmEjr.js';
2
- export { B as Box, c as COSMETICS, d as COSMETICS_BY_ID, e as COSMETIC_ID_PATTERN, f as COSMETIC_SLOTS, g as CosmeticGrantList, h as CosmeticGrantRequest, i as CosmeticItem, j as CosmeticPeople, a as CosmeticSlot, C as CosmeticsView, E as EARNED_COSMETICS, b as Loadout, L as LoadoutUpdate, O as OverlayArt, k as PLACEMENT_DEFAULT, l as PLACEMENT_LIMITS, m as PLACEMENT_ZONE, n as cleanLoadout, o as cleanWorn, p as emptyLoadout, q as fitPlacement, r as overlayBounds, s as ownedFrom, w as wornCosmetics } from './cosmetics-contract-CWnMmEjr.js';
1
+ import { A as AvatarCosmetics, P as Placement } from './cosmetics-contract-CKe1lNNV.js';
2
+ export { B as Box, c as COSMETICS, d as COSMETICS_BY_ID, e as COSMETIC_ID_PATTERN, f as COSMETIC_SLOTS, g as CosmeticGrantList, h as CosmeticGrantRequest, i as CosmeticItem, j as CosmeticPeople, C as CosmeticSlot, a as CosmeticsView, E as EARNED_COSMETICS, b as Loadout, L as LoadoutUpdate, O as OverlayArt, k as PLACEMENT_DEFAULT, l as PLACEMENT_LIMITS, m as PLACEMENT_ZONE, n as cleanLoadout, o as cleanWorn, p as emptyLoadout, q as fitPlacement, r as overlayBounds, s as ownedFrom, w as wornCosmetics } from './cosmetics-contract-CKe1lNNV.js';
3
3
 
4
4
  /**
5
5
  * A person's colour from their avatar picture: the picture's alpha-weighted
package/dist/games.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { n as ResolvedAvatar } from './avatar-contract-DbFGb4K-.js';
2
+ import './cosmetics-contract-CKe1lNNV.js';
3
+
1
4
  /**
2
5
  * Game stats — the wire contract, and the rules both ends must agree on.
3
6
  *
@@ -8,6 +11,7 @@
8
11
  *
9
12
  * Design: hadoku_site docs/planning/game-stats-2026-10-09.md
10
13
  */
14
+
11
15
  /** A categorical fact. An array is a SET — a breakdown counts each element. */
12
16
  type StatAttr = string | number | boolean | string[];
13
17
  type StatAttrs = Record<string, StatAttr>;
@@ -106,6 +110,8 @@ interface CounterTotals {
106
110
  interface ProfileView {
107
111
  name: string;
108
112
  isMe: boolean;
113
+ /** Their avatar as every app draws it (picture, character, what they wear). Absent only from a prefs-api older than the field. */
114
+ avatar?: ResolvedAvatar;
109
115
  totals: OutcomeTotals;
110
116
  ratings: {
111
117
  mode: string;
@@ -121,6 +127,8 @@ interface LeaderboardRow {
121
127
  rank: number;
122
128
  name: string;
123
129
  isMe: boolean;
130
+ /** Their avatar as every app draws it (picture, character, what they wear). Absent only from a prefs-api older than the field. */
131
+ avatar?: ResolvedAvatar;
124
132
  value: number;
125
133
  totals: OutcomeTotals;
126
134
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/prefs-client",
3
- "version": "1.1.22",
4
- "gitHead": "3251948ab8c8406d567973aca93780cab8fd8c03",
3
+ "version": "1.1.23",
4
+ "gitHead": "1582ea97324afa92f0f56035605d4f481513bbfd",
5
5
  "description": "Client SDK for the hadoku unified preferences store. Wraps /prefs/api/v1/* with localStorage caching, debounced writes, Zod-validated reads, and a usePrefs() React hook, plus match history, ratings and leaderboards for every game (./games), the one resolved avatar per user (./avatar), and the avatar cosmetics renderer (./cosmetics).",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",