arn-browser 0.0.4 → 0.0.6

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.
@@ -12,51 +12,14 @@ import {
12
12
  } from "@aws-sdk/client-ec2";
13
13
  import { SocksProxyAgent } from "socks-proxy-agent";
14
14
  import { setTimeout as sleep } from "timers/promises";
15
- import fs from "fs";
16
- import path from "path";
17
- import { pathToFileURL } from "url";
18
15
  import https from "https";
19
16
  import http from "http";
20
-
21
- // Global configuration cache
22
- let config = null;
17
+ import { arn, query } from "arn-knexjs";
23
18
 
24
19
  // ==========================================
25
20
  // SECTION 1: CONFIGURATION & UTILITIES
26
21
  // ==========================================
27
22
 
28
- /**
29
- * Dynamically loads 'browser_automation_env.js' from the user's project root.
30
- * This replaces the static import of 'arn' and 'query'.
31
- */
32
- async function loadUserConfig() {
33
- if (config) return config;
34
-
35
- try {
36
- const projectRoot = process.cwd();
37
- // Adjust path if your structure is different (e.g., just "utility" or "../utility")
38
- const envPath = path.join(projectRoot, "utility", "browser_automation_env.js");
39
-
40
- if (!fs.existsSync(envPath)) {
41
- throw new Error(`Could not find configuration file at: ${envPath}`);
42
- }
43
-
44
- const envUrl = pathToFileURL(envPath).href;
45
- const userEnv = await import(envUrl);
46
-
47
- // Validate required exports
48
- if (!userEnv.arn || !userEnv.query) {
49
- throw new Error("[AWS Manager] 'browser_automation_env.js' is missing 'arn' or 'query' exports.");
50
- }
51
-
52
- config = userEnv;
53
- return config;
54
- } catch (error) {
55
- console.error("❌ Config Error:", error.message);
56
- throw error;
57
- }
58
- }
59
-
60
23
  /**
61
24
  * Native Node.js implementation of an HTTP GET request to replace Superagent.
62
25
  * Supports custom agents (SOCKS/HTTP).
@@ -109,8 +72,6 @@ function nativeGet(url, agent = null, timeout = 5000) {
109
72
  * @returns {Promise<object>} - Returns { ec2Client, instanceId, elasticIpName }.
110
73
  */
