UNPKG

@nodesecure/vulnera

Version:

NodeSecure vulnerabilities strategies

49 lines 1.47 kB
// Import Third-party Dependencies import * as httpie from "@openally/httpie"; import * as utils from "../utils.js"; export class OSV { static ROOT_API = "https://api.osv.dev"; #credential; constructor(options = {}) { this.#credential = options.credential; } async query(query) { if (!query.package.ecosystem) { query.package.ecosystem = "npm"; } const { data } = await httpie.post(new URL("v1/query", OSV.ROOT_API), { headers: this.#credential?.headers, body: query }); return data.vulns; } queryBySpec(spec) { const { name, version } = utils.parseNpmSpec(spec); return this.query({ version, package: { name, ecosystem: "npm" } }); } async queryBatch(queries) { for (const query of queries) { if (!query.package.ecosystem) { query.package.ecosystem = "npm"; } } const { data } = await httpie.post(new URL("v1/querybatch", OSV.ROOT_API), { headers: this.#credential?.headers, body: { queries } }); return data.results; } async findVulnById(id) { const { data } = await httpie.get(new URL(`v1/vulns/${id}`, OSV.ROOT_API), { headers: this.#credential?.headers }); return data; } } //# sourceMappingURL=osv.js.map