UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

84 lines 3.63 kB
import { APIError, APIResponse, XID } from '../types'; export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; export interface RequestConfig { method?: HttpMethod; headers?: Record<string, string>; body?: any; params?: Record<string, any>; timeout?: number; retries?: number; cache?: boolean; organizationId?: XID; } export interface APIClientConfig { baseUrl: string; apiKey?: string; publishableKey?: string; organizationId?: XID; timeout?: number; retries?: number; headers?: Record<string, string>; } export type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>; export type ResponseInterceptor = (response: Response) => Response | Promise<Response>; export type ErrorHandler = (error: APIError) => void; export declare class APIClient { private config; private requestInterceptors; private responseInterceptors; private errorHandlers; constructor(config: APIClientConfig); setConfig(config: Partial<APIClientConfig>): void; setOrganizationContext(organizationId: XID): void; clearOrganizationContext(): void; addRequestInterceptor(interceptor: RequestInterceptor): void; addResponseInterceptor(interceptor: ResponseInterceptor): void; addErrorHandler(handler: ErrorHandler): void; request<T = any>(endpoint: string, config?: RequestConfig): Promise<APIResponse<T>>; get<T = any>(endpoint: string, config?: RequestConfig): Promise<APIResponse<T>>; post<T = any>(endpoint: string, data?: any, config?: RequestConfig): Promise<APIResponse<T>>; put<T = any>(endpoint: string, data?: any, config?: RequestConfig): Promise<APIResponse<T>>; patch<T = any>(endpoint: string, data?: any, config?: RequestConfig): Promise<APIResponse<T>>; delete<T = any>(endpoint: string, config?: RequestConfig): Promise<APIResponse<T>>; private buildUrl; private buildRequestConfig; private executeRequest; private parseResponse; private createAPIError; } export declare const createAPIClient: (config: APIClientConfig) => APIClient; export declare const isAPIError: (error: any) => error is APIError; export declare const handleAPIError: (error: any) => APIError; export declare const retryRequest: <T>(requestFn: () => Promise<T>, maxRetries?: number, delay?: number) => Promise<T>; export declare const withCache: <T>(requestFn: () => Promise<T>, cacheKey: string, ttl?: number) => Promise<T>; export declare const batchRequests: <T>(requests: (() => Promise<T>)[], batchSize?: number, delay?: number) => Promise<T[]>; export declare const uploadFile: (client: APIClient, endpoint: string, file: File, options?: { onProgress?: (progress: number) => void; abortSignal?: AbortSignal; additionalData?: Record<string, any>; }) => Promise<APIResponse<any>>; export declare const downloadFile: (client: APIClient, endpoint: string, filename?: string, options?: { onProgress?: (progress: number) => void; abortSignal?: AbortSignal; }) => Promise<void>; export declare class APIWebSocket { private url; private config; private ws; private reconnectAttempts; private maxReconnectAttempts; private reconnectDelay; private messageQueue; private eventHandlers; constructor(url: string, config?: { token?: string; organizationId?: XID; autoReconnect?: boolean; }); connect(): Promise<void>; disconnect(): void; send(message: any): void; on(event: string, handler: (data: any) => void): () => void; private handleMessage; } //# sourceMappingURL=api.d.ts.map