n8n-nodes-dominusnode 1.0.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.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/credentials/DominusNodeApi.credentials.d.ts +7 -0
- package/dist/credentials/DominusNodeApi.credentials.js +42 -0
- package/dist/credentials/DominusNodeApi.credentials.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/DominusNodeProxy/DominusNodeProxy.node.d.ts +24 -0
- package/dist/nodes/DominusNodeProxy/DominusNodeProxy.node.js +436 -0
- package/dist/nodes/DominusNodeProxy/DominusNodeProxy.node.js.map +1 -0
- package/dist/nodes/DominusNodeUsage/DominusNodeUsage.node.d.ts +13 -0
- package/dist/nodes/DominusNodeUsage/DominusNodeUsage.node.js +105 -0
- package/dist/nodes/DominusNodeUsage/DominusNodeUsage.node.js.map +1 -0
- package/dist/nodes/DominusNodeWallet/DominusNodeWallet.node.d.ts +33 -0
- package/dist/nodes/DominusNodeWallet/DominusNodeWallet.node.js +656 -0
- package/dist/nodes/DominusNodeWallet/DominusNodeWallet.node.js.map +1 -0
- package/dist/shared/auth.d.ts +74 -0
- package/dist/shared/auth.js +264 -0
- package/dist/shared/auth.js.map +1 -0
- package/dist/shared/constants.d.ts +9 -0
- package/dist/shared/constants.js +13 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/ssrf.d.ts +42 -0
- package/dist/shared/ssrf.js +252 -0
- package/dist/shared/ssrf.js.map +1 -0
- package/package.json +41 -0
- package/src/credentials/DominusNodeApi.credentials.ts +39 -0
- package/src/index.ts +4 -0
- package/src/nodes/DominusNodeProxy/DominusNodeProxy.node.ts +459 -0
- package/src/nodes/DominusNodeUsage/DominusNodeUsage.node.ts +130 -0
- package/src/nodes/DominusNodeWallet/DominusNodeWallet.node.ts +898 -0
- package/src/shared/auth.ts +272 -0
- package/src/shared/constants.ts +11 -0
- package/src/shared/ssrf.ts +257 -0
- package/tests/DominusNodeProxy.test.ts +281 -0
- package/tests/DominusNodeUsage.test.ts +250 -0
- package/tests/DominusNodeWallet.test.ts +591 -0
- package/tests/ssrf.test.ts +238 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DomiNode Proxy n8n community node.
|
|
3
|
+
*
|
|
4
|
+
* Operations:
|
|
5
|
+
* - Proxied Fetch: Make HTTP requests through DomiNode's rotating proxy network
|
|
6
|
+
* - Get Proxy Config: Retrieve proxy endpoint configuration
|
|
7
|
+
* - List Active Sessions: List currently active proxy sessions
|
|
8
|
+
*
|
|
9
|
+
* Security:
|
|
10
|
+
* - Full SSRF prevention (private IPs, hex/octal/decimal, IPv6 variants,
|
|
11
|
+
* Teredo, 6to4, CGNAT, multicast, .localhost/.local/.internal/.arpa)
|
|
12
|
+
* - DNS rebinding protection
|
|
13
|
+
* - OFAC sanctioned country blocking
|
|
14
|
+
* - Read-only HTTP methods only (GET, HEAD, OPTIONS)
|
|
15
|
+
* - Credential sanitization in error messages
|
|
16
|
+
* - Prototype pollution prevention
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as http from "node:http";
|
|
22
|
+
import * as tls from "node:tls";
|
|
23
|
+
import {
|
|
24
|
+
IDataObject,
|
|
25
|
+
IExecuteFunctions,
|
|
26
|
+
INodeExecutionData,
|
|
27
|
+
INodeType,
|
|
28
|
+
INodeTypeDescription,
|
|
29
|
+
NodeOperationError,
|
|
30
|
+
} from "n8n-workflow";
|
|
31
|
+
|
|
32
|
+
import { validateUrl } from "../../shared/ssrf";
|
|
33
|
+
import {
|
|
34
|
+
DominusNodeAuth,
|
|
35
|
+
sanitizeError,
|
|
36
|
+
checkDnsRebinding,
|
|
37
|
+
SANCTIONED_COUNTRIES,
|
|
38
|
+
} from "../../shared/auth";
|
|
39
|
+
import { ALLOWED_METHODS, MAX_BODY_TRUNCATE } from "../../shared/constants";
|
|
40
|
+
|
|
41
|
+
const BLOCKED_HEADERS = new Set([
|
|
42
|
+
"host",
|
|
43
|
+
"connection",
|
|
44
|
+
"content-length",
|
|
45
|
+
"transfer-encoding",
|
|
46
|
+
"proxy-authorization",
|
|
47
|
+
"authorization",
|
|
48
|
+
"user-agent",
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
export class DominusNodeProxy implements INodeType {
|
|
52
|
+
description: INodeTypeDescription = {
|
|
53
|
+
displayName: "DomiNode Proxy",
|
|
54
|
+
name: "dominusNodeProxy",
|
|
55
|
+
icon: "file:dominusnode.svg",
|
|
56
|
+
group: ["transform"],
|
|
57
|
+
version: 1,
|
|
58
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
59
|
+
description: "Make requests through DomiNode rotating proxy network",
|
|
60
|
+
defaults: { name: "DomiNode Proxy" },
|
|
61
|
+
inputs: ["main"],
|
|
62
|
+
outputs: ["main"],
|
|
63
|
+
credentials: [{ name: "dominusNodeApi", required: true }],
|
|
64
|
+
properties: [
|
|
65
|
+
{
|
|
66
|
+
displayName: "Operation",
|
|
67
|
+
name: "operation",
|
|
68
|
+
type: "options",
|
|
69
|
+
noDataExpression: true,
|
|
70
|
+
options: [
|
|
71
|
+
{
|
|
72
|
+
name: "Proxied Fetch",
|
|
73
|
+
value: "proxiedFetch",
|
|
74
|
+
description: "Make an HTTP request through the proxy network",
|
|
75
|
+
action: "Proxied fetch",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "Get Proxy Config",
|
|
79
|
+
value: "getProxyConfig",
|
|
80
|
+
description: "Get proxy endpoint configuration",
|
|
81
|
+
action: "Get proxy config",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "List Active Sessions",
|
|
85
|
+
value: "listActiveSessions",
|
|
86
|
+
description: "List currently active proxy sessions",
|
|
87
|
+
action: "List active sessions",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
default: "proxiedFetch",
|
|
91
|
+
},
|
|
92
|
+
// Proxied Fetch parameters
|
|
93
|
+
{
|
|
94
|
+
displayName: "URL",
|
|
95
|
+
name: "url",
|
|
96
|
+
type: "string",
|
|
97
|
+
default: "",
|
|
98
|
+
required: true,
|
|
99
|
+
description: "The URL to fetch through the proxy",
|
|
100
|
+
displayOptions: { show: { operation: ["proxiedFetch"] } },
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
displayName: "Method",
|
|
104
|
+
name: "method",
|
|
105
|
+
type: "options",
|
|
106
|
+
options: [
|
|
107
|
+
{ name: "GET", value: "GET" },
|
|
108
|
+
{ name: "HEAD", value: "HEAD" },
|
|
109
|
+
{ name: "OPTIONS", value: "OPTIONS" },
|
|
110
|
+
],
|
|
111
|
+
default: "GET",
|
|
112
|
+
description: "HTTP method (only read-only methods allowed)",
|
|
113
|
+
displayOptions: { show: { operation: ["proxiedFetch"] } },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
displayName: "Proxy Type",
|
|
117
|
+
name: "proxyType",
|
|
118
|
+
type: "options",
|
|
119
|
+
options: [
|
|
120
|
+
{ name: "Datacenter ($3/GB)", value: "dc" },
|
|
121
|
+
{ name: "Residential ($5/GB)", value: "residential" },
|
|
122
|
+
{ name: "Auto", value: "auto" },
|
|
123
|
+
],
|
|
124
|
+
default: "dc",
|
|
125
|
+
description: "Type of proxy IP to use",
|
|
126
|
+
displayOptions: { show: { operation: ["proxiedFetch"] } },
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: "Country",
|
|
130
|
+
name: "country",
|
|
131
|
+
type: "string",
|
|
132
|
+
default: "",
|
|
133
|
+
description: "Two-letter country code for geo-targeting (e.g., US, GB, DE). Leave empty for any.",
|
|
134
|
+
displayOptions: { show: { operation: ["proxiedFetch"] } },
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
displayName: "Custom Headers",
|
|
138
|
+
name: "headers",
|
|
139
|
+
type: "fixedCollection",
|
|
140
|
+
typeOptions: { multipleValues: true },
|
|
141
|
+
default: {},
|
|
142
|
+
description: "Custom HTTP headers to include in the request",
|
|
143
|
+
displayOptions: { show: { operation: ["proxiedFetch"] } },
|
|
144
|
+
options: [
|
|
145
|
+
{
|
|
146
|
+
name: "header",
|
|
147
|
+
displayName: "Header",
|
|
148
|
+
values: [
|
|
149
|
+
{
|
|
150
|
+
displayName: "Name",
|
|
151
|
+
name: "name",
|
|
152
|
+
type: "string",
|
|
153
|
+
default: "",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
displayName: "Value",
|
|
157
|
+
name: "value",
|
|
158
|
+
type: "string",
|
|
159
|
+
default: "",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
169
|
+
const items = this.getInputData();
|
|
170
|
+
const returnData: INodeExecutionData[] = [];
|
|
171
|
+
const credentials = await this.getCredentials("dominusNodeApi");
|
|
172
|
+
|
|
173
|
+
const apiKey = credentials.apiKey as string;
|
|
174
|
+
const baseUrl = (credentials.baseUrl as string) || "https://api.dominusnode.com";
|
|
175
|
+
const proxyHost = (credentials.proxyHost as string) || "proxy.dominusnode.com";
|
|
176
|
+
const proxyPort = Number(credentials.proxyPort) || 8080;
|
|
177
|
+
|
|
178
|
+
if (!apiKey) {
|
|
179
|
+
throw new NodeOperationError(this.getNode(), "API Key is required");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const auth = new DominusNodeAuth(apiKey, baseUrl);
|
|
183
|
+
const operation = this.getNodeParameter("operation", 0) as string;
|
|
184
|
+
|
|
185
|
+
for (let i = 0; i < items.length; i++) {
|
|
186
|
+
try {
|
|
187
|
+
if (operation === "proxiedFetch") {
|
|
188
|
+
const url = this.getNodeParameter("url", i) as string;
|
|
189
|
+
const method = this.getNodeParameter("method", i, "GET") as string;
|
|
190
|
+
const proxyType = this.getNodeParameter("proxyType", i, "dc") as string;
|
|
191
|
+
const country = this.getNodeParameter("country", i, "") as string;
|
|
192
|
+
const headersParam = this.getNodeParameter("headers", i, {}) as {
|
|
193
|
+
header?: Array<{ name: string; value: string }>;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Validate URL (SSRF prevention)
|
|
197
|
+
if (!url || typeof url !== "string") {
|
|
198
|
+
throw new NodeOperationError(this.getNode(), "URL is required", { itemIndex: i });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let parsedUrl: URL;
|
|
202
|
+
try {
|
|
203
|
+
parsedUrl = validateUrl(url);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
throw new NodeOperationError(
|
|
206
|
+
this.getNode(),
|
|
207
|
+
err instanceof Error ? err.message : "URL validation failed",
|
|
208
|
+
{ itemIndex: i },
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// DNS rebinding protection
|
|
213
|
+
try {
|
|
214
|
+
await checkDnsRebinding(parsedUrl.hostname);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
throw new NodeOperationError(
|
|
217
|
+
this.getNode(),
|
|
218
|
+
err instanceof Error ? err.message : "DNS validation failed",
|
|
219
|
+
{ itemIndex: i },
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Validate method
|
|
224
|
+
const upperMethod = method.toUpperCase();
|
|
225
|
+
if (!ALLOWED_METHODS.has(upperMethod)) {
|
|
226
|
+
throw new NodeOperationError(
|
|
227
|
+
this.getNode(),
|
|
228
|
+
`HTTP method '${upperMethod}' is not allowed. Only GET, HEAD, OPTIONS are permitted.`,
|
|
229
|
+
{ itemIndex: i },
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// OFAC sanctioned country check
|
|
234
|
+
if (country) {
|
|
235
|
+
const upper = country.toUpperCase();
|
|
236
|
+
if (SANCTIONED_COUNTRIES.has(upper)) {
|
|
237
|
+
throw new NodeOperationError(
|
|
238
|
+
this.getNode(),
|
|
239
|
+
`Country '${upper}' is blocked (OFAC sanctioned country)`,
|
|
240
|
+
{ itemIndex: i },
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Build proxy username for geo-targeting (uses hyphens, not underscores)
|
|
246
|
+
const userParts: string[] = [];
|
|
247
|
+
if (proxyType && proxyType !== "auto") userParts.push(proxyType);
|
|
248
|
+
if (country) userParts.push(`country-${country.toUpperCase()}`);
|
|
249
|
+
const username = userParts.length > 0 ? userParts.join("-") : "auto";
|
|
250
|
+
const proxyAuth = "Basic " + Buffer.from(`${username}:${apiKey}`).toString("base64");
|
|
251
|
+
|
|
252
|
+
// Build safe headers
|
|
253
|
+
const safeHeaders: Record<string, string> = {};
|
|
254
|
+
if (headersParam.header) {
|
|
255
|
+
for (const { name, value } of headersParam.header) {
|
|
256
|
+
if (!name) continue;
|
|
257
|
+
if (BLOCKED_HEADERS.has(name.toLowerCase())) continue;
|
|
258
|
+
// CRLF injection prevention
|
|
259
|
+
if (/[\r\n\0]/.test(name) || /[\r\n\0]/.test(value)) continue;
|
|
260
|
+
safeHeaders[name] = value;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Route through proxy gateway
|
|
265
|
+
const MAX_BODY_BYTES = 1_048_576; // 1MB response cap
|
|
266
|
+
const result = await new Promise<{
|
|
267
|
+
status: number;
|
|
268
|
+
headers: Record<string, string>;
|
|
269
|
+
body: string;
|
|
270
|
+
}>((resolve, reject) => {
|
|
271
|
+
const timeout = setTimeout(
|
|
272
|
+
() => reject(new Error("Proxy request timed out after 30000ms")),
|
|
273
|
+
30_000,
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
if (parsedUrl.protocol === "https:") {
|
|
277
|
+
// HTTPS: CONNECT tunnel + TLS
|
|
278
|
+
const connectHost = parsedUrl.hostname.includes(":") ? `[${parsedUrl.hostname}]` : parsedUrl.hostname;
|
|
279
|
+
const connectReq = http.request({
|
|
280
|
+
hostname: proxyHost,
|
|
281
|
+
port: proxyPort,
|
|
282
|
+
method: "CONNECT",
|
|
283
|
+
path: `${connectHost}:${parsedUrl.port || 443}`,
|
|
284
|
+
headers: {
|
|
285
|
+
"Proxy-Authorization": proxyAuth,
|
|
286
|
+
Host: `${connectHost}:${parsedUrl.port || 443}`,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
connectReq.on("connect", (_res, tunnelSocket) => {
|
|
291
|
+
if (_res.statusCode !== 200) {
|
|
292
|
+
clearTimeout(timeout);
|
|
293
|
+
tunnelSocket.destroy();
|
|
294
|
+
reject(new Error(`CONNECT failed: ${_res.statusCode}`));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const tlsSocket = tls.connect(
|
|
299
|
+
{
|
|
300
|
+
host: parsedUrl.hostname,
|
|
301
|
+
socket: tunnelSocket,
|
|
302
|
+
servername: parsedUrl.hostname,
|
|
303
|
+
minVersion: "TLSv1.2",
|
|
304
|
+
},
|
|
305
|
+
() => {
|
|
306
|
+
const reqPath = parsedUrl.pathname + parsedUrl.search;
|
|
307
|
+
let reqLine = `${upperMethod} ${reqPath} HTTP/1.1\r\nHost: ${parsedUrl.host}\r\nUser-Agent: n8n-nodes-dominusnode/1.0.0\r\nAccept: */*\r\nConnection: close\r\n`;
|
|
308
|
+
for (const [k, v] of Object.entries(safeHeaders)) {
|
|
309
|
+
if (!["host", "user-agent", "connection"].includes(k.toLowerCase())) {
|
|
310
|
+
reqLine += `${k}: ${v}\r\n`;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
reqLine += "\r\n";
|
|
314
|
+
tlsSocket.write(reqLine);
|
|
315
|
+
|
|
316
|
+
const chunks: Buffer[] = [];
|
|
317
|
+
let byteCount = 0;
|
|
318
|
+
tlsSocket.on("data", (chunk: Buffer) => {
|
|
319
|
+
byteCount += chunk.length;
|
|
320
|
+
if (byteCount <= MAX_BODY_BYTES + 16384) chunks.push(chunk);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
let finalized = false;
|
|
324
|
+
const finalize = () => {
|
|
325
|
+
if (finalized) return;
|
|
326
|
+
finalized = true;
|
|
327
|
+
clearTimeout(timeout);
|
|
328
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
329
|
+
const headerEnd = raw.indexOf("\r\n\r\n");
|
|
330
|
+
if (headerEnd === -1) {
|
|
331
|
+
reject(new Error("Malformed response"));
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const headerSection = raw.substring(0, headerEnd);
|
|
335
|
+
const body = raw.substring(headerEnd + 4).substring(0, MAX_BODY_BYTES);
|
|
336
|
+
const statusLine = headerSection.split("\r\n")[0];
|
|
337
|
+
const statusMatch = statusLine.match(/^HTTP\/\d\.\d\s+(\d+)/);
|
|
338
|
+
const status = statusMatch ? parseInt(statusMatch[1], 10) : 0;
|
|
339
|
+
const respHeaders: Record<string, string> = {};
|
|
340
|
+
for (const line of headerSection.split("\r\n").slice(1)) {
|
|
341
|
+
const ci = line.indexOf(":");
|
|
342
|
+
if (ci > 0) {
|
|
343
|
+
respHeaders[line.substring(0, ci).trim().toLowerCase()] =
|
|
344
|
+
line.substring(ci + 1).trim();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
resolve({ status, headers: respHeaders, body });
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
tlsSocket.on("end", finalize);
|
|
351
|
+
tlsSocket.on("close", finalize);
|
|
352
|
+
tlsSocket.on("error", (err) => {
|
|
353
|
+
clearTimeout(timeout);
|
|
354
|
+
reject(err);
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
tlsSocket.on("error", (err) => {
|
|
360
|
+
clearTimeout(timeout);
|
|
361
|
+
reject(err);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
connectReq.on("error", (err) => {
|
|
366
|
+
clearTimeout(timeout);
|
|
367
|
+
reject(err);
|
|
368
|
+
});
|
|
369
|
+
connectReq.end();
|
|
370
|
+
} else {
|
|
371
|
+
// HTTP: direct proxy request (full-URL path)
|
|
372
|
+
const req = http.request(
|
|
373
|
+
{
|
|
374
|
+
hostname: proxyHost,
|
|
375
|
+
port: proxyPort,
|
|
376
|
+
method: upperMethod,
|
|
377
|
+
path: url,
|
|
378
|
+
headers: {
|
|
379
|
+
...safeHeaders,
|
|
380
|
+
"Proxy-Authorization": proxyAuth,
|
|
381
|
+
Host: parsedUrl.host,
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
(res) => {
|
|
385
|
+
const chunks: Buffer[] = [];
|
|
386
|
+
let byteCount = 0;
|
|
387
|
+
res.on("data", (chunk: Buffer) => {
|
|
388
|
+
byteCount += chunk.length;
|
|
389
|
+
if (byteCount <= MAX_BODY_BYTES) chunks.push(chunk);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
let finalized = false;
|
|
393
|
+
const finalize = () => {
|
|
394
|
+
if (finalized) return;
|
|
395
|
+
finalized = true;
|
|
396
|
+
clearTimeout(timeout);
|
|
397
|
+
const body = Buffer.concat(chunks).toString("utf-8").substring(0, MAX_BODY_BYTES);
|
|
398
|
+
const respHeaders: Record<string, string> = {};
|
|
399
|
+
for (const [k, v] of Object.entries(res.headers)) {
|
|
400
|
+
if (v) respHeaders[k] = Array.isArray(v) ? v.join(", ") : v;
|
|
401
|
+
}
|
|
402
|
+
resolve({ status: res.statusCode ?? 0, headers: respHeaders, body });
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
res.on("end", finalize);
|
|
406
|
+
res.on("close", finalize);
|
|
407
|
+
res.on("error", (err) => {
|
|
408
|
+
clearTimeout(timeout);
|
|
409
|
+
reject(err);
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
req.on("error", (err) => {
|
|
415
|
+
clearTimeout(timeout);
|
|
416
|
+
reject(err);
|
|
417
|
+
});
|
|
418
|
+
req.end();
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
returnData.push({
|
|
423
|
+
json: {
|
|
424
|
+
status: result.status,
|
|
425
|
+
headers: result.headers,
|
|
426
|
+
body: result.body.substring(0, MAX_BODY_TRUNCATE),
|
|
427
|
+
url,
|
|
428
|
+
method: upperMethod,
|
|
429
|
+
proxyType,
|
|
430
|
+
country: country || undefined,
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
} else if (operation === "getProxyConfig") {
|
|
434
|
+
const result = await auth.apiRequest("GET", "/api/proxy/config");
|
|
435
|
+
returnData.push({ json: result as IDataObject });
|
|
436
|
+
} else if (operation === "listActiveSessions") {
|
|
437
|
+
const result = await auth.apiRequest("GET", "/api/sessions/active");
|
|
438
|
+
returnData.push({ json: result as IDataObject });
|
|
439
|
+
}
|
|
440
|
+
} catch (err) {
|
|
441
|
+
if (this.continueOnFail()) {
|
|
442
|
+
returnData.push({
|
|
443
|
+
json: {
|
|
444
|
+
error: sanitizeError(err instanceof Error ? err.message : String(err)),
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
throw new NodeOperationError(
|
|
450
|
+
this.getNode(),
|
|
451
|
+
sanitizeError(err instanceof Error ? err.message : String(err)),
|
|
452
|
+
{ itemIndex: i },
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return [returnData];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DomiNode Usage n8n community node.
|
|
3
|
+
*
|
|
4
|
+
* Operations:
|
|
5
|
+
* - Check Usage: Get proxy usage statistics for a given period
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
IDataObject,
|
|
12
|
+
IExecuteFunctions,
|
|
13
|
+
INodeExecutionData,
|
|
14
|
+
INodeType,
|
|
15
|
+
INodeTypeDescription,
|
|
16
|
+
NodeOperationError,
|
|
17
|
+
} from "n8n-workflow";
|
|
18
|
+
|
|
19
|
+
import { DominusNodeAuth, sanitizeError, periodToDateRange } from "../../shared/auth";
|
|
20
|
+
|
|
21
|
+
const VALID_PERIODS = new Set(["day", "week", "month"]);
|
|
22
|
+
|
|
23
|
+
export class DominusNodeUsage implements INodeType {
|
|
24
|
+
description: INodeTypeDescription = {
|
|
25
|
+
displayName: "DomiNode Usage",
|
|
26
|
+
name: "dominusNodeUsage",
|
|
27
|
+
icon: "file:dominusnode.svg",
|
|
28
|
+
group: ["transform"],
|
|
29
|
+
version: 1,
|
|
30
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
31
|
+
description: "Check DomiNode proxy usage statistics",
|
|
32
|
+
defaults: { name: "DomiNode Usage" },
|
|
33
|
+
inputs: ["main"],
|
|
34
|
+
outputs: ["main"],
|
|
35
|
+
credentials: [{ name: "dominusNodeApi", required: true }],
|
|
36
|
+
properties: [
|
|
37
|
+
{
|
|
38
|
+
displayName: "Operation",
|
|
39
|
+
name: "operation",
|
|
40
|
+
type: "options",
|
|
41
|
+
noDataExpression: true,
|
|
42
|
+
options: [
|
|
43
|
+
{
|
|
44
|
+
name: "Check Usage",
|
|
45
|
+
value: "checkUsage",
|
|
46
|
+
description: "Get proxy usage statistics for a given period",
|
|
47
|
+
action: "Check usage",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
default: "checkUsage",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
displayName: "Period",
|
|
54
|
+
name: "period",
|
|
55
|
+
type: "options",
|
|
56
|
+
options: [
|
|
57
|
+
{ name: "Day", value: "day" },
|
|
58
|
+
{ name: "Week", value: "week" },
|
|
59
|
+
{ name: "Month", value: "month" },
|
|
60
|
+
],
|
|
61
|
+
default: "month",
|
|
62
|
+
description: "Time period for usage statistics",
|
|
63
|
+
displayOptions: { show: { operation: ["checkUsage"] } },
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
69
|
+
const items = this.getInputData();
|
|
70
|
+
const returnData: INodeExecutionData[] = [];
|
|
71
|
+
const credentials = await this.getCredentials("dominusNodeApi");
|
|
72
|
+
|
|
73
|
+
const apiKey = credentials.apiKey as string;
|
|
74
|
+
const baseUrl = (credentials.baseUrl as string) || "https://api.dominusnode.com";
|
|
75
|
+
|
|
76
|
+
if (!apiKey) {
|
|
77
|
+
throw new NodeOperationError(this.getNode(), "API Key is required");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const auth = new DominusNodeAuth(apiKey, baseUrl);
|
|
81
|
+
|
|
82
|
+
for (let i = 0; i < items.length; i++) {
|
|
83
|
+
try {
|
|
84
|
+
const operation = this.getNodeParameter("operation", i) as string;
|
|
85
|
+
|
|
86
|
+
if (operation === "checkUsage") {
|
|
87
|
+
const period = this.getNodeParameter("period", i, "month") as string;
|
|
88
|
+
|
|
89
|
+
if (!VALID_PERIODS.has(period)) {
|
|
90
|
+
throw new NodeOperationError(
|
|
91
|
+
this.getNode(),
|
|
92
|
+
`Invalid period '${period}'. Must be one of: day, week, month`,
|
|
93
|
+
{ itemIndex: i },
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Backend expects since/until ISO dates, NOT a days integer
|
|
98
|
+
const { since, until } = periodToDateRange(period);
|
|
99
|
+
const params = new URLSearchParams({ since, until });
|
|
100
|
+
const result = await auth.apiRequest("GET", `/api/usage?${params.toString()}`);
|
|
101
|
+
|
|
102
|
+
returnData.push({ json: (result ?? {}) as IDataObject });
|
|
103
|
+
} else {
|
|
104
|
+
throw new NodeOperationError(
|
|
105
|
+
this.getNode(),
|
|
106
|
+
`Unknown operation: ${operation}`,
|
|
107
|
+
{ itemIndex: i },
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
if (this.continueOnFail()) {
|
|
112
|
+
returnData.push({
|
|
113
|
+
json: {
|
|
114
|
+
error: sanitizeError(err instanceof Error ? err.message : String(err)),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (err instanceof NodeOperationError) throw err;
|
|
120
|
+
throw new NodeOperationError(
|
|
121
|
+
this.getNode(),
|
|
122
|
+
sanitizeError(err instanceof Error ? err.message : String(err)),
|
|
123
|
+
{ itemIndex: i },
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return [returnData];
|
|
129
|
+
}
|
|
130
|
+
}
|