arn-browser 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -91,3 +91,38 @@ export function isProxyAlive(proxyHost: string, proxyPort: number): Promise<stri
|
|
|
91
91
|
* @param timeout - Request timeout in ms.
|
|
92
92
|
*/
|
|
93
93
|
export function nativeGet(url: string, agent?: any, timeout?: number): Promise<string>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Proxy configuration object returned by fetchAwsProxy.
|
|
97
|
+
*/
|
|
98
|
+
export interface ProxyConfig {
|
|
99
|
+
type: "socks5" | "http";
|
|
100
|
+
host: string;
|
|
101
|
+
port: number;
|
|
102
|
+
user: string | null;
|
|
103
|
+
pass: string | null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Parameters for fetchAwsProxy function.
|
|
108
|
+
*/
|
|
109
|
+
export interface FetchAwsProxyParams {
|
|
110
|
+
instance_name: string;
|
|
111
|
+
/**
|
|
112
|
+
* If true, uses getActiveProxyWithStartStop (hard reset).
|
|
113
|
+
* If false, uses getActiveProxy (IP cycling).
|
|
114
|
+
* @default true
|
|
115
|
+
*/
|
|
116
|
+
useStartStop?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* The proxy type. Determines the port (socks5: 10001, http: 9001).
|
|
119
|
+
* @default 'socks5'
|
|
120
|
+
*/
|
|
121
|
+
proxy_type?: "socks5" | "http";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Fetches an active AWS proxy and returns it in a standardized format.
|
|
126
|
+
* @returns The proxy configuration object or null if not found.
|
|
127
|
+
*/
|
|
128
|
+
export function fetchAwsProxy(params: FetchAwsProxyParams): Promise<ProxyConfig | null>;
|
|
@@ -506,7 +506,7 @@ export async function getActiveProxy({ instance_name }) {
|
|
|
506
506
|
}
|
|
507
507
|
|
|
508
508
|
await sleep(15000); // Wait for boot
|
|
509
|
-
const proxyAlive = await isProxyAlive(publicIp,
|
|
509
|
+
const proxyAlive = await isProxyAlive(publicIp, 10001);
|
|
510
510
|
await sleep(5000);
|
|
511
511
|
|
|
512
512
|
if (!proxyAlive) {
|
|
@@ -536,7 +536,7 @@ export async function getActiveProxyWithStartStop({ instance_name }) {
|
|
|
536
536
|
let publicIp = await getPublicIpAddress({ instance_name });
|
|
537
537
|
|
|
538
538
|
await sleep(15000); // Wait for boot
|
|
539
|
-
const proxyAlive = await isProxyAlive(publicIp,
|
|
539
|
+
const proxyAlive = await isProxyAlive(publicIp, 10001);
|
|
540
540
|
|
|
541
541
|
if (!proxyAlive) {
|
|
542
542
|
console.log("No Unique IP Found or Proxy Dead");
|
|
@@ -577,7 +577,7 @@ export async function getActiveProxyConditional({ instance_name }) {
|
|
|
577
577
|
await sleep(2000);
|
|
578
578
|
|
|
579
579
|
let publicIp = await getPublicIpAddress({ instance_name });
|
|
580
|
-
const proxyAlive = await isProxyAlive(publicIp,
|
|
580
|
+
const proxyAlive = await isProxyAlive(publicIp, 10001);
|
|
581
581
|
|
|
582
582
|
if (!proxyAlive) {
|
|
583
583
|
console.log("Proxy is not alive or no unique IP found.");
|
|
@@ -597,7 +597,7 @@ export async function getActiveProxyConditional({ instance_name }) {
|
|
|
597
597
|
* Uses native Node.js HTTP/HTTPS modules via 'nativeGet'.
|
|
598
598
|
*
|
|
599
599
|
* @param {string} proxyHost - IP address of the proxy.
|
|
600
|
-
* @param {number} proxyPort - Port of the proxy (usually
|
|
600
|
+
* @param {number} proxyPort - Port of the proxy (usually 10001).
|
|
601
601
|
*/
|
|
602
602
|
export async function isProxyAlive(proxyHost, proxyPort) {
|
|
603
603
|
const agent = new SocksProxyAgent(`socks5://${proxyHost}:${proxyPort}`);
|
|
@@ -623,3 +623,43 @@ export async function isProxyAlive(proxyHost, proxyPort) {
|
|
|
623
623
|
|
|
624
624
|
return null;
|
|
625
625
|
}
|
|
626
|
+
|
|
627
|
+
// ==========================================
|
|
628
|
+
// SECTION 8: HIGH-LEVEL PROXY FETCH
|
|
629
|
+
// ==========================================
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* @typedef {Object} ProxyConfig
|
|
633
|
+
* @property {'socks5'|'http'} type - The proxy type.
|
|
634
|
+
* @property {string} host - The proxy host IP address.
|
|
635
|
+
* @property {number} port - The proxy port.
|
|
636
|
+
* @property {string|null} user - The proxy username (null if not required).
|
|
637
|
+
* @property {string|null} pass - The proxy password (null if not required).
|
|
638
|
+
*/
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Fetches an active AWS proxy and returns it in a standardized format.
|
|
642
|
+
*
|
|
643
|
+
* @param {Object} params - The parameters object.
|
|
644
|
+
* @param {string} params.instance_name - The name of the EC2 instance.
|
|
645
|
+
* @param {boolean} [params.useStartStop=true] - If true, uses getActiveProxyWithStartStop (hard reset).
|
|
646
|
+
* If false, uses getActiveProxy (IP cycling).
|
|
647
|
+
* @param {'socks5'|'http'} [params.proxy_type='socks5'] - The proxy type (socks5: port 10001, http: port 9001).
|
|
648
|
+
* @returns {Promise<ProxyConfig|null>} - The proxy configuration object or null if not found.
|
|
649
|
+
*/
|
|
650
|
+
export const fetchAwsProxy = async ({ instance_name, useStartStop = true, proxy_type = "socks5" }) => {
|
|
651
|
+
let getawsproxy;
|
|
652
|
+
if (useStartStop) {
|
|
653
|
+
getawsproxy = await getActiveProxyWithStartStop({ instance_name: instance_name });
|
|
654
|
+
} else {
|
|
655
|
+
getawsproxy = await getActiveProxy({ instance_name: instance_name });
|
|
656
|
+
}
|
|
657
|
+
if (!getawsproxy) {
|
|
658
|
+
console.log("Aws proxy not found");
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
/** @type {ProxyConfig} */
|
|
662
|
+
const port = proxy_type === "socks5" ? 10001 : 9001;
|
|
663
|
+
let temp_proxy = { type: proxy_type, host: getawsproxy, port: port, user: null, pass: null };
|
|
664
|
+
return temp_proxy;
|
|
665
|
+
};
|