vulncheck-sdk
Version:
A comprehensive TypeScript/JavaScript SDK for the VulnCheck API - vulnerability intelligence platform with enriched CVE data, threat intelligence, and security tooling
84 lines • 3.36 kB
JavaScript
import { HttpClient } from './http.js';
import { validateConfig, buildQueryString, isValidCVE, isValidCPE, isValidPURL } from '../utils/index.js';
import { VulnCheckValidationError } from '../errors/index.js';
export class VulnCheckClient {
constructor(config) {
validateConfig(config);
this.http = new HttpClient(config);
}
async getCVE(cveId, indexName = 'vulncheck-nvd2') {
if (!isValidCVE(cveId)) {
throw new VulnCheckValidationError(`Invalid CVE ID format: ${cveId}`);
}
const response = await this.http.get(`/v3/index/${indexName}?cve=${cveId}`);
return response.data.length > 0 ? response.data[0] : null;
}
async getCVEsFromIndex(indexName, options = {}) {
const queryString = buildQueryString(options);
return this.http.get(`/v3/index/${indexName}${queryString}`);
}
async getCVEsByCPE(cpe, options = {}) {
if (!isValidCPE(cpe)) {
throw new VulnCheckValidationError(`Invalid CPE format: ${cpe}`);
}
const queryString = buildQueryString({ cpe, ...options });
return this.http.get(`/v3/cpe${queryString}`);
}
async getCVEsByPURL(purl, options = {}) {
if (!isValidPURL(purl)) {
throw new VulnCheckValidationError(`Invalid PURL format: ${purl}`);
}
const queryString = buildQueryString({ purl, ...options });
return this.http.get(`/v3/purl${queryString}`);
}
async searchCPEs(criteria, options = {}) {
if (Object.keys(criteria).length === 0) {
throw new VulnCheckValidationError('At least one search criteria must be provided');
}
const queryString = buildQueryString({ ...criteria, ...options });
return this.http.get(`/v3/search/cpe${queryString}`);
}
async getIndexes() {
return this.http.get('/v3/index');
}
async queryIndex(indexName, options = {}) {
if (!indexName) {
throw new VulnCheckValidationError('Index name is required');
}
const queryString = buildQueryString(options);
return this.http.get(`/v3/index/${indexName}${queryString}`);
}
async getBackups() {
return this.http.get('/v3/backup');
}
async downloadBackup(indexName) {
if (!indexName) {
throw new VulnCheckValidationError('Index name is required');
}
return this.http.get(`/v3/backup/${indexName}`);
}
async getInitialAccessRules(rules) {
if (!rules) {
throw new VulnCheckValidationError('Rules parameter is required');
}
return this.http.get(`/v3/rules/initial-access/${rules}`);
}
async getIPsByTags(filter, options = {}) {
if (!filter) {
throw new VulnCheckValidationError('Filter is required');
}
const queryString = buildQueryString(options);
return this.http.get(`/v3/tags/${filter}${queryString}`);
}
async getDNSByTags(filter, options = {}) {
if (!filter) {
throw new VulnCheckValidationError('Filter is required');
}
const queryString = buildQueryString(options);
return this.http.get(`/v3/pdns/${filter}${queryString}`);
}
async getOpenAPISpec() {
return this.http.get('/v3/openapi');
}
}
//# sourceMappingURL=index.js.map