111
74
  async function fetchAwsClientAndInstanceId({ instance_name }) {
112
- const { arn, query } = await loadUserConfig();
113
-
114
75
  const { data: [data] = [], error } = await arn.single(
115
76
  query("api_aws_proxy_account").select("*").where({ instance_name }).limit(1)
116
77
  );
@@ -400,7 +361,6 @@ export async function DeleteUnassociatedElasticIPs({ instance_name }) {
400
361
  * Stops the instance and releases IPs.
401
362
  */
402
363
  export async function resetServersAndIp() {
403
- const { arn, query } = await loadUserConfig();
404
364
  const thirtyMinutesAgo = new Date(new Date().getTime() - 25 * 60000).toISOString();
405
365
 
406
366
  const { data, error } = await arn.single(
@@ -440,8 +400,6 @@ export async function resetServersAndIp() {
440
400
  * Updates the database to indicate the server is currently being used (status: 1).
441
401
  */
442
402
  async function keepServerAlivetoDB({ instance_name }) {
443
- const { arn, query } = await loadUserConfig();
444
-
445
403
  const { error: updateError } = await arn.single(
446
404
  query("api_aws_proxy_account")
447
405
  .update({
@@ -460,8 +418,6 @@ async function keepServerAlivetoDB({ instance_name }) {
460
418
  * Tracks usage statistics for a specific IP address in the database.
461
419
  */
462
420
  async function updateProxyToDB({ instance_name, ip_address }) {
463
- const { arn, query } = await loadUserConfig();
464
-
465
421
  // 1. Get Account ID
466
422
  let { data: [accountData] = [], error: accountError } = await arn.single(
467
423
  query("api_aws_proxy_account").select("id").where({ instance_name }).limit(1)
@@ -70,7 +70,7 @@ export function get_multilogin_proxy(options?: MultiloginProxyOptions): Promise<
70
70
 
71
71
  /**
72
72
  * Generates a PacketStream proxy object with a random session ID.
73
- * Credentials are loaded dynamically from 'browser_automation_env.js'.
73
+ * Credentials are loaded from environment variables (PACKETSTREAM_USER, PACKETSTREAM_PASS_KEY, PACKETSTREAM_HOST, PACKETSTREAM_PORT).
74
74
  * @returns The proxy object.
75
75
  */
76
76
  export function get_packetstream_proxy(): Promise<ProxyObject>;
@@ -1,57 +1,36 @@
1
1
  import { setTimeout as sleep } from "timers/promises";
2
2
  import randomstring from "randomstring";
3
- import fs from "fs";
4
- import path from "path";
5
- import { pathToFileURL } from "url";
6
3
  import { getMultiloginToken } from "../multilogin_token_manager.js";
7
- // Assuming fetchAwsProxy is in the same directory or adjust path accordingly
8
4
  import { getActiveProxyWithStartStop as fetchAwsProxy } from "./custom-proxy.js";
5
+ import { arn, query } from "arn-knexjs";
9
6
 
10
- // Global configuration cache
11
- let config = null;
7
+ // Environment variables for PacketStream
8
+ const PACKETSTREAM_USER = process.env.PACKETSTREAM_USER;
9
+ const PACKETSTREAM_PASS_KEY = process.env.PACKETSTREAM_PASS_KEY;
10
+ const PACKETSTREAM_HOST = process.env.PACKETSTREAM_HOST;
11
+ const PACKETSTREAM_PORT = process.env.PACKETSTREAM_PORT;
12
12
 
13
13
  // ==========================================
14
14
  // SECTION 1: CONFIGURATION & UTILITIES
15
15
  // ==========================================
16
16
 
17
17
  /**
18
- * Dynamically loads 'browser_automation_env.js' from the user's project root.
18
+ * Validates PacketStream environment variables are set.
19
19
  */
20
- async function loadUserConfig() {
21
- if (config) return config;
22
-
23
- try {
24
- const projectRoot = process.cwd();
25
- const envPath = path.join(projectRoot, "utility", "browser_automation_env.js");
26
-
27
- if (!fs.existsSync(envPath)) {
28
- throw new Error(`Could not find configuration file at: ${envPath}`);
29
- }
30
-
31
- const envUrl = pathToFileURL(envPath).href;
32
- const userEnv = await import(envUrl);
33
-
34
- // Validate required exports
35
- const requiredKeys = [
36
- "arn",
37
- "query",
38
- "PACKETSTREAM_USER",
39
- "PACKETSTREAM_PASS_KEY",
40
- "PACKETSTREAM_HOST",
41
- "PACKETSTREAM_PORT",
42
- ];
43
-
44
- const missing = requiredKeys.filter((key) => !userEnv[key]);
20
+ function validatePacketStreamEnv() {
21
+ const required = {
22
+ PACKETSTREAM_USER,
23
+ PACKETSTREAM_PASS_KEY,
24
+ PACKETSTREAM_HOST,
25
+ PACKETSTREAM_PORT,
26
+ };
45
27
 
46
- if (missing.length > 0) {
47
- throw new Error(`[Proxy Manager] 'browser_automation_env.js' is missing exports: ${missing.join(", ")}`);
48
- }
28
+ const missing = Object.entries(required)
29
+ .filter(([, value]) => !value)
30
+ .map(([key]) => key);
49
31
 
50
- config = userEnv;
51
- return config;
52
- } catch (error) {
53
- console.error("❌ Config Error:", error.message);
54
- throw error;
32
+ if (missing.length > 0) {
33
+ throw new Error(`[Proxy Manager] Missing environment variables: ${missing.join(", ")}`);
55
34
  }
56
35
  }
57
36
 
@@ -147,8 +126,8 @@ export async function get_multilogin_proxy({
147
126
  * Generates a PacketStream proxy object with a random session ID using credentials from config.
148
127
  */
149
128
  export async function get_packetstream_proxy() {
150
- // 1. Load config dynamically
151
- const { PACKETSTREAM_USER, PACKETSTREAM_PASS_KEY, PACKETSTREAM_HOST, PACKETSTREAM_PORT } = await loadUserConfig();
129
+ // 1. Validate environment variables
130
+ validatePacketStreamEnv();
152
131
 
153
132
  // 2. Generate Random Session ID
154
133
  const proxy_session_id = randomstring.generate({
@@ -176,8 +155,6 @@ export async function get_packetstream_proxy() {
176
155
  // ==========================================
177
156
 
178
157
  export async function get_x_proxy({ provider }) {
179
- const { arn, query } = await loadUserConfig();
180
-
181
158
  const { data: [proxyInstance] = [], error: getProxy_error } = await arn.single(
182
159
  query("x_accounts_proxy")
183
160
  .update({
@@ -1,32 +0,0 @@
1
- // utility/browser_automation_env.js
2
-
3
- // 1. Import your existing database connection/client here
4
- import { arn, query } from "./customApiClient.js";
5
-
6
- // 2. Multilogin Credentials
7
- const MULTILOGIN_EMAIL = "arndesk1@gmail.com";
8
- const MULTILOGIN_PASSWORD = "Xq#u.@994E5Ezum";
9
- const MULTILOGIN_WORKSPACE_ID = "bad9e7e1-cfab-4c8d-bd19-91aa82929711";
10
-
11
- // 3. Database Row ID for token storage
12
- const ROW_ID = "088e930f-e009-4ee8-bb79-4f677c2b7307";
13
-
14
- // 4. PacketStream Credentials
15
- const PACKETSTREAM_USER = "mauraiz55";
16
- // This is the static part of the password before the "_country" flags
17
- const PACKETSTREAM_PASS_KEY = "hygsm2irLAT8DwNE_country-UnitedStates_session";
18
- const PACKETSTREAM_HOST = "209.38.173.242"; // or "proxy.packetstream.io"
19
- const PACKETSTREAM_PORT = 31112;
20
-
21
- export {
22
- arn,
23
- query,
24
- MULTILOGIN_EMAIL,
25
- MULTILOGIN_PASSWORD,
26
- MULTILOGIN_WORKSPACE_ID,
27
- ROW_ID,
28
- PACKETSTREAM_USER,
29
- PACKETSTREAM_PASS_KEY,
30
- PACKETSTREAM_HOST,
31
- PACKETSTREAM_PORT,
32
- };