import type { SupabaseClient } from "@supabase/supabase-js";
import type { AuthHeaders } from "./token";
import type * as ApiTypes from "./types";
import type { ApiErrorCode, ApiResult } from "./common/envelope";
export type { APICallParams, APICallParamsStrict, APIEndpoints, GetEndpoint, ApiAuthRequirement, ApiResponseKind, HTTPMethod, } from "./types";
/**
 * Set the SDK version to be included in API request headers
 * Called by the SDK during initialization
 */
export declare function setSdkVersion(version: string): void;
/**
 * Get the currently set SDK version
 */
export declare function getSdkVersion(): string | undefined;
type AnyApiCallParams<E extends keyof ApiTypes.APIEndpoints> = ApiTypes.APICallParams<E> | ApiTypes.APICallParamsStrict<E>;
type EndpointResponse<E extends keyof ApiTypes.APIEndpoints> = ApiTypes.APIEndpoints[E]['response'];
type ApiResponseFor<E extends keyof ApiTypes.APIEndpoints> = EndpointResponse<E> extends undefined ? void : NonNullable<EndpointResponse<E>>;
/**
 * API client that returns typed envelope responses.
 * Consumers must use isApiSuccess/isApiError type guards or unwrapResponse helper.
 */
export type ApiClient = <E extends keyof ApiTypes.APIEndpoints>(params: AnyApiCallParams<E>) => Promise<ApiResult<ApiResponseFor<E>>>;
/**
 * Opt-in strict client type for new code.
 *
 * Use this when you want the compiler to force `APICallParamsStrict` at call sites.
 * Existing clients (createInternalAPIClient, createBearerAPIClient, etc.) are still
 * runtime-compatible and can be annotated as ApiClientStrict.
 */
export type ApiClientStrict = <E extends keyof ApiTypes.APIEndpoints>(params: ApiTypes.APICallParamsStrict<E>) => Promise<ApiResult<ApiResponseFor<E>>>;
export interface ApiRequestErrorOptions {
    endpoint: keyof ApiTypes.APIEndpoints;
    status: number;
    method: ApiTypes.HTTPMethod;
    auth?: ApiTypes.ApiAuthRequirement;
    requestId?: string;
    body?: unknown;
    cause?: unknown;
    /** Typed error code from envelope error responses */
    errorCode?: ApiErrorCode;
    /** Retry delay from Retry-After header, in milliseconds */
    retryAfterMs?: number;
}
export declare class ApiRequestError extends Error {
    readonly endpoint: keyof ApiTypes.APIEndpoints;
    readonly status: number;
    readonly method: ApiTypes.HTTPMethod;
    readonly auth?: ApiTypes.ApiAuthRequirement;
    readonly requestId?: string;
    readonly body?: unknown;
    readonly cause?: unknown;
    /** Typed error code from envelope error responses (e.g., 'auth:forbidden', 'validation:invalid_input') */
    readonly errorCode?: ApiErrorCode;
    /** Retry delay from Retry-After header, in milliseconds */
    readonly retryAfterMs?: number;
    constructor(message: string, options: ApiRequestErrorOptions);
}
/**
 * Parse the Retry-After header value to milliseconds.
 * The header can be either:
 * - A number of seconds (e.g., "120")
 * - An HTTP-date (e.g., "Wed, 21 Oct 2025 07:28:00 GMT")
 *
 * @returns milliseconds to wait, or undefined if header is missing/invalid.
 *   Returns 0 for "Retry-After: 0" (meaning retry immediately).
 */
export declare function parseRetryAfterHeader(headerValue: string | null): number | undefined;
export declare const getApiUrl: (endpoint: keyof ApiTypes.APIEndpoints) => string;
export declare function parseErrorBody(response: Response): Promise<unknown>;
/**
 * Parse a successful HTTP response and return an ApiResult envelope.
 *
 * This function ALWAYS returns an ApiResult - it never throws for API-level errors.
 * HTTP-level errors (network failures, JSON parse errors) still throw ApiRequestError.
 */
export declare function parseSuccessResponse<E extends keyof ApiTypes.APIEndpoints>(endpoint: E, response: Response, config: ApiTypes.APIEndpoints[E]): Promise<ApiResult<ApiResponseFor<E>>>;
export declare function createAuthenticatedApiClient(supabase: SupabaseClient): Promise<ApiClient>;
export declare function createCMSClient(headers?: AuthHeaders | {}, baseUrl?: string): ApiClient;
export declare const createServerAPIClient: (apiKey: string, baseUrl?: string) => ApiClient;
export declare function createInternalAPIClient(baseUrl?: string): ApiClient;
export declare function createBearerAPIClient(token: string, baseUrl?: string): ApiClient;
