Skip to content

feat: enrich default user agent with Node.js version and OS info#638

Closed
Bret Comnes (bcomnes) wants to merge 1 commit into
v1.4.xfrom
feat/richer-user-agent
Closed

feat: enrich default user agent with Node.js version and OS info#638
Bret Comnes (bcomnes) wants to merge 1 commit into
v1.4.xfrom
feat/richer-user-agent

Conversation

@bcomnes

Copy link
Copy Markdown
Member

The SDK base UA now includes the Node.js version and OS platform/arch alongside the SDK name and version:

socketsecurity-sdk/1.4.96 node/v22.0.0 linux/arm64

When callers pass a userAgent option it is appended rather than replacing the base, so the full string becomes:

socketsecurity-sdk/1.4.96 node/v22.0.0 linux/arm64 socket/1.1.96 (https://github.com/SocketDev/socket-cli)

Add buildSdkBaseUserAgent() internal helper for the SDK's own base token. Update createUserAgentFromPkgJson() JSDoc to clarify it builds a caller token to be passed via SocketSdkOptions.userAgent.

The SDK base UA now includes the Node.js version and OS platform/arch
alongside the SDK name and version:

  socketsecurity-sdk/1.4.96 node/v22.0.0 linux/arm64

When callers pass a userAgent option it is appended rather than replacing
the base, so the full string becomes:

  socketsecurity-sdk/1.4.96 node/v22.0.0 linux/arm64 socket/1.1.96 (https://github.com/SocketDev/socket-cli)

Add buildSdkBaseUserAgent() internal helper for the SDK's own base token.
Update createUserAgentFromPkgJson() JSDoc to clarify it builds a caller
token to be passed via SocketSdkOptions.userAgent.

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.

Pull request overview

This PR enriches the SDK’s default User-Agent header by including runtime environment details (Node.js version and OS platform/arch) alongside the SDK name/version, and changes the userAgent option behavior to append an additional caller token rather than replace the base SDK user agent.

Changes:

  • Add an internal buildSdkBaseUserAgent() helper to construct the SDK’s base User-Agent token including Node.js and OS info.
  • Update SocketSdkOptions.userAgent documentation and adjust header construction to append the caller-provided token to the SDK base.
  • Clarify createUserAgentFromPkgJson() JSDoc to reflect that it builds a caller token appended to the SDK base header.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.ts
Comment on lines +1018 to +1020
'User-Agent': userAgent
? `${DEFAULT_USER_AGENT} ${userAgent}`
: DEFAULT_USER_AGENT
Comment thread src/index.ts
Comment on lines +1018 to +1020
'User-Agent': userAgent
? `${DEFAULT_USER_AGENT} ${userAgent}`
: DEFAULT_USER_AGENT
Comment thread src/index.ts
Comment on lines +958 to +963
function buildSdkBaseUserAgent(pkgData: {
name: string
version: string
}): string {
const name = pkgData.name.replace('@', '').replace('/', '-')
return [
John-David Dalton (jdalton) added a commit that referenced this pull request Jul 24, 2026
The default User-Agent now includes the running Node.js version and the OS
platform/arch alongside the SDK name/version, built by a new
buildSdkBaseUserAgent helper in user-agent.mts. A caller-supplied userAgent
is now appended to that base rather than replacing it, so requests always
carry the SDK's own identifying token.

Ports #638 (based on the v1.4.x line) to v4/main.

Example emitted header:
socketsecurity-sdk/4.0.4 node/v24.14.1 linux/arm64 socket/1.1.96 (https://github.com/SocketDev/socket-cli)
@jdalton

Copy link
Copy Markdown
Collaborator

Superseded. The default user-agent enrichment (Node.js version + OS platform/arch, with a caller-supplied userAgent appended rather than replacing the base) has been ported to v4/main in #665 (squashed as 6cee256).

This PR was based on the retired v1.4.x line, so the change belongs on main instead. Closing.

@jdalton
John-David Dalton (jdalton) deleted the feat/richer-user-agent branch July 24, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants