From 214a1b5909b7bf232a969c43e12268e102c1d1cf Mon Sep 17 00:00:00 2001 From: Eric Luce <37158449+eluce2@users.noreply.github.com> Date: Sat, 31 Jan 2026 13:04:59 -0600 Subject: [PATCH] fix(typegen): convert list-tables endpoint from GET to POST Prevents 431 Request Header Fields Too Large when config grows. Passes config as JSON body instead of query param, matching test-connection and table-metadata endpoints. Co-Authored-By: Claude Opus 4.5 --- .changeset/list-tables-post.md | 5 ++ packages/typegen/src/server/app.ts | 64 ++++++++++--------- .../typegen/web/src/hooks/useListTables.ts | 6 +- 3 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 .changeset/list-tables-post.md diff --git a/.changeset/list-tables-post.md b/.changeset/list-tables-post.md new file mode 100644 index 00000000..a6871cea --- /dev/null +++ b/.changeset/list-tables-post.md @@ -0,0 +1,5 @@ +--- +"@proofkit/typegen": patch +--- + +Fix list-tables endpoint 431 error by converting from GET to POST diff --git a/packages/typegen/src/server/app.ts b/packages/typegen/src/server/app.ts index f50af4c2..3a51450b 100644 --- a/packages/typegen/src/server/app.ts +++ b/packages/typegen/src/server/app.ts @@ -432,42 +432,44 @@ export function createApiApp(context: ApiContext) { } }, ) - .get("/list-tables", zValidator("query", z.object({ config: z.string() })), async (c) => { - const input = c.req.valid("query"); - // Parse the JSON-encoded config string - let config: z.infer; - try { - config = typegenConfigSingle.parse(JSON.parse(input.config)); - } catch (_err) { - return c.json({ error: "Invalid config format" }, 400); - } - if (config.type !== "fmodata") { - return c.json({ error: "Invalid config type" }, 400); - } - try { - const result = createOdataClientFromConfig(config); - if ("error" in result) { + .post( + "/list-tables", + zValidator("json", z.object({ config: typegenConfigSingleRequestForValidation })), + async (c) => { + const rawInput = c.req.valid("json"); + const configWithType = + "type" in rawInput.config && rawInput.config.type + ? rawInput.config + : { ...(rawInput.config as Record), type: "fmdapi" as const }; + const config = typegenConfigSingle.parse(configWithType); + if (config.type !== "fmodata") { + return c.json({ error: "Invalid config type" }, 400); + } + try { + const result = createOdataClientFromConfig(config); + if ("error" in result) { + return c.json( + { + error: result.error, + kind: result.kind, + suspectedField: result.suspectedField, + }, + result.statusCode as ContentfulStatusCode, + ); + } + const { db } = result; + const tableNames = await db.listTableNames(); + return c.json({ tables: tableNames }); + } catch (err) { return c.json( { - error: result.error, - kind: result.kind, - suspectedField: result.suspectedField, + error: err instanceof Error ? err.message : "Failed to list tables", }, - result.statusCode as ContentfulStatusCode, + 500, ); } - const { db } = result; - const tableNames = await db.listTableNames(); - return c.json({ tables: tableNames }); - } catch (err) { - return c.json( - { - error: err instanceof Error ? err.message : "Failed to list tables", - }, - 500, - ); - } - }) + }, + ) // POST /api/test-connection .post( "/test-connection", diff --git a/packages/typegen/web/src/hooks/useListTables.ts b/packages/typegen/web/src/hooks/useListTables.ts index d45c6ae8..dc917259 100644 --- a/packages/typegen/web/src/hooks/useListTables.ts +++ b/packages/typegen/web/src/hooks/useListTables.ts @@ -24,9 +24,9 @@ export function useListTables(configIndex: number, enabled?: boolean) { throw new Error("Config not found or invalid type"); } - const res = await client.api["list-tables"].$get({ - query: { - config: JSON.stringify(config), + const res = await client.api["list-tables"].$post({ + json: { + config, }, });