UNPKG

parea-ai

Version:

Client SDK library to connect to Parea AI.

81 lines (80 loc) 2.66 kB
import { AxiosResponse } from 'axios'; /** * Interface representing the configuration for an HTTP request. */ interface RequestConfig { /** The HTTP method to be used for the request. */ method: 'GET' | 'POST' | 'PUT' | 'DELETE'; /** The endpoint URL for the request. */ endpoint: string; /** Optional data to be sent with the request. */ data?: any; /** Optional query parameters for the request. */ params?: any; /** Optional API key for authentication. */ apiKey?: string; } /** * A singleton class for making HTTP requests with configurable options and mock mode. */ export declare class HTTPClient { private static instance; private baseURL; private apiKey; private client; private mockMode; private defaultMockResponse; private constructor(); /** * Gets the singleton instance of the HTTPClient. * @returns The HTTPClient instance. */ static getInstance(): HTTPClient; /** * Sets a custom mock response message. * @param mockMessage - The message to be used in the mock response. */ setMockHandler(mockMessage: string): void; /** * Enables or disables mock mode. * @param enable - Boolean flag to enable or disable mock mode. */ enableMockMode(enable: boolean): void; /** * Sets the API key for authentication. * @param apiKey - The API key to be used for requests. */ setApiKey(apiKey: string): void; /** * Sets the base URL for all requests. * @param baseURL - The base URL to be used. */ setBaseURL(baseURL: string): void; /** * Sends an HTTP request based on the provided configuration. * @param config - The request configuration. * @returns A promise that resolves to the axios response. * @throws Will throw an error if the request fails. */ request(config: RequestConfig): Promise<AxiosResponse<any>>; /** * Intercepts and processes the request before it is sent. * @param config - The request configuration. * @returns The processed request configuration. */ private requestInterceptor; /** * Intercepts and processes the response before it is handled. * @param response - The axios response object. * @returns The processed response. */ private responseInterceptor; /** * Intercepts and processes errors that occur during the request. * @param error - The axios error object. * @returns A rejected promise with the error. * @throws Will throw a custom error if the server is down or unavailable. */ private errorInterceptor; } export {};