kucoin-universal-sdk
Version:
Official KuCoin Universal SDK.
150 lines (149 loc) • 4.27 kB
TypeScript
import { AxiosInterceptorOptions, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
/**
* Describes the structure for Axios request interceptors.
* @template T - The type of the request configuration.
*/
export interface AxiosRequestInterceptor {
onFulfilled?: ((value: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>) | null;
onRejected?: ((error: any) => any) | null;
options?: AxiosInterceptorOptions;
}
/**
* Describes the structure for Axios response interceptors.
* @template T - The type of the response.
*/
export interface AxiosResponseInterceptor {
onFulfilled?: ((value: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>) | null;
onRejected?: ((error: any) => any) | null;
}
/**
* Represents HTTP interceptors for requests and responses.
*/
export interface Interceptor {
/**
* Handles modifications to the request before sending.
*/
before: AxiosRequestInterceptor;
/**
* Handles processing of the response or errors.
*/
after: AxiosResponseInterceptor;
}
export interface ProxyOption {
http?: {
host: string;
port: number;
};
https?: {
host: string;
port: number;
};
auth?: {
username: string;
password: string;
};
}
/**
* TransportOption interface for storing various HTTP request configurations
*/
export interface TransportOption {
/**
* Request timeout duration (in milliseconds)
*/
timeout: number;
/**
* Whether to enable keep-alive (persistent connection)
*/
keepAlive: boolean;
/**
* Maximum number of idle (keep-alive) connections across all hosts
*/
maxIdleConns: number;
/**
* Maximum idle connections per host
*/
maxIdleConnsPerHost: number;
/**
* Total number of connections per host
*/
maxConnsPerHost: number;
/**
* Maximum time an idle connection will remain idle (in milliseconds)
*/
idleConnTimeout: number;
/**
* HTTP(s) proxy options
*/
proxy?: ProxyOption;
/**
* Maximum number of retry attempts
*/
maxRetries: number;
/**
* Delay duration between retries (in milliseconds)
*/
retryDelay: number;
/**
* HTTP interceptors
*/
interceptors?: Interceptor[];
}
/**
* Default values for TransportOption
*/
export declare const DEFAULT_TRANSPORT_OPTION: TransportOption;
/**
* TransportOptionBuilder for creating and customizing TransportOption instances
*/
export declare class TransportOptionBuilder {
private option;
constructor();
/**
* Set the request timeout duration (in milliseconds)
*/
setTimeout(timeout: number): TransportOptionBuilder;
/**
* Set whether to enable keep-alive (persistent connection)
*/
setKeepAlive(keepAlive: boolean): TransportOptionBuilder;
/**
* Set the maximum number of idle (keep-alive) connections across all hosts
*/
setMaxIdleConns(maxIdleConns: number): TransportOptionBuilder;
/**
* Set the maximum idle connections per host
*/
setMaxIdleConnsPerHost(maxIdleConnsPerHost: number): TransportOptionBuilder;
/**
* Set the total number of connections per host
*/
setMaxConnsPerHost(maxConnsPerHost: number): TransportOptionBuilder;
/**
* Set the maximum time an idle connection will remain idle (in milliseconds)
*/
setIdleConnTimeout(idleConnTimeout: number): TransportOptionBuilder;
/**
* Set the HTTP(s) proxy options
*/
setProxy(proxy: ProxyOption): TransportOptionBuilder;
/**
* Set the maximum number of retry attempts
*/
setMaxRetries(maxRetries: number): TransportOptionBuilder;
/**
* Set the delay duration between retries (in milliseconds)
*/
setRetryDelay(retryDelay: number): TransportOptionBuilder;
/**
* Set the HTTP interceptors
*/
setInterceptors(interceptors: Interceptor[]): TransportOptionBuilder;
/**
* Add an HTTP interceptor
*/
addInterceptor(interceptor: Interceptor): TransportOptionBuilder;
/**
* Build and return the TransportOption instance
*/
build(): TransportOption;
}