UNPKG

15 kBJavaScriptView Raw
1"use strict";
2/*
3 * ---------------------------------------------------------
4 * Copyright(C) Microsoft Corporation. All rights reserved.
5 * ---------------------------------------------------------
6 *
7 * ---------------------------------------------------------
8 * Generated file, DO NOT EDIT
9 * ---------------------------------------------------------
10 */
11var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13 return new (P || (P = Promise))(function (resolve, reject) {
14 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17 step((generator = generator.apply(thisArg, _arguments || [])).next());
18 });
19};
20Object.defineProperty(exports, "__esModule", { value: true });
21exports.AlertApi = void 0;
22const basem = require("./ClientApiBases");
23const AlertInterfaces = require("./interfaces/AlertInterfaces");
24class AlertApi extends basem.ClientApiBase {
25 constructor(baseUrl, handlers, options) {
26 super(baseUrl, handlers, 'node-Alert-api', options);
27 }
28 /**
29 * Get an alert.
30 *
31 * @param {string} project - Project ID or project name
32 * @param {number} alertId - ID of alert to retrieve
33 * @param {string} repository - Name or id of a repository that alert is part of
34 * @param {string} ref
35 * @param {AlertInterfaces.ExpandOption} expand - Expand alert attributes. Possible options are {ValidationFingerprint, None}
36 */
37 getAlert(project, alertId, repository, ref, expand) {
38 return __awaiter(this, void 0, void 0, function* () {
39 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
40 let routeValues = {
41 project: project,
42 alertId: alertId,
43 repository: repository
44 };
45 let queryValues = {
46 ref: ref,
47 expand: expand,
48 };
49 try {
50 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "e21b4630-b7d2-4031-99e3-3ad328cc4a7f", routeValues, queryValues);
51 let url = verData.requestUrl;
52 let options = this.createRequestOptions('application/json', verData.apiVersion);
53 let res;
54 res = yield this.rest.get(url, options);
55 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.Alert, false);
56 resolve(ret);
57 }
58 catch (err) {
59 reject(err);
60 }
61 }));
62 });
63 }
64 /**
65 * Get alerts for a repository
66 *
67 * @param {string} project - Project ID or project name
68 * @param {string} repository - The name or ID of the repository
69 * @param {number} top - The maximum number of alerts to return
70 * @param {string} orderBy - Must be "id" "firstSeen" "lastSeen" "fixedOn" or "severity" Defaults to "id"
71 * @param {AlertInterfaces.SearchCriteria} criteria - Options to limit the alerts returned
72 * @param {string} continuationToken - If there are more alerts than can be returned, a continuation token is placed in the "x-ms-continuationtoken" header. Use that token here to get the next page of alerts
73 */
74 getAlerts(project, repository, top, orderBy, criteria, continuationToken) {
75 return __awaiter(this, void 0, void 0, function* () {
76 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
77 let routeValues = {
78 project: project,
79 repository: repository
80 };
81 let queryValues = {
82 top: top,
83 orderBy: orderBy,
84 criteria: criteria,
85 continuationToken: continuationToken,
86 };
87 try {
88 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "e21b4630-b7d2-4031-99e3-3ad328cc4a7f", routeValues, queryValues);
89 let url = verData.requestUrl;
90 let options = this.createRequestOptions('application/json', verData.apiVersion);
91 let res;
92 res = yield this.rest.get(url, options);
93 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.Alert, true);
94 resolve(ret);
95 }
96 catch (err) {
97 reject(err);
98 }
99 }));
100 });
101 }
102 /**
103 * Get an alert.
104 *
105 * @param {string} project - Project ID or project name
106 * @param {number} alertId - ID of alert to retrieve
107 * @param {string} repository - Name or id of a repository that alert is part of
108 * @param {string} ref
109 * @param {AlertInterfaces.ExpandOption} expand - Expand alert attributes. Possible options are {ValidationFingerprint, None}
110 */
111 getAlertSarif(project, alertId, repository, ref, expand) {
112 return __awaiter(this, void 0, void 0, function* () {
113 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
114 let routeValues = {
115 project: project,
116 alertId: alertId,
117 repository: repository
118 };
119 let queryValues = {
120 ref: ref,
121 expand: expand,
122 };
123 try {
124 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "e21b4630-b7d2-4031-99e3-3ad328cc4a7f", routeValues, queryValues);
125 let url = verData.requestUrl;
126 let options = this.createRequestOptions('application/json', verData.apiVersion);
127 let res;
128 res = yield this.rest.get(url, options);
129 let ret = this.formatResponse(res.result, null, false);
130 resolve(ret);
131 }
132 catch (err) {
133 reject(err);
134 }
135 }));
136 });
137 }
138 /**
139 * Update the status of an alert
140 *
141 * @param {AlertInterfaces.AlertStateUpdate} stateUpdate - The new status of the alert
142 * @param {string} project - Project ID or project name
143 * @param {number} alertId - The ID of the alert
144 * @param {string} repository - The name or ID of the repository
145 */
146 updateAlert(stateUpdate, project, alertId, repository) {
147 return __awaiter(this, void 0, void 0, function* () {
148 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
149 let routeValues = {
150 project: project,
151 alertId: alertId,
152 repository: repository
153 };
154 try {
155 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "e21b4630-b7d2-4031-99e3-3ad328cc4a7f", routeValues);
156 let url = verData.requestUrl;
157 let options = this.createRequestOptions('application/json', verData.apiVersion);
158 let res;
159 res = yield this.rest.update(url, stateUpdate, options);
160 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.Alert, false);
161 resolve(ret);
162 }
163 catch (err) {
164 reject(err);
165 }
166 }));
167 });
168 }
169 /**
170 * Get instances of an alert.
171 *
172 * @param {string} project - Project ID or project name
173 * @param {number} alertId - ID of alert to retrieve
174 * @param {string} repository - Name or id of a repository that alert is part of
175 * @param {string} ref
176 */
177 getAlertInstances(project, alertId, repository, ref) {
178 return __awaiter(this, void 0, void 0, function* () {
179 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
180 let routeValues = {
181 project: project,
182 alertId: alertId,
183 repository: repository
184 };
185 let queryValues = {
186 ref: ref,
187 };
188 try {
189 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "f451ba96-0e95-458a-8dd5-3df894770a49", routeValues, queryValues);
190 let url = verData.requestUrl;
191 let options = this.createRequestOptions('application/json', verData.apiVersion);
192 let res;
193 res = yield this.rest.get(url, options);
194 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.AlertAnalysisInstance, true);
195 resolve(ret);
196 }
197 catch (err) {
198 reject(err);
199 }
200 }));
201 });
202 }
203 /**
204 * Update alert metadata associations.
205 *
206 * @param {AlertInterfaces.AlertMetadata[]} alertsMetadata - A list of metadata to associate with alerts.
207 * @param {string} project - Project ID or project name
208 * @param {string} repository - The name or ID of the repository.
209 */
210 updateAlertsMetadata(alertsMetadata, project, repository) {
211 return __awaiter(this, void 0, void 0, function* () {
212 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
213 let routeValues = {
214 project: project,
215 repository: repository
216 };
217 try {
218 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "65de4b84-7519-4ae8-8623-175f79b49b80", routeValues);
219 let url = verData.requestUrl;
220 let options = this.createRequestOptions('application/json', verData.apiVersion);
221 let res;
222 res = yield this.rest.update(url, alertsMetadata, options);
223 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.AlertMetadataChange, true);
224 resolve(ret);
225 }
226 catch (err) {
227 reject(err);
228 }
229 }));
230 });
231 }
232 /**
233 * Upload a Sarif containing security alerts
234 *
235 * @param {NodeJS.ReadableStream} contentStream - Content to upload
236 * @param {string} project - Project ID or project name
237 * @param {string} repository - The name or ID of a repository
238 */
239 uploadSarif(customHeaders, contentStream, project, repository) {
240 return __awaiter(this, void 0, void 0, function* () {
241 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
242 let routeValues = {
243 project: project,
244 repository: repository
245 };
246 customHeaders = customHeaders || {};
247 customHeaders["Content-Type"] = "application/octet-stream";
248 try {
249 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "2a141cae-a50d-4c22-b41b-13f77748d035", routeValues);
250 let url = verData.requestUrl;
251 let options = this.createRequestOptions('application/json', verData.apiVersion);
252 options.additionalHeaders = customHeaders;
253 let res;
254 res = yield this.rest.uploadStream("POST", url, contentStream, options);
255 let ret = this.formatResponse(res.result, null, false);
256 resolve(ret);
257 }
258 catch (err) {
259 reject(err);
260 }
261 }));
262 });
263 }
264 /**
265 * @param {string} project - Project ID or project name
266 * @param {string} repository
267 * @param {AlertInterfaces.AlertType} alertType
268 */
269 getUxFilters(project, repository, alertType) {
270 return __awaiter(this, void 0, void 0, function* () {
271 if (alertType == null) {
272 throw new TypeError('alertType can not be null or undefined');
273 }
274 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
275 let routeValues = {
276 project: project,
277 repository: repository
278 };
279 let queryValues = {
280 alertType: alertType,
281 };
282 try {
283 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "Alert", "8f90675b-f794-434d-8f2c-cfae0a11c02a", routeValues, queryValues);
284 let url = verData.requestUrl;
285 let options = this.createRequestOptions('application/json', verData.apiVersion);
286 let res;
287 res = yield this.rest.get(url, options);
288 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.UxFilters, false);
289 resolve(ret);
290 }
291 catch (err) {
292 reject(err);
293 }
294 }));
295 });
296 }
297 /**
298 * Get the status of the Sarif processing job
299 *
300 * @param {number} sarifId - Sarif ID returned when the Sarif was uploaded
301 */
302 getSarif(sarifId) {
303 return __awaiter(this, void 0, void 0, function* () {
304 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
305 let routeValues = {
306 sarifId: sarifId
307 };
308 try {
309 let verData = yield this.vsoClient.getVersioningData("7.2-preview.2", "Alert", "a04689e7-0f81-48a2-8d18-40654c47494c", routeValues);
310 let url = verData.requestUrl;
311 let options = this.createRequestOptions('application/json', verData.apiVersion);
312 let res;
313 res = yield this.rest.get(url, options);
314 let ret = this.formatResponse(res.result, AlertInterfaces.TypeInfo.SarifUploadStatus, false);
315 resolve(ret);
316 }
317 catch (err) {
318 reject(err);
319 }
320 }));
321 });
322 }
323}
324exports.AlertApi = AlertApi;