-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathadvisories-bulk.ts
More file actions
51 lines (41 loc) · 1.38 KB
/
advisories-bulk.ts
File metadata and controls
51 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Import Third-party Dependencies
import * as httpie from "@openally/httpie";
// Import Internal Dependencies
import { getHttpAgent } from "../http.ts";
import { getLocalRegistryURL } from "../registry.ts";
import type { DefaultRegistryApiOptions } from "./common/types.ts";
/**
* Record of package names to their versions to query advisories for.
* Key: package name (e.g., "lodash")
* Value: array of versions (e.g., ["4.17.21", "4.17.20"])
*/
export type PackageVersions = Record<string, string[]>;
export type AdvisoriesBulkApiOptions = DefaultRegistryApiOptions & { registry?: string; };
export interface Cvss {
score: number;
vectorString: string | null;
}
export interface Advisory {
id: number;
url: string;
title: string;
severity: string;
vulnerable_versions: string;
cwe: string[];
cvss: Cvss;
}
/**
* Record of package names to their Advisory.
* Key: package name (e.g., "lodash")
* Value: Advisory
*/
export type Advisories = Record<string, Advisory[]>;
export async function advisoriesBulk(packageVersions: PackageVersions, options?: AdvisoriesBulkApiOptions): Promise<Advisories> {
const query = new URL("/-/npm/v1/security/advisories/bulk", options?.registry ?? getLocalRegistryURL());
const { data } = await httpie.post<string>(query, {
authorization: options?.token,
body: packageVersions,
agent: getHttpAgent()
});
return JSON.parse(data);
}