Skip to content

fix(web): register the drifted document endpoints in the api contract#1283

Open
abhay-codes07 wants to merge 1 commit into
supermemoryai:mainfrom
abhay-codes07:fix/endpoint-map-contract-drift
Open

fix(web): register the drifted document endpoints in the api contract#1283
abhay-codes07 wants to merge 1 commit into
supermemoryai:mainfrom
abhay-codes07:fix/endpoint-map-contract-drift

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

What

The @repo/lib endpoint map and validation schemas have drifted behind what the web app actually exchanges with the API. Three concrete gaps:

  1. categories is missing from DocumentsWithMemoriesQuerySchema. The memories grid and the X-bookmarks status query both filter by categories on @post/documents/documents — and both smuggle it past client validation with disableValidation: true because the schema doesn't know the field. Any future caller that filters by category without remembering that flag gets the key silently stripped and a filter that no-ops.

  2. @post/documents/documents/facets was never registered. DocumentFacetsQuerySchema exists in the validation package but is imported nowhere — dead code — while the memories grid calls the endpoint as an untyped raw URL and hand-casts the response to a local type.

  3. @patch/documents/:id was never registered. MemoryUpdateSchema exists for exactly this (its own comment pairs it with MemoryAddSchema, but only the add path got wired). The document-edit and file-metadata mutations PATCH via template-literal URLs (`@patch/documents/${id}`), bypassing all request/response typing.

Changes

  • DocumentsWithMemoriesQuerySchema gains categories: z.array(z.string()).optional()
  • New DocumentFacetSchema / DocumentFacetsResponseSchema (mirroring the shape the grid already consumes, with total optional since the UI guards it), and @post/documents/documents/facets registered with the previously-dead query schema as input
  • @patch/documents/:id registered with MemoryUpdateSchema / MemoryResponseSchema / params, and both PATCH call sites in use-document-mutations.ts converted to the typed route with params: { id }
  • bun tests covering the categories field and the facets response shape

Deliberately out of scope

The existing disableValidation: true flags stay put, including on the two calls that motivated the categories fix. Every current caller of @post/documents/documents sets the flag, which means output validation against DocumentsWithMemoriesResponseSchema has never been exercised in production — removing the flags safely needs someone to verify the declared response schemas against live responses (I don't have staging access). With the schemas now correct, that cleanup becomes a mechanical follow-up.

Testing

  • bun test in packages/validation — 12 pass (4 new)
  • tsc --noEmit -p packages/validation — clean
  • bun test + bun run build in apps/web — clean
  • biome check on all touched files — clean

cc @MaheshtheDev

The endpoint map and validation schemas have fallen behind what the
web app actually exchanges with the API:

- the memories grid and the X-bookmarks status query filter
  @post/documents/documents by `categories`, a field
  DocumentsWithMemoriesQuerySchema doesn't declare — both smuggle it
  past client validation with disableValidation, and any future caller
  that forgets the flag gets the key silently stripped and a filter
  that no-ops
- @post/documents/documents/facets was never registered:
  DocumentFacetsQuerySchema sits unused in the validation package
  while the grid calls the endpoint as an untyped raw URL and
  hand-casts the response
- @patch/documents/:id was never registered even though
  MemoryUpdateSchema exists for exactly this pairing; the
  document-edit and file-metadata mutations PATCH via template-literal
  URLs with no request/response typing

Add `categories` to the documents query schema, introduce
DocumentFacetSchema/DocumentFacetsResponseSchema (total optional — the
UI already guards its absence) and register the facets endpoint with
the previously-dead query schema, register @patch/documents/:id with
MemoryUpdateSchema/MemoryResponseSchema/params, and convert both PATCH
call sites to the typed route.

The existing disableValidation flags are deliberately left in place:
every current caller of @post/documents/documents sets one, so output
validation has never been exercised against production responses;
removing them is a follow-up that needs verification against the live
API. With the schemas now truthful, that cleanup becomes mechanical.

Tested: bun test in packages/validation (12 pass, 4 new), tsc --noEmit
on packages/validation, bun test + bun run build in apps/web, biome
clean on all touched files.
Copilot AI review requested due to automatic review settings July 13, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants