@socketsecurity/cli-with-sentry 0.15.32 → 0.15.34

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 (39) hide show
  1. package/dist/cli.js +297 -141
  2. package/dist/cli.js.map +1 -1
  3. package/dist/constants.js +3 -3
  4. package/dist/constants.js.map +1 -1
  5. package/dist/shadow-inject.js.map +1 -1
  6. package/dist/utils.js +128 -95
  7. package/dist/utils.js.map +1 -1
  8. package/external/@socketsecurity/registry/external/@inquirer/confirm.js +0 -1
  9. package/external/@socketsecurity/registry/external/@inquirer/input.js +0 -1
  10. package/external/@socketsecurity/registry/external/@inquirer/password.js +0 -1
  11. package/external/@socketsecurity/registry/external/@inquirer/search.js +0 -1
  12. package/external/@socketsecurity/registry/external/@inquirer/select.js +0 -1
  13. package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +0 -1
  14. package/external/@socketsecurity/registry/external/@npmcli/package-json/lib/read-package.js +0 -1
  15. package/external/@socketsecurity/registry/external/@npmcli/package-json/lib/sort.js +0 -1
  16. package/external/@socketsecurity/registry/external/@npmcli/promise-spawn.js +0 -1
  17. package/external/@socketsecurity/registry/external/@socketregistry/is-unicode-supported.js +0 -1
  18. package/external/@socketsecurity/registry/external/@socketregistry/packageurl-js.js +0 -1
  19. package/external/@socketsecurity/registry/external/@socketregistry/yocto-spinner.js +0 -1
  20. package/external/@socketsecurity/registry/external/@yarnpkg/extensions.js +0 -1
  21. package/external/@socketsecurity/registry/external/browserslist.js +0 -1
  22. package/external/@socketsecurity/registry/external/cacache.js +0 -1
  23. package/external/@socketsecurity/registry/external/fast-sort.js +0 -1
  24. package/external/@socketsecurity/registry/external/libnpmpack.js +0 -1
  25. package/external/@socketsecurity/registry/external/make-fetch-happen.js +0 -1
  26. package/external/@socketsecurity/registry/external/normalize-package-data.js +0 -1
  27. package/external/@socketsecurity/registry/external/npm-package-arg.js +0 -1
  28. package/external/@socketsecurity/registry/external/pacote.js +0 -1
  29. package/external/@socketsecurity/registry/external/picomatch.js +0 -1
  30. package/external/@socketsecurity/registry/external/semver.js +0 -1
  31. package/external/@socketsecurity/registry/external/signal-exit.js +0 -1
  32. package/external/@socketsecurity/registry/external/spdx-correct.js +0 -1
  33. package/external/@socketsecurity/registry/external/spdx-expression-parse.js +0 -1
  34. package/external/@socketsecurity/registry/external/tinyglobby.js +0 -1
  35. package/external/@socketsecurity/registry/external/validate-npm-package-name.js +0 -1
  36. package/external/@socketsecurity/registry/external/which.js +0 -1
  37. package/external/@socketsecurity/registry/external/yoctocolors-cjs.js +0 -1
  38. package/external/@socketsecurity/registry/lib/debug.js +37 -9
  39. package/package.json +5 -5
package/dist/utils.js CHANGED
@@ -376,7 +376,7 @@ let _cachedConfig;
376
376
  // When using --config or SOCKET_CLI_CONFIG, do not persist the config.
377
377
  let _readOnlyConfig = false;
