feat(docs): add gzip compression to docs-ledger publish requests#16033
feat(docs): add gzip compression to docs-ledger publish requests#16033broady wants to merge 6 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
Co-Authored-By: cbro <cbro@buildwithfern.com>
Co-Authored-By: cbro <cbro@buildwithfern.com>
… calls Co-Authored-By: cbro <cbro@buildwithfern.com>
Co-Authored-By: cbro <cbro@buildwithfern.com>
Co-Authored-By: cbro <cbro@buildwithfern.com>
Co-Authored-By: cbro <cbro@buildwithfern.com>
4c37296 to
6605a3a
Compare
| const savedFetch = globalThis.fetch; | ||
| globalThis.fetch = createGzipFetch(); | ||
| const fdr = createFdrService({ | ||
| token: token.value, | ||
| ...(Object.keys(headers).length > 0 && { headers }) | ||
| }); | ||
| globalThis.fetch = savedFetch; |
There was a problem hiding this comment.
Critical: Global state corruption on error
If createFdrService() throws an exception, globalThis.fetch will remain permanently modified to the gzip-compressing version, affecting all subsequent fetch calls in the process. This will cause subsequent non-compressed endpoints to receive gzipped data they don't expect.
Fix: Wrap in try/finally:
const savedFetch = globalThis.fetch;
try {
globalThis.fetch = createGzipFetch();
const fdr = createFdrService({
token: token.value,
...(Object.keys(headers).length > 0 && { headers })
});
} finally {
globalThis.fetch = savedFetch;
}| const savedFetch = globalThis.fetch; | |
| globalThis.fetch = createGzipFetch(); | |
| const fdr = createFdrService({ | |
| token: token.value, | |
| ...(Object.keys(headers).length > 0 && { headers }) | |
| }); | |
| globalThis.fetch = savedFetch; | |
| const savedFetch = globalThis.fetch; | |
| let fdr; | |
| try { | |
| globalThis.fetch = createGzipFetch(); | |
| fdr = createFdrService({ | |
| token: token.value, | |
| ...(Object.keys(headers).length > 0 && { headers }) | |
| }); | |
| } finally { | |
| globalThis.fetch = savedFetch; | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
Description
Refs FER-10484
Adds transparent gzip compression to docs-ledger publish request bodies (register, finish, preview register) using the oRPC SDK's built-in
fetchoption. Full typed client is preserved — no raw fetch calls.Depends on https://github.com/fern-api/fern-platform/pull/11324 (adds
fetchoption toCreateDocsLedgerClientOptions).Changes Made
compressedLedgerFetch.ts: streaming gzip viaCompressionStreamAPI, passed as customfetchtocreateDocsLedgerClientpublishDocsLedger.ts: usescreateGzipFetch()for register + finish callspublishDocsLedgerPreview.ts: usescreateGzipFetch()for preview register + finish callsHow it works
LinkFetchClientserializes the body into aRequestobject with aReadableStreambodynew CompressionStream("gzip")(Web Streams API)Content-Encoding: gzipheader, removesContent-Length(chunked transfer)@fastify/compresstransparently decompresses on the server sideTesting
feat/docs_ledger— the published@fern-api/fdr-sdkdoesn't include theorpc-clientmodule yet. Biome, depcheck, boundaries, lint-pr-title all pass.Link to Devin session: https://app.devin.ai/sessions/39280dca1e9e4499ab649331c7809231
Requested by: @broady