Files
kuentagym/website/api.html
T
dsantillan 22654c61fc
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Podcasts: en español solamente, y se acuerdan de dónde ibas
Música tiene una sección **Podcasts**: programas por categoría —Salud y fitness,
Deporte, Comedia, Noticias, Historia, Crímenes reales, Ciencia, Tecnología,
Sociedad y cultura, Negocios, Ficción, Educación, Música, Ocio— que suenan mientras
entrenás y siguen donde los dejaste. Sin dependencias nuevas y sin clave de API: el
directorio de Apple es público.

**En español se comprueba, no se supone.** La tienda dice dónde se *vende* un
podcast, no en qué idioma está —en el ranking español de comedia hay uno en catalán
y en el argentino uno en inglés—, así que se lee el `<language>` del feed de cada
programa (los primeros 64 KB, con una petición `Range`: el idioma está en las
primeras líneas) y se descarta lo que no sea español. Un feed sin etiqueta se queda:
feeds genuinamente españoles la omiten, y tirarlos por una omisión sería sacar
podcasts buenos de la lista. La respuesta cuenta cuántos quedaron afuera y por qué
(`skipped`), así que una lista corta nunca es un misterio, y abrir un programa en
otro idioma se contesta con `spanish:false` en vez de con una lista vacía.

Es la otra mitad de la radio y es lo contrario en todo lo que le importa al
reproductor: un podcast es un **archivo** —tiene principio, final y un minuto en el
que ibas—. Por eso hay un módulo de reglas puras (`lib/podcast-view.js`: dónde
retomar, qué cuenta como escuchado, cuál sigue, cuántas posiciones se guardan) y
por eso `lib/radio-player.js` pasa a ser `lib/player.js`: **un solo elemento de
audio** para las dos cosas, que es lo que impide que una emisora y un episodio suenen
a la vez. La barra crece línea de progreso, −15 s, +30 s, siguiente episodio y reloj;
la posición se guarda por perfil (con tope de 200, lo más nuevo primero) en pausa, al
parar, al terminar y cuando la app se va al fondo, porque con la pantalla bloqueada
iOS suspende los temporizadores y un guardado sólo desde el tick perdería lo
escuchado con el teléfono guardado. Media Session muestra episodio, programa y
progreso en la pantalla bloqueada.

Nada se descarga y nada pasa por el servidor: el episodio llega como la URL del
`enclosure` y el audio va de quien lo publica al teléfono. Acá no hay lista blanca
posible —un feed vive en cualquier host—, así que la puerta es **https, host real y
nunca una dirección privada**, comprobada en la URL y en dónde terminó el pedido, con
el cuerpo leído a tope y la conexión cortada al llegar: este contenedor vive adentro
de una casa.

Verificado con datos reales: 20 programas en español por categoría (idiomas es, es-ES,
es-mx), un feed de 40 episodios parseado, un feed en inglés contestado como
`spanish:false` y la dirección de metadatos rechazada con 400 sin hacer el pedido.

Fuera de los podcasts: la página de la API ocultaba `health` y `music` enteras —el
generador sólo dibuja las secciones de su tabla de etiquetas—, así que ahora están,
con radio y podcasts incluidas.
2026-09-23 21:11:20 -04:00

