@socketsecurity/cli-with-sentry 0.15.64 → 1.0.1

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 (202) hide show
  1. package/dist/cli.js +2952 -3600
  2. package/dist/cli.js.map +1 -1
  3. package/dist/constants.js +4 -4
  4. package/dist/constants.js.map +1 -1
  5. package/dist/shadow-npm-inject.js +1 -61
  6. package/dist/shadow-npm-inject.js.map +1 -1
  7. package/dist/types/cli.d.mts +1 -0
  8. package/dist/types/commands/analytics/cmd-analytics.d.mts.map +1 -1
  9. package/dist/types/commands/audit-log/cmd-audit-log.d.mts.map +1 -1
  10. package/dist/types/commands/audit-log/output-audit-log.d.mts +2 -2
  11. package/dist/types/commands/audit-log/output-audit-log.d.mts.map +1 -1
  12. package/dist/types/commands/ci/cmd-ci.d.mts.map +1 -1
  13. package/dist/types/commands/config/cmd-config-auto.d.mts.map +1 -1
  14. package/dist/types/commands/config/cmd-config-get.d.mts.map +1 -1
  15. package/dist/types/commands/config/cmd-config-list.d.mts.map +1 -1
  16. package/dist/types/commands/config/cmd-config-set.d.mts.map +1 -1
  17. package/dist/types/commands/config/cmd-config-unset.d.mts.map +1 -1
  18. package/dist/types/commands/fix/agent-fix.d.mts +36 -0
  19. package/dist/types/commands/fix/agent-fix.d.mts.map +1 -0
  20. package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
  21. package/dist/types/commands/fix/get-actual-tree.d.mts +3 -0
  22. package/dist/types/commands/fix/get-actual-tree.d.mts.map +1 -0
  23. package/dist/types/commands/fix/handle-fix.d.mts +11 -1
  24. package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
  25. package/dist/types/commands/fix/npm-fix.d.mts +2 -10
  26. package/dist/types/commands/fix/npm-fix.d.mts.map +1 -1
  27. package/dist/types/commands/fix/pnpm-fix.d.mts +2 -10
  28. package/dist/types/commands/fix/pnpm-fix.d.mts.map +1 -1
  29. package/dist/types/commands/json/cmd-json.d.mts.map +1 -1
  30. package/dist/types/commands/login/attempt-login.d.mts +5 -1
  31. package/dist/types/commands/login/attempt-login.d.mts.map +1 -1
  32. package/dist/types/commands/logout/cmd-logout.d.mts.map +1 -1
  33. package/dist/types/commands/manifest/cmd-manifest-setup.d.mts.map +1 -1
  34. package/dist/types/commands/manifest/convert_gradle_to_maven.d.mts.map +1 -1
  35. package/dist/types/commands/npm/cmd-npm.d.mts.map +1 -1
  36. package/dist/types/commands/npx/cmd-npx.d.mts.map +1 -1
  37. package/dist/types/commands/optimize/get-overrides-by-agent.d.mts +35 -2
  38. package/dist/types/commands/optimize/get-overrides-by-agent.d.mts.map +1 -1
  39. package/dist/types/commands/organization/cmd-organization-dependencies.d.mts +10 -0
  40. package/dist/types/commands/organization/cmd-organization-dependencies.d.mts.map +1 -0
  41. package/dist/types/commands/organization/cmd-organization-list.d.mts.map +1 -1
  42. package/dist/types/commands/organization/cmd-organization-policy-license.d.mts.map +1 -1
  43. package/dist/types/commands/organization/cmd-organization-policy-security.d.mts +1 -1
  44. package/dist/types/commands/organization/cmd-organization-policy-security.d.mts.map +1 -1
  45. package/dist/types/commands/organization/cmd-organization-quota.d.mts.map +1 -1
  46. package/dist/types/commands/organization/cmd-organization.d.mts.map +1 -1
  47. package/dist/types/commands/{dependencies → organization}/fetch-dependencies.d.mts.map +1 -1
  48. package/dist/types/commands/{dependencies → organization}/handle-dependencies.d.mts.map +1 -1
  49. package/dist/types/commands/{dependencies → organization}/output-dependencies.d.mts.map +1 -1
  50. package/dist/types/commands/package/cmd-package-score.d.mts.map +1 -1
  51. package/dist/types/commands/package/cmd-package-shallow.d.mts.map +1 -1
  52. package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts.map +1 -1
  53. package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts.map +1 -1
  54. package/dist/types/commands/{diff-scan/cmd-diff-scan-get.d.mts → repository/cmd-repository-create.d.mts} +2 -2
  55. package/dist/types/commands/repository/cmd-repository-create.d.mts.map +1 -0
  56. package/dist/types/commands/{cdxgen/cmd-cdxgen.d.mts → repository/cmd-repository-del.d.mts} +2 -2
  57. package/dist/types/commands/repository/cmd-repository-del.d.mts.map +1 -0
  58. package/dist/types/commands/{dependencies/cmd-dependencies.d.mts → repository/cmd-repository-list.d.mts} +2 -2
  59. package/dist/types/commands/repository/cmd-repository-list.d.mts.map +1 -0
  60. package/dist/types/commands/repository/cmd-repository-update.d.mts +10 -0
  61. package/dist/types/commands/repository/cmd-repository-update.d.mts.map +1 -0
  62. package/dist/types/commands/{info/cmd-info.d.mts → repository/cmd-repository-view.d.mts} +2 -2
  63. package/dist/types/commands/repository/cmd-repository-view.d.mts.map +1 -0
  64. package/dist/types/commands/repository/cmd-repository.d.mts +3 -0
  65. package/dist/types/commands/repository/cmd-repository.d.mts.map +1 -0
  66. package/dist/types/commands/repository/fetch-create-repo.d.mts.map +1 -0
  67. package/dist/types/commands/repository/fetch-delete-repo.d.mts.map +1 -0
  68. package/dist/types/commands/repository/fetch-list-all-repos.d.mts.map +1 -0
  69. package/dist/types/commands/repository/fetch-list-repos.d.mts.map +1 -0
  70. package/dist/types/commands/repository/fetch-update-repo.d.mts.map +1 -0
  71. package/dist/types/commands/repository/fetch-view-repo.d.mts.map +1 -0
  72. package/dist/types/commands/repository/handle-create-repo.d.mts.map +1 -0
  73. package/dist/types/commands/repository/handle-delete-repo.d.mts.map +1 -0
  74. package/dist/types/commands/repository/handle-list-repos.d.mts.map +1 -0
  75. package/dist/types/commands/repository/handle-update-repo.d.mts.map +1 -0
  76. package/dist/types/commands/repository/handle-view-repo.d.mts.map +1 -0
  77. package/dist/types/commands/repository/output-create-repo.d.mts.map +1 -0
  78. package/dist/types/commands/repository/output-delete-repo.d.mts.map +1 -0
  79. package/dist/types/commands/repository/output-list-repos.d.mts.map +1 -0
  80. package/dist/types/commands/repository/output-update-repo.d.mts.map +1 -0
  81. package/dist/types/commands/repository/output-view-repo.d.mts.map +1 -0
  82. package/dist/types/commands/scan/cmd-scan-create.d.mts.map +1 -1
  83. package/dist/types/commands/scan/cmd-scan-del.d.mts.map +1 -1
  84. package/dist/types/commands/scan/cmd-scan-diff.d.mts.map +1 -1
  85. package/dist/types/commands/scan/cmd-scan-github.d.mts.map +1 -1
  86. package/dist/types/commands/scan/cmd-scan-list.d.mts.map +1 -1
  87. package/dist/types/commands/scan/cmd-scan-metadata.d.mts.map +1 -1
  88. package/dist/types/commands/scan/cmd-scan-report.d.mts.map +1 -1
  89. package/dist/types/commands/scan/cmd-scan-view.d.mts.map +1 -1
  90. package/dist/types/commands/scan/cmd-scan.d.mts.map +1 -1
  91. package/dist/types/commands/scan/handle-create-github-scan.d.mts.map +1 -1
  92. package/dist/types/commands/scan/output-scan-github.d.mts +3 -0
  93. package/dist/types/commands/scan/output-scan-github.d.mts.map +1 -0
  94. package/dist/types/commands/scan/suggest-org-slug.d.mts.map +1 -1
  95. package/dist/types/commands/scan/suggest-to-persist-orgslug.d.mts +2 -0
  96. package/dist/types/commands/scan/suggest-to-persist-orgslug.d.mts.map +1 -0
  97. package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts.map +1 -1
  98. package/dist/types/commands/threat-feed/output-threat-feed.d.mts.map +1 -1
  99. package/dist/types/commands/wrapper/cmd-wrapper.d.mts.map +1 -1
  100. package/dist/types/utils/config.d.mts +3 -4
  101. package/dist/types/utils/config.d.mts.map +1 -1
  102. package/dist/types/utils/determine-org-slug.d.mts +1 -1
  103. package/dist/types/utils/determine-org-slug.d.mts.map +1 -1
  104. package/dist/types/utils/lockfile.d.mts +2 -0
  105. package/dist/types/utils/lockfile.d.mts.map +1 -0
  106. package/dist/types/utils/meow-with-subcommands.d.mts +1 -1
  107. package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
  108. package/dist/types/utils/ms-at-home.d.mts +2 -0
  109. package/dist/types/utils/ms-at-home.d.mts.map +1 -0
  110. package/dist/types/utils/package-environment.d.mts +11 -11
  111. package/dist/types/utils/package-environment.d.mts.map +1 -1
  112. package/dist/types/utils/pnpm.d.mts +1 -1
  113. package/dist/types/utils/pnpm.d.mts.map +1 -1
  114. package/dist/types/utils/semver.d.mts.map +1 -1
  115. package/dist/utils.js +308 -326
  116. package/dist/utils.js.map +1 -1
  117. package/dist/vendor.js +17131 -17120
  118. package/external/@coana-tech/cli/cli.mjs +14035 -3820
  119. package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +7 -7
  120. package/external/@socketsecurity/registry/external/@socketregistry/packageurl-js.js +12 -8
  121. package/external/@socketsecurity/registry/external/cacache.js +6 -6
  122. package/external/@socketsecurity/registry/external/libnpmpack.js +47 -45
  123. package/external/@socketsecurity/registry/external/make-fetch-happen.js +37 -36
  124. package/external/@socketsecurity/registry/external/pacote.js +45 -44
  125. package/external/blessed-contrib/lib/widget/charts/bar.js +6 -3
  126. package/external/blessed-contrib/lib/widget/charts/line.js +6 -3
  127. package/package.json +28 -28
  128. package/dist/types/commands/cdxgen/cmd-cdxgen.d.mts.map +0 -1
  129. package/dist/types/commands/cdxgen/handle-cdxgen.d.mts +0 -4
  130. package/dist/types/commands/cdxgen/handle-cdxgen.d.mts.map +0 -1
  131. package/dist/types/commands/dependencies/cmd-dependencies.d.mts.map +0 -1
  132. package/dist/types/commands/diff-scan/cmd-diff-scan-get.d.mts.map +0 -1
  133. package/dist/types/commands/diff-scan/cmd-diff-scan.d.mts +0 -3
  134. package/dist/types/commands/diff-scan/cmd-diff-scan.d.mts.map +0 -1
  135. package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts +0 -8
  136. package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts.map +0 -1
  137. package/dist/types/commands/diff-scan/handle-diff-scan.d.mts +0 -10
  138. package/dist/types/commands/diff-scan/handle-diff-scan.d.mts.map +0 -1
  139. package/dist/types/commands/diff-scan/output-diff-scan.d.mts +0 -8
  140. package/dist/types/commands/diff-scan/output-diff-scan.d.mts.map +0 -1
  141. package/dist/types/commands/fix/run-fix.d.mts +0 -12
  142. package/dist/types/commands/fix/run-fix.d.mts.map +0 -1
  143. package/dist/types/commands/info/cmd-info.d.mts.map +0 -1
  144. package/dist/types/commands/info/fetch-package-info.d.mts +0 -3
  145. package/dist/types/commands/info/fetch-package-info.d.mts.map +0 -1
  146. package/dist/types/commands/info/handle-package-info.d.mts +0 -17
  147. package/dist/types/commands/info/handle-package-info.d.mts.map +0 -1
  148. package/dist/types/commands/info/output-package-info.d.mts +0 -10
  149. package/dist/types/commands/info/output-package-info.d.mts.map +0 -1
  150. package/dist/types/commands/report/cmd-report-create.d.mts +0 -10
  151. package/dist/types/commands/report/cmd-report-create.d.mts.map +0 -1
  152. package/dist/types/commands/report/cmd-report-view.d.mts +0 -10
  153. package/dist/types/commands/report/cmd-report-view.d.mts.map +0 -1
  154. package/dist/types/commands/report/cmd-report.d.mts +0 -3
  155. package/dist/types/commands/report/cmd-report.d.mts.map +0 -1
  156. package/dist/types/commands/repos/cmd-repos-create.d.mts +0 -10
  157. package/dist/types/commands/repos/cmd-repos-create.d.mts.map +0 -1
  158. package/dist/types/commands/repos/cmd-repos-del.d.mts +0 -10
  159. package/dist/types/commands/repos/cmd-repos-del.d.mts.map +0 -1
  160. package/dist/types/commands/repos/cmd-repos-list.d.mts +0 -10
  161. package/dist/types/commands/repos/cmd-repos-list.d.mts.map +0 -1
  162. package/dist/types/commands/repos/cmd-repos-update.d.mts +0 -10
  163. package/dist/types/commands/repos/cmd-repos-update.d.mts.map +0 -1
  164. package/dist/types/commands/repos/cmd-repos-view.d.mts +0 -10
  165. package/dist/types/commands/repos/cmd-repos-view.d.mts.map +0 -1
  166. package/dist/types/commands/repos/cmd-repos.d.mts +0 -3
  167. package/dist/types/commands/repos/cmd-repos.d.mts.map +0 -1
  168. package/dist/types/commands/repos/fetch-create-repo.d.mts.map +0 -1
  169. package/dist/types/commands/repos/fetch-delete-repo.d.mts.map +0 -1
  170. package/dist/types/commands/repos/fetch-list-all-repos.d.mts.map +0 -1
  171. package/dist/types/commands/repos/fetch-list-repos.d.mts.map +0 -1
  172. package/dist/types/commands/repos/fetch-update-repo.d.mts.map +0 -1
  173. package/dist/types/commands/repos/fetch-view-repo.d.mts.map +0 -1
  174. package/dist/types/commands/repos/handle-create-repo.d.mts.map +0 -1
  175. package/dist/types/commands/repos/handle-delete-repo.d.mts.map +0 -1
  176. package/dist/types/commands/repos/handle-list-repos.d.mts.map +0 -1
  177. package/dist/types/commands/repos/handle-update-repo.d.mts.map +0 -1
  178. package/dist/types/commands/repos/handle-view-repo.d.mts.map +0 -1
  179. package/dist/types/commands/repos/output-create-repo.d.mts.map +0 -1
  180. package/dist/types/commands/repos/output-delete-repo.d.mts.map +0 -1
  181. package/dist/types/commands/repos/output-list-repos.d.mts.map +0 -1
  182. package/dist/types/commands/repos/output-update-repo.d.mts.map +0 -1
  183. package/dist/types/commands/repos/output-view-repo.d.mts.map +0 -1
  184. /package/dist/types/commands/{dependencies → organization}/fetch-dependencies.d.mts +0 -0
  185. /package/dist/types/commands/{dependencies → organization}/handle-dependencies.d.mts +0 -0
  186. /package/dist/types/commands/{dependencies → organization}/output-dependencies.d.mts +0 -0
  187. /package/dist/types/commands/{repos → repository}/fetch-create-repo.d.mts +0 -0
  188. /package/dist/types/commands/{repos → repository}/fetch-delete-repo.d.mts +0 -0
  189. /package/dist/types/commands/{repos → repository}/fetch-list-all-repos.d.mts +0 -0
  190. /package/dist/types/commands/{repos → repository}/fetch-list-repos.d.mts +0 -0
  191. /package/dist/types/commands/{repos → repository}/fetch-update-repo.d.mts +0 -0
  192. /package/dist/types/commands/{repos → repository}/fetch-view-repo.d.mts +0 -0
  193. /package/dist/types/commands/{repos → repository}/handle-create-repo.d.mts +0 -0
  194. /package/dist/types/commands/{repos → repository}/handle-delete-repo.d.mts +0 -0
  195. /package/dist/types/commands/{repos → repository}/handle-list-repos.d.mts +0 -0
  196. /package/dist/types/commands/{repos → repository}/handle-update-repo.d.mts +0 -0
  197. /package/dist/types/commands/{repos → repository}/handle-view-repo.d.mts +0 -0
  198. /package/dist/types/commands/{repos → repository}/output-create-repo.d.mts +0 -0
  199. /package/dist/types/commands/{repos → repository}/output-delete-repo.d.mts +0 -0
  200. /package/dist/types/commands/{repos → repository}/output-list-repos.d.mts +0 -0
  201. /package/dist/types/commands/{repos → repository}/output-update-repo.d.mts +0 -0
  202. /package/dist/types/commands/{repos → repository}/output-view-repo.d.mts +0 -0
