fixed all libs to be buildiable and dependency hell from removing some
This commit is contained in:
parent
5c64b1ccf8
commit
a282dac6cd
40 changed files with 4050 additions and 8219 deletions
48
libs/http-client/src/proxy-manager.ts
Normal file
48
libs/http-client/src/proxy-manager.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import { SocksProxyAgent } from 'socks-proxy-agent';
|
||||
import type { ProxyConfig } from './types.js';
|
||||
|
||||
export class ProxyManager {
|
||||
/**
|
||||
* Create appropriate proxy agent based on configuration
|
||||
*/
|
||||
static createAgent(proxy: ProxyConfig): HttpsProxyAgent<string> | SocksProxyAgent {
|
||||
const { type, host, port, username, password } = proxy;
|
||||
|
||||
let proxyUrl: string;
|
||||
|
||||
if (username && password) {
|
||||
proxyUrl = `${type}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}`;
|
||||
} else {
|
||||
proxyUrl = `${type}://${host}:${port}`;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'http':
|
||||
case 'https':
|
||||
return new HttpsProxyAgent(proxyUrl);
|
||||
case 'socks4':
|
||||
case 'socks5':
|
||||
return new SocksProxyAgent(proxyUrl);
|
||||
default:
|
||||
throw new Error(`Unsupported proxy type: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate proxy configuration
|
||||
*/
|
||||
static validateConfig(proxy: ProxyConfig): void {
|
||||
if (!proxy.host) {
|
||||
throw new Error('Proxy host is required');
|
||||
}
|
||||
|
||||
if (!proxy.port || proxy.port < 1 || proxy.port > 65535) {
|
||||
throw new Error('Invalid proxy port');
|
||||
}
|
||||
|
||||
if (!['http', 'https', 'socks4', 'socks5'].includes(proxy.type)) {
|
||||
throw new Error(`Invalid proxy type: ${proxy.type}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue