@socketsecurity/cli-with-sentry 1.1.14 → 1.1.15

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/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
6
 
7
+ ## [1.1.15](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.15) - 2025-09-16
8
+
9
+ ### Changed
10
+ - Improved `socket fix` environment variable detection with clearer error messages when required variables are missing
11
+
12
+ ### Fixed
13
+ - Resolved path handling issue in `socket optimize` command
14
+ - Command flag parsing now correctly detects subsequent arguments
15
+
7
16
  ## [1.1.14](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.14) - 2025-09-17
8
17
 
9
18
  ### Changed
package/dist/cli.js CHANGED
@@ -230,10 +230,10 @@ function formatDataOrg(data) {
230
230
  const topFiveAlertTypes = entry['top_five_alert_types'];
231
231
  for (const type of Object.keys(topFiveAlertTypes)) {
232
232
  const count = topFiveAlertTypes[type] ?? 0;
233
- if (!totalTopAlerts[type]) {
234
- totalTopAlerts[type] = count;
235
- } else {
233
+ if (totalTopAlerts[type]) {
236
234
  totalTopAlerts[type] += count;
235
+ } else {
236
+ totalTopAlerts[type] = count;
237
237
  }
238
238
  }
239
239
  }
@@ -241,10 +241,10 @@ function formatDataOrg(data) {
241
241
  const formatted = formattedData[metric];
242
242
  for (const entry of data) {
243
243
  const date = formatDate(entry['created_at']);
244
- if (!formatted[date]) {
245
- formatted[date] = entry[metric];
246
- } else {
244
+ if (formatted[date]) {
247
245
  formatted[date] += entry[metric];
246
+ } else {
247
+ formatted[date] = entry[metric];
248
248
  }
249
249
  }
250
250
  }
@@ -3394,21 +3394,72 @@ function ciRepoInfo() {
3394
3394
  repo: ownerSlashRepo.slice(slashIndex + 1)
3395
3395
  };
3396
3396
  }
3397
+ /**
3398
+ * Get formatted instructions for setting CI environment variables.
3399
+ */
3400
+ function getCiEnvInstructions() {
3401
+ return 'To enable automatic pull request creation, run in CI with these environment variables:\n' + ' - CI=1\n' + ' - SOCKET_CLI_GITHUB_TOKEN=<your-github-token>\n' + ' - SOCKET_CLI_GIT_USER_NAME=<git-username>\n' + ' - SOCKET_CLI_GIT_USER_EMAIL=<git-email>';
3402
+ }
3403
+
3404
+ /**
3405
+ * Check which required CI environment variables are missing.
3406
+ * Returns lists of missing and present variables.
3407
+ */
3408
+ function checkCiEnvVars() {
3409
+ const {
3410
+ CI,
3411
+ SOCKET_CLI_GIT_USER_EMAIL,
3412
+ SOCKET_CLI_GIT_USER_NAME,
3413
+ SOCKET_CLI_GITHUB_TOKEN
3414
+ } = constants.default.ENV;
3415
+ const missing = [];
3416
+ const present = [];
3417
+ if (CI) {
3418
+ present.push('CI');
3419
+ } else {
3420
+ missing.push('CI');
3421
+ }
3422
+ if (SOCKET_CLI_GIT_USER_EMAIL) {
3423
+ present.push('SOCKET_CLI_GIT_USER_EMAIL');
3424
+ } else {
3425
+ missing.push('SOCKET_CLI_GIT_USER_EMAIL');
3426
+ }
3427
+ if (SOCKET_CLI_GIT_USER_NAME) {
3428
+ present.push('SOCKET_CLI_GIT_USER_NAME');
3429
+ } else {
3430
+ missing.push('SOCKET_CLI_GIT_USER_NAME');
3431
+ }
3432
+ if (SOCKET_CLI_GITHUB_TOKEN) {
3433
+ present.push('SOCKET_CLI_GITHUB_TOKEN');
3434
+ } else {
3435
+ missing.push('SOCKET_CLI_GITHUB_TOKEN (or GITHUB_TOKEN)');
3436
+ }
3437
+ return {
3438
+ missing,
3439
+ present
3440
+ };
3441
+ }
3397
3442
  async function getFixEnv() {
3398
3443
  const baseBranch = await utils.getBaseBranch();
3399
3444
  const gitEmail = constants.default.ENV.SOCKET_CLI_GIT_USER_EMAIL;
3400
3445
  const gitUser = constants.default.ENV.SOCKET_CLI_GIT_USER_NAME;
3401
3446
  const githubToken = constants.default.ENV.SOCKET_CLI_GITHUB_TOKEN;
3402
3447
  const isCi = !!(constants.default.ENV.CI && gitEmail && gitUser && githubToken);
3403
- if (
3404
- // If isCi is false,
3405
- !isCi && (
3406
- // but some CI checks are passing,
3407
- constants.default.ENV.CI || gitEmail || gitUser || githubToken) &&
3448
+ const envCheck = checkCiEnvVars();
3449
+
3450
+ // Provide clear feedback about missing environment variables.
3451
+ if (constants.default.ENV.CI && envCheck.missing.length > 1) {
3452
+ // CI is set but other required vars are missing.
3453
+ const missingExceptCi = envCheck.missing.filter(v => v !== 'CI');
3454
+ if (missingExceptCi.length) {
3455
+ logger.logger.warn(`CI mode detected, but pull request creation is disabled due to missing environment variables:\n` + ` Missing: ${arrays.joinAnd(missingExceptCi)}\n` + ` Set these variables to enable automatic pull request creation.`);
3456
+ }
3457
+ } else if (
3458
+ // If not in CI but some CI-related env vars are set.
3459
+ !constants.default.ENV.CI && envCheck.present.length &&
3408
3460
  // then log about it when in debug mode.
3409
3461
  require$$9.isDebug('notice')) {
3410
- const envVars = [...(constants.default.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'])];
3411
- require$$9.debugFn('notice', `miss: fixEnv.isCi is false, expected ${arrays.joinAnd(envVars)} to be set`);
3462
+ require$$9.debugFn('notice', `miss: fixEnv.isCi is false, expected ${arrays.joinAnd(envCheck.missing)} to be set`);
3412
3463
  }
3413
3464
  let repoInfo;
3414
3465
  if (isCi) {
@@ -3486,6 +3537,19 @@ async function coanaFix(fixConfig) {
3486
3537
  const isAll = !ghsas.length || ghsas.length === 1 && (ghsas[0] === 'all' || ghsas[0] === 'auto');
3487
3538
  const shouldOpenPrs = fixEnv.isCi && fixEnv.repoInfo;
3488
3539
  if (!shouldOpenPrs) {
3540
+ // Inform user about local mode when fixes will be applied.
3541
+ if (!onlyCompute && ghsas.length) {
3542
+ const envCheck = checkCiEnvVars();
3543
+ if (envCheck.present.length) {
3544
+ // Some CI vars are set but not all - show what's missing.
3545
+ if (envCheck.missing.length) {
3546
+ logger.logger.info('Running in local mode - fixes will be applied directly to your working directory.\n' + `Missing environment variables for PR creation: ${arrays.joinAnd(envCheck.missing)}`);
3547
+ }
3548
+ } else {
3549
+ // No CI vars are present - show general local mode message.
3550
+ logger.logger.info('Running in local mode - fixes will be applied directly to your working directory.\n' + getCiEnvInstructions());
3551
+ }
3552
+ }
3489
3553
  const ids = isAll ? ['all'] : ghsas.slice(0, limit);
3490
3554
  if (!ids.length) {
3491
3555
  spinner?.stop();
@@ -3630,6 +3694,16 @@ async function coanaFix(fixConfig) {
3630
3694
  }
3631
3695
 
3632
3696
  // Set up git remote.
3697
+ if (!fixEnv.githubToken) {
3698
+ logger.logger.error('Cannot create pull request: SOCKET_CLI_GITHUB_TOKEN environment variable is not set.\n' + 'Set SOCKET_CLI_GITHUB_TOKEN or GITHUB_TOKEN to enable PR creation.');
3699
+ // eslint-disable-next-line no-await-in-loop
3700
+ await utils.gitResetAndClean(fixEnv.baseBranch, cwd);
3701
+ // eslint-disable-next-line no-await-in-loop
3702
+ await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
3703
+ // eslint-disable-next-line no-await-in-loop
3704
+ await utils.gitDeleteBranch(branch, cwd);
3705
+ continue ghsaLoop;
3706
+ }
3633
3707
  // eslint-disable-next-line no-await-in-loop
3634
3708
  await utils.setGitRemoteGithubRepoUrl(fixEnv.repoInfo.owner, fixEnv.repoInfo.repo, fixEnv.githubToken, cwd);
3635
3709
 
@@ -3751,7 +3825,7 @@ async function convertIdsToGhsas(ids) {
3751
3825
  const conversionResult = await utils.convertPurlToGhsas(trimmedId);
3752
3826
  if (conversionResult.ok && conversionResult.data.length) {
3753
3827
  validGhsas.push(...conversionResult.data);
3754
- logger.logger.info(`Converted ${trimmedId} to ${conversionResult.data.length} GHSA(s): ${conversionResult.data.join(', ')}`);
3828
+ logger.logger.info(`Converted ${trimmedId} to ${conversionResult.data.length} GHSA(s): ${arrays.joinAnd(conversionResult.data)}`);
3755
3829
  } else {
3756
3830
  errors.push(`${trimmedId}: ${conversionResult.message || 'No GHSAs found'}`);
3757
3831
  }
@@ -3925,8 +3999,15 @@ async function run$K(argv, importMeta, {
3925
3999
  Options
3926
4000
  ${utils.getFlagListOutput(config.flags)}
3927
4001
 
4002
+ Environment Variables (for CI/PR mode)
4003
+ CI Set to enable CI mode
4004
+ SOCKET_CLI_GITHUB_TOKEN GitHub token for PR creation (or GITHUB_TOKEN)
4005
+ SOCKET_CLI_GIT_USER_NAME Git username for commits
4006
+ SOCKET_CLI_GIT_USER_EMAIL Git email for commits
4007
+
3928
4008
  Examples
3929
4009
  $ ${command}
4010
+ $ ${command} --id CVE-2021-23337
3930
4011
  $ ${command} ./path/to/project --range-style pin
3931
4012
  `
3932
4013
  };
@@ -4614,6 +4695,8 @@ async function runCdxgen(argvObj) {
4614
4695
  shadowResult.spawnPromise.process.on('exit', () => {
4615
4696
  if (cleanupPackageLock) {
4616
4697
  try {
4698
+ // TODO: Consider using trash instead of rmSync for safer deletion.
4699
+ // This removes the temporary package-lock.json we created for cdxgen.
4617
4700
  fs$1.rmSync(`./${PACKAGE_LOCK_JSON}`);
4618
4701
  } catch {}
4619
4702
  }
@@ -4879,7 +4962,7 @@ async function run$F(argv, importMeta, context) {
4879
4962
  // options or missing arguments.
4880
4963
  // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
4881
4964
  process.exitCode = 2;
4882
- logger.logger.fail(`Unknown ${words.pluralize('argument', unknownsCount)}: ${unknowns.join(', ')}`);
4965
+ logger.logger.fail(`Unknown ${words.pluralize('argument', unknownsCount)}: ${arrays.joinAnd(unknowns)}`);
4883
4966
  return;
4884
4967
  }
4885
4968
  if (dryRun) {
@@ -8405,7 +8488,7 @@ async function fetchPurlsShallowScore(purls, options) {
8405
8488
  return sockSdkCResult;
8406
8489
  }
8407
8490
  const sockSdk = sockSdkCResult.data;
8408
- logger.logger.info(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
8491
+ logger.logger.info(`Requesting shallow score data for ${purls.length} package urls (purl): ${arrays.joinAnd(purls)}`);
8409
8492
  const batchPackageCResult = await utils.handleApiCall(sockSdk.batchPackageFetch({
8410
8493
  components: purls.map(purl => ({
8411
8494
  purl
@@ -13963,7 +14046,7 @@ async function run$3(argv, importMeta, {
13963
14046
  }
13964
14047
  });
13965
14048
  if (argSet.size) {
13966
- logger.logger.info(`Warning: ignoring these excessive args: ${Array.from(argSet).join(', ')}`);
14049
+ logger.logger.info(`Warning: ignoring these excessive args: ${arrays.joinAnd(Array.from(argSet))}`);
13967
14050
  }
13968
14051
  const hasApiToken = utils.hasDefaultApiToken();
13969
14052
  const {
@@ -14652,5 +14735,5 @@ void (async () => {
14652
14735
  await utils.captureException(e);
14653
14736
  }
14654
14737
  })();
14655
- //# debugId=934b325d-4c21-4b37-9c71-c80f38f54d52
14738
+ //# debugId=243906f3-caec-435c-aaca-fe5ec4aeb381
14656
14739
  //# sourceMappingURL=cli.js.map