@hadoku/game-ui 0.1.252 → 0.1.254

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A board's trouble, live or replayed, told to the server log as a page event (`kind: 'trouble'`)
3
+ * over HTTP: the socket is what is in trouble, so it cannot carry it. The server keeps a page event's
4
+ * facts flat and short, so the facts are made so here: a long error arrives clipped, never refused.
5
+ */
6
+ import { type PageEvent } from '@wolffm/platform-wire/telemetry';
7
+ import { type Fetch } from './http.js';
8
+ export type TroublePage = Extract<PageEvent['page'], 'match' | 'replay'>;
9
+ /** Who reports: the match it is about, when there is one, and the page's own build. */
10
+ export type TroubleSource = {
11
+ matchId: string | null;
12
+ ui: string;
13
+ };
14
+ /**
15
+ * `what`, the match, the build and then `detail`'s facts, as a page event's `data`: at most its field
16
+ * count, names clipped, an absent fact left out. The first three go first so no detail crowds them out.
17
+ */
18
+ export declare function troubleData(what: string, detail: Record<string, unknown>, source: TroubleSource): PageEvent['data'];
19
+ /** Posts `what` and its facts to the page-event route; the page shows nothing either way. */
20
+ export declare function sendPageTrouble(page: TroublePage, what: string, detail: Record<string, unknown>, source: TroubleSource, fetchImpl?: Fetch): void;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A board's trouble, live or replayed, told to the server log as a page event (`kind: 'trouble'`)
3
+ * over HTTP: the socket is what is in trouble, so it cannot carry it. The server keeps a page event's
4
+ * facts flat and short, so the facts are made so here: a long error arrives clipped, never refused.
5
+ */
6
+ import { CLIENT_FIELDS_MAX, CLIENT_KEY_MAX, CLIENT_TEXT_MAX, PAGE_EVENT_PATH } from '@wolffm/platform-wire/telemetry';
7
+ import { apiUrl, pageFetch, sendJson } from "./http.js";
8
+ /** One fact as a page event holds it: a number or a flag as it is, anything else as its text, clipped. */
9
+ function scalar(value) {
10
+ if (typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value)))
11
+ return value;
12
+ const text = typeof value === 'string' ? value : (JSON.stringify(value) ?? String(value));
13
+ return text.slice(0, CLIENT_TEXT_MAX);
14
+ }
15
+ /**
16
+ * `what`, the match, the build and then `detail`'s facts, as a page event's `data`: at most its field
17
+ * count, names clipped, an absent fact left out. The first three go first so no detail crowds them out.
18
+ */
19
+ export function troubleData(what, detail, source) {
20
+ const facts = [['what', what], ['matchId', source.matchId], ['ui', source.ui], ...Object.entries(detail)];
21
+ const data = new Map();
22
+ for (const [name, value] of facts) {
23
+ const key = name.slice(0, CLIENT_KEY_MAX);
24
+ if (data.size >= CLIENT_FIELDS_MAX)
25
+ break;
26
+ if (key === '' || data.has(key) || value === null || value === undefined)
27
+ continue;
28
+ data.set(key, scalar(value));
29
+ }
30
+ return Object.fromEntries(data);
31
+ }
32
+ /** Posts `what` and its facts to the page-event route; the page shows nothing either way. */
33
+ export function sendPageTrouble(page, what, detail, source, fetchImpl = pageFetch) {
34
+ const event = { page, kind: 'trouble', data: troubleData(what, detail, source) };
35
+ void sendJson(apiUrl(PAGE_EVENT_PATH), 'POST', event, fetchImpl, { keepalive: true }).catch((err) => console.warn(`[${page}] could not report`, what, err));
36
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.252",
4
- "gitHead": "99dd1c144e4d4a67ae56a1d82a2e59559ce6d79c",
3
+ "version": "0.1.254",
4
+ "gitHead": "7a37d4cacbc4f864ecaa4a14a0878be5b90e863f",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
@@ -53,8 +53,8 @@
53
53
  "react-dom": "^19.2.8"
54
54
  },
55
55
  "dependencies": {
56
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.256",
57
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.256",
56
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.258",
57
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.258",
58
58
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.4",
59
59
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.158",
60
60
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.158",