feat: enrich default user agent with Node.js version and OS info#638
Open
Bret Comnes (bcomnes) wants to merge 1 commit into
Open
feat: enrich default user agent with Node.js version and OS info#638Bret Comnes (bcomnes) wants to merge 1 commit into
Bret Comnes (bcomnes) wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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 baseUser-Agenttoken including Node.js and OS info. - Update
SocketSdkOptions.userAgentdocumentation 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 on lines
+1018
to
+1020
| 'User-Agent': userAgent | ||
| ? `${DEFAULT_USER_AGENT} ${userAgent}` | ||
| : DEFAULT_USER_AGENT |
Comment on lines
+1018
to
+1020
| 'User-Agent': userAgent | ||
| ? `${DEFAULT_USER_AGENT} ${userAgent}` | ||
| : DEFAULT_USER_AGENT |
Comment on lines
+958
to
+963
| function buildSdkBaseUserAgent(pkgData: { | ||
| name: string | ||
| version: string | ||
| }): string { | ||
| const name = pkgData.name.replace('@', '').replace('/', '-') | ||
| return [ |
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.
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.