mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add Urlscan.io node (#2266)
* ✨ Create urlscan.io node * ⚡ Change default visibility to private Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
212
packages/nodes-base/nodes/UrlScanIo/UrlScanIo.node.ts
Normal file
212
packages/nodes-base/nodes/UrlScanIo/UrlScanIo.node.ts
Normal file
@@ -0,0 +1,212 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeCredentialTestResult,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
scanFields,
|
||||
scanOperations,
|
||||
} from './descriptions';
|
||||
|
||||
import {
|
||||
handleListing,
|
||||
normalizeId,
|
||||
urlScanIoApiRequest,
|
||||
} from './GenericFunctions';
|
||||
|
||||
export class UrlScanIo implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'urlscan.io',
|
||||
name: 'urlScanIo',
|
||||
icon: 'file:urlScanIo.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume the urlscan.io API',
|
||||
defaults: {
|
||||
name: 'urlscan.io',
|
||||
color: '#f3d337',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'urlScanIoApi',
|
||||
required: true,
|
||||
testedBy: 'urlScanIoApiTest',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
noDataExpression: true,
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Scan',
|
||||
value: 'scan',
|
||||
},
|
||||
],
|
||||
default: 'scan',
|
||||
},
|
||||
...scanOperations,
|
||||
...scanFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
credentialTest: {
|
||||
async urlScanIoApiTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credentials: ICredentialsDecrypted,
|
||||
): Promise<NodeCredentialTestResult> {
|
||||
const { apiKey } = credentials.data as { apiKey: string };
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'API-KEY': apiKey,
|
||||
},
|
||||
method: 'GET',
|
||||
uri: 'https://urlscan.io/user/quotas',
|
||||
json: true,
|
||||
};
|
||||
|
||||
try {
|
||||
await this.helpers.request(options);
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Authentication successful',
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0) as 'scan';
|
||||
const operation = this.getNodeParameter('operation', 0) as 'perform' | 'get' | 'getAll';
|
||||
|
||||
let responseData;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
|
||||
try {
|
||||
|
||||
if (resource === 'scan') {
|
||||
|
||||
// **********************************************************************
|
||||
// scan
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'get') {
|
||||
|
||||
// ----------------------------------------
|
||||
// scan: get
|
||||
// ----------------------------------------
|
||||
|
||||
const scanId = this.getNodeParameter('scanId', i) as string;
|
||||
responseData = await urlScanIoApiRequest.call(this, 'GET', `/result/${scanId}`);
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------------
|
||||
// scan: getAll
|
||||
// ----------------------------------------
|
||||
|
||||
// https://urlscan.io/docs/search
|
||||
|
||||
const filters = this.getNodeParameter('filters', i) as { query?: string };
|
||||
|
||||
const qs: IDataObject = {};
|
||||
|
||||
if (filters?.query) {
|
||||
qs.q = filters.query;
|
||||
}
|
||||
|
||||
responseData = await handleListing.call(this, '/search', qs);
|
||||
responseData = responseData.map(normalizeId);
|
||||
|
||||
} else if (operation === 'perform') {
|
||||
|
||||
// ----------------------------------------
|
||||
// scan: perform
|
||||
// ----------------------------------------
|
||||
|
||||
// https://urlscan.io/docs/search
|
||||
|
||||
const {
|
||||
tags: rawTags,
|
||||
...rest
|
||||
} = this.getNodeParameter('additionalFields', i) as {
|
||||
customAgent?: string;
|
||||
visibility?: 'public' | 'private' | 'unlisted';
|
||||
tags?: string;
|
||||
referer?: string;
|
||||
overrideSafety: string;
|
||||
};
|
||||
|
||||
const body: IDataObject = {
|
||||
url: this.getNodeParameter('url', i) as string,
|
||||
...rest,
|
||||
};
|
||||
|
||||
if (rawTags) {
|
||||
const tags = rawTags.split(',').map(tag => tag.trim());
|
||||
|
||||
if (tags.length > 10) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter at most 10 tags',
|
||||
);
|
||||
}
|
||||
|
||||
body.tags = tags;
|
||||
}
|
||||
|
||||
responseData = await urlScanIoApiRequest.call(this, 'POST', '/scan', body);
|
||||
responseData = normalizeId(responseData);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Array.isArray(responseData)
|
||||
? returnData.push(...responseData)
|
||||
: returnData.push(responseData);
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user