mobbdev 0.0.107 → 0.0.110

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.
Files changed (3) hide show
  1. package/.env +4 -2
  2. package/dist/index.mjs +462 -570
  3. package/package.json +11 -4
package/.env CHANGED
@@ -1,7 +1,9 @@
1
- # production@v15
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,335 @@ 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
+ __typename
364
+ ... on InitOrganizationAndProjectGoodResponse {
365
+ projectId
366
+ userId
367
+ organizationId
368
+ }
369
+ ... on UserAlreadyInProjectError {
370
+ error
371
+ status
372
+ }
373
+ }
374
+ }
375
+ `;
376
+ var CreateCliLoginDocument = `
377
+ mutation CreateCliLogin($publicKey: String!) {
378
+ insert_cli_login_one(object: {publicKey: $publicKey}) {
379
+ id
380
+ }
381
+ }
382
+ `;
383
+ var PerformCliLoginDocument = `
384
+ mutation performCliLogin($loginId: String!) {
385
+ performCliLogin(loginId: $loginId) {
386
+ status
387
+ }
388
+ }
389
+ `;
390
+ var CreateProjectDocument = `
391
+ mutation CreateProject($organizationId: String!, $projectName: String!) {
392
+ createProject(organizationId: $organizationId, projectName: $projectName) {
393
+ projectId
394
+ }
395
+ }
396
+ `;
397
+ var defaultWrapper = (action, _operationName, _operationType) => action();
398
+ function getSdk(client, withWrapper = defaultWrapper) {
399
+ return {
400
+ Me(variables, requestHeaders) {
401
+ return withWrapper((wrappedRequestHeaders) => client.request(MeDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "Me", "query");
402
+ },
403
+ getOrgAndProjectId(variables, requestHeaders) {
404
+ return withWrapper((wrappedRequestHeaders) => client.request(GetOrgAndProjectIdDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getOrgAndProjectId", "query");
405
+ },
406
+ GetEncryptedApiToken(variables, requestHeaders) {
407
+ return withWrapper((wrappedRequestHeaders) => client.request(GetEncryptedApiTokenDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "GetEncryptedApiToken", "query");
408
+ },
409
+ FixReportState(variables, requestHeaders) {
410
+ return withWrapper((wrappedRequestHeaders) => client.request(FixReportStateDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "FixReportState", "query");
411
+ },
412
+ GetVulnerabilityReportPaths(variables, requestHeaders) {
413
+ return withWrapper((wrappedRequestHeaders) => client.request(GetVulnerabilityReportPathsDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "GetVulnerabilityReportPaths", "query");
414
+ },
415
+ getAnalysis(variables, requestHeaders) {
416
+ return withWrapper((wrappedRequestHeaders) => client.request(GetAnalysisDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getAnalysis", "subscription");
417
+ },
418
+ getAnalsyis(variables, requestHeaders) {
419
+ return withWrapper((wrappedRequestHeaders) => client.request(GetAnalsyisDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getAnalsyis", "query");
420
+ },
421
+ getFixes(variables, requestHeaders) {
422
+ return withWrapper((wrappedRequestHeaders) => client.request(GetFixesDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getFixes", "query");
423
+ },
424
+ getVulByNodesMetadata(variables, requestHeaders) {
425
+ return withWrapper((wrappedRequestHeaders) => client.request(GetVulByNodesMetadataDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "getVulByNodesMetadata", "query");
426
+ },
427
+ updateScmToken(variables, requestHeaders) {
428
+ return withWrapper((wrappedRequestHeaders) => client.request(UpdateScmTokenDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "updateScmToken", "mutation");
429
+ },
430
+ uploadS3BucketInfo(variables, requestHeaders) {
431
+ return withWrapper((wrappedRequestHeaders) => client.request(UploadS3BucketInfoDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "uploadS3BucketInfo", "mutation");
432
+ },
433
+ DigestVulnerabilityReport(variables, requestHeaders) {
434
+ return withWrapper((wrappedRequestHeaders) => client.request(DigestVulnerabilityReportDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "DigestVulnerabilityReport", "mutation");
435
+ },
436
+ SubmitVulnerabilityReport(variables, requestHeaders) {
437
+ return withWrapper((wrappedRequestHeaders) => client.request(SubmitVulnerabilityReportDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "SubmitVulnerabilityReport", "mutation");
438
+ },
439
+ CreateCommunityUser(variables, requestHeaders) {
440
+ return withWrapper((wrappedRequestHeaders) => client.request(CreateCommunityUserDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "CreateCommunityUser", "mutation");
441
+ },
442
+ CreateCliLogin(variables, requestHeaders) {
443
+ return withWrapper((wrappedRequestHeaders) => client.request(CreateCliLoginDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "CreateCliLogin", "mutation");
444
+ },
445
+ performCliLogin(variables, requestHeaders) {
446
+ return withWrapper((wrappedRequestHeaders) => client.request(PerformCliLoginDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "performCliLogin", "mutation");
447
+ },
448
+ CreateProject(variables, requestHeaders) {
449
+ return withWrapper((wrappedRequestHeaders) => client.request(CreateProjectDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "CreateProject", "mutation");
450
+ }
451
+ };
452
+ }
453
+
121
454
  // src/utils/index.ts
122
455
  var utils_exports = {};
123
456
  __export(utils_exports, {
@@ -250,322 +583,7 @@ import Debug3 from "debug";
250
583
  import { GraphQLClient } from "graphql-request";
251
584
  import { v4 as uuidv4 } from "uuid";
252
585
 
253
- // src/features/analysis/graphql/mutations.ts
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
586
+ // src/features/analysis/graphql/subscribe.ts
569
587
  import { createClient } from "graphql-ws";
570
588
  import WebSocket from "ws";
571
589
  var SUBSCRIPTION_TIMEOUT_MS = 10 * 60 * 1e3;
@@ -647,150 +665,6 @@ function subscribe(query, variables, callback, wsClientOptions) {
647
665
 
648
666
  // src/features/analysis/graphql/types.ts
649
667
  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
668
  var VulnerabilityReportIssueCodeNodeZ = z2.object({
795
669
  vulnerabilityReportIssueId: z2.string(),
796
670
  path: z2.string(),
@@ -826,6 +700,7 @@ var GQLClient = class {
826
700
  constructor(args) {
827
701
  __publicField(this, "_client");
828
702
  __publicField(this, "_apiKey");
703
+ __publicField(this, "_clientSdk");
829
704
  const { apiKey } = args;
830
705
  this._apiKey = apiKey;
831
706
  debug3(`init with apiKey ${apiKey}`);
@@ -845,23 +720,18 @@ var GQLClient = class {
845
720
  };
846
721
  }
847
722
  });
723
+ this._clientSdk = getSdk(this._client);
848
724
  }
849
725
  async getUserInfo() {
850
- const { me } = await this._client.request(ME);
726
+ const { me } = await this._clientSdk.Me();
851
727
  return me;
852
728
  }
853
729
  async createCliLogin(variables) {
854
- const res = CreateCliLoginZ.parse(
855
- await this._client.request(
856
- CREATE_CLI_LOGIN,
857
- variables,
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;
730
+ const res = await this._clientSdk.CreateCliLogin(variables, {
731
+ // We may have outdated API key in the config storage. Avoid using it for the login request.
732
+ [API_KEY_HEADER_NAME]: ""
733
+ });
734
+ return res.insert_cli_login_one?.id || "";
865
735
  }
866
736
  async verifyToken() {
867
737
  await this.createCommunityUser();
@@ -874,23 +744,21 @@ var GQLClient = class {
874
744
  return true;
875
745
  }
876
746
  async getOrgAndProjectId(projectName) {
877
- const getOrgAndProjectIdResult = await this._client.request(
878
- GET_ORG_AND_PROJECT_ID
879
- );
880
- const [user] = GetOrgAndProjectIdQueryZ.parse(
881
- getOrgAndProjectIdResult
882
- ).users;
883
- const org = user.userOrganizationsAndUserOrganizationRoles[0].organization;
884
- const project = projectName ? org.projects.find((project2) => project2.name === projectName) ?? null : org.projects[0];
747
+ const getOrgAndProjectIdResult = await this._clientSdk.getOrgAndProjectId();
748
+ const org = getOrgAndProjectIdResult?.users?.at(0)?.userOrganizationsAndUserOrganizationRoles?.at(0)?.organization;
749
+ if (!org?.id) {
750
+ throw new Error("Organization not found");
751
+ }
752
+ const project = projectName ? org?.projects.find((project2) => project2.name === projectName) ?? null : org?.projects[0];
753
+ if (!project?.id) {
754
+ throw new Error("Project not found");
755
+ }
885
756
  let projectId = project?.id;
886
757
  if (!projectId) {
887
- const createdProject = await this._client.request(
888
- CREATE_PROJECT,
889
- {
890
- organizationId: org.id,
891
- projectName: projectName || "My project"
892
- }
893
- );
758
+ const createdProject = await this._clientSdk.CreateProject({
759
+ organizationId: org.id,
760
+ projectName: projectName || "My project"
761
+ });
894
762
  projectId = createdProject.createProject.projectId;
895
763
  }
896
764
  return {
@@ -899,26 +767,22 @@ var GQLClient = class {
899
767
  };
900
768
  }
901
769
  async getEncryptedApiToken(variables) {
902
- const res = await this._client.request(
903
- GET_ENCRYPTED_API_TOKEN,
904
- variables,
905
- {
906
- // We may have outdated API key in the config storage. Avoid using it for the login request.
907
- [API_KEY_HEADER_NAME]: ""
908
- }
909
- );
910
- return GetEncryptedApiTokenZ.parse(res).cli_login_by_pk.encryptedApiToken;
770
+ const res = await this._clientSdk.GetEncryptedApiToken(variables, {
771
+ // We may have outdated API key in the config storage. Avoid using it for the login request.
772
+ [API_KEY_HEADER_NAME]: ""
773
+ });
774
+ return res?.cli_login_by_pk?.encryptedApiToken || null;
911
775
  }
912
776
  async createCommunityUser() {
913
777
  try {
914
- await this._client.request(CREATE_COMMUNITY_USER);
778
+ await this._clientSdk.CreateCommunityUser();
915
779
  } catch (e) {
916
780
  debug3("create community user failed %o", e);
917
781
  }
918
782
  }
919
783
  async updateScmToken(args) {
920
784
  const { scmType, url, token, org, username, refreshToken } = args;
921
- const updateScmTokenResult = await this._client.request(UPDATE_SCM_TOKEN, {
785
+ const updateScmTokenResult = await this._clientSdk.updateScmToken({
922
786
  scmType,
923
787
  url,
924
788
  token,
@@ -926,13 +790,13 @@ var GQLClient = class {
926
790
  username,
927
791
  refreshToken
928
792
  });
929
- return UpdateScmTokenZ.parse(updateScmTokenResult);
793
+ return updateScmTokenResult;
930
794
  }
931
795
  async uploadS3BucketInfo() {
932
- const uploadS3BucketInfoResult = await this._client.request(UPLOAD_S3_BUCKET_INFO, {
796
+ const uploadS3BucketInfoResult = await this._clientSdk.uploadS3BucketInfo({
933
797
  fileName: "report.json"
934
798
  });
935
- return UploadS3BucketInfoZ.parse(uploadS3BucketInfoResult);
799
+ return uploadS3BucketInfoResult;
936
800
  }
937
801
  async getVulByNodesMetadata({
938
802
  hunks,
@@ -948,7 +812,7 @@ var GQLClient = class {
948
812
  };
949
813
  return filter;
950
814
  });
951
- const getVulByNodesMetadataRes = await this._client.request(GET_VUL_BY_NODES_METADATA, {
815
+ const getVulByNodesMetadataRes = await this._clientSdk.getVulByNodesMetadata({
952
816
  filters: { _or: filters },
953
817
  vulnerabilityReportId
954
818
  });
@@ -984,15 +848,15 @@ var GQLClient = class {
984
848
  fixReportId,
985
849
  projectId
986
850
  }) {
987
- const res = await this._client.request(
988
- DIGEST_VULNERABILITY_REPORT,
989
- {
990
- fixReportId,
991
- vulnerabilityReportFileName: "report.json",
992
- projectId
993
- }
994
- );
995
- return DigestVulnerabilityReportZ.parse(res).digestVulnerabilityReport;
851
+ const res = await this._clientSdk.DigestVulnerabilityReport({
852
+ fixReportId,
853
+ vulnerabilityReportFileName: "report.json",
854
+ projectId
855
+ });
856
+ if (res.digestVulnerabilityReport.__typename !== "VulnerabilityReport") {
857
+ throw new Error("Digesting vulnerability report failed");
858
+ }
859
+ return res.digestVulnerabilityReport;
996
860
  }
997
861
  async submitVulnerabilityReport(params) {
998
862
  const {
@@ -1005,7 +869,7 @@ var GQLClient = class {
1005
869
  vulnerabilityReportFileName,
1006
870
  pullRequest
1007
871
  } = params;
1008
- const res = await this._client.request(SUBMIT_VULNERABILITY_REPORT, {
872
+ const res = await this._clientSdk.SubmitVulnerabilityReport({
1009
873
  fixReportId,
1010
874
  repoUrl,
1011
875
  reference,
@@ -1015,21 +879,21 @@ var GQLClient = class {
1015
879
  sha: sha || "",
1016
880
  experimentalEnabled
1017
881
  });
1018
- return CreateUpdateFixReportMutationZ.parse(res);
882
+ return res;
1019
883
  }
1020
884
  async getFixReportState(fixReportId) {
1021
- const res = await this._client.request(
1022
- GET_FIX_REPORT_STATE,
1023
- { id: fixReportId }
1024
- );
1025
- return GetFixReportZ.parse(res).fixReport_by_pk.state;
885
+ const res = await this._clientSdk.FixReportState({ id: fixReportId });
886
+ return res?.fixReport_by_pk?.state || "Created" /* Created */;
1026
887
  }
1027
888
  async waitFixReportInit(fixReportId, includeDigested = false) {
1028
- const FINAL_STATES = ["Finished", "Failed"];
1029
- let lastState = "Created";
889
+ const FINAL_STATES = [
890
+ "Finished" /* Finished */,
891
+ "Failed" /* Failed */
892
+ ];
893
+ let lastState = "Created" /* Created */;
1030
894
  let attempts = 100;
1031
895
  if (includeDigested) {
1032
- FINAL_STATES.push("Digested");
896
+ FINAL_STATES.push("Digested" /* Digested */);
1033
897
  }
1034
898
  do {
1035
899
  await sleep(REPORT_STATE_CHECK_DELAY);
@@ -1041,23 +905,20 @@ var GQLClient = class {
1041
905
  return lastState;
1042
906
  }
1043
907
  async getVulnerabilityReportPaths(vulnerabilityReportId) {
1044
- const res = await this._client.request(
1045
- GET_VULNERABILITY_REPORT_PATHS,
1046
- { vulnerabilityReportId }
1047
- );
1048
- return GetVulnerabilityReportPathsZ.parse(
1049
- res
1050
- ).vulnerability_report_path.map((p) => p.path);
908
+ const res = await this._clientSdk.GetVulnerabilityReportPaths({
909
+ vulnerabilityReportId
910
+ });
911
+ return res.vulnerability_report_path.map((p) => p.path);
1051
912
  }
1052
913
  async subscribeToAnalysis(params) {
1053
914
  const { callbackStates } = params;
1054
915
  return subscribe(
1055
- SUBSCRIBE_TO_ANALYSIS,
916
+ GetAnalysisDocument,
1056
917
  params.subscribeToAnalysisParams,
1057
918
  async (resolve, reject, data) => {
1058
- if (data.analysis.state === "Failed") {
919
+ if (!data.analysis?.state || data.analysis?.state === "Failed" /* Failed */) {
1059
920
  reject(data);
1060
- throw new Error(`Analysis failed with id: ${data.analysis.id}`);
921
+ throw new Error(`Analysis failed with id: ${data.analysis?.id}`);
1061
922
  }
1062
923
  if (callbackStates.includes(data.analysis?.state)) {
1063
924
  await params.callback(data.analysis.id);
@@ -1071,28 +932,19 @@ var GQLClient = class {
1071
932
  );
1072
933
  }
1073
934
  async getAnalysis(analysisId) {
1074
- const res = await this._client.request(GET_ANALYSIS, {
935
+ const res = await this._clientSdk.getAnalsyis({
1075
936
  analysisId
1076
937
  });
1077
- return GetAnalysisQueryZ.parse(res);
1078
- }
1079
- async getFix(fixId) {
1080
- const res = await this._client.request(
1081
- GET_FIX,
1082
- {
1083
- fixId
1084
- }
1085
- );
1086
- return GetFixQueryZ.parse(res);
938
+ if (!res.analysis) {
939
+ throw new Error(`Analysis not found: ${analysisId}`);
940
+ }
941
+ return res.analysis;
1087
942
  }
1088
943
  async getFixes(fixIds) {
1089
- const res = await this._client.request(
1090
- GET_FIXES,
1091
- {
1092
- filters: { id: { _in: fixIds } }
1093
- }
1094
- );
1095
- return GetFixesQueryZ.parse(res);
944
+ const res = await this._clientSdk.getFixes({
945
+ filters: { id: { _in: fixIds } }
946
+ });
947
+ return res;
1096
948
  }
1097
949
  };
1098
950
 
@@ -3740,31 +3592,44 @@ async function sendReport({
3740
3592
  gqlClient
3741
3593
  }) {
3742
3594
  try {
3743
- const sumbitRes = await gqlClient.submitVulnerabilityReport(
3595
+ const submitRes = await gqlClient.submitVulnerabilityReport(
3744
3596
  submitVulnerabilityReportVariables
3745
3597
  );
3746
- if (sumbitRes.submitVulnerabilityReport.__typename !== "VulnerabilityReport") {
3747
- debug4("error submit vul report %s", sumbitRes);
3598
+ if (submitRes.submitVulnerabilityReport.__typename !== "VulnerabilityReport") {
3599
+ debug4("error submit vul report %s", submitRes);
3748
3600
  throw new Error("\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed");
3749
3601
  }
3750
3602
  spinner.update({ text: progressMassages.processingVulnerabilityReport });
3751
3603
  await gqlClient.subscribeToAnalysis({
3752
3604
  subscribeToAnalysisParams: {
3753
- analysisId: sumbitRes.submitVulnerabilityReport.fixReportId
3605
+ analysisId: submitRes.submitVulnerabilityReport.fixReportId
3754
3606
  },
3755
3607
  callback: () => spinner.update({
3756
- text: "\u2699\uFE0F Vulnerability report proccessed successfuly"
3608
+ text: "\u2699\uFE0F Vulnerability report processed successfully"
3757
3609
  }),
3758
- callbackStates: ["Digested", "Finished"],
3610
+ callbackStates: [
3611
+ "Digested" /* Digested */,
3612
+ "Finished" /* Finished */
3613
+ ],
3759
3614
  timeoutInMs: VUL_REPORT_DIGEST_TIMEOUT_MS
3760
3615
  });
3761
- return sumbitRes;
3616
+ return submitRes;
3762
3617
  } catch (e) {
3763
3618
  spinner.error({ text: "\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed" });
3764
3619
  throw e;
3765
3620
  }
3766
3621
  }
3767
3622
 
3623
+ // src/features/analysis/utils/index.ts
3624
+ function getFromArraySafe(array) {
3625
+ return array.reduce((acc, nullableItem) => {
3626
+ if (nullableItem) {
3627
+ acc.push(nullableItem);
3628
+ }
3629
+ return acc;
3630
+ }, []);
3631
+ }
3632
+
3768
3633
  // src/features/analysis/handle_finished_analysis.ts
3769
3634
  var debug5 = Debug5("mobbdev:handle-finished-analysis");
3770
3635
  var contactUsMarkdown = `For specific requests [contact us](https://mobb.ai/contact) and we'll do the most to answer your need quickly.`;
@@ -3824,7 +3689,7 @@ function buildAnalysisSummaryComment(params) {
3824
3689
  if (!fix) {
3825
3690
  throw new Error(`fix ${vulnerabilityReportIssue.fixId} not found`);
3826
3691
  }
3827
- const issueType = getIssueType(fix.issueType);
3692
+ const issueType = getIssueType(fix.issueType ?? null);
3828
3693
  const vulnerabilityReportIssueCount = (result[issueType] || 0) + 1;
3829
3694
  return {
3830
3695
  ...result,
@@ -3855,13 +3720,16 @@ async function handleFinishedAnalysis({
3855
3720
  projectId,
3856
3721
  project: { organizationId }
3857
3722
  }
3858
- } = getAnalysis.analysis;
3859
- const { commitSha, pullRequest } = getAnalysis.analysis.repo;
3723
+ } = getAnalysis;
3724
+ if (!getAnalysis.repo || !getAnalysis.repo.commitSha || !getAnalysis.repo.pullRequest) {
3725
+ throw new Error("repo not found");
3726
+ }
3727
+ const { commitSha, pullRequest } = getAnalysis.repo;
3860
3728
  const diff = await scm.getPrDiff({ pull_number: pullRequest });
3861
3729
  const prVulenrabilities = await getRelevantVulenrabilitiesFromDiff({
3862
3730
  diff,
3863
3731
  gqlClient,
3864
- vulnerabilityReportId: getAnalysis.analysis.vulnerabilityReportId
3732
+ vulnerabilityReportId: getAnalysis.vulnerabilityReportId
3865
3733
  });
3866
3734
  const { vulnerabilityReportIssueCodeNodes } = prVulenrabilities;
3867
3735
  const fixesId = vulnerabilityReportIssueCodeNodes.map(
@@ -3935,7 +3803,7 @@ async function handleFinishedAnalysis({
3935
3803
  vulnerabilityReportIssue: { fixId }
3936
3804
  } = vulnerabilityReportIssueCodeNode;
3937
3805
  const fix = fixesById[fixId];
3938
- if (!fix) {
3806
+ if (!fix || fix.patchAndQuestions.__typename !== "FixData") {
3939
3807
  throw new Error(`fix ${fixId} not found`);
3940
3808
  }
3941
3809
  const {
@@ -3971,7 +3839,7 @@ async function handleFinishedAnalysis({
3971
3839
  commentId
3972
3840
  });
3973
3841
  const scanerString = scannerToFriendlyString(scanner);
3974
- const issueType = getIssueType(fix.issueType);
3842
+ const issueType = getIssueType(fix.issueType ?? null);
3975
3843
  const title = `# ${MobbIconMarkdown} ${issueType} fix is ready`;
3976
3844
  const subTitle = `### Apply the following code change to fix ${issueType} issue detected by **${scanerString}**:`;
3977
3845
  const diff2 = `\`\`\`diff
@@ -4594,6 +4462,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
4594
4462
  const {
4595
4463
  uploadS3BucketInfo: { repoUploadInfo, reportUploadInfo }
4596
4464
  } = await gqlClient.uploadS3BucketInfo();
4465
+ if (!reportUploadInfo || !repoUploadInfo) {
4466
+ throw new Error("uploadS3BucketInfo is null");
4467
+ }
4597
4468
  let reportPath = scanFile;
4598
4469
  if (srcPath) {
4599
4470
  return await uploadExistingRepo();
@@ -4602,9 +4473,13 @@ async function _scan(params, { skipPrompts = false } = {}) {
4602
4473
  throw new Error("repo is required in case srcPath is not provided");
4603
4474
  }
4604
4475
  const userInfo = await gqlClient.getUserInfo();
4476
+ if (!userInfo) {
4477
+ throw new Error("userInfo is null");
4478
+ }
4479
+ const scmConfigs = getFromArraySafe(userInfo.scmConfigs);
4605
4480
  const tokenInfo = getScmConfig({
4606
4481
  url: repo,
4607
- scmConfigs: userInfo.scmConfigs,
4482
+ scmConfigs,
4608
4483
  includeOrgTokens: false
4609
4484
  });
4610
4485
  const isRepoAvailable = await scmCanReachRepo({
@@ -4667,7 +4542,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
4667
4542
  await uploadFile({
4668
4543
  file: reportPath,
4669
4544
  url: reportUploadInfo.url,
4670
- uploadFields: reportUploadInfo.uploadFields,
4545
+ uploadFields: JSON.parse(reportUploadInfo.uploadFieldsJSON),
4671
4546
  uploadKey: reportUploadInfo.uploadKey
4672
4547
  });
4673
4548
  } catch (e) {
@@ -4690,6 +4565,10 @@ async function _scan(params, { skipPrompts = false } = {}) {
4690
4565
  pullRequest: params.pullRequest
4691
4566
  }
4692
4567
  });
4568
+ if (sendReportRes.submitVulnerabilityReport.__typename !== "VulnerabilityReport") {
4569
+ mobbSpinner.error({ text: "\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed" });
4570
+ throw new Error("\u{1F575}\uFE0F\u200D\u2642\uFE0F Mobb analysis failed");
4571
+ }
4693
4572
  if (command === "review") {
4694
4573
  await gqlClient.subscribeToAnalysis({
4695
4574
  subscribeToAnalysisParams: {
@@ -4702,7 +4581,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
4702
4581
  githubActionToken: z11.string().parse(githubActionToken),
4703
4582
  scanner: z11.nativeEnum(SCANNERS).parse(scanner)
4704
4583
  }),
4705
- callbackStates: ["Finished"]
4584
+ callbackStates: ["Finished" /* Finished */]
4706
4585
  });
4707
4586
  }
4708
4587
  mobbSpinner.success({
@@ -4733,6 +4612,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
4733
4612
  return reportPath2;
4734
4613
  }
4735
4614
  async function askToOpenAnalysis() {
4615
+ if (!repoUploadInfo || !reportUploadInfo) {
4616
+ throw new Error("uploadS3BucketInfo is null");
4617
+ }
4736
4618
  const reportUrl = getReportUrl({
4737
4619
  organizationId,
4738
4620
  projectId,
@@ -4826,9 +4708,13 @@ async function _scan(params, { skipPrompts = false } = {}) {
4826
4708
  await open2(scmAuthUrl2);
4827
4709
  for (let i = 0; i < LOGIN_MAX_WAIT / LOGIN_CHECK_DELAY; i++) {
4828
4710
  const userInfo2 = await gqlClient.getUserInfo();
4711
+ if (!userInfo2) {
4712
+ throw new CliError2("User info not found");
4713
+ }
4714
+ const scmConfigs2 = getFromArraySafe(userInfo2.scmConfigs);
4829
4715
  const tokenInfo2 = getScmConfig({
4830
4716
  url: repoUrl,
4831
- scmConfigs: userInfo2.scmConfigs,
4717
+ scmConfigs: scmConfigs2,
4832
4718
  includeOrgTokens: false
4833
4719
  });
4834
4720
  if (tokenInfo2.accessToken && tokenInfo2.accessToken !== oldToken) {
@@ -4844,6 +4730,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
4844
4730
  throw new CliError2(`${scmName} login timeout`);
4845
4731
  }
4846
4732
  async function uploadExistingRepo() {
4733
+ if (!repoUploadInfo || !reportUploadInfo) {
4734
+ throw new Error("uploadS3BucketInfo is null");
4735
+ }
4847
4736
  if (!srcPath || !reportPath) {
4848
4737
  throw new Error("src path and reportPath is required");
4849
4738
  }
@@ -4852,7 +4741,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
4852
4741
  await uploadFile({
4853
4742
  file: reportPath,
4854
4743
  url: reportUploadInfo.url,
4855
- uploadFields: reportUploadInfo.uploadFields,
4744
+ uploadFields: JSON.parse(reportUploadInfo.uploadFieldsJSON),
4856
4745
  uploadKey: reportUploadInfo.uploadKey
4857
4746
  });
4858
4747
  } catch (e) {
@@ -4880,7 +4769,10 @@ async function _scan(params, { skipPrompts = false } = {}) {
4880
4769
  callback: () => digestSpinner.update({
4881
4770
  text: progressMassages.processingVulnerabilityReportSuccess
4882
4771
  }),
4883
- callbackStates: ["Digested", "Finished"],
4772
+ callbackStates: [
4773
+ "Digested" /* Digested */,
4774
+ "Finished" /* Finished */
4775
+ ],
4884
4776
  timeoutInMs: VUL_REPORT_DIGEST_TIMEOUT_MS
4885
4777
  });
4886
4778
  } catch (e) {
@@ -4904,7 +4796,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
4904
4796
  await uploadFile({
4905
4797
  file: zipBuffer,
4906
4798
  url: repoUploadInfo.url,
4907
- uploadFields: repoUploadInfo.uploadFields,
4799
+ uploadFields: JSON.parse(repoUploadInfo.uploadFieldsJSON),
4908
4800
  uploadKey: repoUploadInfo.uploadKey
4909
4801
  });
4910
4802
  } catch (e) {
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.107",
3
+ "version": "0.0.110",
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
  ]