// ── This module's own API bindings ──────────────────────────────────────── // // Core hands out the request PRIMITIVE and nothing above it (MODULE_API.md // §3.5): same-origin `/api/v1`, cookies included, JSON in and out, and an // `ApiError` thrown on any non-2xx. The paths are this module's, because the // routes at the other end are — `server/router/**` in this repo serves them. // // **Do not build your own fetch wrapper.** The primitive is what carries the // session cookie, the CSRF handling and the error shape core's `ErrorState` // knows how to render. A module that calls `fetch` directly gets none of that // and finds out one page at a time. // // Keeping the bindings in one file, ordered the way the routers are, is // convention rather than contract — but the two halves of every call live in // different directories and nothing checks them against each other, so anything // that makes a mismatch easy to see is worth doing. import rg from './core.js' const { request: req, BASE } = rg.api // ── public ──────────────────────────────────────────────────────────────── // Token-free, same-origin reads. Paths are relative to `/api/v1`, so this hits // `/api/v1/public/rust/servers` — the route `server/router/public/rust.router.js` // registers under the `/rust` prefix `module.json` declares. export const servers = { list: () => req('/public/rust/servers'), // One server, and the only route under `/servers/:id` that can answer "no such // server": the four below answer an empty list for an id nobody ever // configured, because an unknown server genuinely has no events. get: (id) => req(`/public/rust/servers/${encodeURIComponent(id)}`), // `kind` is a comma-separated list and `wipe` a wipe id; both are optional and // both are built here rather than in a page, so the query string this module // sends exists in one file. events: (id, { kinds = null, wipe = null, limit = null } = {}) => req(`/public/rust/servers/${encodeURIComponent(id)}/events${query({ kind: kinds && kinds.length ? kinds.join(',') : null, wipe, limit, })}`), leaderboard: (id, { wipe = null, sort = null, limit = null } = {}) => req(`/public/rust/servers/${encodeURIComponent(id)}/leaderboard${query({ wipe, sort, limit })}`), wipes: (id) => req(`/public/rust/servers/${encodeURIComponent(id)}/wipes`), online: (id) => req(`/public/rust/servers/${encodeURIComponent(id)}/online`), } /** * A query string from the parameters that have a value, or `''`. * * **An absent parameter must be absent, not empty.** `?wipe=` is not the same * question as no `wipe` at all — the first asks for a wipe whose id is the empty * string — and a page that sends one because a `