Repository navigation
feat: allow custom default headers on CommsApi - #104
Merged
Merged
Conversation
Adds a `headers` option to `CommsApiOptions`, threaded through every client and the multipart upload helper, so SDK consumers can attribute their traffic (e.g. `Doist-Platform: cli` for the Comms CLI). Custom headers can never override Authorization, X-Request-Id or the multipart Content-Type. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Merged
4 tasks done
doistbot
reviewed
Oct 20, 2026
doistbot
left a comment
Member
There was a problem hiding this comment.
This PR adds an optional headers option to CommsApi so apps can identify themselves (e.g. via Doist-Platform) on every request, including multipart uploads, with the SDK-managed Authorization, X-Request-Id, and multipart Content-Type headers always merging on top. The plumbing threads through the clients the same way customFetch already does, keeping the diff mechanical and non-breaking for existing consumers. No inline issues were flagged.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (2)
src/transport/http-client.ts:39: Reserved headers are only protected case-sensitively. A caller passing
authorizationorx-request-id(lowercase) leaves both keys on the plain object, andfetchtreats header names case-insensitively, so the request ends up with combined values such asAuthorization: Bearer token, Bearer forged. Strip reserved names fromcustomHeaderscase-insensitively (or build headers withHeaders.set). The same case-collision applies to the{ ...customHeaders, Authorization, 'Content-Type' }merge inmultipart-upload.ts.src/utils/multipart-upload.ts:270: The new
headersargument inuploadMultipartFilehas no test coverage: no test passes custom headers or asserts thatAuthorization/Content-Typestill win. The PR description says a test proves the multipartContent-Typeguarantee, but the only new test exerciseshttpClient.request. Add a real-server test inmultipart-upload.test.tsthat sends a custom header plus conflictingauthorization/content-typevalues and asserts the SDK values are used.
6 tasks done
scottlovegrove
added this pull request to stack #106
October 20, 2026 16:14
roryist
marked this pull request as ready for review
October 21, 2026 09:09
doist-release-bot Bot
added a commit
that referenced
this pull request
Oct 21, 2026
## [3.6.0](v3.5.0...v3.6.0) (2026-10-21) ### Features * allow custom default headers on CommsApi ([#104](#104)) ([cdf1a5c](cdf1a5c))
Contributor
|
🎉 This PR is included in version 3.6.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Apps built on this SDK can now say who they are: a
headersoption onCommsApisends extra headers (likeDoist-Platform: cli) on every request. Nothing changes for existing consumers.Why
The Comms backend tells its clients apart by the
Doist-Platformheader. When a request arrives without it, dashboards and logs file it under "unknown". The Comms CLI is one of those unknowns today: it sends every request through this SDK, and the SDK had no way to attach a header. The accepted platform values are growing aclientry on the backend side, so the SDK needs a door to send it through.What changes
new CommsApi(token, { ... })baseUrl,version,customFetchheaders(new)headerssetContent-Type,Authorization,X-Request-IdheaderssetThe only change is the new option; every request a client makes, including the multipart attachment upload, carries the configured headers. Everything else is how it already worked.
A configured header can never replace
Authorization,X-Request-Id, or the multipartContent-Type— those merge on top, and a test proves it.3 things to look at
customFetchalready does, so the diff is one mechanical line per call site plus the plumbing inhttp-client.tsandbase-client.ts.migration.tsand the OAuth helpers inauthentication.tsdeliberately don't take the option — they aren't constructed fromCommsApiOptions. They can follow if ever needed.How it relates to other PRs
Doist/comms-cli#88 covers the CLI's one direct fetch today; once this ships in a release, the CLI passes
headers: { 'Doist-Platform': 'cli' }toCommsApiand all its traffic is attributed.References
Doist-Platformare logged as "unknown" (seeget_current_appin Doist/comms-backend).(Written by Rory's agent)
🤖 Generated with Claude Code