package/dist/utils.js CHANGED
@@ -279,7 +279,7 @@ function safeReadFileSync(filepath, options) {
279
279
  }
280
280
 
281
281
  const sensitiveConfigKeys = new Set(['apiToken']);
282
- const supportedConfigKeys = new Map([['apiBaseUrl', 'Base URL of the API endpoint'], ['apiProxy', 'A proxy through which to access the API'], ['apiToken', 'The API token required to access most API endpoints'], ['defaultOrg', 'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'], ['enforcedOrgs', 'Orgs in this list have their security policies enforced on this machine'], ['isTestingV1', 'For development of testing the next major bump']]);
282
+ const supportedConfigKeys = new Map([['apiBaseUrl', 'Base URL of the API endpoint'], ['apiProxy', 'A proxy through which to access the API'], ['apiToken', 'The API token required to access most API endpoints'], ['defaultOrg', 'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'], ['enforcedOrgs', 'Orgs in this list have their security policies enforced on this machine'], ['skipAskToPersistDefaultOrg', 'This flag prevents the CLI from asking you to persist the org slug when you selected one interactively'], ['org', 'Alias for defaultOrg']]);
283
283
  function getConfigValues() {
284
284
  if (_cachedConfig === undefined) {
285
285
  // Order: env var > --config flag > file
@@ -315,7 +315,8 @@ function getConfigValues() {
315
315
  function normalizeConfigKey(key) {
316
316
  // Note: apiKey was the old name of the token. When we load a config with
317
317
  // property apiKey, we'll copy that to apiToken and delete the old property.
318
- const normalizedKey = key === 'apiKey' ? 'apiToken' : key;
318
+ // We added `org` as a convenience alias for `defaultOrg`
319
+ const normalizedKey = key === 'apiKey' ? 'apiToken' : key === 'org' ? 'defaultOrg' : key;
319
320
  if (!supportedConfigKeys.has(normalizedKey)) {
320
321
  return {
321
322
  ok: false,
@@ -325,7 +326,7 @@ function normalizeConfigKey(key) {
325
326
  }
326
327
  return {
327
328
  ok: true,
328
- data: key
329
+ data: normalizedKey
329
330
  };
330
331
  }
331
332
  function findSocketYmlSync(dir = process.cwd()) {
@@ -377,9 +378,6 @@ function getConfigValueOrUndef(key) {
377
378
  function isReadOnlyConfig() {
378
379
  return _readOnlyConfig;
379
380
  }
380
- function isTestingV1() {
381
- return !!getConfigValueOrUndef('isTestingV1');
382
- }
383
381
  let _cachedConfig;
384
382
  // When using --config or SOCKET_CLI_CONFIG, do not persist the config.
385
383
  let _readOnlyConfig = false;
@@ -411,7 +409,7 @@ function overrideCachedConfig(jsonConfig) {
411
409
  _cachedConfig = config;
412
410
  _readOnlyConfig = true;
413
411
 
414
- // Normalize apiKey to apiToken.
412
+ // Normalize apiKey to apiToken
415
413
  if (_cachedConfig['apiKey']) {
416
414
  if (_cachedConfig['apiToken']) {
417
415
  logger.logger.warn('Note: The config override had both apiToken and apiKey. Using the apiToken value. Remove the apiKey to get rid of this message.');
@@ -437,17 +435,31 @@ function overrideConfigApiToken(apiToken) {
437
435
  _readOnlyConfig = true;
438
436
  }
439
437
  let _pendingSave = false;
440
- function updateConfigValue(key, value) {
438
+ function updateConfigValue(configKey, value) {
441
439
  const localConfig = getConfigValues();
442
- const keyResult = normalizeConfigKey(key);
440
+ const keyResult = normalizeConfigKey(configKey);
443
441
  if (!keyResult.ok) {
444
442
  return keyResult;
445
443
  }
446
- localConfig[keyResult.data] = value;
444
+ const key = keyResult.data;
445
+ let wasDeleted = value === undefined; // implicitly when serializing
446
+ if (key === 'skipAskToPersistDefaultOrg') {
447
+ if (value === 'true' || value === 'false') {
448
+ localConfig['skipAskToPersistDefaultOrg'] = value === 'true';
449
+ } else {
450
+ delete localConfig['skipAskToPersistDefaultOrg'];
451
+ wasDeleted = true;
452
+ }
453
+ } else {
454
+ if (value === 'undefined' || value === 'true' || value === 'false') {
455
+ logger.logger.warn(`Note: The value is set to "${value}", as a string (!). Use \`socket config unset\` to reset a key.`);
456
+ }
457
+ localConfig[key] = value;
458
+ }
447
459
  if (_readOnlyConfig) {
448
460
  return {
449
461
  ok: true,
450
- message: `Config key '${key}' was updated`,
462
+ message: `Config key '${key}' was ${wasDeleted ? 'deleted' : `updated`}`,
451
463
  data: 'Change applied but not persisted; current config is overridden through env var or flag'
452
464
  };
453
465
  }
@@ -466,7 +478,7 @@ function updateConfigValue(key, value) {
466
478
  }
467
479
  return {
468
480
  ok: true,
469
- message: `Config key '${key}' was updated`,
481
+ message: `Config key '${key}' was ${wasDeleted ? 'deleted' : `updated`}`,
470
482
  data: undefined
471
483
  };
472
484
  }
@@ -587,21 +599,6 @@ async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApi
587
599
  };
588
600
  }
589
601
 
590
- // TODO: this function is removed after v1.0.0
591
- function handleUnsuccessfulApiResponse(_name, error, cause, status) {
592
- const message = `${error || 'No error message returned'}${cause ? ` (reason: ${cause})` : ''}`;
593
- if (status === 401 || status === 403) {
594
- // Lazily access constants.spinner.
595
- const {
596
- spinner
597
- } = constants;
598
- spinner.stop();
599
- throw new AuthError(message);
600
- }
601
- logger.logger.fail(failMsgWithBadge('Socket API returned an error', message));
602
- // eslint-disable-next-line n/no-process-exit
603
- process.exit(1);
604
- }
605
602
  async function handleApiCall(value, fetchingDesc) {
606
603
  // Lazily access constants.spinner.
607
604
  const {
@@ -992,18 +989,6 @@ const outputFlags = {
992
989
  description: 'Output result as markdown'
993
990
  }
994
991
  };
995
- const validationFlags = {
996
- all: {
997
- type: 'boolean',
998
- default: false,
999
- description: 'Include all issues'
1000
- },
1001
- strict: {
1002
- type: 'boolean',
1003
- default: false,
1004
- description: 'Exits with an error code if any matching issues are found'
1005
- }
1006
- };
1007
992
 
1008
993
  function checkCommandInput(outputKind, ...checks) {
1009
994
  if (checks.every(d => d.test)) {
@@ -1182,6 +1167,7 @@ async function meowWithSubcommands(subcommands, options) {
1182
1167
  // Plus, if we allow this then meow() can just exit here.
1183
1168
  autoHelp: false
1184
1169
  });
1170
+ const orgFlag = String(cli1.flags['org'] || '') || undefined;
1185
1171
 
1186
1172
  // Hard override the config if instructed to do so.
1187
1173
  // The env var overrides the --flag, which overrides the persisted config
@@ -1211,7 +1197,8 @@ async function meowWithSubcommands(subcommands, options) {
1211
1197
  }
1212
1198
  }
1213
1199
  if (configOverrideResult?.ok === false) {
1214
- emitBanner(name);
1200
+ emitBanner(name, orgFlag);
1201
+ logger.logger.error(''); // spacing in stderr
1215
1202
  logger.logger.fail(configOverrideResult.message);
1216
1203
  process.exitCode = 2;
1217
1204
  return;
@@ -1231,13 +1218,8 @@ async function meowWithSubcommands(subcommands, options) {
1231
1218
  });
1232
1219
  }
1233
1220
  }
1234
- if (isTestingV1()) {
1235
- delete subcommands['diff-scan'];
1236
- delete subcommands['info'];
1237
- delete subcommands['report'];
1238
- }
1239
1221
  function formatCommandsForHelp(isRootCommand) {
1240
- if (!isRootCommand || !isTestingV1()) {
1222
+ if (!isRootCommand) {
1241
1223
  return getHelpListOutput({
1242
1224
  ...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
1243
1225
  1: subcommand
@@ -1256,7 +1238,7 @@ async function meowWithSubcommands(subcommands, options) {
1256
1238
  }
1257
1239
 
1258
1240
  // "Bucket" some commands for easier usage.
1259
- const commands = new Set(['analytics', 'audit-log', 'config', 'dependencies', 'fix', 'install', 'login', 'logout', 'manifest', 'npm', 'npx', 'optimize', 'organization', 'package', 'raw-npm', 'raw-npx', 'repos', 'scan', 'threat-feed', 'uninstall', 'wrapper']);
1241
+ const commands = new Set(['analytics', 'audit-log', 'config', 'fix', 'install', 'login', 'logout', 'manifest', 'npm', 'npx', 'optimize', 'organization', 'package', 'raw-npm', 'raw-npx', 'repos', 'scan', 'threat-feed', 'uninstall', 'wrapper']);
1260
1242
  Object.entries(subcommands).filter(([_name, subcommand]) => !subcommand.hidden).map(([name]) => name).forEach(name => {
1261
1243
  if (commands.has(name)) {
1262
1244
  commands.delete(name);
@@ -1317,14 +1299,13 @@ async function meowWithSubcommands(subcommands, options) {
1317
1299
  const cli2 = vendor.meow(`
1318
1300
  Usage
1319
1301
  $ ${name} <command>
1320
-
1321
- ${isRootCommand && isTestingV1() ? '' : ' Commands'}
1302
+ ${isRootCommand ? '' : '\n Commands'}
1322
1303
  ${formatCommandsForHelp(isRootCommand)}
1323
1304
 
1324
- ${isRootCommand && isTestingV1() ? ' Options' : ' Options'}${isRootCommand ? ' (Note: all CLI commands have these flags even when not displayed in their help)\n' : ''}
1325
- ${getFlagListOutput(flags, 6, isTestingV1() ? {
1305
+ ${isRootCommand ? ' Options' : ' Options'}${isRootCommand ? ' (Note: all CLI commands have these flags even when not displayed in their help)\n' : ''}
1306
+ ${getFlagListOutput(flags, 6, {
1326
1307
  padName: 25
1327
- } : undefined)}
1308
+ })}
1328
1309
 
1329
1310
  Examples
1330
1311
  $ ${name} --help
@@ -1344,7 +1325,8 @@ ${isRootCommand ? ` $ ${name} scan create --json` : ''}${isRootCommand ? `\
1344
1325
 
1345
1326
  // ...else we provide basic instructions and help.
1346
1327
  if (!cli2.flags['nobanner']) {
1347
- emitBanner(name);
1328
+ emitBanner(name, orgFlag);
1329
+ // meow will add newline so don't add stderr spacing here
1348
1330
  }
1349
1331
  if (!cli2.flags['help'] && cli2.flags['dryRun']) {
1350
1332
  process.exitCode = 0;
@@ -1383,7 +1365,9 @@ function meowOrExit({
1383
1365
  autoHelp: false // meow will exit(0) before printing the banner
1384
1366
  });
1385
1367
  if (!cli.flags['nobanner']) {
1386
- emitBanner(command);
1368
+ emitBanner(command, String(cli.flags['org'] || '') || undefined);
1369
+ // Add spacing in stderr. meow.help adds a newline too so we do it here
1370
+ logger.logger.error('');
1387
1371
  }
1388
1372
 
1389
1373
  // As per https://github.com/sindresorhus/meow/issues/178
@@ -1424,7 +1408,7 @@ function meowOrExit({
1424
1408
  process.exitCode = 0;
1425
1409
  return cli;
1426
1410
  }
1427
- function emitBanner(name) {
1411
+ function emitBanner(name, orgFlag) {
1428
1412
  // Print a banner at the top of each command.
1429
1413
  // This helps with brand recognition and marketing.
1430
1414
  // It also helps with debugging since it contains version and command details.
@@ -1433,9 +1417,9 @@ function emitBanner(name) {
1433
1417
  // and pipe the result to other tools. By emitting the banner over stderr
1434
1418
  // you can do something like `socket scan view xyz | jq | process`.
1435
1419
  // The spinner also emits over stderr for example.
1436
- logger.logger.error(getAsciiHeader(name));
1420
+ logger.logger.error(getAsciiHeader(name, orgFlag));
1437
1421
  }
1438
- function getAsciiHeader(command) {
1422
+ function getAsciiHeader(command, orgFlag) {
1439
1423
  // Note: In tests we return <redacted> because otherwise snapshots will fail.
1440
1424
  const {
1441
1425
  REDACTED
@@ -1448,23 +1432,42 @@ function getAsciiHeader(command) {
1448
1432
  const nodeVersion = redacting ? REDACTED : process.version;
1449
1433
  const defaultOrg = getConfigValueOrUndef('defaultOrg');
1450
1434
  const readOnlyConfig = isReadOnlyConfig() ? '*' : '.';
1451
- const v1test = isTestingV1() ? ' (is testing v1)' : '';
1452
- const feedback = isTestingV1() ? vendor.yoctocolorsCjsExports.green(' (Thank you for testing the v1 bump! Please send us any feedback you might have!)\n') : '';
1453
- const shownToken = redacting ? REDACTED : getVisibleTokenPrefix() || 'no';
1435
+ const shownToken = redacting ? REDACTED : getVisibleTokenPrefix() || '(not set)';
1454
1436
  const relCwd = redacting ? REDACTED : path$1.normalizePath(tildify(process.cwd()));
1455
- let nodeVerWarn = '';
1456
- if (vendor.semverExports.parse(constants.NODE_VERSION).major < 20) {
1457
- nodeVerWarn += vendor.yoctocolorsCjsExports.bold(` ${vendor.yoctocolorsCjsExports.red('Warning:')} NodeJS version 19 and lower will be ${vendor.yoctocolorsCjsExports.red('unsupported')} after April 30th, 2025.`);
1458
- nodeVerWarn += '\n';
1459
- nodeVerWarn += ' Soon after the Socket CLI will require NodeJS version 20 or higher.';
1460
- nodeVerWarn += '\n';
1461
- }
1437
+ // Note: we must redact org when creating snapshots because dev machine probably
1438
+ // has a default org set but CI won't. Showing --org is fine either way.
1439
+ const orgPart = orgFlag ? `--org: ${orgFlag}` : redacting ? 'org: <redacted>' : defaultOrg ? `default org: ${defaultOrg}` : '(org not set)';
1440
+ // Note: We could draw these with ascii box art instead but I worry about
1441
+ // portability and paste-ability. "simple" ascii chars just work.
1462
1442
  const body = `
1463
1443
  _____ _ _ /---------------
1464
- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}${v1test}
1465
- |__ | ${readOnlyConfig} | _| '_| -_| _| | Node: ${nodeVersion}, API token set: ${shownToken}${defaultOrg ? `, default org: ${redacting ? REDACTED : defaultOrg}` : ''}
1466
- |_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}`.trimStart();
1467
- return ` ${body}\n${nodeVerWarn}${feedback}`;
1444
+ | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}
1445
+ |__ | ${readOnlyConfig} | _| '_| -_| _| | Node: ${nodeVersion}, API token: ${shownToken}, ${orgPart}
1446
+ |_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}
1447
+ `.trim();
1448
+ return ` ${body}`; // Note: logger will auto-append a newline
1449
+ }
1450
+
1451
+ function msAtHome(isoTimeStamp) {
1452
+ const timeStart = Date.parse(isoTimeStamp);
1453
+ const timeEnd = Date.now();
1454
+ const rtf = new Intl.RelativeTimeFormat('en', {
1455
+ numeric: 'always',
1456
+ style: 'short'
1457
+ });
1458
+ const delta = timeEnd - timeStart;
1459
+ if (delta < 60 * 60 * 1000) {
1460
+ return rtf.format(-Math.round(delta / (60 * 1000)), 'minute');
1461
+ // return Math.round(delta / (60 * 1000)) + ' min ago'
1462
+ } else if (delta < 24 * 60 * 60 * 1000) {
1463
+ return rtf.format(-(delta / (60 * 60 * 1000)).toFixed(1), 'hour');
1464
+ // return (delta / (60 * 60 * 1000)).toFixed(1) + ' hr ago'
1465
+ } else if (delta < 7 * 24 * 60 * 60 * 1000) {
1466
+ return rtf.format(-(delta / (24 * 60 * 60 * 1000)).toFixed(1), 'day');
1467
+ // return (delta / (24 * 60 * 60 * 1000)).toFixed(1) + ' day ago'
1468
+ } else {
1469
+ return isoTimeStamp.slice(0, 10);
1470
+ }
1468
1471
  }
1469
1472
 
1470
1473
  async function suggestOrgSlug() {
@@ -1493,6 +1496,9 @@ async function suggestOrgSlug() {
1493
1496
  description: 'Do not use any of these organizations (will end in a no-op)'
1494
1497
  }]
1495
1498
  });
1499
+ if (proceed === undefined) {
1500
+ return undefined;
1501
+ }
1496
1502
  if (proceed) {
1497
1503
  return proceed;
1498
1504
  }
@@ -1501,28 +1507,127 @@ async function suggestOrgSlug() {
1501
1507
  }
1502
1508
  }
1503
1509
 
1504
- async function determineOrgSlug(orgFlag, firstArg, interactive, dryRun) {
1510
+ async function suggestToPersistOrgSlug(orgSlug) {
1511
+ const skipAsk = getConfigValue('skipAskToPersistDefaultOrg');
1512
+ if (!skipAsk.ok || skipAsk.data) {
1513
+ // Don't ask to store it when disabled before, or when reading config fails.
1514
+ return;
1515
+ }
1516
+ const result = await prompts.select({
1517
+ message: `Would you like to use this org (${orgSlug}) as the default org for future calls?`,
1518
+ choices: [{
1519
+ name: 'Yes',
1520
+ value: 'yes',
1521
+ description: 'Stores it in your config'
1522
+ }, {
1523
+ name: 'No',
1524
+ value: 'no',
1525
+ description: 'Do not persist this org as default org'
1526
+ }, {
1527
+ name: "No and don't ask again",
1528
+ value: 'sush',
1529
+ description: 'Do not store as default org and do not ask again to persist it'
1530
+ }]
1531
+ });
1532
+ if (result === 'yes') {
1533
+ const updateResult = updateConfigValue('defaultOrg', orgSlug);
1534
+ if (updateResult.ok) {
1535
+ logger.logger.success('Updated default org config to:', orgSlug);
1536
+ } else {
1537
+ logger.logger.fail('(Non blocking) Failed to update default org in config:', updateResult.cause);
1538
+ }
1539
+ } else if (result === 'sush') {
1540
+ const updateResult = updateConfigValue('skipAskToPersistDefaultOrg', true);
1541
+ if (updateResult.ok) {
1542
+ logger.logger.info('Default org not changed. Will not ask to persist again.');
1543
+ } else {
1544
+ logger.logger.fail(`(Non blocking) Failed to store preference; will ask to persist again next time. Reason: ${updateResult.cause}`);
1545
+ }
1546
+ }
1547
+ }
1548
+
1549
+ async function determineOrgSlug(orgFlag, interactive, dryRun) {
1505
1550
  const defaultOrgSlug = getConfigValueOrUndef('defaultOrg');
1506
1551
  let orgSlug = String(orgFlag || defaultOrgSlug || '');
1507
1552
  if (!orgSlug) {
1508
- if (isTestingV1()) {
1509
- // ask from server
1510
- logger.logger.warn('Missing the org slug and no --org flag set. Trying to auto-discover the org now...');
1511
- logger.logger.info('Note: you can set the default org slug to prevent this issue. You can also override all that with the --org flag.');
1512
- if (dryRun) {
1513
- logger.logger.fail('Skipping auto-discovery of org in dry-run mode');
1514
- } else if (!interactive) {
1515
- logger.logger.fail('Skipping auto-discovery of org when interactive = false');
1516
- } else {
1517
- orgSlug = (await suggestOrgSlug()) || '';
1518
- }
1553
+ if (!interactive) {
1554
+ logger.logger.warn('Note: This command requires an org slug because the remote API endpoint does.');
1555
+ logger.logger.warn('');
1556
+ logger.logger.warn('It seems no default org was setup and the `--org` flag was not used.');
1557
+ logger.logger.warn("Additionally, `--no-interactive` was set so we can't ask for it.");
1558
+ logger.logger.warn('Since v1.0.0 the org _argument_ for all commands was dropped in favor of an');
1559
+ logger.logger.warn('implicit default org setting, which will be setup when you run `socket login`.');
1560
+ logger.logger.warn('');
1561
+ logger.logger.warn('Note: When running in CI, you probably want to set the `--org` flag.');
1562
+ logger.logger.warn('');
1563
+ logger.logger.warn('For details, see: https://docs.socket.dev/docs/v1-migration-guide');
1564
+ logger.logger.warn('');
1565
+ logger.logger.warn('This command will exit now because the org slug is required to proceed.');
1566
+ return ['', undefined];
1567
+ }
1568
+
1569
+ // ask from server
1570
+ logger.logger.warn('Unable to determine the target org. Trying to auto-discover it now...');
1571
+ logger.logger.info('Note: you can run `socket login` to set a default org. You can also override it with the --org flag.');
1572
+ logger.logger.error(''); // spacing in stderr
1573
+ if (dryRun) {
1574
+ logger.logger.fail('Skipping auto-discovery of org in dry-run mode');
1519
1575
  } else {
1520
- orgSlug = firstArg || '';
1576
+ orgSlug = (await suggestOrgSlug()) || '';
1577
+ if (orgSlug) {
1578
+ await suggestToPersistOrgSlug(orgSlug);
1579
+ }
1521
1580
  }
1522
1581
  }
1523
1582
  return [orgSlug, defaultOrgSlug];
1524
1583
  }
1525
1584
 
1585
+ function getPurlObject(purl) {
1586
+ return typeof purl === 'string' ? vendor.packageurlJsExports.PackageURL.fromString(purl) : purl;
1587
+ }
1588
+
1589
+ const {
1590
+ SOCKET_WEBSITE_URL
1591
+ } = constants;
1592
+ function getPkgFullNameFromPurl(purl) {
1593
+ const purlObj = getPurlObject(purl);
1594
+ const {
1595
+ name,
1596
+ namespace
1597
+ } = purlObj;
1598
+ return namespace ? `${namespace}${purlObj.type === 'maven' ? ':' : '/'}${name}` : name;
1599
+ }
1600
+ function getSocketDevPackageOverviewUrlFromPurl(purl) {
1601
+ const purlObj = getPurlObject(purl);
1602
+ const fullName = getPkgFullNameFromPurl(purlObj);
1603
+ return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version);
1604
+ }
1605
+ function getSocketDevPackageOverviewUrl(ecosystem, fullName, version) {
1606
+ const url = `${SOCKET_WEBSITE_URL}/${ecosystem}/package/${fullName}`;
1607
+ return ecosystem === 'golang' ? `${url}${version ? `?section=overview&version=${version}` : ''}` : `${url}${version ? `/overview/${version}` : ''}`;
1608
+ }
1609
+
1610
+ /**
1611
+ * Convert a Map<string, Map|string> to a nested object of similar shape.
1612
+ * The goal is to serialize it with JSON.stringify, which Map can't do.
1613
+ */
1614
+ function mapToObject(map) {
1615
+ return Object.fromEntries(Array.from(map.entries()).map(([k, v]) => [k, v instanceof Map ? mapToObject(v) : v]));
1616
+ }
1617
+
1618
+ function* walkNestedMap(map, keys = []) {
1619
+ for (const [key, value] of map.entries()) {
1620
+ if (value instanceof Map) {
1621
+ yield* walkNestedMap(value, keys.concat(key));
1622
+ } else {
1623
+ yield {
1624
+ keys: keys.concat(key),
1625
+ value: value
1626
+ };
1627
+ }
1628
+ }
1629
+ }
1630
+
1526
1631
  const {
1527
1632
  NODE_MODULES: NODE_MODULES$1,
1528
1633
  NPM: NPM$4,
@@ -1628,164 +1733,6 @@ async function getPackageFilesForScan(cwd, inputPaths, supportedFiles, config) {
1628
1733
  return packageFiles;
1629
1734
  }
1630
1735
 
1631
- const {
1632
- NODE_MODULES,
1633
- NPM: NPM$3,
1634
- NPX,
1635
- SOCKET_CLI_ISSUES_URL
1636
- } = constants;
1637
- function exitWithBinPathError(binName) {
1638
- logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
1639
- // The exit code 127 indicates that the command or binary being executed
1640
- // could not be found.
1641
- // eslint-disable-next-line n/no-process-exit
1642
- process.exit(127);
1643
- }
1644
- let _npmBinPathDetails;
1645
- function getNpmBinPathDetails() {
1646
- if (_npmBinPathDetails === undefined) {
1647
- _npmBinPathDetails = findBinPathDetailsSync(NPM$3);
1648
- }
1649
- return _npmBinPathDetails;
1650
- }
1651
- let _npxBinPathDetails;
1652
- function getNpxBinPathDetails() {
1653
- if (_npxBinPathDetails === undefined) {
1654
- _npxBinPathDetails = findBinPathDetailsSync(NPX);
1655
- }
1656
- return _npxBinPathDetails;
1657
- }
1658
- function isNpmBinPathShadowed() {
1659
- return getNpmBinPathDetails().shadowed;
1660
- }
1661
- function isNpxBinPathShadowed() {
1662
- return getNpxBinPathDetails().shadowed;
1663
- }
1664
- let _npmBinPath;
1665
- function getNpmBinPath() {
1666
- if (_npmBinPath === undefined) {
1667
- _npmBinPath = getNpmBinPathDetails().path;
1668
- if (!_npmBinPath) {
1669
- exitWithBinPathError(NPM$3);
1670
- }
1671
- }
1672
- return _npmBinPath;
1673
- }
1674
- let _npmPath;
1675
- function getNpmPath() {
1676
- if (_npmPath === undefined) {
1677
- const npmBinPath = getNpmBinPath();
1678
- _npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined;
1679
- if (!_npmPath) {
1680
- let message = 'Unable to find npm CLI install directory.';
1681
- if (npmBinPath) {
1682
- message += `\nSearched parent directories of ${path.dirname(npmBinPath)}.`;
1683
- }
1684
- message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`;
1685
- logger.logger.fail(message);
1686
- // The exit code 127 indicates that the command or binary being executed
1687
- // could not be found.
1688
- // eslint-disable-next-line n/no-process-exit
1689
- process.exit(127);
1690
- }
1691
- }
1692
- return _npmPath;
1693
- }
1694
- let _npmRequire;
1695
- function getNpmRequire() {
1696
- if (_npmRequire === undefined) {
1697
- const npmPath = getNpmPath();
1698
- const npmNmPath = path.join(npmPath, NODE_MODULES, NPM$3);
1699
- _npmRequire = Module.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'));
1700
- }
1701
- return _npmRequire;
1702
- }
1703
- let _npxBinPath;
1704
- function getNpxBinPath() {
1705
- if (_npxBinPath === undefined) {
1706
- _npxBinPath = getNpxBinPathDetails().path;
1707
- if (!_npxBinPath) {
1708
- exitWithBinPathError(NPX);
1709
- }
1710
- }
1711
- return _npxBinPath;
1712
- }
1713
-
1714
- const helpFlags = new Set(['--help', '-h']);
1715
- function cmdFlagsToString(args) {
1716
- const result = [];
1717
- for (let i = 0, {
1718
- length
1719
- } = args; i < length; i += 1) {
1720
- if (args[i].startsWith('--')) {
1721
- // Check if the next item exists and is NOT another flag.
1722
- if (i + 1 < length && !args[i + 1].startsWith('--')) {
1723
- result.push(`${args[i]}=${args[i + 1]}`);
1724
- i += 1;
1725
- } else {
1726
- result.push(args[i]);
1727
- }
1728
- }
1729
- }
1730
- return result.join(' ');
1731
- }
1732
- function cmdPrefixMessage(cmdName, text) {
1733
- const cmdPrefix = cmdName ? `${cmdName}: ` : '';
1734
- return `${cmdPrefix}${text}`;
1735
- }
1736
- function isHelpFlag(cmdArg) {
1737
- return helpFlags.has(cmdArg);
1738
- }
1739
-
1740
- function getPurlObject(purl) {
1741
- return typeof purl === 'string' ? vendor.packageurlJsExports.PackageURL.fromString(purl) : purl;
1742
- }
1743
-
1744
- const {
1745
- SOCKET_WEBSITE_URL
1746
- } = constants;
1747
- function getPkgFullNameFromPurl(purl) {
1748
- const purlObj = getPurlObject(purl);
1749
- const {
1750
- name,
1751
- namespace
1752
- } = purlObj;
1753
- return namespace ? `${namespace}${purlObj.type === 'maven' ? ':' : '/'}${name}` : name;
1754
- }
1755
- function getSocketDevAlertUrl(alertType) {
1756
- return `${SOCKET_WEBSITE_URL}/alerts/${alertType}`;
1757
- }
1758
- function getSocketDevPackageOverviewUrlFromPurl(purl) {
1759
- const purlObj = getPurlObject(purl);
1760
- const fullName = getPkgFullNameFromPurl(purlObj);
1761
- return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version);
1762
- }
1763
- function getSocketDevPackageOverviewUrl(ecosystem, fullName, version) {
1764
- const url = `${SOCKET_WEBSITE_URL}/${ecosystem}/package/${fullName}`;
1765
- return ecosystem === 'golang' ? `${url}${version ? `?section=overview&version=${version}` : ''}` : `${url}${version ? `/overview/${version}` : ''}`;
1766
- }
1767
-
1768
- /**
1769
- * Convert a Map<string, Map|string> to a nested object of similar shape.
1770
- * The goal is to serialize it with JSON.stringify, which Map can't do.
1771
- */
1772
- function mapToObject(map) {
1773
- return Object.fromEntries(Array.from(map.entries()).map(([k, v]) => [k, v instanceof Map ? mapToObject(v) : v]));
1774
- }
1775
-
1776
- function* walkNestedMap(map, keys = []) {
1777
- for (const [key, value] of map.entries()) {
1778
- if (value instanceof Map) {
1779
- yield* walkNestedMap(value, keys.concat(key));
1780
- } else {
1781
- yield {
1782
- keys: keys.concat(key),
1783
- value: value
1784
- };
1785
- }
1786
- }
1787
- }
1788
-
1789
1736
  async function readOrDefaultSocketJson(cwd) {
1790
1737
  const result = await readSocketJson(cwd, true);
1791
1738
  if (result.ok) {
@@ -1891,6 +1838,89 @@ async function writeSocketJson(cwd, socketJson) {
1891
1838
  };
1892
1839
  }
1893
1840
 
1841
+ const {
1842
+ NODE_MODULES,
1843
+ NPM: NPM$3,
1844
+ NPX,
1845
+ SOCKET_CLI_ISSUES_URL
1846
+ } = constants;
1847
+ function exitWithBinPathError(binName) {
1848
+ logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
1849
+ // The exit code 127 indicates that the command or binary being executed
1850
+ // could not be found.
1851
+ // eslint-disable-next-line n/no-process-exit
1852
+ process.exit(127);
1853
+ }
1854
+ let _npmBinPathDetails;
1855
+ function getNpmBinPathDetails() {
1856
+ if (_npmBinPathDetails === undefined) {
1857
+ _npmBinPathDetails = findBinPathDetailsSync(NPM$3);
1858
+ }
1859
+ return _npmBinPathDetails;
1860
+ }
1861
+ let _npxBinPathDetails;
1862
+ function getNpxBinPathDetails() {
1863
+ if (_npxBinPathDetails === undefined) {
1864
+ _npxBinPathDetails = findBinPathDetailsSync(NPX);
1865
+ }
1866
+ return _npxBinPathDetails;
1867
+ }
1868
+ function isNpmBinPathShadowed() {
1869
+ return getNpmBinPathDetails().shadowed;
1870
+ }
1871
+ function isNpxBinPathShadowed() {
1872
+ return getNpxBinPathDetails().shadowed;
1873
+ }
1874
+ let _npmBinPath;
1875
+ function getNpmBinPath() {
1876
+ if (_npmBinPath === undefined) {
1877
+ _npmBinPath = getNpmBinPathDetails().path;
1878
+ if (!_npmBinPath) {
1879
+ exitWithBinPathError(NPM$3);
1880
+ }
1881
+ }
1882
+ return _npmBinPath;
1883
+ }
1884
+ let _npmPath;
1885
+ function getNpmPath() {
1886
+ if (_npmPath === undefined) {
1887
+ const npmBinPath = getNpmBinPath();
1888
+ _npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined;
1889
+ if (!_npmPath) {
1890
+ let message = 'Unable to find npm CLI install directory.';
1891
+ if (npmBinPath) {
1892
+ message += `\nSearched parent directories of ${path.dirname(npmBinPath)}.`;
1893
+ }
1894
+ message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`;
1895
+ logger.logger.fail(message);
1896
+ // The exit code 127 indicates that the command or binary being executed
1897
+ // could not be found.
1898
+ // eslint-disable-next-line n/no-process-exit
1899
+ process.exit(127);
1900
+ }
1901
+ }
1902
+ return _npmPath;
1903
+ }
1904
+ let _npmRequire;
1905
+ function getNpmRequire() {
1906
+ if (_npmRequire === undefined) {
1907
+ const npmPath = getNpmPath();
1908
+ const npmNmPath = path.join(npmPath, NODE_MODULES, NPM$3);
1909
+ _npmRequire = Module.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'));
1910
+ }
1911
+ return _npmRequire;
1912
+ }
1913
+ let _npxBinPath;
1914
+ function getNpxBinPath() {
1915
+ if (_npxBinPath === undefined) {
1916
+ _npxBinPath = getNpxBinPathDetails().path;
1917
+ if (!_npxBinPath) {
1918
+ exitWithBinPathError(NPX);
1919
+ }
1920
+ }
1921
+ return _npxBinPath;
1922
+ }
1923
+
1894
1924
  const {
1895
1925
  ALERT_TYPE_CRITICAL_CVE,
1896
1926
  ALERT_TYPE_CVE,
@@ -1910,13 +1940,6 @@ function createEnum(obj) {
1910
1940
  ...obj
1911
1941
  });
1912
1942
  }
1913
- function pick(input, keys) {
1914
- const result = {};
1915
- for (const key of keys) {
1916
- result[key] = input[key];
1917
- }
1918
- return result;
1919
- }
1920
1943
 
1921
1944
  const ALERT_FIX_TYPE = createEnum({
1922
1945
  cve: 'cve',
@@ -1924,71 +1947,12 @@ const ALERT_FIX_TYPE = createEnum({
1924
1947
  upgrade: 'upgrade'
1925
1948
  });
1926
1949
 
1927
- function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
1928
- const values = list.filter(Boolean);
1929
- const {
1930
- length
1931
- } = values;
1932
- if (!length) {
1933
- return '';
1934
- }
1935
- if (length === 1) {
1936
- return values[0];
1937
- }
1938
- const finalValue = values.pop();
1939
- return `${values.join(', ')}${separator}${finalValue}`;
1940
- }
1941
-
1942
1950
  const ALERT_SEVERITY = createEnum({
1943
1951
  critical: 'critical',
1944
1952
  high: 'high',
1945
1953
  middle: 'middle',
1946
1954
  low: 'low'
1947
1955
  });
1948
- // Ordered from most severe to least.
1949
- const ALERT_SEVERITIES_SORTED = Object.freeze(['critical', 'high', 'middle', 'low']);
1950
- function getDesiredSeverities(lowestToInclude) {
1951
- const result = [];
1952
- for (const severity of ALERT_SEVERITIES_SORTED) {
1953
- result.push(severity);
1954
- if (severity === lowestToInclude) {
1955
- break;
1956
- }
1957
- }
1958
- return result;
1959
- }
1960
- function formatSeverityCount(severityCount) {
1961
- const summary = [];
1962
- for (const severity of ALERT_SEVERITIES_SORTED) {
1963
- if (severityCount[severity]) {
1964
- summary.push(`${severityCount[severity]} ${severity}`);
1965
- }
1966
- }
1967
- return stringJoinWithSeparateFinalSeparator(summary);
1968
- }
1969
- function getSeverityCount(issues, lowestToInclude) {
1970
- const severityCount = pick({
1971
- low: 0,
1972
- middle: 0,
1973
- high: 0,
1974
- critical: 0
1975
- }, getDesiredSeverities(lowestToInclude));
1976
- for (const issue of issues) {
1977
- const {
1978
- value
1979
- } = issue;
1980
- if (!value) {
1981
- continue;
1982
- }
1983
- const {
1984
- severity
1985
- } = value;
1986
- if (severityCount[severity] !== undefined) {
1987
- severityCount[severity] += 1;
1988
- }
1989
- }
1990
- return severityCount;
1991
- }
1992
1956
 
1993
1957
  class ColorOrMarkdown {
1994
1958
  constructor(useMarkdown) {
@@ -2026,7 +1990,7 @@ class ColorOrMarkdown {
2026
1990
  }
2027
1991
  }
2028
1992
 
2029
- const RangeStyles = ['caret', 'gt', 'lt', 'pin', 'preserve', 'tilde'];
1993
+ const RangeStyles = ['caret', 'gt', 'gte', 'lt', 'lte', 'pin', 'preserve', 'tilde'];
2030
1994
  function applyRange(refRange, version, style = 'preserve') {
2031
1995
  switch (style) {
2032
1996
  case 'caret':
@@ -2520,7 +2484,7 @@ function idToPurl(id, type) {
2520
2484
  return `pkg:${type}/${id}`;
2521
2485
  }
2522
2486
 
2523
- function extractOverridesFromPnpmLockfileContent(lockfileContent) {
2487
+ function extractOverridesFromPnpmLockSrc(lockfileContent) {
2524
2488
  return typeof lockfileContent === 'string' ? /^overrides:(\r?\n {2}.+)+(?:\r?\n)*/m.exec(lockfileContent)?.[0] ?? '' : '';
2525
2489
  }
2526
2490
  async function extractPurlsFromPnpmLockfile(lockfile) {
@@ -2570,9 +2534,6 @@ function parsePnpmLockfileVersion(version) {
2570
2534
  } catch {}
2571
2535
  return null;
2572
2536
  }
2573
- async function readPnpmLockfile(lockfilePath) {
2574
- return fs.existsSync(lockfilePath) ? await readFileUtf8(lockfilePath) : null;
2575
- }
2576
2537
  function stripLeadingPnpmDepPathSlash(depPath) {
2577
2538
  return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
2578
2539
  }
@@ -2680,6 +2641,36 @@ function npa(...args) {
2680
2641
  return null;
2681
2642
  }
2682
2643
 
2644
+ async function readLockfile(lockfilePath) {
2645
+ return fs.existsSync(lockfilePath) ? await readFileUtf8(lockfilePath) : null;
2646
+ }
2647
+
2648
+ const helpFlags = new Set(['--help', '-h']);
2649
+ function cmdFlagsToString(args) {
2650
+ const result = [];
2651
+ for (let i = 0, {
2652
+ length
2653
+ } = args; i < length; i += 1) {
2654
+ if (args[i].startsWith('--')) {
2655
+ // Check if the next item exists and is NOT another flag.
2656
+ if (i + 1 < length && !args[i + 1].startsWith('--')) {
2657
+ result.push(`${args[i]}=${args[i + 1]}`);
2658
+ i += 1;
2659
+ } else {
2660
+ result.push(args[i]);
2661
+ }
2662
+ }
2663
+ }
2664
+ return result.join(' ');
2665
+ }
2666
+ function cmdPrefixMessage(cmdName, text) {
2667
+ const cmdPrefix = cmdName ? `${cmdName}: ` : '';
2668
+ return `${cmdPrefix}${text}`;
2669
+ }
2670
+ function isHelpFlag(cmdArg) {
2671
+ return helpFlags.has(cmdArg);
2672
+ }
2673
+
2683
2674
  const {
2684
2675
  NPM: NPM$2,
2685
2676
  SOCKET_CLI_SAFE_BIN,
@@ -3196,10 +3187,8 @@ fi
3196
3187
  };
3197
3188
  }
3198
3189
 
3199
- exports.ALERT_SEVERITY = ALERT_SEVERITY;
3200
3190
  exports.AuthError = AuthError;
3201
3191
  exports.COMPLETION_CMD_PREFIX = COMPLETION_CMD_PREFIX;
3202
- exports.ColorOrMarkdown = ColorOrMarkdown;
3203
3192
  exports.InputError = InputError;
3204
3193
  exports.RangeStyles = RangeStyles;
3205
3194
  exports.applyRange = applyRange;
@@ -3211,9 +3200,8 @@ exports.commonFlags = commonFlags;
3211
3200
  exports.createEnum = createEnum;
3212
3201
  exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironment;
3213
3202
  exports.determineOrgSlug = determineOrgSlug;
3214
- exports.extractOverridesFromPnpmLockfileContent = extractOverridesFromPnpmLockfileContent;
3203
+ exports.extractOverridesFromPnpmLockSrc = extractOverridesFromPnpmLockSrc;
3215
3204
  exports.failMsgWithBadge = failMsgWithBadge;
3216
- exports.formatSeverityCount = formatSeverityCount;
3217
3205
  exports.getAlertsMapFromPnpmLockfile = getAlertsMapFromPnpmLockfile;
3218
3206
  exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
3219
3207
  exports.getBashrcDetails = getBashrcDetails;
@@ -3230,17 +3218,12 @@ exports.getNpxBinPath = getNpxBinPath;
3230
3218
  exports.getOutputKind = getOutputKind;
3231
3219
  exports.getPackageFilesForScan = getPackageFilesForScan;
3232
3220
  exports.getPkgFullNameFromPurl = getPkgFullNameFromPurl;
3233
- exports.getPublicToken = getPublicToken;
3234
3221
  exports.getPurlObject = getPurlObject;
3235
- exports.getSeverityCount = getSeverityCount;
3236
- exports.getSocketDevAlertUrl = getSocketDevAlertUrl;
3237
- exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl;
3238
3222
  exports.getSocketDevPackageOverviewUrlFromPurl = getSocketDevPackageOverviewUrlFromPurl;
3239
3223
  exports.getVisibleTokenPrefix = getVisibleTokenPrefix;
3240
3224
  exports.globWorkspace = globWorkspace;
3241
3225
  exports.handleApiCall = handleApiCall;
3242
3226
  exports.handleApiCallNoSpinner = handleApiCallNoSpinner;
3243
- exports.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse;
3244
3227
  exports.hasDefaultToken = hasDefaultToken;
3245
3228
  exports.idToNpmPurl = idToNpmPurl;
3246
3229
  exports.idToPurl = idToPurl;
@@ -3248,7 +3231,6 @@ exports.isHelpFlag = isHelpFlag;
3248
3231
  exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
3249
3232
  exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
3250
3233
  exports.isReadOnlyConfig = isReadOnlyConfig;
3251
- exports.isTestingV1 = isTestingV1;
3252
3234
  exports.logAlertsMap = logAlertsMap;
3253
3235
  exports.mapToObject = mapToObject;
3254
3236
  exports.mdTable = mdTable;
@@ -3256,14 +3238,15 @@ exports.mdTableOfPairs = mdTableOfPairs;
3256
3238
  exports.mdTableStringNumber = mdTableStringNumber;
3257
3239
  exports.meowOrExit = meowOrExit;
3258
3240
  exports.meowWithSubcommands = meowWithSubcommands;
3241
+ exports.msAtHome = msAtHome;
3259
3242
  exports.npa = npa;
3260
3243
  exports.outputFlags = outputFlags;
3261
3244
  exports.parsePnpmLockfile = parsePnpmLockfile;
3262
3245
  exports.parsePnpmLockfileVersion = parsePnpmLockfileVersion;
3263
3246
  exports.queryApiSafeJson = queryApiSafeJson;
3264
3247
  exports.queryApiSafeText = queryApiSafeText;
3248
+ exports.readLockfile = readLockfile;
3265
3249
  exports.readOrDefaultSocketJson = readOrDefaultSocketJson;
3266
- exports.readPnpmLockfile = readPnpmLockfile;
3267
3250
  exports.readSocketJson = readSocketJson;
3268
3251
  exports.removeNodeModules = removeNodeModules;
3269
3252
  exports.runAgentInstall = runAgentInstall;
@@ -3275,8 +3258,7 @@ exports.suggestOrgSlug = suggestOrgSlug;
3275
3258
  exports.supportedConfigKeys = supportedConfigKeys;
3276
3259
  exports.tildify = tildify;
3277
3260
  exports.updateConfigValue = updateConfigValue;
3278
- exports.validationFlags = validationFlags;
3279
3261
  exports.walkNestedMap = walkNestedMap;
3280
3262
  exports.writeSocketJson = writeSocketJson;
3281
- //# debugId=fd828cc1-419a-483c-901d-1879551233f0
3263
+ //# debugId=ba9b8f1a-3ce9-4a1c-9132-b806f964514a
3282
3264
  //# sourceMappingURL=utils.js.map