mobbdev 0.0.107 → 0.0.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +4 -2
- package/dist/index.mjs +449 -570
- package/package.json +11 -4
package/.env
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# production@
|
|
1
|
+
# production@v17
|
|
2
2
|
WEB_LOGIN_URL="https://app.mobb.ai/cli-login"
|
|
3
3
|
API_URL="https://api.mobb.ai/v1/graphql"
|
|
4
4
|
WEB_APP_URL="https://app.mobb.ai"
|
|
5
5
|
GITLAB_API_TOKEN=""
|
|
6
6
|
GITHUB_API_TOKEN=""
|
|
7
|
-
ADO_TEST_ACCESS_TOKEN=""
|
|
7
|
+
ADO_TEST_ACCESS_TOKEN=""
|
|
8
|
+
HASURA_ACCESS_KEY=""
|
|
9
|
+
LOCAL_GRAPHQL_ENDPOINT=""
|
package/dist/index.mjs
CHANGED
|
@@ -55,7 +55,9 @@ var SCANNERS = {
|
|
|
55
55
|
var SupportedScannersZ = z.enum([SCANNERS.Checkmarx, SCANNERS.Snyk]);
|
|
56
56
|
var envVariablesSchema = z.object({
|
|
57
57
|
WEB_APP_URL: z.string(),
|
|
58
|
-
API_URL: z.string()
|
|
58
|
+
API_URL: z.string(),
|
|
59
|
+
HASURA_ACCESS_KEY: z.string(),
|
|
60
|
+
LOCAL_GRAPHQL_ENDPOINT: z.string()
|
|
59
61
|
}).required();
|
|
60
62
|
var envVariables = envVariablesSchema.parse(process.env);
|
|
61
63
|
debug("config %o", envVariables);
|
|
@@ -90,6 +92,8 @@ var mobbAscii = `
|
|
|
90
92
|
var PROJECT_DEFAULT_NAME = "My first project";
|
|
91
93
|
var WEB_APP_URL = envVariables.WEB_APP_URL;
|
|
92
94
|
var API_URL = envVariables.API_URL;
|
|
95
|
+
var HASURA_ACCESS_KEY = envVariables.HASURA_ACCESS_KEY;
|
|
96
|
+
var LOCAL_GRAPHQL_ENDPOINT = envVariables.LOCAL_GRAPHQL_ENDPOINT;
|
|
93
97
|
var errorMessages = {
|
|
94
98
|
missingCxProjectName: `project name ${chalk.bold(
|
|
95
99
|
"(--cx-project-name)"
|
|
@@ -118,6 +122,328 @@ import os2 from "node:os";
|
|
|
118
122
|
import path6 from "node:path";
|
|
119
123
|
import { pipeline } from "node:stream/promises";
|
|
120
124
|
|
|
125
|
+
// src/generates/client_generates.ts
|
|
126
|
+
var MeDocument = `
|
|
127
|
+
query Me {
|
|
128
|
+
me {
|
|
129
|
+
id
|
|
130
|
+
email
|
|
131
|
+
scmConfigs {
|
|
132
|
+
id
|
|
133
|
+
orgId
|
|
134
|
+
refreshToken
|
|
135
|
+
scmType
|
|
136
|
+
scmUrl
|
|
137
|
+
scmUsername
|
|
138
|
+
token
|
|
139
|
+
tokenLastUpdate
|
|
140
|
+
userId
|
|
141
|
+
scmOrg
|
|
142
|
+
isTokenAvailable
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
var GetOrgAndProjectIdDocument = `
|
|
148
|
+
query getOrgAndProjectId {
|
|
149
|
+
users: user {
|
|
150
|
+
userOrganizationsAndUserOrganizationRoles {
|
|
151
|
+
organization {
|
|
152
|
+
id
|
|
153
|
+
projects(order_by: {updatedAt: desc}) {
|
|
154
|
+
id
|
|
155
|
+
name
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
var GetEncryptedApiTokenDocument = `
|
|
163
|
+
query GetEncryptedApiToken($loginId: uuid!) {
|
|
164
|
+
cli_login_by_pk(id: $loginId) {
|
|
165
|
+
encryptedApiToken
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
`;
|
|
169
|
+
var FixReportStateDocument = `
|
|
170
|
+
query FixReportState($id: uuid!) {
|
|
171
|
+
fixReport_by_pk(id: $id) {
|
|
172
|
+
state
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
var GetVulnerabilityReportPathsDocument = `
|
|
177
|
+
query GetVulnerabilityReportPaths($vulnerabilityReportId: uuid!) {
|
|
178
|
+
vulnerability_report_path(
|
|
179
|
+
where: {vulnerabilityReportId: {_eq: $vulnerabilityReportId}}
|
|
180
|
+
) {
|
|
181
|
+
path
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
var GetAnalysisDocument = `
|
|
186
|
+
subscription getAnalysis($analysisId: uuid!) {
|
|
187
|
+
analysis: fixReport_by_pk(id: $analysisId) {
|
|
188
|
+
id
|
|
189
|
+
state
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
`;
|
|
193
|
+
var GetAnalsyisDocument = `
|
|
194
|
+
query getAnalsyis($analysisId: uuid!) {
|
|
195
|
+
analysis: fixReport_by_pk(id: $analysisId) {
|
|
196
|
+
id
|
|
197
|
+
state
|
|
198
|
+
repo {
|
|
199
|
+
commitSha
|
|
200
|
+
pullRequest
|
|
201
|
+
}
|
|
202
|
+
vulnerabilityReportId
|
|
203
|
+
vulnerabilityReport {
|
|
204
|
+
projectId
|
|
205
|
+
project {
|
|
206
|
+
organizationId
|
|
207
|
+
}
|
|
208
|
+
file {
|
|
209
|
+
signedFile {
|
|
210
|
+
url
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
`;
|
|
217
|
+
var GetFixesDocument = `
|
|
218
|
+
query getFixes($filters: fix_bool_exp!) {
|
|
219
|
+
fixes: fix(where: $filters) {
|
|
220
|
+
issueType
|
|
221
|
+
id
|
|
222
|
+
patchAndQuestions {
|
|
223
|
+
__typename
|
|
224
|
+
... on FixData {
|
|
225
|
+
patch
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`;
|
|
231
|
+
var GetVulByNodesMetadataDocument = `
|
|
232
|
+
query getVulByNodesMetadata($filters: [vulnerability_report_issue_code_node_bool_exp!], $vulnerabilityReportId: uuid!) {
|
|
233
|
+
vulnerabilityReportIssueCodeNodes: vulnerability_report_issue_code_node(
|
|
234
|
+
order_by: {index: desc}
|
|
235
|
+
where: {_or: $filters, vulnerabilityReportIssue: {fixId: {_is_null: false}, vulnerabilityReportId: {_eq: $vulnerabilityReportId}}}
|
|
236
|
+
) {
|
|
237
|
+
vulnerabilityReportIssueId
|
|
238
|
+
path
|
|
239
|
+
startLine
|
|
240
|
+
vulnerabilityReportIssue {
|
|
241
|
+
issueType
|
|
242
|
+
fixId
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
fixablePrVuls: vulnerability_report_issue_aggregate(
|
|
246
|
+
where: {fixId: {_is_null: false}, vulnerabilityReportId: {_eq: $vulnerabilityReportId}, codeNodes: {_or: $filters}}
|
|
247
|
+
) {
|
|
248
|
+
aggregate {
|
|
249
|
+
count
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
nonFixablePrVuls: vulnerability_report_issue_aggregate(
|
|
253
|
+
where: {fixId: {_is_null: true}, vulnerabilityReportId: {_eq: $vulnerabilityReportId}, codeNodes: {_or: $filters}}
|
|
254
|
+
) {
|
|
255
|
+
aggregate {
|
|
256
|
+
count
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
totalScanVulnerabilities: vulnerability_report_issue_aggregate(
|
|
260
|
+
where: {vulnerabilityReportId: {_eq: $vulnerabilityReportId}}
|
|
261
|
+
) {
|
|
262
|
+
aggregate {
|
|
263
|
+
count
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
`;
|
|
268
|
+
var UpdateScmTokenDocument = `
|
|
269
|
+
mutation updateScmToken($scmType: String!, $url: String!, $token: String!, $org: String, $username: String, $refreshToken: String) {
|
|
270
|
+
updateScmToken(
|
|
271
|
+
scmType: $scmType
|
|
272
|
+
url: $url
|
|
273
|
+
token: $token
|
|
274
|
+
org: $org
|
|
275
|
+
username: $username
|
|
276
|
+
refreshToken: $refreshToken
|
|
277
|
+
) {
|
|
278
|
+
__typename
|
|
279
|
+
... on ScmAccessTokenUpdateSuccess {
|
|
280
|
+
token
|
|
281
|
+
}
|
|
282
|
+
... on InvalidScmTypeError {
|
|
283
|
+
status
|
|
284
|
+
error
|
|
285
|
+
}
|
|
286
|
+
... on BadScmCredentials {
|
|
287
|
+
status
|
|
288
|
+
error
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
`;
|
|
293
|
+
var UploadS3BucketInfoDocument = `
|
|
294
|
+
mutation uploadS3BucketInfo($fileName: String!) {
|
|
295
|
+
uploadS3BucketInfo(fileName: $fileName) {
|
|
296
|
+
status
|
|
297
|
+
error
|
|
298
|
+
reportUploadInfo: uploadInfo {
|
|
299
|
+
url
|
|
300
|
+
fixReportId
|
|
301
|
+
uploadFieldsJSON
|
|
302
|
+
uploadKey
|
|
303
|
+
}
|
|
304
|
+
repoUploadInfo {
|
|
305
|
+
url
|
|
306
|
+
fixReportId
|
|
307
|
+
uploadFieldsJSON
|
|
308
|
+
uploadKey
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
`;
|
|
313
|
+
var DigestVulnerabilityReportDocument = `
|
|
314
|
+
mutation DigestVulnerabilityReport($vulnerabilityReportFileName: String!, $fixReportId: String!, $projectId: String!) {
|
|
315
|
+
digestVulnerabilityReport(
|
|
316
|
+
fixReportId: $fixReportId
|
|
317
|
+
vulnerabilityReportFileName: $vulnerabilityReportFileName
|
|
318
|
+
projectId: $projectId
|
|
319
|
+
) {
|
|
320
|
+
__typename
|
|
321
|
+
... on VulnerabilityReport {
|
|
322
|
+
vulnerabilityReportId
|
|
323
|
+
fixReportId
|
|
324
|
+
}
|
|
325
|
+
... on RabbitSendError {
|
|
326
|
+
status
|
|
327
|
+
error
|
|
328
|
+
}
|
|
329
|
+
... on ReportValidationError {
|
|
330
|
+
status
|
|
331
|
+
error
|
|
332
|
+
}
|
|
333
|
+
... on ReferenceNotFoundError {
|
|
334
|
+
status
|
|
335
|
+
error
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
`;
|
|
340
|
+
var SubmitVulnerabilityReportDocument = `
|
|
341
|
+
mutation SubmitVulnerabilityReport($fixReportId: String!, $repoUrl: String!, $reference: String!, $projectId: String!, $sha: String, $experimentalEnabled: Boolean, $vulnerabilityReportFileName: String, $pullRequest: Int) {
|
|
342
|
+
submitVulnerabilityReport(
|
|
343
|
+
fixReportId: $fixReportId
|
|
344
|
+
repoUrl: $repoUrl
|
|
345
|
+
reference: $reference
|
|
346
|
+
sha: $sha
|
|
347
|
+
experimentalEnabled: $experimentalEnabled
|
|
348
|
+
pullRequest: $pullRequest
|
|
349
|
+
projectId: $projectId
|
|
350
|
+
vulnerabilityReportFileName: $vulnerabilityReportFileName
|
|
351
|
+
) {
|
|
352
|
+
__typename
|
|
353
|
+
... on VulnerabilityReport {
|
|
354
|
+
vulnerabilityReportId
|
|
355
|
+
fixReportId
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
`;
|
|
360
|
+
var CreateCommunityUserDocument = `
|
|
361
|
+
mutation CreateCommunityUser {
|
|
362
|
+
initOrganizationAndProject {
|
|
363
|
+
userId
|
|
364
|
+
projectId
|
|
365
|
+
organizationId
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
`;
|
|
369
|
+
var CreateCliLoginDocument = `
|
|
370
|
+
mutation CreateCliLogin($publicKey: String!) {
|
|
371
|
+
insert_cli_login_one(object: {publicKey: $publicKey}) {
|
|
372
|
+
id
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
`;
|
|
376
|
+
var PerformCliLoginDocument = `
|
|
377
|
+
mutation performCliLogin($loginId: String!) {
|
|
378
|
+
performCliLogin(loginId: $loginId) {
|
|
379
|
+
status
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
`;
|
|
383
|
+
var CreateProjectDocument = `
|
|
384
|
+
mutation CreateProject($organizationId: String!, $projectName: String!) {
|
|
385
|
+
createProject(organizationId: $organizationId, projectName: $projectName) {
|
|
386
|
+
projectId
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
`;
|
|
390
|
+
var defaultWrapper = (action, _operationName, _operationType) => action();
|
|
391
|
+
function getSdk(client, withWrapper = defaultWrapper) {
|
|
392
|
+
return {
|
|
393
|
+
Me(variables, requestHeaders) {
|
|
394
|
+
return withWrapper((wrappedRequestHeaders) => client.request(MeDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "Me", "query");
|
|
395
|
+
},
|
|
396
|
+
getOrgAndProjectId(variables, requestHeaders) {
|
|
397
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetOrgAndProjectIdDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getOrgAndProjectId", "query");
|
|
398
|
+
},
|
|
399
|
+
GetEncryptedApiToken(variables, requestHeaders) {
|
|
400
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetEncryptedApiTokenDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "GetEncryptedApiToken", "query");
|
|
401
|
+
},
|
|
402
|
+
FixReportState(variables, requestHeaders) {
|
|
403
|
+
return withWrapper((wrappedRequestHeaders) => client.request(FixReportStateDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "FixReportState", "query");
|
|
404
|
+
},
|
|
405
|
+
GetVulnerabilityReportPaths(variables, requestHeaders) {
|
|
406
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetVulnerabilityReportPathsDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "GetVulnerabilityReportPaths", "query");
|
|
407
|
+
},
|
|
408
|
+
getAnalysis(variables, requestHeaders) {
|
|
409
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetAnalysisDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getAnalysis", "subscription");
|
|
410
|
+
},
|
|
411
|
+
getAnalsyis(variables, requestHeaders) {
|
|
412
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetAnalsyisDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getAnalsyis", "query");
|
|
413
|
+
},
|
|
414
|
+
getFixes(variables, requestHeaders) {
|
|
415
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetFixesDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getFixes", "query");
|
|
416
|
+
},
|
|
417
|
+
getVulByNodesMetadata(variables, requestHeaders) {
|
|
418
|
+
return withWrapper((wrappedRequestHeaders) => client.request(GetVulByNodesMetadataDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getVulByNodesMetadata", "query");
|
|
419
|
+
},
|
|
420
|
+
updateScmToken(variables, requestHeaders) {
|
|
421
|
+
return withWrapper((wrappedRequestHeaders) => client.request(UpdateScmTokenDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "updateScmToken", "mutation");
|
|
422
|
+
},
|
|
423
|
+
uploadS3BucketInfo(variables, requestHeaders) {
|
|
424
|
+
return withWrapper((wrappedRequestHeaders) => client.request(UploadS3BucketInfoDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "uploadS3BucketInfo", "mutation");
|
|
425
|
+
},
|
|
426
|
+
DigestVulnerabilityReport(variables, requestHeaders) {
|
|
427
|
+
return withWrapper((wrappedRequestHeaders) => client.request(DigestVulnerabilityReportDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "DigestVulnerabilityReport", "mutation");
|
|
428
|
+
},
|
|
429
|
+
SubmitVulnerabilityReport(variables, requestHeaders) {
|
|
430
|
+
return withWrapper((wrappedRequestHeaders) => client.request(SubmitVulnerabilityReportDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "SubmitVulnerabilityReport", "mutation");
|
|
431
|
+
},
|
|
432
|
+
CreateCommunityUser(variables, requestHeaders) {
|
|
433
|
+
return withWrapper((wrappedRequestHeaders) => client.request(CreateCommunityUserDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "CreateCommunityUser", "mutation");
|
|
434
|
+
},
|
|
435
|
+
CreateCliLogin(variables, requestHeaders) {
|
|
436
|
+
return withWrapper((wrappedRequestHeaders) => client.request(CreateCliLoginDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "CreateCliLogin", "mutation");
|
|
437
|
+
},
|
|
438
|
+
performCliLogin(variables, requestHeaders) {
|
|
439
|
+
return withWrapper((wrappedRequestHeaders) => client.request(PerformCliLoginDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "performCliLogin", "mutation");
|
|
440
|
+
},
|
|
441
|
+
CreateProject(variables, requestHeaders) {
|
|
442
|
+
return withWrapper((wrappedRequestHeaders) => client.request(CreateProjectDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "CreateProject", "mutation");
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
121
447
|
// src/utils/index.ts
|
|
122
448
|
var utils_exports = {};
|
|
123
449
|
__export(utils_exports, {
|
|
@@ -250,322 +576,7 @@ import Debug3 from "debug";
|
|
|
250
576
|
import { GraphQLClient } from "graphql-request";
|
|
251
577
|
import { v4 as uuidv4 } from "uuid";
|
|
252
578
|
|
|
253
|
-
// src/features/analysis/graphql/
|
|
254
|
-
import { gql } from "graphql-request";
|
|
255
|
-
var UPDATE_SCM_TOKEN = gql`
|
|
256
|
-
mutation updateScmToken(
|
|
257
|
-
$scmType: String!
|
|
258
|
-
$url: String!
|
|
259
|
-
$token: String!
|
|
260
|
-
$org: String
|
|
261
|
-
$username: String
|
|
262
|
-
$refreshToken: String
|
|
263
|
-
) {
|
|
264
|
-
updateScmToken(
|
|
265
|
-
scmType: $scmType
|
|
266
|
-
url: $url
|
|
267
|
-
token: $token
|
|
268
|
-
org: $org
|
|
269
|
-
username: $username
|
|
270
|
-
refreshToken: $refreshToken
|
|
271
|
-
) {
|
|
272
|
-
__typename
|
|
273
|
-
... on ScmAccessTokenUpdateSuccess {
|
|
274
|
-
token
|
|
275
|
-
}
|
|
276
|
-
... on InvalidScmTypeError {
|
|
277
|
-
status
|
|
278
|
-
error
|
|
279
|
-
}
|
|
280
|
-
... on BadScmCredentials {
|
|
281
|
-
status
|
|
282
|
-
error
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
`;
|
|
287
|
-
var UPLOAD_S3_BUCKET_INFO = gql`
|
|
288
|
-
mutation uploadS3BucketInfo($fileName: String!) {
|
|
289
|
-
uploadS3BucketInfo(fileName: $fileName) {
|
|
290
|
-
status
|
|
291
|
-
error
|
|
292
|
-
reportUploadInfo: uploadInfo {
|
|
293
|
-
url
|
|
294
|
-
fixReportId
|
|
295
|
-
uploadFieldsJSON
|
|
296
|
-
uploadKey
|
|
297
|
-
}
|
|
298
|
-
repoUploadInfo {
|
|
299
|
-
url
|
|
300
|
-
fixReportId
|
|
301
|
-
uploadFieldsJSON
|
|
302
|
-
uploadKey
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
`;
|
|
307
|
-
var DIGEST_VULNERABILITY_REPORT = gql`
|
|
308
|
-
mutation DigestVulnerabilityReport(
|
|
309
|
-
$vulnerabilityReportFileName: String!
|
|
310
|
-
$fixReportId: String!
|
|
311
|
-
$projectId: String!
|
|
312
|
-
) {
|
|
313
|
-
digestVulnerabilityReport(
|
|
314
|
-
fixReportId: $fixReportId
|
|
315
|
-
vulnerabilityReportFileName: $vulnerabilityReportFileName
|
|
316
|
-
projectId: $projectId
|
|
317
|
-
) {
|
|
318
|
-
__typename
|
|
319
|
-
... on VulnerabilityReport {
|
|
320
|
-
vulnerabilityReportId
|
|
321
|
-
fixReportId
|
|
322
|
-
}
|
|
323
|
-
... on RabbitSendError {
|
|
324
|
-
status
|
|
325
|
-
error
|
|
326
|
-
}
|
|
327
|
-
... on ReportValidationError {
|
|
328
|
-
status
|
|
329
|
-
error
|
|
330
|
-
}
|
|
331
|
-
... on ReferenceNotFoundError {
|
|
332
|
-
status
|
|
333
|
-
error
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
`;
|
|
338
|
-
var SUBMIT_VULNERABILITY_REPORT = gql`
|
|
339
|
-
mutation SubmitVulnerabilityReport(
|
|
340
|
-
$fixReportId: String!
|
|
341
|
-
$repoUrl: String!
|
|
342
|
-
$reference: String!
|
|
343
|
-
$projectId: String!
|
|
344
|
-
$sha: String
|
|
345
|
-
$experimentalEnabled: Boolean
|
|
346
|
-
$vulnerabilityReportFileName: String
|
|
347
|
-
$pullRequest: Int
|
|
348
|
-
) {
|
|
349
|
-
submitVulnerabilityReport(
|
|
350
|
-
fixReportId: $fixReportId
|
|
351
|
-
repoUrl: $repoUrl
|
|
352
|
-
reference: $reference
|
|
353
|
-
sha: $sha
|
|
354
|
-
experimentalEnabled: $experimentalEnabled
|
|
355
|
-
pullRequest: $pullRequest
|
|
356
|
-
projectId: $projectId
|
|
357
|
-
vulnerabilityReportFileName: $vulnerabilityReportFileName
|
|
358
|
-
) {
|
|
359
|
-
__typename
|
|
360
|
-
... on VulnerabilityReport {
|
|
361
|
-
vulnerabilityReportId
|
|
362
|
-
fixReportId
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
`;
|
|
367
|
-
var CREATE_COMMUNITY_USER = gql`
|
|
368
|
-
mutation CreateCommunityUser {
|
|
369
|
-
initOrganizationAndProject {
|
|
370
|
-
userId
|
|
371
|
-
projectId
|
|
372
|
-
organizationId
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
`;
|
|
376
|
-
var CREATE_CLI_LOGIN = gql`
|
|
377
|
-
mutation CreateCliLogin($publicKey: String!) {
|
|
378
|
-
insert_cli_login_one(object: { publicKey: $publicKey }) {
|
|
379
|
-
id
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
`;
|
|
383
|
-
var PERFORM_CLI_LOGIN = gql`
|
|
384
|
-
mutation performCliLogin($loginId: String!) {
|
|
385
|
-
performCliLogin(loginId: $loginId) {
|
|
386
|
-
status
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
`;
|
|
390
|
-
var CREATE_PROJECT = gql`
|
|
391
|
-
mutation CreateProject($organizationId: String!, $projectName: String!) {
|
|
392
|
-
createProject(organizationId: $organizationId, projectName: $projectName) {
|
|
393
|
-
projectId
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
`;
|
|
397
|
-
|
|
398
|
-
// src/features/analysis/graphql/queries.ts
|
|
399
|
-
import { gql as gql2 } from "graphql-request";
|
|
400
|
-
var ME = gql2`
|
|
401
|
-
query Me {
|
|
402
|
-
me {
|
|
403
|
-
id
|
|
404
|
-
email
|
|
405
|
-
scmConfigs {
|
|
406
|
-
id
|
|
407
|
-
orgId
|
|
408
|
-
refreshToken
|
|
409
|
-
scmType
|
|
410
|
-
scmUrl
|
|
411
|
-
scmUsername
|
|
412
|
-
token
|
|
413
|
-
tokenLastUpdate
|
|
414
|
-
userId
|
|
415
|
-
scmOrg
|
|
416
|
-
isTokenAvailable
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
`;
|
|
421
|
-
var GET_ORG_AND_PROJECT_ID = gql2`
|
|
422
|
-
query getOrgAndProjectId {
|
|
423
|
-
users: user {
|
|
424
|
-
userOrganizationsAndUserOrganizationRoles {
|
|
425
|
-
organization {
|
|
426
|
-
id
|
|
427
|
-
projects(order_by: { updatedAt: desc }) {
|
|
428
|
-
id
|
|
429
|
-
name
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
`;
|
|
436
|
-
var GET_ENCRYPTED_API_TOKEN = gql2`
|
|
437
|
-
query GetEncryptedApiToken($loginId: uuid!) {
|
|
438
|
-
cli_login_by_pk(id: $loginId) {
|
|
439
|
-
encryptedApiToken
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
`;
|
|
443
|
-
var GET_FIX_REPORT_STATE = gql2`
|
|
444
|
-
query FixReportState($id: uuid!) {
|
|
445
|
-
fixReport_by_pk(id: $id) {
|
|
446
|
-
state
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
`;
|
|
450
|
-
var GET_VULNERABILITY_REPORT_PATHS = gql2`
|
|
451
|
-
query GetVulnerabilityReportPaths($vulnerabilityReportId: uuid!) {
|
|
452
|
-
vulnerability_report_path(
|
|
453
|
-
where: { vulnerabilityReportId: { _eq: $vulnerabilityReportId } }
|
|
454
|
-
) {
|
|
455
|
-
path
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
`;
|
|
459
|
-
var SUBSCRIBE_TO_ANALYSIS = gql2`
|
|
460
|
-
subscription getAnalysis($analysisId: uuid!) {
|
|
461
|
-
analysis: fixReport_by_pk(id: $analysisId) {
|
|
462
|
-
id
|
|
463
|
-
state
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
`;
|
|
467
|
-
var GET_ANALYSIS = gql2`
|
|
468
|
-
query getAnalsyis($analysisId: uuid!) {
|
|
469
|
-
analysis: fixReport_by_pk(id: $analysisId) {
|
|
470
|
-
id
|
|
471
|
-
state
|
|
472
|
-
repo {
|
|
473
|
-
commitSha
|
|
474
|
-
pullRequest
|
|
475
|
-
}
|
|
476
|
-
vulnerabilityReportId
|
|
477
|
-
vulnerabilityReport {
|
|
478
|
-
projectId
|
|
479
|
-
project {
|
|
480
|
-
organizationId
|
|
481
|
-
}
|
|
482
|
-
file {
|
|
483
|
-
signedFile {
|
|
484
|
-
url
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
`;
|
|
491
|
-
var GET_FIX = gql2`
|
|
492
|
-
query getFix($fixId: uuid!) {
|
|
493
|
-
fix_by_pk(id: $fixId) {
|
|
494
|
-
issueType
|
|
495
|
-
id
|
|
496
|
-
patchAndQuestions {
|
|
497
|
-
patch
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
`;
|
|
502
|
-
var GET_FIXES = gql2`
|
|
503
|
-
query getFixes($filters: fix_bool_exp!) {
|
|
504
|
-
fixes: fix(where: $filters) {
|
|
505
|
-
issueType
|
|
506
|
-
id
|
|
507
|
-
patchAndQuestions {
|
|
508
|
-
patch
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
`;
|
|
513
|
-
var GET_VUL_BY_NODES_METADATA = gql2`
|
|
514
|
-
query getVulByNodesMetadata(
|
|
515
|
-
$filters: [vulnerability_report_issue_code_node_bool_exp!]
|
|
516
|
-
$vulnerabilityReportId: uuid!
|
|
517
|
-
) {
|
|
518
|
-
vulnerabilityReportIssueCodeNodes: vulnerability_report_issue_code_node(
|
|
519
|
-
order_by: { index: desc }
|
|
520
|
-
where: {
|
|
521
|
-
_or: $filters
|
|
522
|
-
vulnerabilityReportIssue: {
|
|
523
|
-
fixId: { _is_null: false }
|
|
524
|
-
vulnerabilityReportId: { _eq: $vulnerabilityReportId }
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
) {
|
|
528
|
-
vulnerabilityReportIssueId
|
|
529
|
-
path
|
|
530
|
-
startLine
|
|
531
|
-
vulnerabilityReportIssue {
|
|
532
|
-
issueType
|
|
533
|
-
fixId
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
fixablePrVuls: vulnerability_report_issue_aggregate(
|
|
537
|
-
where: {
|
|
538
|
-
fixId: { _is_null: false }
|
|
539
|
-
vulnerabilityReportId: { _eq: $vulnerabilityReportId }
|
|
540
|
-
codeNodes: { _or: $filters }
|
|
541
|
-
}
|
|
542
|
-
) {
|
|
543
|
-
aggregate {
|
|
544
|
-
count
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
nonFixablePrVuls: vulnerability_report_issue_aggregate(
|
|
548
|
-
where: {
|
|
549
|
-
fixId: { _is_null: true }
|
|
550
|
-
vulnerabilityReportId: { _eq: $vulnerabilityReportId }
|
|
551
|
-
codeNodes: { _or: $filters }
|
|
552
|
-
}
|
|
553
|
-
) {
|
|
554
|
-
aggregate {
|
|
555
|
-
count
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
totalScanVulnerabilities: vulnerability_report_issue_aggregate(
|
|
559
|
-
where: { vulnerabilityReportId: { _eq: $vulnerabilityReportId } }
|
|
560
|
-
) {
|
|
561
|
-
aggregate {
|
|
562
|
-
count
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
`;
|
|
567
|
-
|
|
568
|
-
// src/features/analysis/graphql/subscirbe.ts
|
|
579
|
+
// src/features/analysis/graphql/subscribe.ts
|
|
569
580
|
import { createClient } from "graphql-ws";
|
|
570
581
|
import WebSocket from "ws";
|
|
571
582
|
var SUBSCRIPTION_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
@@ -647,150 +658,6 @@ function subscribe(query, variables, callback, wsClientOptions) {
|
|
|
647
658
|
|
|
648
659
|
// src/features/analysis/graphql/types.ts
|
|
649
660
|
import { z as z2 } from "zod";
|
|
650
|
-
var UpdateScmTokenZ = z2.object({
|
|
651
|
-
updateScmToken: z2.object({
|
|
652
|
-
token: z2.string()
|
|
653
|
-
})
|
|
654
|
-
});
|
|
655
|
-
var UploadFieldsZ = z2.object({
|
|
656
|
-
bucket: z2.string(),
|
|
657
|
-
"X-Amz-Algorithm": z2.string(),
|
|
658
|
-
"X-Amz-Credential": z2.string(),
|
|
659
|
-
"X-Amz-Date": z2.string(),
|
|
660
|
-
Policy: z2.string(),
|
|
661
|
-
"X-Amz-Signature": z2.string()
|
|
662
|
-
});
|
|
663
|
-
var ReportUploadInfoZ = z2.object({
|
|
664
|
-
url: z2.string(),
|
|
665
|
-
fixReportId: z2.string(),
|
|
666
|
-
uploadFieldsJSON: z2.string().transform((str, ctx) => {
|
|
667
|
-
try {
|
|
668
|
-
return JSON.parse(str);
|
|
669
|
-
} catch (e) {
|
|
670
|
-
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
671
|
-
return z2.NEVER;
|
|
672
|
-
}
|
|
673
|
-
}),
|
|
674
|
-
uploadKey: z2.string()
|
|
675
|
-
}).transform(({ uploadFieldsJSON, ...input }) => ({
|
|
676
|
-
...input,
|
|
677
|
-
uploadFields: uploadFieldsJSON
|
|
678
|
-
}));
|
|
679
|
-
var UploadS3BucketInfoZ = z2.object({
|
|
680
|
-
uploadS3BucketInfo: z2.object({
|
|
681
|
-
status: z2.string(),
|
|
682
|
-
error: z2.string().nullish(),
|
|
683
|
-
reportUploadInfo: ReportUploadInfoZ,
|
|
684
|
-
repoUploadInfo: ReportUploadInfoZ
|
|
685
|
-
})
|
|
686
|
-
});
|
|
687
|
-
var GetOrgAndProjectIdQueryZ = z2.object({
|
|
688
|
-
users: z2.array(
|
|
689
|
-
z2.object({
|
|
690
|
-
userOrganizationsAndUserOrganizationRoles: z2.array(
|
|
691
|
-
z2.object({
|
|
692
|
-
organization: z2.object({
|
|
693
|
-
id: z2.string(),
|
|
694
|
-
projects: z2.array(
|
|
695
|
-
z2.object({
|
|
696
|
-
id: z2.string(),
|
|
697
|
-
name: z2.string()
|
|
698
|
-
})
|
|
699
|
-
).nonempty()
|
|
700
|
-
})
|
|
701
|
-
})
|
|
702
|
-
).nonempty()
|
|
703
|
-
})
|
|
704
|
-
).nonempty()
|
|
705
|
-
});
|
|
706
|
-
var CreateCliLoginZ = z2.object({
|
|
707
|
-
insert_cli_login_one: z2.object({
|
|
708
|
-
id: z2.string()
|
|
709
|
-
})
|
|
710
|
-
});
|
|
711
|
-
var GetEncryptedApiTokenZ = z2.object({
|
|
712
|
-
cli_login_by_pk: z2.object({
|
|
713
|
-
encryptedApiToken: z2.string().nullable()
|
|
714
|
-
})
|
|
715
|
-
});
|
|
716
|
-
var DigestVulnerabilityReportZ = z2.object({
|
|
717
|
-
digestVulnerabilityReport: z2.object({
|
|
718
|
-
vulnerabilityReportId: z2.string()
|
|
719
|
-
})
|
|
720
|
-
});
|
|
721
|
-
var AnalysisStateZ = z2.enum([
|
|
722
|
-
"Created",
|
|
723
|
-
"Deleted",
|
|
724
|
-
"Digested",
|
|
725
|
-
"Expired",
|
|
726
|
-
"Failed",
|
|
727
|
-
"Finished",
|
|
728
|
-
"Initialized",
|
|
729
|
-
"Requested"
|
|
730
|
-
]);
|
|
731
|
-
var GetFixReportZ = z2.object({
|
|
732
|
-
fixReport_by_pk: z2.object({
|
|
733
|
-
state: AnalysisStateZ
|
|
734
|
-
})
|
|
735
|
-
});
|
|
736
|
-
var GetFixReportSubscriptionZ = z2.object({
|
|
737
|
-
analysis: z2.object({
|
|
738
|
-
id: z2.string(),
|
|
739
|
-
state: AnalysisStateZ
|
|
740
|
-
})
|
|
741
|
-
});
|
|
742
|
-
var GetVulnerabilityReportPathsZ = z2.object({
|
|
743
|
-
vulnerability_report_path: z2.array(
|
|
744
|
-
z2.object({
|
|
745
|
-
path: z2.string()
|
|
746
|
-
})
|
|
747
|
-
)
|
|
748
|
-
});
|
|
749
|
-
var CreateUpdateFixReportMutationZ = z2.object({
|
|
750
|
-
submitVulnerabilityReport: z2.object({
|
|
751
|
-
__typename: z2.literal("VulnerabilityReport"),
|
|
752
|
-
vulnerabilityReportId: z2.string(),
|
|
753
|
-
fixReportId: z2.string()
|
|
754
|
-
})
|
|
755
|
-
});
|
|
756
|
-
var CreateProjectMutationZ = z2.object({
|
|
757
|
-
createProject: z2.object({
|
|
758
|
-
projectId: z2.string()
|
|
759
|
-
})
|
|
760
|
-
});
|
|
761
|
-
var GetAnalysisQueryZ = z2.object({
|
|
762
|
-
analysis: z2.object({
|
|
763
|
-
id: z2.string(),
|
|
764
|
-
state: z2.string(),
|
|
765
|
-
repo: z2.object({
|
|
766
|
-
commitSha: z2.string(),
|
|
767
|
-
pullRequest: z2.number()
|
|
768
|
-
}),
|
|
769
|
-
vulnerabilityReportId: z2.string(),
|
|
770
|
-
vulnerabilityReport: z2.object({
|
|
771
|
-
projectId: z2.string(),
|
|
772
|
-
project: z2.object({
|
|
773
|
-
organizationId: z2.string()
|
|
774
|
-
}),
|
|
775
|
-
file: z2.object({
|
|
776
|
-
signedFile: z2.object({
|
|
777
|
-
url: z2.string()
|
|
778
|
-
})
|
|
779
|
-
})
|
|
780
|
-
})
|
|
781
|
-
})
|
|
782
|
-
});
|
|
783
|
-
var FixDataZ = z2.object({
|
|
784
|
-
issueType: z2.string(),
|
|
785
|
-
id: z2.string(),
|
|
786
|
-
patchAndQuestions: z2.object({
|
|
787
|
-
patch: z2.string()
|
|
788
|
-
})
|
|
789
|
-
});
|
|
790
|
-
var GetFixQueryZ = z2.object({
|
|
791
|
-
fix_by_pk: FixDataZ
|
|
792
|
-
});
|
|
793
|
-
var GetFixesQueryZ = z2.object({ fixes: z2.array(FixDataZ) });
|
|
794
661
|
var VulnerabilityReportIssueCodeNodeZ = z2.object({
|
|
795
662
|
vulnerabilityReportIssueId: z2.string(),
|
|
796
663
|
path: z2.string(),
|
|
@@ -826,6 +693,7 @@ var GQLClient = class {
|
|
|
826
693
|
constructor(args) {
|
|
827
694
|
__publicField(this, "_client");
|
|
828
695
|
__publicField(this, "_apiKey");
|
|
696
|
+
__publicField(this, "_clientSdk");
|
|
829
697
|
const { apiKey } = args;
|
|
830
698
|
this._apiKey = apiKey;
|
|
831
699
|
debug3(`init with apiKey ${apiKey}`);
|
|
@@ -845,23 +713,18 @@ var GQLClient = class {
|
|
|
845
713
|
};
|
|
846
714
|
}
|
|
847
715
|
});
|
|
716
|
+
this._clientSdk = getSdk(this._client);
|
|
848
717
|
}
|
|
849
718
|
async getUserInfo() {
|
|
850
|
-
const { me } = await this.
|
|
719
|
+
const { me } = await this._clientSdk.Me();
|
|
851
720
|
return me;
|
|
852
721
|
}
|
|
853
722
|
async createCliLogin(variables) {
|
|
854
|
-
const res =
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
// We may have outdated API key in the config storage. Avoid using it for the login request.
|
|
860
|
-
[API_KEY_HEADER_NAME]: ""
|
|
861
|
-
}
|
|
862
|
-
)
|
|
863
|
-
);
|
|
864
|
-
return res.insert_cli_login_one.id;
|
|
723
|
+
const res = await this._clientSdk.CreateCliLogin(variables, {
|
|
724
|
+
// We may have outdated API key in the config storage. Avoid using it for the login request.
|
|
725
|
+
[API_KEY_HEADER_NAME]: ""
|
|
726
|
+
});
|
|
727
|
+
return res.insert_cli_login_one?.id || "";
|
|
865
728
|
}
|
|
866
729
|
async verifyToken() {
|
|
867
730
|
await this.createCommunityUser();
|
|
@@ -874,23 +737,21 @@ var GQLClient = class {
|
|
|
874
737
|
return true;
|
|
875
738
|
}
|
|
876
739
|
async getOrgAndProjectId(projectName) {
|
|
877
|
-
const getOrgAndProjectIdResult = await this.
|
|
878
|
-
|
|
879
|
-
)
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
).
|
|
883
|
-
|
|
884
|
-
|
|
740
|
+
const getOrgAndProjectIdResult = await this._clientSdk.getOrgAndProjectId();
|
|
741
|
+
const org = getOrgAndProjectIdResult?.users?.at(0)?.userOrganizationsAndUserOrganizationRoles?.at(0)?.organization;
|
|
742
|
+
if (!org?.id) {
|
|
743
|
+
throw new Error("Organization not found");
|
|
744
|
+
}
|
|
745
|
+
const project = projectName ? org?.projects.find((project2) => project2.name === projectName) ?? null : org?.projects[0];
|
|
746
|
+
if (!project?.id) {
|
|
747
|
+
throw new Error("Project not found");
|
|
748
|
+
}
|
|
885
749
|
let projectId = project?.id;
|
|
886
750
|
if (!projectId) {
|
|
887
|
-
const createdProject = await this.
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
projectName: projectName || "My project"
|
|
892
|
-
}
|
|
893
|
-
);
|
|
751
|
+
const createdProject = await this._clientSdk.CreateProject({
|
|
752
|
+
organizationId: org.id,
|
|
753
|
+
projectName: projectName || "My project"
|
|
754
|
+
});
|
|
894
755
|
projectId = createdProject.createProject.projectId;
|
|
895
756
|
}
|
|
896
757
|
return {
|
|
@@ -899,26 +760,22 @@ var GQLClient = class {
|
|
|
899
760
|
};
|
|
900
761
|
}
|
|
901
762
|
async getEncryptedApiToken(variables) {
|
|
902
|
-
const res = await this.
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
[API_KEY_HEADER_NAME]: ""
|
|
908
|
-
}
|
|
909
|
-
);
|
|
910
|
-
return GetEncryptedApiTokenZ.parse(res).cli_login_by_pk.encryptedApiToken;
|
|
763
|
+
const res = await this._clientSdk.GetEncryptedApiToken(variables, {
|
|
764
|
+
// We may have outdated API key in the config storage. Avoid using it for the login request.
|
|
765
|
+
[API_KEY_HEADER_NAME]: ""
|
|
766
|
+
});
|
|
767
|
+
return res?.cli_login_by_pk?.encryptedApiToken || null;
|
|
911
768
|
}
|
|
912
769
|
async createCommunityUser() {
|
|
913
770
|
try {
|
|
914
|
-
await this.
|
|
771
|
+
await this._clientSdk.CreateCommunityUser();
|
|
915
772
|
} catch (e) {
|
|
916
773
|
debug3("create community user failed %o", e);
|
|
917
774
|
}
|
|
918
775
|
}
|
|
919
776
|
async updateScmToken(args) {
|
|
920
777
|
const { scmType, url, token, org, username, refreshToken } = args;
|
|
921
|
-
const updateScmTokenResult = await this.
|
|
778
|
+
const updateScmTokenResult = await this._clientSdk.updateScmToken({
|
|
922
779
|
scmType,
|
|
923
780
|
url,
|
|
924
781
|
token,
|
|
@@ -926,13 +783,13 @@ var GQLClient = class {
|
|
|
926
783
|
username,
|
|
927
784
|
refreshToken
|
|
928
785
|
});
|
|
929
|
-
return
|
|
786
|
+
return updateScmTokenResult;
|
|
930
787
|
}
|
|
931
788
|
async uploadS3BucketInfo() {
|
|
932
|
-
const uploadS3BucketInfoResult = await this.
|
|
789
|
+
const uploadS3BucketInfoResult = await this._clientSdk.uploadS3BucketInfo({
|
|
933
790
|
fileName: "report.json"
|
|
934
791
|
});
|
|
935
|
-
return
|
|
792
|
+
return uploadS3BucketInfoResult;
|
|
936
793
|
}
|
|
937
794
|
async getVulByNodesMetadata({
|
|
938
795
|
hunks,
|
|
@@ -948,7 +805,7 @@ var GQLClient = class {
|
|
|
948
805
|
};
|
|
949
806
|
return filter;
|
|
950
807
|
});
|
|
951
|
-
const getVulByNodesMetadataRes = await this.
|
|
808
|
+
const getVulByNodesMetadataRes = await this._clientSdk.getVulByNodesMetadata({
|
|
952
809
|
filters: { _or: filters },
|
|
953
810
|
vulnerabilityReportId
|
|
954
811
|
});
|
|
@@ -984,15 +841,15 @@ var GQLClient = class {
|
|
|
984
841
|
fixReportId,
|
|
985
842
|
projectId
|
|
986
843
|
}) {
|
|
987
|
-
const res = await this.
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
return
|
|
844
|
+
const res = await this._clientSdk.DigestVulnerabilityReport({
|
|
845
|
+
fixReportId,
|
|
846
|
+
vulnerabilityReportFileName: "report.json",
|
|
847
|
+
projectId
|
|
848
|
+
});
|
|
849
|
+
if (res.digestVulnerabilityReport.__typename !== "VulnerabilityReport") {
|
|
850
|
+
throw new Error("Digesting vulnerability report failed");
|
|
851
|
+
}
|
|
852
|
+
return res.digestVulnerabilityReport;
|
|
996
853
|
}
|
|
997
854
|
async submitVulnerabilityReport(params) {
|
|
998
855
|
const {
|
|
@@ -1005,7 +862,7 @@ var GQLClient = class {
|
|
|
1005
862
|
vulnerabilityReportFileName,
|
|
1006
863
|
pullRequest
|
|
1007
864
|
} = params;
|
|
1008
|
-
const res = await this.
|
|
865
|
+
const res = await this._clientSdk.SubmitVulnerabilityReport({
|
|
1009
866
|
fixReportId,
|
|
1010
867
|
repoUrl,
|
|
1011
868
|
reference,
|
|
@@ -1015,21 +872,21 @@ var GQLClient = class {
|
|
|
1015
872
|
sha: sha || "",
|
|
1016
873
|
experimentalEnabled
|
|
1017
874
|
});
|
|
1018
|
-
return
|
|
875
|
+
return res;
|
|
1019
876
|
}
|
|
1020
877
|
async getFixReportState(fixReportId) {
|
|
1021
|
-
const res = await this.
|
|
1022
|
-
|
|
1023
|
-
{ id: fixReportId }
|
|
1024
|
-
);
|
|
1025
|
-
return GetFixReportZ.parse(res).fixReport_by_pk.state;
|
|
878
|
+
const res = await this._clientSdk.FixReportState({ id: fixReportId });
|
|
879
|
+
return res?.fixReport_by_pk?.state || "Created" /* Created */;
|
|
1026
880
|
}
|
|
1027
881
|
async waitFixReportInit(fixReportId, includeDigested = false) {
|
|
1028
|
-
const FINAL_STATES = [
|
|
1029
|
-
|
|
882
|
+
const FINAL_STATES = [
|
|
883
|
+
"Finished" /* Finished */,
|
|
884
|
+
"Failed" /* Failed */
|
|
885
|
+
];
|
|
886
|
+
let lastState = "Created" /* Created */;
|
|
1030
887
|
let attempts = 100;
|
|
1031
888
|
if (includeDigested) {
|
|
1032
|
-
FINAL_STATES.push("Digested");
|
|
889
|
+
FINAL_STATES.push("Digested" /* Digested */);
|
|
1033
890
|
}
|
|
1034
891
|
do {
|
|
1035
892
|
await sleep(REPORT_STATE_CHECK_DELAY);
|
|
@@ -1041,23 +898,20 @@ var GQLClient = class {
|
|
|
1041
898
|
return lastState;
|
|
1042
899
|
}
|
|
1043
900
|
async getVulnerabilityReportPaths(vulnerabilityReportId) {
|
|
1044
|
-
const res = await this.
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
);
|
|
1048
|
-
return GetVulnerabilityReportPathsZ.parse(
|
|
1049
|
-
res
|
|
1050
|
-
).vulnerability_report_path.map((p) => p.path);
|
|
901
|
+
const res = await this._clientSdk.GetVulnerabilityReportPaths({
|
|
902
|
+
vulnerabilityReportId
|
|
903
|
+
});
|
|
904
|
+
return res.vulnerability_report_path.map((p) => p.path);
|
|
1051
905
|
}
|
|
1052
906
|
async subscribeToAnalysis(params) {
|
|
1053
907
|
const { callbackStates } = params;
|
|
1054
908
|
return subscribe(
|
|
1055
|
-
|
|
909
|
+
GetAnalysisDocument,
|
|
1056
910
|
params.subscribeToAnalysisParams,
|
|
1057
911
|
async (resolve, reject, data) => {
|
|
1058
|
-
if (data.analysis.state === "Failed") {
|
|
912
|
+
if (!data.analysis?.state || data.analysis?.state === "Failed" /* Failed */) {
|
|
1059
913
|
reject(data);
|
|
1060
|
-
throw new Error(`Analysis failed with id: ${data.analysis
|
|
914
|
+
throw new Error(`Analysis failed with id: ${data.analysis?.id}`);
|
|
1061
915
|
}
|
|
1062
916
|
if (callbackStates.includes(data.analysis?.state)) {
|
|
1063
917
|
await params.callback(data.analysis.id);
|
|
@@ -1071,28 +925,19 @@ var GQLClient = class {
|
|
|
1071
925
|
);
|
|
1072
926
|
}
|
|
1073
927
|
async getAnalysis(analysisId) {
|
|
1074
|
-
const res = await this.
|
|
928
|
+
const res = await this._clientSdk.getAnalsyis({
|
|
1075
929
|
analysisId
|
|
1076
930
|
});
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
GET_FIX,
|
|
1082
|
-
{
|
|
1083
|
-
fixId
|
|
1084
|
-
}
|
|
1085
|
-
);
|
|
1086
|
-
return GetFixQueryZ.parse(res);
|
|
931
|
+
if (!res.analysis) {
|
|
932
|
+
throw new Error(`Analysis not found: ${analysisId}`);
|
|
933
|
+
}
|
|
934
|
+
return res.analysis;
|
|
1087
935
|
}
|
|
1088
936
|
async getFixes(fixIds) {
|
|
1089
|
-
const res = await this.
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
}
|
|
1094
|
-
);
|
|
1095
|
-
return GetFixesQueryZ.parse(res);
|
|
937
|
+
const res = await this._clientSdk.getFixes({
|
|
938
|
+
filters: { id: { _in: fixIds } }
|
|
939
|
+
});
|
|
940
|
+
return res;
|
|
1096
941
|
}
|
|
1097
942
|
};
|
|
1098
943
|
|
|
@@ -3740,25 +3585,28 @@ async function sendReport({
|
|
|
3740
3585
|
gqlClient
|
|
3741
3586
|
}) {
|
|
3742
3587
|
try {
|
|
3743
|
-
const
|
|
3588
|
+
const submitRes = await gqlClient.submitVulnerabilityReport(
|
|
3744
3589
|
submitVulnerabilityReportVariables
|
|
3745
3590
|
);
|
|
3746
|
-
if (
|
|
3747
|
-
debug4("error submit vul report %s",
|
|
3591
|
+
if (submitRes.submitVulnerabilityReport.__typename !== "VulnerabilityReport") {
|
|
3592
|
+
debug4("error submit vul report %s", submitRes);
|
|
3748
3593
|
throw new Error("\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed");
|
|
3749
3594
|
}
|
|
3750
3595
|
spinner.update({ text: progressMassages.processingVulnerabilityReport });
|
|
3751
3596
|
await gqlClient.subscribeToAnalysis({
|
|
3752
3597
|
subscribeToAnalysisParams: {
|
|
3753
|
-
analysisId:
|
|
3598
|
+
analysisId: submitRes.submitVulnerabilityReport.fixReportId
|
|
3754
3599
|
},
|
|
3755
3600
|
callback: () => spinner.update({
|
|
3756
|
-
text: "\u2699\uFE0F Vulnerability report
|
|
3601
|
+
text: "\u2699\uFE0F Vulnerability report processed successfully"
|
|
3757
3602
|
}),
|
|
3758
|
-
callbackStates: [
|
|
3603
|
+
callbackStates: [
|
|
3604
|
+
"Digested" /* Digested */,
|
|
3605
|
+
"Finished" /* Finished */
|
|
3606
|
+
],
|
|
3759
3607
|
timeoutInMs: VUL_REPORT_DIGEST_TIMEOUT_MS
|
|
3760
3608
|
});
|
|
3761
|
-
return
|
|
3609
|
+
return submitRes;
|
|
3762
3610
|
} catch (e) {
|
|
3763
3611
|
spinner.error({ text: "\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed" });
|
|
3764
3612
|
throw e;
|
|
@@ -3824,7 +3672,7 @@ function buildAnalysisSummaryComment(params) {
|
|
|
3824
3672
|
if (!fix) {
|
|
3825
3673
|
throw new Error(`fix ${vulnerabilityReportIssue.fixId} not found`);
|
|
3826
3674
|
}
|
|
3827
|
-
const issueType = getIssueType(fix.issueType);
|
|
3675
|
+
const issueType = getIssueType(fix.issueType ?? null);
|
|
3828
3676
|
const vulnerabilityReportIssueCount = (result[issueType] || 0) + 1;
|
|
3829
3677
|
return {
|
|
3830
3678
|
...result,
|
|
@@ -3855,13 +3703,16 @@ async function handleFinishedAnalysis({
|
|
|
3855
3703
|
projectId,
|
|
3856
3704
|
project: { organizationId }
|
|
3857
3705
|
}
|
|
3858
|
-
} = getAnalysis
|
|
3859
|
-
|
|
3706
|
+
} = getAnalysis;
|
|
3707
|
+
if (!getAnalysis.repo || !getAnalysis.repo.commitSha || !getAnalysis.repo.pullRequest) {
|
|
3708
|
+
throw new Error("repo not found");
|
|
3709
|
+
}
|
|
3710
|
+
const { commitSha, pullRequest } = getAnalysis.repo;
|
|
3860
3711
|
const diff = await scm.getPrDiff({ pull_number: pullRequest });
|
|
3861
3712
|
const prVulenrabilities = await getRelevantVulenrabilitiesFromDiff({
|
|
3862
3713
|
diff,
|
|
3863
3714
|
gqlClient,
|
|
3864
|
-
vulnerabilityReportId: getAnalysis.
|
|
3715
|
+
vulnerabilityReportId: getAnalysis.vulnerabilityReportId
|
|
3865
3716
|
});
|
|
3866
3717
|
const { vulnerabilityReportIssueCodeNodes } = prVulenrabilities;
|
|
3867
3718
|
const fixesId = vulnerabilityReportIssueCodeNodes.map(
|
|
@@ -3935,7 +3786,7 @@ async function handleFinishedAnalysis({
|
|
|
3935
3786
|
vulnerabilityReportIssue: { fixId }
|
|
3936
3787
|
} = vulnerabilityReportIssueCodeNode;
|
|
3937
3788
|
const fix = fixesById[fixId];
|
|
3938
|
-
if (!fix) {
|
|
3789
|
+
if (!fix || fix.patchAndQuestions.__typename !== "FixData") {
|
|
3939
3790
|
throw new Error(`fix ${fixId} not found`);
|
|
3940
3791
|
}
|
|
3941
3792
|
const {
|
|
@@ -3971,7 +3822,7 @@ async function handleFinishedAnalysis({
|
|
|
3971
3822
|
commentId
|
|
3972
3823
|
});
|
|
3973
3824
|
const scanerString = scannerToFriendlyString(scanner);
|
|
3974
|
-
const issueType = getIssueType(fix.issueType);
|
|
3825
|
+
const issueType = getIssueType(fix.issueType ?? null);
|
|
3975
3826
|
const title = `# ${MobbIconMarkdown} ${issueType} fix is ready`;
|
|
3976
3827
|
const subTitle = `### Apply the following code change to fix ${issueType} issue detected by **${scanerString}**:`;
|
|
3977
3828
|
const diff2 = `\`\`\`diff
|
|
@@ -4594,6 +4445,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4594
4445
|
const {
|
|
4595
4446
|
uploadS3BucketInfo: { repoUploadInfo, reportUploadInfo }
|
|
4596
4447
|
} = await gqlClient.uploadS3BucketInfo();
|
|
4448
|
+
if (!reportUploadInfo || !repoUploadInfo) {
|
|
4449
|
+
throw new Error("uploadS3BucketInfo is null");
|
|
4450
|
+
}
|
|
4597
4451
|
let reportPath = scanFile;
|
|
4598
4452
|
if (srcPath) {
|
|
4599
4453
|
return await uploadExistingRepo();
|
|
@@ -4602,9 +4456,15 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4602
4456
|
throw new Error("repo is required in case srcPath is not provided");
|
|
4603
4457
|
}
|
|
4604
4458
|
const userInfo = await gqlClient.getUserInfo();
|
|
4459
|
+
const scmConfigs = [];
|
|
4460
|
+
for (const scmConfig of userInfo?.scmConfigs || []) {
|
|
4461
|
+
if (scmConfig?.__typename === "ScmConfig") {
|
|
4462
|
+
scmConfigs.push(scmConfig);
|
|
4463
|
+
}
|
|
4464
|
+
}
|
|
4605
4465
|
const tokenInfo = getScmConfig({
|
|
4606
4466
|
url: repo,
|
|
4607
|
-
scmConfigs
|
|
4467
|
+
scmConfigs,
|
|
4608
4468
|
includeOrgTokens: false
|
|
4609
4469
|
});
|
|
4610
4470
|
const isRepoAvailable = await scmCanReachRepo({
|
|
@@ -4667,7 +4527,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4667
4527
|
await uploadFile({
|
|
4668
4528
|
file: reportPath,
|
|
4669
4529
|
url: reportUploadInfo.url,
|
|
4670
|
-
uploadFields: reportUploadInfo.
|
|
4530
|
+
uploadFields: JSON.parse(reportUploadInfo.uploadFieldsJSON),
|
|
4671
4531
|
uploadKey: reportUploadInfo.uploadKey
|
|
4672
4532
|
});
|
|
4673
4533
|
} catch (e) {
|
|
@@ -4690,6 +4550,10 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4690
4550
|
pullRequest: params.pullRequest
|
|
4691
4551
|
}
|
|
4692
4552
|
});
|
|
4553
|
+
if (sendReportRes.submitVulnerabilityReport.__typename !== "VulnerabilityReport") {
|
|
4554
|
+
mobbSpinner.error({ text: "\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed" });
|
|
4555
|
+
throw new Error("\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed");
|
|
4556
|
+
}
|
|
4693
4557
|
if (command === "review") {
|
|
4694
4558
|
await gqlClient.subscribeToAnalysis({
|
|
4695
4559
|
subscribeToAnalysisParams: {
|
|
@@ -4702,7 +4566,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4702
4566
|
githubActionToken: z11.string().parse(githubActionToken),
|
|
4703
4567
|
scanner: z11.nativeEnum(SCANNERS).parse(scanner)
|
|
4704
4568
|
}),
|
|
4705
|
-
callbackStates: ["Finished"]
|
|
4569
|
+
callbackStates: ["Finished" /* Finished */]
|
|
4706
4570
|
});
|
|
4707
4571
|
}
|
|
4708
4572
|
mobbSpinner.success({
|
|
@@ -4733,6 +4597,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4733
4597
|
return reportPath2;
|
|
4734
4598
|
}
|
|
4735
4599
|
async function askToOpenAnalysis() {
|
|
4600
|
+
if (!repoUploadInfo || !reportUploadInfo) {
|
|
4601
|
+
throw new Error("uploadS3BucketInfo is null");
|
|
4602
|
+
}
|
|
4736
4603
|
const reportUrl = getReportUrl({
|
|
4737
4604
|
organizationId,
|
|
4738
4605
|
projectId,
|
|
@@ -4826,9 +4693,15 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4826
4693
|
await open2(scmAuthUrl2);
|
|
4827
4694
|
for (let i = 0; i < LOGIN_MAX_WAIT / LOGIN_CHECK_DELAY; i++) {
|
|
4828
4695
|
const userInfo2 = await gqlClient.getUserInfo();
|
|
4696
|
+
const scmConfigs2 = [];
|
|
4697
|
+
for (const scmConfig of userInfo2?.scmConfigs || []) {
|
|
4698
|
+
if (scmConfig?.__typename === "ScmConfig") {
|
|
4699
|
+
scmConfigs2.push(scmConfig);
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4829
4702
|
const tokenInfo2 = getScmConfig({
|
|
4830
4703
|
url: repoUrl,
|
|
4831
|
-
scmConfigs:
|
|
4704
|
+
scmConfigs: scmConfigs2,
|
|
4832
4705
|
includeOrgTokens: false
|
|
4833
4706
|
});
|
|
4834
4707
|
if (tokenInfo2.accessToken && tokenInfo2.accessToken !== oldToken) {
|
|
@@ -4844,6 +4717,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4844
4717
|
throw new CliError2(`${scmName} login timeout`);
|
|
4845
4718
|
}
|
|
4846
4719
|
async function uploadExistingRepo() {
|
|
4720
|
+
if (!repoUploadInfo || !reportUploadInfo) {
|
|
4721
|
+
throw new Error("uploadS3BucketInfo is null");
|
|
4722
|
+
}
|
|
4847
4723
|
if (!srcPath || !reportPath) {
|
|
4848
4724
|
throw new Error("src path and reportPath is required");
|
|
4849
4725
|
}
|
|
@@ -4852,7 +4728,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4852
4728
|
await uploadFile({
|
|
4853
4729
|
file: reportPath,
|
|
4854
4730
|
url: reportUploadInfo.url,
|
|
4855
|
-
uploadFields: reportUploadInfo.
|
|
4731
|
+
uploadFields: JSON.parse(reportUploadInfo.uploadFieldsJSON),
|
|
4856
4732
|
uploadKey: reportUploadInfo.uploadKey
|
|
4857
4733
|
});
|
|
4858
4734
|
} catch (e) {
|
|
@@ -4880,7 +4756,10 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4880
4756
|
callback: () => digestSpinner.update({
|
|
4881
4757
|
text: progressMassages.processingVulnerabilityReportSuccess
|
|
4882
4758
|
}),
|
|
4883
|
-
callbackStates: [
|
|
4759
|
+
callbackStates: [
|
|
4760
|
+
"Digested" /* Digested */,
|
|
4761
|
+
"Finished" /* Finished */
|
|
4762
|
+
],
|
|
4884
4763
|
timeoutInMs: VUL_REPORT_DIGEST_TIMEOUT_MS
|
|
4885
4764
|
});
|
|
4886
4765
|
} catch (e) {
|
|
@@ -4904,7 +4783,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4904
4783
|
await uploadFile({
|
|
4905
4784
|
file: zipBuffer,
|
|
4906
4785
|
url: repoUploadInfo.url,
|
|
4907
|
-
uploadFields: repoUploadInfo.
|
|
4786
|
+
uploadFields: JSON.parse(repoUploadInfo.uploadFieldsJSON),
|
|
4908
4787
|
uploadKey: repoUploadInfo.uploadKey
|
|
4909
4788
|
});
|
|
4910
4789
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobbdev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.108",
|
|
4
4
|
"description": "Automated secure code remediation tool",
|
|
5
5
|
"repository": "https://github.com/mobb-dev/bugsy",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
8
8
|
"scripts": {
|
|
9
|
+
"env": "dotenv -e ./.env",
|
|
9
10
|
"postinstall": "node ./src/post_install/cx_install.mjs",
|
|
10
11
|
"build": "tsc && tsup-node --env.NODE_ENV production",
|
|
11
12
|
"build:dev": "tsup-node --env.NODE_ENV development",
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
"lint": "eslint --cache --max-warnings 0 --ignore-path .eslintignore --ext .ts,.tsx,.jsx .",
|
|
15
16
|
"lint:fix": "eslint --fix --cache --max-warnings 0 --ignore-path .eslintignore --ext .js,.ts,.tsx,.jsx .",
|
|
16
17
|
"lint:fix:files": "eslint --fix --cache --max-warnings 0 --ignore-path .eslintignore --ext .js,.ts,.tsx,.jsx",
|
|
17
|
-
"prepack": "dotenv-vault pull production .env && pnpm build"
|
|
18
|
+
"prepack": "dotenv-vault pull production .env && pnpm build",
|
|
19
|
+
"generate": "pnpm run env -- graphql-codegen -r dotenv/config --config client_codegen.ts"
|
|
18
20
|
},
|
|
19
21
|
"bin": {
|
|
20
22
|
"mobbdev": "bin/cli.mjs"
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
"globby": "13.2.2",
|
|
43
45
|
"graphql": "16.8.1",
|
|
44
46
|
"graphql-request": "5.0.0",
|
|
47
|
+
"graphql-tag": "2.12.6",
|
|
45
48
|
"graphql-ws": "5.14.3",
|
|
46
49
|
"inquirer": "9.2.7",
|
|
47
50
|
"isomorphic-ws": "5.0.0",
|
|
@@ -65,6 +68,10 @@
|
|
|
65
68
|
"zod": "3.23.7"
|
|
66
69
|
},
|
|
67
70
|
"devDependencies": {
|
|
71
|
+
"@graphql-codegen/cli": "2.16.5",
|
|
72
|
+
"@graphql-codegen/typescript": "2.7.2",
|
|
73
|
+
"@graphql-codegen/typescript-graphql-request": "4.5.8",
|
|
74
|
+
"@graphql-codegen/typescript-operations": "2.5.5",
|
|
68
75
|
"@octokit/request-error": "3.0.3",
|
|
69
76
|
"@octokit/types": "13.5.0",
|
|
70
77
|
"@types/adm-zip": "0.5.0",
|
|
@@ -93,8 +100,8 @@
|
|
|
93
100
|
"node": ">=12.20.0"
|
|
94
101
|
},
|
|
95
102
|
"files": [
|
|
96
|
-
"bin",
|
|
97
|
-
"dist",
|
|
103
|
+
"bin/cli.mjs",
|
|
104
|
+
"dist/index.mjs",
|
|
98
105
|
".env",
|
|
99
106
|
"src/post_install"
|
|
100
107
|
]
|