/** * @file Header utilities for HTTP/HTTPS requests. Two pure-data helpers: * * - `parseRetryAfterHeader` turns a `Retry-After` header value (delay-seconds * OR HTTP-date per RFC 7231 §7.1.3) into a millisecond delay for `onRetry` * callbacks. * - `sanitizeHeaders` redacts `Authorization`, `Cookie`, and the other * credential-bearing headers before they reach a logger or telemetry * payload. No I/O — these can be imported anywhere without dragging the * Node.js `http`/`https` modules into the bundle. */ /** * Build an HTTP Basic `Authorization` header value from a Socket API token. * * The Socket API uses the token as the username with an empty password, so the * credential pair is `:`. Centralized here so every Socket caller emits * the identical shape instead of hand-rolling `btoa(\`${token}:`)`. * * @example * ;```ts * const headers = { Authorization: basicAuthHeader(apiToken) } * // { Authorization: 'Basic c2t0X3h4eHg6' } * ``` * * @param token - The Socket API token, used as the Basic-auth username. * * @returns The `Authorization` header value, e.g. `Basic `. */ export declare function basicAuthHeader(token: string): string; /** * Whether a header name looks credential-bearing and should be redacted from * logs and telemetry. Case-insensitive substring match on the name only — the * value is never inspected. * * @param name - The header name (e.g. `Authorization`, `x-api-key`). * * @returns `true` when the value should be replaced with `[REDACTED]`. */ export declare function isSensitiveHeaderName(name: string): boolean; /** * Parse a `Retry-After` HTTP header value into milliseconds. * * Supports both formats defined in RFC 7231 §7.1.3: * * - **delay-seconds**: integer number of seconds (e.g., `"120"`) * - **HTTP-date**: an absolute date/time (e.g., `"Fri, 31 Dec 2027 23:59:59 * GMT"`) * * When the header is an array of multiple values, the first element is used. * * @example * ;```ts * import { setTimeout as delay } from 'node:timers/promises' * const ms = parseRetryAfterHeader(response.headers['retry-after']) * if (ms !== undefined) { * await delay(ms) * } * ``` * * @param value - The raw Retry-After header value(s) * * @returns Delay in milliseconds, or `undefined` if the value cannot be parsed */ export declare function parseRetryAfterHeader(value: string | string[] | undefined): number | undefined; /** * Redact sensitive HTTP headers for safe logging and telemetry. * * Replaces values of credential-bearing headers with `[REDACTED]`, matching the * header name by shape (see `isSensitiveHeaderName`) so custom token headers * are covered without an enumerated list. Non-sensitive headers pass through * unchanged. Array values are joined with `', '`. * * @example * ;```ts * const safe = sanitizeHeaders({ * authorization: 'Bearer secret', * 'content-type': 'application/json', * }) * // { authorization: '[REDACTED]', 'content-type': 'application/json' } * ``` * * @param headers - HTTP headers to sanitize. * * @returns A new object with sensitive values redacted * * @unused No internal or Socket consumers; exercised only by its unit tests. */ export declare function sanitizeHeaders(headers: Record | undefined): Record;