socket 1.0.50 → 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,
@@ -3886,7 +3696,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3886
3696
  packumentCache.clear();
3887
3697
  };
3888
3698
  const getModifiedFiles = async (cwd = process.cwd()) => {
3889
- const unstagedCResult = await gitUnstagedModifiedFiles(cwd);
3699
+ const unstagedCResult = await utils.gitUnstagedModifiedFiles(cwd);
3890
3700
  return unstagedCResult.ok ? unstagedCResult.data.filter(filepath => {
3891
3701
  const basename = path.basename(filepath);
3892
3702
  return basename === 'package.json' || basename === pkgEnvDetails.lockName;
@@ -4028,7 +3838,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4028
3838
  }
4029
3839
  if (fixEnv.isCi && (
4030
3840
  // eslint-disable-next-line no-await-in-loop
4031
- await gitRemoteBranchExists(branch, cwd))) {
3841
+ await utils.gitRemoteBranchExists(branch, cwd))) {
4032
3842
  debug.debugFn('notice', `skip: remote branch "${branch}" for ${name}@${newVersion} exists`);
4033
3843
  seenBranches.add(branch);
4034
3844
  continue infosLoop;
@@ -4063,9 +3873,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4063
3873
  // Reset things just in case.
4064
3874
  if (fixEnv.isCi) {
4065
3875
  // eslint-disable-next-line no-await-in-loop
4066
- await gitResetAndClean(fixEnv.baseBranch, cwd);
3876
+ await utils.gitResetAndClean(fixEnv.baseBranch, cwd);
4067
3877
  // eslint-disable-next-line no-await-in-loop
4068
- await gitCheckoutBranch(fixEnv.baseBranch, cwd);
3878
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
4069
3879
  }
4070
3880
  continue infosLoop;
4071
3881
  }
@@ -4111,22 +3921,27 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4111
3921
  if (!errored && fixEnv.isCi && fixEnv.repoInfo) {
4112
3922
  debug.debugFn('notice', 'pr: creating');
4113
3923
  try {
4114
- if (
3924
+ const pushed =
4115
3925
  // eslint-disable-next-line no-await-in-loop
4116
- !(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),
4117
3929
  // eslint-disable-next-line no-await-in-loop
4118
3930
  await getModifiedFiles(cwd), {
4119
3931
  cwd,
4120
3932
  email: fixEnv.gitEmail,
4121
3933
  user: fixEnv.gitUser
4122
- }))) {
3934
+ })) && (
3935
+ // eslint-disable-next-line no-await-in-loop
3936
+ await utils.gitPushBranch(branch, cwd));
3937
+ if (!pushed) {
4123
3938
  logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
4124
3939
  // eslint-disable-next-line no-await-in-loop
4125
- await gitResetAndClean(fixEnv.baseBranch, cwd);
3940
+ await utils.gitResetAndClean(fixEnv.baseBranch, cwd);
4126
3941
  // eslint-disable-next-line no-await-in-loop
4127
- await gitCheckoutBranch(fixEnv.baseBranch, cwd);
3942
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
4128
3943
  // eslint-disable-next-line no-await-in-loop
4129
- await gitDeleteBranch(branch, cwd);
3944
+ await utils.gitDeleteBranch(branch, cwd);
4130
3945
  // eslint-disable-next-line no-await-in-loop
4131
3946
  const maybeActualTree = await installer(pkgEnvDetails, {
4132
3947
  cwd,
@@ -4187,9 +4002,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4187
4002
  if (fixEnv.isCi) {
4188
4003
  spinner?.start();
4189
4004
  // eslint-disable-next-line no-await-in-loop
4190
- await gitResetAndClean(branch, cwd);
4005
+ await utils.gitResetAndClean(branch, cwd);
4191
4006
  // eslint-disable-next-line no-await-in-loop
4192
- await gitCheckoutBranch(fixEnv.baseBranch, cwd);
4007
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
4193
4008
  // eslint-disable-next-line no-await-in-loop
4194
4009
  const maybeActualTree = await installer(pkgEnvDetails, {
4195
4010
  cwd,
@@ -7886,11 +7701,11 @@ async function fetchDependencies({
7886
7701
  limit,
7887
7702
  offset
7888
7703
  }) {
7889
- const sockSdkResult = await utils.setupSdk();
7890
- if (!sockSdkResult.ok) {
7891
- return sockSdkResult;
7704
+ const sockSdkCResult = await utils.setupSdk();
7705
+ if (!sockSdkCResult.ok) {
7706
+ return sockSdkCResult;
7892
7707
  }
7893
- const sockSdk = sockSdkResult.data;
7708
+ const sockSdk = sockSdkCResult.data;
7894
7709
  return await utils.handleApiCall(sockSdk.searchDependencies({
7895
7710
  limit,
7896
7711
  offset
@@ -8060,11 +7875,11 @@ async function run$q(argv, importMeta, {
8060
7875
  }
8061
7876
 
8062
7877
  async function fetchLicensePolicy(orgSlug) {
8063
- const sockSdkResult = await utils.setupSdk();
8064
- if (!sockSdkResult.ok) {
8065
- return sockSdkResult;
7878
+ const sockSdkCResult = await utils.setupSdk();
7879
+ if (!sockSdkCResult.ok) {
7880
+ return sockSdkCResult;
8066
7881
  }
8067
- const sockSdk = sockSdkResult.data;
7882
+ const sockSdk = sockSdkCResult.data;
8068
7883
  return await utils.handleApiCall(sockSdk.getOrgLicensePolicy(orgSlug), 'organization license policy');
8069
7884
  }
8070
7885
 
@@ -8185,11 +8000,11 @@ async function run$p(argv, importMeta, {
8185
8000
  }
8186
8001
 
8187
8002
  async function fetchSecurityPolicy(orgSlug) {
8188
- const sockSdkResult = await utils.setupSdk();
8189
- if (!sockSdkResult.ok) {
8190
- return sockSdkResult;
8003
+ const sockSdkCResult = await utils.setupSdk();
8004
+ if (!sockSdkCResult.ok) {
8005
+ return sockSdkCResult;
8191
8006
  }
8192
- const sockSdk = sockSdkResult.data;
8007
+ const sockSdk = sockSdkCResult.data;
8193
8008
  return await utils.handleApiCall(sockSdk.getOrgSecurityPolicy(orgSlug), 'organization security policy');
8194
8009
  }
8195
8010
 
@@ -8313,11 +8128,11 @@ async function run$o(argv, importMeta, {
8313
8128
  }
8314
8129
 
8315
8130
  async function fetchOrganization() {
8316
- const sockSdkResult = await utils.setupSdk();
8317
- if (!sockSdkResult.ok) {
8318
- return sockSdkResult;
8131
+ const sockSdkCResult = await utils.setupSdk();
8132
+ if (!sockSdkCResult.ok) {
8133
+ return sockSdkCResult;
8319
8134
  }
8320
- const sockSdk = sockSdkResult.data;
8135
+ const sockSdk = sockSdkCResult.data;
8321
8136
  return await utils.handleApiCall(sockSdk.getOrganizations(), 'organization list');
8322
8137
  }
8323
8138
 
@@ -8472,11 +8287,11 @@ const cmdOrganizationPolicy = {
8472
8287
  };
8473
8288
 
8474
8289
  async function fetchQuota() {
8475
- const sockSdkResult = await utils.setupSdk();
8476
- if (!sockSdkResult.ok) {
8477
- return sockSdkResult;
8290
+ const sockSdkCResult = await utils.setupSdk();
8291
+ if (!sockSdkCResult.ok) {
8292
+ return sockSdkCResult;
8478
8293
  }
8479
- const sockSdk = sockSdkResult.data;
8294
+ const sockSdk = sockSdkCResult.data;
8480
8295
  return await utils.handleApiCall(sockSdk.getQuota(), 'token quota');
8481
8296
  }
8482
8297
 
@@ -8938,11 +8753,11 @@ async function run$l(argv, importMeta, {
8938
8753
 
8939
8754
  async function fetchPurlsShallowScore(purls) {
8940
8755
  logger.logger.info(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
8941
- const sockSdkResult = await utils.setupSdk();
8942
- if (!sockSdkResult.ok) {
8943
- return sockSdkResult;
8756
+ const sockSdkCResult = await utils.setupSdk();
8757
+ if (!sockSdkCResult.ok) {
8758
+ return sockSdkCResult;
8944
8759
  }
8945
- const sockSdk = sockSdkResult.data;
8760
+ const sockSdk = sockSdkCResult.data;
8946
8761
  const result = await utils.handleApiCall(sockSdk.batchPackageFetch({
8947
8762
  alerts: 'true'
8948
8763
  }, {
@@ -9453,11 +9268,11 @@ async function fetchCreateRepo({
9453
9268
  repoName,
9454
9269
  visibility
9455
9270
  }) {
9456
- const sockSdkResult = await utils.setupSdk();
9457
- if (!sockSdkResult.ok) {
9458
- return sockSdkResult;
9271
+ const sockSdkCResult = await utils.setupSdk();
9272
+ if (!sockSdkCResult.ok) {
9273
+ return sockSdkCResult;
9459
9274
  }
9460
- const sockSdk = sockSdkResult.data;
9275
+ const sockSdk = sockSdkCResult.data;
9461
9276
  return await utils.handleApiCall(sockSdk.createOrgRepo(orgSlug, {
9462
9277
  name: repoName,
9463
9278
  description,
@@ -9630,11 +9445,11 @@ async function run$h(argv, importMeta, {
9630
9445
  }
9631
9446
 
9632
9447
  async function fetchDeleteRepo(orgSlug, repoName) {
9633
- const sockSdkResult = await utils.setupSdk();
9634
- if (!sockSdkResult.ok) {
9635
- return sockSdkResult;
9448
+ const sockSdkCResult = await utils.setupSdk();
9449
+ if (!sockSdkCResult.ok) {
9450
+ return sockSdkCResult;
9636
9451
  }
9637
- const sockSdk = sockSdkResult.data;
9452
+ const sockSdk = sockSdkCResult.data;
9638
9453
  return await utils.handleApiCall(sockSdk.deleteOrgRepo(orgSlug, repoName), 'to delete a repository');
9639
9454
  }
9640
9455
 
@@ -9758,11 +9573,11 @@ async function fetchListAllRepos({
9758
9573
  orgSlug,
9759
9574
  sort
9760
9575
  }) {
9761
- const sockSdkResult = await utils.setupSdk();
9762
- if (!sockSdkResult.ok) {
9763
- return sockSdkResult;
9576
+ const sockSdkCResult = await utils.setupSdk();
9577
+ if (!sockSdkCResult.ok) {
9578
+ return sockSdkCResult;
9764
9579
  }
9765
- const sockSdk = sockSdkResult.data;
9580
+ const sockSdk = sockSdkCResult.data;
9766
9581
  const rows = [];
9767
9582
  let protection = 0;
9768
9583
  let nextPage = 0;
@@ -9808,11 +9623,11 @@ async function fetchListRepos({
9808
9623
  per_page,
9809
9624
  sort
9810
9625
  }) {
9811
- const sockSdkResult = await utils.setupSdk();
9812
- if (!sockSdkResult.ok) {
9813
- return sockSdkResult;
9626
+ const sockSdkCResult = await utils.setupSdk();
9627
+ if (!sockSdkCResult.ok) {
9628
+ return sockSdkCResult;
9814
9629
  }
9815
- const sockSdk = sockSdkResult.data;
9630
+ const sockSdk = sockSdkCResult.data;
9816
9631
  return await utils.handleApiCall(sockSdk.getOrgRepoList(orgSlug, {
9817
9632
  sort,
9818
9633
  direction,
@@ -10052,11 +9867,11 @@ async function fetchUpdateRepo({
10052
9867
  repoName,
10053
9868
  visibility
10054
9869
  }) {
10055
- const sockSdkResult = await utils.setupSdk();
10056
- if (!sockSdkResult.ok) {
10057
- return sockSdkResult;
9870
+ const sockSdkCResult = await utils.setupSdk();
9871
+ if (!sockSdkCResult.ok) {
9872
+ return sockSdkCResult;
10058
9873
  }
10059
- const sockSdk = sockSdkResult.data;
9874
+ const sockSdk = sockSdkCResult.data;
10060
9875
  return await utils.handleApiCall(sockSdk.updateOrgRepo(orgSlug, repoName, {
10061
9876
  orgSlug,
10062
9877
  name: repoName,
@@ -10229,11 +10044,11 @@ async function run$e(argv, importMeta, {
10229
10044
  }
10230
10045
 
10231
10046
  async function fetchViewRepo(orgSlug, repoName) {
10232
- const sockSdkResult = await utils.setupSdk();
10233
- if (!sockSdkResult.ok) {
10234
- return sockSdkResult;
10047
+ const sockSdkCResult = await utils.setupSdk();
10048
+ if (!sockSdkCResult.ok) {
10049
+ return sockSdkCResult;
10235
10050
  }
10236
- const sockSdk = sockSdkResult.data;
10051
+ const sockSdk = sockSdkCResult.data;
10237
10052
  return await utils.handleApiCall(sockSdk.getOrgRepo(orgSlug, repoName), 'repository data');
10238
10053
  }
10239
10054
 
@@ -10426,7 +10241,9 @@ async function suggestTarget() {
10426
10241
  }
10427
10242
 
10428
10243
  const {
10429
- 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
10430
10247
  } = constants;
10431
10248
  const config$c = {
10432
10249
  commandName: 'create',
@@ -10597,10 +10414,10 @@ async function run$c(argv, importMeta, {
10597
10414
  report
10598
10415
  } = cli.flags;
10599
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();
10600
10418
 
10601
10419
  // Accept zero or more paths. Default to cwd() if none given.
10602
- let targets = cli.input || [process.cwd()];
10603
- const cwd = cwdOverride && cwdOverride !== 'process.cwd()' ? path.resolve(process.cwd(), String(cwdOverride)) : process.cwd();
10420
+ let targets = cli.input || [cwd];
10604
10421
  const sockJson = await utils.readOrDefaultSocketJson(cwd);
10605
10422
 
10606
10423
  // Note: This needs meow booleanDefault=undefined
@@ -10617,7 +10434,7 @@ async function run$c(argv, importMeta, {
10617
10434
  branchName = sockJson.defaults.scan.create.branch;
10618
10435
  logger.logger.info('Using default --branch from socket.json:', branchName);
10619
10436
  } else {
10620
- branchName = 'socket-default-branch';
10437
+ branchName = (await utils.gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH$1;
10621
10438
  }
10622
10439
  }
10623
10440
  if (!repoName) {
@@ -10625,7 +10442,7 @@ async function run$c(argv, importMeta, {
10625
10442
  repoName = sockJson.defaults.scan.create.repo;
10626
10443
  logger.logger.info('Using default --repo from socket.json:', repoName);
10627
10444
  } else {
10628
- repoName = 'socket-default-repository';
10445
+ repoName = (await utils.getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY$1;
10629
10446
  }
10630
10447
  }
10631
10448
  if (typeof report !== 'boolean') {
@@ -10753,11 +10570,11 @@ async function run$c(argv, importMeta, {
10753
10570
  }
10754
10571
 
10755
10572
  async function fetchDeleteOrgFullScan(orgSlug, scanId) {
10756
- const sockSdkResult = await utils.setupSdk();
10757
- if (!sockSdkResult.ok) {
10758
- return sockSdkResult;
10573
+ const sockSdkCResult = await utils.setupSdk();
10574
+ if (!sockSdkCResult.ok) {
10575
+ return sockSdkCResult;
10759
10576
  }
10760
- const sockSdk = sockSdkResult.data;
10577
+ const sockSdk = sockSdkCResult.data;
10761
10578
  return await utils.handleApiCall(sockSdk.deleteOrgFullScan(orgSlug, scanId), 'to delete a scan');
10762
10579
  }
10763
10580
 
@@ -12045,11 +11862,11 @@ async function fetchListScans({
12045
11862
  repo,
12046
11863
  sort
12047
11864
  }) {
12048
- const sockSdkResult = await utils.setupSdk();
12049
- if (!sockSdkResult.ok) {
12050
- return sockSdkResult;
11865
+ const sockSdkCResult = await utils.setupSdk();
11866
+ if (!sockSdkCResult.ok) {
11867
+ return sockSdkCResult;
12051
11868
  }
12052
- const sockSdk = sockSdkResult.data;
11869
+ const sockSdk = sockSdkCResult.data;
12053
11870
  return await utils.handleApiCall(sockSdk.getOrgFullScanList(orgSlug, {
12054
11871
  ...(branch ? {
12055
11872
  branch
@@ -12296,11 +12113,11 @@ async function run$8(argv, importMeta, {
12296
12113
  }
12297
12114
 
12298
12115
  async function fetchScanMetadata(orgSlug, scanId) {
12299
- const sockSdkResult = await utils.setupSdk();
12300
- if (!sockSdkResult.ok) {
12301
- return sockSdkResult;
12116
+ const sockSdkCResult = await utils.setupSdk();
12117
+ if (!sockSdkCResult.ok) {
12118
+ return sockSdkCResult;
12302
12119
  }
12303
- const sockSdk = sockSdkResult.data;
12120
+ const sockSdk = sockSdkCResult.data;
12304
12121
  return await utils.handleApiCall(sockSdk.getOrgFullScanMetadata(orgSlug, scanId), 'meta data for a full scan');
12305
12122
  }
12306
12123
 
@@ -12700,6 +12517,10 @@ async function outputScanConfigResult(result) {
12700
12517
  logger.logger.log('');
12701
12518
  }
12702
12519
 
12520
+ const {
12521
+ SOCKET_DEFAULT_BRANCH,
12522
+ SOCKET_DEFAULT_REPOSITORY
12523
+ } = constants;
12703
12524
  async function setupScanConfig(cwd, defaultOnReadError = false) {
12704
12525
  const jsonPath = path.join(cwd, `socket.json`);
12705
12526
  if (fs$1.existsSync(jsonPath)) {
@@ -12750,7 +12571,7 @@ async function setupScanConfig(cwd, defaultOnReadError = false) {
12750
12571
  if (!sockJson.defaults.scan.create) {
12751
12572
  sockJson.defaults.scan.create = {};
12752
12573
  }
12753
- const result = await configureScan(sockJson.defaults.scan.create);
12574
+ const result = await configureScan(sockJson.defaults.scan.create, cwd);
12754
12575
  if (!result.ok || result.data.canceled) {
12755
12576
  return result;
12756
12577
  }
@@ -12791,10 +12612,10 @@ async function setupScanConfig(cwd, defaultOnReadError = false) {
12791
12612
  }
12792
12613
  return canceledByUser();
12793
12614
  }
12794
- async function configureScan(config) {
12615
+ async function configureScan(config, cwd = process.cwd()) {
12795
12616
  const defaultRepoName = await prompts.input({
12796
12617
  message: '(--repo) What repo name (slug) should be reported to Socket for this dir?',
12797
- default: config.repo || 'socket-default-repository',
12618
+ default: config.repo || (await utils.getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY,
12798
12619
  required: false
12799
12620
  // validate: async string => bool
12800
12621
  });
@@ -12802,7 +12623,7 @@ async function configureScan(config) {
12802
12623
  return canceledByUser();
12803
12624
  }
12804
12625
  if (defaultRepoName) {
12805
- // 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
12806
12627
  // this default then an existing user probably would not expect the change?
12807
12628
  config.repo = defaultRepoName;
12808
12629
  } else {
@@ -12810,7 +12631,7 @@ async function configureScan(config) {
12810
12631
  }
12811
12632
  const defaultBranchName = await prompts.input({
12812
12633
  message: '(--branch) What branch name (slug) should be reported to Socket for this dir?',
12813
- default: config.branch || 'socket-default-branch',
12634
+ default: config.branch || (await utils.gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH,
12814
12635
  required: false
12815
12636
  // validate: async string => bool
12816
12637
  });
@@ -12818,7 +12639,7 @@ async function configureScan(config) {
12818
12639
  return canceledByUser();
12819
12640
  }
12820
12641
  if (defaultBranchName) {
12821
- // 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
12822
12643
  // this default then an existing user probably would not expect the change?
12823
12644
  config.branch = defaultBranchName;
12824
12645
  } else {
@@ -13165,11 +12986,11 @@ async function handleScanView(orgSlug, scanId, filePath, outputKind) {
13165
12986
  }
13166
12987
 
13167
12988
  async function streamScan(orgSlug, scanId, file) {
13168
- const sockSdkResult = await utils.setupSdk();
13169
- if (!sockSdkResult.ok) {
13170
- return sockSdkResult;
12989
+ const sockSdkCResult = await utils.setupSdk();
12990
+ if (!sockSdkCResult.ok) {
12991
+ return sockSdkCResult;
13171
12992
  }
13172
- const sockSdk = sockSdkResult.data;
12993
+ const sockSdk = sockSdkCResult.data;
13173
12994
  logger.logger.info('Requesting data from API...');
13174
12995
 
13175
12996
  // Note: this will write to stdout or target file. It's not a noop
@@ -14319,5 +14140,5 @@ void (async () => {
14319
14140
  await utils.captureException(e);
14320
14141
  }
14321
14142
  })();
14322
- //# debugId=a6f657d8-6263-4651-bc8b-01702cb07501
14143
+ //# debugId=404eb6bb-65e8-45cb-9cb8-b36c31796d71
14323
14144
  //# sourceMappingURL=cli.js.map