378
378
  function overrideCachedConfig(jsonConfig) {
379
- debug.debugFn('Overriding entire config, marking config as read-only.');
379
+ debug.debugFn('override: full config (not stored)');
380
380
  let config;
381
381
  try {
382
382
  config = JSON.parse(String(jsonConfig));
@@ -417,7 +417,8 @@ function overrideCachedConfig(jsonConfig) {
417
417
  };
418
418
  }
419
419
  function overrideConfigApiToken(apiToken) {
420
- debug.debugFn('Overriding API token, marking config as read-only.');
420
+ debug.debugFn('override: API token (not stored)');
421
+
421
422
  // Set token to the local cached config and mark it read-only so it doesn't persist
422
423
  _cachedConfig = {
423
424
  ...vendor.configExports,
@@ -486,7 +487,7 @@ function captureExceptionSync(exception, hint) {
486
487
  if (!Sentry) {
487
488
  return '';
488
489
  }
489
- debug.debugFn(`Sending exception to Sentry.`);
490
+ debug.debugFn('send: exception to Sentry');
490
491
  return Sentry.captureException(exception, hint);
491
492
  }
492
493
 
@@ -607,13 +608,13 @@ async function handleApiCall(value, fetchingDesc) {
607
608
  spinner.successAndStop(`Received API response (after requesting ${fetchingDesc}).`);
608
609
  } catch (e) {
609
610
  spinner.failAndStop(`An error was thrown while requesting ${fetchingDesc}`);
610
- debug.debugFn(`${fetchingDesc} threw error:\n`, e);
611
611
  const message = `${e || 'No error message returned'}`;
612
- const cause = `${e || 'No error message returned'}`;
612
+ const reason = `${e || 'No error message returned'}`;
613
+ debug.debugFn(`${fetchingDesc} threw error:\n`, e);
613
614
  return {
614
615
  ok: false,
615
616
  message: 'Socket API returned an error',
616
- cause: `${message}${cause ? ` ( Reason: ${cause} )` : ''}`
617
+ cause: `${message}${reason ? ` ( Reason: ${reason} )` : ''}`
617
618
  };
618
619
  } finally {
619
620
  spinner.stop();
@@ -623,11 +624,14 @@ async function handleApiCall(value, fetchingDesc) {
623
624
  if (result.success === false) {
624
625
  const err = result;
625
626
  const message = `${err.error || 'No error message returned'}`;
627
+ const {
628
+ cause: reason
629
+ } = err;
626
630
  debug.debugFn(`${fetchingDesc} bad response:\n`, err);
627
631
  return {
628
632
  ok: false,
629
633
  message: 'Socket API returned an error',
630
- cause: `${message}${err.cause ? ` ( Reason: ${err.cause} )` : ''}`,
634
+ cause: `${message}${reason ? ` ( Reason: ${reason} )` : ''}`,
631
635
  data: {
632
636
  code: result.status
633
637
  }
@@ -645,13 +649,13 @@ async function handleApiCallNoSpinner(value, description) {
645
649
  try {
646
650
  result = await value;
647
651
  } catch (e) {
648
- debug.debugFn(`${description} threw error:\n`, e);
649
652
  const message = `${e || 'No error message returned'}`;
650
- const cause = `${e || 'No error message returned'}`;
653
+ const reason = `${e || 'No error message returned'}`;
654
+ debug.debugFn(`${description} threw error:\n`, e);
651
655
  return {
652
656
  ok: false,
653
657
  message: 'Socket API returned an error',
654
- cause: `${message}${cause ? ` ( Reason: ${cause} )` : ''}`
658
+ cause: `${message}${reason ? ` ( Reason: ${reason} )` : ''}`
655
659
  };
656
660
  }
657
661
 
@@ -750,13 +754,13 @@ async function queryApiSafeText(path, fetchSpinnerDesc) {
750
754
  } = constants;
751
755
  spinner.failAndStop(`An error was thrown while requesting ${fetchSpinnerDesc}`);
752
756
  }
753
- debug.debugFn('Error thrown trying to await queryApi():\n', e);
754
- const msg = e?.message;
757
+ const cause = e?.message;
758
+ debug.debugFn('catch: error in queryApi()\n', e);
755
759
  return {
756
760
  ok: false,
757
761
  message: 'API Request failed to complete',
758
- ...(msg ? {
759
- cause: msg
762
+ ...(cause ? {
763
+ cause
760
764
  } : {})
761
765
  };
762
766
  }
@@ -775,7 +779,7 @@ async function queryApiSafeText(path, fetchSpinnerDesc) {
775
779
  data
776
780
  };
777
781
  } catch (e) {
778
- debug.debugFn('Error thrown trying to await result.text():\n', e);
782
+ debug.debugFn('catch: await result.text()\n', e);
779
783
  return {
780
784
  ok: false,
781
785
  message: 'API Request failed to complete',
@@ -896,30 +900,33 @@ cols) {
896
900
  function serializeResultJson(data) {
897
901
  if (typeof data !== 'object' || !data) {
898
902
  process.exitCode = 1;
899
- // We should not allow to expect the json value to be "null", or a boolean/number/string, even if they are valid "json".
900
- const msg = 'There was a problem converting the data set to JSON. The JSON was not an object. Please try again without --json';
901
903
  debug.debugFn('typeof data=', typeof data);
902
904
  if (typeof data !== 'object' && data) {
903
905
  debug.debugFn('data:\n', data);
904
906
  }
907
+
908
+ // We should not allow the json value to be "null", or a boolean/number/string,
909
+ // even if they are valid "json".
910
+ const message = 'There was a problem converting the data set to JSON. The JSON was not an object. Please try again without --json';
905
911
  return JSON.stringify({
906
912
  ok: false,
907
913
  message: 'Unable to serialize JSON',
908
- data: msg
914
+ data: message
909
915
  }).trim() + '\n';
910
916
  }
911
917
  try {
912
918
  return JSON.stringify(data, null, 2).trim() + '\n';
913
919
  } catch (e) {
914
- debug.debugFn('Unexpected error:\n', e);
920
+ debug.debugFn('catch: unexpected\n', e);
915
921
  process.exitCode = 1;
922
+
916
923
  // This could be caused by circular references, which is an "us" problem
917
- const msg = 'There was a problem converting the data set to JSON. Please try again without --json';
918
- logger.logger.fail(msg);
924
+ const message = 'There was a problem converting the data set to JSON. Please try again without --json';
925
+ logger.logger.fail(message);
919
926
  return JSON.stringify({
920
927
  ok: false,
921
928
  message: 'Unable to serialize JSON',
922
- data: msg
929
+ data: message
923
930
  }).trim() + '\n';
924
931
  }
925
932
  }
@@ -1462,7 +1469,7 @@ function findNpmPathSync(npmBinPath) {
1462
1469
  }
1463
1470
  }
1464
1471
  async function getPackageFilesForScan(cwd, inputPaths, supportedFiles, config) {
1465
- debug.debugFn(`Resolving ${inputPaths.length} paths:\n`, inputPaths);
1472
+ debug.debugFn(`resolve: ${inputPaths.length} paths`, inputPaths);
1466
1473
 
1467
1474
  // Lazily access constants.spinner.
1468
1475
  const {
@@ -1483,7 +1490,7 @@ async function getPackageFilesForScan(cwd, inputPaths, supportedFiles, config) {
1483
1490
  }
1484
1491
  const packageFiles = await filterGlobResultToSupportedFiles(entries, supportedFiles);
1485
1492
  spinner.successAndStop(`Found ${packageFiles.length} local ${words.pluralize('file', packageFiles.length)}`);
1486
- debug.debugFn('Absolute paths:\n', packageFiles);
1493
+ debug.debugFn('paths: absolute', packageFiles);
1487
1494
  return packageFiles;
1488
1495
  }
1489
1496
 
@@ -2266,8 +2273,7 @@ function getCveInfoFromAlertsMap(alertsMap, options_) {
2266
2273
  error = e;
2267
2274
  }
2268
2275
  }
2269
- debug.debugFn('Unexpected condition: Invalid SocketPackageAlert.');
2270
- debug.debugDir(alert);
2276
+ debug.debugFn('fail: invalid SocketPackageAlert\n', alert);
2271
2277
  if (error) {
2272
2278
  // Explicitly use debugLog here.
2273
2279
  debug.debugLog(error);
@@ -2660,57 +2666,6 @@ const {
2660
2666
  } = constants;
2661
2667
  const AGENTS = [BUN, NPM, PNPM, YARN_BERRY, YARN_CLASSIC, VLT];
2662
2668
  const binByAgent = new Map([[BUN, BUN], [NPM, NPM], [PNPM, PNPM], [YARN_BERRY, YARN], [YARN_CLASSIC, YARN], [VLT, VLT]]);
2663
- async function getAgentExecPath(agent) {
2664
- const binName = binByAgent.get(agent);
2665
- if (binName === NPM) {
2666
- // Lazily access constants.npmExecPath.
2667
- return constants.npmExecPath;
2668
- }
2669
- return (await vendor.libExports$1(binName, {
2670
- nothrow: true
2671
- })) ?? binName;
2672
- }
2673
- async function getAgentVersion(agentExecPath, cwd) {
2674
- let result;
2675
- try {
2676
- result =
2677
- // Coerce version output into a valid semver version by passing it through
2678
- // semver.coerce which strips leading v's, carets (^), comparators (<,<=,>,>=,=),
2679
- // and tildes (~).
2680
- vendor.semverExports.coerce(
2681
- // All package managers support the "--version" flag.
2682
- (await spawn.spawn(agentExecPath, ['--version'], {
2683
- cwd,
2684
- // Lazily access constants.WIN32.
2685
- shell: constants.WIN32
2686
- })).stdout.trim()) ?? undefined;
2687
- } catch (e) {
2688
- debug.debugFn('Unexpected error:\n', e);
2689
- }
2690
- return result;
2691
- }
2692
-
2693
- // The order of LOCKS properties IS significant as it affects iteration order.
2694
- const LOCKS = {
2695
- [`bun${LOCK_EXT}`]: BUN,
2696
- [`bun${BINARY_LOCK_EXT}`]: BUN,
2697
- // If both package-lock.json and npm-shrinkwrap.json are present in the root
2698
- // of a project, npm-shrinkwrap.json will take precedence and package-lock.json
2699
- // will be ignored.
2700
- // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
2701
- 'npm-shrinkwrap.json': NPM,
2702
- 'package-lock.json': NPM,
2703
- 'pnpm-lock.yaml': PNPM,
2704
- 'pnpm-lock.yml': PNPM,
2705
- [`yarn${LOCK_EXT}`]: YARN_CLASSIC,
2706
- 'vlt-lock.json': VLT,
2707
- // Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
2708
- // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
2709
- //
2710
- // Unlike the other LOCKS keys this key contains a directory AND filename so
2711
- // it has to be handled differently.
2712
- 'node_modules/.package-lock.json': NPM
2713
- };
2714
2669
  const readLockFileByAgent = (() => {
2715
2670
  function wrapReader(reader) {
2716
2671
  return async (...args) => {
@@ -2746,6 +2701,57 @@ const readLockFileByAgent = (() => {
2746
2701
  return undefined;
2747
2702
  })], [NPM, defaultReader], [PNPM, defaultReader], [VLT, defaultReader], [YARN_BERRY, defaultReader], [YARN_CLASSIC, defaultReader]]);
2748
2703
  })();
2704
+
2705
+ // The order of LOCKS properties IS significant as it affects iteration order.
2706
+ const LOCKS = {
2707
+ [`bun${LOCK_EXT}`]: BUN,
2708
+ [`bun${BINARY_LOCK_EXT}`]: BUN,
2709
+ // If both package-lock.json and npm-shrinkwrap.json are present in the root
2710
+ // of a project, npm-shrinkwrap.json will take precedence and package-lock.json
2711
+ // will be ignored.
2712
+ // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
2713
+ 'npm-shrinkwrap.json': NPM,
2714
+ 'package-lock.json': NPM,
2715
+ 'pnpm-lock.yaml': PNPM,
2716
+ 'pnpm-lock.yml': PNPM,
2717
+ [`yarn${LOCK_EXT}`]: YARN_CLASSIC,
2718
+ 'vlt-lock.json': VLT,
2719
+ // Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
2720
+ // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
2721
+ //
2722
+ // Unlike the other LOCKS keys this key contains a directory AND filename so
2723
+ // it has to be handled differently.
2724
+ 'node_modules/.package-lock.json': NPM
2725
+ };
2726
+ async function getAgentExecPath(agent) {
2727
+ const binName = binByAgent.get(agent);
2728
+ if (binName === NPM) {
2729
+ // Lazily access constants.npmExecPath.
2730
+ return constants.npmExecPath;
2731
+ }
2732
+ return (await vendor.libExports$1(binName, {
2733
+ nothrow: true
2734
+ })) ?? binName;
2735
+ }
2736
+ async function getAgentVersion(agentExecPath, cwd) {
2737
+ let result;
2738
+ try {
2739
+ result =
2740
+ // Coerce version output into a valid semver version by passing it through
2741
+ // semver.coerce which strips leading v's, carets (^), comparators (<,<=,>,>=,=),
2742
+ // and tildes (~).
2743
+ vendor.semverExports.coerce(
2744
+ // All package managers support the "--version" flag.
2745
+ (await spawn.spawn(agentExecPath, ['--version'], {
2746
+ cwd,
2747
+ // Lazily access constants.WIN32.
2748
+ shell: constants.WIN32
2749
+ })).stdout.trim()) ?? undefined;
2750
+ } catch (e) {
2751
+ debug.debugFn('catch: unexpected\n', e);
2752
+ }
2753
+ return result;
2754
+ }
2749
2755
  async function detectPackageEnvironment({
2750
2756
  cwd = process.cwd(),
2751
2757
  onUnknown
@@ -2902,38 +2908,62 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
2902
2908
  const agentVersion = details.agentVersion ?? 'unknown';
2903
2909
  if (!details.agentSupported) {
2904
2910
  const minVersion = constants.minimumVersionByAgent.get(agent);
2905
- logger?.fail(cmdPrefixMessage(cmdName, `Requires ${agent} >=${minVersion}. Current version: ${agentVersion}.`));
2906
- return;
2911
+ return {
2912
+ ok: false,
2913
+ message: 'Version Mismatch',
2914
+ cause: cmdPrefixMessage(cmdName, `Requires ${agent} >=${minVersion}. Current version: ${agentVersion}.`)
2915
+ };
2907
2916
  }
2908
2917
  if (!details.nodeSupported) {
2909
2918
  const minVersion = constants.maintainedNodeVersions.last;
2910
- logger?.fail(cmdPrefixMessage(cmdName, `Requires Node >=${minVersion}. Current version: ${nodeVersion}.`));
2911
- return;
2919
+ return {
2920
+ ok: false,
2921
+ message: 'Version Mismatch',
2922
+ cause: cmdPrefixMessage(cmdName, `Requires Node >=${minVersion}. Current version: ${nodeVersion}.`)
2923
+ };
2912
2924
  }
2913
2925
  if (!details.pkgSupports.agent) {
2914
- logger?.fail(cmdPrefixMessage(cmdName, `Package engine "${agent}" requires ${pkgRequirements.agent}. Current version: ${agentVersion}`));
2915
- return;
2926
+ return {
2927
+ ok: false,
2928
+ message: 'Engine Mismatch',
2929
+ cause: cmdPrefixMessage(cmdName, `Package engine "${agent}" requires ${pkgRequirements.agent}. Current version: ${agentVersion}`)
2930
+ };
2916
2931
  }
2917
2932
  if (!details.pkgSupports.node) {
2918
- logger?.fail(cmdPrefixMessage(cmdName, `Package engine "node" requires ${pkgRequirements.node}. Current version: ${nodeVersion}`));
2919
- return;
2933
+ return {
2934
+ ok: false,
2935
+ message: 'Version Mismatch',
2936
+ cause: cmdPrefixMessage(cmdName, `Package engine "node" requires ${pkgRequirements.node}. Current version: ${nodeVersion}`)
2937
+ };
2920
2938
  }
2921
2939
  const lockName = details.lockName ?? 'lock file';
2922
2940
  if (details.lockName === undefined || details.lockSrc === undefined) {
2923
- logger?.fail(cmdPrefixMessage(cmdName, `No ${lockName} found`));
2924
- return;
2941
+ return {
2942
+ ok: false,
2943
+ message: 'Missing Lock File',
2944
+ cause: cmdPrefixMessage(cmdName, `No ${lockName} found`)
2945
+ };
2925
2946
  }
2926
2947
  if (details.lockSrc.trim() === '') {
2927
- logger?.fail(cmdPrefixMessage(cmdName, `${lockName} is empty`));
2928
- return;
2948
+ return {
2949
+ ok: false,
2950
+ message: 'Empty Lock File',
2951
+ cause: cmdPrefixMessage(cmdName, `${lockName} is empty`)
2952
+ };
2929
2953
  }
2930
2954
  if (details.pkgPath === undefined) {
2931
- logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
2932
- return;
2955
+ return {
2956
+ ok: false,
2957
+ message: 'Missing package.json',
2958
+ cause: cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`)
2959
+ };
2933
2960
  }
2934
2961
  if (prod && (agent === BUN || agent === YARN_BERRY)) {
2935
- logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${agent}${agentVersion ? `@${agentVersion}` : ''}`));
2936
- return;
2962
+ return {
2963
+ ok: false,
2964
+ message: 'Bad input',
2965
+ cause: cmdPrefixMessage(cmdName, `--prod not supported for ${agent}${agentVersion ? `@${agentVersion}` : ''}`)
2966
+ };
2937
2967
  }
2938
2968
  if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
2939
2969
  // Note: In tests we return <redacted> because otherwise snapshots will fail.
@@ -2944,7 +2974,10 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
2944
2974
  const redacting = constants.ENV.VITEST;
2945
2975
  logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${redacting ? REDACTED : details.lockPath}`));
2946
2976
  }
2947
- return details;
2977
+ return {
2978
+ ok: true,
2979
+ data: details
2980
+ };
2948
2981
  }
2949
2982
 
2950
2983
  const COMPLETION_CMD_PREFIX = 'complete -F _socket_completion';
@@ -3086,5 +3119,5 @@ exports.updateConfigValue = updateConfigValue;
3086
3119
  exports.validationFlags = validationFlags;
3087
3120
  exports.walkNestedMap = walkNestedMap;
3088
3121
  exports.writeSocketJson = writeSocketJson;
3089
- //# debugId=ec929ce8-d2ad-4474-bc64-e03115717674
3122
+ //# debugId=b1554986-4b7c-4c24-bcf5-3821d9e3eb87
3090
3123
  //# sourceMappingURL=utils.js.map