/** * @file User-Agent header generation for socket-lib's outbound HTTP requests. * Three-token format aligned with socket-cli's `getCliUserAgent` and * coana-tech-cli's `configureAxiosUserAgent`: `/ * node/ /` e.g. `socketsecurity-lib/6.0.0 * node/v22.10.0 darwin/arm64` Downstream callers (sdxgen SEA binary, Socket * CLIs, etc.) can identify themselves via the `SOCKET_CALLER_USER_AGENT` env * var, which is appended to the lib's own UA so the server still sees the lib * identifier. @example import { getSocketCallerUserAgent } from * '@socketsecurity/lib/http-request/user-agent' * request.setHeader('User-Agent', getSocketCallerUserAgent()) */ /** * Compose a three-token User-Agent string from a `{ name, version }` pair, * optionally appending a caller-supplied identifier. * * Used directly by socket-lib's own outbound requests (via * `getSocketCallerUserAgent`) and exported for sibling packages (socket-cli, * socket-sdk-js) so Socket emits one canonical UA shape. * * @example * ;```typescript * buildUserAgent({ name: '@socketsecurity/lib', version: '6.0.0' }) * // 'socketsecurity-lib/6.0.0 node/v22.10.0 darwin/arm64' * * buildUserAgent({ name: 'sdxgen', version: '0.5.0' }, 'embedded-by-foo/1') * // 'sdxgen/0.5.0 node/v22.10.0 darwin/arm64 embedded-by-foo/1' * ``` */ export declare function buildUserAgent(pkg: { name: string; version: string; }, caller?: string | undefined): string; /** * Chain User-Agent fragments into a breadcrumb trail, ordered identity → hop: * the immediate agent first, each forwarded caller after, so it reads * left-to-right and a server's UA parser buckets by the immediate agent. Each * fragment is sanitized; empties are dropped; an immediately-repeated fragment * is collapsed so re-proxying doesn't stutter the same hop twice. * * @example * chainUserAgents(['socketsecurity-firewall-api-proxy/0.0.0', 'vlt/1.2.3']) * // 'socketsecurity-firewall-api-proxy/0.0.0 vlt/1.2.3' */ export declare function chainUserAgents(parts: ReadonlyArray): string; /** * User-Agent header for socket-lib's own outbound HTTP requests. * * Composes the lib's base UA (lazily cached — name, lib version, node version, * platform, and arch are stable for the process lifetime) with the * caller-supplied identifier from `SOCKET_CALLER_USER_AGENT` (re-read every * call so child-process / test-stub changes propagate). * * Empty or whitespace-only env values are treated as unset. * * @example * ;```typescript * // No env override: * getSocketCallerUserAgent() * // 'socketsecurity-lib/6.0.0 node/v22.10.0 darwin/arm64' * * // With SOCKET_CALLER_USER_AGENT='sdxgen/0.5.0': * getSocketCallerUserAgent() * // 'socketsecurity-lib/6.0.0 node/v22.10.0 darwin/arm64 sdxgen/0.5.0' * ``` */ export declare function getSocketCallerUserAgent(): string; /** * Sanitize a single User-Agent fragment for safe inclusion in an outgoing HTTP * header. A caller identifier (`SOCKET_CALLER_USER_AGENT`, or a UA a proxy * forwards on behalf of its client) is untrusted, so strip control chars (C0 * incl. CR/LF — the header- and log-injection vector — DEL, and C1), collapse * internal whitespace to one space, trim, and cap length. Returns '' for * nullish / blank / all-control input. */ export declare function sanitizeUserAgent(value: string | undefined): string;