feat(api): API v1 writes, token grants, live events, OpenAPI, API keys settings #126
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/123-api-writes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #123. Stacked on #125 (#122 read endpoints): this branch starts from
feat/122-api-read, so until #125 merges the diff here includes its commits too. Merge #125 first; this PR's own commits are the five aftera93579e.Built as docs/api.md's decided choices A to H:
api_keys.grants, a list, default[]and never null, so every existing key gains nothing.suggestions,quick_notes,todos,sync. A grant that changes things also needscan_write.ApiKeys.allowed?/3is the one check, shared with MCP;/mereports grants.POST /documents/:id/pages(typed or drawn),PATCH /documents/:id(move),POST /notebooks,/folders,/reports,/pdfs(multipart upload or JSON, Choice F),/reviews. Each needs its MCP write tool. A read-only key gets403 read_only.Idempotency-Keymakes retries safe (24 hours).GET /events, a server-sent events stream of hints (ready,changes,suggestions,todos,sync), with a keepalive that re-checks the key. There is a newtranscribedchange kind, and mcp.md says to ignore unknown kinds.priv/static/openapi.json, served publicly at/api/v1/openapi.json. A test checks that it lists every route and nothing else.RmAnalyzer.QRCode), with no new dependency, and checked against segno and zbarimg.Tests: write_test (30), app_test (29), api_keys_grants_test (14), events_test (5), openapi_test (3), qr_code_test (10), changes_transcribed_test (2), settings tests.
mix precommit: 1770 passed.Posted by Haystack for Nye (its token can't comment).
Nye's review of PR #126 (#123 writes, grants, app features, events) at
3a41b23Verdict: one small fix (F3, low), then ready. Everything on the focus list holds.
Finding
F3 (low): POST /api/v1/notebooks with a non-string folder_id (5, ["work"]) answers 201 and puts the notebook in My files
instead of 400 (Notebooks.make's string/1 turns it into ""). Folder-limited keys are still refused, so no reach bypass.
Fix: in WriteController.create_notebook, 400 invalid_params when folder_id is present and not a string (same for name).
Test: out/write_attack_nye_test.exs, cases 2 and 3 (
mix test <file> --only case:2 --only case:3).Held (C16)
Nits (no change needed to ship)
Posted by Haystack for Nye (its token can't comment).
Nye's re-review at
d737848: Re-checked atd737848. F3 is fixed: every non-string folder_id (false, true, 0, 1.5, [], lists, maps) gets a 400 naming folder_id; null or missing still files in My files for full-access keys; folder-limited keys are still refused outside their folders; read-only keys get 403 and no key gets 401 before the type check. All 25 of my attack tests pass. Full precommit passes on the head (1796 tests) and on main merged with it (1797). CI green. Approve from my side; the ship report is with Jeremy.Haystack's note: the head has since moved one commit to
ec859da(fix(api): 400 for a non-string name on POST /notebooks): a two-line change inwrite_controller.exthat runs the sameoptional_stringcheck onname, plus one test. I read the diff; CI is green onec859daand the PR is mergeable. Nye has the re-check of that commit from Upper Wolfjaw.Posted by Haystack for Nye (its token can't comment).
Nye's re-check at
ec859da: clean.The one new commit makes a
namethat isn't a string get a 400 instead of a 500. Checked:folder_id→ 400;nullstill works; folder-limited keys still refused).mix precommitpasses on main merged with this PR (1798 tests, no conflicts). CI green atec859da.No open findings. Ready to merge on Jeremy's ship it.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.