@ksaa-nlp/gamehub-sdk 3.7.0 → 3.11.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.
Files changed (40) hide show
  1. package/README.md +105 -11
  2. package/SPEC.md +201 -84
  3. package/dist/gamehub-sdk.js +174 -83
  4. package/dist/gamehub-sdk.js.map +3 -3
  5. package/dist/src/api-client.d.ts +6 -5
  6. package/dist/src/api-client.d.ts.map +1 -1
  7. package/dist/src/api-client.js +9 -8
  8. package/dist/src/api-client.js.map +1 -1
  9. package/dist/src/bridge.d.ts +10 -6
  10. package/dist/src/bridge.d.ts.map +1 -1
  11. package/dist/src/bridge.js +90 -59
  12. package/dist/src/bridge.js.map +1 -1
  13. package/dist/src/browser-entry.d.ts.map +1 -1
  14. package/dist/src/browser-entry.js +6 -5
  15. package/dist/src/browser-entry.js.map +1 -1
  16. package/dist/src/constants.d.ts +1 -1
  17. package/dist/src/constants.d.ts.map +1 -1
  18. package/dist/src/constants.js +1 -1
  19. package/dist/src/constants.js.map +1 -1
  20. package/dist/src/init.d.ts.map +1 -1
  21. package/dist/src/init.js +21 -9
  22. package/dist/src/init.js.map +1 -1
  23. package/dist/src/main.d.ts +1 -1
  24. package/dist/src/main.d.ts.map +1 -1
  25. package/dist/src/main.js +1 -0
  26. package/dist/src/main.js.map +1 -1
  27. package/dist/src/session.d.ts.map +1 -1
  28. package/dist/src/session.js +8 -3
  29. package/dist/src/session.js.map +1 -1
  30. package/dist/src/state.d.ts +2 -1
  31. package/dist/src/state.d.ts.map +1 -1
  32. package/dist/src/state.js +1 -0
  33. package/dist/src/state.js.map +1 -1
  34. package/dist/src/transport.d.ts +52 -0
  35. package/dist/src/transport.d.ts.map +1 -0
  36. package/dist/src/transport.js +130 -0
  37. package/dist/src/transport.js.map +1 -0
  38. package/dist/types/bootstrap.d.ts +9 -0
  39. package/dist/types/bootstrap.d.ts.map +1 -1
  40. package/package.json +2 -1
package/SPEC.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GameHub SDK — Specification
2
2
 
3
- Version: 3.1.0
3
+ Version: 3.11.0
4
4
  Status: Authoritative. Supersedes README/MIGRATION/CHANGELOG where they conflict.
5
5
 
6
6
  This document is the single source of truth for the GameHub SDK. Code, tests, and consumer docs follow this spec; if a behaviour is observed in code but not described here, treat it as undocumented and revisit before relying on it.
@@ -28,7 +28,8 @@ The SDK is not coupled to any realtime transport. When the host attaches a multi
28
28
  - Submit scores (`submitScore`, `submitMatchScore`) and league-match results (`submitMatchResult`).
29
29
  - Fetch questions (`getQuestions`) and words (`getWords`).
30
30
  - Request the host's report dialog for a question (`reportQuestion`) or word (`reportWord`).
31
- - Surface a bootstrap snapshot (`getBootstrap()`) including the opaque `multiplayer` block.
31
+ - Surface a bootstrap snapshot (`getBootstrap()`) including the trusted
32
+ `sessionMode` and opaque `multiplayer` block.
32
33
  - Forward player-visible host commands (`pause`, `resume`) to optional `window.onGameHubPause` / `onGameHubResume` callbacks.
33
34
  - Type definitions for authoring UGC server bundles (`./server` subpath, types-only at runtime).
34
35
  - Node-only dev harness (`./server/dev` subpath) for unit-testing a guest bundle against a simulated `ctx`.
@@ -50,24 +51,25 @@ The SDK is not coupled to any realtime transport. When the host attaches a multi
50
51
 
51
52
  The package is laid out flat under `src/` and `types/`. No subdirectories.
52
53
 
53
- | File | Responsibility |
54
- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------- |
55
- | `src/main.ts` | Public entry. Defines the `Sdk` interface and `createSdk()` factory. Pure on import. |
56
- | `src/browser-entry.ts` | The only file with side effects on import. Used by the IIFE bundle to attach `window.GameHubSDK`. |
57
- | `src/init.ts` | `detectEnvironment`, `autoInit`, `ensureInitialized`, `installHostMessageListener`. |
58
- | `src/bridge.ts` | postMessage protocol: bootstrap parsing, request/response handlers, send helper. |
59
- | `src/session.ts` | `startSession`, `submitScore`, `submitMatchScore`, `submitMatchResult`, `getQuestions`, `getWords`. |
60
- | `src/match-context.ts` | `fetchMatchContext` (HTTP `/leagues/<id>/matches/<id>`). |
61
- | `src/api-client.ts` | `apiRequest`: thin `fetch` wrapper that prefixes the API base and attaches the Bearer token. |
62
- | `src/state.ts` | `SdkState` interface + the singleton `state` object. All mutable state lives here. |
63
- | `src/constants.ts` | `SDK_VERSION`, `MESSAGE_PREFIX`, `PARENT_REQUEST_TIMEOUT_MS`, `QUESTIONS_LIMIT_CAP`, `WORDS_LIMIT_CAP`. |
64
- | `src/utils.ts` | `isBrowser`, `warn`, `error`, `unwrapResult`, `readQueryParam`. |
65
- | `types/api.ts` | `ApiResponse`, `ApiRequestOptions`. |
66
- | `types/bootstrap.ts` | `BootstrapMultiplayer`, `BootstrapConfig`, `BootstrapData`. |
67
- | `types/session.ts` | `Question`, `QuestionOptions`, `ScoreMetadata`, `EventData`, `GameCompleteData`, `StartSessionResult`, `SubmitScoreResult`, `WordOptions`, `ReportWordData`, `ReportableWord` (re-exports `Word`). |
68
- | `types/word.ts` | `Word` + sub-interfaces (`WordSense`, `WordForm`, `Lookup`, `Synset`, `FormRepresentation`, `DynamicProp`, …) — Words Bank feature. |
69
- | `types/match.ts` | `MatchParticipantMember`, `MatchParticipant`, `MatchContext`, `MatchResultPayload`. |
70
- | `src/server-entry.ts` | `./server` subpath. Types-only at runtime: `GuestModule`, `Ctx`, `PeerInfo`, `BroadcastOptions`, `EndMatchPayload`, `CreateOptions`. No imports from the browser SDK; safe for tooling that compiles the bundle on Node. |
54
+ | File | Responsibility |
55
+ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
56
+ | `src/main.ts` | Public entry. Defines the `Sdk` interface and `createSdk()` factory. Pure on import. |
57
+ | `src/browser-entry.ts` | The only file with side effects on import. Used by the IIFE bundle to attach `window.GameHubSDK`. |
58
+ | `src/init.ts` | `detectEnvironment`, `autoInit`, `ensureInitialized`, `installHostMessageListener`. |
59
+ | `src/transport.ts` | Host transport abstraction: `HostTransport` interface, `PostMessageTransport` (iframe ⇄ parent) and `NativeBridgeTransport` (`window.GameHubNativeHost`), plus `getTransport()` / `hasHost()` detection. See §6.7. |
60
+ | `src/bridge.ts` | Host protocol: builds the `GAMEHUB_SDK_*` envelopes, correlates request/response by `messageId`, send helper. Transport-independent — routes through `getTransport()`. |
61
+ | `src/session.ts` | `startSession`, `submitScore`, `submitMatchScore`, `submitMatchResult`, `getQuestions`, `getWords`. |
62
+ | `src/match-context.ts` | `fetchMatchContext` (HTTP `/leagues/<id>/matches/<id>`). |
63
+ | `src/api-client.ts` | `apiRequest`: thin `fetch` wrapper that prefixes the API base and attaches the Bearer token. |
64
+ | `src/state.ts` | `SdkState` interface + the singleton `state` object. All mutable state lives here. |
65
+ | `src/constants.ts` | `SDK_VERSION`, `MESSAGE_PREFIX`, `PARENT_REQUEST_TIMEOUT_MS`, `QUESTIONS_LIMIT_CAP`, `WORDS_LIMIT_CAP`. |
66
+ | `src/utils.ts` | `isBrowser`, `warn`, `error`, `unwrapResult`, `readQueryParam`. |
67
+ | `types/api.ts` | `ApiResponse`, `ApiRequestOptions`. |
68
+ | `types/bootstrap.ts` | `BootstrapMultiplayer`, `BootstrapConfig`, `BootstrapData`. |
69
+ | `types/session.ts` | `Question`, `QuestionOptions`, `ScoreMetadata`, `EventData`, `GameCompleteData`, `StartSessionResult`, `SubmitScoreResult`, `WordOptions`, `ReportWordData`, `ReportableWord` (re-exports `Word`). |
70
+ | `types/word.ts` | `Word` + sub-interfaces (`WordSense`, `WordForm`, `Lookup`, `Synset`, `FormRepresentation`, `DynamicProp`, …) — Words Bank feature. |
71
+ | `types/match.ts` | `MatchParticipantMember`, `MatchParticipant`, `MatchContext`, `MatchResultPayload`. |
72
+ | `src/server-entry.ts` | `./server` subpath. Types-only at runtime: `GuestModule`, `Ctx`, `PeerInfo`, `BroadcastOptions`, `EndMatchPayload`, `CreateOptions`. No imports from the browser SDK; safe for tooling that compiles the bundle on Node. |
71
73
  | `src/server-dev-harness.ts` | `./server/dev` subpath. `runLocal(guest, opts)` returns a `LocalRoom` that simulates the colyseus host (`join`, `send`, `leave`, `advance`, etc.) and records every bridge call to `outbox`. Pure Node — does not import `isolated-vm` or anything browser. |
72
74
 
73
75
  ### 3.2 Singleton model
@@ -153,43 +155,60 @@ Slug must match `[a-z0-9-]+` (case-insensitive).
153
155
 
154
156
  ## 6. Bootstrap protocol
155
157
 
156
- The SDK communicates with the host page through namespaced `postMessage` envelopes. All envelope types are `MESSAGE_PREFIX + '_' + name`, where `MESSAGE_PREFIX = 'GAMEHUB_SDK'`. The full taxonomy follows.
158
+ The SDK communicates with the host through namespaced envelopes. All envelope types are `MESSAGE_PREFIX + '_' + name`, where `MESSAGE_PREFIX = 'GAMEHUB_SDK'`. The envelope shapes and the `messageId` correlation are **transport-independent**; the wire underneath is chosen by `getTransport()` (`src/transport.ts`):
159
+
160
+ - **`postmessage`** — the game runs in an `<iframe>` and exchanges envelopes with its parent window via `window.postMessage` (the classic embedding).
161
+ - **`native`** — the game is the top-level document in a native WebView (e.g. a Flutter app) and exchanges envelopes through an injected `window.GameHubNativeHost` object. See §6.7.
162
+ - **none** — standalone (dev harness, or served from the GameHub origin). `getTransport()` returns `null` and `hasHost()` is `false`; host round-trips resolve `null` and `apiRequest` falls back to a direct `fetch`.
163
+
164
+ The full taxonomy follows. It applies to **both** transports identically.
157
165
 
158
166
  ### 6.1 Message-type taxonomy
159
167
 
