/** * @fileoverview API Context and utilities for managing a shared API client instance * Provides context, provider component, and hooks for consistent API access across the application */ import { type ReactNode } from 'react'; import type { CustomAuthConfig, TokenManager } from '../auth'; import { ApiClient } from './client'; import type { MockConfigArray } from './types'; /** * Props for the ApiProvider component * * @template T - Type extending CustomAuthConfig that defines the shape of authentication data * * @example * ```tsx * const apiClient = createApiClient({...}); * * return ( * * * * ); * ``` */ interface ApiProviderProps { /** React children nodes */ children: ReactNode; /** Configured API client instance */ apiClient: ApiClient; /** Whether to use mock API */ mocked?: boolean; /** Mock configurations for API requests */ mockConfig?: MockConfigArray; } /** * Provider component for the API context * Makes the API client instance available to all child components * * @template T - Type extending CustomAuthConfig * * @example * ```tsx * function App() { * return ( * * * * ); * } * ``` */ export declare function ApiProvider({ children, apiClient, mocked, mockConfig, }: Readonly>): import("react/jsx-runtime").JSX.Element; /** * Hook for accessing the API client instance * Must be used within an ApiProvider component * * @template T - Type extending CustomAuthConfig for type-safe API operations * @returns The shared API client instance * @throws Error if used outside of ApiProvider * * @example * ```tsx * function MyComponent() { * const api = useApi(); * * const fetchData = async () => { * try { * const data = await api.get('/endpoint'); * // Handle response * } catch (error) { * // Handle error * } * }; * * return
...
; * } * ``` */ export declare function useApi(): ApiClient; /** * Factory function to create a configured ApiClient instance * * @template T - Type extending CustomAuthConfig that defines the shape of authentication data * @param config - Configuration options for the API client * @param config.baseURL - Base URL for all API requests * @param config.tokenManager - Token manager instance for handling authentication * @param config.defaultHeaders - Default headers to include in all requests * @param config.timeout - Request timeout in milliseconds (default: 30000) * @param config.retries - Number of retry attempts for failed requests (default: 1) * @returns Configured ApiClient instance * * @example * ```typescript * const apiClient = createApiClient({ * baseURL: 'https://api.example.com', * tokenManager: tokenManager, * defaultHeaders: { * 'Content-Type': 'application/json', * }, * timeout: 5000, * retries: 2, * }); * ``` */ export declare function createApiClient({ baseURL, tokenManager, defaultHeaders, timeout, retries, }: { baseURL: string; tokenManager: TokenManager; defaultHeaders?: HeadersInit; timeout?: number; retries?: number; }): ApiClient; export {};