diff --git a/api/openapi.yaml b/api/openapi.yaml index 1fbf6d1..710c738 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -64,8 +64,8 @@ info: servers: - url: / description: Same origin as the openGym web app (the normal deployment) - - url: https://gym.duarte-santos.ch - description: Example public instance + - url: https://opengym.example.com + description: Your self-hosted instance tags: - name: meta diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..4666033 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,30 @@ +{ + "name": "gym-app", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "js-yaml": "^4.1.0" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..bbce4a1 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "js-yaml": "^4.1.0" + } +} diff --git a/scripts/build-api-docs.mjs b/scripts/build-api-docs.mjs new file mode 100644 index 0000000..3f3e9bf --- /dev/null +++ b/scripts/build-api-docs.mjs @@ -0,0 +1,670 @@ +#!/usr/bin/env node +// Builds website/api.html — the static API reference — from api/openapi.yaml. +// +// node scripts/build-api-docs.mjs +// +// Deterministic: the same spec always produces byte-identical output (no +// timestamps), so re-running it only dirties the file when the spec changed. +// The page is plain HTML in the site's own design (styles.css + site.js) with +// native
cards per endpoint — no Swagger UI, no runtime rendering. +// +// js-yaml lives in the repo-root package.json (devDependency, build-time only). + +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import yaml from 'js-yaml' + +const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..') +const specPath = path.join(root, 'api', 'openapi.yaml') +const outPath = path.join(root, 'website', 'api.html') +const spec = yaml.load(fs.readFileSync(specPath, 'utf8')) + +/* ------------------------------------------------------------------ helpers */ + +const esc = s => String(s) + .replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"') + +// The subset of markdown the spec actually uses: `code`, **bold**, *italic*, links. +const mdInline = s => esc(String(s).trim()) + .replace(/`([^`]+)`/g, '$1') + .replace(/\*\*([^*]+)\*\*/g, '$1') + .replace(/(^|[\s(—>])\*([^*\n]+)\*(?=[\s.,;:)—]|$)/g, '$1$2') + .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') + +// One description onto one line (for table cells and card subtitles). +const mdCell = s => mdInline(String(s).replace(/\s*\n\s*/g, ' ')) + +// Block markdown: paragraphs and "- " lists (with wrapped continuation lines). +function mdBlock (src) { + const out = [] + let para = [], list = null + const flushPara = () => { if (para.length) { out.push(`

${mdInline(para.join(' '))}

