@hadoku/game-server 0.1.212 → 0.1.213

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.
@@ -12,8 +12,8 @@
12
12
  * them only when the shared secret checks out; otherwise we overwrite them with
13
13
  * the most restrictive identity.
14
14
  */
15
- import { TIER_ORDER, type Tier, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator } from '@wolffm/service-kernel/auth';
16
- export { TIER_ORDER, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator };
15
+ import { TIER_ORDER, type Tier, rankOf, tierOf, edgeTierOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator } from '@wolffm/service-kernel/auth';
16
+ export { TIER_ORDER, rankOf, tierOf, edgeTierOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator };
17
17
  export type { Tier };
18
18
  /**
19
19
  * The floor must be a tier this build knows, and never `public` here —
package/dist/edge-auth.js CHANGED
@@ -12,9 +12,9 @@
12
12
  * them only when the shared secret checks out; otherwise we overwrite them with
13
13
  * the most restrictive identity.
14
14
  */
15
- import { TIER_ORDER, assertFloor as kernelAssertFloor, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator, } from '@wolffm/service-kernel/auth';
15
+ import { TIER_ORDER, assertFloor as kernelAssertFloor, rankOf, tierOf, edgeTierOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator, } from '@wolffm/service-kernel/auth';
16
16
  import { ENV_PREFIX, edgeAuth, gate } from './kernel.js';
17
- export { TIER_ORDER, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator };
17
+ export { TIER_ORDER, rankOf, tierOf, edgeTierOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator };
18
18
  /**
19
19
  * The floor must be a tier this build knows, and never `public` here —
20
20
  * cardtable admits members and friends, never the public tier. An unknown
@@ -26,45 +26,13 @@
26
26
  * account's place in it exactly as above.
27
27
  */
28
28
  import type { ParticipantId } from '@wolffm/rooms-protocol';
29
+ import type { PlatformRoomView, RoomCreateInput, RoomLobby } from '../room/lobby.js';
29
30
  import type { EraseStep } from './index.js';
30
- import type { IdMove } from './anonymise.js';
31
31
  export interface LiveMatch {
32
32
  seatOf(participantId: ParticipantId): number | null;
33
33
  }
