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

Parked opened this
Closed without merging

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.

Notes

stopped parked by the crew deploy 9b4345b

opened this

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, ownPage in src/http/api.ts.
    • limit is a whole number from 1 to 200, default 50.
    • cursor is the id of the last item of the previous page. next_cursor is null on the last page.
    • A bad limit (0, 201, -1, abc, 1.5) is a 422 invalid_limit. A malformed or unknown cursor is a 422 invalid_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 in src/ changed to follow the new shape. The existing tests that read the bare array now read items. The shape is also noted in docs/ORIGINS.md.
  • Tests: test/own-lists.test.ts is new. For each route it checks the shape, pages with limit=2 to the end and gets exactly the unpaged list, and that bad limits and cursors are refused.
  • Parity helper: I widened test/parity.test.ts's call helper so its list falls back to items. That would also hide a bare-array regression on any other route that test reads.

Choices and omissions:

  • A bad limit is 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.

Closes #4841

2 earlier comments · 1 event
commented

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, ownPage in src/http/api.ts.
    • limit is a whole number from 1 to 200, default 50.
    • cursor is the id of the last item of the previous page. next_cursor is null on the last page.
    • A bad limit (0, 201, -1, abc, 1.5) is a 422 invalid_limit. A malformed or unknown cursor is a 422 invalid_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 in src/ changed to follow the new shape. The existing tests that read the bare array now read items. The shape is also noted in docs/ORIGINS.md.
  • Tests: test/own-lists.test.ts is new. For each route it checks the shape, pages with limit=2 to the end and gets exactly the unpaged list, and that bad limits and cursors are refused.
  • Parity helper: I widened test/parity.test.ts's call helper so its list falls back to items. That would also hide a bare-array regression on any other route that test reads.

Choices and omissions:

  • A bad limit is 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 — before the latest push

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.

commented

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: main added keyedWindow and keyedPage for lists paged by name. This branch's ownPage pages 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/origins and /api/v1/user/origin-apps still answer { items, next_cursor } with limit and cursor. Each now also keeps the timePhase timing that main added. The list is fetched under its own phase, and render times the paging and JSON response.
commented

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

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs