@hadoku/game-ui 0.1.194 → 0.1.196

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/dist/http.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * The app's one HTTP client: where `/api/` is, and how a request goes out and a
3
- * reply is read. Every call sends the session cookie (`credentials:
4
- * 'same-origin'`), because every `/api` route is friend-gated at the edge.
2
+ * The app's one HTTP client: where `/api/` is, and how a request goes out and a reply is read. Every
3
+ * call sends the session cookie (`credentials: 'same-origin'`), because every `/api` route is gated at
4
+ * the edge: a request carries a signed-in account.
5
5
  */
6
6
  /** The page's own transport: every client's default, and what a page-long read is kept for (`readOnce`). */
7
7
  export const pageFetch = (input, init) => fetch(input, init);
@@ -18,7 +18,7 @@
18
18
  * is the server's own sentence as is (the seat strip shows it under the seats). A body that is not a
19
19
  * room is a refusal too, never a crash: a proxy's error page parses as nothing.
20
20
  */
21
- import { apiBase, bodyOf, getJson, isRecord, pageFetch, sendJson, serverMessage } from "../http.js";
21
+ import { apiBase, bodyOf, getJson, isRecord, pageFetch, sendJson, serverMessage, writeJson } from "../http.js";
22
22
  const UNREACHABLE = 'Could not reach the server.';
23
23
  const NOT_A_ROOM = 'The server answered with something that is not a room.';
24
24
  const id = (roomId) => `/${encodeURIComponent(roomId)}`;
@@ -26,30 +26,15 @@ export function roomCoreClient({ parse, fetch: fetchImpl = pageFetch, base = api
26
26
  const url = (path) => `${base}rooms${path}`;
27
27
  /** A write answered with the room; `whatFailed` null for a seat op, whose refusal is the server's own sentence. */
28
28
  const send = async (path, payload, whatFailed, method = 'POST') => {
29
- let res;
30
- try {
31
- res = await sendJson(url(path), method, payload, fetchImpl);
32
- }
33
- catch {
34
- return { ok: false, message: UNREACHABLE };
35
- }
36
- const body = await bodyOf(res);
37
- if (!res.ok)
38
- return { ok: false, message: whatFailed === null ? serverMessage(body, res.status) : `${whatFailed}: ${serverMessage(body, res.status)}.` };
39
- const room = parse(body);
29
+ const written = await writeJson(url(path), method, payload, whatFailed, fetchImpl);
30
+ if (!written.ok)
31
+ return written;
32
+ const room = parse(written.data);
40
33
  return room === null ? { ok: false, message: NOT_A_ROOM } : { ok: true, room };
41
34
  };
42
35
  const end = async (roomId, verb, whatFailed) => {
43
- let res;
44
- try {
45
- res = await sendJson(url(`${id(roomId)}/${verb}`), 'POST', {}, fetchImpl);
46
- }
47
- catch {
48
- return { ok: false, message: UNREACHABLE };
49
- }
50
- if (res.ok)
51
- return { ok: true };
52
- return { ok: false, message: `${whatFailed}: ${serverMessage(await bodyOf(res), res.status)}.` };
36
+ const written = await writeJson(url(`${id(roomId)}/${verb}`), 'POST', {}, whatFailed, fetchImpl);
37
+ return written.ok ? { ok: true } : written;
53
38
  };
54
39
  const read = async (path) => {
55
40
  let res;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.194",
4
- "gitHead": "0962b3184641c70fa0ebdf6ace69eff2016b985b",
3
+ "version": "0.1.196",
4
+ "gitHead": "7322504089601dad1d2e8d06319a29f821c89e42",
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.198",
57
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.198",
56
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.200",
57
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.200",
58
58
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
59
59
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.150",
60
60
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.150",