proxy-auto-ts
Version:
A comprehensive TypeScript library for automatic proxy management with validation, rotation, and intelligent selection
125 lines • 3.49 kB
TypeScript
export interface ProxyFetchResult {
data: any;
proxy: string;
latency: number;
}
export interface ProxyManagerConfig {
timeout?: number;
validationTimeout?: number;
fallbackUrls?: string[];
userAgents?: string[];
proxyListPath?: string;
}
/**
* ProxyManager - A comprehensive proxy management library
*
* @example
* ```typescript
* import { ProxyManager } from 'proxy-auto-ts';
*
* const proxyManager = new ProxyManager();
* await proxyManager.initialize(); // Initialize proxy list
* const result = await proxyManager.fetchWithProxy('https://httpbin.org/ip');
* console.log(result.data);
* ```
*
* @example
* ```typescript
* // Auto-initialization on first use
* const proxyManager = new ProxyManager();
* const result = await proxyManager.fetchWithProxy('https://httpbin.org/ip');
* console.log(result.data);
* ```
*/
export declare class ProxyManager {
private proxies;
private readonly config;
private initialized;
constructor(config?: ProxyManagerConfig);
/**
* Initialize the proxy manager by loading proxies
*/
initialize(): Promise<void>;
/**
* Ensure proxy manager is initialized
*/
private ensureInitialized;
/**
* Load proxies from file or URL
*/
private loadProxies;
/**
* Get copy of loaded proxies
*/
getProxies(): Promise<string[]>;
/**
* Get number of loaded proxies
*/
getProxyCount(): Promise<number>;
/**
* Get random user agent
*/
private getRandomUserAgent;
/**
* Format proxy URL
*/
private formatProxyUrl;
/**
* Validate proxy for specific URL
*/
private validateProxyForUrl;
/**
* Fetch URL through proxy with automatic fallback
*
* @param url - Target URL to fetch
* @param maxRetries - Maximum number of proxy retries
* @returns Promise<ProxyFetchResult>
*/
fetchWithProxy(url: string, maxRetries?: number): Promise<ProxyFetchResult>;
/**
* Find best proxy based on latency
*
* @param testUrl - URL to test proxies against
* @param maxProxiesToTest - Maximum number of proxies to test
* @returns Promise<ProxyFetchResult>
*/
findBestProxy(testUrl?: string, maxProxiesToTest?: number): Promise<ProxyFetchResult>;
/**
* Fetch URL with specific proxy
*
* @param url - Target URL to fetch
* @param targetProxy - Specific proxy to use
* @returns Promise<ProxyFetchResult>
*/
fetchWithSpecificProxy(url: string, targetProxy: string): Promise<ProxyFetchResult>;
/**
* Test proxy connectivity
*
* @param proxy - Proxy to test
* @param testUrl - URL to test against
* @returns Promise<boolean>
*/
testProxy(proxy: string, testUrl?: string): Promise<boolean>;
/**
* Validate all loaded proxies using worker threads for maximum performance
*
* @param testUrl - URL to test proxies against
* @returns Promise<{proxy: string, latency: number, status: number|null}[]>
*/
validateAllProxies(testUrl?: string): Promise<{
proxy: string;
latency: number;
status: number | null;
}[]>;
/**
* Get proxy statistics
*
* @returns Object with proxy statistics
*/
getStats(): Promise<{
totalProxies: number;
proxyListPath: string;
config: Required<ProxyManagerConfig>;
}>;
}
//# sourceMappingURL=lib.d.ts.map