socket 1.0.49 → 1.0.51

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/dist/cli.js CHANGED
@@ -20,7 +20,6 @@ var npm = require('../external/@socketsecurity/registry/lib/npm');
20
20
  var packages = require('../external/@socketsecurity/registry/lib/packages');
21
21
  var sorts = require('../external/@socketsecurity/registry/lib/sorts');
22
22
  var strings = require('../external/@socketsecurity/registry/lib/strings');
23
- var path$1 = require('../external/@socketsecurity/registry/lib/path');
24
23
  var regexps = require('../external/@socketsecurity/registry/lib/regexps');
25
24
  var fs$2 = require('../external/@socketsecurity/registry/lib/fs');
26
25
  var shadowNpmInject = require('./shadow-npm-inject.js');
@@ -33,20 +32,20 @@ var promises = require('node:stream/promises');
33
32
 
34
33
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
35
34
  async function fetchOrgAnalyticsData(time) {
36
- const sockSdkResult = await utils.setupSdk();
37
- if (!sockSdkResult.ok) {
38
- return sockSdkResult;
35
+ const sockSdkCResult = await utils.setupSdk();
36
+ if (!sockSdkCResult.ok) {
37
+ return sockSdkCResult;
39
38
  }
40
- const sockSdk = sockSdkResult.data;
39
+ const sockSdk = sockSdkCResult.data;
41
40
  return await utils.handleApiCall(sockSdk.getOrgAnalytics(time.toString()), 'analytics data');
42
41
  }
43
42
 
44
43
  async function fetchRepoAnalyticsData(repo, time) {
45
- const sockSdkResult = await utils.setupSdk();
46
- if (!sockSdkResult.ok) {
47
- return sockSdkResult;
44
+ const sockSdkCResult = await utils.setupSdk();
45
+ if (!sockSdkCResult.ok) {
46
+ return sockSdkCResult;
48
47
  }
49
- const sockSdk = sockSdkResult.data;
48
+ const sockSdk = sockSdkCResult.data;
50
49
  return await utils.handleApiCall(sockSdk.getRepoAnalytics(repo, time.toString()), 'analytics data');
51
50
  }
52
51
 
@@ -455,11 +454,11 @@ async function fetchAuditLog({
455
454
  page,
456
455
  perPage
457
456
  }) {
458
- const sockSdkResult = await utils.setupSdk();
459
- if (!sockSdkResult.ok) {
460
- return sockSdkResult;
457
+ const sockSdkCResult = await utils.setupSdk();
458
+ if (!sockSdkCResult.ok) {
459
+ return sockSdkCResult;
461
460
  }
462
- const sockSdk = sockSdkResult.data;
461
+ const sockSdk = sockSdkCResult.data;
463
462
  return await utils.handleApiCall(sockSdk.getAuditLogEvents(orgSlug, {
464
463
  // I'm not sure this is used at all.
465
464
  outputJson: String(outputKind === 'json'),
@@ -872,11 +871,11 @@ async function getDefaultOrgSlug() {
872
871
  data: defaultOrgResult
873
872
  };
874
873
  }
875
- const sockSdkResult = await utils.setupSdk();
876
- if (!sockSdkResult.ok) {
877
- return sockSdkResult;
874
+ const sockSdkCResult = await utils.setupSdk();
875
+ if (!sockSdkCResult.ok) {
876
+ return sockSdkCResult;
878
877
  }
879
- const sockSdk = sockSdkResult.data;
878
+ const sockSdk = sockSdkCResult.data;
880
879
  const result = await utils.handleApiCall(sockSdk.getOrganizations(), 'list of organizations');
881
880
  if (!result.ok) {
882
881
  return result;
@@ -906,6 +905,9 @@ async function getDefaultOrgSlug() {
906
905
  };
907
906
  }
908
907
 
908
+ const {
909
+ SOCKET_DEFAULT_REPOSITORY: SOCKET_DEFAULT_REPOSITORY$3
910
+ } = constants;
909
911
  async function fetchCreateOrgFullScan(packagePaths, orgSlug, defaultBranch, pendingHead, tmp, cwd, {
910
912
  branchName,
911
913
  commitHash,
@@ -914,11 +916,12 @@ async function fetchCreateOrgFullScan(packagePaths, orgSlug, defaultBranch, pend
914
916
  pullRequest,
915
917
  repoName
916
918
  }) {
917
- const sockSdkResult = await utils.setupSdk();
918
- if (!sockSdkResult.ok) {
919
- return sockSdkResult;
919
+ const sockSdkCResult = await utils.setupSdk();
920
+ if (!sockSdkCResult.ok) {
921
+ return sockSdkCResult;
920
922
  }
921
- const sockSdk = sockSdkResult.data;
923
+ const sockSdk = sockSdkCResult.data;
924
+ const repo = repoName || (await utils.getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY$3;
922
925
  return await utils.handleApiCall(sockSdk.createOrgFullScan(orgSlug, {
923
926
  ...(branchName ? {
924
927
  branch: branchName
@@ -936,19 +939,19 @@ async function fetchCreateOrgFullScan(packagePaths, orgSlug, defaultBranch, pend
936
939
  ...(pullRequest ? {
937
940
  pull_request: String(pullRequest)
938
941
  } : {}),
939
- repo: repoName || 'socket-default-repository',
940
- // mandatory, this is server default for repo
942
+ // The repo is mandatory, this is server default for repo.
943
+ repo,
941
944
  set_as_pending_head: String(pendingHead),
942
945
  tmp: String(tmp)
943
946
  }, packagePaths, cwd), 'to create a scan');
944
947
  }
945
948
 
946
949
  async function fetchSupportedScanFileNames() {
947
- const sockSdkResult = await utils.setupSdk();
948
- if (!sockSdkResult.ok) {
949
- return sockSdkResult;
950
+ const sockSdkCResult = await utils.setupSdk();
951
+ if (!sockSdkCResult.ok) {
952
+ return sockSdkCResult;
950
953
  }
951
- const sockSdk = sockSdkResult.data;
954
+ const sockSdk = sockSdkCResult.data;
952
955
  return await utils.handleApiCall(sockSdk.getReportSupportedFiles(), 'supported scan file types');
953
956
  }
954
957
 
@@ -957,11 +960,11 @@ async function fetchSupportedScanFileNames() {
957
960
  * full scan ID.
958
961
  */
959
962
  async function fetchReportData(orgSlug, scanId, includeLicensePolicy) {
960
- const sockSdkResult = await utils.setupSdk();
961
- if (!sockSdkResult.ok) {
962
- return sockSdkResult;
963
+ const sockSdkCResult = await utils.setupSdk();
964
+ if (!sockSdkCResult.ok) {
965
+ return sockSdkCResult;
963
966
  }
964
- const sockSdk = sockSdkResult.data;
967
+ const sockSdk = sockSdkCResult.data;
965
968
  let policyStatus = 'requested...';
966
969
  let scanStatus = 'requested...';
967
970
  let finishedFetching = false;
@@ -1998,12 +2001,12 @@ async function handleCreateNewScan({
1998
2001
  });
1999
2002
  logger.logger.info('Auto generation finished. Proceeding with Scan creation.');
2000
2003
  }
2001
- const supportedFileNames = await fetchSupportedScanFileNames();
2002
- if (!supportedFileNames.ok) {
2003
- await outputCreateNewScan(supportedFileNames, outputKind, interactive);
2004
+ const fileNamesCResult = await fetchSupportedScanFileNames();
2005
+ if (!fileNamesCResult.ok) {
2006
+ await outputCreateNewScan(fileNamesCResult, outputKind, interactive);
2004
2007
  return;
2005
2008
  }
2006
- const packagePaths = await utils.getPackageFilesForScan(cwd, targets, supportedFileNames.data);
2009
+ const packagePaths = await utils.getPackageFilesForScan(cwd, targets, fileNamesCResult.data);
2007
2010
  const wasValidInput = utils.checkCommandInput(outputKind, {
2008
2011
  nook: true,
2009
2012
  test: packagePaths.length > 0,
@@ -2051,6 +2054,10 @@ async function handleCreateNewScan({
2051
2054
  }
2052
2055
  }
2053
2056
 
2057
+ const {
2058
+ SOCKET_DEFAULT_BRANCH: SOCKET_DEFAULT_BRANCH$2,
2059
+ SOCKET_DEFAULT_REPOSITORY: SOCKET_DEFAULT_REPOSITORY$2
2060
+ } = constants;
2054
2061
  async function handleCI(autoManifest) {
2055
2062
  // ci: {
2056
2063
  // description: 'Alias for "report create --view --strict"',
@@ -2059,16 +2066,16 @@ async function handleCI(autoManifest) {
2059
2066
  const result = await getDefaultOrgSlug();
2060
2067
  if (!result.ok) {
2061
2068
  process.exitCode = result.code ?? 1;
2062
- // Always assume json mode
2069
+ // Always assume json mode.
2063
2070
  logger.logger.log(utils.serializeResultJson(result));
2064
2071
  return;
2065
2072
  }
2073
+ const cwd = process.cwd();
2066
2074
 
2067
- // TODO: does it make sense to discover the commit details from local git?
2068
2075
  // TODO: does it makes sense to use custom branch/repo names here? probably socket.yml, right
2069
2076
  await handleCreateNewScan({
2070
2077
  autoManifest,
2071
- branchName: 'socket-default-branch',
2078
+ branchName: (await utils.gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH$2,
2072
2079
  commitMessage: '',
2073
2080
  commitHash: '',
2074
2081
  committers: '',
@@ -2077,14 +2084,15 @@ async function handleCI(autoManifest) {
2077
2084
  interactive: false,
2078
2085
  orgSlug: result.data,
2079
2086
  outputKind: 'json',
2087
+ // When 'pendingHead' is true, it requires 'branchName' set and 'tmp' false.
2080
2088
  pendingHead: true,
2081
- // when true, requires branch name set, tmp false
2082
2089
  pullRequest: 0,
2083
- repoName: 'socket-default-repository',
2090
+ repoName: (await utils.getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY$2,
2084
2091
  readOnly: false,
2085
2092
  report: true,
2086
2093
  targets: ['.'],
2087
- tmp: false // don't set when pendingHead is true
2094
+ // Don't set 'tmp' when 'pendingHead' is true.
2095
+ tmp: false
2088
2096
  });
2089
2097
  }
2090
2098
 
@@ -2252,11 +2260,11 @@ async function discoverConfigValue(key) {
2252
2260
  };
2253
2261
  }
2254
2262
  async function getDefaultOrgFromToken() {
2255
- const sockSdkResult = await utils.setupSdk();
2256
- if (!sockSdkResult.ok) {
2263
+ const sockSdkCResult = await utils.setupSdk();
2264
+ if (!sockSdkCResult.ok) {
2257
2265
  return undefined;
2258
2266
  }
2259
- const sockSdk = sockSdkResult.data;
2267
+ const sockSdk = sockSdkCResult.data;
2260
2268
  const result = await utils.handleApiCall(sockSdk.getOrganizations(), 'list of organizations');
2261
2269
  if (result.ok) {
2262
2270
  const arr = Array.from(Object.values(result.data.organizations)).map(({
@@ -2273,11 +2281,11 @@ async function getDefaultOrgFromToken() {
2273
2281
  return undefined;
2274
2282
  }
2275
2283
  async function getEnforceableOrgsFromToken() {
2276
- const sockSdkResult = await utils.setupSdk();
2277
- if (!sockSdkResult.ok) {
2284
+ const sockSdkCResult = await utils.setupSdk();
2285
+ if (!sockSdkCResult.ok) {
2278
2286
  return undefined;
2279
2287
  }
2280
- const sockSdk = sockSdkResult.data;
2288
+ const sockSdk = sockSdkCResult.data;
2281
2289
  const result = await utils.handleApiCall(sockSdk.getOrganizations(), 'list of organizations');
2282
2290
  if (result.ok) {
2283
2291
  const arr = Array.from(Object.values(result.data.organizations)).map(({
@@ -2999,36 +3007,6 @@ function createSocketBranchParser(options) {
2999
3007
  };
3000
3008
  }
3001
3009
  const genericSocketBranchParser = createSocketBranchParser();
3002
- async function getBaseGitBranch(cwd = process.cwd()) {
3003
- // Lazily access constants.ENV properties.
3004
- const {
3005
- GITHUB_BASE_REF,
3006
- GITHUB_REF_NAME,
3007
- GITHUB_REF_TYPE
3008
- } = constants.ENV;
3009
- // 1. In a pull request, this is always the base branch.
3010
- if (GITHUB_BASE_REF) {
3011
- return GITHUB_BASE_REF;
3012
- }
3013
- // 2. If it's a branch (not a tag), GITHUB_REF_TYPE should be 'branch'.
3014
- if (GITHUB_REF_TYPE === 'branch' && GITHUB_REF_NAME) {
3015
- return GITHUB_REF_NAME;
3016
- }
3017
- // 3. Try to resolve the default remote branch using 'git remote show origin'.
3018
- // This handles detached HEADs or workflows triggered by tags/releases.
3019
- try {
3020
- const originDetails = (await spawn.spawn('git', ['remote', 'show', 'origin'], {
3021
- cwd
3022
- })).stdout;
3023
- const match = /(?<=HEAD branch: ).+/.exec(originDetails);
3024
- if (match?.[0]) {
3025
- return match[0].trim();
3026
- }
3027
- } catch {}
3028
- // GitHub defaults to branch name "main"
3029
- // https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches#about-the-default-branch
3030
- return 'main';
3031
- }
3032
3010
  function getSocketBranchFullNameComponent(pkgName) {
3033
3011
  const purlObj = utils.getPurlObject(typeof pkgName === 'string' && !pkgName.startsWith('pkg:') ? vendor.packageurlJsExports.PackageURL.fromString(`pkg:unknown/${pkgName}`) : pkgName);
3034
3012
  const branchMaybeNamespace = purlObj.namespace ? `${formatBranchName(purlObj.namespace)}--` : '';
@@ -3088,184 +3066,6 @@ function getSocketPullRequestTitle(purl, newVersion, workspace) {
3088
3066
  const fullName = utils.getPkgFullNameFromPurl(purlObj);
3089
3067
  return `Bump ${fullName} from ${purlObj.version} to ${newVersion}${workspace ? ` in ${workspace}` : ''}`;
3090
3068
  }
3091
- async function gitCleanFdx(cwd = process.cwd()) {
3092
- const stdioIgnoreOptions = {
3093
- cwd,
3094
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3095
- };
3096
- // TODO: propagate CResult?
3097
- await spawn.spawn('git', ['clean', '-fdx'], stdioIgnoreOptions);
3098
- }
3099
- async function gitCheckoutBranch(branch, cwd = process.cwd()) {
3100
- const stdioIgnoreOptions = {
3101
- cwd,
3102
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3103
- };
3104
- try {
3105
- await spawn.spawn('git', ['checkout', branch], stdioIgnoreOptions);
3106
- return true;
3107
- } catch {}
3108
- return false;
3109
- }
3110
- async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3111
- if (!filepaths.length) {
3112
- debug.debugFn('notice', `miss: no filepaths to add`);
3113
- return false;
3114
- }
3115
- const {
3116
- cwd = process.cwd(),
3117
- // Lazily access constants.ENV.SOCKET_CLI_GIT_USER_EMAIL.
3118
- email = constants.ENV.SOCKET_CLI_GIT_USER_EMAIL,
3119
- // Lazily access constants.ENV.SOCKET_CLI_GIT_USER_NAME.
3120
- user = constants.ENV.SOCKET_CLI_GIT_USER_NAME
3121
- } = {
3122
- __proto__: null,
3123
- ...options
3124
- };
3125
- const stdioIgnoreOptions = {
3126
- cwd,
3127
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3128
- };
3129
- try {
3130
- await gitEnsureIdentity(user, email, cwd);
3131
- await spawn.spawn('git', ['checkout', '-b', branch], stdioIgnoreOptions);
3132
- await spawn.spawn('git', ['add', ...filepaths], stdioIgnoreOptions);
3133
- await spawn.spawn('git', ['commit', '-m', commitMsg], stdioIgnoreOptions);
3134
- await spawn.spawn('git', ['push', '--force', '--set-upstream', 'origin', branch], stdioIgnoreOptions);
3135
- return true;
3136
- } catch (e) {
3137
- debug.debugFn('error', `caught: git push --force --set-upstream origin ${branch} failed`);
3138
- debug.debugDir('inspect', {
3139
- error: e
3140
- });
3141
- }
3142
- return false;
3143
- }
3144
- async function gitDeleteBranch(branch, cwd = process.cwd()) {
3145
- const stdioIgnoreOptions = {
3146
- cwd,
3147
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3148
- };
3149
- try {
3150
- // Will throw with exit code 1 if branch does not exist.
3151
- await spawn.spawn('git', ['branch', '-D', branch], stdioIgnoreOptions);
3152
- return true;
3153
- } catch {}
3154
- return false;
3155
- }
3156
- async function gitRepoInfo(cwd = process.cwd()) {
3157
- try {
3158
- const remoteUrl = (await spawn.spawn('git', ['remote', 'get-url', 'origin'], {
3159
- cwd
3160
- })).stdout;
3161
- // 1. Handle SSH-style, e.g. git@github.com:owner/repo.git
3162
- const sshMatch = /^git@[^:]+:([^/]+)\/(.+?)(?:\.git)?$/.exec(remoteUrl);
3163
- if (sshMatch) {
3164
- return {
3165
- owner: sshMatch[1],
3166
- repo: sshMatch[2]
3167
- };
3168
- }
3169
- // 2. Handle HTTPS/URL-style, e.g. https://github.com/owner/repo.git
3170
- try {
3171
- const parsed = new URL(remoteUrl);
3172
- const segments = parsed.pathname.split('/');
3173
- const owner = segments.at(-2);
3174
- const repo = segments.at(-1)?.replace(/\.git$/, '');
3175
- if (owner && repo) {
3176
- return {
3177
- owner,
3178
- repo
3179
- };
3180
- }
3181
- } catch {}
3182
- debug.debugFn('error', 'git: unmatched git remote URL format');
3183
- debug.debugDir('inspect', {
3184
- remoteUrl
3185
- });
3186
- } catch (e) {
3187
- debug.debugFn('error', 'caught: `git remote get-url origin` failed');
3188
- debug.debugDir('inspect', {
3189
- error: e
3190
- });
3191
- }
3192
- return null;
3193
- }
3194
- async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
3195
- const stdioIgnoreOptions = {
3196
- cwd,
3197
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3198
- };
3199
- const stdioPipeOptions = {
3200
- cwd
3201
- };
3202
- const identEntries = [['user.email', name], ['user.name', email]];
3203
- await Promise.all(identEntries.map(async ({
3204
- 0: prop,
3205
- 1: value
3206
- }) => {
3207
- let configValue;
3208
- try {
3209
- // Will throw with exit code 1 if the config property is not set.
3210
- configValue = (await spawn.spawn('git', ['config', '--get', prop], stdioPipeOptions)).stdout;
3211
- } catch {}
3212
- if (configValue !== value) {
3213
- try {
3214
- await spawn.spawn('git', ['config', prop, value], stdioIgnoreOptions);
3215
- } catch (e) {
3216
- debug.debugFn('error', `caught: git config ${prop} ${value} failed`);
3217
- debug.debugDir('inspect', {
3218
- error: e
3219
- });
3220
- }
3221
- }
3222
- }));
3223
- }
3224
- async function gitRemoteBranchExists(branch, cwd = process.cwd()) {
3225
- const stdioPipeOptions = {
3226
- cwd
3227
- };
3228
- try {
3229
- return (await spawn.spawn('git', ['ls-remote', '--heads', 'origin', branch], stdioPipeOptions)).stdout.length > 0;
3230
- } catch {}
3231
- return false;
3232
- }
3233
- async function gitResetAndClean(branch = 'HEAD', cwd = process.cwd()) {
3234
- // Discards tracked changes.
3235
- await gitResetHard(branch, cwd);
3236
- // Deletes all untracked files and directories.
3237
- await gitCleanFdx(cwd);
3238
- }
3239
- async function gitResetHard(branch = 'HEAD', cwd = process.cwd()) {
3240
- const stdioIgnoreOptions = {
3241
- cwd,
3242
- stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3243
- };
3244
- await spawn.spawn('git', ['reset', '--hard', branch], stdioIgnoreOptions);
3245
- }
3246
- async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
3247
- try {
3248
- const stdioPipeOptions = {
3249
- cwd
3250
- };
3251
- const changedFilesDetails = (await spawn.spawn('git', ['diff', '--name-only'], stdioPipeOptions)).stdout;
3252
- const relPaths = changedFilesDetails.split('\n') ?? [];
3253
- return {
3254
- ok: true,
3255
- data: relPaths.map(p => path$1.normalizePath(p))
3256
- };
3257
- } catch (e) {
3258
- debug.debugFn('error', 'caught: git diff --name-only failed');
3259
- debug.debugDir('inspect', {
3260
- error: e
3261
- });
3262
- return {
3263
- ok: false,
3264
- message: 'Git Error',
3265
- cause: 'Unexpected error while trying to ask git whether repo is dirty'
3266
- };
3267
- }
3268
- }
3269
3069
 
3270
3070
  function getPrsForPurl(fixEnv, partialPurl) {
3271
3071
  if (!fixEnv) {
@@ -3686,11 +3486,21 @@ function ciRepoInfo() {
3686
3486
  };
3687
3487
  }
3688
3488
  async function getFixEnv() {
3689
- const baseBranch = await getBaseGitBranch();
3489
+ const baseBranch = await utils.getBaseBranch();
3690
3490
  const gitEmail = constants.ENV.SOCKET_CLI_GIT_USER_EMAIL;
3691
3491
  const gitUser = constants.ENV.SOCKET_CLI_GIT_USER_NAME;
3692
3492
  const githubToken = constants.ENV.SOCKET_CLI_GITHUB_TOKEN;
3693
3493
  const isCi = !!(constants.ENV.CI && gitEmail && gitUser && githubToken);
3494
+ if (
3495
+ // If isCi is false,
3496
+ !isCi && (
3497
+ // but some CI checks are passing,
3498
+ constants.ENV.CI || gitEmail || gitUser || githubToken) &&
3499
+ // then log about it when in debug mode.
3500
+ debug.isDebug('notice')) {
3501
+ const envVars = [...(constants.ENV.CI ? [] : ['process.env.CI']), ...(gitEmail ? [] : ['process.env.SOCKET_CLI_GIT_USER_EMAIL']), ...(gitUser ? [] : ['process.env.SOCKET_CLI_GIT_USER_NAME']), ...(githubToken ? [] : ['process.env.GITHUB_TOKEN'])];
3502
+ debug.debugFn('notice', `miss: fixEnv.isCi is false, expected ${arrays.joinAnd(envVars)} to be set`);
3503
+ }
3694
3504
  let repoInfo = null;
3695
3505
  if (isCi) {
3696
3506
  repoInfo = ciRepoInfo();
@@ -3699,7 +3509,7 @@ async function getFixEnv() {
3699
3509
  if (isCi) {
3700
3510
  debug.debugFn('notice', 'falling back to `git remote get-url origin`');
3701
3511
  }
3702
- repoInfo = await gitRepoInfo();
3512
+ repoInfo = await utils.getRepoInfo();
3703
3513
  }
3704
3514
  const prs = isCi && repoInfo ? await getSocketPrs(repoInfo.owner, repoInfo.repo, {
3705
3515
  author: gitUser,
@@ -3821,6 +3631,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3821
3631
  pkgPath: rootPath
3822
3632
  } = pkgEnvDetails;
3823
3633
  const fixEnv = await getFixEnv();
3634
+ debug.debugDir('inspect', {
3635
+ fixEnv
3636
+ });
3824
3637
  const {
3825
3638
  autoMerge,
3826
3639
  cwd,
@@ -3883,7 +3696,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3883
3696
  packumentCache.clear();
3884
3697
  };
3885
3698
  const getModifiedFiles = async (cwd = process.cwd()) => {
3886
- const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
3699
+ const unstagedCResult = await utils.gitUnstagedModifiedFiles(cwd);
3887
3700
  return unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
3888
3701
  const basename = path.basename(filepath);
3889
3702
  return basename === 'package.json' || basename === pkgEnvDetails.lockName;
@@ -4025,7 +3838,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4025
3838
  }
4026
3839
  if (fixEnv.isCi && (
4027
3840
  // eslint-disable-next-line no-await-in-loop
4028
- await gitRemoteBranchExists(branch, cwd))) {
3841
+ await utils.gitRemoteBranchExists(branch, cwd))) {
4029
3842
  debug.debugFn('notice', `skip: remote branch "${branch}" for ${name}@${newVersion} exists`);
4030
3843
  seenBranches.add(branch);
4031
3844
  continue infosLoop;
@@ -4060,9 +3873,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4060
3873
  // Reset things just in case.
4061
3874
  if (fixEnv.isCi) {
4062
3875
  // eslint-disable-next-line no-await-in-loop
4063
- await gitResetAndClean(fixEnv.baseBranch, cwd);
3876
+ await utils.gitResetAndClean(fixEnv.baseBranch, cwd);
4064
3877
  // eslint-disable-next-line no-await-in-loop
4065
- await gitCheckoutBranch(fixEnv.baseBranch, cwd);
3878
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
4066
3879
  }
4067
3880
  continue infosLoop;
4068
3881
  }
@@ -4108,22 +3921,27 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4108
3921
  if (!errored && fixEnv.isCi && fixEnv.repoInfo) {
4109
3922
  debug.debugFn('notice', 'pr: creating');
4110
3923
  try {
4111
- if (
3924
+ const pushed =
4112
3925
  // eslint-disable-next-line no-await-in-loop
4113
- !(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace),
3926
+ (await utils.gitCreateBranch(branch, cwd)) && (
3927
+ // eslint-disable-next-line no-await-in-loop
3928
+ await utils.gitCommit(getSocketCommitMessage(oldPurl, newVersion, workspace),
4114
3929
  // eslint-disable-next-line no-await-in-loop
4115
3930
  await getModifiedFiles(cwd), {
4116
3931
  cwd,
4117
3932
  email: fixEnv.gitEmail,
4118
3933
  user: fixEnv.gitUser
4119
- }))) {
3934
+ })) && (
3935
+ // eslint-disable-next-line no-await-in-loop
3936
+ await utils.gitPushBranch(branch, cwd));
3937
+ if (!pushed) {
4120
3938
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4121
3939
  // eslint-disable-next-line no-await-in-loop
4122
- await gitResetAndClean(fixEnv.baseBranch, cwd);
3940
+ await utils.gitResetAndClean(fixEnv.baseBranch, cwd);
4123
3941
  // eslint-disable-next-line no-await-in-loop
4124
- await gitCheckoutBranch(fixEnv.baseBranch, cwd);
3942
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
4125
3943
  // eslint-disable-next-line no-await-in-loop
4126
- await gitDeleteBranch(branch, cwd);
3944
+ await utils.gitDeleteBranch(branch, cwd);
4127
3945
  // eslint-disable-next-line no-await-in-loop
4128
3946
  const maybeActualTree = await installer(pkgEnvDetails, {
4129
3947
  cwd,
@@ -4184,9 +4002,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4184
4002
  if (fixEnv.isCi) {
4185
4003
  spinner?.start();
4186
4004
  // eslint-disable-next-line no-await-in-loop
4187
- await gitResetAndClean(branch, cwd);
4005
+ await utils.gitResetAndClean(branch, cwd);
4188
4006
  // eslint-disable-next-line no-await-in-loop
4189
- await gitCheckoutBranch(fixEnv.baseBranch, cwd);
4007
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
4190
4008
  // eslint-disable-next-line no-await-in-loop
4191
4009
  const maybeActualTree = await installer(pkgEnvDetails, {
4192
4010
  cwd,
@@ -7883,11 +7701,11 @@ async function fetchDependencies({
7883
7701
  limit,
7884
7702
  offset
7885
7703
  }) {
7886
- const sockSdkResult = await utils.setupSdk();
7887
- if (!sockSdkResult.ok) {
7888
- return sockSdkResult;
7704
+ const sockSdkCResult = await utils.setupSdk();
7705
+ if (!sockSdkCResult.ok) {
7706
+ return sockSdkCResult;
7889
7707
  }
7890
- const sockSdk = sockSdkResult.data;
7708
+ const sockSdk = sockSdkCResult.data;
7891
7709
  return await utils.handleApiCall(sockSdk.searchDependencies({
7892
7710
  limit,
7893
7711
  offset
@@ -8057,11 +7875,11 @@ async function run$q(argv, importMeta, {
8057
7875
  }
8058
7876
 
8059
7877
  async function fetchLicensePolicy(orgSlug) {
8060
- const sockSdkResult = await utils.setupSdk();
8061
- if (!sockSdkResult.ok) {
8062
- return sockSdkResult;
7878
+ const sockSdkCResult = await utils.setupSdk();
7879
+ if (!sockSdkCResult.ok) {
7880
+ return sockSdkCResult;
8063
7881
  }
8064
- const sockSdk = sockSdkResult.data;
7882
+ const sockSdk = sockSdkCResult.data;
8065
7883
  return await utils.handleApiCall(sockSdk.getOrgLicensePolicy(orgSlug), 'organization license policy');
8066
7884
  }
8067
7885
 
@@ -8182,11 +8000,11 @@ async function run$p(argv, importMeta, {
8182
8000
  }
8183
8001
 
8184
8002
  async function fetchSecurityPolicy(orgSlug) {
8185
- const sockSdkResult = await utils.setupSdk();
8186
- if (!sockSdkResult.ok) {
8187
- return sockSdkResult;
8003
+ const sockSdkCResult = await utils.setupSdk();
8004
+ if (!sockSdkCResult.ok) {
8005
+ return sockSdkCResult;
8188
8006
  }
8189
- const sockSdk = sockSdkResult.data;
8007
+ const sockSdk = sockSdkCResult.data;
8190
8008
  return await utils.handleApiCall(sockSdk.getOrgSecurityPolicy(orgSlug), 'organization security policy');
8191
8009
  }
8192
8010
 
@@ -8310,11 +8128,11 @@ async function run$o(argv, importMeta, {
8310
8128
  }
8311
8129
 
8312
8130
  async function fetchOrganization() {
8313
- const sockSdkResult = await utils.setupSdk();
8314
- if (!sockSdkResult.ok) {
8315
- return sockSdkResult;
8131
+ const sockSdkCResult = await utils.setupSdk();
8132
+ if (!sockSdkCResult.ok) {
8133
+ return sockSdkCResult;
8316
8134
  }
8317
- const sockSdk = sockSdkResult.data;
8135
+ const sockSdk = sockSdkCResult.data;
8318
8136
  return await utils.handleApiCall(sockSdk.getOrganizations(), 'organization list');
8319
8137
  }
8320
8138
 
@@ -8469,11 +8287,11 @@ const cmdOrganizationPolicy = {
8469
8287
  };
8470
8288
 
8471
8289
  async function fetchQuota() {
8472
- const sockSdkResult = await utils.setupSdk();
8473
- if (!sockSdkResult.ok) {
8474
- return sockSdkResult;
8290
+ const sockSdkCResult = await utils.setupSdk();
8291
+ if (!sockSdkCResult.ok) {
8292
+ return sockSdkCResult;
8475
8293
  }
8476
- const sockSdk = sockSdkResult.data;
8294
+ const sockSdk = sockSdkCResult.data;
8477
8295
  return await utils.handleApiCall(sockSdk.getQuota(), 'token quota');
8478
8296
  }
8479
8297
 
@@ -8935,11 +8753,11 @@ async function run$l(argv, importMeta, {
8935
8753
 
8936
8754
  async function fetchPurlsShallowScore(purls) {
8937
8755
  logger.logger.info(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
8938
- const sockSdkResult = await utils.setupSdk();
8939
- if (!sockSdkResult.ok) {
8940
- return sockSdkResult;
8756
+ const sockSdkCResult = await utils.setupSdk();
8757
+ if (!sockSdkCResult.ok) {
8758
+ return sockSdkCResult;
8941
8759
  }
8942
- const sockSdk = sockSdkResult.data;
8760
+ const sockSdk = sockSdkCResult.data;
8943
8761
  const result = await utils.handleApiCall(sockSdk.batchPackageFetch({
8944
8762
  alerts: 'true'
8945
8763
  }, {
@@ -9450,11 +9268,11 @@ async function fetchCreateRepo({
9450
9268
  repoName,
9451
9269
  visibility
9452
9270
  }) {
9453
- const sockSdkResult = await utils.setupSdk();
9454
- if (!sockSdkResult.ok) {
9455
- return sockSdkResult;
9271
+ const sockSdkCResult = await utils.setupSdk();
9272
+ if (!sockSdkCResult.ok) {
9273
+ return sockSdkCResult;
9456
9274
  }
9457
- const sockSdk = sockSdkResult.data;
9275
+ const sockSdk = sockSdkCResult.data;
9458
9276
  return await utils.handleApiCall(sockSdk.createOrgRepo(orgSlug, {
9459
9277
  name: repoName,
9460
9278
  description,
@@ -9627,11 +9445,11 @@ async function run$h(argv, importMeta, {
9627
9445
  }
9628
9446
 
9629
9447
  async function fetchDeleteRepo(orgSlug, repoName) {
9630
- const sockSdkResult = await utils.setupSdk();
9631
- if (!sockSdkResult.ok) {
9632
- return sockSdkResult;
9448
+ const sockSdkCResult = await utils.setupSdk();
9449
+ if (!sockSdkCResult.ok) {
9450
+ return sockSdkCResult;
9633
9451
  }
9634
- const sockSdk = sockSdkResult.data;
9452
+ const sockSdk = sockSdkCResult.data;
9635
9453
  return await utils.handleApiCall(sockSdk.deleteOrgRepo(orgSlug, repoName), 'to delete a repository');
9636
9454
  }
9637
9455
 
@@ -9755,11 +9573,11 @@ async function fetchListAllRepos({
9755
9573
  orgSlug,
9756
9574
  sort
9757
9575
  }) {
9758
- const sockSdkResult = await utils.setupSdk();
9759
- if (!sockSdkResult.ok) {
9760
- return sockSdkResult;
9576
+ const sockSdkCResult = await utils.setupSdk();
9577
+ if (!sockSdkCResult.ok) {
9578
+ return sockSdkCResult;
9761
9579
  }
9762
- const sockSdk = sockSdkResult.data;
9580
+ const sockSdk = sockSdkCResult.data;
9763
9581
  const rows = [];
9764
9582
  let protection = 0;
9765
9583
  let nextPage = 0;
@@ -9805,11 +9623,11 @@ async function fetchListRepos({
9805
9623
  per_page,
9806
9624
  sort
9807
9625
  }) {
9808
- const sockSdkResult = await utils.setupSdk();
9809
- if (!sockSdkResult.ok) {
9810
- return sockSdkResult;
9626
+ const sockSdkCResult = await utils.setupSdk();
9627
+ if (!sockSdkCResult.ok) {
9628
+ return sockSdkCResult;
9811
9629
  }
9812
- const sockSdk = sockSdkResult.data;
9630
+ const sockSdk = sockSdkCResult.data;
9813
9631
  return await utils.handleApiCall(sockSdk.getOrgRepoList(orgSlug, {
9814
9632
  sort,
9815
9633
  direction,
@@ -10049,11 +9867,11 @@ async function fetchUpdateRepo({
10049
9867
  repoName,
10050
9868
  visibility
10051
9869
  }) {
10052
- const sockSdkResult = await utils.setupSdk();
10053
- if (!sockSdkResult.ok) {
10054
- return sockSdkResult;
9870
+ const sockSdkCResult = await utils.setupSdk();
9871
+ if (!sockSdkCResult.ok) {
9872
+ return sockSdkCResult;
10055
9873
  }
10056
- const sockSdk = sockSdkResult.data;
9874
+ const sockSdk = sockSdkCResult.data;
10057
9875
  return await utils.handleApiCall(sockSdk.updateOrgRepo(orgSlug, repoName, {
10058
9876
  orgSlug,
10059
9877
  name: repoName,
@@ -10226,11 +10044,11 @@ async function run$e(argv, importMeta, {
10226
10044
  }
10227
10045
 
10228
10046
  async function fetchViewRepo(orgSlug, repoName) {
10229
- const sockSdkResult = await utils.setupSdk();
10230
- if (!sockSdkResult.ok) {
10231
- return sockSdkResult;
10047
+ const sockSdkCResult = await utils.setupSdk();
10048
+ if (!sockSdkCResult.ok) {
10049
+ return sockSdkCResult;
10232
10050
  }
10233
- const sockSdk = sockSdkResult.data;
10051
+ const sockSdk = sockSdkCResult.data;
10234
10052
  return await utils.handleApiCall(sockSdk.getOrgRepo(orgSlug, repoName), 'repository data');
10235
10053
  }
10236
10054
 
@@ -10423,7 +10241,9 @@ async function suggestTarget() {
10423
10241
  }
10424
10242
 
10425
10243
  const {
10426
- DRY_RUN_BAILING_NOW: DRY_RUN_BAILING_NOW$c
10244
+ DRY_RUN_BAILING_NOW: DRY_RUN_BAILING_NOW$c,
10245
+ SOCKET_DEFAULT_BRANCH: SOCKET_DEFAULT_BRANCH$1,
10246
+ SOCKET_DEFAULT_REPOSITORY: SOCKET_DEFAULT_REPOSITORY$1
10427
10247
  } = constants;
10428
10248
  const config$c = {
10429
10249
  commandName: 'create',
@@ -10594,10 +10414,10 @@ async function run$c(argv, importMeta, {
10594
10414
  report
10595
10415
  } = cli.flags;
10596
10416
  let [orgSlug] = await utils.determineOrgSlug(String(orgFlag || ''), interactive, dryRun);
10417
+ const cwd = cwdOverride && cwdOverride !== 'process.cwd()' ? path.resolve(process.cwd(), String(cwdOverride)) : process.cwd();
10597
10418
 
10598
10419
  // Accept zero or more paths. Default to cwd() if none given.
10599
- let targets = cli.input || [process.cwd()];
10600
- const cwd = cwdOverride && cwdOverride !== 'process.cwd()' ? path.resolve(process.cwd(), String(cwdOverride)) : process.cwd();
10420
+ let targets = cli.input || [cwd];
10601
10421
  const sockJson = await utils.readOrDefaultSocketJson(cwd);
10602
10422
 
10603
10423
  // Note: This needs meow booleanDefault=undefined
@@ -10614,7 +10434,7 @@ async function run$c(argv, importMeta, {
10614
10434
  branchName = sockJson.defaults.scan.create.branch;
10615
10435
  logger.logger.info('Using default --branch from socket.json:', branchName);
10616
10436
  } else {
10617
- branchName = 'socket-default-branch';
10437
+ branchName = (await utils.gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH$1;
10618
10438
  }
10619
10439
  }
10620
10440
  if (!repoName) {
@@ -10622,7 +10442,7 @@ async function run$c(argv, importMeta, {
10622
10442
  repoName = sockJson.defaults.scan.create.repo;
10623
10443
  logger.logger.info('Using default --repo from socket.json:', repoName);
10624
10444
  } else {
10625
- repoName = 'socket-default-repository';
10445
+ repoName = (await utils.getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY$1;
10626
10446
  }
10627
10447
  }
10628
10448
  if (typeof report !== 'boolean') {
@@ -10750,11 +10570,11 @@ async function run$c(argv, importMeta, {
10750
10570
  }
10751
10571
 
10752
10572
  async function fetchDeleteOrgFullScan(orgSlug, scanId) {
10753
- const sockSdkResult = await utils.setupSdk();
10754
- if (!sockSdkResult.ok) {
10755
- return sockSdkResult;
10573
+ const sockSdkCResult = await utils.setupSdk();
10574
+ if (!sockSdkCResult.ok) {
10575
+ return sockSdkCResult;
10756
10576
  }
10757
- const sockSdk = sockSdkResult.data;
10577
+ const sockSdk = sockSdkCResult.data;
10758
10578
  return await utils.handleApiCall(sockSdk.deleteOrgFullScan(orgSlug, scanId), 'to delete a scan');
10759
10579
  }
10760
10580
 
@@ -12042,11 +11862,11 @@ async function fetchListScans({
12042
11862
  repo,
12043
11863
  sort
12044
11864
  }) {
12045
- const sockSdkResult = await utils.setupSdk();
12046
- if (!sockSdkResult.ok) {
12047
- return sockSdkResult;
11865
+ const sockSdkCResult = await utils.setupSdk();
11866
+ if (!sockSdkCResult.ok) {
11867
+ return sockSdkCResult;
12048
11868
  }
12049
- const sockSdk = sockSdkResult.data;
11869
+ const sockSdk = sockSdkCResult.data;
12050
11870
  return await utils.handleApiCall(sockSdk.getOrgFullScanList(orgSlug, {
12051
11871
  ...(branch ? {
12052
11872
  branch
@@ -12293,11 +12113,11 @@ async function run$8(argv, importMeta, {
12293
12113
  }
12294
12114
 
12295
12115
  async function fetchScanMetadata(orgSlug, scanId) {
12296
- const sockSdkResult = await utils.setupSdk();
12297
- if (!sockSdkResult.ok) {
12298
- return sockSdkResult;
12116
+ const sockSdkCResult = await utils.setupSdk();
12117
+ if (!sockSdkCResult.ok) {
12118
+ return sockSdkCResult;
12299
12119
  }
12300
- const sockSdk = sockSdkResult.data;
12120
+ const sockSdk = sockSdkCResult.data;
12301
12121
  return await utils.handleApiCall(sockSdk.getOrgFullScanMetadata(orgSlug, scanId), 'meta data for a full scan');
12302
12122
  }
12303
12123
 
@@ -12697,6 +12517,10 @@ async function outputScanConfigResult(result) {
12697
12517
  logger.logger.log('');
12698
12518
  }
12699
12519
 
12520
+ const {
12521
+ SOCKET_DEFAULT_BRANCH,
12522
+ SOCKET_DEFAULT_REPOSITORY
12523
+ } = constants;
12700
12524
  async function setupScanConfig(cwd, defaultOnReadError = false) {
12701
12525
  const jsonPath = path.join(cwd, `socket.json`);
12702
12526
  if (fs$1.existsSync(jsonPath)) {
@@ -12747,7 +12571,7 @@ async function setupScanConfig(cwd, defaultOnReadError = false) {
12747
12571
  if (!sockJson.defaults.scan.create) {
12748
12572
  sockJson.defaults.scan.create = {};
12749
12573
  }
12750
- const result = await configureScan(sockJson.defaults.scan.create);
12574
+ const result = await configureScan(sockJson.defaults.scan.create, cwd);
12751
12575
  if (!result.ok || result.data.canceled) {
12752
12576
  return result;
12753
12577
  }
@@ -12788,10 +12612,10 @@ async function setupScanConfig(cwd, defaultOnReadError = false) {
12788
12612
  }
12789
12613
  return canceledByUser();
12790
12614
  }
12791
- async function configureScan(config) {
12615
+ async function configureScan(config, cwd = process.cwd()) {
12792
12616
  const defaultRepoName = await prompts.input({
12793
12617
  message: '(--repo) What repo name (slug) should be reported to Socket for this dir?',
12794
- default: config.repo || 'socket-default-repository',
12618
+ default: config.repo || (await utils.getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY,
12795
12619
  required: false
12796
12620
  // validate: async string => bool
12797
12621
  });
@@ -12799,7 +12623,7 @@ async function configureScan(config) {
12799
12623
  return canceledByUser();
12800
12624
  }
12801
12625
  if (defaultRepoName) {
12802
- // Even if it's 'socket-default-repository' store it because if we change
12626
+ // Even if it's SOCKET_DEFAULT_REPOSITORY store it because if we change
12803
12627
  // this default then an existing user probably would not expect the change?
12804
12628
  config.repo = defaultRepoName;
12805
12629
  } else {
@@ -12807,7 +12631,7 @@ async function configureScan(config) {
12807
12631
  }
12808
12632
  const defaultBranchName = await prompts.input({
12809
12633
  message: '(--branch) What branch name (slug) should be reported to Socket for this dir?',
12810
- default: config.branch || 'socket-default-branch',
12634
+ default: config.branch || (await utils.gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH,
12811
12635
  required: false
12812
12636
  // validate: async string => bool
12813
12637
  });
@@ -12815,7 +12639,7 @@ async function configureScan(config) {
12815
12639
  return canceledByUser();
12816
12640
  }
12817
12641
  if (defaultBranchName) {
12818
- // Even if it's 'socket-default-branch' store it because if we change
12642
+ // Even if it's SOCKET_DEFAULT_BRANCH store it because if we change
12819
12643
  // this default then an existing user probably would not expect the change?
12820
12644
  config.branch = defaultBranchName;
12821
12645
  } else {
@@ -13162,11 +12986,11 @@ async function handleScanView(orgSlug, scanId, filePath, outputKind) {
13162
12986
  }
13163
12987
 
13164
12988
  async function streamScan(orgSlug, scanId, file) {
13165
- const sockSdkResult = await utils.setupSdk();
13166
- if (!sockSdkResult.ok) {
13167
- return sockSdkResult;
12989
+ const sockSdkCResult = await utils.setupSdk();
12990
+ if (!sockSdkCResult.ok) {
12991
+ return sockSdkCResult;
13168
12992
  }
13169
- const sockSdk = sockSdkResult.data;
12993
+ const sockSdk = sockSdkCResult.data;
13170
12994
  logger.logger.info('Requesting data from API...');
13171
12995
 
13172
12996
  // Note: this will write to stdout or target file. It's not a noop
@@ -14316,5 +14140,5 @@ void (async () => {
14316
14140
  await utils.captureException(e);
14317
14141
  }
14318
14142
  })();
14319
- //# debugId=58e3aaaf-7fac-4e39-b6b9-5bb2c754bc3d
14143
+ //# debugId=404eb6bb-65e8-45cb-9cb8-b36c31796d71
14320
14144
  //# sourceMappingURL=cli.js.map