mobbdev 0.0.10 → 0.0.11

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 CHANGED
@@ -1,4 +1,5 @@
1
- # production@v3
1
+ # production@v5
2
2
  WEB_LOGIN_URL="https://app.mobb.dev/cli-login"
3
3
  WEB_REPORT_URL="https://app.mobb.dev/report/"
4
- API_URL="https://api.mobb.dev/v1/graphql"
4
+ API_URL="https://api.mobb.dev/v1/graphql"
5
+ WEB_APP_URL="https://app.mobb.dev"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
package/src/constants.mjs CHANGED
@@ -9,7 +9,7 @@ dotenv.config({ path: path.join(__dirname, '../.env') });
9
9
  const envVariablesSchema = z
10
10
  .object({
11
11
  WEB_LOGIN_URL: z.string(),
12
- WEB_REPORT_URL: z.string(),
12
+ WEB_APP_URL: z.string(),
13
13
  API_URL: z.string(),
14
14
  })
15
15
  .required();
@@ -17,5 +17,5 @@ const envVariablesSchema = z
17
17
  const envVariables = envVariablesSchema.parse(process.env);
18
18
 
19
19
  export const WEB_LOGIN_URL = envVariables.WEB_LOGIN_URL;
20
- export const WEB_REPORT_URL = envVariables.WEB_REPORT_URL;
20
+ export const WEB_APP_URL = envVariables.WEB_APP_URL;
21
21
  export const API_URL = envVariables.API_URL;
package/src/gql.mjs CHANGED
@@ -2,18 +2,28 @@ import fetch from 'node-fetch';
2
2
  import { API_URL } from './constants.mjs';
3
3
 
4
4
  const ME = `
5
- query me {
6
- me {
5
+ query Me {
6
+ user {
7
+ id
7
8
  email
8
- projectId
9
+ userOrganizations {
10
+ organization {
11
+ id
12
+ projects {
13
+ id
14
+ }
15
+ }
16
+ }
9
17
  }
10
18
  }
11
19
  `;
12
20
 
13
21
  const CREATE_COMMUNITY_USER = `
14
22
  mutation CreateCommunityUser {
15
- createCommunityUser {
16
- status
23
+ initOrganizationAndProject {
24
+ userId
25
+ projectId
26
+ organizationId
17
27
  }
18
28
  }
19
29
  `;
@@ -34,13 +44,13 @@ mutation uploadS3BucketInfo($fileName: String!) {
34
44
  `;
35
45
 
36
46
  const SUBMIT_VULNERABILITY_REPORT = `
37
- mutation SubmitVulnerabilityReport($vulnerabilityReportFileName: String!, $fixReportId: String!, $repoUrl: String!, $reference: String!) {
47
+ mutation SubmitVulnerabilityReport($vulnerabilityReportFileName: String!, $fixReportId: String!, $repoUrl: String!, $reference: String!, $projectId: String!) {
38
48
  submitVulnerabilityReport(
39
49
  fixReportId: $fixReportId
40
50
  repoUrl: $repoUrl
41
51
  reference: $reference
42
52
  vulnerabilityReportFileName: $vulnerabilityReportFileName
43
- githubAuthToken: null
53
+ projectId: $projectId
44
54
  ) {
45
55
  __typename
46
56
  }
@@ -50,6 +60,8 @@ mutation SubmitVulnerabilityReport($vulnerabilityReportFileName: String!, $fixRe
50
60
  export class GQLClient {
51
61
  constructor(token) {
52
62
  this._token = token;
63
+ this._projectId = undefined;
64
+ this._organizationId = undefined;
53
65
  }
54
66
 
55
67
  async _apiCall(query, variables = {}) {
@@ -81,11 +93,30 @@ export class GQLClient {
81
93
  return data.data;
82
94
  }
83
95
 
96
+ getOrganizationId() {
97
+ return this._organizationId;
98
+ }
99
+
100
+ getProjectId() {
101
+ return this._projectId;
102
+ }
103
+
84
104
  async verifyToken() {
85
105
  await this.createCommunityUser();
86
106
 
87
107
  try {
88
- await this._apiCall(ME);
108
+ const userInfo = await this._apiCall(ME);
109
+ const {
110
+ user: [{ userOrganizations }],
111
+ } = userInfo;
112
+ const [
113
+ {
114
+ organization: { id: organizationId, projects },
115
+ },
116
+ ] = userOrganizations;
117
+ const [{ id: projectId }] = projects;
118
+ this._projectId = projectId;
119
+ this._organizationId = organizationId;
89
120
  } catch (e) {
90
121
  return false;
91
122
  }
@@ -121,6 +152,7 @@ export class GQLClient {
121
152
  repoUrl,
122
153
  reference,
123
154
  vulnerabilityReportFileName: 'report.json',
155
+ projectId: this._projectId,
124
156
  });
125
157
  }
126
158
  }
package/src/index.mjs CHANGED
@@ -9,7 +9,7 @@ import { webLogin } from './web-login.mjs';
9
9
  import { downloadRepo, getDefaultBranch } from './github.mjs';
10
10
  import { getSnykReport } from './snyk.mjs';
11
11
  import { uploadFile } from './upload-file.mjs';
12
- import { WEB_REPORT_URL } from './constants.mjs';
12
+ import { WEB_APP_URL } from './constants.mjs';
13
13
 
14
14
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
15
  const packageJson = JSON.parse(
@@ -82,6 +82,10 @@ export async function main(dirname, repoUrl) {
82
82
  console.log(
83
83
  'You will be redirected to our report page, please wait until the analysis is finished and enjoy your fixes.'
84
84
  );
85
- await open(`${WEB_REPORT_URL}${uploadData.fixReportId}`);
85
+ const projectId = gqlClient.getProjectId();
86
+ const organizationId = gqlClient.getOrganizationId();
87
+ await open(
88
+ `${WEB_APP_URL}/organization/${organizationId}/project/${projectId}/report/${uploadData.fixReportId}`
89
+ );
86
90
  }
87
91
  }