n8n-nodes-binalyze-air
Version:
Binalyze AIR nodes for automating DFIR with n8n workflows
167 lines • 8.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.api = void 0;
const helpers_1 = require("../../utils/helpers");
exports.api = {
async getOrganizations(context, credentials, options) {
try {
const queryParams = {};
if (options === null || options === void 0 ? void 0 : options.pageNumber) {
queryParams.pageNumber = options.pageNumber;
}
if (options === null || options === void 0 ? void 0 : options.pageSize) {
queryParams.pageSize = options.pageSize;
}
if (options === null || options === void 0 ? void 0 : options.searchTerm) {
queryParams['filter[searchTerm]'] = options.searchTerm;
}
if (options === null || options === void 0 ? void 0 : options.nameFilter) {
queryParams['filter[name]'] = options.nameFilter;
}
if (options === null || options === void 0 ? void 0 : options.sortBy) {
queryParams.sortBy = options.sortBy;
}
if (options === null || options === void 0 ? void 0 : options.sortType) {
queryParams.sortType = options.sortType;
}
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'GET', '/api/public/organizations', Object.keys(queryParams).length > 0 ? queryParams : undefined);
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, 'fetch organizations');
}
catch (error) {
throw new Error(`Failed to fetch organizations: ${error instanceof Error ? error.message : String(error)}`);
}
},
async getAllOrganizations(context, credentials, nameFilter, pageSize = 100) {
try {
const allOrganizations = [];
let currentPage = 1;
let hasMorePages = true;
let iterationCount = 0;
const maxIterations = 50;
while (hasMorePages && iterationCount < maxIterations) {
iterationCount++;
const queryParams = {
pageNumber: currentPage,
pageSize,
};
if (nameFilter) {
queryParams['filter[name]'] = nameFilter;
}
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'GET', '/api/public/organizations', queryParams);
const responseData = await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `fetch organizations page ${currentPage}`);
const result = responseData.result;
const organizations = (result === null || result === void 0 ? void 0 : result.entities) || [];
allOrganizations.push(...organizations);
if (result && result.currentPage && result.totalPageCount) {
if (result.currentPage < result.totalPageCount) {
currentPage++;
if (organizations.length === 0) {
hasMorePages = false;
}
}
else {
hasMorePages = false;
}
}
else {
if (organizations.length === 0) {
hasMorePages = false;
}
else if (organizations.length < pageSize) {
hasMorePages = false;
}
else {
currentPage++;
if (currentPage > 100) {
hasMorePages = false;
}
}
}
}
if (iterationCount >= maxIterations) {
}
return allOrganizations;
}
catch (error) {
throw new Error(`Failed to fetch all organizations: ${error instanceof Error ? error.message : String(error)}`);
}
},
async createOrganization(context, credentials, data) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'POST', '/api/public/organizations');
requestOptions.body = data;
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, 'create organization');
}
catch (error) {
throw new Error(`Failed to create organization: ${error instanceof Error ? error.message : String(error)}`);
}
},
async updateOrganization(context, credentials, id, data) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'PATCH', `/api/public/organizations/${id}`);
requestOptions.body = data;
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `update organization ${id}`);
}
catch (error) {
throw new Error(`Failed to update organization: ${error instanceof Error ? error.message : String(error)}`);
}
},
async getOrganizationById(context, credentials, id) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'GET', `/api/public/organizations/${id}`);
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `fetch organization with ID ${id}`);
}
catch (error) {
throw new Error(`Failed to fetch organization with ID ${id}: ${error instanceof Error ? error.message : String(error)}`);
}
},
async checkOrganizationNameExists(context, credentials, name) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'GET', '/api/public/organizations/check', { name });
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, 'check organization name');
}
catch (error) {
throw new Error(`Failed to check organization name: ${error instanceof Error ? error.message : String(error)}`);
}
},
async updateOrganizationShareableDeployment(context, credentials, id, status) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'POST', `/api/public/organizations/${id}/shareable-deployment`);
requestOptions.body = { status };
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `update organization ${id} shareable deployment`);
}
catch (error) {
throw new Error(`Failed to update organization ${id} shareable deployment: ${error instanceof Error ? error.message : String(error)}`);
}
},
async deleteOrganization(context, credentials, id) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'DELETE', `/api/public/organizations/${id}`);
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `delete organization with ID ${id}`);
}
catch (error) {
throw new Error(`Failed to delete organization with ID ${id}: ${error instanceof Error ? error.message : String(error)}`);
}
},
async addTagsToOrganization(context, credentials, id, tags) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'PATCH', `/api/public/organizations/${id}/tags`);
requestOptions.body = { tags };
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `add tags to organization with ID ${id}`);
}
catch (error) {
throw new Error(`Failed to add tags to organization with ID ${id}: ${error instanceof Error ? error.message : String(error)}`);
}
},
async deleteTagsFromOrganization(context, credentials, id, tags) {
try {
const requestOptions = (0, helpers_1.buildRequestOptionsWithErrorHandling)(credentials, 'DELETE', `/api/public/organizations/${id}/tags`);
requestOptions.body = { tags };
return await (0, helpers_1.makeApiRequestWithErrorHandling)(context, requestOptions, `delete tags from organization with ID ${id}`);
}
catch (error) {
throw new Error(`Failed to delete tags from organization with ID ${id}: ${error instanceof Error ? error.message : String(error)}`);
}
}
};
//# sourceMappingURL=organizations.js.map