/** * curl transport: config construction, progress parsing, exit classification. * * Why curl rather than Node's own `fetch`: the transfer has to outlive the * Raycast command that started it. A detached Node process could do it, but * curl already handles Range resume, redirects, retries and connection timeouts, * and it is present on every macOS install. * * Two decisions here are load-bearing, both verified empirically: * * 1. The URL is passed as CONFIG on curl's stdin (`curl -K -`), never on the * command line and never in a file. Signed URLs are bearer credentials; * argv is world-readable via `ps`, and a file outlives a process killed * before it can delete it. * 2. Timeouts are THROUGHPUT-based (`--speed-limit`/`--speed-time`), not * wall-clock (`--max-time`). `--max-time` counts machine sleep against the * budget, so a laptop closed for ten minutes guarantees a spurious failure * on an otherwise healthy transfer. */ import { DownloadError, type SignalName } from "./errors"; export declare function hasCurl(): boolean; /** Bytes/sec below which a transfer is considered dead, sustained for `stallSeconds`. */ export declare const DEFAULT_SPEED_LIMIT_BYTES = 1024; export declare const DEFAULT_STALL_SECONDS = 120; export interface CurlConfigOptions { url: string; /** Destination. Callers should pass the `.part` path, not the final one. */ outputPath: string; headers?: Record; followRedirects?: boolean; /** Continue a partial transfer via HTTP Range. */ resume?: boolean; /** * Stall THRESHOLD, not a rate limit: if throughput stays below this for * `stallSeconds`, curl aborts. Lowering it makes stall detection more * forgiving; it does not slow the transfer down. */ speedLimitBytes?: number; stallSeconds?: number; connectTimeoutSeconds?: number; /** * Cap the transfer rate in bytes/sec (curl `--limit-rate`). Genuinely slows * the download — useful for tests and for not saturating a connection. */ limitRateBytes?: number; /** * Absolute wall-clock cap. Deliberately optional and unset by default — * see the note above about sleep. */ maxTimeSeconds?: number; /** * Write the response headers to this path (`--dump-header`). * * The point is the NEXT attempt, not this one: a resumed transfer has to * prove the bytes on disk still belong to the resource it is about to append * to, and `ETag`/`Last-Modified` are the only proof a server offers. They are * dumped even for an interrupted transfer, because that is precisely the * transfer whose partial gets resumed. */ dumpHeaderPath?: string; /** * `If-Range` validator for a resumed transfer. * * Turns a silent splice into a clean refusal. Measured against a * Range-capable local server: with a stale validator the server answers 200 * with the whole body, and curl exits 33 leaving the partial untouched — * where the same request WITHOUT `If-Range` gets a 206 and appends the new * resource's bytes to the old resource's prefix, exit 0, published. */ ifRange?: string; } /** * Build curl's config, which the runner writes to curl's stdin (`curl -K -`). * * Everything sensitive lives in this text, so it must never reach argv or disk. */ export declare function buildCurlConfig(options: CurlConfigOptions): string; /** * Refuse caller headers that would fight the resume machinery. * * `Range` and `If-Range` belong to the transport. Caller headers are appended * AFTER the generated ones, so a second `If-Range` — or a hand-written `Range` * — is what a server or proxy may act on, and the resume guard silently stops * guarding: a 206 comes back for bytes that do not continue the partial, curl * exits 0, and the spliced file is published. * * Refused rather than dropped, because a caller who passed one meant something * by it and deserves to be told it cannot work. Exported so `startDownload` can * fail before it claims a path or spawns anything, rather than minutes later * inside a detached process. */ export declare function assertCallerHeaders(headers?: Record): void; export interface CurlProgress { bytesDownloaded: number; totalBytes?: number; speedBytesPerSec?: number; etaSeconds?: number; } /** * Parse curl's default progress meter. * * Deliberately NOT `--progress-bar`: that mode emits only a percentage, which is * why the existing Fetch extension's speed and ETA fields are hardcoded to zero * and its speed UI has never rendered. The default meter carries real numbers: * * % Total % Received % Xferd Average Speed Time Time Time Current * Dload Upload Total Spent Left Speed * 13 365M 13 48.7M 0 0 8058k 0 0:00:46 0:00:06 0:00:40 8501k * * Returns the most recent complete sample, or null if none is present yet. */ export declare function parseCurlMeter(buffer: string): CurlProgress | null; /** Parse curl's abbreviated sizes: `1234`, `48.7M`, `365M`, `8058k`. */ export declare function parseCurlSize(field: string | undefined): number | undefined; /** Parse `H:MM:SS`. curl prints `--:--:--` when it has no estimate. */ export declare function parseCurlDuration(field: string | undefined): number | undefined; export interface CurlWriteOut { sizeDownload?: number; speedDownload?: number; httpCode?: number; } /** Parse the trailing `write-out` block (size, speed, http_code — one per line). */ export declare function parseWriteOut(stdout: string): CurlWriteOut; export interface ClassifyCurlInput { exitCode: number | null; signal?: SignalName | null; httpCode?: number; stderrTail?: string; /** True when the local process deliberately terminated curl. */ cancelled?: boolean; /** Whether the request was made with redirects enabled. Default true. */ followRedirects?: boolean; /** Whether the request resumed an existing partial (sent a Range). Default false. */ resumed?: boolean; } /** * Turn a finished curl invocation into a typed error. * * HTTP status is consulted before the exit code: curl exits 22 for every 4xx/5xx * under `fail-with-body`, and "403 Forbidden" is far more actionable than * "curl exited 22". */ export declare function classifyCurlFailure(input: ClassifyCurlInput): DownloadError; //# sourceMappingURL=curl.d.ts.map