arn-browser 0.1.1 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arn-browser",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A lightweight, browser autmation helper.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -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>;
@@ -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
+ };