Skip to content

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

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

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.
Copy link
Copy Markdown

Copilot AI left a comment

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 [
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.

2 participants