@socketsecurity/cli-with-sentry 1.1.8 → 1.1.12

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 (274) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/README.md +3 -3
  3. package/bin/cli.js +2 -1
  4. package/bin/npm-cli.js +2 -1
  5. package/bin/npx-cli.js +2 -1
  6. package/bin/pnpm-cli.js +29 -0
  7. package/bin/yarn-cli.js +29 -0
  8. package/dist/cli.js +857 -612
  9. package/dist/cli.js.map +1 -1
  10. package/dist/constants.js +35 -10
  11. package/dist/constants.js.map +1 -1
  12. package/dist/flags.js +16 -17
  13. package/dist/flags.js.map +1 -1
  14. package/dist/instrument-with-sentry.js +3 -3
  15. package/dist/instrument-with-sentry.js.map +1 -1
  16. package/dist/npm-cli.js +26 -0
  17. package/dist/npm-cli.js.map +1 -0
  18. package/dist/npx-cli.js +26 -0
  19. package/dist/npx-cli.js.map +1 -0
  20. package/dist/pnpm-cli.js +26 -0
  21. package/dist/pnpm-cli.js.map +1 -0
  22. package/dist/shadow-npm-inject.js +9 -11
  23. package/dist/shadow-npm-inject.js.map +1 -1
  24. package/dist/shadow-pnpm-bin.js +235 -0
  25. package/dist/shadow-pnpm-bin.js.map +1 -0
  26. package/dist/shadow-yarn-bin.js +200 -0
  27. package/dist/shadow-yarn-bin.js.map +1 -0
  28. package/dist/socket-completion.bash +0 -0
  29. package/dist/tsconfig.dts.tsbuildinfo +1 -1
  30. package/dist/types/commands/analytics/cmd-analytics.d.mts +2 -3
  31. package/dist/types/commands/analytics/cmd-analytics.d.mts.map +1 -1
  32. package/dist/types/commands/audit-log/cmd-audit-log.d.mts +2 -3
  33. package/dist/types/commands/audit-log/cmd-audit-log.d.mts.map +1 -1
  34. package/dist/types/commands/ci/cmd-ci.d.mts +2 -3
  35. package/dist/types/commands/ci/cmd-ci.d.mts.map +1 -1
  36. package/dist/types/commands/config/cmd-config-auto.d.mts +2 -3
  37. package/dist/types/commands/config/cmd-config-auto.d.mts.map +1 -1
  38. package/dist/types/commands/config/cmd-config-get.d.mts +2 -3
  39. package/dist/types/commands/config/cmd-config-get.d.mts.map +1 -1
  40. package/dist/types/commands/config/cmd-config-list.d.mts +2 -3
  41. package/dist/types/commands/config/cmd-config-list.d.mts.map +1 -1
  42. package/dist/types/commands/config/cmd-config-set.d.mts +2 -3
  43. package/dist/types/commands/config/cmd-config-set.d.mts.map +1 -1
  44. package/dist/types/commands/config/cmd-config-unset.d.mts +2 -3
  45. package/dist/types/commands/config/cmd-config-unset.d.mts.map +1 -1
  46. package/dist/types/commands/fix/cmd-fix.d.mts +2 -3
  47. package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
  48. package/dist/types/commands/fix/env-helpers.d.mts +1 -1
  49. package/dist/types/commands/fix/env-helpers.d.mts.map +1 -1
  50. package/dist/types/commands/fix/git.d.mts +1 -1
  51. package/dist/types/commands/fix/git.d.mts.map +1 -1
  52. package/dist/types/commands/fix/handle-fix.d.mts +5 -0
  53. package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
  54. package/dist/types/commands/fix/pull-request.d.mts +1 -1
  55. package/dist/types/commands/fix/pull-request.d.mts.map +1 -1
  56. package/dist/types/commands/install/cmd-install-completion.d.mts +2 -3
  57. package/dist/types/commands/install/cmd-install-completion.d.mts.map +1 -1
  58. package/dist/types/commands/json/cmd-json.d.mts +2 -3
  59. package/dist/types/commands/json/cmd-json.d.mts.map +1 -1
  60. package/dist/types/commands/login/cmd-login.d.mts +2 -3
  61. package/dist/types/commands/login/cmd-login.d.mts.map +1 -1
  62. package/dist/types/commands/logout/cmd-logout.d.mts +2 -3
  63. package/dist/types/commands/logout/cmd-logout.d.mts.map +1 -1
  64. package/dist/types/commands/manifest/cmd-manifest-auto.d.mts +2 -3
  65. package/dist/types/commands/manifest/cmd-manifest-auto.d.mts.map +1 -1
  66. package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts +2 -3
  67. package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts.map +1 -1
  68. package/dist/types/commands/manifest/cmd-manifest-conda.d.mts +2 -3
  69. package/dist/types/commands/manifest/cmd-manifest-conda.d.mts.map +1 -1
  70. package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts +2 -3
  71. package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts.map +1 -1
  72. package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts +2 -3
  73. package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts.map +1 -1
  74. package/dist/types/commands/manifest/cmd-manifest-scala.d.mts +2 -3
  75. package/dist/types/commands/manifest/cmd-manifest-scala.d.mts.map +1 -1
  76. package/dist/types/commands/manifest/cmd-manifest-setup.d.mts +2 -3
  77. package/dist/types/commands/manifest/cmd-manifest-setup.d.mts.map +1 -1
  78. package/dist/types/commands/manifest/cmd-manifest.d.mts +2 -3
  79. package/dist/types/commands/manifest/cmd-manifest.d.mts.map +1 -1
  80. package/dist/types/commands/manifest/detect-manifest-actions.d.mts.map +1 -1
  81. package/dist/types/commands/manifest/generate_auto_manifest.d.mts.map +1 -1
  82. package/dist/types/commands/manifest/output-requirements.d.mts.map +1 -1
  83. package/dist/types/commands/manifest/run-cdxgen.d.mts.map +1 -1
  84. package/dist/types/commands/manifest/setup-manifest-config.d.mts.map +1 -1
  85. package/dist/types/commands/npm/cmd-npm.d.mts +2 -3
  86. package/dist/types/commands/npm/cmd-npm.d.mts.map +1 -1
  87. package/dist/types/commands/npx/cmd-npx.d.mts +2 -3
  88. package/dist/types/commands/npx/cmd-npx.d.mts.map +1 -1
  89. package/dist/types/commands/oops/cmd-oops.d.mts +2 -3
  90. package/dist/types/commands/oops/cmd-oops.d.mts.map +1 -1
  91. package/dist/types/commands/optimize/cmd-optimize.d.mts +2 -3
  92. package/dist/types/commands/optimize/cmd-optimize.d.mts.map +1 -1
  93. package/dist/types/commands/organization/cmd-organization-dependencies.d.mts +2 -3
  94. package/dist/types/commands/organization/cmd-organization-dependencies.d.mts.map +1 -1
  95. package/dist/types/commands/organization/cmd-organization-list.d.mts +2 -3
  96. package/dist/types/commands/organization/cmd-organization-list.d.mts.map +1 -1
  97. package/dist/types/commands/organization/cmd-organization-policy-license.d.mts +2 -3
  98. package/dist/types/commands/organization/cmd-organization-policy-license.d.mts.map +1 -1
  99. package/dist/types/commands/organization/cmd-organization-policy-security.d.mts +2 -3
  100. package/dist/types/commands/organization/cmd-organization-policy-security.d.mts.map +1 -1
  101. package/dist/types/commands/organization/cmd-organization-quota.d.mts +2 -3
  102. package/dist/types/commands/organization/cmd-organization-quota.d.mts.map +1 -1
  103. package/dist/types/commands/package/cmd-package-score.d.mts +2 -3
  104. package/dist/types/commands/package/cmd-package-score.d.mts.map +1 -1
  105. package/dist/types/commands/package/cmd-package-shallow.d.mts +2 -3
  106. package/dist/types/commands/package/cmd-package-shallow.d.mts.map +1 -1
  107. package/dist/types/commands/package/output-purls-shallow-score.d.mts.map +1 -1
  108. package/dist/types/commands/patch/cmd-patch.d.mts +2 -3
  109. package/dist/types/commands/patch/cmd-patch.d.mts.map +1 -1
  110. package/dist/types/commands/patch/handle-patch.d.mts.map +1 -1
  111. package/dist/types/commands/pnpm/cmd-pnpm.d.mts +10 -0
  112. package/dist/types/commands/pnpm/cmd-pnpm.d.mts.map +1 -0
  113. package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts +2 -3
  114. package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts.map +1 -1
  115. package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts +2 -3
  116. package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts.map +1 -1
  117. package/dist/types/commands/repository/cmd-repository-create.d.mts +2 -3
  118. package/dist/types/commands/repository/cmd-repository-create.d.mts.map +1 -1
  119. package/dist/types/commands/repository/cmd-repository-del.d.mts +2 -3
  120. package/dist/types/commands/repository/cmd-repository-del.d.mts.map +1 -1
  121. package/dist/types/commands/repository/cmd-repository-list.d.mts +2 -3
  122. package/dist/types/commands/repository/cmd-repository-list.d.mts.map +1 -1
  123. package/dist/types/commands/repository/cmd-repository-update.d.mts +2 -3
  124. package/dist/types/commands/repository/cmd-repository-update.d.mts.map +1 -1
  125. package/dist/types/commands/repository/cmd-repository-view.d.mts +2 -3
  126. package/dist/types/commands/repository/cmd-repository-view.d.mts.map +1 -1
  127. package/dist/types/commands/repository/handle-list-repos.d.mts +2 -1
  128. package/dist/types/commands/repository/handle-list-repos.d.mts.map +1 -1
  129. package/dist/types/commands/repository/output-list-repos.d.mts +2 -1
  130. package/dist/types/commands/repository/output-list-repos.d.mts.map +1 -1
  131. package/dist/types/commands/repository/types.d.mts +2 -0
  132. package/dist/types/commands/repository/types.d.mts.map +1 -0
  133. package/dist/types/commands/scan/cmd-scan-create.d.mts +2 -3
  134. package/dist/types/commands/scan/cmd-scan-create.d.mts.map +1 -1
  135. package/dist/types/commands/scan/cmd-scan-del.d.mts +2 -3
  136. package/dist/types/commands/scan/cmd-scan-del.d.mts.map +1 -1
  137. package/dist/types/commands/scan/cmd-scan-diff.d.mts +2 -3
  138. package/dist/types/commands/scan/cmd-scan-diff.d.mts.map +1 -1
  139. package/dist/types/commands/scan/cmd-scan-github.d.mts +2 -3
  140. package/dist/types/commands/scan/cmd-scan-github.d.mts.map +1 -1
  141. package/dist/types/commands/scan/cmd-scan-list.d.mts.map +1 -1
  142. package/dist/types/commands/scan/cmd-scan-metadata.d.mts.map +1 -1
  143. package/dist/types/commands/scan/cmd-scan-reach.d.mts +2 -3
  144. package/dist/types/commands/scan/cmd-scan-reach.d.mts.map +1 -1
  145. package/dist/types/commands/scan/cmd-scan-report.d.mts.map +1 -1
  146. package/dist/types/commands/scan/cmd-scan-setup.d.mts +2 -3
  147. package/dist/types/commands/scan/cmd-scan-setup.d.mts.map +1 -1
  148. package/dist/types/commands/scan/cmd-scan-view.d.mts.map +1 -1
  149. package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts +2 -3
  150. package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts.map +1 -1
  151. package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts +2 -3
  152. package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts.map +1 -1
  153. package/dist/types/commands/wrapper/cmd-wrapper.d.mts +2 -3
  154. package/dist/types/commands/wrapper/cmd-wrapper.d.mts.map +1 -1
  155. package/dist/types/commands/yarn/cmd-yarn.d.mts +10 -0
  156. package/dist/types/commands/yarn/cmd-yarn.d.mts.map +1 -0
  157. package/dist/types/commands.d.mts +31 -63
  158. package/dist/types/commands.d.mts.map +1 -1
  159. package/dist/types/constants.d.mts +17 -1
  160. package/dist/types/constants.d.mts.map +1 -1
  161. package/dist/types/flags.d.mts.map +1 -1
  162. package/dist/types/npm-cli.d.mts +3 -0
  163. package/dist/types/npm-cli.d.mts.map +1 -0
  164. package/dist/types/npx-cli.d.mts +3 -0
  165. package/dist/types/npx-cli.d.mts.map +1 -0
  166. package/dist/types/pnpm-cli.d.mts +3 -0
  167. package/dist/types/pnpm-cli.d.mts.map +1 -0
  168. package/dist/types/shadow/npm/arborist-helpers.d.mts.map +1 -1
  169. package/dist/types/shadow/pnpm/bin.d.mts +10 -0
  170. package/dist/types/shadow/pnpm/bin.d.mts.map +1 -0
  171. package/dist/types/shadow/pnpm/link.d.mts +2 -0
  172. package/dist/types/shadow/pnpm/link.d.mts.map +1 -0
  173. package/dist/types/shadow/yarn/bin.d.mts +10 -0
  174. package/dist/types/shadow/yarn/bin.d.mts.map +1 -0
  175. package/dist/types/shadow/yarn/link.d.mts +2 -0
  176. package/dist/types/shadow/yarn/link.d.mts.map +1 -0
  177. package/dist/types/utils/alerts-map.d.mts.map +1 -1
  178. package/dist/types/utils/api.d.mts +22 -1
  179. package/dist/types/utils/api.d.mts.map +1 -1
  180. package/dist/types/utils/cmd.d.mts +25 -1
  181. package/dist/types/utils/cmd.d.mts.map +1 -1
  182. package/dist/types/utils/coana.d.mts.map +1 -1
  183. package/dist/types/utils/config.d.mts +1 -1
  184. package/dist/types/utils/config.d.mts.map +1 -1
  185. package/dist/types/utils/cve-to-ghsa.d.mts +6 -0
  186. package/dist/types/utils/cve-to-ghsa.d.mts.map +1 -0
  187. package/dist/types/utils/git.d.mts +4 -4
  188. package/dist/types/utils/git.d.mts.map +1 -1
  189. package/dist/types/utils/github.d.mts.map +1 -1
  190. package/dist/types/utils/lockfile.d.mts +1 -1
  191. package/dist/types/utils/lockfile.d.mts.map +1 -1
  192. package/dist/types/utils/meow-with-subcommands.d.mts +16 -1
  193. package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
  194. package/dist/types/utils/npm-config.d.mts +1 -1
  195. package/dist/types/utils/npm-config.d.mts.map +1 -1
  196. package/dist/types/utils/npm-package-arg.d.mts +1 -1
  197. package/dist/types/utils/npm-package-arg.d.mts.map +1 -1
  198. package/dist/types/utils/output-formatting.d.mts.map +1 -1
  199. package/dist/types/utils/package-environment.d.mts.map +1 -1
  200. package/dist/types/utils/pnpm-paths.d.mts +5 -0
  201. package/dist/types/utils/pnpm-paths.d.mts.map +1 -0
  202. package/dist/types/utils/pnpm.d.mts +2 -2
  203. package/dist/types/utils/pnpm.d.mts.map +1 -1
  204. package/dist/types/utils/purl-to-ghsa.d.mts +6 -0
  205. package/dist/types/utils/purl-to-ghsa.d.mts.map +1 -0
  206. package/dist/types/utils/purl.d.mts +6 -6
  207. package/dist/types/utils/purl.d.mts.map +1 -1
  208. package/dist/types/utils/requirements.d.mts +4 -0
  209. package/dist/types/utils/requirements.d.mts.map +1 -1
  210. package/dist/types/utils/sdk.d.mts.map +1 -1
  211. package/dist/types/utils/semver.d.mts +3 -4
  212. package/dist/types/utils/semver.d.mts.map +1 -1
  213. package/dist/types/utils/socket-json.d.mts +3 -0
  214. package/dist/types/utils/socket-json.d.mts.map +1 -1
  215. package/dist/types/utils/strings.d.mts +2 -0
  216. package/dist/types/utils/strings.d.mts.map +1 -0
  217. package/dist/types/utils/yarn-paths.d.mts +5 -0
  218. package/dist/types/utils/yarn-paths.d.mts.map +1 -0
  219. package/dist/types/utils/yarn-version.d.mts +2 -0
  220. package/dist/types/utils/yarn-version.d.mts.map +1 -0
  221. package/dist/types/yarn-cli.d.mts +3 -0
  222. package/dist/types/yarn-cli.d.mts.map +1 -0
  223. package/dist/utils.js +614 -141
  224. package/dist/utils.js.map +1 -1
  225. package/dist/vendor.js +58640 -64697
  226. package/dist/yarn-cli.js +26 -0
  227. package/dist/yarn-cli.js.map +1 -0
  228. package/external/@socketsecurity/registry/lib/url.js +13 -12
  229. package/external/blessed/lib/tput.js +13 -13
  230. package/external/blessed/lib/widgets/ansiimage.js +1 -1
  231. package/external/blessed/lib/widgets/bigtext.js +1 -1
  232. package/external/blessed/lib/widgets/box.js +1 -1
  233. package/external/blessed/lib/widgets/button.js +1 -1
  234. package/external/blessed/lib/widgets/checkbox.js +1 -1
  235. package/external/blessed/lib/widgets/element.js +1 -1
  236. package/external/blessed/lib/widgets/filemanager.js +1 -1
  237. package/external/blessed/lib/widgets/form.js +1 -1
  238. package/external/blessed/lib/widgets/image.js +1 -1
  239. package/external/blessed/lib/widgets/input.js +1 -1
  240. package/external/blessed/lib/widgets/layout.js +1 -1
  241. package/external/blessed/lib/widgets/line.js +1 -1
  242. package/external/blessed/lib/widgets/list.js +1 -1
  243. package/external/blessed/lib/widgets/listbar.js +1 -1
  244. package/external/blessed/lib/widgets/listtable.js +1 -1
  245. package/external/blessed/lib/widgets/loading.js +1 -1
  246. package/external/blessed/lib/widgets/log.js +1 -1
  247. package/external/blessed/lib/widgets/message.js +1 -1
  248. package/external/blessed/lib/widgets/node.js +3 -2
  249. package/external/blessed/lib/widgets/overlayimage.js +1 -1
  250. package/external/blessed/lib/widgets/progressbar.js +1 -1
  251. package/external/blessed/lib/widgets/prompt.js +1 -1
  252. package/external/blessed/lib/widgets/question.js +1 -1
  253. package/external/blessed/lib/widgets/radiobutton.js +1 -1
  254. package/external/blessed/lib/widgets/radioset.js +1 -1
  255. package/external/blessed/lib/widgets/screen.js +8 -6
  256. package/external/blessed/lib/widgets/scrollablebox.js +1 -1
  257. package/external/blessed/lib/widgets/scrollabletext.js +1 -1
  258. package/external/blessed/lib/widgets/table.js +1 -1
  259. package/external/blessed/lib/widgets/terminal.js +1 -1
  260. package/external/blessed/lib/widgets/text.js +1 -1
  261. package/external/blessed/lib/widgets/textarea.js +1 -1
  262. package/external/blessed/lib/widgets/textbox.js +1 -1
  263. package/external/blessed/lib/widgets/video.js +1 -1
  264. package/external/blessed/vendor/tng.js +11 -4
  265. package/external/blessed-contrib/lib/widget/charts/bar.js +4 -4
  266. package/external/blessed-contrib/lib/widget/charts/line.js +4 -4
  267. package/logo-dark.png +0 -0
  268. package/logo-light.png +0 -0
  269. package/package.json +70 -97
  270. package/requirements.json +2 -2
  271. package/shadow-bin/npm +1 -1
  272. package/shadow-bin/npx +1 -1
  273. package/shadow-bin/pnpm +27 -0
  274. package/shadow-bin/yarn +27 -0
package/dist/utils.js CHANGED
@@ -11,21 +11,21 @@ var path$1 = require('../external/@socketsecurity/registry/lib/path');
11
11
  var sorts = require('../external/@socketsecurity/registry/lib/sorts');
12
12
  var spinner = require('../external/@socketsecurity/registry/lib/spinner');
13
13
  var words = require('../external/@socketsecurity/registry/lib/words');
14
- var Module = require('node:module');
15
- var path = require('node:path');
16
14
  var flags = require('./flags.js');
15
+ var path = require('node:path');
17
16
  var regexps = require('../external/@socketsecurity/registry/lib/regexps');
18
17
  var prompts = require('../external/@socketsecurity/registry/lib/prompts');
19
18
  var spawn = require('../external/@socketsecurity/registry/lib/spawn');
20
19
  var fs = require('../external/@socketsecurity/registry/lib/fs');
20
+ var require$$5 = require('node:module');
21
21
  var shadowNpmBin = require('./shadow-npm-bin.js');
22
22
  var fs$1 = require('node:fs');
23
+ var require$$13 = require('../external/@socketsecurity/registry/lib/url');
23
24
  var promises = require('node:timers/promises');
24
25
  var npm = require('../external/@socketsecurity/registry/lib/npm');
25
- var globs = require('../external/@socketsecurity/registry/lib/globs');
26
26
  var packages = require('../external/@socketsecurity/registry/lib/packages');
27
+ var globs = require('../external/@socketsecurity/registry/lib/globs');
27
28
  var streams = require('../external/@socketsecurity/registry/lib/streams');
28
- var require$$13 = require('../external/@socketsecurity/registry/lib/url');
29
29
 
30
30
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
31
31
  const sensitiveConfigKeyLookup = new Set(['apiToken']);
@@ -92,20 +92,30 @@ function findSocketYmlSync(dir = process.cwd()) {
92
92
  if (typeof yml === 'string') {
93
93
  try {
94
94
  return {
95
- path: ymlPath,
96
- parsed: vendor.configExports.parseSocketConfig(yml)
95
+ ok: true,
96
+ data: {
97
+ path: ymlPath,
98
+ parsed: vendor.configExports.parseSocketConfig(yml)
99
+ }
97
100
  };
98
101
  } catch (e) {
99
102
  require$$9.debugDir('inspect', {
100
103
  error: e
101
104
  });
102
- throw new Error(`Found file but was unable to parse ${ymlPath}`);
105
+ return {
106
+ ok: false,
107
+ message: `Found file but was unable to parse ${ymlPath}`,
108
+ cause: e instanceof Error ? e.message : String(e)
109
+ };
103
110
  }
104
111
  }
105
112
  prevDir = dir;
106
113
  dir = path.join(dir, '..');
107
114
  }
