n8n-nodes-script-runner 1.1.0 → 1.3.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.
|
@@ -6,20 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.HttpRequestRunner = void 0;
|
|
7
7
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0',
|
|
15
|
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
|
|
16
|
-
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
17
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edge/120.0.0.0',
|
|
18
|
-
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0',
|
|
19
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
|
|
20
|
-
];
|
|
9
|
+
const user_agents_1 = __importDefault(require("user-agents"));
|
|
10
|
+
const userAgent = new user_agents_1.default({
|
|
11
|
+
deviceCategory: 'desktop',
|
|
12
|
+
platform: 'Win32',
|
|
13
|
+
});
|
|
21
14
|
function getRandomUserAgent() {
|
|
22
|
-
return
|
|
15
|
+
return userAgent.random().toString();
|
|
23
16
|
}
|
|
24
17
|
class HttpRequestRunner {
|
|
25
18
|
constructor() {
|
|
@@ -29,7 +22,6 @@ class HttpRequestRunner {
|
|
|
29
22
|
icon: 'file:httprequest.svg',
|
|
30
23
|
group: ['transform'],
|
|
31
24
|
version: 1,
|
|
32
|
-
maxNodes: 1,
|
|
33
25
|
subtitle: '={{$parameter["library"]}}',
|
|
34
26
|
description: 'Make HTTP requests with axios, fetch, or custom scripts',
|
|
35
27
|
defaults: {
|
|
@@ -158,6 +150,19 @@ class HttpRequestRunner {
|
|
|
158
150
|
default: 30000,
|
|
159
151
|
description: 'Request timeout in milliseconds',
|
|
160
152
|
},
|
|
153
|
+
{
|
|
154
|
+
displayName: 'Proxy',
|
|
155
|
+
name: 'proxy',
|
|
156
|
+
type: 'string',
|
|
157
|
+
displayOptions: {
|
|
158
|
+
show: {
|
|
159
|
+
library: ['axios', 'fetch'],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
default: '',
|
|
163
|
+
placeholder: 'http://proxy.example.com:8080',
|
|
164
|
+
description: 'Proxy server URL (optional)',
|
|
165
|
+
},
|
|
161
166
|
{
|
|
162
167
|
displayName: 'Custom Script',
|
|
163
168
|
name: 'script',
|
|
@@ -171,25 +176,67 @@ class HttpRequestRunner {
|
|
|
171
176
|
rows: 15,
|
|
172
177
|
alwaysOpenEditWindow: true,
|
|
173
178
|
},
|
|
174
|
-
default: `// Axios example:
|
|
175
|
-
const
|
|
179
|
+
default: `// Axios example with proxy:
|
|
180
|
+
const config = {
|
|
176
181
|
method: 'GET',
|
|
177
182
|
url: 'https://api.example.com/data',
|
|
178
|
-
headers: {
|
|
179
|
-
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': 'application/json',
|
|
185
|
+
'User-Agent': $userAgent // Random user agent if enabled
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
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
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const response = await axios(config);
|
|
180
200
|
return response.data;
|
|
181
201
|
|
|
182
|
-
// Fetch example:
|
|
202
|
+
// Fetch example (note: fetch doesn't support proxy natively):
|
|
183
203
|
// const response = await fetch('https://api.example.com/data', {
|
|
184
204
|
// method: 'POST',
|
|
185
|
-
// headers: {
|
|
205
|
+
// headers: {
|
|
206
|
+
// 'Content-Type': 'application/json',
|
|
207
|
+
// 'User-Agent': $userAgent
|
|
208
|
+
// },
|
|
186
209
|
// body: JSON.stringify({ key: 'value' })
|
|
187
210
|
// });
|
|
188
211
|
// return await response.json();
|
|
189
212
|
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
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',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
displayName: 'Random User-Agent',
|
|
218
|
+
name: 'randomUserAgent',
|
|
219
|
+
type: 'boolean',
|
|
220
|
+
displayOptions: {
|
|
221
|
+
show: {
|
|
222
|
+
library: ['custom'],
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
default: true,
|
|
226
|
+
description: 'Whether to use a random User-Agent header automatically. Access via $userAgent variable in custom script',
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
displayName: 'Proxy',
|
|
230
|
+
name: 'proxy',
|
|
231
|
+
type: 'string',
|
|
232
|
+
displayOptions: {
|
|
233
|
+
show: {
|
|
234
|
+
library: ['custom'],
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
default: '',
|
|
238
|
+
placeholder: 'http://proxy.example.com:8080',
|
|
239
|
+
description: 'Proxy server URL (optional). Access via $proxy variable in custom script',
|
|
193
240
|
},
|
|
194
241
|
{
|
|
195
242
|
displayName: 'Return Full Response',
|
|
@@ -220,8 +267,11 @@ return response.data;
|
|
|
220
267
|
if (library === 'custom') {
|
|
221
268
|
// Custom script execution
|
|
222
269
|
const script = this.getNodeParameter('script', itemIndex);
|
|
223
|
-
const
|
|
224
|
-
|
|
270
|
+
const proxy = this.getNodeParameter('proxy', itemIndex, '');
|
|
271
|
+
const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
|
|
272
|
+
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);
|
|
225
275
|
}
|
|
226
276
|
else if (library === 'axios') {
|
|
227
277
|
// Axios execution
|
|
@@ -231,6 +281,7 @@ return response.data;
|
|
|
231
281
|
const queryParamsJson = this.getNodeParameter('queryParams', itemIndex, '{}');
|
|
232
282
|
const timeout = this.getNodeParameter('timeout', itemIndex, 30000);
|
|
233
283
|
const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
|
|
284
|
+
const proxy = this.getNodeParameter('proxy', itemIndex, '');
|
|
234
285
|
const headers = JSON.parse(headersJson);
|
|
235
286
|
const params = JSON.parse(queryParamsJson);
|
|
236
287
|
// Add random user-agent if enabled and not already set
|
|
@@ -244,6 +295,21 @@ return response.data;
|
|
|
244
295
|
params,
|
|
245
296
|
timeout,
|
|
246
297
|
};
|
|
298
|
+
// Add proxy if configured
|
|
299
|
+
if (proxy) {
|
|
300
|
+
const proxyUrl = new URL(proxy);
|
|
301
|
+
config.proxy = {
|
|
302
|
+
host: proxyUrl.hostname,
|
|
303
|
+
port: parseInt(proxyUrl.port) || (proxyUrl.protocol === 'https:' ? 443 : 80),
|
|
304
|
+
protocol: proxyUrl.protocol.replace(':', ''),
|
|
305
|
+
};
|
|
306
|
+
if (proxyUrl.username) {
|
|
307
|
+
config.proxy.auth = {
|
|
308
|
+
username: proxyUrl.username,
|
|
309
|
+
password: proxyUrl.password,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
}
|
|
247
313
|
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
248
314
|
const bodyJson = this.getNodeParameter('body', itemIndex, '{}');
|
|
249
315
|
config.data = JSON.parse(bodyJson);
|
|
@@ -269,8 +335,14 @@ return response.data;
|
|
|
269
335
|
const queryParamsJson = this.getNodeParameter('queryParams', itemIndex, '{}');
|
|
270
336
|
const timeout = this.getNodeParameter('timeout', itemIndex, 30000);
|
|
271
337
|
const randomUserAgent = this.getNodeParameter('randomUserAgent', itemIndex, true);
|
|
338
|
+
const proxy = this.getNodeParameter('proxy', itemIndex, '');
|
|
272
339
|
const headers = JSON.parse(headersJson);
|
|
273
340
|
const params = JSON.parse(queryParamsJson);
|
|
341
|
+
// Note: Native fetch API doesn't support proxy configuration directly
|
|
342
|
+
// Proxy setting is available but would require additional proxy agent libraries
|
|
343
|
+
if (proxy) {
|
|
344
|
+
console.warn('Proxy configuration is not supported with native fetch. Use axios or custom script instead.');
|
|
345
|
+
}
|
|
274
346
|
// Add random user-agent if enabled and not already set
|
|
275
347
|
if (randomUserAgent && !headers['User-Agent'] && !headers['user-agent']) {
|
|
276
348
|
headers['User-Agent'] = getRandomUserAgent();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-script-runner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/jsdom": "^27.0.0",
|
|
36
36
|
"@types/node": "^20.10.0",
|
|
37
|
+
"@types/user-agents": "^1.0.4",
|
|
37
38
|
"gulp": "^4.0.2",
|
|
38
39
|
"n8n-workflow": "^1.0.0",
|
|
39
40
|
"typescript": "^5.3.0"
|
|
@@ -41,9 +42,9 @@
|
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"axios": "^1.6.0",
|
|
43
44
|
"cheerio": "^1.0.0-rc.12",
|
|
44
|
-
"jsdom": "^23.0.0"
|
|
45
|
+
"jsdom": "^23.0.0",
|
|
46
|
+
"user-agents": "^1.1.669"
|
|
45
47
|
},
|
|
46
48
|
"author": "",
|
|
47
49
|
"license": "MIT"
|
|
48
|
-
|
|
49
50
|
}
|