type AuthHeaders = { jwt?: string; apiKey?: string; }; export type HTTPMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'PUT'; /** * Options for configuring the `CorePikkuFetch` utility. * * @typedef {Object} CorePikkuFetchOptions * @property {boolean} [transformDate] - Whether to transform date-like strings in the response to `Date` objects. * @property {string} [serverUrl] - The base server URL for requests. * @property {AuthHeaders} [authHeaders] - Authorization headers, including JWT or API key. * @property {typeof globalThis.fetch} [fetch] - A fetch implementation to use instead of the global one. * @property {RequestInit['cache']} [cache] - The cache mode for the request. * @property {RequestInit['credentials']} [credentials] - The credentials mode for the request. * @property {RequestInit['mode']} [mode] - The mode for the request. */ export type CorePikkuFetchOptions = { transformDate?: boolean; serverUrl?: string; authHeaders?: AuthHeaders; fetch?: typeof globalThis.fetch; } & Pick; /** * The `CorePikkuFetch` class provides a utility for making HTTP requests, including handling authorization, * transforming dates in responses, and managing server URLs. This class is designed to simplify API wires * with configurable options and support for JWT and API key-based authentication. */ export declare class CorePikkuFetch { private options; private authHeaders; private extraHeaders; /** * Constructs a new instance of the `CorePikkuFetch` class. * * @param {CorePikkuFetchOptions} options - Optional configuration for the fetch utility. */ constructor(options?: CorePikkuFetchOptions); /** * Generates the headers for the request, including authorization headers if set. * * @returns {Record} - The headers for the request. */ private getHeaders; setHeader(name: string, value: string | null): void; /** * Sets the server URL for subsequent requests. * * @param {string} serverUrl - The server URL to be set. */ setServerUrl(serverUrl: string): void; /** * Returns the configured base server URL (without trailing slash), or * undefined if it hasn't been set yet. */ getServerUrl(): string | undefined; /** * Sets the JWT for authorization. * * @param {string} jwt - The JWT to be used for authorization. */ setAuthorizationJWT(jwt: string | null): void; /** * Sets the API key for authorization. * * @param {string} [apiKey] - The API key to be used for authorization. */ setAPIKey(apiKey: string | null): void; post(uri: string, data: any, options?: RequestInit): Promise; get(uri: string, data: any, options?: RequestInit): Promise; patch(uri: string, data: any, options?: RequestInit): Promise; head(uri: string, data: any, options?: RequestInit): Promise; /** * Uploads a file to a URL obtained from `getUploadURL`. * Handles both presigned URLs (e.g. S3) and header-based auth (e.g. B2). * * @param {Object} uploadInfo - The result from the backend's `getUploadURL` call. * @param {string} uploadInfo.uploadUrl - The URL to upload to. * @param {string} uploadInfo.assetKey - The finalized asset key. * @param {Record} [uploadInfo.uploadHeaders] - Optional headers required by the storage backend. * @param {Blob | File | Buffer | ReadableStream} body - The file content to upload. * @param {string} [contentType] - The MIME type (used as fallback if not in uploadHeaders). * @returns {Promise<{ assetKey: string; response: Response }>} - The asset key and raw response. */ uploadFile(uploadInfo: { uploadUrl: string; assetKey: string; uploadHeaders?: Record; uploadMethod?: 'PUT' | 'POST'; }, body: Blob | File | BufferSource | ReadableStream, contentType?: string): Promise<{ assetKey: string; response: Response; }>; /** * Makes an API request with the specified URI, method, and data, and optionally transforms dates in the response. * * @param {string} uri - The endpoint URI for the request. * @param {HTTPMethod} method - The HTTP method for the request. * @param {any} data - The data to be sent with the request. * @param {RequestInit} [options] - Additional options for the request. * @returns {Promise} - A promise that resolves to the response data. * @throws {PikkuFetchError} - Throws a decoded error if the status code is >= 400. */ api(uri: string, method: HTTPMethod, data: any, options?: RequestInit): Promise; /** * Opens an SSE stream to the given path and calls `handler` for each parsed * JSON event. Returns a handle with a `close()` method that aborts the stream. * * @param path - Server-relative path (e.g. `/workflow-run/:runId/stream`) * @param handler - Called with each decoded JSON event * @param onError - Called once if the stream errors (and is not already closed) */ subscribeToSSE(path: string, handler: (event: T) => void, onError?: (err: unknown) => void): { close: () => void; }; /** * Makes a raw fetch request with the specified URI, method, and data. * * @param {string} uri - The endpoint URI for the request. * @param {HTTPMethod} method - The HTTP method for the request. * @param {any} data - The data to be sent with the request. * @param {RequestInit} [options] - Additional options for the request. * @returns {Promise} - A promise that resolves to the fetch response. */ fetch(uri: string, method: any, // HTTPMethod, TODO: the generated file is a subset of HTTPMethod data: any, options?: RequestInit): Promise; /** * Verifies that the server URL is set before making a request. * * @throws {Error} - Throws an error if the server URL is not set. */ private verifyServerUrlSet; /** * Transforms date-like strings in the response data into `Date` objects if the `transformDate` option is set. * * @param {any} data - The data to transform. * @returns {any} - The transformed data. */ private transformDates; } export {};