/
types.ts
246 lines (213 loc) · 5 KB
/
types.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import { DepGraphData } from '@snyk/dep-graph';
import { CustomError } from './lib/errors/custom-error';
/* Scan Result
* this data is returned by the CLI plugins to identify
* what should be scanned for issues
*/
export interface GitTarget {
remoteUrl: string;
branch: string;
}
export interface ContainerTarget {
image: string;
}
export interface ScanResult {
readonly identity: Identity;
readonly facts: Facts[];
readonly name?: string;
readonly policy?: string;
readonly target?: GitTarget | ContainerTarget;
}
export interface Identity {
type: string;
targetFile?: string;
// options used to scan should be here
args?: { [key: string]: string };
}
export interface Facts {
type: string;
data: any;
}
/* Test Result
* this data is returned on a `snyk test` for supported project types
* after the relevant plugin extracts dependencies
*/
export interface TestResult {
readonly issues: Issue[];
readonly issuesData: IssuesData;
readonly depGraphData: DepGraphData;
readonly remediation?: RemediationChanges; // TODO: not yet in the CLI TestResults type
}
export interface Issue {
pkgName: string;
pkgVersion?: string;
issueId: string;
fixInfo: FixInfo;
}
interface UpgradePath {
path: UpgradePathItem[];
}
export interface FixInfo {
upgradePaths?: UpgradePath[];
isPatchable?: boolean;
nearestFixedInVersion?: string;
}
interface UpgradePathItem {
name: string;
version: string;
newVersion?: string;
isDropped?: boolean;
}
export interface IssuesData {
[issueId: string]: {
id: string;
severity: SEVERITY;
title: string;
};
}
/* Remediation Data
* this data is returned on a `snyk test` for supported project types
*/
export interface Upgrade {
upgradeTo: string; // name@version
}
export interface UpgradeVulns extends Upgrade {
vulns: string[];
}
export interface UpgradeRemediation extends UpgradeVulns {
upgrades: string[];
}
export interface PatchRemediation {
paths: PatchObject[];
}
export interface DependencyUpdates {
[from: string]: UpgradeRemediation;
}
export interface PinRemediation extends UpgradeVulns {
isTransitive: boolean;
}
export interface DependencyPins {
[name: string]: PinRemediation;
}
// Remediation changes to be applied to the project,
// including information on all and unresolved issues.
export interface RemediationChanges {
unresolved: IssueData[];
upgrade: DependencyUpdates;
patch: {
[name: string]: PatchRemediation;
};
ignore: unknown;
pin: DependencyPins;
}
export interface IssueData {
id: string;
packageName: string;
version: string;
moduleName?: string;
below: string; // Vulnerable below version
semver: {
vulnerable: string | string[];
vulnerableHashes?: string[];
vulnerableByDistro?: {
[distroNameAndVersion: string]: string[];
};
};
patches: Patch[];
isNew: boolean;
description: string;
title: string;
severity: SEVERITY;
fixedIn: string[];
legalInstructions?: string;
reachability?: REACHABILITY;
}
interface Patch {
version: string;
id: string;
urls: string[];
modificationTime: string;
}
export enum REACHABILITY {
FUNCTION = 'function',
PACKAGE = 'package',
NOT_REACHABLE = 'not-reachable',
NO_INFO = 'no-info',
}
export interface PatchObject {
[name: string]: {
patched: string;
};
}
export enum SEVERITY {
LOW = 'low',
MEDIUM = 'medium',
HIGH = 'high',
CRITICAL = 'critical',
}
/* End Remediation Data
*/
/* Snyk fix types
* Types for concepts introduced as part of this lib
*/
export type SupportedScanTypes = 'pip';
export interface Workspace {
path: string;
readFile: (path: string) => Promise<string>;
writeFile: (path: string, content: string) => Promise<void>;
}
export interface EntityToFix {
readonly workspace: Workspace;
readonly scanResult: ScanResult;
readonly testResult: TestResult;
readonly options: CliTestOptions;
}
// Partial CLI test options interface
// defining only what is used by @snyk/fix
// add more as needed
export interface PythonTestOptions {
command?: string; // python interpreter to use for python tests
}
export type CliTestOptions = PythonTestOptions;
export interface WithError<Original> {
original: Original;
error: CustomError;
tip?: string;
}
export interface WithFixChangesApplied<Original> {
original: Original;
changes: FixChangesSummary[];
}
export interface WithUserMessage<Original> {
original: Original;
userMessage: string;
}
export type FixChangesSummary = FixChangesSuccess | FixChangesError;
interface FixChangesSuccess {
success: true;
userMessage: string;
issueIds: string[];
from?: string;
to?: string;
}
interface FixChangesError {
success: false;
userMessage: string;
reason: string;
tip?: string;
issueIds: string[];
from?: string;
to?: string;
}
export interface ErrorsByEcoSystem {
[ecosystem: string]: { originals: EntityToFix[]; userMessage: string };
}
export interface FixOptions {
dryRun?: boolean;
quiet?: boolean;
stripAnsi?: boolean;
}
export interface FixedMeta {
fixed: number;
failed: number;
}