Skip to content

feat(fetch): identify CLI with a Clerk-CLI User-Agent header#301

Merged
rafa-thayto merged 1 commit into
mainfrom
wooded-timbale
May 21, 2026
Merged

feat(fetch): identify CLI with a Clerk-CLI User-Agent header#301
rafa-thayto merged 1 commit into
mainfrom
wooded-timbale

Conversation

@rafa-thayto
Copy link
Copy Markdown
Contributor

@rafa-thayto rafa-thayto commented May 21, 2026

Summary

  • Sets User-Agent: Clerk-CLI/<version> (Bun/<v>; <platform>-<arch>[; ci]) on every outbound request via the central loggedFetch helper, replacing Bun's default Bun/<v> so Clerk's edge can route or filter CLI traffic separately.
  • Routes the lone direct fetch() in api/catalog through loggedFetch, picking up both the UA and standard debug-logging behavior (also fixes a pre-existing violation of .claude/rules/debug-logging.md).
  • Callers can still override User-Agent via headers (verified in fetch.test.ts).

Test plan

  • bun run format — clean
  • bun run lint — 0 warnings, 0 errors
  • bun run typecheck — passes
  • bun run build — passes
  • New tests in user-agent.test.ts + fetch.test.ts cover UA shape, caller override, platform/arch, CI marker, printable-ASCII — all green
  • Updated token-exchange.test.ts to read headers via Headers.get() (the helper now passes a Headers instance through)
  • Reviewer: confirm UA shows up in Cloud Run logs as Clerk-CLI/... instead of Bun/...

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: f71b7dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
clerk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request implements a Clerk-CLI-specific User-Agent header for outbound HTTP requests. A new buildUserAgent() helper constructs the string Clerk-CLI/<version> (Bun/<bun-version>; <platform>-<arch>) with optional CI environment detection. The loggedFetch function is updated to apply this User-Agent when the caller hasn't provided one. The catalog loader switches from withNetworkAccess(fetch(...)) to loggedFetch(...). Existing test assertions in token-exchange.test.ts are updated to use the Headers .get() API for consistency. A changeset documents the feature.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a Clerk-CLI User-Agent header to identify the CLI in outbound requests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the feature: setting a custom Clerk-CLI User-Agent on all outbound requests, routing catalog.ts through loggedFetch, and allowing caller overrides.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rafa-thayto rafa-thayto enabled auto-merge (squash) May 21, 2026 00:57
Sets `Clerk-CLI/<version> (Bun/<v>; <platform>-<arch>[; ci])` on every
outbound request via the central loggedFetch helper, replacing Bun's
default `Bun/<v>` UA so Clerk's edge can route or filter CLI traffic
separately (e.g. to dedicated PLAPI Cloud Run services). Also routes
the lone direct fetch() in api/catalog through loggedFetch so it picks
up the UA and gets the standard debug logging.
@rafa-thayto rafa-thayto merged commit da2e3cf into main May 21, 2026
9 of 10 checks passed
@rafa-thayto rafa-thayto deleted the wooded-timbale branch May 21, 2026 01:35
import { DEV_CLI_VERSION, resolveCliVersion } from "./version.ts";

export function buildUserAgent(): string {
const version = resolveCliVersion() ?? DEV_CLI_VERSION;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the future it would be nice to encapsulate this as like getCliVersion() so callers don't need to worry about the fallback.

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.

3 participants