160
- | Direction | Type (after prefix) | Purpose |
161
- | ---------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
162
- | SDK → host | `READY` | Fired once on script load when inside an iframe. Carries `{ version }`. |
163
- | SDK → host | `BOOTSTRAP_REQUEST` | Asks the host for bootstrap config. Carries `{ messageId }`. |
164
- | host → SDK | `BOOTSTRAP` | Bootstrap config response. Carries `{ payload: BootstrapConfig, messageId? }`. Host may also push an unsolicited one any time. |
165
- | SDK → host | `AUTH_REQUEST` | Asks the host for an auth token. Carries `{ messageId }`. |
166
- | host → SDK | `AUTH_RESPONSE` | Auth response. Carries `{ token: string \| null, leagueId?, gameId?, matchId?, messageId }`. |
167
- | host → SDK | `SET_AUTH` | Unsolicited auth update. Carries `{ token }`. Triggers session start if not already running. |
168
- | host → SDK | `COMMAND` | Player-visible host command. Carries `{ command: 'pause' \| 'resume' }`. Routed to optional `window.onGameHubPause/Resume`. |
169
- | SDK → host | `INIT` | Fired after auto-init resolves. Carries `{ slug, auto: true }`. |
170
- | SDK → host | `SESSION_STARTED` | Fired when a session token is obtained. Carries `{ token }`. |
171
- | SDK → host | `SCORE_SUBMITTED` | Fired when a score is accepted. Carries `{ score, accepted, timeTaken }`. |
172
- | SDK → host | `GAME_COMPLETE` | Fired by `sdk.notifyComplete(data?)`. Carries `data` verbatim. |
173
- | SDK → host | `REQUEST_CLOSE` | Fired by `sdk.requestClose()`. Empty payload. |
174
- | SDK → host | `LOG_EVENT` | Fired by `sdk.logEvent(name, data?)`. Carries `{ event, data }`. |
175
- | SDK → host | `QUESTION_REPORT` | Fired by `sdk.reportQuestion(data)`. Carries `{ questionId?, prompt?, message?, questions? }`. With `questions` the host renders a question-picker dropdown; otherwise it reports the single `questionId`. |
176
- | SDK → host | `WORD_REPORT` | Fired by `sdk.reportWord(data)` (Words Bank feature). Carries `{ wordId?, lemma?, message?, words? }`. Same picker/single semantics as `QUESTION_REPORT`, relabeled to lemma. |
177
- | SDK → host | `API_REQUEST` | Asks the host to proxy a backend HTTP call. Carries `{ messageId, endpoint, method, body }`. See §6.6. |
178
- | host → SDK | `API_RESPONSE` | Result of a proxied call. Carries `{ messageId, ok: boolean, result?: ApiResponse, error?: string }`. See §6.6. |
168
+ | Direction | Type (after prefix) | Purpose |
169
+ | ---------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
170
+ | SDK → host | `READY` | Fired once on script load when a host transport is present (`hasHost()`). Carries `{ version }`. |
171
+ | SDK → host | `BOOTSTRAP_REQUEST` | Asks the host for bootstrap config. Carries `{ messageId }`. |
172
+ | host → SDK | `BOOTSTRAP` | Bootstrap config response. The initial response carries `{ payload: BootstrapConfig, messageId }` and must echo `BOOTSTRAP_REQUEST.messageId`. After the parent origin is pinned, the host may push an unsolicited update without `messageId`. |
173
+ | SDK → host | `AUTH_REQUEST` | Asks the host for an auth token. Carries `{ messageId }`. |
174
+ | host → SDK | `AUTH_RESPONSE` | Auth response. Carries `{ token: string \| null, leagueId?, gameId?, matchId?, messageId }`. |
175
+ | host → SDK | `SET_AUTH` | Unsolicited auth update. Carries `{ token }`. Triggers session start if not already running. |
176
+ | host → SDK | `COMMAND` | Player-visible host command. Carries `{ command: 'pause' \| 'resume' }`. Routed to optional `window.onGameHubPause/Resume`. |
177
+ | SDK → host | `INIT` | Fired after auto-init resolves. Carries `{ slug, auto: true }`. |
178
+ | SDK → host | `SESSION_STARTED` | Fired when a session token is obtained. Carries `{ token }`. |
179
+ | SDK → host | `SCORE_SUBMITTED` | Fired when a score is accepted. Carries `{ score, accepted, timeTaken }`. |
180
+ | SDK → host | `GAME_COMPLETE` | Fired by `sdk.notifyComplete(data?)`. Carries `data` verbatim. |
181
+ | SDK → host | `REQUEST_CLOSE` | Fired by `sdk.requestClose()`. Empty payload. |
182
+ | SDK → host | `LOG_EVENT` | Fired by `sdk.logEvent(name, data?)`. Carries `{ event, data }`. |
183
+ | SDK → host | `QUESTION_REPORT` | Fired by `sdk.reportQuestion(data)`. Carries `{ questionId?, prompt?, message?, questions? }`. With `questions` the host renders a question-picker dropdown; otherwise it reports the single `questionId`. |
184
+ | SDK → host | `WORD_REPORT` | Fired by `sdk.reportWord(data)` (Words Bank feature). Carries `{ wordId?, lemma?, message?, words? }`. Same picker/single semantics as `QUESTION_REPORT`, relabeled to lemma. |
185
+ | SDK → host | `API_REQUEST` | Asks the host to proxy a backend HTTP call. Carries `{ messageId, endpoint, method, body }`. See §6.6. |
186
+ | host → SDK | `API_RESPONSE` | Result of a proxied call. Carries `{ messageId, ok: boolean, result?: ApiResponse, error?: string }`. See §6.6. |
187
+
188
+ The production GameHub play host uses these existing envelopes, together with
189
+ successful SDK API routes, to aggregate per-game feature observations for the
190
+ admin SDK-usage report. This is host behavior only: the SDK emits no additional
191
+ telemetry and its wire protocol/version is unchanged. The report contract and
192
+ feature-to-observation map live in
193
+ [`../../specs/sdk-usage-report.md`](../../specs/sdk-usage-report.md).
179
194
 
180
195
  Every SDK → host envelope also includes the resolved `gameSlug` as a top-level field (except `API_REQUEST`, whose payload is the proxied request).
181
196
 
182
197
  ### 6.2 Origin handling
183
198
 
184
- The SDK fires the initial `BOOTSTRAP_REQUEST` with target origin `'*'` because it has not yet learned the parent's origin. The very first `BOOTSTRAP` reply records `event.origin` into `state.parentOrigin`. All subsequent SDK → host messages target that recorded origin. Calls before any inbound message fall back to `'*'`.
199
+ Origin handling is a property of the **postMessage** transport only. Every inbound browser message must have `event.source === window.parent`; messages from ancestors, sibling frames, popups, and unrelated windows are ignored. This direct-parent check applies before any envelope-specific handler runs.
200
+
201
+ The SDK fires the initial `BOOTSTRAP_REQUEST` with target origin `'*'` because it has not yet learned the parent's origin. The host must echo its `messageId`. A valid correlated `BOOTSTRAP`, `AUTH_RESPONSE`, or `API_RESPONSE` from the direct parent pins `event.origin` into `state.parentOrigin`. Empty/opaque (`'null'`) origins do not establish the browser trust boundary. All subsequent SDK → host messages target the pinned origin, and all inbound messages from a different origin are ignored.
185
202
 
186
- If `event.origin` changes mid-session (e.g. the host navigates between origins), `state.parentOrigin` is overwritten by the next inbound message. There is no origin allowlist; the SDK trusts whatever the parent reports. This is acceptable because the iframe contents are themselves served by GameHub.
203
+ The origin pin is immutable for the lifetime of the game document. If the host navigates to another origin, the existing SDK instance does not follow it; a fresh game document is required. Unsolicited `BOOTSTRAP`, `SET_AUTH`, and `COMMAND` messages are accepted only after the origin has been pinned and only from the same direct parent/origin.
204
+
205
+ On the **native** transport there is no web origin: inbound `HostMessage.origin` is `null`, `state.parentOrigin` stays `null`, and the transport ignores it when sending (it posts through `window.GameHubNativeHost`). The trust boundary is the native app itself, which owns the WebView and injects the bridge.
187
206
 
