import { InternalServiceId } from "../utils/internal-service-auth.js"; //#region src/api-client/base-client.d.ts /** * Makes an HTTP request with consistent header defaults * * @param url - The URL to fetch * @param options - Standard fetch options (headers will be merged with defaults) * @returns Promise * * @example * ```typescript * // With Authorization header * const response = await apiFetch('https://api.example.com/data', { * method: 'POST', * headers: { * Authorization: 'Bearer your-api-key' * }, * body: JSON.stringify({ data: 'value' }) * }); * * // Without Authorization * const response = await apiFetch('https://api.example.com/public', { * method: 'GET' * }); * ``` */ declare function apiFetch(url: string, options?: RequestInit): Promise; declare class BaseApiError extends Error { readonly statusCode: number; readonly responseBody: string; constructor(message: string, statusCode: number, responseBody: string); get isNotFound(): boolean; get isUnauthorized(): boolean; get isForbidden(): boolean; } type BaseApiClientAuth = { mode: 'internalService'; internalServiceName: InternalServiceId; } | { mode: 'apiKey'; apiKey: string; isCI?: boolean; }; interface BaseApiClientConfig { apiUrl: string; tenantId: string; projectId: string; auth: BaseApiClientAuth; ref?: string; userId?: string; userEmail?: string; } declare abstract class BaseApiClient { protected apiUrl: string; protected tenantId: string | undefined; protected projectId: string; protected apiKey: string | undefined; protected isCI: boolean; protected internalServiceName?: InternalServiceId; protected ref?: string; protected userId?: string; protected userEmail?: string; protected constructor(config: BaseApiClientConfig); protected checkTenantId(): string; /** * Builds a URL from the base API URL and a path * Supports optional ref and pagination query parameters */ protected buildUrl(path: string, params?: { page?: number; limit?: number; }): string; /** * Gets auth headers for requests * Handles both internal service JWT tokens and API key authentication */ protected getAuthHeaders(): Promise>; /** * Wrapper around fetch that automatically includes auth header * Uses X-API-Key for CI mode, Authorization Bearer for interactive mode * @deprecated Use getAuthHeaders() with apiFetch() instead for more flexibility */ protected authenticatedFetch(url: string, options?: RequestInit): Promise; /** * Creates an error instance for failed requests * Override in subclasses to return specific error types */ protected createError(message: string, statusCode: number, responseBody: string): BaseApiError; /** * Extracts data from a successful response * Override in subclasses if the API wraps responses (e.g., { data: ... }) */ protected extractResponseData(response: Response): Promise; /** * Makes a GET request with authentication */ protected makeGetRequest(path: string, errorContext: string): Promise; /** * Makes a POST request with authentication */ protected makePostRequest(path: string, body: unknown, errorContext: string): Promise; /** * Makes paginated GET requests and collects all results */ protected makePaginatedGetRequest(path: string, errorContext: string, pageSize?: number): Promise; getTenantId(): string | undefined; getProjectId(): string; getApiUrl(): string; getIsCI(): boolean; } //#endregion export { BaseApiClient, BaseApiClientAuth, BaseApiClientConfig, BaseApiError, apiFetch };