108
- return undefined;
115
+ return {
116
+ ok: true,
117
+ data: undefined
118
+ };
109
119
  }
110
120
  function getConfigValue(key) {
111
121
  const localConfig = getConfigValues();
@@ -256,6 +266,22 @@ function updateConfigValue(configKey, value) {
256
266
  };
257
267
  }
258
268
 
269
+ const require$2 = require$$5.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('utils.js', document.baseURI).href)));
270
+ let _requirements;
271
+ function getRequirements() {
272
+ if (_requirements === undefined) {
273
+ _requirements = /*@__PURE__*/require$2(path.join(constants.default.rootPath, 'requirements.json'));
274
+ }
275
+ return _requirements;
276
+ }
277
+
278
+ /**
279
+ * Convert command path to requirements key.
280
+ */
281
+ function getRequirementsKey(cmdPath) {
282
+ return cmdPath.replace(/^socket[: ]/, '').replace(/ +/g, ':');
283
+ }
284
+
259
285
  const TOKEN_PREFIX = 'sktsec_';
260
286
  const TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length;
261
287
  const TOKEN_VISIBLE_LENGTH = 5;
@@ -330,10 +356,14 @@ async function setupSdk(options) {
330
356
  return {
331
357
  ok: true,
332
358
  data: new vendor.distExports.SocketSdk(apiToken, {
333
- agent: apiProxy ? new ProxyAgent({
334
- proxy: apiProxy
335
- }) : undefined,
336
- baseUrl: apiBaseUrl,
359
+ ...(apiProxy ? {
360
+ agent: new ProxyAgent({
361
+ proxy: apiProxy
362
+ })
363
+ } : {}),
364
+ ...(apiBaseUrl ? {
365
+ baseUrl: apiBaseUrl
366
+ } : {}),
337
367
  timeout: constants.default.ENV.SOCKET_CLI_API_TIMEOUT,
338
368
  userAgent: vendor.distExports.createUserAgentFromPkgJson({
339
369
  name: constants.default.ENV.INLINED_SOCKET_CLI_NAME,
@@ -345,6 +375,32 @@ async function setupSdk(options) {
345
375
  }
346
376
 
347
377
  const NO_ERROR_MESSAGE = 'No error message returned';
378
+ /**
379
+ * Get command requirements from requirements.json based on command path.
380
+ */
381
+ function getCommandRequirements(cmdPath) {
382
+ if (!cmdPath) {
383
+ return undefined;
384
+ }
385
+ const requirements = getRequirements();
386
+ const key = getRequirementsKey(cmdPath);
387
+ return requirements.api[key] || undefined;
388
+ }
389
+
390
+ /**
391
+ * Log required permissions for a command when encountering 403 errors.
392
+ */
393
+ function logPermissionsFor403(cmdPath) {
394
+ const requirements = getCommandRequirements(cmdPath);
395
+ if (!requirements?.permissions?.length) {
396
+ return;
397
+ }
398
+ logger.logger.error('This command requires the following API permissions:');
399
+ for (const permission of requirements.permissions) {
400
+ logger.logger.error(` - ${permission}`);
401
+ }
402
+ logger.logger.error('Please ensure your API token has the required permissions.');
403
+ }
348
404
 
349
405
  // The Socket API server that should be used for operations.
350
406
  function getDefaultApiBaseUrl() {
@@ -355,6 +411,10 @@ function getDefaultApiBaseUrl() {
355
411
  const API_V0_URL = constants.default.API_V0_URL;
356
412
  return API_V0_URL;
357
413
  }
414
+
415
+ /**
416
+ * Get user-friendly error message for HTTP status codes.
417
+ */
358
418
  async function getErrorMessageForHttpStatusCode(code) {
359
419
  if (code === 400) {
360
420
  return 'One of the options passed might be incorrect';
@@ -370,8 +430,12 @@ async function getErrorMessageForHttpStatusCode(code) {
370
430
  }
371
431
  return `Server responded with status code ${code}`;
372
432
  }
433
+ /**
434
+ * Handle Socket SDK API calls with error handling and permission logging.
435
+ */
373
436
  async function handleApiCall(value, options) {
374
437
  const {
438
+ commandPath,
375
439
  description,
376
440
  spinner
377
441
  } = {
@@ -399,7 +463,7 @@ async function handleApiCall(value, options) {
399
463
  spinner?.stop();
400
464
  const socketSdkErrorResult = {
401
465
  ok: false,
402
- message: 'Socket API returned an error',
466
+ message: 'Socket API error',
403
467
  cause: vendor.messageWithCauses(e)
404
468
  };
405
469
  if (description) {
@@ -430,12 +494,17 @@ async function handleApiCall(value, options) {
430
494
  const cause = reason && message !== reason ? `${message} (reason: ${reason})` : message;
431
495
  const socketSdkErrorResult = {
432
496
  ok: false,
433
- message: 'Socket API returned an error',
497
+ message: 'Socket API error',
434
498
  cause,
435
499
  data: {
436
500
  code: sdkResult.status
437
501
  }
438
502
  };
503
+
504
+ // Log required permissions for 403 errors when in a command context.
505
+ if (commandPath && sdkResult.status === 403) {
506
+ logPermissionsFor403(commandPath);
507
+ }
439
508
  return socketSdkErrorResult;
440
509
  }
441
510
  const socketSdkSuccessResult = {
@@ -454,7 +523,7 @@ async function handleApiCallNoSpinner(value, description) {
454
523
  error: e
455
524
  });
456
525
  const errStr = e ? String(e).trim() : '';
457
- const message = 'Socket API returned an error';
526
+ const message = 'Socket API error';
458
527
  const rawCause = errStr || NO_ERROR_MESSAGE;
459
528
  const cause = message !== rawCause ? rawCause : '';
460
529
  return {
@@ -479,7 +548,7 @@ async function handleApiCallNoSpinner(value, description) {
479
548
  const cause = reason && message !== reason ? `${message} (reason: ${reason})` : message;
480
549
  return {
481
550
  ok: false,
482
- message: 'Socket API returned an error',
551
+ message: 'Socket API error',
483
552
  cause,
484
553
  data: {
485
554
  code: sdkResult.status
@@ -494,9 +563,9 @@ async function handleApiCallNoSpinner(value, description) {
494
563
  }
495
564
  }
496
565
  async function queryApi(path, apiToken) {
497
- const baseUrl = getDefaultApiBaseUrl() || '';
566
+ const baseUrl = getDefaultApiBaseUrl();
498
567
  if (!baseUrl) {
499
- logger.logger.warn('API endpoint is not set and default was empty. Request is likely to fail.');
568
+ throw new Error('Socket API base URL is not configured.');
500
569
  }
501
570
  return await fetch(`${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}${path}`, {
502
571
  method: 'GET',
@@ -505,7 +574,11 @@ async function queryApi(path, apiToken) {
505
574
  }
506
575
  });
507
576
  }
508
- async function queryApiSafeText(path, description) {
577
+
578
+ /**
579
+ * Query Socket API endpoint and return text response with error handling.
580
+ */
581
+ async function queryApiSafeText(path, description, commandPath) {
509
582
  const apiToken = getDefaultApiToken();
510
583
  if (!apiToken) {
511
584
  return {
@@ -550,11 +623,10 @@ async function queryApiSafeText(path, description) {
550
623
  const {
551
624
  status
552
625
  } = result;
553
- const reason = await getErrorMessageForHttpStatusCode(status);
554
626
  return {
555
627
  ok: false,
556
- message: 'Socket API returned an error',
557
- cause: `${result.statusText} (reason: ${reason})`,
628
+ message: 'Socket API error',
629
+ cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)})`,
558
630
  data: {
559
631
  code: status
560
632
  }
@@ -578,6 +650,10 @@ async function queryApiSafeText(path, description) {
578
650
  };
579
651
  }
580
652
  }
653
+
654
+ /**
655
+ * Query Socket API endpoint and return parsed JSON response.
656
+ */
581
657
  async function queryApiSafeJson(path, description = '') {
582
658
  const result = await queryApiSafeText(path, description);
583
659
  if (!result.ok) {
@@ -592,10 +668,13 @@ async function queryApiSafeJson(path, description = '') {
592
668
  return {
593
669
  ok: false,
594
670
  message: 'Server returned invalid JSON',
595
- cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) || '<empty>').trim() + (result.data?.length > 100 ? '...' : '')}\``
671
+ cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) || constants.EMPTY_VALUE).trim() + (result.data?.length > 100 ? '...' : '')}\``
596
672
  };
597
673
  }
598
674
  }
675
+ /**
676
+ * Send POST/PUT request to Socket API with JSON response handling.
677
+ */
599
678
  async function sendApiRequest(path, options) {
600
679
  const apiToken = getDefaultApiToken();
601
680
  if (!apiToken) {
@@ -605,12 +684,17 @@ async function sendApiRequest(path, options) {
605
684
  cause: 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your Socket API token.'
606
685
  };
607
686
  }
608
- const baseUrl = getDefaultApiBaseUrl() || '';
687
+ const baseUrl = getDefaultApiBaseUrl();
609
688
  if (!baseUrl) {
610
- logger.logger.warn('API endpoint is not set and default was empty. Request is likely to fail.');
689
+ return {
690
+ ok: false,
691
+ message: 'Configuration Error',
692
+ cause: 'Socket API endpoint is not configured. Please check your environment configuration.'
693
+ };
611
694
  }
612
695
  const {
613
696
  body,
697
+ commandPath,
614
698
  description,
615
699
  method
616
700
  } = {
@@ -663,11 +747,14 @@ async function sendApiRequest(path, options) {
663
747
  const {
664
748
  status
665
749
  } = result;
666
- const reason = await getErrorMessageForHttpStatusCode(status);
750
+ // Log required permissions for 403 errors when in a command context.
751
+ if (commandPath && status === 403) {
752
+ logPermissionsFor403(commandPath);
753
+ }
667
754
  return {
668
755
  ok: false,
669
- message: 'Socket API returned an error',
670
- cause: `${result.statusText} (reason: ${reason})`,
756
+ message: 'Socket API error',
757
+ cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)})`,
671
758
  data: {
672
759
  code: status
673
760
  }
@@ -693,7 +780,7 @@ async function sendApiRequest(path, options) {
693
780
  }
694
781
 
695
782
  function failMsgWithBadge(badge, message) {
696
- const prefix = vendor.yoctocolorsCjsExports.bgRed(vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.white(` ${badge}${message ? ': ' : ''}`)));
783
+ const prefix = vendor.yoctocolorsCjsExports.bgRedBright(vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.red(` ${badge}${message ? ': ' : ''}`)));
697
784
  const postfix = message ? ` ${vendor.yoctocolorsCjsExports.bold(message)}` : '';
698
785
  return `${prefix}${postfix}`;
699
786
  }
@@ -887,18 +974,10 @@ function getOutputKind(json, markdown) {
887
974
  return constants.OUTPUT_TEXT;
888
975
  }
889
976
 
890
- const require$2 = Module.createRequire(require('node:url').pathToFileURL(__filename).href);
891
- let _requirements;
892
- function getRequirements() {
893
- if (_requirements === undefined) {
894
- _requirements = /*@__PURE__*/require$2(path.join(constants.default.rootPath, 'requirements.json'));
895
- }
896
- return _requirements;
977
+ function camelToKebab(str) {
978
+ return str === '' ? '' : str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
897
979
  }
898
980
 
899
- function camelToKebab(string) {
900
- return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
901
- }
902
981
  function getFlagApiRequirementsOutput(cmdPath, options) {
903
982
  const {
904
983
  indent = 6
@@ -906,20 +985,21 @@ function getFlagApiRequirementsOutput(cmdPath, options) {
906
985
  __proto__: null,
907
986
  ...options
908
987
  };
909
- const key = cmdPath.replace(/^socket[: ]/, '').replace(/ +/g, ':');
988
+ const key = getRequirementsKey(cmdPath);
910
989
  const requirements = getRequirements();
911
990
  const data = requirements.api[key];
912
991
  let result = '';
913
992
  if (data) {
914
993
  const quota = data?.quota;
915
- const perms = data?.permissions;
994
+ const rawPerms = data?.permissions;
916
995
  const padding = ''.padEnd(indent);
917
996
  const lines = [];
918
- if (typeof quota === 'number') {
997
+ if (Number.isFinite(quota) && quota > 0) {
919
998
  lines.push(`${padding}- Quota: ${quota} ${words.pluralize('unit', quota)}`);
920
999
  }
921
- if (Array.isArray(perms) && perms.length) {
922
- lines.push(`${padding}- Permissions: ${perms.join(' ')}`);
1000
+ if (Array.isArray(rawPerms) && rawPerms.length) {
1001
+ const perms = rawPerms.slice().sort(sorts.naturalCompare);
1002
+ lines.push(`${padding}- Permissions: ${arrays.joinAnd(perms)}`);
923
1003
  }
924
1004
  result += lines.join('\n');
925
1005
  }
@@ -980,6 +1060,10 @@ function tildify(cwd) {
980
1060
 
981
1061
  const HELP_INDENT = 2;
982
1062
  const HELP_PAD_NAME = 28;
1063
+
1064
+ /**
1065
+ * Format a command description for help output.
1066
+ */
983
1067
  function description(command) {
984
1068
  const description = command?.description;
985
1069
  const str = typeof description === 'string' ? description : String(description);
@@ -1004,6 +1088,10 @@ function findBestCommandMatch(input, subcommands, aliases) {
1004
1088
  }
1005
1089
  return bestMatch;
1006
1090
  }
1091
+
1092
+ /**
1093
+ * Generate the ASCII banner header for Socket CLI commands.
1094
+ */
1007
1095
  function getAsciiHeader(command, orgFlag) {
1008
1096
  // Note: In tests we return <redacted> because otherwise snapshots will fail.
1009
1097
  const {
@@ -1047,19 +1135,28 @@ function levenshteinDistance(a, b) {
1047
1135
  for (let i = 1; i <= a.length; i++) {
1048
1136
  for (let j = 1; j <= b.length; j++) {
1049
1137
  const cost = a[i - 1] === b[j - 1] ? 0 : 1;
1050
- matrix[i][j] = Math.min(matrix[i - 1][j] + 1,
1138
+ matrix[i][j] = Math.min(
1051
1139
  // Deletion.
1052
- matrix[i][j - 1] + 1,
1140
+ matrix[i - 1][j] + 1,
1053
1141
  // Insertion.
1054
- matrix[i - 1][j - 1] + cost // Substitution.
1055
- );
1142
+ matrix[i][j - 1] + 1,
1143
+ // Substitution.
1144
+ matrix[i - 1][j - 1] + cost);
1056
1145
  }
1057
1146
  }
1058
1147
  return matrix[a.length][b.length];
1059
1148
  }
1149
+
1150
+ /**
1151
+ * Determine if the banner should be suppressed based on output flags.
1152
+ */
1060
1153
  function shouldSuppressBanner(flags) {
1061
- return Boolean(flags['json'] || flags['markdown'] || flags['nobanner']);
1154
+ return Boolean(flags['json'] || flags['markdown'] || flags['banner'] === false);
1062
1155
  }
1156
+
1157
+ /**
1158
+ * Emit the Socket CLI banner to stderr for branding and debugging.
1159
+ */
1063
1160
  function emitBanner(name, orgFlag) {
1064
1161
  // Print a banner at the top of each command.
1065
1162
  // This helps with brand recognition and marketing.
@@ -1071,6 +1168,10 @@ function emitBanner(name, orgFlag) {
1071
1168
  // The spinner also emits over stderr for example.
1072
1169
  logger.logger.error(getAsciiHeader(name, orgFlag));
1073
1170
  }
1171
+
1172
+ /**
1173
+ * Main function for handling CLI with subcommands using meow.
1174
+ */
1074
1175
  async function meowWithSubcommands(subcommands, options) {
1075
1176
  const {
1076
1177
  aliases = {},
@@ -1083,11 +1184,6 @@ async function meowWithSubcommands(subcommands, options) {
1083
1184
  __proto__: null,
1084
1185
  ...options
1085
1186
  };
1086
- const [commandOrAliasName_, ...rawCommandArgv] = argv;
1087
- let commandOrAliasName = commandOrAliasName_;
1088
- if (!commandOrAliasName && defaultSub) {
1089
- commandOrAliasName = defaultSub;
1090
- }
1091
1187
  const flags$1 = {
1092
1188
  ...flags.commonFlags,
1093
1189
  version: {
@@ -1095,13 +1191,18 @@ async function meowWithSubcommands(subcommands, options) {
1095
1191
  hidden: true,
1096
1192
  description: 'Print the app version'
1097
1193
  },
1098
- ...additionalOptions.flags
1194
+ ...require$$11.getOwn(additionalOptions, 'flags')
1099
1195
  };
1196
+ const [commandOrAliasName_, ...rawCommandArgv] = argv;
1197
+ let commandOrAliasName = commandOrAliasName_;
1198
+ if (!commandOrAliasName && defaultSub) {
1199
+ commandOrAliasName = defaultSub;
1200
+ }
1100
1201
 
1101
- // No further args or first arg is a flag (shrug)
1202
+ // No further args or first arg is a flag (shrug).
1102
1203
  const isRootCommand = name === 'socket' && (!commandOrAliasName || commandOrAliasName?.startsWith('-'));
1103
1204
 
1104
- // Try to support `socket <purl>` as a shorthand for `socket package score <purl>`
1205
+ // Try to support `socket <purl>` as a shorthand for `socket package score <purl>`.
1105
1206
  if (!isRootCommand) {
1106
1207
  if (commandOrAliasName?.startsWith('pkg:')) {
1107
1208
  logger.logger.info('Invoking `socket package score`.');
@@ -1174,7 +1275,6 @@ async function meowWithSubcommands(subcommands, options) {
1174
1275
  if (noSpinner) {
1175
1276
  constants.default.spinner.spinner = spinner.getCliSpinners('ci');
1176
1277
  }
1177
-
1178
1278
  // Hard override the config if instructed to do so.
1179
1279
  // The env var overrides the --flag, which overrides the persisted config
1180
1280
  // Also, when either of these are used, config updates won't persist.
@@ -1182,7 +1282,7 @@ async function meowWithSubcommands(subcommands, options) {
1182
1282
  if (constants.default.ENV.SOCKET_CLI_CONFIG) {
1183
1283
  configOverrideResult = overrideCachedConfig(constants.default.ENV.SOCKET_CLI_CONFIG);
1184
1284
  } else if (cli1.flags['config']) {
1185
- configOverrideResult = overrideCachedConfig(String(cli1.flags['config'] || ''));
1285
+ configOverrideResult = overrideCachedConfig(cli1.flags['config']);
1186
1286
  }
1187
1287
  if (constants.default.ENV.SOCKET_CLI_NO_API_TOKEN) {
1188
1288
  // This overrides the config override and even the explicit token env var.
@@ -1216,6 +1316,8 @@ async function meowWithSubcommands(subcommands, options) {
1216
1316
  const commandDefinition = commandName ? subcommands[commandName] : undefined;
1217
1317
  // Third: If a valid command has been found, then we run it...
1218
1318
  if (commandDefinition) {
1319
+ // Extract the original command arguments from the full argv
1320
+ // by skipping the command name
1219
1321
  return await commandDefinition.run(commandArgv, importMeta, {
1220
1322
  parentName: name
1221
1323
  });
@@ -1242,9 +1344,12 @@ async function meowWithSubcommands(subcommands, options) {
1242
1344
  //'json',
1243
1345
  'license', 'login', 'logout', 'manifest', constants.NPM, constants.NPX, 'optimize', 'organization', 'package',
1244
1346
  //'patch',
1347
+ // PNPM,
1245
1348
  'raw-npm', 'raw-npx', 'repository', 'scan',
1246
1349
  //'security',
1247
- 'threat-feed', 'uninstall', 'wrapper']);
1350
+ 'threat-feed', 'uninstall', 'wrapper'
1351
+ // YARN,
1352
+ ]);
1248
1353
  Object.entries(subcommands).filter(([_name, subcommand]) => !subcommand.hidden).map(([name]) => name).forEach(name => {
1249
1354
  if (commands.has(name)) {
1250
1355
  commands.delete(name);
@@ -1288,6 +1393,11 @@ async function meowWithSubcommands(subcommands, options) {
1288
1393
  }
1289
1394
  lines.push(` ${getFlagListOutput({
1290
1395
  ...flags$1,
1396
+ // Explicitly document the negated --no-banner variant.
1397
+ noBanner: {
1398
+ ...flags$1['banner'],
1399
+ hidden: false
1400
+ },
1291
1401
  // Explicitly document the negated --no-spinner variant.
1292
1402
  noSpinner: {
1293
1403
  ...flags$1['spinner'],
@@ -1298,12 +1408,12 @@ async function meowWithSubcommands(subcommands, options) {
1298
1408
  padName: HELP_PAD_NAME
1299
1409
  })}`);
1300
1410
  if (isRootCommand) {
1301
- lines.push('', 'Environment variables', ' SOCKET_CLI_API_TOKEN Set the Socket API token', ' SOCKET_CLI_CONFIG A JSON stringified Socket configuration object', ' SOCKET_CLI_GITHUB_API_URL Change the base URL for GitHub REST API calls', ' SOCKET_CLI_GIT_USER_EMAIL The git config `user.email` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]@users.noreply.github.com`, ' SOCKET_CLI_GIT_USER_NAME The git config `user.name` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]`, ` SOCKET_CLI_GITHUB_TOKEN A classic or fine-grained ${vendor.terminalLinkExports('GitHub personal access token', 'https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens')}`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} GITHUB_TOKEN`, ' SOCKET_CLI_NO_API_TOKEN Make the default API token `undefined`', ' SOCKET_CLI_NPM_PATH The absolute location of the npm directory', ' SOCKET_CLI_ORG_SLUG Specify the Socket organization slug', '', ' SOCKET_CLI_ACCEPT_RISKS Accept risks of a Socket wrapped npm/npx run', ' SOCKET_CLI_VIEW_ALL_RISKS View all risks of a Socket wrapped npm/npx run', '', 'Environment variables for development', ' SOCKET_CLI_API_BASE_URL Change the base URL for Socket API calls', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} The "apiBaseUrl" value of socket/settings local app data`, ' if present, else https://api.socket.dev/v0/', ' SOCKET_CLI_API_PROXY Set the proxy Socket API requests are routed through, e.g. if set to', ` ${vendor.terminalLinkExports('http://127.0.0.1:9090', 'https://docs.proxyman.io/troubleshooting/couldnt-see-any-requests-from-3rd-party-network-libraries')} then all request are passed through that proxy`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} HTTPS_PROXY, https_proxy, HTTP_PROXY, and http_proxy`, ' SOCKET_CLI_API_TIMEOUT Set the timeout in milliseconds for Socket API requests', ' SOCKET_CLI_DEBUG Enable debug logging in Socket CLI', ` DEBUG Enable debug logging based on the ${vendor.terminalLinkExports('debug', 'https://socket.dev/npm/package/debug')} package`);
1411
+ lines.push('', 'Environment variables', ' SOCKET_CLI_API_TOKEN Set the Socket API token', ' SOCKET_CLI_CONFIG A JSON stringified Socket configuration object', ' SOCKET_CLI_GITHUB_API_URL Change the base URL for GitHub REST API calls', ' SOCKET_CLI_GIT_USER_EMAIL The git config `user.email` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]@users.noreply.github.com`, ' SOCKET_CLI_GIT_USER_NAME The git config `user.name` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]`, ` SOCKET_CLI_GITHUB_TOKEN A classic or fine-grained ${vendor.terminalLinkExports('GitHub personal access token', 'https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens')}`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} GITHUB_TOKEN`, ' SOCKET_CLI_NO_API_TOKEN Make the default API token `undefined`', ' SOCKET_CLI_NPM_PATH The absolute location of the npm directory', ' SOCKET_CLI_ORG_SLUG Specify the Socket organization slug', '', ' SOCKET_CLI_ACCEPT_RISKS Accept risks of a Socket wrapped npm/npx run', ' SOCKET_CLI_VIEW_ALL_RISKS View all risks of a Socket wrapped npm/npx run', '', 'Environment variables for development', ' SOCKET_CLI_API_BASE_URL Change the base URL for Socket API calls', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} The "apiBaseUrl" value of socket/settings local app data`, ` if present, else ${constants.API_V0_URL}`, ' SOCKET_CLI_API_PROXY Set the proxy Socket API requests are routed through, e.g. if set to', ` ${vendor.terminalLinkExports('http://127.0.0.1:9090', 'https://docs.proxyman.io/troubleshooting/couldnt-see-any-requests-from-3rd-party-network-libraries')} then all request are passed through that proxy`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} HTTPS_PROXY, https_proxy, HTTP_PROXY, and http_proxy`, ' SOCKET_CLI_API_TIMEOUT Set the timeout in milliseconds for Socket API requests', ' SOCKET_CLI_DEBUG Enable debug logging in Socket CLI', ` DEBUG Enable debug logging based on the ${vendor.terminalLinkExports('debug', `${constants.SOCKET_WEBSITE_URL}/npm/package/debug`)} package`);
1302
1412
  }
1303
1413
 
1304
1414
  // Parse it again. Config overrides should now be applied (may affect help).
1305
1415
  // Note: this is displayed as help screen if the command does not override it
1306
- // (which is the case for most sub-commands with sub-commands)
1416
+ // (which is the case for most sub-commands with sub-commands).
1307
1417
  const cli2 = vendor.meow({
1308
1418
  argv,
1309
1419
  importMeta,
@@ -1323,7 +1433,7 @@ async function meowWithSubcommands(subcommands, options) {
1323
1433
  // ...else we provide basic instructions and help.
1324
1434
  if (!shouldSuppressBanner(cli2.flags)) {
1325
1435
  emitBanner(name, orgFlag);
1326
- // meow will add newline so don't add stderr spacing here
1436
+ // Meow will add newline so don't add stderr spacing here.
1327
1437
  }
1328
1438
  if (!cli2.flags['help'] && cli2.flags['dryRun']) {
1329
1439
  process.exitCode = 0;
@@ -1336,7 +1446,8 @@ async function meowWithSubcommands(subcommands, options) {
1336
1446
  }
1337
1447
 
1338
1448
  /**
1339
- * Note: meow will exit immediately if it calls its .showHelp()
1449
+ * Create meow CLI instance or exit with help/error (meow will exit immediately
1450
+ * if it calls .showHelp()).
1340
1451
  */
1341
1452
  function meowOrExit({
1342
1453
  allowUnknownFlags = true,
@@ -1361,14 +1472,19 @@ function meowOrExit({
1361
1472
  help: strings.trimNewlines(config.help(command, config)),
1362
1473
  importMeta
1363
1474
  });
1364
- const noSpinner = cli.flags['spinner'] === false;
1475
+ const {
1476
+ help: helpFlag,
1477
+ org: orgFlag,
1478
+ spinner: spinnerFlag,
1479
+ version: versionFlag
1480
+ } = cli.flags;
1481
+ const noSpinner = spinnerFlag === false;
1365
1482
 
1366
1483
  // Use CI spinner style when --no-spinner is passed.
1367
1484
  if (noSpinner) {
1368
1485
  constants.default.spinner.spinner = spinner.getCliSpinners('ci');
1369
1486
  }
1370
1487
  if (!shouldSuppressBanner(cli.flags)) {
1371
- const orgFlag = String(cli.flags['org'] || '').trim() || undefined;
1372
1488
  emitBanner(command, orgFlag);
1373
1489
  // Add newline in stderr.
1374
1490
  // Meow help adds a newline too so we do it here.
@@ -1393,12 +1509,12 @@ function meowOrExit({
1393
1509
  // })
1394
1510
  // }
1395
1511
 
1396
- if (cli.flags['help']) {
1512
+ if (helpFlag) {
1397
1513
  cli.showHelp(0);
1398
1514
  }
1399
1515
 
1400
1516
  // Meow doesn't detect 'version' as an unknown flag, so we do the leg work here.
1401
- if (!require$$11.hasOwn(config.flags, 'version') && cli.flags['version']) {
1517
+ if (versionFlag && !require$$11.hasOwn(config.flags, 'version')) {
1402
1518
  // Use `console.error` here instead of `logger.error` to match Meow behavior.
1403
1519
  console.error('Unknown flag\n--version');
1404
1520
  // eslint-disable-next-line n/no-process-exit
@@ -1408,7 +1524,6 @@ function meowOrExit({
1408
1524
  // Now test for help state. Run Meow again. If it exits now, it must be due
1409
1525
  // to wanting to print the help screen. But it would exit(0) and we want a
1410
1526
  // consistent exit(2) for that case (missing input).
1411
- // TODO: Move away from meow.
1412
1527
  process.exitCode = 2;
1413
1528
  vendor.meow({
1414
1529
  argv,
@@ -1679,7 +1794,7 @@ async function getBaseBranch(cwd = process.cwd()) {
1679
1794
  return 'main';
1680
1795
  }
1681
1796
  async function getRepoInfo(cwd = process.cwd()) {
1682
- let info = null;
1797
+ let info;
1683
1798
  const quotedCmd = '`git remote get-url origin`';
1684
1799
  require$$9.debugFn('stdio', `spawn: ${quotedCmd}`);
1685
1800
  try {
@@ -1745,7 +1860,7 @@ async function gitBranch(cwd = process.cwd()) {
1745
1860
  });
1746
1861
  }
1747
1862
  }
1748
- return null;
1863
+ return undefined;
1749
1864
  }
1750
1865
 
1751
1866
  /**
@@ -2056,7 +2171,7 @@ async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
2056
2171
  }
2057
2172
  const parsedGitRemoteUrlCache = new Map();
2058
2173
  function parseGitRemoteUrl(remoteUrl) {
2059
- let result = parsedGitRemoteUrlCache.get(remoteUrl) ?? null;
2174
+ let result = parsedGitRemoteUrlCache.get(remoteUrl);
2060
2175
  if (result) {
2061
2176
  return {
2062
2177
  ...result
@@ -2108,7 +2223,7 @@ function getPurlObject(purl, options) {
2108
2223
  if (shouldThrow) {
2109
2224
  throw e;
2110
2225
  }
2111
- return null;
2226
+ return undefined;
2112
2227
  }
2113
2228
  }
2114
2229
  function normalizePurl(rawPurl) {
@@ -2448,7 +2563,7 @@ async function getPackageFilesForScan(inputPaths, supportedFiles, options) {
2448
2563
  return filterBySupportedScanFiles(filepaths, supportedFiles);
2449
2564
  }
2450
2565
 
2451
- function exitWithBinPathError(binName) {
2566
+ function exitWithBinPathError$2(binName) {
2452
2567
  logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
2453
2568
  // The exit code 127 indicates that the command or binary being executed
2454
2569
  // could not be found.
@@ -2460,7 +2575,7 @@ function getNpmBinPath() {
2460
2575
  if (_npmBinPath === undefined) {
2461
2576
  _npmBinPath = getNpmBinPathDetails().path;
2462
2577
  if (!_npmBinPath) {
2463
- exitWithBinPathError(constants.NPM);
2578
+ exitWithBinPathError$2(constants.NPM);
2464
2579
  }
2465
2580
  }
2466
2581
  return _npmBinPath;
@@ -2501,7 +2616,7 @@ function getNpmRequire() {
2501
2616
  if (_npmRequire === undefined) {
2502
2617
  const npmDirPath = getNpmDirPath();
2503
2618
  const npmNmPath = path.join(npmDirPath, `${constants.NODE_MODULES}/npm`);
2504
- _npmRequire = Module.createRequire(path.join(fs$1.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
2619
+ _npmRequire = require$$5.createRequire(path.join(fs$1.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
2505
2620
  }
2506
2621
  return _npmRequire;
2507
2622
  }
@@ -2510,7 +2625,7 @@ function getNpxBinPath() {
2510
2625
  if (_npxBinPath === undefined) {
2511
2626
  _npxBinPath = getNpxBinPathDetails().path;
2512
2627
  if (!_npxBinPath) {
2513
- exitWithBinPathError('npx');
2628
+ exitWithBinPathError$2('npx');
2514
2629
  }
2515
2630
  }
2516
2631
  return _npxBinPath;
@@ -2530,23 +2645,33 @@ function isNpxBinPathShadowed() {
2530
2645
  }
2531
2646
 
2532
2647
  const helpFlags = new Set(['--help', '-h']);
2648
+
2649
+ /**
2650
+ * Convert command arguments to a properly formatted string representation.
2651
+ */
2533
2652
  function cmdFlagsToString(args) {
2534
2653
  const result = [];
2535
2654
  for (let i = 0, {
2536
2655
  length
2537
2656
  } = args; i < length; i += 1) {
2538
- if (args[i].startsWith('--')) {
2657
+ const arg = args[i].trim();
2658
+ if (arg.startsWith('--')) {
2659
+ const nextArg = i + 1 < length ? args[i + 1].trim() : undefined;
2539
2660
  // Check if the next item exists and is NOT another flag.
2540
- if (i + 1 < length && !args[i + 1].startsWith('--')) {
2541
- result.push(`${args[i]}=${args[i + 1]}`);
2661
+ if (nextArg?.startsWith('--')) {
2662
+ result.push(`${arg}=${nextArg}`);
2542
2663
  i += 1;
2543
2664
  } else {
2544
- result.push(args[i]);
2665
+ result.push(arg);
2545
2666
  }
2546
2667
  }
2547
2668
  }
2548
2669
  return result.join(' ');
2549
2670
  }
2671
+
2672
+ /**
2673
+ * Convert flag values to array format for processing.
2674
+ */
2550
2675
  function cmdFlagValueToArray(value) {
2551
2676
  if (typeof value === 'string') {
2552
2677
  return value.trim().split(/, */).filter(Boolean);
@@ -2556,10 +2681,81 @@ function cmdFlagValueToArray(value) {
2556
2681
  }
2557
2682
  return [];
2558
2683
  }
2684
+
2685
+ /**
2686
+ * Add command name prefix to message text.
2687
+ */
2559
2688
  function cmdPrefixMessage(cmdName, text) {
2560
2689
  const cmdPrefix = cmdName ? `${cmdName}: ` : '';
2561
2690
  return `${cmdPrefix}${text}`;
2562
2691
  }
2692
+
2693
+ /**
2694
+ * Filter out Socket flags from argv before passing to subcommands.
2695
+ */
2696
+ function filterFlags(argv, flagsToFilter, exceptions) {
2697
+ const filtered = [];
2698
+
2699
+ // Build set of flags to filter from the provided flag objects.
2700
+ const flagsToFilterSet = new Set();
2701
+ const flagsWithValueSet = new Set();
2702
+ for (const [flagName, flag] of Object.entries(flagsToFilter)) {
2703
+ const longFlag = `--${camelToKebab(flagName)}`;
2704
+ // Special case for negated booleans.
2705
+ if (flagName === 'spinner' || flagName === 'banner') {
2706
+ flagsToFilterSet.add(`--no-${flagName}`);
2707
+ } else {
2708
+ flagsToFilterSet.add(longFlag);
2709
+ }
2710
+ if (flag?.shortFlag) {
2711
+ flagsToFilterSet.add(`-${flag.shortFlag}`);
2712
+ }
2713
+ // Track flags that take values.
2714
+ if (flag.type !== 'boolean') {
2715
+ flagsWithValueSet.add(longFlag);
2716
+ if (flag?.shortFlag) {
2717
+ flagsWithValueSet.add(`-${flag.shortFlag}`);
2718
+ }
2719
+ }
2720
+ }
2721
+ for (let i = 0, {
2722
+ length
2723
+ } = argv; i < length; i += 1) {
2724
+ const arg = argv[i];
2725
+ // Check if this flag should be kept as an exception.
2726
+ if (exceptions?.includes(arg)) {
2727
+ filtered.push(arg);
2728
+ // Handle flags that take values.
2729
+ if (flagsWithValueSet.has(arg)) {
2730
+ // Include the next argument (the flag value).
2731
+ i += 1;
2732
+ if (i < length) {
2733
+ filtered.push(argv[i]);
2734
+ }
2735
+ }
2736
+ } else if (flagsToFilterSet.has(arg)) {
2737
+ // Skip flags that take values.
2738
+ if (flagsWithValueSet.has(arg)) {
2739
+ // Skip the next argument (the flag value).
2740
+ i += 1;
2741
+ }
2742
+ // Skip boolean flags (no additional argument to skip).
2743
+ } else if (arg && Array.from(flagsWithValueSet).some(flag => arg.startsWith(`${flag}=`))) {
2744
+ // Skip --flag=value format for Socket flags unless it's an exception.
2745
+ if (exceptions?.some(exc => arg.startsWith(`${exc}=`))) {
2746
+ filtered.push(arg);
2747
+ }
2748
+ // Otherwise skip it.
2749
+ } else {
2750
+ filtered.push(arg);
2751
+ }
2752
+ }
2753
+ return filtered;
2754
+ }
2755
+
2756
+ /**
2757
+ * Check if argument is a help flag.
2758
+ */
2563
2759
  function isHelpFlag(cmdArg) {
2564
2760
  return helpFlags.has(cmdArg);
2565
2761
  }
@@ -2670,7 +2866,8 @@ async function spawnCoana(args, orgSlug, options, extra) {
2670
2866
  };
2671
2867
  } catch (e) {
2672
2868
  const stderr = e?.stderr;
2673
- const message = stderr ? stderr : e?.message;
2869
+ const cause = e?.message || constants.UNKNOWN_ERROR;
2870
+ const message = stderr ? stderr : cause;
2674
2871
  return {
2675
2872
  ok: false,
2676
2873
  data: e,
@@ -2695,30 +2892,45 @@ function readOrDefaultSocketJson(cwd) {
2695
2892
  // This should be unreachable but it makes TS happy.
2696
2893
  getDefaultSocketJson();
2697
2894
  }
2895
+ async function findSocketJsonUp(cwd) {
2896
+ return await findUp(constants.SOCKET_JSON, {
2897
+ onlyFiles: true,
2898
+ cwd
2899
+ });
2900
+ }
2901
+ async function readOrDefaultSocketJsonUp(cwd) {
2902
+ const socketJsonPath = await findSocketJsonUp(cwd);
2903
+ if (socketJsonPath) {
2904
+ const socketJsonDir = path.dirname(socketJsonPath);
2905
+ const jsonCResult = readSocketJsonSync(socketJsonDir, true);
2906
+ return jsonCResult.ok ? jsonCResult.data : getDefaultSocketJson();
2907
+ }
2908
+ return getDefaultSocketJson();
2909
+ }
2698
2910
  function getDefaultSocketJson() {
2699
2911
  return {
2700
- ' _____ _ _ ': 'Local config file for Socket CLI tool ( https://npmjs.org/socket ), to work with https://socket.dev',
2912
+ ' _____ _ _ ': `Local config file for Socket CLI tool ( ${constants.SOCKET_WEBSITE_URL}/npm/package/${constants.SOCKET_JSON.replace('.json', '')} ), to work with ${constants.SOCKET_WEBSITE_URL}`,
2701
2913
  '| __|___ ___| |_ ___| |_ ': ' The config in this file is used to set as defaults for flags or command args when using the CLI',
2702
2914
  "|__ | . | _| '_| -_| _| ": ' in this dir, often a repo root. You can choose commit or .ignore this file, both works.',
2703
- '|_____|___|___|_,_|___|_|.dev': 'Warning: This file may be overwritten without warning by `socket manifest setup` or other commands',
2915
+ '|_____|___|___|_,_|___|_|.dev': `Warning: This file may be overwritten without warning by \`${constants.SOCKET_JSON.replace('.json', '')} manifest setup\` or other commands`,
2704
2916
  version: 1
2705
2917
  };
2706
2918
  }
2707
2919
  function readSocketJsonSync(cwd, defaultOnError = false) {
2708
- const sockJsonPath = path.join(cwd, 'socket.json');
2920
+ const sockJsonPath = path.join(cwd, constants.SOCKET_JSON);
2709
2921
  if (!fs$1.existsSync(sockJsonPath)) {
2710
- require$$9.debugFn('notice', `miss: socket.json not found at ${cwd}`);
2922
+ require$$9.debugFn('notice', `miss: ${constants.SOCKET_JSON} not found at ${cwd}`);
2711
2923
  return {
2712
2924
  ok: true,
2713
2925
  data: getDefaultSocketJson()
2714
2926
  };
2715
2927
  }
2716
- let json = null;
2928
+ let jsonContent = null;
2717
2929
  try {
2718
- json = fs$1.readFileSync(sockJsonPath, 'utf8');
2930
+ jsonContent = fs$1.readFileSync(sockJsonPath, 'utf8');
2719
2931
  } catch (e) {
2720
2932
  if (defaultOnError) {
2721
- logger.logger.warn('Failed to read socket.json, using default');
2933
+ logger.logger.warn(`Failed to read ${constants.SOCKET_JSON}, using default`);
2722
2934
  require$$9.debugDir('inspect', {
2723
2935
  error: e
2724
2936
  });
@@ -2727,27 +2939,29 @@ function readSocketJsonSync(cwd, defaultOnError = false) {
2727
2939
  data: getDefaultSocketJson()
2728
2940
  };
2729
2941
  }
2730
- const msg = e?.message;
2942
+ const cause = e?.message;
2731
2943
  require$$9.debugDir('inspect', {
2732
2944
  error: e
2733
2945
  });
2734
2946
  return {
2735
2947
  ok: false,
2736
- message: 'Failed to read socket.json',
2737
- cause: `An error occurred while trying to read socket.json${msg ? `: ${msg}` : ''}`
2948
+ message: `Failed to read ${constants.SOCKET_JSON}`,
2949
+ cause: `An error occurred while trying to read ${constants.SOCKET_JSON}${cause ? `: ${cause}` : ''}`
2738
2950
  };
2739
2951
  }
2740
- let obj;
2952
+ let jsonObj;
2741
2953
  try {
2742
- obj = JSON.parse(json);
2954
+ jsonObj = JSON.parse(jsonContent);
2743
2955
  } catch (e) {
2744
2956
  require$$9.debugFn('error', 'caught: JSON.parse error');
2745
2957
  require$$9.debugDir('inspect', {
2746
- error: e,
2747
- json
2958
+ jsonContent
2959
+ });
2960
+ require$$9.debugDir('inspect', {
2961
+ error: e
2748
2962
  });
2749
2963
  if (defaultOnError) {
2750
- logger.logger.warn('Failed to parse socket.json, using default');
2964
+ logger.logger.warn(`Failed to parse ${constants.SOCKET_JSON}, using default`);
2751
2965
  return {
2752
2966
  ok: true,
2753
2967
  data: getDefaultSocketJson()
@@ -2755,11 +2969,11 @@ function readSocketJsonSync(cwd, defaultOnError = false) {
2755
2969
  }
2756
2970
  return {
2757
2971
  ok: false,
2758
- message: 'Failed to parse socket.json',
2759
- cause: 'socket.json does not contain valid JSON, please verify'
2972
+ message: `Failed to parse ${constants.SOCKET_JSON}`,
2973
+ cause: `${constants.SOCKET_JSON} does not contain valid JSON, please verify`
2760
2974
  };
2761
2975
  }
2762
- if (!obj) {
2976
+ if (!jsonObj) {
2763
2977
  logger.logger.warn('Warning: file contents was empty, using default');
2764
2978
  return {
2765
2979
  ok: true,
@@ -2767,17 +2981,17 @@ function readSocketJsonSync(cwd, defaultOnError = false) {
2767
2981
  };
2768
2982
  }
2769
2983
 
2770
- // Do we really care to validate? All properties are optional so code will have
2771
- // to check every step of the way regardless. Who cares about validation here...?
2984
+ // TODO: Do we need to validate? All properties are optional so code will have
2985
+ // to check every step of the way regardless.
2772
2986
  return {
2773
2987
  ok: true,
2774
- data: obj
2988
+ data: jsonObj
2775
2989
  };
2776
2990
  }
2777
2991
  async function writeSocketJson(cwd, sockJson) {
2778
- let json = '';
2992
+ let jsonContent = '';
2779
2993
  try {
2780
- json = JSON.stringify(sockJson, null, 2);
2994
+ jsonContent = JSON.stringify(sockJson, null, 2);
2781
2995
  } catch (e) {
2782
2996
  require$$9.debugFn('error', 'caught: JSON.stringify error');
2783
2997
  require$$9.debugDir('inspect', {
@@ -2787,11 +3001,11 @@ async function writeSocketJson(cwd, sockJson) {
2787
3001
  return {
2788
3002
  ok: false,
2789
3003
  message: 'Failed to serialize to JSON',
2790
- cause: 'There was an unexpected problem converting the socket json object to a JSON string. Unable to store it.'
3004
+ cause: `There was an unexpected problem converting the ${constants.SOCKET_JSON} object to a JSON string. Unable to store it.`
2791
3005
  };
2792
3006
  }
2793
- const filepath = path.join(cwd, 'socket.json');
2794
- await fs$1.promises.writeFile(filepath, json + '\n', 'utf8');
3007
+ const filepath = path.join(cwd, constants.SOCKET_JSON);
3008
+ await fs$1.promises.writeFile(filepath, `${jsonContent}\n`, 'utf8');
2795
3009
  return {
2796
3010
  ok: true,
2797
3011
  data: undefined
@@ -2809,7 +3023,7 @@ ttlMs = 5 * 60 * 1000) {
2809
3023
  return await fs.readJson(cacheJsonPath);
2810
3024
  }
2811
3025
  }
2812
- return null;
3026
+ return undefined;
2813
3027
  }
2814
3028
  async function writeCache(key, data) {
2815
3029
  const {
@@ -2877,7 +3091,11 @@ async function fetchGhsaDetails(ids) {
2877
3091
  }
2878
3092
  }
2879
3093
  } catch (e) {
2880
- require$$9.debugFn('error', `Failed to fetch GHSA details: ${e?.message || constants.UNKNOWN_ERROR}`);
3094
+ const cause = e?.message;
3095
+ require$$9.debugFn('error', `Failed to fetch GHSA details${cause ? `: ${cause}` : ''}`);
3096
+ require$$9.debugDir('inspect', {
3097
+ error: e
3098
+ });
2881
3099
  }
2882
3100
  return results;
2883
3101
  }
@@ -2959,8 +3177,17 @@ async function enablePrAutoMerge({
2959
3177
  }
2960
3178
  async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
2961
3179
  const {
2962
- host
2963
- } = new URL(constants.default.ENV.GITHUB_SERVER_URL);
3180
+ GITHUB_SERVER_URL
3181
+ } = constants.default.ENV;
3182
+ const urlObj = require$$13.parseUrl(GITHUB_SERVER_URL);
3183
+ const host = urlObj?.host;
3184
+ if (!host) {
3185
+ require$$9.debugFn('error', 'invalid: GITHUB_SERVER_URL env var');
3186
+ require$$9.debugDir('inspect', {
3187
+ GITHUB_SERVER_URL
3188
+ });
3189
+ return false;
3190
+ }
2964
3191
  const url = `https://x-access-token:${token}@${host}/${owner}/${repo}`;
2965
3192
  const stdioIgnoreOptions = {
2966
3193
  cwd,
@@ -2980,13 +3207,106 @@ async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()
2980
3207
  return false;
2981
3208
  }
2982
3209
 
2983
- const RangeStyles = ['caret', 'gt', 'gte', 'lt', 'lte', 'pin', 'preserve', 'tilde'];
3210
+ /**
3211
+ * Converts CVE IDs to GHSA IDs using GitHub API.
3212
+ */
3213
+ async function convertCveToGhsa(cveId) {
3214
+ try {
3215
+ const cacheKey = `cve-to-ghsa-${cveId}`;
3216
+ const octokit = getOctokit();
3217
+ const response = await cacheFetch(cacheKey, () => octokit.rest.securityAdvisories.listGlobalAdvisories({
3218
+ cve_id: cveId,
3219
+ per_page: 1
3220
+ }));
3221
+ if (!response.data.length) {
3222
+ return {
3223
+ ok: false,
3224
+ message: `No GHSA found for CVE ${cveId}`
3225
+ };
3226
+ }
3227
+ return {
3228
+ ok: true,
3229
+ data: response.data[0].ghsa_id
3230
+ };
3231
+ } catch (e) {
3232
+ return {
3233
+ ok: false,
3234
+ message: `Failed to convert CVE to GHSA: ${e instanceof Error ? e.message : 'Unknown error'}`
3235
+ };
3236
+ }
3237
+ }
3238
+
3239
+ const PURL_TO_GITHUB_ECOSYSTEM_MAPPING = {
3240
+ __proto__: null,
3241
+ // GitHub Advisory Database supported ecosystems
3242
+ cargo: 'rust',
3243
+ composer: 'composer',
3244
+ gem: 'rubygems',
3245
+ go: 'go',
3246
+ golang: 'go',
3247
+ maven: 'maven',
3248
+ npm: 'npm',
3249
+ nuget: 'nuget',
3250
+ pypi: 'pip',
3251
+ swift: 'swift'
3252
+ };
3253
+
3254
+ /**
3255
+ * Converts PURL to GHSA IDs using GitHub API.
3256
+ */
3257
+ async function convertPurlToGhsas(purl) {
3258
+ try {
3259
+ const purlObj = getPurlObject(purl, {
3260
+ throws: false
3261
+ });
3262
+ if (!purlObj) {
3263
+ return {
3264
+ ok: false,
3265
+ message: `Invalid PURL format: ${purl}`
3266
+ };
3267
+ }
3268
+ const {
3269
+ name,
3270
+ type: ecosystem,
3271
+ version
3272
+ } = purlObj;
3273
+
3274
+ // Map PURL ecosystem to GitHub ecosystem.
3275
+ const githubEcosystem = PURL_TO_GITHUB_ECOSYSTEM_MAPPING[ecosystem];
3276
+ if (!githubEcosystem) {
3277
+ return {
3278
+ ok: false,
3279
+ message: `Unsupported PURL ecosystem: ${ecosystem}`
3280
+ };
3281
+ }
3282
+
3283
+ // Search for advisories affecting this package.
3284
+ const cacheKey = `purl-to-ghsa-${ecosystem}-${name}-${version || constants.LATEST}`;
3285
+ const octokit = getOctokit();
3286
+ const affects = version ? `${name}@${version}` : name;
3287
+ const response = await cacheFetch(cacheKey, () => octokit.rest.securityAdvisories.listGlobalAdvisories({
3288
+ ecosystem: githubEcosystem,
3289
+ affects
3290
+ }));
3291
+ return {
3292
+ ok: true,
3293
+ data: response.data.map(a => a.ghsa_id)
3294
+ };
3295
+ } catch (e) {
3296
+ return {
3297
+ ok: false,
3298
+ message: `Failed to convert PURL to GHSA: ${e instanceof Error ? e.message : constants.UNKNOWN_ERROR}`
3299
+ };
3300
+ }
3301
+ }
3302
+
3303
+ const RangeStyles = ['pin', 'preserve'];
2984
3304
  function getMajor(version) {
2985
3305
  try {
2986
3306
  const coerced = vendor.semverExports.coerce(version);
2987
- return coerced ? vendor.semverExports.major(coerced) : null;
3307
+ return coerced ? vendor.semverExports.major(coerced) : undefined;
2988
3308
  } catch {}
2989
- return null;
3309
+ return undefined;
2990
3310
  }
2991
3311
 
2992
3312
  const COMPLETION_CMD_PREFIX = 'complete -F _socket_completion';
@@ -3074,11 +3394,63 @@ function captureExceptionSync(exception, hint) {
3074
3394
  return Sentry.captureException(exception, hint);
3075
3395
  }
3076
3396
 
3397
+ function exitWithBinPathError$1(binName) {
3398
+ logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
3399
+ // The exit code 127 indicates that the command or binary being executed
3400
+ // could not be found.
3401
+ // eslint-disable-next-line n/no-process-exit
3402
+ process.exit(127);
3403
+ }
3404
+ let _yarnBinPath;
3405
+ function getYarnBinPath() {
3406
+ if (_yarnBinPath === undefined) {
3407
+ _yarnBinPath = getYarnBinPathDetails().path;
3408
+ if (!_yarnBinPath) {
3409
+ exitWithBinPathError$1(constants.default.YARN);
3410
+ }
3411
+ }
3412
+ return _yarnBinPath;
3413
+ }
3414
+ let _yarnBinPathDetails;
3415
+ function getYarnBinPathDetails() {
3416
+ if (_yarnBinPathDetails === undefined) {
3417
+ _yarnBinPathDetails = findBinPathDetailsSync(constants.default.YARN);
3418
+ }
3419
+ return _yarnBinPathDetails;
3420
+ }
3421
+ function isYarnBinPathShadowed() {
3422
+ return getYarnBinPathDetails().shadowed;
3423
+ }
3424
+
3425
+ let _isYarnBerry;
3426
+ function isYarnBerry() {
3427
+ if (_isYarnBerry === undefined) {
3428
+ try {
3429
+ const yarnBinPath = getYarnBinPath();
3430
+ const result = spawn.spawnSync(yarnBinPath, ['--version'], {
3431
+ encoding: 'utf8',
3432
+ shell: constants.default.WIN32
3433
+ });
3434
+ if (result.status === 0 && result.stdout) {
3435
+ const version = result.stdout;
3436
+ // Yarn Berry starts from version 2.x
3437
+ const majorVersion = parseInt(version.split('.')[0], 10);
3438
+ _isYarnBerry = majorVersion >= 2;
3439
+ } else {
3440
+ _isYarnBerry = false;
3441
+ }
3442
+ } catch {
3443
+ _isYarnBerry = false;
3444
+ }
3445
+ }
3446
+ return _isYarnBerry;
3447
+ }
3448
+
3077
3449
  function npa(...args) {
3078
3450
  try {
3079
3451
  return Reflect.apply(vendor.npaExports, undefined, args);
3080
3452
  } catch {}
3081
- return null;
3453
+ return undefined;
3082
3454
  }
3083
3455
 
3084
3456
  function shadowNpmInstall(options) {
@@ -3242,10 +3614,10 @@ const LOCKS = {
3242
3614
  // will be ignored.
3243
3615
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
3244
3616
  'npm-shrinkwrap.json': NPM,
3245
- 'package-lock.json': NPM,
3246
- 'pnpm-lock.yaml': PNPM,
3247
- 'pnpm-lock.yml': PNPM,
3248
- [`yarn${EXT_LOCK}`]: YARN_CLASSIC,
3617
+ [constants.PACKAGE_LOCK_JSON]: NPM,
3618
+ [constants.PNPM_LOCK_YAML]: PNPM,
3619
+ ['pnpm-lock.yml']: PNPM,
3620
+ [constants.YARN_LOCK]: YARN_CLASSIC,
3249
3621
  'vlt-lock.json': VLT,
3250
3622
  // Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
3251
3623
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
@@ -3517,6 +3889,105 @@ function getEcosystemChoicesForMeow() {
3517
3889
  return [...ALL_ECOSYSTEMS];
3518
3890
  }
3519
3891
 
3892
+ function exitWithBinPathError(binName) {
3893
+ logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
3894
+ // The exit code 127 indicates that the command or binary being executed
3895
+ // could not be found.
3896
+ // eslint-disable-next-line n/no-process-exit
3897
+ process.exit(127);
3898
+ }
3899
+ let _pnpmBinPath;
3900
+ function getPnpmBinPath() {
3901
+ if (_pnpmBinPath === undefined) {
3902
+ _pnpmBinPath = getPnpmBinPathDetails().path;
3903
+ if (!_pnpmBinPath) {
3904
+ exitWithBinPathError('pnpm');
3905
+ }
3906
+ }
3907
+ return _pnpmBinPath;
3908
+ }
3909
+ let _pnpmBinPathDetails;
3910
+ function getPnpmBinPathDetails() {
3911
+ if (_pnpmBinPathDetails === undefined) {
3912
+ _pnpmBinPathDetails = findBinPathDetailsSync('pnpm');
3913
+ }
3914
+ return _pnpmBinPathDetails;
3915
+ }
3916
+ function isPnpmBinPathShadowed() {
3917
+ return getPnpmBinPathDetails().shadowed;
3918
+ }
3919
+
3920
+ function toFilterConfig(obj) {
3921
+ const normalized = {
3922
+ __proto__: null
3923
+ };
3924
+ const keys = require$$11.isObject(obj) ? Object.keys(obj) : [];
3925
+ for (const key of keys) {
3926
+ const value = obj[key];
3927
+ if (typeof value === 'boolean' || Array.isArray(value)) {
3928
+ normalized[key] = value;
3929
+ }
3930
+ }
3931
+ return normalized;
3932
+ }
3933
+
3934
+ function idToNpmPurl(id) {
3935
+ return `pkg:${constants.NPM}/${id}`;
3936
+ }
3937
+
3938
+ async function extractPurlsFromPnpmLockfile(lockfile) {
3939
+ const packages = lockfile?.packages ?? {};
3940
+ const seen = new Set();
3941
+ const visit = pkgPath => {
3942
+ if (seen.has(pkgPath)) {
3943
+ return;
3944
+ }
3945
+ const pkg = packages[pkgPath];
3946
+ if (!pkg) {
3947
+ return;
3948
+ }
3949
+ seen.add(pkgPath);
3950
+ const deps = {
3951
+ __proto__: null,
3952
+ ...pkg.dependencies,
3953
+ ...pkg.optionalDependencies,
3954
+ ...pkg.devDependencies
3955
+ };
3956
+ for (const depName in deps) {
3957
+ const ref = deps[depName];
3958
+ const subKey = isPnpmDepPath(ref) ? ref : `/${depName}@${ref}`;
3959
+ visit(subKey);
3960
+ }
3961
+ };
3962
+ for (const pkgPath of Object.keys(packages)) {
3963
+ visit(pkgPath);
3964
+ }
3965
+ return Array.from(seen).map(p => idToNpmPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))));
3966
+ }
3967
+ function isPnpmDepPath(maybeDepPath) {
3968
+ return maybeDepPath.length > 0 && maybeDepPath.charCodeAt(0) === 47; /*'/'*/
3969
+ }
3970
+ function parsePnpmLockfile(lockfileContent) {
3971
+ let result;
3972
+ if (typeof lockfileContent === 'string') {
3973
+ try {
3974
+ result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
3975
+ } catch {}
3976
+ }
3977
+ return require$$11.isObjectObject(result) ? result : null;
3978
+ }
3979
+ async function readPnpmLockfile(lockfilePath) {
3980
+ return fs$1.existsSync(lockfilePath) ? await fs.readFileUtf8(lockfilePath) : undefined;
3981
+ }
3982
+ function stripLeadingPnpmDepPathSlash(depPath) {
3983
+ return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
3984
+ }
3985
+ function stripPnpmPeerSuffix(depPath) {
3986
+ const parenIndex = depPath.indexOf('(');
3987
+ const index = parenIndex === -1 ? depPath.indexOf('_') : parenIndex;
3988
+ return index === -1 ? depPath : depPath.slice(0, index);
3989
+ }
3990
+
3520
3991
  function isArtifactAlertCve(alert) {
3521
3992
  const {
3522
3993
  type
@@ -3580,21 +4051,7 @@ class ColorOrMarkdown {
3580
4051
  }
3581
4052
  }
3582
4053
 
3583
- function toFilterConfig(obj) {
3584
- const normalized = {
3585
- __proto__: null
3586
- };
3587
- const keys = require$$11.isObject(obj) ? Object.keys(obj) : [];
3588
- for (const key of keys) {
3589
- const value = obj[key];
3590
- if (typeof value === 'boolean' || Array.isArray(value)) {
3591
- normalized[key] = value;
3592
- }
3593
- }
3594
- return normalized;
3595
- }
3596
-
3597
- const require$1 = Module.createRequire(require('node:url').pathToFileURL(__filename).href);
4054
+ const require$1 = require$$5.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('utils.js', document.baseURI).href)));
3598
4055
  let _translations;
3599
4056
  function getTranslations() {
3600
4057
  if (_translations === undefined) {
@@ -3947,10 +4404,13 @@ function logAlertsMap(alertsMap, options) {
3947
4404
  output.write('\n');
3948
4405
  }
3949
4406
 
3950
- function idToNpmPurl(id) {
3951
- return `pkg:${constants.NPM}/${id}`;
4407
+ async function getAlertsMapFromPnpmLockfile(lockfile, options) {
4408
+ const purls = await extractPurlsFromPnpmLockfile(lockfile);
4409
+ return await getAlertsMapFromPurls(purls, {
4410
+ overrides: lockfile.overrides,
4411
+ ...options
4412
+ });
3952
4413
  }
3953
-
3954
4414
  async function getAlertsMapFromPurls(purls, options) {
3955
4415
  const uniqPurls = arrays.arrayUnique(purls);
3956
4416
  require$$9.debugDir('silly', {
@@ -3984,10 +4444,11 @@ async function getAlertsMapFromPurls(purls, options) {
3984
4444
  });
3985
4445
  if (!sockSdkCResult.ok) {
3986
4446
  spinner?.stop();
3987
- throw new Error('Auth error: Run `socket login` first');
4447
+ throw new Error('Auth error: Run `socket login` first.');
3988
4448
  }
3989
4449
  const sockSdk = sockSdkCResult.data;
3990
- const socketYml = findSocketYmlSync()?.parsed;
4450
+ const socketYmlResult = findSocketYmlSync();
4451
+ const socketYml = socketYmlResult.ok && socketYmlResult.data ? socketYmlResult.data.parsed : undefined;
3991
4452
  const alertsMapOptions = {
3992
4453
  consolidate: opts.consolidate,
3993
4454
  filter: opts.filter,
@@ -4053,6 +4514,8 @@ exports.checkCommandInput = checkCommandInput;
4053
4514
  exports.cmdFlagValueToArray = cmdFlagValueToArray;
4054
4515
  exports.cmdFlagsToString = cmdFlagsToString;
4055
4516
  exports.cmdPrefixMessage = cmdPrefixMessage;
4517
+ exports.convertCveToGhsa = convertCveToGhsa;
4518
+ exports.convertPurlToGhsas = convertPurlToGhsas;
4056
4519
  exports.createEnum = createEnum;
4057
4520
  exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironment;
4058
4521
  exports.detectDefaultBranch = detectDefaultBranch;
@@ -4062,7 +4525,9 @@ exports.extractTier1ReachabilityScanId = extractTier1ReachabilityScanId;
4062
4525
  exports.failMsgWithBadge = failMsgWithBadge;
4063
4526
  exports.fetchGhsaDetails = fetchGhsaDetails;
4064
4527
  exports.fetchOrganization = fetchOrganization;
4528
+ exports.filterFlags = filterFlags;
4065
4529
  exports.findUp = findUp;
4530
+ exports.getAlertsMapFromPnpmLockfile = getAlertsMapFromPnpmLockfile;
4066
4531
  exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
4067
4532
  exports.getBaseBranch = getBaseBranch;
4068
4533
  exports.getBashrcDetails = getBashrcDetails;
@@ -4082,6 +4547,7 @@ exports.getOctokitGraphql = getOctokitGraphql;
4082
4547
  exports.getOrgSlugs = getOrgSlugs;
4083
4548
  exports.getOutputKind = getOutputKind;
4084
4549
  exports.getPackageFilesForScan = getPackageFilesForScan;
4550
+ exports.getPnpmBinPath = getPnpmBinPath;
4085
4551
  exports.getPublicApiToken = getPublicApiToken;
4086
4552
  exports.getPurlObject = getPurlObject;
4087
4553
  exports.getRepoInfo = getRepoInfo;
@@ -4090,6 +4556,7 @@ exports.getSocketDevPackageOverviewUrlFromPurl = getSocketDevPackageOverviewUrlF
4090
4556
  exports.getSupportedConfigEntries = getSupportedConfigEntries;
4091
4557
  exports.getSupportedConfigKeys = getSupportedConfigKeys;
4092
4558
  exports.getVisibleTokenPrefix = getVisibleTokenPrefix;
4559
+ exports.getYarnBinPath = getYarnBinPath;
4093
4560
  exports.gitBranch = gitBranch;
4094
4561
  exports.gitCheckoutBranch = gitCheckoutBranch;
4095
4562
  exports.gitCommit = gitCommit;
@@ -4108,10 +4575,13 @@ exports.idToNpmPurl = idToNpmPurl;
4108
4575
  exports.isHelpFlag = isHelpFlag;
4109
4576
  exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
4110
4577
  exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
4578
+ exports.isPnpmBinPathShadowed = isPnpmBinPathShadowed;
4111
4579
  exports.isReadOnlyConfig = isReadOnlyConfig;
4112
4580
  exports.isReportSupportedFile = isReportSupportedFile;
4113
4581
  exports.isSensitiveConfigKey = isSensitiveConfigKey;
4114
4582
  exports.isSupportedConfigKey = isSupportedConfigKey;
4583
+ exports.isYarnBerry = isYarnBerry;
4584
+ exports.isYarnBinPathShadowed = isYarnBinPathShadowed;
4115
4585
  exports.logAlertsMap = logAlertsMap;
4116
4586
  exports.mapToObject = mapToObject;
4117
4587
  exports.mdTable = mdTable;
@@ -4122,9 +4592,12 @@ exports.meowWithSubcommands = meowWithSubcommands;
4122
4592
  exports.msAtHome = msAtHome;
4123
4593
  exports.normalizePurl = normalizePurl;
4124
4594
  exports.npa = npa;
4595
+ exports.parsePnpmLockfile = parsePnpmLockfile;
4125
4596
  exports.queryApiSafeJson = queryApiSafeJson;
4126
4597
  exports.queryApiSafeText = queryApiSafeText;
4127
4598
  exports.readOrDefaultSocketJson = readOrDefaultSocketJson;
4599
+ exports.readOrDefaultSocketJsonUp = readOrDefaultSocketJsonUp;
4600
+ exports.readPnpmLockfile = readPnpmLockfile;
4128
4601
  exports.readSocketJsonSync = readSocketJsonSync;
4129
4602
  exports.runAgentInstall = runAgentInstall;
4130
4603
  exports.sendApiRequest = sendApiRequest;
@@ -4138,5 +4611,5 @@ exports.toFilterConfig = toFilterConfig;
4138
4611
  exports.updateConfigValue = updateConfigValue;
4139
4612
  exports.walkNestedMap = walkNestedMap;
4140
4613
  exports.writeSocketJson = writeSocketJson;
4141
- //# debugId=737faea9-c80e-4b25-92fc-cf5802905b27
4614
+ //# debugId=1da7b4a0-f584-4be9-bf6b-9269a66c830
4142
4615
  //# sourceMappingURL=utils.js.map