@hadoku/platform-wire 0.0.0-stage → 0.1.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hadoku-cardtable contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ /** A malformed avatar or colour costs only itself (it draws Discord's way without one), never the whole snapshot. */
3
+ export declare const DiscordMessageSchema: z.ZodObject<{
4
+ author: z.ZodString;
5
+ avatar: z.ZodCatch<z.ZodNullable<z.ZodString>>;
6
+ color: z.ZodCatch<z.ZodNullable<z.ZodString>>;
7
+ text: z.ZodString;
8
+ at: z.ZodString;
9
+ }, z.core.$strip>;
10
+ export type DiscordMessage = z.infer<typeof DiscordMessageSchema>;
11
+ /** Newest last. */
12
+ export declare const DiscordRecentSchema: z.ZodObject<{
13
+ messages: z.ZodArray<z.ZodObject<{
14
+ author: z.ZodString;
15
+ avatar: z.ZodCatch<z.ZodNullable<z.ZodString>>;
16
+ color: z.ZodCatch<z.ZodNullable<z.ZodString>>;
17
+ text: z.ZodString;
18
+ at: z.ZodString;
19
+ }, z.core.$strip>>;
20
+ }, z.core.$strip>;
21
+ export type DiscordRecent = z.infer<typeof DiscordRecentSchema>;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * A Discord channel's recent chat: ArchiveBot's signed `GET /api/messages/recent`
3
+ * (WolffM/ArchiveBot#37), relayed and cached by the app's server.
4
+ * Plain text by ArchiveBot's own contract — no ids or links ever arrive. The avatar comes as the
5
+ * image itself, a `data:` URI (hadoku.me's CSP admits those, not Discord's CDN).
6
+ */
7
+ import { z } from 'zod';
8
+ /** A malformed avatar or colour costs only itself (it draws Discord's way without one), never the whole snapshot. */
9
+ export const DiscordMessageSchema = z.object({
10
+ author: z.string(),
11
+ /** The author's avatar as Discord draws it in the server, a 64px `data:` URI; null when ArchiveBot could not read it. */
12
+ avatar: z
13
+ .string()
14
+ .regex(/^data:image\/(?:png|webp|jpeg|gif);base64,[A-Za-z0-9+/]+=*$/)
15
+ .nullable()
16
+ .catch(null),
17
+ /** Their name's role colour, `#rrggbb`; null for Discord's default. */
18
+ color: z
19
+ .string()
20
+ .regex(/^#[0-9a-f]{6}$/i)
21
+ .nullable()
22
+ .catch(null),
23
+ text: z.string(),
24
+ /** ISO, no milliseconds. */
25
+ at: z.string(),
26
+ });
27
+ /** Newest last. */
28
+ export const DiscordRecentSchema = z.object({ messages: z.array(DiscordMessageSchema) });
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ /** `{ epoch, seq }` — structurally `@wolffm/rooms-protocol`'s `SeqCursor`, which is deliberately zod-free. */
3
+ export declare const SeqCursorSchema: z.ZodObject<{
4
+ epoch: z.ZodString;
5
+ seq: z.ZodNumber;
6
+ }, z.core.$strip>;
7
+ export type WireCursor = z.infer<typeof SeqCursorSchema>;
8
+ export declare const serverEnvelopeSchema: <F extends z.ZodType>(frame: F) => z.ZodObject<{
9
+ matchId: z.ZodString;
10
+ cursor: z.ZodObject<{
11
+ epoch: z.ZodString;
12
+ seq: z.ZodNumber;
13
+ }, z.core.$strip>;
14
+ frame: F;
15
+ }, z.core.$strip>;
16
+ export interface ServerEnvelope<Frame> {
17
+ matchId: string;
18
+ cursor: WireCursor;
19
+ frame: Frame;
20
+ }
@@ -0,0 +1,9 @@
1
+ /* The server → client envelope around one frame of a match's stream: which match, the stream's
2
+ * cursor, and the game's `Frame`. A game adds its own flags with `.extend`. */
3
+ import { z } from 'zod';
4
+ /** `{ epoch, seq }` — structurally `@wolffm/rooms-protocol`'s `SeqCursor`, which is deliberately zod-free. */
5
+ export const SeqCursorSchema = z.object({
6
+ epoch: z.string().min(1),
7
+ seq: z.number().int().positive(),
8
+ });
9
+ export const serverEnvelopeSchema = (frame) => z.object({ matchId: z.string().min(1), cursor: SeqCursorSchema, frame });
@@ -0,0 +1,169 @@
1
+ import { z } from 'zod';
2
+ /** An event's title, which is its room's name: 1 to `max` characters, no control characters. */
3
+ export declare const eventTitleSchema: (max: number) => z.ZodString;
4
+ export declare const StartsAtSchema: z.ZodISODateTime;
5
+ /**
6
+ * A room made for an event (`scheduledFor`) is open to come into and chat in from the moment it
7
+ * exists, but seats nobody until this long before the event starts. The server holds it; the
8
+ * room draws its seats shut until then.
9
+ */
10
+ export declare const SEATS_OPEN_BEFORE_MS: number;
11
+ /** When the seats of a room whose event starts at `scheduledFor` (ms) open, in ms. */
12
+ export declare function seatsOpenAt(scheduledFor: number): number;
13
+ /** A request body that names its unknown fields. */
14
+ export declare const strictBody: <S extends z.ZodRawShape>(shape: S) => z.ZodObject<{ -readonly [P in keyof S]: S[P]; }, z.core.$strict>;
15
+ /**
16
+ * `PATCH /api/events/:id`, organizer only: a new start. `title` is accepted only as the room's
17
+ * own name unchanged — an event is named after its room — so a form that sends its whole state
18
+ * still saves.
19
+ */
20
+ export declare const updateEventBodySchema: (titleMax: number) => z.ZodObject<{
21
+ title: z.ZodOptional<z.ZodString>;
22
+ startsAt: z.ZodISODateTime;
23
+ }, z.core.$strict>;
24
+ /** One event as `GET /api/events` sends it, scoped to the caller (`mine`): the game's `kind` and `room`. */
25
+ export declare const eventViewSchema: <K extends z.ZodType, R extends z.ZodType>(kind: K, room: R) => z.ZodObject<{
26
+ id: z.ZodString;
27
+ kind: K;
28
+ title: z.ZodString;
29
+ startsAt: z.ZodString;
30
+ organizer: z.ZodString;
31
+ mine: z.ZodCatch<z.ZodBoolean>;
32
+ roomId: z.ZodCatch<z.ZodNullable<z.ZodString>>;
33
+ room: z.ZodOptional<z.ZodCatch<z.ZodNullable<R>>>;
34
+ signedUp: z.ZodOptional<z.ZodCatch<z.ZodNullable<z.ZodNumber>>>;
35
+ }, z.core.$strip>;
36
+ export declare const eventListSchema: <V extends z.ZodType>(view: V) => z.ZodObject<{
37
+ events: z.ZodCatch<z.ZodArray<V>>;
38
+ }, z.core.$strip>;
39
+ /** The one Rally schema an event form may carry: a required availability grid (#22 §3). */
40
+ export declare const RALLY_EVENT_SCHEMA: {
41
+ readonly name: "event-signup";
42
+ readonly version: 1;
43
+ };
44
+ export declare const RallyFormIdSchema: z.ZodString;
45
+ /** One of a form's best windows: when, how many can make all of it, and the pick those people would play (an option ref). */
46
+ export declare const RallyWindowSchema: z.ZodObject<{
47
+ at: z.ZodString;
48
+ endsAt: z.ZodString;
49
+ free: z.ZodNumber;
50
+ pick: z.ZodNullable<z.ZodString>;
51
+ }, z.core.$strip>;
52
+ export type RallyWindow = z.infer<typeof RallyWindowSchema>;
53
+ /**
54
+ * What Rally tells a service caller of a form's time question with a length: for each start that
55
+ * anyone can make, how many can make the whole length; and the best windows. Counts, never names.
56
+ */
57
+ export declare const RallyAvailabilitySchema: z.ZodObject<{
58
+ lengthMin: z.ZodNumber;
59
+ starts: z.ZodArray<z.ZodObject<{
60
+ at: z.ZodString;
61
+ free: z.ZodNumber;
62
+ }, z.core.$strip>>;
63
+ best: z.ZodArray<z.ZodObject<{
64
+ at: z.ZodString;
65
+ endsAt: z.ZodString;
66
+ free: z.ZodNumber;
67
+ pick: z.ZodNullable<z.ZodString>;
68
+ }, z.core.$strip>>;
69
+ }, z.core.$strip>;
70
+ export type RallyAvailability = z.infer<typeof RallyAvailabilitySchema>;
71
+ /** Rally's `GET /rally/api/forms/{id}/summary`, its `data`. `availability` comes to a service caller only. */
72
+ export declare const RallyFormSummarySchema: z.ZodObject<{
73
+ id: z.ZodString;
74
+ title: z.ZodString;
75
+ status: z.ZodEnum<{
76
+ open: "open";
77
+ closed: "closed";
78
+ }>;
79
+ closesAt: z.ZodNullable<z.ZodString>;
80
+ url: z.ZodString;
81
+ createdBy: z.ZodNullable<z.ZodString>;
82
+ schema: z.ZodObject<{
83
+ name: z.ZodString;
84
+ version: z.ZodNumber;
85
+ }, z.core.$strip>;
86
+ availability: z.ZodCatch<z.ZodOptional<z.ZodObject<{
87
+ lengthMin: z.ZodNumber;
88
+ starts: z.ZodArray<z.ZodObject<{
89
+ at: z.ZodString;
90
+ free: z.ZodNumber;
91
+ }, z.core.$strip>>;
92
+ best: z.ZodArray<z.ZodObject<{
93
+ at: z.ZodString;
94
+ endsAt: z.ZodString;
95
+ free: z.ZodNumber;
96
+ pick: z.ZodNullable<z.ZodString>;
97
+ }, z.core.$strip>>;
98
+ }, z.core.$strip>>>;
99
+ }, z.core.$strip>;
100
+ export type RallyFormSummary = z.infer<typeof RallyFormSummarySchema>;
101
+ /** Whether a form makes the promise an event form needs. */
102
+ export declare function isEventSignupForm(summary: Pick<RallyFormSummary, 'schema'>): boolean;
103
+ /** `POST /api/events/forms`: attach a Rally form, checked through its summary. */
104
+ export declare const AttachFormBodySchema: z.ZodObject<{
105
+ formId: z.ZodString;
106
+ }, z.core.$strict>;
107
+ export type AttachFormBody = z.output<typeof AttachFormBodySchema>;
108
+ /** An attached form as `GET /api/events/forms` and `POST /api/events/forms` send it: Rally's summary, and who attached it. */
109
+ export declare const AttachedFormSchema: z.ZodObject<{
110
+ id: z.ZodString;
111
+ title: z.ZodString;
112
+ status: z.ZodEnum<{
113
+ open: "open";
114
+ closed: "closed";
115
+ }>;
116
+ closesAt: z.ZodNullable<z.ZodString>;
117
+ url: z.ZodString;
118
+ createdBy: z.ZodNullable<z.ZodString>;
119
+ schema: z.ZodObject<{
120
+ name: z.ZodString;
121
+ version: z.ZodNumber;
122
+ }, z.core.$strip>;
123
+ attachedBy: z.ZodString;
124
+ mine: z.ZodCatch<z.ZodBoolean>;
125
+ windows: z.ZodCatch<z.ZodArray<z.ZodObject<{
126
+ at: z.ZodString;
127
+ endsAt: z.ZodString;
128
+ free: z.ZodNumber;
129
+ pick: z.ZodNullable<z.ZodString>;
130
+ }, z.core.$strip>>>;
131
+ }, z.core.$strip>;
132
+ export type AttachedForm = z.infer<typeof AttachedFormSchema>;
133
+ export declare const FormListSchema: z.ZodObject<{
134
+ forms: z.ZodCatch<z.ZodArray<z.ZodObject<{
135
+ id: z.ZodString;
136
+ title: z.ZodString;
137
+ status: z.ZodEnum<{
138
+ open: "open";
139
+ closed: "closed";
140
+ }>;
141
+ closesAt: z.ZodNullable<z.ZodString>;
142
+ url: z.ZodString;
143
+ createdBy: z.ZodNullable<z.ZodString>;
144
+ schema: z.ZodObject<{
145
+ name: z.ZodString;
146
+ version: z.ZodNumber;
147
+ }, z.core.$strip>;
148
+ attachedBy: z.ZodString;
149
+ mine: z.ZodCatch<z.ZodBoolean>;
150
+ windows: z.ZodCatch<z.ZodArray<z.ZodObject<{
151
+ at: z.ZodString;
152
+ endsAt: z.ZodString;
153
+ free: z.ZodNumber;
154
+ pick: z.ZodNullable<z.ZodString>;
155
+ }, z.core.$strip>>>;
156
+ }, z.core.$strip>>>;
157
+ }, z.core.$strip>;
158
+ /**
159
+ * A form id from what an organizer pastes: the bare id, or its Rally link
160
+ * (`https://hadoku.me/rally?e=<id>`). Null for anything else.
161
+ */
162
+ export declare function rallyFormIdOf(text: string): string | null;
163
+ /** Where "Create a form" sends the organizer: Rally's builder, from the app `origin`, returning to `returnUrl` with the new form (#22 §1). */
164
+ export declare function rallyCreateUrl(origin: string, ref: string, returnUrl: string): string;
165
+ /** Rally's return trip, read from `location.search` (before any `#/` route): the new form and our ref, or null. */
166
+ export declare function rallyReturnOf(search: string): {
167
+ formId: string;
168
+ ref: string;
169
+ } | null;
package/dist/events.js ADDED
@@ -0,0 +1,141 @@
1
+ /*
2
+ * Scheduled events and attached Rally forms: the front page's calendar and polls. An event is a
3
+ * room with a start time, read from the room each time (the operator, 2026-10-30: "the room is the
4
+ * source of truth"); what the room plays is the game's, `eventViewSchema`'s type parameters. A form
5
+ * is a Rally form on schema `event-signup@1`, listed while Rally says it is open (#22).
6
+ */
7
+ import { z } from 'zod';
8
+ // eslint-disable-next-line no-control-regex
9
+ const CONTROL = /[\u0000-\u001f\u007f]/;
10
+ /** An event's title, which is its room's name: 1 to `max` characters, no control characters. */
11
+ export const eventTitleSchema = (max) => z
12
+ .string({ error: 'title must be a string' })
13
+ .trim()
14
+ .min(1, { error: `title must be 1–${max} characters` })
15
+ .max(max, { error: `title must be 1–${max} characters` })
16
+ .refine((title) => !CONTROL.test(title), { error: 'title must not contain control characters' });
17
+ export const StartsAtSchema = z.iso.datetime({ offset: true, error: 'startsAt must be an ISO date-time' });
18
+ /**
19
+ * A room made for an event (`scheduledFor`) is open to come into and chat in from the moment it
20
+ * exists, but seats nobody until this long before the event starts. The server holds it; the
21
+ * room draws its seats shut until then.
22
+ */
23
+ export const SEATS_OPEN_BEFORE_MS = 30 * 60_000;
24
+ /** When the seats of a room whose event starts at `scheduledFor` (ms) open, in ms. */
25
+ export function seatsOpenAt(scheduledFor) {
26
+ return scheduledFor - SEATS_OPEN_BEFORE_MS;
27
+ }
28
+ /** A request body that names its unknown fields. */
29
+ export const strictBody = (shape) => z.strictObject(shape, {
30
+ error: (iss) => (iss.code === 'unrecognized_keys' ? `unknown field(s): ${iss.keys.join(', ')}` : 'body must be a JSON object'),
31
+ });
32
+ /**
33
+ * `PATCH /api/events/:id`, organizer only: a new start. `title` is accepted only as the room's
34
+ * own name unchanged — an event is named after its room — so a form that sends its whole state
35
+ * still saves.
36
+ */
37
+ export const updateEventBodySchema = (titleMax) => strictBody({ title: eventTitleSchema(titleMax).optional(), startsAt: StartsAtSchema });
38
+ /** One event as `GET /api/events` sends it, scoped to the caller (`mine`): the game's `kind` and `room`. */
39
+ export const eventViewSchema = (kind, room) => z.object({
40
+ id: z.string(),
41
+ /** What the room plays now. */
42
+ kind,
43
+ /** The room's name. */
44
+ title: z.string(),
45
+ startsAt: z.string(),
46
+ organizer: z.string(),
47
+ /** Whether the caller organized it: only they may move or cancel it. */
48
+ mine: z.boolean().catch(false),
49
+ /** The event's room. An event whose room has closed is not listed. */
50
+ roomId: z.string().nullable().catch(null),
51
+ /** The room as it is now. Always sent; optional only so a reader's fixture may leave it out. */
52
+ room: room.nullable().catch(null).optional(),
53
+ /**
54
+ * How many said on the event's Rally form that they can make it: respondents free for the
55
+ * form's whole length from `startsAt`. Null for an event made without a form, or while Rally
56
+ * cannot say.
57
+ */
58
+ signedUp: z.number().int().min(0).nullable().catch(null).optional(),
59
+ });
60
+ export const eventListSchema = (view) => z.object({ events: z.array(view).catch([]) });
61
+ /* ── Rally forms ─────────────────────────────────────────────────────── */
62
+ /** The one Rally schema an event form may carry: a required availability grid (#22 §3). */
63
+ export const RALLY_EVENT_SCHEMA = { name: 'event-signup', version: 1 };
64
+ export const RallyFormIdSchema = z.string({ error: 'formId must be a Rally form id' }).regex(/^[A-Za-z0-9_-]{1,64}$/, { error: 'formId must be a Rally form id' });
65
+ /** One of a form's best windows: when, how many can make all of it, and the pick those people would play (an option ref). */
66
+ export const RallyWindowSchema = z.object({
67
+ at: z.string(),
68
+ endsAt: z.string(),
69
+ free: z.number().int().min(0),
70
+ pick: z.string().nullable(),
71
+ });
72
+ /**
73
+ * What Rally tells a service caller of a form's time question with a length: for each start that
74
+ * anyone can make, how many can make the whole length; and the best windows. Counts, never names.
75
+ */
76
+ export const RallyAvailabilitySchema = z.object({
77
+ lengthMin: z.number().int(),
78
+ starts: z.array(z.object({ at: z.string(), free: z.number().int().min(0) })),
79
+ best: z.array(RallyWindowSchema),
80
+ });
81
+ /** Rally's `GET /rally/api/forms/{id}/summary`, its `data`. `availability` comes to a service caller only. */
82
+ export const RallyFormSummarySchema = z.object({
83
+ id: z.string(),
84
+ title: z.string(),
85
+ status: z.enum(['open', 'closed']),
86
+ closesAt: z.string().nullable(),
87
+ url: z.string(),
88
+ createdBy: z.string().nullable(),
89
+ schema: z.object({ name: z.string(), version: z.number().int() }),
90
+ availability: RallyAvailabilitySchema.optional().catch(undefined),
91
+ });
92
+ /** Whether a form makes the promise an event form needs. */
93
+ export function isEventSignupForm(summary) {
94
+ return summary.schema.name === RALLY_EVENT_SCHEMA.name && summary.schema.version === RALLY_EVENT_SCHEMA.version;
95
+ }
96
+ /** `POST /api/events/forms`: attach a Rally form, checked through its summary. */
97
+ export const AttachFormBodySchema = strictBody({ formId: RallyFormIdSchema });
98
+ /** An attached form as `GET /api/events/forms` and `POST /api/events/forms` send it: Rally's summary, and who attached it. */
99
+ export const AttachedFormSchema = RallyFormSummarySchema.omit({ availability: true }).extend({
100
+ attachedBy: z.string(),
101
+ /** Whether the caller attached it: only they may detach it, or make an event from it. */
102
+ mine: z.boolean().catch(false),
103
+ /** Its best windows, best first, for an event made from it (`RallyWindow`); empty when its time question has no length. */
104
+ windows: z.array(RallyWindowSchema).catch([]),
105
+ });
106
+ export const FormListSchema = z.object({ forms: z.array(AttachedFormSchema).catch([]) });
107
+ const RALLY_ORIGIN = 'https://hadoku.me';
108
+ /**
109
+ * A form id from what an organizer pastes: the bare id, or its Rally link
110
+ * (`https://hadoku.me/rally?e=<id>`). Null for anything else.
111
+ */
112
+ export function rallyFormIdOf(text) {
113
+ const trimmed = text.trim();
114
+ if (RallyFormIdSchema.safeParse(trimmed).success)
115
+ return trimmed;
116
+ let url;
117
+ try {
118
+ url = new URL(trimmed);
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ if (url.origin !== RALLY_ORIGIN || !/^\/rally\/?$/.test(url.pathname))
124
+ return null;
125
+ const id = url.searchParams.get('e');
126
+ return id !== null && RallyFormIdSchema.safeParse(id).success ? id : null;
127
+ }
128
+ /** Where "Create a form" sends the organizer: Rally's builder, from the app `origin`, returning to `returnUrl` with the new form (#22 §1). */
129
+ export function rallyCreateUrl(origin, ref, returnUrl) {
130
+ const q = new URLSearchParams({ origin, ref, return: returnUrl });
131
+ return `${RALLY_ORIGIN}/rally?${q.toString()}`;
132
+ }
133
+ /** Rally's return trip, read from `location.search` (before any `#/` route): the new form and our ref, or null. */
134
+ export function rallyReturnOf(search) {
135
+ const q = new URLSearchParams(search);
136
+ const formId = q.get('form');
137
+ const ref = q.get('ref');
138
+ if (formId === null || ref === null || ref === '' || ref.length > 200)
139
+ return null;
140
+ return RallyFormIdSchema.safeParse(formId).success ? { formId, ref } : null;
141
+ }
package/dist/look.d.ts ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * What a person looks like beyond their character: the avatar picture they
3
+ * chose (Discord, Steam or an upload) and the cosmetics they wear.
4
+ *
5
+ * The operator, 2026-11-05: *"picture/character are the same thing and all
6
+ * over the entire site it's the same avatar. we must display all
7
+ * customizations everywhere."* So a look rides beside `avatarId` on every wire
8
+ * that carries a face, and every face and name draws it.
9
+ *
10
+ * The server resolves it from prefs-api (`packages/game-server/src/people.ts`), which
11
+ * only ever serves what a person owns. This schema guards the shape so one bad
12
+ * field costs that field, never the face or the list it sits in; the browser
13
+ * runs `cleanWorn` from `@wolffm/prefs-client/cosmetics` before drawing, which
14
+ * drops ids its catalogue does not know.
15
+ */
16
+ import { z } from 'zod';
17
+ export declare const WornSchema: z.ZodObject<{
18
+ effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
19
+ gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
20
+ font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
21
+ overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
22
+ message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
23
+ placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
24
+ x: z.ZodNumber;
25
+ y: z.ZodNumber;
26
+ r: z.ZodNumber;
27
+ s: z.ZodNumber;
28
+ flip: z.ZodBoolean;
29
+ back: z.ZodBoolean;
30
+ }, z.core.$strip>>>;
31
+ }, z.core.$strip>;
32
+ /** The longest picture URL a look carries: Discord's and Steam's CDN paths are well under it. */
33
+ export declare const LOOK_PICTURE_MAX = 2048;
34
+ /**
35
+ * Watchparty's own bound on an avatar id (`sprite: z.string().min(1).max(32)` in
36
+ * `@wolffm/watchparty-ui@0.39.8`'s bundled `room-chrome.js`).
37
+ */
38
+ export declare const AVATAR_ID_MAX = 32;
39
+ export declare const LookSchema: z.ZodObject<{
40
+ picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
41
+ cosmetics: z.ZodCatch<z.ZodOptional<z.ZodObject<{
42
+ effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
43
+ gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
44
+ font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
45
+ overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
46
+ message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
47
+ placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
48
+ x: z.ZodNumber;
49
+ y: z.ZodNumber;
50
+ r: z.ZodNumber;
51
+ s: z.ZodNumber;
52
+ flip: z.ZodBoolean;
53
+ back: z.ZodBoolean;
54
+ }, z.core.$strip>>>;
55
+ }, z.core.$strip>>>;
56
+ }, z.core.$strip>;
57
+ export type Look = z.infer<typeof LookSchema>;
58
+ /**
59
+ * A person in a record of the past (a tournament, a replay), as the server draws them when the
60
+ * record is shown: their character and their look, looked up then (R12), never kept with the record.
61
+ */
62
+ export declare const PersonFaceSchema: z.ZodObject<{
63
+ avatarId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
64
+ look: z.ZodCatch<z.ZodOptional<z.ZodObject<{
65
+ picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
66
+ cosmetics: z.ZodCatch<z.ZodOptional<z.ZodObject<{
67
+ effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
68
+ gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
69
+ font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
70
+ overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
71
+ message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
72
+ placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
73
+ x: z.ZodNumber;
74
+ y: z.ZodNumber;
75
+ r: z.ZodNumber;
76
+ s: z.ZodNumber;
77
+ flip: z.ZodBoolean;
78
+ back: z.ZodBoolean;
79
+ }, z.core.$strip>>>;
80
+ }, z.core.$strip>>>;
81
+ }, z.core.$strip>>>;
82
+ }, z.core.$strip>;
83
+ export type PersonFace = z.infer<typeof PersonFaceSchema>;
84
+ export type Worn = z.infer<typeof WornSchema>;
85
+ /** A look with nothing in it is no look: one `=== undefined` for every reader. */
86
+ export declare function lookOrNone(look: Look | null | undefined): Look | undefined;
87
+ /** Whether two looks draw the same. */
88
+ export declare function sameLook(a: Look | undefined, b: Look | undefined): boolean;
package/dist/look.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * What a person looks like beyond their character: the avatar picture they
3
+ * chose (Discord, Steam or an upload) and the cosmetics they wear.
4
+ *
5
+ * The operator, 2026-11-05: *"picture/character are the same thing and all
6
+ * over the entire site it's the same avatar. we must display all
7
+ * customizations everywhere."* So a look rides beside `avatarId` on every wire
8
+ * that carries a face, and every face and name draws it.
9
+ *
10
+ * The server resolves it from prefs-api (`packages/game-server/src/people.ts`), which
11
+ * only ever serves what a person owns. This schema guards the shape so one bad
12
+ * field costs that field, never the face or the list it sits in; the browser
13
+ * runs `cleanWorn` from `@wolffm/prefs-client/cosmetics` before drawing, which
14
+ * drops ids its catalogue does not know.
15
+ */
16
+ import { z } from 'zod';
17
+ /** A cosmetic id, `<slot>.<name>` (`COSMETIC_ID_PATTERN`'s shape, bounded). */
18
+ const cosmeticId = z.string().regex(/^[a-z]+\.[a-z0-9-]+$/).max(64).optional().catch(undefined);
19
+ const PlacementSchema = z.object({
20
+ x: z.number(),
21
+ y: z.number(),
22
+ r: z.number(),
23
+ s: z.number(),
24
+ flip: z.boolean(),
25
+ back: z.boolean(),
26
+ });
27
+ export const WornSchema = z.object({
28
+ effect: cosmeticId,
29
+ gradient: cosmeticId,
30
+ font: cosmeticId,
31
+ overlay: cosmeticId,
32
+ message: cosmeticId,
33
+ placement: PlacementSchema.optional().catch(undefined),
34
+ });
35
+ /** The longest picture URL a look carries: Discord's and Steam's CDN paths are well under it. */
36
+ export const LOOK_PICTURE_MAX = 2048;
37
+ /**
38
+ * Watchparty's own bound on an avatar id (`sprite: z.string().min(1).max(32)` in
39
+ * `@wolffm/watchparty-ui@0.39.8`'s bundled `room-chrome.js`).
40
+ */
41
+ export const AVATAR_ID_MAX = 32;
42
+ export const LookSchema = z.object({
43
+ /** An https image, square, drawn instead of the character's portrait. Absent: the character is the picture. */
44
+ picture: z.url({ protocol: /^https$/ }).max(LOOK_PICTURE_MAX).optional().catch(undefined),
45
+ /** What they wear. Absent when nothing is. */
46
+ cosmetics: WornSchema.optional().catch(undefined),
47
+ });
48
+ /**
49
+ * A person in a record of the past (a tournament, a replay), as the server draws them when the
50
+ * record is shown: their character and their look, looked up then (R12), never kept with the record.
51
+ */
52
+ export const PersonFaceSchema = z.object({
53
+ avatarId: z.string().trim().min(1).max(AVATAR_ID_MAX).optional().catch(undefined),
54
+ look: LookSchema.optional().catch(undefined),
55
+ });
56
+ const WORN_KEYS = ['effect', 'gradient', 'font', 'overlay', 'message', 'placement'];
57
+ /** Only the keys that hold something, always in one order, so two copies of one look compare equal. */
58
+ function wornOrNone(worn) {
59
+ if (worn === undefined)
60
+ return undefined;
61
+ const out = {};
62
+ for (const k of WORN_KEYS) {
63
+ const v = worn[k];
64
+ if (v === undefined)
65
+ continue;
66
+ out[k] = k === 'placement' ? { x: worn.placement.x, y: worn.placement.y, r: worn.placement.r, s: worn.placement.s, flip: worn.placement.flip, back: worn.placement.back } : v;
67
+ }
68
+ return Object.keys(out).length === 0 ? undefined : out;
69
+ }
70
+ /** A look with nothing in it is no look: one `=== undefined` for every reader. */
71
+ export function lookOrNone(look) {
72
+ if (look === null || look === undefined)
73
+ return undefined;
74
+ const worn = wornOrNone(look.cosmetics);
75
+ if (look.picture === undefined && worn === undefined)
76
+ return undefined;
77
+ return { ...(look.picture === undefined ? {} : { picture: look.picture }), ...(worn === undefined ? {} : { cosmetics: worn }) };
78
+ }
79
+ /** Whether two looks draw the same. */
80
+ export function sameLook(a, b) {
81
+ return JSON.stringify(lookOrNone(a) ?? null) === JSON.stringify(lookOrNone(b) ?? null);
82
+ }
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ /** A fraction across or down the WHOLE board: 0 at its left or top edge, 1 at its right or bottom. */
3
+ export declare const BoardFractionSchema: z.ZodNumber;
4
+ /** Server → the match's other sockets: a game's presence message, stamped with the seat it came from. */
5
+ export declare const presenceEchoSchema: <Shape extends z.ZodRawShape, C extends z.core.$ZodObjectConfig>(message: z.ZodObject<Shape, C>) => z.ZodObject<(keyof Shape & "seat" extends never ? Shape & {
6
+ seat: z.ZodNumber;
7
+ } : { [K in keyof Shape as K extends "seat" ? never : K]: Shape[K]; } & {
8
+ seat: z.ZodNumber;
9
+ }) extends infer T ? { [k in keyof T]: T[k]; } : never, z.core.$strict>;
10
+ /**
11
+ * How often a seat may send: the sender throttles to `PRESENCE_SEND_MS`, and
12
+ * the server drops anything past `PRESENCE_MAX_PER_SECOND` from one socket
13
+ * (a client bug, not a game event; nothing is owed back for it).
14
+ */
15
+ export declare const PRESENCE_SEND_MS = 60;
16
+ export declare const PRESENCE_MAX_PER_SECOND = 40;
@@ -0,0 +1,14 @@
1
+ /* Presence: each player's pointer, relayed seat to seat. What a point is anchored to is the game's;
2
+ * the board's frame, the seat stamped on the echo and how often a seat may send are every game's. */
3
+ import { z } from 'zod';
4
+ /** A fraction across or down the WHOLE board: 0 at its left or top edge, 1 at its right or bottom. */
5
+ export const BoardFractionSchema = z.number().min(0).max(1);
6
+ /** Server → the match's other sockets: a game's presence message, stamped with the seat it came from. */
7
+ export const presenceEchoSchema = (message) => message.extend({ seat: z.number().int().min(0) }).strict();
8
+ /**
9
+ * How often a seat may send: the sender throttles to `PRESENCE_SEND_MS`, and
10
+ * the server drops anything past `PRESENCE_MAX_PER_SECOND` from one socket
11
+ * (a client bug, not a game event; nothing is owed back for it).
12
+ */
13
+ export const PRESENCE_SEND_MS = 60;
14
+ export const PRESENCE_MAX_PER_SECOND = 40;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A uniform [0,1) from `crypto`, never `Math.random`: one rule, one place, for
3
+ * every draw the UI or the server makes. `globalThis.crypto` is the Web Crypto API in a browser and
4
+ * in Node alike.
5
+ */
6
+ export declare function secureRandom(): number;
7
+ /**
8
+ * One of `items`, or undefined when there are none.
9
+ *
10
+ * `rand` is injectable so a draw can be asserted against a pinned source
11
+ * rather than sampled and hoped about.
12
+ */
13
+ export declare function pickRandom<T>(items: readonly T[], rand?: () => number): T | undefined;
package/dist/random.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A uniform [0,1) from `crypto`, never `Math.random`: one rule, one place, for
3
+ * every draw the UI or the server makes. `globalThis.crypto` is the Web Crypto API in a browser and
4
+ * in Node alike.
5
+ */
6
+ export function secureRandom() {
7
+ const buf = new Uint32Array(1);
8
+ globalThis.crypto.getRandomValues(buf);
9
+ return buf[0] / 2 ** 32;
10
+ }
11
+ /**
12
+ * One of `items`, or undefined when there are none.
13
+ *
14
+ * `rand` is injectable so a draw can be asserted against a pinned source
15
+ * rather than sampled and hoped about.
16
+ */
17
+ export function pickRandom(items, rand = secureRandom) {
18
+ if (items.length === 0)
19
+ return undefined;
20
+ return items[Math.min(items.length - 1, Math.floor(rand() * items.length))];
21
+ }
@@ -0,0 +1 @@
1
+ export declare const SERVER_RESTARTING_EVENT = "server:restarting";
@@ -0,0 +1,7 @@
1
+ /*
2
+ * The server is about to restart on purpose (a deploy's SIGTERM), told to every
3
+ * socket just before it closes them, so a client can tell a planned drop from a
4
+ * lost connection and say "Updating…" rather than "Reconnecting…" while it
5
+ * comes back. No payload: the event is the whole message.
6
+ */
7
+ export const SERVER_RESTARTING_EVENT = 'server:restarting';
@@ -0,0 +1 @@
1
+ export declare const ROOM_ID_RE: RegExp;
@@ -0,0 +1,6 @@
1
+ /*
2
+ * A room id: every id the lobby mints, and the only shape a route, a stream key or a watchparty
3
+ * room key (`<app>-<id>`) accepts. The room feed's wire itself is the rooms core's
4
+ * (`@wolffm/rooms-protocol`'s `feed.ts`).
5
+ */
6
+ export const ROOM_ID_RE = /^[a-z0-9-]{1,40}$/;
@@ -0,0 +1,66 @@
1
+ import { z } from 'zod';
2
+ /** A series runs to one game or to three — the room's own count. */
3
+ export declare const SeriesLengthSchema: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<3>]>;
4
+ export type SeriesLength = z.infer<typeof SeriesLengthSchema>;
5
+ /** One of a table's (at most two) seats, in seat order. */
6
+ export declare const RoomTablePlayerSchema: z.ZodObject<{
7
+ memberId: z.ZodString;
8
+ name: z.ZodString;
9
+ }, z.core.$strict>;
10
+ export type RoomTablePlayer = z.infer<typeof RoomTablePlayerSchema>;
11
+ /** One finished game: the match it was, and which seat won — `null` for a draw or no knowable winner, never a guess. */
12
+ export declare const RoomTableGameSchema: z.ZodObject<{
13
+ matchId: z.ZodString;
14
+ winner: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodNull]>;
15
+ }, z.core.$strict>;
16
+ export type RoomTableGame = z.infer<typeof RoomTableGameSchema>;
17
+ /**
18
+ * A table's schemas, its series moving through the game's `phases`. `id` is `"t-" + 8 hex`, the
19
+ * first table's stable for the room's life; `matchId` is the live game, or `null` between games.
20
+ */
21
+ export declare function roomTableSchemas<const P extends readonly [string, ...string[]]>(phases: P): {
22
+ SeriesPhaseSchema: z.ZodEnum<{ [k_1 in P[number]]: k_1; } extends infer T ? { [k in keyof T]: T[k]; } : never>;
23
+ RoomTableSeriesSchema: z.ZodObject<{
24
+ length: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<3>]>;
25
+ wins: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
26
+ games: z.ZodArray<z.ZodObject<{
27
+ matchId: z.ZodString;
28
+ winner: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodNull]>;
29
+ }, z.core.$strict>>;
30
+ phase: z.ZodEnum<{ [k_1 in P[number]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;
31
+ }, z.core.$strict>;
32
+ RoomTableSchema: z.ZodObject<{
33
+ id: z.ZodString;
34
+ players: z.ZodArray<z.ZodObject<{
35
+ memberId: z.ZodString;
36
+ name: z.ZodString;
37
+ }, z.core.$strict>>;
38
+ matchId: z.ZodNullable<z.ZodString>;
39
+ series: z.ZodObject<{
40
+ length: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<3>]>;
41
+ wins: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
42
+ games: z.ZodArray<z.ZodObject<{
43
+ matchId: z.ZodString;
44
+ winner: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodNull]>;
45
+ }, z.core.$strict>>;
46
+ phase: z.ZodEnum<{ [k_1 in P[number]]: k_1; } extends infer T_2 ? { [k in keyof T_2]: T_2[k]; } : never>;
47
+ }, z.core.$strict>;
48
+ }, z.core.$strict>;
49
+ RoomTablesSchema: z.ZodArray<z.ZodObject<{
50
+ id: z.ZodString;
51
+ players: z.ZodArray<z.ZodObject<{
52
+ memberId: z.ZodString;
53
+ name: z.ZodString;
54
+ }, z.core.$strict>>;
55
+ matchId: z.ZodNullable<z.ZodString>;
56
+ series: z.ZodObject<{
57
+ length: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<3>]>;
58
+ wins: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
59
+ games: z.ZodArray<z.ZodObject<{
60
+ matchId: z.ZodString;
61
+ winner: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodNull]>;
62
+ }, z.core.$strict>>;
63
+ phase: z.ZodEnum<{ [k_1 in P[number]]: k_1; } extends infer T_3 ? { [k in keyof T_3]: T_3[k]; } : never>;
64
+ }, z.core.$strict>;
65
+ }, z.core.$strict>>;
66
+ };
package/dist/tables.js ADDED
@@ -0,0 +1,35 @@
1
+ /* Room tables: a room holds at least one, each seating up to two players for a series of one game
2
+ * or three, each its own match. The phases a series moves through are the game's own list. */
3
+ import { z } from 'zod';
4
+ /** A series runs to one game or to three — the room's own count. */
5
+ export const SeriesLengthSchema = z.union([z.literal(1), z.literal(3)]);
6
+ /** One of a table's (at most two) seats, in seat order. */
7
+ export const RoomTablePlayerSchema = z.strictObject({
8
+ memberId: z.string().min(1),
9
+ name: z.string(),
10
+ });
11
+ /** One finished game: the match it was, and which seat won — `null` for a draw or no knowable winner, never a guess. */
12
+ export const RoomTableGameSchema = z.strictObject({
13
+ matchId: z.string().min(1),
14
+ winner: z.union([z.literal(0), z.literal(1), z.null()]),
15
+ });
16
+ /**
17
+ * A table's schemas, its series moving through the game's `phases`. `id` is `"t-" + 8 hex`, the
18
+ * first table's stable for the room's life; `matchId` is the live game, or `null` between games.
19
+ */
20
+ export function roomTableSchemas(phases) {
21
+ const SeriesPhaseSchema = z.enum(phases);
22
+ const RoomTableSeriesSchema = z.strictObject({
23
+ length: SeriesLengthSchema,
24
+ wins: z.tuple([z.number().int().min(0), z.number().int().min(0)]),
25
+ games: z.array(RoomTableGameSchema),
26
+ phase: SeriesPhaseSchema,
27
+ });
28
+ const RoomTableSchema = z.strictObject({
29
+ id: z.string().min(1),
30
+ players: z.array(RoomTablePlayerSchema).max(2),
31
+ matchId: z.string().nullable(),
32
+ series: RoomTableSeriesSchema,
33
+ });
34
+ return { SeriesPhaseSchema, RoomTableSeriesSchema, RoomTableSchema, RoomTablesSchema: z.array(RoomTableSchema).min(1) };
35
+ }
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ /** An event's facts: flat scalars, a bounded field set. */
3
+ export declare const ClientDataSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
4
+ /** One event from a match's socket, of one of the game's own `kinds`. */
5
+ export declare const clientEventSchema: <const K extends readonly [string, ...string[]]>(kinds: K) => z.ZodObject<{
6
+ matchId: z.ZodString;
7
+ kind: z.ZodEnum<{ [k_1 in K[number]]: k_1; } extends infer T ? { [k in keyof T]: T[k]; } : never>;
8
+ data: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
9
+ }, z.core.$strict>;
10
+ /** Where a page event is sent, under `/api/`: a screen with no match has no match socket to carry it. */
11
+ export declare const PAGE_EVENT_PATH = "client-events";
12
+ /**
13
+ * The same telemetry from a screen outside a match, sent over HTTP to `PAGE_EVENT_PATH` and written
14
+ * into the server's log as a `client` event keyed by page and user. `page: 'front'`, `kind: 'perf'`:
15
+ * a list's scroll smoothness, one summary per scroll burst.
16
+ */
17
+ export declare const PageEventSchema: z.ZodObject<{
18
+ page: z.ZodEnum<{
19
+ front: "front";
20
+ }>;
21
+ kind: z.ZodEnum<{
22
+ perf: "perf";
23
+ }>;
24
+ data: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
25
+ }, z.core.$strict>;
26
+ export type PageEvent = z.output<typeof PageEventSchema>;
27
+ /** A socket sending more than this in one second is a client bug; the rest of that second is dropped. */
28
+ export declare const CLIENT_EVENT_MAX_PER_SECOND = 20;
29
+ /** Where the browser's usage batches go, under `/api/`. */
30
+ export declare const USAGE_PATH = "usage";
31
+ /** The most entries one usage batch may carry; a page flushes well before it. */
32
+ export declare const USAGE_BATCH_MAX = 200;
33
+ export declare const UsageBatchSchema: z.ZodObject<{
34
+ entries: z.ZodArray<z.ZodObject<{
35
+ kind: z.ZodEnum<{
36
+ view: "view";
37
+ click: "click";
38
+ }>;
39
+ screen: z.ZodString;
40
+ target: z.ZodOptional<z.ZodString>;
41
+ }, z.core.$strict>>;
42
+ }, z.core.$strict>;
43
+ export type UsageBatch = z.output<typeof UsageBatchSchema>;
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Client telemetry: what a browser knows and the server cannot, written into the server's log so a
3
+ * report is read from the log, never deduced from code (the operator, 2026-10-08: *"you should
4
+ * always confirm everything with telemetry."*). Flat scalars, no hidden information, nothing relayed.
5
+ */
6
+ import { z } from 'zod';
7
+ const ScalarSchema = z.union([z.string().max(80), z.number().finite(), z.boolean()]);
8
+ /** An event's facts: flat scalars, a bounded field set. */
9
+ export const ClientDataSchema = z.record(z.string().min(1).max(32), ScalarSchema).refine((d) => Object.keys(d).length <= 16, 'at most 16 fields');
10
+ /** One event from a match's socket, of one of the game's own `kinds`. */
11
+ export const clientEventSchema = (kinds) => z.object({ matchId: z.string().min(1), kind: z.enum(kinds), data: ClientDataSchema }).strict();
12
+ /** Where a page event is sent, under `/api/`: a screen with no match has no match socket to carry it. */
13
+ export const PAGE_EVENT_PATH = 'client-events';
14
+ /**
15
+ * The same telemetry from a screen outside a match, sent over HTTP to `PAGE_EVENT_PATH` and written
16
+ * into the server's log as a `client` event keyed by page and user. `page: 'front'`, `kind: 'perf'`:
17
+ * a list's scroll smoothness, one summary per scroll burst.
18
+ */
19
+ export const PageEventSchema = z.object({ page: z.enum(['front']), kind: z.enum(['perf']), data: ClientDataSchema }).strict();
20
+ /** A socket sending more than this in one second is a client bug; the rest of that second is dropped. */
21
+ export const CLIENT_EVENT_MAX_PER_SECOND = 20;
22
+ /** Where the browser's usage batches go, under `/api/`. */
23
+ export const USAGE_PATH = 'usage';
24
+ /** The most entries one usage batch may carry; a page flushes well before it. */
25
+ export const USAGE_BATCH_MAX = 200;
26
+ /**
27
+ * A name a usage entry carries: a screen (a route's `kind`) or a target (an element's
28
+ * `data-testid`, ids stripped). Lowercase words, digits and `-`, `_`, `.`, `:` and `/` — never a
29
+ * label, a name or anything a player typed.
30
+ */
31
+ const UsageNameSchema = z.string().min(1).max(64).regex(/^[a-z0-9][a-z0-9_.:/-]*$/);
32
+ /**
33
+ * What the browser reports about how the app is used: each screen it shows and each named control
34
+ * pressed, batched. The server only counts them; nothing per click is stored.
35
+ */
36
+ const UsageEntrySchema = z.object({ kind: z.enum(['view', 'click']), screen: UsageNameSchema, target: UsageNameSchema.optional() }).strict();
37
+ export const UsageBatchSchema = z.object({ entries: z.array(UsageEntrySchema).min(1).max(USAGE_BATCH_MAX) }).strict();
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@hadoku/platform-wire",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.5",
4
+ "gitHead": "5ed24a59e1d1340e34c2ba1abe31c152f396282b",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "description": "The wire any game speaks: room ids, telemetry, presence, events and tables, the Discord relay, looks, the restart notice, secure random and a generic server envelope. Knows no game; a game's own part rides as a type parameter. MIT; imports only zod.",
8
+ "exports": {
9
+ "./room-feed": {
10
+ "types": "./dist/room-feed.d.ts",
11
+ "import": "./dist/room-feed.js"
12
+ },
13
+ "./telemetry": {
14
+ "types": "./dist/telemetry.d.ts",
15
+ "import": "./dist/telemetry.js"
16
+ },
17
+ "./presence": {
18
+ "types": "./dist/presence.d.ts",
19
+ "import": "./dist/presence.js"
20
+ },
21
+ "./discord": {
22
+ "types": "./dist/discord.d.ts",
23
+ "import": "./dist/discord.js"
24
+ },
25
+ "./restarting": {
26
+ "types": "./dist/restarting.d.ts",
27
+ "import": "./dist/restarting.js"
28
+ },
29
+ "./look": {
30
+ "types": "./dist/look.d.ts",
31
+ "import": "./dist/look.js"
32
+ },
33
+ "./random": {
34
+ "types": "./dist/random.d.ts",
35
+ "import": "./dist/random.js"
36
+ },
37
+ "./events": {
38
+ "types": "./dist/events.d.ts",
39
+ "import": "./dist/events.js"
40
+ },
41
+ "./tables": {
42
+ "types": "./dist/tables.d.ts",
43
+ "import": "./dist/tables.js"
44
+ },
45
+ "./envelope": {
46
+ "types": "./dist/envelope.d.ts",
47
+ "import": "./dist/envelope.js"
48
+ }
49
+ },
50
+ "dependencies": {
51
+ "zod": "4.5.4"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "LICENSE"
56
+ ],
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/WolffM/hadoku-cardtable.git",
60
+ "directory": "packages/platform-wire"
61
+ }
62
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.