188
207
  ### 6.3 Request/response correlation
189
208
 
190
209
  - Each SDK-initiated request includes a `messageId: string` (currently `Date.now().toString()`).
191
- - The host's response must echo the same `messageId`. The SDK's `requestBootstrapFromParent` and `getAuthTokenFromParent` ignore messages with a mismatched `messageId`.
192
- - The host may push an unsolicited `BOOTSTRAP` with no `messageId`; the SDK still merges it.
210
+ - The host's response must echo the same `messageId`. Bootstrap, auth, and API request handlers ignore missing or mismatched IDs.
211
+ - The host may push an unsolicited `BOOTSTRAP` with no `messageId` only after a correlated response has pinned the direct parent origin.
193
212
  - Each request has a `PARENT_REQUEST_TIMEOUT_MS` (2000 ms) timeout. On timeout the promise resolves to `null` (bootstrap) or `null` (auth); the SDK does not retry.
194
213
 
195
214
  ### 6.4 Bootstrap merge semantics
@@ -202,8 +221,15 @@ If `event.origin` changes mid-session (e.g. the host navigates between origins),
202
221
  - Non-string and non-null → ignored (field left as-is).
203
222
  - `multiplayer`:
204
223
  - Explicit `null` → `null`.
205
- - Object with `roomCode`, `reconnectionToken`, `wsEndpoint` all strings → trimmed and stored.
224
+ - Object with a `reservation` object (string `name`, `sessionId`, `roomId` — the `SdkSeatReservation` shape) and a string `wsEndpoint` → only `wsEndpoint` is trimmed; the `reservation` object is stored as-is.
225
+ - Optional `roomCode`, `role`, and `connectionScope` strings are copied only
226
+ when non-empty and bounded. `connectionScope` lets a game partition its own
227
+ reconnect storage by public embed and outer-host instance; the SDK neither
228
+ stores nor interprets it.
206
229
  - Any other shape → ignored (field left as-is).
230
+ - `sessionMode` accepts only `'authenticated'`, `'embed-guest'`,
231
+ `'league-guest'`, or explicit `null`; every other value is ignored. The
232
+ trusted host, not uploaded game code, selects this authority mode.
207
233
 
208
234
  This lets the host clear fields explicitly (via `null`) without overwriting unset fields.
209
235
 
@@ -211,7 +237,7 @@ This lets the host clear fields explicitly (via `null`) without overwriting unse
211
237
 
212
238
  1. **Idle.** `state.bootstrapReceived = false`.
213
239
  2. **Request.** First call to `requestBootstrapFromParent()` posts `BOOTSTRAP_REQUEST` and starts the timeout.
214
- 3. **Response.** Host replies with `BOOTSTRAP`. `state.bootstrapReceived = true`. `parentOrigin` recorded.
240
+ 3. **Response.** Host replies with `BOOTSTRAP` carrying the matching `messageId`. `state.bootstrapReceived = true`; the direct parent's non-opaque origin is pinned.
215
241
  4. **Cache.** Subsequent calls return `snapshotBootstrap()` synchronously (wrapped in a resolved promise).
216
242
  5. **Update.** Any later unsolicited `BOOTSTRAP` from the host triggers `mergeBootstrapConfig` without affecting `bootstrapReceived`. Existing callers do not get re-notified.
217
243
 
@@ -223,18 +249,50 @@ The SDK never issues a cross-origin request to the GameHub backend. When a game
223
249
 
224
250
  `apiRequest(endpoint, options)` (`src/api-client.ts`) chooses its transport by context:
225
251
 
226
- - **Embedded** (`window.parent !== window`): delegates to `requestApiFromParent(endpoint, options)` (`src/bridge.ts`). This posts `API_REQUEST` `{ messageId, endpoint, method, body }` to the parent and awaits the matching `API_RESPONSE`.
227
- - **Standalone** (dev harness, or a game served from the GameHub origin): the legacy direct `fetch` path against `state.apiBase`, attaching `Authorization: Bearer <token>` (§7.2). This path is same-origin by construction, so CORS does not apply.
252
+ - **Hosted** (`hasHost()` — iframe parent or native bridge): delegates to `requestApiFromParent(endpoint, options)` (`src/bridge.ts`). This sends `API_REQUEST` `{ messageId, endpoint, method, body }` to the host and awaits the matching `API_RESPONSE`. On the native transport the host is the native app, which performs the real HTTPS call and keeps the bearer token out of the WebView entirely.
253
+ - **Standalone** (dev harness, or a game served from the GameHub origin): the direct `fetch` path against `state.apiBase`, attaching `Authorization: Bearer <token>` (§7.2). This path is same-origin by construction, so CORS does not apply.
228
254
 
229
255
  Protocol details:
230
256
 
231
- - `endpoint` is the path **after** `/api` (e.g. `/sessions/start`), exactly as passed to `apiRequest`. The host prepends its own same-origin API base. The host **must reject** any `endpoint` that is not a relative path (does not start with `/`, or starts with `//`) so the iframe cannot use the host as an open proxy.
257
+ - `endpoint` is the path **after** `/api` (e.g. `/sessions/start`), exactly as passed to `apiRequest`. The host prepends its own same-origin API base. The host must use a method/path/query/body allowlist for the documented SDK REST surface (§16), bind game/league/match identifiers to trusted bootstrap context, and reject absolute/protocol-relative paths, traversal encodings, unknown queries, and unrelated GameHub APIs. A relative-path check alone is not sufficient because uploaded game code is untrusted.
258
+ - A public embed host may translate the ordinary `/sessions/start` and
259
+ `/sessions/submit` requests to its guest or authenticated embed endpoints.
260
+ That translation binds the request to host-owned embed, guest/auth session,
261
+ publisher origin, and host instance; it does not change the SDK-facing
262
+ endpoint or game integration.
232
263
  - `body` is the unserialised request body (or `null`); the host serialises it.
233
- - The host attaches authentication from **its own** auth context (it holds the same token it bootstrapped to the SDK). The SDK does not send the bearer token in `API_REQUEST`.
264
+ - The host attaches authority from **its own** context. For authenticated
265
+ external embeds this is an opaque embed credential held only in outer-host
266
+ memory; it is never added to bootstrap or an `API_REQUEST`.
234
267
  - `API_RESPONSE.ok === true` carries the parsed JSON envelope in `result`; the promise resolves with it. `ok === false` carries an `error` string; the promise rejects. The per-call `try/catch` blocks in `session.ts` / `match-context.ts` turn either outcome into the usual degraded result — public methods still never throw (§17).
