import { LogLayerTransportParams, LoggerlessTransport, LoggerlessTransportConfig } from "@loglayer/transport"; //#region src/errors.d.ts /** * Error thrown when HTTP request fails */ declare class HttpTransportError extends Error { status?: number; response?: Response; constructor(message: string, status?: number, response?: Response); } /** * Error thrown when rate limit is exceeded */ declare class RateLimitError extends Error { retryAfter: number; constructor(message: string, retryAfter: number); } /** * Error thrown when log entry exceeds size limits */ declare class LogSizeError extends Error { logEntry: Record; size: number; limit: number; constructor(message: string, logEntry: Record, size: number, limit: number); } //#endregion //#region src/HttpTransport.d.ts /** * Parameters passed to the `payloadTemplate` function. * Extends `LogLayerTransportParams` with a convenience `message` field * (the `messages` array joined with a space). */ type HttpPayloadTemplateParams = LogLayerTransportParams & { /** Convenience: messages joined with a space */message: string; }; /** * Configuration options for the HTTP transport. */ interface HttpTransportConfig extends LoggerlessTransportConfig { /** * The URL to send logs to */ url: string; /** * HTTP method to use for requests * @default "POST" */ method?: string; /** * Headers to include in the request. Can be an object or a function that returns headers. */ headers?: Record | (() => Record); /** * Content type for single log requests. User-specified headers take precedence. * @default "application/json" */ contentType?: string; /** * Content type for batch log requests. User-specified headers take precedence. * @default "application/json" */ batchContentType?: string; /** * Optional callback for error handling */ onError?: (err: Error) => void; /** * Optional callback for debugging log entries before they are sent */ onDebug?: (entry: Record) => void; /** * Optional callback for debugging HTTP requests and responses */ onDebugReqRes?: (reqRes: { req: { url: string; method: string; headers: Record; body: string | Uint8Array; }; res: { status: number; statusText: string; headers: Record; body: string; }; }) => void; /** * Function to transform log data into the payload format. * Receives all `LogLayerTransportParams` fields plus a convenience `message` * string (the `messages` array joined with a space). */ payloadTemplate: (params: HttpPayloadTemplateParams) => string; /** * Whether to use gzip compression * @default false */ compression?: boolean; /** * Number of retry attempts before giving up * @default 3 */ maxRetries?: number; /** * Base delay between retries in milliseconds * @default 1000 */ retryDelay?: number; /** * Whether to respect rate limiting by waiting when a 429 response is received * @default true */ respectRateLimit?: boolean; /** * Whether to enable batch sending * @default true */ enableBatchSend?: boolean; /** * Number of log entries to batch before sending * @default 100 */ batchSize?: number; /** * Timeout in milliseconds for sending batches regardless of size * @default 5000 */ batchSendTimeout?: number; /** * Delimiter to use between log entries in batch mode * @default "\n" */ batchSendDelimiter?: string; /** * Batch mode for sending multiple log entries * - "delimiter": Join entries with a delimiter (default) * - "field": Wrap entries in an object with a field name * - "array": Send entries as a plain JSON array * @default "delimiter" */ batchMode?: "delimiter" | "field" | "array"; /** * Field name to wrap batch entries in when batchMode is "field" (e.g., "batch" for Logflare) * @default undefined */ batchFieldName?: string; /** * Maximum size of a single log entry in bytes * @default 1048576 (1MB) */ maxLogSize?: number; /** * Maximum size of the payload (uncompressed) in bytes * @default 5242880 (5MB) */ maxPayloadSize?: number; /** * Whether to enable Next.js Edge Runtime compatibility mode * When enabled, TextEncoder and compression are disabled * @default false */ enableNextJsEdgeCompat?: boolean; } /** * HttpTransport is responsible for sending logs to any HTTP endpoint. * It supports batching, compression, retries, and rate limiting. * * Features: * - Configurable HTTP method and headers * - Custom payload template function * - Gzip compression support * - Retry logic with exponential backoff * - Rate limiting support * - Batch sending with configurable size and timeout * - Error and debug callbacks * - Log size validation * - Payload size tracking for batching */ declare class HttpTransport extends LoggerlessTransport { private url; private method; private headers; private contentType; private batchContentType; private onError?; private onDebug?; private onDebugReqRes?; private payloadTemplate; private compression; private maxRetries; private retryDelay; private respectRateLimit; private enableBatchSend; private batchSize; private batchSendTimeout; private batchSendDelimiter; private batchMode; private batchFieldName?; private maxLogSize; private maxPayloadSize; private enableNextJsEdgeCompat; private batchQueue; private batchTimeout?; private isProcessingBatch; private currentBatchSize; /** * Creates a new instance of HttpTransport. * * @param config - Configuration options for the transport */ constructor(config: HttpTransportConfig); /** * Processes and ships log entries to the HTTP endpoint. * * @param params - Log parameters including level, messages, and metadata * @returns The original messages array */ shipToLogger(params: LogLayerTransportParams): any[]; /** * Adds a payload to the batch queue and triggers sending if conditions are met */ private addToBatch; /** * Processes the current batch and sends it to the HTTP endpoint */ private processBatch; /** * Sends a batch of payloads to the HTTP endpoint */ private sendBatch; /** * Sends a single payload to the HTTP endpoint */ private sendPayload; } //#endregion export { type HttpPayloadTemplateParams, HttpTransport, type HttpTransportConfig, HttpTransportError, LogSizeError, RateLimitError }; //# sourceMappingURL=index.d.ts.map