`); para = [] } } + const flushList = () => { + if (list) { out.push(``); list = null } + } + for (const raw of String(src).split('\n')) { + const line = raw.trimEnd() + if (!line.trim()) { flushPara(); flushList(); continue } + if (/^- /.test(line.trim()) && !para.length) { + flushPara() + list = list || [] + list.push(line.trim().slice(2)) + } else if (list && /^\s/.test(raw)) { + list[list.length - 1] += ' ' + line.trim() + } else { + flushList() + para.push(line.trim()) + } + } + flushPara(); flushList() + return out.join('\n') +} + +const refName = ref => ref.split('/').pop() +const schemaLink = ref => `${esc(refName(ref))}` + +// A compact, human type for one JSON-schema node. +function fmtType (s) { + if (!s) return 'any' + if (s.$ref) return schemaLink(s.$ref) + if (s.oneOf) return s.oneOf.map(fmtType).join(' | ') + if (s.enum) return s.enum.map(v => esc(JSON.stringify(v))).join(' | ') + if (s.const !== undefined) return `always ${esc(JSON.stringify(s.const))}` + if (s.type === 'array') { + const it = s.items ? fmtType(s.items) : 'any' + return (/[ |]/.test(it.replace(/<[^>]*>/g, '')) ? `(${it})` : it) + '[]' + } + let t = Array.isArray(s.type) ? s.type.join(' | ') : (s.type || 'object') + const bits = [] + if (s.format) bits.push(s.format) + if (s.maxLength) bits.push(`≤ ${s.maxLength} chars`) + if (s.minimum !== undefined || s.maximum !== undefined) bits.push(`${s.minimum ?? ''}–${s.maximum ?? ''}`) + if (s.default !== undefined) bits.push(`default ${esc(JSON.stringify(s.default))}`) + return esc(t) + (bits.length ? ` (${bits.join(', ')})` : '') +} + +// One-line shape signature for a response body: { user: SessionUser } +function fmtSig (s) { + if (!s) return '' + if (s.$ref) return schemaLink(s.$ref) + if (s.properties) { + return '{ ' + Object.entries(s.properties) + .map(([k, v]) => `${esc(k)}: ${fmtType(v)}`).join(', ') + ' }' + } + return fmtType(s) +} + +// Rows for a property table, nesting one level into objects and object arrays. +function * propRows (schema, prefix = '', depth = 0) { + const req = new Set(schema.required || []) + for (const [k, v] of Object.entries(schema.properties || {})) { + yield { name: prefix + k, required: req.has(k), type: fmtType(v), desc: v.description || '' } + if (depth < 2) { + if (v.type === 'object' && v.properties) yield * propRows(v, `${prefix}${k}.`, depth + 1) + else if (v.type === 'array' && v.items && v.items.properties) yield * propRows(v.items, `${prefix}${k}[].`, depth + 1) + } + } +} + +function ptab (rows) { + if (!rows.length) return '' + return `
` + rows.map(r => ` +
+ ${esc(r.name)}${r.required ? 'required' : ''} + ${r.type} + ${r.desc ? mdCell(r.desc) : ''} +
`).join('') + `\n
` +} + +/* ------------------------------------------------------------ endpoint cards */ + +const TAGS = { + meta: { title: 'Meta', side: 'Health & public config' }, + auth: { title: 'Auth', side: 'Passkeys & sessions' }, + pairing: { title: 'Pairing', side: 'Connect the mobile app' }, + data: { title: 'Data', side: 'State sync' }, + push: { title: 'Push', side: 'Notifications & rest timer' }, + activity: { title: 'Activity', side: 'Live presence' }, + admin: { title: 'Admin', side: 'Users, invites, audit log' } +} + +// "Admin: list all users" → "List all users": the section heading and the ADMIN +// chip already say who may call it, so the prefix is noise on every admin card. +const sumText = s => { + const t = String(s || '').replace(/^Admin:\s*/, '') + return t.charAt(0).toUpperCase() + t.slice(1) +} + +function authOf (op, tag) { + if (Array.isArray(op.security) && op.security.length === 0) { + return { chip: 'public', line: 'Public — no authentication required.' } + } + if (tag === 'admin') { + return { + chip: 'admin', + line: 'Admin only — a signed-in session whose user is an admin (ADMIN_UIDS or admin:true), as the session cookie or a Bearer token.' + } + } + return { + chip: null, + line: 'Requires a session — the cookie set at sign-in, or Authorization: Bearer <token> from mobile-app pairing.' + } +} + +function responseRows (op) { + return Object.entries(op.responses || {}).map(([code, r]) => { + if (r.$ref) r = spec.components.responses[refName(r.$ref)] + const cls = 's' + code[0] + const content = r.content && r.content['application/json'] + const extras = [] + if (code.startsWith('2')) { + if (content && content.schema) extras.push(fmtSig(content.schema)) + if (r.headers) extras.push(`sets ${Object.keys(r.headers).map(esc).join(', ')}`) + } else if (content) { + const exs = [] + if (content.example) exs.push(content.example) + if (content.examples) for (const e of Object.values(content.examples)) exs.push(e.value) + if (content.schema && content.schema.example) exs.push(content.schema.example) + for (const e of exs) if (e && e.error) extras.push(`${esc(JSON.stringify({ error: e.error }))}`) + } + return ` +
+ ${esc(code)} + ${mdCell(r.description || '')}${extras.length ? `${extras.join(' · ')}` : ''} +
` + }).join('') +} + +function endpointCard (pathKey, method, op) { + const tag = (op.tags || [])[0] || 'meta' + const auth = authOf(op, tag) + const body = op.requestBody + const bodySchema = body && body.content && body.content['application/json'] && body.content['application/json'].schema + const example = bodySchema && (bodySchema.example ?? (body.content['application/json'].example)) + + let bodyHtml = '' + if (bodySchema) { + const optional = body.required === false ? ' (optional)' : '' + if (bodySchema.$ref) { + bodyHtml = `

Request body${optional}

${schemaLink(bodySchema.$ref)}

` + } else { + bodyHtml = `

Request body (JSON)${optional}

` + + ptab([...propRows(bodySchema)]) + } + if (example) { + bodyHtml += `\n
${esc(JSON.stringify(example, null, 2))}
` + } + } + + const params = (op.parameters || []).map(p => ({ + name: p.name + (p.in && p.in !== 'query' ? ` (${esc(p.in)})` : ''), + required: !!p.required, + type: fmtType(p.schema), + desc: p.description || '' + })) + // p.name may contain markup now; ptab escapes r.name — build rows pre-escaped instead: + const paramTab = params.length + ? `

Query parameters

` + params.map(r => ` +
+ ${r.name}${r.required ? 'required' : ''} + ${r.type} + ${r.desc ? mdCell(r.desc) : ''} +
`).join('') + `\n
` + : '' + + return ` +
+ + ${method.toUpperCase()} + ${esc(pathKey)}${auth.chip ? `${auth.chip}` : ''} + + ${mdCell(sumText(op.summary))} + +
+${mdBlock(op.description || '')} +

