2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
2021-09-30 09:58:30 -07:00
|
|
|
|
2023-03-09 09:13:15 -08:00
|
|
|
import type { IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
2021-09-30 09:58:30 -07:00
|
|
|
|
|
|
|
export async function urlScanIoApiRequest(
|
|
|
|
this: IExecuteFunctions,
|
|
|
|
method: 'GET' | 'POST',
|
|
|
|
endpoint: string,
|
|
|
|
body: IDataObject = {},
|
|
|
|
qs: IDataObject = {},
|
|
|
|
) {
|
|
|
|
const options: OptionsWithUri = {
|
|
|
|
method,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
uri: `https://urlscan.io/api/v1${endpoint}`,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!Object.keys(body).length) {
|
|
|
|
delete options.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object.keys(qs).length) {
|
|
|
|
delete options.qs;
|
|
|
|
}
|
|
|
|
|
2022-11-22 08:57:17 -08:00
|
|
|
return this.helpers.requestWithAuthentication.call(this, 'urlScanIoApi', options);
|
2021-09-30 09:58:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function handleListing(
|
|
|
|
this: IExecuteFunctions,
|
|
|
|
endpoint: string,
|
|
|
|
qs: IDataObject = {},
|
|
|
|
): Promise<IDataObject[]> {
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
let responseData;
|
|
|
|
|
|
|
|
qs.size = 100;
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0, false);
|
2022-11-18 06:26:22 -08:00
|
|
|
const limit = this.getNodeParameter('limit', 0, 0);
|
2021-09-30 09:58:30 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
responseData = await urlScanIoApiRequest.call(this, 'GET', endpoint, {}, qs);
|
2023-02-27 19:39:43 -08:00
|
|
|
returnData.push(...(responseData.results as IDataObject[]));
|
2021-09-30 09:58:30 -07:00
|
|
|
|
|
|
|
if (!returnAll && returnData.length > limit) {
|
|
|
|
return returnData.slice(0, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseData.results.length) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const lastResult = responseData.results[responseData.results.length - 1];
|
2021-09-30 09:58:30 -07:00
|
|
|
qs.search_after = lastResult.sort;
|
|
|
|
}
|
|
|
|
} while (responseData.total > returnData.length);
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const normalizeId = ({ _id, uuid, ...rest }: IDataObject) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (_id) return { scanId: _id, ...rest };
|
|
|
|
if (uuid) return { scanId: uuid, ...rest };
|
2021-09-30 09:58:30 -07:00
|
|
|
return rest;
|
|
|
|
};
|