235
268
  - Timeout is `HOST_API_TIMEOUT_MS` (15 000 ms), larger than the 2 s bootstrap/auth timeout because the round-trip includes the host's real network call. On timeout the promise rejects and the call degrades.
236
269
  - `messageId` is `'api_' + Date.now() + '_' + <seq>`, where `<seq>` is a monotonic counter so concurrent proxied calls (e.g. session start + questions) never collide.
237
270
 
271
+ ### 6.7 Native bridge transport
272
+
273
+ When a game is rendered in a native WebView rather than an iframe, the native app plays the host role. Because the game is the **top-level document** (`window.parent === window`), the postMessage transport is unavailable; the SDK instead talks to an injected `window.GameHubNativeHost` object.
274
+
275
+ **Detection.** `getTransport()` selects the native transport when `window.GameHubNativeHost.postMessage` is a function. This is checked **before** the iframe check, so a native host always wins. The native app must inject the object **before** the SDK script runs (e.g. a WebView user-script evaluated at document start), otherwise the SDK falls through to standalone.
276
+
277
+ **Contract.** The object is bidirectional:
278
+
279
+ ```ts
280
+ interface GameHubNativeHost {
281
+ // game → host. The SDK calls this with a JSON-stringified envelope.
282
+ postMessage(json: string): void;
283
+ // host → game. The SDK installs this; the native app invokes it (via the
284
+ // WebView's "evaluate JavaScript" channel) with one envelope, either as a
285
+ // JSON string or an already-parsed object.
286
+ receive?(envelope: string | object): void;
287
+ }
288
+ ```
289
+
290
+ - The native app implements `postMessage` (typically forwarding to its WebView message channel — e.g. `flutter_inappwebview`'s `callHandler`).
291
+ - The SDK installs `receive` when the transport is constructed. The native app calls `window.GameHubNativeHost.receive(env)` to deliver every host → SDK envelope (`BOOTSTRAP`, `AUTH_RESPONSE`, `API_RESPONSE`, `SET_AUTH`, `COMMAND`).
292
+ - Envelope shapes, `messageId` correlation, and timeouts (§6.3) are identical to the postMessage transport. The native host must therefore echo the `messageId` on `BOOTSTRAP`/`AUTH_RESPONSE`/`API_RESPONSE` exactly as an iframe host does.
293
+ - The native host is responsible for the same protocol an iframe host implements: replying to `BOOTSTRAP_REQUEST`/`AUTH_REQUEST`, proxying `API_REQUEST` (performing the real HTTPS call natively — see §6.6), and reacting to one-way signals (`REQUEST_CLOSE`, `QUESTION_REPORT`, `WORD_REPORT`, `SCORE_SUBMITTED`, `GAME_COMPLETE`, `LOG_EVENT`).
294
+ - Multiplayer is unchanged: the host passes `bootstrap.multiplayer` `{ reservation, wsEndpoint }`, and the game opens its own Colyseus WebSocket from inside the WebView (§19.1). The SDK does not proxy realtime traffic over the bridge.
295
+
238
296
  ## 7. Authentication
239
297
 
240
298
  ### 7.1 Token sources
@@ -249,7 +307,7 @@ The SDK never reads the token from storage and never writes it. Each page load s
249
307
 
250
308
  ### 7.2 Sending the token
251
309
 
252
- On the **standalone** transport, when `state.authToken` is non-null, `apiRequest` attaches `Authorization: Bearer <token>` to every outbound HTTP request. On the **host-proxied** transport (§6.6, the embedded default) the host attaches the bearer header from its own auth context instead. Either way the SDK does not parse the token, refresh it, or check its expiry. A 401 from the server is a normal failed response; the SDK surfaces the error and does not retry.
310
+ On the **standalone** transport, when `state.authToken` is non-null, `apiRequest` attaches `Authorization: Bearer <token>` to every outbound HTTP request. On the **host-proxied** transport (§6.6, the hosted default — iframe or native) the host attaches the bearer header from its own auth context instead. A native host can therefore keep the token entirely outside the WebView. Either way the SDK does not parse the token, refresh it, or check its expiry. A 401 from the server is a normal failed response; the SDK surfaces the error and does not retry.
253
311
 
254
312
  ### 7.3 Token rotation
255
313
 
@@ -261,16 +319,18 @@ If the host posts `SET_AUTH` mid-session, the new token is used for subsequent r
261
319
 
262
320
  `startSession()` picks one of three endpoints from the active context:
263
321
 
264
- | Condition | Endpoint | Body |
265
- | ----------------------------------- | ---------------------------------------------------- | -------------- |
266
- | `leagueId && gameId && matchId` | `POST /leagues/<leagueId>/matches/<matchId>/session` | `{ gameId }` |
267
- | `leagueId && gameId` (no `matchId`) | `POST /leagues/<leagueId>/sessions` | `{ gameId }` |
268
- | otherwise | `POST /sessions/start` | `{ gameSlug }` |
322
+ | Condition | Endpoint | Body |
323
+ | ----------------------------------------- | ---------------------------------------------------- | -------------- |
324
+ | `leagueId && gameId && matchId` | `POST /leagues/<leagueId>/matches/<matchId>/session` | `{ gameId }` |
325
+ | `leagueId && gameId` (no `matchId`) | `POST /leagues/<leagueId>/sessions` | `{ gameId }` |
326
+ | otherwise (including trusted embed modes) | `POST /sessions/start` | `{ gameSlug }` |
269
327
 
270
328
  ### 8.2 Preconditions
271
329
 
272
330
  - `gameSlug` must be non-null. If null, `startSession` returns `{ success: false, error: 'Game slug not set' }` synchronously.
273
- - Auth is required unless this is a league-match session (`leagueId && gameId && matchId`), which allows guest play.
331
+ - Auth is required unless this is a league-match session (`leagueId && gameId && matchId`) or the trusted bootstrap selected `sessionMode === 'embed-guest'` or `sessionMode === 'authenticated'`. In authenticated embed mode the trusted outer host, not the SDK, owns the credential.
332
+ - A game cannot opt itself into guest authority: unsupported bootstrap values
333
+ are ignored, and standalone unauthenticated behavior is unchanged.
274
334
 
275
335
  ### 8.3 Idempotency
276
336
 
@@ -280,7 +340,7 @@ Once `state.sessionToken` is non-null, subsequent `startSession()` calls short-c
280
340
 
281
341
  A session is opened by any of:
282
342
 
283
- - `autoInit()` (when auth or league-match context is present).
343
+ - `autoInit()` (when auth, a trusted authenticated/embed-guest mode, or league-match context is present).
284
344
  - The host posting `SET_AUTH` (when the slug is known and no session is already running).
285
345
  - Any score-submitting call that finds no session.
286
346
  - An explicit `sdk.startSession()` call.
@@ -364,7 +424,7 @@ The HTTP league-match surface (`getMatchContext`, `submitMatchResult`) is indepe
364
424
  ### 11.1 `getQuestions(options?)`
365
425
 
366
426
  - Awaits `ensureInitialized()`.
367
- - Identifier is `state.gameId || state.gameSlug`. Returns `[]` if both are null.
427
+ - Identifier is `state.gameSlug || state.gameId`. Returns `[]` if both are null.
368
428
  - Validates `options.difficulty` against `'easy' | 'medium' | 'hard'`. Returns `[]` on mismatch.
369
429
  - Validates `options.limit` is a positive number. Returns `[]` on mismatch.
370
430
  - GETs `/games/<identifier>/questions?limit=<n>&random=true[&gameId=…][&difficulty=…][&category=…][&profileId=…]`.
@@ -396,7 +456,7 @@ interface Question {
396
456
  ### 11bis.1 `getWords(options?)`
397
457
 
398
458
  Mirrors `getQuestions`. Awaits `ensureInitialized()`; identifier is
399
- `state.gameId || state.gameSlug` (returns `[]` if both null). Validates
459
+ `state.gameSlug || state.gameId` (returns `[]` if both null). Validates
400
460
  `options.difficulty` and `options.limit` the same way (returns `[]` on
401
461
  mismatch). GETs
402
462
  `/games/<identifier>/words?limit=<n>&random=true[&gameId=…][&difficulty=…][&category=…][&tags=a,b][&profileId=…]`.
@@ -458,6 +518,7 @@ interface SdkState {
458
518
  leagueId: string | null;
459
519
  gameId: string | null;
460
520
  matchId: string | null;
521
+ bootstrapSessionMode: BootstrapSessionMode | null;
461
522
 
462
523
  // Free-form bootstrap fields
463
524
  bootstrapMode: string | null;
@@ -540,16 +601,17 @@ interface SdkState {
540
601
 
541
602
  ### 14.6 Host signalling
542
603
 
543
- | Method | Returns | Postmessage emitted (after prefix) |
544
- | --------------------------------- | ------- | ------------------------------------------------- |
545
- | `notifyComplete(data?)` | `void` | `GAME_COMPLETE` |
546
- | `requestClose()` | `void` | `REQUEST_CLOSE` |
547
- | `logEvent(eventName, eventData?)` | `void` | `LOG_EVENT { event: eventName, data: eventData }` |
604
+ | Method | Returns | Postmessage emitted (after prefix) |
605
+ | --------------------------------- | ------- | ---------------------------------------------------------------- |
606
+ | `notifyComplete(data?)` | `void` | `GAME_COMPLETE` |
607
+ | `requestClose()` | `void` | `REQUEST_CLOSE` |
608
+ | `logEvent(eventName, eventData?)` | `void` | `LOG_EVENT { event: eventName, data: eventData }` |
548
609
  | `reportQuestion(data)` | `void` | `QUESTION_REPORT { questionId?, prompt?, message?, questions? }` |
549
610
 
550
611
  `reportQuestion(data: ReportQuestionData)` asks the host to open its "report this question" dialog. The host owns the dialog (the SDK renders no DOM — see §19.3) and submits the report, collecting the reason, an optional message, and — for guests — name/email. Like the other host signals it no-ops outside an iframe.
551
612
 
552
613
  Two modes:
614
+
553
615
  - **Single question** — pass `questionId` (and optionally `prompt`). The dialog reports that one question.
554
616
  - **Pick from a list** — pass `questions: ReportableQuestion[]` (each `{ questionId, prompt? }`). The host renders a dropdown so the player chooses which question to report; `questionId`, when also supplied, pre-selects an entry. The `questions` array is forwarded verbatim (each entry normalised to `{ questionId, prompt }`) on the `QUESTION_REPORT` envelope.
555
617
 
@@ -568,10 +630,22 @@ All types listed below are re-exported from the package root and form the public
568
630
  ### 15.1 Bootstrap
569
631
 
570
632
  ```ts
633
+ interface SdkSeatReservation {
634
+ name: string;
635
+ sessionId: string;
636
+ roomId: string;
637
+ processId?: string;
638
+ publicAddress?: string;
639
+ reconnectionToken?: string;
640
+ devMode?: boolean;
641
+ }
642
+
571
643
  interface BootstrapMultiplayer {
572
- roomCode: string;
573
- reconnectionToken: string;
644
+ reservation: SdkSeatReservation;
574
645
  wsEndpoint: string;
646
+ roomCode?: string;
647
+ role?: string;
648
+ connectionScope?: string;
575
649
  }
576
650
 
577
651
  interface BootstrapConfig {
@@ -580,6 +654,7 @@ interface BootstrapConfig {
580
654
  leagueId?: string | null;
581
655
  gameId?: string | null;
582
656
  matchId?: string | null;
657
+ sessionMode?: BootstrapSessionMode | null;
583
658
  mode?: string | null;
584
659
  playerName?: string | null;
585
660
  playerCount?: string | null;
@@ -595,6 +670,7 @@ interface BootstrapData {
595
670
  leagueId: string | null;
596
671
  gameId: string | null;
597
672
  matchId: string | null;
673
+ sessionMode: BootstrapSessionMode | null;
598
674
  mode: string | null;
599
675
  playerName: string | null;
600
676
  playerCount: string | null;
@@ -604,6 +680,8 @@ interface BootstrapData {
604
680
  multiplayer: BootstrapMultiplayer | null;
605
681
  isBootstrapped: boolean;
606
682
  }
683
+
684
+ type BootstrapSessionMode = 'authenticated' | 'embed-guest' | 'league-guest';
607
685
  ```
608
686
 
609
687
  ### 15.2 Session / scoring
@@ -715,14 +793,14 @@ interface ApiRequestOptions {
715
793
 
716
794
  The SDK assumes the GameHub server exposes the following endpoints. When embedded these are reached via the host proxy (§6.6); standalone they are reached directly under `state.apiBase`. Either way the SDK calls `apiRequest` with the same `endpoint` path. Any change to these contracts must be coordinated server-side and is a major-version event for the SDK.
717
795
 
718
- | Method | Path | Auth | Request body | Successful response shape |
719
- | ------ | ----------------------------------------------- | -------- | ------------------------ | ------------------------------------------------------------------ |
720
- | POST | `/sessions/start` | Bearer | `{ gameSlug }` | `{ success: true, data: { token } }` or `{ success: true, token }` |
721
- | POST | `/leagues/<leagueId>/sessions` | Bearer | `{ gameId }` | as above |
722
- | POST | `/leagues/<leagueId>/matches/<matchId>/session` | optional | `{ gameId }` | as above (guest sessions allowed) |
723
- | POST | `/sessions/submit` | optional | `{ token, score, meta }` | `{ success: true, data: { accepted, timeTaken } }` |
724
- | GET | `/games/<id-or-slug>/questions?…` | optional | n/a | `Question[]` or `{ questions: Question[] }` |
725
- | GET | `/leagues/<leagueId>/matches/<matchId>` | optional | n/a | `{ success: true, data: MatchContext }` |
796
+ | Method | Path | Auth | Request body | Successful response shape |
797
+ | ------ | ----------------------------------------------- | ---------------------------------- | ------------------------ | ------------------------------------------------------------------ |
798
+ | POST | `/sessions/start` | Bearer or trusted embed-guest host | `{ gameSlug }` | `{ success: true, data: { token } }` or `{ success: true, token }` |
799
+ | POST | `/leagues/<leagueId>/sessions` | Bearer | `{ gameId }` | as above |
800
+ | POST | `/leagues/<leagueId>/matches/<matchId>/session` | optional | `{ gameId }` | as above (guest sessions allowed) |
801
+ | POST | `/sessions/submit` | optional | `{ token, score, meta }` | `{ success: true, data: { accepted, timeTaken } }` |
802
+ | GET | `/games/<id-or-slug>/questions?…` | optional | n/a | `Question[]` or `{ questions: Question[] }` |
803
+ | GET | `/leagues/<leagueId>/matches/<matchId>` | optional | n/a | `{ success: true, data: MatchContext }` |
726
804
 
727
805
  ### 16.1 Response envelope
728
806
 
@@ -757,7 +835,9 @@ These rules exist because of a real prior regression where transport-related cle
757
835
 
758
836
  - The SDK must not import any realtime client (`@colyseus/sdk`, `ws`, `socket.io-client`, …).
759
837
  - The SDK must not open a `WebSocket`, `EventSource`, or `RTCPeerConnection`.
760
- - The `bootstrapMultiplayer` field is opaque. The SDK validates only its shape (three strings); it does not parse or interpret the values.
838
+ - The `bootstrapMultiplayer` field is opaque. The SDK validates the reservation,
839
+ endpoint, and optional bounded room/role/scope strings; it does not parse or
840
+ interpret them.
761
841
  - The server-clock helper (`attachServerClock`) belongs in `@ksaa-nlp/colyseus-schemas/clock`, not here.
762
842
 
763
843
  ### 19.2 HTTP plumbing is transport-agnostic
@@ -769,7 +849,7 @@ These rules exist because of a real prior regression where transport-related cle
769
849
  ### 19.3 No DOM injection
770
850
 
771
851
  - The SDK must not create, modify, or query DOM elements outside reading `window.location` and the `<script>` tag list during environment detection.
772
- - The SDK must not register global event listeners outside the single `message` listener installed by `installHostMessageListener()`.
852
+ - On the postMessage transport, the SDK must not register global event listeners outside the `message` listeners its transport installs (the ambient one from `installHostMessageListener()` plus the short-lived per-request handlers in `bridge.ts`, each removed on settle/timeout). On the native transport it touches only `window.GameHubNativeHost` (reading `postMessage`, installing `receive`) — no DOM and no `window` event listeners.
773
853
 
774
854
  ### 19.4 No storage
775
855
 
@@ -794,7 +874,7 @@ These rules exist because of a real prior regression where transport-related cle
794
874
 
795
875
  ### 20.3 Bundle budget
796
876
 
797
- The IIFE bundle (`dist/gamehub-sdk.js`) is expected to remain under **25 KB raw / 10 KB gzip** in the absence of new feature areas. Crossing that threshold should be a deliberate decision tied to a release note. Current size: ~20 KB raw.
877
+ The IIFE bundle (`dist/gamehub-sdk.js`) is expected to remain under **10 KB gzip**, the figure that matters on the wire. The raw budget was historically **25 KB**; the native-bridge transport added in 3.8.0 (a deliberate new feature area — §6.7) pushed raw past that historical target. Current 3.11.0 size: 27,997 bytes raw / 6,285 bytes gzip. Further growth should be a deliberate decision tied to a release note, and gzip remains the hard ceiling.
798
878
 
799
879
  ### 20.4 No runtime dependencies
800
880
 
@@ -802,7 +882,7 @@ The IIFE bundle (`dist/gamehub-sdk.js`) is expected to remain under **25 KB raw
802
882
 
803
883
  ## 21. Testing acceptance criteria
804
884
 
805
- The SDK does not currently ship a test suite, but every change should be verifiable against this checklist:
885
+ The SDK ships focused Node tests for transport trust-boundary behavior. Every change should also be verifiable against this checklist:
806
886
 
807
887
  ### 21.1 Pure-import safety
808
888
 
@@ -813,25 +893,44 @@ The SDK does not currently ship a test suite, but every change should be verifia
813
893
 
814
894
  - `autoInit()` resolves `false` and logs the slug-not-found warning when the page is not under `/games/<slug>/`.
815
895
  - Score-submit calls in this state return `{ success: false, error }` and never throw.
896
+ - Setting `sessionMode: 'embed-guest'` through trusted bootstrap permits the
897
+ ordinary session call; an absent or invalid mode leaves anonymous
898
+ standalone calls denied.
899
+ - Setting `sessionMode: 'authenticated'` through trusted bootstrap permits
900
+ session auto-start without an SDK-visible JWT. The host must supply the
901
+ authority when proxying; standalone code cannot manufacture that authority.
816
902
 
817
903
  ### 21.3 Iframe boot
818
904
 
819
905
  - The iframe receives a `BOOTSTRAP_REQUEST` from the SDK within ~100 ms of script load.
820
- - Replying with `BOOTSTRAP { payload: { gameSlug } }` causes `getBootstrap().isBootstrapped` to flip to `true` and `getGameSlug()` to return the value.
906
+ - Replying from `window.parent` with `BOOTSTRAP { messageId, payload: { gameSlug } }`, echoing the request ID, causes `getBootstrap().isBootstrapped` to flip to `true` and `getGameSlug()` to return the value.
821
907
  - Replying with `AUTH_RESPONSE { token }` makes `isAuthenticated()` true.
822
908
  - Posting `SET_AUTH { token }` after init opens a session and fires `SESSION_STARTED`.
909
+ - A message from a window other than `window.parent` is ignored even when its envelope and `messageId` otherwise look valid.
910
+ - After the direct parent origin is pinned, a message from the same parent window with a different `event.origin` is ignored and cannot replace `state.parentOrigin`.
911
+
912
+ ### 21.3b Native bridge boot
913
+
914
+ - With `window.GameHubNativeHost = { postMessage(json) { … } }` injected before the SDK loads (and `window.parent === window`), `getTransport().kind === 'native'` and `hasHost()` is `true`.
915
+ - The SDK calls `GameHubNativeHost.postMessage` with a JSON-stringified `BOOTSTRAP_REQUEST` on boot. Calling `window.GameHubNativeHost.receive(JSON.stringify({ type: 'GAMEHUB_SDK_BOOTSTRAP', messageId, payload: { gameSlug } }))` (echoing the requested `messageId`) flips `getBootstrap().isBootstrapped` to `true`.
916
+ - `receive` accepts both a JSON string and an already-parsed object; malformed strings are ignored without throwing.
917
+ - `apiRequest` travels as an `API_REQUEST` over `postMessage`, and the native host's `API_RESPONSE` (delivered via `receive`) resolves/rejects it identically to the iframe path.
823
918
 
824
919
  ### 21.4 Score submission
825
920
 
826
921
  - `submitScore(42, { level: 3 })` causes a POST to `/api/sessions/submit` with `{ token, score: 42, meta: { level: 3 } }` and Bearer auth. When embedded (the default), this travels as an `API_REQUEST` `{ endpoint: '/sessions/submit', method: 'POST', body: { … } }` and the **host** performs the POST with its own bearer auth (§6.6); standalone, the SDK POSTs directly.
827
922
  - Returns `{ success: true, accepted: true, timeTaken: <n> }` on a `{ success: true, data: { accepted: true, timeTaken: 1234 } }` server response.
828
923
  - Fires `SCORE_SUBMITTED { score: 42, accepted: true, timeTaken: 1234 }` to the host.
924
+ - In public embed mode, the game still emits `/sessions/start` and
925
+ `/sessions/submit`; the host binds and rewrites those requests for guest or
926
+ authenticated play. The SDK never creates or stores the embed guest ID,
927
+ authorization code, or opaque authenticated credential.
829
928
 
830
929
  ### 21.4b Host-proxied transport (embedded)
831
930
 
832
931
  - Inside an iframe, no public method issues a direct cross-origin `fetch`; each `apiRequest` posts an `API_REQUEST` and resolves on the matching `API_RESPONSE`.
833
932
  - A host that never replies leaves the call pending until `HOST_API_TIMEOUT_MS` (15 s), after which it degrades to the usual failure shape.
834
- - An `API_RESPONSE { ok: false, error }` degrades identically. The host must reject endpoints that aren't relative API paths.
933
+ - An `API_RESPONSE { ok: false, error }` degrades identically. The host must reject requests outside the documented SDK REST method/path/query/body allowlist, even when the endpoint is a relative GameHub API path.
835
934
 
836
935
  ### 21.5 League-match path
837
936
 
@@ -844,6 +943,20 @@ The SDK does not currently ship a test suite, but every change should be verifia
844
943
  - `grep -rn "@colyseus" src/ types/` returns only comment references (no import statements).
845
944
  - `npm pack --dry-run` produces a tarball whose `peerDependencies` and `dependencies` are both empty/absent.
846
945
 
946
+ ### 21.7 SDK Usage Intelligence Report synchronization
947
+
948
+ Every new public SDK method, alias, or capability must be represented in the
949
+ GameHub SDK Usage Intelligence Report in the same change. This is part of the
950
+ definition of done for a public API addition, not optional follow-up work.
951
+
952
+ The authoritative maintenance checklist is
953
+ [`../../specs/sdk-usage-report.md` §4.1](../../specs/sdk-usage-report.md#41-mandatory-synchronization-for-new-sdk-apis).
954
+ At minimum, the change must update the report inventory and labels, static
955
+ scanner registry/version, runtime-observation strategy where applicable,
956
+ admin contract/UI/CSV, automated tests, and both package specifications. A
957
+ method that cannot cross an observable host or server boundary must be
958
+ explicitly classified as static-only.
959
+
847
960
  ## 21bis. UGC server bundle subpath
848
961
 
849
962
  The `./server` and `./server/dev` subpaths are separate from the browser SDK. Importing them has **no overlap** with the iframe runtime — they target the colyseus UGC sandbox, not the browser host.
@@ -856,8 +969,12 @@ The `./server` and `./server/dev` subpaths are separate from the browser SDK. Im
856
969
  import type { GuestModule, Ctx, PeerInfo } from '@ksaa-nlp/gamehub-sdk/server';
857
970
 
858
971
  const guest: GuestModule = {
859
- onCreate(ctx, opts) { ctx.state.round = 0; },
860
- onJoin(ctx, peer) { ctx.broadcast('peer:joined', { peerId: peer.peerId }); },
972
+ onCreate(ctx, opts) {
973
+ ctx.state.round = 0;
974
+ },
975
+ onJoin(ctx, peer) {
976
+ ctx.broadcast('peer:joined', { peerId: peer.peerId });
977
+ },
861
978
  onMessage(ctx, peer, type, payload) {
862
979
  if (type === 'answer') ctx.send(peer.peerId, 'ack', { ok: true });
863
980
  },
@@ -903,7 +1020,7 @@ expect(room.outbox).toContainEqual({
903
1020
  - **Bootstrap.** The set of context the host gives the iframe at load: slug, IDs, auth, multiplayer block, display strings.
904
1021
  - **Session.** A server-issued token representing a single playthrough. Used to authenticate `submitScore`.
905
1022
  - **League match.** A scheduled game between two participants tracked by GameHub's league system. Has its own session endpoint that allows guest submitters.
906
- - **Multiplayer block.** The opaque `{ roomCode, reconnectionToken, wsEndpoint }` triple the host provides for the game to open its own realtime connection.
1023
+ - **Multiplayer block.** The opaque `{ reservation, wsEndpoint }` pair the host provides for the game to open its own realtime connection, where `reservation` is the Colyseus seat-reservation (`SdkSeatReservation`).
907
1024
  - **Host.** The GameHub-served page that frames the game in an iframe. Owns auth, matchmaking, and the bootstrap pipeline.
908
1025
  - **Game.** The iframe-hosted application that consumes this SDK.
909
1026
  - **Standalone.** A game loaded outside an iframe. `isInIframe()` returns false; the bootstrap pipeline is skipped.