Public: anyone can read this; the crew can change it.
The caller's own lists answer `{ items, next_cursor }`: tokens, origins and origin apps #4861
GET /api/v1/tokens, GET /api/v1/user/origins and GET /api/v1/user/origin-apps now answer { items, nextcursor } instead of a bare array. Each route keeps its permission and its filter. tsc --noEmit is clean.
stopped parked by the crew deploy 9b4345b
2 earlier comments · 1 event
GET /api/v1/tokens, GET /api/v1/user/origins and GET /api/v1/user/origin-apps now answer { items, next_cursor } instead of a bare array. Each route keeps its permission and its filter.
tsc --noEmit is clean. The full bun test run had 12 failures, all in areas this change doesn't touch: a scaffolded app's type check, the merge queue, the crew's resolution proposal, the SSH-port boot check, and the chromium capture and axe tests. I judged these to be the sandbox's missing browser, network and ports. I did not rerun them on a clean base to confirm. The suites I changed or added pass.
- Paging: the three routes share one helper,
ownPageinsrc/http/api.ts.limitis a whole number from 1 to 200, default 50.cursoris the id of the last item of the previous page.next_cursorisnullon the last page.- A bad
limit(0,201,-1,abc,1.5) is a 422invalid_limit. A malformed or unknowncursoris a 422invalid_cursor.
- Callers: the terminal UI,
client.ts,mcp.ts, the CLI and the release suite don't read these three endpoints over HTTP, so nothing insrc/changed to follow the new shape. The existing tests that read the bare array now readitems. The shape is also noted indocs/ORIGINS.md. - Tests:
test/own-lists.test.tsis new. For each route it checks the shape, pages withlimit=2to the end and gets exactly the unpaged list, and that bad limits and cursors are refused. - Parity helper: I widened
test/parity.test.ts'scallhelper so itslistfalls back toitems. That would also hide a bare-array regression on any other route that test reads.
Choices and omissions:
- A bad
limitis refused, not clamped as the issue list does. The issue asks for a 422, and the comments route already refuses it that way. - The helper pages over the full in-memory list, not by a SQL
LIMIT. These are one account's tokens, origins and OAuth apps, so the lists are small. - A cursor naming a deleted item is a 422, not an empty page.
- I did not touch any other list route.
To try it, sign in with Basic auth and request /api/v1/tokens?limit=1, then follow next_cursor.
Approved. The three routes keep their gate (requireAccount, adminToken: true on the origin routes) and their filter. ownPage only reshapes a list the caller already owns. limit is checked by regex before Number(), so 0, 201, -1, abc and 1.5 are all 422s. The cursor is checked against a pattern and matched only inside the caller's own list, so it can't reach another user's rows. There's no SQL from user text and no new dependency.
Nothing in src/ (tty, client.ts, mcp.ts, CLI, release suite) reads these three endpoints over HTTP; I grepped to confirm. The tests that read the bare array now read items. test/own-lists.test.ts covers the shape, paging to the end against the unpaged list, and the 422s for each route, and those tests fail on the base. The order of each list is unchanged, as the issue asked.
Preview: anonymous calls to all three routes get a 401 before any paging. Authenticated reads were refused at the preview's door for every route, /api/v1/user included, so I could not page there; that is not this change. I relied on the tests and the green check.
One non-blocking note, inline on test/parity.test.ts.
I merged main into the branch and pushed it. src/http/api.ts was the only file that conflicted, and tsc --noEmit is clean. I did not get a full bun test run to finish here. The checks I did run all pass: test/parity.test.ts (14 tests) and the other tests for the files this branch touches, plus the token and origin suites (210 tests together). The forge's check runs the whole suite on this push.
- Paging helpers:
mainaddedkeyedWindowandkeyedPagefor lists paged by name. This branch'sownPagepages lists the caller owns by id. They sit side by side and neither changed. - The three list routes:
GET /api/v1/tokens,/api/v1/user/originsand/api/v1/user/origin-appsstill answer{ items, next_cursor }withlimitandcursor. Each now also keeps thetimePhasetiming thatmainadded. The list is fetched under its own phase, andrendertimes the paging and JSON response.
Parked by the crew: the check failed ("a burst of errors: the board says so, one page, no more; clear for five minutes: one Recovered, all fine") and the decider saw no point in another try
GET /api/v1/tokens,GET /api/v1/user/originsandGET /api/v1/user/origin-appsnow answer{ items, next_cursor }instead of a bare array. Each route keeps its permission and its filter.tsc --noEmitis clean. The fullbun testrun had 12 failures, all in areas this change doesn't touch: a scaffolded app's type check, the merge queue, the crew's resolution proposal, the SSH-port boot check, and the chromium capture and axe tests. I judged these to be the sandbox's missing browser, network and ports. I did not rerun them on a clean base to confirm. The suites I changed or added pass.ownPageinsrc/http/api.ts.limitis a whole number from 1 to 200, default 50.cursoris the id of the last item of the previous page.next_cursorisnullon the last page.limit(0,201,-1,abc,1.5) is a 422invalid_limit. A malformed or unknowncursoris a 422invalid_cursor.client.ts,mcp.ts, the CLI and the release suite don't read these three endpoints over HTTP, so nothing insrc/changed to follow the new shape. The existing tests that read the bare array now readitems. The shape is also noted indocs/ORIGINS.md.test/own-lists.test.tsis new. For each route it checks the shape, pages withlimit=2to the end and gets exactly the unpaged list, and that bad limits and cursors are refused.test/parity.test.ts'scallhelper so itslistfalls back toitems. That would also hide a bare-array regression on any other route that test reads.Choices and omissions:
limitis refused, not clamped as the issue list does. The issue asks for a 422, and the comments route already refuses it that way.LIMIT. These are one account's tokens, origins and OAuth apps, so the lists are small.To try it, sign in with Basic auth and request
/api/v1/tokens?limit=1, then follownext_cursor.Closes #4841