feat: enrich default user agent with Node.js version and OS info#665
Merged
Conversation
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)
This was referenced Jul 24, 2026
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.
Ports #638 (based on the retired v1.4.x line) to v4/main. Same behavior, adapted to v4's file layout.
What changed
buildSdkBaseUserAgent(pkgData)insrc/user-agent.mtsbuilds the SDK's base UA as<name>/<version> node/<process.version> <os.platform()>/<os.arch()>.DEFAULT_USER_AGENT(src/constants.mts) now usesbuildSdkBaseUserAgentinstead ofcreateUserAgentFromPkgJson.SocketSdknow appends a caller-supplieduserAgentto the base rather than replacing it:`${DEFAULT_USER_AGENT} ${userAgent}`. So every request carries the SDK's own identifying token.createUserAgentFromPkgJsonis unchanged (still builds a caller token with optional homepage) — it's the intended way to construct the token you pass asuserAgent.Example emitted header with a caller UA:
Tests
test/repo/unit/user-agent.test.mts: newbuildSdkBaseUserAgentsuite asserts the default UA includesnode/<version>and<platform>/<arch>, plus scoped-name normalization.test/repo/unit/getapi-sendapi-methods.test.mts: the existing custom-UA test now asserts the caller token is appended to the enriched base (was: replaced).tsgo + lint green. Full unit suite green except the pre-existing
resolveBasePathtests that assert the cwd path containssocket-sdk-js(they fail only in a/tmpworktree, unrelated to this change).