3071 lines
157 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<!-- GENERATED FILE - do not edit by hand.
Built by scripts/build-api-docs.mjs from api/openapi.yaml (KuentaGYM API v1.3.8).
Regenerate with: node scripts/build-api-docs.mjs -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>API — KuentaGYM</title>
<meta name="description" content="The complete KuentaGYM HTTP API, documented as an OpenAPI spec: passkey auth, state sync, push notifications, pairing and admin routes.">
<meta name="theme-color" content="#000000">
<meta name="robots" content="index,follow,max-image-preview:large">
<meta property="og:title" content="KuentaGYM API reference">
<meta property="og:description" content="The complete KuentaGYM HTTP API as an OpenAPI spec: passkey auth, state sync, push notifications, pairing and admin routes.">
<meta property="og:image" content="https://gym.dploy.lol/img/social.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="KuentaGYM — your training, your data, your server. Two phones showing the home and workout screens.">
<meta property="og:url" content="https://gym.dploy.lol/api.html">
<meta property="og:type" content="website">
<meta property="og:site_name" content="KuentaGYM">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="KuentaGYM API reference">
<meta name="twitter:image" content="https://gym.dploy.lol/img/social.jpg">
<link rel="canonical" href="https://gym.dploy.lol/api.html">
<link rel="icon" type="image/png" sizes="512x512" href="icon-512.png">
<link rel="icon" type="image/png" sizes="180x180" href="icon-180.png">
<link rel="apple-touch-icon" href="icon-180.png">
<link rel="stylesheet" href="styles.css?v=20">
<script>document.documentElement.className += ' js'</script>
<!-- No analytics and no third-party requests: every page here is static and loads
only files from this host. -->
<style>
/* ------------------------------------------------------------- API reference
Generated page — the reference itself is static HTML in the site's design.
Layout: one 880px column of per-endpoint <details> cards. */
main.api-main { max-width: 880px; margin: 0 auto; padding: clamp(44px, 7vw, 72px) var(--pad) 0; }
main.api-main h1 { font-size: clamp(36px, 6.5vw, 60px); letter-spacing: -.03em; }
main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; font-size: clamp(16.5px, 2vw, 19px); }
.api-actions { margin-top: 26px; }
.api-actions .btn svg { width: 17px; height: 17px; }
.api-facts { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 20px; color: var(--fg-3); font-size: 13.5px; }
.api-facts span::after { content: "·"; margin-left: 10px; color: var(--fg-3); }
.api-facts span:last-child::after { content: ""; margin-left: 0; }
.api-sec { padding: 0; margin-top: clamp(46px, 7vw, 68px); }
.api-sec h2 { font-size: clamp(24px, 3.4vw, 32px); scroll-margin-top: 76px; }
.api-sec .sub { color: var(--fg-2); font-size: 15.5px; margin-top: 6px; max-width: 62ch; }
.api-sec .sub code, .ov code, .ep-auth code {
background: var(--surface-2); border-radius: 5px; padding: 1.5px 5px; font-size: .85em; color: #e4e4e8;
}
/* base URLs */
.srv { margin-top: 20px; border: 1px solid var(--hair-soft); border-radius: var(--r-s); background: var(--surface); overflow: hidden; }
.srv-row { display: flex; flex-wrap: wrap; gap: 2px 16px; align-items: baseline; padding: 12px 16px; }
.srv-row + .srv-row { border-top: 1px solid var(--hair-soft); }
.srv-row > code { font-size: 13.5px; color: var(--acc); }
.srv-row > span { color: var(--fg-3); font-size: 13.5px; }
/* overview cards (from the spec's info sections) */
/* align-items:start, so a short card stops at its own last line instead of
stretching to its neighbour's height and showing a panel of empty background. */
.ov-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 12px; margin-top: 18px; }
.ov { background: var(--surface); border: 1px solid var(--hair-soft); border-radius: var(--r-m); padding: 20px 22px; }
.ov h3 { font-size: 15.5px; margin-bottom: 8px; }
.ov p, .ov li { color: var(--fg-2); font-size: 14px; line-height: 1.55; }
.ov p + p, .ov p + ul { margin-top: 8px; }
.ov ul { padding-left: 18px; margin: 0; }
.ov li { margin: 5px 0; }
.ov li::marker { color: var(--fg-3); }
.ov:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (max-width: 720px) { .ov-grid { grid-template-columns: 1fr; } }
/* expand / collapse all */
.xall { display: flex; gap: 16px; justify-content: flex-end; margin: 30px 0 -34px; }
.xall button { color: var(--fg-3); font-size: 13px; cursor: pointer; padding: 4px 0; transition: color .2s var(--ease); }
.xall button:hover { color: var(--fg); }
/* endpoint + schema cards */
.eps { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.ep { background: var(--surface); border: 1px solid var(--hair-soft); border-radius: var(--r-s); scroll-margin-top: 70px; transition: border-color .25s var(--ease); }
.ep:hover, .ep[open] { border-color: var(--hair); }
.ep > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px; align-items: center; }
.ep > summary::-webkit-details-marker { display: none; }
.m { justify-self: start; min-width: 52px; text-align: center; padding: 3px 8px; border-radius: 7px; font-size: 11px; font-weight: 700; letter-spacing: .05em; font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; }
.m.get { color: #6cb2ff; background: rgba(108, 178, 255, .12); }
.m.post { color: var(--acc); background: var(--acc-soft); }
.m.put { color: #ffb340; background: rgba(255, 159, 10, .14); }
.m.delete, .m.patch { color: #ff6b5e; background: rgba(255, 80, 60, .12); }
.ep-path { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.ep-path code, .sch-name code { font-size: 13.5px; color: var(--fg); word-break: break-all; }
.ep-chip { font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 2px 7px; border-radius: 6px; }
.ep-chip.public { color: var(--fg-2); background: rgba(255, 255, 255, .07); }
.ep-chip.admin { color: #ffb340; background: rgba(255, 159, 10, .12); }
.ep-chev { width: 8px; height: 8px; border-right: 1.6px solid var(--fg-3); border-bottom: 1.6px solid var(--fg-3); transform: rotate(45deg) translate(-1px, -1px); transition: transform .25s var(--ease); }
.ep[open] > summary .ep-chev { transform: rotate(225deg); }
.ep-sum { grid-column: 2 / -1; color: var(--fg-3); font-size: 13.5px; line-height: 1.45; }
.ep-body { border-top: 1px solid var(--hair-soft); padding: 16px 16px 18px; }
/* WebAuthn type names run to 34 characters. On a phone they are wider than the
card, so every prose block in here is allowed to break inside a word. */
.ep-body > p, .ep-body > ul li, .ov p, .ov li, .p-desc, .api-sec .sub, .ep-auth,
.ep-path code, .sch-name code, .p-name, .p-type { overflow-wrap: break-word; }
.ep-body > p { color: var(--fg-2); font-size: 14.5px; line-height: 1.65; margin: 0 0 10px; max-width: 74ch; }
.ep-body > ul { margin: 0 0 10px; padding-left: 20px; }
.ep-body > ul li { color: var(--fg-2); font-size: 14.5px; line-height: 1.65; margin: 4px 0; }
/* Identifiers are half of every sentence in an API description: as full chips they
turn a paragraph into confetti, so here they are monospace with a hairline tint. */
.ep-body p code, .ep-body li code, .ov p code, .ov li code, .api-sec .sub code,
.ep-auth code, .p-desc code {
background: rgba(255, 255, 255, .05); border-radius: 4px; padding: 0 3px;
font-size: .9em; line-height: inherit; color: #d8dee2;
}
/* Grid, not flex: the sentence wraps around code chips, and a flex row would
centre the whole wrapped block against the padlock and stagger the lines. */
.ep-auth { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 8px; color: var(--fg-3); font-size: 13px; line-height: 1.6; margin: 14px 0 0 !important; }
.ep-auth svg { width: 13px; height: 13px; margin-top: 3px; }
.ep-h { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-3); margin: 18px 0 8px !important; }
.p-hint { color: var(--fg-3); font-weight: 400; text-transform: none; letter-spacing: 0; }
/* parameter / response tables */
.ptab { border: 1px solid var(--hair-soft); border-radius: 10px; overflow: hidden; }
.prow { display: grid; grid-template-columns: minmax(140px, 220px) minmax(110px, 200px) 1fr; gap: 3px 14px; padding: 10px 14px; font-size: 13.5px; }
.prow + .prow { border-top: 1px solid var(--hair-soft); }
.p-name { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--fg); word-break: break-all; }
.p-req { font-style: normal; color: #ffb340; font-size: 10.5px; margin-left: 7px; letter-spacing: .04em; }
.p-type { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--fg-3); word-break: break-word; }
.p-type a, .r-sig a, .p-desc a { color: var(--acc); }
.p-desc { color: var(--fg-2); line-height: 1.5; }
.rrow { grid-template-columns: 44px 1fr; }
.r-code { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; font-weight: 600; }
.r-code.s2 { color: var(--acc); } .r-code.s3 { color: #6cb2ff; }
.r-code.s4 { color: #ffb340; } .r-code.s5 { color: #ff6b5e; }
.r-sig { display: block; margin-top: 4px; font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; color: var(--fg-3); word-break: break-word; line-height: 1.6; }
.r-sig code, .p-type code { background: none; padding: 0; color: inherit; font-size: inherit; }
.ep-body pre { margin: 8px 0 2px; padding: 12px 14px; font-size: 12.5px; }
@media (max-width: 680px) {
.prow { grid-template-columns: minmax(0, 1fr) auto; }
.prow .p-desc { grid-column: 1 / -1; margin-top: 1px; }
.rrow { grid-template-columns: 44px 1fr; }
.rrow .p-desc { grid-column: auto; margin-top: 0; }
}
/* schema cards */
.sch > summary { grid-template-columns: minmax(0, 1fr) auto; }
.sch .ep-sum { grid-column: 1 / -1; }
/* The header, the navigation sheet and the contents drawer belong to the site, not
to this page: .navsheet, .toc-btn, .side and .rail-close live in styles.css and
site.js and behave identically here, on the docs page and on the home page. This
file deliberately adds nothing of its own to them — one implementation is the
only way the two rail pages can feel like the same rail. */
</style>
</head>
<body class="topnav">
<a class="skip" href="#main">Skip to content</a>
<nav><div class="wrap nav-in">
<a class="brand" href="/">
<img src="icon-180.png" alt="" width="24" height="24">
KuentaGYM
</a>
<div class="nav-quick">
<a class="ql site" href="/#features">Features</a>
<a class="ql site" href="/#screens">Screenshots</a>
<a class="ql site" href="/docs.html">Docs</a>
<a class="ql site" href="/api.html">API</a>
<a class="ql site" href="/about.html">About</a>
<a class="ql" href="https://git.dploy.lol/dsantillan/kuentagym" rel="noopener">Source</a>
<a class="cta" href="/#download">Get started</a>
</div>
<button class="nav-toggle" id="navtoggle" aria-expanded="false" aria-controls="sitemenu" aria-label="Menu">
<span></span><span></span>
</button>
</div></nav>
<!-- The navigation sheet: the header's links again, for the widths where the bar has
room only for the brand and the download. Byte-identical on every page, like the
bar above it — nothing is ever dropped because of which page you are on. -->
<div class="navsheet" id="sitemenu" role="navigation" aria-label="Site" aria-hidden="true">
<div class="nl-rows">
<a class="nl" href="/#features">Features</a>
<a class="nl" href="/#screens">Screenshots</a>
<a class="nl" href="/docs.html">Docs</a>
<a class="nl" href="/api.html">API</a>
<a class="nl" href="/about.html">About</a>
<a class="nl" href="https://git.dploy.lol/dsantillan/kuentagym" rel="noopener">Source</a>
</div>
</div>
<!-- The one control that opens the contents, at every width. The drawer it opens is
closed in CSS, so it is shut on first paint whether or not the script runs. -->
<button class="toc-btn" id="tocbtn" aria-expanded="false" aria-controls="menu">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" aria-hidden="true"><path d="M4 6.5h16M4 12h16M4 17.5h10"/></svg>
Contents
</button>
<!-- The contents drawer: one list, one way in, one way out. Closed by default at
every width, and no preference is remembered — see .side in styles.css. -->
<aside class="side" id="menu" aria-label="Contents" aria-hidden="true">
<div class="side-top">
<p class="side-title">Contents</p>
<button class="rail-close" aria-label="Close contents"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M5 5l14 14M19 5L5 19"/></svg></button>
</div>
<p class="side-label">On this page</p>
<a class="side-link" href="#overview"><b>Overview</b><span>Auth model, sessions, conventions</span></a>
<a class="side-link" href="#meta"><b>Meta</b><span>Health &amp; public config</span></a>
<a class="side-link" href="#auth"><b>Auth</b><span>Passkeys &amp; sessions</span></a>
<a class="side-link" href="#pairing"><b>Pairing</b><span>Connect the mobile app</span></a>
<a class="side-link" href="#data"><b>Data</b><span>State sync</span></a>
<a class="side-link" href="#health"><b>Health</b><span>Apple Health metrics &amp; the second opinion</span></a>
<a class="side-link" href="#music"><b>Música</b><span>Playlists, radio &amp; podcasts</span></a>
<a class="side-link" href="#push"><b>Push</b><span>Notifications &amp; rest timer</span></a>
<a class="side-link" href="#activity"><b>Activity</b><span>Live presence</span></a>
<a class="side-link" href="#admin"><b>Admin</b><span>Users, invites, audit log</span></a>
<a class="side-link" href="#schemas"><b>Schemas</b><span>The state blob, the error shape &amp; co.</span></a>
<p class="side-label">More</p>
<a class="side-link" href="/"><b>Home</b><span>The tour, and how to run it</span></a>
<a class="side-link" href="/docs.html"><b>Docs</b><span>Install, self-host, import</span></a>
<a class="side-link" href="/about.html"><b>About</b><span>The story and the milestones</span></a>
</aside>
<main id="main" class="api-main">
<h1>API</h1>
<p class="lead">Every route the KuentaGYM backend serves — passkey auth, state sync,
push, pairing, admin — as one hand-written
OpenAPI&nbsp;spec. The same file lives
<a href="https://git.dploy.lol/dsantillan/kuentagym/blob/main/api/openapi.yaml" rel="noopener">in the repository</a>
at <code>api/openapi.yaml</code>, next to the one server file it documents.</p>
<div class="actions api-actions">
<a class="btn" href="https://git.dploy.lol/dsantillan/kuentagym/raw/branch/main/api/openapi.yaml" rel="noopener">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3v12m0 0l-5-5m5 5l5-5M4 19h16"/></svg>
Download openapi.yaml</a>
</div>
<p class="api-facts">
<span>OpenAPI 3.1.0</span>
<span>KuentaGYM v1.3.8</span>
<span>43 endpoints</span>
<span>AGPL-3.0-or-later</span>
</p>
<section class="api-sec" id="overview">
<h2>Overview</h2>
<p class="sub">Passkey (WebAuthn) auth + per-user state storage for KuentaGYM. One Node file, no framework, JSON-file
storage, HMAC-signed session cookies.</p>
<div class="srv">
<div class="srv-row"><code>/</code><span>Same origin as the KuentaGYM web app (the normal deployment)</span></div>
<div class="srv-row"><code>https://kuentagym.example.com</code><span>Your self-hosted instance</span></div>
</div>
<div class="ov-grid">
<div class="ov">
<h3>Authentication</h3>
<p>Sign-in is <b>passkey only</b> (WebAuthn, via <code>@simplewebauthn/server</code>). A successful <code>register/verify</code> or <code>login/verify</code> sets the session cookie; every authenticated route then works with that cookie. The paired mobile app has no shared cookie jar, so it redeems a short pairing code (<code>/api/pair/redeem</code>) for the <i>same</i> signed token and sends it as <code>Authorization: Bearer &lt;token&gt;</code> instead.</p>
</div>
<div class="ov">
<h3>Sessions</h3>
<p>The cookie/bearer value is <code>&lt;payload&gt;.&lt;hmac&gt;</code> where the payload is <code>&lt;uid&gt;:&lt;expiry-ms&gt;:&lt;session-version&gt;</code>, signed with a per-instance secret (HMAC-SHA256). Sessions last <code>SESSION_DAYS</code> (default 90). <code>POST /api/logout/all</code> bumps the user's session version, which invalidates every token ever issued for the account.</p>
</div>
<div class="ov">
<h3>CSRF</h3>
<p>State-changing browser requests must come from the app's own origin. The server checks <code>Sec-Fetch-Site</code> (falling back to <code>Origin</code> vs the configured <code>ORIGIN</code>); a mismatch is refused with <code>403 {&quot;error&quot;:&quot;cross-origin request refused&quot;}</code> on any non-GET route. Exempt: the WebAuthn and <code>pair/redeem</code> routes (each carries its own one-shot credential in the body) and any request authenticated with a Bearer token.</p>
</div>
<div class="ov">
<h3>Environment-dependent behavior</h3>
<ul><li><code>INVITE_ONLY=1</code> — registration requires a valid invite code (minted by an admin).</li><li><code>ALLOW_GUEST=0</code> — hides the client-side &quot;continue without account&quot; mode; the server merely reports the flag via <code>GET /api/config</code> (guest mode never talks to this API at all).</li><li><code>ADMIN_UIDS=&lt;uid&gt;,&lt;uid&gt;</code> — user ids treated as admins (a <code>&quot;admin&quot;: true</code> flag on the user record in <code>db.json</code> works too). Admins get the <code>/api/admin/*</code> routes.</li><li><code>AUDIT_LOG</code> (default on), <code>AUDIT_MAX</code> (default 5000 events), <code>AUDIT_DAYS</code> (default 90), <code>AUDIT_IP</code> (<code>off</code> | <code>net</code> | <code>full</code>, default off) — shape the audit log served by <code>GET /api/admin/audit</code>.</li></ul>
</div>
<div class="ov">
<h3>Conventions</h3>
<ul><li>Every response body is JSON with <code>Cache-Control: no-store</code>.</li><li>Errors are always <code>{&quot;error&quot;: &quot;&lt;human-readable message&gt;&quot;}</code>.</li><li>Unknown method+path pairs return <code>404 {&quot;error&quot;:&quot;not found&quot;}</code>; an unhandled exception returns <code>500 {&quot;error&quot;:&quot;server error&quot;}</code>.</li><li>Request bodies are parsed as JSON regardless of Content-Type. A body that does not parse, or parses to anything but an object (<code>null</code>, a string, an array), is <code>400 {&quot;error&quot;:&quot;invalid json&quot;}</code> on every route that reads one; an empty body counts as <code>{}</code>. A body over 5 MiB is <code>413 {&quot;error&quot;:&quot;body too large&quot;}</code>; the rest of the upload is discarded so the answer reaches the client.</li><li>CORS: the request's <code>Origin</code> is reflected in <code>Access-Control-Allow-Origin</code> <b>without</b> <code>Allow-Credentials</code> — cross-origin callers can only ever authenticate with a Bearer token, never with the cookie.</li></ul>
</div>
</div>
</section>
<div class="xall" aria-label="Card controls">
<button data-xall="1">Expand all</button>
<button data-xall="0">Collapse all</button>
</div>
<section class="api-sec" id="meta">
<h2>Meta</h2>
<p class="sub">Health and public configuration</p>
<div class="eps">
<details class="ep" id="op-getHealth">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/health</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Health check</span>
</summary>
<div class="ep-body">
<p>Always public. Also reports how many user accounts exist.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The server is up.<span class="r-sig">{ ok: always true, users: integer }</span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-getConfig">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/config</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Public instance configuration</span>
</summary>
<div class="ep-body">
<p>The flags the login screen needs before anyone is signed in. Both reflect environment variables on the server (<code>INVITE_ONLY</code>, <code>ALLOW_GUEST</code>).</p>
<p><code>features</code> is the one that exists because the app and the api are deployed separately: the frontend is rebuilt from source on every deploy while the api's code lives inside its container, so a deploy can leave a new screen on top of an older api. Naming what this server can do lets a screen say &quot;this server is older than the app&quot; instead of showing a request that quietly fails — or, worse, a number that never moves.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Instance flags.<span class="r-sig">{ invite_only: boolean, allow_guest: boolean, features: (&quot;vitals&quot; | &quot;vitals.hours&quot; | &quot;vitals.receipt&quot; | &quot;music.lookup&quot; | &quot;radio&quot; | &quot;podcasts&quot; | &quot;insights&quot;)[], coach: object }</span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="auth">
<h2>Auth</h2>
<p class="sub">Passkey (WebAuthn) registration and login, sessions</p>
<div class="eps">
<details class="ep" id="op-getMe">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/me</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Who am I?</span>
</summary>
<div class="ep-body">
<p>Resolves the current session to a user.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">A valid session.<span class="r-sig">{ user: <a href="#schema-SessionUser">SessionUser</a> }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-registerOptions">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/register/options</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Start passkey registration (WebAuthn ceremony, step 1)</span>
</summary>
<div class="ep-body">
<p>Returns <code>PublicKeyCredentialCreationOptions</code> (from <code>@simplewebauthn/server</code>'s <code>generateRegistrationOptions</code>) plus a challenge id <code>cid</code>. The client passes <code>options</code> to <code>navigator.credentials.create()</code> (or <code>@simplewebauthn/browser</code>'s <code>startRegistration</code>) and sends the result to <code>/api/register/verify</code> together with the <code>cid</code>. Challenges are one-shot and expire after 5 minutes.</p>
<p>CSRF-exempt (the challenge is the credential). No session required.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">name<em class="p-req" title="required">required</em></span>
<span class="p-type">string <span class="p-hint">(&le; 40 chars)</span></span>
<span class="p-desc">Display name for the new profile (trimmed, max 40 chars).</span>
</div>
<div class="prow">
<span class="p-name">code</span>
<span class="p-type">string</span>
<span class="p-desc">Invite code — required (and validated) only when the instance runs with INVITE_ONLY. Compared case-insensitively.</span>
</div>
</div>
<pre><code>{
&quot;name&quot;: &quot;Ada&quot;,
&quot;code&quot;: &quot;3F9C21A07B54D688&quot;
}</code></pre>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Ceremony options.<span class="r-sig">{ cid: string, options: <a href="#schema-WebAuthnRegistrationOptions">WebAuthnRegistrationOptions</a> }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc"><code>name</code> missing/empty.<span class="r-sig"><code>{&quot;error&quot;:&quot;name required&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Instance is invite-only and the code is missing, used, or revoked.<span class="r-sig"><code>{&quot;error&quot;:&quot;a valid invite code is required&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-registerVerify">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/register/verify</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Finish passkey registration (WebAuthn ceremony, step 2)</span>
</summary>
<div class="ep-body">
<p>Verifies the authenticator's attestation response against the stored challenge (<code>verifyRegistrationResponse</code>), creates the user + credential, and signs the caller in (sets the session cookie). On an invite-only instance the invite is re-checked and burned here. CSRF-exempt.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">cid<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The challenge id from /api/register/options.</span>
</div>
<div class="prow">
<span class="p-name">credential<em class="p-req" title="required">required</em></span>
<span class="p-type"><a href="#schema-WebAuthnRegistrationCredential">WebAuthnRegistrationCredential</a></span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Registered and signed in. The session cookie is set.<span class="r-sig">{ user: <a href="#schema-SessionUser">SessionUser</a> } &middot; sets <code>Set-Cookie</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Challenge expired/replayed, or the attestation did not verify (wrong origin/RP ID, malformed response…). The message is human-readable.<span class="r-sig"><code>{&quot;error&quot;:&quot;challenge expired — try again&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Invite-only and the code became invalid since step 1.<span class="r-sig"><code>{&quot;error&quot;:&quot;invite code is no longer valid — ask for a new one&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">409</span>
<span class="p-desc">This credential id is already registered.<span class="r-sig"><code>{&quot;error&quot;:&quot;credential already registered&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-loginOptions">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/login/options</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Start passkey login (WebAuthn ceremony, step 1)</span>
</summary>
<div class="ep-body">
<p>Returns <code>PublicKeyCredentialRequestOptions</code> (<code>generateAuthenticationOptions</code> with an empty <code>allowCredentials</code> — discoverable credentials / resident keys are required at registration, so the browser offers the user their passkeys itself) plus a one-shot challenge id <code>cid</code>. CSRF-exempt. Takes no request body.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Ceremony options.<span class="r-sig">{ cid: string, options: <a href="#schema-WebAuthnAuthenticationOptions">WebAuthnAuthenticationOptions</a> }</span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-loginVerify">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/login/verify</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Finish passkey login (WebAuthn ceremony, step 2)</span>
</summary>
<div class="ep-body">
<p>Verifies the assertion (<code>verifyAuthenticationResponse</code>), updates the signature counter, and signs the caller in (sets the session cookie). CSRF-exempt.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">cid<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The challenge id from /api/login/options.</span>
</div>
<div class="prow">
<span class="p-name">credential<em class="p-req" title="required">required</em></span>
<span class="p-type"><a href="#schema-WebAuthnAuthenticationCredential">WebAuthnAuthenticationCredential</a></span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Signed in. The session cookie is set.<span class="r-sig">{ user: <a href="#schema-SessionUser">SessionUser</a> } &middot; sets <code>Set-Cookie</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Challenge expired/replayed, or the assertion did not verify.<span class="r-sig"><code>{&quot;error&quot;:&quot;not verified&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">The account has been disabled by an admin.<span class="r-sig"><code>{&quot;error&quot;:&quot;this account has been disabled&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">404</span>
<span class="p-desc">The passkey's credential id is unknown to this instance.<span class="r-sig"><code>{&quot;error&quot;:&quot;unknown passkey — create a profile first&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s5">500</span>
<span class="p-desc">Credential exists but its user record is missing (corrupt db).<span class="r-sig"><code>{&quot;error&quot;:&quot;user missing&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-logout">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/logout</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Sign out (this device)</span>
</summary>
<div class="ep-body">
<p>Clears the session cookie. Always succeeds — an invalid or missing session is a no-op. The token itself stays cryptographically valid until it expires; use /api/logout/all to revoke tokens.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Cookie cleared.<span class="r-sig"><a href="#schema-Ok">Ok</a> &middot; sets <code>Set-Cookie</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-logoutAll">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/logout/all</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Sign out everywhere</span>
</summary>
<div class="ep-body">
<p>Bumps the account's session version, which invalidates <b>every</b> cookie and Bearer token ever issued for it — on every device, including a copy someone walked off with. Passkeys are untouched; signing back in works immediately. Also clears the caller's own cookie. Unredeemed pairing codes for the account are voided too.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">All sessions revoked.<span class="r-sig"><a href="#schema-Ok">Ok</a> &middot; sets <code>Set-Cookie</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="pairing">
<h2>Pairing</h2>
<p class="sub">Mobile-app pairing (code from a signed-in browser tab)</p>
<div class="eps">
<details class="ep" id="op-pairCreate">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/pair/create</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Mint a pairing code for the mobile app</span>
</summary>
<div class="ep-body">
<p>Called from an already signed-in browser tab (Settings → &quot;Pair the mobile app&quot;). Returns an 8-character code (alphabet without 0/O/1/I) the phone redeems within 5 minutes via /api/pair/redeem. One-shot.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">A fresh pairing code.<span class="r-sig">{ code: string }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pairRedeem">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/pair/redeem</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Redeem a pairing code for a Bearer token</span>
</summary>
<div class="ep-body">
<p>Called from the mobile app with the code shown in the browser. No session required — the code <i>is</i> the credential (one-shot, 5-minute TTL). Returns the same HMAC-signed session token the cookie would carry; the app sends it as <code>Authorization: Bearer &lt;token&gt;</code> from then on. CSRF-exempt.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">code<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The pairing code (case-insensitive).</span>
</div>
</div>
<pre><code>{
&quot;code&quot;: &quot;K7WQ2MZP&quot;
}</code></pre>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Paired.<span class="r-sig">{ token: string, user: <a href="#schema-SessionUser">SessionUser</a> }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Code unknown, already used, expired — or the account behind it is gone or disabled (deliberately the same message for all of these).<span class="r-sig"><code>{&quot;error&quot;:&quot;invalid or expired code&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="data">
<h2>Data</h2>
<p class="sub">Per-user state sync (the whole app state as one JSON blob)</p>
<div class="eps">
<details class="ep" id="op-getData">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/data</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Pull the account's app state</span>
</summary>
<div class="ep-body">
<p>Returns the caller's entire app state as one JSON blob, or <code>{&quot;state&quot;: null}</code> if nothing has been synced yet, together with <code>rev</code>, the server's revision of that document (0 when there is none). A client keeps the <code>rev</code> it last read or wrote and sends it back as <code>baseRev</code> on the next push, which lets the server refuse a write over a document the client never saw (see the 409 on PUT).</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The stored state, or null, and its revision.<span class="r-sig">{ state: <a href="#schema-State">State</a> | null, rev: integer }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-putData">
<summary>
<span class="m put">PUT</span>
<span class="ep-path"><code>/api/data</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Push the account's app state</span>
</summary>
<div class="ep-body">
<p>Replaces the stored state wholesale (atomic write; there is no merge on the server). The <code>active</code> field — an in-progress workout — is stripped before saving: a running session belongs to the device running it. Body limit 5 MiB.</p>
<p>With <code>baseRev</code> the write is conditional: it goes through only when <code>baseRev</code> equals the document's current revision, and answers 409 with the current document otherwise — the client merges the two and pushes again with the revision it was given. Without <code>baseRev</code> the write is unconditional (clients from before revisions, and deliberate replaces such as a backup import). The server stamps the new revision into the document as <code>_rev</code>; a <code>_rev</code> sent by the client is ignored.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">state<em class="p-req" title="required">required</em></span>
<span class="p-type"><a href="#schema-State">State</a></span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">baseRev</span>
<span class="p-type">integer | null</span>
<span class="p-desc">The revision this client last read or wrote. Omit or null for an unconditional overwrite.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Saved.<span class="r-sig">{ ok: always true, ts: number | null, rev: integer }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc"><code>state</code> missing or not an object, <code>state</code> an array, or <code>workouts</code>/<code>routines</code> set to anything other than an array or null. Entries inside those two arrays that are not objects (<code>null</code>, numbers, nested arrays) are dropped before the write rather than refused, so a client with a damaged copy still syncs.<span class="r-sig"><code>{&quot;error&quot;:&quot;state required&quot;}</code> &middot; <code>{&quot;error&quot;:&quot;invalid state&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">409</span>
<span class="p-desc"><code>baseRev</code> is not the current revision — another client wrote since this one last read. Carries the current document so the client can merge and retry.</span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="health">
<h2>Health</h2>
<p class="sub">Apple Health metrics ingested from an iPhone (Health Auto Export automations) — per profile, write-only for the phone's ingest key</p>
<div class="eps">
<details class="ep" id="op-vitalsGet">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/vitals</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">The caller's Apple Health metrics, as per-day aggregates</span>
</summary>
<div class="ep-body">
<p>What the Salud view renders: one entry per metric, one bucket per day, and every bucket carrying every numeric field HAE sent under the name it used (<code>qty</code>, <code>Min</code>/<code>Avg</code>/<code>Max</code>, <code>systolic</code>/<code>diastolic</code>, <code>asleep</code>/<code>inBed</code>/<code>core</code>/<code>deep</code>/<code>rem</code>…), already summed and averaged for that day.</p>
<p>The server deliberately does not decide what &quot;steps today&quot; means — which field a card shows is a presentation rule (frontend <code>lib/vitals-view.js</code>), so a metric HAE adds later needs no change here.</p>
<p>A session is always required: the ingest key is write-only, so a key that leaks out of a phone can add to a profile's health file and still cannot read it back.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">days</span>
<span class="p-type">integer <span class="p-hint">(1&ndash;400, default 90)</span></span>
<span class="p-desc">Calendar days to return, including today.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The stored metrics for the window, oldest day first.<span class="r-sig">{ ok: boolean, days: integer, key: string, updatedAt: integer, last: object, metrics: object, workouts: object[] }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-vitalsClear">
<summary>
<span class="m delete">DELETE</span>
<span class="ep-path"><code>/api/vitals</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Delete the caller's health data, or one metric of it</span>
</summary>
<div class="ep-body">
<p>Removes the profile's health file and nothing else: the workout history, the account and the ingest key are untouched, so a phone needs no re-configuring to sync again.</p>
<p>With <code>?metric=</code> it forgets <b>one</b> measurement instead, days and hours included, and leaves every other metric in place — the answer to &quot;these numbers look wrong, start this one over&quot;. It is a reset rather than a loss whenever the automation's Date Range is wider than a day: the next sync sends that metric again from Apple Health. A metric the profile does not have answers <code>200</code> with <code>metric: null</code>, not an error.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">metric</span>
<span class="p-type">string</span>
<span class="p-desc">The metric name exactly as HAE wrote it (<code>step_count</code>, <code>heart_rate</code>…). Omit it to clear everything.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Deleted (also when there was nothing stored).<span class="r-sig">{ ok: boolean }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-vitalsHours">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/vitals/hours</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One metric's hours on one day</span>
</summary>
<div class="ep-body">
<p>The detail behind a card: the hourly buckets the phone sent for a single metric on a single day, oldest first, each carrying the same per-field aggregates a day does.</p>
<p>This is a separate request on purpose. The hours are the bulky part of health data (24 buckets per metric per day), and they are only interesting once somebody taps a card, so a screen listing forty metrics fetches none of them.</p>
<p>A day the automation grouped by Day has no hours and comes back as an empty list rather than a fabricated one: the honest answer to &quot;what did the hours look like&quot; for a payload that never carried hours is that the automation does not send them. Set Time Grouping to <b>Hours</b> in Health Auto Export to keep them — the day remains the sum of its hours, so nothing is counted twice.</p>
<p>Session only, like <code>GET /api/vitals</code>: the ingest key is write-only.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">metric<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The metric name exactly as HAE wrote it (<code>step_count</code>, <code>heart_rate</code>…).</span>
</div>
<div class="prow">
<span class="p-name">day<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">A calendar day, in the phone's own date, as <code>YYYY-MM-DD</code>.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The hours stored for that metric and day (empty when there are none).<span class="r-sig">{ ok: boolean, metric: string, day: string, units: string, hours: object[] }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-insightsGet">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/insights</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">The profile's last second opinion, if the instance has one</span>
</summary>
<div class="ep-body">
<p>Whether this instance is configured for a second opinion at all (<code>configured</code>, false unless <code>JEV_API_KEY</code> or <code>OPENCODE_API_KEY</code> is set), what was judged last, whether that judgment is still about the data on screen, and what is left of today's budget.</p>
<p>The judgment itself is a small object: one entry per question the server asked, each with the option or level the model chose and the probability it put there. A question it did not answer is <code>null</code> — the server never fills a gap with a guess, and the screen says the question went unanswered rather than drawing a zero.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">raw</span>
<span class="p-type">&quot;1&quot;</span>
<span class="p-desc">Include the gateway's own response body, exactly as it arrived. Debugging detail: the default response leaves it out, because a screen polling this does not need it.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The state of the feature and the last judgment.<span class="r-sig">{ ok: boolean, configured: boolean, model: string, host: string, insight: object, freshness: object, budget: object }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-insightsAsk">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/insights</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Ask for a second opinion about this profile</span>
</summary>
<div class="ep-body">
<p>Builds a state from the profile's own data — a week of every health metric it has, the sets per body part over four weeks, the last few sessions, <b>the whole training history per exercise</b> (sessions, the estimate of the best set then and now, one point per session, and where it has stalled), the weekly load and volume of the last ten weeks, the newest weigh-in, and the Coach intake's goal and limitations note — sends it to Jev (TypeSafe's System One model, through the OpenCode Zen gateway) with four typed questions, and stores the answers.</p>
<p><b>What leaves the instance is decided server-side and is aggregates only</b>: no name, no workout titles, no chat, and no identifier of a person. The exceptions are deliberate and small: the Coach intake's <code>limitations</code> note, because &quot;bad shoulder&quot; changes the answer, and the <b>library id of an exercise that has stopped progressing</b>, because a question about which exercise to change has to name something the app can edit — a library id is a row in a public dataset, not an identifier of anybody. The one piece of the person's own writing that goes is the intake's <code>limitations</code> field, because &quot;bad shoulder&quot; changes the answer; the sheet in front of the button lists exactly what will be sent before it is sent.</p>
<p>It costs a request, so it is never on a timer: the call is the ask, and the budget (<code>per profile per day</code>, plus a ten-minute floor) is enforced here rather than trusted to the client. A profile with no health data and no training still gets an answer — the questions that cannot be answered are simply not asked.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The judgment, parsed. Every question the model left unanswered is null.<span class="r-sig">{ ok: boolean, model: string, host: string, insight: object, freshness: object, budget: object, sent: object }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">The instance has no key configured — the message names the variable to set.</span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">429</span>
<span class="p-desc">Today's budget is spent, or ten minutes have not passed since the last ask.</span>
</div>
<div class="prow rrow">
<span class="r-code s5">502</span>
<span class="p-desc">The gateway refused or failed; the message carries what it said.</span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-vitalsIngest">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/vitals/ingest</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Receive a Health Auto Export JSON export</span>
</summary>
<div class="ep-body">
<p>The endpoint an iOS automation posts to. In Health Auto Export: Automation Type <b>REST API</b>, URL = this endpoint, header <code>Authorization: Bearer &lt;ingest key&gt;</code> (from <code>POST /api/vitals/key</code>), Export Format <b>JSON</b>, Export Version <b>2</b>, Summarize Data <b>On</b>, Time Grouping <b>Hours</b> (or <b>Days</b> for totals with nothing behind them), Date Range <b>Previous 7 Days</b> — with the default range every sync carries today only, and the past is never in the file.</p>
<p>The merge is idempotent, which is what makes a five-minute cadence safe:</p>
<p>* A payload whose datapoints all sit on midnight is HAE's own day grouping, and a day total <i>replaces</i> the day it names — so the same day re-sent all afternoon converges on the day's total instead of adding up. * A payload whose datapoints all sit on the hour is its hour grouping: the <i>hour</i> is replaced for the same reason (the hour in progress grows on every run), and the day is recomputed as the sum of its hours, so the day and the hourly detail can never disagree. * Anything else is a real sample: it is identified by its instant plus its numbers and is counted once, and it also lands in its own hour, which is where intraday detail comes from. Repeats come back as <code>duplicates</code>.</p>
<p>CSRF-exempt: the request carries its own credential in a header and has no session to borrow.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p>
<pre><code>{
&quot;data&quot;: {
&quot;metrics&quot;: [
{
&quot;name&quot;: &quot;step_count&quot;,
&quot;units&quot;: &quot;count&quot;,
&quot;data&quot;: [
{
&quot;qty&quot;: 12481,
&quot;date&quot;: &quot;2026-09-03 00:00:00 +0200&quot;
}
]
}
]
}
}</code></pre>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Accepted — including an export with nothing in it, because a scheduled automation that fires when there is nothing to report is not a failure.<span class="r-sig">{ ok: boolean, ts: integer, received: object, stored: object }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Not a Health Auto Export JSON export (or not JSON at all).<span class="r-sig"><code>{&quot;error&quot;:&quot;not a Health Auto Export JSON export&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No ingest key, an unknown or rotated key, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;invalid ingest key&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">413</span>
<span class="p-desc">Body over 32 MB. Group by days in HAE, or select fewer metrics.<span class="r-sig"><code>{&quot;error&quot;:&quot;body too large&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-vitalsKeyCreate">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/vitals/key</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Get the profile's ingest key, creating it on first use</span>
</summary>
<div class="ep-body">
<p>Idempotent: a second call returns the key that exists rather than invalidating the configuration already pasted into the phone.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The ingest key.<span class="r-sig">{ ok: boolean, key: string }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-vitalsKeyRotate">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/vitals/key/rotate</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Replace the profile's ingest key</span>
</summary>
<div class="ep-body">
<p>The old key stops working everywhere at once. Stored health data is untouched; the phone stops syncing until the new key is pasted in. Separate from the session token on purpose — losing a phone should not sign you out of the app.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">A new key.<span class="r-sig">{ ok: boolean, key: string }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="music">
<h2>Música</h2>
<p class="sub">Música — reading a public Apple Music page for a saved playlist's card, the live radio station directory, and the Spanish-language podcast directory. Audio is never proxied by this server: a station arrives as a resolved stream URL, an episode as the publisher's own file URL, and the phone talks to the station or the publisher directly.</p>
<div class="eps">
<details class="ep" id="op-radioGet">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/radio</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Live radio stations for a genre, with their stream URLs resolved</span>
</summary>
<div class="ep-body">
<p>What the <b>Radio</b> section of the Música screen draws. Every station arrives with the URL to hand an <code>&lt;audio&gt;</code> element already resolved — the one non-obvious decision here, and it is about iOS: audio may only start <i>inside</i> the tap that asked for it, so anything asynchronous between the finger and the <code>play()</code> is a press that quietly does nothing.</p>
<p>The audio never passes through this server. The list is the whole feature on this side: the phone then talks to the station directly, so this instance spends no bandwidth and keeps no copy of anything. Sources are SomaFM (commercial-free) and Radio Paradise for the curated picks, and the public radio-browser directory for the rest, filtered to HTTPS and to codecs a browser plays without a library (HLS streams are skipped — that would mean shipping a player library).</p>
<p>A session is required. Not to protect the stations — they are public — but because this container sits on the owner's own network and fetches on behalf of whoever asks.</p>
<p>An unknown or missing <code>genre</code> is not an error: it falls back to the first genre.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">genre</span>
<span class="p-type">&quot;workout&quot; | &quot;techno&quot; | &quot;rnb&quot; | &quot;latin&quot; | &quot;hiphop&quot; | &quot;reggae&quot; | &quot;chill&quot; | &quot;jazz&quot; | &quot;rock&quot; | &quot;electronic&quot;</span>
<span class="p-desc">Genre key. Missing or unrecognised falls back to <code>workout</code>.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The genres for the chips, and the stations for the one that was asked for.<span class="r-sig">{ ok: boolean, genres: object[], genre: string, label: string, stations: <a href="#schema-RadioStation">RadioStation</a>[] }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-radioNow">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/radio/now</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">What a station says it is playing</span>
</summary>
<div class="ep-body">
<p>The line under the station's name in the player bar, and the metadata the lock screen shows. Only <b>SomaFM</b> and <b>Radio Paradise</b> publish this; for anything else the answer is <code>now: null</code> and the bar shows the station itself rather than inventing a track.</p>
<p>The station is rebuilt from <code>src</code> + <code>id</code> rather than accepted as an object, and the id is checked against a plain-id pattern, because the id is used to build a URL this process fetches: without that, a session would be enough to make the api a request proxy for anything on the owner's network. The two known sources are the only ones accepted.</p>
<p>The client polls this every 45 seconds while something plays — the screen's own timer, so when iOS suspends it on a locked screen the caption freezes and the music does not.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">src<em class="p-req" title="required">required</em></span>
<span class="p-type">&quot;soma&quot; | &quot;paradise&quot;</span>
<span class="p-desc">Which service the station belongs to.</span>
</div>
<div class="prow">
<span class="p-name">id<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The station's id at that service (a SomaFM channel like <code>beatblender</code>, or a Radio Paradise mix like <code>main</code>).</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The current track, or <code>null</code> when the station does not publish one.<span class="r-sig">{ ok: boolean, now: object }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">No such station — an unknown <code>src</code>, or an <code>id</code> that is not a plain id.</span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-podcastsGet">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/podcasts</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Spanish-language podcast shows for a category</span>
</summary>
<div class="ep-body">
<p>What the <b>Podcasts</b> section of the Música screen draws. Apple's public podcast directory (no API key, no account) supplies the storefront charts per category and the feed URL behind each show; the episodes themselves come from the publisher's own RSS, fetched by <code>GET /api/podcasts/show</code>.</p>
<p><b>Spanish only, and checked rather than assumed.</b> A storefront says a podcast is sold in Spain or Mexico, which is not the same as being in Spanish — the Spanish comedy chart carries a Catalan show, the Argentine one an English show. So each show's feed is read (its first 64 KB, with a <code>Range</code> request) and its <code>&lt;language&gt;</code> decides: <code>es</code>, <code>es-ES</code>, <code>es-419</code> and <code>spa</code> are kept, <code>ca</code> and <code>en</code> are dropped, and a feed that declares no language at all is kept too — genuinely Spanish feeds omit the tag, and dropping them over an omission would quietly remove good podcasts. <code>skipped</code> reports how many went each way, so a short list is never a mystery.</p>
<p>The audio never passes through this server: an episode is a file URL in the publisher's enclosure, handed to the phone. What this route costs is server-side requests to Apple and to each publisher's feed, so the answer is cached for thirty minutes.</p>
<p>A session is required. Not to protect the shows — they are public — but because this container sits on the owner's own network and fetches on behalf of whoever asks.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">category</span>
<span class="p-type">&quot;fitness&quot; | &quot;sports&quot; | &quot;comedy&quot; | &quot;news&quot; | &quot;history&quot; | &quot;truecrime&quot; | &quot;science&quot; | &quot;tech&quot; | &quot;society&quot; | &quot;business&quot; | &quot;fiction&quot; | &quot;education&quot; | &quot;music&quot; | &quot;leisure&quot;</span>
<span class="p-desc">Category key. Missing or unrecognised falls back to <code>fitness</code>.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The categories for the chips, and the Spanish shows in the one asked for.<span class="r-sig">{ ok: boolean, categories: object[], category: string, label: string, shows: <a href="#schema-PodcastShow">PodcastShow</a>[], skipped: object }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-podcastsShow">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/podcasts/show</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One show's episodes, read out of the publisher's feed</span>
</summary>
<div class="ep-body">
<p>The episode list behind a show, newest first, from the publisher's own RSS — the same feed every podcast app in the world reads. Each episode carries the <code>https://</code> URL of its audio file (<code>enclosure</code>), which is what the phone plays; nothing is downloaded by this server and no audio is proxied.</p>
<p>Two things are refused or reported rather than faked:</p>
<ul><li><b>A URL this process will not fetch</b> is a <code>400</code>. Podcast feeds live on every host in the world, so there is no allowlist to hide behind: the rule is https, no credentials, a real hostname, and never a private address (no loopback, no <code>10.</code>/<code>192.168.</code>/<code>172.16-31.</code>, no link-local, no IPv6 literals, no <code>.local</code>). A redirect is checked the same way, because a redirect is otherwise the way around it.</li><li><b>A feed that is not Spanish</b> is answered with <code>200</code> and <code>spanish: false</code> (with <code>episodes: []</code>), not with a hidden empty list: the show exists, it is simply not in Spanish, and saying which of the two it is is the whole point of the field.</li></ul>
<p>Episodes without a public audio enclosure are left out: a trailer, a subscriber-only episode or a video is a row that plays silence or nothing. Feeds are up to a few megabytes, so the body is read with a cap and the connection is dropped at it; a feed cut off mid-item simply loses that last, unparseable item.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">feed<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The show's feed URL, exactly as <code>GET /api/podcasts</code> returned it.</span>
</div>
<div class="prow">
<span class="p-name">title</span>
<span class="p-type">string <span class="p-hint">(&le; 120 chars)</span></span>
<span class="p-desc">The directory's name for the show, used only when the feed declares none.</span>
</div>
<div class="prow">
<span class="p-name">image</span>
<span class="p-type">string <span class="p-hint">(&le; 300 chars)</span></span>
<span class="p-desc">The directory's artwork, used only when the feed declares none.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The show and its episodes — or <code>show: null</code> when the feed did not answer.<span class="r-sig">{ ok: boolean, feed: string, spanish: boolean, show: object, episodes: <a href="#schema-PodcastEpisode">PodcastEpisode</a>[], error: string }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">The feed URL is not one this server will fetch (not https, not a public host).</span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-musicLookup">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/music/lookup</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Read what a public Apple Music page says about itself</span>
</summary>
<div class="ep-body">
<p>Apple has no API for somebody else's public playlists, so a playlist saved in KuentaGYM is a <i>link</i> — and this is how the card gets its title, artwork, track count and curator without the client fetching Apple itself (which CORS would refuse anyway).</p>
<p>The URL must be an Apple Music link on an allowlisted host (<code>hostAllowed</code>), and so must the URL the request ends up at: a redirect is otherwise a way around the allowlist. This container sits on the owner's own network, which is the whole reason for the check.</p>
<p>An unreachable page or a page that left the allowlist is <b>not</b> an error status — the answer is <code>200</code> with <code>meta: null</code> and an <code>error</code> naming which of the two happened, because the app's job then is to save the link anyway with the name the person typed.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">url<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">A public <code>https://music.apple.com/...</code> link.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">What the page said, or <code>meta: null</code> with a reason.<span class="r-sig">{ ok: boolean, meta: object, error: string }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Not an Apple Music link, or a plain-<code>http</code>/off-host URL. Refused before any request is made.</span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="push">
<h2>Push</h2>
<p class="sub">Web Push (VAPID) subscriptions, rest-timer and test pushes</p>
<div class="eps">
<details class="ep" id="op-pushPublicKey">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/push/public-key</code><span class="ep-chip public">public</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">VAPID public key</span>
</summary>
<div class="ep-body">
<p>The instance's Web-Push application server key (generated once at first boot), for <code>PushManager.subscribe({applicationServerKey})</code>. Public.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The key.<span class="r-sig">{ key: string }</span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pushSubscribe">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/push/subscribe</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Register a Web-Push subscription</span>
</summary>
<div class="ep-body">
<p>Stores the browser's <code>PushSubscription</code> for this account. Only <code>endpoint</code> and the two protocol keys are kept. The endpoint must be a public <code>https://</code> URL — private/loopback/link-local addresses are refused (here and again at send time, against DNS rebinding). At most 20 subscriptions per user; the oldest are dropped first. Re-subscribing an existing endpoint replaces it and keeps its original <code>created</code> — the client re-sends its subscription on every signed-in boot, so a row the instance lost comes back on its own.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">subscription<em class="p-req" title="required">required</em></span>
<span class="p-type"><a href="#schema-PushSubscription">PushSubscription</a></span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">deviceId</span>
<span class="p-type">string</span>
<span class="p-desc">A token the browser made up for itself (stored in its localStorage), so rest-timer pushes can be aimed at the device that started the rest. Optional; anything that is not a short token is ignored.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Stored.<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Malformed subscription, or an endpoint that isn't acceptable.<span class="r-sig"><code>{&quot;error&quot;:&quot;invalid subscription&quot;}</code> &middot; <code>{&quot;error&quot;:&quot;endpoint must not point at a private address&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pushStatus">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/push/status</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Does the server hold this subscription?</span>
</summary>
<div class="ep-body">
<p>Whether the caller's account has a stored subscription with exactly this <code>endpoint</code>. The browser's <code>PushManager.getSubscription()</code> says nothing about the server's side — a row pruned after a dead send (404/410/403) leaves the browser subscribed to nowhere — so the client asks here before showing the notifications switch as on, and re-registers when the answer is no.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">endpoint<em class="p-req" title="required">required</em></span>
<span class="p-type">string <span class="p-hint">(uri)</span></span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The answer.<span class="r-sig">{ subscribed: boolean }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pushUnsubscribe">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/push/unsubscribe</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Remove a Web-Push subscription</span>
</summary>
<div class="ep-body">
<p>Removes the caller's subscription with the given endpoint. Idempotent.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">endpoint<em class="p-req" title="required">required</em></span>
<span class="p-type">string <span class="p-hint">(uri)</span></span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Removed (or was never there).<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pushTest">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/push/test</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Send a test notification</span>
</summary>
<div class="ep-body">
<p>Sends a test push to all of the caller's subscriptions (localized with the <code>lang</code> in their synced state). Returns 200 even if delivery to individual endpoints fails — dead endpoints (404/410, and 403 for a subscription made against a VAPID key the instance no longer has) are pruned as a side effect.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Sends attempted.<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pushRestTimer">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/push/rest-timer</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Schedule a server-side rest-timer push</span>
</summary>
<div class="ep-body">
<p>Schedules one push after <code>seconds</code> (a number or numeric string ≥ 1, clamped to 3600). One pending timer per device — <code>deviceId</code>, the same token the subscription was registered with; a new call from the same device replaces it, and the push goes only to that device's subscriptions. Without a <code>deviceId</code> there is one timer per account and the push goes to every subscription, as before. The client schedules this on rest start/extend and cancels on skip or on-screen completion — the push only actually fires when the tab was backgrounded/suspended and never got to cancel it. Timers live in memory: an API restart drops them.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">seconds<em class="p-req" title="required">required</em></span>
<span class="p-type">number <span class="p-hint">(1&ndash;3600)</span></span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">deviceId</span>
<span class="p-type">string</span>
<span class="p-desc">The browser's own token, see <code>POST /api/push/subscribe</code>. Optional.</span>
</div>
</div>
<pre><code>{
&quot;seconds&quot;: 90,
&quot;deviceId&quot;: &quot;3f9c1d2e7b0a4c6d9e8f1a2b3c4d5e6f&quot;
}</code></pre>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Timer scheduled.<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc"><code>seconds</code> missing, not numeric, or below 1. Nothing is scheduled.<span class="r-sig"><code>{&quot;error&quot;:&quot;seconds required&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-pushRestTimerCancel">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/push/rest-timer/cancel</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Cancel the pending rest-timer push</span>
</summary>
<div class="ep-body">
<p>Cancels the caller's scheduled rest-timer push, if any. With a <code>deviceId</code> only that device's timer; without one, every pending timer of the account. Idempotent.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span> <span class="p-hint">(optional)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">deviceId</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Cancelled (or nothing was pending).<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="activity">
<h2>Activity</h2>
<p class="sub">Live-workout presence heartbeat</p>
<div class="eps">
<details class="ep" id="op-postActivity">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/activity</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Live-workout presence heartbeat</span>
</summary>
<div class="ep-body">
<p>The client pings this every ~20 s while a workout is on screen; the admin dashboard reads who is training right now. Purely ephemeral, in-memory, never persisted; entries expire ~70 s after the last ping. <code>{&quot;active&quot;: false}</code> drops the caller's entry immediately.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Requires a session — the cookie set at sign-in, or <code>Authorization: Bearer &lt;token&gt;</code> from mobile-app pairing.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">active</span>
<span class="p-type">boolean</span>
<span class="p-desc">false ends the presence; true (with the fields below) updates it.</span>
</div>
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string <span class="p-hint">(&le; 60 chars)</span></span>
<span class="p-desc">Routine/workout name being trained.</span>
</div>
<div class="prow">
<span class="p-name">exIdx</span>
<span class="p-type">integer</span>
<span class="p-desc">Current exercise index (0-based).</span>
</div>
<div class="prow">
<span class="p-name">exTotal</span>
<span class="p-type">integer</span>
<span class="p-desc">Exercises in the workout.</span>
</div>
<div class="prow">
<span class="p-name">setsDone</span>
<span class="p-type">integer</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">setsTotal</span>
<span class="p-type">integer</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">startedAt</span>
<span class="p-type">number</span>
<span class="p-desc">Workout start, ms since epoch (defaults to now).</span>
</div>
</div>
<pre><code>{
&quot;active&quot;: true,
&quot;name&quot;: &quot;Push Day&quot;,
&quot;exIdx&quot;: 2,
&quot;exTotal&quot;: 5,
&quot;setsDone&quot;: 7,
&quot;setsTotal&quot;: 16,
&quot;startedAt&quot;: 1756500000000
}</code></pre>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Presence updated.<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="admin">
<h2>Admin</h2>
<p class="sub">Admin dashboard — requires an admin session (<code>ADMIN_UIDS</code> or <code>admin:true</code>)</p>
<div class="eps">
<details class="ep" id="op-adminUsers">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/admin/users</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">List all users</span>
</summary>
<div class="ep-body">
<p>One row per user with workout counts, last sync, push status and live presence. <code>workouts</code> counts only the entries the drill-down can show. Admin only.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">All users.<span class="r-sig">{ users: <a href="#schema-AdminUserRow">AdminUserRow</a>[], invite_only: boolean, now: number }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminUser">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/admin/user</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One user in detail</span>
</summary>
<div class="ep-body">
<p>Drill-down — full workout history (newest first) and body-weight log for one user. Admin only. Anything in <code>routines</code>, <code>bodyweight</code> or <code>workouts</code> that is not an object is left out, and a list that is not an array reads as empty: PUT /api/data drops those entries now, but a state file written before it did still has them and this route has to answer for it.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">id<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The user id.</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The user's detail.<span class="r-sig"><a href="#schema-AdminUserDetail">AdminUserDetail</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">404</span>
<span class="p-desc">No user with that id.<span class="r-sig"><code>{&quot;error&quot;:&quot;no such user&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminUserDisable">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/admin/user/disable</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Disable or re-enable a user</span>
</summary>
<div class="ep-body">
<p>Sets the <code>disabled</code> flag. A disabled account is locked out everywhere at once (every existing session stops resolving) and dropped from live presence. Admins cannot be disabled. Audited.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">id<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The user id.</span>
</div>
<div class="prow">
<span class="p-name">disabled<em class="p-req" title="required">required</em></span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Flag updated.<span class="r-sig">{ ok: always true, id: string, disabled: boolean }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">Target is an admin.<span class="r-sig"><code>{&quot;error&quot;:&quot;cannot disable an admin&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">404</span>
<span class="p-desc">No user with that id.<span class="r-sig"><code>{&quot;error&quot;:&quot;no such user&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminInvites">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/admin/invites</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">List invite codes</span>
</summary>
<div class="ep-body">
<p>All invite codes, with the redeeming user's name resolved for display.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">All invites.<span class="r-sig">{ invites: <a href="#schema-Invite">Invite</a>[], invite_only: boolean }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminInviteNew">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/admin/invites/new</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Mint an invite code</span>
</summary>
<div class="ep-body">
<p>Creates a fresh single-use invite code (16 hex chars = 64 bits — the code itself is the thing that isn't worth guessing; rate limiting is the reverse proxy's job). Audited.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span> <span class="p-hint">(optional)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">note</span>
<span class="p-type">string <span class="p-hint">(&le; 60 chars)</span></span>
<span class="p-desc">Free-form label (&quot;for Alex&quot;).</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">The new invite.<span class="r-sig">{ invite: <a href="#schema-Invite">Invite</a> }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminInviteRevoke">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/admin/invites/revoke</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Revoke an unused invite code</span>
</summary>
<div class="ep-body">
<p>Deletes an unused code. A code that was already redeemed cannot be revoked.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Request body <span class="p-hint">(JSON)</span></p><div class="ptab">
<div class="prow">
<span class="p-name">code<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Revoked.<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">400</span>
<span class="p-desc">The code was already used.<span class="r-sig"><code>{&quot;error&quot;:&quot;already used — cannot revoke&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">404</span>
<span class="p-desc">No such code.<span class="r-sig"><code>{&quot;error&quot;:&quot;no such code&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminAudit">
<summary>
<span class="m get">GET</span>
<span class="ep-path"><code>/api/admin/audit</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Read the activity log</span>
</summary>
<div class="ep-body">
<p>The audit log (sign-ins, failed attempts, admin actions), newest first, paged by event id (<code>before</code> cursor — offset paging would repeat rows as new events land). Retention (<code>AUDIT_MAX</code> events / <code>AUDIT_DAYS</code> days) is applied on read as well as on the hourly compaction. When <code>AUDIT_LOG</code> is off the route still answers, with <code>enabled: false</code> and whatever was logged before.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Query parameters</p><div class="ptab">
<div class="prow">
<span class="p-name">limit</span>
<span class="p-type">integer <span class="p-hint">(1&ndash;200, default 100)</span></span>
<span class="p-desc">Page size.</span>
</div>
<div class="prow">
<span class="p-name">before</span>
<span class="p-type">integer</span>
<span class="p-desc">Only events with id &lt; before (cursor from <code>nextBefore</code>).</span>
</div>
<div class="prow">
<span class="p-name">cat</span>
<span class="p-type">&quot;auth&quot; | &quot;admin&quot; | &quot;fail&quot;</span>
<span class="p-desc">Filter — <code>fail</code> keeps only failed events; any other value keeps events whose name starts with <code>&lt;cat&gt;.</code> (in practice <code>auth</code> or <code>admin</code>).</span>
</div>
</div>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">One page of the log.<span class="r-sig">{ events: <a href="#schema-AuditEvent">AuditEvent</a>[], total: integer, nextBefore: integer | null, enabled: boolean, ip_mode: &quot;off&quot; | &quot;net&quot; | &quot;full&quot;, retention: object, now: number }</span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
</div>
</div>
</details>
<details class="ep" id="op-adminAuditClear">
<summary>
<span class="m post">POST</span>
<span class="ep-path"><code>/api/admin/audit/clear</code><span class="ep-chip admin">admin</span></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Clear the activity log</span>
</summary>
<div class="ep-body">
<p>Deletes the log file. The clear is itself the first event of the fresh log, and event ids are never reset — a wipe always leaves a visible id gap.</p>
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Admin only — a signed-in session whose user is an admin (<code>ADMIN_UIDS</code> or <code>admin:true</code>), as the session cookie or a Bearer token.</span></p>
<p class="ep-h">Responses</p>
<div class="ptab">
<div class="prow rrow">
<span class="r-code s2">200</span>
<span class="p-desc">Cleared.<span class="r-sig"><a href="#schema-Ok">Ok</a></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">401</span>
<span class="p-desc">No session, expired/revoked session, or a disabled account.<span class="r-sig"><code>{&quot;error&quot;:&quot;not signed in&quot;}</code></span></span>
</div>
<div class="prow rrow">
<span class="r-code s4">403</span>
<span class="p-desc">Signed in, but not an admin. The attempt is recorded in the audit log.<span class="r-sig"><code>{&quot;error&quot;:&quot;forbidden&quot;}</code></span></span>
</div>
</div>
</div>
</details>
</div>
</section>
<section class="api-sec" id="schemas">
<h2>Schemas</h2>
<p class="sub">The named shapes the endpoints above link to. The <code>State</code> blob
is <b>representative, not enforced</b> — the server stores it opaquely and the app
grows it over time.</p>
<div class="eps">
<details class="ep sch" id="schema-Error">
<summary>
<span class="sch-name"><code>Error</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">error<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">Human-readable message. This is the only error shape the API has.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-Ok">
<summary>
<span class="sch-name"><code>Ok</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">ok</span>
<span class="p-type">always true</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-PodcastShow">
<summary>
<span class="sch-name"><code>PodcastShow</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One show in the Podcasts section.</span>
</summary>
<div class="ep-body">
<p><code>feed</code> is the only field the episodes can be fetched with, and it is what the show is saved by in a profile.</p>
<div class="ptab">
<div class="prow">
<span class="p-name">feed<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The publisher's RSS URL</span>
</div>
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc">The directory's own id for the show.</span>
</div>
<div class="prow">
<span class="p-name">name<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">author</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">image</span>
<span class="p-type">string</span>
<span class="p-desc">HTTPS artwork.</span>
</div>
<div class="prow">
<span class="p-name">genre</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">country</span>
<span class="p-type">string</span>
<span class="p-desc">The storefront it was found in: <code>es</code> or <code>mx</code>.</span>
</div>
<div class="prow">
<span class="p-name">lang</span>
<span class="p-type">string</span>
<span class="p-desc">What the feed itself declares — <code>es</code>, <code>es-ES</code>, <code>es-mx</code>… — or null when it declares nothing, which is a &quot;kept, unconfirmed&quot; and not a &quot;not Spanish&quot;.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-PodcastEpisode">
<summary>
<span class="sch-name"><code>PodcastEpisode</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One episode: a file with a length, which is the difference that matters against a radio station — there is a position to remember and a place to resume from.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The feed's guid</span>
</div>
<div class="prow">
<span class="p-name">title<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">url<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The <code>https://</code> audio file to play. Never proxied.</span>
</div>
<div class="prow">
<span class="p-name">date</span>
<span class="p-type">string</span>
<span class="p-desc">ISO 8601</span>
</div>
<div class="prow">
<span class="p-name">duration</span>
<span class="p-type">integer</span>
<span class="p-desc">Seconds</span>
</div>
<div class="prow">
<span class="p-name">image</span>
<span class="p-type">string</span>
<span class="p-desc">Episode artwork</span>
</div>
<div class="prow">
<span class="p-name">episode</span>
<span class="p-type">integer</span>
<span class="p-desc"><code>itunes:episode</code>, when the feed numbers them.</span>
</div>
<div class="prow">
<span class="p-name">bytes</span>
<span class="p-type">integer</span>
<span class="p-desc">The enclosure's declared size.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-RadioStation">
<summary>
<span class="sch-name"><code>RadioStation</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One row in the Radio section: everything the screen needs to draw the station <i>and</i> to start playing it, because the <code>play()</code> has to happen inside the tap that chose it.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">src<em class="p-req" title="required">required</em></span>
<span class="p-type">&quot;soma&quot; | &quot;paradise&quot; | &quot;rb&quot;</span>
<span class="p-desc">Where it came from — <code>soma</code> (SomaFM, commercial-free), <code>paradise</code> (Radio Paradise, four hand-mixed channels) or <code>rb</code> (the public radio-browser directory). <code>src</code> + <code>id</code> is what <code>GET /api/radio/now</code> is asked about, and only the first two answer.</span>
</div>
<div class="prow">
<span class="p-name">id<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The station's id at that source.</span>
</div>
<div class="prow">
<span class="p-name">name<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">genre</span>
<span class="p-type">string</span>
<span class="p-desc">Free-form tags or the channel's own genre.</span>
</div>
<div class="prow">
<span class="p-name">detail</span>
<span class="p-type">string</span>
<span class="p-desc">The second line — country, codec, bitrate for the directory, or &quot;no advertising&quot; for the curated ones.</span>
</div>
<div class="prow">
<span class="p-name">image</span>
<span class="p-type">string</span>
<span class="p-desc">HTTPS logo</span>
</div>
<div class="prow">
<span class="p-name">url<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">The stream, already resolved to an HTTPS URL a browser plays natively. For SomaFM this comes from the channel's own <code>.pls</code> rather than a guessed bitrate URL.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-SessionUser">
<summary>
<span class="sch-name"><code>SessionUser</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">The caller's identity, as returned by /api/me and the sign-in routes.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc">Stable user id (16 base64url chars).</span>
</div>
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">admin</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-WebAuthnRegistrationOptions">
<summary>
<span class="sch-name"><code>WebAuthnRegistrationOptions</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">PublicKeyCredentialCreationOptionsJSON — pass to <code>startRegistration()</code> (@simplewebauthn/browser) or decode for <code>navigator.credentials.create()</code>.</span>
</summary>
<div class="ep-body">
<p>Resident keys are required; attestation is <code>none</code>.</p>
<div class="ptab">
<div class="prow">
<span class="p-name">challenge</span>
<span class="p-type">string</span>
<span class="p-desc">base64url</span>
</div>
<div class="prow">
<span class="p-name">rp</span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">rp.name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">rp.id</span>
<span class="p-type">string</span>
<span class="p-desc">The RP_ID the instance is configured with.</span>
</div>
<div class="prow">
<span class="p-name">user</span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.id</span>
<span class="p-type">string</span>
<span class="p-desc">base64url user handle</span>
</div>
<div class="prow">
<span class="p-name">user.name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.displayName</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">pubKeyCredParams</span>
<span class="p-type">object[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">authenticatorSelection</span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">authenticatorSelection.residentKey</span>
<span class="p-type">always &quot;required&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">authenticatorSelection.userVerification</span>
<span class="p-type">always &quot;preferred&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">attestation</span>
<span class="p-type">always &quot;none&quot;</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-WebAuthnRegistrationCredential">
<summary>
<span class="sch-name"><code>WebAuthnRegistrationCredential</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">RegistrationResponseJSON — the value <code>startRegistration()</code> resolves with (the created credential plus the authenticator's attestation response), sent back verbatim.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc">base64url credential id</span>
</div>
<div class="prow">
<span class="p-name">rawId</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">type</span>
<span class="p-type">always &quot;public-key&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response</span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response.clientDataJSON</span>
<span class="p-type">string</span>
<span class="p-desc">base64url</span>
</div>
<div class="prow">
<span class="p-name">response.attestationObject</span>
<span class="p-type">string</span>
<span class="p-desc">base64url</span>
</div>
<div class="prow">
<span class="p-name">response.transports</span>
<span class="p-type">string[]</span>
<span class="p-desc">e.g. [&quot;internal&quot;, &quot;hybrid&quot;] — stored for later logins.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-WebAuthnAuthenticationOptions">
<summary>
<span class="sch-name"><code>WebAuthnAuthenticationOptions</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">PublicKeyCredentialRequestOptionsJSON — pass to <code>startAuthentication()</code>.</span>
</summary>
<div class="ep-body">
<p><code>allowCredentials</code> is empty: the browser offers the user's discoverable passkeys itself.</p>
<div class="ptab">
<div class="prow">
<span class="p-name">challenge</span>
<span class="p-type">string</span>
<span class="p-desc">base64url</span>
</div>
<div class="prow">
<span class="p-name">rpId</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">userVerification</span>
<span class="p-type">always &quot;preferred&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">allowCredentials</span>
<span class="p-type">object[]</span>
<span class="p-desc">Always empty.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-WebAuthnAuthenticationCredential">
<summary>
<span class="sch-name"><code>WebAuthnAuthenticationCredential</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">AuthenticationResponseJSON — the value <code>startAuthentication()</code> resolves with, sent back verbatim.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc">base64url credential id</span>
</div>
<div class="prow">
<span class="p-name">rawId</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">type</span>
<span class="p-type">always &quot;public-key&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response</span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response.clientDataJSON</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response.authenticatorData</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response.signature</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">response.userHandle</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-State">
<summary>
<span class="sch-name"><code>State</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">The whole app state as one blob.</span>
</summary>
<div class="ep-body">
<p>The server treats it as opaque (it only strips <code>active</code> on save and reads a few fields for reminders and the admin dashboard) — the schema below is <b>representative, not enforced</b> (except <code>workouts</code> and <code>routines</code>, which must be arrays (or null) when present), and grows with the app. Concurrent writes are caught by the server's revision (<code>_rev</code>, see PUT /api/data); the client merges the two documents and decides by <code>_ts</code> which side's settings win.</p>
<div class="ptab">
<div class="prow">
<span class="p-name">_ts</span>
<span class="p-type">number</span>
<span class="p-desc">Client-set last-write timestamp (ms since epoch); drives sync.</span>
</div>
<div class="prow">
<span class="p-name">_rev</span>
<span class="p-type">integer</span>
<span class="p-desc">Server-set revision, incremented on every accepted PUT. Ignored when sent by a client.</span>
</div>
<div class="prow">
<span class="p-name">unit</span>
<span class="p-type">&quot;kg&quot; | &quot;lb&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">lang</span>
<span class="p-type">string</span>
<span class="p-desc">UI language code (&quot;en&quot;, &quot;de&quot;, &quot;pt&quot;, …) — also localizes pushes.</span>
</div>
<div class="prow">
<span class="p-name">theme</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">accent</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">workouts</span>
<span class="p-type"><a href="#schema-Workout">Workout</a>[]</span>
<span class="p-desc">Completed workouts, chronological.</span>
</div>
<div class="prow">
<span class="p-name">routines</span>
<span class="p-type"><a href="#schema-Routine">Routine</a>[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">week</span>
<span class="p-type">object</span>
<span class="p-desc">Weekly plan: weekday (0=Sunday … 6) → routine id.</span>
</div>
<div class="prow">
<span class="p-name">dayPlan</span>
<span class="p-type">object</span>
<span class="p-desc">Per-date overrides: ISO date → routine id, or &quot;rest&quot;. Wins over <code>week</code>.</span>
</div>
<div class="prow">
<span class="p-name">bodyweight</span>
<span class="p-type"><a href="#schema-BodyweightEntry">BodyweightEntry</a>[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">customEx</span>
<span class="p-type">object[]</span>
<span class="p-desc">User-created exercises (id, name, muscles…).</span>
</div>
<div class="prow">
<span class="p-name">exWeights</span>
<span class="p-type">object</span>
<span class="p-desc">Per-exercise last/best weight memory: exercise id → {w, d}.</span>
</div>
<div class="prow">
<span class="p-name">reminder</span>
<span class="p-type">object</span>
<span class="p-desc">Daily &quot;workout planned today&quot; push. The server reads this: at <code>time</code> (HH:MM, in <code>tz</code>) it sends one push if a routine is planned and nothing was logged yet.</span>
</div>
<div class="prow">
<span class="p-name">reminder.on</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">reminder.time</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">reminder.tz</span>
<span class="p-type">string | null</span>
<span class="p-desc">IANA zone (&quot;Europe/Zurich&quot;); the user's own clock.</span>
</div>
<div class="prow">
<span class="p-name">restSec</span>
<span class="p-type">number</span>
<span class="p-desc">Default rest-timer seconds.</span>
</div>
<div class="prow">
<span class="p-name">effort</span>
<span class="p-type">&quot;none&quot; | &quot;rir&quot; | &quot;rpe&quot; | null</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">equipProfiles</span>
<span class="p-type">object[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">settings</span>
<span class="p-type">object</span>
<span class="p-desc">Catch-all note: the remaining top-level keys (sound, keepAwake, gifSize, targetW, autoBackup, …) are flat settings values like the ones above.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-Workout">
<summary>
<span class="sch-name"><code>Workout</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One completed workout (representative shape).</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">d</span>
<span class="p-type">string <span class="p-hint">(date)</span></span>
<span class="p-desc">ISO day, e.g. &quot;2026-08-30&quot;.</span>
</div>
<div class="prow">
<span class="p-name">start</span>
<span class="p-type">number</span>
<span class="p-desc">ms since epoch</span>
</div>
<div class="prow">
<span class="p-name">end</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">routineId</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">bw</span>
<span class="p-type">number</span>
<span class="p-desc">Body weight that day, in <code>unit</code>.</span>
</div>
<div class="prow">
<span class="p-name">vol</span>
<span class="p-type">number</span>
<span class="p-desc">Total volume (Σ weight × reps).</span>
</div>
<div class="prow">
<span class="p-name">prs</span>
<span class="p-type">string[]</span>
<span class="p-desc">Exercise ids that hit a personal record.</span>
</div>
<div class="prow">
<span class="p-name">entries</span>
<span class="p-type">object[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">entries[].id</span>
<span class="p-type">string</span>
<span class="p-desc">Exercise id.</span>
</div>
<div class="prow">
<span class="p-name">entries[].topW</span>
<span class="p-type">number | null</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">entries[].sets</span>
<span class="p-type">object[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">entries[].sets[].w</span>
<span class="p-type">number</span>
<span class="p-desc">Weight.</span>
</div>
<div class="prow">
<span class="p-name">entries[].sets[].r</span>
<span class="p-type">number</span>
<span class="p-desc">Reps.</span>
</div>
<div class="prow">
<span class="p-name">entries[].sets[].done</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">entries[].sets[].rir</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">entries[].sets[].rpe</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-Routine">
<summary>
<span class="sch-name"><code>Routine</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">A workout template (representative shape).</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">emoji</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">ex</span>
<span class="p-type">object[]</span>
<span class="p-desc">Exercises with set/rep targets.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-BodyweightEntry">
<summary>
<span class="sch-name"><code>BodyweightEntry</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">d</span>
<span class="p-type">string <span class="p-hint">(date)</span></span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">w</span>
<span class="p-type">number</span>
<span class="p-desc">Weight in <code>unit</code>.</span>
</div>
<div class="prow">
<span class="p-name">t</span>
<span class="p-type">number</span>
<span class="p-desc">Timestamp (ms).</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-PushSubscription">
<summary>
<span class="sch-name"><code>PushSubscription</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">The browser's PushSubscription.toJSON() — only these fields are stored.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">endpoint<em class="p-req" title="required">required</em></span>
<span class="p-type">string <span class="p-hint">(uri)</span></span>
<span class="p-desc">Public https:// push-service URL.</span>
</div>
<div class="prow">
<span class="p-name">keys<em class="p-req" title="required">required</em></span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">keys.p256dh<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">keys.auth<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-AdminUserRow">
<summary>
<span class="sch-name"><code>AdminUserRow</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">created</span>
<span class="p-type">string | null</span>
<span class="p-desc">ISO timestamp.</span>
</div>
<div class="prow">
<span class="p-name">disabled</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">admin</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">invitedBy</span>
<span class="p-type">string | null</span>
<span class="p-desc">The invite code this account was created with.</span>
</div>
<div class="prow">
<span class="p-name">workouts</span>
<span class="p-type">integer</span>
<span class="p-desc">Total logged workouts.</span>
</div>
<div class="prow">
<span class="p-name">lastWorkout</span>
<span class="p-type">string | null</span>
<span class="p-desc">ISO day of the newest workout.</span>
</div>
<div class="prow">
<span class="p-name">lastSync</span>
<span class="p-type">number | null</span>
<span class="p-desc">The state's <code>_ts</code> (ms).</span>
</div>
<div class="prow">
<span class="p-name">hasPush</span>
<span class="p-type">boolean</span>
<span class="p-desc">Has at least one push subscription.</span>
</div>
<div class="prow">
<span class="p-name">live</span>
<span class="p-type"><a href="#schema-Presence">Presence</a> | null</span>
<span class="p-desc">Currently training, or null.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-Presence">
<summary>
<span class="sch-name"><code>Presence</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">Live-workout snapshot (from /api/activity heartbeats).</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">exIdx</span>
<span class="p-type">integer</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">exTotal</span>
<span class="p-type">integer</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">setsDone</span>
<span class="p-type">integer</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">setsTotal</span>
<span class="p-type">integer</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">startedAt</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">updatedAt</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-AdminUserDetail">
<summary>
<span class="sch-name"><code>AdminUserDetail</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">user</span>
<span class="p-type">object</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.id</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.created</span>
<span class="p-type">string | null</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.disabled</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.admin</span>
<span class="p-type">boolean</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">user.invitedBy</span>
<span class="p-type">string | null</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">unit</span>
<span class="p-type">&quot;kg&quot; | &quot;lb&quot;</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">lastSync</span>
<span class="p-type">number | null</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">routines</span>
<span class="p-type">object[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">routines[].id</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">routines[].name</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">routines[].emoji</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">routines[].count</span>
<span class="p-type">integer</span>
<span class="p-desc">Number of exercises.</span>
</div>
<div class="prow">
<span class="p-name">bodyweight</span>
<span class="p-type"><a href="#schema-BodyweightEntry">BodyweightEntry</a>[]</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">workouts</span>
<span class="p-type"><a href="#schema-Workout">Workout</a>[]</span>
<span class="p-desc">Full history, newest first.</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-Invite">
<summary>
<span class="sch-name"><code>Invite</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">code</span>
<span class="p-type">string</span>
<span class="p-desc">16 hex chars.</span>
</div>
<div class="prow">
<span class="p-name">note</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">createdBy</span>
<span class="p-type">string</span>
<span class="p-desc">Admin user id.</span>
</div>
<div class="prow">
<span class="p-name">created</span>
<span class="p-type">string</span>
<span class="p-desc">ISO timestamp.</span>
</div>
<div class="prow">
<span class="p-name">usedBy</span>
<span class="p-type">string | null</span>
<span class="p-desc">User id that redeemed the code (absent/null while unused).</span>
</div>
<div class="prow">
<span class="p-name">usedAt</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">usedByName</span>
<span class="p-type">string | null</span>
<span class="p-desc">Resolved display name (only in GET /api/admin/invites).</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-VitalsField">
<summary>
<span class="sch-name"><code>VitalsField</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One numeric field of one metric for one day, aggregated over the samples that carried it.</span>
</summary>
<div class="ep-body">
<p>A counter's day is its <code>sum</code>; a rate's is its <code>avg</code>; a gauge's is its <code>last</code>. Both are stored so the rule that picks one is a display decision rather than a storage one.</p>
<div class="ptab">
<div class="prow">
<span class="p-name">n</span>
<span class="p-type">integer</span>
<span class="p-desc">Samples that contributed.</span>
</div>
<div class="prow">
<span class="p-name">sum</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">min</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">max</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">last</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">avg</span>
<span class="p-type">number</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-VitalsDay">
<summary>
<span class="sch-name"><code>VitalsDay</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One day for one metric, keyed by the date the <i>phone</i> wrote (HAE stamps every sample with its own local offset, so the server never re-derives the day from its own clock).</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">day</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">n</span>
<span class="p-type">integer</span>
<span class="p-desc">Samples stored for this day.</span>
</div>
<div class="prow">
<span class="p-name">lastTs</span>
<span class="p-type">integer</span>
<span class="p-desc">Epoch ms of the day's newest sample.</span>
</div>
<div class="prow">
<span class="p-name">hours</span>
<span class="p-type">integer</span>
<span class="p-desc">How many hourly buckets this day has (0 or 1 when the automation grouped by Day, or when the samples arrived without an hour of their own). The buckets themselves are not in this response — <code>GET /api/vitals/hours</code> answers one metric and one day, because 24 buckets × every metric × every day is not something a grid of cards should download.</span>
</div>
<div class="prow">
<span class="p-name">f</span>
<span class="p-type">object</span>
<span class="p-desc">Field name as HAE wrote it — <code>qty</code>, <code>Avg</code>, <code>asleep</code>, <code>systolic</code>…</span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-VitalsMetric">
<summary>
<span class="sch-name"><code>VitalsMetric</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum"></span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">units</span>
<span class="p-type">string</span>
<span class="p-desc"></span>
</div>
<div class="prow">
<span class="p-name">sources</span>
<span class="p-type">string[]</span>
<span class="p-desc">The apps/devices that reported this metric, newest first.</span>
</div>
<div class="prow">
<span class="p-name">days</span>
<span class="p-type"><a href="#schema-VitalsDay">VitalsDay</a>[]</span>
<span class="p-desc"></span>
</div>
</div>
</div>
</details>
<details class="ep sch" id="schema-AuditEvent">
<summary>
<span class="sch-name"><code>AuditEvent</code></span>
<span class="ep-chev" aria-hidden="true"></span>
<span class="ep-sum">One line of the audit log.</span>
</summary>
<div class="ep-body">
<div class="ptab">
<div class="prow">
<span class="p-name">id<em class="p-req" title="required">required</em></span>
<span class="p-type">integer</span>
<span class="p-desc">Monotonic, never reset — a cleared log leaves a visible id gap.</span>
</div>
<div class="prow">
<span class="p-name">ts<em class="p-req" title="required">required</em></span>
<span class="p-type">number</span>
<span class="p-desc">ms since epoch.</span>
</div>
<div class="prow">
<span class="p-name">ev<em class="p-req" title="required">required</em></span>
<span class="p-type">string</span>
<span class="p-desc">Event name. Currently one of: <code>auth.register.ok|fail|denied</code>, <code>auth.login.ok|fail</code>, <code>auth.logout</code>, <code>auth.logout.all</code>, <code>auth.pair.create|ok|fail</code>, <code>admin.denied</code>, <code>admin.user.disable|enable</code>, <code>admin.invite.create|revoke</code>, <code>admin.audit.clear</code>.</span>
</div>
<div class="prow">
<span class="p-name">ok<em class="p-req" title="required">required</em></span>
<span class="p-type">boolean</span>
<span class="p-desc">false for failed/denied attempts.</span>
</div>
<div class="prow">
<span class="p-name">uid</span>
<span class="p-type">string</span>
<span class="p-desc">Acting (or affected) user id.</span>
</div>
<div class="prow">
<span class="p-name">name</span>
<span class="p-type">string</span>
<span class="p-desc">Acting user's name (max 40 chars).</span>
</div>
<div class="prow">
<span class="p-name">tgt</span>
<span class="p-type">string</span>
<span class="p-desc">Target user id (admin actions).</span>
</div>
<div class="prow">
<span class="p-name">tname</span>
<span class="p-type">string</span>
<span class="p-desc">Target user's name.</span>
</div>
<div class="prow">
<span class="p-name">msg</span>
<span class="p-type">string</span>
<span class="p-desc">Short detail — a failure reason code, or the invite code involved. Rejected invite guesses and unknown credential ids are deliberately never recorded.</span>
</div>
<div class="prow">
<span class="p-name">ip</span>
<span class="p-type">string</span>
<span class="p-desc">Only when AUDIT_IP is on — the full address (<code>full</code>) or just the network, /24 or /48 (<code>net</code>).</span>
</div>
</div>
</div>
</details>
</div>
</section>
</main>
<footer><div class="wrap foot">
<span class="c">KuentaGYM · AGPL-3.0 · © 2026 <a href="https://duarte-santos.ch" rel="noopener">Duarte Santos</a> · a rebranded fork of <a href="https://gitlab.com/DuarteSantos8/opengym" rel="noopener">openGym</a></span>
<div class="links">
<a href="docs.html">Docs</a>
<a href="about.html">About</a>
<a href="https://git.dploy.lol/dsantillan/kuentagym" rel="noopener">Source code</a>
<a href="/#download">Get started</a>
</div>
</div></footer>
<script src="site.js?v=20" defer></script>
<script>
/* Jumping to an anchor inside a collapsed card opens the card — and re-aligns, since
the browser scrolled to where the target was while it was still collapsed. */
;(() => {
const openTo = id => {
const el = id && document.getElementById(id)
if (!el) return
let opened = false
for (let d = el.closest('details'); d; d = d.parentElement && d.parentElement.closest('details')) {
if (!d.open) { d.open = true; opened = true }
}
// 'instant' on purpose: html has scroll-behavior:smooth, and an animated
// re-align races the jump the browser already started.
if (opened) requestAnimationFrame(() => el.scrollIntoView({ block: 'start', behavior: 'instant' }))
}
addEventListener('hashchange', () => openTo(location.hash.slice(1)))
document.addEventListener('click', e => {
const a = e.target.closest('a[href^="#"]')
if (a) openTo(a.getAttribute('href').slice(1))
})
openTo(location.hash.slice(1))
})()
/* Expand / collapse every card at once. */
document.querySelectorAll('[data-xall]').forEach(b => b.addEventListener('click', () => {
document.querySelectorAll('details.ep').forEach(d => { d.open = b.dataset.xall === '1' })
}))
</script>
</body>
</html>