n8n-nodes-kaduu
Version:
n8n Kaduu API Nodes
342 lines • 14.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KaduuLeaks = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class KaduuLeaks {
constructor() {
this.description = {
displayName: 'Kaduu Leaks',
name: 'kaduuLeaks',
icon: 'file:kaduu.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Interact with Kaduu Leaks API',
defaults: {
name: 'Kaduu Leaks',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'kaduuApi',
required: true,
},
],
requestDefaults: {
baseURL: 'https://app.leak.center/svc-saas',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
timeout: 10000,
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Leak',
value: 'leak',
},
],
default: 'leak',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['leak'],
},
},
options: [
{
name: 'Browse',
value: 'browse',
description: 'Browse all available leaks',
action: 'Browse leaks',
},
{
name: 'Search',
value: 'search',
description: 'Search through leak content',
action: 'Search leaks',
},
{
name: 'Get',
value: 'get',
description: 'Get a specific leak by ID',
action: 'Get a leak',
},
],
default: 'browse',
},
{
displayName: 'Name Filter',
name: 'name',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['leak'],
operation: ['browse'],
},
},
description: 'Optional name filter for browsing leaks',
},
{
displayName: 'Search Query',
name: 'query',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['leak'],
operation: ['search'],
},
},
description: 'Search query (3-10000 characters)',
},
{
displayName: 'Leak ID',
name: 'leakId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['leak'],
operation: ['get'],
},
},
description: 'ID of the leak to retrieve',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['leak'],
operation: ['browse', 'search'],
},
},
options: [
{
displayName: 'Page',
name: 'page',
type: 'number',
typeOptions: {
minValue: 0,
},
default: 0,
description: 'Page number of results to return',
},
{
displayName: 'Size',
name: 'size',
type: 'number',
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 10,
description: 'Number of results per page',
},
{
displayName: 'Sort Direction',
name: 'sortDirection',
type: 'options',
options: [
{
name: 'Ascending',
value: 'ASC',
},
{
name: 'Descending',
value: 'DESC',
},
],
default: 'DESC',
},
{
displayName: 'Sort Field',
name: 'sortField',
type: 'options',
options: [
{
name: 'Created At',
value: 'createdAt',
},
{
name: 'Size',
value: 'size',
},
{
name: 'Name',
value: 'name',
},
],
default: 'createdAt',
},
],
},
{
displayName: 'Search Options',
name: 'searchOptions',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
resource: ['leak'],
operation: ['search'],
},
},
options: [
{
displayName: 'Highlight Results',
name: 'highlight',
type: 'boolean',
default: false,
description: 'Whether to highlight matching terms in results',
},
{
displayName: 'Fragment Length',
name: 'length',
type: 'number',
typeOptions: {
minValue: 0,
maxValue: 1000,
},
default: 1000,
description: 'Length of text fragments to return',
},
],
},
],
};
}
async execute() {
var _a, _b, _c, _d, _e, _f, _g;
const items = this.getInputData();
const returnData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
let responseData;
for (let i = 0; i < items.length; i++) {
try {
if (resource === 'leak') {
if (operation === 'browse') {
const name = this.getNodeParameter('name', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const qs = {
...additionalFields,
name,
};
try {
responseData = await this.helpers.requestWithAuthentication.call(this, 'kaduuApi', {
method: 'GET',
url: '/leak',
qs,
json: true,
});
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
else if (operation === 'search') {
const query = this.getNodeParameter('query', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const searchOptions = this.getNodeParameter('searchOptions', i);
if (query.length < 3 || query.length > 10000) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Search query must be between 3 and 10000 characters long', { itemIndex: i });
}
const qs = {
query,
page: (_a = additionalFields.page) !== null && _a !== void 0 ? _a : 0,
size: (_b = additionalFields.size) !== null && _b !== void 0 ? _b : 10,
sortDirection: (_c = additionalFields.sortDirection) !== null && _c !== void 0 ? _c : 'DESC',
sortField: (_d = additionalFields.sortField) !== null && _d !== void 0 ? _d : 'createdAt',
highlight: (_e = searchOptions.highlight) !== null && _e !== void 0 ? _e : false,
length: (_f = searchOptions.length) !== null && _f !== void 0 ? _f : 1000,
};
try {
responseData = await this.helpers.requestWithAuthentication.call(this, 'kaduuApi', {
method: 'GET',
url: '/leak/search',
qs,
json: true,
});
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
else if (operation === 'get') {
const leakId = this.getNodeParameter('leakId', i);
if (!leakId) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Leak ID is required', { itemIndex: i });
}
try {
responseData = await this.helpers.requestWithAuthentication.call(this, 'kaduuApi', {
method: 'GET',
url: `/leak/${leakId}`,
json: true,
});
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
}
if (Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.content)) {
returnData.push.apply(returnData, responseData.content.map((item) => ({
json: {
...item,
_metadata: {
totalElements: responseData === null || responseData === void 0 ? void 0 : responseData.totalElements,
totalPages: responseData === null || responseData === void 0 ? void 0 : responseData.totalPages,
currentPage: responseData === null || responseData === void 0 ? void 0 : responseData.number,
pageSize: responseData === null || responseData === void 0 ? void 0 : responseData.size,
},
},
})));
}
else if (responseData) {
returnData.push({ json: responseData });
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No valid response data received');
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
_error: (_g = error.description) !== null && _g !== void 0 ? _g : error.message,
_node: this.getNode().name,
_itemIndex: i,
},
});
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.KaduuLeaks = KaduuLeaks;
//# sourceMappingURL=KaduuLeaks.node.js.map