n8n-nodes-tenable-community
Version:
n8n node for the Tenable One platform
73 lines (72 loc) • 3.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TenableMSSPClient = void 0;
/**
* @file Client for interacting with the Tenable MSSP API.
* Handles authentication and provides methods for all MSSP-related operations.
*/
const n8n_workflow_1 = require("n8n-workflow");
/**
* @class TenableMSSPClient
* @description Implements the client for the Tenable MSSP (Managed Security Service Provider) API.
*/
class TenableMSSPClient {
/**
* Creates an instance of the TenableMSSPClient.
* @param {ITriggerFunctions | IExecuteFunctions} context The n8n context object for credentials and helpers.
*/
constructor(context) {
this.context = context;
}
/**
* A private helper method to send authenticated requests to the Tenable API.
* @private
* @param {IHttpRequestOptions} options - The request options.
* @returns {Promise<unknown>} A promise that resolves to the API response.
* @throws {NodeApiError} Wraps API errors in a standard n8n error.
*/
async sendRequest(options) {
var _a, _b, _c;
const credentials = await this.context.getCredentials('tenableOneApi');
const requestOptions = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { 'X-ApiKeys': `accessKey=${credentials.accessKey};secretKey=${credentials.secretKey}` }), json: true, url: `https://cloud.tenable.com/${options.url}`, timeout: 60000 });
try {
return await this.context.helpers.httpRequest(requestOptions);
}
catch (error) {
if (error instanceof n8n_workflow_1.NodeApiError) {
const errorDetails = error.cause ? (_a = error.cause.response) === null || _a === void 0 ? void 0 : _a.body : { message: error.message };
const errorMessage = ((_c = (_b = errorDetails === null || errorDetails === void 0 ? void 0 : errorDetails.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) || (errorDetails === null || errorDetails === void 0 ? void 0 : errorDetails.message) || 'No additional error details provided.';
throw new n8n_workflow_1.NodeApiError(this.context.getNode(), { message: `Tenable API Error: ${errorMessage}` });
}
throw new n8n_workflow_1.NodeApiError(this.context.getNode(), { message: error.message });
}
}
/**
* Retrieves a list of MSSP accounts.
* @param {object} [options] Optional parameters.
* @param {IDataObject} [options.qs] Optional query parameters for filtering and pagination.
* @returns {Promise<unknown>} A promise that resolves to the list of accounts.
*/
async listAccounts(options = {}) {
return this.sendRequest({ method: 'GET', url: 'mssp/accounts', qs: options.qs });
}
/**
* Retrieves the details of a specific MSSP account.
* @param {object} params The parameters for the request.
* @param {string} params.accountId The ID of the account.
* @returns {Promise<unknown>} A promise that resolves to the account details.
*/
async getAccountDetails(params) {
return this.sendRequest({ method: 'GET', url: `mssp/accounts/${params.accountId}` });
}
/**
* Creates a new evaluation account under the MSSP portal.
* @param {object} options The options for the request.
* @param {IDataObject} options.body The definition of the evaluation account.
* @returns {Promise<unknown>} A promise that resolves to the newly created account details.
*/
async createEvaluationAccount(options) {
return this.sendRequest({ method: 'POST', url: 'mssp/accounts/v2/eval', body: options.body });
}
}
exports.TenableMSSPClient = TenableMSSPClient;