n8n-nodes-script-runner 1.3.0 → 1.4.0

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.
@@ -7,6 +7,7 @@ exports.HttpRequestRunner = void 0;
7
7
  const n8n_workflow_1 = require("n8n-workflow");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const user_agents_1 = __importDefault(require("user-agents"));
10
+ const https_proxy_agent_1 = require("https-proxy-agent");
10
11
  const userAgent = new user_agents_1.default({
11
12
  deviceCategory: 'desktop',
12
13
  platform: 'Win32',
@@ -176,7 +177,7 @@ class HttpRequestRunner {
176
177
  rows: 15,
177
178
  alwaysOpenEditWindow: true,
178
179
  },
179
- default: `// Axios example with proxy:
180
+ default: `// Axios example with proxy agent:
180
181
  const config = {
181
182
  method: 'GET',
182
183
  url: 'https://api.example.com/data',
@@ -186,32 +187,30 @@ const config = {
186
187
  }
187
188
  };
188
189
 
189
- // Add proxy if configured
190
- if ($proxy) {
191
- const proxyUrl = new URL($proxy);
192
- config.proxy = {
193
- host: proxyUrl.hostname,
194
- port: parseInt(proxyUrl.port) || 80,
195
- protocol: proxyUrl.protocol.replace(':', '')
196
- };
190
+ // Add proxy agent if configured
191
+ if ($proxyAgent) {
192
+ config.httpsAgent = $proxyAgent;
193
+ config.proxy = false; // Disable default axios proxy
197
194
  }
198
195
 
199
196
  const response = await axios(config);
200
197
  return response.data;
201
198
 
202
- // Fetch example (note: fetch doesn't support proxy natively):
199
+ // Fetch example with proxy agent:
203
200
  // const response = await fetch('https://api.example.com/data', {
204
201
  // method: 'POST',
205
202
  // headers: {
206
203
  // 'Content-Type': 'application/json',
207
204
  // 'User-Agent': $userAgent
208
205
  // },
209
- // body: JSON.stringify({ key: 'value' })
206
+ // body: JSON.stringify({ key: 'value' }),
207
+ // agent: $proxyAgent // Use the proxy agent
210
208
  // });
211
209
  // return await response.json();
212
210
 
213
- // Available variables: axios, fetch, items, $item, itemIndex, $proxy, $userAgent`,
214
- description: 'Custom JavaScript code for HTTP requests. Available: axios, fetch, items, $item, itemIndex, $proxy, $userAgent',
211
+ // Available variables: axios, fetch, items, $item, itemIndex, $proxyAgent, $userAgent
212
+ // $proxyAgent is an HttpsProxyAgent instance (null if no proxies configured)`,
213
+ description: 'Custom JavaScript code for HTTP requests. Available: axios, fetch, items, $item, itemIndex, $proxyAgent, $userAgent',
215
214
  },
216
215
  {
217
216
  displayName: 'Random User-Agent',
@@ -226,17 +225,20 @@ return response.data;
226
225
  description: 'Whether to use a random User-Agent header automatically. Access via $userAgent variable in custom script',
227
226
  },
228
227
  {
229
- displayName: 'Proxy',
230
- name: 'proxy',
228
+ displayName: 'Proxy List',
229
+ name: 'proxyList',
231
230
  type: 'string',
232
231
  displayOptions: {
233
232
  show: {
234
233
  library: ['custom'],
235
234
  },
236
235
  },
236
+ typeOptions: {
237
+ rows: 10,
238
+ },
237
239
  default: '',
238
- placeholder: 'http://proxy.example.com:8080',
239
- description: 'Proxy server URL (optional). Access via $proxy variable in custom script',
240
+ placeholder: '208.195.173.53:65095:username:password\n208.195.162.166:65095:username:password',
241
+ description: 'List of proxies (one per line) in format: IP:PORT:USERNAME:PASSWORD. A random proxy will be selected and available as $proxyAgent in your script',
240
242
  },
241
243
  {
242
244
  displayName: 'Return Full Response',
@@ -267,11 +269,22 @@ return response.data;
267
269
  if (library === 'custom') {
268
270
  // Custom script execution
269
271
  const script = this.getNodeParameter('script', itemIndex);
270
- const proxy = this.getNodeParameter('proxy', itemIndex, '');
272
+ const proxyList = this.getNodeParameter('proxyList', itemIndex, '');
271
273
  const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
272
274
  const userAgent = randomUserAgent ? getRandomUserAgent() : '';
273
- const executeScript = new Function('axios', 'fetch', 'items', '$item', 'itemIndex', '$proxy', '$userAgent', `return (async () => { ${script} })();`);
274
- result = await executeScript(axios_1.default, fetch, items, $item, itemIndex, proxy, userAgent);
275
+ // Parse proxy list and select random proxy
276
+ let proxyAgent = null;
277
+ if (proxyList && proxyList.trim()) {
278
+ const proxies = proxyList.split('\n').filter(p => p.trim());
279
+ if (proxies.length > 0) {
280
+ const randomProxy = proxies[Math.floor(Math.random() * proxies.length)];
281
+ const [ip, port, username, password] = randomProxy.split(':');
282
+ const proxyUrl = `http://${username}:${password}@${ip}:${port}`;
283
+ proxyAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
284
+ }
285
+ }
286
+ const executeScript = new Function('axios', 'fetch', 'items', '$item', 'itemIndex', '$proxyAgent', '$userAgent', `return (async () => { ${script} })();`);
287
+ result = await executeScript(axios_1.default, fetch, items, $item, itemIndex, proxyAgent, userAgent);
275
288
  }
276
289
  else if (library === 'axios') {
277
290
  // Axios execution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-script-runner",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Custom n8n nodes for script execution (jsdom, cheerio) and HTTP requests (axios, fetch)",
5
5
  "main": "index.js",
6
6
  "scripts": {