n8n-nodes-binalyze-air
Version:
Binalyze AIR nodes for automating DFIR with n8n workflows
153 lines • 5.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AirTrigger = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const helpers_1 = require("./utils/helpers");
class AirTrigger {
constructor() {
this.description = {
displayName: 'AIR Trigger',
name: 'airTrigger',
icon: {
light: 'file:b-logo-dark.svg',
dark: 'file:b-logo-light.svg',
},
group: ['trigger'],
version: 1,
description: 'Trigger workflows based on AIR events',
defaults: {
name: 'AIR Trigger',
},
inputs: [],
outputs: ["main"],
credentials: [
{
name: 'airApi',
required: true,
},
],
webhooks: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
},
],
properties: [
{
displayName: 'Event Names or IDs',
name: 'eventTypes',
type: 'multiOptions',
required: true,
typeOptions: {
loadOptionsMethod: 'getEventTypes',
},
default: [],
description: 'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
},
{
displayName: 'Bearer Token',
name: 'bearerToken',
type: 'string',
required: true,
typeOptions: {
password: true,
},
default: '',
description: 'The Bearer token that AIR will send in the Authorization header for webhook authentication',
},
],
};
this.methods = {
loadOptions: {
async getEventTypes() {
try {
const credentials = await (0, helpers_1.getAirCredentials)(this);
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'GET', '/api/public/event-subscription/event-names');
const response = await (0, helpers_1.makeApiRequestWithErrorHandling)(this, requestOptions, 'fetch event types');
if (!response.success || !Array.isArray(response.result)) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to fetch event types from AIR');
}
return response.result.map((eventName) => ({
name: eventName,
value: eventName,
description: eventName,
}));
}
catch (error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to load event types: ${error instanceof Error ? error.message : String(error)}`);
}
},
},
};
}
async webhook() {
const req = this.getRequestObject();
const resp = this.getResponseObject();
const selectedEventTypes = this.getNodeParameter('eventTypes', []);
const bearerToken = this.getNodeParameter('bearerToken', '');
const authHeader = req.headers.authorization;
if (!authHeader) {
resp.status(401).json({
success: false,
error: 'Missing authorization header'
});
return {
noWebhookResponse: true,
};
}
const providedToken = authHeader.replace('Bearer ', '');
if (providedToken !== bearerToken) {
resp.status(401).json({
success: false,
error: 'Invalid Bearer token'
});
return {
noWebhookResponse: true,
};
}
const body = this.getBodyData();
if (!body.eventName || typeof body.eventName !== 'string') {
resp.status(400).json({
success: false,
error: 'Invalid event structure: missing eventName'
});
return {
noWebhookResponse: true,
};
}
const workflowId = this.getWorkflow().id;
const workflowName = this.getWorkflow().name;
const eventName = body.eventName;
if (selectedEventTypes.length > 0 && !selectedEventTypes.includes(eventName)) {
resp.status(200).json({
success: true,
message: 'Event ignored - not in selected event types',
workflowId: workflowId,
workflowName: workflowName
});
return {
noWebhookResponse: true,
};
}
resp.status(200).json({
success: true,
message: 'Event received and processed',
workflowId: workflowId,
workflowName: workflowName
});
return {
workflowData: [
[
{
json: body,
headers: req.headers,
},
],
],
};
}
}
exports.AirTrigger = AirTrigger;
//# sourceMappingURL=AirTrigger.node.js.map