netstorage
Version:
A TypeScript API and CLI for the Akamai NetStorage REST interface
45 lines (44 loc) • 2.24 kB
TypeScript
import { type Readable, type Writable } from 'node:stream';
import { type NetStorageClientConfig } from '../index';
/**
* Configuration options for the makeStreamRequest function.
*
* @property {string} [url] Full URL to use instead of protocol + host + path.
* @property {'http' | 'https'} [protocol] Protocol for the request.
* @property {string} [host] Hostname of the server.
* @property {string} [path] Path to append to the host.
* @property {'PUT' | 'POST' | 'PATCH' | 'GET'} [method] HTTP method to use.
* @property {Record<string, string>} [headers] Headers to include with the request.
* @property {Readable} [inputStream] Optional readable stream for request body.
* @property {Writable} [outputStream] Optional writable stream for response body.
* @property {AbortSignal} [signal] AbortSignal to cancel the request.
* @property {number} [timeout] Timeout in milliseconds.
* @property {(bytes: number) => void} [onProgress] Callback to track transferred bytes.
* @property {Record<string, string | number>} [query] Query parameters to append to the URL.
*/
export interface StreamRequestOptions {
url?: string;
protocol?: 'http' | 'https';
host?: string;
path?: string;
method?: 'PUT' | 'POST' | 'PATCH' | 'GET';
headers?: Record<string, string>;
inputStream?: Readable;
outputStream?: Writable;
signal?: AbortSignal;
timeout?: number;
onProgress?: (bytes: number) => void;
query?: Record<string, string | number>;
}
/**
* Makes an HTTP or HTTPS request with streaming support for request and response bodies.
* Supports timeouts, abort signals, query parameters, progress tracking, and optional logging.
* @param config - The NetStorageconfig containing logger and other config info.
* @param options - Configuration options for the request.
* @param options.url - Optional full URL to override protocol/host/path/query resolution.
* @returns Promise resolving to an object with statusCode and optional body.
*/
export declare function makeStreamRequest(config: NetStorageClientConfig, { method, headers, inputStream, outputStream, signal, timeout, onProgress, ...options }: StreamRequestOptions): Promise<{
statusCode: number;
body?: string;
}>;