API.md: document every endpoint (page tags, Next server routes, public/auth aliases)
release gate / check (push) Failing after 6m39s

Cross-checked all 140 registered Go routes against the reference; the only
undocumented ones were the page-tag endpoints. Add POST /api/pages/{id}/tags
and DELETE /api/pages/{id}/tags/{tagId} plus a Page tags subsection (owner-or-
shared tag rule, metadata with no content-version bump, cascade, sidebar
drag-to-tag), and surface tags:[{tag}] in the page list/detail projections.

Clarify two aliases: GET /share/bookmark/{id} on Go is the rate-limited public
JSON projection (Next.js renders the HTML page at the same path), and Go's
/api/auth/ catch-all implements only session+signout (other subpaths 404 on
Go, served by Next).

Add a Next.js server routes subsection: the /api/[...path] proxy (assertion
signing, CSRF + 1 MiB streaming cap, X-Next-Cursor passthrough, no client
Authorization forwarding), NextAuth /api/auth/*, and POST /api/session/revoke
(honest {revoked,reason} global-revocation reporting).

Docs-only; no version bump.
This commit is contained in:
Andrew S Erwin
2026-11-19 14:03:03 -06:00
parent 7f64cbae0b
commit ef69be6320
+32 -3
View File
@@ -31,6 +31,9 @@ capped (100 per bookmark/tag/collection share, 200 per shared date).
| GET, POST | `/api/auth/callback/authelia` | **501**, client-owned callback stub | | GET, POST | `/api/auth/callback/authelia` | **501**, client-owned callback stub |
The browser's NextAuth `/api/auth/*` endpoints remain on the Next server. The browser's NextAuth `/api/auth/*` endpoints remain on the Next server.
Go's `/api/auth/` catch-all implements only `GET /api/auth/session` and
`POST /api/auth/signout`; every other subpath (`csrf`, `providers`, `signin`,
`callback/credentials`, …) answers **404** on Go and is served by Next.
Direct Go API consumers use the `superbrain_session` cookie from login. Direct Go API consumers use the `superbrain_session` cookie from login.
`TIER=core|multi` (or an explicit `AUTH_MODE` override) decides which half `TIER=core|multi` (or an explicit `AUTH_MODE` override) decides which half
of the auth surface is live: in `oidc` mode login/signup/password-reset all of the auth surface is live: in `oidc` mode login/signup/password-reset all
@@ -55,6 +58,17 @@ of a qualifying administrator — e.g. after demoting the last one — never
re-opens promotion through signup. Recovery is operator-driven re-opens promotion through signup. Recovery is operator-driven
(`ADMIN_EMAILS` + `make seed`, or promotion by an existing admin). (`ADMIN_EMAILS` + `make seed`, or promotion by an existing admin).
### Next.js server routes
The web server (`web/app/api/`) exposes three route families; everything else
is proxied:
| Method | Path | Behavior |
|---|---|---|
| ALL | `/api/[...path]` | Server-side proxy to the Go API. Signs a 60s Bearer assertion from the NextAuth session, forwards the signed observed client IP, enforces the same-origin / `Sec-Fetch-Site` CSRF check and the 1 MiB streaming body cap, and passes through `X-Next-Cursor`. Does **not** forward client `Authorization` headers (so `sb_` keys only work against Go directly) |
| GET, POST | `/api/auth/*` | NextAuth (Auth.js): `csrf`, `providers`, `signin`, `signout`, `session`, `callback/credentials`, `callback/authelia`. The browser session lives here; Go's `/api/auth/` only implements `session`/`signout` |
| POST | `/api/session/revoke` | Explicit "sign out everywhere": calls Go `POST /api/auth/signout` with a signed assertion and reports honestly — `{revoked:true}` on success, `{revoked:false,reason}` (`no-backend-session` / `backend-error` / `unreachable`) when global revocation could not be confirmed. Same-origin `Origin` required (403 otherwise). The NextAuth `signOut` event is a fail-open backstop |
### API keys (MCP / machine clients) ### API keys (MCP / machine clients)
Personal long-lived Bearer credentials (`sb_` + 43 base64url characters) for Personal long-lived Bearer credentials (`sb_` + 43 base64url characters) for
@@ -243,8 +257,11 @@ projection and UI agree. Detail responses also include
| GET | `/api/bookmarks/{id}/markdown` | Markdown attachment, owned/shared only | | GET | `/api/bookmarks/{id}/markdown` | Markdown attachment, owned/shared only |
| GET | `/api/preview?url=...` | `{title,description,ogTitle,ogDescription,ogImage,favicon}`; nullable on fetch failure | | GET | `/api/preview?url=...` | `{title,description,ogTitle,ogDescription,ogImage,favicon}`; nullable on fetch failure |
| GET | `/api/public/bookmarks/{id}` | Public bookmark projection without login; private records return 404 | | GET | `/api/public/bookmarks/{id}` | Public bookmark projection without login; private records return 404 |
| GET | `/share/bookmark/{id}` | Go serves the same public JSON projection as `/api/public/bookmarks/{id}` at this path (per-client + per-id rate limited). The Next.js server renders the public **HTML** page at the same path for browsers |
Public HTML pages remain at `/share/bookmark/{id}` on the Next.js server. Browsers get the public **HTML** page at `/share/bookmark/{id}` from the
Next.js server; the Go API serves the public **JSON** projection at that same
path (table above).
For pagination, read the `X-Next-Cursor` response header and pass that opaque For pagination, read the `X-Next-Cursor` response header and pass that opaque
value as `cursor` with the same filters. An absent header marks the final page. value as `cursor` with the same filters. An absent header marks the final page.
`limit` must be between 1 and 200. The web proxy forwards the cursor header. `limit` must be between 1 and 200. The web proxy forwards the cursor header.
@@ -287,10 +304,10 @@ test-only). CardDAV keeps the configured HTTPS port.
| PATCH | `/api/kanban/columns/{id}` | Updated column; body `{label?,color?}` | | PATCH | `/api/kanban/columns/{id}` | Updated column; body `{label?,color?}` |
| DELETE | `/api/kanban/columns/{id}` | `{ok:true,movedTo,moved}`; moves cards, never deletes bookmarks; refuses last column | | DELETE | `/api/kanban/columns/{id}` | `{ok:true,movedTo,moved}`; moves cards, never deletes bookmarks; refuses last column |
| PUT | `/api/kanban/cards/{id}` | Moved bookmark; body `{columnId,position,version}`. Reorders the target column (0-based position, clamped at the end) and normalizes every card's `kanbanPosition`. Owner only. `version` is REQUIRED: 400 when missing/invalid, 409 when stale; success bumps the moved card's `version` | | PUT | `/api/kanban/cards/{id}` | Moved bookmark; body `{columnId,position,version}`. Reorders the target column (0-based position, clamped at the end) and normalizes every card's `kanbanPosition`. Owner only. `version` is REQUIRED: 400 when missing/invalid, 409 when stale; success bumps the moved card's `version` |
| GET | `/api/pages?search=...` | Pages, pinned first, with `parentId` and `_count.{bookmarks,children}`; title/content substring search treats `%` and `_` literally and uses trigram indexes | | GET | `/api/pages?search=...` | Pages, pinned first, with `parentId`, `tags:[{tag}]` and `_count.{bookmarks,children}`; title/content substring search treats `%` and `_` literally and uses trigram indexes |
| POST | `/api/pages` | 201 page; body `{title?,content?,parentId?}`. `parentId` must be an owned page; a missing/foreign parent is 400 | | POST | `/api/pages` | 201 page; body `{title?,content?,parentId?}`. `parentId` must be an owned page; a missing/foreign parent is 400 |
| PUT | `/api/pages` | `{ok:true}`; complete `{order:[id,...]}` | | PUT | `/api/pages` | `{ok:true}`; complete `{order:[id,...]}` |
| GET | `/api/pages/{id}` | Page plus ordered `bookmarks:[{bookmark}]`, owner-scoped `backlinks:[{id,title,updatedAt}]`, resolved outgoing `links:[{id,title}]`, and `embeds:[{collectionId,viewId,position,collection,view}]` | | GET | `/api/pages/{id}` | Page plus `tags:[{tag}]`, ordered `bookmarks:[{bookmark}]`, owner-scoped `backlinks:[{id,title,updatedAt}]`, resolved outgoing `links:[{id,title}]`, and `embeds:[{collectionId,viewId,position,collection,view}]` |
| PATCH | `/api/pages/{id}` | Updated page; `{title?,content?,pinned?,icon?,parentId?,version?,addBookmarkId?,removeBookmarkId?}`. `version` (the base revision from GET) is REQUIRED with `content`: 400 when missing, 409 when stale. Metadata-only patches (including moving a page) stay version-free and do not bump the revision. Moving under itself or a descendant is rejected 400 (no cycles) | | PATCH | `/api/pages/{id}` | Updated page; `{title?,content?,pinned?,icon?,parentId?,version?,addBookmarkId?,removeBookmarkId?}`. `version` (the base revision from GET) is REQUIRED with `content`: 400 when missing, 409 when stale. Metadata-only patches (including moving a page) stay version-free and do not bump the revision. Moving under itself or a descendant is rejected 400 (no cycles) |
| GET | `/api/pages/{id}/backlinks` | Owner-scoped `[{id,title,updatedAt}]` from `PageLink` — the pages whose Markdown links here | | GET | `/api/pages/{id}/backlinks` | Owner-scoped `[{id,title,updatedAt}]` from `PageLink` — the pages whose Markdown links here |
| GET | `/api/pages/{id}/revisions` | Version history metadata `[{id,version,title,icon,createdAt,length}]`, newest first; bodies fetched separately | | GET | `/api/pages/{id}/revisions` | Version history metadata `[{id,version,title,icon,createdAt,length}]`, newest first; bodies fetched separately |
@@ -298,6 +315,18 @@ test-only). CardDAV keeps the configured HTTPS port.
| POST | `/api/pages/{id}/revisions/{revisionId}/restore` | Restores a snapshot as a **new** version; body `{version}` (current base) — 400 missing, 409 stale. The restore itself is recorded in history | | POST | `/api/pages/{id}/revisions/{revisionId}/restore` | Restores a snapshot as a **new** version; body `{version}` (current base) — 400 missing, 409 stale. The restore itself is recorded in history |
| DELETE | `/api/pages/{id}` | Moves the page to Trash; keeps bookmarks and promotes child pages. Restoring also restores its revisions and creates a new revision | | DELETE | `/api/pages/{id}` | Moves the page to Trash; keeps bookmarks and promotes child pages. Restoring also restores its revisions and creates a new revision |
| GET | `/api/pages/{id}/markdown` | Markdown attachment | | GET | `/api/pages/{id}/markdown` | Markdown attachment |
| POST | `/api/pages/{id}/tags` | Attaches a tag; body `{tagId}`; returns the refreshed page projection (with `tags`). 400 missing/invalid tag, 404 foreign page. Idempotent (`ON CONFLICT DO NOTHING`) |
| DELETE | `/api/pages/{id}/tags/{tagId}` | Detaches a tag; returns the refreshed page projection. 404 foreign page |
### Page tags
Pages carry tags like bookmarks (`PageTag`, migration 023). A tag may be
attached when it is owned by the caller **or shared with them** — the same
rule as bookmark tags. Tagging is metadata: it neither requires nor bumps the
page content `version`, and the join row cascades when the page or the tag is
deleted. The sidebar's "Untagged Pages" list is derived client-side from the
`tags` array on `GET /api/pages` (empty = untagged); dragging a page onto a tag
calls `POST /api/pages/{id}/tags`.
### Connected pages (phase 3) ### Connected pages (phase 3)