n8n-nodes-tenable-community
Version:
n8n node for the Tenable One platform
73 lines (72 loc) • 3.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TenableDownloadsClient = void 0;
/**
* @file Client for interacting with the Tenable Downloads API.
* Handles authentication and provides methods for all Downloads-related operations.
*/
const n8n_workflow_1 = require("n8n-workflow");
/**
* @class TenableDownloadsClient
* @description Implements the client for the Tenable Downloads API, which provides access
* to product installers and other downloadable content.
*/
class TenableDownloadsClient {
/**
* Creates an instance of the TenableDownloadsClient.
* @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 Downloads 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://www.tenable.com/downloads/api/v2/${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 all available product pages from the Tenable Downloads portal.
* @returns {Promise<unknown>} A promise that resolves to the list of product pages.
*/
async listProductPages() {
return this.sendRequest({ method: 'GET', url: 'pages' });
}
/**
* Retrieves a list of downloadable files for a specific product.
* @param {object} params The parameters for the request.
* @param {string} params.slug The unique identifier (slug) of the product page.
* @returns {Promise<unknown>} A promise that resolves to the list of downloadable files for the product.
*/
async listDownloadableFiles(params) {
return this.sendRequest({ method: 'GET', url: `pages/${params.slug}` });
}
/**
* Downloads a specific file from a product page.
* @param {object} params The parameters for the request.
* @param {string} params.slug The slug of the product page.
* @param {string} params.file The name of the file to download.
* @returns {Promise<unknown>} A promise that resolves to the file content/stream.
*/
async downloadFile(params) {
return this.sendRequest({ method: 'GET', url: `pages/${params.slug}/files/${params.file}` });
}
}
exports.TenableDownloadsClient = TenableDownloadsClient;