web/src/utils/fetch-security-info.ts

50 lines · 1088 bytes

5 symbols in this file
 1import { fetchEnrich } from './fetch-enrich';
 2
 3const normalizeRepo = (github: string): string =>
 4  github.replace(/^https?:\/\/github\.com\//, '').replace(/\/+$/, '');
 5
 6export const fetchSecurityReport = (
 7  github: string,
 8): Promise<SecurityReportResponse | null> => {
 9  const repo = normalizeRepo(github);
10  return fetchEnrich<SecurityReportResponse>(
11    'Security Report',
12    `/v1/enrich/security/${repo}`,
13    repo,
14  );
15};
16
17export interface SecurityCheck {
18  name: string;
19  score: number;
20  reason: string;
21  url: string;
22}
23
24export interface SecurityAdvisory {
25  ghsaId: string;
26  cveId: string | null;
27  summary: string;
28  severity: string;
29  cvssScore: number | null;
30  publishedAt: string;
31  url: string;
32  firstPatchedVersion: string | null;
33  vulnerableRange: string;
34  isPatched: boolean;
35}
36
37export interface SecurityReportResponse {
38  repo: string;
39  scorecard: {
40    available: boolean;
41    overallScore: number | null;
42    generatedAt: string;
43    checks: SecurityCheck[];
44  };
45  advisories: {
46    count: number;
47    items: SecurityAdvisory[];
48  };
49  fuzzed: boolean;
50}