mobbdev 0.0.167 → 0.0.169

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 (2) hide show
  1. package/dist/index.mjs +132 -82
  2. package/package.json +14 -10
package/dist/index.mjs CHANGED
@@ -3637,7 +3637,7 @@ function getFetch(url) {
3637
3637
  }
3638
3638
  return fetch2;
3639
3639
  }
3640
- function getOktoKit(options) {
3640
+ function getOctoKit(options) {
3641
3641
  const token = !options?.auth && !isGithubOnPrem(options?.url) ? GITHUB_API_TOKEN : options?.auth;
3642
3642
  const baseUrl = options?.url && isGithubOnPrem(options.url) ? `${new URL(options.url).origin}/api/v3` : void 0;
3643
3643
  return new Octokit({
@@ -3654,7 +3654,7 @@ function isGithubActionActionToken(token) {
3654
3654
  }
3655
3655
  async function githubValidateParams(url, accessToken) {
3656
3656
  try {
3657
- const oktoKit = getOktoKit({ auth: accessToken, url });
3657
+ const oktoKit = getOctoKit({ auth: accessToken, url });
3658
3658
  if (accessToken && !isGithubActionActionToken(accessToken)) {
3659
3659
  await oktoKit.rest.users.getAuthenticated();
3660
3660
  }
@@ -3681,57 +3681,57 @@ async function githubValidateParams(url, accessToken) {
3681
3681
  }
3682
3682
 
3683
3683
  // src/features/analysis/scm/github/github.ts
3684
- function getGithubSdk(parmas = {}) {
3685
- const octokit = getOktoKit(parmas);
3684
+ function getGithubSdk(params = {}) {
3685
+ const octokit = getOctoKit(params);
3686
3686
  return {
3687
- async postPrComment(params) {
3688
- return octokit.request(POST_COMMENT_PATH, params);
3687
+ async postPrComment(params2) {
3688
+ return octokit.request(POST_COMMENT_PATH, params2);
3689
3689
  },
3690
- async updatePrComment(params) {
3691
- return octokit.request(UPDATE_COMMENT_PATH, params);
3690
+ async updatePrComment(params2) {
3691
+ return octokit.request(UPDATE_COMMENT_PATH, params2);
3692
3692
  },
3693
- async getPrComments(params) {
3694
- return octokit.request(GET_PR_COMMENTS_PATH, params);
3693
+ async getPrComments(params2) {
3694
+ return octokit.request(GET_PR_COMMENTS_PATH, params2);
3695
3695
  },
3696
- async getPrComment(params) {
3697
- return octokit.request(GET_PR_COMMENT_PATH, params);
3696
+ async getPrComment(params2) {
3697
+ return octokit.request(GET_PR_COMMENT_PATH, params2);
3698
3698
  },
3699
- async deleteComment(params) {
3700
- return octokit.request(DELETE_COMMENT_PATH, params);
3699
+ async deleteComment(params2) {
3700
+ return octokit.request(DELETE_COMMENT_PATH, params2);
3701
3701
  },
3702
- async replyToCodeReviewComment(params) {
3703
- return octokit.request(REPLY_TO_CODE_REVIEW_COMMENT_PATH, params);
3702
+ async replyToCodeReviewComment(params2) {
3703
+ return octokit.request(REPLY_TO_CODE_REVIEW_COMMENT_PATH, params2);
3704
3704
  },
3705
- async getPrDiff(params) {
3705
+ async getPrDiff(params2) {
3706
3706
  return octokit.request(GET_PR, {
3707
- ...params,
3707
+ ...params2,
3708
3708
  mediaType: { format: "diff" }
3709
3709
  });
3710
3710
  },
3711
- async getPr(params) {
3712
- return octokit.request(GET_PR, { ...params });
3711
+ async getPr(params2) {
3712
+ return octokit.request(GET_PR, { ...params2 });
3713
3713
  },
3714
- async createOrUpdateRepositorySecret(params) {
3715
- return octokit.request(CREATE_OR_UPDATE_A_REPOSITORY_SECRET, params);
3714
+ async createOrUpdateRepositorySecret(params2) {
3715
+ return octokit.request(CREATE_OR_UPDATE_A_REPOSITORY_SECRET, params2);
3716
3716
  },
3717
- async getRepositoryPublicKey(params) {
3718
- return octokit.request(GET_A_REPOSITORY_PUBLIC_KEY, params);
3717
+ async getRepositoryPublicKey(params2) {
3718
+ return octokit.request(GET_A_REPOSITORY_PUBLIC_KEY, params2);
3719
3719
  },
3720
- async postGeneralPrComment(params) {
3721
- return octokit.request(POST_GENERAL_PR_COMMENT, params);
3720
+ async postGeneralPrComment(params2) {
3721
+ return octokit.request(POST_GENERAL_PR_COMMENT, params2);
3722
3722
  },
3723
- async getGeneralPrComments(params) {
3724
- return octokit.request(GET_GENERAL_PR_COMMENTS, params);
3723
+ async getGeneralPrComments(params2) {
3724
+ return octokit.request(GET_GENERAL_PR_COMMENTS, params2);
3725
3725
  },
3726
- async deleteGeneralPrComment(params) {
3727
- return octokit.request(DELETE_GENERAL_PR_COMMENT, params);
3726
+ async deleteGeneralPrComment(params2) {
3727
+ return octokit.request(DELETE_GENERAL_PR_COMMENT, params2);
3728
3728
  },
3729
3729
  async getGithubUsername() {
3730
3730
  const res = await octokit.rest.users.getAuthenticated();
3731
3731
  return res.data.login;
3732
3732
  },
3733
- async getGithubIsUserCollaborator(params) {
3734
- const { username, repoUrl } = params;
3733
+ async getGithubIsUserCollaborator(params2) {
3734
+ const { username, repoUrl } = params2;
3735
3735
  try {
3736
3736
  const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
3737
3737
  const res = await octokit.rest.repos.checkCollaborator({
@@ -3747,8 +3747,8 @@ function getGithubSdk(parmas = {}) {
3747
3747
  }
3748
3748
  return false;
3749
3749
  },
3750
- async getGithubPullRequestStatus(params) {
3751
- const { repoUrl, prNumber } = params;
3750
+ async getGithubPullRequestStatus(params2) {
3751
+ const { repoUrl, prNumber } = params2;
3752
3752
  const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
3753
3753
  const res = await octokit.rest.pulls.get({
3754
3754
  owner,
@@ -3763,8 +3763,8 @@ function getGithubSdk(parmas = {}) {
3763
3763
  }
3764
3764
  return res.data.state;
3765
3765
  },
3766
- async getGithubIsRemoteBranch(params) {
3767
- const { repoUrl, branch } = params;
3766
+ async getGithubIsRemoteBranch(params2) {
3767
+ const { repoUrl, branch } = params2;
3768
3768
  const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
3769
3769
  try {
3770
3770
  const res = await octokit.rest.repos.getBranch({
@@ -3891,8 +3891,8 @@ function getGithubSdk(parmas = {}) {
3891
3891
  sha: res.data.sha
3892
3892
  };
3893
3893
  },
3894
- async getGithubBlameRanges(params) {
3895
- const { ref, gitHubUrl, path: path9 } = params;
3894
+ async getGithubBlameRanges(params2) {
3895
+ const { ref, gitHubUrl, path: path9 } = params2;
3896
3896
  const { owner, repo } = parseGithubOwnerAndRepo(gitHubUrl);
3897
3897
  const res = await octokit.graphql(
3898
3898
  GET_BLAME_DOCUMENT,
@@ -3915,8 +3915,8 @@ function getGithubSdk(parmas = {}) {
3915
3915
  }));
3916
3916
  },
3917
3917
  // todo: refactor the name for this function
3918
- async createPr(params) {
3919
- const { sourceRepoUrl, filesPaths, userRepoUrl, title, body } = params;
3918
+ async createPr(params2) {
3919
+ const { sourceRepoUrl, filesPaths, userRepoUrl, title, body } = params2;
3920
3920
  const { owner: sourceOwner, repo: sourceRepo } = parseGithubOwnerAndRepo(sourceRepoUrl);
3921
3921
  const { owner, repo } = parseGithubOwnerAndRepo(userRepoUrl);
3922
3922
  const [sourceFilePath, secondFilePath] = filesPaths;
@@ -4042,10 +4042,17 @@ function getGithubSdk(parmas = {}) {
4042
4042
 
4043
4043
  // src/features/analysis/scm/gitlab/gitlab.ts
4044
4044
  import querystring2 from "node:querystring";
4045
+ import { setTimeout as setTimeout2 } from "node:timers/promises";
4046
+ import {
4047
+ createRequesterFn
4048
+ } from "@gitbeaker/requester-utils";
4045
4049
  import {
4046
4050
  Gitlab
4047
4051
  } from "@gitbeaker/rest";
4048
- import { ProxyAgent as ProxyAgent2 } from "undici";
4052
+ import {
4053
+ fetch as undiciFetch,
4054
+ ProxyAgent as ProxyAgent2
4055
+ } from "undici";
4049
4056
 
4050
4057
  // src/features/analysis/scm/gitlab/types.ts
4051
4058
  import { z as z12 } from "zod";
@@ -4065,9 +4072,23 @@ function getGitBeaker(options) {
4065
4072
  const url = options.url;
4066
4073
  const host = url ? new URL(url).origin : "https://gitlab.com";
4067
4074
  if (token?.startsWith("glpat-") || token === "") {
4068
- return new Gitlab({ token, host });
4075
+ return new Gitlab({
4076
+ token,
4077
+ host,
4078
+ requesterFn: createRequesterFn(
4079
+ (_, reqo) => Promise.resolve(reqo),
4080
+ brokerRequestHandler
4081
+ )
4082
+ });
4069
4083
  }
4070
- return new Gitlab({ oauthToken: token, host });
4084
+ return new Gitlab({
4085
+ oauthToken: token,
4086
+ host,
4087
+ requesterFn: createRequesterFn(
4088
+ (_, reqo) => Promise.resolve(reqo),
4089
+ brokerRequestHandler
4090
+ )
4091
+ });
4071
4092
  }
4072
4093
  async function gitlabValidateParams({
4073
4094
  url,
@@ -4317,41 +4338,56 @@ async function getGitlabBlameRanges({ ref, gitlabUrl, path: path9 }, options) {
4317
4338
  };
4318
4339
  });
4319
4340
  }
4320
- function initGitlabFetchMock() {
4321
- console.log("initGitlabFetchMock starting");
4322
- const globalFetch = global.fetch;
4323
- function myFetch(input, init) {
4324
- console.log(
4325
- `myFetch called with input: ${input} ${JSON.stringify(input)} ${JSON.stringify(init)}`,
4326
- input,
4327
- input?.url
4328
- );
4329
- let urlParsed = null;
4330
- try {
4331
- urlParsed = input?.url ? new URL(input?.url) : null;
4332
- } catch (err) {
4333
- console.log(
4334
- `this block is used for unit tests only. URL ${input?.url} starts from local directory`
4335
- );
4336
- }
4337
- console.log(`urlParsed: ${urlParsed} ${urlParsed?.href}`);
4338
- if (urlParsed && isBrokerUrl(urlParsed.href)) {
4339
- console.log(`urlParsed is broker url: ${urlParsed.href}`);
4340
- const dispatcher = new ProxyAgent2({
4341
- uri: GIT_PROXY_HOST,
4342
- requestTls: {
4343
- rejectUnauthorized: false
4344
- }
4345
- });
4346
- return globalFetch(input, { dispatcher });
4347
- }
4348
- console.log("urlParsed is not broker url");
4349
- return globalFetch(input, init);
4341
+ async function processBody(response) {
4342
+ const headers = response.headers;
4343
+ const type2 = headers.get("content-type")?.split(";")[0]?.trim();
4344
+ if (type2 === "application/json") {
4345
+ return await response.json();
4346
+ }
4347
+ return await response.text();
4348
+ }
4349
+ async function brokerRequestHandler(endpoint, options) {
4350
+ const retryCodes = [429, 502];
4351
+ const maxRetries = 10;
4352
+ const { prefixUrl, searchParams } = options || {};
4353
+ let baseUrl;
4354
+ if (prefixUrl)
4355
+ baseUrl = prefixUrl.endsWith("/") ? prefixUrl : `${prefixUrl}/`;
4356
+ const url = new URL(endpoint, baseUrl);
4357
+ url.search = searchParams || "";
4358
+ const dispatcher = url && isBrokerUrl(url.href) ? new ProxyAgent2({
4359
+ uri: GIT_PROXY_HOST,
4360
+ requestTls: {
4361
+ rejectUnauthorized: false
4362
+ }
4363
+ }) : void 0;
4364
+ for (let i = 0; i < maxRetries; i += 1) {
4365
+ const response = await undiciFetch(url, {
4366
+ headers: options?.headers,
4367
+ method: options?.method,
4368
+ body: options?.body ? String(options?.body) : void 0,
4369
+ dispatcher
4370
+ }).catch((e) => {
4371
+ if (e.name === "TimeoutError" || e.name === "AbortError") {
4372
+ throw new Error("Query timeout was reached");
4373
+ }
4374
+ throw e;
4375
+ });
4376
+ if (response.ok)
4377
+ return {
4378
+ body: await processBody(response),
4379
+ headers: Object.fromEntries(response.headers.entries()),
4380
+ status: response.status
4381
+ };
4382
+ if (!retryCodes.includes(response.status))
4383
+ throw new Error(`gitbeaker: ${response.statusText}`);
4384
+ await setTimeout2(2 ** i * 0.25);
4385
+ continue;
4350
4386
  }
4351
- global.fetch = myFetch;
4352
- console.log("initGitlabFetchMock finished");
4387
+ throw new Error(
4388
+ `Could not successfully complete this request due to Error 429. Check the applicable rate limits for this endpoint.`
4389
+ );
4353
4390
  }
4354
- initGitlabFetchMock();
4355
4391
 
4356
4392
  // src/features/analysis/scm/scmSubmit/index.ts
4357
4393
  import fs from "node:fs/promises";
@@ -5685,6 +5721,10 @@ async function adoValidateParams({
5685
5721
  await getAdoClientParams({ url, accessToken, tokenOrg })
5686
5722
  );
5687
5723
  await api2.connect();
5724
+ if (url) {
5725
+ const git = await api2.getGitApi();
5726
+ await validateAdoRepo({ git, repoUrl: url });
5727
+ }
5688
5728
  } catch (e) {
5689
5729
  console.log("adoValidateParams error", e);
5690
5730
  const error = e;
@@ -5727,6 +5767,20 @@ async function _getOrgsForOauthToken({
5727
5767
  const orgs = accounts.value.map((account) => account.accountName).filter((value, index, array) => array.indexOf(value) === index);
5728
5768
  return orgs;
5729
5769
  }
5770
+ async function validateAdoRepo({
5771
+ git,
5772
+ repoUrl
5773
+ }) {
5774
+ const isAdoRepo = !!parseScmURL(repoUrl, "Ado" /* Ado */);
5775
+ if (!isAdoRepo) {
5776
+ return;
5777
+ }
5778
+ const { repo, projectName } = parseAdoOwnerAndRepo(repoUrl);
5779
+ const branches = await git.getBranches(repo, projectName);
5780
+ if (!branches || branches.length === 0) {
5781
+ throw new InvalidRepoUrlError("no branches");
5782
+ }
5783
+ }
5730
5784
 
5731
5785
  // src/features/analysis/scm/ado/ado.ts
5732
5786
  async function getAdoSdk(params) {
@@ -5734,12 +5788,8 @@ async function getAdoSdk(params) {
5734
5788
  return {
5735
5789
  async getAdoIsUserCollaborator({ repoUrl }) {
5736
5790
  try {
5737
- const { repo, projectName } = parseAdoOwnerAndRepo(repoUrl);
5738
5791
  const git = await api2.getGitApi();
5739
- const branches = await git.getBranches(repo, projectName);
5740
- if (!branches || branches.length === 0) {
5741
- throw new InvalidRepoUrlError("no branches");
5742
- }
5792
+ await validateAdoRepo({ git, repoUrl });
5743
5793
  return true;
5744
5794
  } catch (e) {
5745
5795
  return false;
@@ -8008,7 +8058,7 @@ async function scan(scanOptions, { skipPrompts = false } = {}) {
8008
8058
  const selectedScanner = scanner || await choseScanner();
8009
8059
  if (selectedScanner !== SCANNERS.Checkmarx && selectedScanner !== SCANNERS.Snyk) {
8010
8060
  throw new CliError(
8011
- "Vulnerability scanning via Bugsy is available only with Snyk at the moment. Additional scanners will follow soon."
8061
+ "Vulnerability scanning via Bugsy is available only with Snyk and Checkmarx at the moment. Additional scanners will follow soon."
8012
8062
  );
8013
8063
  }
8014
8064
  selectedScanner === SCANNERS.Checkmarx && validateCheckmarxInstallation();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.167",
3
+ "version": "0.0.169",
4
4
  "description": "Automated secure code remediation tool",
5
- "repository": "https://github.com/mobb-dev/bugsy",
5
+ "repository": "git+https://github.com/mobb-dev/bugsy.git",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
8
  "scripts": {
@@ -12,12 +12,14 @@
12
12
  "build": "tsc && tsup-node --env.NODE_ENV production",
13
13
  "build:dev": "tsup-node --env.NODE_ENV development",
14
14
  "test": "GIT_PROXY_HOST=http://tinyproxy:8888 TOKEN=$(../../scripts/login_auth0.sh) vitest run",
15
+ "test:coverage": "GIT_PROXY_HOST=http://tinyproxy:8888 TOKEN=$(../../scripts/login_auth0.sh) vitest run --coverage ",
15
16
  "test:watch": "TOKEN=$(../../scripts/login_auth0.sh) vitest",
16
17
  "lint": "eslint --cache --max-warnings 0 --ignore-path .eslintignore --ext .ts,.tsx,.jsx .",
17
18
  "lint:fix": "eslint --fix --cache --max-warnings 0 --ignore-path .eslintignore --ext .js,.ts,.tsx,.jsx .",
18
19
  "lint:fix:files": "eslint --fix --cache --max-warnings 0 --ignore-path .eslintignore --ext .js,.ts,.tsx,.jsx",
19
20
  "prepack": "dotenv-vault pull production .env && pnpm build",
20
- "generate": "pnpm run env -- graphql-codegen -r dotenv/config --config client_codegen.ts"
21
+ "generate": "pnpm run env -- graphql-codegen -r dotenv/config --config client_codegen.ts",
22
+ "test:e2e": "cd ./__e2e__ && npm i && npm run test"
21
23
  },
22
24
  "bin": {
23
25
  "mobbdev": "bin/cli.mjs"
@@ -63,19 +65,19 @@
63
65
  "supports-color": "9.4.0",
64
66
  "tar": "6.2.1",
65
67
  "tmp": "0.2.3",
66
- "undici": "6.19.8",
68
+ "undici": "6.20.0",
67
69
  "uuid": "10.0.0",
68
70
  "ws": "8.18.0",
69
71
  "yargs": "17.7.2",
70
72
  "zod": "3.23.8"
71
73
  },
72
74
  "devDependencies": {
73
- "@graphql-codegen/cli": "5.0.2",
74
- "@graphql-codegen/typescript": "4.0.9",
75
+ "@graphql-codegen/cli": "5.0.3",
76
+ "@graphql-codegen/typescript": "4.1.0",
75
77
  "@graphql-codegen/typescript-graphql-request": "6.2.0",
76
- "@graphql-codegen/typescript-operations": "4.2.3",
78
+ "@graphql-codegen/typescript-operations": "4.3.0",
77
79
  "@octokit/request-error": "3.0.3",
78
- "@octokit/types": "13.6.0",
80
+ "@octokit/types": "13.6.1",
79
81
  "@types/adm-zip": "0.5.5",
80
82
  "@types/chalk-animation": "1.6.3",
81
83
  "@types/configstore": "6.0.2",
@@ -89,14 +91,16 @@
89
91
  "@types/yargs": "17.0.33",
90
92
  "@typescript-eslint/eslint-plugin": "7.17.0",
91
93
  "@typescript-eslint/parser": "7.17.0",
94
+ "@vitest/coverage-istanbul": "2.1.2",
95
+ "@vitest/ui": "^2.1.2",
92
96
  "eslint": "8.57.0",
93
- "eslint-plugin-import": "2.30.0",
97
+ "eslint-plugin-import": "2.31.0",
94
98
  "eslint-plugin-prettier": "5.2.1",
95
99
  "eslint-plugin-simple-import-sort": "10.0.0",
96
100
  "prettier": "3.3.3",
97
101
  "tsup": "7.2.0",
98
102
  "typescript": "4.9.5",
99
- "vitest": "0.34.6"
103
+ "vitest": "2.1.2"
100
104
  },
101
105
  "engines": {
102
106
  "node": ">=18.18.0"