mobbdev 0.0.60 → 0.0.62

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 +75 -18
  2. package/package.json +3 -1
package/dist/index.mjs CHANGED
@@ -202,6 +202,7 @@ async function getGitInfo(srcDirPath) {
202
202
  // src/features/analysis/graphql/gql.ts
203
203
  import Debug3 from "debug";
204
204
  import { GraphQLClient } from "graphql-request";
205
+ import { v4 as uuidv4 } from "uuid";
205
206
 
206
207
  // src/features/analysis/graphql/mutations.ts
207
208
  import { gql } from "graphql-request";
@@ -443,7 +444,20 @@ var GQLClient = class {
443
444
  const { apiKey } = args;
444
445
  debug3(`init with apiKey ${apiKey}`);
445
446
  this._client = new GraphQLClient(API_URL, {
446
- headers: { [API_KEY_HEADER_NAME]: apiKey || "" }
447
+ headers: { [API_KEY_HEADER_NAME]: apiKey || "" },
448
+ requestMiddleware: (request) => {
449
+ const requestId = uuidv4();
450
+ debug3(
451
+ `sending API request with id: ${requestId} and with request: ${request.body}`
452
+ );
453
+ return {
454
+ ...request,
455
+ headers: {
456
+ ...request.headers,
457
+ "x-hasura-request-id": requestId
458
+ }
459
+ };
460
+ }
447
461
  });
448
462
  }
449
463
  async getUserInfo() {
@@ -938,6 +952,56 @@ import { z as z5 } from "zod";
938
952
  import { RequestError } from "@octokit/request-error";
939
953
  import { Octokit } from "octokit";
940
954
  import { z as z3 } from "zod";
955
+
956
+ // src/features/analysis/scm/urlParser.ts
957
+ var pathnameParsingMap = {
958
+ "gitlab.com": (pathname) => {
959
+ if (pathname.length < 2)
960
+ return null;
961
+ return {
962
+ organization: pathname[0],
963
+ repoName: pathname[pathname.length - 1]
964
+ };
965
+ },
966
+ "github.com": (pathname) => {
967
+ if (pathname.length !== 2)
968
+ return null;
969
+ return {
970
+ organization: pathname[0],
971
+ repoName: pathname[1]
972
+ };
973
+ }
974
+ };
975
+ var NAME_REGEX = /[a-z0-9\-_.+]+/i;
976
+ var parseScmURL = (scmURL) => {
977
+ try {
978
+ const url = new URL(scmURL);
979
+ const hostname = url.hostname.toLowerCase();
980
+ if (!(hostname in pathnameParsingMap))
981
+ return null;
982
+ const projectPath = url.pathname.substring(1).replace(/.git$/i, "");
983
+ const repo = pathnameParsingMap[hostname](
984
+ projectPath.split("/")
985
+ );
986
+ if (!repo)
987
+ return null;
988
+ const { organization, repoName } = repo;
989
+ if (!organization || !repoName)
990
+ return null;
991
+ if (!organization.match(NAME_REGEX) || !repoName.match(NAME_REGEX))
992
+ return null;
993
+ return {
994
+ hostname: url.hostname,
995
+ organization,
996
+ projectPath,
997
+ repoName
998
+ };
999
+ } catch (e) {
1000
+ return null;
1001
+ }
1002
+ };
1003
+
1004
+ // src/features/analysis/scm/github.ts
941
1005
  function removeTrailingSlash(str) {
942
1006
  return str.trim().replace(/\/+$/, "");
943
1007
  }
@@ -980,7 +1044,6 @@ var GetBlameDocument = `
980
1044
  }
981
1045
  }
982
1046
  `;
983
- var githubUrlRegex = /^http[s]?:\/\/[^/\s]+\/([^/.\s]+\/[^/.\s]+)(\.git)?(\/)?$/i;
984
1047
  function getOktoKit(options) {
985
1048
  const token = options?.githubAuthToken ?? GITHUB_API_TOKEN ?? "";
986
1049
  return new Octokit({ auth: token });
@@ -1207,17 +1270,15 @@ async function getCommit({
1207
1270
  }
1208
1271
  function parseOwnerAndRepo(gitHubUrl) {
1209
1272
  gitHubUrl = removeTrailingSlash(gitHubUrl);
1210
- if (!githubUrlRegex.test(gitHubUrl)) {
1273
+ const parsingResult = parseScmURL(gitHubUrl);
1274
+ if (!parsingResult || parsingResult.hostname !== "github.com") {
1211
1275
  throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1212
1276
  }
1213
- const groups = gitHubUrl.split(githubUrlRegex).filter((res) => res);
1214
- const ownerAndRepo = groups[0]?.split("/");
1215
- const owner = ownerAndRepo?.at(0);
1216
- const repo = ownerAndRepo?.at(1);
1217
- if (!owner || !repo) {
1277
+ const { organization, repoName } = parsingResult;
1278
+ if (!organization || !repoName) {
1218
1279
  throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1219
1280
  }
1220
- return { owner, repo };
1281
+ return { owner: organization, repo: repoName };
1221
1282
  }
1222
1283
  async function queryGithubGraphql(query, variables, options) {
1223
1284
  const token = options?.githubAuthToken ?? GITHUB_API_TOKEN ?? "";
@@ -1787,7 +1848,6 @@ var EnvVariablesZod2 = z5.object({
1787
1848
  GITLAB_API_TOKEN: z5.string().optional()
1788
1849
  });
1789
1850
  var { GITLAB_API_TOKEN } = EnvVariablesZod2.parse(process.env);
1790
- var gitlabUrlRegex = /^http[s]?:\/\/[^/\s]+\/(([^/.\s]+[/])+)([^/.\s]+)(\.git)?(\/)?$/i;
1791
1851
  function getGitBeaker(options) {
1792
1852
  const token = options?.gitlabAuthToken ?? GITLAB_API_TOKEN ?? "";
1793
1853
  if (token?.startsWith("glpat-") || token === "") {
@@ -1987,14 +2047,12 @@ async function getGitlabReferenceData({ ref, gitlabUrl }, options) {
1987
2047
  }
1988
2048
  function parseOwnerAndRepo2(gitlabUrl) {
1989
2049
  gitlabUrl = removeTrailingSlash2(gitlabUrl);
1990
- if (!gitlabUrlRegex.test(gitlabUrl)) {
2050
+ const parsingResult = parseScmURL(gitlabUrl);
2051
+ if (!parsingResult || parsingResult.hostname !== "gitlab.com") {
1991
2052
  throw new InvalidUrlPatternError(`invalid gitlab repo Url ${gitlabUrl}`);
1992
2053
  }
1993
- const groups = gitlabUrl.split(gitlabUrlRegex).filter((res) => res);
1994
- const owner = groups[0]?.split("/")[0];
1995
- const repo = groups[2];
1996
- const projectPath = `${groups[0]}${repo}`;
1997
- return { owner, repo, projectPath };
2054
+ const { organization, repoName, projectPath } = parsingResult;
2055
+ return { owner: organization, repo: repoName, projectPath };
1998
2056
  }
1999
2057
  async function getGitlabBlameRanges({ ref, gitlabUrl, path: path8 }, options) {
2000
2058
  const { projectPath } = parseOwnerAndRepo2(gitlabUrl);
@@ -2590,10 +2648,9 @@ Example:
2590
2648
  )}`;
2591
2649
  throw new CliError(formattedErrorMessage);
2592
2650
  }
2593
- var GIT_REPO_URL_PATTERN = /^https:\/\/(gitlab|github)\.com\/(([^/.\s]+[/])+)([^/.\s]+)(\.git)?(\/)?$/i;
2594
2651
  var UrlZ = z6.string({
2595
2652
  invalid_type_error: "is not a valid GitHub / GitLab URL"
2596
- }).regex(GIT_REPO_URL_PATTERN, {
2653
+ }).refine((data) => !!parseScmURL(data), {
2597
2654
  message: "is not a valid GitHub / GitLab URL"
2598
2655
  });
2599
2656
  function validateRepoUrl(args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "repository": "https://github.com/mobb-dev/bugsy",
6
6
  "main": "dist/index.js",
@@ -49,6 +49,7 @@
49
49
  "supports-color": "9.4.0",
50
50
  "tar": "6.2.0",
51
51
  "tmp": "0.2.1",
52
+ "uuid": "9.0.0",
52
53
  "yargs": "17.7.2",
53
54
  "zod": "3.22.3"
54
55
  },
@@ -63,6 +64,7 @@
63
64
  "@types/semver": "7.5.0",
64
65
  "@types/tar": "^6.1.6",
65
66
  "@types/tmp": "0.2.3",
67
+ "@types/uuid": "9.0.1",
66
68
  "@types/yargs": "17.0.24",
67
69
  "@typescript-eslint/eslint-plugin": "5.44.0",
68
70
  "@typescript-eslint/parser": "5.44.0",