n8n-nodes-script-runner 1.2.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',
|
|
@@ -150,6 +151,19 @@ class HttpRequestRunner {
|
|
|
150
151
|
default: 30000,
|
|
151
152
|
description: 'Request timeout in milliseconds',
|
|
152
153
|
},
|
|
154
|
+
{
|
|
155
|
+
displayName: 'Proxy',
|
|
156
|
+
name: 'proxy',
|
|
157
|
+
type: 'string',
|
|
158
|
+
displayOptions: {
|
|
159
|
+
show: {
|
|
160
|
+
library: ['axios', 'fetch'],
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
default: '',
|
|
164
|
+
placeholder: 'http://proxy.example.com:8080',
|
|
165
|
+
description: 'Proxy server URL (optional)',
|
|
166
|
+
},
|
|
153
167
|
{
|
|
154
168
|
displayName: 'Custom Script',
|
|
155
169
|
name: 'script',
|
|
@@ -163,25 +177,68 @@ class HttpRequestRunner {
|
|
|
163
177
|
rows: 15,
|
|
164
178
|
alwaysOpenEditWindow: true,
|
|
165
179
|
},
|
|
166
|
-
default: `// Axios example:
|
|
167
|
-
const
|
|
180
|
+
default: `// Axios example with proxy agent:
|
|
181
|
+
const config = {
|
|
168
182
|
method: 'GET',
|
|
169
183
|
url: 'https://api.example.com/data',
|
|
170
|
-
headers: {
|
|
171
|
-
|
|
184
|
+
headers: {
|
|
185
|
+
'Content-Type': 'application/json',
|
|
186
|
+
'User-Agent': $userAgent // Random user agent if enabled
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Add proxy agent if configured
|
|
191
|
+
if ($proxyAgent) {
|
|
192
|
+
config.httpsAgent = $proxyAgent;
|
|
193
|
+
config.proxy = false; // Disable default axios proxy
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const response = await axios(config);
|
|
172
197
|
return response.data;
|
|
173
198
|
|
|
174
|
-
// Fetch example:
|
|
199
|
+
// Fetch example with proxy agent:
|
|
175
200
|
// const response = await fetch('https://api.example.com/data', {
|
|
176
201
|
// method: 'POST',
|
|
177
|
-
// headers: {
|
|
178
|
-
//
|
|
202
|
+
// headers: {
|
|
203
|
+
// 'Content-Type': 'application/json',
|
|
204
|
+
// 'User-Agent': $userAgent
|
|
205
|
+
// },
|
|
206
|
+
// body: JSON.stringify({ key: 'value' }),
|
|
207
|
+
// agent: $proxyAgent // Use the proxy agent
|
|
179
208
|
// });
|
|
180
209
|
// return await response.json();
|
|
181
210
|
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
description: 'Custom JavaScript code for HTTP requests. Available: axios, fetch, items, $item, itemIndex',
|
|
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',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
displayName: 'Random User-Agent',
|
|
217
|
+
name: 'randomUserAgent',
|
|
218
|
+
type: 'boolean',
|
|
219
|
+
displayOptions: {
|
|
220
|
+
show: {
|
|
221
|
+
library: ['custom'],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
default: true,
|
|
225
|
+
description: 'Whether to use a random User-Agent header automatically. Access via $userAgent variable in custom script',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
displayName: 'Proxy List',
|
|
229
|
+
name: 'proxyList',
|
|
230
|
+
type: 'string',
|
|
231
|
+
displayOptions: {
|
|
232
|
+
show: {
|
|
233
|
+
library: ['custom'],
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
typeOptions: {
|
|
237
|
+
rows: 10,
|
|
238
|
+
},
|
|
239
|
+
default: '',
|
|
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',
|
|
185
242
|
},
|
|
186
243
|
{
|
|
187
244
|
displayName: 'Return Full Response',
|
|
@@ -212,9 +269,22 @@ return response.data;
|
|
|
212
269
|
if (library === 'custom') {
|
|
213
270
|
// Custom script execution
|
|
214
271
|
const script = this.getNodeParameter('script', itemIndex);
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
|
|
272
|
+
const proxyList = this.getNodeParameter('proxyList', itemIndex, '');
|
|
273
|
+
const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
|
|
274
|
+
const userAgent = randomUserAgent ? getRandomUserAgent() : '';
|
|
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);
|
|
218
288
|
}
|
|
219
289
|
else if (library === 'axios') {
|
|
220
290
|
// Axios execution
|
|
@@ -224,6 +294,7 @@ return response.data;
|
|
|
224
294
|
const queryParamsJson = this.getNodeParameter('queryParams', itemIndex, '{}');
|
|
225
295
|
const timeout = this.getNodeParameter('timeout', itemIndex, 30000);
|
|
226
296
|
const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
|
|
297
|
+
const proxy = this.getNodeParameter('proxy', itemIndex, '');
|
|
227
298
|
const headers = JSON.parse(headersJson);
|
|
228
299
|
const params = JSON.parse(queryParamsJson);
|
|
229
300
|
// Add random user-agent if enabled and not already set
|
|
@@ -237,6 +308,21 @@ return response.data;
|
|
|
237
308
|
params,
|
|
238
309
|
timeout,
|
|
239
310
|
};
|
|
311
|
+
// Add proxy if configured
|
|
312
|
+
if (proxy) {
|
|
313
|
+
const proxyUrl = new URL(proxy);
|
|
314
|
+
config.proxy = {
|
|
315
|
+
host: proxyUrl.hostname,
|
|
316
|
+
port: parseInt(proxyUrl.port) || (proxyUrl.protocol === 'https:' ? 443 : 80),
|
|
317
|
+
protocol: proxyUrl.protocol.replace(':', ''),
|
|
318
|
+
};
|
|
319
|
+
if (proxyUrl.username) {
|
|
320
|
+
config.proxy.auth = {
|
|
321
|
+
username: proxyUrl.username,
|
|
322
|
+
password: proxyUrl.password,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
240
326
|
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
241
327
|
const bodyJson = this.getNodeParameter('body', itemIndex, '{}');
|
|
242
328
|
config.data = JSON.parse(bodyJson);
|
|
@@ -262,8 +348,14 @@ return response.data;
|
|
|
262
348
|
const queryParamsJson = this.getNodeParameter('queryParams', itemIndex, '{}');
|
|
263
349
|
const timeout = this.getNodeParameter('timeout', itemIndex, 30000);
|
|
264
350
|
const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
|
|
351
|
+
const proxy = this.getNodeParameter('proxy', itemIndex, '');
|
|
265
352
|
const headers = JSON.parse(headersJson);
|
|
266
353
|
const params = JSON.parse(queryParamsJson);
|
|
354
|
+
// Note: Native fetch API doesn't support proxy configuration directly
|
|
355
|
+
// Proxy setting is available but would require additional proxy agent libraries
|
|
356
|
+
if (proxy) {
|
|
357
|
+
console.warn('Proxy configuration is not supported with native fetch. Use axios or custom script instead.');
|
|
358
|
+
}
|
|
267
359
|
// Add random user-agent if enabled and not already set
|
|
268
360
|
if (randomUserAgent && !headers['User-Agent'] && !headers['user-agent']) {
|
|
269
361
|
headers['User-Agent'] = getRandomUserAgent();
|