34
- /** What this file reads off a room — `FileLobby.list()`'s own `RoomView[]` satisfies this structurally. */
35
- interface RoomSummary {
36
- id: string;
37
- members: readonly {
38
- id: string;
39
- }[];
40
- }
41
- /** `room/lobby.ts`'s own `LeaveResult`/`CloseRoomResult`, narrowed to what this file reads; `FileLobby` satisfies both structurally. */
42
- type RoomsLeaveResult = {
43
- ok: true;
44
- forfeited?: {
45
- tableId: string;
46
- matchIds: string[];
47
- };
48
- } | {
49
- ok: false;
50
- };
51
- type RoomsCloseResult = {
52
- ok: true;
53
- matches: string[];
54
- } | {
55
- ok: false;
56
- };
57
- /** A narrow slice of `room/lobby.ts`'s `Lobby` — declared here, not imported, so this platform file carries no edge into the tangled lobby. */
58
- interface RoomsLobby {
59
- list(): readonly RoomSummary[];
60
- leave(roomId: string, memberId: string): RoomsLeaveResult;
61
- close(roomId: string, callerId: string): RoomsCloseResult;
62
- anonymise(ids: ReadonlySet<string>, to: string): number;
63
- /** Account merge: every room naming the merged-away account, and not the kept one, names the kept one. */
64
- merge(move: IdMove): number;
65
- /** Every room written or deleted so far is on disk: a step answers only once what it changed is. */
66
- flushed(): Promise<void>;
67
- }
34
+ /** What the steps call on the lobby; `flushed` lets a step answer only once what it changed is on disk. */
35
+ type RoomsLobby = Pick<RoomLobby<PlatformRoomView, RoomCreateInput>, 'list' | 'leave' | 'close' | 'anonymise' | 'merge' | 'flushed'>;
68
36
  export interface RoomsEraseDeps<M extends LiveMatch> {
69
37
  lobby: RoomsLobby;
70
38
  /** Every match still being played. */
@@ -4,19 +4,13 @@
4
4
  * (routes, pools, play/socket.ts) need no edit.
5
5
  *
6
6
  * `httpCaller` binds the kernel's injected caller-id deriver to this app's own identity scheme
7
- * (`room/identity.ts`). `callerOf` builds the full `Caller` the room layer wants: it is NOT moved
8
- * into the kernel (`room/lobby.ts`'s `Caller` and `UNNAMED` stay app-side, by the wave's own
9
- * ruling), and `UNNAMED` is copied here rather than imported from `room/lobby.ts` — this file is
10
- * `platform` and `room/lobby.ts` is `tangled` (`scripts/layers/layers.json`), so importing it back
11
- * would restore the very `platform→tangled` edge this wave cuts
12
- * (`scripts/layers/ratchet.test.ts`, the `http/request.ts→../room/lobby.js` edge). The object
13
- * `callerOf` builds matches `room/lobby.ts`'s `Caller` shape structurally, which is all a caller
14
- * of `callerOf` needs — nothing here imports that type either.
7
+ * (`room/identity.ts`). `callerOf` builds the full `Caller` the room layer wants (`room/caller.ts`).
15
8
  */
16
9
  import type { ParticipantId } from '@wolffm/rooms-protocol';
17
10
  import type { RateLimitConfig } from '@wolffm/rooms-server';
18
11
  import type { Request, Response } from 'express';
19
12
  import { bodyErrors, parseBody, readBody, type BodySchema } from '@wolffm/service-kernel/limits';
13
+ import type { Caller } from '../room/caller.js';
20
14
  export { bodyErrors, parseBody, readBody };
21
15
  export type { BodySchema };
22
16
  /**
@@ -30,11 +24,7 @@ export declare const httpCaller: (req: Request) => ParticipantId;
30
24
  * userId — a roster is for humans; a key the edge sent no name for gets `UNNAMED`), and the userId
31
25
  * a saved room keeps instead of the name (R12).
32
26
  */
33
- export declare function callerOf(req: Request): {
34
- id: string;
35
- name: string;
36
- userId: string | null;
37
- };
27
+ export declare function callerOf(req: Request): Caller;
38
28
  /**
39
29
  * A per-caller token bucket for a costly step: each pass reports `costly-act` and each refusal
40
30
  * `rate-limited`, both named by `act`, so telemetry shows who is spending the expensive steps and
@@ -1,5 +1,6 @@
1
1
  import { bodyErrors, makeCallerId, parseBody, readBody, costlyActLimit as kernelCostlyActLimit, perCallerLimit as kernelPerCallerLimit, } from '@wolffm/service-kernel/limits';
2
2
  import { accountIdOf, userNameOf } from '../edge-auth.js';
3
+ import { UNNAMED } from '../room/constants.js';
3
4
  import { identityFromHeaders } from '../room/identity.js';
4
5
  export { bodyErrors, parseBody, readBody };
5
6
  /**
@@ -8,8 +9,6 @@ export { bodyErrors, parseBody, readBody };
8
9
  * for someone the edge could not name.
9
10
  */
10
11
  export const httpCaller = makeCallerId(identityFromHeaders);
11
- /** `room/lobby.ts`'s own word for an unnamed member. Kept in sync by hand — see this file's header. */
12
- const UNNAMED = 'friend';
13
12
  /**
14
13
  * Who is asking, for a lobby call: the id, the DISPLAY NAME (`X-User-Name`, never the opaque
15
14
  * userId — a roster is for humans; a key the edge sent no name for gets `UNNAMED`), and the userId
@@ -22,9 +22,8 @@
22
22
  */
23
23
  import { Router, type Request, type Response } from 'express';
24
24
  import { type RateLimitConfig } from '@wolffm/rooms-server';
25
- import { bodyErrors, callerOf, type BodySchema } from './request.js';
26
- /** Who is asking — exactly what `callerOf` returns, never a redeclared shape. */
27
- type CallerLike = ReturnType<typeof callerOf>;
25
+ import type { Caller } from '../room/caller.js';
26
+ import { bodyErrors, type BodySchema } from './request.js';
28
27
  /** The minimal room shape every route here touches; the real `RoomView` satisfies it and rides through untouched as `V`. */
29
28
  export interface RoomViewCore {
30
29
  id: string;
@@ -42,7 +41,7 @@ export interface LobbyCore<V extends RoomViewCore, C> {
42
41
  get(roomId: string): V | undefined;
43
42
  offered(): V[];
44
43
  isMember(roomId: string, callerId: string): boolean;
45
- create(caller: CallerLike, body: C): {
44
+ create(caller: Caller, body: C): {
46
45
  ok: true;
47
46
  room: V;
48
47
  } | {
@@ -50,7 +49,7 @@ export interface LobbyCore<V extends RoomViewCore, C> {
50
49
  };
51
50
  /** The tier floor a room made from `body` would have (`room/lobby.ts`'s `minTierOf`). */
52
51
  minTierOf(body: C): string | undefined;
53
- join(roomId: string, caller: CallerLike, password?: string): {
52
+ join(roomId: string, caller: Caller, password?: string): {
54
53
  ok: true;
55
54
  room: V;
56
55
  } | {
@@ -78,7 +77,7 @@ export interface LobbyCore<V extends RoomViewCore, C> {
78
77
  ok: false;
79
78
  reason: string;
80
79
  };
81
- bindWatchparty(caller: CallerLike, watchpartyRoom: string): {
80
+ bindWatchparty(caller: Caller, watchpartyRoom: string): {
82
81
  ok: true;
83
82
  room: V;
84
83
  } | {
@@ -247,7 +246,7 @@ export interface RoomCoreDeps<V extends RoomViewCore, C, P extends object, G = n
247
246
  here?: (roomId: string) => ReadonlySet<string>;
248
247
  /** "Reset = Close": runs AFTER `closed`, same as `index.ts`'s own `seedTestingRooms` boot call. */
249
248
  reseedTesting?: () => void;
250
- arrived?: (roomId: string, caller: CallerLike) => void;
249
+ arrived?: (roomId: string, caller: Caller) => void;
251
250
  /** Each table's game, by table id (`play/table-game.ts`). A hook: this file never inspects `G`'s shape. */
252
251
  tableGames?(room: V): Record<string, G>;
253
252
  /** The room as a browser is sent it, when the game draws less than its lobby holds (Magic's `podForPeople`). Absent: the room as it is. */
@@ -299,6 +298,6 @@ export interface RoomCoreHandle<V extends RoomViewCore, G = never> {
299
298
  export declare function attachRoomCore<V extends RoomViewCore, C, P extends object, G = never>(api: Router, deps: RoomCoreDeps<V, C, P, G>, opts?: {
300
299
  beforeWildcard?(router: Router): void;
301
300
  /** Every other PATCH variant (Magic's `{ format }`/`{ mode }`) — method syntax for bivariance, like `LobbyCore`. */
302
- onPatch?(req: Request, res: Response, body: P, caller: CallerLike, roomId: string): void;
301
+ onPatch?(req: Request, res: Response, body: P, caller: Caller, roomId: string): void;
303
302
  }): RoomCoreHandle<V, G>;
304
303
  export { bodyErrors };
package/dist/http/trim.js CHANGED
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { readFile } from 'node:fs/promises';
13
13
  import { Router } from 'express';
14
- import { rankOf, tierOf } from '../edge-auth.js';
14
+ import { isAdmin } from '../edge-auth.js';
15
15
  import { jsonLogger } from '@wolffm/service-kernel/log';
16
16
  import { atomicWriteJson } from '@wolffm/service-kernel/state';
17
17
  import { bodyErrors } from './request.js';
@@ -59,10 +59,10 @@ export function attachTrim(api, deps) {
59
59
  const log = deps.log ?? jsonLogger('cardtable-trim');
60
60
  const trim = Router();
61
61
  trim.get('/', async (req, res) => {
62
- res.json({ trim: await readTrim(file, log), canEdit: rankOf(tierOf(req)) >= rankOf('admin') });
62
+ res.json({ trim: await readTrim(file, log), canEdit: isAdmin(req) });
63
63
  });
64
64
  trim.put('/', async (req, res) => {
65
- if (rankOf(tierOf(req)) < rankOf('admin'))
65
+ if (!isAdmin(req))
66
66
  return res.status(403).json({ error: 'admin tier required' });
67
67
  const next = parseTrim(req.body?.trim);
68
68
  if (next === null)
@@ -41,6 +41,7 @@
41
41
  * shown in a seat row; there is exactly one id per participant rather than an
42
42
  * internal id plus a wire handle to keep in sync.
43
43
  */
44
+ import { headerValue } from '@wolffm/service-kernel/auth';
44
45
  import { createParticipantIdDeriver } from '@wolffm/rooms-server';
45
46
  /**
46
47
  * Domain separation for the digest.
@@ -118,12 +119,6 @@ export function deriveParticipantId(input) {
118
119
  participantIdDerived = true;
119
120
  return derive(input).id;
120
121
  }
121
- function headerValue(headers, name) {
122
- const raw = headers[name];
123
- if (typeof raw === 'string' && raw !== '')
124
- return raw;
125
- return null;
126
- }
127
122
  /**
128
123
  * The identity of a handshake, from its SANITIZED headers.
129
124
  *
@@ -61,6 +61,7 @@
61
61
  import { participantHandle } from '@wolffm/rooms-protocol';
62
62
  import { createChatHistoryStore } from '@wolffm/rooms-server/chat';
63
63
  import { serveRoom } from '@wolffm/rooms-server/room';
64
+ import { headerValue } from '@wolffm/service-kernel/auth';
64
65
  import { rankOf } from '../edge-auth.js';
65
66
  import { timerDelay } from '../timers.js';
66
67
  import { applyPerson } from '../people.js';
@@ -116,10 +117,6 @@ function mayJoin(lobby, place, participantId, tier) {
116
117
  return true;
117
118
  return roomAdmits(lobby.get(place.roomId), lobby.isMember(place.roomId, participantId), tier);
118
119
  }
119
- function accountOfHeaders(headers) {
120
- const id = headers['x-user-id'];
121
- return typeof id === 'string' && id !== '' ? id : undefined;
122
- }
123
120
  /**
124
121
  * The `/room` handshake floor — refused HERE, a forged or headerless socket never reaches
125
122
  * `connection` at all. `serveRoom`'s own `admit` is called only once a client has CONNECTED and
@@ -187,7 +184,7 @@ export async function attachServedRoom(io, deps) {
187
184
  const roomId = place.roomId;
188
185
  if (roomId !== null)
189
186
  lobbyRoomOf.set(socket, roomId);
190
- const accountId = accountOfHeaders(headers);
187
+ const accountId = headerValue(headers, 'x-user-id') ?? undefined;
191
188
  return {
192
189
  roomId: place.served,
193
190
  key: participantId,
@@ -24,12 +24,8 @@
24
24
  */
25
25
  import type { Server as SocketIOServer } from 'socket.io';
26
26
  import { type RoomFeedHandle } from '@wolffm/rooms-server';
27
- /** A narrow slice of `room/lobby.ts`'s `Lobby` — declared here, not imported, so this platform file carries no edge into the tangled lobby. `FileLobby` satisfies it structurally. */
28
- interface RoomFeedLobby {
29
- touch(roomId: string, memberId: string): void;
30
- isMember(roomId: string, memberId: string): boolean;
31
- onChange(listener: (roomId: string) => void): () => void;
32
- }
27
+ import type { PlatformRoomView, RoomCreateInput, RoomLobby } from './lobby.js';
28
+ type RoomFeedLobby = Pick<RoomLobby<PlatformRoomView, RoomCreateInput>, 'touch' | 'isMember' | 'onChange'>;
33
29
  interface RoomFeedDeps {
34
30
  lobby: RoomFeedLobby;
35
31
  log?: (line: Record<string, unknown>) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.212",
4
- "gitHead": "a9e2641a46c10f8803503badaf42ec88a15b23e9",
3
+ "version": "0.1.213",
4
+ "gitHead": "d8a95c3583ef6c967ef63ade32c57ae9a3b6272b",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
@@ -16,9 +16,9 @@
16
16
  "play/remote/"
17
17
  ],
18
18
  "dependencies": {
19
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.212",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.212",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.245",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.213",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.213",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.246",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
23
23
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",
24
24
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.152",