export type ContentType = "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain" | "text/html" | "text/css" | "text/javascript" | "application/javascript" | "application/octet-stream" | "image/png" | "image/jpeg" | "image/gif" | "image/svg+xml" | "audio/mpeg" | "video/mp4" | "application/pdf" | "application/zip" | (string & {}); export type Authorization = "Bearer" | "Basic" | "Digest" | "HOBA" | "Mutual" | "AWS4-HMAC-SHA256" | (string & {}); export type Accept = "application/json" | "application/xml" | "text/plain" | "text/html" | "text/css" | "text/javascript" | "application/javascript" | "image/png" | "image/jpeg" | "audio/mpeg" | "video/mp4" | "*/*" | (string & {}); export type CacheControl = "no-cache" | "no-store" | "max-age=0" | "must-revalidate" | "public" | "private" | "no-transform" | "only-if-cached" | "max-age=3600" | "max-age=86400" | "s-maxage=3600" | "stale-while-revalidate=300" | (string & {}); export type ContentEncoding = "gzip" | "deflate" | "br" | "identity" | "compress" | (string & {}); export type Connection = "keep-alive" | "close" | "upgrade" | (string & {}); export type XRequestedWith = "XMLHttpRequest" | (string & {}); export type XFrameOptions = "DENY" | "SAMEORIGIN" | "ALLOW-FROM https://example.com" | (string & {}); export type XContentTypeOptions = "nosniff" | (string & {}); export interface AcchioHeaders { "A-IM"?: string; Accept?: Accept; "Accept-Charset"?: string; "Accept-Encoding"?: ContentEncoding; "Accept-Language"?: string; "Accept-Datetime"?: string; "Access-Control-Request-Method"?: string; "Access-Control-Request-Headers"?: string; Authorization?: Authorization; "Cache-Control"?: CacheControl; Connection?: Connection; "Content-Length"?: string; "Content-Type"?: ContentType; Cookie?: string; Date?: string; Expect?: string; Forwarded?: string; From?: string; Host?: string; "If-Match"?: string; "If-Modified-Since"?: string; "If-None-Match"?: string; "If-Range"?: string; "If-Unmodified-Since"?: string; "Max-Forwards"?: string; Origin?: string; Pragma?: string; "Proxy-Authorization"?: string; Range?: string; Referer?: string; TE?: string; "User-Agent"?: string; Upgrade?: string; Via?: string; Warning?: string; "WWW-Authenticate"?: string; "Proxy-Authenticate"?: string; "Access-Control-Allow-Origin"?: string; "Access-Control-Allow-Credentials"?: string; "Access-Control-Expose-Headers"?: string; "Access-Control-Max-Age"?: string; "Access-Control-Allow-Methods"?: string; "Access-Control-Allow-Headers"?: string; "Strict-Transport-Security"?: string; "X-Content-Type-Options"?: XContentTypeOptions; "X-Frame-Options"?: XFrameOptions; "X-XSS-Protection"?: string; "Content-Security-Policy"?: string; "X-CSRF-Token"?: string; "X-Requested-With"?: XRequestedWith; [key: `X-${string}`]: string | undefined; [key: string]: string | undefined; } export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS"; export type ResponseType = "json" | "text" | "blob" | "arraybuffer" | "xml"; export interface AcchioRequestConfig { url?: string; method?: HttpMethod; baseURL?: string; headers?: AcchioHeaders; params?: Record; data?: any; timeout?: number; withCredentials?: boolean; responseType?: ResponseType; validateStatus?: (status: number) => boolean; transformRequest?: Array<(data: any, headers?: AcchioHeaders) => any>; transformResponse?: Array<(data: any) => any>; adapter?: "node" | "browser" | "auto"; maxRedirects?: number; decompress?: boolean; cancelToken?: AcchioCancelToken; onUploadProgress?: (progressEvent: ProgressEvent) => void; onDownloadProgress?: (progressEvent: ProgressEvent) => void; xsrfCookieName?: string; xsrfHeaderName?: string; maxContentLength?: number; maxBodyLength?: number; } export interface AcchioResponse { data: T; status: number; statusText: string; headers: Record; config: AcchioRequestConfig; request?: any; } export interface AcchioError extends Error { config: AcchioRequestConfig; code?: string; request?: any; response?: AcchioResponse; isAcchioError: boolean; toJSON: () => object; } export interface AcchioInterceptorManager { use(onFulfilled?: (value: V) => V | Promise, onRejected?: (error: any) => any): number; eject(id: number): void; clear(): void; } export interface AcchioInstance { defaults: AcchioRequestConfig; interceptors: { request: AcchioInterceptorManager; response: AcchioInterceptorManager; }; request>(config: AcchioRequestConfig): Promise; get>(url: string, config?: AcchioRequestConfig): Promise; post>(url: string, data?: any, config?: AcchioRequestConfig): Promise; put>(url: string, data?: any, config?: AcchioRequestConfig): Promise; patch>(url: string, data?: any, config?: AcchioRequestConfig): Promise; delete>(url: string, config?: AcchioRequestConfig): Promise; head>(url: string, config?: AcchioRequestConfig): Promise; options>(url: string, config?: AcchioRequestConfig): Promise; create(config?: AcchioRequestConfig): AcchioInstance; } export interface Adapter { request(config: AcchioRequestConfig): Promise; } export interface Interceptor { fulfilled?: (value: T) => T | Promise; rejected?: (error: any) => any; } export type RequestTransformer = (data: any, headers?: Record) => any; export type ResponseTransformer = (data: any) => any; export interface ProgressEvent { loaded: number; total?: number; percent?: number; bytesPerSecond?: number; lengthComputable: boolean; } export interface AcchioRequestConfigWithProgress extends AcchioRequestConfig { onUploadProgress?: (progressEvent: ProgressEvent) => void; onDownloadProgress?: (progressEvent: ProgressEvent) => void; } export interface AcchioCancel { message?: string; __CANCEL__?: boolean; } export interface AcchioCancelToken { promise: Promise; reason?: AcchioCancel; throwIfRequested(): void; } export interface AcchioCancelTokenSource { token: AcchioCancelToken; cancel: (message?: string) => void; } export interface AcchioCancelStatic { new (message?: string): AcchioCancel; } export interface AcchioCancelTokenStatic { new (executor: (cancel: (message?: string) => void) => void): AcchioCancelToken; source(): AcchioCancelTokenSource; } export interface AcchioConstructor { new (config?: AcchioRequestConfig): AcchioInstance; create(config?: AcchioRequestConfig): AcchioInstance; defaults: AcchioRequestConfig; } export interface AcchioStatic extends AcchioInstance { create(config?: AcchioRequestConfig): AcchioInstance; Cancel: AcchioCancelStatic; CancelToken: AcchioCancelTokenStatic; isCancel(value: any): boolean; all(values: Array>): Promise; spread(callback: (...args: T[]) => R): (array: T[]) => R; } export type AcchioPromise = Promise & { cancel?: () => void; }; export declare const DEFAULT_CONFIG: AcchioRequestConfig; export interface AcchioDefaults { headers: { common: Record; get: Record; post: Record; put: Record; patch: Record; delete: Record; head: Record; options: Record; }; } export interface AcchioInterceptor { request: AcchioInterceptorManager; response: AcchioInterceptorManager; } export type AdapterType = "node" | "browser" | "auto" | Adapter; export interface Transformable { transformRequest?: RequestTransformer[]; transformResponse?: ResponseTransformer[]; } export interface TimeoutConfig { timeout: number; timeoutErrorMessage?: string; } export interface RetryConfig { retries: number; retryDelay?: number | ((retryCount: number) => number); retryCondition?: (error: AcchioError) => boolean; } export interface CacheConfig { cache?: boolean; cacheMaxAge?: number; etag?: boolean; } export interface AuthConfig { username?: string; password?: string; bearerToken?: string; apiKey?: string; apiKeyHeader?: string; } export type FullAcchioConfig = AcchioRequestConfig & TimeoutConfig & RetryConfig & CacheConfig & AuthConfig; export interface AcchioEventMap { request: { config: AcchioRequestConfig; }; response: { response: AcchioResponse; }; error: { error: AcchioError; }; cancel: { cancel: AcchioCancel; }; } export type AcchioEvent = keyof AcchioEventMap; export interface AcchioEventListener { (event: AcchioEventMap[T]): void; } export interface AcchioPlugin { (instance: AcchioInstance, config?: AcchioRequestConfig): void; } export interface AcchioMiddleware { onRequest?: (config: AcchioRequestConfig) => AcchioRequestConfig | Promise; onResponse?: (response: AcchioResponse) => AcchioResponse | Promise; onError?: (error: AcchioError) => AcchioError | Promise; } export interface URLParamsConfig { paramsSerializer?: (params: Record) => string; encodeParams?: boolean; } export interface FileUploadConfig { file: File | Blob | Buffer; fileName?: string; fileFieldName?: string; formData?: boolean; } export interface DownloadConfig { download?: boolean; fileName?: string; responseType: "blob" | "arraybuffer"; } export interface StreamConfig { stream?: boolean; onData?: (chunk: any) => void; onEnd?: () => void; onError?: (error: Error) => void; } export interface EventSourceConfig { eventSource?: boolean; onMessage?: (data: any) => void; onOpen?: (event: Event) => void; onError?: (event: Event) => void; } export interface MetricsConfig { enableMetrics?: boolean; onRequestStart?: (config: AcchioRequestConfig) => void; onRequestEnd?: (config: AcchioRequestConfig, response?: AcchioResponse, error?: AcchioError) => void; onRequestDuration?: (duration: number, config: AcchioRequestConfig) => void; } export type ExtendedAcchioConfig = FullAcchioConfig & URLParamsConfig & FileUploadConfig & DownloadConfig & StreamConfig & EventSourceConfig & MetricsConfig; export type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; export type Required = { [P in keyof T]-?: T[P]; }; export type PartialAcchioConfig = DeepPartial; export interface AcchioFactory { (config?: AcchioRequestConfig): AcchioInstance; create: (config?: AcchioRequestConfig) => AcchioInstance; } export interface AcchioModule { default: AcchioStatic; Acchio: AcchioStatic; } export type RuntimeEnvironment = "node" | "browser" | "deno" | "unknown"; export interface EnvironmentInfo { runtime: RuntimeEnvironment; version?: string; features: { fetch: boolean; stream: boolean; blob: boolean; formData: boolean; buffer: boolean; }; } export interface ValidationResult { isValid: boolean; errors: string[]; warnings: string[]; } export interface Logger { debug: (...args: any[]) => void; info: (...args: any[]) => void; warn: (...args: any[]) => void; error: (...args: any[]) => void; } export interface LoggingConfig { logger?: Logger; logLevel?: "debug" | "info" | "warn" | "error" | "silent"; logRequests?: boolean; logResponses?: boolean; logErrors?: boolean; } export type CompleteAcchioConfig = AcchioRequestConfig & TimeoutConfig & RetryConfig & CacheConfig & AuthConfig & URLParamsConfig & LoggingConfig & MetricsConfig; export type MethodWithoutData = "get" | "delete" | "head" | "options"; export type MethodWithData = "post" | "put" | "patch"; export type AcchioMethodConfig = T extends MethodWithoutData ? Omit : T extends MethodWithData ? AcchioRequestConfig : never; export interface AcchioRequestOverload { (config: AcchioRequestConfig): Promise>; (url: string, config?: AcchioRequestConfig): Promise>; } export interface AcchioGetOverload { (url: string, config?: AcchioRequestConfig): Promise>; } export interface AcchioPostOverload { (url: string, data?: any, config?: AcchioRequestConfig): Promise>; } export type Stringifiable = string | number | boolean | null | undefined; export type ParamValue = Stringifiable | Stringifiable[] | { [key: string]: ParamValue; }; export interface HttpMethodDataMap { GET: { hasData: false; }; DELETE: { hasData: false; }; HEAD: { hasData: false; }; OPTIONS: { hasData: false; }; POST: { hasData: true; }; PUT: { hasData: true; }; PATCH: { hasData: true; }; } export type ConfigForMethod = HttpMethodDataMap[T] extends { hasData: true; } ? AcchioRequestConfig : Omit; export type ResponseData = T extends AcchioResponse ? D : never; export type TypedAcchioRequest = (config: AcchioRequestConfig) => Promise>;