${lockSvg}${auth.line}

+${paramTab} +${bodyHtml} +

Responses

+
${responseRows(op)} +
+
+
` +} + +/* -------------------------------------------------------------- schema cards */ + +// A schema has no summary of its own, so the collapsed row borrows the first +// sentence of its description — and the body then starts at the second, rather +// than repeating what the reader just read on the way in. +function schemaCard (name, s) { + const desc = (s.description || '').trim() + const flat = desc.replace(/\s*\n\s*/g, ' ') + const m = flat.match(/^(.+?[.!?])(\s|$)/) + const lead = m ? m[1] : flat + const rest = m ? flat.slice(m[0].length).trim() : '' + const rows = [...propRows(s)] + return ` +
+ + ${esc(name)} + + ${lead ? mdCell(lead) : ''} + +
+${rest ? mdBlock(rest) : ''} +${rows.length ? ptab(rows) : '

Free-form object.

'} +
+
` +} + +/* ----------------------------------------------------------------- overview */ + +// The spec's info.description carries "### Heading" sections — each becomes a card. +const infoParts = spec.info.description.split(/^### /m).slice(1).map(chunk => { + const nl = chunk.indexOf('\n') + return { title: chunk.slice(0, nl).trim(), body: chunk.slice(nl + 1) } +}) + +const serversHtml = spec.servers.map(s => ` +
${esc(s.url)}${mdCell(s.description || '')}
`).join('') + +const overviewCards = infoParts.map(p => ` +
+

${esc(p.title)}

+${mdBlock(p.body)} +
`).join('') + +/* ---------------------------------------------------------------- assemble */ + +const lockSvg = '' + +const ops = [] +for (const [p, methods] of Object.entries(spec.paths)) { + for (const [m, op] of Object.entries(methods)) ops.push({ path: p, method: m, op }) +} + +const tagSections = Object.keys(TAGS).map(tag => { + const t = spec.tags.find(x => x.name === tag) || {} + const cards = ops.filter(o => (o.op.tags || [])[0] === tag) + .map(o => endpointCard(o.path, o.method, o.op)).join('\n') + return ` +
+

${TAGS[tag].title}

+

${mdCell(t.description || '')}

+
+${cards} +
+
` +}).join('\n') + +const schemaCards = Object.entries(spec.components.schemas) + .map(([n, s]) => schemaCard(n, s)).join('\n') + +const railTags = Object.keys(TAGS).map(tag => + ` ${TAGS[tag].title}${TAGS[tag].side}` +).join('\n') + +const css = ` +/* ------------------------------------------------------------- API reference + Generated page — the reference itself is static HTML in the site's design. + Layout: one 880px column of per-endpoint
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; } + +/* --------------------------------------------------- contents drawer (rail) + The chapter rail is closed by default. Below 980px it is the hamburger sheet + the whole site uses; from 980px up a quiet "Contents" pill opens it as a + drawer over the left edge, with a close button inside. The .toc-btn / + .rail-close / body.contents-open classes are the reusable pattern. */ +.toc-btn { display: none; } +@media (min-width: 980px) { + .toc-btn { + position: fixed; left: 18px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 62; + display: inline-flex; align-items: center; gap: 8px; + padding: 10px 17px 10px 15px; border-radius: 999px; cursor: pointer; + background: rgba(23, 24, 27, .85); + backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); + border: 1px solid var(--hair); color: var(--fg-2); + font-size: 13.5px; font-weight: 500; letter-spacing: -.01em; + transition: color .2s var(--ease), border-color .2s var(--ease), background-color .2s var(--ease); + } + .toc-btn:hover { color: var(--fg); border-color: rgba(255, 255, 255, .25); background: rgba(32, 33, 37, .92); } + .toc-btn svg { width: 15px; height: 15px; } + + body.topnav .side { + display: block; position: fixed; left: 0; right: auto; top: 0; bottom: 0; z-index: 80; + width: min(320px, 86vw); max-height: none; + padding: 58px 24px calc(34px + env(safe-area-inset-bottom)) calc(26px + env(safe-area-inset-left)); + background: #0a0b0c; border-right: 1px solid var(--hair-soft); border-bottom: 0; + overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; + box-shadow: 40px 0 80px rgba(0, 0, 0, .5); + transform: translateX(-102%); visibility: hidden; opacity: 1; pointer-events: auto; + transition: transform .32s var(--ease), visibility .32s; + } + body.topnav.contents-open .side { transform: none; visibility: visible; } + body.contents-open::after { + content: ""; position: fixed; inset: 0; z-index: 75; + background: rgba(0, 0, 0, .55); + backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); + opacity: 1; pointer-events: auto; + } + .rail-close { + position: absolute; top: 14px; right: 12px; width: 34px; height: 34px; + display: flex; align-items: center; justify-content: center; + border-radius: 9px; color: var(--fg-3); cursor: pointer; + transition: color .2s var(--ease), background-color .2s var(--ease); + } + .rail-close:hover { color: var(--fg); background: rgba(255, 255, 255, .06); } + .rail-close svg { width: 15px; height: 15px; } +} +@media (max-width: 979.98px) { .rail-close { display: none; } } +/* Self-sufficiency: with the rail closed the page never reserves rail space. */ +@media (min-width: 1300px) { body.topnav { padding-left: 0; } } +@media (prefers-reduced-motion: reduce) { body.topnav .side { transition-duration: .01ms; } } +` + +const js = ` +/* Contents drawer (>=980px; below that the hamburger sheet in site.js owns the rail). */ +;(() => { + const body = document.body + const btn = document.querySelector('.toc-btn') + const menu = document.getElementById('menu') + if (!btn || !menu) return + const set = open => { + body.classList.toggle('contents-open', open) + btn.setAttribute('aria-expanded', String(open)) + body.style.overflow = open ? 'hidden' : '' + } + btn.addEventListener('click', e => { e.stopPropagation(); set(!body.classList.contains('contents-open')) }) + menu.querySelector('.rail-close')?.addEventListener('click', () => set(false)) + document.addEventListener('click', e => { + if (!body.classList.contains('contents-open')) return + if (e.target.closest('#menu') || e.target.closest('.toc-btn')) return + set(false) + }) + menu.addEventListener('click', e => { if (e.target.closest('a')) set(false) }) + document.addEventListener('keydown', e => { if (e.key === 'Escape') set(false) }) + addEventListener('resize', () => { + if (innerWidth < 980) set(false) + else { + // crossing up: make sure a hamburger-opened sheet doesn't linger + body.classList.remove('menu-open'); menu.classList.remove('open') + if (!body.classList.contains('contents-open')) body.style.overflow = '' + } + }) +})() + +/* 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' }) +})) +` + +const html = ` + + + + + +API — openGym + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

API

+

Every route the openGym backend serves — passkey auth, state sync, + push, pairing, admin — as one hand-written + OpenAPI spec. The same file lives + in the repository + at api/openapi.yaml, next to the one server file it documents.

+ +

+ OpenAPI ${esc(spec.openapi)} + openGym v${esc(spec.info.version)} + ${ops.length} endpoints + ${esc(spec.info.license.name)} +

+ +
+

Overview

+

${mdCell(spec.info.summary)}. One Node file, no framework, JSON-file + storage, HMAC-signed session cookies.

+
${serversHtml} +
+
${overviewCards} +
+
+ +
+ + +
+${tagSections} + +
+

Schemas

+

The named shapes the endpoints above link to. The State blob + is representative, not enforced — the server stores it opaquely and the app + grows it over time.

+
+${schemaCards} +
+
+
+ + + + + + + +` + +fs.writeFileSync(outPath, html) +console.log(`wrote ${path.relative(root, outPath)} — ${ops.length} endpoints, ${Object.keys(spec.components.schemas).length} schemas, ${(html.length / 1024).toFixed(1)} KB`) diff --git a/website/README.md b/website/README.md index c05addc..7b6e5ae 100644 --- a/website/README.md +++ b/website/README.md @@ -28,6 +28,12 @@ two things that come from the public gitlab.com API at view time — the star/is counts and the About page's release timeline. Those two URLs pointed at api.github.com until that account was suspended; they go back once it is restored. +`api.html` is the one **generated** file in here: `node scripts/build-api-docs.mjs` +rewrites it from `../api/openapi.yaml`. Edit the spec, re-run the script, commit both — +never hand-edit `api.html`, the next run overwrites it. The page is static HTML in this +site's own design (no Swagger UI, nothing rendered at view time); the only script of its +own it carries is the contents drawer and the card expand/collapse. + `styles.css` and `site.js` are cache-busted with `?v=N` — nginx serves the site with `no-cache, must-revalidate`, but the query bump is what saves a Cloudflare edge from handing out an old stylesheet with new markup. Bump it on every change. diff --git a/website/api.html b/website/api.html index c986f2b..a55f2da 100644 --- a/website/api.html +++ b/website/api.html @@ -1,4 +1,7 @@ + @@ -6,104 +9,187 @@ API — openGym + + + + + + + + + + - - - + @@ -129,33 +215,2007 @@ main.api-main .lead a { color: var(--acc); } - -